Skip to content

Commit 12dcdd5

Browse files
Merge branch 'nahim_cjit' of github.com:Devsh-Graphics-Programming/Nabla
2 parents e79e452 + 4f26c1a commit 12dcdd5

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef _NBL_VIDEO_C_JIT_INCLUDE_LOADER_H_INCLUDED_
2+
#define _NBL_VIDEO_C_JIT_INCLUDE_LOADER_H_INCLUDED_
3+
4+
#include "nbl/asset/utils/IShaderCompiler.h"
5+
6+
#include "nbl/video/SPhysicalDeviceFeatures.h"
7+
#include "nbl/video/SPhysicalDeviceLimits.h"
8+
9+
#include <string>
10+
11+
12+
namespace nbl::video
13+
{
14+
15+
class NBL_API2 CJITIncludeLoader : public asset::IShaderCompiler::IIncludeLoader
16+
{
17+
public:
18+
CJITIncludeLoader(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features);
19+
std::optional<std::string> getInclude(const system::path& searchPath, const std::string& includeName) const override;
20+
21+
private:
22+
core::unordered_map<system::path, std::string> m_includes;
23+
std::string collectDeviceCaps(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features);
24+
25+
};
26+
27+
} //nbl::video
28+
29+
#endif // CJITINCLUDELOADER_H

include/nbl/video/ILogicalDevice.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "nbl/video/CThreadSafeGPUQueueAdapter.h"
3030
#include "nbl/video/IDeviceMemoryAllocator.h"
3131

32-
#include "nbl/video/SPhysicalDeviceFeatures.h"
32+
#include "nbl/video/CJITIncludeLoader.h"
3333

3434
namespace nbl::video
3535
{
@@ -502,8 +502,12 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
502502
(*m_offsets)[qci.familyIndex + 1u] = qci.count;
503503
}
504504
std::inclusive_scan(m_offsets->begin(),m_offsets->end(),m_offsets->begin());
505+
506+
addJITIncludeLoader();
505507
}
506508

509+
void addJITIncludeLoader();
510+
507511
// must be called by implementations of mapMemory()
508512
static void post_mapMemory(IDeviceMemoryAllocation* memory, void* ptr, IDeviceMemoryAllocation::MemoryRange rng, core::bitflag<IDeviceMemoryAllocation::E_MAPPING_CPU_ACCESS_FLAGS> access)
509513
{

src/nbl/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ set(NBL_ASSET_SOURCES
198198
${NBL_ROOT_PATH}/src/nbl/asset/interchange/CGLSLLoader.cpp
199199
${NBL_ROOT_PATH}/src/nbl/asset/interchange/CHLSLLoader.cpp
200200
${NBL_ROOT_PATH}/src/nbl/asset/interchange/CSPVLoader.cpp
201-
201+
202202
# Pipeline loaders
203203
${NBL_ROOT_PATH}/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp
204204

@@ -280,6 +280,7 @@ set(NBL_VIDEO_SOURCES
280280
${NBL_ROOT_PATH}/src/nbl/video/IGPUDescriptorSet.cpp
281281
${NBL_ROOT_PATH}/src/nbl/video/IDeviceMemoryAllocation.cpp
282282
${NBL_ROOT_PATH}/src/nbl/video/IDeviceMemoryBacked.cpp
283+
${NBL_ROOT_PATH}/src/nbl/video/CJITIncludeLoader.cpp
283284

284285
# Vulkan
285286
${NBL_ROOT_PATH}/src/nbl/video/CVulkanSwapchain.cpp
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "nbl/asset/utils/CJITIncludeLoader.h"
2+
3+
namespace nbl::video
4+
{
5+
6+
CJITIncludeLoader::CJITIncludeLoader(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features)
7+
{
8+
m_includes["nbl/builtin/hlsl/jit/device_capabilities.hlsl"] = collectDeviceCaps(limits, features);
9+
}
10+
11+
std::optional<std::string> CJITIncludeLoader::getInclude(const system::path& searchPath, const std::string& includeName) const
12+
{
13+
system::path path = searchPath / includeName;
14+
15+
assert(searchPath == "nbl/builtin/hlsl/jit");
16+
17+
// Look up the content in m_includes map
18+
auto it = m_includes.find(path);
19+
if (it != m_includes.end())
20+
{
21+
// Return the content of the specified include file
22+
return it->second;
23+
}
24+
25+
return std::nullopt;
26+
}
27+
28+
29+
std::string CJITIncludeLoader::collectDeviceCaps(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features)
30+
{
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+
}
57+
58+
}

src/nbl/video/ILogicalDevice.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ using namespace nbl::video;
66

77
E_API_TYPE ILogicalDevice::getAPIType() const { return m_physicalDevice->getAPIType(); }
88

9+
void ILogicalDevice::addJITIncludeLoader()
10+
{
11+
if(auto cc = (m_physicalDevice && m_compilerSet) ? m_compilerSet->getShaderCompiler(asset::IShader::E_CONTENT_TYPE::ECT_HLSL) : nullptr)
12+
{
13+
if(auto finder = cc->getDefaultIncludeFinder())
14+
{
15+
finder->addSearchPath("nbl/builtin/hlsl/jit", core::make_smart_refctd_ptr<CJITIncludeLoader>(m_physicalDevice->getLimits(), m_physicalDevice->getFeatures()));
16+
}
17+
}
18+
}
19+
920
core::smart_refctd_ptr<IGPUDescriptorSetLayout> ILogicalDevice::createDescriptorSetLayout(const IGPUDescriptorSetLayout::SBinding* _begin, const IGPUDescriptorSetLayout::SBinding* _end)
1021
{
1122
uint32_t dynamicSSBOCount=0u,dynamicUBOCount=0u;

0 commit comments

Comments
 (0)