summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Justen <jordan.l.justen@intel.com>2015-08-17 16:32:42 -0700
committerJordan Justen <jordan.l.justen@intel.com>2015-08-23 01:43:15 -0700
commit331a47bbf0b30247bcd5d2cb69d8c3b1e886b362 (patch)
tree41eb0c7bbe50475e0647a104bf55a8a0525a4b25
parent7a3921e3ad81a83a915137045892b8957e33f917 (diff)
glsl/cs: Initialize gl_LocalInvocationIndex in main()cs-local-index-v1
We initialize gl_LocalInvocationIndex based on the extension spec formula: gl_LocalInvocationIndex = gl_LocalInvocationID.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y + gl_LocalInvocationID.y * gl_WorkGroupSize.x + gl_LocalInvocationID.x; https://www.opengl.org/registry/specs/ARB/compute_shader.txt Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
-rw-r--r--src/glsl/builtin_variables.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index 8f8be9067d..082c73acbd 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -1059,6 +1059,7 @@ builtin_variable_generator::generate_cs_special_vars()
add_system_value(SYSTEM_VALUE_WORK_GROUP_ID, glsl_type::uvec3_type,
"gl_WorkGroupID");
add_variable("gl_GlobalInvocationID", glsl_type::uvec3_type, ir_var_auto, 0);
+ add_variable("gl_LocalInvocationIndex", glsl_type::uint_type, ir_var_auto, 0);
/* TODO: finish this. */
}
@@ -1217,6 +1218,11 @@ _mesa_glsl_initialize_variables(exec_list *instructions,
}
+using ir_builder::swizzle_x;
+using ir_builder::swizzle_y;
+using ir_builder::swizzle_z;
+
+
/**
* Initialize compute shader variables with values that are derived from other
* compute shader variable.
@@ -1249,6 +1255,28 @@ initialize_cs_derived_variables(gl_shader *shader,
gl_WorkGroupSize),
gl_LocalInvocationID));
main_sig->body.push_head(inst);
+
+ /* gl_LocalInvocationIndex =
+ * gl_LocalInvocationID.z * gl_WorkGroupSize.x * gl_WorkGroupSize.y +
+ * gl_LocalInvocationID.y * gl_WorkGroupSize.x +
+ * gl_LocalInvocationID.x;
+ */
+ ir_expression *index_z =
+ ir_builder::mul(ir_builder::mul(swizzle_z(gl_LocalInvocationID),
+ swizzle_x(gl_WorkGroupSize)),
+ swizzle_y(gl_WorkGroupSize));
+ ir_expression *index_y =
+ ir_builder::mul(swizzle_y(gl_LocalInvocationID),
+ swizzle_x(gl_WorkGroupSize));
+ ir_expression *index_y_plus_z = ir_builder::add(index_y, index_z);
+ ir_builder::operand index_x(swizzle_x(gl_LocalInvocationID));
+ ir_expression *index_x_plus_y_plus_z =
+ ir_builder::add(index_y_plus_z, index_x);
+ ir_variable *gl_LocalInvocationIndex =
+ shader->symbols->get_variable("gl_LocalInvocationIndex");
+ assert(gl_LocalInvocationIndex);
+ inst = ir_builder::assign(gl_LocalInvocationIndex, index_x_plus_y_plus_z);
+ main_sig->body.push_head(inst);
}