diff options
author | Jordan Justen <jordan.l.justen@intel.com> | 2015-08-08 10:00:33 -0700 |
---|---|---|
committer | Jordan Justen <jordan.l.justen@intel.com> | 2015-08-08 10:00:33 -0700 |
commit | 7c75ec3180d1d94b242127d728003dac0049a7af (patch) | |
tree | f997d1eca8523de90f7bdc7eaa344090180f6a1e | |
parent | 9065d126a966f4bf66dbba97d45d42b5a5da8f71 (diff) |
global id hacksglobal-id-temp
-rw-r--r-- | src/glsl/ast_to_hir.cpp | 42 | ||||
-rw-r--r-- | src/glsl/builtin_functions.cpp | 7 | ||||
-rw-r--r-- | src/glsl/builtin_variables.cpp | 13 | ||||
-rw-r--r-- | src/glsl/glsl_parser_extras.cpp | 4 | ||||
-rw-r--r-- | src/glsl/linker.cpp | 2 | ||||
-rw-r--r-- | src/glsl/lower_cs_global_id.cpp | 47 | ||||
-rw-r--r-- | src/glsl/opt_dead_builtin_variables.cpp | 9 |
7 files changed, 119 insertions, 5 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 68f71c6393..8cacf4838c 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -6546,6 +6546,48 @@ ast_cs_input_layout::hir(exec_list *instructions, new(var) ir_constant(glsl_type::uvec3_type, &data); var->data.has_initializer = true; +#if 0 + ir_variable *gl_WorkGroupID = + state->symbols->get_variable("gl_WorkGroupID"); + ir_variable *gl_WorkGroupSize = var; + ir_variable *gl_LocalInvocationID = + state->symbols->get_variable("gl_LocalInvocationID"); + ir_variable *gl_GlobalInvocationID = + new(state->symbols) ir_variable(glsl_type::uvec3_type, + "gl_GlobalInvocationID", + ir_var_auto); + gl_GlobalInvocationID->data.how_declared = ir_var_declared_implicitly; + gl_GlobalInvocationID->data.read_only = true; + instructions->push_tail(gl_GlobalInvocationID); + state->symbols->add_variable(gl_GlobalInvocationID); + gl_WorkGroupID->data.used = true; + gl_WorkGroupSize->data.used = true; + gl_LocalInvocationID->data.used = true; + ir_instruction *const inst = + ir_builder::assign(gl_GlobalInvocationID, + ir_builder::add(ir_builder::mul(gl_WorkGroupID, + gl_WorkGroupSize), + gl_LocalInvocationID)); + instructions->push_tail(inst); +#else + ir_variable *gl_GlobalInvocationID = + new(state->symbols) ir_variable(glsl_type::uvec3_type, + "gl_GlobalInvocationID", + ir_var_auto); + gl_GlobalInvocationID->data.how_declared = ir_var_declared_implicitly; + gl_GlobalInvocationID->data.read_only = true; + instructions->push_tail(gl_GlobalInvocationID); + state->symbols->add_variable(gl_GlobalInvocationID); +#if 0 + memset(&data, 0, sizeof(data)); + gl_GlobalInvocationID->constant_value = + new(gl_GlobalInvocationID) ir_constant(glsl_type::uvec3_type, &data); + gl_GlobalInvocationID->constant_initializer = + new(gl_GlobalInvocationID) ir_constant(glsl_type::uvec3_type, &data); + gl_GlobalInvocationID->data.has_initializer = true; +#endif +#endif + return NULL; } diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp index 2175c66cbd..7631698dc1 100644 --- a/src/glsl/builtin_functions.cpp +++ b/src/glsl/builtin_functions.cpp @@ -459,6 +459,7 @@ private: void create_shader(); void create_intrinsics(); void create_builtins(); + void create_builtin_globals(); /** * IR builder helpers: @@ -782,6 +783,7 @@ builtin_builder::initialize() create_shader(); create_intrinsics(); create_builtins(); + create_builtin_globals(); } void @@ -2524,6 +2526,11 @@ builtin_builder::create_builtins() } void +builtin_builder::create_builtin_globals() +{ +} + +void builtin_builder::add_function(const char *name, ...) { va_list ap; diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp index 5154b2f55f..0475243407 100644 --- a/src/glsl/builtin_variables.cpp +++ b/src/glsl/builtin_variables.cpp @@ -1049,8 +1049,17 @@ builtin_variable_generator::generate_cs_special_vars() "gl_LocalInvocationID"); add_system_value(SYSTEM_VALUE_WORK_GROUP_ID, glsl_type::uvec3_type, "gl_WorkGroupID"); - add_system_value(SYSTEM_VALUE_GLOBAL_INVOCATION_ID, glsl_type::uvec3_type, - "gl_GlobalInvocationID"); +#if 0 + ir_variable *global_id = + add_system_value(SYSTEM_VALUE_GLOBAL_INVOCATION_ID, glsl_type::uvec3_type, + "gl_GlobalInvocationID"); + ir_assign *assign_global_id = + new(mem_ctx) ir_assignment(ir_binop_mul, + glsl_type::vec4_type, + var_ref(gl_ModelViewProjectionMatrix), + var_ref(gl_Vertex))) + instructions->push_tail(var); +#endif /* TODO: finish this. */ } diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 49fc12dce0..3e5dfc5e9a 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -1649,7 +1649,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, lower_subroutine(shader->ir, state); - set_cs_variable_deps_as_used(shader, state); + //set_cs_variable_deps_as_used(shader, state); /* Do some optimization at compile time to reduce shader IR size * and reduce later work if the same shader is linked multiple times @@ -1724,6 +1724,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, } } + lower_cs_global_id(shader); + delete state->symbols; ralloc_free(state); } diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index f628198db9..168dc2db34 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -2153,7 +2153,7 @@ link_intrastage_shaders(void *mem_ctx, } } - lower_cs_global_id(linked); + //lower_cs_global_id(linked); /* Make a pass over all variable declarations to ensure that arrays with * unspecified sizes have a size specified. The size is inferred from the diff --git a/src/glsl/lower_cs_global_id.cpp b/src/glsl/lower_cs_global_id.cpp index 606b43c6ff..7f57dc94ec 100644 --- a/src/glsl/lower_cs_global_id.cpp +++ b/src/glsl/lower_cs_global_id.cpp @@ -105,17 +105,19 @@ lower_cs_global_id_visitor::visit(ir_dereference_variable *ir) ir_list->push_head(GlobalInvocationID); if (gl_WorkGroupID == NULL) { + printf("%d\n", __LINE__); gl_WorkGroupID = new(mem_ctx) ir_variable(uvec3_t, "gl_WorkGroupID", ir_var_system_value); gl_WorkGroupID->data.how_declared = ir_var_declared_implicitly; gl_WorkGroupID->data.read_only = true; - gl_WorkGroupID->data.location = SYSTEM_VALUE_GLOBAL_INVOCATION_ID; + gl_WorkGroupID->data.location = SYSTEM_VALUE_WORK_GROUP_ID; gl_WorkGroupID->data.explicit_location = true; gl_WorkGroupID->data.explicit_index = 0; ir_list->push_head(gl_WorkGroupID); } if (gl_WorkGroupSize == NULL) { + printf("%d\n", __LINE__); gl_WorkGroupSize = new(mem_ctx) ir_variable(uvec3_t, "gl_WorkGroupSize", ir_var_auto); gl_WorkGroupSize->data.how_declared = ir_var_declared_implicitly; @@ -124,6 +126,7 @@ lower_cs_global_id_visitor::visit(ir_dereference_variable *ir) } if (gl_LocalInvocationID == NULL) { + printf("%d\n", __LINE__); gl_LocalInvocationID = new(mem_ctx) ir_variable(uvec3_t, "gl_LocalInvocationID", ir_var_system_value); @@ -139,6 +142,9 @@ lower_cs_global_id_visitor::visit(ir_dereference_variable *ir) * gl_GlobalInvocationID = * gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID */ + gl_WorkGroupID->data.used = true; + gl_WorkGroupSize->data.used = true; + gl_LocalInvocationID->data.used = true; ir_instruction *const inst = ir_builder::assign(GlobalInvocationID, ir_builder::add(ir_builder::mul(gl_WorkGroupID, @@ -154,6 +160,7 @@ lower_cs_global_id_visitor::visit(ir_dereference_variable *ir) return visit_continue; } +#if 0 bool lower_cs_global_id(gl_shader *shader) { @@ -175,3 +182,41 @@ lower_cs_global_id(gl_shader *shader) return v.progress; } +#else +bool +lower_cs_global_id(gl_shader *shader) +{ + /* gl_GlobalInvocationID only exists in the compute shader. + */ + if (shader->Stage != MESA_SHADER_COMPUTE) + return false; + + ir_function_signature *const main_sig = + link_get_main_function_signature(shader); + if (main_sig == NULL) { + return false; + } + + ir_variable *gl_GlobalInvocationID = + shader->symbols->get_variable("gl_GlobalInvocationID"); + if (gl_GlobalInvocationID == NULL) { + return false; + } + + ir_variable *gl_WorkGroupID = + shader->symbols->get_variable("gl_WorkGroupID"); + ir_variable *gl_WorkGroupSize = + shader->symbols->get_variable("gl_WorkGroupSize"); + ir_variable *gl_LocalInvocationID = + shader->symbols->get_variable("gl_LocalInvocationID"); + + ir_instruction *const inst = + ir_builder::assign(gl_GlobalInvocationID, + ir_builder::add(ir_builder::mul(gl_WorkGroupID, + gl_WorkGroupSize), + gl_LocalInvocationID)); + main_sig->body.push_head(inst); + + return true; +} +#endif diff --git a/src/glsl/opt_dead_builtin_variables.cpp b/src/glsl/opt_dead_builtin_variables.cpp index 0d4e3a8f00..1fafa59f62 100644 --- a/src/glsl/opt_dead_builtin_variables.cpp +++ b/src/glsl/opt_dead_builtin_variables.cpp @@ -62,6 +62,12 @@ optimize_dead_builtin_variables(exec_list *instructions, * information, so removing these variables from the user shader will * cause problems later. * + * For compute shaders, gl_GlobalInvocationID has some dependencies, so + * we avoid removing these dependencies: + * + * gl_GlobalInvocationID = + * gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID + * * Matrix uniforms with "Transpose" are not eliminated because there's * an optimization pass that can turn references to the regular matrix * into references to the transpose matrix. Eliminating the transpose @@ -73,6 +79,9 @@ optimize_dead_builtin_variables(exec_list *instructions, */ if (strcmp(var->name, "gl_ModelViewProjectionMatrix") == 0 || strcmp(var->name, "gl_Vertex") == 0 + || strcmp(var->name, "gl_WorkGroupID") == 0 + || strcmp(var->name, "gl_WorkGroupSize") == 0 + || strcmp(var->name, "gl_LocalInvocationID") == 0 || strstr(var->name, "Transpose") != NULL) continue; |