[Mesa-dev] [PATCH] radv: properly load unused gl_LocalInvocationID/gl_WorkGroupID components

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Dec 18 21:06:38 UTC 2017


F1 2017 looks good now.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/common/ac_nir_to_llvm.c | 21 ++++++++++++++++++---
 src/amd/vulkan/radv_shader.c    |  7 +++++--
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index f18edf40a6..d11d328a5a 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -94,7 +94,7 @@ struct nir_to_llvm_context {
 	LLVMValueRef push_constants;
 	LLVMValueRef view_index;
 	LLVMValueRef num_work_groups;
-	LLVMValueRef workgroup_ids;
+	LLVMValueRef workgroup_ids[3];
 	LLVMValueRef local_invocation_ids;
 	LLVMValueRef tg_size;
 
@@ -747,7 +747,15 @@ static void create_function(struct nir_to_llvm_context *ctx,
 			add_user_sgpr_argument(&args, ctx->ac.v3i32,
 					       &ctx->num_work_groups);
 		}
-		add_sgpr_argument(&args, ctx->ac.v3i32, &ctx->workgroup_ids);
+
+		for (int i = 0; i < 3; i++) {
+			ctx->workgroup_ids[i] = NULL;
+			if (ctx->shader_info->info.cs.uses_block_id[i]) {
+				add_sgpr_argument(&args, ctx->ac.i32,
+						  &ctx->workgroup_ids[i]);
+			}
+		}
+
 		if (ctx->shader_info->info.cs.uses_local_invocation_idx)
 			add_sgpr_argument(&args, ctx->ac.i32, &ctx->tg_size);
 		add_vgpr_argument(&args, ctx->ac.v3i32, &ctx->local_invocation_ids);
@@ -4046,7 +4054,14 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
 
 	switch (instr->intrinsic) {
 	case nir_intrinsic_load_work_group_id: {
-		result = ctx->nctx->workgroup_ids;
+		LLVMValueRef values[3];
+
+		for (int i = 0; i < 3; i++) {
+			values[i] = ctx->nctx->workgroup_ids[i] ?
+				    ctx->nctx->workgroup_ids[i] : ctx->ac.i32_0;
+		}
+
+		result = ac_build_gather_values(&ctx->ac, values, 3);
 		break;
 	}
 	case nir_intrinsic_load_base_vertex: {
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index f96b0c07f1..ab8ba42511 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -395,8 +395,11 @@ radv_fill_shader_variant(struct radv_device *device,
 	case MESA_SHADER_COMPUTE: {
 		struct ac_shader_info *info = &variant->info.info;
 		variant->rsrc2 |=
-			S_00B84C_TGID_X_EN(1) | S_00B84C_TGID_Y_EN(1) |
-			S_00B84C_TGID_Z_EN(1) | S_00B84C_TIDIG_COMP_CNT(2) |
+			S_00B84C_TGID_X_EN(info->cs.uses_block_id[0]) |
+			S_00B84C_TGID_Y_EN(info->cs.uses_block_id[1]) |
+			S_00B84C_TGID_Z_EN(info->cs.uses_block_id[2]) |
+			S_00B84C_TIDIG_COMP_CNT(info->cs.uses_thread_id[2] ? 2 :
+						info->cs.uses_thread_id[1] ? 1 : 0) |
 			S_00B84C_TG_SIZE_EN(info->cs.uses_local_invocation_idx) |
 			S_00B84C_LDS_SIZE(variant->config.lds_size);
 		break;
-- 
2.15.1



More information about the mesa-dev mailing list