- "sum" array: each element should be 64 multiplied by the element's index, so multiples of 64 going from 0 to 4032; works as expected

- "data" array: each element of the array should be equal exactly to its index, going from 0 to 4095. Does not work quite as expected.

Shader objective: data-wide scan

Shader logic: in each of the wavefronts, we run an exclusive scan, result being 0..63 in each wavefront. To modify each wavefront to a correct value, we also take sum of every wavefront(64), write it to "sum" array(64 values equal to 64 each), and run a scan over that(0,64,...4032), to get the values that should be added to each of the wavefronts to bump them up to desired values and thus get our datawide scan.And here's where the interesting stuff happens.

It seemed sensible to me to run the scan over the "sum" array in a single block, and I put the appropriate line of code inside an if block, tasking the very first block with this calculation(in the shader code you see the fourth block).

And here's the crux of the whole thing: only the block that you specify will have expected values; every other block will output 64..127, ignoring the last line of code. If the if block is removed, resulting outputs are as expected, "data" array being 0..4095.

I'm not ready to blame any compiler or driver involved, but I have a very hard time making sense of this situation. It's unobvious to me how this shader code could be incorrect.

I've tried to set this whole thing up as helpful and easy to use and understand as I could, the git repo has my (somewhat) minimal Vulkan setup for a compute shader execution and a Visual Studio solution file that will get you straight to the breakpoint and arrays warranting inspection.If you need more details, please ask and I'll do my best to be of further help.

and use this function `get_by_index()` in your code everywhere, instead of `data[global]` will be `get_by_index(global)`

this fix my code in that link on AMD

I see that you have 4k array size, it may be bad to create thislarge switch for every used array...

from my experience with AMD Vulkan I saw that getting arrays from texture(`texelFetch()`) work correct, when uniform/push_const does not

so this is option 2 is - send you array as Sampler2D and get it by `texelFetch()` in shader

summary, ways to fix it:

1. GLSL(not SPIRV) shaders in OpenGL in AMD do work correct, when SPIRV shaders in Vulkan are broken.(not just this bug, lots of bugs, I say every non linear logic shader in AMD Vulkan may trigger UB randomly, too many bugs) (check my other bugs, my 2k+ lines of code shaders do not work in AMD or trigger UB in process(when in OpenGL they do work on same AMD))

2. this is only Windows bug, AMD Vulkan drivers in Linux do work correct with this shaders, and my bugs does not work on Linux.

3. use Nvidia, shaders do not have bugs there, I test my self everything

4. use listed above "tricks" that may fix this bug for you(and you maybe get stuck with other bug) that `switch` that return array static index, or `texelFetch`