Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- include/vkd3d_shader.h | 2 ++ libs/vkd3d-shader/vkd3d_shader.map | 1 + libs/vkd3d-shader/vkd3d_shader_main.c | 29 ++++++++++++++++++++++++----- tests/vkd3d_shader_api.c | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 92ce9b9..3dc3bb0 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -750,6 +750,7 @@ struct vkd3d_shader_signature #ifndef VKD3D_SHADER_NO_PROTOTYPES
const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor); +const enum vkd3d_shader_source_type *vkd3d_shader_get_supported_source_types(unsigned int *count);
int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages); @@ -782,6 +783,7 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature * Function pointer typedefs for vkd3d-shader functions. */ typedef const char *(*PFN_vkd3d_shader_get_version)(unsigned int *major, unsigned int *minor); +typedef const enum vkd3d_shader_source_type *(*PFN_vkd3d_shader_get_supported_source_types)(unsigned int *count);
typedef int (*PFN_vkd3d_shader_compile)(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages); diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map index eca7278..15a1403 100644 --- a/libs/vkd3d-shader/vkd3d_shader.map +++ b/libs/vkd3d-shader/vkd3d_shader.map @@ -9,6 +9,7 @@ global: vkd3d_shader_free_scan_descriptor_info; vkd3d_shader_free_shader_code; vkd3d_shader_free_shader_signature; + vkd3d_shader_get_supported_source_types; vkd3d_shader_get_version; vkd3d_shader_parse_input_signature; vkd3d_shader_parse_root_signature; diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index ab08620..7a5c405 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -255,19 +255,25 @@ static void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parser)
static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_info *compile_info) { + const enum vkd3d_shader_source_type *source_types; + unsigned int count, i; + 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) + source_types = vkd3d_shader_get_supported_source_types(&count); + for (i = 0; i < count; ++i) { - case VKD3D_SHADER_SOURCE_DXBC_TPF: + if (source_types[i] == compile_info->source_type) break; - default: - WARN("Invalid shader source type %#x.\n", compile_info->source_type); - return VKD3D_ERROR_INVALID_ARGUMENT; + } + if (i == count) + { + WARN("Invalid shader source type %#x.\n", compile_info->source_type); + return VKD3D_ERROR_INVALID_ARGUMENT; }
switch (compile_info->target_type) @@ -1037,3 +1043,16 @@ const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor)
return "vkd3d-shader " PACKAGE_VERSION VKD3D_VCS_ID; } + +const enum vkd3d_shader_source_type *vkd3d_shader_get_supported_source_types(unsigned int *count) +{ + static const enum vkd3d_shader_source_type types[] = + { + VKD3D_SHADER_SOURCE_DXBC_TPF, + }; + + TRACE("count %p.\n", count); + + *count = ARRAY_SIZE(types); + return types; +} diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index fab17ad..df2a4f2 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -75,6 +75,7 @@ static void test_invalid_shaders(void)
static void test_vkd3d_shader_pfns(void) { + PFN_vkd3d_shader_get_supported_source_types pfn_vkd3d_shader_get_supported_source_types; PFN_vkd3d_shader_free_scan_descriptor_info pfn_vkd3d_shader_free_scan_descriptor_info; PFN_vkd3d_shader_serialize_root_signature pfn_vkd3d_shader_serialize_root_signature; PFN_vkd3d_shader_find_signature_element pfn_vkd3d_shader_find_signature_element; @@ -90,11 +91,14 @@ static void test_vkd3d_shader_pfns(void) struct vkd3d_shader_versioned_root_signature_desc root_signature_desc; unsigned int major, minor, expected_major, expected_minor; struct vkd3d_shader_scan_descriptor_info descriptor_info; + const enum vkd3d_shader_source_type *source_types; struct vkd3d_shader_signature_element *element; struct vkd3d_shader_compile_info compile_info; struct vkd3d_shader_signature signature; struct vkd3d_shader_code dxbc, spirv; const char *version, *p; + unsigned int i, count; + bool b; int rc;
static const struct vkd3d_shader_versioned_root_signature_desc empty_rs_desc = @@ -119,6 +123,7 @@ static void test_vkd3d_shader_pfns(void) }; static const struct vkd3d_shader_code vs = {vs_code, sizeof(vs_code)};
+ pfn_vkd3d_shader_get_supported_source_types = vkd3d_shader_get_supported_source_types; pfn_vkd3d_shader_free_scan_descriptor_info = vkd3d_shader_free_scan_descriptor_info; pfn_vkd3d_shader_serialize_root_signature = vkd3d_shader_serialize_root_signature; pfn_vkd3d_shader_find_signature_element = vkd3d_shader_find_signature_element; @@ -138,6 +143,21 @@ static void test_vkd3d_shader_pfns(void) ok(major == expected_major, "Got unexpected major version %u.\n", major); ok(minor == expected_minor, "Got unexpected minor version %u.\n", minor);
+ source_types = pfn_vkd3d_shader_get_supported_source_types(&count); + ok(source_types, "Got unexpected source types array %p.\n", source_types); + ok(count, "Got unexpected source type count %u.\n", count); + + b = false; + for (i = 0; i < count; ++i) + { + if (source_types[i] == VKD3D_SHADER_SOURCE_DXBC_TPF) + { + b = true; + break; + } + } + ok(b, "The dxbc-tpf source type is not supported.\n"); + rc = pfn_vkd3d_shader_serialize_root_signature(&empty_rs_desc, &dxbc, NULL); ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc); rc = pfn_vkd3d_shader_parse_root_signature(&dxbc, &root_signature_desc, NULL);