diff --git a/examples/computeshader/computeshader.cpp b/examples/computeshader/computeshader.cpp index 7e9b4d47..b9a33210 100644 --- a/examples/computeshader/computeshader.cpp +++ b/examples/computeshader/computeshader.cpp @@ -654,6 +654,12 @@ public: } } + virtual void viewChanged() + { + camera.setPerspective(60.0f, (float)width * 0.5f / (float)height, 1.0f, 256.0f); + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/conditionalrender/conditionalrender.cpp b/examples/conditionalrender/conditionalrender.cpp index 3c8195e9..5b3613b5 100644 --- a/examples/conditionalrender/conditionalrender.cpp +++ b/examples/conditionalrender/conditionalrender.cpp @@ -330,6 +330,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Visibility")) { diff --git a/examples/debugmarker/debugmarker.cpp b/examples/debugmarker/debugmarker.cpp index dc5e42a8..8b7c7348 100644 --- a/examples/debugmarker/debugmarker.cpp +++ b/examples/debugmarker/debugmarker.cpp @@ -777,6 +777,10 @@ public: updateUniformBuffers(); } + virtual void viewChanged() + { + updateUniformBuffers(); + } virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { @@ -796,4 +800,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/deferred/deferred.cpp b/examples/deferred/deferred.cpp index 0994e2f9..18bf1874 100644 --- a/examples/deferred/deferred.cpp +++ b/examples/deferred/deferred.cpp @@ -809,6 +809,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBufferOffscreen(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/deferredmultisampling/deferredmultisampling.cpp b/examples/deferredmultisampling/deferredmultisampling.cpp index 3e95ae45..0b6f6805 100644 --- a/examples/deferredmultisampling/deferredmultisampling.cpp +++ b/examples/deferredmultisampling/deferredmultisampling.cpp @@ -647,6 +647,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBufferOffscreen(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/deferredshadows/deferredshadows.cpp b/examples/deferredshadows/deferredshadows.cpp index 033ce34a..ac7a017b 100644 --- a/examples/deferredshadows/deferredshadows.cpp +++ b/examples/deferredshadows/deferredshadows.cpp @@ -808,6 +808,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBufferOffscreen(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/descriptorindexing/descriptorindexing.cpp b/examples/descriptorindexing/descriptorindexing.cpp index 354d3b55..d0a016ac 100644 --- a/examples/descriptorindexing/descriptorindexing.cpp +++ b/examples/descriptorindexing/descriptorindexing.cpp @@ -409,6 +409,11 @@ public: updateUniformBuffersCamera(); } + virtual void viewChanged() + { + updateUniformBuffersCamera(); + } + }; VULKAN_EXAMPLE_MAIN() \ No newline at end of file diff --git a/examples/displacement/displacement.cpp b/examples/displacement/displacement.cpp index 125ff200..2ae6b0ff 100644 --- a/examples/displacement/displacement.cpp +++ b/examples/displacement/displacement.cpp @@ -385,6 +385,12 @@ public: updateUniformBuffers(); } } + + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -408,4 +414,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/distancefieldfonts/distancefieldfonts.cpp b/examples/distancefieldfonts/distancefieldfonts.cpp index 30cafc75..d3c67d9f 100644 --- a/examples/distancefieldfonts/distancefieldfonts.cpp +++ b/examples/distancefieldfonts/distancefieldfonts.cpp @@ -643,6 +643,7 @@ public: virtual void viewChanged() { + camera.setPerspective(splitScreen ? 30.0f : 45.0f, (float)width / (float)(height * ((splitScreen) ? 0.5f : 1.0f)), 1.0f, 256.0f); updateUniformBuffers(); } @@ -663,4 +664,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/gltfloading/gltfloading.cpp b/examples/gltfloading/gltfloading.cpp index c2144ded..1aa42647 100644 --- a/examples/gltfloading/gltfloading.cpp +++ b/examples/gltfloading/gltfloading.cpp @@ -729,6 +729,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/gltfscenerendering/gltfscenerendering.cpp b/examples/gltfscenerendering/gltfscenerendering.cpp index 64f062f1..02b655d5 100644 --- a/examples/gltfscenerendering/gltfscenerendering.cpp +++ b/examples/gltfscenerendering/gltfscenerendering.cpp @@ -631,6 +631,11 @@ void VulkanExample::render() } } +void VulkanExample::viewChanged() +{ + updateUniformBuffers(); +} + void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay) { if (overlay->header("Visibility")) { @@ -659,4 +664,4 @@ void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay) } } -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/gltfscenerendering/gltfscenerendering.h b/examples/gltfscenerendering/gltfscenerendering.h index e02abfe6..1d6cffe3 100644 --- a/examples/gltfscenerendering/gltfscenerendering.h +++ b/examples/gltfscenerendering/gltfscenerendering.h @@ -162,5 +162,6 @@ public: void updateUniformBuffers(); void prepare(); virtual void render(); + virtual void viewChanged(); virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); }; diff --git a/examples/gltfskinning/gltfskinning.cpp b/examples/gltfskinning/gltfskinning.cpp index d7988b83..f019395e 100644 --- a/examples/gltfskinning/gltfskinning.cpp +++ b/examples/gltfskinning/gltfskinning.cpp @@ -995,6 +995,11 @@ void VulkanExample::render() } } +void VulkanExample::viewChanged() +{ + updateUniformBuffers(); +} + void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) @@ -1006,4 +1011,4 @@ void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay) } } -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/gltfskinning/gltfskinning.h b/examples/gltfskinning/gltfskinning.h index 9423c01c..67f9c070 100644 --- a/examples/gltfskinning/gltfskinning.h +++ b/examples/gltfskinning/gltfskinning.h @@ -232,5 +232,6 @@ class VulkanExample : public VulkanExampleBase void updateUniformBuffers(); void prepare(); virtual void render(); + virtual void viewChanged(); virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay); }; diff --git a/examples/hdr/hdr.cpp b/examples/hdr/hdr.cpp index cda5b452..304a069c 100644 --- a/examples/hdr/hdr.cpp +++ b/examples/hdr/hdr.cpp @@ -870,6 +870,11 @@ public: updateUniformBuffers(); } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/indirectdraw/indirectdraw.cpp b/examples/indirectdraw/indirectdraw.cpp index c5e373a9..4baee4aa 100644 --- a/examples/indirectdraw/indirectdraw.cpp +++ b/examples/indirectdraw/indirectdraw.cpp @@ -499,6 +499,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffer(true); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (!vulkanDevice->features.multiDrawIndirect) { @@ -512,4 +517,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/inlineuniformblocks/inlineuniformblocks.cpp b/examples/inlineuniformblocks/inlineuniformblocks.cpp index 1dafe711..04b11bf7 100644 --- a/examples/inlineuniformblocks/inlineuniformblocks.cpp +++ b/examples/inlineuniformblocks/inlineuniformblocks.cpp @@ -357,6 +357,11 @@ public: updateUniformBuffers(); } + virtual void viewChanged() + { + updateUniformBuffers(); + } + /* [POI] Update descriptor sets at runtime */ @@ -401,4 +406,4 @@ public: }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/inputattachments/inputattachments.cpp b/examples/inputattachments/inputattachments.cpp index f0927815..3fd2c828 100644 --- a/examples/inputattachments/inputattachments.cpp +++ b/examples/inputattachments/inputattachments.cpp @@ -606,6 +606,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/instancing/instancing.cpp b/examples/instancing/instancing.cpp index d8dbe2b7..74feb2f7 100644 --- a/examples/instancing/instancing.cpp +++ b/examples/instancing/instancing.cpp @@ -482,6 +482,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffer(true); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Statistics")) { @@ -490,4 +495,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/multisampling/multisampling.cpp b/examples/multisampling/multisampling.cpp index f73cef79..26e1691a 100644 --- a/examples/multisampling/multisampling.cpp +++ b/examples/multisampling/multisampling.cpp @@ -541,6 +541,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + // Returns the maximum sample count usable by the platform VkSampleCountFlagBits getMaxUsableSampleCount() { diff --git a/examples/multithreading/multithreading.cpp b/examples/multithreading/multithreading.cpp index 38ef02f2..c60d18a9 100644 --- a/examples/multithreading/multithreading.cpp +++ b/examples/multithreading/multithreading.cpp @@ -527,6 +527,11 @@ public: } } + virtual void viewChanged() + { + updateMatrices(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Statistics")) { @@ -539,4 +544,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/multiview/multiview.cpp b/examples/multiview/multiview.cpp index 17a4a676..b9397cfb 100644 --- a/examples/multiview/multiview.cpp +++ b/examples/multiview/multiview.cpp @@ -738,6 +738,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/oit/oit.cpp b/examples/oit/oit.cpp index 2743f974..77bdd68e 100644 --- a/examples/oit/oit.cpp +++ b/examples/oit/oit.cpp @@ -507,7 +507,7 @@ private: vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); } - void buildCommandBuffers() + void buildCommandBuffers() override { if (resized) return; @@ -656,4 +656,4 @@ private: VkDeviceSize objectUniformBufferSize; }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/particlefire/particlefire.cpp b/examples/particlefire/particlefire.cpp index b4b9bb55..e966d545 100644 --- a/examples/particlefire/particlefire.cpp +++ b/examples/particlefire/particlefire.cpp @@ -589,6 +589,11 @@ public: updateUniformBuffers(); } } + + virtual void viewChanged() + { + updateUniformBuffers(); + } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/pbrtexture/pbrtexture.cpp b/examples/pbrtexture/pbrtexture.cpp index 5be56716..e69c8b78 100644 --- a/examples/pbrtexture/pbrtexture.cpp +++ b/examples/pbrtexture/pbrtexture.cpp @@ -1340,6 +1340,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/pipelines/pipelines.cpp b/examples/pipelines/pipelines.cpp index 68d0415a..13034073 100644 --- a/examples/pipelines/pipelines.cpp +++ b/examples/pipelines/pipelines.cpp @@ -334,6 +334,12 @@ public: } } + virtual void viewChanged() + { + camera.setPerspective(60.0f, (float)(width / 3.0f) / (float)height, 0.1f, 256.0f); + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (!deviceFeatures.fillModeNonSolid) { @@ -344,4 +350,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/pushdescriptors/pushdescriptors.cpp b/examples/pushdescriptors/pushdescriptors.cpp index b1979828..a6f6094d 100644 --- a/examples/pushdescriptors/pushdescriptors.cpp +++ b/examples/pushdescriptors/pushdescriptors.cpp @@ -337,6 +337,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/specializationconstants/specializationconstants.cpp b/examples/specializationconstants/specializationconstants.cpp index 0384086d..d0692d03 100644 --- a/examples/specializationconstants/specializationconstants.cpp +++ b/examples/specializationconstants/specializationconstants.cpp @@ -320,10 +320,10 @@ public: } } - virtual void windowResized() + virtual void viewChanged() { updateUniformBuffers(); } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/sphericalenvmapping/sphericalenvmapping.cpp b/examples/sphericalenvmapping/sphericalenvmapping.cpp index 883184aa..9bf8ce3e 100644 --- a/examples/sphericalenvmapping/sphericalenvmapping.cpp +++ b/examples/sphericalenvmapping/sphericalenvmapping.cpp @@ -277,6 +277,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -288,4 +293,4 @@ public: }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/ssao/ssao.cpp b/examples/ssao/ssao.cpp index 92558908..be9e81ae 100644 --- a/examples/ssao/ssao.cpp +++ b/examples/ssao/ssao.cpp @@ -944,6 +944,12 @@ public: } } + virtual void viewChanged() + { + updateUniformBufferMatrices(); + updateUniformBufferSSAOParams(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/subpasses/subpasses.cpp b/examples/subpasses/subpasses.cpp index d1e4ea93..9f59df3c 100644 --- a/examples/subpasses/subpasses.cpp +++ b/examples/subpasses/subpasses.cpp @@ -903,6 +903,12 @@ public: } } + virtual void viewChanged() + { + updateUniformBufferDeferredMatrices(); + updateUniformBufferDeferredLights(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Subpasses")) { diff --git a/examples/terraintessellation/terraintessellation.cpp b/examples/terraintessellation/terraintessellation.cpp index 80a79e27..30bcbd1e 100644 --- a/examples/terraintessellation/terraintessellation.cpp +++ b/examples/terraintessellation/terraintessellation.cpp @@ -828,6 +828,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -853,4 +858,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/tessellation/tessellation.cpp b/examples/tessellation/tessellation.cpp index 444a0789..87b5b8fd 100644 --- a/examples/tessellation/tessellation.cpp +++ b/examples/tessellation/tessellation.cpp @@ -326,6 +326,12 @@ public: } } + virtual void viewChanged() + { + camera.setPerspective(45.0f, (float)(width * ((splitScreen) ? 0.5f : 1.0f)) / (float)height, 0.1f, 256.0f); + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/textoverlay/textoverlay.cpp b/examples/textoverlay/textoverlay.cpp index 7672b2b8..4c8fa1e4 100644 --- a/examples/textoverlay/textoverlay.cpp +++ b/examples/textoverlay/textoverlay.cpp @@ -514,6 +514,8 @@ public: case alignCenter: x -= textWidth / 2.0f; break; + case alignLeft: + break; } // Generate a uv mapped quad per char in the new text @@ -885,6 +887,10 @@ public: if (!prepared) return; draw(); + if (camera.updated) + { + updateUniformBuffers(); + } if (frameCounter == 0) { vkDeviceWaitIdle(device); @@ -892,13 +898,6 @@ public: } } - virtual void viewChanged() - { - vkDeviceWaitIdle(device); - updateUniformBuffers(); - updateTextOverlay(); - } - virtual void windowResized() { // SRS - Recreate text overlay resources in case number of swapchain images has changed on resize @@ -906,6 +905,12 @@ public: prepareTextOverlay(); } + virtual void viewChanged() + { + updateUniformBuffers(); + updateTextOverlay(); + } + #if !defined(__ANDROID__) virtual void keyPressed(uint32_t keyCode) { diff --git a/examples/texture3d/texture3d.cpp b/examples/texture3d/texture3d.cpp index f2f672e2..773848c2 100644 --- a/examples/texture3d/texture3d.cpp +++ b/examples/texture3d/texture3d.cpp @@ -773,6 +773,11 @@ public: updateUniformBuffers(camera.updated); } + virtual void viewChanged() + { + updateUniformBuffers(true); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { diff --git a/examples/texturearray/texturearray.cpp b/examples/texturearray/texturearray.cpp index 41cd5392..921addea 100644 --- a/examples/texturearray/texturearray.cpp +++ b/examples/texturearray/texturearray.cpp @@ -550,6 +550,10 @@ public: updateUniformBuffersCamera(); } + virtual void viewChanged() + { + updateUniformBuffersCamera(); + } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/texturecubemaparray/texturecubemaparray.cpp b/examples/texturecubemaparray/texturecubemaparray.cpp index 6d9c5494..6e649d82 100644 --- a/examples/texturecubemaparray/texturecubemaparray.cpp +++ b/examples/texturecubemaparray/texturecubemaparray.cpp @@ -529,6 +529,11 @@ public: } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -548,4 +553,4 @@ public: } }; -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/texturesparseresidency/texturesparseresidency.cpp b/examples/texturesparseresidency/texturesparseresidency.cpp index 0875a6ec..10889474 100644 --- a/examples/texturesparseresidency/texturesparseresidency.cpp +++ b/examples/texturesparseresidency/texturesparseresidency.cpp @@ -708,6 +708,11 @@ void VulkanExample::render() } } +void VulkanExample::viewChanged() +{ + updateUniformBuffers(); +} + // Fills a buffer with random colors void VulkanExample::randomPattern(uint8_t* buffer, uint32_t width, uint32_t height) { diff --git a/examples/texturesparseresidency/texturesparseresidency.h b/examples/texturesparseresidency/texturesparseresidency.h index e061dc9e..5da19e18 100644 --- a/examples/texturesparseresidency/texturesparseresidency.h +++ b/examples/texturesparseresidency/texturesparseresidency.h @@ -116,6 +116,7 @@ public: void updateUniformBuffers(); void prepare(); virtual void render(); + virtual void viewChanged(); void uploadContent(VirtualTexturePage page, VkImage image); void fillRandomPages(); void fillMipTail(); diff --git a/examples/triangle/triangle.cpp b/examples/triangle/triangle.cpp index 6b16b296..6d0e35d3 100644 --- a/examples/triangle/triangle.cpp +++ b/examples/triangle/triangle.cpp @@ -109,7 +109,7 @@ public: // Fences // Used to check the completion of queue operations (e.g. command buffer execution) - std::vector waitFences; + std::vector queueCompleteFences; VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { @@ -148,7 +148,7 @@ public: vkDestroySemaphore(device, presentCompleteSemaphore, nullptr); vkDestroySemaphore(device, renderCompleteSemaphore, nullptr); - for (auto& fence : waitFences) + for (auto& fence : queueCompleteFences) { vkDestroyFence(device, fence, nullptr); } @@ -196,8 +196,8 @@ public: fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; // Create in signaled state so we don't wait on first render of each command buffer fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; - waitFences.resize(drawCmdBuffers.size()); - for (auto& fence : waitFences) + queueCompleteFences.resize(drawCmdBuffers.size()); + for (auto& fence : queueCompleteFences) { VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence)); } @@ -337,6 +337,16 @@ public: void draw() { +#if defined(VK_USE_PLATFORM_MACOS_MVK) + // SRS - on macOS use swapchain helper function with common semaphores/fences for proper resize handling + // Get next image in the swap chain (back/front buffer) + prepareFrame(); + + // Use a fence to wait until the command buffer has finished execution before using it again + VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX)); + VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer])); +#else + // SRS - on other platforms use original bare code with local semaphores/fences for illustrative purposes // Get next image in the swap chain (back/front buffer) VkResult acquire = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer); if (!((acquire == VK_SUCCESS) || (acquire == VK_SUBOPTIMAL_KHR))) { @@ -344,8 +354,9 @@ public: } // Use a fence to wait until the command buffer has finished execution before using it again - VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX)); - VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer])); + VK_CHECK_RESULT(vkWaitForFences(device, 1, &queueCompleteFences[currentBuffer], VK_TRUE, UINT64_MAX)); + VK_CHECK_RESULT(vkResetFences(device, 1, &queueCompleteFences[currentBuffer])); +#endif // Pipeline stage at which the queue submission will wait (via pWaitSemaphores) VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; @@ -353,16 +364,29 @@ public: VkSubmitInfo submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at - submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing submitInfo.waitSemaphoreCount = 1; // One wait semaphore - submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed submitInfo.signalSemaphoreCount = 1; // One signal semaphore submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; // Command buffers(s) to execute in this batch (submission) submitInfo.commandBufferCount = 1; // One command buffer +#if defined(VK_USE_PLATFORM_MACOS_MVK) + // SRS - on macOS use swapchain helper function with common semaphores/fences for proper resize handling + submitInfo.pWaitSemaphores = &semaphores.presentComplete; // Semaphore(s) to wait upon before the submitted command buffer starts executing + submitInfo.pSignalSemaphores = &semaphores.renderComplete; // Semaphore(s) to be signaled when command buffers have completed + // Submit to the graphics queue passing a wait fence VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer])); + // Present the current buffer to the swap chain + submitFrame(); +#else + // SRS - on other platforms use original bare code with local semaphores/fences for illustrative purposes + submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing + submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed + + // Submit to the graphics queue passing a wait fence + VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, queueCompleteFences[currentBuffer])); + // Present the current buffer to the swap chain // Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore for swap chain presentation // This ensures that the image is not presented to the windowing system until all commands have been submitted @@ -370,7 +394,7 @@ public: if (!((present == VK_SUCCESS) || (present == VK_SUBOPTIMAL_KHR))) { VK_CHECK_RESULT(present); } - +#endif } // Prepare vertex and index buffers for an indexed triangle @@ -1235,7 +1259,7 @@ int main(const int argc, const char *argv[]) vulkanExample->setupWindow(nullptr); vulkanExample->prepare(); vulkanExample->renderLoop(); - delete(vulkanExample); + //delete(vulkanExample); // SRS - vulkanExample deleted by AppDelegate termination event handler } return 0; } diff --git a/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp index b10f9991..5607b051 100644 --- a/examples/vertexattributes/vertexattributes.cpp +++ b/examples/vertexattributes/vertexattributes.cpp @@ -580,6 +580,11 @@ void VulkanExample::render() } } +void VulkanExample::viewChanged() +{ + updateUniformBuffers(); +} + void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay) { if (overlay->header("Vertex buffer attributes")) { @@ -596,4 +601,4 @@ void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay) } } -VULKAN_EXAMPLE_MAIN() \ No newline at end of file +VULKAN_EXAMPLE_MAIN() diff --git a/examples/vertexattributes/vertexattributes.h b/examples/vertexattributes/vertexattributes.h index 97abf1b3..d51f96ec 100644 --- a/examples/vertexattributes/vertexattributes.h +++ b/examples/vertexattributes/vertexattributes.h @@ -139,5 +139,6 @@ public: void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent); void drawSceneNode(VkCommandBuffer commandBuffer, Node node); virtual void render(); + virtual void viewChanged(); virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); };