From 33eb0bf47da3218e85db4fd648cf5ca873bd2f07 Mon Sep 17 00:00:00 2001 From: coulsonwang Date: Sat, 31 Oct 2020 17:47:03 +0800 Subject: [PATCH] fix ios crash (#2966) --- .../renderer/gfx-metal/MTLCommandBuffer.mm | 5 +++-- native/cocos/renderer/gfx-metal/MTLDevice.mm | 5 ++--- native/cocos/renderer/gfx-metal/MTLSampler.mm | 4 +--- native/cocos/renderer/gfx-metal/MTLUtils.mm | 20 +------------------ 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index 279116eef5..afc67364fc 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -23,7 +23,7 @@ CCMTLCommandBuffer::CCMTLCommandBuffer(Device *device) _mtlCommandQueue(id(((CCMTLDevice *)device)->getMTLCommandQueue())), _mtkView((MTKView *)(((CCMTLDevice *)device)->getMTKView())), _frameBoundarySemaphore(dispatch_semaphore_create(MAX_INFLIGHT_BUFFER)) { - uint setCount = device->bindingMappingInfo().bufferOffsets.size(); + const auto setCount = device->bindingMappingInfo().bufferOffsets.size(); _GPUDescriptorSets.resize(setCount); _dynamicOffsets.resize(setCount); } @@ -65,13 +65,14 @@ void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer void CCMTLCommandBuffer::end() { if (!_commandBufferBegan) return; + [_mtlCommandBuffer presentDrawable:_mtkView.currentDrawable]; [_mtlCommandBuffer addCompletedHandler:^(id commandBuffer) { // GPU work is complete // Signal the semaphore to start the CPU work dispatch_semaphore_signal(_frameBoundarySemaphore); + [commandBuffer release]; }]; [_mtlCommandBuffer commit]; - [_mtlCommandBuffer release]; _commandBufferBegan = false; } diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index fac0588a4a..71458278da 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -55,9 +55,9 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) { _mtkView = (MTKView *)_windowHandle; _mtlDevice = ((MTKView *)_mtkView).device; _mtlCommandQueue = [id(_mtlDevice) newCommandQueue]; - + #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) - static_cast(_mtkView).depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8; + static_cast(_mtkView).depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8; _depthBits = 32; _features[(int)Feature::FORMAT_D32FS8] = true; #else @@ -175,7 +175,6 @@ void CCMTLDevice::present() { _numInstances = queue->_numInstances; _numTriangles = queue->_numTriangles; _gpuStagingBufferPool->reset(); - [((MTKView *)(_mtkView)).currentDrawable present]; } Fence *CCMTLDevice::createFence(const FenceInfo &info) { diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.mm b/native/cocos/renderer/gfx-metal/MTLSampler.mm index c18822952f..cc0b04b081 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.mm +++ b/native/cocos/renderer/gfx-metal/MTLSampler.mm @@ -27,9 +27,7 @@ bool CCMTLSampler::initialize(const SamplerInfo &info) { _mipLODBias = info.mipLODBias; MTLSamplerDescriptor *descriptor = [[MTLSamplerDescriptor alloc] init]; -#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) - if (@available(iOS 14.0, *)) descriptor.borderColor = (MTLSamplerBorderColor)mu::toMTLSamplerBorderColor(_borderColor); -#else +#if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) descriptor.borderColor = (MTLSamplerBorderColor)mu::toMTLSamplerBorderColor(_borderColor); #endif descriptor.sAddressMode = mu::toMTLSamplerAddressMode(_addressU); diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index 43c854edf3..5417820e4f 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -486,13 +486,7 @@ MTLSamplerAddressMode toMTLSamplerAddressMode(Address mode) { case Address::MIRROR: return MTLSamplerAddressModeMirrorRepeat; case Address::CLAMP: return MTLSamplerAddressModeClampToEdge; case Address::BORDER: { -#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) - if (@available(iOS 14.0, *)) - return MTLSamplerAddressModeClampToBorderColor; - else - break; - ; -#else +#if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) return MTLSamplerAddressModeClampToBorderColor; #endif } @@ -511,18 +505,6 @@ int toMTLSamplerBorderColor(const Color &color) { return MTLSamplerBorderColorOpaqueBlack; else return MTLSamplerBorderColorOpaqueWhite; -#else - if (@available(iOS 14.0, *)) { - float diff = color.x - 0.5f; - if (math::IsEqualF(color.w, 0.f)) - return MTLSamplerBorderColorTransparentBlack; - else if (math::IsEqualF(diff, 0.f)) - return MTLSamplerBorderColorOpaqueBlack; - else - return MTLSamplerBorderColorOpaqueWhite; - } else { - return 0; - } #endif }