07bc4e2f96
I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027.
86 lines
2 KiB
GLSL
86 lines
2 KiB
GLSL
/* clang-format off */
|
|
[compute]
|
|
|
|
#version 450
|
|
|
|
VERSION_DEFINES
|
|
|
|
#define BLOCK_SIZE 8
|
|
|
|
layout(local_size_x = BLOCK_SIZE, local_size_y = BLOCK_SIZE, local_size_z = 1) in;
|
|
/* clang-format on */
|
|
|
|
shared float tmp_data[BLOCK_SIZE * BLOCK_SIZE];
|
|
|
|
#ifdef READ_TEXTURE
|
|
|
|
//use for main texture
|
|
layout(set = 0, binding = 0) uniform sampler2D source_texture;
|
|
|
|
#else
|
|
|
|
//use for intermediate textures
|
|
layout(r32f, set = 0, binding = 0) uniform restrict readonly image2D source_luminance;
|
|
|
|
#endif
|
|
|
|
layout(r32f, set = 1, binding = 0) uniform restrict writeonly image2D dest_luminance;
|
|
|
|
#ifdef WRITE_LUMINANCE
|
|
layout(set = 2, binding = 0) uniform sampler2D prev_luminance;
|
|
#endif
|
|
|
|
layout(push_constant, binding = 1, std430) uniform Params {
|
|
ivec2 source_size;
|
|
float max_luminance;
|
|
float min_luminance;
|
|
float exposure_adjust;
|
|
float pad[3];
|
|
}
|
|
|
|
params;
|
|
|
|
void main() {
|
|
uint t = gl_LocalInvocationID.y * BLOCK_SIZE + gl_LocalInvocationID.x;
|
|
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
|
|
|
|
if (any(lessThan(pos, params.source_size))) {
|
|
#ifdef READ_TEXTURE
|
|
vec3 v = texelFetch(source_texture, pos, 0).rgb;
|
|
tmp_data[t] = max(v.r, max(v.g, v.b));
|
|
#else
|
|
tmp_data[t] = imageLoad(source_luminance, pos).r;
|
|
#endif
|
|
} else {
|
|
tmp_data[t] = 0.0;
|
|
}
|
|
|
|
groupMemoryBarrier();
|
|
barrier();
|
|
|
|
uint size = (BLOCK_SIZE * BLOCK_SIZE) >> 1;
|
|
|
|
do {
|
|
if (t < size) {
|
|
tmp_data[t] += tmp_data[t + size];
|
|
}
|
|
groupMemoryBarrier();
|
|
barrier();
|
|
|
|
size >>= 1;
|
|
|
|
} while (size >= 1);
|
|
|
|
if (t == 0) {
|
|
//compute rect size
|
|
ivec2 rect_size = min(params.source_size - pos, ivec2(BLOCK_SIZE));
|
|
float avg = tmp_data[0] / float(rect_size.x * rect_size.y);
|
|
//float avg = tmp_data[0] / float(BLOCK_SIZE*BLOCK_SIZE);
|
|
pos /= ivec2(BLOCK_SIZE);
|
|
#ifdef WRITE_LUMINANCE
|
|
float prev_lum = texelFetch(prev_luminance, ivec2(0, 0), 0).r; //1 pixel previous exposure
|
|
avg = clamp(prev_lum + (avg - prev_lum) * params.exposure_adjust, params.min_luminance, params.max_luminance);
|
|
#endif
|
|
imageStore(dest_luminance, pos, vec4(avg));
|
|
}
|
|
}
|