From 718714799f2f903c4d200194c151c3db1683cfae Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Tue, 23 Jul 2024 02:11:19 +0200 Subject: [PATCH] Add an API to set descriptor set and binding of default uniform block --- libshaderc/include/shaderc/shaderc.h | 5 +++++ libshaderc/src/shaderc.cc | 5 +++++ .../include/libshaderc_util/compiler.h | 15 +++++++++++++++ libshaderc_util/src/compiler.cc | 2 ++ 4 files changed, 27 insertions(+) diff --git a/libshaderc/include/shaderc/shaderc.h b/libshaderc/include/shaderc/shaderc.h index 3a3e97d6b..fc7e85af2 100644 --- a/libshaderc/include/shaderc/shaderc.h +++ b/libshaderc/include/shaderc/shaderc.h @@ -506,6 +506,11 @@ SHADERC_EXPORT void shaderc_compile_options_set_invert_y( SHADERC_EXPORT void shaderc_compile_options_set_nan_clamp( shaderc_compile_options_t options, bool enable); +// Sets the descriptor set and binding for the default uniform block in the +// relaxed Vulkan rules mode. +SHADERC_EXPORT void shaderc_compile_options_set_default_uniform_block_set_and_binding( + shaderc_compile_options_t options, uint32_t set, uint32_t binding); + // An opaque handle to the results of a call to any shaderc_compile_into_*() // function. typedef struct shaderc_compilation_result* shaderc_compilation_result_t; diff --git a/libshaderc/src/shaderc.cc b/libshaderc/src/shaderc.cc index 63f1bbc6c..c5d164dd2 100644 --- a/libshaderc/src/shaderc.cc +++ b/libshaderc/src/shaderc.cc @@ -579,6 +579,11 @@ void shaderc_compile_options_set_nan_clamp(shaderc_compile_options_t options, options->compiler.SetNanClamp(enable); } +void shaderc_compile_options_set_default_uniform_block_set_and_binding( + shaderc_compile_options_t options, uint32_t set, uint32_t binding) { + options->compiler.SetDefaultUniformBlockSetAndBinding(set, binding); +} + shaderc_compiler_t shaderc_compiler_initialize() { shaderc_compiler_t compiler = new (std::nothrow) shaderc_compiler; if (compiler) { diff --git a/libshaderc_util/include/libshaderc_util/compiler.h b/libshaderc_util/include/libshaderc_util/compiler.h index d9d02b951..ca0d2ed72 100644 --- a/libshaderc_util/include/libshaderc_util/compiler.h +++ b/libshaderc_util/include/libshaderc_util/compiler.h @@ -214,6 +214,8 @@ class Compiler { hlsl_16bit_types_enabled_(false), invert_y_enabled_(false), nan_clamp_(false), + default_uniform_block_set_(0), + default_uniform_block_binding_(0), hlsl_explicit_bindings_() {} // Requests that the compiler place debug information into the object code, @@ -339,6 +341,13 @@ class Compiler { } } + // Sets the descriptor set and binding for the default uniform block in + // the relaxed Vulkan rules mode. + void SetDefaultUniformBlockSetAndBinding(uint32_t set, uint32_t binding) { + default_uniform_block_set_ = set; + default_uniform_block_binding_ = binding; + } + // Sets an explicit set and binding for the given HLSL register in the given // shader stage. For example, // SetHlslRegisterSetAndBinding(Stage::Fragment, "t1", "4", "5") @@ -563,6 +572,12 @@ class Compiler { // as a composition of max and min. bool nan_clamp_; + // Descriptor set for the default uniform block in relaxed Vulkan rules mode. + uint32_t default_uniform_block_set_; + + // Binding for the default uniform block in relaxed Vulkan rules mode. + uint32_t default_uniform_block_binding_; + // A sequence of triples, each triple representing a specific HLSL register // name, and the set and binding numbers it should be mapped to, but in // the form of strings. This is how Glslang wants to consume the data. diff --git a/libshaderc_util/src/compiler.cc b/libshaderc_util/src/compiler.cc index e5f5d1055..e05dc6c71 100644 --- a/libshaderc_util/src/compiler.cc +++ b/libshaderc_util/src/compiler.cc @@ -312,6 +312,8 @@ std::tuple, size_t> Compiler::Compile( } shader.setInvertY(invert_y_enabled_); shader.setNanMinMaxClamp(nan_clamp_); + shader.setGlobalUniformSet(default_uniform_block_set_); + shader.setGlobalUniformBinding(default_uniform_block_binding_); const EShMessages rules = GetMessageRules(target_env_, source_language_, hlsl_offsets_,