vkd3d-shader: Allow vkd3d_shader_compile() to handle multiple 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-06-23 13:50:12 +04:30 committed by Alexandre Julliard
parent d6ec017077
commit 95fa257a37
5 changed files with 27 additions and 5 deletions

View File

@ -234,6 +234,14 @@ enum vkd3d_shader_source_type
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SOURCE_TYPE), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SOURCE_TYPE),
}; };
enum vkd3d_shader_target_type
{
VKD3D_SHADER_TARGET_NONE,
VKD3D_SHADER_TARGET_SPIRV_BINARY,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE),
};
struct vkd3d_shader_compile_info struct vkd3d_shader_compile_info
{ {
enum vkd3d_shader_structure_type type; enum vkd3d_shader_structure_type type;
@ -242,6 +250,7 @@ struct vkd3d_shader_compile_info
struct vkd3d_shader_code source; struct vkd3d_shader_code source;
enum vkd3d_shader_source_type source_type; enum vkd3d_shader_source_type source_type;
enum vkd3d_shader_target_type target_type;
const struct vkd3d_shader_compile_option *options; const struct vkd3d_shader_compile_option *options;
unsigned int option_count; unsigned int option_count;
@ -663,7 +672,7 @@ struct vkd3d_shader_signature
#ifndef VKD3D_SHADER_NO_PROTOTYPES #ifndef VKD3D_SHADER_NO_PROTOTYPES
int vkd3d_shader_compile(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 *out);
void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code); void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code);
int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc, int vkd3d_shader_parse_root_signature(const struct vkd3d_shader_code *dxbc,
@ -693,7 +702,7 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
* Function pointer typedefs for vkd3d-shader functions. * Function pointer typedefs for vkd3d-shader functions.
*/ */
typedef int (*PFN_vkd3d_shader_compile)(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); struct vkd3d_shader_code *out);
typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code); typedef void (*PFN_vkd3d_shader_free_shader_code)(struct vkd3d_shader_code *code);
typedef int (*PFN_vkd3d_shader_parse_root_signature)(const struct vkd3d_shader_code *dxbc, typedef int (*PFN_vkd3d_shader_parse_root_signature)(const struct vkd3d_shader_code *dxbc,

View File

@ -120,10 +120,19 @@ static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_
return VKD3D_ERROR_INVALID_ARGUMENT; return VKD3D_ERROR_INVALID_ARGUMENT;
} }
switch (compile_info->target_type)
{
case VKD3D_SHADER_TARGET_SPIRV_BINARY:
break;
default:
WARN("Invalid shader target type %#x.\n", compile_info->target_type);
return VKD3D_ERROR_INVALID_ARGUMENT;
}
return VKD3D_OK; return VKD3D_OK;
} }
int vkd3d_shader_compile(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 *out)
{ {
struct vkd3d_shader_instruction instruction; struct vkd3d_shader_instruction instruction;
struct vkd3d_dxbc_compiler *spirv_compiler; struct vkd3d_dxbc_compiler *spirv_compiler;
@ -131,7 +140,7 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, s
struct vkd3d_shader_parser parser; struct vkd3d_shader_parser parser;
int ret; int ret;
TRACE("compile_info %p, spirv %p.\n", compile_info, spirv); TRACE("compile_info %p, out %p.\n", compile_info, out);
if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0) if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0)
return ret; return ret;
@ -174,7 +183,7 @@ int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, s
} }
if (ret >= 0) if (ret >= 0)
ret = vkd3d_dxbc_compiler_generate_spirv(spirv_compiler, spirv); ret = vkd3d_dxbc_compiler_generate_spirv(spirv_compiler, out);
vkd3d_dxbc_compiler_destroy(spirv_compiler); vkd3d_dxbc_compiler_destroy(spirv_compiler);
vkd3d_shader_parser_destroy(&parser); vkd3d_shader_parser_destroy(&parser);

View File

@ -1351,6 +1351,7 @@ static HRESULT create_shader_stage(struct d3d12_device *device,
compile_info.source.code = code->pShaderBytecode; compile_info.source.code = code->pShaderBytecode;
compile_info.source.size = code->BytecodeLength; compile_info.source.size = code->BytecodeLength;
compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
compile_info.options = NULL; compile_info.options = NULL;
compile_info.option_count = 0; compile_info.option_count = 0;

View File

@ -193,6 +193,7 @@ int main(int argc, char **argv)
info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
info.next = NULL; info.next = NULL;
info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
info.options = options.compile_options; info.options = options.compile_options;
info.option_count = options.compile_option_count; info.option_count = options.compile_option_count;

View File

@ -60,6 +60,7 @@ static void test_invalid_shaders(void)
info.source.code = ps_break_code; info.source.code = ps_break_code;
info.source.size = sizeof(ps_break_code); info.source.size = sizeof(ps_break_code);
info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
info.options = &option; info.options = &option;
info.option_count = 1; info.option_count = 1;
@ -136,6 +137,7 @@ static void test_vkd3d_shader_pfns(void)
compile_info.next = NULL; compile_info.next = NULL;
compile_info.source = vs; compile_info.source = vs;
compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY;
compile_info.options = NULL; compile_info.options = NULL;
compile_info.option_count = 0; compile_info.option_count = 0;