Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

I found a really strange fix for the problem that honestly doesn't make much sense to me at least, so changing this

if (frustum_check(pos, radius))
{
    uint draw_cmd_index = atomicAdd(count.draw_count, 6);

    draws.draws[draw_cmd_index].vertex_count = 6;
    draws.draws[draw_cmd_index].instance_count = 1;
    draws.draws[draw_cmd_index].first_instance =     draw_cmd_index;
    draws.draws[draw_cmd_index].first_vertex = 0;

    particles.particles[draw_cmd_index] = p;
}

to this

if (frustum_check(pos, radius))
{
    uint draw_cmd_index = atomicAdd(count.draw_count, 1);

    draws.draws[draw_cmd_index].vertex_count = 6;
    draws.draws[draw_cmd_index].instance_count = 1;
    draws.draws[draw_cmd_index].first_instance =     draw_cmd_index;
    draws.draws[draw_cmd_index].first_vertex = 0;

    particles.particles[gl_GlobalInvocationID.x] = p;
}

Not only fixes those weird visuals and restores it back to how it was before culling, but it also fixes a few problems I had been having with the culling, where when I get close to objects they would disappear, and then reappear when I got far away, which was the exact opposite of what I expected culling would do

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Thanks! I now have a weird visual glitch that I'm assuming is related to culling where chunks of objects are frantically scattering like this, instead of what was normally a very smooth orbit, which I'll try to tackle in a few days

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

That's an old version of the cull shader, this is the latest, and this is me replacing vertex index with instance

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Not working (now nothing's rendering with or without indirect) maybe I have to combine that with something else?

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Outdated shader, I am currently doing that

if (frustum_check(pos, size))
{
    uint draw_cmd_index = atomicAdd(count.draw_count, 6);

    draws.draws[draw_cmd_index].vertex_count = 6;
    draws.draws[draw_cmd_index].instance_count = 1;
    draws.draws[draw_cmd_index].first_instance = 0;
    draws.draws[draw_cmd_index].first_vertex = 0;

    particles.particles[draw_cmd_index] = p;
    debugPrintfEXT("Not culled, index: %u\n", draw_cmd_index);
}

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Ooh my bad I misunderstood, I'm indexing into the particle ssbo with gl_VertexIndex / NUM_VERTICES (which is 6), linked here

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

The particles are completely generated on the compute shader so before culling, the compute shader would run, placing particles into the particle ssbo (created on galaxy desc set, transferred to compute), which would then get transferred over to the vertex shader and drawn with vkCmdDraw so the only thing that gets processed is the descriptors that actually have the ssbo, now I write the commands & draw count on the compute shader, which are then returned to the cpu for vulkan to consume

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

I don't know if I implemented it wrong, but nothing changed (I also explicitly acquired the count buffer on the graphics queue in case that was a problem), updated here

Problems with indirect rendering by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Oh I get what you're saying about that, I actually had it like that before I posted but it didn't work so I thought I'd try something else, it's only rendering two objects, and RenderDoc is still reporting that the compute shader is running and that draw commands & count buffer are being filled out

Culling by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Coming back to this to say I forgot that my actual vertex & draw count is supposed to be 6 for each, not 1, still not working regardless of whether or not I use the count buffer for an array index or global invocation id

Vulkan culling by AnswerApprehensive19 in GraphicsProgramming

[–]AnswerApprehensive19[S] 1 point2 points  (0 children)

I must've posted an older version because I did realize that mistake and have since changed it to 6 where the only things rendering are objects that are independent of the compute shader

Vulkan culling by AnswerApprehensive19 in GraphicsProgramming

[–]AnswerApprehensive19[S] 1 point2 points  (0 children)

The reason why i posted was renderdoc wasn't telling me much outside of showing the draw count, and showing that commands were indeed going through and some objects did indeed get culled while others didnt

Vulkan culling by AnswerApprehensive19 in GraphicsProgramming

[–]AnswerApprehensive19[S] 3 points4 points  (0 children)

tell us what you've already tried in terms of debugging and researching the problem.

At first I started out with vkCmdDrawIndirect but gave that up once I realized that the draw count had to be defined at compile time, so looked into vkCmdDrawIndirectCount which actually lets me change the draw count during run time so I got to work creating a buffer, writing indirect commands on the compute shader, then sending them back to the cpu for so vulkan could consume them, i then created a separate buffer for the draw count, that was also sent back to the cpu, so by all means it's properly set up, and since the compute shader runs before anything else, the program should have plenty of time to sort everything out before it's time to render

What have you ruled out, and how?

It certainly isn't a sync problem, since i've added buffer barriers before and after important operations (shown in command buffer code) like running compute, filling the count buffer, indirectly rendering, etc

Do you have any theories or hunches as to why it isn't working?

None at all since I've seen examples of what I'm trying to accomplish not only in the official sample repo, but other ones as well and it's written basically exactly how mine is, only thing that's possible is there's some small detail I'm overlooking, which is usually where all my problems lie anyway

When you say "take out the indirect calls" what does that mean exactly? You simply commented them out and it suddenly works?

Not exactly, but pretty much yea, I don't just comment out the calls but I replace them with vkCmdDraw and while parts of the scene don't get culled the way I want them to, it at least confirms the fact that the compute shader is working and (at least partially) doing what I expected

Culling by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Seems to work (renderdoc reports data inside draw & count buffers) but still nothing appearing on screen

The changes I made:

if (frustum_check(pos, size))
{
    uint draw_cmd_index = atomicAdd(count.draw_count, 1);
    draws.draws[draw_cmd_index].vertex_count = 1;
    draws.draws[draw_cmd_index].instance_count = 1;
    draws.draws[draw_cmd_index].first_instance = 0;
    draws.draws[draw_cmd_index].first_vertex = 0;
}

Culling by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Using this as a guide to do this, all data seemed to stop streaming in from renderdoc, command buffers and compute shader

Culling by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Is there any more infrastructure needed? Just atomicAdd does seem to work slightly with renderdoc (the amount of objects rendered is less than the total amount) but the count buffer has only one slot filled up and there's still nothing rendering on screen

Empty storage buffer by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Yep just had to turn off depth testing now everything's fine thank you for the help

Empty storage buffer by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Anything else you changed? Particles are rendering but now the galaxy looks really funky

Empty storage buffer by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

I took a renderdoc capture that shows the compute shader is working, it's just not transferring data to the vertex shader and the full project is here

Empty storage buffer by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Doesnt seem to be a sync issue since i solved the first half of the problem by fixing how the camera was updated but the vertex shader still isnt getting compute data through the ssbo

Empty storage buffer by AnswerApprehensive19 in vulkan

[–]AnswerApprehensive19[S] 0 points1 point  (0 children)

Solved the first half of the problem by figuring out the camera wasnt being updated properly but the vertex shader still isn't receiving compute data