Plumbs labels for the following Metal objects:
- Buffers - Pipelines - QuerySets - Samplers - Shaders - Textures Change also includes: - Metal debug name utilities Bug: dawn:1784 Change-Id: Iddd2546f842c794570c225577d35c82e56809c6c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130940 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
parent
83ffcdecc2
commit
2552dd3c9f
|
@ -53,6 +53,7 @@ class Buffer final : public BufferBase {
|
||||||
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
|
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
|
||||||
void UnmapImpl() override;
|
void UnmapImpl() override;
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
|
void SetLabelImpl() override;
|
||||||
void* GetMappedPointer() override;
|
void* GetMappedPointer() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "dawn/native/CommandBuffer.h"
|
#include "dawn/native/CommandBuffer.h"
|
||||||
#include "dawn/native/metal/CommandRecordingContext.h"
|
#include "dawn/native/metal/CommandRecordingContext.h"
|
||||||
#include "dawn/native/metal/DeviceMTL.h"
|
#include "dawn/native/metal/DeviceMTL.h"
|
||||||
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ MaybeError Buffer::Initialize(bool mappedAtCreation) {
|
||||||
if (mMtlBuffer == nullptr) {
|
if (mMtlBuffer == nullptr) {
|
||||||
return DAWN_OUT_OF_MEMORY_ERROR("Buffer allocation failed");
|
return DAWN_OUT_OF_MEMORY_ERROR("Buffer allocation failed");
|
||||||
}
|
}
|
||||||
|
SetLabelImpl();
|
||||||
|
|
||||||
// The buffers with mappedAtCreation == true will be initialized in
|
// The buffers with mappedAtCreation == true will be initialized in
|
||||||
// BufferBase::MapAtCreation().
|
// BufferBase::MapAtCreation().
|
||||||
|
@ -235,4 +237,8 @@ void Buffer::ClearBuffer(CommandRecordingContext* commandContext,
|
||||||
value:clearValue];
|
value:clearValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Buffer::SetLabelImpl() {
|
||||||
|
SetDebugName(GetDevice(), mMtlBuffer.Get(), "Dawn_Buffer", GetLabel());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::metal
|
} // namespace dawn::native::metal
|
||||||
|
|
|
@ -47,8 +47,19 @@ MaybeError ComputePipeline::Initialize() {
|
||||||
&computeData));
|
&computeData));
|
||||||
|
|
||||||
NSError* error = nullptr;
|
NSError* error = nullptr;
|
||||||
mMtlComputePipelineState.Acquire(
|
NSRef<NSString> label = MakeDebugName(GetDevice(), "Dawn_ComputePipeline", GetLabel());
|
||||||
[mtlDevice newComputePipelineStateWithFunction:computeData.function.Get() error:&error]);
|
|
||||||
|
NSRef<MTLComputePipelineDescriptor> descriptorRef =
|
||||||
|
AcquireNSRef([MTLComputePipelineDescriptor new]);
|
||||||
|
MTLComputePipelineDescriptor* descriptor = descriptorRef.Get();
|
||||||
|
descriptor.computeFunction = computeData.function.Get();
|
||||||
|
descriptor.label = label.Get();
|
||||||
|
|
||||||
|
mMtlComputePipelineState.Acquire([mtlDevice
|
||||||
|
newComputePipelineStateWithDescriptor:descriptor
|
||||||
|
options:MTLPipelineOptionNone
|
||||||
|
reflection:nil
|
||||||
|
error:&error]);
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
return DAWN_INTERNAL_ERROR("Error creating pipeline state " +
|
return DAWN_INTERNAL_ERROR("Error creating pipeline state " +
|
||||||
std::string([error.localizedDescription UTF8String]));
|
std::string([error.localizedDescription UTF8String]));
|
||||||
|
|
|
@ -17,18 +17,21 @@
|
||||||
#include "dawn/common/Math.h"
|
#include "dawn/common/Math.h"
|
||||||
#include "dawn/common/Platform.h"
|
#include "dawn/common/Platform.h"
|
||||||
#include "dawn/native/metal/DeviceMTL.h"
|
#include "dawn/native/metal/DeviceMTL.h"
|
||||||
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
|
|
||||||
namespace dawn::native::metal {
|
namespace dawn::native::metal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
ResultOrError<id<MTLCounterSampleBuffer>> CreateCounterSampleBuffer(Device* device,
|
ResultOrError<id<MTLCounterSampleBuffer>> CreateCounterSampleBuffer(Device* device,
|
||||||
|
NSString* label,
|
||||||
MTLCommonCounterSet counterSet,
|
MTLCommonCounterSet counterSet,
|
||||||
uint32_t count)
|
uint32_t count)
|
||||||
API_AVAILABLE(macos(10.15), ios(14.0)) {
|
API_AVAILABLE(macos(10.15), ios(14.0)) {
|
||||||
NSRef<MTLCounterSampleBufferDescriptor> descriptorRef =
|
NSRef<MTLCounterSampleBufferDescriptor> descriptorRef =
|
||||||
AcquireNSRef([MTLCounterSampleBufferDescriptor new]);
|
AcquireNSRef([MTLCounterSampleBufferDescriptor new]);
|
||||||
MTLCounterSampleBufferDescriptor* descriptor = descriptorRef.Get();
|
MTLCounterSampleBufferDescriptor* descriptor = descriptorRef.Get();
|
||||||
|
descriptor.label = label;
|
||||||
|
|
||||||
// To determine which counters are available from a device, we need to iterate through
|
// To determine which counters are available from a device, we need to iterate through
|
||||||
// the counterSets property of a MTLDevice. Then configure which counters will be
|
// the counterSets property of a MTLDevice. Then configure which counters will be
|
||||||
|
@ -81,6 +84,8 @@ MaybeError QuerySet::Initialize() {
|
||||||
mVisibilityBuffer = AcquireNSPRef([device->GetMTLDevice()
|
mVisibilityBuffer = AcquireNSPRef([device->GetMTLDevice()
|
||||||
newBufferWithLength:bufferSize
|
newBufferWithLength:bufferSize
|
||||||
options:MTLResourceStorageModePrivate]);
|
options:MTLResourceStorageModePrivate]);
|
||||||
|
SetDebugName(GetDevice(), mVisibilityBuffer.Get(), "Dawn_QuerySet_VisibilityBuffer",
|
||||||
|
GetLabel());
|
||||||
|
|
||||||
if (mVisibilityBuffer == nil) {
|
if (mVisibilityBuffer == nil) {
|
||||||
return DAWN_OUT_OF_MEMORY_ERROR("Failed to allocate query set.");
|
return DAWN_OUT_OF_MEMORY_ERROR("Failed to allocate query set.");
|
||||||
|
@ -89,8 +94,11 @@ MaybeError QuerySet::Initialize() {
|
||||||
}
|
}
|
||||||
case wgpu::QueryType::PipelineStatistics:
|
case wgpu::QueryType::PipelineStatistics:
|
||||||
if (@available(macOS 10.15, iOS 14.0, *)) {
|
if (@available(macOS 10.15, iOS 14.0, *)) {
|
||||||
DAWN_TRY_ASSIGN(mCounterSampleBuffer,
|
NSRef<NSString> label = MakeDebugName(
|
||||||
CreateCounterSampleBuffer(device, MTLCommonCounterSetStatistic,
|
GetDevice(), "Dawn_QuerySet_PipelineStatisticCounterSampleBuffer", GetLabel());
|
||||||
|
DAWN_TRY_ASSIGN(
|
||||||
|
mCounterSampleBuffer,
|
||||||
|
CreateCounterSampleBuffer(device, label.Get(), MTLCommonCounterSetStatistic,
|
||||||
GetQueryCount()));
|
GetQueryCount()));
|
||||||
} else {
|
} else {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -98,8 +106,11 @@ MaybeError QuerySet::Initialize() {
|
||||||
break;
|
break;
|
||||||
case wgpu::QueryType::Timestamp:
|
case wgpu::QueryType::Timestamp:
|
||||||
if (@available(macOS 10.15, iOS 14.0, *)) {
|
if (@available(macOS 10.15, iOS 14.0, *)) {
|
||||||
DAWN_TRY_ASSIGN(mCounterSampleBuffer,
|
NSRef<NSString> label = MakeDebugName(
|
||||||
CreateCounterSampleBuffer(device, MTLCommonCounterSetTimestamp,
|
GetDevice(), "Dawn_QuerySet_TimestampCounterSampleBuffer", GetLabel());
|
||||||
|
DAWN_TRY_ASSIGN(
|
||||||
|
mCounterSampleBuffer,
|
||||||
|
CreateCounterSampleBuffer(device, label.Get(), MTLCommonCounterSetTimestamp,
|
||||||
GetQueryCount()));
|
GetQueryCount()));
|
||||||
} else {
|
} else {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
|
|
@ -341,6 +341,9 @@ MaybeError RenderPipeline::Initialize() {
|
||||||
AcquireNSRef([MTLRenderPipelineDescriptor new]);
|
AcquireNSRef([MTLRenderPipelineDescriptor new]);
|
||||||
MTLRenderPipelineDescriptor* descriptorMTL = descriptorMTLRef.Get();
|
MTLRenderPipelineDescriptor* descriptorMTL = descriptorMTLRef.Get();
|
||||||
|
|
||||||
|
NSRef<NSString> label = MakeDebugName(GetDevice(), "Dawn_RenderPipeline", GetLabel());
|
||||||
|
descriptorMTL.label = label.Get();
|
||||||
|
|
||||||
NSRef<MTLVertexDescriptor> vertexDesc;
|
NSRef<MTLVertexDescriptor> vertexDesc;
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling)) {
|
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling)) {
|
||||||
vertexDesc = AcquireNSRef([MTLVertexDescriptor new]);
|
vertexDesc = AcquireNSRef([MTLVertexDescriptor new]);
|
||||||
|
|
|
@ -72,6 +72,9 @@ MaybeError Sampler::Initialize(const SamplerDescriptor* descriptor) {
|
||||||
NSRef<MTLSamplerDescriptor> mtlDescRef = AcquireNSRef([MTLSamplerDescriptor new]);
|
NSRef<MTLSamplerDescriptor> mtlDescRef = AcquireNSRef([MTLSamplerDescriptor new]);
|
||||||
MTLSamplerDescriptor* mtlDesc = mtlDescRef.Get();
|
MTLSamplerDescriptor* mtlDesc = mtlDescRef.Get();
|
||||||
|
|
||||||
|
NSRef<NSString> label = MakeDebugName(GetDevice(), "Dawn_Sampler", GetLabel());
|
||||||
|
mtlDesc.label = label.Get();
|
||||||
|
|
||||||
mtlDesc.minFilter = FilterModeToMinMagFilter(descriptor->minFilter);
|
mtlDesc.minFilter = FilterModeToMinMagFilter(descriptor->minFilter);
|
||||||
mtlDesc.magFilter = FilterModeToMinMagFilter(descriptor->magFilter);
|
mtlDesc.magFilter = FilterModeToMinMagFilter(descriptor->magFilter);
|
||||||
mtlDesc.mipFilter = FilterModeToMipFilter(descriptor->mipmapFilter);
|
mtlDesc.mipFilter = FilterModeToMipFilter(descriptor->mipmapFilter);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "dawn/native/metal/DeviceMTL.h"
|
#include "dawn/native/metal/DeviceMTL.h"
|
||||||
#include "dawn/native/metal/PipelineLayoutMTL.h"
|
#include "dawn/native/metal/PipelineLayoutMTL.h"
|
||||||
#include "dawn/native/metal/RenderPipelineMTL.h"
|
#include "dawn/native/metal/RenderPipelineMTL.h"
|
||||||
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
#include "dawn/native/stream/BlobSource.h"
|
#include "dawn/native/stream/BlobSource.h"
|
||||||
#include "dawn/native/stream/ByteVectorSink.h"
|
#include "dawn/native/stream/ByteVectorSink.h"
|
||||||
#include "dawn/platform/DawnPlatform.h"
|
#include "dawn/platform/DawnPlatform.h"
|
||||||
|
@ -376,6 +377,9 @@ MaybeError ShaderModule::CreateFunction(SingleShaderStage stage,
|
||||||
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()]);
|
out->function = AcquireNSPRef([*library newFunctionWithName:name.Get()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostringstream labelStream;
|
||||||
|
labelStream << GetLabel() << "::" << entryPointName;
|
||||||
|
SetDebugName(GetDevice(), out->function.Get(), "Dawn_ShaderModule", labelStream.str());
|
||||||
GetDevice()->GetBlobCache()->EnsureStored(mslCompilation);
|
GetDevice()->GetBlobCache()->EnsureStored(mslCompilation);
|
||||||
|
|
||||||
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
|
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
|
||||||
|
|
|
@ -78,6 +78,7 @@ class Texture final : public TextureBase {
|
||||||
void InitializeAsWrapping(const TextureDescriptor* descriptor, NSPRef<id<MTLTexture>> wrapped);
|
void InitializeAsWrapping(const TextureDescriptor* descriptor, NSPRef<id<MTLTexture>> wrapped);
|
||||||
|
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
|
void SetLabelImpl() override;
|
||||||
|
|
||||||
MaybeError ClearTexture(CommandRecordingContext* commandContext,
|
MaybeError ClearTexture(CommandRecordingContext* commandContext,
|
||||||
const SubresourceRange& range,
|
const SubresourceRange& range,
|
||||||
|
@ -108,6 +109,7 @@ class TextureView final : public TextureViewBase {
|
||||||
using TextureViewBase::TextureViewBase;
|
using TextureViewBase::TextureViewBase;
|
||||||
MaybeError Initialize(const TextureViewDescriptor* descriptor);
|
MaybeError Initialize(const TextureViewDescriptor* descriptor);
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
|
void SetLabelImpl() override;
|
||||||
|
|
||||||
NSPRef<id<MTLTexture>> mMtlTextureView;
|
NSPRef<id<MTLTexture>> mMtlTextureView;
|
||||||
};
|
};
|
||||||
|
|
|
@ -760,6 +760,7 @@ MaybeError Texture::InitializeAsInternalTexture(const TextureDescriptor* descrip
|
||||||
if (mMtlTexture == nil) {
|
if (mMtlTexture == nil) {
|
||||||
return DAWN_OUT_OF_MEMORY_ERROR("Failed to allocate texture.");
|
return DAWN_OUT_OF_MEMORY_ERROR("Failed to allocate texture.");
|
||||||
}
|
}
|
||||||
|
SetLabelImpl();
|
||||||
|
|
||||||
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
|
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
|
||||||
DAWN_TRY(ClearTexture(device->GetPendingCommandContext(), GetAllSubresources(),
|
DAWN_TRY(ClearTexture(device->GetPendingCommandContext(), GetAllSubresources(),
|
||||||
|
@ -777,6 +778,7 @@ void Texture::InitializeAsWrapping(const TextureDescriptor* descriptor,
|
||||||
NSRef<MTLTextureDescriptor> mtlDesc = CreateMetalTextureDescriptor();
|
NSRef<MTLTextureDescriptor> mtlDesc = CreateMetalTextureDescriptor();
|
||||||
mMtlUsage = [*mtlDesc usage];
|
mMtlUsage = [*mtlDesc usage];
|
||||||
mMtlTexture = std::move(wrapped);
|
mMtlTexture = std::move(wrapped);
|
||||||
|
SetLabelImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Texture::InitializeFromIOSurface(const ExternalImageDescriptor* descriptor,
|
MaybeError Texture::InitializeFromIOSurface(const ExternalImageDescriptor* descriptor,
|
||||||
|
@ -807,6 +809,7 @@ MaybeError Texture::InitializeFromIOSurface(const ExternalImageDescriptor* descr
|
||||||
mMtlTexture = AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc.Get()
|
mMtlTexture = AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc.Get()
|
||||||
iosurface:ioSurface
|
iosurface:ioSurface
|
||||||
plane:0]);
|
plane:0]);
|
||||||
|
SetLabelImpl();
|
||||||
}
|
}
|
||||||
SetIsSubresourceContentInitialized(descriptor->isInitialized, GetAllSubresources());
|
SetIsSubresourceContentInitialized(descriptor->isInitialized, GetAllSubresources());
|
||||||
return {};
|
return {};
|
||||||
|
@ -848,6 +851,10 @@ void Texture::DestroyImpl() {
|
||||||
mIOSurface = nullptr;
|
mIOSurface = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::SetLabelImpl() {
|
||||||
|
SetDebugName(GetDevice(), mMtlTexture.Get(), "Dawn_Texture", GetLabel());
|
||||||
|
}
|
||||||
|
|
||||||
id<MTLTexture> Texture::GetMTLTexture() const {
|
id<MTLTexture> Texture::GetMTLTexture() const {
|
||||||
return mMtlTexture.Get();
|
return mMtlTexture.Get();
|
||||||
}
|
}
|
||||||
|
@ -1187,6 +1194,7 @@ MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetLabelImpl();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1194,6 +1202,10 @@ void TextureView::DestroyImpl() {
|
||||||
mMtlTextureView = nil;
|
mMtlTextureView = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureView::SetLabelImpl() {
|
||||||
|
SetDebugName(GetDevice(), mMtlTextureView.Get(), "Dawn_TextureView", GetLabel());
|
||||||
|
}
|
||||||
|
|
||||||
id<MTLTexture> TextureView::GetMTLTexture() const {
|
id<MTLTexture> TextureView::GetMTLTexture() const {
|
||||||
ASSERT(mMtlTextureView != nullptr);
|
ASSERT(mMtlTextureView != nullptr);
|
||||||
return mMtlTextureView.Get();
|
return mMtlTextureView.Get();
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
#ifndef SRC_DAWN_NATIVE_METAL_UTILSMETAL_H_
|
#ifndef SRC_DAWN_NATIVE_METAL_UTILSMETAL_H_
|
||||||
#define SRC_DAWN_NATIVE_METAL_UTILSMETAL_H_
|
#define SRC_DAWN_NATIVE_METAL_UTILSMETAL_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "dawn/common/NSRef.h"
|
||||||
#include "dawn/common/StackContainer.h"
|
#include "dawn/common/StackContainer.h"
|
||||||
#include "dawn/native/dawn_platform.h"
|
#include "dawn/native/dawn_platform.h"
|
||||||
#include "dawn/native/metal/DeviceMTL.h"
|
#include "dawn/native/metal/DeviceMTL.h"
|
||||||
|
@ -32,6 +35,21 @@ enum class SingleShaderStage;
|
||||||
|
|
||||||
namespace dawn::native::metal {
|
namespace dawn::native::metal {
|
||||||
|
|
||||||
|
NSRef<NSString> MakeDebugName(DeviceBase* device, const char* prefix, std::string label = "");
|
||||||
|
|
||||||
|
// Templating for setting the label on MTL objects because not all MTL objects are of the same base
|
||||||
|
// class. For example MTLBuffer and MTLTexture inherit MTLResource, but MTLFunction does not. Note
|
||||||
|
// that we allow a nullable Metal object because APISetLabel does not currently do any checks on
|
||||||
|
// backend resources.
|
||||||
|
template <typename T>
|
||||||
|
void SetDebugName(DeviceBase* device, T* mtlObj, const char* prefix, std::string label = "") {
|
||||||
|
if (mtlObj == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSRef<NSString> debugName = MakeDebugName(device, prefix, label);
|
||||||
|
[mtlObj setLabel:debugName.Get()];
|
||||||
|
}
|
||||||
|
|
||||||
Aspect GetDepthStencilAspects(MTLPixelFormat format);
|
Aspect GetDepthStencilAspects(MTLPixelFormat format);
|
||||||
MTLCompareFunction ToMetalCompareFunction(wgpu::CompareFunction compareFunction);
|
MTLCompareFunction ToMetalCompareFunction(wgpu::CompareFunction compareFunction);
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,19 @@ void ResolveInAnotherRenderPass(
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
NSRef<NSString> MakeDebugName(DeviceBase* device, const char* prefix, std::string label) {
|
||||||
|
std::ostringstream objectNameStream;
|
||||||
|
objectNameStream << prefix;
|
||||||
|
|
||||||
|
if (!label.empty() && device->IsToggleEnabled(Toggle::UseUserDefinedLabelsInBackend)) {
|
||||||
|
objectNameStream << "_" << label;
|
||||||
|
}
|
||||||
|
const std::string debugName = objectNameStream.str();
|
||||||
|
NSRef<NSString> nsDebugName =
|
||||||
|
AcquireNSRef([[NSString alloc] initWithUTF8String:debugName.c_str()]);
|
||||||
|
return nsDebugName;
|
||||||
|
}
|
||||||
|
|
||||||
Aspect GetDepthStencilAspects(MTLPixelFormat format) {
|
Aspect GetDepthStencilAspects(MTLPixelFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case MTLPixelFormatDepth16Unorm:
|
case MTLPixelFormatDepth16Unorm:
|
||||||
|
|
Loading…
Reference in New Issue