Skip to content

Commit

Permalink
[vulkan] precise barriers for shader read only textures
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Dec 12, 2024
1 parent 1cf3a53 commit 8ce5707
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
16 changes: 8 additions & 8 deletions runtime/Core/Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ namespace Spartan
static bool IsBreadcrumbsEnabled() { return m_breadcrumbs_enabled; }

private:
inline static bool m_validation_layer_enabled = false; // Enables Vulkan diagnostic layers, incurs significant per-draw CPU performance overhead
inline static bool m_gpu_assisted_validation_enabled = false; // Performs GPU-based validation with substantial CPU and GPU performance impact
inline static bool m_logging_to_file_enabled = false; // Writes diagnostic logs to disk, causes high CPU overhead due to file I/O operations
inline static bool m_breadcrumbs_enabled = false; // Tracks GPU crash information in breadcrumbs.txt, minimal overhead (AMD GPUs only)
inline static bool m_renderdoc_enabled = false; // Integrates RenderDoc graphics debugging, introduces high CPU overhead from API wrapping
inline static bool m_gpu_marking_enabled = true; // Enables GPU resource marking with negligible performance cost
inline static bool m_gpu_timing_enabled = true; // Enables GPU performance timing with negligible performance cost
inline static bool m_shader_optimization_enabled = true; // Controls shader optimization, disabling has significant performance implications
inline static bool m_validation_layer_enabled = false; // enables Vulkan diagnostic layers, incurs significant per-draw CPU performance overhead
inline static bool m_gpu_assisted_validation_enabled = false; // performs GPU-based validation with substantial CPU and GPU performance impact
inline static bool m_logging_to_file_enabled = false; // writes diagnostic logs to disk, causes high CPU overhead due to file I/O operations
inline static bool m_breadcrumbs_enabled = false; // tracks GPU crash information in breadcrumbs.txt, minimal overhead (AMD GPUs only)
inline static bool m_renderdoc_enabled = false; // integrates RenderDoc graphics debugging, introduces high CPU overhead from API wrapping
inline static bool m_gpu_marking_enabled = true; // enables GPU resource marking with negligible performance cost
inline static bool m_gpu_timing_enabled = true; // enables GPU performance timing with negligible performance cost
inline static bool m_shader_optimization_enabled = true; // controls shader optimization, disabling has significant performance impact
};
}
27 changes: 12 additions & 15 deletions runtime/RHI/Vulkan/Vulkan_CommandList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace Spartan
if (!is_destination_mask)
{
return make_tuple(
VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT,
VK_ACCESS_2_MEMORY_READ_BIT | VK_ACCESS_2_MEMORY_WRITE_BIT
);
}
Expand All @@ -117,31 +117,30 @@ namespace Spartan
case VK_IMAGE_LAYOUT_PREINITIALIZED:
SP_ASSERT_MSG(!is_destination_mask, "The new layout used in a transition must not be VK_IMAGE_LAYOUT_PREINITIALIZED.");
return make_tuple(
VK_PIPELINE_STAGE_2_HOST_BIT,
VK_PIPELINE_STAGE_2_HOST_BIT,
VK_ACCESS_2_HOST_WRITE_BIT
);

case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
return make_tuple(
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_ACCESS_2_NONE
);

case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
return make_tuple(
VK_PIPELINE_STAGE_2_TRANSFER_BIT,
VK_PIPELINE_STAGE_2_TRANSFER_BIT,
VK_ACCESS_2_TRANSFER_READ_BIT
);

case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
return make_tuple(
VK_PIPELINE_STAGE_2_TRANSFER_BIT,
VK_PIPELINE_STAGE_2_TRANSFER_BIT,
VK_ACCESS_2_TRANSFER_WRITE_BIT
);

case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
{
// todo: use this for more fine-grained synchronization
VkPipelineStageFlags2 used_stages = 0;
used_stages |= pso.shaders[RHI_Shader_Type::Vertex] ? VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT : 0;
used_stages |= pso.shaders[RHI_Shader_Type::Hull] ? VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT : 0;
Expand All @@ -150,9 +149,7 @@ namespace Spartan
used_stages |= pso.shaders[RHI_Shader_Type::Compute] ? VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT : 0;

return make_tuple(
VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT |
VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT,
used_stages,
VK_ACCESS_2_SHADER_READ_BIT
);
}
Expand All @@ -161,25 +158,25 @@ namespace Spartan
if (is_depth)
{
return make_tuple(
VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT |
VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT |
VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT,
VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT_KHR |
VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT_KHR |
VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT_KHR
);
}
else
{
return make_tuple(
VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT
);
}

case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL:
return make_tuple(
VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT |
VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT |
VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT,
VK_ACCESS_2_SHADER_READ_BIT
);
Expand All @@ -193,7 +190,7 @@ namespace Spartan
case VK_IMAGE_LAYOUT_GENERAL:
return make_tuple(
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
VK_ACCESS_2_SHADER_READ_BIT |
VK_ACCESS_2_SHADER_READ_BIT |
VK_ACCESS_2_SHADER_WRITE_BIT
);

Expand Down
4 changes: 2 additions & 2 deletions runtime/RHI/Vulkan/Vulkan_SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ namespace Spartan

void RHI_SwapChain::SetVsync(const bool enabled)
{
// For v-sync, we could Mailbox for lower latency, but Fifo is always supported, so we'll assume that
// for v-sync, we could Mailbox for lower latency, but Fifo is always supported, so we'll assume that

if ((m_present_mode == RHI_Present_Mode::Fifo) != enabled)
{
Expand All @@ -504,7 +504,7 @@ namespace Spartan

bool RHI_SwapChain::GetVsync()
{
// For v-sync, we could Mailbox for lower latency, but Fifo is always supported, so we'll assume that
// for v-sync, we could Mailbox for lower latency, but Fifo is always supported, so we'll assume that
return m_present_mode == RHI_Present_Mode::Fifo;
}

Expand Down

0 comments on commit 8ce5707

Please sign in to comment.