Skip to content

Commit

Permalink
GS:MTL: Give labels to textures
Browse files Browse the repository at this point in the history
  • Loading branch information
TellowKrinkle authored and stenzek committed Dec 30, 2023
1 parent 4707304 commit 97310b8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pcsx2/GS/Renderers/Metal/GSDeviceMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ class GSDeviceMTL final : public GSDevice
std::vector<DebugEntry> 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<u32>(TextureLabel::Last) + 1] = {};
u32 m_dl_texture_count = 0;

GSDeviceMTL();
~GSDeviceMTL() override;

Expand Down
70 changes: 70 additions & 0 deletions pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -536,6 +604,8 @@ static constexpr MTLPixelFormat ConvertPixelFormat(GSTexture::Format format)
MRCOwned<id<MTLTexture>> 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<u32>(label)]++]];
GSTextureMTL* t = new GSTextureMTL(this, tex, type, format);
switch (type)
{
Expand Down
5 changes: 3 additions & 2 deletions pcsx2/GS/Renderers/Metal/GSTextureMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
GSDownloadTextureMTL::~GSDownloadTextureMTL() = default;

std::unique_ptr<GSDownloadTextureMTL> GSDownloadTextureMTL::Create(GSDeviceMTL* dev, u32 width, u32 height, GSTexture::Format format)
{
{ @autoreleasepool {
const u32 buffer_size = GetBufferSize(width, height, format, PITCH_ALIGNMENT);

MRCOwned<id<MTLBuffer>> buffer = MRCTransfer([dev->m_dev.dev newBufferWithLength:buffer_size options:MTLResourceStorageModeShared]);
Expand All @@ -162,8 +162,9 @@
return {};
}

[buffer setLabel:[NSString stringWithFormat:@"Download Texture %d", dev->m_dl_texture_count++]];
return std::unique_ptr<GSDownloadTextureMTL>(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)
Expand Down

0 comments on commit 97310b8

Please sign in to comment.