mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
fix metal blit buffer (#2918)
This commit is contained in:
@@ -57,7 +57,6 @@ private:
|
||||
uint _maxColorRenderTargets = 0;
|
||||
uint _maxBufferBindingIndex = 0;
|
||||
bool _icbSuppored = false;
|
||||
void *_blitedBuffer = nullptr;
|
||||
CCMTLGPUStagingBufferPool *_gpuStagingBufferPool = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user