[Mesa-dev] [PATCH 10/10] radv/ac: enable EXT_shader_subgroup_ballot and EXT_shader_subgroup_vote

Connor Abbott connora at valvesoftware.com
Tue Aug 1 02:24:17 UTC 2017


From: Connor Abbott <cwabbott0 at gmail.com>

---
 src/amd/common/ac_nir_to_llvm.c | 49 +++++++++++++++++++++++++++++++++++++++++
 src/amd/vulkan/radv_device.c    |  8 +++++++
 src/amd/vulkan/radv_pipeline.c  |  2 ++
 3 files changed, 59 insertions(+)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index f756b9a..3dd1cbb 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -4142,6 +4142,55 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
 	case nir_intrinsic_load_patch_vertices_in:
 		result = LLVMConstInt(ctx->ac.i32, ctx->nctx->options->key.tcs.input_vertices, false);
 		break;
+	case nir_intrinsic_ballot:
+		result = ac_build_ballot(&ctx->ac, get_src(ctx, instr->src[0]));
+		break;
+	case nir_intrinsic_read_first_invocation: {
+		LLVMValueRef src0 = get_src(ctx, instr->src[0]);
+		ac_build_optimization_barrier(&ctx->ac, &src0);
+	        LLVMValueRef srcs[1] = { src0 };
+		result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.readfirstlane",
+					    ctx->ac.i32, srcs, 1,
+					    AC_FUNC_ATTR_NOUNWIND |
+					    AC_FUNC_ATTR_READNONE |
+					    AC_FUNC_ATTR_CONVERGENT);
+		break;
+        }
+	case nir_intrinsic_read_invocation: {
+		LLVMValueRef src0 = get_src(ctx, instr->src[0]);
+		ac_build_optimization_barrier(&ctx->ac, &src0);
+	        LLVMValueRef srcs[2] = { src0, get_src(ctx, instr->src[1]) };
+		result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.readlane",
+					    ctx->ac.i32, srcs, 2,
+					    AC_FUNC_ATTR_NOUNWIND |
+					    AC_FUNC_ATTR_READNONE |
+					    AC_FUNC_ATTR_CONVERGENT);
+		break;
+        }
+	case nir_intrinsic_load_subgroup_invocation:
+		result = ac_get_thread_id(&ctx->ac);
+		break;
+	case nir_intrinsic_load_subgroup_size:
+		result = LLVMConstInt(ctx->ac.i32, 64, 0);
+		break;
+	case nir_intrinsic_vote_all:
+		result = LLVMBuildSExt(ctx->ac.builder,
+				       ac_build_vote_all(&ctx->ac,
+							 get_src(ctx, instr->src[0])),
+				       ctx->ac.i32, "");
+		break;
+	case nir_intrinsic_vote_any:
+		result = LLVMBuildSExt(ctx->ac.builder,
+				       ac_build_vote_any(&ctx->ac,
+							 get_src(ctx, instr->src[0])),
+				       ctx->ac.i32, "");
+		break;
+	case nir_intrinsic_vote_eq:
+		result = LLVMBuildSExt(ctx->ac.builder,
+				       ac_build_vote_eq(&ctx->ac,
+							 get_src(ctx, instr->src[0])),
+				       ctx->ac.i32, "");
+		break;
 	default:
 		fprintf(stderr, "Unknown intrinsic: ");
 		nir_print_instr(&instr->instr, stderr);
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index eb25872..e8fe086 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -165,6 +165,14 @@ static const VkExtensionProperties common_device_extensions[] = {
 		.extensionName = VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME,
 		.specVersion = 1,
 	},
+	{
+		.extensionName = VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
+		.specVersion = 1,
+	},
+	{
+		.extensionName = VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
+		.specVersion = 1,
+	},
 };
 static const VkExtensionProperties ext_sema_device_extensions[] = {
 	{
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 2fc64e8..c354807 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -234,6 +234,8 @@ radv_shader_compile_to_nir(struct radv_device *device,
 			.tessellation = true,
 			.int64 = true,
 			.variable_pointers = true,
+			.shader_ballot = true,
+			.shader_group_vote = true,
 		};
 		entry_point = spirv_to_nir(spirv, module->size / 4,
 					   spec_entries, num_spec_entries,
-- 
2.9.4



More information about the mesa-dev mailing list