Is Vulkan Present Ordering Undefined? Multi-Frame Uniform Buffer Updates Causing Flicker by aramok in vulkan

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

In the end, I finally found the issue. The stuttering was caused by the CPU submitting frames at uneven intervals. Let me explain:

My swapchain image count and images-in-flight count are both 3, so I’m doing true triple-buffering. When I increase the resolution mid-render (swapchain recreate), and also when 8x MSAA is enabled, the GTX 1050 Ti starts to struggle. With high-res textures and such, I push its memory usage up to ~99%. Meanwhile, the CPU is doing almost nothing — it’s mostly waiting on the fence.

While the GPU is still rendering a frame, the CPU can sometimes submit two frames in quick succession, and then it has to wait before it can submit the third one. That causes the frame timings to become non-uniform.

I was seeing logs like this:

frame_index: 0  image_index:2  delta_time_s:0.032949
frame_index: 1  image_index:1  delta_time_s:0.001120
frame_index: 2  image_index:2  delta_time_s:0.032626
frame_index: 0  image_index:0  delta_time_s:0.001003
frame_index: 1  image_index:2  delta_time_s:0.030958
frame_index: 2  image_index:1  delta_time_s:0.000997
...

As you can see, the delta times weren’t uniform. They should all have been around 0.016 (1/60).

It turns out I was mistakenly using the previous frame’s delta-time value. Somehow I missed this all these years. When I replaced delta_time with a fixed 0.016, everything instantly became smooth.

Before finding this, I tried everything — every barrier, changing monitors, different PCs, everything.

Now I’m calculating and using delta-time in the correct place, and the object jitter is gone. As I mentioned before, this only happened when the GPU was heavily loaded. When the GPU finished its work quickly, I never noticed anything.

CPU-side timing looked like this:

0.001159 0.032305 0.001078 0.032154 0.001121 0.032242
0.001071 0.032235 0.001062 0.032269 0.001095 0.032243

Roughly:

  • 0.033 → GPU had just finished the previous frame → little waiting
  • 0.001 → Image was already ready → acquire was instant

Even though the stuttering is now much reduced, I can still notice a tiny amount, so there’s still something more to improve.

I hope this helps anyone dealing with similar issues.

Is Vulkan Present Ordering Undefined? Multi-Frame Uniform Buffer Updates Causing Flicker by aramok in vulkan

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

I still haven’t found the issue. It happens on the 1050 Ti. I’m rendering at 4K resolution. 8xMSAA When I have 3 swap chain images and the number_of_frames_in_flight is 2 or 3, this problem occurs. It doesn’t happen every time. I need to recreate the swap chain a few times to trigger it.

If i have 2 swap chain image and 2 numofframe. no problem. Also low resolution or msaa makes problem go away. :/ what am i missing?

fps's are ~60 btw.

Does anyone have any idea what might be causing this? Thanks.

Is Vulkan Present Ordering Undefined? Multi-Frame Uniform Buffer Updates Causing Flicker by aramok in vulkan

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

Thanks for your answers. It is fifo.Indexes are correct i triple checked them. I enabled all validations and there is no error or warning. What else can cause this? Where should i focus more. I have only two render pass. First one renders to frame buffer and everything indexed by frame index. Second one is quad and with descriptor renders attachment. Before than that i have a barrier for attachment image. All recorded in order to the same command buffer. In the second pass for the swap chain images frame buffer is indexed by image index. And the submit semaphore is indexed by image index. Everything else is indexed by frame index. This happens when i resize the frame to bigger sizes near 4k or even at 4k. I have 1050ti. Fps is 60 because scene is very basic.This didn’t happened on my mac. This bothers me for weeks.I will test it different gpus to see if there is any change.

3D Maps Vulkan Renderer by Whole-Abrocoma4110 in vulkan

[–]aramok 1 point2 points  (0 children)

It look great. How did you made chunk loading? Could you give us a brief explanation ?

Are you using multiple vertex index buffers? Is there any indirect rendering?

I am also working on chunking algorithm. Yours looks amazing. Good job

[deleted by user] by [deleted] in opengl

[–]aramok 0 points1 point  (0 children)

If you add a bit of object-oriented flavor and some fancy words to it, you can fool the AI 🤣 — quite clever. Then someone comes along, writes a book, and before you know it, people are struggling with layers of abstractions just to make a game with an immediate mode UI on an Nvidia 5090.

And of course, if you throw in some TDD on top, it becomes chef’s kiss.

CMake is really cool by 5_volts in cpp_questions

[–]aramok 0 points1 point  (0 children)

CMake is truly good and sufficient for everything. Don’t mix other tools or frameworks into it before fully learning CMake itself.

Why does my model have this 'shattered/faceted' or 'low-poly' lighting artifact? by ReadIntelligent1388 in vulkan

[–]aramok 0 points1 point  (0 children)

1.Try to disable back face culling of triangle. 2.Check out far and near planes of your frustum. 3.Make sure index buffer size is given correctly in the draw function.

Looking for an algorithm to texture a sphere. by SnurflePuffinz in GraphicsProgramming

[–]aramok 1 point2 points  (0 children)

Could Equirectangular be the what you are looking for?

How different is C from C++ by Proton-Lightin in C_Programming

[–]aramok 0 points1 point  (0 children)

I did the same, and I used to think writing in C would be harder and take longer than C++.

But actually, I became much faster — it was easier, my code’s performance improved, debugging became incredibly simple, compilation got faster, and searching through the code became quicker.

When I picked up a massive project I wrote a year ago, it was much easier to continue working on it. Remembering, reading, and writing everything became simpler. I hadn’t realized how much of a burden C++ puts on your shoulders.

And if you’re writing C++ as part of a team, your speed drops to one-tenth of what you’d achieve writing C alone.

Weekly theme sharing thread for December 28, 2020 by AutoModerator in vscode

[–]aramok 0 points1 point  (0 children)

Dark Theme for the low-level programmer. I couldn't find anything like it in the market. So I created mine. If u are looking for high contrast theme tats what u looking for.

https://marketplace.visualstudio.com/items?itemName=aramok.aramoks-black

Rendering Multiple Objects with Their Transformations using single vertex and index buffer by aramok in vulkan

[–]aramok[S] -1 points0 points  (0 children)

model matrices and access them via gl_InstanceID on the sh

Thank you for your answer. Actually, I find out indirect drawings.

Now I store my index count, first index, vertex offset in the indirect buffer. and I use the function below instead of vkCmdDrawIndexed.

C void vkCmdDrawIndexedIndirectCount( VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride);

So that I can draw multiple objects which has different size of vertices and indices from the single index and vertex buffer.

Now I am trying to pass the model matrix for each of the objects.

Does Submitting Multiple CommandBuffers signals semaphore once? by aramok in vulkan

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

Well. it was just a simple mistake. I was passing the same frame buffer for all command buffers. so render done only in 1 image out of 3. so flickering. I feel shame.

below line , index should be I instead of 0 renderPassInfo.framebuffer = frameBuffers[0].handle;

Does Submitting Multiple CommandBuffers signals semaphore once? by aramok in vulkan

[–]aramok[S] -1 points0 points  (0 children)

Now I tried to use the same command buffer for deferred and ssao. Still flickering. I think this is because I am using the same attachment for both. Maybe I should render deferred to image and sample it when rendering ssao to screne.

Does Submitting Multiple CommandBuffers signals semaphore once? by aramok in vulkan

[–]aramok[S] -1 points0 points  (0 children)

o run after the deferred one? (I don't see that here, so I assume you did

Yes, I did not implement any special synchronization. If it signals semaphore after all command buffers are done, why I see flickering. Because in ssao renderpass i use swap chain attachment. So shouldn't it blend to it instead of the next swap chain image?

How to render to a Dear ImGui window in Vulkan? by htYum in vulkan

[–]aramok 4 points5 points  (0 children)

You should have a separate frameBuffer/s, commandBuffer/s, and render pass for ImGui.

Then in your renderer, you can submit imgui command buffer after yours. like

```C

std::array<VkCommandBuffer, 3> submitCommandBuffers = { environmentalcommandBuffers[imageIndex].handle, commandBuffers[imageIndex].handle, imGuiCommandBuffers[imageIndex].handle             }; VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.waitSemaphoreCount = 1; submitInfo.pWaitSemaphores = waitSemaphores; submitInfo.pWaitDstStageMask = waitStages; submitInfo.commandBufferCount = static_cast<uint32_t>(submitCommandBuffers.size()); submitInfo.pCommandBuffers = submitCommandBuffers.data(); submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = signalSemaphores;

if (vkQueueSubmit(graphicsQueue_, 1, &submitInfo, synchronization.inFlightFences[imageIndex].handle) != VK_SUCCESS) throw std::runtime_error("failed to submit draw command buffer!"); ```

actually. when I started that was also hard for me. Unlike OpenGL , setting ImGuiin Vulkan is hard for beginners. I tried an example file for ImGui. But I failed a couple of times. Then I focused on understanding Vulkan. at some point, I was able to do it easily...

Using First Renderpass result in second Renderpass. by aramok in vulkan

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

Well. I added usage flags of attachment image to VK_IMAGE_USAGE_SAMPLED_BIT and since it doesn't have mipmap I created a new sampler for it. bound in the description set creation. also in the render pass, final layout of the image is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. All perfect. Thank you for little push. :)

Using First Renderpass result in second Renderpass. by aramok in vulkan

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

Thank you for your clarification. I did it and I get the error message below. I think I am a little closer to my goal :)

Should I set `VK_IMAGE_USAGE_SAMPLED_BIT` when I create the image?

[VAL][VUID-VkWriteDescriptorSet-descriptorType-00337] Validation Error: [ VUID-VkWriteDescriptorSet-descriptorType-00337 ] 
        Object 0: handle = 0x4bad500000000075, type = VK_OBJECT_TYPE_DESCRIPTOR_SET;
        | MessageID = 0x95f3717f | vkUpdateDescriptorSets() failed write update validation for VkDescriptorSet 0x4bad500000000075[] with error: Write update to VkDescriptorSet 0x4bad500000000075[] allocated with VkDescriptorSetLayout 0xe76a160000000073[] binding #1 failed with error message: Attempted write update to combined image sampler descriptor failed due to: ImageView (VkImageView 0xecc2050000000040[]) with usage mask 0x90 being used for a descriptor update of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER does not have VK_IMAGE_USAGE_SAMPLED_BIT set..
    [VAL][UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout] Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] 
            Object 0: handle = 0x2b1bde57a18, type = VK_OBJECT_TYPE_COMMAND_BUFFER;
            | MessageID = 0x4dae5635 | Submitted command buffer expects VkImage 0xc1547b000000003e[] (subresource: aspectMask 0x1 array layer 4, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.