From e9fbe529d6180b7312d7bec300329b08b7663d4a Mon Sep 17 00:00:00 2001 From: Johannes Unterguggenberger Date: Thu, 21 Mar 2024 17:13:27 +0100 Subject: [PATCH] Towards fixing everything. Most importantly these issues: https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/6177 --- auto_vk_toolkit/include/imgui_manager.hpp | 20 +++++++++++++++++++ auto_vk_toolkit/src/imgui_manager.cpp | 18 ++++++++--------- auto_vk_toolkit/src/window.cpp | 8 ++++---- examples/framebuffer/source/framebuffer.cpp | 8 ++++---- examples/hello_world/source/hello_world.cpp | 2 +- examples/model_loader/source/model_loader.cpp | 2 +- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/auto_vk_toolkit/include/imgui_manager.hpp b/auto_vk_toolkit/include/imgui_manager.hpp index 69464d0d..c8c8ef62 100644 --- a/auto_vk_toolkit/include/imgui_manager.hpp +++ b/auto_vk_toolkit/include/imgui_manager.hpp @@ -25,6 +25,7 @@ namespace avk , mQueue { &aQueueToSubmitTo } , mUserInteractionEnabled{ true } , mAlterSettingsBeforeInitialization{ std::move(aAlterSettingsBeforeInitialization) } + , mIncomingLayout{ layout::color_attachment_optimal } { if (aRenderpassToUse.has_value()) { mRenderpass = std::move(aRenderpassToUse.value()); @@ -126,6 +127,24 @@ namespace avk bool end_wanting_to_occupy_mouse() const { return !mOccupyMouse && mOccupyMouseLastFrame; } + + /** Gets the image layout that imgui_manager assumes the color attachment to be in when it starts + * to render into it. + * The default value is: avk::layout::color_attachment_optimal + */ + layout::image_layout previous_image_layout() const { + return mIncomingLayout; + } + + /** Sets the image layout that imgui_manager shall expect the color attachment to be in + * before starting to render into it. + * Note: This change might only have effect BEFORE imgui_manager has been initialized, + * i.e., before its ::initialize() method has been invoked by the framework for the + * first time. => Ensure to configure this value before starting the composition! + */ + void set_previous_image_layout(layout::image_layout aIncomingLayout) { + mIncomingLayout = aIncomingLayout; + } private: void upload_fonts(); void construct_render_pass(); @@ -156,6 +175,7 @@ namespace avk // customization std::function mAlterSettingsBeforeInitialization = {}; std::string mCustomTtfFont = {}; + layout::image_layout mIncomingLayout; }; } diff --git a/auto_vk_toolkit/src/imgui_manager.cpp b/auto_vk_toolkit/src/imgui_manager.cpp index 720804c6..de1ebe10 100644 --- a/auto_vk_toolkit/src/imgui_manager.cpp +++ b/auto_vk_toolkit/src/imgui_manager.cpp @@ -522,7 +522,7 @@ namespace avk auto* wnd = context().main_window(); std::vector attachments; - attachments.push_back(attachment::declare(format_from_window_color_buffer(wnd), on_load::load, usage::color(0), on_store::store.in_layout(layout::present_src))); + attachments.push_back(attachment::declare(format_from_window_color_buffer(wnd), on_load::load.from_previous_layout(mIncomingLayout), usage::color(0), on_store::store.in_layout(layout::present_src))); for (auto a : wnd->get_additional_back_buffer_attachments()) { // Well... who would have guessed the following (and, who understands??): // @@ -544,13 +544,13 @@ namespace avk subpass_dependency( subpass::external >> subpass::index(0), // ... we have to synchronize all these stages with color+dept_stencil write access: - stage::color_attachment_output | stage::early_fragment_tests | stage::late_fragment_tests >> stage::color_attachment_output | stage::early_fragment_tests | stage::late_fragment_tests, - access::color_attachment_write | access::depth_stencil_attachment_write >> access::color_attachment_read | access::depth_stencil_attachment_write + stage::color_attachment_output >> stage::color_attachment_output, + access::none >> access::color_attachment_read | access::color_attachment_write // read && write due to layout transition ), subpass_dependency( subpass::index(0) >> subpass::external, - stage::color_attachment_output >> stage::none, // assume semaphore afterwards - access::color_attachment_write >> access::none + stage::color_attachment_output >> stage::color_attachment_output, // assume semaphore afterwards + access::color_attachment_write >> access::none // ^ ...but still, gotta synchronize image layout transition with subsequent presentKHR :ohgodwhy: ) } ); @@ -562,13 +562,13 @@ namespace avk , { subpass_dependency( subpass::external >> subpass::index(0), - stage::none >> stage::color_attachment_output, - access::none >> access::color_attachment_read | access::color_attachment_write + stage::color_attachment_output >> stage::color_attachment_output, + access::none >> access::color_attachment_read | access::color_attachment_write // read && write due to layout transition ), subpass_dependency( subpass::index(0) >> subpass::external, - stage::color_attachment_output >> stage::none, // assume semaphore afterwards - access::color_attachment_write >> access::none + stage::color_attachment_output >> stage::color_attachment_output, // assume semaphore afterwards + access::color_attachment_write >> access::none // ^ ...but still, gotta synchronize image layout transition with subsequent presentKHR :ohgodwhy: ) } ); diff --git a/auto_vk_toolkit/src/window.cpp b/auto_vk_toolkit/src/window.cpp index ff93550a..b6cdc8d6 100644 --- a/auto_vk_toolkit/src/window.cpp +++ b/auto_vk_toolkit/src/window.cpp @@ -834,12 +834,12 @@ namespace avk auto newRenderPass = context().create_renderpass(renderpassAttachments, { // We only create one subpass here => create default dependencies as per specification chapter 8.1) Render Pass Creation: avk::subpass_dependency{avk::subpass::external >> avk::subpass::index(0), - avk::stage::none >> avk::stage::all_graphics, - avk::access::none >> avk::access::input_attachment_read | avk::access::color_attachment_read | avk::access::color_attachment_write | avk::access::depth_stencil_attachment_read | avk::access::depth_stencil_attachment_write + stage::color_attachment_output >> stage::early_fragment_tests | stage::late_fragment_tests | stage::color_attachment_output, + access::none >> access::color_attachment_read | access::color_attachment_write | access::depth_stencil_attachment_read | access::depth_stencil_attachment_write }, avk::subpass_dependency{avk::subpass::index(0) >> avk::subpass::external, - avk::stage::all_graphics >> avk::stage::none, - avk::access::color_attachment_write | avk::access::depth_stencil_attachment_write >> avk::access::none + stage::color_attachment_output >> stage::color_attachment_output, + access::color_attachment_write >> access::none } }); if (mBackBufferRenderpass.has_value() && mBackBufferRenderpass.is_shared_ownership_enabled()) { diff --git a/examples/framebuffer/source/framebuffer.cpp b/examples/framebuffer/source/framebuffer.cpp index 3cf55e6b..060e8726 100644 --- a/examples/framebuffer/source/framebuffer.cpp +++ b/examples/framebuffer/source/framebuffer.cpp @@ -223,12 +223,12 @@ class framebuffer_app : public avk::invokee // Transition the layouts before performing the transfer operation: avk::sync::image_memory_barrier(mOneFramebuffer->image_at(mSelectedAttachmentToCopy), // None here, because we're synchronizing with a semaphore - avk::stage::none >> avk::stage::copy | avk::stage::blit, - avk::access::none >> avk::access::transfer_read + avk::stage::color_attachment_output >> avk::stage::copy | avk::stage::blit, + avk::access::color_attachment_write >> avk::access::transfer_read ).with_layout_transition(sourceImageLayout >> avk::layout::transfer_src), avk::sync::image_memory_barrier(mainWnd->current_backbuffer()->image_at(0), - avk::stage::none >> avk::stage::copy | avk::stage::blit, - avk::access::none >> avk::access::transfer_write + avk::stage::color_attachment_output >> avk::stage::copy | avk::stage::blit, + avk::access::color_attachment_write >> avk::access::transfer_write ).with_layout_transition(avk::layout::undefined >> avk::layout::transfer_dst), // Perform the transfer operation: diff --git a/examples/hello_world/source/hello_world.cpp b/examples/hello_world/source/hello_world.cpp index f211d5e3..a726161e 100644 --- a/examples/hello_world/source/hello_world.cpp +++ b/examples/hello_world/source/hello_world.cpp @@ -160,7 +160,7 @@ int main() // <== Starting point == auto composition = configure_and_compose( avk::application_name("Hello, Auto-Vk-Toolkit World!"), [](avk::validation_layers& config) { - //config.enable_feature(vk::ValidationFeatureEnableEXT::eSynchronizationValidation); + config.enable_feature(vk::ValidationFeatureEnableEXT::eSynchronizationValidation); }, // Pass windows: mainWnd, diff --git a/examples/model_loader/source/model_loader.cpp b/examples/model_loader/source/model_loader.cpp index 3cc2ded7..58a984dd 100644 --- a/examples/model_loader/source/model_loader.cpp +++ b/examples/model_loader/source/model_loader.cpp @@ -466,7 +466,7 @@ int main() // <== Starting point == auto composition = configure_and_compose( avk::application_name("Auto-Vk-Toolkit Example: Model Loader"), [](avk::validation_layers& config) { - //config.enable_feature(vk::ValidationFeatureEnableEXT::eSynchronizationValidation); + config.enable_feature(vk::ValidationFeatureEnableEXT::eSynchronizationValidation); }, // Pass windows: mainWnd,