vkd3d_shader_compile_info::source_type can not hard write to VKD3D_SHADER_SOURCE_DXBC_TPF, it is decided by magic number of shader source.
From: fanwenjie fanwj@mail.ustc.edu.cn
--- dlls/wined3d/shader_spirv.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/shader_spirv.c b/dlls/wined3d/shader_spirv.c index fe1cc03e9f4..e12dfe250df 100644 --- a/dlls/wined3d/shader_spirv.c +++ b/dlls/wined3d/shader_spirv.c @@ -244,6 +244,25 @@ static void shader_spirv_init_shader_interface_vk(struct wined3d_shader_spirv_sh iface->vkd3d_interface.uav_counter_count = b->uav_counter_count; }
+/* test type of shader source by magic number (first 4 bytes of shader source) */ +static enum vkd3d_shader_source_type shader_spirv_get_source_type(unsigned int magic) +{ + if ((magic & 0xFFFF) < 0x400) + { + /* value of second byte is less than 4 for Direct3D shader model 1, 2, and 3 shaders */ + return VKD3D_SHADER_SOURCE_D3D_BYTECODE; + } + else if (0x43425844 == magic) + { + /* values of first 4 bytes are 'D', 'X', 'B', 'C' for Direct3D shader model 4 and 5 shaders */ + return VKD3D_SHADER_SOURCE_DXBC_TPF; + } + else + { + return VKD3D_SHADER_SOURCE_HLSL; + } +} + static VkShaderModule shader_spirv_compile_shader(struct wined3d_context_vk *context_vk, const struct wined3d_shader_desc *shader_desc, enum wined3d_shader_type shader_type, const struct shader_spirv_compile_arguments *args, const struct shader_spirv_resource_bindings *bindings, @@ -269,7 +288,7 @@ static VkShaderModule shader_spirv_compile_shader(struct wined3d_context_vk *con info.next = &compile_args.spirv_target; info.source.code = shader_desc->byte_code; info.source.size = shader_desc->byte_code_size; - info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; + info.source_type = shader_spirv_get_source_type(*(unsigned int*)info.source.code); info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; info.options = spirv_compile_options; info.option_count = ARRAY_SIZE(spirv_compile_options); @@ -708,7 +727,7 @@ static void shader_spirv_scan_shader(struct wined3d_shader *shader, info.next = descriptor_info; info.source.code = shader->byte_code; info.source.size = shader->byte_code_size; - info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; + info.source_type = shader_spirv_get_source_type(*(unsigned int*)info.source.code); info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; info.options = spirv_compile_options; info.option_count = ARRAY_SIZE(spirv_compile_options);
Sure, but that's moot as long as vkd3d doesn't support compiling d3dbc to spirv-binary; it's just going to fail in a different way. Compiling d3dbc to spirv-binary is also going to require extra information from wined3d, similar to what's contained in the vs_compile_args and ps_compile_args structures. The interface for that hasn't been defined yet.
Yes, we'll need this patch eventually, but currently it's invalid library usage. (Granted, vkd3d-shader happens to handle this specific case without asserting or crashing, but that's not true in general...)
It's probably better to defer this patch until we have a working sm1 -> spirv compiler in vkd3d-shader.
This merge request was closed by Zebediah Figura.
This was implemented upstream in 1474f5cc47d9f056382f04ea5dff3314c6d181b8.