Skip to content

Commit 7d4895a

Browse files
committed
Allocate buffer for gathered luma values
1 parent 734b887 commit 7d4895a

File tree

5 files changed

+89
-20
lines changed

5 files changed

+89
-20
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#ifndef _AUTOEXPOSURE_COMMON_INCLUDED_
6+
#define _AUTOEXPOSURE_COMMON_INCLUDED_
7+
8+
struct AutoexposurePushData
9+
{
10+
uint32_t viewportSizeX, viewportSizeY;
11+
};
12+
13+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (C) 2024-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#include "app_resources/common.hlsl"
6+
7+
[[vk::push_constant]] AutoexposurePushData pushData;
8+
9+
uint32_t3 nbl::hlsl::glsl::gl_WorkGroupSize()
10+
{
11+
return uint32_t3(WorkgroupSize, 1, 1);
12+
}
13+
14+
[numthreads(SubgroupSize, SubgroupSize, 1)]
15+
void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
16+
{
17+
}

26_Autoexposure/app_resources/present.frag.hlsl

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

11-
#include <nbl/builtin/hlsl/luma_meter/luma_meter.hlsl>
12-
1311
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] Texture2D texture;
1412
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] SamplerState samplerState;
1513

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (C) 2024-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#include "app_resources/common.hlsl"
6+
7+
[[vk::push_constant]] AutoexposurePushData pushData;
8+
9+
uint32_t3 nbl::hlsl::glsl::gl_WorkGroupSize()
10+
{
11+
return uint32_t3(WorkgroupSize, 1, 1);
12+
}
13+
14+
[numthreads(SubgroupSize, SubgroupSize, 1)]
15+
void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
16+
{
17+
}

26_Autoexposure/main.cpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,46 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
227227
};
228228
}
229229

230+
// Allocate and create buffer for Luma Gather
231+
{
232+
// Allocate memory
233+
nbl::video::IDeviceMemoryAllocator::SAllocation allocation = {};
234+
smart_refctd_ptr<IGPUBuffer> buffer;
235+
//smart_refctd_ptr<nbl::video::IGPUDescriptorSet> ds;
236+
{
237+
auto build_buffer = [this](
238+
smart_refctd_ptr<ILogicalDevice> m_device,
239+
nbl::video::IDeviceMemoryAllocator::SAllocation* allocation,
240+
smart_refctd_ptr<IGPUBuffer>& buffer,
241+
size_t buffer_size,
242+
const char* label)
243+
{
244+
IGPUBuffer::SCreationParams params;
245+
params.size = buffer_size;
246+
params.usage = IGPUBuffer::EUF_STORAGE_BUFFER_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT;
247+
buffer = m_device->createBuffer(std::move(params));
248+
if (!buffer)
249+
return logFail("Failed to create GPU buffer of size %d!\n", buffer_size);
250+
251+
buffer->setObjectDebugName(label);
252+
253+
auto reqs = buffer->getMemoryReqs();
254+
reqs.memoryTypeBits &= m_physicalDevice->getHostVisibleMemoryTypeBits();
255+
256+
*allocation = m_device->allocate(reqs, buffer.get(), IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT);
257+
if (!allocation->isValid())
258+
return logFail("Failed to allocate Device Memory compatible with our GPU Buffer!\n");
259+
260+
assert(allocation->memory.get() == buffer->getBoundMemory().memory);
261+
};
262+
263+
auto x = m_physicalDevice->getLimits();
264+
265+
build_buffer(m_device, &allocation, buffer, m_physicalDevice->getLimits().maxSubgroupSize, "Luma Gather Buffer");
266+
}
267+
m_lumaGatherBDA = buffer->getDeviceAddress();
268+
}
269+
230270
// Allocate and Leave 1/4 for image uploads, to test image copy with small memory remaining
231271
{
232272
uint32_t localOffset = video::StreamingTransientDataBufferMT<>::invalid_value;
@@ -347,8 +387,6 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
347387
queue->endCapture();
348388
}
349389

350-
m_computeSubgroupSize = m_physicalDevice->getLimits().maxComputeWorkgroupSubgroups;
351-
352390
return true;
353391
}
354392

@@ -487,8 +525,8 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
487525
smart_refctd_ptr<IWindow> m_window;
488526
smart_refctd_ptr<CSimpleResizeSurface<CDefaultSwapchainFramebuffers>> m_surface;
489527

490-
// constants
491-
uint32_t m_computeSubgroupSize = 0;
528+
// luma gather
529+
uint64_t m_lumaGatherBDA;
492530
};
493531

494532
NBL_MAIN_FUNC(AutoexposureApp)
@@ -531,20 +569,6 @@ int main()
531569
if (!device)
532570
return 1; // could not create selected driver.
533571

534-
QToQuitEventReceiver receiver;
535-
device->setEventReceiver(&receiver);
536-
537-
IVideoDriver* driver = device->getVideoDriver();
538-
539-
nbl::io::IFileSystem* filesystem = device->getFileSystem();
540-
IAssetManager* am = device->getAssetManager();
541-
542-
IAssetLoader::SAssetLoadParams lp;
543-
auto imageBundle = am->getAsset("../../media/noises/spp_benchmark_4k_512.exr", lp);
544-
545-
auto glslCompiler = am->getCompilerSet();
546-
const auto inputColorSpace = std::make_tuple(inFormat,ECP_SRGB,EOTF_IDENTITY);
547-
548572
using LumaMeterClass = ext::LumaMeter::CLumaMeter;
549573
constexpr auto MeterMode = LumaMeterClass::EMM_MEDIAN;
550574
const float minLuma = 1.f/2048.f;

0 commit comments

Comments
 (0)