diff --git a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c index d98062eab0d..63935d6a04c 100644 --- a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c +++ b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.c @@ -33,6 +33,31 @@ #include "git_sha1.h" #include "vulkan/vulkan.h" +static const struct spirv_to_nir_options +spirv_to_nir_options = { + .caps = { + .draw_parameters = true, + .multiview = true, + .subgroup_basic = true, + }, + .ubo_addr_format = nir_address_format_32bit_index_offset, + .ssbo_addr_format = nir_address_format_32bit_index_offset, + .shared_addr_format = nir_address_format_32bit_offset, + + /* use_deref_buffer_array_length + nir_lower_explicit_io force + * get_ssbo_size to take in the return from load_vulkan_descriptor + * instead of vulkan_resource_index. This makes it much easier to + * get the DXIL handle for the SSBO. + */ + .use_deref_buffer_array_length = true +}; + +const struct spirv_to_nir_options* +dxil_spirv_nir_get_spirv_options(void) +{ + return &spirv_to_nir_options; +} + /* Logic extracted from vk_spirv_to_nir() so we have the same preparation * steps for both the vulkan driver and the lib used by the WebGPU * implementation. diff --git a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.h b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.h index cdb4d00b5b3..dae042143cb 100644 --- a/src/microsoft/spirv_to_dxil/dxil_spirv_nir.h +++ b/src/microsoft/spirv_to_dxil/dxil_spirv_nir.h @@ -28,6 +28,9 @@ #include "spirv_to_dxil.h" #include "nir.h" +const struct spirv_to_nir_options* +dxil_spirv_nir_get_spirv_options(void); + void dxil_spirv_nir_prep(nir_shader *nir); diff --git a/src/microsoft/spirv_to_dxil/spirv2dxil.c b/src/microsoft/spirv_to_dxil/spirv2dxil.c index 45227885d04..0619111d77c 100644 --- a/src/microsoft/spirv_to_dxil/spirv2dxil.c +++ b/src/microsoft/spirv_to_dxil/spirv2dxil.c @@ -99,25 +99,12 @@ compile_shader(const char *filename, gl_shader_stage shader_stage, struct shader size_t word_count = file_size / WORD_SIZE; - struct spirv_to_nir_options spirv_opts = { - .caps = { - .draw_parameters = true, - }, - .ubo_addr_format = nir_address_format_32bit_index_offset, - .ssbo_addr_format = nir_address_format_32bit_index_offset, - .shared_addr_format = nir_address_format_32bit_offset_as_64bit, - - // use_deref_buffer_array_length + nir_lower_explicit_io force - // get_ssbo_size to take in the return from load_vulkan_descriptor - // instead of vulkan_resource_index. This makes it much easier to - // get the DXIL handle for the SSBO. - .use_deref_buffer_array_length = true - }; + const struct spirv_to_nir_options *spirv_opts = dxil_spirv_nir_get_spirv_options(); shader->nir = spirv_to_nir( (const uint32_t *)file_contents, word_count, NULL, 0, (gl_shader_stage)shader_stage, shader->entry_point, - &spirv_opts, &nir_options); + spirv_opts, &nir_options); free(file_contents); if (!shader->nir) { fprintf(stderr, "SPIR-V to NIR failed\n"); diff --git a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c index c25f41dac5f..9f0779cc465 100644 --- a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c +++ b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c @@ -56,22 +56,6 @@ spirv_to_dxil(const uint32_t *words, size_t word_count, if (stage == DXIL_SPIRV_SHADER_NONE || stage == DXIL_SPIRV_SHADER_KERNEL) return false; - struct spirv_to_nir_options spirv_opts = { - .caps = { - .draw_parameters = true, - .multiview = true, - .subgroup_basic = true, - }, - .ubo_addr_format = nir_address_format_32bit_index_offset, - .ssbo_addr_format = nir_address_format_32bit_index_offset, - .shared_addr_format = nir_address_format_32bit_offset, - - // use_deref_buffer_array_length + nir_lower_explicit_io force - // get_ssbo_size to take in the return from load_vulkan_descriptor - // instead of vulkan_resource_index. This makes it much easier to - // get the DXIL handle for the SSBO. - .use_deref_buffer_array_length = true - }; glsl_type_singleton_init_or_ref(); @@ -81,6 +65,7 @@ spirv_to_dxil(const uint32_t *words, size_t word_count, .validator_version_max = validator_version_max, }; + const struct spirv_to_nir_options *spirv_opts = dxil_spirv_nir_get_spirv_options(); struct nir_shader_compiler_options nir_options = *dxil_get_nir_compiler_options(); // We will manually handle base_vertex when vertex_id and instance_id have // have been already converted to zero-base. @@ -90,7 +75,7 @@ spirv_to_dxil(const uint32_t *words, size_t word_count, nir_shader *nir = spirv_to_nir( words, word_count, (struct nir_spirv_specialization *)specializations, num_specializations, (gl_shader_stage)stage, entry_point_name, - &spirv_opts, &nir_options); + spirv_opts, &nir_options); if (!nir) { glsl_type_singleton_decref(); return false; diff --git a/src/microsoft/vulkan/dzn_pipeline.c b/src/microsoft/vulkan/dzn_pipeline.c index 17faa501d69..dd3e7d2ee76 100644 --- a/src/microsoft/vulkan/dzn_pipeline.c +++ b/src/microsoft/vulkan/dzn_pipeline.c @@ -215,28 +215,12 @@ dzn_pipeline_get_nir_shader(struct dzn_device *device, } VK_FROM_HANDLE(vk_shader_module, module, stage_info->module); - struct spirv_to_nir_options spirv_opts = { - .caps = { - .draw_parameters = true, - .multiview = true, - .subgroup_basic = true, - }, - .ubo_addr_format = nir_address_format_32bit_index_offset, - .ssbo_addr_format = nir_address_format_32bit_index_offset, - .shared_addr_format = nir_address_format_32bit_offset, - - /* use_deref_buffer_array_length + nir_lower_explicit_io force - * get_ssbo_size to take in the return from load_vulkan_descriptor - * instead of vulkan_resource_index. This makes it much easier to - * get the DXIL handle for the SSBO. - */ - .use_deref_buffer_array_length = true - }; + const struct spirv_to_nir_options *spirv_opts = dxil_spirv_nir_get_spirv_options(); VkResult result = vk_shader_module_to_nir(&device->vk, module, stage, stage_info->pName, stage_info->pSpecializationInfo, - &spirv_opts, options->nir_opts, NULL, nir); + spirv_opts, options->nir_opts, NULL, nir); if (result != VK_SUCCESS) return result;