Skip to content

Commit c14c19a

Browse files
Move CJITIncludeLoader and make it work nicely!
1 parent 12dcdd5 commit c14c19a

File tree

5 files changed

+41
-59
lines changed

5 files changed

+41
-59
lines changed

include/nbl/asset/utils/CJITIncludeLoader.h renamed to include/nbl/video/CJITIncludeLoader.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ namespace nbl::video
1515
class NBL_API2 CJITIncludeLoader : public asset::IShaderCompiler::IIncludeLoader
1616
{
1717
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;
18+
inline CJITIncludeLoader(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features)
19+
{
20+
m_includes["nbl/builtin/hlsl/jit/device_capabilities.hlsl"] = collectDeviceCaps(limits,features);
21+
}
22+
23+
found_t getInclude(const system::path& searchPath, const std::string& includeName) const override;
2024

2125
private:
22-
core::unordered_map<system::path, std::string> m_includes;
26+
core::unordered_map<system::path,std::string> m_includes;
2327
std::string collectDeviceCaps(const SPhysicalDeviceLimits& limits, const SPhysicalDeviceFeatures& features);
2428

2529
};

include/nbl/video/ILogicalDevice.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -479,34 +479,7 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
479479
virtual const void* getNativeHandle() const = 0;
480480

481481
protected:
482-
ILogicalDevice(core::smart_refctd_ptr<IAPIConnection>&& api, IPhysicalDevice* physicalDevice, const SCreationParams& params)
483-
: m_api(api), m_physicalDevice(physicalDevice), m_enabledFeatures(params.featuresToEnable), m_compilerSet(params.compilerSet)
484-
{
485-
uint32_t qcnt = 0u;
486-
uint8_t greatestFamNum = 0u;
487-
for (uint32_t i=0u; i<params.queueParamsCount; ++i)
488-
{
489-
greatestFamNum = (std::max)(greatestFamNum, params.queueParams[i].familyIndex);
490-
qcnt += params.queueParams[i].count;
491-
}
492-
493-
m_queues = core::make_refctd_dynamic_array<queues_array_t>(qcnt);
494-
m_offsets = core::make_refctd_dynamic_array<q_offsets_array_t>(greatestFamNum + 1u, 0u);
495-
496-
for (uint32_t i=0u; i<params.queueParamsCount; ++i)
497-
{
498-
const auto& qci = params.queueParams[i];
499-
if (qci.familyIndex == greatestFamNum)
500-
continue;
501-
502-
(*m_offsets)[qci.familyIndex + 1u] = qci.count;
503-
}
504-
std::inclusive_scan(m_offsets->begin(),m_offsets->end(),m_offsets->begin());
505-
506-
addJITIncludeLoader();
507-
}
508-
509-
void addJITIncludeLoader();
482+
ILogicalDevice(core::smart_refctd_ptr<IAPIConnection>&& api, IPhysicalDevice* physicalDevice, const SCreationParams& params);
510483

511484
// must be called by implementations of mapMemory()
512485
static void post_mapMemory(IDeviceMemoryAllocation* memory, void* ptr, IDeviceMemoryAllocation::MemoryRange rng, core::bitflag<IDeviceMemoryAllocation::E_MAPPING_CPU_ACCESS_FLAGS> access)

src/nbl/asset/utils/CJITIncludeLoader.cpp renamed to src/nbl/video/CJITIncludeLoader.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
#include "nbl/asset/utils/CJITIncludeLoader.h"
1+
#include "nbl/video/CJITIncludeLoader.h"
22

33
namespace nbl::video
44
{
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
5+
auto CJITIncludeLoader::getInclude(const system::path& searchPath, const std::string& includeName) const -> found_t
126
{
13-
system::path path = searchPath / includeName;
14-
15-
assert(searchPath == "nbl/builtin/hlsl/jit");
7+
assert(searchPath=="nbl/builtin/hlsl/jit");
168

179
// 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-
}
10+
auto it = m_includes.find(includeName);
11+
if (it!=m_includes.end())
12+
return {includeName,it->second};
2413

25-
return std::nullopt;
14+
return {};
2615
}
2716

2817

@@ -54,5 +43,4 @@ std::string CJITIncludeLoader::collectDeviceCaps(const SPhysicalDeviceLimits& li
5443
#endif // _NBL_BUILTIN_HLSL_JIT_DEVICE_CAPABILITIES_INCLUDED_
5544
)===";
5645
}
57-
5846
}

src/nbl/video/ILogicalDevice.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@ using namespace nbl;
44
using namespace nbl::video;
55

66

7-
E_API_TYPE ILogicalDevice::getAPIType() const { return m_physicalDevice->getAPIType(); }
8-
9-
void ILogicalDevice::addJITIncludeLoader()
7+
ILogicalDevice::ILogicalDevice(core::smart_refctd_ptr<IAPIConnection>&& api, IPhysicalDevice* physicalDevice, const SCreationParams& params)
8+
: m_api(api), m_physicalDevice(physicalDevice), m_enabledFeatures(params.featuresToEnable), m_compilerSet(params.compilerSet)
109
{
11-
if(auto cc = (m_physicalDevice && m_compilerSet) ? m_compilerSet->getShaderCompiler(asset::IShader::E_CONTENT_TYPE::ECT_HLSL) : nullptr)
10+
uint32_t qcnt = 0u;
11+
uint8_t greatestFamNum = 0u;
12+
for (uint32_t i=0u; i<params.queueParamsCount; ++i)
1213
{
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-
}
14+
greatestFamNum = (std::max)(greatestFamNum, params.queueParams[i].familyIndex);
15+
qcnt += params.queueParams[i].count;
1716
}
17+
18+
m_queues = core::make_refctd_dynamic_array<queues_array_t>(qcnt);
19+
m_offsets = core::make_refctd_dynamic_array<q_offsets_array_t>(greatestFamNum + 1u, 0u);
20+
21+
for (uint32_t i=0u; i<params.queueParamsCount; ++i)
22+
{
23+
const auto& qci = params.queueParams[i];
24+
if (qci.familyIndex == greatestFamNum)
25+
continue;
26+
27+
(*m_offsets)[qci.familyIndex + 1u] = qci.count;
28+
}
29+
std::inclusive_scan(m_offsets->begin(),m_offsets->end(),m_offsets->begin());
30+
31+
if (auto hlslCompiler = m_compilerSet ? m_compilerSet->getShaderCompiler(asset::IShader::E_CONTENT_TYPE::ECT_HLSL):nullptr)
32+
hlslCompiler->getDefaultIncludeFinder()->addSearchPath("nbl/builtin/hlsl/jit",core::make_smart_refctd_ptr<CJITIncludeLoader>(m_physicalDevice->getLimits(),m_physicalDevice->getFeatures()));
1833
}
1934

35+
E_API_TYPE ILogicalDevice::getAPIType() const { return m_physicalDevice->getAPIType(); }
36+
2037
core::smart_refctd_ptr<IGPUDescriptorSetLayout> ILogicalDevice::createDescriptorSetLayout(const IGPUDescriptorSetLayout::SBinding* _begin, const IGPUDescriptorSetLayout::SBinding* _end)
2138
{
2239
uint32_t dynamicSSBOCount=0u,dynamicUBOCount=0u;

0 commit comments

Comments
 (0)