Mesa (main): glsl: add new build program resource helpers
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon May 16 04:43:32 UTC 2022
Module: Mesa
Branch: main
Commit: 43a8454ea8bed0a18e15a8636464985878a33468
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=43a8454ea8bed0a18e15a8636464985878a33468
Author: Timothy Arceri <tarceri at itsqueeze.com>
Date: Mon Mar 21 17:41:58 2022 +1100
glsl: add new build program resource helpers
These will be used by a new nir based glsl varying linker that will
add varyings directly to the list before the are packed and we lose
the information.
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15731>
---
src/compiler/glsl/gl_nir_linker.c | 37 ++++++++++++++++++++++++++++++++-----
src/compiler/glsl/gl_nir_linker.h | 11 +++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c
index d16c5d50f43..8f6d4ee39b9 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -507,6 +507,36 @@ add_interface_variables(const struct gl_constants *consts,
return false;
}
+bool
+nir_add_packed_var_to_resource_list(const struct gl_constants *consts,
+ struct gl_shader_program *shProg,
+ struct set *resource_set,
+ nir_variable *var,
+ unsigned stage, GLenum type)
+{
+ if (!add_shader_variable(consts, shProg, resource_set, 1 << stage,
+ type, var, var->name, var->type, false,
+ var->data.location - VARYING_SLOT_VAR0,
+ inout_has_same_location(var, stage), NULL))
+ return false;
+
+ return true;
+}
+
+/**
+ * Initilise list of program resources that point to resource data.
+ */
+void
+init_program_resource_list(struct gl_shader_program *prog)
+{
+ /* Rebuild resource list. */
+ if (prog->data->ProgramResourceList) {
+ ralloc_free(prog->data->ProgramResourceList);
+ prog->data->ProgramResourceList = NULL;
+ prog->data->NumProgramResourceList = 0;
+ }
+}
+
/* TODO: as we keep adding features, this method is becoming more and more
* similar to its GLSL counterpart at linker.cpp. Eventually it would be good
* to check if they could be refactored, and reduce code duplication somehow
@@ -517,11 +547,8 @@ nir_build_program_resource_list(const struct gl_constants *consts,
bool rebuild_resourse_list)
{
/* Rebuild resource list. */
- if (prog->data->ProgramResourceList && rebuild_resourse_list) {
- ralloc_free(prog->data->ProgramResourceList);
- prog->data->ProgramResourceList = NULL;
- prog->data->NumProgramResourceList = 0;
- }
+ if (rebuild_resourse_list)
+ init_program_resource_list(prog);
int input_stage = MESA_SHADER_STAGES, output_stage = 0;
diff --git a/src/compiler/glsl/gl_nir_linker.h b/src/compiler/glsl/gl_nir_linker.h
index f45b6f7bb0a..ddd9f26ba9a 100644
--- a/src/compiler/glsl/gl_nir_linker.h
+++ b/src/compiler/glsl/gl_nir_linker.h
@@ -24,6 +24,8 @@
#ifndef GL_NIR_LINKER_H
#define GL_NIR_LINKER_H
+#include "main/glheader.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -59,6 +61,15 @@ bool gl_nir_link_uniforms(const struct gl_constants *consts,
void gl_nir_set_uniform_initializers(const struct gl_constants *consts,
struct gl_shader_program *prog);
+bool nir_add_packed_var_to_resource_list(const struct gl_constants *consts,
+ struct gl_shader_program *shProg,
+ struct set *resource_set,
+ nir_variable *var,
+ unsigned stage, GLenum type);
+
+void
+init_program_resource_list(struct gl_shader_program *prog);
+
void nir_build_program_resource_list(const struct gl_constants *consts,
struct gl_shader_program *prog,
bool rebuild_resourse_list);
More information about the mesa-commit
mailing list