Skip to content

Commit 495850f

Browse files
add a lot of debug naming, and fix one possible validation error
1 parent 4f5baf6 commit 495850f

File tree

1 file changed

+50
-35
lines changed

1 file changed

+50
-35
lines changed

07_StagingAndMultipleQueues/main.cpp

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,21 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
108108
lp.logger = m_logger.get();
109109

110110
auto transferUpQueue = getTransferUpQueue();
111-
const core::bitflag<IGPUCommandPool::CREATE_FLAGS> commandPoolFlags = IGPUCommandPool::CREATE_FLAGS::RESET_COMMAND_BUFFER_BIT;
112111
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, FRAMES_IN_FLIGHT> commandPools;
113112
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandBuffer>, FRAMES_IN_FLIGHT> commandBuffers;
114113
std::fill(commandPools.begin(), commandPools.end(), nullptr);
115114

116115
core::smart_refctd_ptr<ICPUImage> cpuImages[IMAGE_CNT];
117116
for (uint32_t i = 0u; i < FRAMES_IN_FLIGHT; ++i)
118117
{
118+
const core::bitflag<IGPUCommandPool::CREATE_FLAGS> commandPoolFlags = IGPUCommandPool::CREATE_FLAGS::RESET_COMMAND_BUFFER_BIT;
119119
commandPools[i] = m_device->createCommandPool(transferUpQueue->getFamilyIndex(), commandPoolFlags);
120120
commandPools[i]->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, {commandBuffers.data() + i, 1}, core::smart_refctd_ptr(m_logger));
121+
commandBuffers[i]->setObjectDebugName(("Upload Command Buffer #"+std::to_string(i)).c_str());
121122
}
122123

123124
core::smart_refctd_ptr<ISemaphore> imgFillSemaphore = m_device->createSemaphore(0);
125+
imgFillSemaphore->setObjectDebugName("Image Fill Semaphore");
124126
SIntendedSubmitInfo intendedSubmit = {
125127
.queue = transferUpQueue,
126128
.waitSemaphores = {},
@@ -166,6 +168,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
166168
imgParams.preinitialized = false;
167169

168170
images[imageIdx] = m_device->createImage(std::move(imgParams));
171+
images[imageIdx]->setObjectDebugName(("Image #"+std::to_string(imageIdx)).c_str());
169172
auto imageAllocation = m_device->allocate(images[imageIdx]->getMemoryReqs(), images[imageIdx].get(), IDeviceMemoryAllocation::EMAF_NONE);
170173
imageHandlesCreated++;
171174
imageHandlesCreated.notify_one();
@@ -232,7 +235,12 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
232235

233236
cmdBuff->end();
234237

235-
const IQueue::SSubmitInfo::SSemaphoreInfo signalSemaphore = {.semaphore=m_imagesLoadedSemaphore.get(),.value=imageIdx+1u,.stageMask=PIPELINE_STAGE_FLAGS::COPY_BIT};
238+
const IQueue::SSubmitInfo::SSemaphoreInfo signalSemaphore = {
239+
.semaphore=m_imagesLoadedSemaphore.get(),
240+
.value=imageIdx+1u,
241+
// cannot signal from COPY stage because there's a layout transition we need to wait for right after and it doesn't have an explicit stage
242+
.stageMask=PIPELINE_STAGE_FLAGS::ALL_COMMANDS_BITS
243+
};
236244
transferUpQueue->startCapture();
237245
getTransferUpQueue()->submit(intendedSubmit.popSubmit({&signalSemaphore,1}));
238246
transferUpQueue->endCapture();
@@ -249,44 +257,48 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
249257
{
250258
// INITIALIZE COMMON DATA
251259
auto computeQueue = getComputeQueue();
252-
const core::bitflag<IGPUCommandPool::CREATE_FLAGS> commandPoolFlags = static_cast<IGPUCommandPool::CREATE_FLAGS>(IGPUCommandPool::CREATE_FLAGS::NONE);
253-
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, FRAMES_IN_FLIGHT> commandPools;
254-
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandBuffer>, FRAMES_IN_FLIGHT> commandBuffers;
260+
261+
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout;
255262
core::smart_refctd_ptr<IGPUDescriptorSet> descSets[FRAMES_IN_FLIGHT];
256-
std::fill(commandPools.begin(), commandPools.end(), nullptr);
257-
nbl::video::IGPUDescriptorSetLayout::SBinding bindings[2] = {
258-
{
259-
.binding = 0,
260-
.type = nbl::asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER,
261-
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
262-
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
263-
.count = 1,
264-
.samplers = nullptr
265-
},
263+
{
264+
nbl::video::IGPUDescriptorSetLayout::SBinding bindings[2] = {
265+
{
266+
.binding = 0,
267+
.type = nbl::asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER, // TODO: just an image descriptor type when separable samplers arrive
268+
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
269+
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
270+
.count = 1,
271+
.samplers = nullptr
272+
},
273+
{
274+
.binding = 1,
275+
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
276+
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
277+
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
278+
.count = 1,
279+
.samplers = nullptr
280+
}
281+
};
282+
283+
dsLayout = m_device->createDescriptorSetLayout(bindings);
284+
if (!dsLayout)
285+
logFailAndTerminate("Failed to create a Descriptor Layout!\n");
286+
auto descPool = m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE, { &dsLayout.get(),1 }, &FRAMES_IN_FLIGHT);
287+
for (uint32_t i = 0u; i < FRAMES_IN_FLIGHT; ++i)
266288
{
267-
.binding = 1,
268-
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
269-
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
270-
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
271-
.count = 1,
272-
.samplers = nullptr
289+
descSets[i] = descPool->createDescriptorSet(core::smart_refctd_ptr(dsLayout));
290+
descSets[i]->setObjectDebugName(("Descriptor Set #" + std::to_string(i)).c_str());
273291
}
274-
};
275-
smart_refctd_ptr<IGPUDescriptorSetLayout> dsLayout[1] = { m_device->createDescriptorSetLayout(bindings) };
276-
if (!dsLayout[0])
277-
logFailAndTerminate("Failed to create a Descriptor Layout!\n");
278-
smart_refctd_ptr<nbl::video::IDescriptorPool> descPools[FRAMES_IN_FLIGHT] = { // TODO: only one desc pool?
279-
m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE, {&dsLayout[0].get(), 1}),
280-
m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE, {&dsLayout[0].get(), 1}),
281-
m_device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE, {&dsLayout[0].get(), 1})
282-
};
292+
}
283293

294+
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandPool>, FRAMES_IN_FLIGHT> commandPools;
295+
std::array<core::smart_refctd_ptr<nbl::video::IGPUCommandBuffer>, FRAMES_IN_FLIGHT> commandBuffers;
284296
for (uint32_t i = 0u; i < FRAMES_IN_FLIGHT; ++i)
285297
{
298+
const core::bitflag<IGPUCommandPool::CREATE_FLAGS> commandPoolFlags = IGPUCommandPool::CREATE_FLAGS::NONE;
286299
commandPools[i] = m_device->createCommandPool(getComputeQueue()->getFamilyIndex(), commandPoolFlags);
287300
commandPools[i]->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, {commandBuffers.data() + i, 1}, core::smart_refctd_ptr(m_logger));
288-
289-
descSets[i] = descPools[i]->createDescriptorSet(core::smart_refctd_ptr(dsLayout[0]));
301+
commandBuffers[i]->setObjectDebugName(("Histogram Command Buffer #" + std::to_string(i)).c_str());
290302
}
291303

292304
// LOAD SHADER FROM FILE
@@ -310,7 +322,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
310322
pc[0].size = sizeof(PushConstants);
311323

312324
smart_refctd_ptr<nbl::video::IGPUComputePipeline> pipeline;
313-
smart_refctd_ptr<IGPUPipelineLayout> pplnLayout = m_device->createPipelineLayout(pc, smart_refctd_ptr(dsLayout[0]));
325+
smart_refctd_ptr<IGPUPipelineLayout> pplnLayout = m_device->createPipelineLayout(pc,std::move(dsLayout));
314326
{
315327
// Nabla actually has facilities for SPIR-V Reflection and "guessing" pipeline layouts for a given SPIR-V which we'll cover in a different example
316328
if (!pplnLayout)
@@ -359,6 +371,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
359371
m_histogramBufferMemPtrs[2] = m_histogramBufferMemPtrs[1] + HISTOGRAM_SIZE;
360372
}
361373

374+
// TODO: will no longer be necessary after separable samplers and images
362375
IGPUSampler::SParams samplerParams;
363376
samplerParams.AnisotropicFilter = false;
364377
core::smart_refctd_ptr<IGPUSampler> sampler = m_device->createSampler(samplerParams);
@@ -399,9 +412,11 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
399412
params.subresourceRange.aspectMask = IImage::E_ASPECT_FLAGS::EAF_COLOR_BIT;
400413
params.subresourceRange.layerCount = images[imageToProcessId]->getCreationParameters().arrayLayers;
401414

402-
imgInfo.desc = m_device->createImageView(std::move(params));
403-
if (!imgInfo.desc)
415+
auto view = m_device->createImageView(std::move(params));
416+
if (!view)
404417
logFailAndTerminate("Couldn't create descriptor.");
418+
view->setObjectDebugName(("Image View #"+std::to_string(imageToProcessId)).c_str());
419+
imgInfo.desc = std::move(view);
405420
imgInfo.info.image = { .sampler = sampler, .imageLayout = IImage::LAYOUT::READ_ONLY_OPTIMAL };
406421

407422
IGPUDescriptorSet::SWriteDescriptorSet write[1] = {

0 commit comments

Comments
 (0)