From d6ec017077e90cc16cf277857ca9134b5a0d7895 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 19 Jun 2020 16:13:36 +0430 Subject: [PATCH] vkd3d-shader: Allow vkd3d_shader_compile_dxbc() to handle multiple source types. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- include/vkd3d_shader.h | 14 +++++++++++-- libs/vkd3d-shader/vkd3d_shader.map | 2 +- libs/vkd3d-shader/vkd3d_shader_main.c | 29 +++++++++++++++++++++------ libs/vkd3d/state.c | 3 ++- programs/vkd3d-compiler/main.c | 3 ++- tests/vkd3d_shader_api.c | 10 +++++---- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 367f8a20..5c9e42ed 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -226,6 +226,14 @@ struct vkd3d_shader_transform_feedback_info unsigned int buffer_stride_count; }; +enum vkd3d_shader_source_type +{ + VKD3D_SHADER_SOURCE_NONE, + VKD3D_SHADER_SOURCE_DXBC_TPF, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SOURCE_TYPE), +}; + struct vkd3d_shader_compile_info { enum vkd3d_shader_structure_type type; @@ -233,6 +241,8 @@ struct vkd3d_shader_compile_info struct vkd3d_shader_code source; + enum vkd3d_shader_source_type source_type; + const struct vkd3d_shader_compile_option *options; unsigned int option_count; }; @@ -653,7 +663,7 @@ struct vkd3d_shader_signature #ifndef VKD3D_SHADER_NO_PROTOTYPES -int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *spirv); +int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *spirv); void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code); int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc, @@ -682,7 +692,7 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature /* * Function pointer typedefs for vkd3d-shader functions. */ -typedef int (*PFN_vkd3d_shader_compile_dxbc)(const struct vkd3d_shader_compile_info *compile_info, +typedef int (*PFN_vkd3d_shader_compile)(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *spirv); typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code); diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map index 74c38e1f..a8c73b64 100644 --- a/libs/vkd3d-shader/vkd3d_shader.map +++ b/libs/vkd3d-shader/vkd3d_shader.map @@ -1,7 +1,7 @@ VKD3D_1_0 { global: - vkd3d_shader_compile_dxbc; + vkd3d_shader_compile; vkd3d_shader_convert_root_signature; vkd3d_shader_find_signature_element; vkd3d_shader_free_root_signature; diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 71794368..5e471221 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -103,7 +103,27 @@ static void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parser) free_shader_desc(&parser->shader_desc); } -int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *spirv) +static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_info *compile_info) +{ + if (compile_info->type != VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO) + { + WARN("Invalid structure type %#x.\n", compile_info->type); + return VKD3D_ERROR_INVALID_ARGUMENT; + } + + switch (compile_info->source_type) + { + case VKD3D_SHADER_SOURCE_DXBC_TPF: + break; + default: + WARN("Invalid shader source type %#x.\n", compile_info->source_type); + return VKD3D_ERROR_INVALID_ARGUMENT; + } + + return VKD3D_OK; +} + +int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *spirv) { struct vkd3d_shader_instruction instruction; struct vkd3d_dxbc_compiler *spirv_compiler; @@ -113,11 +133,8 @@ int vkd3d_shader_compile_dxbc(const struct vkd3d_shader_compile_info *compile_in TRACE("compile_info %p, spirv %p.\n", compile_info, spirv); - if (compile_info->type != VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO) - { - WARN("Invalid compile_info structure type %#x.\n", compile_info->type); - return VKD3D_ERROR_INVALID_ARGUMENT; - } + if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0) + return ret; scan_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO; scan_info.next = NULL; diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 8bc2595c..2a1107fb 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1350,10 +1350,11 @@ static HRESULT create_shader_stage(struct d3d12_device *device, compile_info.next = shader_interface; compile_info.source.code = code->pShaderBytecode; compile_info.source.size = code->BytecodeLength; + compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.options = NULL; compile_info.option_count = 0; - if ((ret = vkd3d_shader_compile_dxbc(&compile_info, &spirv)) < 0) + if ((ret = vkd3d_shader_compile(&compile_info, &spirv)) < 0) { WARN("Failed to compile shader, vkd3d result %d.\n", ret); return hresult_from_vkd3d_result(ret); diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index d33dafda..9013f215 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -192,6 +192,7 @@ int main(int argc, char **argv) info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.next = NULL; + info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; info.options = options.compile_options; info.option_count = options.compile_option_count; @@ -201,7 +202,7 @@ int main(int argc, char **argv) return 1; } - ret = vkd3d_shader_compile_dxbc(&info, &spirv); + ret = vkd3d_shader_compile(&info, &spirv); vkd3d_shader_free_shader_code(&info.source); if (ret < 0) { diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index 00c6f957..5b47703a 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -59,10 +59,11 @@ static void test_invalid_shaders(void) info.next = NULL; info.source.code = ps_break_code; info.source.size = sizeof(ps_break_code); + info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; info.options = &option; info.option_count = 1; - rc = vkd3d_shader_compile_dxbc(&info, &spirv); + rc = vkd3d_shader_compile(&info, &spirv); ok(rc == VKD3D_ERROR_INVALID_SHADER, "Got unexpected error code %d.\n", rc); } @@ -75,8 +76,8 @@ static void test_vkd3d_shader_pfns(void) PFN_vkd3d_shader_parse_root_signature pfn_vkd3d_shader_parse_root_signature; PFN_vkd3d_shader_free_root_signature pfn_vkd3d_shader_free_root_signature; PFN_vkd3d_shader_free_shader_code pfn_vkd3d_shader_free_shader_code; - PFN_vkd3d_shader_compile_dxbc pfn_vkd3d_shader_compile_dxbc; PFN_vkd3d_shader_scan_dxbc pfn_vkd3d_shader_scan_dxbc; + PFN_vkd3d_shader_compile pfn_vkd3d_shader_compile; struct vkd3d_versioned_root_signature_desc root_signature_desc; struct vkd3d_shader_signature_element *element; @@ -115,8 +116,8 @@ static void test_vkd3d_shader_pfns(void) pfn_vkd3d_shader_parse_root_signature = vkd3d_shader_parse_root_signature; pfn_vkd3d_shader_free_root_signature = vkd3d_shader_free_root_signature; pfn_vkd3d_shader_free_shader_code = vkd3d_shader_free_shader_code; - pfn_vkd3d_shader_compile_dxbc = vkd3d_shader_compile_dxbc; pfn_vkd3d_shader_scan_dxbc = vkd3d_shader_scan_dxbc; + pfn_vkd3d_shader_compile = vkd3d_shader_compile; rc = pfn_vkd3d_shader_serialize_root_signature(&empty_rs_desc, &dxbc); ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc); @@ -134,10 +135,11 @@ static void test_vkd3d_shader_pfns(void) compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; compile_info.next = NULL; compile_info.source = vs; + compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.options = NULL; compile_info.option_count = 0; - rc = pfn_vkd3d_shader_compile_dxbc(&compile_info, &spirv); + rc = pfn_vkd3d_shader_compile(&compile_info, &spirv); ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc); pfn_vkd3d_shader_free_shader_code(&spirv);