fix metal blit buffer (#2918)

This commit is contained in:
coulsonwang
2020-10-19 10:00:40 +08:00
committed by GitHub
parent 0f0cac425f
commit fb8cebbbfd
2 changed files with 7 additions and 12 deletions
@@ -57,7 +57,6 @@ private:
uint _maxColorRenderTargets = 0;
uint _maxBufferBindingIndex = 0;
bool _icbSuppored = false;
void *_blitedBuffer = nullptr;
CCMTLGPUStagingBufferPool *_gpuStagingBufferPool = nullptr;
};
+7 -11
View File
@@ -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<MTLBuffer> sourceBuffer = id<MTLBuffer>(_blitedBuffer);
if (sourceBuffer == nil || sourceBuffer.allocatedSize < size) {
if (sourceBuffer)
[sourceBuffer release];
sourceBuffer = [id<MTLDevice>(_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<MTLCommandBuffer> commandBuffer = [id<MTLCommandQueue>(_mtlCommandQueue) commandBuffer];
// Encode a blit pass to copy data from the source buffer to the private buffer.
id<MTLBlitCommandEncoder> blitCommandEncoder = [commandBuffer blitCommandEncoder];
[blitCommandEncoder copyFromBuffer:sourceBuffer
sourceOffset:0
[blitCommandEncoder copyFromBuffer:stagingBuffer.mtlBuffer
sourceOffset:stagingBuffer.startOffset
toBuffer:id<MTLBuffer>(dstBuffer)
destinationOffset:offset
size:size];