Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- include/vkd3d_shader.h | 4 ++++ libs/vkd3d-shader/vkd3d_shader.map | 1 + libs/vkd3d-shader/vkd3d_shader_main.c | 36 ++++++++++++++++++++++++++++++----- tests/vkd3d_shader_api.c | 24 +++++++++++++++-------- 4 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 3dc3bb0..af97b04 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -751,6 +751,8 @@ struct vkd3d_shader_signature
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); +const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types( + enum vkd3d_shader_source_type source_type, unsigned int *count);
int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages); @@ -784,6 +786,8 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature */ 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 const enum vkd3d_shader_target_type *(*PFN_vkd3d_shader_get_supported_target_types)( + enum vkd3d_shader_source_type source_type, 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 15a1403..1937131 100644 --- a/libs/vkd3d-shader/vkd3d_shader.map +++ b/libs/vkd3d-shader/vkd3d_shader.map @@ -10,6 +10,7 @@ global: vkd3d_shader_free_shader_code; vkd3d_shader_free_shader_signature; vkd3d_shader_get_supported_source_types; + vkd3d_shader_get_supported_target_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 7a5c405..3e7b6cc 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -256,6 +256,7 @@ 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; + const enum vkd3d_shader_target_type *target_types; unsigned int count, i;
if (compile_info->type != VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO) @@ -276,13 +277,16 @@ static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_ return VKD3D_ERROR_INVALID_ARGUMENT; }
- switch (compile_info->target_type) + target_types = vkd3d_shader_get_supported_target_types(compile_info->source_type, &count); + for (i = 0; i < count; ++i) { - case VKD3D_SHADER_TARGET_SPIRV_BINARY: + if (target_types[i] == compile_info->target_type) break; - default: - WARN("Invalid shader target type %#x.\n", compile_info->target_type); - return VKD3D_ERROR_INVALID_ARGUMENT; + } + if (i == count) + { + WARN("Invalid shader target type %#x.\n", compile_info->target_type); + return VKD3D_ERROR_INVALID_ARGUMENT; }
return VKD3D_OK; @@ -1056,3 +1060,25 @@ const enum vkd3d_shader_source_type *vkd3d_shader_get_supported_source_types(uns *count = ARRAY_SIZE(types); return types; } + +const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types( + enum vkd3d_shader_source_type source_type, unsigned int *count) +{ + static const enum vkd3d_shader_target_type dxbc_tpf_types[] = + { + VKD3D_SHADER_TARGET_SPIRV_BINARY, + }; + + TRACE("source_type %#x, count %p.\n", source_type, count); + + switch (source_type) + { + case VKD3D_SHADER_SOURCE_DXBC_TPF: + *count = ARRAY_SIZE(dxbc_tpf_types); + return dxbc_tpf_types; + + default: + *count = 0; + return NULL; + } +} diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c index df2a4f2..d0f3f5d 100644 --- a/tests/vkd3d_shader_api.c +++ b/tests/vkd3d_shader_api.c @@ -76,6 +76,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_get_supported_target_types pfn_vkd3d_shader_get_supported_target_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; @@ -92,12 +93,13 @@ static void test_vkd3d_shader_pfns(void) unsigned int major, minor, expected_major, expected_minor; struct vkd3d_shader_scan_descriptor_info descriptor_info; const enum vkd3d_shader_source_type *source_types; + const enum vkd3d_shader_target_type *target_types; struct vkd3d_shader_signature_element *element; struct vkd3d_shader_compile_info compile_info; + unsigned int i, j, source_count, target_count; struct vkd3d_shader_signature signature; struct vkd3d_shader_code dxbc, spirv; const char *version, *p; - unsigned int i, count; bool b; int rc;
@@ -124,6 +126,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_get_supported_target_types = vkd3d_shader_get_supported_target_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; @@ -143,20 +146,25 @@ 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); + source_types = pfn_vkd3d_shader_get_supported_source_types(&source_count); ok(source_types, "Got unexpected source types array %p.\n", source_types); - ok(count, "Got unexpected source type count %u.\n", count); + ok(source_count, "Got unexpected source type count %u.\n", source_count);
b = false; - for (i = 0; i < count; ++i) + for (i = 0; i < source_count; ++i) { - if (source_types[i] == VKD3D_SHADER_SOURCE_DXBC_TPF) + target_types = pfn_vkd3d_shader_get_supported_target_types(source_types[i], &target_count); + ok(target_types, "Got unexpected target types array %p.\n", target_types); + ok(target_count, "Got unexpected target type count %u.\n", target_count); + + for (j = 0; j < target_count; ++j) { - b = true; - break; + if (source_types[i] == VKD3D_SHADER_SOURCE_DXBC_TPF + && target_types[j] == VKD3D_SHADER_TARGET_SPIRV_BINARY) + b = true; } } - ok(b, "The dxbc-tpf source type is not supported.\n"); + ok(b, "The dxbc-tpf source type with spirv-binary target 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);