Skip to content

Commit

Permalink
Towards fixing everything.
Browse files Browse the repository at this point in the history
Most importantly these issues: KhronosGroup/Vulkan-ValidationLayers#6177
  • Loading branch information
johannesugb committed Mar 26, 2024
1 parent 3a2507e commit e9fbe52
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
20 changes: 20 additions & 0 deletions auto_vk_toolkit/include/imgui_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -156,6 +175,7 @@ namespace avk
// customization
std::function<void(float)> mAlterSettingsBeforeInitialization = {};
std::string mCustomTtfFont = {};
layout::image_layout mIncomingLayout;
};

}
18 changes: 9 additions & 9 deletions auto_vk_toolkit/src/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ namespace avk

auto* wnd = context().main_window();
std::vector<attachment> 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??):
//
Expand All @@ -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:
)
}
);
Expand All @@ -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:
)
}
);
Expand Down
8 changes: 4 additions & 4 deletions auto_vk_toolkit/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
8 changes: 4 additions & 4 deletions examples/framebuffer/source/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/source/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/model_loader/source/model_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e9fbe52

Please sign in to comment.