Skip to content

Commit 4275c23

Browse files
author
devsh
committed
add a general binding info
1 parent 0b2e2f1 commit 4275c23

File tree

6 files changed

+82
-19
lines changed

6 files changed

+82
-19
lines changed

include/nbl/asset/IPipelineLayout.h

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
#ifndef _NBL_ASSET_I_PIPELINE_LAYOUT_H_INCLUDED_
55
#define _NBL_ASSET_I_PIPELINE_LAYOUT_H_INCLUDED_
66

7+
#include "nbl/macros.h"
8+
#include "nbl/core/declarations.h"
79

810
#include <algorithm>
911
#include <array>
1012

11-
#include "nbl/macros.h"
12-
#include "nbl/core/declarations.h"
13+
#include "nbl/asset/IDescriptorSetLayout.h"
14+
#include "nbl/builtin/hlsl/binding_info.hlsl"
1315

1416

1517
namespace nbl::asset
@@ -21,7 +23,7 @@ namespace nbl::asset
2123
however they serve as a fast path with regard to data upload from the
2224
CPU and data access from the GPU.
2325
24-
Note that IrrlichtBaW limits push constant size to 128 bytes.
26+
Note that Nabla limits push constant size to 128 bytes.
2527
2628
Push Constants are an alternative to an UBO where it performs really poorly,
2729
mostly very small and very frequent updates. Examples of which are:
@@ -140,6 +142,44 @@ class IPipelineLayout
140142
return static_cast<int32_t>(i)-1;
141143
}
142144

145+
// utility function, if you compile shaders for specific layouts, not create layouts given shaders
146+
using desc_type_bitset_t = std::bitset<static_cast<size_t>(IDescriptor::E_TYPE::ET_COUNT)>;
147+
// TODO: add constraints for stage and creation flags, or just return the storage index & redirect?
148+
core::string getBindingInfoForHLSL(const hlsl::SBindingInfo& info, const desc_type_bitset_t allowedTypes=desc_type_bitset_t().set()) const
149+
{
150+
if (info.set>=DESCRIPTOR_SET_COUNT)
151+
return "#error \"::nbl::hlsl::SBindingInfo::set out of range!\"";
152+
const auto* layout = m_descSetLayouts[info.set];
153+
if (!layout)
154+
return "#error \"::nbl::hlsl::SBindingInfo::set layout is nullptr!\"";
155+
//
156+
using redirect_t = IDescriptorSetLayoutBase::CBindingRedirect;
157+
using storage_range_index_t = redirect_t::storage_range_index_t;
158+
const redirect_t* redirect;
159+
storage_range_index_t found;
160+
{
161+
const redirect_t::binding_number_t binding(info.binding);
162+
for (auto t=0u; t<static_cast<size_t>(IDescriptor::E_TYPE::ET_COUNT); t++)
163+
if (allowedTypes.test(t))
164+
{
165+
redirect = &layout->getDescriptorRedirect(static_cast<IDescriptor::E_TYPE>(t));
166+
found = redirect->findBindingStorageIndex(binding);
167+
if (found)
168+
break;
169+
}
170+
if (!found && allowedTypes.test(static_cast<size_t>(IDescriptor::E_TYPE::ET_SAMPLER)))
171+
{
172+
redirect = &layout->getImmutableSamplerRedirect();
173+
found = redirect->findBindingStorageIndex(binding);
174+
}
175+
if (!found)
176+
return "#error \"Could not find `::nbl::hlsl::SBindingInfo::binding` in `::nbl::hlsl::SBindingInfo::set`'s layout!\"";
177+
}
178+
const auto count = redirect->getCount(found);
179+
assert(count); // this layout should have never passed validation
180+
return "::nbl::hlsl::ConstevalBindingInfo<"+std::to_string(info.set)+","+std::to_string(info.binding)+","+std::to_string(count)+">";
181+
}
182+
143183
protected:
144184
IPipelineLayout(
145185
const std::span<const asset::SPushConstantRange> _pcRanges,

include/nbl/builtin/hlsl/binding_info.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ struct ConstevalBindingInfo
1919
NBL_CONSTEXPR_STATIC_INLINE uint32_t Count = count;
2020
};
2121

22+
// used for descriptor set layout lookups
23+
struct SBindingInfo
24+
{
25+
//! binding index for a given resource
26+
uint32_t binding : 29;
27+
//! descriptor set index for a resource
28+
uint32_t set : 3;
29+
};
30+
2231
}
2332
}
2433
#endif

include/nbl/ext/ImGui/ImGui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class UI final : public core::IReferenceCounted
2424
struct SResourceParameters
2525
{
2626
//! for a given pipeline layout we need to know what is intended for UI resources
27+
// TODO: introduce a common type between ImGUI and Blit for the descriptor infos "binding_info.hlsl"
2728
struct SBindingInfo
2829
{
2930
//! descriptor set index for a resource

include/nbl/video/utilities/CComputeBlit.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,34 @@ class NBL_API2 CComputeBlit : public core::IReferenceCounted
4747
core::smart_refctd_ptr<system::ILogger>&& logger=nullptr
4848
);
4949

50-
// if you set the balues too small, we'll correct them ourselves anyway
51-
struct STask
50+
// create your pipelines
51+
struct SPipelines
5252
{
53+
core::smart_refctd_ptr<IGPUComputePipeline> blit;
54+
core::smart_refctd_ptr<IGPUComputePipeline> coverage;
55+
};
56+
struct SPipelinesCreateInfo
57+
{
58+
// required
59+
CAssetConverter* converter;
60+
// in theory we _could_ accept either pipeline layout type (or just the base) and make the CPU one back from the GPU
61+
const asset::ICPUPipelineLayout* layout;
62+
// must be Uniform Texel Buffer descriptor type
63+
hlsl::SBindingInfo kernelWeights;
64+
// must be Sampled Image descriptor type
65+
hlsl::SBindingInfo inputs;
66+
// must be Sampler descriptor type
67+
hlsl::SBindingInfo samplers;
68+
// must be Storage Image descriptor type
69+
hlsl::SBindingInfo outputs;
70+
//! If you set the balues too small, we'll correct them ourselves anyway
71+
// needs to be at least as big as the maximum subgroup size
5372
uint32_t workgroupSizeLog2 : 4 = 0;
54-
// the TRUE output format, not the storage view format you might manually encode into
55-
hlsl::format::TexelBlockFormat outputFormat : 8 = hlsl::format::TexelBlockFormat::TBF_UNKNOWN;
73+
//
5674
uint32_t sharedMemoryPerInvocation : 6 = 0;
57-
uint32_t unused : 14 = 0;
5875
};
59-
76+
SPipelines createAndCachePipelines(const SPipelinesCreateInfo& info);
77+
6078
//! Returns the original format if supports STORAGE_IMAGE otherwise returns a format in its compat class which supports STORAGE_IMAGE.
6179
inline asset::E_FORMAT getOutputViewFormat(const asset::E_FORMAT format)
6280
{
@@ -585,8 +603,6 @@ class NBL_API2 CComputeBlit : public core::IReferenceCounted
585603
EBT_COUNT
586604
};
587605

588-
void createAndCachePipelines(CAssetConverter* converter, core::smart_refctd_ptr<IGPUComputePipeline>* pipelines, const std::span<const STask> tasks);
589-
590606
core::smart_refctd_ptr<ILogicalDevice> m_device;
591607
system::logger_opt_smart_ptr m_logger;
592608
core::smart_refctd_ptr<asset::IShaderCompiler::CCache> m_shaderCache;

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ core::smart_refctd_ptr<video::IGPUGraphicsPipeline> UI::createPipeline(SCreation
221221

222222
std::stringstream stream;
223223

224+
// TODO: Use the `ConstevalBindingInfo`
224225
stream << "// -> this code has been autogenerated with Nabla ImGUI extension\n"
225226
<< "#define NBL_TEXTURES_BINDING_IX " << creationParams.resources.texturesInfo.bindingIx << "\n"
226227
<< "#define NBL_SAMPLER_STATES_BINDING_IX " << creationParams.resources.samplersInfo.bindingIx << "\n"

src/nbl/video/utilities/CComputeBlit.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ CComputeBlit::CComputeBlit(smart_refctd_ptr<ILogicalDevice>&& logicalDevice, sma
2020
m_shaderCache = make_smart_refctd_ptr<IShaderCompiler::CCache>();
2121
}
2222

23-
void CComputeBlit::createAndCachePipelines(CAssetConverter* converter, smart_refctd_ptr<IGPUComputePipeline>* pipelines, const std::span<const STask> tasks)
23+
auto CComputeBlit::createAndCachePipelines(const SPipelinesCreateInfo& info) -> SPipelines
2424
{
25+
SPipelines retval;
2526
core::vector<smart_refctd_ptr<ICPUComputePipeline>> cpuPplns;
2627
cpuPplns.reserve(tasks.size());
2728

@@ -50,12 +51,6 @@ void CComputeBlit::createAndCachePipelines(CAssetConverter* converter, smart_ref
5051
}
5152
const auto common = [&]()->std::string
5253
{
53-
// TODO: introduce a common type between ImGUI and Blit for the descriptor infos
54-
auto serializeBindingInfo = [](const hlsl::SBindingInfo& info={})->std::string
55-
{
56-
return "ConstevalBindingInfo<"+std::to_string(info.Set)+","+std::to_string(info.Set)+","+std::to_string(info.Count)+">";
57-
};
58-
5954
std::ostringstream tmp;
6055
tmp << R"===(
6156
#include "nbl/builtin/hlsl/binding_info.hlsl"
@@ -67,7 +62,7 @@ using namespace nbl::hlsl;
6762
struct ConstevalParameters
6863
{
6964
NBL_CONSTEXPR_STATIC_INLINE uint32_t WorkGroupSize = )===" << (0x1u<<task.workgroupSizeLog2) << R"===(;
70-
using kernel_weight_binding_t = )===" << serializeBindingInfo() << R"===(;
65+
using kernel_weight_binding_t = )===" << layout->getBindingInfoForHLSL() << R"===(;
7166
using input_sampler_binding_t = )===" << serializeBindingInfo() << R"===(;
7267
using input_image_binding_t = )===" << serializeBindingInfo() << R"===(;
7368
using output_binding_t = )===" << serializeBindingInfo() << R"===(;
@@ -122,6 +117,7 @@ struct ConstevalParameters
122117
auto convertResults = reserveResults.convert(params);
123118
assert(!convertResults.blocking());
124119
}
120+
return retval;
125121
}
126122

127123
#if 0

0 commit comments

Comments
 (0)