r/vulkan 2d ago

Everything renders fine until vkQueuePresentKHR, where 3D disappears.

tldr:

3D objects won't appear on the window, yet RenderDoc shows everything renders and presents fine.

Cry for help:

I'm capturing with RenderDoc and can see that everything renders and presents fine, yet the 3D objects are missing after presenting the image on the window. Here's the capture file if you wish to check it out. To see what's actually shown on the window, you can extract the capture's thumbnail with: renderdoccmd thumb capture.rdc --out thumbnail.png

I've been on this for days and am finally relenting to reddit.

If anyone has seen this before, has ideas, or leads on how I could debug this, anything would be appreciated.

If you decide to delve deep within the capture file, take note this is a test program running on a bindless rendering engine.

Setup:

There's a camera with an identity model/view matrix and the following orthogonal matrix:

┌ 0.13636, 0.00000, 0.00000, 0.00000┐
│ 0.00000, 0.18182, 0.00000, 0.00000│
│ 0.00000, 0.00000, 0.00100, 0.00000│
└ 0.00000, 0.00000, 0.00000, 1.00000┘

Then, a blue 2D object is at (0, 0) with a size of (0.5, 0.5) in NDC space.
Finally, a magenta 3D object at (3, 0, 1) with a rotation of (0, 45, 45) degrees.

It has been solved!

My problem was I wasn't synchronizing the update of my camera matrices' buffer and the rendering of 3D objects, which means the projection/view/model multiplications were flawed.

To find it, I had to enable the validation layers' synchronization features, validate_sync and syncval_shader_accesses_heuristic.

If you end up in my position and want to enable them, go read this:
https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/docs/khronos_validation_layer.md#configuring-the-validation-layer

2 Upvotes

14 comments sorted by

4

u/Chainsawkitten 1d ago

If it renders fine in RenderDoc but not outside, my usual assumption is incorrect synchronization/cache flushing/layout transitions.

1

u/Due-Baby9136 1d ago

I'm synchronising my submit and present with a semaphore. As far as I know that should be enough, right?

2

u/Chainsawkitten 1d ago

You need:

  • Barriers between any uses of resources (unless both uses are read-only).
  • Image transition when using images in different ways. Nowadays you can use unified image layouts to reduce the need for this (but you still need a transition to/from PRESENT_SRC).
  • Semaphore to make sure the acquired swapchain image is ready before you start rendering to it.
  • Semaphore to make sure you've finished rendering before presenting.

The validation layers should be able to catch this if you enable synchronization validation (which I believe is off by default).

1

u/Due-Baby9136 1d ago

I've typed my earlier answer a bit too fast. I'm doing a single submit until it works, so my buffers are only used once and are read-only. My images use barriers to transition their layouts, I believe those appear in the renderdoc capture file. The two semaphores, for the swapchain image availability and end of rendering are also present.

As per the validation layers... synchronization validation?!? I shall look at this tonight, I'm sure it'll prove useful.

2

u/Chainsawkitten 1d ago

I haven't been able to look at the RenderDoc capture as they are not portable across GPU vendors.

1

u/Due-Baby9136 1d ago

Thank you very much, it was indeed a synchronization error. I had to enable both validate_sync and syncval_shader_accesses_heuristic, to find there were no synchronization between the update of my camera matrix buffer and the rendering of 3D objects.

5

u/positivcheg 1d ago

Classic question. Validation layers completely 0 errors and warnings?

I usually turn depth test, cull none and things like that. In case if all validation layers are silent.

1

u/Due-Baby9136 1d ago

Yup, validation layers are silent. I hadn't thought of disabling the depth test, but, after trying, it doesn't help.

3

u/No_Celebration8219 2d ago

swap chain setup correctly? is your backbuffer set? Vulkan will render to any attached buffer so make sure you're setting the swapchain correctly.

1

u/Due-Baby9136 2d ago

Yes, it's correctly setup. I've cleared the color attachment to green to prove this. The 2D object also appear. The 3D one is the only one missing.

4

u/imMute 2d ago

Try changing the cullMode OR frontFace settings. They have to match your data ordering or everything will get culled wrong.

2

u/Due-Baby9136 1d ago

I've actually disabled culling entirely.

1

u/Due-Baby9136 1d ago

I've noticed removing the projection matrix of the 3D vertex shader let's 3D objects appear, given they end up in the NDC frustum, which is very unlikely without the projection/view/model multiplications.

But the matrix is fine by my knowledge, I think it might be a by-product of the actual problem.

2

u/ParaLizzardo 22h ago

You can try to open vulkan configurator app and crank up the settings for validation layer.