diff --git a/pcsx2/GS/GSCapture.cpp b/pcsx2/GS/GSCapture.cpp index aa6b181785..f0c7c178e1 100644 --- a/pcsx2/GS/GSCapture.cpp +++ b/pcsx2/GS/GSCapture.cpp @@ -16,6 +16,7 @@ #include "common/BitUtils.h" #include "common/DynamicLibrary.h" #include "common/Path.h" +#include "common/SmallString.h" #include "common/StringUtil.h" #include "common/Threading.h" @@ -838,6 +839,10 @@ bool GSCapture::DeliverVideoFrame(GSTexture* stex) Console.Error("GSCapture: Failed to create %x%d download texture", stex->GetWidth(), stex->GetHeight()); return false; } + +#ifdef PCSX2_DEVBUILD + pf.tex->SetDebugName(TinyString::from_fmt("GSCapture {}x{} Download Texture", stex->GetWidth(), stex->GetHeight())); +#endif } const GSVector4i rc(0, 0, stex->GetWidth(), stex->GetHeight()); diff --git a/pcsx2/GS/Renderers/Common/GSDevice.cpp b/pcsx2/GS/Renderers/Common/GSDevice.cpp index 5c4d3ba98a..677862ef9b 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.cpp +++ b/pcsx2/GS/Renderers/Common/GSDevice.cpp @@ -10,6 +10,7 @@ #include "common/BitUtils.h" #include "common/FileSystem.h" #include "common/Path.h" +#include "common/SmallString.h" #include "common/StringUtil.h" #include "imgui.h" @@ -78,9 +79,111 @@ static int MipmapLevelsForSize(int width, int height) return std::min(static_cast(std::log2(std::max(width, height))) + 1, MAXIMUM_TEXTURE_MIPMAP_LEVELS); } +#ifdef PCSX2_DEVBUILD + +enum class TextureLabel +{ + ColorRT, + HDRRT, + U16RT, + U32RT, + DepthStencil, + PrimIDTexture, + RWTexture, + CLUTTexture, + Texture, + ReplacementTexture, + Other, + Last = Other, +}; + +static std::array(TextureLabel::Last) + 1> s_texture_counts; + +static TextureLabel GetTextureLabel(GSTexture::Type type, GSTexture::Format format) +{ + switch (type) + { + case GSTexture::Type::RenderTarget: + switch (format) + { + case GSTexture::Format::Color: + return TextureLabel::ColorRT; + case GSTexture::Format::HDRColor: + return TextureLabel::HDRRT; + case GSTexture::Format::UInt16: + return TextureLabel::U16RT; + case GSTexture::Format::UInt32: + return TextureLabel::U32RT; + case GSTexture::Format::PrimID: + return TextureLabel::PrimIDTexture; + default: + return TextureLabel::Other; + } + case GSTexture::Type::Texture: + switch (format) + { + case GSTexture::Format::Color: + return TextureLabel::Texture; + case GSTexture::Format::UNorm8: + return TextureLabel::CLUTTexture; + case GSTexture::Format::BC1: + case GSTexture::Format::BC2: + case GSTexture::Format::BC3: + case GSTexture::Format::BC7: + return TextureLabel::ReplacementTexture; + default: + return TextureLabel::Other; + } + case GSTexture::Type::DepthStencil: + return TextureLabel::DepthStencil; + case GSTexture::Type::RWTexture: + return TextureLabel::RWTexture; + case GSTexture::Type::Invalid: + default: + return TextureLabel::Other; + } +} + +static const char* TextureLabelString(TextureLabel label) +{ + switch (label) + { + case TextureLabel::ColorRT: + return "Color RT"; + case TextureLabel::HDRRT: + return "HDR RT"; + case TextureLabel::U16RT: + return "U16 RT"; + case TextureLabel::U32RT: + return "U32 RT"; + case TextureLabel::DepthStencil: + return "Depth Stencil"; + case TextureLabel::PrimIDTexture: + return "PrimID"; + case TextureLabel::RWTexture: + return "RW Texture"; + case TextureLabel::CLUTTexture: + return "CLUT Texture"; + case TextureLabel::Texture: + return "Texture"; + case TextureLabel::ReplacementTexture: + return "Replacement Texture"; + case TextureLabel::Other: + default: + return "Unknown Texture"; + } +} + +#endif + std::unique_ptr g_gs_device; -GSDevice::GSDevice() = default; +GSDevice::GSDevice() +{ +#ifdef PCSX2_DEVBUILD + s_texture_counts.fill(0); +#endif +} GSDevice::~GSDevice() { @@ -327,6 +430,15 @@ GSTexture* GSDevice::FetchSurface(GSTexture::Type type, int width, int height, i return nullptr; } } + +#ifdef PCSX2_DEVBUILD + if (GSConfig.UseDebugDevice) + { + const TextureLabel label = GetTextureLabel(type, format); + const u32 id = ++s_texture_counts[static_cast(label)]; + t->SetDebugName(TinyString::from_fmt("{} {}", TextureLabelString(label), id)); + } +#endif } } diff --git a/pcsx2/GS/Renderers/Common/GSTexture.cpp b/pcsx2/GS/Renderers/Common/GSTexture.cpp index 8001cf244c..bc8a9e61c0 100644 --- a/pcsx2/GS/Renderers/Common/GSTexture.cpp +++ b/pcsx2/GS/Renderers/Common/GSTexture.cpp @@ -14,6 +14,8 @@ GSTexture::GSTexture() = default; +GSTexture::~GSTexture() = default; + bool GSTexture::Save(const std::string& fn) { // Depth textures need special treatment - we have a stencil component. @@ -62,6 +64,25 @@ bool GSTexture::Save(const std::string& fn) return GSPng::Save(format, fn, dl->GetMapPointer(), m_size.x, m_size.y, dl->GetMapPitch(), compression, g_gs_device->IsRBSwapped()); } +const char* GSTexture::GetFormatName(Format format) +{ + static constexpr const char* format_names[] = { + "Invalid", + "Color", + "HDRColor", + "DepthStencil", + "UNorm8", + "UInt16", + "UInt32", + "PrimID", + "BC1", + "BC2", + "BC3", + "BC7", + }; + return format_names[(static_cast(format) < std::size(format_names)) ? static_cast(format) : 0]; +} + u32 GSTexture::GetCompressedBytesPerBlock() const { return GetCompressedBytesPerBlock(m_format); diff --git a/pcsx2/GS/Renderers/Common/GSTexture.h b/pcsx2/GS/Renderers/Common/GSTexture.h index e22176e01f..1b58e16849 100644 --- a/pcsx2/GS/Renderers/Common/GSTexture.h +++ b/pcsx2/GS/Renderers/Common/GSTexture.h @@ -6,6 +6,7 @@ #include "GS/GSVector.h" #include +#include class GSTexture { @@ -70,15 +71,19 @@ protected: public: GSTexture(); - virtual ~GSTexture() {} + virtual ~GSTexture(); // Returns the native handle of a texture. virtual void* GetNativeHandle() const = 0; virtual bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) = 0; - virtual bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) = 0; + virtual bool Map(GSMap& m, const GSVector4i* r = nullptr, int layer = 0) = 0; virtual void Unmap() = 0; - virtual void GenerateMipmap() {} + virtual void GenerateMipmap() = 0; + +#ifdef PCSX2_DEVBUILD + virtual void SetDebugName(std::string_view name) = 0; +#endif bool Save(const std::string& fn); @@ -94,6 +99,7 @@ public: __fi Format GetFormat() const { return m_format; } __fi bool IsCompressedFormat() const { return IsCompressedFormat(m_format); } + static const char* GetFormatName(Format format); static u32 GetCompressedBytesPerBlock(Format format); static u32 GetCompressedBlockSize(Format format); static u32 CalcUploadPitch(Format format, u32 width); @@ -197,6 +203,11 @@ public: /// call to CopyFromTexture() and the Flush() call. virtual void Flush() = 0; +#ifdef PCSX2_DEVBUILD + /// Sets object name that will be displayed in graphics debuggers. + virtual void SetDebugName(std::string_view name) = 0; +#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 /// texels outside of the rectangle used for CopyFromTexture is undefined. diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 46c56abac3..0b02c31d8d 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -60,6 +60,21 @@ GSDevice11::GSDevice11() GSDevice11::~GSDevice11() = default; +void GSDevice11::SetD3DDebugObjectName(ID3D11DeviceChild* obj, std::string_view name) +{ +#ifdef PCSX2_DEVBUILD + // WKPDID_D3DDebugObjectName + static constexpr GUID guid = {0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}}; + + UINT existing_data_size; + HRESULT hr = obj->GetPrivateData(guid, &existing_data_size, nullptr); + if (SUCCEEDED(hr) && existing_data_size > 0) + return; + + obj->SetPrivateData(guid, static_cast(name.length()), name.data()); +#endif +} + RenderAPI GSDevice11::GetRenderAPI() const { return RenderAPI::D3D11; diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.h b/pcsx2/GS/Renderers/DX11/GSDevice11.h index 10d501312e..9f70639d4a 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.h +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.h @@ -7,7 +7,10 @@ #include "GS/GSVector.h" #include "GS/Renderers/Common/GSDevice.h" #include "GS/Renderers/DX11/D3D11ShaderCache.h" + +#include #include + #include #include #include @@ -265,6 +268,8 @@ public: GSDevice11(); ~GSDevice11() override; + static void SetD3DDebugObjectName(ID3D11DeviceChild* obj, std::string_view name); + __fi static GSDevice11* GetInstance() { return static_cast(g_gs_device.get()); } __fi ID3D11Device1* GetD3DDevice() const { return m_dev.get(); } __fi ID3D11DeviceContext1* GetD3DContext() const { return m_ctx.get(); } diff --git a/pcsx2/GS/Renderers/DX11/GSTexture11.cpp b/pcsx2/GS/Renderers/DX11/GSTexture11.cpp index ed18ab0e07..87a3163a86 100644 --- a/pcsx2/GS/Renderers/DX11/GSTexture11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSTexture11.cpp @@ -5,9 +5,12 @@ #include "GSTexture11.h" #include "GS/GSPng.h" #include "GS/GSPerfMon.h" + #include "common/Console.h" #include "common/BitUtils.h" +#include "fmt/format.h" + GSTexture11::GSTexture11(wil::com_ptr_nothrow texture, const D3D11_TEXTURE2D_DESC& desc, GSTexture::Type type, GSTexture::Format format) : m_texture(std::move(texture)) @@ -85,6 +88,22 @@ void GSTexture11::GenerateMipmap() GSDevice11::GetInstance()->GetD3DContext()->GenerateMips(operator ID3D11ShaderResourceView*()); } +#ifdef PCSX2_DEVBUILD + +void GSTexture11::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + GSDevice11::SetD3DDebugObjectName(m_texture.get(), name); + if (m_srv) + GSDevice11::SetD3DDebugObjectName(m_srv.get(), fmt::format("{} SRV", name)); + if (m_rtv) + GSDevice11::SetD3DDebugObjectName(m_srv.get(), fmt::format("{} RTV", name)); +} + +#endif + GSTexture11::operator ID3D11Texture2D*() { return m_texture.get(); @@ -258,3 +277,15 @@ void GSDownloadTexture11::Flush() // Handled when mapped. } + +#ifdef PCSX2_DEVBUILD + +void GSDownloadTexture11::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + GSDevice11::SetD3DDebugObjectName(m_texture.get(), name); +} + +#endif diff --git a/pcsx2/GS/Renderers/DX11/GSTexture11.h b/pcsx2/GS/Renderers/DX11/GSTexture11.h index c412496e4a..ad1ed1c344 100644 --- a/pcsx2/GS/Renderers/DX11/GSTexture11.h +++ b/pcsx2/GS/Renderers/DX11/GSTexture11.h @@ -33,6 +33,10 @@ public: void Unmap() override; void GenerateMipmap() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + operator ID3D11Texture2D*(); operator ID3D11ShaderResourceView*(); operator ID3D11RenderTargetView*(); @@ -55,6 +59,10 @@ public: void Flush() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + private: GSDownloadTexture11(wil::com_ptr_nothrow tex, u32 width, u32 height, GSTexture::Format format); diff --git a/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp b/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp index dae9a11197..2b528ffe17 100644 --- a/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp +++ b/pcsx2/GS/Renderers/DX12/D3D12Builders.cpp @@ -354,20 +354,12 @@ u32 D3D12::RootSignatureBuilder::AddDescriptorTable( return index; } -#ifdef _DEBUG +#ifdef PCSX2_DEVBUILD #include "common/StringUtil.h" -void D3D12::SetObjectName(ID3D12Object* object, const char* name) +void D3D12::SetObjectName(ID3D12Object* object, std::string_view name) { object->SetName(StringUtil::UTF8StringToWideString(name).c_str()); } -void D3D12::SetObjectNameFormatted(ID3D12Object* object, const char* format, ...) -{ - std::va_list ap; - va_start(ap, format); - SetObjectName(object, StringUtil::StdStringFromFormatV(format, ap).c_str()); - va_end(ap); -} - #endif diff --git a/pcsx2/GS/Renderers/DX12/D3D12Builders.h b/pcsx2/GS/Renderers/DX12/D3D12Builders.h index 5088ff010d..ca650ccf71 100644 --- a/pcsx2/GS/Renderers/DX12/D3D12Builders.h +++ b/pcsx2/GS/Renderers/DX12/D3D12Builders.h @@ -9,6 +9,7 @@ #include #include +#include class D3D12ShaderCache; @@ -130,15 +131,9 @@ namespace D3D12 D3D12_COMPUTE_PIPELINE_STATE_DESC m_desc; }; -#ifdef _DEBUG - void SetObjectName(ID3D12Object* object, const char* name); - void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...); +#ifdef PCSX2_DEVBUILD + void SetObjectName(ID3D12Object* object, std::string_view name); #else - static inline void SetObjectName(ID3D12Object* object, const char* name) - { - } - static inline void SetObjectNameFormatted(ID3D12Object* object, const char* format, ...) - { - } + static inline void SetObjectName(ID3D12Object* object, std::string_view name) {} #endif } // namespace D3D12 diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index 012e95378b..0091578bf0 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -16,6 +16,7 @@ #include "common/BitUtils.h" #include "common/HostSys.h" #include "common/ScopedGuard.h" +#include "common/SmallString.h" #include "common/StringUtil.h" #include "D3D12MemAlloc.h" @@ -2438,7 +2439,7 @@ bool GSDevice12::CompileConvertPipelines() if (!m_convert[index]) return false; - D3D12::SetObjectNameFormatted(m_convert[index].get(), "Convert pipeline %d", i); + D3D12::SetObjectName(m_convert[index].get(), TinyString::from_fmt("Convert pipeline {}", static_cast(i))); if (i == ShaderConvert::COPY) { @@ -2454,8 +2455,8 @@ bool GSDevice12::CompileConvertPipelines() if (!m_color_copy[i]) return false; - D3D12::SetObjectNameFormatted(m_color_copy[i].get(), "Color copy pipeline (r=%u, g=%u, b=%u, a=%u)", - i & 1u, (i >> 1) & 1u, (i >> 2) & 1u, (i >> 3) & 1u); + D3D12::SetObjectName(m_color_copy[i].get(), TinyString::from_fmt("Color copy pipeline (r={}, g={}, b={}, a={})", + i & 1u, (i >> 1) & 1u, (i >> 2) & 1u, (i >> 3) & 1u)); } } else if (i == ShaderConvert::HDR_INIT || i == ShaderConvert::HDR_RESOLVE) @@ -2472,8 +2473,7 @@ bool GSDevice12::CompileConvertPipelines() if (!arr[ds]) return false; - D3D12::SetObjectNameFormatted( - arr[ds].get(), "HDR %s/copy pipeline (ds=%u)", is_setup ? "setup" : "finish", ds); + D3D12::SetObjectName(arr[ds].get(), TinyString::from_fmt("HDR {}/copy pipeline (ds={})", is_setup ? "setup" : "finish", ds)); } } } @@ -2500,8 +2500,8 @@ bool GSDevice12::CompileConvertPipelines() if (!m_date_image_setup_pipelines[ds][datm]) return false; - D3D12::SetObjectNameFormatted( - m_date_image_setup_pipelines[ds][datm].get(), "DATE image clear pipeline (ds=%u, datm=%u)", ds, datm); + D3D12::SetObjectName(m_date_image_setup_pipelines[ds][datm].get(), + TinyString::from_fmt("DATE image clear pipeline (ds={}, datm={})", ds, datm)); } } @@ -2546,7 +2546,7 @@ bool GSDevice12::CompilePresentPipelines() if (!m_present[index]) return false; - D3D12::SetObjectNameFormatted(m_present[index].get(), "Present pipeline %d", i); + D3D12::SetObjectName(m_present[index].get(), TinyString::from_fmt("Present pipeline {}", static_cast(i))); } return true; @@ -2582,7 +2582,7 @@ bool GSDevice12::CompileInterlacePipelines() if (!m_interlace[i]) return false; - D3D12::SetObjectNameFormatted(m_convert[i].get(), "Interlace pipeline %d", i); + D3D12::SetObjectName(m_convert[i].get(), TinyString::from_fmt("Interlace pipeline {}", static_cast(i))); } return true; @@ -2619,7 +2619,7 @@ bool GSDevice12::CompileMergePipelines() if (!m_merge[i]) return false; - D3D12::SetObjectNameFormatted(m_convert[i].get(), "Merge pipeline %d", i); + D3D12::SetObjectName(m_convert[i].get(), TinyString::from_fmt("Merge pipeline {}", i)); } return true; @@ -2946,8 +2946,8 @@ GSDevice12::ComPtr GSDevice12::CreateTFXPipeline(const Pipe ComPtr pipeline(gpb.Create(m_device.get(), m_shader_cache)); if (pipeline) { - D3D12::SetObjectNameFormatted( - pipeline.get(), "TFX Pipeline %08X/%" PRIX64 "%08X", p.vs.key, p.ps.key_hi, p.ps.key_lo); + D3D12::SetObjectName( + pipeline.get(), TinyString::from_fmt("TFX Pipeline {:08X}/{:08X}{:016X}", p.vs.key, p.ps.key_hi, p.ps.key_lo)); } return pipeline; diff --git a/pcsx2/GS/Renderers/DX12/GSTexture12.cpp b/pcsx2/GS/Renderers/DX12/GSTexture12.cpp index 1719a5bb6d..daa29e080a 100644 --- a/pcsx2/GS/Renderers/DX12/GSTexture12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSTexture12.cpp @@ -190,15 +190,8 @@ std::unique_ptr GSTexture12::Create(Type type, Format format, int w switch (type) { - case Type::Texture: - { - D3D12::SetObjectNameFormatted(resource.get(), "%dx%d texture", width, height); - } - break; - case Type::RenderTarget: { - D3D12::SetObjectNameFormatted(resource.get(), "%dx%d render target", width, height); write_descriptor_type = WriteDescriptorType::RTV; if (!CreateRTVDescriptor(resource.get(), rtv_format, &write_descriptor)) { @@ -210,7 +203,6 @@ std::unique_ptr GSTexture12::Create(Type type, Format format, int w case Type::DepthStencil: { - D3D12::SetObjectNameFormatted(resource.get(), "%dx%d depth stencil", width, height); write_descriptor_type = WriteDescriptorType::DSV; if (!CreateDSVDescriptor(resource.get(), dsv_format, &write_descriptor)) { @@ -220,12 +212,6 @@ std::unique_ptr GSTexture12::Create(Type type, Format format, int w } break; - case Type::RWTexture: - { - D3D12::SetObjectNameFormatted(resource.get(), "%dx%d RW texture", width, height); - } - break; - default: break; } @@ -601,6 +587,18 @@ void GSTexture12::GenerateMipmap() SetUseFenceCounter(GSDevice12::GetInstance()->GetCurrentFenceValue()); } +#ifdef PCSX2_DEVBUILD + +void GSTexture12::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + D3D12::SetObjectName(m_resource.get(), name); +} + +#endif + void GSTexture12::TransitionToState(D3D12_RESOURCE_STATES state) { TransitionToState(GSDevice12::GetInstance()->GetCommandList(), state); @@ -800,3 +798,15 @@ void GSDownloadTexture12::Flush() else dev->WaitForFence(m_copy_fence_value, GSConfig.HWSpinGPUForReadbacks); } + +#ifdef PCSX2_DEVBUILD + +void GSDownloadTexture12::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + D3D12::SetObjectName(m_buffer.get(), name); +} + +#endif diff --git a/pcsx2/GS/Renderers/DX12/GSTexture12.h b/pcsx2/GS/Renderers/DX12/GSTexture12.h index 3d1761d380..3b1ce5dad3 100644 --- a/pcsx2/GS/Renderers/DX12/GSTexture12.h +++ b/pcsx2/GS/Renderers/DX12/GSTexture12.h @@ -42,6 +42,10 @@ public: void Unmap() override; void GenerateMipmap() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + void TransitionToState(D3D12_RESOURCE_STATES state); void CommitClear(); void CommitClear(ID3D12GraphicsCommandList* cmdlist); @@ -112,6 +116,10 @@ public: void Flush() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + private: GSDownloadTexture12(u32 width, u32 height, GSTexture::Format format); diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 0e83edf116..c2ac9dc17b 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -13,6 +13,7 @@ #include "common/Console.h" #include "common/BitUtils.h" #include "common/HashCombine.h" +#include "common/SmallString.h" #include "fmt/format.h" @@ -2781,6 +2782,11 @@ bool GSTextureCache::PrepareDownloadTexture(u32 width, u32 height, GSTexture::Fo return false; } +#ifdef PCSX2_DEVBUILD + (*tex)->SetDebugName(TinyString::from_fmt("Texture Cache {}x{} {} Readback", + new_width, new_height, GSTexture::GetFormatName(format))); +#endif + return true; } diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h index 74b9897fae..97e5bead2b 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h @@ -321,24 +321,6 @@ public: std::vector m_debug_entries; u32 m_debug_group_level = 0; - enum class TextureLabel - { - ColorRT, - HDRRT, - U16RT, - U32RT, - DepthStencil, - PrimIDTexture, - RWTexture, - Unorm8Texture, - Texture, - ReplacementTexture, - Other, - Last = Other, - }; - u32 m_texture_counts[static_cast(TextureLabel::Last) + 1] = {}; - u32 m_dl_texture_count = 0; - GSDeviceMTL(); ~GSDeviceMTL() override; diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index fe1139485a..15c5211a96 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -500,74 +500,6 @@ static constexpr MTLPixelFormat ConvertPixelFormat(GSTexture::Format format) } } -static GSDeviceMTL::TextureLabel GetTextureLabel(GSTexture::Type type, GSTexture::Format format) -{ - switch (type) - { - case GSTexture::Type::RenderTarget: - switch (format) - { - case GSTexture::Format::Color: return GSDeviceMTL::TextureLabel::ColorRT; - case GSTexture::Format::HDRColor: return GSDeviceMTL::TextureLabel::HDRRT; - case GSTexture::Format::UInt16: return GSDeviceMTL::TextureLabel::U16RT; - case GSTexture::Format::UInt32: return GSDeviceMTL::TextureLabel::U32RT; - case GSTexture::Format::PrimID: return GSDeviceMTL::TextureLabel::PrimIDTexture; - case GSTexture::Format::Invalid: - case GSTexture::Format::DepthStencil: - case GSTexture::Format::UNorm8: - case GSTexture::Format::BC1: - case GSTexture::Format::BC2: - case GSTexture::Format::BC3: - case GSTexture::Format::BC7: - return GSDeviceMTL::TextureLabel::Other; - } - case GSTexture::Type::Texture: - switch (format) - { - case GSTexture::Format::Color: - return GSDeviceMTL::TextureLabel::Texture; - case GSTexture::Format::UNorm8: - return GSDeviceMTL::TextureLabel::Unorm8Texture; - case GSTexture::Format::BC1: - case GSTexture::Format::BC2: - case GSTexture::Format::BC3: - case GSTexture::Format::BC7: - return GSDeviceMTL::TextureLabel::ReplacementTexture; - case GSTexture::Format::Invalid: - case GSTexture::Format::HDRColor: - case GSTexture::Format::DepthStencil: - case GSTexture::Format::UInt16: - case GSTexture::Format::UInt32: - case GSTexture::Format::PrimID: - return GSDeviceMTL::TextureLabel::Other; - } - case GSTexture::Type::DepthStencil: - return GSDeviceMTL::TextureLabel::DepthStencil; - case GSTexture::Type::RWTexture: - return GSDeviceMTL::TextureLabel::RWTexture; - case GSTexture::Type::Invalid: - return GSDeviceMTL::TextureLabel::Other; - } -} - -static const char* TextureLabelString(GSDeviceMTL::TextureLabel label) -{ - switch (label) - { - case GSDeviceMTL::TextureLabel::ColorRT: return "Color RT"; - case GSDeviceMTL::TextureLabel::HDRRT: return "HDR RT"; - case GSDeviceMTL::TextureLabel::U16RT: return "U16 RT"; - case GSDeviceMTL::TextureLabel::U32RT: return "U32 RT"; - case GSDeviceMTL::TextureLabel::DepthStencil: return "Depth Stencil"; - case GSDeviceMTL::TextureLabel::PrimIDTexture: return "PrimID"; - case GSDeviceMTL::TextureLabel::RWTexture: return "RW Texture"; - case GSDeviceMTL::TextureLabel::Unorm8Texture: return "Unorm8 Texture"; - case GSDeviceMTL::TextureLabel::Texture: return "Texture"; - case GSDeviceMTL::TextureLabel::ReplacementTexture: return "Replacement Texture"; - case GSDeviceMTL::TextureLabel::Other: return "Unknown Texture"; - } -} - GSTexture* GSDeviceMTL::CreateSurface(GSTexture::Type type, int width, int height, int levels, GSTexture::Format format) { @autoreleasepool { MTLPixelFormat fmt = ConvertPixelFormat(format); @@ -604,8 +536,6 @@ GSTexture* GSDeviceMTL::CreateSurface(GSTexture::Type type, int width, int heigh MRCOwned> tex = MRCTransfer([m_dev.dev newTextureWithDescriptor:desc]); if (tex) { - TextureLabel label = GetTextureLabel(type, format); - [tex setLabel:[NSString stringWithFormat:@"%s %d", TextureLabelString(label), m_texture_counts[static_cast(label)]++]]; GSTextureMTL* t = new GSTextureMTL(this, tex, type, format); switch (type) { diff --git a/pcsx2/GS/Renderers/Metal/GSTextureMTL.h b/pcsx2/GS/Renderers/Metal/GSTextureMTL.h index 4cc639968c..0ef7291011 100644 --- a/pcsx2/GS/Renderers/Metal/GSTextureMTL.h +++ b/pcsx2/GS/Renderers/Metal/GSTextureMTL.h @@ -5,6 +5,8 @@ #include "GS/Renderers/Common/GSTexture.h" +#include + #ifndef __OBJC__ #error "This header is for use with Objective-C++ only. #endif @@ -40,6 +42,10 @@ public: void Unmap() override; void GenerateMipmap() override; id GetTexture() { return m_texture; } + +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif }; class GSDownloadTextureMTL final : public GSDownloadTexture @@ -56,6 +62,10 @@ public: void Flush() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + private: GSDownloadTextureMTL(GSDeviceMTL* dev, MRCOwned> buffer, u32 width, u32 height, GSTexture::Format format); diff --git a/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm index f2483163a3..4d54a027e6 100644 --- a/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm @@ -128,6 +128,24 @@ void GSTextureMTL::GenerateMipmap() } }} +#ifdef PCSX2_DEVBUILD + +void GSTextureMTL::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + @autoreleasepool { + NSString* label = [[[NSString alloc] autorelease] + initWithBytes:name.data() + length:static_cast(name.length()) + encoding:NSUTF8StringEncoding]; + [m_texture setLabel:label]; + } +} + +#endif + GSDownloadTextureMTL::GSDownloadTextureMTL(GSDeviceMTL* dev, MRCOwned> buffer, u32 width, u32 height, GSTexture::Format format) : GSDownloadTexture(width, height, format) @@ -150,7 +168,6 @@ std::unique_ptr GSDownloadTextureMTL::Create(GSDeviceMTL* return {}; } - [buffer setLabel:[NSString stringWithFormat:@"Download Texture %d", dev->m_dl_texture_count++]]; return std::unique_ptr(new GSDownloadTextureMTL(dev, buffer, width, height, format)); }} @@ -244,4 +261,22 @@ void GSDownloadTextureMTL::Flush() m_copy_cmdbuffer = nil; } +#ifdef PCSX2_DEVBUILD + +void GSDownloadTextureMTL::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + @autoreleasepool { + NSString* label = [[[NSString alloc] autorelease] + initWithBytes:name.data() + length:static_cast(name.length()) + encoding:NSUTF8StringEncoding]; + [m_buffer setLabel:label]; + } +} + +#endif + #endif diff --git a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp index 4cdaf9eca2..1ded1c69f9 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp @@ -316,6 +316,19 @@ void GSTextureOGL::GenerateMipmap() glGenerateTextureMipmap(m_texture_id); } +#ifdef PCSX2_DEVBUILD + +void GSTextureOGL::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + if (glObjectLabel) + glObjectLabel(GL_TEXTURE, m_texture_id, static_cast(name.length()), static_cast(name.data())); +} + +#endif + GSDownloadTextureOGL::GSDownloadTextureOGL(u32 width, u32 height, GSTexture::Format format) : GSDownloadTexture(width, height, format) { @@ -469,3 +482,16 @@ void GSDownloadTextureOGL::Flush() glDeleteSync(m_sync); m_sync = {}; } + +#ifdef PCSX2_DEVBUILD + +void GSDownloadTextureOGL::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + if (glObjectLabel) + glObjectLabel(GL_BUFFER, m_buffer_id, name.length(), name.data()); +} + +#endif \ No newline at end of file diff --git a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h index be59eac9da..2b511e6fc0 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h +++ b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h @@ -36,10 +36,14 @@ public: void* GetNativeHandle() const override; - bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) final; - bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) final; - void Unmap() final; - void GenerateMipmap() final; + bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) override; + bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) override; + void Unmap() override; + void GenerateMipmap() override; + +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif bool IsIntegerFormat() const { @@ -67,6 +71,10 @@ public: void Flush() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + private: GSDownloadTextureOGL(u32 width, u32 height, GSTexture::Format format); diff --git a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp index fca10c0554..7cf4ab9fe9 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp @@ -165,28 +165,6 @@ std::unique_ptr GSTextureVK::Create(Type type, Format format, int w return {}; } - switch (type) - { - case Type::Texture: - Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), image, "%dx%d texture", width, height); - break; - - case Type::RenderTarget: - Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), image, "%dx%d render target", width, height); - break; - - case Type::DepthStencil: - Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), image, "%dx%d depth stencil", width, height); - break; - - case Type::RWTexture: - Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), image, "%dx%d RW texture", width, height); - break; - - default: - break; - } - return std::unique_ptr( new GSTextureVK(type, format, width, height, levels, image, allocation, view, vk_format)); } @@ -517,6 +495,19 @@ void GSTextureVK::GenerateMipmap() } } +#ifdef PCSX2_DEVBUILD + +void GSTextureVK::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), m_image, "%.*s", static_cast(name.size()), name.data()); + Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), m_view, "%.*s", static_cast(name.size()), name.data()); +} + +#endif + void GSTextureVK::CommitClear() { if (m_state != GSTexture::State::Cleared) @@ -937,3 +928,15 @@ void GSDownloadTextureVK::Flush() else GSDeviceVK::GetInstance()->WaitForFenceCounter(m_copy_fence_counter); } + +#ifdef PCSX2_DEVBUILD + +void GSDownloadTextureVK::SetDebugName(std::string_view name) +{ + if (name.empty()) + return; + + Vulkan::SetObjectName(GSDeviceVK::GetInstance()->GetDevice(), m_buffer, "%.*s", static_cast(name.size()), name.data()); +} + +#endif \ No newline at end of file diff --git a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h index 653c395ecf..a6f2fc1215 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h +++ b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h @@ -53,6 +53,10 @@ public: void Unmap() override; void GenerateMipmap() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + void TransitionToLayout(Layout layout); void CommitClear(); void CommitClear(VkCommandBuffer cmdbuf); @@ -117,6 +121,10 @@ public: void Flush() override; +#ifdef PCSX2_DEVBUILD + void SetDebugName(std::string_view name) override; +#endif + private: GSDownloadTextureVK(u32 width, u32 height, GSTexture::Format format); diff --git a/pcsx2/GS/Renderers/Vulkan/VKBuilders.h b/pcsx2/GS/Renderers/Vulkan/VKBuilders.h index 11493e99f7..bc75f29690 100644 --- a/pcsx2/GS/Renderers/Vulkan/VKBuilders.h +++ b/pcsx2/GS/Renderers/Vulkan/VKBuilders.h @@ -11,7 +11,7 @@ #include #include -#ifdef _DEBUG +#ifdef PCSX2_DEVBUILD #define ENABLE_VULKAN_DEBUG_OBJECTS 1 #endif