Skip to content

Commit

Permalink
Fix computeshader sample first frame being rendered with bogus UBOs (#…
Browse files Browse the repository at this point in the history
…1125)

After this change, the sample's render() method would first update its UBO and then start drawing stuff so as to have valid frame output from frame 0, similarly to other samples.
  • Loading branch information
takayhan-AMD authored May 15, 2024
1 parent 9756ad8 commit 3a94116
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions examples/computeshader/computeshader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Vulkan Example - Compute shader image processing
*
*
* This sample uses a compute shader to apply different filters to an image
*
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
Expand Down Expand Up @@ -344,20 +344,20 @@ class VulkanExample : public VulkanExampleBase
// Create a semaphore for compute & graphics sync
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &graphics.semaphore));

// Signal the semaphore
VkSubmitInfo submitInfo = vks::initializers::submitInfo();
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &graphics.semaphore;
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
VK_CHECK_RESULT(vkQueueWaitIdle(queue));

// Setup descriptors

// The graphics pipeline uses two sets with two bindings
// One set for displaying the input image and one set for displaying the output image with the compute filter applied
// Binding 0: Vertex shader uniform buffer
// Binding 1: Sampled image (before/after compute filter is applied)
// Binding 1: Sampled image (before/after compute filter is applied)

std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0),
Expand Down Expand Up @@ -562,9 +562,11 @@ class VulkanExample : public VulkanExampleBase
virtual void render()
{
if (!prepared)
{
return;
draw();
}
updateUniformBuffers();
draw();
}

virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
Expand Down

0 comments on commit 3a94116

Please sign in to comment.