fix ios crash (#2966)

This commit is contained in:
coulsonwang
2020-10-31 17:47:03 +08:00
committed by GitHub
parent 19c68d840c
commit 33eb0bf47d
4 changed files with 7 additions and 27 deletions
@@ -23,7 +23,7 @@ CCMTLCommandBuffer::CCMTLCommandBuffer(Device *device)
_mtlCommandQueue(id<MTLCommandQueue>(((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<MTLCommandBuffer> 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;
}
+2 -3
View File
@@ -55,9 +55,9 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) {
_mtkView = (MTKView *)_windowHandle;
_mtlDevice = ((MTKView *)_mtkView).device;
_mtlCommandQueue = [id<MTLDevice>(_mtlDevice) newCommandQueue];
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
static_cast<MTKView*>(_mtkView).depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
static_cast<MTKView *>(_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) {
@@ -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);
+1 -19
View File
@@ -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
}