Skip to content

Commit

Permalink
Debug and sync improvements (#32)
Browse files Browse the repository at this point in the history
* WIP Debug and Sync improvements

* Add GPU debug zone for upload buffers
  • Loading branch information
Pursche committed Jul 28, 2024
1 parent 5af2ad4 commit 3f375e3
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 170 deletions.
6 changes: 6 additions & 0 deletions Source/Renderer/Renderer/BackendDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Source/Renderer/Renderer/BackendDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
58 changes: 34 additions & 24 deletions Source/Renderer/Renderer/CommandList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -887,6 +888,15 @@ namespace Renderer
BufferBarrier(bufferID, from);
}

void CommandList::UploadBufferBarrier()
{
Commands::UploadBufferBarrier* command = AddCommand<Commands::UploadBufferBarrier>();

#if COMMANDLIST_DEBUG_IMMEDIATE_MODE
Commands::UploadBufferBarrier::DISPATCH_FUNCTION(_renderer, _immediateCommandList, command);
#endif
}

void CommandList::DrawImgui()
{
Commands::DrawImgui* command = AddCommand<Commands::DrawImgui>();
Expand Down
1 change: 1 addition & 0 deletions Source/Renderer/Renderer/CommandList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
110 changes: 56 additions & 54 deletions Source/Renderer/Renderer/Commands/Commands.cpp
Original file line number Diff line number Diff line change
@@ -1,87 +1,89 @@
#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"

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;
Expand Down
15 changes: 15 additions & 0 deletions Source/Renderer/Renderer/Commands/UploadBufferBarrier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "Renderer/BackendDispatch.h"

#include <Base/Types.h>

namespace Renderer
{
namespace Commands
{
struct UploadBufferBarrier
{
static const BackendDispatchFunction DISPATCH_FUNCTION;
};
}
}
2 changes: 2 additions & 0 deletions Source/Renderer/Renderer/Descriptors/ComputePipelineDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Renderer
struct ComputePipelineDesc
{
ComputeShaderID computeShader = ComputeShaderID::Invalid();

std::string debugName;
};
PRAGMA_NO_PADDING_END;

Expand Down
2 changes: 2 additions & 0 deletions Source/Renderer/Renderer/Descriptors/GraphicsPipelineDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageID(ImageResource resource)> ResourceToImageID = nullptr;
std::function<DepthImageID(DepthImageResource resource)> ResourceToDepthImageID = nullptr;
std::function<ImageID(ImageMutableResource resource)> MutableResourceToImageID = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions Source/Renderer/Renderer/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Source/Renderer/Renderer/RenderGraphBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace Renderer
NC_LOG_CRITICAL("Please implement more of these");
}

commandList.ImageBarrier(resource);
_resources.SetLastBarrier(imageID, currentPassIndex);
}

Expand All @@ -96,6 +97,7 @@ namespace Renderer
const DepthImageDesc& imageDesc = _renderer->GetImageDesc(imageID);
commandList.Clear(resource, imageDesc.depthClearValue);

commandList.ImageBarrier(resource);
_resources.SetLastBarrier(imageID, currentPassIndex);
}
}
Expand Down
13 changes: 13 additions & 0 deletions Source/Renderer/Renderer/RenderGraphResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace Renderer

DynamicArray<DescriptorSet*> trackedDescriptorSets;

std::string currentPassName;

static robin_hood::unordered_map<u32, u32> imageIDToResource;
static robin_hood::unordered_map<u32, u32> depthImageIDToResource;
static robin_hood::unordered_map<u32, u32> bufferIDToResource;
Expand All @@ -92,6 +94,9 @@ namespace Renderer

void RenderGraphResources::InitializePipelineDesc(GraphicsPipelineDesc& desc)
{
RenderGraphResourcesData* data = static_cast<RenderGraphResourcesData*>(_data);
desc.debugName = data->currentPassName;

desc.ResourceToImageID = [&](ImageResource resource)
{
return GetImage(resource);
Expand All @@ -112,6 +117,8 @@ namespace Renderer

void RenderGraphResources::InitializePipelineDesc(ComputePipelineDesc& desc)
{
RenderGraphResourcesData* data = static_cast<RenderGraphResourcesData*>(_data);
desc.debugName = data->currentPassName;
}

const ImageDesc& RenderGraphResources::GetImageDesc(ImageResource resource)
Expand Down Expand Up @@ -701,4 +708,10 @@ namespace Renderer

data->trackedDepthImageLastBarrier[index] = passID;
}

void RenderGraphResources::SetPassName(std::string passName)
{
RenderGraphResourcesData* data = static_cast<RenderGraphResourcesData*>(_data);
data->currentPassName = passName;
}
}
3 changes: 3 additions & 0 deletions Source/Renderer/Renderer/RenderGraphResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Renderer/Renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 3f375e3

Please sign in to comment.