Skip to content

Commit 33ed235

Browse files
committed
Merge branch 'rgb19e7-bug' into spirv-optimizer
2 parents ff1f979 + 1f334b8 commit 33ed235

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,4 @@ int main()
313313
renderer = nullptr;
314314

315315
return 0;
316-
}
316+
}

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ layout(set = 1, binding = 5, std430, row_major) restrict readonly buffer LightRa
138138
vec3 fetchAccumulation(in ivec2 coord)
139139
{
140140
const uvec2 data = imageLoad(accumulation,coord).rg;
141-
return vec4(unpackHalf2x16(data[0]),unpackHalf2x16(data[1])).rgb;
142-
//return nbl_glsl_decodeRGB19E7(data);
141+
//return vec4(unpackHalf2x16(data[0]),unpackHalf2x16(data[1])).rgb;
142+
return nbl_glsl_decodeRGB19E7(data);
143143
}
144144
void storeAccumulation(in vec3 color, in ivec2 coord)
145145
{
146-
//const uvec2 data = nbl_glsl_encodeRGB19E7(color);
147-
const uvec2 data = uvec2(packHalf2x16(color.rg),packHalf2x16(vec2(color.b,1.0)));
146+
const uvec2 data = nbl_glsl_encodeRGB19E7(color);
147+
//const uvec2 data = uvec2(packHalf2x16(color.rg),packHalf2x16(vec2(color.b,1.0)));
148148
imageStore(accumulation,coord,uvec4(data,0u,0u));
149149
}
150150

include/nbl/builtin/glsl/format/constants.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#define nbl_glsl_RGB19E7_EXP_BIAS 63
99
#define nbl_glsl_MAX_RGB19E7_EXP (nbl_glsl_RGB19E7_EXP_BIAS+1)
1010

11-
#define MAX_RGB19E7_MANTISSA_VALUES (0x1<<nbl_glsl_RGB19E7_MANTISSA_BITS)
12-
#define MAX_RGB19E7_MANTISSA (MAX_RGB19E7_MANTISSA_VALUES-1)
13-
#define nbl_glsl_MAX_RGB19E7 float(MAX_RGB19E7_MANTISSA)/float(MAX_RGB19E7_MANTISSA_VALUES)*exp2(float(nbl_glsl_MAX_RGB19E7_EXP-nbl_glsl_RGB19E7_MANTISSA_BITS))
11+
#define nbl_glsl_MAX_RGB19E7_MANTISSA_VALUES (0x1<<nbl_glsl_RGB19E7_MANTISSA_BITS)
12+
#define nbl_glsl_MAX_RGB19E7_MANTISSA (nbl_glsl_MAX_RGB19E7_MANTISSA_VALUES-1)
13+
#define nbl_glsl_MAX_RGB19E7 float(nbl_glsl_MAX_RGB19E7_MANTISSA)/float(nbl_glsl_MAX_RGB19E7_MANTISSA_VALUES)*exp2(float(nbl_glsl_MAX_RGB19E7_EXP-nbl_glsl_RGB19E7_MANTISSA_BITS))
1414

1515
#define nbl_glsl_RGB19E7_COMPONENT_INDICES ivec4(0,0,1,1)
1616
#define nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS ivec4(0,nbl_glsl_RGB19E7_MANTISSA_BITS,(2*nbl_glsl_RGB19E7_MANTISSA_BITS)&31,(3*nbl_glsl_RGB19E7_MANTISSA_BITS)&31)

include/nbl/builtin/glsl/format/encode.glsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ uvec2 nbl_glsl_encodeRGB19E7(in vec3 col)
99
const float maxrgb = max(max(clamped.r,clamped.g),clamped.b);
1010

1111
const int f32_exp = ((floatBitsToInt(maxrgb)>>23) & 0xff) - 127;
12-
const int shared_exp = clamp(f32_exp,-nbl_glsl_RGB19E7_EXP_BIAS-1,nbl_glsl_MAX_RGB19E7_EXP) + 1;
13-
14-
const uvec3 mantissas = uvec3(clamped*exp2(nbl_glsl_RGB19E7_MANTISSA_BITS-shared_exp) + 0.5);
12+
int shared_exp = clamp(f32_exp,-nbl_glsl_RGB19E7_EXP_BIAS-1,nbl_glsl_MAX_RGB19E7_EXP) + 1;
13+
14+
float scale = exp2(nbl_glsl_RGB19E7_MANTISSA_BITS - shared_exp);
15+
const uint maxm = uint(maxrgb*scale + 0.5);
16+
const bool need = (maxm == nbl_glsl_MAX_RGB19E7_MANTISSA_VALUES);
17+
scale = need ? 0.5*scale : scale;
18+
shared_exp = need ? (shared_exp+1) : shared_exp;
19+
const uvec3 mantissas = uvec3(clamped*scale + 0.5);
1520

1621
uvec2 encoded;
1722
encoded.x = bitfieldInsert(mantissas.x,mantissas.y,nbl_glsl_RGB19E7_COMPONENT_BITOFFSETS[1],nbl_glsl_RGB19E7_G_COMPONENT_SPLIT);

0 commit comments

Comments
 (0)