Metal: replace last temp transfer buffer with staging slice
Change-Id: Ifc2ca70d0d6c8e325a0edccdd1f1d02b6110131f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423136 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
0734c6223c
commit
cc6ddcd142
@ -487,22 +487,25 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
|
||||
}
|
||||
SkASSERT(combinedBufferSize > 0 && !individualMipOffsets.empty());
|
||||
|
||||
// TODO: Create GrMtlTransferBuffer
|
||||
NSUInteger options = 0;
|
||||
if (@available(macOS 10.11, iOS 9.0, *)) {
|
||||
options |= MTLResourceStorageModePrivate;
|
||||
}
|
||||
id<MTLBuffer> transferBuffer = [fDevice newBufferWithLength: combinedBufferSize
|
||||
options: options];
|
||||
if (nil == transferBuffer) {
|
||||
return false;
|
||||
#ifdef SK_BUILD_FOR_MAC
|
||||
static const size_t kMinAlignment = 4;
|
||||
#else
|
||||
static const size_t kMinAlignment = 1;
|
||||
#endif
|
||||
size_t alignment = std::max(bpp, kMinAlignment);
|
||||
GrStagingBufferManager::Slice slice = fStagingBufferManager.allocateStagingBufferSlice(
|
||||
combinedBufferSize, alignment);
|
||||
if (!slice.fBuffer) {
|
||||
return nullptr;
|
||||
}
|
||||
GrMtlBuffer* mtlBuffer = static_cast<GrMtlBuffer*>(slice.fBuffer);
|
||||
id<MTLBuffer> transferBuffer = mtlBuffer->mtlBuffer();
|
||||
|
||||
auto cmdBuffer = this->commandBuffer();
|
||||
id<MTLBlitCommandEncoder> GR_NORETAIN blitCmdEncoder = cmdBuffer->getBlitCommandEncoder();
|
||||
// clear the buffer to transparent black
|
||||
NSRange clearRange;
|
||||
clearRange.location = 0;
|
||||
clearRange.location = slice.fOffset;
|
||||
clearRange.length = combinedBufferSize;
|
||||
[blitCmdEncoder fillBuffer: transferBuffer
|
||||
range: clearRange
|
||||
@ -517,7 +520,7 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
|
||||
const size_t rowBytes = currentWidth * bpp;
|
||||
|
||||
[blitCmdEncoder copyFromBuffer: transferBuffer
|
||||
sourceOffset: individualMipOffsets[currentMipLevel]
|
||||
sourceOffset: slice.fOffset + individualMipOffsets[currentMipLevel]
|
||||
sourceBytesPerRow: rowBytes
|
||||
sourceBytesPerImage: rowBytes * currentHeight
|
||||
sourceSize: MTLSizeMake(currentWidth, currentHeight, 1)
|
||||
@ -529,6 +532,7 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
|
||||
currentWidth = std::max(1, currentWidth/2);
|
||||
currentHeight = std::max(1, currentHeight/2);
|
||||
}
|
||||
// Don't need didModifyRange: here because fillBuffer: happens on the GPU
|
||||
|
||||
if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) {
|
||||
tex->markMipmapsDirty();
|
||||
|
Loading…
Reference in New Issue
Block a user