Reland "Metal: Add labels to help with GPU Debugging"

Original change's description:
> Metal: Add labels and debug groups to help with GPU Debugging.
>
> * Adds SK_ENABLE_MTL_DEBUG_INFO to enable labels and debug groups,
>   dependent on skia_enable_gpu_debug_layers.
>
> Bug: skia:12150
> Change-Id: I5b4538c0f6df6ceed72d7e8e6f1952fd193b7b90
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/422756
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>

Bug: skia:12150

Change-Id: I4bc686b7fdb1b929dbfdb2dd12fb5170fc9b36a2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/425185
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2021-07-07 12:02:10 -04:00 committed by Skia Commit-Bot
parent 55d339c348
commit 758d81f715
14 changed files with 228 additions and 18 deletions

View File

@ -1027,6 +1027,9 @@ optional("gpu") {
if (skia_use_metal) {
public_defines += [ "SK_METAL" ]
sources += skia_metal_sources
if (skia_enable_metal_debug_info) {
public_defines += [ "SK_ENABLE_MTL_DEBUG_INFO" ]
}
frameworks += [ "Metal.framework" ]
frameworks += [ "Foundation.framework" ]
cflags_objcc += [ "-fobjc-arc" ]

View File

@ -115,6 +115,7 @@ declare_args() {
skia_use_sfntly = skia_use_icu
skia_enable_vulkan_debug_layers = skia_enable_gpu_debug_layers
skia_enable_direct3d_debug_layer = skia_enable_gpu_debug_layers
skia_enable_metal_debug_info = skia_enable_gpu_debug_layers
skia_use_vma = skia_use_vulkan
}

View File

@ -42,9 +42,13 @@ sk_sp<GrMtlAttachment> GrMtlAttachment::MakeStencil(GrMtlGpu* gpu,
if (sampleCnt > 1) {
desc.textureType = MTLTextureType2DMultisample;
}
id<MTLTexture> stencilTexture = [gpu->device() newTextureWithDescriptor:desc];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
stencilTexture.label = @"Stencil";
#endif
return sk_sp<GrMtlAttachment>(
new GrMtlAttachment(gpu, dimensions, UsageFlags::kStencilAttachment,
[gpu->device() newTextureWithDescriptor:desc]));
stencilTexture));
}
GrMtlAttachment::~GrMtlAttachment() {

View File

@ -23,6 +23,17 @@
GR_NORETAIN_BEGIN
#ifdef SK_ENABLE_MTL_DEBUG_INFO
NSString* kBufferTypeNames[kGrGpuBufferTypeCount] = {
@"Vertex",
@"Index",
@"Indirect",
@"Xfer CPU to GPU",
@"Xfer GPU to CPU",
@"Uniform",
};
#endif
sk_sp<GrMtlBuffer> GrMtlBuffer::Make(GrMtlGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrMtlBuffer> buffer(new GrMtlBuffer(gpu, size, intendedType, accessPattern));
@ -57,6 +68,9 @@ GrMtlBuffer::GrMtlBuffer(GrMtlGpu* gpu, size_t size, GrGpuBufferType intendedTyp
fMtlBuffer = size == 0 ? nil :
[gpu->device() newBufferWithLength: size
options: options];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
fMtlBuffer.label = kBufferTypeNames[(int)intendedType];
#endif
this->registerWithCache(SkBudgeted::kYes);
VALIDATE();
}
@ -194,7 +208,8 @@ void GrMtlBuffer::validate() const {
this->intendedType() == GrGpuBufferType::kIndex ||
this->intendedType() == GrGpuBufferType::kXferCpuToGpu ||
this->intendedType() == GrGpuBufferType::kXferGpuToCpu ||
this->intendedType() == GrGpuBufferType::kDrawIndirect);
this->intendedType() == GrGpuBufferType::kDrawIndirect ||
this->intendedType() == GrGpuBufferType::kUniform);
SkASSERT(fMappedBuffer == nil || fMtlBuffer == nil ||
fMappedBuffer.length <= fMtlBuffer.length);
}

View File

@ -60,6 +60,18 @@ public:
}
void callFinishedCallbacks() { fFinishedCallbacks.reset(); }
void pushDebugGroup(NSString* string) {
if (@available(macOS 10.13, iOS 11.0, *)) {
[fCmdBuffer pushDebugGroup:string];
}
}
void popDebugGroup() {
if (@available(macOS 10.13, iOS 11.0, *)) {
[fCmdBuffer popDebugGroup];
}
}
private:
static const int kInitialTrackedResourcesCount = 32;

View File

@ -25,7 +25,9 @@ sk_sp<GrMtlCommandBuffer> GrMtlCommandBuffer::Make(id<MTLCommandQueue> queue) {
return nullptr;
}
mtlCommandBuffer.label = @"GrMtlCommandBuffer::Create";
#ifdef SK_ENABLE_MTL_DEBUG_INFO
mtlCommandBuffer.label = @"GrMtlCommandBuffer::Make";
#endif
return sk_sp<GrMtlCommandBuffer>(new GrMtlCommandBuffer(mtlCommandBuffer));
}

View File

@ -151,7 +151,7 @@ GrMtlGpu::GrMtlGpu(GrDirectContext* direct, const GrContextOptions& options,
, fOutstandingCommandBuffers(sizeof(OutstandingCommandBuffer), kDefaultOutstandingAllocCnt)
, fResourceProvider(this)
, fStagingBufferManager(this)
, fUniformsRingBuffer(this, 128 * 1024, 256, GrGpuBufferType::kVertex)
, fUniformsRingBuffer(this, 128 * 1024, 256, GrGpuBufferType::kUniform)
, fDisconnected(false) {
fMtlCaps.reset(new GrMtlCaps(options, fDevice, featureSet));
this->initCapsAndCompiler(fMtlCaps);
@ -415,6 +415,9 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex,
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"uploadToTexture"];
#endif
for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) {
if (texels[currentMipLevel].fPixels) {
SkASSERT(1 == mipLevelCount || currentHeight == layerHeight);
@ -443,6 +446,9 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex,
#ifdef SK_BUILD_FOR_MAC
[mtlBuffer->mtlBuffer() didModifyRange: NSMakeRange(slice.fOffset, combinedBufferSize)];
#endif
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) {
tex->markMipmapsDirty();
@ -505,9 +511,12 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"clearTexture"];
#endif
// clear the buffer to transparent black
NSRange clearRange;
clearRange.location = slice.fOffset;
clearRange.location = 0;
clearRange.length = combinedBufferSize;
[blitCmdEncoder fillBuffer: transferBuffer
range: clearRange
@ -522,7 +531,7 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
const size_t rowBytes = currentWidth * bpp;
[blitCmdEncoder copyFromBuffer: transferBuffer
sourceOffset: slice.fOffset + individualMipOffsets[currentMipLevel]
sourceOffset: individualMipOffsets[currentMipLevel]
sourceBytesPerRow: rowBytes
sourceBytesPerImage: rowBytes * currentHeight
sourceSize: MTLSizeMake(currentWidth, currentHeight, 1)
@ -535,6 +544,9 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
currentHeight = std::max(1, currentHeight/2);
}
// Don't need didModifyRange: here because fillBuffer: happens on the GPU
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) {
tex->markMipmapsDirty();
@ -694,6 +706,9 @@ sk_sp<GrTexture> GrMtlGpu::onCreateCompressedTexture(SkISize dimensions,
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"onCreateCompressedTexture"];
#endif
// copy data into the buffer, skipping any trailing bytes
memcpy(bufferData, data, dataSize);
@ -721,6 +736,9 @@ sk_sp<GrTexture> GrMtlGpu::onCreateCompressedTexture(SkISize dimensions,
#ifdef SK_BUILD_FOR_MAC
[mtlBuffer->mtlBuffer() didModifyRange: NSMakeRange(slice.fOffset, dataSize)];
#endif
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
return std::move(tex);
}
@ -930,6 +948,9 @@ bool GrMtlGpu::createMtlTextureForBackendSurface(MTLPixelFormat mtlFormat,
desc.textureType = MTLTextureType2DMultisample;
}
id<MTLTexture> testTexture = [fDevice newTextureWithDescriptor: desc];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
testTexture.label = @"testTexture";
#endif
info->fTexture.reset(GrRetainPtrFromId(testTexture));
return true;
}
@ -997,6 +1018,9 @@ bool GrMtlGpu::onClearBackendTexture(const GrBackendTexture& backendTexture,
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"onClearBackendTexture"];
#endif
GrMtlBuffer* mtlBuffer = static_cast<GrMtlBuffer*>(slice.fBuffer);
SkISize levelDimensions(backendTexture.dimensions());
@ -1027,6 +1051,7 @@ bool GrMtlGpu::onClearBackendTexture(const GrBackendTexture& backendTexture,
#ifdef SK_BUILD_FOR_MAC
[mtlBuffer->mtlBuffer() didModifyRange: NSMakeRange(slice.fOffset, combinedBufferSize)];
#endif
[blitCmdEncoder popDebugGroup];
if (finishedCallback) {
this->addFinishedCallback(std::move(finishedCallback));
@ -1094,6 +1119,9 @@ bool GrMtlGpu::onUpdateCompressedBackendTexture(const GrBackendTexture& backendT
GrMtlCommandBuffer* cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"onUpdateCompressedBackendTexture"];
#endif
GrMtlBuffer* mtlBuffer = static_cast<GrMtlBuffer*>(slice.fBuffer);
SkISize levelDimensions(backendTexture.dimensions());
@ -1123,6 +1151,7 @@ bool GrMtlGpu::onUpdateCompressedBackendTexture(const GrBackendTexture& backendT
#ifdef SK_BUILD_FOR_MAC
[mtlBuffer->mtlBuffer() didModifyRange:NSMakeRange(slice.fOffset, combinedBufferSize)];
#endif
[blitCmdEncoder popDebugGroup];
if (finishedCallback) {
this->addFinishedCallback(std::move(finishedCallback));
@ -1237,6 +1266,9 @@ void GrMtlGpu::copySurfaceAsBlit(GrSurface* dst, GrSurface* src, const SkIRect&
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"copySurfaceAsBlit"];
#endif
[blitCmdEncoder copyFromTexture: srcTex
sourceSlice: 0
sourceLevel: 0
@ -1246,6 +1278,9 @@ void GrMtlGpu::copySurfaceAsBlit(GrSurface* dst, GrSurface* src, const SkIRect&
destinationSlice: 0
destinationLevel: 0
destinationOrigin: MTLOriginMake(dstPoint.fX, dstPoint.fY, 0)];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
}
bool GrMtlGpu::onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
@ -1385,6 +1420,9 @@ bool GrMtlGpu::onTransferPixelsTo(GrTexture* texture,
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"onTransferPixelsTo"];
#endif
[blitCmdEncoder copyFromBuffer: mtlBuffer
sourceOffset: offset + grMtlBuffer->offset()
sourceBytesPerRow: rowBytes
@ -1394,6 +1432,9 @@ bool GrMtlGpu::onTransferPixelsTo(GrTexture* texture,
destinationSlice: 0
destinationLevel: 0
destinationOrigin: origin];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
return true;
}
@ -1463,6 +1504,9 @@ bool GrMtlGpu::readOrTransferPixels(GrSurface* surface,
auto cmdBuffer = this->commandBuffer();
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder pushDebugGroup:@"readOrTransferPixels"];
#endif
[blitCmdEncoder copyFromTexture: mtlTexture
sourceSlice: 0
sourceLevel: 0
@ -1476,6 +1520,9 @@ bool GrMtlGpu::readOrTransferPixels(GrSurface* surface,
// Sync GPU data back to the CPU
[blitCmdEncoder synchronizeResource: transferBuffer];
#endif
#ifdef SK_ENABLE_MTL_DEBUG_INFO
[blitCmdEncoder popDebugGroup];
#endif
return true;
}

View File

@ -74,6 +74,9 @@ private:
MTLRenderPassDescriptor* fRenderPassDesc;
SkRect fBounds;
size_t fCurrentVertexStride;
#ifdef SK_ENABLE_MTL_DEBUG_INFO
bool fDebugGroupActive = false;
#endif
static constexpr size_t kNumBindings = GrMtlUniformHandler::kUniformBindingCount + 2;
struct {

View File

@ -94,6 +94,12 @@ bool GrMtlOpsRenderPass::onBindPipeline(const GrProgramInfo& programInfo,
}
fActiveRenderCmdEncoder->setRenderPipelineState(fActivePipelineState->mtlPipelineState());
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
fActivePipelineState->setDrawState(fActiveRenderCmdEncoder,
programInfo.pipeline().writeSwizzle(),
programInfo.pipeline().getXferProcessor());
@ -128,6 +134,12 @@ bool GrMtlOpsRenderPass::onBindTextures(const GrGeometryProcessor& geomProc,
const GrPipeline& pipeline) {
SkASSERT(fActivePipelineState);
SkASSERT(fActiveRenderCmdEncoder);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
fActivePipelineState->setTextures(geomProc, pipeline, geomProcTextures);
fActivePipelineState->bindTextures(fActiveRenderCmdEncoder);
return true;
@ -183,7 +195,9 @@ void GrMtlOpsRenderPass::inlineUpload(GrOpFlushState* state, GrDeferredTextureUp
}
void GrMtlOpsRenderPass::initRenderState(GrMtlRenderCommandEncoder* encoder) {
#ifdef SK_ENABLE_MTL_DEBUG_INFO
encoder->pushDebugGroup(@"initRenderState");
#endif
encoder->setFrontFacingWinding(MTLWindingCounterClockwise);
// Strictly speaking we shouldn't have to set this, as the default viewport is the size of
// the drawable used to generate the renderCommandEncoder -- but just in case.
@ -191,7 +205,9 @@ void GrMtlOpsRenderPass::initRenderState(GrMtlRenderCommandEncoder* encoder) {
(double) fRenderTarget->width(), (double) fRenderTarget->height(),
0.0, 1.0 };
encoder->setViewport(viewport);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
encoder->popDebugGroup();
#endif
}
void GrMtlOpsRenderPass::setupRenderPass(
@ -262,6 +278,12 @@ void GrMtlOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
sk_sp<const GrBuffer> instanceBuffer,
sk_sp<const GrBuffer> vertexBuffer,
GrPrimitiveRestart primRestart) {
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
SkASSERT(GrPrimitiveRestart::kNo == primRestart);
int inputBufferIndex = 0;
if (vertexBuffer) {
@ -289,10 +311,21 @@ void GrMtlOpsRenderPass::onBindBuffers(sk_sp<const GrBuffer> indexBuffer,
void GrMtlOpsRenderPass::onDraw(int vertexCount, int baseVertex) {
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(), 0, 0);
fActiveRenderCmdEncoder->drawPrimitives(fActivePrimitiveType, baseVertex, vertexCount);
fGpu->stats()->incNumDraws();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
@ -300,6 +333,12 @@ void GrMtlOpsRenderPass::onDrawIndexed(int indexCount, int baseIndex, uint16_t m
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
SkASSERT(fActiveIndexBuffer);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(),
fCurrentVertexStride * baseVertex, 0);
@ -309,12 +348,23 @@ void GrMtlOpsRenderPass::onDrawIndexed(int indexCount, int baseIndex, uint16_t m
fActiveRenderCmdEncoder->drawIndexedPrimitives(fActivePrimitiveType, indexCount,
MTLIndexTypeUInt16, indexBuffer, indexOffset);
fGpu->stats()->incNumDraws();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
int baseVertex) {
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(), 0, 0);
if (@available(macOS 10.11, iOS 9.0, *)) {
@ -324,6 +374,11 @@ void GrMtlOpsRenderPass::onDrawInstanced(int instanceCount, int baseInstance, in
SkASSERT(false);
}
fGpu->stats()->incNumDraws();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::onDrawIndexedInstanced(
@ -331,6 +386,12 @@ void GrMtlOpsRenderPass::onDrawIndexedInstanced(
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
SkASSERT(fActiveIndexBuffer);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(), 0, 0);
auto mtlIndexBuffer = static_cast<const GrMtlBuffer*>(fActiveIndexBuffer.get());
@ -344,6 +405,11 @@ void GrMtlOpsRenderPass::onDrawIndexedInstanced(
SkASSERT(false);
}
fGpu->stats()->incNumDraws();
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::onDrawIndirect(const GrBuffer* drawIndirectBuffer,
@ -352,6 +418,12 @@ void GrMtlOpsRenderPass::onDrawIndirect(const GrBuffer* drawIndirectBuffer,
SkASSERT(fGpu->caps()->nativeDrawIndirectSupport());
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(), 0, 0);
auto mtlIndirectBuffer = static_cast<const GrMtlBuffer*>(drawIndirectBuffer);
@ -367,6 +439,11 @@ void GrMtlOpsRenderPass::onDrawIndirect(const GrBuffer* drawIndirectBuffer,
bufferOffset += stride;
fGpu->stats()->incNumDraws();
}
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer,
@ -376,6 +453,12 @@ void GrMtlOpsRenderPass::onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffe
SkASSERT(fActivePipelineState);
SkASSERT(nil != fActiveRenderCmdEncoder);
SkASSERT(fActiveIndexBuffer);
#ifdef SK_ENABLE_MTL_DEBUG_INFO
if (!fDebugGroupActive) {
fActiveRenderCmdEncoder->pushDebugGroup(@"bindAndDraw");
fDebugGroupActive = true;
}
#endif
this->setVertexBuffer(fActiveRenderCmdEncoder, fActiveVertexBuffer.get(), 0, 0);
auto mtlIndexBuffer = static_cast<const GrMtlBuffer*>(fActiveIndexBuffer.get());
@ -398,6 +481,11 @@ void GrMtlOpsRenderPass::onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffe
bufferOffset += stride;
fGpu->stats()->incNumDraws();
}
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkASSERT(fDebugGroupActive);
fActiveRenderCmdEncoder->popDebugGroup();
fDebugGroupActive = false;
#endif
}
void GrMtlOpsRenderPass::setVertexBuffer(GrMtlRenderCommandEncoder* encoder,

View File

@ -108,11 +108,9 @@ void GrMtlPipelineState::setTextures(const GrGeometryProcessor& geomProc,
void GrMtlPipelineState::setDrawState(GrMtlRenderCommandEncoder* renderCmdEncoder,
const GrSwizzle& writeSwizzle,
const GrXferProcessor& xferProcessor) {
renderCmdEncoder->pushDebugGroup(@"setDrawState");
this->bindUniforms(renderCmdEncoder);
this->setBlendConstants(renderCmdEncoder, writeSwizzle, xferProcessor);
this->setDepthStencilState(renderCmdEncoder);
renderCmdEncoder->popDebugGroup();
}
void GrMtlPipelineState::bindUniforms(GrMtlRenderCommandEncoder* renderCmdEncoder) {

View File

@ -400,6 +400,15 @@ static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment) {
static MTLRenderPipelineDescriptor* read_pipeline_data(SkReadBuffer* reader) {
auto pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
// set label
{
SkString description;
reader->readString(&description);
pipelineDescriptor.label = @(description.c_str());
}
#endif
// set up vertex descriptor
{
auto vertexDescriptor = [[MTLVertexDescriptor alloc] init];
@ -495,6 +504,16 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(
// Ordering in how we set these matters. If it changes adjust read_pipeline_data, above.
auto pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
SkString description = GrProgramDesc::Describe(programInfo, *fGpu->caps());
int split = description.find("\n");
description.resize(split);
pipelineDescriptor.label = @(description.c_str());
if (writer) {
writer->writeString(description.c_str());
}
#endif
pipelineDescriptor.vertexDescriptor = create_vertex_descriptor(programInfo.geomProc(),
writer.get());
@ -684,6 +703,7 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(
}
}
#endif
id<MTLRenderPipelineState> pipelineState;
{
TRACE_EVENT0("skia.shaders", "newRenderPipelineStateWithDescriptor");

View File

@ -33,12 +33,15 @@ public:
[fCommandEncoder setLabel:label];
}
void pushDebugGroup(NSString* debugString) {
[fCommandEncoder pushDebugGroup:debugString];
void pushDebugGroup(NSString* string) {
[fCommandEncoder pushDebugGroup:string];
}
void popDebugGroup() {
[fCommandEncoder popDebugGroup];
}
void insertDebugSignpost(NSString* string) {
[fCommandEncoder insertDebugSignpost:string];
}
void setRenderPipelineState(id<MTLRenderPipelineState> pso) {
if (fCurrentRenderPipelineState != pso) {
@ -48,7 +51,10 @@ public:
}
void setTriangleFillMode(MTLTriangleFillMode fillMode) {
[fCommandEncoder setTriangleFillMode:fillMode];
if (fCurrentTriangleFillMode != fillMode) {
[fCommandEncoder setTriangleFillMode:fillMode];
fCurrentTriangleFillMode = fillMode;
}
}
void setFrontFacingWinding(MTLWinding winding) {
@ -248,6 +254,7 @@ private:
__weak id<MTLTexture> fCurrentTexture[GrSamplerState::kNumUniqueSamplers];
GrMtlSampler* fCurrentSampler[GrSamplerState::kNumUniqueSamplers] = { 0 };
MTLScissorRect fCurrentScissorRect = { 0, 0, 0, 0 };
MTLTriangleFillMode fCurrentTriangleFillMode = (MTLTriangleFillMode)-1;
};
GR_NORETAIN_END

View File

@ -100,6 +100,9 @@ sk_sp<GrMtlRenderTarget> GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gp
SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) &
colorTexture.usage);
}
#ifdef SK_ENABLE_MTL_DEBUG_INFO
colorTexture.label = @"MSAA RenderTarget";
#endif
mtlRT = new GrMtlRenderTarget(
gpu, dimensions, sampleCnt, colorTexture, texture, kWrapped);
mtlRT->setRequiresManualMSAAResolve();

View File

@ -82,7 +82,14 @@ id<MTLTexture> create_msaa_texture(GrMtlGpu* gpu, SkISize dimensions, MTLPixelFo
texDesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget;
}
return [gpu->device() newTextureWithDescriptor:texDesc];
id<MTLTexture> msaaTexture = [gpu->device() newTextureWithDescriptor:texDesc];
#ifdef SK_ENABLE_MTL_DEBUG_INFO
msaaTexture.label = @"MSAA RenderTarget";
#endif
if (@available(macOS 10.11, iOS 9.0, *)) {
SkASSERT((MTLTextureUsageShaderRead|MTLTextureUsageRenderTarget) & msaaTexture.usage);
}
return msaaTexture;
}
sk_sp<GrMtlTextureRenderTarget> GrMtlTextureRenderTarget::MakeNewTextureRenderTarget(
@ -106,12 +113,15 @@ sk_sp<GrMtlTextureRenderTarget> GrMtlTextureRenderTarget::MakeNewTextureRenderTa
if (!colorTexture) {
return nullptr;
}
if (@available(macOS 10.11, iOS 9.0, *)) {
SkASSERT((MTLTextureUsageShaderRead|MTLTextureUsageRenderTarget) & colorTexture.usage);
}
#ifdef SK_ENABLE_MTL_DEBUG_INFO
texture.label = @"Resolve TextureRenderTarget";
#endif
return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(
gpu, budgeted, dimensions, sampleCnt, colorTexture, texture, mipmapStatus));
} else {
#ifdef SK_ENABLE_MTL_DEBUG_INFO
texture.label = @"TextureRenderTarget";
#endif
return sk_sp<GrMtlTextureRenderTarget>(
new GrMtlTextureRenderTarget(gpu, budgeted, dimensions, texture, mipmapStatus));
}
@ -136,9 +146,6 @@ sk_sp<GrMtlTextureRenderTarget> GrMtlTextureRenderTarget::MakeWrappedTextureRend
if (!colorTexture) {
return nullptr;
}
if (@available(macOS 10.11, iOS 9.0, *)) {
SkASSERT((MTLTextureUsageShaderRead|MTLTextureUsageRenderTarget) & colorTexture.usage);
}
return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(
gpu, dimensions, sampleCnt, colorTexture, texture, mipmapStatus, cacheable));
} else {