i’m giving myself some exercises to learn hlsl. Yesterday I was thinking about a ConnectAll ComputeShader.
While the CPU approach is quite straight forward iterating…
FOutput.SliceCount = SpreadMax * (SpreadMax-1);
int k = 0;
for (int i = 0; i < SpreadMax; i++){
for(int j = 1 + i; j < SpreadMax; j++){
FOutput[k](k) = FInput[i](i);
k++;
FOutput[k](k) = FInput[j](j);
k++;
}
}
… I wonder how it is done when everything is threaded and gets calculated at the same time.
Is it even possible to access the other vertices that are running on the other threads? Thats the moment where the dog on the gpu bites his own tail I guess?
- include "particle_struct.fxh"
StructuredBuffer<particle> particles; // particle input
AppendStructuredBuffer<particle> Output : BACKBUFFER; // particle output
[numthreads(128,1,1)](numthreads(128,1,1))
void CSConnectAll(uint3 index : SV_DispatchThreadID)
{
uint size, stride;
particles.GetDimensions(size, stride);
//getting other particle positions and append them
Output.Append(particles[index.x](index.x));
}
technique10 Connect
{
pass P0
{
SetComputeShader( CompileShader( cs_5_0, CSConnectAll() ) );
}
}
(I’m trying this with particles, and yes, I’m aware that the result amount of particles would be n*(n-1) :-).)
But there are also some even more basic questions. Maybe thats just not a task for the GPU? Maybe it’s better to create the vertices (and lines) directly in GeometryShader?
hi. sry did’t head time to write proper answer before
it’s ok task for gpu, and yes u have to create lines in GeometryShader
in general there are few options u can create every line, then discards ones that are not passed test
the input-stream (as a LineList) lets me access the position of 2 vertices - but not all of them to connect them all?
My initial idea was to generate “pairs” of vertices in a ComputeShader and then send them to the rendering pipeline.
So, is there a way to get all the vertices diretly in GS? That basically would change my understanding of this stage ;-).
(by the way, any book recommondations to dx11? thinking of this one: Amazon.com)
u need to replace inout LineStream with TriangleStream
since u can’t use linestram to draw triangles u also gonna need to maintain proper input for triangle steam
otherwise u need second geometry shader that will convert linestream to triangle steam.
usually i just take GS quad code and offset the vertices of the quad
since u know a bit programming might u can check this one
can’t figure out how to assign ouputs for the pins
the idea is suppa simple u got spread of textures and spread of binsizes u want to split them across pins… however changing this part to tex in my patch prolly way to go…
Thanks again, antokhio,
either I still don’t get it or we missunderstood each other :).
I don’t want to draw triangles; I want to connect every vertex with every vertex - like the good’ol connectall-(3d-vector).
here is a bruteforce way that actually worked for me once:
your positions are in a buffer(N), dispatch N*N vertices (with NullGeometry node), draw lines in GS from (i%N) to (i/N)
that way you’ll cover all combinations (any vertex connected to every other vertex)
i mean - you only read two positions in GS and drawing one line, no loops. and since you dispatch N*N of them (and by that getting all possible pairs), all lines will drawn in the end. twice :D
@vux: the thing is, since the particle-positions already are in a StructuredBuffer, I didn’t want to pull them back to cpu again. And the other reason for doing this on gpu was learning purpose :).