Signed-off-by: Isabella Bosia ibosia@codeweavers.com --- include/vkd3d_shader.h | 13 ++++++++ libs/vkd3d-shader/spirv.c | 47 +++++++++++++++++++++++++++ libs/vkd3d-shader/vkd3d_shader_main.c | 3 ++ 3 files changed, 63 insertions(+)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 3752540..4c57f61 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -73,6 +73,18 @@ 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 { /** @@ -451,6 +463,7 @@ enum vkd3d_shader_target_type * shaders. */ VKD3D_SHADER_TARGET_SPIRV_BINARY, + VKD3D_SHADER_TARGET_SPIRV_TEXT,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_TARGET_TYPE), }; diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 6a6d187..530e802 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -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, 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
+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, enum vkd3d_shader_spirv_environment environment) {} 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) 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; }
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index e3abaf7..6984843 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -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[] = { 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);