From fb8cebbbfdc70ff9f948c7e4d531efed6d46c5c8 Mon Sep 17 00:00:00 2001 From: coulsonwang Date: Mon, 19 Oct 2020 10:00:40 +0800 Subject: [PATCH] fix metal blit buffer (#2918) --- native/cocos/renderer/gfx-metal/MTLDevice.h | 1 - native/cocos/renderer/gfx-metal/MTLDevice.mm | 18 +++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.h b/native/cocos/renderer/gfx-metal/MTLDevice.h index 7007d1e945..cfcb23d4d7 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.h +++ b/native/cocos/renderer/gfx-metal/MTLDevice.h @@ -57,7 +57,6 @@ private: uint _maxColorRenderTargets = 0; uint _maxBufferBindingIndex = 0; bool _icbSuppored = false; - void *_blitedBuffer = nullptr; CCMTLGPUStagingBufferPool *_gpuStagingBufferPool = nullptr; }; diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index dc7f9f1f0a..7fe3ef1f70 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -326,22 +326,18 @@ void CCMTLDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *t } void CCMTLDevice::blitBuffer(void *srcData, uint offset, uint size, void *dstBuffer) { - id sourceBuffer = id(_blitedBuffer); - if (sourceBuffer == nil || sourceBuffer.allocatedSize < size) { - if (sourceBuffer) - [sourceBuffer release]; - sourceBuffer = [id(_mtlDevice) newBufferWithBytes:srcData - length:size - options:MTLResourceStorageModeShared]; - } - + CCMTLGPUBuffer stagingBuffer; + stagingBuffer.size = size; + _gpuStagingBufferPool->alloc(&stagingBuffer); + memcpy(stagingBuffer.mappedData, srcData, size); + // Create a command buffer for GPU work. id commandBuffer = [id(_mtlCommandQueue) commandBuffer]; // Encode a blit pass to copy data from the source buffer to the private buffer. id blitCommandEncoder = [commandBuffer blitCommandEncoder]; - [blitCommandEncoder copyFromBuffer:sourceBuffer - sourceOffset:0 + [blitCommandEncoder copyFromBuffer:stagingBuffer.mtlBuffer + sourceOffset:stagingBuffer.startOffset toBuffer:id(dstBuffer) destinationOffset:offset size:size];