Skip to content

Commit b57580f

Browse files
committed
bug fixes
1 parent 84c1cd6 commit b57580f

File tree

6 files changed

+57
-50
lines changed

6 files changed

+57
-50
lines changed

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "nbl/asset/utils/ISPIRVOptimizer.h"
99
#include "nbl/asset/utils/IShaderCompiler.h"
10+
#include "nbl/asset/utils/CJITIncludeLoader.h"
1011

1112
#ifdef _NBL_PLATFORM_WINDOWS_
1213

@@ -26,6 +27,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
2627
CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system);
2728
~CHLSLCompiler();
2829

30+
2931
struct SOptions : IShaderCompiler::SCompilerOptions
3032
{
3133
// TODO: Add extra dxc options
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
#ifndef _NBL_ASSET_C_JIT_INCLUDE_LOADER_H_INCLUDED_
22
#define _NBL_ASSET_C_JIT_INCLUDE_LOADER_H_INCLUDED_
33

4+
#include "nbl/asset/utils/IShaderCompiler.h"
5+
#include "nbl/video/SPhysicalDeviceFeatures.h"
6+
#include "nbl/video/SPhysicalDeviceLimits.h"
7+
48
#include <string>
5-
#include <unordered_map>
69

7-
class CJITIncludeLoader
10+
using namespace nbl::asset;
11+
12+
13+
namespace nbl::video
14+
{
15+
16+
class NBL_API2 CJITIncludeLoader : public IShaderCompiler::IIncludeLoader
817
{
918
public:
1019
CJITIncludeLoader();
11-
std::string loadInclude(const std::string path);
20+
std::optional<std::string> getInclude(const system::path& searchPath, const std::string& includeName) const override;
1221

1322
private:
14-
std::unordered_map<std::string, std::string> m_includes;
15-
std::string collectDeviceCaps();
23+
core::unordered_map<system::path, std::string> m_includes;
24+
std::string collectDeviceCaps(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features);
1625
};
1726

27+
} //nbl::asset
28+
1829
#endif // CJITINCLUDELOADER_H

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "nbl/asset/ICPUSpecializedShader.h"
1515
#include "nbl/asset/utils/ISPIRVOptimizer.h"
16-
#include "nbl/asset/utils/CJITIncludeLoader.h"
1716

1817
namespace nbl::asset
1918
{
@@ -294,8 +293,6 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
294293
core::smart_refctd_ptr<system::ISystem> m_system;
295294
private:
296295
core::smart_refctd_ptr<CIncludeFinder> m_defaultIncludeFinder;
297-
298-
CJITIncludeLoader m_JITIncludeLoader;
299296
};
300297

301298
NBL_ENUM_ADD_BITWISE_OPERATORS(IShaderCompiler::E_DEBUG_INFO_FLAGS)

include/nbl/builtin/hlsl/jit/device_capabilities.hlsl

Whitespace-only changes.

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// For conditions of distribution and use, see copyright notice in nabla.h
44
#include "nbl/asset/utils/CHLSLCompiler.h"
55
#include "nbl/asset/utils/shadercUtils.h"
6+
#include "nbl/asset/utils/CJITIncludeLoader.h"
67
#ifdef NBL_EMBED_BUILTIN_RESOURCES
78
#include "nbl/builtin/CArchive.h"
89
#include "spirv/builtin/CArchive.h"
@@ -31,6 +32,7 @@
3132

3233
using namespace nbl;
3334
using namespace nbl::asset;
35+
using namespace nbl::video;
3436
using Microsoft::WRL::ComPtr;
3537

3638
static constexpr const wchar_t* SHADER_MODEL_PROFILE = L"XX_6_7";
@@ -46,8 +48,6 @@ namespace nbl::asset::hlsl::impl
4648
CHLSLCompiler::CHLSLCompiler(core::smart_refctd_ptr<system::ISystem>&& system)
4749
: IShaderCompiler(std::move(system))
4850
{
49-
m_defaultIncludeFinder->addSearchPath("", core::make_smart_refctd_ptr<CJITIncludeLoader>());
50-
5151
ComPtr<IDxcUtils> utils;
5252
auto res = DxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(utils.GetAddressOf()));
5353
assert(SUCCEEDED(res));
@@ -355,6 +355,8 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
355355

356356
core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* code, const IShaderCompiler::SCompilerOptions& options) const
357357
{
358+
m_defaultIncludeFinder->addSearchPath("nbl/builtin/hlsl/jit", core::make_smart_refctd_ptr<CJITIncludeLoader>());
359+
358360
auto hlslOptions = option_cast(options);
359361

360362
if (!code)

src/nbl/asset/utils/CJITIncludeLoader.cpp

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,53 @@
44

55
CJITIncludeLoader::CJITIncludeLoader()
66
{
7-
m_includes["device_capabilities.hlsl"] = collectDeviceCaps();
7+
m_includes["nbl/builtin/hlsl/jit/device_capabilities.hlsl"] = collectDeviceCaps(limits, features);
88
}
99

10-
std::string CJITIncludeLoader::loadInclude(const std::string path)
10+
std::optional<std::string> CJITIncludeLoader::getInclude(const system::path& searchPath, const std::string& includeName) const
1111
{
12-
const std::string prefix = "nbl/builtin/hlsl/jit/";
13-
if (path.compare(0, prefix.size(), prefix) == 0)
14-
{
15-
std::string includeFileName = path.substr(prefix.size());
12+
system::path path = searchPath / includeName;
1613

14+
if (searchPath == "nbl/builtin/hlsl/jit")
15+
{
1716
// Look up the content in m_includes map
18-
auto it = m_includes.find(includeFileName);
17+
auto it = m_includes.find(path);
1918
if (it != m_includes.end())
2019
{
2120
// Return the content of the specified include file
2221
return it->second;
2322
}
24-
else
25-
{
26-
// Handle error: include file not found
27-
std::cerr << "Error: Include file '" << path << "' not found!" << std::endl;
28-
return "";
29-
}
30-
}
31-
else
32-
{
33-
// Handle error: invalid include path
34-
std::cerr << "Error: Invalid include path '" << path << "'!" << std::endl;
35-
return "";
23+
return std::nullopt;
3624
}
25+
return std::nullopt;
3726
}
3827

3928

40-
std::string CJITIncludeLoader::collectDeviceCaps()
29+
std::string CJITIncludeLoader::collectDeviceCaps(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features)
4130
{
42-
std::ostringstream content;
43-
content << "#ifndef _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_" << std::endl;
44-
content << "#define _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_" << std::endl;
45-
content << "namespace nbl {" << std::endl;
46-
content << "namespace hlsl {" << std::endl;
47-
content << "namespace jit {" << std::endl;
48-
content << "struct device_capabilities {" << std::endl;
49-
content << " NBL_CONSTEXPR_STATIC_INLINE bool shaderFloat64 = false" << std::endl;
50-
content << " NBL_CONSTEXPR_STATIC_INLINE bool shaderDrawParameters = false" << std::endl;
51-
content << " NBL_CONSTEXPR_STATIC_INLINE bool subgroupArithmetic = false" << std::endl;
52-
content << " NBL_CONSTEXPR_STATIC_INLINE bool fragmentShaderPixelInterlock = false" << std::endl;
53-
content << std::endl;
54-
content << " NBL_CONSTEXPR_STATIC_INLINE uint16_t maxOptimallyResidentWorkgroupInvocations = 0" << std::endl;
55-
content << "};" << std::endl;
56-
content << "}" << std::endl;
57-
content << "}" << std::endl;
58-
content << "#endif" << std::endl;
59-
60-
return content.str();
61-
}
31+
return R"===(
32+
#ifndef _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_
33+
#define _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_
34+
35+
namespace nbl
36+
{
37+
namespace hlsl
38+
{
39+
namespace jit
40+
{
41+
struct device_capabilities
42+
{
43+
NBL_CONSTEXPR_STATIC_INLINE bool shaderFloat64 = )===" + std::to_string(features.shaderFloat64) + R"===(;
44+
NBL_CONSTEXPR_STATIC_INLINE bool shaderDrawParameters = )===" + std::to_string(features.shaderDrawParameters) + R"===(;
45+
NBL_CONSTEXPR_STATIC_INLINE bool subgroupArithmetic = )===" + std::to_string(limits.shaderSubgroupArithmetic) + R"===(;
46+
NBL_CONSTEXPR_STATIC_INLINE bool fragmentShaderPixelInterlock = )===" + std::to_string(features.fragmentShaderPixelInterlock) + R"===(;
47+
48+
NBL_CONSTEXPR_STATIC_INLINE uint16_t maxOptimallyResidentWorkgroupInvocations = )===" + std::to_string(limits.maxOptimallyResidentWorkgroupInvocations) + R"===(;
49+
};
50+
}
51+
}
52+
}
53+
54+
#endif // _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_
55+
)===";
56+
}

0 commit comments

Comments
 (0)