diff --git a/Source/Renderer/Renderer/BackendDispatch.cpp b/Source/Renderer/Renderer/BackendDispatch.cpp index e2a23df1..f2bde2f7 100644 --- a/Source/Renderer/Renderer/BackendDispatch.cpp +++ b/Source/Renderer/Renderer/BackendDispatch.cpp @@ -319,6 +319,12 @@ namespace Renderer renderer->BufferBarrier(commandList, actualData->bufferID, actualData->from); } + void BackendDispatch::UploadBufferBarrier(Renderer* renderer, CommandListID commandList, const void*) + { + ZoneScopedC(tracy::Color::Red3); + renderer->UploadBufferBarrier(commandList); + } + void BackendDispatch::DrawImgui(Renderer* renderer, CommandListID commandList, const void* data) { ZoneScopedC(tracy::Color::Red3); diff --git a/Source/Renderer/Renderer/BackendDispatch.h b/Source/Renderer/Renderer/BackendDispatch.h index ca03f756..ea9d15d2 100644 --- a/Source/Renderer/Renderer/BackendDispatch.h +++ b/Source/Renderer/Renderer/BackendDispatch.h @@ -60,6 +60,7 @@ namespace Renderer static void ImageBarrier(Renderer* renderer, CommandListID commandList, const void* data); static void DepthImageBarrier(Renderer* renderer, CommandListID commandList, const void* data); static void BufferBarrier(Renderer* renderer, CommandListID commandList, const void* data); + static void UploadBufferBarrier(Renderer* renderer, CommandListID commandList, const void*); static void DrawImgui(Renderer* renderer, CommandListID commandList, const void* data); diff --git a/Source/Renderer/Renderer/CommandList.cpp b/Source/Renderer/Renderer/CommandList.cpp index 02ab97a1..e36f6614 100644 --- a/Source/Renderer/Renderer/CommandList.cpp +++ b/Source/Renderer/Renderer/CommandList.cpp @@ -4,41 +4,42 @@ #include "DescriptorSetResource.h" // Commands +#include "Commands/AddSignalSemaphore.h" +#include "Commands/AddWaitSemaphore.h" +#include "Commands/BeginTrace.h" +#include "Commands/BindDescriptorSet.h" +#include "Commands/BufferBarrier.h" #include "Commands/Clear.h" +#include "Commands/CopyBuffer.h" +#include "Commands/CopyImage.h" +#include "Commands/DepthImageBarrier.h" +#include "Commands/Dispatch.h" +#include "Commands/DispatchIndirect.h" #include "Commands/Draw.h" -#include "Commands/DrawIndirect.h" -#include "Commands/DrawIndirectCount.h" +#include "Commands/DrawImgui.h" #include "Commands/DrawIndexed.h" #include "Commands/DrawIndexedIndirect.h" #include "Commands/DrawIndexedIndirectCount.h" -#include "Commands/Dispatch.h" -#include "Commands/DispatchIndirect.h" +#include "Commands/DrawIndirect.h" +#include "Commands/DrawIndirectCount.h" +#include "Commands/EndTrace.h" +#include "Commands/FidelityFXCommands.h" +#include "Commands/FillBuffer.h" +#include "Commands/ImageBarrier.h" +#include "Commands/MarkFrameStart.h" #include "Commands/PopMarker.h" +#include "Commands/PushConstant.h" #include "Commands/PushMarker.h" -#include "Commands/SetPipeline.h" +#include "Commands/SetBuffer.h" #include "Commands/SetDepthBias.h" +#include "Commands/SetIndexBuffer.h" +#include "Commands/SetPipeline.h" #include "Commands/SetScissorRect.h" -#include "Commands/SetViewport.h" #include "Commands/SetVertexBuffer.h" -#include "Commands/SetIndexBuffer.h" -#include "Commands/SetBuffer.h" -#include "Commands/BindDescriptorSet.h" -#include "Commands/MarkFrameStart.h" -#include "Commands/BeginTrace.h" -#include "Commands/EndTrace.h" -#include "Commands/AddSignalSemaphore.h" -#include "Commands/AddWaitSemaphore.h" -#include "Commands/CopyImage.h" -#include "Commands/CopyBuffer.h" -#include "Commands/FillBuffer.h" -#include "Commands/UpdateBuffer.h" -#include "Commands/ImageBarrier.h" -#include "Commands/DepthImageBarrier.h" -#include "Commands/BufferBarrier.h" -#include "Commands/DrawImgui.h" -#include "Commands/PushConstant.h" +#include "Commands/SetViewport.h" #include "Commands/TimeQuery.h" -#include "Commands/FidelityFXCommands.h" +#include "Commands/UpdateBuffer.h" +#include "Commands/UploadBufferBarrier.h" namespace Renderer { @@ -887,6 +888,15 @@ namespace Renderer BufferBarrier(bufferID, from); } + void CommandList::UploadBufferBarrier() + { + Commands::UploadBufferBarrier* command = AddCommand(); + +#if COMMANDLIST_DEBUG_IMMEDIATE_MODE + Commands::UploadBufferBarrier::DISPATCH_FUNCTION(_renderer, _immediateCommandList, command); +#endif + } + void CommandList::DrawImgui() { Commands::DrawImgui* command = AddCommand(); diff --git a/Source/Renderer/Renderer/CommandList.h b/Source/Renderer/Renderer/CommandList.h index 200672cb..0da9d401 100644 --- a/Source/Renderer/Renderer/CommandList.h +++ b/Source/Renderer/Renderer/CommandList.h @@ -126,6 +126,7 @@ namespace Renderer void ImageBarrier(DepthImageMutableResource resource); void BufferBarrier(BufferResource resource, BufferPassUsage from); void BufferBarrier(BufferMutableResource resource, BufferPassUsage from); + void UploadBufferBarrier(); void DrawImgui(); diff --git a/Source/Renderer/Renderer/Commands/Commands.cpp b/Source/Renderer/Renderer/Commands/Commands.cpp index e909f088..b890b11c 100644 --- a/Source/Renderer/Renderer/Commands/Commands.cpp +++ b/Source/Renderer/Renderer/Commands/Commands.cpp @@ -1,38 +1,39 @@ +#include "AddSignalSemaphore.h" +#include "AddWaitSemaphore.h" +#include "BeginTrace.h" +#include "BindDescriptorSet.h" +#include "BufferBarrier.h" #include "Clear.h" +#include "CopyBuffer.h" +#include "CopyImage.h" +#include "DepthImageBarrier.h" +#include "Dispatch.h" +#include "DispatchIndirect.h" #include "Draw.h" -#include "DrawIndirect.h" -#include "DrawIndirectCount.h" +#include "DrawImgui.h" #include "DrawIndexed.h" #include "DrawIndexedIndirect.h" #include "DrawIndexedIndirectCount.h" -#include "Dispatch.h" -#include "DispatchIndirect.h" +#include "DrawIndirect.h" +#include "DrawIndirectCount.h" +#include "EndTrace.h" +#include "FidelityFXCommands.h" +#include "FillBuffer.h" +#include "ImageBarrier.h" +#include "MarkFrameStart.h" #include "PopMarker.h" +#include "PushConstant.h" #include "PushMarker.h" -#include "SetPipeline.h" +#include "SetBuffer.h" #include "SetDepthBias.h" +#include "SetIndexBuffer.h" +#include "SetPipeline.h" #include "SetScissorRect.h" -#include "SetViewport.h" #include "SetVertexBuffer.h" -#include "SetIndexBuffer.h" -#include "SetBuffer.h" -#include "BindDescriptorSet.h" -#include "MarkFrameStart.h" -#include "BeginTrace.h" -#include "EndTrace.h" -#include "AddSignalSemaphore.h" -#include "AddWaitSemaphore.h" -#include "CopyImage.h" -#include "CopyBuffer.h" -#include "FillBuffer.h" -#include "UpdateBuffer.h" -#include "ImageBarrier.h" -#include "BufferBarrier.h" -#include "DepthImageBarrier.h" -#include "DrawImgui.h" -#include "PushConstant.h" +#include "SetViewport.h" #include "TimeQuery.h" -#include "FidelityFXCommands.h" +#include "UpdateBuffer.h" +#include "UploadBufferBarrier.h" #include "Renderer/BackendDispatch.h" @@ -40,48 +41,49 @@ namespace Renderer { namespace Commands { + const BackendDispatchFunction AddSignalSemaphore::DISPATCH_FUNCTION = &BackendDispatch::AddSignalSemaphore; + const BackendDispatchFunction AddWaitSemaphore::DISPATCH_FUNCTION = &BackendDispatch::AddWaitSemaphore; + const BackendDispatchFunction BeginComputePipeline::DISPATCH_FUNCTION = &BackendDispatch::BeginComputePipeline; + const BackendDispatchFunction BeginGraphicsPipeline::DISPATCH_FUNCTION = &BackendDispatch::BeginGraphicsPipeline; + const BackendDispatchFunction BeginTimeQuery::DISPATCH_FUNCTION = &BackendDispatch::BeginTimeQuery; + const BackendDispatchFunction BeginTrace::DISPATCH_FUNCTION = &BackendDispatch::BeginTrace; + const BackendDispatchFunction BindDescriptorSet::DISPATCH_FUNCTION = &BackendDispatch::BindDescriptorSet; + const BackendDispatchFunction BufferBarrier::DISPATCH_FUNCTION = &BackendDispatch::BufferBarrier; + const BackendDispatchFunction ClearDepthImage::DISPATCH_FUNCTION = &BackendDispatch::ClearDepthImage; const BackendDispatchFunction ClearImageColor::DISPATCH_FUNCTION = &BackendDispatch::ClearImageColor; - const BackendDispatchFunction ClearImageUInt::DISPATCH_FUNCTION = &BackendDispatch::ClearImageUInt; const BackendDispatchFunction ClearImageInt::DISPATCH_FUNCTION = &BackendDispatch::ClearImageInt; - const BackendDispatchFunction ClearDepthImage::DISPATCH_FUNCTION = &BackendDispatch::ClearDepthImage; + const BackendDispatchFunction ClearImageUInt::DISPATCH_FUNCTION = &BackendDispatch::ClearImageUInt; + const BackendDispatchFunction CopyBuffer::DISPATCH_FUNCTION = &BackendDispatch::CopyBuffer; + const BackendDispatchFunction CopyDepthImage::DISPATCH_FUNCTION = &BackendDispatch::CopyDepthImage; + const BackendDispatchFunction CopyImage::DISPATCH_FUNCTION = &BackendDispatch::CopyImage; + const BackendDispatchFunction DepthImageBarrier::DISPATCH_FUNCTION = &BackendDispatch::DepthImageBarrier; + const BackendDispatchFunction Dispatch::DISPATCH_FUNCTION = &BackendDispatch::Dispatch; + const BackendDispatchFunction DispatchIndirect::DISPATCH_FUNCTION = &BackendDispatch::DispatchIndirect; const BackendDispatchFunction Draw::DISPATCH_FUNCTION = &BackendDispatch::Draw; - const BackendDispatchFunction DrawIndirect::DISPATCH_FUNCTION = &BackendDispatch::DrawIndirect; - const BackendDispatchFunction DrawIndirectCount::DISPATCH_FUNCTION = &BackendDispatch::DrawIndirectCount; + const BackendDispatchFunction DrawImgui::DISPATCH_FUNCTION = &BackendDispatch::DrawImgui; const BackendDispatchFunction DrawIndexed::DISPATCH_FUNCTION = &BackendDispatch::DrawIndexed; const BackendDispatchFunction DrawIndexedIndirect::DISPATCH_FUNCTION = &BackendDispatch::DrawIndexedIndirect; const BackendDispatchFunction DrawIndexedIndirectCount::DISPATCH_FUNCTION = &BackendDispatch::DrawIndexedIndirectCount; - const BackendDispatchFunction Dispatch::DISPATCH_FUNCTION = &BackendDispatch::Dispatch; - const BackendDispatchFunction DispatchIndirect::DISPATCH_FUNCTION = &BackendDispatch::DispatchIndirect; - const BackendDispatchFunction PopMarker::DISPATCH_FUNCTION = &BackendDispatch::PopMarker; - const BackendDispatchFunction PushMarker::DISPATCH_FUNCTION = &BackendDispatch::PushMarker; - const BackendDispatchFunction BeginGraphicsPipeline::DISPATCH_FUNCTION = &BackendDispatch::BeginGraphicsPipeline; - const BackendDispatchFunction EndGraphicsPipeline::DISPATCH_FUNCTION = &BackendDispatch::EndGraphicsPipeline; - const BackendDispatchFunction BeginComputePipeline::DISPATCH_FUNCTION = &BackendDispatch::BeginComputePipeline; + const BackendDispatchFunction DrawIndirect::DISPATCH_FUNCTION = &BackendDispatch::DrawIndirect; + const BackendDispatchFunction DrawIndirectCount::DISPATCH_FUNCTION = &BackendDispatch::DrawIndirectCount; const BackendDispatchFunction EndComputePipeline::DISPATCH_FUNCTION = &BackendDispatch::EndComputePipeline; - const BackendDispatchFunction BeginTimeQuery::DISPATCH_FUNCTION = &BackendDispatch::BeginTimeQuery; + const BackendDispatchFunction EndGraphicsPipeline::DISPATCH_FUNCTION = &BackendDispatch::EndGraphicsPipeline; const BackendDispatchFunction EndTimeQuery::DISPATCH_FUNCTION = &BackendDispatch::EndTimeQuery; - const BackendDispatchFunction SetDepthBias::DISPATCH_FUNCTION = &BackendDispatch::SetDepthBias; - const BackendDispatchFunction SetScissorRect::DISPATCH_FUNCTION = &BackendDispatch::SetScissorRect; - const BackendDispatchFunction SetViewport::DISPATCH_FUNCTION = &BackendDispatch::SetViewport; - const BackendDispatchFunction SetVertexBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetVertexBuffer; - const BackendDispatchFunction SetIndexBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetIndexBuffer; - const BackendDispatchFunction SetBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetBuffer; - const BackendDispatchFunction BindDescriptorSet::DISPATCH_FUNCTION = &BackendDispatch::BindDescriptorSet; - const BackendDispatchFunction MarkFrameStart::DISPATCH_FUNCTION = &BackendDispatch::MarkFrameStart; - const BackendDispatchFunction BeginTrace::DISPATCH_FUNCTION = &BackendDispatch::BeginTrace; const BackendDispatchFunction EndTrace::DISPATCH_FUNCTION = &BackendDispatch::EndTrace; - const BackendDispatchFunction AddSignalSemaphore::DISPATCH_FUNCTION = &BackendDispatch::AddSignalSemaphore; - const BackendDispatchFunction AddWaitSemaphore::DISPATCH_FUNCTION = &BackendDispatch::AddWaitSemaphore; - const BackendDispatchFunction CopyImage::DISPATCH_FUNCTION = &BackendDispatch::CopyImage; - const BackendDispatchFunction CopyDepthImage::DISPATCH_FUNCTION = &BackendDispatch::CopyDepthImage; - const BackendDispatchFunction CopyBuffer::DISPATCH_FUNCTION = &BackendDispatch::CopyBuffer; const BackendDispatchFunction FillBuffer::DISPATCH_FUNCTION = &BackendDispatch::FillBuffer; - const BackendDispatchFunction UpdateBuffer::DISPATCH_FUNCTION = &BackendDispatch::UpdateBuffer; const BackendDispatchFunction ImageBarrier::DISPATCH_FUNCTION = &BackendDispatch::ImageBarrier; - const BackendDispatchFunction DepthImageBarrier::DISPATCH_FUNCTION = &BackendDispatch::DepthImageBarrier; - const BackendDispatchFunction BufferBarrier::DISPATCH_FUNCTION = &BackendDispatch::BufferBarrier; - const BackendDispatchFunction DrawImgui::DISPATCH_FUNCTION = &BackendDispatch::DrawImgui; + const BackendDispatchFunction MarkFrameStart::DISPATCH_FUNCTION = &BackendDispatch::MarkFrameStart; + const BackendDispatchFunction PopMarker::DISPATCH_FUNCTION = &BackendDispatch::PopMarker; const BackendDispatchFunction PushConstant::DISPATCH_FUNCTION = &BackendDispatch::PushConstant; + const BackendDispatchFunction PushMarker::DISPATCH_FUNCTION = &BackendDispatch::PushMarker; + const BackendDispatchFunction SetBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetBuffer; + const BackendDispatchFunction SetDepthBias::DISPATCH_FUNCTION = &BackendDispatch::SetDepthBias; + const BackendDispatchFunction SetIndexBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetIndexBuffer; + const BackendDispatchFunction SetScissorRect::DISPATCH_FUNCTION = &BackendDispatch::SetScissorRect; + const BackendDispatchFunction SetVertexBuffer::DISPATCH_FUNCTION = &BackendDispatch::SetVertexBuffer; + const BackendDispatchFunction SetViewport::DISPATCH_FUNCTION = &BackendDispatch::SetViewport; + const BackendDispatchFunction UpdateBuffer::DISPATCH_FUNCTION = &BackendDispatch::UpdateBuffer; + const BackendDispatchFunction UploadBufferBarrier::DISPATCH_FUNCTION = &BackendDispatch::UploadBufferBarrier; // FidelityFX const BackendDispatchFunction DispatchCacao::DISPATCH_FUNCTION = &BackendDispatch::DispatchCacao; diff --git a/Source/Renderer/Renderer/Commands/UploadBufferBarrier.h b/Source/Renderer/Renderer/Commands/UploadBufferBarrier.h new file mode 100644 index 00000000..ffb5327f --- /dev/null +++ b/Source/Renderer/Renderer/Commands/UploadBufferBarrier.h @@ -0,0 +1,15 @@ +#pragma once +#include "Renderer/BackendDispatch.h" + +#include + +namespace Renderer +{ + namespace Commands + { + struct UploadBufferBarrier + { + static const BackendDispatchFunction DISPATCH_FUNCTION; + }; + } +} \ No newline at end of file diff --git a/Source/Renderer/Renderer/Descriptors/ComputePipelineDesc.h b/Source/Renderer/Renderer/Descriptors/ComputePipelineDesc.h index f54ef734..a129b018 100644 --- a/Source/Renderer/Renderer/Descriptors/ComputePipelineDesc.h +++ b/Source/Renderer/Renderer/Descriptors/ComputePipelineDesc.h @@ -11,6 +11,8 @@ namespace Renderer struct ComputePipelineDesc { ComputeShaderID computeShader = ComputeShaderID::Invalid(); + + std::string debugName; }; PRAGMA_NO_PADDING_END; diff --git a/Source/Renderer/Renderer/Descriptors/GraphicsPipelineDesc.h b/Source/Renderer/Renderer/Descriptors/GraphicsPipelineDesc.h index 87c337ce..b3edcca2 100644 --- a/Source/Renderer/Renderer/Descriptors/GraphicsPipelineDesc.h +++ b/Source/Renderer/Renderer/Descriptors/GraphicsPipelineDesc.h @@ -41,6 +41,8 @@ namespace Renderer States states; // Everything below this isn't hashable in the PipelineHandler since it will depend on the RenderGraph (which gets recreated every frame) + std::string debugName = ""; + std::function ResourceToImageID = nullptr; std::function ResourceToDepthImageID = nullptr; std::function MutableResourceToImageID = nullptr; diff --git a/Source/Renderer/Renderer/RenderGraph.cpp b/Source/Renderer/Renderer/RenderGraph.cpp index 083cb1ad..eb7e6e5d 100644 --- a/Source/Renderer/Renderer/RenderGraph.cpp +++ b/Source/Renderer/Renderer/RenderGraph.cpp @@ -130,6 +130,8 @@ namespace Renderer commandList.BeginTimeQuery(totalTimeQueryID); commandList.PushMarker("RenderGraph", Color::PastelBlue); + commandList.UploadBufferBarrier(); + for (u32 i = 0; i < data->passes.Count(); i++) { IRenderPass* pass = data->passes[i]; @@ -145,6 +147,7 @@ namespace Renderer commandList.BeginTimeQuery(passTimeQueryID); commandList.PushMarker(pass->_name, Color::PastelGreen); + resources.SetPassName(pass->_name); commandList.SetCurrentPassIndex(i); _renderGraphBuilder->PrePass(commandList, i, pass->_name); diff --git a/Source/Renderer/Renderer/RenderGraphBuilder.cpp b/Source/Renderer/Renderer/RenderGraphBuilder.cpp index e79e070e..0d5cfd5f 100644 --- a/Source/Renderer/Renderer/RenderGraphBuilder.cpp +++ b/Source/Renderer/Renderer/RenderGraphBuilder.cpp @@ -85,6 +85,7 @@ namespace Renderer NC_LOG_CRITICAL("Please implement more of these"); } + commandList.ImageBarrier(resource); _resources.SetLastBarrier(imageID, currentPassIndex); } @@ -96,6 +97,7 @@ namespace Renderer const DepthImageDesc& imageDesc = _renderer->GetImageDesc(imageID); commandList.Clear(resource, imageDesc.depthClearValue); + commandList.ImageBarrier(resource); _resources.SetLastBarrier(imageID, currentPassIndex); } } diff --git a/Source/Renderer/Renderer/RenderGraphResources.cpp b/Source/Renderer/Renderer/RenderGraphResources.cpp index 26fa7e8d..6916c057 100644 --- a/Source/Renderer/Renderer/RenderGraphResources.cpp +++ b/Source/Renderer/Renderer/RenderGraphResources.cpp @@ -70,6 +70,8 @@ namespace Renderer DynamicArray trackedDescriptorSets; + std::string currentPassName; + static robin_hood::unordered_map imageIDToResource; static robin_hood::unordered_map depthImageIDToResource; static robin_hood::unordered_map bufferIDToResource; @@ -92,6 +94,9 @@ namespace Renderer void RenderGraphResources::InitializePipelineDesc(GraphicsPipelineDesc& desc) { + RenderGraphResourcesData* data = static_cast(_data); + desc.debugName = data->currentPassName; + desc.ResourceToImageID = [&](ImageResource resource) { return GetImage(resource); @@ -112,6 +117,8 @@ namespace Renderer void RenderGraphResources::InitializePipelineDesc(ComputePipelineDesc& desc) { + RenderGraphResourcesData* data = static_cast(_data); + desc.debugName = data->currentPassName; } const ImageDesc& RenderGraphResources::GetImageDesc(ImageResource resource) @@ -701,4 +708,10 @@ namespace Renderer data->trackedDepthImageLastBarrier[index] = passID; } + + void RenderGraphResources::SetPassName(std::string passName) + { + RenderGraphResourcesData* data = static_cast(_data); + data->currentPassName = passName; + } } \ No newline at end of file diff --git a/Source/Renderer/Renderer/RenderGraphResources.h b/Source/Renderer/Renderer/RenderGraphResources.h index dbb14b7f..b26888da 100644 --- a/Source/Renderer/Renderer/RenderGraphResources.h +++ b/Source/Renderer/Renderer/RenderGraphResources.h @@ -137,12 +137,15 @@ namespace Renderer void SetLastBarrier(ImageID imageID, u32 passID); void SetLastBarrier(DepthImageID imageID, u32 passID); + void SetPassName(std::string passName); + private: Renderer* _renderer = nullptr; Memory::Allocator* _allocator = nullptr; IRenderGraphResourcesData* _data = nullptr; + friend class RenderGraph; friend class RenderGraphBuilder; friend class CommandList; friend class DescriptorSetResource; diff --git a/Source/Renderer/Renderer/Renderer.h b/Source/Renderer/Renderer/Renderer.h index ca658005..be19700a 100644 --- a/Source/Renderer/Renderer/Renderer.h +++ b/Source/Renderer/Renderer/Renderer.h @@ -154,6 +154,7 @@ namespace Renderer virtual void ImageBarrier(CommandListID commandListID, ImageID imageID) = 0; virtual void ImageBarrier(CommandListID commandListID, DepthImageID imageID) = 0; virtual void BufferBarrier(CommandListID commandListID, BufferID bufferID, BufferPassUsage from) = 0; + virtual void UploadBufferBarrier(CommandListID commandListID) = 0; virtual void PushConstant(CommandListID commandListID, void* data, u32 offset, u32 size) = 0; virtual void FillBuffer(CommandListID commandListID, BufferID dstBuffer, u64 dstOffset, u64 size, u32 data) = 0; diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/BufferHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/BufferHandlerVK.cpp index 47c6b137..3b09e17e 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/BufferHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/BufferHandlerVK.cpp @@ -192,7 +192,7 @@ namespace Renderer } buffer.name = desc.name; - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)buffer.buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, buffer.name.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)buffer.buffer, VK_OBJECT_TYPE_BUFFER, buffer.name.c_str()); return bufferID; } diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.cpp index 1e0881bc..1a7c7625 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.cpp @@ -5,12 +5,13 @@ namespace Renderer namespace Backend { bool DebugMarkerUtilVK::_initialized = false; - bool DebugMarkerUtilVK::_debugMarkersAvailable = false; - bool DebugMarkerUtilVK::_debugMarkersEnabled = false; - PFN_vkDebugMarkerSetObjectTagEXT DebugMarkerUtilVK::fnDebugMarkerSetObjectTag = nullptr; - PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerUtilVK::fnDebugMarkerSetObjectName = nullptr; - PFN_vkCmdDebugMarkerBeginEXT DebugMarkerUtilVK::fnCmdDebugMarkerBegin = nullptr; - PFN_vkCmdDebugMarkerEndEXT DebugMarkerUtilVK::fnCmdDebugMarkerEnd = nullptr; - PFN_vkCmdDebugMarkerInsertEXT DebugMarkerUtilVK::fnCmdDebugMarkerInsert = nullptr; + bool DebugMarkerUtilVK::_debugUtilsEnabled = false; + bool DebugMarkerUtilVK::_debugUtilsAvailable = false; + + PFN_vkSetDebugUtilsObjectTagEXT DebugMarkerUtilVK::fnSetDebugUtilsObjectTag = nullptr; + PFN_vkSetDebugUtilsObjectNameEXT DebugMarkerUtilVK::fnSetDebugUtilsObjectName = nullptr; + PFN_vkCmdBeginDebugUtilsLabelEXT DebugMarkerUtilVK::fnCmdBeginDebugUtilsLabel = nullptr; + PFN_vkCmdEndDebugUtilsLabelEXT DebugMarkerUtilVK::fnCmdEndDebugUtilsLabel = nullptr; + PFN_vkCmdInsertDebugUtilsLabelEXT DebugMarkerUtilVK::fnCmdInsertDebugUtilsLabel = nullptr; } } diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.h b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.h index 19dba728..f426c682 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.h +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/DebugMarkerUtilVK.h @@ -17,98 +17,106 @@ namespace Renderer static bool GetDebugMarkersEnabled() { - return _debugMarkersEnabled; + return _debugUtilsEnabled; } - static void SetObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char* name) + static void SetObjectName(VkDevice device, uint64_t object, VkObjectType objectType, const char* name) { - if (_debugMarkersAvailable && _debugMarkersEnabled) + if (_debugUtilsAvailable && _debugUtilsEnabled) { - VkDebugMarkerObjectNameInfoEXT nameInfo = {}; - nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT; - nameInfo.objectType = objectType; - nameInfo.object = object; - nameInfo.pObjectName = name; - fnDebugMarkerSetObjectName(device, &nameInfo); + const VkDebugUtilsObjectNameInfoEXT nameInfo = + { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, + .pNext = NULL, + .objectType = objectType, + .objectHandle = object, + .pObjectName = name, + }; + fnSetDebugUtilsObjectName(device, &nameInfo); } } static void PushMarker(VkCommandBuffer commandBuffer, Color color, std::string name) { - if (_debugMarkersAvailable && _debugMarkersEnabled) + if (_debugUtilsAvailable && _debugUtilsEnabled) { - VkDebugMarkerMarkerInfoEXT markerInfo = {}; - markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT; - - markerInfo.color[0] = color.r; - markerInfo.color[1] = color.g; - markerInfo.color[2] = color.b; - markerInfo.color[3] = color.a; - - markerInfo.pMarkerName = name.c_str(); - fnCmdDebugMarkerBegin(commandBuffer, &markerInfo); + VkDebugUtilsLabelEXT label = + { + .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, + .pNext = NULL, + .pLabelName = NULL, + .color = { 0.0f, 0.0f, 0.0f, 0.0f }, + }; + + label.color[0] = color.r; + label.color[1] = color.g; + label.color[2] = color.b; + label.color[3] = color.a; + + label.pLabelName = name.c_str(); + fnCmdBeginDebugUtilsLabel(commandBuffer, &label); } } static void PopMarker(VkCommandBuffer commandBuffer) { - if (_debugMarkersAvailable && _debugMarkersEnabled) + if (_debugUtilsAvailable && _debugUtilsEnabled) { - fnCmdDebugMarkerEnd(commandBuffer); + fnCmdEndDebugUtilsLabel(commandBuffer); } } private: - static void InitializeFunctions(VkDevice device) + static void InitializeFunctions(VkInstance instance) { assert(!_initialized); _initialized = true; - if (_debugMarkersAvailable && _debugMarkersEnabled) + if (_debugUtilsAvailable && _debugUtilsEnabled) { - fnDebugMarkerSetObjectTag = (PFN_vkDebugMarkerSetObjectTagEXT)vkGetDeviceProcAddr(device, "vkDebugMarkerSetObjectTagEXT"); - fnDebugMarkerSetObjectName = (PFN_vkDebugMarkerSetObjectNameEXT)vkGetDeviceProcAddr(device, "vkDebugMarkerSetObjectNameEXT"); - fnCmdDebugMarkerBegin = (PFN_vkCmdDebugMarkerBeginEXT)vkGetDeviceProcAddr(device, "vkCmdDebugMarkerBeginEXT"); - fnCmdDebugMarkerEnd = (PFN_vkCmdDebugMarkerEndEXT)vkGetDeviceProcAddr(device, "vkCmdDebugMarkerEndEXT"); - fnCmdDebugMarkerInsert = (PFN_vkCmdDebugMarkerInsertEXT)vkGetDeviceProcAddr(device, "vkCmdDebugMarkerInsertEXT"); + fnSetDebugUtilsObjectTag = (PFN_vkSetDebugUtilsObjectTagEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectTagEXT"); + fnSetDebugUtilsObjectName = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"); + fnCmdBeginDebugUtilsLabel = (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(instance, "vkCmdBeginDebugUtilsLabelEXT"); + fnCmdEndDebugUtilsLabel = (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(instance, "vkCmdEndDebugUtilsLabelEXT"); + fnCmdInsertDebugUtilsLabel = (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(instance, "vkCmdInsertDebugUtilsLabelEXT"); } } static void CheckExtension(const VkExtensionProperties& extension) { - if (_debugMarkersEnabled) + if (_debugUtilsEnabled) { - if (!strcmp(extension.extensionName, VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) + if (!strcmp(extension.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { - _debugMarkersAvailable = true; + _debugUtilsAvailable = true; } } } static void AddValidationLayer(std::vector& layers) { - if (_debugMarkersAvailable && _debugMarkersEnabled) - layers.push_back("VK_EXT_debug_maker"); + if (_debugUtilsAvailable && _debugUtilsEnabled) + layers.push_back("VK_EXT_DEBUG_UTILS_EXTENSION_NAME"); } static void AddEnabledExtension(std::vector& extensions) { - if (_debugMarkersAvailable && _debugMarkersEnabled) - extensions.push_back(VK_EXT_DEBUG_MARKER_EXTENSION_NAME); + if (_debugUtilsAvailable && _debugUtilsEnabled) + extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } - static void SetDebugMarkersEnabled(bool available) { _debugMarkersEnabled = available; } + static void SetDebugUtilsEnabled(bool available) { _debugUtilsEnabled = available; } private: static bool _initialized; - static bool _debugMarkersEnabled; - static bool _debugMarkersAvailable; - - static PFN_vkDebugMarkerSetObjectTagEXT fnDebugMarkerSetObjectTag; - static PFN_vkDebugMarkerSetObjectNameEXT fnDebugMarkerSetObjectName; - static PFN_vkCmdDebugMarkerBeginEXT fnCmdDebugMarkerBegin; - static PFN_vkCmdDebugMarkerEndEXT fnCmdDebugMarkerEnd; - static PFN_vkCmdDebugMarkerInsertEXT fnCmdDebugMarkerInsert; + static bool _debugUtilsEnabled; + static bool _debugUtilsAvailable; + + static PFN_vkSetDebugUtilsObjectTagEXT fnSetDebugUtilsObjectTag; + static PFN_vkSetDebugUtilsObjectNameEXT fnSetDebugUtilsObjectName; + static PFN_vkCmdBeginDebugUtilsLabelEXT fnCmdBeginDebugUtilsLabel; + static PFN_vkCmdEndDebugUtilsLabelEXT fnCmdEndDebugUtilsLabel; + static PFN_vkCmdInsertDebugUtilsLabelEXT fnCmdInsertDebugUtilsLabel; friend class RenderDeviceVK; }; diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ImageHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ImageHandlerVK.cpp index 5dcbd1fd..a2d62f43 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ImageHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ImageHandlerVK.cpp @@ -202,6 +202,12 @@ namespace Renderer vkGetSwapchainImagesKHR(_device->_device, swapChain, &imageCount, images); image.image = images[index]; + for (u32 i = 0; i < 3; i++) + { + std::string imageName = "swapchain"; + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)images[index], VK_OBJECT_TYPE_IMAGE, imageName.c_str()); + } + CreateImageViews(image, format); // Transition image from VK_IMAGE_LAYOUT_UNDEFINED to VK_IMAGE_LAYOUT_GENERAL @@ -589,8 +595,6 @@ namespace Renderer void ImageHandlerVK::CreateImage(Image& image, VkFormat& format) { - // ImageHandlerVKData& data = static_cast(*_data); - // Create image VkImageCreateInfo imageInfo = {}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; @@ -691,6 +695,8 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create image!"); } + + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.image, VK_OBJECT_TYPE_IMAGE, image.desc.debugName.c_str()); } void ImageHandlerVK::CreateImage(DepthImage& image) @@ -746,6 +752,8 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create image!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.image, VK_OBJECT_TYPE_IMAGE, image.desc.debugName.c_str()); + // Create Depth View VkImageViewCreateInfo depthViewInfo = {}; depthViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; @@ -768,7 +776,7 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create depth image view!"); } - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.depthView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, image.desc.debugName.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.depthView, VK_OBJECT_TYPE_IMAGE_VIEW, image.desc.debugName.c_str()); // Transition image from VK_IMAGE_LAYOUT_UNDEFINED to VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL _device->TransitionImageLayout(image.image, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, 1, 1); @@ -813,6 +821,9 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create color image view!"); } + + std::string mipName = image.desc.debugName + " mip " + std::to_string(i); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.mipViews[i], VK_OBJECT_TYPE_IMAGE_VIEW, mipName.c_str()); } if (vkCreateImageView(_device->_device, &colorViewInfo, nullptr, &image.colorView) != VK_SUCCESS) @@ -820,6 +831,8 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create color image view!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.colorView, VK_OBJECT_TYPE_IMAGE_VIEW, image.desc.debugName.c_str()); + // Also create mipViews that are arrays of the specific view, down to the last mip colorViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -833,9 +846,12 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create color image view!"); } + + std::string mipName = image.desc.debugName + " mip array " + std::to_string(i); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.mipArrayViews[i], VK_OBJECT_TYPE_IMAGE_VIEW, mipName.c_str()); } - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.colorView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, image.desc.debugName.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)image.colorView, VK_OBJECT_TYPE_IMAGE_VIEW, image.desc.debugName.c_str()); if (!image.isSwapchain) { diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.cpp index 7304b74c..676776be 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.cpp @@ -5,6 +5,7 @@ #include "ImageHandlerVK.h" #include "SpirvReflect.h" #include "DescriptorSetBuilderVK.h" +#include "DebugMarkerUtilVK.h" #include #include @@ -281,9 +282,10 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create render pass!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.renderPass, VK_OBJECT_TYPE_RENDER_PASS, desc.debugName.c_str()); // -- Create Framebuffer -- - CreateFramebuffer(pipeline); + CreateFramebuffer(pipeline, desc.debugName); // -- Get Reflection data from shader -- std::vector bindInfos; @@ -364,6 +366,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create descriptor set layout!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.descriptorSetLayouts[i], VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, desc.debugName.c_str()); } // -- Create Push Constant Range from reflected SPIR-V -- @@ -590,6 +593,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create pipeline layout!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.pipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT, desc.debugName.c_str()); // Set up dynamic viewport and scissor std::vector dynamicStates; @@ -626,8 +630,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create graphics pipeline!"); } - - + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.pipeline, VK_OBJECT_TYPE_PIPELINE, desc.debugName.c_str()); GraphicsPipelineID pipelineID = GraphicsPipelineID(static_cast(nextID)); pipeline.descriptorSetBuilder = new DescriptorSetBuilderVK(_allocator, pipelineID, this, _shaderHandler, _bufferHandler, _device->_descriptorMegaPool); @@ -696,6 +699,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create descriptor set layout!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.descriptorSetLayouts[i], VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, desc.debugName.c_str()); } VkPipelineLayoutCreateInfo pipelineLayoutInfo = {}; @@ -709,6 +713,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create pipeline layout!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.pipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT, desc.debugName.c_str()); VkPipelineShaderStageCreateInfo shaderStage = { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO }; shaderStage.module = _shaderHandler->GetShaderModule(desc.computeShader); @@ -723,6 +728,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create compute pipeline!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.pipeline, VK_OBJECT_TYPE_PIPELINE, desc.debugName.c_str()); ComputePipelineID pipelineID = ComputePipelineID(static_cast(nextID)); pipeline.descriptorSetBuilder = new DescriptorSetBuilderVK(_allocator, pipelineID, this, _shaderHandler, _bufferHandler, _device->_descriptorMegaPool); @@ -954,7 +960,7 @@ namespace Renderer return sets[setNumber]; } - void PipelineHandlerVK::CreateFramebuffer(GraphicsPipeline& pipeline) + void PipelineHandlerVK::CreateFramebuffer(GraphicsPipeline& pipeline, const std::string& debugName) { u32 numAttachments = pipeline.numRenderTargets; @@ -993,6 +999,7 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create framebuffer!"); } + DebugMarkerUtilVK::SetObjectName(_device->_device, (uint64_t)pipeline.framebuffer, VK_OBJECT_TYPE_FRAMEBUFFER, debugName.c_str()); } } } \ No newline at end of file diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.h b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.h index e06e7711..04fc01d8 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.h +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/PipelineHandlerVK.h @@ -87,7 +87,7 @@ namespace Renderer bool TryFindExistingCPipeline(u64 descHash, size_t& id); DescriptorSetLayoutData& GetDescriptorSet(i32 setNumber, std::vector& sets); - void CreateFramebuffer(GraphicsPipeline& pipeline); + void CreateFramebuffer(GraphicsPipeline& pipeline, const std::string& debugName); private: Memory::Allocator* _allocator; diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.cpp index f70d52b0..dcb5ec96 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.cpp @@ -66,7 +66,9 @@ namespace Renderer "VK_KHR_shader_subgroup_extended_types", "VK_EXT_descriptor_indexing", "VK_EXT_sampler_filter_minmax", - "VK_EXT_host_query_reset" + "VK_EXT_host_query_reset", + "VK_KHR_shader_float16_int8", + "VK_KHR_shader_atomic_int64" }; RenderDeviceVK::RenderDeviceVK(Novus::Window* window) @@ -155,7 +157,7 @@ namespace Renderer void RenderDeviceVK::InitOnce() { //#if _DEBUG - DebugMarkerUtilVK::SetDebugMarkersEnabled(true); + DebugMarkerUtilVK::SetDebugUtilsEnabled(true); //#endif InitVulkan(); SetupDebugMessenger(); @@ -319,12 +321,17 @@ namespace Renderer createInfo.pApplicationInfo = &appInfo; // Check extensions - uint32_t extensionCount = 0; - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); - std::vector extensions(extensionCount); - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data()); - auto requiredExtensions = GetRequiredExtensions(); + auto remainingRequiredExtensions = requiredExtensions; + if (!CheckInstanceExtensionSupport(remainingRequiredExtensions)) + { + for (auto& extension : remainingRequiredExtensions) + { + NC_LOG_ERROR("Missing required extension: {}", extension); + } + + NC_LOG_CRITICAL("Required extensions are missing!"); + } createInfo.enabledExtensionCount = static_cast(requiredExtensions.size()); createInfo.ppEnabledExtensionNames = requiredExtensions.data(); @@ -348,6 +355,8 @@ namespace Renderer { NC_LOG_CRITICAL("Failed to create Vulkan instance!"); } + + DebugMarkerUtilVK::InitializeFunctions(_instance); } VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) @@ -505,7 +514,6 @@ namespace Renderer { enabledExtensions.push_back(extension); } - DebugMarkerUtilVK::AddEnabledExtension(enabledExtensions); createInfo.enabledExtensionCount = static_cast(enabledExtensions.size()); createInfo.ppEnabledExtensionNames = enabledExtensions.data(); @@ -529,8 +537,6 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create logical device!"); } - DebugMarkerUtilVK::InitializeFunctions(_device); - vkGetDeviceQueue(_device, indices.graphicsFamily.value(), 0, &_graphicsQueue); vkGetDeviceQueue(_device, indices.transferFamily.value(), 0, &_transferQueue); vkGetDeviceQueue(_device, indices.presentFamily.value(), 0, &_presentQueue); @@ -850,6 +856,30 @@ namespace Renderer return indices; } + bool RenderDeviceVK::CheckInstanceExtensionSupport(std::vector& requiredExtensions) + { + // Check extensions + uint32_t extensionCount = 0; + vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); + std::vector extensions(extensionCount); + vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data()); + + for (auto extension : extensions) + { + requiredExtensions.erase(std::remove_if(requiredExtensions.begin(), requiredExtensions.end(), + [&extension](const char* requiredExtension) + { + return std::strcmp(requiredExtension, extension.extensionName) == 0; + }), + requiredExtensions.end() + ); + + DebugMarkerUtilVK::CheckExtension(extension); + } + + return requiredExtensions.empty(); + } + bool RenderDeviceVK::CheckDeviceExtensionSupport(VkPhysicalDevice device) { uint32_t extensionCount; @@ -863,8 +893,6 @@ namespace Renderer for (const auto& extension : availableExtensions) { requiredExtensions.erase(extension.extensionName); - - DebugMarkerUtilVK::CheckExtension(extension); } return requiredExtensions.empty(); diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.h b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.h index 95a860af..dab05dc8 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.h +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/RenderDeviceVK.h @@ -96,6 +96,7 @@ namespace Renderer int RateDeviceSuitability(VkPhysicalDevice device); QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device); + bool CheckInstanceExtensionSupport(std::vector& requiredExtensions); bool CheckDeviceExtensionSupport(VkPhysicalDevice device); bool CheckDeviceFeatureSupport(VkPhysicalDevice device, VkPhysicalDeviceFeatures2& requestedFeatures); diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ShaderHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ShaderHandlerVK.cpp index d9bb9277..2ad72d67 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ShaderHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/ShaderHandlerVK.cpp @@ -124,7 +124,7 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create shader module!"); } - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)shaderModule, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, debugName.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)shaderModule, VK_OBJECT_TYPE_SHADER_MODULE, debugName.c_str()); return shaderModule; } diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/TextureHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/TextureHandlerVK.cpp index c7d03cfe..151500a3 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/TextureHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/TextureHandlerVK.cpp @@ -814,7 +814,7 @@ namespace Renderer NC_LOG_CRITICAL("Failed to create image!"); } - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)texture.image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, texture.debugName.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)texture.image, VK_OBJECT_TYPE_IMAGE, texture.debugName.c_str()); //_device->TransitionImageLayout(texture.image, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, texture.layers, texture.mipLevels); @@ -844,7 +844,7 @@ namespace Renderer texture.imguiTextureHandle = ImGui_ImplVulkan_AddTexture(imguiSampler, texture.imageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } - DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)texture.imageView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, texture.debugName.c_str()); + DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)texture.imageView, VK_OBJECT_TYPE_IMAGE_VIEW, texture.debugName.c_str()); } u32 TextureHandlerVK::AddTextureToArrayInternal(const TextureID textureID, const TextureArrayID textureArrayID, u64 hash) diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.cpp index a8c0882f..94bf0cd8 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.cpp @@ -1,11 +1,12 @@ #include "UploadBufferHandlerVK.h" #include "BufferHandlerVK.h" -#include "TextureHandlerVK.h" #include "CommandListHandlerVK.h" -#include "SemaphoreHandlerVK.h" +#include "DebugMarkerUtilVK.h" #include "RenderDeviceVK.h" #include "Renderer/Renderers/Vulkan/RendererVK.h" #include "Renderer/RenderSettings.h" +#include "SemaphoreHandlerVK.h" +#include "TextureHandlerVK.h" #include #include @@ -113,6 +114,9 @@ namespace Renderer bool needsWait = false; std::mutex submitMutex; SemaphoreID uploadFinishedSemaphore; + + // These are copies of the barriers which needs to run on the main commandlist + moodycamel::ConcurrentQueue bufferMemoryBarriers; }; void UploadBufferHandlerVK::Init(RendererVK* renderer, RenderDeviceVK* device, BufferHandlerVK* bufferHandler, TextureHandlerVK* textureHandler, SemaphoreHandlerVK* semaphoreHandler, CommandListHandlerVK* commandListHandler) @@ -182,8 +186,8 @@ namespace Renderer std::scoped_lock lock(data->submitMutex); CommandListID commandListID = _commandListHandler->BeginCommandList(QueueType::Graphics); - VkCommandBuffer commandBuffer = _commandListHandler->GetCommandBuffer(commandListID); + DebugMarkerUtilVK::PushMarker(commandBuffer, Color::PastelPurple, "Uploads"); #if TRACY_ENABLE TracySourceLocation(ExecuteUpload, "ExecuteUpload", tracy::Color::Yellow2); @@ -193,7 +197,7 @@ namespace Renderer for (u32 i = 0; i < data->stagingBuffers.Num; i++) { - StagingBuffer& stagingBuffer = data->stagingBuffers.Get(i); + StagingBuffer& stagingBuffer = data->stagingBuffers.Get(i); if (stagingBuffer.bufferStatus == BufferStatus::READY && stagingBuffer.totalHandles > 0) { @@ -212,6 +216,7 @@ namespace Renderer _commandListHandler->AddSignalSemaphore(commandListID, semaphore); data->needsWait = true; + DebugMarkerUtilVK::PopMarker(commandBuffer); _commandListHandler->EndCommandList(commandListID, VK_NULL_HANDLE); // Reset staging buffer allocators and uploadToBufferTasks @@ -254,6 +259,21 @@ namespace Renderer data->isDirty = false; } + void UploadBufferHandlerVK::SyncBarrier(VkCommandBuffer commandBuffer) + { + UploadBufferHandlerVKData* data = static_cast(_data); + + VkBufferMemoryBarrier barriers[64]; + u32 numDequeued = static_cast(data->bufferMemoryBarriers.try_dequeue_bulk(&barriers[0], 64)); + + while (numDequeued > 0) + { + vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, numDequeued, &barriers[0], 0, nullptr); + + numDequeued = static_cast(data->bufferMemoryBarriers.try_dequeue_bulk(&barriers[0], 64)); // Try to dequeue more + } + } + std::shared_ptr UploadBufferHandlerVK::CreateUploadBuffer(BufferID targetBuffer, size_t targetOffset, size_t size) { if (targetBuffer == BufferID::Invalid()) @@ -524,8 +544,6 @@ namespace Renderer void UploadBufferHandlerVK::ExecuteStagingBuffer(VkCommandBuffer commandBuffer, StagingBuffer& stagingBuffer) { - //UploadBufferHandlerVKData* data = static_cast(_data); - { UploadTask* task; while (stagingBuffer.uploadTasks.try_dequeue(task)) @@ -635,6 +653,11 @@ namespace Renderer } vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &bufferBarrier, 0, nullptr); + + UploadBufferHandlerVKData* data = static_cast(_data); + bufferBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; + bufferBarrier.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; + data->bufferMemoryBarriers.enqueue(bufferBarrier); } void UploadBufferHandlerVK::HandleUploadToTextureTask(VkCommandBuffer commandBuffer, StagingBuffer& stagingBuffer, UploadToTextureTask* uploadToTextureTask) @@ -772,6 +795,11 @@ namespace Renderer bufferBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &bufferBarrier, 0, nullptr); + + UploadBufferHandlerVKData* data = static_cast(_data); + bufferBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; + bufferBarrier.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_MEMORY_READ_BIT; + data->bufferMemoryBarriers.enqueue(bufferBarrier); } } diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.h b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.h index d35a72c1..06a0b0fd 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.h +++ b/Source/Renderer/Renderer/Renderers/Vulkan/Backend/UploadBufferHandlerVK.h @@ -36,6 +36,8 @@ namespace Renderer void ExecuteUploadTasks(); void Clear(); + void SyncBarrier(VkCommandBuffer commandBuffer); + [[nodiscard]] std::shared_ptr CreateUploadBuffer(BufferID targetBuffer, size_t targetOffset, size_t size); [[nodiscard]] std::shared_ptr CreateUploadBuffer(TextureID targetTexture, size_t targetOffset, size_t size, size_t numMipsToGenerate = 0); void CopyBufferToBuffer(BufferID targetBuffer, size_t targetOffset, BufferID sourceBuffer, size_t sourceOffset, size_t size); diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.cpp b/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.cpp index 36e24008..03cf13b6 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.cpp +++ b/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.cpp @@ -1101,7 +1101,7 @@ namespace Renderer } VkDescriptorSet descriptorSet = builder.BuildDescriptorSet(static_cast(slot), Backend::DescriptorLifetime::PerFrame); - Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)descriptorSet, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, DescriptorSetToName(slot)); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)descriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, DescriptorSetToName(slot)); VkPipelineLayout pipelineLayout = _pipelineHandler->GetPipelineLayout(graphicsPipelineID); @@ -1126,7 +1126,7 @@ namespace Renderer } VkDescriptorSet descriptorSet = builder.BuildDescriptorSet(static_cast(slot), Backend::DescriptorLifetime::PerFrame); - Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)descriptorSet, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, DescriptorSetToName(slot)); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)descriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, DescriptorSetToName(slot)); VkPipelineLayout pipelineLayout = _pipelineHandler->GetPipelineLayout(computePipelineID); @@ -1360,6 +1360,12 @@ namespace Renderer vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, 0, 0, nullptr, 1, &bufferBarrier, 0, nullptr); } + void RendererVK::UploadBufferBarrier(CommandListID commandListID) + { + VkCommandBuffer commandBuffer = _commandListHandler->GetCommandBuffer(commandListID); + _uploadBufferHandler->SyncBarrier(commandBuffer); + } + void RendererVK::PushConstant(CommandListID commandListID, void* data, u32 offset, u32 size) { VkCommandBuffer commandBuffer = _commandListHandler->GetCommandBuffer(commandListID); @@ -1402,6 +1408,7 @@ namespace Renderer { CommandListID commandListID = _commandListHandler->BeginCommandList(Backend::QueueType::Graphics); VkCommandBuffer commandBuffer = _commandListHandler->GetCommandBuffer(commandListID); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)commandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER,"Present CommandList"); // Tracy profiling PushMarker(commandListID, Color::PastelRed, "Present Blitting"); @@ -1425,14 +1432,16 @@ namespace Renderer u32 semaphoreIndex = swapChain->frameIndex; VkFence frameFence = _commandListHandler->GetCurrentFence(); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)frameFence, VK_OBJECT_TYPE_FENCE, "Present Frame Fence"); + + VkSemaphore imageAvailableSemaphore = _semaphoreHandler->GetVkSemaphore(swapChain->imageAvailableSemaphores.Get(semaphoreIndex)); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)imageAvailableSemaphore, VK_OBJECT_TYPE_SEMAPHORE, "Present Image Available Semaphore"); // Acquire next swapchain image VkResult result; u32 frameIndex; { ZoneScopedNC("Present::AcquireNextImage", tracy::Color::Red); - VkSemaphore imageAvailableSemaphore = _semaphoreHandler->GetVkSemaphore(swapChain->imageAvailableSemaphores.Get(semaphoreIndex)); - result = vkAcquireNextImageKHR(_device->_device, swapChain->swapChain, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &frameIndex); if (result == VK_ERROR_OUT_OF_DATE_KHR) @@ -1452,18 +1461,18 @@ namespace Renderer if (semaphoreID != SemaphoreID::Invalid()) { VkSemaphore semaphore = _semaphoreHandler->GetVkSemaphore(semaphoreID); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)semaphore, VK_OBJECT_TYPE_SEMAPHORE, "Present Wait Semaphore"); + _commandListHandler->AddWaitSemaphore(commandListID, semaphore); // Wait for the provided semaphore to finish } - VkSemaphore imageAvailableSemaphore = _semaphoreHandler->GetVkSemaphore(swapChain->imageAvailableSemaphores.Get(semaphoreIndex)); VkSemaphore blitFinishedSemaphore = _semaphoreHandler->GetVkSemaphore(swapChain->blitFinishedSemaphores.Get(semaphoreIndex)); + Backend::DebugMarkerUtilVK::SetObjectName(_device->_device, (u64)imageAvailableSemaphore, VK_OBJECT_TYPE_SEMAPHORE, "Present Blit Finished Semaphore"); _commandListHandler->AddWaitSemaphore(commandListID, imageAvailableSemaphore); // Wait for swapchain image to be available _commandListHandler->AddSignalSemaphore(commandListID, blitFinishedSemaphore); // Signal that blitting is done } - VkImage image = _imageHandler->GetImage(imageID); - // Create sampler SamplerDesc samplerDesc; samplerDesc.enabled = true; @@ -1549,6 +1558,7 @@ namespace Renderer VkPipelineLayout pipelineLayout = _pipelineHandler->GetPipelineLayout(pipelineID); Backend::DescriptorSetBuilderVK& builder = _pipelineHandler->GetDescriptorSetBuilder(pipelineID); + ImageBarrier(commandListID, imageID); BeginPipeline(commandListID, pipelineID); SetViewport(commandListID, _lastViewport); @@ -1597,8 +1607,8 @@ namespace Renderer // Present { - ImageID swapchainImageID = swapChain->imageIDs.Get(frameIndex); - VkImage image = _imageHandler->GetImage(swapchainImageID); + //ImageID swapchainImageID = swapChain->imageIDs.Get(frameIndex); + //VkImage image = _imageHandler->GetImage(swapchainImageID); VkSemaphore blitFinishedSemaphore = _semaphoreHandler->GetVkSemaphore(swapChain->blitFinishedSemaphores.Get(semaphoreIndex)); @@ -1725,6 +1735,12 @@ namespace Renderer // Transition depth image from VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.depthBuffer.resource, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, 1); // Transition image from VK_IMAGE_LAYOUT_GENERAL to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + if (normalImage != ImageID::Invalid()) + { + const ImageDesc& normalImageDesc = _imageHandler->GetImageDesc(normalImage); + _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.normalBuffer.resource, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, normalImageDesc.depth, normalImageDesc.mipLevels); + } + // Transition image from VK_IMAGE_LAYOUT_GENERAL to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL const ImageDesc& outputImageDesc = _imageHandler->GetImageDesc(outputImage); _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.outputBuffer.resource, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, outputImageDesc.depth, outputImageDesc.mipLevels); @@ -1737,6 +1753,12 @@ namespace Renderer // Transition depth image from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL to VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.depthBuffer.resource, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, 1, 1); + // Transition image from VK_IMAGE_LAYOUT_GENERAL to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + if (normalImage != ImageID::Invalid()) + { + const ImageDesc& normalImageDesc = _imageHandler->GetImageDesc(normalImage); + _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.normalBuffer.resource, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, normalImageDesc.depth, normalImageDesc.mipLevels); + } // Transition image from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL to VK_IMAGE_LAYOUT_GENERAL _device->TransitionImageLayout(commandBuffer, (VkImage)dispatchDescription.outputBuffer.resource, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, outputImageDesc.depth, outputImageDesc.mipLevels); } diff --git a/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.h b/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.h index bc8bcafd..8b0f917b 100644 --- a/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.h +++ b/Source/Renderer/Renderer/Renderers/Vulkan/RendererVK.h @@ -137,6 +137,7 @@ namespace Renderer void ImageBarrier(CommandListID commandListID, ImageID imageID) override; void ImageBarrier(CommandListID commandListID, DepthImageID imageID) override; void BufferBarrier(CommandListID commandListID, BufferID bufferID, BufferPassUsage from) override; + void UploadBufferBarrier(CommandListID commandListID) override; void PushConstant(CommandListID commandListID, void* data, u32 offset, u32 size) override; void FillBuffer(CommandListID commandListID, BufferID dstBuffer, u64 dstOffset, u64 size, u32 data) override;