Skip to content

Commit aabb421

Browse files
authored
Add ConvertUBOToPushConstants and corresponding tests (#737)
1 parent e256723 commit aabb421

File tree

6 files changed

+655
-14
lines changed

6 files changed

+655
-14
lines changed

Graphics/ShaderTools/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ if(ENABLE_SPIRV)
117117

118118
if (${USE_SPIRV_TOOLS})
119119
list(APPEND SOURCE src/SPIRVTools.cpp)
120+
list(APPEND SOURCE src/ConvertUBOToPushConstant.cpp)
120121
list(APPEND INCLUDE include/SPIRVTools.hpp)
121122
endif()
122123

@@ -180,6 +181,17 @@ if(ENABLE_SPIRV)
180181
PRIVATE
181182
SPIRV-Tools-opt
182183
)
184+
# Add SPIRV-Tools internal headers path for custom pass implementation
185+
# We need both the source directory (for internal headers like pass.h)
186+
# and the binary directory (for generated headers like NonSemanticShaderDebugInfo100.h)
187+
get_target_property(SPIRV_TOOLS_SOURCE_DIR SPIRV-Tools-opt SOURCE_DIR)
188+
get_target_property(SPIRV_TOOLS_BINARY_DIR SPIRV-Tools-opt BINARY_DIR)
189+
get_filename_component(SPIRV_TOOLS_ROOT_DIR "${SPIRV_TOOLS_SOURCE_DIR}/../.." ABSOLUTE)
190+
get_filename_component(SPIRV_TOOLS_ROOT_BINARY_DIR "${SPIRV_TOOLS_BINARY_DIR}/../.." ABSOLUTE)
191+
target_include_directories(Diligent-ShaderTools PRIVATE
192+
${SPIRV_TOOLS_ROOT_DIR}
193+
${SPIRV_TOOLS_ROOT_BINARY_DIR}
194+
)
183195
target_compile_definitions(Diligent-ShaderTools PRIVATE USE_SPIRV_TOOLS=1)
184196
endif()
185197

Graphics/ShaderTools/include/SPIRVTools.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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> ConvertUBOToPushConstants(const std::vector<uint32_t>& SPIRV,
61+
const std::string& BlockName);
62+
5263
} // namespace Diligent

0 commit comments

Comments
 (0)