Skip to content

Commit bed4f09

Browse files
committed
move targetSpirvVersion from SCompilerOptions to SPreprocessorOptions, define __SPIRV_MAJOR_VERSION__ and __SPIRV_MINOR_VERSION__, update examples_tests submodules
1 parent b8c2ca1 commit bed4f09

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,27 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
118118
std::string_view definition;
119119
};
120120

121+
//
122+
using E_SPIRV_VERSION = nbl::hlsl::SpirvVersion;
123+
124+
static inline constexpr uint32_t getSpirvMajor(E_SPIRV_VERSION version) {
125+
return (version >> 16u) & 0xFFu;
126+
}
127+
128+
static inline constexpr uint32_t getSpirvMinor(E_SPIRV_VERSION version) {
129+
return (version >> 8u) & 0xFFu;
130+
}
131+
121132
//
122133
struct SPreprocessorOptions
123134
{
124135
std::string_view sourceIdentifier = "";
125136
system::logger_opt_ptr logger = nullptr;
126137
const CIncludeFinder* includeFinder = nullptr;
127138
std::span<const SMacroDefinition> extraDefines = {};
139+
E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6;
128140
};
129141

130-
//
131-
using E_SPIRV_VERSION = nbl::hlsl::SpirvVersion;
132-
133142
// https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#debugging
134143
enum class E_DEBUG_INFO_FLAGS : uint8_t
135144
{
@@ -169,7 +178,6 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
169178
virtual IShader::E_CONTENT_TYPE getCodeContentType() const { return IShader::E_CONTENT_TYPE::ECT_UNKNOWN; };
170179

171180
IShader::E_SHADER_STAGE stage = IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY;
172-
E_SPIRV_VERSION targetSpirvVersion = E_SPIRV_VERSION::ESV_1_6;
173181
const ISPIRVOptimizer* spirvOptimizer = nullptr;
174182
core::bitflag<E_DEBUG_INFO_FLAGS> debugInfoFlags = core::bitflag<E_DEBUG_INFO_FLAGS>(E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT) | E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT;
175183
SPreprocessorOptions preprocessorOptions = {};
@@ -301,7 +309,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
301309

302310
// Only SEntry should instantiate this struct
303311
SCompilerArgs(const SCompilerOptions& options)
304-
: stage(options.stage), targetSpirvVersion(options.targetSpirvVersion), debugInfoFlags(options.debugInfoFlags), preprocessorArgs(options.preprocessorOptions)
312+
: stage(options.stage), targetSpirvVersion(options.preprocessorOptions.targetSpirvVersion), debugInfoFlags(options.debugInfoFlags), preprocessorArgs(options.preprocessorOptions)
305313
{
306314
if (options.spirvOptimizer) {
307315
for (auto pass : options.spirvOptimizer->getPasses())

src/nbl/asset/utils/CGLSLCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ core::smart_refctd_ptr<IShader> CGLSLCompiler::compileToSPIRV_impl(const std::st
266266

267267
shaderc::Compiler comp;
268268
shaderc::CompileOptions shadercOptions; //default options
269-
shadercOptions.SetTargetSpirv(static_cast<shaderc_spirv_version>(glslOptions.targetSpirvVersion));
269+
shadercOptions.SetTargetSpirv(static_cast<shaderc_spirv_version>(glslOptions.preprocessorOptions.targetSpirvVersion));
270270
const shaderc_shader_kind stage = glslOptions.stage == IShader::E_SHADER_STAGE::ESS_UNKNOWN ? shaderc_glsl_infer_from_source : ESStoShadercEnum(glslOptions.stage);
271271
if (glslOptions.debugInfoFlags.value != IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_NONE)
272272
shadercOptions.SetGenerateDebugInfo();

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset
346346

347347
namespace nbl::wave
348348
{
349-
extern nbl::core::string resolveString(std::string& code, const IShaderCompiler::SPreprocessorOptions& preprocessOptions, bool withCaching, std::function<void(nbl::wave::context&)> post);
349+
extern nbl::core::string preprocess(std::string& code, const IShaderCompiler::SPreprocessorOptions& preprocessOptions, bool withCaching, std::function<void(nbl::wave::context&)> post);
350350
}
351351

352352
std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions, std::vector<std::string>& dxc_compile_flags_override, std::vector<CCache::SEntry::SPreprocessingDependency>* dependencies) const
@@ -365,7 +365,7 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
365365
}
366366

367367
// preprocess
368-
core::string resolvedString = nbl::wave::resolveString(code, preprocessOptions, bool(dependencies) /* if dependencies were passed, we assume we want caching*/,
368+
core::string resolvedString = nbl::wave::preprocess(code, preprocessOptions, bool(dependencies) /* if dependencies were passed, we assume we want caching*/,
369369
[&dxc_compile_flags_override, &stage, &dependencies](nbl::wave::context& context) -> void
370370
{
371371
if (context.get_hooks().m_dxc_compile_flags_override.size() != 0)
@@ -435,7 +435,7 @@ core::smart_refctd_ptr<IShader> CHLSLCompiler::compileToSPIRV_impl(const std::st
435435
for (size_t i = 0; i < required.size(); i++)
436436
arguments.push_back(required[i]);
437437
//
438-
switch (options.targetSpirvVersion)
438+
switch (options.preprocessorOptions.targetSpirvVersion)
439439
{
440440
case hlsl::SpirvVersion::ESV_1_4:
441441
arguments.push_back(L"-fspv-target-env=vulkan1.1spirv1.4");

src/nbl/asset/utils/CWaveStringResolver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
in Debug/RWDI
2424
25-
then make resolveString full C API with raw in/out pointers and bytes out pointer,
25+
then make preprocess full C API with raw in/out pointers and bytes out pointer,
2626
with mismtach we must be very careful about memory ownership as STL stuff will have
2727
different struct layouts and its easy to make a crash, we will have extra memcpy and
2828
deallocation but as a trade each config will have almost the same preprocessing perf
@@ -33,6 +33,8 @@
3333
3434
NOTE: this approach allows to do all in single Nabla module, no extra proxy/fake shared DLL needed!
3535
NOTE: yep I know I have currently a callback for which context size will differ accross TUs afterwards but will think about it
36+
37+
or ignore it and take care of NSC special target creating global HLSL PCH injected into each registered input
3638
*/
3739

3840
#include "nbl/asset/utils/IShaderCompiler.h"
@@ -44,11 +46,13 @@ using namespace nbl::asset;
4446

4547
namespace nbl::wave
4648
{
47-
std::string resolveString(std::string& code, const nbl::asset::IShaderCompiler::SPreprocessorOptions& preprocessOptions, bool withCaching, std::function<void(nbl::wave::context&)> post)
49+
std::string preprocess(std::string& code, const nbl::asset::IShaderCompiler::SPreprocessorOptions& preprocessOptions, bool withCaching, std::function<void(nbl::wave::context&)> post)
4850
{
4951
nbl::wave::context context(code.begin(), code.end(), preprocessOptions.sourceIdentifier.data(), { preprocessOptions });
5052
context.set_caching(withCaching);
5153
context.add_macro_definition("__HLSL_VERSION");
54+
context.add_macro_definition("__SPIRV_MAJOR_VERSION__=" + std::to_string(IShaderCompiler::getSpirvMajor(preprocessOptions.targetSpirvVersion)));
55+
context.add_macro_definition("__SPIRV_MINOR_VERSION__=" + std::to_string(IShaderCompiler::getSpirvMinor(preprocessOptions.targetSpirvVersion)));
5256

5357
// instead of defining extraDefines as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D 32768",
5458
// now define them as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D=32768"

src/nbl/video/ILogicalDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ core::smart_refctd_ptr<asset::IShader> ILogicalDevice::compileShader(const SShad
364364
asset::IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT |
365365
asset::IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT;
366366
commonCompileOptions.spirvOptimizer = creationParams.optimizer;
367-
commonCompileOptions.targetSpirvVersion = m_physicalDevice->getLimits().spirvVersion;
367+
commonCompileOptions.preprocessorOptions.targetSpirvVersion = m_physicalDevice->getLimits().spirvVersion;
368368

369369
commonCompileOptions.readCache = creationParams.readCache;
370370
commonCompileOptions.writeCache = creationParams.writeCache;

0 commit comments

Comments
 (0)