diff --git a/vulkan/vulkan_context.cpp b/vulkan/vulkan_context.cpp index 35ceb45c..3e9e67f7 100644 --- a/vulkan/vulkan_context.cpp +++ b/vulkan/vulkan_context.cpp @@ -230,6 +230,15 @@ vk::CommandBuffer Context::begin_cmd_buffer() return one_time_use_cmd; } +void Context::hard_barrier(vk::CommandBuffer cmd) +{ + vk::MemoryBarrier barrier(vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, + vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite); + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, + vk::PipelineStageFlagBits::eAllCommands, + {}, barrier, {}, {}); +} + void Context::end_cmd_buffer() { one_time_use_cmd.end(); diff --git a/vulkan/vulkan_context.hpp b/vulkan/vulkan_context.hpp index af5ea4c2..0aab8175 100644 --- a/vulkan/vulkan_context.hpp +++ b/vulkan/vulkan_context.hpp @@ -32,6 +32,7 @@ class Context void wait_idle(); vk::CommandBuffer begin_cmd_buffer(); void end_cmd_buffer(); + void hard_barrier(vk::CommandBuffer cmd); vma::Allocator allocator; vk::Device device; diff --git a/vulkan/vulkan_shader_chain.cpp b/vulkan/vulkan_shader_chain.cpp index 4d64fb2e..02b90dbb 100644 --- a/vulkan/vulkan_shader_chain.cpp +++ b/vulkan/vulkan_shader_chain.cpp @@ -279,6 +279,8 @@ bool ShaderChain::load_shader_preset(std::string filename) current_frame_index = 0; last_frame_index = 2; + context->wait_idle(); + return true; } @@ -393,6 +395,8 @@ void ShaderChain::do_frame(uint8_t *data, int width, int height, int stride, vk: if (!context->swapchain->begin_frame()) return; + current_frame_index = context->swapchain->get_current_frame(); + auto cmd = context->swapchain->get_cmd(); update_and_propagate_sizes(width, height, viewport_width, viewport_height); @@ -509,7 +513,6 @@ void ShaderChain::do_frame(uint8_t *data, int width, int height, int stride, vk: context->swapchain->end_frame(); last_frame_index = current_frame_index; - current_frame_index = (current_frame_index + 1) % queue_size; frame_count++; } @@ -523,7 +526,7 @@ void ShaderChain::upload_original(vk::CommandBuffer cmd, uint8_t *data, int widt format, wrap_mode_from_string(pipelines[0]->shader->wrap_mode), pipelines[0]->shader->filter_linear, - true); + pipelines[0]->shader->mipmap_input); }; if (original.size() > original_history_size) diff --git a/vulkan/vulkan_texture.cpp b/vulkan/vulkan_texture.cpp index 13d2bdf7..37a61f3a 100644 --- a/vulkan/vulkan_texture.cpp +++ b/vulkan/vulkan_texture.cpp @@ -108,11 +108,11 @@ void Texture::from_buffer(vk::CommandBuffer cmd, .setImage(image) .setOldLayout(vk::ImageLayout::eUndefined) .setNewLayout(vk::ImageLayout::eTransferDstOptimal) - .setSrcAccessMask(vk::AccessFlagBits::eNone) + .setSrcAccessMask(vk::AccessFlagBits::eShaderRead) .setDstAccessMask(vk::AccessFlagBits::eTransferWrite) .setSubresourceRange(srr(0)); - cmd.pipelineBarrier(vk::PipelineStageFlagBits::eTopOfPipe, + cmd.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, barrier);