Skip to content

Commit dd2c5d3

Browse files
Merge pull request #717 from Devsh-Graphics-Programming/clustered_rendering_cleanup
Clustered rendering cleanup
2 parents 21c9a18 + e444bee commit dd2c5d3

File tree

8 files changed

+217
-158
lines changed

8 files changed

+217
-158
lines changed

include/nbl/asset/IRenderpass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class IRenderpass
320320
}
321321
return false;
322322
}
323-
323+
324324
template<bool InputAttachment>
325325
static inline bool invalidLayout(const IImage::LAYOUT _layout)
326326
{

include/nbl/builtin/glsl/algorithm.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define NBL_GLSL_DECLARE_LOWER_BOUND_COMP(ARRAY_NAME,TYPE,COMP) NBL_GLSL_CONCATENATE4(uint lower_bound_,ARRAY_NAME,_,NBL_GLSL_LESS)(uint begin, in uint end, in TYPE value);
88

9-
#define NBL_GLSL_DECLARE_UPPER_BOUND_COMP(ARRAY_NAME,TYPE,COMP) NBL_GLSL_CONCATENATE4(uint lower_bound_,ARRAY_NAME,_,NBL_GLSL_LESS)(uint begin, in uint end, in TYPE value);
9+
#define NBL_GLSL_DECLARE_UPPER_BOUND_COMP(ARRAY_NAME,TYPE,COMP) NBL_GLSL_CONCATENATE4(uint upper_bound_,ARRAY_NAME,_,NBL_GLSL_LESS)(uint begin, in uint end, in TYPE value);
1010

1111

1212
#define NBL_GLSL_DECLARE_LOWER_BOUND(ARRAY_NAME,TYPE) NBL_GLSL_DECLARE_LOWER_BOUND_COMP(ARRAY_NAME,TYPE,NBL_GLSL_LESS) \

include/nbl/ext/LumaMeter/CLumaMeter.h

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CLumaMeter : public core::TotalInterface
2323
public:
2424
_NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_BIN_COUNT = 256u;
2525
_NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_BIN_GLOBAL_REPLICATION = 4u;
26+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t DEFAULT_DESCRIPTOR_COUNT = 3u;
2627

2728
enum E_METERING_MODE
2829
{
@@ -90,7 +91,18 @@ class CLumaMeter : public core::TotalInterface
9091
static core::SRange<const asset::SPushConstantRange> getDefaultPushConstantRanges();
9192

9293
//
93-
static core::SRange<const video::IGPUDescriptorSetLayout::SBinding> getDefaultBindings(video::IVideoDriver* driver);
94+
static core::SRange<const video::IGPUDescriptorSetLayout::SBinding> getDefaultBindings(video::ILogicalDevice* device);
95+
96+
//
97+
static inline core::smart_refctd_ptr<video::IGPUPipelineLayout> getDefaultPipelineLayout(video::ILogicalDevice* device)
98+
{
99+
auto pcRange = getDefaultPushConstantRanges();
100+
auto bindings = getDefaultBindings(device);
101+
return device->createGPUPipelineLayout(
102+
pcRange.begin(), pcRange.end(),
103+
device->createGPUDescriptorSetLayout(bindings.begin(), bindings.end()), nullptr, nullptr, nullptr
104+
);
105+
}
94106

95107
//
96108
static inline size_t getOutputBufferSize(E_METERING_MODE meterMode, uint32_t arrayLayers=1u)
@@ -118,13 +130,67 @@ class CLumaMeter : public core::TotalInterface
118130
E_METERING_MODE meterMode, float minLuma=1.f/2048.f, float maxLuma=65536.f
119131
);
120132

121-
// we expect user binds correct pipeline, descriptor sets and pushes the push constants by themselves
122-
static inline void dispatchHelper(video::IVideoDriver* driver, const DispatchInfo_t& dispatchInfo, bool issueDefaultBarrier=true)
133+
template <E_METERING_MODE mode>
134+
static inline void updateDescriptorSet(
135+
video::IGPUDescriptorSet* ds,
136+
const core::smart_refctd_ptr<video::IGPUBuffer> paramUbo,
137+
const asset::SBufferRange<video::IGPUBuffer>& outputSSBORange,
138+
const core::smart_refctd_ptr<video::IGPUImageView> inputImageView,
139+
video::ILogicalDevice* logicalDevice)
123140
{
124-
driver->dispatch(dispatchInfo.workGroupCount[0], dispatchInfo.workGroupCount[1], dispatchInfo.workGroupCount[2]);
141+
static_assert(mode < EMM_COUNT, "Invalide meter mode!");
142+
143+
video::IGPUDescriptorSet::SWriteDescriptorSet writes[DEFAULT_DESCRIPTOR_COUNT] = {};
144+
video::IGPUDescriptorSet::SDescriptorInfo infos[DEFAULT_DESCRIPTOR_COUNT] = {};
145+
146+
const asset::E_DESCRIPTOR_TYPE descriptorTypes[DEFAULT_DESCRIPTOR_COUNT] =
147+
{
148+
asset::EDT_UNIFORM_BUFFER, // luma input params
149+
asset::EDT_STORAGE_BUFFER, // luma output buffer
150+
asset::EDT_COMBINED_IMAGE_SAMPLER // input image
151+
};
152+
153+
infos[0].desc = paramUbo;
154+
infos[0].buffer.offset = 0ull;
155+
infos[0].buffer.size = sizeof(Uniforms_t<mode>);
156+
157+
infos[1].desc = outputSSBORange.buffer;
158+
infos[1].buffer.offset = outputSSBORange.offset;
159+
infos[1].buffer.size = outputSSBORange.size - infos[1].buffer.offset;
125160

126-
if (issueDefaultBarrier)
127-
defaultBarrier();
161+
infos[2].desc = inputImageView;
162+
infos[2].image.sampler = nullptr;
163+
infos[2].image.imageLayout = asset::EIL_SHADER_READ_ONLY_OPTIMAL;
164+
165+
for (uint32_t binding = 0u; binding < DEFAULT_DESCRIPTOR_COUNT; ++binding)
166+
{
167+
writes[binding].dstSet = ds;
168+
writes[binding].binding = binding;
169+
writes[binding].arrayElement = 0u;
170+
writes[binding].count = 1u;
171+
writes[binding].descriptorType = descriptorTypes[binding];
172+
writes[binding].info = infos + binding;
173+
}
174+
175+
logicalDevice->updateDescriptorSets(DEFAULT_DESCRIPTOR_COUNT, writes, 0u, nullptr);
176+
}
177+
178+
// we expect user binds correct pipeline, descriptor sets and pushes the push constants by themselves
179+
static inline void dispatchHelper(
180+
video::IGPUCommandBuffer* cmdbuf,
181+
const DispatchInfo_t& dispatchInfo,
182+
const asset::E_PIPELINE_STAGE_FLAGS srcStageMask,
183+
const uint32_t srcBarrierCount,
184+
const video::IGPUCommandBuffer::SBufferMemoryBarrier* srcBarriers,
185+
const asset::E_PIPELINE_STAGE_FLAGS dstStageMask,
186+
const uint32_t dstBarrierCount,
187+
const video::IGPUCommandBuffer::SBufferMemoryBarrier* dstBarriers)
188+
{
189+
if (srcStageMask != asset::E_PIPELINE_STAGE_FLAGS::EPSF_TOP_OF_PIPE_BIT && srcBarrierCount)
190+
cmdbuf->pipelineBarrier(srcStageMask, asset::EPSF_COMPUTE_SHADER_BIT, asset::EDF_NONE, 0u, nullptr, srcBarrierCount, srcBarriers, 0u, nullptr);
191+
cmdbuf->dispatch(dispatchInfo.workGroupCount[0], dispatchInfo.workGroupCount[1], dispatchInfo.workGroupCount[2]);
192+
if (dstStageMask != asset::E_PIPELINE_STAGE_FLAGS::EPSF_BOTTOM_OF_PIPE_BIT && dstBarrierCount)
193+
cmdbuf->pipelineBarrier(asset::EPSF_COMPUTE_SHADER_BIT, dstStageMask, asset::EDF_NONE, 0u, nullptr, dstBarrierCount, dstBarriers, 0u, nullptr);
128194
}
129195

130196
private:
@@ -155,8 +221,6 @@ class CLumaMeter : public core::TotalInterface
155221
}
156222
return retval;
157223
}
158-
159-
static void defaultBarrier();
160224
};
161225

162226

0 commit comments

Comments
 (0)