Files
unkernel/test/vk/host/shaders/shared512fn.comp

24 lines
656 B
Plaintext

// SPDX-License-Identifier: MIT
// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
#version 450
// shared512.comp with the barrier in a function of its own (SPIR-V not
// inlined): the translator's virtual invocations do not take barriers
// outside the entry point, so on a device allowing 256 there is no
// pipeline.
layout(local_size_x = 512) in;
layout(set = 0, binding = 0) buffer B { float v[]; } b;
shared float s[512];
void reduce(uint i) {
for (uint k = 256u; k > 0u; k >>= 1) {
if (i < k) s[i] += s[i + k];
barrier();
}
}
void main() {
uint i = gl_LocalInvocationID.x;
s[i] = b.v[i];
barrier();
reduce(i);
if (i == 0u) b.v[0] = s[0];
}