Metal: avoid uses of autorelease

BUG=chromium:947089

Change-Id: I1e7ef4a91a8b1c6108485b8c99e88a53a25ebb7b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6160
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2019-03-28 18:16:04 +00:00 committed by Commit Bot service account
parent 0ae00a187d
commit 19179e180b
2 changed files with 21 additions and 13 deletions

View File

@ -238,17 +238,17 @@ namespace dawn_native { namespace metal {
} }
} }
MTLDepthStencilDescriptor* ComputeDepthStencilDesc( MTLDepthStencilDescriptor* MakeDepthStencilDesc(
const DepthStencilStateDescriptor* descriptor) { const DepthStencilStateDescriptor* descriptor) {
MTLDepthStencilDescriptor* mtlDepthStencilDescriptor = MTLDepthStencilDescriptor* mtlDepthStencilDescriptor = [MTLDepthStencilDescriptor new];
[[MTLDepthStencilDescriptor new] autorelease];
mtlDepthStencilDescriptor.depthCompareFunction = mtlDepthStencilDescriptor.depthCompareFunction =
ToMetalCompareFunction(descriptor->depthCompare); ToMetalCompareFunction(descriptor->depthCompare);
mtlDepthStencilDescriptor.depthWriteEnabled = descriptor->depthWriteEnabled; mtlDepthStencilDescriptor.depthWriteEnabled = descriptor->depthWriteEnabled;
if (StencilTestEnabled(descriptor)) { if (StencilTestEnabled(descriptor)) {
MTLStencilDescriptor* backFaceStencil = [[MTLStencilDescriptor new] autorelease]; MTLStencilDescriptor* backFaceStencil = [MTLStencilDescriptor new];
MTLStencilDescriptor* frontFaceStencil = [[MTLStencilDescriptor new] autorelease]; MTLStencilDescriptor* frontFaceStencil = [MTLStencilDescriptor new];
backFaceStencil.stencilCompareFunction = backFaceStencil.stencilCompareFunction =
ToMetalCompareFunction(descriptor->stencilBack.compare); ToMetalCompareFunction(descriptor->stencilBack.compare);
@ -274,7 +274,11 @@ namespace dawn_native { namespace metal {
mtlDepthStencilDescriptor.backFaceStencil = backFaceStencil; mtlDepthStencilDescriptor.backFaceStencil = backFaceStencil;
mtlDepthStencilDescriptor.frontFaceStencil = frontFaceStencil; mtlDepthStencilDescriptor.frontFaceStencil = frontFaceStencil;
[backFaceStencil release];
[frontFaceStencil release];
} }
return mtlDepthStencilDescriptor; return mtlDepthStencilDescriptor;
} }
@ -316,7 +320,9 @@ namespace dawn_native { namespace metal {
descriptorMTL.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology()); descriptorMTL.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology());
descriptorMTL.vertexDescriptor = MakeVertexDesc(); MTLVertexDescriptor* vertexDesc = MakeVertexDesc();
descriptorMTL.vertexDescriptor = vertexDesc;
[vertexDesc release];
// TODO(kainino@chromium.org): push constants, textures, samplers // TODO(kainino@chromium.org): push constants, textures, samplers
@ -324,7 +330,6 @@ namespace dawn_native { namespace metal {
NSError* error = nil; NSError* error = nil;
mMtlRenderPipelineState = [mtlDevice newRenderPipelineStateWithDescriptor:descriptorMTL mMtlRenderPipelineState = [mtlDevice newRenderPipelineStateWithDescriptor:descriptorMTL
error:&error]; error:&error];
[descriptorMTL.vertexDescriptor release];
[descriptorMTL release]; [descriptorMTL release];
if (error != nil) { if (error != nil) {
NSLog(@" error => %@", error); NSLog(@" error => %@", error);
@ -333,12 +338,13 @@ namespace dawn_native { namespace metal {
} }
} }
// create depth stencil state and cache it, fetch the cached depth stencil state when we // Create depth stencil state and cache it, fetch the cached depth stencil state when we
// call setDepthStencilState() for a given render pipeline in CommandBuffer, in order to // call setDepthStencilState() for a given render pipeline in CommandEncoder, in order to
// improve performance. // improve performance.
mMtlDepthStencilState = MTLDepthStencilDescriptor* depthStencilDesc =
[mtlDevice newDepthStencilStateWithDescriptor:ComputeDepthStencilDesc( MakeDepthStencilDesc(GetDepthStencilStateDescriptor());
GetDepthStencilStateDescriptor())]; mMtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:depthStencilDesc];
[depthStencilDesc release];
} }
RenderPipeline::~RenderPipeline() { RenderPipeline::~RenderPipeline() {

View File

@ -66,7 +66,7 @@ namespace dawn_native { namespace metal {
Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor) Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) { : SamplerBase(device, descriptor) {
MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new]; MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new];
[mtlDesc autorelease];
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);
@ -81,6 +81,8 @@ namespace dawn_native { namespace metal {
mtlDesc.borderColor = BorderColor(descriptor->borderColor); mtlDesc.borderColor = BorderColor(descriptor->borderColor);
mMtlSamplerState = [device->GetMTLDevice() newSamplerStateWithDescriptor:mtlDesc]; mMtlSamplerState = [device->GetMTLDevice() newSamplerStateWithDescriptor:mtlDesc];
[mtlDesc release];
} }
Sampler::~Sampler() { Sampler::~Sampler() {