diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 6c9301c2..d2045332 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -928,13 +928,12 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte return VKD3D_OK; } -static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, - struct vkd3d_shader_message_context *message_context) +static int scan_with_parser(const struct vkd3d_shader_compile_info *compile_info, + struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser *parser) { struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info; struct vkd3d_shader_instruction instruction; struct vkd3d_shader_scan_context context; - struct vkd3d_shader_parser *parser; int ret; if ((scan_descriptor_info = vkd3d_find_struct(compile_info->next, SCAN_DESCRIPTOR_INFO))) @@ -945,12 +944,6 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, vkd3d_shader_scan_context_init(&context, compile_info, scan_descriptor_info, message_context); - if ((ret = vkd3d_shader_sm4_parser_create(compile_info, message_context, &parser)) < 0) - { - vkd3d_shader_scan_context_cleanup(&context); - return ret; - } - if (TRACE_ON()) { vkd3d_shader_trace(parser); @@ -982,7 +975,42 @@ static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, done: vkd3d_shader_scan_context_cleanup(&context); + return ret; +} + +static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info, + struct vkd3d_shader_message_context *message_context) +{ + struct vkd3d_shader_parser *parser; + int ret; + + if ((ret = vkd3d_shader_sm4_parser_create(compile_info, message_context, &parser)) < 0) + { + WARN("Failed to initialise shader parser.\n"); + return ret; + } + + ret = scan_with_parser(compile_info, message_context, parser); vkd3d_shader_parser_destroy(parser); + + return ret; +} + +static int scan_d3dbc(const struct vkd3d_shader_compile_info *compile_info, + struct vkd3d_shader_message_context *message_context) +{ + struct vkd3d_shader_parser *parser; + int ret; + + if ((ret = vkd3d_shader_sm1_parser_create(compile_info, message_context, &parser)) < 0) + { + WARN("Failed to initialise shader parser.\n"); + return ret; + } + + ret = scan_with_parser(compile_info, message_context, parser); + vkd3d_shader_parser_destroy(parser); + return ret; } @@ -1012,6 +1040,10 @@ int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char ret = VKD3D_ERROR_NOT_IMPLEMENTED; break; + case VKD3D_SHADER_SOURCE_D3D_BYTECODE: + ret = scan_d3dbc(compile_info, &message_context); + break; + default: ERR("Unsupported source type %#x.\n", compile_info->source_type); ret = VKD3D_ERROR_INVALID_ARGUMENT; @@ -1045,6 +1077,7 @@ static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info if ((ret = vkd3d_shader_sm4_parser_create(compile_info, message_context, &parser)) < 0) { + WARN("Failed to initialise shader parser.\n"); vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info); return ret; } diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index c9045b81..6fb855c2 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -274,6 +274,9 @@ static void test_d3dbc(void) (int)d3d_asm.size, (char *)d3d_asm.code); vkd3d_shader_free_shader_code(&d3d_asm); + rc = vkd3d_shader_scan(&info, NULL); + ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc); + info.source.size = sizeof(vs_minimal) + 1; rc = vkd3d_shader_compile(&info, &d3d_asm, NULL); ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);