I am starting with compute shaders, watched the NODE 17 workshop with vux? I believe on YT. Now I am stuck at the following problem:
I do hitdetection on a depthstream. 16 areas, each of them with a Z min max threshold. I have a function that checks if there are pixels within each of those 16 regions, then writes 1 - respectively 0 into that int Array[16]. These are my buttons.
But I have no clue on how to get my data back, since I can’t use tid.xy.
So any tips appreciated! also on the general structure.
you did’t add the texture in there
and also if you use tid.xy you most likely have a two dimensional array mining that your output would be like thath:
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
so when you readback it turns to one dimensinal array eg. 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
most likely you need to do some extra work to map this to one dimensional structure, or you need to readback the whole thing, arrange in 2d grid and check…
Second one, when you do an append buffer, you have to keep in mind that, buffer would be created on total amount of elements, and then, there is underhood logic witch then decides witch slice to keep, and witch one to pass (like dispatch indirect args buffer), since readback reads raw buffer without any flags you can expect that your buffer size is going to be total amount of elements, not only appended elements…
Thing to note here also, that AppendBuffer not gonna give you values in order… If you do 0,1,2,3 you will get 3, 1 , 0, 2 back, that’s way AppendBuffer is also called un-ordered array…
Think there is also something like CopyCounter, if you readback it, it will give you real size of the buffer
thanks for the extensive answer. I get how XY threading translates to a one dimensional buffer.
But I think can’t readback the whole array since it’s too large? I mean that would be all the pixels I analyze.
I want to readback as few as possible.
So is the trick so use tid.xy to write my int[16] array to specific locations within the buffer and readback just these? Or use an array size for my button hits that works with my threading size?
Anyways, all i can say, is that i prolly would be able to make it work, after watching vuxes tutorial, but that’s not the most easy one for a compute starter, i suspect there is few stuff missing around, like there is ThreadGroups defined, but never used, and such example is most likely to show how thread group works…
Anyways, i’ve woul love to look in to this more time, but i have some urgent stuff to do, maybe tomorrow if i get some time…
no, please ignore that. I was just playing around with the append buffer trying to get something out of the shader. Basically all I want to readback is a float or bool for each of those 16 hitAreas.
thanks for your help, which is always appreciated.
this is not urgent, just want to dig a little bit into CS. book of shaders, shadertoy, rastertek and the old and trusty book by Paul Varcholik have no cs tutorials, so also happy if you have some good resources to learn.