spirv_to_dxil: Unify spirv_to_nir_options
Beyond the pure refactoring, this fixes spirv2dxil, which was using outdated values. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20884>
This commit is contained in:
committed by
Marge Bot
parent
12a471afac
commit
e07e9a08cb
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user