Skip to content

Commit f1e3e98

Browse files
committed
Fix luma_meter
1 parent 4edd38c commit f1e3e98

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

include/nbl/builtin/hlsl/luma_meter/luma_meter.hlsl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ struct geom_meter {
105105
float_t lumaSum = reduction(luma, sdata);
106106

107107
if (tid == GroupSize - 1) {
108-
uint32_t3 workgroupSize = glsl::gl_WorkGroupSize();
109-
uint32_t workgroupIndex = dot(uint32_t3(workgroupSize.y * workgroupSize.z, workgroupSize.z, 1), glsl::gl_WorkGroupID());
108+
uint32_t3 workgroupCount = glsl::gl_NumWorkGroups();
109+
uint32_t workgroupIndex = (workgroupCount.x * workgroupCount.y * workgroupCount.z) / 64;
110110

111111
uploadFloat(
112112
val,
@@ -122,8 +122,8 @@ struct geom_meter {
122122
NBL_REF_ARG(ValueAccessor) val
123123
)
124124
{
125-
uint32_t tid = workgroup::SubgroupContiguousIndex();
126-
float_t lumaSum = glsl::subgroupAdd(
125+
uint32_t tid = glsl::gl_SubgroupInvocationID();
126+
float_t luma = glsl::subgroupAdd(
127127
downloadFloat(
128128
val,
129129
tid,
@@ -132,7 +132,10 @@ struct geom_meter {
132132
)
133133
);
134134

135-
return lumaSum;
135+
uint32_t3 workGroupCount = glsl::gl_NumWorkGroups();
136+
uint32_t fixedPointBitsLeft = 32 - uint32_t(ceil(log2(workGroupCount.x * workGroupCount.y * workGroupCount.z))) + glsl::gl_SubgroupSizeLog2();
137+
138+
return (luma / (1 << fixedPointBitsLeft)) / sampleCount;
136139
}
137140

138141
float_t sampleCount;

0 commit comments

Comments
 (0)