From 9df59713daf3b0373a56013f3f238976cdcd036a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 1 Dec 2024 23:01:33 +1000 Subject: [PATCH] GPUDevice: Put debug messages/scopes behind conditions And completely compile them out in Release builds. Gets Devel close to Release in terms of performance. --- src/util/d3d11_device.cpp | 14 ++- src/util/d3d11_device.h | 2 + src/util/d3d11_pipeline.cpp | 8 ++ src/util/d3d11_pipeline.h | 4 + src/util/d3d11_texture.cpp | 19 +++- src/util/d3d11_texture.h | 8 ++ src/util/d3d12_builders.cpp | 2 +- src/util/d3d12_builders.h | 4 +- src/util/d3d12_device.cpp | 16 ++-- src/util/d3d12_device.h | 2 + src/util/d3d12_pipeline.cpp | 8 ++ src/util/d3d12_pipeline.h | 4 + src/util/d3d12_texture.cpp | 16 ++++ src/util/d3d12_texture.h | 8 ++ src/util/gpu_device.h | 125 +++++++++++++++++++++++--- src/util/gpu_texture.h | 17 ++++ src/util/media_capture.cpp | 2 - src/util/metal_device.h | 14 +++ src/util/metal_device.mm | 28 ++++++ src/util/opengl_device.cpp | 10 +-- src/util/opengl_device.h | 2 + src/util/opengl_pipeline.cpp | 14 +-- src/util/opengl_pipeline.h | 6 +- src/util/opengl_stream_buffer.cpp | 6 +- src/util/opengl_stream_buffer.h | 2 + src/util/opengl_texture.cpp | 24 ++--- src/util/opengl_texture.h | 8 ++ src/util/postprocessing_shader_fx.cpp | 2 +- src/util/postprocessing_shader_fx.h | 2 +- src/util/vulkan_device.cpp | 15 ++-- src/util/vulkan_device.h | 2 + src/util/vulkan_pipeline.cpp | 8 ++ src/util/vulkan_pipeline.h | 4 + src/util/vulkan_texture.cpp | 16 ++++ src/util/vulkan_texture.h | 8 ++ 35 files changed, 357 insertions(+), 73 deletions(-) diff --git a/src/util/d3d11_device.cpp b/src/util/d3d11_device.cpp index db619df30..9f50261d7 100644 --- a/src/util/d3d11_device.cpp +++ b/src/util/d3d11_device.cpp @@ -32,7 +32,7 @@ static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RG void SetD3DDebugObjectName(ID3D11DeviceChild* obj, std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES // WKPDID_D3DDebugObjectName static constexpr GUID guid = {0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}}; @@ -115,7 +115,7 @@ bool D3D11Device::CreateDeviceAndMainSwapChain(std::string_view adapter, Feature } } -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES if (m_debug_device) m_context.As(&m_annotation); #endif @@ -832,36 +832,34 @@ float D3D11Device::GetAndResetAccumulatedGPUTime() return value; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11Device::PushDebugGroup(const char* name) { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_annotation) return; m_annotation->BeginEvent(StringUtil::UTF8StringToWideString(name).c_str()); -#endif } void D3D11Device::PopDebugGroup() { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_annotation) return; m_annotation->EndEvent(); -#endif } void D3D11Device::InsertDebugMessage(const char* msg) { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_annotation) return; m_annotation->SetMarker(StringUtil::UTF8StringToWideString(msg).c_str()); -#endif } +#endif + void D3D11Device::MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) { diff --git a/src/util/d3d11_device.h b/src/util/d3d11_device.h index d06a75872..c279fdf53 100644 --- a/src/util/d3d11_device.h +++ b/src/util/d3d11_device.h @@ -80,9 +80,11 @@ public: std::unique_ptr CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override; std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void PushDebugGroup(const char* name) override; void PopDebugGroup() override; void InsertDebugMessage(const char* msg) override; +#endif void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) override; diff --git a/src/util/d3d11_pipeline.cpp b/src/util/d3d11_pipeline.cpp index b0d4dd681..21bac1563 100644 --- a/src/util/d3d11_pipeline.cpp +++ b/src/util/d3d11_pipeline.cpp @@ -47,11 +47,15 @@ ID3D11ComputeShader* D3D11Shader::GetComputeShader() const return static_cast(m_shader.Get()); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11Shader::SetDebugName(std::string_view name) { SetD3DDebugObjectName(m_shader.Get(), name); } +#endif + std::unique_ptr D3D11Device::CreateShaderFromBinary(GPUShaderStage stage, std::span data, Error* error) { @@ -135,11 +139,15 @@ D3D11Pipeline::~D3D11Pipeline() D3D11Device::GetInstance().UnbindPipeline(this); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11Pipeline::SetDebugName(std::string_view name) { // can't label this directly } +#endif + D3D11Device::ComPtr D3D11Device::GetRasterizationState(const GPUPipeline::RasterizationState& rs, Error* error) { diff --git a/src/util/d3d11_pipeline.h b/src/util/d3d11_pipeline.h index c3d58d3b2..97be1399a 100644 --- a/src/util/d3d11_pipeline.h +++ b/src/util/d3d11_pipeline.h @@ -30,7 +30,9 @@ public: ALWAYS_INLINE const std::vector& GetBytecode() const { return m_bytecode; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D11Shader(GPUShaderStage stage, Microsoft::WRL::ComPtr shader, std::vector bytecode); @@ -49,7 +51,9 @@ class D3D11Pipeline final : public GPUPipeline public: ~D3D11Pipeline() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif ALWAYS_INLINE bool IsComputePipeline() const { return !m_vs; } ALWAYS_INLINE ID3D11RasterizerState* GetRasterizerState() const { return m_rs.Get(); } diff --git a/src/util/d3d11_texture.cpp b/src/util/d3d11_texture.cpp index cd5fd2931..813d5cc46 100644 --- a/src/util/d3d11_texture.cpp +++ b/src/util/d3d11_texture.cpp @@ -42,11 +42,15 @@ D3D11Sampler::D3D11Sampler(ComPtr ss) : m_ss(std::move(ss)) D3D11Sampler::~D3D11Sampler() = default; +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11Sampler::SetDebugName(std::string_view name) { SetD3DDebugObjectName(m_ss.Get(), name); } +#endif + std::unique_ptr D3D11Device::CreateSampler(const GPUSampler::Config& config, Error* error) { static constexpr std::array(GPUSampler::AddressMode::MaxCount)> ta = {{ @@ -200,8 +204,7 @@ bool D3D11Texture::Map(void** map, u32* map_stride, u32 x, u32 y, u32 width, u32 if (IsCompressedFormat(m_format)) { - *map = static_cast(sr.pData) + ((y / GetBlockSize()) * sr.RowPitch) + - ((x / GetBlockSize()) * GetPixelSize()); + *map = static_cast(sr.pData) + ((y / GetBlockSize()) * sr.RowPitch) + ((x / GetBlockSize()) * GetPixelSize()); } else { @@ -225,11 +228,15 @@ void D3D11Texture::GenerateMipmaps() D3D11Device::GetD3DContext()->GenerateMips(m_srv.Get()); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11Texture::SetDebugName(std::string_view name) { SetD3DDebugObjectName(m_texture.Get(), name); } +#endif + DXGI_FORMAT D3D11Texture::GetDXGIFormat() const { return D3DCommon::GetFormatMapping(m_format).resource_format; @@ -419,11 +426,15 @@ void D3D11TextureBuffer::Unmap(u32 used_elements) m_buffer.Unmap(D3D11Device::GetD3DContext(), size); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11TextureBuffer::SetDebugName(std::string_view name) { SetD3DDebugObjectName(m_buffer.GetD3DBuffer(), name); } +#endif + std::unique_ptr D3D11Device::CreateTextureBuffer(GPUTextureBuffer::Format format, u32 size_in_elements, Error* error /* = nullptr */) { @@ -543,6 +554,8 @@ void D3D11DownloadTexture::Flush() // Handled when mapped. } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D11DownloadTexture::SetDebugName(std::string_view name) { if (name.empty()) @@ -551,6 +564,8 @@ void D3D11DownloadTexture::SetDebugName(std::string_view name) SetD3DDebugObjectName(m_texture.Get(), name); } +#endif + std::unique_ptr D3D11Device::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */) { diff --git a/src/util/d3d11_texture.h b/src/util/d3d11_texture.h index 25f636442..0e0617d49 100644 --- a/src/util/d3d11_texture.h +++ b/src/util/d3d11_texture.h @@ -26,7 +26,9 @@ public: ALWAYS_INLINE ID3D11SamplerState* GetSamplerState() const { return m_ss.Get(); } ALWAYS_INLINE ID3D11SamplerState* const* GetSamplerStateArray() const { return m_ss.GetAddressOf(); } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D11Sampler(ComPtr ss); @@ -88,7 +90,9 @@ public: void Unmap() override; void GenerateMipmaps() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D11Texture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type, Format format, Flags flags, @@ -118,7 +122,9 @@ public: void* Map(u32 required_elements) override; void Unmap(u32 used_elements) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D11StreamBuffer m_buffer; @@ -140,7 +146,9 @@ public: void Flush() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D11DownloadTexture(Microsoft::WRL::ComPtr tex, u32 width, u32 height, GPUTexture::Format format); diff --git a/src/util/d3d12_builders.cpp b/src/util/d3d12_builders.cpp index 7eaf69bb6..a423a5fcc 100644 --- a/src/util/d3d12_builders.cpp +++ b/src/util/d3d12_builders.cpp @@ -310,7 +310,7 @@ u32 D3D12::RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE return index; } -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES void D3D12::SetObjectName(ID3D12Object* object, std::string_view name) { diff --git a/src/util/d3d12_builders.h b/src/util/d3d12_builders.h index 81dc57f7a..f139b2f0e 100644 --- a/src/util/d3d12_builders.h +++ b/src/util/d3d12_builders.h @@ -6,6 +6,8 @@ #include "common/types.h" #include "common/windows_headers.h" +#include "gpu_device.h" + #include #include #include @@ -122,7 +124,7 @@ private: D3D12_COMPUTE_PIPELINE_STATE_DESC m_desc; }; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES void SetObjectName(ID3D12Object* object, std::string_view name); #else static inline void SetObjectName(ID3D12Object* object, std::string_view name) diff --git a/src/util/d3d12_device.cpp b/src/util/d3d12_device.cpp index 8e0386053..7dd946c3f 100644 --- a/src/util/d3d12_device.cpp +++ b/src/util/d3d12_device.cpp @@ -59,7 +59,7 @@ static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RG // We just need to keep this alive, never reference it. static DynamicHeapArray s_pipeline_cache_data; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES #include "WinPixEventRuntime/pix3.h" static u32 s_debug_scope_depth = 0; #endif @@ -117,7 +117,7 @@ D3D12Device::D3D12Device() { m_render_api = RenderAPI::D3D12; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES s_debug_scope_depth = 0; #endif } @@ -1273,7 +1273,8 @@ void D3D12Device::SubmitPresent(GPUSwapChain* swap_chain) SC->GetSwapChain()->Present(sync_interval, flags); } -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES + static UINT64 Palette(float phase, const std::array& a, const std::array& b, const std::array& c, const std::array& d) { @@ -1286,41 +1287,36 @@ static UINT64 Palette(float phase, const std::array& a, const std::arr static_cast(std::clamp(result[1] * 255.0f, 0.0f, 255.0f)), static_cast(std::clamp(result[2] * 255.0f, 0.0f, 255.0f))); } -#endif void D3D12Device::PushDebugGroup(const char* name) { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_debug_device) return; const UINT64 color = Palette(static_cast(++s_debug_scope_depth), {0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f}, {1.0f, 1.0f, 0.5f}, {0.8f, 0.90f, 0.30f}); PIXBeginEvent(GetCommandList(), color, "%s", name); -#endif } void D3D12Device::PopDebugGroup() { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_debug_device) return; s_debug_scope_depth = (s_debug_scope_depth == 0) ? 0 : (s_debug_scope_depth - 1u); PIXEndEvent(GetCommandList()); -#endif } void D3D12Device::InsertDebugMessage(const char* msg) { -#if defined(_DEBUG) || defined(_DEVEL) if (!m_debug_device) return; PIXSetMarker(GetCommandList(), PIX_COLOR(0, 0, 0), "%s", msg); -#endif } +#endif + void D3D12Device::SetFeatures(D3D_FEATURE_LEVEL feature_level, FeatureMask disabled_features) { m_render_api_version = D3DCommon::GetRenderAPIVersionForFeatureLevel(feature_level); diff --git a/src/util/d3d12_device.h b/src/util/d3d12_device.h index 6306a1376..3b55d65fd 100644 --- a/src/util/d3d12_device.h +++ b/src/util/d3d12_device.h @@ -101,9 +101,11 @@ public: std::unique_ptr CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override; std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void PushDebugGroup(const char* name) override; void PopDebugGroup() override; void InsertDebugMessage(const char* msg) override; +#endif void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) override; diff --git a/src/util/d3d12_pipeline.cpp b/src/util/d3d12_pipeline.cpp index 4b78c2aff..84088a3ef 100644 --- a/src/util/d3d12_pipeline.cpp +++ b/src/util/d3d12_pipeline.cpp @@ -22,10 +22,14 @@ D3D12Shader::D3D12Shader(GPUShaderStage stage, Bytecode bytecode) : GPUShader(st D3D12Shader::~D3D12Shader() = default; +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12Shader::SetDebugName(std::string_view name) { } +#endif + std::unique_ptr D3D12Device::CreateShaderFromBinary(GPUShaderStage stage, std::span data, Error* error) { @@ -72,11 +76,15 @@ D3D12Pipeline::~D3D12Pipeline() D3D12Device::GetInstance().DeferObjectDestruction(std::move(m_pipeline)); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12Pipeline::SetDebugName(std::string_view name) { D3D12::SetObjectName(m_pipeline.Get(), name); } +#endif + std::string D3D12Pipeline::GetPipelineName(const GraphicsConfig& config) { SHA1Digest hash; diff --git a/src/util/d3d12_pipeline.h b/src/util/d3d12_pipeline.h index e2f83d14f..e7ce7557a 100644 --- a/src/util/d3d12_pipeline.h +++ b/src/util/d3d12_pipeline.h @@ -25,7 +25,9 @@ public: ALWAYS_INLINE const u8* GetBytecodeData() const { return m_bytecode.data(); } ALWAYS_INLINE u32 GetBytecodeSize() const { return static_cast(m_bytecode.size()); } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D12Shader(GPUShaderStage stage, Bytecode bytecode); @@ -48,7 +50,9 @@ public: ALWAYS_INLINE const std::array& GetBlendConstantsF() const { return m_blend_constants_f; } ALWAYS_INLINE bool HasVertexStride() const { return (m_vertex_stride > 0); } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif static std::string GetPipelineName(const GraphicsConfig& config); static std::string GetPipelineName(const ComputeConfig& config); diff --git a/src/util/d3d12_texture.cpp b/src/util/d3d12_texture.cpp index 1d7500dfd..dfcf16046 100644 --- a/src/util/d3d12_texture.cpp +++ b/src/util/d3d12_texture.cpp @@ -616,11 +616,15 @@ void D3D12Texture::ActuallyCommitClear(ID3D12GraphicsCommandList* cmdlist) SetState(State::Dirty); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12Texture::SetDebugName(std::string_view name) { D3D12::SetObjectName(m_resource.Get(), name); } +#endif + u32 D3D12Texture::CalculateSubresource(u32 layer, u32 level, u32 num_levels) { // D3D11CalcSubresource @@ -698,10 +702,14 @@ D3D12Sampler::~D3D12Sampler() // Cleaned up by main class. } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12Sampler::SetDebugName(std::string_view name) { } +#endif + D3D12DescriptorHandle D3D12Device::GetSampler(const GPUSampler::Config& config, Error* error) { const auto it = m_sampler_map.find(config.key); @@ -843,11 +851,15 @@ void D3D12TextureBuffer::Unmap(u32 used_elements) m_buffer.CommitMemory(size); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12TextureBuffer::SetDebugName(std::string_view name) { D3D12::SetObjectName(m_buffer.GetBuffer(), name); } +#endif + std::unique_ptr D3D12Device::CreateTextureBuffer(GPUTextureBuffer::Format format, u32 size_in_elements, Error* error /* = nullptr */) { @@ -1026,6 +1038,8 @@ void D3D12DownloadTexture::Flush() } } +#ifdef ENABLE_GPU_OBJECT_NAMES + void D3D12DownloadTexture::SetDebugName(std::string_view name) { if (name.empty()) @@ -1034,6 +1048,8 @@ void D3D12DownloadTexture::SetDebugName(std::string_view name) D3D12::SetObjectName(m_buffer.Get(), name); } +#endif + std::unique_ptr D3D12Device::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */) { diff --git a/src/util/d3d12_texture.h b/src/util/d3d12_texture.h index 96ccd0f3d..daa768499 100644 --- a/src/util/d3d12_texture.h +++ b/src/util/d3d12_texture.h @@ -43,7 +43,9 @@ public: void GenerateMipmaps() override; void MakeReadyForSampling() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif void TransitionToState(D3D12_RESOURCE_STATES state); void CommitClear(); @@ -115,7 +117,9 @@ public: ALWAYS_INLINE const D3D12DescriptorHandle& GetDescriptor() const { return m_descriptor; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D12Sampler(D3D12DescriptorHandle descriptor); @@ -140,7 +144,9 @@ public: void* Map(u32 required_elements) override; void Unmap(u32 used_elements) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D12StreamBuffer m_buffer; @@ -165,7 +171,9 @@ public: void Flush() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: D3D12DownloadTexture(u32 width, u32 height, GPUTexture::Format format, ComPtr allocation, diff --git a/src/util/gpu_device.h b/src/util/gpu_device.h index 071fdcd72..8a98cb4f5 100644 --- a/src/util/gpu_device.h +++ b/src/util/gpu_device.h @@ -13,6 +13,8 @@ #include "common/small_string.h" #include "common/types.h" +#include "fmt/base.h" + #include #include #include @@ -26,6 +28,11 @@ class Error; class Image; +// Enables debug event generation and object names for graphics debuggers. +#if defined(_DEBUG) || defined(_DEVEL) +#define ENABLE_GPU_OBJECT_NAMES +#endif + enum class RenderAPI : u8 { None, @@ -97,7 +104,14 @@ public: GPUSampler(); virtual ~GPUSampler(); +#ifdef ENABLE_GPU_OBJECT_NAMES virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif static Config GetNearestConfig(); static Config GetLinearConfig(); @@ -135,7 +149,14 @@ public: ALWAYS_INLINE GPUShaderStage GetStage() const { return m_stage; } +#ifdef ENABLE_GPU_OBJECT_NAMES virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif protected: GPUShaderStage m_stage; @@ -429,7 +450,14 @@ public: GPUPipeline(); virtual ~GPUPipeline(); +#ifdef ENABLE_GPU_OBJECT_NAMES virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif }; class GPUTextureBuffer @@ -455,7 +483,14 @@ public: virtual void* Map(u32 required_elements) = 0; virtual void Unmap(u32 used_elements) = 0; +#ifdef ENABLE_GPU_OBJECT_NAMES virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif protected: Format m_format; @@ -739,11 +774,25 @@ public: virtual std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error = nullptr) = 0; +#ifdef ENABLE_GPU_OBJECT_NAMES /// Debug messaging. virtual void PushDebugGroup(const char* name) = 0; virtual void PopDebugGroup() = 0; virtual void InsertDebugMessage(const char* msg) = 0; + /// Formatted debug variants. + template + void PushDebugGroup(fmt::format_string fmt, T&&... args) + { + PushDebugGroup(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } + template + void InsertDebugMessage(fmt::format_string fmt, T&&... args) + { + InsertDebugMessage(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif + /// Vertex/index buffer abstraction. virtual void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) = 0; @@ -929,24 +978,74 @@ ALWAYS_INLINE void GPUDevice::PooledTextureDeleter::operator()(GPUTexture* const } // Macros for debug messages. -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES struct GLAutoPop { - GLAutoPop(int dummy) {} - ~GLAutoPop() { g_gpu_device->PopDebugGroup(); } + GLAutoPop(const char* name) + { + if (g_gpu_device->IsDebugDevice()) [[unlikely]] + g_gpu_device->PushDebugGroup(name); + } + + template + GLAutoPop(fmt::format_string fmt, T&&... args) + { + if (g_gpu_device->IsDebugDevice()) [[unlikely]] + g_gpu_device->PushDebugGroup(SmallString::from_vformat(fmt, fmt::make_format_args(args...))); + } + + ~GLAutoPop() + { + if (g_gpu_device->IsDebugDevice()) [[unlikely]] + g_gpu_device->PopDebugGroup(); + } }; -#define GL_SCOPE(name) GLAutoPop gl_auto_pop((g_gpu_device->PushDebugGroup(name), 0)) -#define GL_PUSH(name) g_gpu_device->PushDebugGroup(name) -#define GL_POP() g_gpu_device->PopDebugGroup() -#define GL_INS(msg) g_gpu_device->InsertDebugMessage(msg) -#define GL_OBJECT_NAME(obj, name) (obj)->SetDebugName(name) +#define GL_SCOPE(name) GLAutoPop gl_auto_pop(name) +#define GL_PUSH(name) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + g_gpu_device->PushDebugGroup(name); \ + } while (0) +#define GL_POP() \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + g_gpu_device->PopDebugGroup(); \ + } while (0) +#define GL_INS(msg) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + g_gpu_device->InsertDebugMessage(msg); \ + } while (0) +#define GL_OBJECT_NAME(obj, name) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + (obj)->SetDebugName(name); \ + } while (0) -#define GL_SCOPE_FMT(...) \ - GLAutoPop gl_auto_pop((g_gpu_device->PushDebugGroup(SmallString::from_format(__VA_ARGS__)), 0)) -#define GL_PUSH_FMT(...) g_gpu_device->PushDebugGroup(SmallString::from_format(__VA_ARGS__)) -#define GL_INS_FMT(...) g_gpu_device->InsertDebugMessage(SmallString::from_format(__VA_ARGS__)) -#define GL_OBJECT_NAME_FMT(obj, ...) (obj)->SetDebugName(SmallString::from_format(__VA_ARGS__)) +#define GL_SCOPE_FMT(...) GLAutoPop gl_auto_pop(__VA_ARGS__) +#define GL_PUSH_FMT(...) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + g_gpu_device->PushDebugGroup(__VA_ARGS__); \ + } while (0) +#define GL_INS_FMT(...) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + g_gpu_device->InsertDebugMessage(__VA_ARGS__); \ + } while (0) +#define GL_OBJECT_NAME_FMT(obj, ...) \ + do \ + { \ + if (g_gpu_device->IsDebugDevice()) [[unlikely]] \ + (obj)->SetDebugName(__VA_ARGS__); \ + } while (0) #else #define GL_SCOPE(name) (void)0 #define GL_PUSH(name) (void)0 diff --git a/src/util/gpu_texture.h b/src/util/gpu_texture.h index dc04d9f59..e243da148 100644 --- a/src/util/gpu_texture.h +++ b/src/util/gpu_texture.h @@ -4,8 +4,11 @@ #pragma once #include "common/gsvector.h" +#include "common/small_string.h" #include "common/types.h" +#include "fmt/format.h" + #include #include #include @@ -184,7 +187,14 @@ public: // Instructs the backend that we're finished rendering to this texture. It may transition it to a new layout. virtual void MakeReadyForSampling(); +#if defined(_DEBUG) || defined(_DEVEL) virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif protected: GPUTexture(u16 width, u16 height, u8 layers, u8 levels, u8 samples, Type type, Format format, Flags flags); @@ -252,8 +262,15 @@ public: /// call to CopyFromTexture() and the Flush() call. virtual void Flush() = 0; +#if defined(_DEBUG) || defined(_DEVEL) /// Sets object name that will be displayed in graphics debuggers. virtual void SetDebugName(std::string_view name) = 0; + template + void SetDebugName(fmt::format_string fmt, T&&... args) + { + SetDebugName(TinyString::from_vformat(fmt, fmt::make_format_args(args...))); + } +#endif /// Reads the specified rectangle from the staging texture to out_ptr, with the specified stride /// (length in bytes of each row). CopyFromTexture() must be called first. The contents of any diff --git a/src/util/media_capture.cpp b/src/util/media_capture.cpp index d356fea0b..af251f026 100644 --- a/src/util/media_capture.cpp +++ b/src/util/media_capture.cpp @@ -285,9 +285,7 @@ bool MediaCaptureBase::DeliverVideoFrame(GPUTexture* stex) return false; } -#if defined(_DEBUG) || defined(_DEVEL) GL_OBJECT_NAME_FMT(pf.tex, "MediaCapture {}x{} Download Texture", stex->GetWidth(), stex->GetHeight()); -#endif } pf.tex->CopyFromTexture(0, 0, stex, 0, 0, m_video_width, m_video_height, 0, 0); diff --git a/src/util/metal_device.h b/src/util/metal_device.h index b83880418..1606343db 100644 --- a/src/util/metal_device.h +++ b/src/util/metal_device.h @@ -44,7 +44,9 @@ public: ALWAYS_INLINE id GetSamplerState() const { return m_ss; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: MetalSampler(id ss); @@ -62,7 +64,9 @@ public: ALWAYS_INLINE id GetLibrary() const { return m_library; } ALWAYS_INLINE id GetFunction() const { return m_function; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: MetalShader(GPUShaderStage stage, id library, id function); @@ -92,7 +96,9 @@ public: ALWAYS_INLINE MTLCullMode GetCullMode() const { return m_cull_mode; } ALWAYS_INLINE MTLPrimitiveType GetPrimitive() const { return m_primitive; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: MetalPipeline(id pipeline, id depth, MTLCullMode cull_mode, MTLPrimitiveType primitive); @@ -122,7 +128,9 @@ public: void MakeReadyForSampling() override; void GenerateMipmaps() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif // Call when the texture is bound to the pipeline, or read from in a copy. ALWAYS_INLINE void SetUseFenceCounter(u64 counter) { m_use_fence_counter = counter; } @@ -161,7 +169,9 @@ public: void Flush() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: MetalDownloadTexture(u32 width, u32 height, GPUTexture::Format format, u8* import_buffer, size_t buffer_offset, @@ -187,7 +197,9 @@ public: void* Map(u32 required_elements) override; void Unmap(u32 used_elements) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: MetalStreamBuffer m_buffer; @@ -265,9 +277,11 @@ public: std::unique_ptr CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override; std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void PushDebugGroup(const char* name) override; void PopDebugGroup() override; void InsertDebugMessage(const char* msg) override; +#endif void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) override; diff --git a/src/util/metal_device.mm b/src/util/metal_device.mm index 26b504230..e6ee3a91e 100644 --- a/src/util/metal_device.mm +++ b/src/util/metal_device.mm @@ -643,6 +643,8 @@ MetalShader::~MetalShader() MetalDevice::DeferRelease(m_library); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalShader::SetDebugName(std::string_view name) { @autoreleasepool @@ -651,6 +653,8 @@ void MetalShader::SetDebugName(std::string_view name) } } +#endif + std::unique_ptr MetalDevice::CreateShaderFromMSL(GPUShaderStage stage, std::string_view source, std::string_view entry_point, Error* error) { @@ -747,11 +751,15 @@ MetalPipeline::~MetalPipeline() MetalDevice::DeferRelease(m_pipeline); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalPipeline::SetDebugName(std::string_view name) { // readonly property :/ } +#endif + id MetalDevice::GetDepthState(const GPUPipeline::DepthState& ds) { const auto it = m_depth_states.find(ds.key); @@ -1157,6 +1165,8 @@ void MetalTexture::GenerateMipmaps() [encoder generateMipmapsForTexture:m_texture]; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalTexture::SetDebugName(std::string_view name) { @autoreleasepool @@ -1165,6 +1175,8 @@ void MetalTexture::SetDebugName(std::string_view name) } } +#endif + std::unique_ptr MetalDevice::CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples, GPUTexture::Type type, GPUTexture::Format format, GPUTexture::Flags flags, const void* data, u32 data_stride, @@ -1381,6 +1393,8 @@ void MetalDownloadTexture::Flush() dev.WaitForFenceCounter(m_copy_fence_counter); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalDownloadTexture::SetDebugName(std::string_view name) { @autoreleasepool @@ -1389,6 +1403,8 @@ void MetalDownloadTexture::SetDebugName(std::string_view name) } } +#endif + std::unique_ptr MetalDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error) { @@ -1408,11 +1424,15 @@ MetalSampler::MetalSampler(id ss) : m_ss(ss) MetalSampler::~MetalSampler() = default; +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalSampler::SetDebugName(std::string_view name) { // lame.. have to put it on the descriptor :/ } +#endif + std::unique_ptr MetalDevice::CreateSampler(const GPUSampler::Config& config, Error* error) { @autoreleasepool @@ -1822,6 +1842,8 @@ void MetalTextureBuffer::Unmap(u32 used_elements) m_buffer.CommitMemory(size); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalTextureBuffer::SetDebugName(std::string_view name) { @autoreleasepool @@ -1830,6 +1852,8 @@ void MetalTextureBuffer::SetDebugName(std::string_view name) } } +#endif + std::unique_ptr MetalDevice::CreateTextureBuffer(GPUTextureBuffer::Format format, u32 size_in_elements, Error* error) { @@ -1840,6 +1864,8 @@ std::unique_ptr MetalDevice::CreateTextureBuffer(GPUTextureBuf return tb; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void MetalDevice::PushDebugGroup(const char* name) { } @@ -1852,6 +1878,8 @@ void MetalDevice::InsertDebugMessage(const char* msg) { } +#endif + void MetalDevice::MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) { diff --git a/src/util/opengl_device.cpp b/src/util/opengl_device.cpp index 0e0f4e39f..cdd2a2d1b 100644 --- a/src/util/opengl_device.cpp +++ b/src/util/opengl_device.cpp @@ -214,29 +214,26 @@ std::unique_ptr OpenGLDevice::CreatePipeline(const GPUPipeline::Com return {}; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLDevice::PushDebugGroup(const char* name) { -#if defined(_DEBUG) || defined(_DEVEL) if (!glPushDebugGroup) return; glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, static_cast(std::strlen(name)), name); -#endif } void OpenGLDevice::PopDebugGroup() { -#if defined(_DEBUG) || defined(_DEVEL) if (!glPopDebugGroup) return; glPopDebugGroup(); -#endif } void OpenGLDevice::InsertDebugMessage(const char* msg) { -#if defined(_DEBUG) || defined(_DEVEL) if (!glDebugMessageInsert) return; @@ -245,9 +242,10 @@ void OpenGLDevice::InsertDebugMessage(const char* msg) glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, static_cast(std::strlen(msg)), msg); } -#endif } +#endif + static void GLAD_API_PTR GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { diff --git a/src/util/opengl_device.h b/src/util/opengl_device.h index c3c1e4ee0..ba4ca9277 100644 --- a/src/util/opengl_device.h +++ b/src/util/opengl_device.h @@ -82,9 +82,11 @@ public: std::unique_ptr CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override; std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void PushDebugGroup(const char* name) override; void PopDebugGroup() override; void InsertDebugMessage(const char* msg) override; +#endif void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) override; diff --git a/src/util/opengl_pipeline.cpp b/src/util/opengl_pipeline.cpp index b0027d452..4f36aba73 100644 --- a/src/util/opengl_pipeline.cpp +++ b/src/util/opengl_pipeline.cpp @@ -78,9 +78,10 @@ OpenGLShader::~OpenGLShader() glDeleteShader(m_id.value()); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLShader::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) { if (m_id.has_value()) @@ -94,9 +95,10 @@ void OpenGLShader::SetDebugName(std::string_view name) m_debug_name = name; } } -#endif } +#endif + bool OpenGLShader::Compile(Error* error) { if (m_compile_tried) @@ -155,7 +157,7 @@ bool OpenGLShader::Compile(Error* error) m_id = shader; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES if (glObjectLabel && !m_debug_name.empty()) { glObjectLabel(GL_SHADER, shader, static_cast(m_debug_name.length()), @@ -584,14 +586,16 @@ OpenGLPipeline::~OpenGLPipeline() dev.UnrefVAO(m_key.va_key); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLPipeline::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) glObjectLabel(GL_PROGRAM, m_program, static_cast(name.length()), name.data()); -#endif } +#endif + std::unique_ptr OpenGLDevice::CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) { const OpenGLPipeline::ProgramCacheKey pkey = OpenGLPipeline::GetProgramCacheKey(config); diff --git a/src/util/opengl_pipeline.h b/src/util/opengl_pipeline.h index 33a088e69..a5f3e575f 100644 --- a/src/util/opengl_pipeline.h +++ b/src/util/opengl_pipeline.h @@ -16,7 +16,9 @@ class OpenGLShader final : public GPUShader public: ~OpenGLShader() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif bool Compile(Error* error); @@ -32,7 +34,7 @@ private: std::optional m_id; bool m_compile_tried = false; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES std::string m_debug_name; #endif }; @@ -104,7 +106,9 @@ public: ALWAYS_INLINE const BlendState& GetBlendState() const { return m_blend_state; } ALWAYS_INLINE GLenum GetTopology() const { return m_topology; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: OpenGLPipeline(const ProgramCacheKey& key, GLuint program, VertexArrayCache::const_iterator vao, diff --git a/src/util/opengl_stream_buffer.cpp b/src/util/opengl_stream_buffer.cpp index a4deff5fb..d0f29a4f0 100644 --- a/src/util/opengl_stream_buffer.cpp +++ b/src/util/opengl_stream_buffer.cpp @@ -29,17 +29,19 @@ void OpenGLStreamBuffer::Unbind() glBindBuffer(m_target, 0); } +#if defined(_DEBUG) || defined(_DEVEL) + void OpenGLStreamBuffer::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) { glObjectLabel(GL_BUFFER, GetGLBufferId(), static_cast(name.length()), static_cast(name.data())); } -#endif } +#endif + namespace { // Uses glBufferSubData() to update. Preferred for drivers which don't support {ARB,EXT}_buffer_storage. diff --git a/src/util/opengl_stream_buffer.h b/src/util/opengl_stream_buffer.h index fa0bca26d..78d9e732c 100644 --- a/src/util/opengl_stream_buffer.h +++ b/src/util/opengl_stream_buffer.h @@ -26,7 +26,9 @@ public: void Bind(); void Unbind(); +#if defined(_DEBUG) || defined(_DEVEL) void SetDebugName(std::string_view name); +#endif struct MappingResult { diff --git a/src/util/opengl_texture.cpp b/src/util/opengl_texture.cpp index 9f23b9274..1b04fb5f7 100644 --- a/src/util/opengl_texture.cpp +++ b/src/util/opengl_texture.cpp @@ -485,18 +485,14 @@ void OpenGLTexture::GenerateMipmaps() glBindTexture(target, 0); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLTexture::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) glObjectLabel(GL_TEXTURE, m_id, static_cast(name.length()), static_cast(name.data())); -#endif } -#if 0 -// If we don't have border clamp.. too bad, just hope for the best. -if (!m_gl_context->IsGLES() || GLAD_GL_ES_VERSION_3_2 || GLAD_GL_NV_texture_border_clamp || - GLAD_GL_EXT_texture_border_clamp || GLAD_GL_OES_texture_border_clamp) #endif ////////////////////////////////////////////////////////////////////////// @@ -510,14 +506,16 @@ OpenGLSampler::~OpenGLSampler() OpenGLDevice::GetInstance().UnbindSampler(m_id); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLSampler::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) glObjectLabel(GL_SAMPLER, m_id, static_cast(name.length()), static_cast(name.data())); -#endif } +#endif + std::unique_ptr OpenGLDevice::CreateSampler(const GPUSampler::Config& config, Error* error /* = nullptr */) { static constexpr std::array(GPUSampler::AddressMode::MaxCount)> ta = {{ @@ -798,17 +796,19 @@ void OpenGLTextureBuffer::Unmap(u32 used_elements) m_buffer->Unmap(size); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLTextureBuffer::SetDebugName(std::string_view name) { -#if defined(_DEBUG) || defined(_DEVEL) if (glObjectLabel) { glObjectLabel(GL_TEXTURE, m_buffer->GetGLBufferId(), static_cast(name.length()), static_cast(name.data())); } -#endif } +#endif + std::unique_ptr OpenGLDevice::CreateTextureBuffer(GPUTextureBuffer::Format format, u32 size_in_elements, Error* error) { @@ -1037,6 +1037,8 @@ void OpenGLDownloadTexture::Flush() m_sync = {}; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void OpenGLDownloadTexture::SetDebugName(std::string_view name) { if (name.empty()) @@ -1046,6 +1048,8 @@ void OpenGLDownloadTexture::SetDebugName(std::string_view name) glObjectLabel(GL_BUFFER, m_buffer_id, static_cast(name.length()), name.data()); } +#endif + std::unique_ptr OpenGLDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */) { diff --git a/src/util/opengl_texture.h b/src/util/opengl_texture.h index 5bc290c2b..7b213b89d 100644 --- a/src/util/opengl_texture.h +++ b/src/util/opengl_texture.h @@ -30,7 +30,9 @@ public: void Unmap() override; void GenerateMipmaps() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif static std::unique_ptr Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Type type, Format format, Flags flags, const void* data, u32 data_pitch, @@ -78,7 +80,9 @@ public: void* Map(u32 required_elements) override; void Unmap(u32 used_elements) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: OpenGLTextureBuffer(Format format, u32 size_in_elements, std::unique_ptr buffer, @@ -97,7 +101,9 @@ public: ALWAYS_INLINE GLuint GetID() const { return m_id; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: OpenGLSampler(GLuint id); @@ -121,7 +127,9 @@ public: void Flush() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: OpenGLDownloadTexture(u32 width, u32 height, GPUTexture::Format format, bool imported, GLuint buffer_id, diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index b24e87287..797085327 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1265,7 +1265,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer pass.samplers.push_back(std::move(sampler)); } -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES pass.name = std::move(pi.name); #endif m_passes.push_back(std::move(pass)); diff --git a/src/util/postprocessing_shader_fx.h b/src/util/postprocessing_shader_fx.h index 329adf2ef..79089541b 100644 --- a/src/util/postprocessing_shader_fx.h +++ b/src/util/postprocessing_shader_fx.h @@ -132,7 +132,7 @@ private: llvm::SmallVector samplers; u32 num_vertices; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES std::string name; #endif }; diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index 9839a387e..f61fb69a7 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -105,7 +105,7 @@ const std::array(GPUTexture::Format::MaxCount)> Vulka // Handles are always 64-bit, even on 32-bit platforms. static const VkRenderPass DYNAMIC_RENDERING_RENDER_PASS = ((VkRenderPass) static_cast(-1LL)); -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES static u32 s_debug_scope_depth = 0; #endif @@ -116,7 +116,7 @@ VulkanDevice::VulkanDevice() { m_render_api = RenderAPI::Vulkan; -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES s_debug_scope_depth = 0; #endif } @@ -2327,7 +2327,7 @@ void VulkanDevice::SubmitPresent(GPUSwapChain* swap_chain) QueuePresent(static_cast(swap_chain)); } -#if defined(_DEBUG) || defined(_DEVEL) +#ifdef ENABLE_GPU_OBJECT_NAMES static std::array Palette(float phase, const std::array& a, const std::array& b, const std::array& c, const std::array& d) { @@ -2337,11 +2337,9 @@ static std::array Palette(float phase, const std::array& a, result[2] = a[2] + b[2] * std::cos(6.28318f * (c[2] * phase + d[2])); return result; } -#endif void VulkanDevice::PushDebugGroup(const char* name) { -#if defined(_DEBUG) || defined(_DEVEL) if (!vkCmdBeginDebugUtilsLabelEXT || !m_debug_device) return; @@ -2355,32 +2353,29 @@ void VulkanDevice::PushDebugGroup(const char* name) {color[0], color[1], color[2], 1.0f}, }; vkCmdBeginDebugUtilsLabelEXT(GetCurrentCommandBuffer(), &label); -#endif } void VulkanDevice::PopDebugGroup() { -#if defined(_DEBUG) || defined(_DEVEL) if (!vkCmdEndDebugUtilsLabelEXT || !m_debug_device) return; s_debug_scope_depth = (s_debug_scope_depth == 0) ? 0 : (s_debug_scope_depth - 1u); vkCmdEndDebugUtilsLabelEXT(GetCurrentCommandBuffer()); -#endif } void VulkanDevice::InsertDebugMessage(const char* msg) { -#if defined(_DEBUG) || defined(_DEVEL) if (!vkCmdInsertDebugUtilsLabelEXT || !m_debug_device) return; const VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, nullptr, msg, {0.0f, 0.0f, 0.0f, 1.0f}}; vkCmdInsertDebugUtilsLabelEXT(GetCurrentCommandBuffer(), &label); -#endif } +#endif + u32 VulkanDevice::GetMaxMultisamples(VkPhysicalDevice physical_device, const VkPhysicalDeviceProperties& properties) { VkImageFormatProperties color_properties = {}; diff --git a/src/util/vulkan_device.h b/src/util/vulkan_device.h index 8ad11229a..a7a9f78ba 100644 --- a/src/util/vulkan_device.h +++ b/src/util/vulkan_device.h @@ -118,9 +118,11 @@ public: std::unique_ptr CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) override; std::unique_ptr CreatePipeline(const GPUPipeline::ComputeConfig& config, Error* error) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void PushDebugGroup(const char* name) override; void PopDebugGroup() override; void InsertDebugMessage(const char* msg) override; +#endif void MapVertexBuffer(u32 vertex_size, u32 vertex_count, void** map_ptr, u32* map_space, u32* map_base_vertex) override; diff --git a/src/util/vulkan_pipeline.cpp b/src/util/vulkan_pipeline.cpp index a6d801c77..7a6c76b87 100644 --- a/src/util/vulkan_pipeline.cpp +++ b/src/util/vulkan_pipeline.cpp @@ -22,11 +22,15 @@ VulkanShader::~VulkanShader() vkDestroyShaderModule(VulkanDevice::GetInstance().GetVulkanDevice(), m_module, nullptr); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanShader::SetDebugName(std::string_view name) { Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_module, name); } +#endif + std::unique_ptr VulkanDevice::CreateShaderFromBinary(GPUShaderStage stage, std::span data, Error* error) { @@ -107,11 +111,15 @@ VulkanPipeline::~VulkanPipeline() VulkanDevice::GetInstance().DeferPipelineDestruction(m_pipeline); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanPipeline::SetDebugName(std::string_view name) { Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_pipeline, name); } +#endif + std::unique_ptr VulkanDevice::CreatePipeline(const GPUPipeline::GraphicsConfig& config, Error* error) { static constexpr std::array, static_cast(GPUPipeline::Primitive::MaxCount)> diff --git a/src/util/vulkan_pipeline.h b/src/util/vulkan_pipeline.h index 13324f3be..2dcc72d91 100644 --- a/src/util/vulkan_pipeline.h +++ b/src/util/vulkan_pipeline.h @@ -15,7 +15,9 @@ public: ALWAYS_INLINE VkShaderModule GetModule() const { return m_module; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: VulkanShader(GPUShaderStage stage, VkShaderModule mod); @@ -34,7 +36,9 @@ public: ALWAYS_INLINE Layout GetLayout() const { return m_layout; } ALWAYS_INLINE u8 GetVerticesPerPrimitive() const { return m_vertices_per_primitive; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: VulkanPipeline(VkPipeline pipeline, Layout layout, u8 vertices_per_primitive, RenderPassFlag render_pass_flags); diff --git a/src/util/vulkan_texture.cpp b/src/util/vulkan_texture.cpp index 8d7061806..4e3accaab 100644 --- a/src/util/vulkan_texture.cpp +++ b/src/util/vulkan_texture.cpp @@ -459,6 +459,8 @@ void VulkanTexture::OverrideImageLayout(Layout new_layout) m_layout = new_layout; } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanTexture::SetDebugName(std::string_view name) { VulkanDevice& dev = VulkanDevice::GetInstance(); @@ -466,6 +468,8 @@ void VulkanTexture::SetDebugName(std::string_view name) Vulkan::SetObjectName(dev.GetVulkanDevice(), m_view, name); } +#endif + void VulkanTexture::TransitionToLayout(Layout layout) { TransitionToLayout(VulkanDevice::GetInstance().GetCurrentCommandBuffer(), layout); @@ -775,11 +779,15 @@ VulkanSampler::~VulkanSampler() // Cleaned up by main class. } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanSampler::SetDebugName(std::string_view name) { Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_sampler, name); } +#endif + VkSampler VulkanDevice::GetSampler(const GPUSampler::Config& config, Error* error) { const auto it = m_sampler_map.find(config.key); @@ -942,6 +950,8 @@ void VulkanTextureBuffer::Unmap(u32 used_elements) m_buffer.CommitMemory(size); } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanTextureBuffer::SetDebugName(std::string_view name) { VulkanDevice& dev = VulkanDevice::GetInstance(); @@ -950,6 +960,8 @@ void VulkanTextureBuffer::SetDebugName(std::string_view name) Vulkan::SetObjectName(dev.GetVulkanDevice(), m_buffer_view, name); } +#endif + std::unique_ptr VulkanDevice::CreateTextureBuffer(GPUTextureBuffer::Format format, u32 size_in_elements, Error* error) { @@ -1195,6 +1207,8 @@ void VulkanDownloadTexture::Flush() } } +#ifdef ENABLE_GPU_OBJECT_NAMES + void VulkanDownloadTexture::SetDebugName(std::string_view name) { if (name.empty()) @@ -1203,6 +1217,8 @@ void VulkanDownloadTexture::SetDebugName(std::string_view name) Vulkan::SetObjectName(VulkanDevice::GetInstance().GetVulkanDevice(), m_buffer, name); } +#endif + std::unique_ptr VulkanDevice::CreateDownloadTexture(u32 width, u32 height, GPUTexture::Format format, Error* error /* = nullptr */) { diff --git a/src/util/vulkan_texture.h b/src/util/vulkan_texture.h index b30ba7dfb..f1c83ccec 100644 --- a/src/util/vulkan_texture.h +++ b/src/util/vulkan_texture.h @@ -56,7 +56,9 @@ public: void MakeReadyForSampling() override; void GenerateMipmaps() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif void TransitionToLayout(Layout layout); void CommitClear(); @@ -120,7 +122,9 @@ public: ALWAYS_INLINE VkSampler GetSampler() const { return m_sampler; } +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: VulkanSampler(VkSampler sampler); @@ -146,7 +150,9 @@ public: void* Map(u32 required_elements) override; void Unmap(u32 used_elements) override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: VulkanStreamBuffer m_buffer; @@ -170,7 +176,9 @@ public: void Flush() override; +#ifdef ENABLE_GPU_OBJECT_NAMES void SetDebugName(std::string_view name) override; +#endif private: VulkanDownloadTexture(u32 width, u32 height, GPUTexture::Format format, VmaAllocation allocation,