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);