[Mesa-dev] [PATCH 02/11] glsl: Add glsl LowerCsDerivedVariables option
Jordan Justen
jordan.l.justen at intel.com
Tue May 24 08:37:47 UTC 2016
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
src/compiler/glsl/builtin_variables.cpp | 13 +++++++++++--
src/compiler/glsl/glsl_parser_extras.cpp | 8 ++++----
src/mesa/drivers/dri/i965/brw_compiler.c | 2 ++
src/mesa/main/mtypes.h | 4 ++++
src/mesa/state_tracker/st_extensions.c | 4 +++-
5 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp
index ff8a7e2..5b1667e 100644
--- a/src/compiler/glsl/builtin_variables.cpp
+++ b/src/compiler/glsl/builtin_variables.cpp
@@ -409,6 +409,7 @@ private:
exec_list * const instructions;
struct _mesa_glsl_parse_state * const state;
glsl_symbol_table * const symtab;
+ struct gl_shader_compiler_options *options;
/**
* True if compatibility-profile-only variables should be included. (In
@@ -436,6 +437,7 @@ private:
builtin_variable_generator::builtin_variable_generator(
exec_list *instructions, struct _mesa_glsl_parse_state *state)
: instructions(instructions), state(state), symtab(state->symbols),
+ options(&state->ctx->Const.ShaderCompilerOptions[state->stage]),
compatibility(!state->is_version(140, 100)),
bool_t(glsl_type::bool_type), int_t(glsl_type::int_type),
uint_t(glsl_type::uint_type),
@@ -1199,8 +1201,15 @@ builtin_variable_generator::generate_cs_special_vars()
"gl_LocalInvocationID");
add_system_value(SYSTEM_VALUE_WORK_GROUP_ID, uvec3_t, "gl_WorkGroupID");
add_system_value(SYSTEM_VALUE_NUM_WORK_GROUPS, uvec3_t, "gl_NumWorkGroups");
- add_variable("gl_GlobalInvocationID", uvec3_t, ir_var_auto, 0);
- add_variable("gl_LocalInvocationIndex", uint_t, ir_var_auto, 0);
+ if (options->LowerCsDerivedVariables) {
+ add_variable("gl_GlobalInvocationID", uvec3_t, ir_var_auto, 0);
+ add_variable("gl_LocalInvocationIndex", uint_t, ir_var_auto, 0);
+ } else {
+ add_system_value(SYSTEM_VALUE_GLOBAL_INVOCATION_ID,
+ uvec3_t, "gl_GlobalInvocationID");
+ add_system_value(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX,
+ uint_t, "gl_LocalInvocationIndex");
+ }
}
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 1d0110b..defbf95 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1783,6 +1783,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
struct _mesa_glsl_parse_state *state =
new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader);
const char *source = shader->Source;
+ struct gl_shader_compiler_options *options =
+ &ctx->Const.ShaderCompilerOptions[shader->Stage];
if (ctx->Const.GenerateTemporaryNames)
(void) p_atomic_cmpxchg(&ir_variable::temporaries_allocate_names,
@@ -1820,9 +1822,6 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
if (!state->error && !shader->ir->is_empty()) {
- struct gl_shader_compiler_options *options =
- &ctx->Const.ShaderCompilerOptions[shader->Stage];
-
assign_subroutine_indexes(shader, state);
lower_subroutine(shader->ir, state);
/* Do some optimization at compile time to reduce shader IR size
@@ -1898,7 +1897,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
}
}
- _mesa_glsl_initialize_derived_variables(shader);
+ if (options->LowerCsDerivedVariables)
+ _mesa_glsl_initialize_derived_variables(shader);
delete state->symbols;
ralloc_free(state);
diff --git a/src/mesa/drivers/dri/i965/brw_compiler.c b/src/mesa/drivers/dri/i965/brw_compiler.c
index 82131db..c3a192d 100644
--- a/src/mesa/drivers/dri/i965/brw_compiler.c
+++ b/src/mesa/drivers/dri/i965/brw_compiler.c
@@ -199,6 +199,8 @@ brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo)
compiler->glsl_compiler_options[MESA_SHADER_COMPUTE]
.LowerShaderSharedVariables = true;
+ compiler->glsl_compiler_options[MESA_SHADER_COMPUTE]
+ .LowerCsDerivedVariables = true;
return compiler;
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 6cd30e8..d922b5d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2954,6 +2954,10 @@ struct gl_shader_compiler_options
GLboolean LowerShaderSharedVariables; /**< Lower compute shader shared
* variable access to intrinsics. */
+ GLboolean LowerCsDerivedVariables; /**< Lower gl_GlobalInvocationID and
+ * gl_LocalInvocationIndex based on
+ * other builtin variables. */
+
const struct nir_shader_compiler_options *NirOptions;
};
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 1d5175b..6ad53e9 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -309,8 +309,10 @@ void st_init_limits(struct pipe_screen *screen,
options->LowerCombinedClipCullDistance = true;
options->LowerBufferInterfaceBlocks = true;
- if (sh == PIPE_SHADER_COMPUTE)
+ if (sh == PIPE_SHADER_COMPUTE) {
options->LowerShaderSharedVariables = true;
+ options->LowerCsDerivedVariables = true;
+ }
}
c->LowerTessLevel = true;
--
2.8.1
More information about the mesa-dev
mailing list