Skip to content

Commit 6addbf1

Browse files
committed
fix layout issues with compute pipeline in 26_Autoexposure example + update luma DSes
1 parent 3a70977 commit 6addbf1

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

26_Autoexposure/app_resources/luma_meter.comp.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include "nbl/builtin/hlsl/luma_meter/luma_meter.hlsl"
66
#include "app_resources/common.hlsl"
77

8-
[[vk::combinedImageSampler]] [[vk::binding(0)]] Texture2D texture;
9-
[[vk::combinedImageSampler]] [[vk::binding(0)]] SamplerState samplerState;
8+
// shared accross frag & compute - binding 0 set 3
9+
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] Texture2D texture;
10+
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] SamplerState samplerState;
1011

1112
[[vk::push_constant]] AutoexposurePushData pushData;
1213

26_Autoexposure/app_resources/present.frag.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl>
99
using namespace nbl::hlsl::ext::FullScreenTriangle;
1010

11+
// shared accross frag & compute - binding 0 set 3
1112
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] Texture2D texture;
1213
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] SamplerState samplerState;
1314

26_Autoexposure/main.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
121121

122122
// create the descriptor sets and with enough room
123123
{
124-
constexpr uint32_t lumaPresentSetCount = 2, tonemapperSetCount = 1;
125-
auto lumaPresentPool = m_device->createDescriptorPoolForDSLayouts(
126-
IDescriptorPool::E_CREATE_FLAGS::ECF_NONE,
127-
{ &lumaPresentDSLayout.get(), 1 },
128-
&lumaPresentSetCount
129-
);
124+
constexpr uint32_t tonemapperSetCount = 1;
125+
126+
core::smart_refctd_ptr<IDescriptorPool> lumaPresentPool;
127+
{
128+
const video::IGPUDescriptorSetLayout* const layouts[] = { nullptr, nullptr, nullptr, lumaPresentDSLayout.get() };
129+
const uint32_t setCounts[] = { 0u, 0u, 0u, 1u }; // leaving you one for 3th set, but you can increase if you really want 2 separate DSs but I think you want single to be shared (then you also need to create 2 DSes as you did)
130+
lumaPresentPool = m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::E_CREATE_FLAGS::ECF_NONE, layouts, setCounts);
131+
}
132+
130133
auto tonemapperPool = m_device->createDescriptorPoolForDSLayouts(
131134
IDescriptorPool::E_CREATE_FLAGS::ECF_NONE,
132135
{ &tonemapperDSLayout.get(), 1 },
@@ -136,9 +139,9 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
136139
if (!lumaPresentPool || !tonemapperPool)
137140
return logFail("Failed to Create Descriptor Pools");
138141

142+
// why do you need 2 separate DSs for combined sampler? from stage flags it looks like you want them shared between compute & fragment
139143
m_lumaPresentDS[0] = lumaPresentPool->createDescriptorSet(core::smart_refctd_ptr(lumaPresentDSLayout));
140-
m_lumaPresentDS[1] = lumaPresentPool->createDescriptorSet(core::smart_refctd_ptr(lumaPresentDSLayout));
141-
if (!m_lumaPresentDS[0] || !m_lumaPresentDS[1])
144+
if (!m_lumaPresentDS[0])
142145
return logFail("Could not create Descriptor Set: lumaPresentDS!");
143146
m_tonemapperDS[0] = tonemapperPool->createDescriptorSet(core::smart_refctd_ptr(tonemapperDSLayout));
144147
if (!m_tonemapperDS[0])
@@ -228,7 +231,8 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
228231

229232
smart_refctd_ptr<IGPUPipelineLayout> layout;
230233
{
231-
layout = m_device->createPipelineLayout({ &pcRange,1 });
234+
layout = m_device->createPipelineLayout({ &pcRange,1 }, nullptr, nullptr, nullptr, core::smart_refctd_ptr(lumaPresentDSLayout)); // dont forget your compute uses combinedImageSampler, cause of your cmd buffer errors is here
235+
232236
IGPUComputePipeline::SCreationParams params = {};
233237
params.layout = layout.get();
234238
params.shader.shader = shader.get();
@@ -483,28 +487,17 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
483487
info1.info.image.imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL;
484488
info1.desc = m_gpuImgView;
485489

486-
IGPUDescriptorSet::SDescriptorInfo info2 = {};
487-
info2.info.image.imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL;
488-
info2.desc = m_gpuImgView;
489-
490490
IGPUDescriptorSet::SWriteDescriptorSet writeDescriptors[] = {
491491
{
492492
.dstSet = m_lumaPresentDS[0].get(),
493493
.binding = 0,
494494
.arrayElement = 0,
495495
.count = 1,
496496
.info = &info1
497-
},
498-
{
499-
.dstSet = m_lumaPresentDS[1].get(),
500-
.binding = 0,
501-
.arrayElement = 0,
502-
.count = 1,
503-
.info = &info2
504497
}
505498
};
506499

507-
m_device->updateDescriptorSets(2, writeDescriptors, 0, nullptr);
500+
m_device->updateDescriptorSets(1, writeDescriptors, 0, nullptr);
508501

509502
queue->endCapture();
510503
}
@@ -533,7 +526,7 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
533526
cmdbuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
534527

535528
cmdbuf->bindComputePipeline(m_lumaMeterPipeline.get());
536-
cmdbuf->bindDescriptorSets(nbl::asset::EPBP_GRAPHICS, m_lumaMeterPipeline->getLayout(), 0, 1, &ds);
529+
cmdbuf->bindDescriptorSets(nbl::asset::EPBP_GRAPHICS, m_lumaMeterPipeline->getLayout(), 3, 1, &ds); // also if you created DS Set with 3th index you need to respect it here - firstSet tells you the index of set and count tells you what range from this index it should update, useful if you had 2 DS with lets say set index 2,3, then you can bind both with single call setting firstSet to 2, count to 2 and last argument would be pointet to your DS pointers
537530
cmdbuf->dispatch(1 + (SampleCount[0] - 1) / SubgroupSize, 1 + (SampleCount[1] - 1) / SubgroupSize);
538531
cmdbuf->end();
539532
}

0 commit comments

Comments
 (0)