Skip to content

Commit

Permalink
Minor debugging enhancements.
Browse files Browse the repository at this point in the history
- On GPU error, log indicate whether device has been resumed or lost,
  and report as either warning or error, respectively.
- On VkDevice loss, stop device-scope GPU capture.
- In debug mode, include address of Metal object in Metal object label.
- Replace setLabelIfNotNil() with setMetalObjectLabel() and move
  inside MVKVulkanAPIObject to allow access to config info.
- When logging contents of MVKDescriptorPool,
  only list descriptor types with allocations.
- Add @autoreleasepool around complex NSString creation.
  • Loading branch information
billhollings committed Aug 27, 2024
1 parent dad3851 commit 38a170b
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 62 deletions.
8 changes: 4 additions & 4 deletions MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
mtlStencilAttDesc.slice = mvkIBR.region.dstSubresource.baseArrayLayer + layIdx;
}
id<MTLRenderCommandEncoder> mtlRendEnc = [cmdEncoder->_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPD];
setLabelIfNotNil(mtlRendEnc, mvkMTLRenderCommandEncoderLabel(commandUse));
cmdEncoder->_cmdBuffer->setMetalObjectLabel(mtlRendEnc, mvkMTLRenderCommandEncoderLabel(commandUse));

float zIncr;
if (blitKey.srcMTLTextureType == MTLTextureType3D) {
Expand Down Expand Up @@ -893,7 +893,7 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
mtlRPD.renderTargetArrayLengthMVK = rslvSlice.dstSubresource.layerCount;
}
id<MTLRenderCommandEncoder> mtlRendEnc = [cmdEncoder->_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPD];
setLabelIfNotNil(mtlRendEnc, mvkMTLRenderCommandEncoderLabel(kMVKCommandUseResolveImage));
cmdEncoder->_cmdBuffer->setMetalObjectLabel(mtlRendEnc, mvkMTLRenderCommandEncoderLabel(kMVKCommandUseResolveImage));

[mtlRendEnc pushDebugGroup: @"vkCmdResolveImage"];
[mtlRendEnc popDebugGroup];
Expand Down Expand Up @@ -1699,7 +1699,7 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
: layerCnt);

id<MTLRenderCommandEncoder> mtlRendEnc = [cmdEncoder->_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc];
setLabelIfNotNil(mtlRendEnc, mtlRendEncName);
cmdEncoder->_cmdBuffer->setMetalObjectLabel(mtlRendEnc, mtlRendEncName);
[mtlRendEnc endEncoding];
} else {
for (uint32_t layer = layerStart; layer < layerEnd; layer++) {
Expand All @@ -1714,7 +1714,7 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
}

id<MTLRenderCommandEncoder> mtlRendEnc = [cmdEncoder->_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc];
setLabelIfNotNil(mtlRendEnc, mtlRendEncName);
cmdEncoder->_cmdBuffer->setMetalObjectLabel(mtlRendEnc, mtlRendEncName);
[mtlRendEnc endEncoding];
}
}
Expand Down
10 changes: 5 additions & 5 deletions MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@

_mtlCmdBuffer = mtlCmdBuff; // not retained

setLabelIfNotNil(_mtlCmdBuffer, _cmdBuffer->_debugName);
_cmdBuffer->setMetalObjectLabel(_mtlCmdBuffer, _cmdBuffer->_debugName);
}

// Multithread autorelease prefill style uses a dedicated autorelease pool when encoding each command.
Expand Down Expand Up @@ -582,7 +582,7 @@

_mtlRenderEncoder = [_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc];
retainIfImmediatelyEncoding(_mtlRenderEncoder);
setLabelIfNotNil(_mtlRenderEncoder, getMTLRenderCommandEncoderName(cmdUse));
_cmdBuffer->setMetalObjectLabel(_mtlRenderEncoder, getMTLRenderCommandEncoderName(cmdUse));

// We shouldn't clear the render area if we are restarting the Metal renderpass
// separately from a Vulkan subpass, and we otherwise only need to clear render
Expand Down Expand Up @@ -847,7 +847,7 @@
}
if (_mtlComputeEncoderUse != cmdUse) {
_mtlComputeEncoderUse = cmdUse;
setLabelIfNotNil(_mtlComputeEncoder, mvkMTLComputeCommandEncoderLabel(cmdUse));
_cmdBuffer->setMetalObjectLabel(_mtlComputeEncoder, mvkMTLComputeCommandEncoderLabel(cmdUse));
}
return _mtlComputeEncoder;
}
Expand All @@ -860,7 +860,7 @@
}
if (_mtlBlitEncoderUse != cmdUse) {
_mtlBlitEncoderUse = cmdUse;
setLabelIfNotNil(_mtlBlitEncoder, mvkMTLBlitCommandEncoderLabel(cmdUse));
_cmdBuffer->setMetalObjectLabel(_mtlBlitEncoder, mvkMTLBlitCommandEncoderLabel(cmdUse));
}
return _mtlBlitEncoder;
}
Expand Down Expand Up @@ -1083,7 +1083,7 @@
}

auto* mtlEnc = [_mtlCmdBuffer blitCommandEncoderWithDescriptor: bpDesc];
setLabelIfNotNil(mtlEnc, mvkMTLBlitCommandEncoderLabel(kMVKCommandUseRecordGPUCounterSample));
_cmdBuffer->setMetalObjectLabel(mtlEnc, mvkMTLBlitCommandEncoderLabel(kMVKCommandUseRecordGPUCounterSample));
[bpDesc release]; // Release temp object
[mtlEnc waitForFence: getStageCountersMTLFence()];
[mtlEnc fillBuffer: _device->getDummyBlitMTLBuffer() range: NSMakeRange(0, 1) value: 0];
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
id<MTLFunction> vtxFunc = newFunctionNamed(isLayeredBlit ? "vtxCmdBlitImageLayered" : "vtxCmdBlitImage"); // temp retain
id<MTLFunction> fragFunc = newBlitFragFunction(blitKey); // temp retain
MTLRenderPipelineDescriptor* plDesc = [MTLRenderPipelineDescriptor new]; // temp retain
plDesc.label = @"vkCmdBlitImage";
owner->setMetalObjectLabel(plDesc, @"vkCmdBlitImage");

plDesc.vertexFunction = vtxFunc;
plDesc.fragmentFunction = fragFunc;
Expand Down Expand Up @@ -118,7 +118,7 @@
id<MTLFunction> vtxFunc = newClearVertFunction(attKey); // temp retain
id<MTLFunction> fragFunc = newClearFragFunction(attKey); // temp retain
MTLRenderPipelineDescriptor* plDesc = [MTLRenderPipelineDescriptor new]; // temp retain
plDesc.label = @"ClearRenderAttachments";
owner->setMetalObjectLabel(plDesc, @"ClearRenderAttachments");
plDesc.vertexFunction = vtxFunc;
plDesc.fragmentFunction = fragFunc;
plDesc.sampleCount = attKey.mtlSampleCount;
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

_deviceMemory->setDebugName(_debugName.UTF8String);
}
setLabelIfNotNil(_mtlBuffer, _debugName);
setMetalObjectLabel(_mtlBuffer, _debugName);
}


Expand Down Expand Up @@ -279,7 +279,7 @@
#pragma mark MVKBufferView

void MVKBufferView::propagateDebugName() {
setLabelIfNotNil(_mtlTexture, _debugName);
setMetalObjectLabel(_mtlTexture, _debugName);
}

#pragma mark Metal
Expand Down
7 changes: 5 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,10 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf

std::string MVKDescriptorPool::getLogDescription() {
#define STR(name) #name
#define printDescCnt(descType, spacing, descPool) descStr << "\n\t" STR(VK_DESCRIPTOR_TYPE_##descType) ": " spacing << _##descPool##Descriptors.size() << " (" << _##descPool##Descriptors.getRemainingDescriptorCount() << " remaining)";
#define printDescCnt(descType, spacing, descPool) \
if (_##descPool##Descriptors.size()) { \
descStr << "\n\t" STR(VK_DESCRIPTOR_TYPE_##descType) ": " spacing << _##descPool##Descriptors.size() \
<< " (" << _##descPool##Descriptors.getRemainingDescriptorCount() << " remaining)"; }

std::stringstream descStr;
descStr << "VkDescriptorPool " << this << " with " << _descriptorSetAvailablility.size() << " descriptor sets, and pooled descriptors:";
Expand Down Expand Up @@ -1075,7 +1078,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
metalArgBuffSize = maxMTLBuffSize;
}
_metalArgumentBuffer = [getMTLDevice() newBufferWithLength: metalArgBuffSize options: MTLResourceStorageModeShared]; // retained
_metalArgumentBuffer.label = @"Descriptor set argument buffer";
setMetalObjectLabel(_metalArgumentBuffer, @"Descriptor set argument buffer");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#pragma mark MVKDeviceMemory

void MVKDeviceMemory::propagateDebugName() {
setLabelIfNotNil(_mtlHeap, _debugName);
setLabelIfNotNil(_mtlBuffer, _debugName);
setMetalObjectLabel(_mtlHeap, _debugName);
setMetalObjectLabel(_mtlBuffer, _debugName);
}

VkResult MVKDeviceMemory::map(const VkMemoryMapInfoKHR* pMemoryMapInfo, void** ppData) {
Expand Down
6 changes: 3 additions & 3 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
}

void MVKImagePlane::propagateDebugName() {
setLabelIfNotNil(_image->_planes[_planeIndex]->_mtlTexture, _image->_debugName);
_image->setMetalObjectLabel(_image->_planes[_planeIndex]->_mtlTexture, _image->_debugName);
}

MVKImageMemoryBinding* MVKImagePlane::getMemoryBinding() const {
Expand Down Expand Up @@ -463,7 +463,7 @@
_image->_planes[planeIndex]->propagateDebugName();
}
if (_ownsTexelBuffer) {
setLabelIfNotNil(_mtlTexelBuffer, _image->_debugName);
setMetalObjectLabel(_mtlTexelBuffer, _image->_debugName);
}
}

Expand Down Expand Up @@ -1768,7 +1768,7 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {

MVKVulkanAPIObject* MVKImageViewPlane::getVulkanAPIObject() { return _imageView; }

void MVKImageViewPlane::propagateDebugName() { setLabelIfNotNil(_mtlTexture, _imageView->_debugName); }
void MVKImageViewPlane::propagateDebugName() { _imageView->setMetalObjectLabel(_mtlTexture, _imageView->_debugName); }


#pragma mark Metal
Expand Down
8 changes: 4 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ static MVKRenderStateType getRenderStateType(VkDynamicState vkDynamicState) {
// Metal does not allow the name of the pipeline to be changed after it has been created,
// and we need to create the Metal pipeline immediately to provide error feedback to app.
// The best we can do at this point is set the pipeline name from the layout.
setLabelIfNotNil(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());
setMetalObjectLabel(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());

return plDesc;
}
Expand Down Expand Up @@ -893,7 +893,7 @@ static MVKRenderStateType getRenderStateType(VkDynamicState vkDynamicState) {
// Metal does not allow the name of the pipeline to be changed after it has been created,
// and we need to create the Metal pipeline immediately to provide error feedback to app.
// The best we can do at this point is set the pipeline name from the layout.
setLabelIfNotNil(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());
setMetalObjectLabel(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());

return plDesc;
}
Expand Down Expand Up @@ -1035,7 +1035,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
// Metal does not allow the name of the pipeline to be changed after it has been created,
// and we need to create the Metal pipeline immediately to provide error feedback to app.
// The best we can do at this point is set the pipeline name from the layout.
setLabelIfNotNil(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());
setMetalObjectLabel(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());

return plDesc;
}
Expand Down Expand Up @@ -2159,7 +2159,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
// Metal does not allow the name of the pipeline to be changed after it has been created,
// and we need to create the Metal pipeline immediately to provide error feedback to app.
// The best we can do at this point is set the pipeline name from the layout.
setLabelIfNotNil(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());
setMetalObjectLabel(plDesc, ((MVKPipelineLayout*)pCreateInfo->layout)->getDebugName());

MVKComputePipelineCompiler* plc = new MVKComputePipelineCompiler(this);
_mtlPipelineState = plc->newMTLComputePipelineState(plDesc); // retained
Expand Down
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKQueryPool.mm
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
#pragma mark -
#pragma mark MVKOcclusionQueryPool

void MVKOcclusionQueryPool::propagateDebugName() { setLabelIfNotNil(_visibilityResultMTLBuffer, _debugName); }
void MVKOcclusionQueryPool::propagateDebugName() { setMetalObjectLabel(_visibilityResultMTLBuffer, _debugName); }

// If a dedicated visibility buffer has been established, use it, otherwise fetch the
// current global visibility buffer, but don't cache it because it could be replaced later.
Expand Down
25 changes: 16 additions & 9 deletions MoltenVK/MoltenVK/GPUObjects/MVKQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#pragma mark -
#pragma mark MVKQueue

void MVKQueue::propagateDebugName() { setLabelIfNotNil(_mtlQueue, _debugName); }
void MVKQueue::propagateDebugName() { setMetalObjectLabel(_mtlQueue, _debugName); }


#pragma mark Queue submissions
Expand Down Expand Up @@ -190,7 +190,7 @@
}
addPerformanceInterval(getPerformanceStats().queue.retrieveMTLCommandBuffer, startTime);
NSString* mtlCmdBuffLabel = getMTLCommandBufferLabel(cmdUse);
setLabelIfNotNil(mtlCmdBuff, mtlCmdBuffLabel);
setMetalObjectLabel(mtlCmdBuff, mtlCmdBuffLabel);
[mtlCmdBuff addCompletedHandler: ^(id<MTLCommandBuffer> mtlCB) { handleMTLCommandBufferError(mtlCB); }];

if ( !mtlCmdBuff ) { reportError(VK_ERROR_OUT_OF_POOL_MEMORY, "%s could not be acquired.", mtlCmdBuffLabel.UTF8String); }
Expand All @@ -200,7 +200,7 @@
NSString* MVKQueue::getMTLCommandBufferLabel(MVKCommandUse cmdUse) {
#define CASE_GET_LABEL(cu) \
case kMVKCommandUse ##cu: \
if ( !_mtlCmdBuffLabel ##cu ) { _mtlCmdBuffLabel ##cu = [[NSString stringWithFormat: @"%s MTLCommandBuffer on Queue %d-%d", mvkVkCommandName(kMVKCommandUse ##cu), _queueFamily->getIndex(), _index] retain]; } \
if ( !_mtlCmdBuffLabel ##cu ) { @autoreleasepool { _mtlCmdBuffLabel ##cu = [[NSString stringWithFormat: @"%s MTLCommandBuffer on Queue %d-%d", mvkVkCommandName(kMVKCommandUse ##cu), _queueFamily->getIndex(), _index] retain]; } } \
return _mtlCmdBuffLabel ##cu

switch (cmdUse) {
Expand All @@ -213,8 +213,10 @@
CASE_GET_LABEL(InvalidateMappedMemoryRanges);
CASE_GET_LABEL(CopyImageToMemory);
default:
MVKAssert(false, "Uncached MTLCommandBuffer label for command use %s.", mvkVkCommandName(cmdUse));
return [NSString stringWithFormat: @"%s MTLCommandBuffer on Queue %d-%d", mvkVkCommandName(cmdUse), _queueFamily->getIndex(), _index];
@autoreleasepool { \
MVKAssert(false, "Uncached MTLCommandBuffer label for command use %s.", mvkVkCommandName(cmdUse));
return [NSString stringWithFormat: @"%s MTLCommandBuffer on Queue %d-%d", mvkVkCommandName(cmdUse), _queueFamily->getIndex(), _index];
}
}
#undef CASE_GET_LABEL
}
Expand Down Expand Up @@ -264,10 +266,15 @@
vkErr = VK_ERROR_OUT_OF_DEVICE_MEMORY;
break;
}
reportError(vkErr, "MTLCommandBuffer \"%s\" execution failed (code %li): %s",
mtlCmdBuff.label ? mtlCmdBuff.label.UTF8String : "",
mtlCmdBuff.error.code, mtlCmdBuff.error.localizedDescription.UTF8String);
if (markDeviceLoss) { getDevice()->markLost(markPhysicalDeviceLoss); }
if (markDeviceLoss) {
getDevice()->stopAutoGPUCapture(MVK_CONFIG_AUTO_GPU_CAPTURE_SCOPE_DEVICE);
getDevice()->markLost(markPhysicalDeviceLoss);
}
reportResult(vkErr, (markDeviceLoss ? MVK_CONFIG_LOG_LEVEL_ERROR : MVK_CONFIG_LOG_LEVEL_WARNING),
"%s VkDevice after MTLCommandBuffer \"%s\" execution failed (code %li): %s",
(markDeviceLoss ? "Lost" : "Resumed"),
(mtlCmdBuff.label ? mtlCmdBuff.label.UTF8String : ""),
mtlCmdBuff.error.code, mtlCmdBuff.error.localizedDescription.UTF8String);

#if MVK_XCODE_12
if (&MTLCommandBufferEncoderInfoErrorKey != nullptr) {
Expand Down
6 changes: 3 additions & 3 deletions MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ static uint32_t getWorkgroupDimensionSize(const SPIRVWorkgroupSizeDimension& wgD
}

// Set the debug name. First try name of shader module, otherwise try name of owner.
NSString* dbName = shaderModule-> getDebugName();
if ( !dbName ) { dbName = _owner-> getDebugName(); }
setLabelIfNotNil(mtlFunc, dbName);
NSString* dbName = shaderModule->getDebugName();
if ( !dbName ) { dbName = _owner->getDebugName(); }
_owner->setMetalObjectLabel(mtlFunc, dbName);

auto& wgSize = _shaderConversionResultInfo.entryPoint.workgroupSize;
return MVKMTLFunction(mtlFunc, _shaderConversionResultInfo, MTLSizeMake(getWorkgroupDimensionSize(wgSize.width, pSpecializationInfo),
Expand Down
10 changes: 5 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

void MVKSwapchain::propagateDebugName() {
if (_debugName) {
size_t imgCnt = _presentableImages.size();
for (size_t imgIdx = 0; imgIdx < imgCnt; imgIdx++) {
NSString* nsName = [[NSString alloc] initWithFormat: @"%@(%lu)", _debugName, imgIdx]; // temp retain
_presentableImages[imgIdx]->setDebugName(nsName.UTF8String);
[nsName release]; // release temp string
@autoreleasepool {
size_t imgCnt = _presentableImages.size();
for (size_t imgIdx = 0; imgIdx < imgCnt; imgIdx++) {
_presentableImages[imgIdx]->setDebugName([NSString stringWithFormat: @"%@(%lu)", _debugName, imgIdx].UTF8String);
}
}
}
}
Expand Down
14 changes: 3 additions & 11 deletions MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class MVKVulkanAPIObject : public MVKReferenceCountingMixin<MVKBaseObject>, publ
/** Sets the debug object name of this instance. */
VkResult setDebugName(const char* pObjectName);

/** Sets the label of the Metal object. */
void setMetalObjectLabel(id mtlObj, NSString* label);

/** Returns the MVKVulkanAPIObject instance referenced by the object of the given type. */
static MVKVulkanAPIObject* getMVKVulkanAPIObject(VkDebugReportObjectTypeEXT objType, uint64_t object);

Expand Down Expand Up @@ -119,14 +122,3 @@ class MVKDispatchableVulkanAPIObject : public MVKVulkanAPIObject {
MVKDispatchableObjectICDRef _icdRef = { 0, this };

};

#pragma mark -
#pragma mark Support functions

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-method-access"
/** Generically avoids setting a label to nil, which many objects don't like. */
static inline void setLabelIfNotNil(id object, NSString* label) { if (label) { [object setLabel: label]; } }
#pragma clang diagnostic pop


21 changes: 20 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,31 @@
VkResult MVKVulkanAPIObject::setDebugName(const char* pObjectName) {
if (pObjectName) {
[_debugName release];
_debugName = [[NSString alloc] initWithUTF8String: pObjectName]; // retained
@autoreleasepool {
_debugName = [[NSString alloc] initWithUTF8String: pObjectName]; // retained
}
propagateDebugName();
}
return VK_SUCCESS;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-method-access"
void MVKVulkanAPIObject::setMetalObjectLabel(id mtlObj, NSString* label) {
if ( !label ) { return; }

// If debug mode is enabled, append the object address.
// Since doing so might internally create other Metal objects, so catch them in an autorelease pool.
if (getMVKConfig().debugMode) {
@autoreleasepool {
[mtlObj setLabel: [label stringByAppendingFormat: @" (%p)", mtlObj]];
}
} else {
[mtlObj setLabel: label];
}
}
#pragma clang diagnostic pop

MVKVulkanAPIObject* MVKVulkanAPIObject::getMVKVulkanAPIObject(VkDebugReportObjectTypeEXT objType, uint64_t object) {
void* pVkObj = (void*)object;
switch (objType) {
Expand Down
6 changes: 4 additions & 2 deletions MoltenVK/MoltenVK/OS/MVKGPUCapture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
MVKGPUCaptureScope::MVKGPUCaptureScope(MVKQueue* mvkQueue) {
_mtlQueue = [mvkQueue->getMTLCommandQueue() retain]; // retained
if (mvkOSVersionIsAtLeast(10.13, 11.0, 1.0)) {
_mtlCaptureScope = [[MTLCaptureManager sharedCaptureManager] newCaptureScopeWithCommandQueue: _mtlQueue]; // retained
_mtlCaptureScope.label = @(mvkQueue->getName().c_str());
@autoreleasepool {
_mtlCaptureScope = [[MTLCaptureManager sharedCaptureManager] newCaptureScopeWithCommandQueue: _mtlQueue]; // retained
mvkQueue->setMetalObjectLabel(_mtlCaptureScope, @(mvkQueue->getName().c_str()));
}

// Due to an retain bug in Metal when the capture layer is installed, capture scopes
// on older OS versions can have too many references on them. If so, release the excess
Expand Down
Loading

0 comments on commit 38a170b

Please sign in to comment.