diff options
author | Jason Ekstrand <[email protected]> | 2018-11-15 10:25:46 -0600 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-11-19 09:57:41 -0600 |
commit | 060817b2fa50bd71dc6a9ece605238ba11fc67e9 (patch) | |
tree | 1b59504420384fa2ebf84ab6c76898db4ef79ca9 /src/compiler | |
parent | 486091bc00ea06f996910885bad080ce7f591c59 (diff) |
intel,nir: Move gl_LocalInvocationID lowering to nir_lower_system_values
It's not at all intel-specific; the formula is dictated by OpenGL and
Vulkan. The only intel-specific thing is that we need the lowering. As
a nice side-effect, the new version is variable-group-size ready.
Reviewed-by: Plamena Manolova <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir.h | 1 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_system_values.c | 49 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index b0cff50eaf2..1dd605010f6 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2178,6 +2178,7 @@ typedef struct nir_shader_compiler_options { bool lower_helper_invocation; bool lower_cs_local_index_from_id; + bool lower_cs_local_id_from_index; bool lower_device_index_to_zero; diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index fbc40573579..08a9e8be44a 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -51,6 +51,45 @@ build_local_group_size(nir_builder *b) return local_size; } +static nir_ssa_def * +build_local_invocation_id(nir_builder *b) +{ + if (b->shader->options->lower_cs_local_id_from_index) { + /* We lower gl_LocalInvocationID from gl_LocalInvocationIndex based + * on this formula: + * + * gl_LocalInvocationID.x = + * gl_LocalInvocationIndex % gl_WorkGroupSize.x; + * gl_LocalInvocationID.y = + * (gl_LocalInvocationIndex / gl_WorkGroupSize.x) % + * gl_WorkGroupSize.y; + * gl_LocalInvocationID.z = + * (gl_LocalInvocationIndex / + * (gl_WorkGroupSize.x * gl_WorkGroupSize.y)) % + * gl_WorkGroupSize.z; + * + * However, the final % gl_WorkGroupSize.z does nothing unless we + * accidentally end up with a gl_LocalInvocationIndex that is too + * large so it can safely be omitted. + */ + nir_ssa_def *local_index = nir_load_local_invocation_index(b); + nir_ssa_def *local_size = build_local_group_size(b); + + nir_ssa_def *id_x, *id_y, *id_z; + id_x = nir_umod(b, local_index, + nir_channel(b, local_size, 0)); + id_y = nir_umod(b, nir_udiv(b, local_index, + nir_channel(b, local_size, 0)), + nir_channel(b, local_size, 1)); + id_z = nir_udiv(b, local_index, + nir_imul(b, nir_channel(b, local_size, 0), + nir_channel(b, local_size, 1))); + return nir_vec3(b, id_x, id_y, id_z); + } else { + return nir_load_local_invocation_id(b); + } +} + static bool convert_block(nir_block *block, nir_builder *b) { @@ -91,7 +130,7 @@ convert_block(nir_block *block, nir_builder *b) */ nir_ssa_def *group_size = build_local_group_size(b); nir_ssa_def *group_id = nir_load_work_group_id(b); - nir_ssa_def *local_id = nir_load_local_invocation_id(b); + nir_ssa_def *local_id = build_local_invocation_id(b); sysval = nir_iadd(b, nir_imul(b, group_id, group_size), local_id); break; @@ -126,6 +165,14 @@ convert_block(nir_block *block, nir_builder *b) break; } + case SYSTEM_VALUE_LOCAL_INVOCATION_ID: + /* If lower_cs_local_id_from_index is true, then we derive the local + * index from the local id. + */ + if (b->shader->options->lower_cs_local_id_from_index) + sysval = build_local_invocation_id(b); + break; + case SYSTEM_VALUE_LOCAL_GROUP_SIZE: { sysval = build_local_group_size(b); break; |