From 279c95422d1f3e2b849d6594fe2e71633a089230 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Mon, 13 Jun 2022 23:04:53 -0400 Subject: [PATCH] Implement viewChanged() in multiple examples for proper window resize handling, fix triangle example resizing on macOS --- examples/computeshader/computeshader.cpp | 6 +++ .../conditionalrender/conditionalrender.cpp | 5 +++ examples/debugmarker/debugmarker.cpp | 6 ++- examples/deferred/deferred.cpp | 5 +++ .../deferredmultisampling.cpp | 5 +++ examples/deferredshadows/deferredshadows.cpp | 5 +++ .../descriptorindexing/descriptorindexing.cpp | 5 +++ examples/displacement/displacement.cpp | 8 +++- .../distancefieldfonts/distancefieldfonts.cpp | 3 +- examples/gltfloading/gltfloading.cpp | 5 +++ .../gltfscenerendering/gltfscenerendering.cpp | 7 ++- .../gltfscenerendering/gltfscenerendering.h | 1 + examples/gltfskinning/gltfskinning.cpp | 7 ++- examples/gltfskinning/gltfskinning.h | 1 + examples/hdr/hdr.cpp | 5 +++ examples/indirectdraw/indirectdraw.cpp | 7 ++- .../inlineuniformblocks.cpp | 7 ++- .../inputattachments/inputattachments.cpp | 5 +++ examples/instancing/instancing.cpp | 7 ++- examples/multisampling/multisampling.cpp | 5 +++ examples/multithreading/multithreading.cpp | 7 ++- examples/multiview/multiview.cpp | 5 +++ examples/oit/oit.cpp | 4 +- examples/particlefire/particlefire.cpp | 7 ++- examples/pbrtexture/pbrtexture.cpp | 5 +++ examples/pipelines/pipelines.cpp | 8 +++- examples/pushdescriptors/pushdescriptors.cpp | 5 +++ .../specializationconstants.cpp | 4 +- .../sphericalenvmapping.cpp | 7 ++- examples/ssao/ssao.cpp | 6 +++ examples/subpasses/subpasses.cpp | 6 +++ .../terraintessellation.cpp | 7 ++- examples/tessellation/tessellation.cpp | 6 +++ examples/textoverlay/textoverlay.cpp | 19 +++++--- examples/texture3d/texture3d.cpp | 5 +++ examples/texturearray/texturearray.cpp | 6 ++- .../texturecubemaparray.cpp | 7 ++- .../texturesparseresidency.cpp | 5 +++ .../texturesparseresidency.h | 1 + examples/triangle/triangle.cpp | 44 ++++++++++++++----- .../vertexattributes/vertexattributes.cpp | 7 ++- examples/vertexattributes/vertexattributes.h | 1 + 42 files changed, 240 insertions(+), 37 deletions(-) diff --git a/examples/computeshader/computeshader.cpp b/examples/computeshader/computeshader.cpp index 7e9b4d47b..b9a332103 100644 --- a/examples/computeshader/computeshader.cpp +++ b/examples/computeshader/computeshader.cpp @@ -654,6 +654,12 @@ class VulkanExample : public VulkanExampleBase } } + 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 3c8195e93..5b3613b5b 100644 --- a/examples/conditionalrender/conditionalrender.cpp +++ b/examples/conditionalrender/conditionalrender.cpp @@ -330,6 +330,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 dc5e42a88..8b7c7348c 100644 --- a/examples/debugmarker/debugmarker.cpp +++ b/examples/debugmarker/debugmarker.cpp @@ -777,6 +777,10 @@ class VulkanExample : public VulkanExampleBase updateUniformBuffers(); } + virtual void viewChanged() + { + updateUniformBuffers(); + } virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { @@ -796,4 +800,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 0994e2f98..18bf1874a 100644 --- a/examples/deferred/deferred.cpp +++ b/examples/deferred/deferred.cpp @@ -809,6 +809,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 3e95ae45e..0b6f6805b 100644 --- a/examples/deferredmultisampling/deferredmultisampling.cpp +++ b/examples/deferredmultisampling/deferredmultisampling.cpp @@ -647,6 +647,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 033ce34a1..ac7a017b7 100644 --- a/examples/deferredshadows/deferredshadows.cpp +++ b/examples/deferredshadows/deferredshadows.cpp @@ -808,6 +808,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 354d3b555..d0a016ac8 100644 --- a/examples/descriptorindexing/descriptorindexing.cpp +++ b/examples/descriptorindexing/descriptorindexing.cpp @@ -409,6 +409,11 @@ class VulkanExample : public VulkanExampleBase 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 125ff2000..2ae6b0ff1 100644 --- a/examples/displacement/displacement.cpp +++ b/examples/displacement/displacement.cpp @@ -385,6 +385,12 @@ class VulkanExample : public VulkanExampleBase updateUniformBuffers(); } } + + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -408,4 +414,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 30cafc751..d3c67d9f3 100644 --- a/examples/distancefieldfonts/distancefieldfonts.cpp +++ b/examples/distancefieldfonts/distancefieldfonts.cpp @@ -643,6 +643,7 @@ class VulkanExample : public VulkanExampleBase 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 @@ class VulkanExample : public VulkanExampleBase } }; -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 c2144dedc..1aa42647a 100644 --- a/examples/gltfloading/gltfloading.cpp +++ b/examples/gltfloading/gltfloading.cpp @@ -729,6 +729,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 64f062f13..02b655d59 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 e02abfe60..1d6cffe34 100644 --- a/examples/gltfscenerendering/gltfscenerendering.h +++ b/examples/gltfscenerendering/gltfscenerendering.h @@ -162,5 +162,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/gltfskinning/gltfskinning.cpp b/examples/gltfskinning/gltfskinning.cpp index d7988b83f..f019395e2 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 9423c01c6..67f9c070a 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 cda5b452d..304a069cc 100644 --- a/examples/hdr/hdr.cpp +++ b/examples/hdr/hdr.cpp @@ -870,6 +870,11 @@ class VulkanExample : public VulkanExampleBase 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 c5e373a99..4baee4aa6 100644 --- a/examples/indirectdraw/indirectdraw.cpp +++ b/examples/indirectdraw/indirectdraw.cpp @@ -499,6 +499,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateUniformBuffer(true); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (!vulkanDevice->features.multiDrawIndirect) { @@ -512,4 +517,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 1dafe7110..04b11bf73 100644 --- a/examples/inlineuniformblocks/inlineuniformblocks.cpp +++ b/examples/inlineuniformblocks/inlineuniformblocks.cpp @@ -357,6 +357,11 @@ class VulkanExample : public VulkanExampleBase updateUniformBuffers(); } + virtual void viewChanged() + { + updateUniformBuffers(); + } + /* [POI] Update descriptor sets at runtime */ @@ -401,4 +406,4 @@ class VulkanExample : public VulkanExampleBase }; -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 f09278150..3fd2c8286 100644 --- a/examples/inputattachments/inputattachments.cpp +++ b/examples/inputattachments/inputattachments.cpp @@ -606,6 +606,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 d8dbe2b74..74feb2f72 100644 --- a/examples/instancing/instancing.cpp +++ b/examples/instancing/instancing.cpp @@ -482,6 +482,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateUniformBuffer(true); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Statistics")) { @@ -490,4 +495,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 f73cef79d..26e1691a9 100644 --- a/examples/multisampling/multisampling.cpp +++ b/examples/multisampling/multisampling.cpp @@ -541,6 +541,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 38ef02f2d..c60d18a9d 100644 --- a/examples/multithreading/multithreading.cpp +++ b/examples/multithreading/multithreading.cpp @@ -527,6 +527,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateMatrices(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Statistics")) { @@ -539,4 +544,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 17a4a676b..b9397cfb9 100644 --- a/examples/multiview/multiview.cpp +++ b/examples/multiview/multiview.cpp @@ -738,6 +738,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 2743f9742..77bdd68ef 100644 --- a/examples/oit/oit.cpp +++ b/examples/oit/oit.cpp @@ -507,7 +507,7 @@ class VulkanExample : public VulkanExampleBase vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); } - void buildCommandBuffers() + void buildCommandBuffers() override { if (resized) return; @@ -656,4 +656,4 @@ class VulkanExample : public VulkanExampleBase 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 b4b9bb552..e966d5458 100644 --- a/examples/particlefire/particlefire.cpp +++ b/examples/particlefire/particlefire.cpp @@ -589,6 +589,11 @@ class VulkanExample : public VulkanExampleBase 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 5be567163..e69c8b786 100644 --- a/examples/pbrtexture/pbrtexture.cpp +++ b/examples/pbrtexture/pbrtexture.cpp @@ -1340,6 +1340,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 68d0415ab..130340734 100644 --- a/examples/pipelines/pipelines.cpp +++ b/examples/pipelines/pipelines.cpp @@ -334,6 +334,12 @@ class VulkanExample: public VulkanExampleBase } } + 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 @@ class VulkanExample: public VulkanExampleBase } }; -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 b19798288..a6f6094de 100644 --- a/examples/pushdescriptors/pushdescriptors.cpp +++ b/examples/pushdescriptors/pushdescriptors.cpp @@ -337,6 +337,11 @@ class VulkanExample : public VulkanExampleBase } } + 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 0384086da..d0692d037 100644 --- a/examples/specializationconstants/specializationconstants.cpp +++ b/examples/specializationconstants/specializationconstants.cpp @@ -320,10 +320,10 @@ class VulkanExample: public VulkanExampleBase } } - 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 883184aad..9bf8ce3e8 100644 --- a/examples/sphericalenvmapping/sphericalenvmapping.cpp +++ b/examples/sphericalenvmapping/sphericalenvmapping.cpp @@ -277,6 +277,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -288,4 +293,4 @@ class VulkanExample : public VulkanExampleBase }; -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 92558908e..be9e81ae8 100644 --- a/examples/ssao/ssao.cpp +++ b/examples/ssao/ssao.cpp @@ -944,6 +944,12 @@ class VulkanExample : public VulkanExampleBase } } + 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 d1e4ea933..9f59df3c1 100644 --- a/examples/subpasses/subpasses.cpp +++ b/examples/subpasses/subpasses.cpp @@ -903,6 +903,12 @@ class VulkanExample : public VulkanExampleBase } } + 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 80a79e276..30bcbd1ed 100644 --- a/examples/terraintessellation/terraintessellation.cpp +++ b/examples/terraintessellation/terraintessellation.cpp @@ -828,6 +828,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -853,4 +858,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 444a07899..87b5b8fda 100644 --- a/examples/tessellation/tessellation.cpp +++ b/examples/tessellation/tessellation.cpp @@ -326,6 +326,12 @@ class VulkanExample : public VulkanExampleBase } } + 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 7672b2b86..4c8fa1e4a 100644 --- a/examples/textoverlay/textoverlay.cpp +++ b/examples/textoverlay/textoverlay.cpp @@ -514,6 +514,8 @@ class TextOverlay 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 @@ class VulkanExample : public VulkanExampleBase if (!prepared) return; draw(); + if (camera.updated) + { + updateUniformBuffers(); + } if (frameCounter == 0) { vkDeviceWaitIdle(device); @@ -892,13 +898,6 @@ class VulkanExample : public VulkanExampleBase } } - 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 @@ class VulkanExample : public VulkanExampleBase 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 f2f672e2d..773848c2c 100644 --- a/examples/texture3d/texture3d.cpp +++ b/examples/texture3d/texture3d.cpp @@ -773,6 +773,11 @@ class VulkanExample : public VulkanExampleBase 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 41cd53920..921addea3 100644 --- a/examples/texturearray/texturearray.cpp +++ b/examples/texturearray/texturearray.cpp @@ -550,6 +550,10 @@ class VulkanExample : public VulkanExampleBase 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 6d9c54947..6e649d823 100644 --- a/examples/texturecubemaparray/texturecubemaparray.cpp +++ b/examples/texturecubemaparray/texturecubemaparray.cpp @@ -529,6 +529,11 @@ class VulkanExample : public VulkanExampleBase } } + virtual void viewChanged() + { + updateUniformBuffers(); + } + virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { @@ -548,4 +553,4 @@ class VulkanExample : public VulkanExampleBase } }; -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 0875a6ecf..108894744 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 e061dc9e7..5da19e185 100644 --- a/examples/texturesparseresidency/texturesparseresidency.h +++ b/examples/texturesparseresidency/texturesparseresidency.h @@ -116,6 +116,7 @@ class VulkanExample : public VulkanExampleBase 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 6b16b296e..6d0e35d38 100644 --- a/examples/triangle/triangle.cpp +++ b/examples/triangle/triangle.cpp @@ -109,7 +109,7 @@ class VulkanExample : public VulkanExampleBase // 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 @@ class VulkanExample : public VulkanExampleBase vkDestroySemaphore(device, presentCompleteSemaphore, nullptr); vkDestroySemaphore(device, renderCompleteSemaphore, nullptr); - for (auto& fence : waitFences) + for (auto& fence : queueCompleteFences) { vkDestroyFence(device, fence, nullptr); } @@ -196,8 +196,8 @@ class VulkanExample : public VulkanExampleBase 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 @@ class VulkanExample : public VulkanExampleBase 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 @@ class VulkanExample : public VulkanExampleBase } // 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 @@ class VulkanExample : public VulkanExampleBase 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 @@ class VulkanExample : public VulkanExampleBase 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 b10f99917..5607b0510 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 97abf1b36..d51f96ece 100644 --- a/examples/vertexattributes/vertexattributes.h +++ b/examples/vertexattributes/vertexattributes.h @@ -139,5 +139,6 @@ class VulkanExample : public VulkanExampleBase 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); };