vkd3d-shader: Introduce vkd3d_shader_get_supported_target_types().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2020-08-06 13:23:49 +04:30 committed by Alexandre Julliard
parent 5f4bd618ed
commit c326d75c1d
4 changed files with 52 additions and 13 deletions

View File

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

View File

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

View File

@ -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;
}
}

View File

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