Skip to content

Commit 9c3cb73

Browse files
committed
Add SPIRV patching to convert uniform block to push constants.
1 parent 2bf4855 commit 9c3cb73

File tree

3 files changed

+409
-2
lines changed

3 files changed

+409
-2
lines changed

Graphics/ShaderTools/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ if(ENABLE_SPIRV)
180180
PRIVATE
181181
SPIRV-Tools-opt
182182
)
183+
# Add SPIRV-Tools internal headers path for custom pass implementation
184+
# We need both the source directory (for internal headers like pass.h)
185+
# and the binary directory (for generated headers like NonSemanticShaderDebugInfo100.h)
186+
get_target_property(SPIRV_TOOLS_SOURCE_DIR SPIRV-Tools-opt SOURCE_DIR)
187+
get_target_property(SPIRV_TOOLS_BINARY_DIR SPIRV-Tools-opt BINARY_DIR)
188+
get_filename_component(SPIRV_TOOLS_ROOT_DIR "${SPIRV_TOOLS_SOURCE_DIR}/../.." ABSOLUTE)
189+
get_filename_component(SPIRV_TOOLS_ROOT_BINARY_DIR "${SPIRV_TOOLS_BINARY_DIR}/../.." ABSOLUTE)
190+
target_include_directories(Diligent-ShaderTools PRIVATE
191+
${SPIRV_TOOLS_ROOT_DIR}
192+
${SPIRV_TOOLS_ROOT_BINARY_DIR}
193+
)
183194
target_compile_definitions(Diligent-ShaderTools PRIVATE USE_SPIRV_TOOLS=1)
184195
endif()
185196

@@ -227,7 +238,7 @@ add_custom_command(OUTPUT ${HLSL_DEFINITIONS_INC} # We must use full path here!
227238
VERBATIM
228239
)
229240

230-
set_common_target_properties(Diligent-ShaderTools)
241+
set_common_target_properties(Diligent-ShaderTools 17)
231242

232243
source_group("src" FILES ${SOURCE})
233244
source_group("include" FILES ${INCLUDE})

Graphics/ShaderTools/include/SPIRVTools.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#pragma once
2828

2929
#include <vector>
30+
#include <string>
3031

3132
#include "FlagEnum.h"
3233

@@ -49,4 +50,14 @@ std::vector<uint32_t> OptimizeSPIRV(const std::vector<uint32_t>& SrcSPIRV,
4950
spv_target_env TargetEnv,
5051
SPIRV_OPTIMIZATION_FLAGS Passes);
5152

53+
/// Converts a uniform buffer variable to a push constant in SPIR-V bytecode.
54+
/// This function modifies the storage class of the specified variable from Uniform to PushConstant,
55+
/// and removes Binding and DescriptorSet decorations.
56+
///
57+
/// \param [in] SPIRV - Source SPIR-V bytecode
58+
/// \param [in] BlockName - Name of the uniform buffer block to convert
59+
/// \return Modified SPIR-V bytecode, or empty vector on failure
60+
std::vector<uint32_t> PatchSPIRVConvertUniformBufferToPushConstant(const std::vector<uint32_t>& SPIRV,
61+
const std::string& BlockName);
62+
5263
} // namespace Diligent

0 commit comments

Comments
 (0)