Don't take initial buffer data in GrGpu::createBuffer.

Bug: skia: 12720
Change-Id: I1d025689e4c977fe487989f8c7a3200b3c9c9e1a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544245
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2022-05-26 14:44:17 -04:00 committed by SkCQ
parent 0b1384de5a
commit 790e8cc4e3
17 changed files with 80 additions and 67 deletions

View File

@ -387,11 +387,12 @@ sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImage
return nullptr;
}
sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern) {
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
this->handleDirtyContext();
sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data);
sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern);
if (!this->caps()->reuseScratchBuffers()) {
buffer->resourcePriv().removeScratchKey();
}

View File

@ -201,12 +201,12 @@ public:
* @param size size of buffer to create.
* @param intendedType hint to the graphics subsystem about what the buffer will be used for.
* @param accessPattern hint to the graphics subsystem about how the data will be accessed.
* @param data optional data with which to initialize the buffer.
*
* @return the buffer if successful, otherwise nullptr.
*/
sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data = nullptr);
sk_sp<GrGpuBuffer> createBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern);
/**
* Resolves MSAA. The resolveRect must already be in the native destination space.
@ -727,8 +727,9 @@ private:
virtual sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&);
virtual sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType,
GrAccessPattern, const void* data) = 0;
virtual sk_sp<GrGpuBuffer> onCreateBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern) = 0;
// overridden by backend-specific derived class to perform the surface read
virtual bool onReadPixels(GrSurface*,

View File

@ -571,14 +571,19 @@ int GrResourceProvider::NumVertsPerAAQuad() { return kVertsPerAAQuad; }
int GrResourceProvider::NumIndicesPerAAQuad() { return kIndicesPerAAQuad; }
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size, GrGpuBufferType intendedType,
sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern,
const void* data) {
if (this->isAbandoned()) {
return nullptr;
}
if (kDynamic_GrAccessPattern != accessPattern) {
return this->gpu()->createBuffer(size, intendedType, accessPattern, data);
auto buffer = this->gpu()->createBuffer(size, intendedType, accessPattern);
if (buffer && data) {
buffer->updateData(data, size);
}
return buffer;
}
// bin by pow2+midpoint with a reasonable min
static const size_t MIN_SIZE = 1 << 12;

View File

@ -1263,14 +1263,10 @@ bool GrD3DGpu::onRegenerateMipMapLevels(GrTexture * tex) {
return true;
}
sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrD3DBuffer> buffer = GrD3DBuffer::Make(this, sizeInBytes, type, accessPattern);
if (data && buffer) {
buffer->updateData(data, sizeInBytes);
}
return std::move(buffer);
sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes,
GrGpuBufferType type,
GrAccessPattern accessPattern) {
return GrD3DBuffer::Make(this, sizeInBytes, type, accessPattern);
}
sk_sp<GrAttachment> GrD3DGpu::makeStencilAttachment(const GrBackendFormat& /*colorFormat*/,

View File

@ -163,8 +163,9 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
const void*) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes,
GrGpuBufferType,
GrAccessPattern) override;
bool onReadPixels(GrSurface*,
SkIRect,

View File

@ -178,13 +178,10 @@ GrOpsRenderPass* GrDawnGpu::onGetOpsRenderPass(
}
///////////////////////////////////////////////////////////////////////////////
sk_sp<GrGpuBuffer> GrDawnGpu::onCreateBuffer(size_t size, GrGpuBufferType type,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrDawnBuffer> buffer = GrDawnBuffer::Make(this, size, type, accessPattern, /*label=*/{});
if (data && buffer) {
buffer->updateData(data, size);
}
return std::move(buffer);
sk_sp<GrGpuBuffer> GrDawnGpu::onCreateBuffer(size_t size,
GrGpuBufferType type,
GrAccessPattern accessPattern) {
return GrDawnBuffer::Make(this, size, type, accessPattern, /*label=*/{});
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -161,8 +161,7 @@ private:
const void* data,
size_t size) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
const void* data) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern) override;
bool onReadPixels(GrSurface*,
SkIRect,

View File

@ -34,16 +34,17 @@
#define VALIDATE() do {} while(false)
#endif
sk_sp<GrGLBuffer> GrGLBuffer::Make(GrGLGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrGLBuffer> GrGLBuffer::Make(GrGLGpu* gpu,
size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern) {
if (gpu->glCaps().transferBufferType() == GrGLCaps::TransferBufferType::kNone &&
(GrGpuBufferType::kXferCpuToGpu == intendedType ||
GrGpuBufferType::kXferGpuToCpu == intendedType)) {
return nullptr;
}
sk_sp<GrGLBuffer> buffer(
new GrGLBuffer(gpu, size, intendedType, accessPattern, data, /*label=*/{}));
sk_sp<GrGLBuffer> buffer(new GrGLBuffer(gpu, size, intendedType, accessPattern, /*label=*/{}));
if (0 == buffer->bufferID()) {
return nullptr;
}
@ -108,7 +109,6 @@ GrGLBuffer::GrGLBuffer(GrGLGpu* gpu,
size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern,
const void* data,
std::string_view label)
: INHERITED(gpu, size, intendedType, accessPattern, label)
, fIntendedType(intendedType)
@ -117,9 +117,11 @@ GrGLBuffer::GrGLBuffer(GrGLGpu* gpu,
, fGLSizeInBytes(0)
, fHasAttachedToTexture(false) {
GL_CALL(GenBuffers(1, &fBufferID));
if (fBufferID) {
// We only need allocate the buffer if this may be the destination of a transfer. Other use
// cases will always get an updateData() or map() call before use.
if (fBufferID && fIntendedType == GrGpuBufferType::kXferGpuToCpu) {
GrGLenum target = gpu->bindBuffer(fIntendedType, this);
GrGLenum error = GL_ALLOC_CALL(BufferData(target, (GrGLsizeiptr)size, data, fUsage));
GrGLenum error = GL_ALLOC_CALL(BufferData(target, (GrGLsizeiptr)size, nullptr, fUsage));
if (error != GR_GL_NO_ERROR) {
GL_CALL(DeleteBuffers(1, &fBufferID));
fBufferID = 0;

View File

@ -16,8 +16,10 @@ class GrGLCaps;
class GrGLBuffer : public GrGpuBuffer {
public:
static sk_sp<GrGLBuffer> Make(GrGLGpu*, size_t size, GrGpuBufferType intendedType,
GrAccessPattern, const void* data = nullptr);
static sk_sp<GrGLBuffer> Make(GrGLGpu*,
size_t size,
GrGpuBufferType intendedType,
GrAccessPattern);
~GrGLBuffer() override {
// either release or abandon should have been called by the owner of this object.
@ -40,7 +42,6 @@ protected:
size_t size,
GrGpuBufferType intendedType,
GrAccessPattern,
const void* data,
std::string_view label);
void onAbandon() override;

View File

@ -926,6 +926,8 @@ bool GrGLGpu::onTransferPixelsTo(GrTexture* texture,
const size_t trimRowBytes = rect.width() * bpp;
const void* pixels = (void*)offset;
SkASSERT(glBuffer->glSizeInBytes() >= offset + rowBytes*(rect.height() - 1) + trimRowBytes);
bool restoreGLRowLength = false;
if (trimRowBytes != rowBytes) {
// we should have checked for this support already
@ -969,7 +971,12 @@ bool GrGLGpu::onTransferPixelsFrom(GrSurface* surface,
sk_sp<GrGpuBuffer> transferBuffer,
size_t offset) {
auto* glBuffer = static_cast<GrGLBuffer*>(transferBuffer.get());
SkASSERT(glBuffer->glSizeInBytes() >= offset + (rect.width() *
rect.height()*
GrColorTypeBytesPerPixel(dstColorType)));
this->bindBuffer(GrGpuBufferType::kXferGpuToCpu, glBuffer);
auto offsetAsPtr = reinterpret_cast<void*>(offset);
return this->readOrTransferPixelsFrom(surface,
rect,
@ -1834,9 +1841,10 @@ sk_sp<GrAttachment> GrGLGpu::makeMSAAAttachment(SkISize dimensions, const GrBack
////////////////////////////////////////////////////////////////////////////////
sk_sp<GrGpuBuffer> GrGLGpu::onCreateBuffer(size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data) {
return GrGLBuffer::Make(this, size, intendedType, accessPattern, data);
sk_sp<GrGpuBuffer> GrGLGpu::onCreateBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern) {
return GrGLBuffer::Make(this, size, intendedType, accessPattern);
}
void GrGLGpu::flushScissorTest(GrScissorTest scissorTest) {
@ -3117,8 +3125,11 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
1, 0,
1, 1
};
fCopyProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), GrGpuBufferType::kVertex,
kStatic_GrAccessPattern, vdata);
fCopyProgramArrayBuffer = GrGLBuffer::Make(this,
sizeof(vdata),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern);
fCopyProgramArrayBuffer->updateData(vdata, sizeof(vdata));
}
if (!fCopyProgramArrayBuffer) {
return false;
@ -3552,8 +3563,11 @@ bool GrGLGpu::onRegenerateMipMapLevels(GrTexture* texture) {
1, 0,
1, 1
};
fMipmapProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), GrGpuBufferType::kVertex,
kStatic_GrAccessPattern, vdata);
fMipmapProgramArrayBuffer = GrGLBuffer::Make(this,
sizeof(vdata),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern);
fMipmapProgramArrayBuffer->updateData(vdata, sizeof(vdata));
}
if (!fMipmapProgramArrayBuffer) {
return false;

View File

@ -259,8 +259,7 @@ private:
GrProtected,
const void* data, size_t dataSize) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
const void* data) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType, GrAccessPattern) override;
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
GrWrapOwnership,

View File

@ -219,8 +219,9 @@ sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRender
/*label=*/{}));
}
sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
GrAccessPattern accessPattern, const void*) {
sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes,
GrGpuBufferType type,
GrAccessPattern accessPattern) {
return sk_sp<GrGpuBuffer>(
new GrMockBuffer(this, sizeInBytes, type, accessPattern, /*label=*/{}));
}

View File

@ -87,8 +87,9 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
const void*) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes,
GrGpuBufferType,
GrAccessPattern) override;
bool onReadPixels(GrSurface*,
SkIRect,

View File

@ -187,8 +187,7 @@ private:
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern,
const void*) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern) override;
bool onReadPixels(GrSurface* surface,
SkIRect,

View File

@ -293,9 +293,10 @@ std::unique_ptr<GrSemaphore> GrMtlGpu::prepareTextureForCrossContextUsage(GrText
return nullptr;
}
sk_sp<GrGpuBuffer> GrMtlGpu::onCreateBuffer(size_t size, GrGpuBufferType type,
GrAccessPattern accessPattern, const void* data) {
return GrMtlBuffer::Make(this, size, type, accessPattern, data);
sk_sp<GrGpuBuffer> GrMtlGpu::onCreateBuffer(size_t size,
GrGpuBufferType type,
GrAccessPattern accessPattern) {
return GrMtlBuffer::Make(this, size, type, accessPattern);
}
static bool check_max_blit_width(int widthInPixels) {

View File

@ -445,8 +445,9 @@ bool GrVkGpu::submitCommandBuffer(SyncQueue sync) {
}
///////////////////////////////////////////////////////////////////////////////
sk_sp<GrGpuBuffer> GrVkGpu::onCreateBuffer(size_t size, GrGpuBufferType type,
GrAccessPattern accessPattern, const void* data) {
sk_sp<GrGpuBuffer> GrVkGpu::onCreateBuffer(size_t size,
GrGpuBufferType type,
GrAccessPattern accessPattern) {
#ifdef SK_DEBUG
switch (type) {
case GrGpuBufferType::kVertex:
@ -467,12 +468,7 @@ sk_sp<GrGpuBuffer> GrVkGpu::onCreateBuffer(size_t size, GrGpuBufferType type,
break;
}
#endif
sk_sp<GrGpuBuffer> buff = GrVkBuffer::Make(this, size, type, accessPattern);
if (data && buff) {
buff->updateData(data, size);
}
return buff;
return GrVkBuffer::Make(this, size, type, accessPattern);
}
bool GrVkGpu::onWritePixels(GrSurface* surface,

View File

@ -269,8 +269,7 @@ private:
sk_sp<GrRenderTarget> onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo&,
const GrVkDrawableInfo&) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
const void* data) override;
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern) override;
bool onReadPixels(GrSurface*,
SkIRect,