Skip to content

Commit df0d845

Browse files
Fix compilation errors in screenshot.
1 parent bd0c088 commit df0d845

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

include/nbl/ext/ScreenShot/ScreenShot.h

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using namespace nbl::video;
2121
inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
2222
ILogicalDevice* logicalDevice,
2323
IQueue* queue,
24-
IGPUSemaphore* semaphore,
24+
ISemaphore* semaphore,
2525
const IGPUImageView* gpuImageView,
2626
const ACCESS_FLAGS accessMask,
2727
const IImage::LAYOUT imageLayout)
2828
{
29-
assert(logicalDevice->getPhysicalDevice()->getQueueFamilyProperties().begin()[queue->getFamilyIndex()].queueFlags.value&IQueue::FAMILY_FLAGS::TRANSFER_BIT);
29+
assert(bool(logicalDevice->getPhysicalDevice()->getQueueFamilyProperties().begin()[queue->getFamilyIndex()].queueFlags.value & IQueue::FAMILY_FLAGS::TRANSFER_BIT));
3030

3131
auto fetchedImageViewParmas = gpuImageView->getCreationParameters();
3232
auto gpuImage = fetchedImageViewParmas.image;
@@ -47,7 +47,7 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
4747
{
4848
// commandbuffer should refcount the pool, so it should be 100% legal to drop at the end of the scope
4949
auto gpuCommandPool = logicalDevice->createCommandPool(queue->getFamilyIndex(),IGPUCommandPool::CREATE_FLAGS::TRANSIENT_BIT);
50-
logicalDevice->createCommandBuffers(gpuCommandPool.get(), IGPUCommandBuffer::LEVEL::PRIMARY, 1u, &gpuCommandBuffer);
50+
gpuCommandPool->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, 1u, &gpuCommandBuffer);
5151
assert(gpuCommandBuffer);
5252
}
5353
gpuCommandBuffer->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
@@ -83,7 +83,7 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
8383
barrier.barrier.dep.dstAccessMask = ACCESS_FLAGS::TRANSFER_READ_BIT;
8484
barrier.oldLayout = imageLayout;
8585
barrier.newLayout = IImage::LAYOUT::TRANSFER_SRC_OPTIMAL;
86-
barrier.image = gpuImage;
86+
barrier.image = gpuImage.get();
8787
barrier.subresourceRange.aspectMask = fetchedImageViewParmas.subresourceRange.aspectMask;
8888
barrier.subresourceRange.baseMipLevel = mipLevelToScreenshot;
8989
barrier.subresourceRange.levelCount = 1u;
@@ -104,29 +104,39 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
104104
}
105105
gpuCommandBuffer->end();
106106

107-
auto fence = logicalDevice->createFence(static_cast<IGPUFence::E_CREATE_FLAGS>(0));
107+
auto signalSemaphore = logicalDevice->createSemaphore(0);
108108

109109
IQueue::SSubmitInfo info;
110-
info.commandBufferCount = 1u;
111-
info.commandBuffers = &gpuCommandBuffer.get();
112-
info.pSignalSemaphores = nullptr;
113-
info.signalSemaphoreCount = 0u;
114-
info.pWaitSemaphores = &semaphore;
115-
info.waitSemaphoreCount = semaphore ? 1u:0u;
116-
auto stageflags = PIPELINE_STAGE_FLAGS::ALL_COMMANDS_BITS; // assume the image we're trying to download could be touched by anything before (host manipulation is implicitly visibile because of submit's guarantees)
117-
info.pWaitDstStageMask = &stageflags;
118-
queue->submit(1u, &info, fence.get());
119-
120-
if (!logicalDevice->blockForFences(1u, &fence.get()))
110+
IQueue::SSubmitInfo::SCommandBufferInfo cmdBufferInfo{ gpuCommandBuffer.get() };
111+
IQueue::SSubmitInfo::SSemaphoreInfo signalSemaphoreInfo;
112+
IQueue::SSubmitInfo::SSemaphoreInfo waitSemaphoreInfo;
113+
signalSemaphoreInfo.semaphore = signalSemaphore.get();
114+
signalSemaphoreInfo.value = 1;
115+
signalSemaphoreInfo.stageMask = PIPELINE_STAGE_FLAGS::ALL_COMMANDS_BITS;
116+
info.commandBuffers = { &cmdBufferInfo, &cmdBufferInfo + 1 };
117+
info.signalSemaphores = { &signalSemaphoreInfo, &signalSemaphoreInfo + 1 };
118+
119+
if (semaphore)
120+
{
121+
waitSemaphoreInfo.semaphore = semaphore;
122+
waitSemaphoreInfo.value = 1;
123+
waitSemaphoreInfo.stageMask = PIPELINE_STAGE_FLAGS::ALL_COMMANDS_BITS;
124+
info.waitSemaphores = { &waitSemaphoreInfo, &waitSemaphoreInfo + 1 };
125+
}
126+
127+
queue->submit({ &info, &info + 1});
128+
129+
ILogicalDevice::SSemaphoreWaitInfo waitInfo{ signalSemaphore.get(), 1u};
130+
131+
if (logicalDevice->blockForSemaphores({&waitInfo, &waitInfo + 1}) != ILogicalDevice::WAIT_RESULT::SUCCESS)
121132
return nullptr;
122133

123134
core::smart_refctd_ptr<ICPUImageView> cpuImageView;
124135
{
125136
const auto gpuTexelBufferSize = gpuTexelBuffer->getSize(); // If you get validation errors from the `invalidateMappedMemoryRanges` we need to expose VK_WHOLE_BUFFER equivalent constant
126-
IDeviceMemoryAllocation::MappedMemoryRange mappedMemoryRange(gpuTexelBuffer->getBoundMemory(),0u,gpuTexelBufferSize);
127-
logicalDevice->mapMemory(mappedMemoryRange, IDeviceMemoryAllocation::EMCAF_READ);
137+
ILogicalDevice::MappedMemoryRange mappedMemoryRange(gpuTexelBuffer->getBoundMemory().memory,0u,gpuTexelBufferSize);
128138

129-
if (gpuTexelBuffer->getBoundMemory()->haveToMakeVisible())
139+
if (gpuTexelBuffer->getBoundMemory().memory->haveToMakeVisible())
130140
logicalDevice->invalidateMappedMemoryRanges(1u,&mappedMemoryRange);
131141

132142
auto cpuNewImage = ICPUImage::create(std::move(fetchedGpuImageParams));
@@ -146,10 +156,9 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
146156

147157
auto cpuNewTexelBuffer = core::make_smart_refctd_ptr<ICPUBuffer>(gpuTexelBufferSize);
148158
{
149-
memcpy(cpuNewTexelBuffer->getPointer(), gpuTexelBuffer->getBoundMemory()->getMappedPointer(), gpuTexelBuffer->getSize());
159+
memcpy(cpuNewTexelBuffer->getPointer(), gpuTexelBuffer->getBoundMemory().memory->getMappedPointer(), gpuTexelBuffer->getSize());
150160
}
151161
cpuNewImage->setBufferAndRegions(core::smart_refctd_ptr(cpuNewTexelBuffer), regions);
152-
logicalDevice->unmapMemory(gpuTexelBuffer->getBoundMemory());
153162
{
154163
auto newCreationParams = cpuNewImage->getCreationParameters();
155164

@@ -172,7 +181,7 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
172181
inline bool createScreenShot(
173182
ILogicalDevice* logicalDevice,
174183
IQueue* queue,
175-
IGPUSemaphore* semaphore,
184+
ISemaphore* semaphore,
176185
const IGPUImageView* gpuImageView,
177186
IAssetManager* assetManager,
178187
system::IFile* outFile,
@@ -188,7 +197,7 @@ inline bool createScreenShot(
188197
inline bool createScreenShot(
189198
ILogicalDevice* logicalDevice,
190199
IQueue* queue,
191-
IGPUSemaphore* semaphore,
200+
ISemaphore* semaphore,
192201
const IGPUImageView* gpuImageView,
193202
IAssetManager* assetManager,
194203
const std::filesystem::path& filename,

0 commit comments

Comments
 (0)