Fix incorrect workgroupBarrier and OOB array access in auto_exposure (#13283)

This commit fixes two issues in auto_exposure.wgsl:
* A `storageBarrier()` was incorrectly used where a `workgroupBarrier()`
should be used instead;
* Resetting the `histogram_shared` array would write beyond the 64th
index, which is out of bounds.

## Solution

The first issue is fixed by using the appropriate workgroupBarrier
instead;
The second issue is fixed by adding a range check before setting
`histogram_shared[local_invocation_index] = 0u`.

## Testing

These changes were tested using the Xcode metal profiler, and I could
not find any noticable change in compute shader performance.
This commit is contained in:
Bram Buurlage 2024-05-13 01:24:58 +02:00 committed by GitHub
parent de7ff295e1
commit bfc13383e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -95,10 +95,12 @@ fn compute_histogram(
@builtin(local_invocation_index) local_invocation_index: u32 @builtin(local_invocation_index) local_invocation_index: u32
) { ) {
// Clear the workgroup shared histogram // Clear the workgroup shared histogram
if local_invocation_index < 64 {
histogram_shared[local_invocation_index] = 0u; histogram_shared[local_invocation_index] = 0u;
}
// Wait for all workgroup threads to clear the shared histogram // Wait for all workgroup threads to clear the shared histogram
storageBarrier(); workgroupBarrier();
let dim = vec2<u32>(textureDimensions(tex_color)); let dim = vec2<u32>(textureDimensions(tex_color));
let uv = vec2<f32>(global_invocation_id.xy) / vec2<f32>(dim); let uv = vec2<f32>(global_invocation_id.xy) / vec2<f32>(dim);