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];