I am attempting to implement a simple compute operation of multiplying all values in a buffer by a push constant.
This shader:
#version 450
layout(local_size_x = 1024, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0) buffer Buffer { float x[]; };
layout(push_constant) uniform PushConsts { float a; };
void main() {
x[gl_GlobalInvocationID.x] *= a;
}
In my current implementation from my prints I get:
in:
1 2 3 4 5 5 4 3 2 1
[7]
workgroups: (1,1,1)
out:
7 14 3 4 5 5 4 3 2 1
1 2 3 4 5 5 4 3 2 1
being the initial values of the buffer.7
being the value of the push constant.(1,1,1)
being the number of workgroups set.7 14 3 4 5 5 4 3 2 1
being the resultant values of the buffer after execution.
Strangely only the 1st 2 values have been multiplied by the push constant (which leads me to think only the 1st 2 invocations ran). I suspect this is likely an issue with memory allocation, although I don’t know where it may be coming from.
I would greatly appreciate any help, and if there is anything I can do to make this post better please let me know.
Project link, code file link and the .spv files (.comp
files are in the repo, but I thought it worth including these in case you didn't want to compile the .comp
files)