diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h index 97e5bead2b708..74b9897fae88b 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h @@ -321,6 +321,24 @@ class GSDeviceMTL final : public GSDevice 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 15c5211a966fc..fe1139485aedd 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -500,6 +500,74 @@ 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); @@ -536,6 +604,8 @@ static constexpr MTLPixelFormat ConvertPixelFormat(GSTexture::Format format) 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.mm b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm index 89c56e08e621e..f4fc5b4d98f02 100644 --- a/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSTextureMTL.mm @@ -152,7 +152,7 @@ GSDownloadTextureMTL::~GSDownloadTextureMTL() = default; std::unique_ptr GSDownloadTextureMTL::Create(GSDeviceMTL* dev, u32 width, u32 height, GSTexture::Format format) -{ +{ @autoreleasepool { const u32 buffer_size = GetBufferSize(width, height, format, PITCH_ALIGNMENT); MRCOwned> buffer = MRCTransfer([dev->m_dev.dev newBufferWithLength:buffer_size options:MTLResourceStorageModeShared]); @@ -162,8 +162,9 @@ return {}; } + [buffer setLabel:[NSString stringWithFormat:@"Download Texture %d", dev->m_dl_texture_count++]]; return std::unique_ptr(new GSDownloadTextureMTL(dev, buffer, width, height, format)); -} +}} void GSDownloadTextureMTL::CopyFromTexture( const GSVector4i& drc, GSTexture* stex, const GSVector4i& src, u32 src_level, bool use_transfer_pitch)