From 22b02ed59ff19623204919de31719039e6963b3d Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 28 Feb 2022 12:23:44 +0100 Subject: [PATCH] vkd3d-shader: Introduce VKD3D_SHADER_COMPILE_OPTION_API_VERSION. Analogous to vkd3d_api_version for libvkd3d. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- include/vkd3d_shader.h | 11 +++++++++++ libs/vkd3d-utils/vkd3d_utils_main.c | 17 +++++++++++++---- libs/vkd3d/state.c | 18 ++++++++++++++---- programs/vkd3d-compiler/main.c | 3 ++- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index be2be3c3..fece054e 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -38,6 +38,15 @@ extern "C" { * compilation, transformation, and reflection of GPU shaders. */ +/** \since 1.3 */ +enum vkd3d_shader_api_version +{ + VKD3D_SHADER_API_VERSION_1_0, + VKD3D_SHADER_API_VERSION_1_1, + VKD3D_SHADER_API_VERSION_1_2, + VKD3D_SHADER_API_VERSION_1_3, +}; + /** The type of a chained structure. */ enum vkd3d_shader_structure_type { @@ -115,6 +124,8 @@ enum vkd3d_shader_compile_option_name VKD3D_SHADER_COMPILE_OPTION_BUFFER_UAV = 0x00000002, /** \a value is a member of enum vkd3d_shader_compile_option_formatting_flags. */ VKD3D_SHADER_COMPILE_OPTION_FORMATTING = 0x00000003, + /** \a value is a member of enum vkd3d_shader_api_version. \since 1.3 */ + VKD3D_SHADER_COMPILE_OPTION_API_VERSION = 0x00000004, VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_NAME), }; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 006e5e20..5534453b 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -158,7 +158,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen { struct vkd3d_shader_preprocess_info preprocess_info; struct vkd3d_shader_hlsl_source_info hlsl_info; - struct vkd3d_shader_compile_option options[1]; + struct vkd3d_shader_compile_option options[2]; struct vkd3d_shader_compile_info compile_info; struct vkd3d_shader_compile_option *option; struct vkd3d_shader_code byte_code; @@ -208,6 +208,10 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen if (messages_blob) *messages_blob = NULL; + option = &options[0]; + option->name = VKD3D_SHADER_COMPILE_OPTION_API_VERSION; + option->value = VKD3D_SHADER_API_VERSION_1_3; + compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; compile_info.next = &preprocess_info; compile_info.source.code = data; @@ -215,7 +219,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL; compile_info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF; compile_info.options = options; - compile_info.option_count = 0; + compile_info.option_count = 1; compile_info.log_level = VKD3D_SHADER_LOG_INFO; compile_info.source_name = filename; @@ -310,6 +314,11 @@ HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename HRESULT hr; int ret; + static const struct vkd3d_shader_compile_option options[] = + { + {VKD3D_SHADER_COMPILE_OPTION_API_VERSION, VKD3D_SHADER_API_VERSION_1_3}, + }; + TRACE("data %p, size %lu, filename %s, macros %p, include %p, preprocessed_blob %p, messages_blob %p.\n", data, size, debugstr_a(filename), macros, include, preprocessed_blob, messages_blob); @@ -322,8 +331,8 @@ HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename compile_info.source.size = size; compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL; compile_info.target_type = VKD3D_SHADER_TARGET_NONE; - compile_info.options = NULL; - compile_info.option_count = 0; + compile_info.options = options; + compile_info.option_count = ARRAY_SIZE(options); compile_info.log_level = VKD3D_SHADER_LOG_INFO; compile_info.source_name = filename; diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 91f6e27b..0cf0c55f 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1768,6 +1768,11 @@ static HRESULT create_shader_stage(struct d3d12_device *device, VkResult vr; int ret; + static const struct vkd3d_shader_compile_option options[] = + { + {VKD3D_SHADER_COMPILE_OPTION_API_VERSION, VKD3D_SHADER_API_VERSION_1_3}, + }; + stage_desc->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stage_desc->pNext = NULL; stage_desc->flags = 0; @@ -1785,8 +1790,8 @@ static HRESULT create_shader_stage(struct d3d12_device *device, compile_info.source.size = code->BytecodeLength; compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; - compile_info.options = NULL; - compile_info.option_count = 0; + compile_info.options = options; + compile_info.option_count = ARRAY_SIZE(options); compile_info.log_level = VKD3D_SHADER_LOG_NONE; compile_info.source_name = NULL; @@ -1814,14 +1819,19 @@ static int vkd3d_scan_dxbc(const D3D12_SHADER_BYTECODE *code, { struct vkd3d_shader_compile_info compile_info; + static const struct vkd3d_shader_compile_option options[] = + { + {VKD3D_SHADER_COMPILE_OPTION_API_VERSION, VKD3D_SHADER_API_VERSION_1_3}, + }; + compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; compile_info.next = descriptor_info; compile_info.source.code = code->pShaderBytecode; compile_info.source.size = code->BytecodeLength; compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF; compile_info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; - compile_info.options = NULL; - compile_info.option_count = 0; + compile_info.options = options; + compile_info.option_count = ARRAY_SIZE(options); compile_info.log_level = VKD3D_SHADER_LOG_NONE; compile_info.source_name = NULL; diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index f1a6b475..2f330f62 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -34,7 +34,7 @@ #include #endif -#define MAX_COMPILE_OPTIONS 3 +#define MAX_COMPILE_OPTIONS 4 enum { @@ -729,6 +729,7 @@ int main(int argc, char **argv) if (!options.explicit_colour && !getenv("NO_COLOUR") && !getenv("NO_COLOR") && has_colour(output)) options.formatting |= VKD3D_SHADER_COMPILE_OPTION_FORMATTING_COLOUR; add_compile_option(&options, VKD3D_SHADER_COMPILE_OPTION_FORMATTING, options.formatting); + add_compile_option(&options, VKD3D_SHADER_COMPILE_OPTION_API_VERSION, VKD3D_SHADER_API_VERSION_1_3); info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.next = &hlsl_source_info;