Skip to content

Commit

Permalink
WIP Debug and Sync improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Pursche committed Jul 3, 2024
1 parent 6182f8a commit 61fbbe2
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 233 deletions.
78 changes: 11 additions & 67 deletions Source/Base/Base/Util/DebugHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,17 @@ PRAGMA_CLANG_DIAGNOSTIC_PUSH;
PRAGMA_CLANG_DIAGNOSTIC_IGNORE(-Wformat-security);
PRAGMA_CLANG_DIAGNOSTIC_IGNORE(-Wnon-pod-varargs);

namespace Logging
{
using source_location = std::source_location;
[[nodiscard]] constexpr auto get_log_source_location(const source_location& location)
{
return spdlog::source_loc { location.file_name(), static_cast<std::int32_t>(location.line()), location.function_name() };
}

struct format_with_location
{
std::string_view value;
spdlog::source_loc loc;

template <typename String>
format_with_location(const String& s, const source_location& location = source_location::current()) : value{ s }, loc{ get_log_source_location(location) } {}
};
}

class DebugHandler
{
public:
template <typename... Args>
inline static void Print(const std::string_view fmt, Args... args)
{
spdlog::default_logger_raw()->log(spdlog::level::info, std::vformat(fmt, std::make_format_args(std::forward<Args>(args)...)));
}

template <typename... Args>
inline static void PrintTrace(const Logging::format_with_location& fmt, Args... args)
{
spdlog::default_logger_raw()->log(fmt.loc, spdlog::level::trace, std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...)));
}

template <typename... Args>
inline static void PrintDebug(const Logging::format_with_location& fmt, Args... args)
{
spdlog::default_logger_raw()->log(fmt.loc, spdlog::level::debug, std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...)));
}

template <typename... Args>
inline static void PrintWarning(const Logging::format_with_location& fmt, Args... args)
{
spdlog::default_logger_raw()->log(fmt.loc, spdlog::level::warn, std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...)));
}

template <typename... Args>
inline static void PrintError(const Logging::format_with_location& fmt, Args... args)
{
spdlog::default_logger_raw()->log(fmt.loc, spdlog::level::err, std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...)));
}

template <typename... Args>
inline static void PrintFatal(const Logging::format_with_location& fmt, Args... args)
{
spdlog::default_logger_raw()->log(fmt.loc, spdlog::level::critical, std::vformat(fmt.value, std::make_format_args(std::forward<Args>(args)...)));

ReleaseModeBreakpoint();
}

template <typename... Args>
inline static void Assert(bool assertion, const Logging::format_with_location& fmt, Args... args)
{
if (!assertion)
{
PrintFatal(fmt, std::forward<Args>(args)...);
}
}
#define NC_GET_LOGGER() quill::Frontend::get_logger("root")
#define NC_LOG_TRACE_L3(fmt, ...) LOG_TRACE_L3(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_TRACE_L2(fmt, ...) LOG_TRACE_L2(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_TRACE_L1(fmt, ...) LOG_TRACE_L1(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_DEBUG(fmt, ...) LOG_DEBUG(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_INFO(fmt, ...) LOG_INFO(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_WARNING(fmt, ...) LOG_WARNING(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_ERROR(fmt, ...) LOG_ERROR(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_LOG_CRITICAL(fmt, ...) LOG_CRITICAL(NC_GET_LOGGER(), fmt, ##__VA_ARGS__); NC_GET_LOGGER()->flush_log(); ReleaseModeBreakpoint();
#define NC_LOG_BACKTRACE(fmt, ...) LOG_BACKTRACE(NC_GET_LOGGER(), fmt, ##__VA_ARGS__);
#define NC_ASSERT(assertion, fmt, ...) if (!(assertion)) { NC_LOG_CRITICAL(fmt, ##__VA_ARGS__); }

private:
};
Expand Down
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
Loading

0 comments on commit 61fbbe2

Please sign in to comment.