[Mesa-dev] [PATCH 05/11] ac/nir: Make shader key a struct.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Wed Aug 23 20:51:47 UTC 2017


Some bits can be passed to almost every shader, and I don't like
adding 5 variables.
---
 src/amd/common/ac_nir_to_llvm.h      | 14 ++++++++------
 src/amd/vulkan/radv_pipeline.c       | 26 +++++++++++++-------------
 src/amd/vulkan/radv_pipeline_cache.c |  2 +-
 src/amd/vulkan/radv_private.h        |  4 ++--
 4 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.h b/src/amd/common/ac_nir_to_llvm.h
index 376db1387a4..2a9ea8a2b3f 100644
--- a/src/amd/common/ac_nir_to_llvm.h
+++ b/src/amd/common/ac_nir_to_llvm.h
@@ -62,16 +62,18 @@ struct ac_fs_variant_key {
 	uint32_t is_int10;
 };
 
-union ac_shader_variant_key {
-	struct ac_vs_variant_key vs;
-	struct ac_fs_variant_key fs;
-	struct ac_tes_variant_key tes;
-	struct ac_tcs_variant_key tcs;
+struct ac_shader_variant_key {
+	union {
+		struct ac_vs_variant_key vs;
+		struct ac_fs_variant_key fs;
+		struct ac_tes_variant_key tes;
+		struct ac_tcs_variant_key tcs;
+	};
 };
 
 struct ac_nir_compiler_options {
 	struct radv_pipeline_layout *layout;
-	union ac_shader_variant_key key;
+	struct ac_shader_variant_key key;
 	bool unsafe_math;
 	bool supports_spill;
 	enum radeon_family family;
diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 5d94acc1519..96917814e56 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -441,7 +441,7 @@ static void radv_fill_shader_variant(struct radv_device *device,
 static struct radv_shader_variant *radv_shader_variant_create(struct radv_device *device,
 							      struct nir_shader *shader,
 							      struct radv_pipeline_layout *layout,
-							      const union ac_shader_variant_key *key,
+							      const struct ac_shader_variant_key *key,
 							      void** code_out,
 							      unsigned *code_size_out,
 							      bool dump)
@@ -538,7 +538,7 @@ radv_pipeline_compile(struct radv_pipeline *pipeline,
 		      gl_shader_stage stage,
 		      const VkSpecializationInfo *spec_info,
 		      struct radv_pipeline_layout *layout,
-		      const union ac_shader_variant_key *key)
+		      const struct ac_shader_variant_key *key)
 {
 	unsigned char sha1[20];
 	unsigned char gs_copy_sha1[20];
@@ -613,10 +613,10 @@ radv_pipeline_compile(struct radv_pipeline *pipeline,
 	return variant;
 }
 
-static union ac_shader_variant_key
+static struct ac_shader_variant_key
 radv_compute_tes_key(bool as_es, bool export_prim_id)
 {
-	union ac_shader_variant_key key;
+	struct ac_shader_variant_key key;
 	memset(&key, 0, sizeof(key));
 	key.tes.as_es = as_es;
 	/* export prim id only happens when no geom shader */
@@ -625,10 +625,10 @@ radv_compute_tes_key(bool as_es, bool export_prim_id)
 	return key;
 }
 
-static union ac_shader_variant_key
+static struct ac_shader_variant_key
 radv_compute_tcs_key(unsigned primitive_mode, unsigned input_vertices)
 {
-	union ac_shader_variant_key key;
+	struct ac_shader_variant_key key;
 	memset(&key, 0, sizeof(key));
 	key.tcs.primitive_mode = primitive_mode;
 	key.tcs.input_vertices = input_vertices;
@@ -652,8 +652,8 @@ radv_tess_pipeline_compile(struct radv_pipeline *pipeline,
 	nir_shader *tes_nir, *tcs_nir;
 	void *tes_code = NULL, *tcs_code = NULL;
 	unsigned tes_code_size = 0, tcs_code_size = 0;
-	union ac_shader_variant_key tes_key;
-	union ac_shader_variant_key tcs_key;
+	struct ac_shader_variant_key tes_key;
+	struct ac_shader_variant_key tcs_key;
 	bool dump = (pipeline->device->debug_flags & RADV_DEBUG_DUMP_SHADERS);
 
 	tes_key = radv_compute_tes_key(radv_pipeline_has_gs(pipeline),
@@ -1656,10 +1656,10 @@ radv_pipeline_init_dynamic_state(struct radv_pipeline *pipeline,
 	pipeline->dynamic_state_mask = states;
 }
 
-static union ac_shader_variant_key
+static struct ac_shader_variant_key
 radv_compute_vs_key(const VkGraphicsPipelineCreateInfo *pCreateInfo, bool as_es, bool as_ls, bool export_prim_id)
 {
-	union ac_shader_variant_key key;
+	struct ac_shader_variant_key key;
 	const VkPipelineVertexInputStateCreateInfo *input_state =
 	                                         pCreateInfo->pVertexInputState;
 
@@ -2068,7 +2068,7 @@ radv_pipeline_init(struct radv_pipeline *pipeline,
 	}
 
 	if (modules[MESA_SHADER_FRAGMENT]) {
-		union ac_shader_variant_key key = {0};
+		struct ac_shader_variant_key key = {0};
 		key.fs.col_format = pipeline->graphics.blend.spi_shader_col_format;
 
 		if (pipeline->device->physical_device->rad_info.chip_class < VI)
@@ -2098,7 +2098,7 @@ radv_pipeline_init(struct radv_pipeline *pipeline,
 			as_es = true;
 		else if (pipeline->shaders[MESA_SHADER_FRAGMENT]->info.fs.prim_id_input)
 			export_prim_id = true;
-		union ac_shader_variant_key key = radv_compute_vs_key(pCreateInfo, as_es, as_ls, export_prim_id);
+		struct ac_shader_variant_key key = radv_compute_vs_key(pCreateInfo, as_es, as_ls, export_prim_id);
 
 		pipeline->shaders[MESA_SHADER_VERTEX] =
 			 radv_pipeline_compile(pipeline, cache, modules[MESA_SHADER_VERTEX],
@@ -2111,7 +2111,7 @@ radv_pipeline_init(struct radv_pipeline *pipeline,
 	}
 
 	if (modules[MESA_SHADER_GEOMETRY]) {
-		union ac_shader_variant_key key = radv_compute_vs_key(pCreateInfo, false, false, false);
+		struct ac_shader_variant_key key = radv_compute_vs_key(pCreateInfo, false, false, false);
 
 		pipeline->shaders[MESA_SHADER_GEOMETRY] =
 			 radv_pipeline_compile(pipeline, cache, modules[MESA_SHADER_GEOMETRY],
diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index 3995434d903..99a614dc104 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -89,7 +89,7 @@ radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
 		 const char *entrypoint,
 		 const VkSpecializationInfo *spec_info,
 		 const struct radv_pipeline_layout *layout,
-		 const union ac_shader_variant_key *key,
+		 const struct ac_shader_variant_key *key,
 		 uint32_t is_geom_copy_shader)
 {
 	struct mesa_sha1 ctx;
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index ca985da16d5..05db2f0f82f 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -956,14 +956,14 @@ struct radv_shader_module {
 	char                                         data[0];
 };
 
-union ac_shader_variant_key;
+struct ac_shader_variant_key;
 
 void
 radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
 		 const char *entrypoint,
 		 const VkSpecializationInfo *spec_info,
 		 const struct radv_pipeline_layout *layout,
-		 const union ac_shader_variant_key *key,
+		 const struct ac_shader_variant_key *key,
 		 uint32_t is_geom_copy_shader);
 
 static inline gl_shader_stage
-- 
2.14.1



More information about the mesa-dev mailing list