Skip to content

Commit 9c330d3

Browse files
committed
clean up push constant usage, more values in push constant
1 parent a15508e commit 9c330d3

6 files changed

Lines changed: 32 additions & 14 deletions

File tree

26_Autoexposure/app_resources/avg_luma_meter.comp.hlsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
6363
TexAccessor tex;
6464

6565
using LumaMeter = luma_meter::geom_meter< WorkgroupSize, PtrAccessor, SharedAccessor, TexAccessor>;
66-
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax, pushData.sampleCount);
66+
LumaMeter meter = LumaMeter::create(pushData.lumaMin, pushData.lumaMax, pushData.sampleCount, pushData.rcpFirstPassWGCount);
6767

68-
meter.sampleLuma(pushData.window, val_accessor, tex, sdata, (float32_t2)(glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()), pushData.viewportSize);
68+
uint32_t texWidth, texHeight;
69+
texture.GetDimensions(texWidth, texHeight);
70+
meter.sampleLuma(pushData.window, val_accessor, tex, sdata, (float32_t2)(glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()), float32_t2(texWidth, texHeight));
6971
}

26_Autoexposure/app_resources/avg_luma_tonemap.comp.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
6868
TexAccessor tex;
6969

7070
using LumaMeter = luma_meter::geom_meter< WorkgroupSize, PtrAccessor, SharedAccessor, TexAccessor>;
71-
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax, pushData.sampleCount);
71+
LumaMeter meter = LumaMeter::create(pushData.lumaMin, pushData.lumaMax, pushData.sampleCount, pushData.rcpFirstPassWGCount);
7272

7373
float32_t EV = meter.gatherLuma(val_accessor);
7474

26_Autoexposure/app_resources/common.hlsl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ namespace hlsl
1616
struct AutoexposurePushData
1717
{
1818
luma_meter::MeteringWindow window;
19-
float32_t2 lumaMinMax;
20-
float32_t sampleCount;
19+
float32_t lumaMin;
20+
float32_t lumaMax;
2121
uint32_t2 viewportSize;
2222
uint64_t lumaMeterBDA;
23+
24+
// mean only
25+
float32_t sampleCount;
26+
float32_t rcpFirstPassWGCount;
27+
28+
// histogram only
29+
float32_t lowerBoundPercentile;
30+
float32_t upperBoundPercentile;
2331
};
2432

2533
#ifdef __HLSL_VERSION

26_Autoexposure/app_resources/median_luma_meter.comp.hlsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
6969
TexAccessor tex;
7070

7171
using LumaMeter = luma_meter::median_meter< WorkgroupSize, BIN_COUNT, PtrAccessor, SharedAccessor, TexAccessor>;
72-
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax);
72+
LumaMeter meter = LumaMeter::create(pushData.lumaMin, pushData.lumaMax, pushData.lowerBoundPercentile, pushData.upperBoundPercentile);
7373

74-
meter.sampleLuma(pushData.window, histo_accessor, tex, sdata, (float32_t2)(glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()), pushData.viewportSize);
74+
uint32_t texWidth, texHeight;
75+
texture.GetDimensions(texWidth, texHeight);
76+
meter.sampleLuma(pushData.window, histo_accessor, tex, sdata, (float32_t2)(glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize()), float32_t2(texWidth, texHeight));
7577
}

26_Autoexposure/app_resources/median_luma_tonemap.comp.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID)
7575
TexAccessor tex;
7676

7777
using LumaMeter = luma_meter::median_meter< WorkgroupSize, BIN_COUNT, PtrAccessor, SharedAccessor, TexAccessor>;
78-
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax);
78+
LumaMeter meter = LumaMeter::create(pushData.lumaMin, pushData.lumaMax, pushData.lowerBoundPercentile, pushData.upperBoundPercentile);
7979

8080
float32_t EV = meter.gatherLuma(histo_accessor, sdata);
8181

26_Autoexposure/main.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ class AutoexposureApp final : public SimpleWindowedApplication, public BuiltinRe
4141
"app_resources/median_luma_tonemap.comp.hlsl",
4242
"app_resources/present.frag.hlsl"
4343
};
44-
constexpr static inline MeteringMode MeterMode = MeteringMode::MEDIAN;
45-
constexpr static inline uint32_t BinCount = 8000; // TODO: it's 8000 here why? gonna set it to workgroup size (1024) for now
44+
constexpr static inline MeteringMode MeterMode = MeteringMode::AVERAGE;
45+
constexpr static inline uint32_t BinCount = 1024;
4646
constexpr static inline uint32_t2 Dimensions = { 1280, 720 };
4747
constexpr static inline float32_t2 MeteringWindowScale = { 0.8f, 0.8f };
4848
constexpr static inline float32_t2 MeteringWindowOffset = { 0.1f, 0.1f };
49-
constexpr static inline float32_t2 LumaMinMax = { 1.0f / 2048.0f, 65536.f };
49+
constexpr static inline float32_t2 LumaRange = { 1.0f / 2048.0f, 65536.f };
50+
constexpr static inline float32_t2 PercentileRange = { 0.45f, 0.55f };
5051

5152
public:
5253
// Yay thanks to multiple inheritance we cannot forward ctors anymore
@@ -768,10 +769,13 @@ class AutoexposureApp final : public SimpleWindowedApplication, public BuiltinRe
768769
auto pc = AutoexposurePushData
769770
{
770771
.window = hlsl::luma_meter::MeteringWindow::create(MeteringWindowScale, MeteringWindowOffset),
771-
.lumaMinMax = LumaMinMax,
772-
.sampleCount = sampleCount,
772+
.lumaMin = LumaRange.x,
773+
.lumaMax = LumaRange.y,
773774
.viewportSize = Dimensions,
774-
.lumaMeterBDA = (MeterMode == MeteringMode::AVERAGE) ? m_gatherBDA : m_histoBDA
775+
.lumaMeterBDA = (MeterMode == MeteringMode::AVERAGE) ? m_gatherBDA : m_histoBDA,
776+
.sampleCount = sampleCount,
777+
.lowerBoundPercentile = PercentileRange.x,
778+
.upperBoundPercentile = PercentileRange.y
775779
};
776780

777781
// Luma Meter
@@ -786,6 +790,8 @@ class AutoexposureApp final : public SimpleWindowedApplication, public BuiltinRe
786790
1 + ((gpuImgExtent.height / 2) - 1) / SubgroupSize
787791
};
788792

793+
pc.rcpFirstPassWGCount = 1.f / float(dispatchSize.x * dispatchSize.y);
794+
789795
cmdbuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
790796
cmdbuf->bindComputePipeline(m_meterPipeline.get());
791797
cmdbuf->bindDescriptorSets(nbl::asset::EPBP_COMPUTE, m_meterPipeline->getLayout(), 0, 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

0 commit comments

Comments
 (0)