Autoexposure example restoration#137
Autoexposure example restoration#137devshgraphicsprogramming wants to merge 97 commits intomasterfrom
Conversation
…Examples-and-Tests into autoexposure_ex
…Examples-and-Tests into autoexposure_ex
…Examples-and-Tests into autoexposure_ex
…Examples-and-Tests into autoexposure_ex
…Examples-and-Tests into autoexposure_ex
| float meteringWindowScaleX, meteringWindowScaleY; | ||
| float meteringWindowOffsetX, meteringWindowOffsetY; | ||
| float lumaMin, lumaMax; | ||
| uint32_t sampleCountX, sampleCountY; | ||
| uint32_t viewportSizeX, viewportSizeY; | ||
| uint64_t lumaMeterBDA; |
There was a problem hiding this comment.
you should pack these up intro structs in nbl::hlsl::luma_meter and friends
P.S. I see you already have, why not use things like nbl::hlsl::luma_meter::LumaMeteringWindow directly here?
26_Autoexposure/main.cpp
Outdated
| const uint32_t2 dispatchSize = { | ||
| 1 + ((gpuImgExtent.width / 2) - 1) / SubgroupSize, | ||
| 1 + ((gpuImgExtent.height / 2) - 1) / SubgroupSize | ||
| }; |
There was a problem hiding this comment.
Half dispatch with full viewport UV means you sample only the top left quarter, EV is computed from that quarter and then applied to the whole image so exposure drifts when luminance is not uniform
counterexample https://godbolt.org/z/de41xd9ro
26_Autoexposure/main.cpp
Outdated
| inline void workLoopBody() override | ||
| { | ||
| memset(m_gatherMemory, 0, m_gatherBuffer->getSize()); | ||
| memset(m_histoMemory, 0, m_gatherBuffer->getSize()); |
There was a problem hiding this comment.
This typo keeps most bins dirty and EV is biased, use m_histoBuffer->getSize()
counterexample https://godbolt.org/z/Mozo84eYY
| tonemapper::Reinhard<float32_t> reinhard = tonemapper::Reinhard<float32_t>::create(EV, 0.18f, 0.85f); | ||
| float32_t3 tonemappedColor = mul(colorspace::decode::XYZtoscRGB, reinhard(CIEColor)); | ||
|
|
||
| textureOut[pos] = float32_t4(colorspace::oetf::sRGB(tonemappedColor), 1.0f); |
There was a problem hiding this comment.
No bounds guard and we have OOB write. We go 1280x720 and dispatch is ceil(Dimensions/SubgroupSize). With SubgroupSize 32 it is 1280x736 coverage
Nabla-Examples-and-Tests/26_Autoexposure/main.cpp
Lines 841 to 844 in 233db45
There was a problem hiding this comment.
I'm not sure about it, could you please confirm the expected metering region is
Dimensions=(1280,720)
MeteringMinUV=(0.1,0.1)
MeteringMaxUV=(0.9,0.9)
SamplingFactor=2
SubgroupSize=m_physicalDevice->getLimits().subgroupSize
and flow like
meteringUVRange = MeteringMaxUV - MeteringMinUV
dispatchSize = ceil(dim * meteringUVRange / (SubgroupSize * SamplingFactor))
window = create(meteringUVRange / (dispatchSize * SubgroupSize), MeteringMinUV)
sampleLuma(..., tileOffset=WorkGroupID*WorkGroupSize, viewportSize=(texWidth,texHeight))
shiftedCoord = (tileOffset + coord) / viewportSize
https://github.com/Devsh-Graphics-Programming/Nabla/blob/79fad2f7d16ba75347c94a8b4327042b4d786547/include/nbl/builtin/hlsl/luma_meter/geom_mean.hlsl#L126uvPos = shiftedCoord * window.meteringWindowScale + window.meteringWindowOffset
https://github.com/Devsh-Graphics-Programming/Nabla/blob/79fad2f7d16ba75347c94a8b4327042b4d786547/include/nbl/builtin/hlsl/luma_meter/geom_mean.hlsl#L77
we have
dispatchSize=(16,9)windowScale=(0.8/(16*32),0.8/(9*32))=(0.0015625,0.002777...)(tileOffset+coord)spans[0,511]x[0,287]
and then sampled UV is approximately
$uv_x\in[0.100000,0.100624]$ $uv_y\in[0.100000,0.101107]$
this is a tiny rectangle near (0.1,0.1) not the intended (I guess) metering window because the coordinates are effectively normalized twice, first by viewportSize in shiftedCoord = (tileOffset + coord) / viewportSize and then scaled again by windowScale = meteringUVRange / (dispatchSize * SubgroupSize).
| tonemapper::Reinhard<float32_t> reinhard = tonemapper::Reinhard<float32_t>::create(EV, 0.18, 0.85f); | ||
| float32_t3 tonemappedColor = mul(colorspace::decode::XYZtoscRGB, reinhard(CIEColor)); | ||
|
|
||
| textureOut[pos] = float32_t4(colorspace::oetf::sRGB(tonemappedColor), 1.0f); |
…se vulkan should do that
No description provided.