vkd3d-shader: Implement VKD3D_SHADER_TARGET_SPIRV_TEXT.

Signed-off-by: Isabella Bosia <ibosia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Isabella Bosia 2020-09-07 12:35:41 +01:00 committed by Alexandre Julliard
parent e75a0d6f14
commit f222f99011
3 changed files with 63 additions and 0 deletions

View File

@ -73,6 +73,18 @@ enum vkd3d_shader_compile_option_buffer_uav
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_BUFFER_UAV), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_BUFFER_UAV),
}; };
enum vkd3d_shader_compile_option_formatting_flags
{
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_NONE = 0x00000000,
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_COLOUR = 0x00000001,
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_INDENT = 0x00000002,
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_SHOW_BYTE_OFFSET = 0x00000004,
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_NO_HEADER = 0x00000008,
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_FRIENDLY_NAMES = 0x00000010,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_FORMATTING_FLAGS),
};
enum vkd3d_shader_compile_option_name enum vkd3d_shader_compile_option_name
{ {
/** /**
@ -451,6 +463,7 @@ enum vkd3d_shader_target_type
* shaders. * shaders.
*/ */
VKD3D_SHADER_TARGET_SPIRV_BINARY, VKD3D_SHADER_TARGET_SPIRV_BINARY,
VKD3D_SHADER_TARGET_SPIRV_TEXT,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE),
}; };

View File

@ -50,6 +50,32 @@ static spv_target_env spv_target_env_from_vkd3d(enum vkd3d_shader_spirv_environm
} }
} }
static uint32_t get_binary_to_text_options(enum vkd3d_shader_compile_option_formatting_flags formatting)
{
uint32_t out = 0;
unsigned int i;
static const struct
{
enum vkd3d_shader_compile_option_formatting_flags vkd3d;
uint32_t spv;
}
valuemap[] =
{
{VKD3D_SHADER_COMPILE_OPTION_FORMATTING_COLOUR, SPV_BINARY_TO_TEXT_OPTION_COLOR },
{VKD3D_SHADER_COMPILE_OPTION_FORMATTING_INDENT, SPV_BINARY_TO_TEXT_OPTION_INDENT },
{VKD3D_SHADER_COMPILE_OPTION_FORMATTING_SHOW_BYTE_OFFSET, SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET},
{VKD3D_SHADER_COMPILE_OPTION_FORMATTING_NO_HEADER, SPV_BINARY_TO_TEXT_OPTION_NO_HEADER },
{VKD3D_SHADER_COMPILE_OPTION_FORMATTING_FRIENDLY_NAMES, SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES },
};
for (i = 0; i < ARRAY_SIZE(valuemap); i++)
if (formatting & valuemap[i].vkd3d)
out |= valuemap[i].spv;
return out;
}
static enum vkd3d_result vkd3d_spirv_binary_to_text(const struct vkd3d_shader_code *spirv, static enum vkd3d_result vkd3d_spirv_binary_to_text(const struct vkd3d_shader_code *spirv,
enum vkd3d_shader_spirv_environment environment, uint32_t options, struct vkd3d_shader_code *out) enum vkd3d_shader_spirv_environment environment, uint32_t options, struct vkd3d_shader_code *out)
{ {
@ -130,6 +156,15 @@ static void vkd3d_spirv_validate(const struct vkd3d_shader_code *spirv,
#else #else
static uint32_t get_binary_to_text_options(enum vkd3d_shader_compile_option_formatting_flags formatting)
{
return 0;
}
static enum vkd3d_result vkd3d_spirv_binary_to_text(const struct vkd3d_shader_code *spirv,
enum vkd3d_shader_spirv_environment environment, uint32_t options, struct vkd3d_shader_code *out)
{
return VKD3D_ERROR;
}
static void vkd3d_spirv_dump(const struct vkd3d_shader_code *spirv, static void vkd3d_spirv_dump(const struct vkd3d_shader_code *spirv,
enum vkd3d_shader_spirv_environment environment) {} enum vkd3d_shader_spirv_environment environment) {}
static void vkd3d_spirv_validate(const struct vkd3d_shader_code *spirv, static void vkd3d_spirv_validate(const struct vkd3d_shader_code *spirv,
@ -9187,6 +9222,18 @@ int vkd3d_dxbc_compiler_generate_spirv(struct vkd3d_dxbc_compiler *compiler,
if (compiler->failed) if (compiler->failed)
return VKD3D_ERROR_INVALID_SHADER; return VKD3D_ERROR_INVALID_SHADER;
if (compile_info->target_type == VKD3D_SHADER_TARGET_SPIRV_TEXT)
{
struct vkd3d_shader_code text;
enum vkd3d_shader_spirv_environment environment = vkd3d_dxbc_compiler_get_target_environment(compiler);
if (vkd3d_spirv_binary_to_text(spirv, environment,
get_binary_to_text_options(VKD3D_SHADER_COMPILE_OPTION_FORMATTING_FRIENDLY_NAMES |
VKD3D_SHADER_COMPILE_OPTION_FORMATTING_INDENT),
&text) != VKD3D_OK)
return VKD3D_ERROR;
*spirv = text;
}
return VKD3D_OK; return VKD3D_OK;
} }

View File

@ -1063,6 +1063,9 @@ const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types(
static const enum vkd3d_shader_target_type dxbc_tpf_types[] = static const enum vkd3d_shader_target_type dxbc_tpf_types[] =
{ {
VKD3D_SHADER_TARGET_SPIRV_BINARY, VKD3D_SHADER_TARGET_SPIRV_BINARY,
#ifdef HAVE_SPIRV_TOOLS
VKD3D_SHADER_TARGET_SPIRV_TEXT,
#endif
}; };
TRACE("source_type %#x, count %p.\n", source_type, count); TRACE("source_type %#x, count %p.\n", source_type, count);