GrResourceProvider::createBuffer: group data ptr with size in overload.

Bug: skia:12720
Change-Id: I9e065e61e904c6f54f601b021db3dcd7fbf3de86
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544247
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2022-05-26 19:33:20 -04:00 committed by SkCQ
parent 8272b06ed8
commit 9c9ef3845d
14 changed files with 101 additions and 76 deletions

View File

@ -209,8 +209,10 @@ private:
v[1].color = SK_ColorGREEN;
v[2].color = SK_ColorYELLOW;
v[3].color = SK_ColorMAGENTA;
fVertexBuffer = flushState->resourceProvider()->createBuffer(
sizeof(v), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, v);
fVertexBuffer = flushState->resourceProvider()->createBuffer(v,
sizeof(v),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern);
}
void onPrepare(GrOpFlushState* flushState) override {

View File

@ -204,8 +204,10 @@ private:
{0, fY},
{100, fY+100},
};
fVertexBuffer = flushState->resourceProvider()->createBuffer(
sizeof(vertices), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, vertices);
fVertexBuffer = flushState->resourceProvider()->createBuffer(vertices,
sizeof(vertices),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern);
}
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {

View File

@ -224,8 +224,10 @@ private:
{-1, +1},
{+1, +1},
};
fVertexBuffer = flushState->resourceProvider()->createBuffer(
sizeof(vertices), GrGpuBufferType::kVertex, kStatic_GrAccessPattern, vertices);
fVertexBuffer = flushState->resourceProvider()->createBuffer(vertices,
sizeof(vertices),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern);
}
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) final {

View File

@ -170,10 +170,10 @@ sk_sp<Base> SkMeshPriv::GpuBuffer<Base, Type>::Make(GrDirectContext* dc,sk_sp<co
SkASSERT(data);
sk_sp<GrGpuBuffer> buffer = dc->priv().resourceProvider()->createBuffer(
data->data(),
data->size(),
Type,
kStatic_GrAccessPattern,
data->data());
kStatic_GrAccessPattern);
if (!buffer) {
return nullptr;
}

View File

@ -436,14 +436,19 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(GrGpuBufferT
if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(key)) {
return std::move(buffer);
}
if (auto buffer = this->createBuffer(size, intendedType, kStatic_GrAccessPattern, staticData)) {
// We shouldn't bin and/or cache static buffers.
SkASSERT(buffer->size() == size);
SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
buffer->resourcePriv().setUniqueKey(key);
return sk_sp<const GrGpuBuffer>(buffer);
auto buffer = this->createBuffer(staticData, size, intendedType, kStatic_GrAccessPattern);
if (!buffer) {
return nullptr;
}
return nullptr;
// We shouldn't bin and/or cache static buffers.
SkASSERT(buffer->size() == size);
SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
buffer->resourcePriv().setUniqueKey(key);
return std::move(buffer);
}
sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(
@ -454,30 +459,35 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(
if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(uniqueKey)) {
return std::move(buffer);
}
if (auto buffer = this->createBuffer(size, intendedType, kStatic_GrAccessPattern)) {
// We shouldn't bin and/or cache static buffers.
SkASSERT(buffer->size() == size);
SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
buffer->resourcePriv().setUniqueKey(uniqueKey);
// Map the buffer. Use a staging buffer on the heap if mapping isn't supported.
skgpu::VertexWriter vertexWriter = {buffer->map(), size};
SkAutoTMalloc<char> stagingBuffer;
if (!vertexWriter) {
SkASSERT(!buffer->isMapped());
vertexWriter = {stagingBuffer.reset(size), size};
}
initializeBufferFn(std::move(vertexWriter), size);
if (buffer->isMapped()) {
buffer->unmap();
} else {
buffer->updateData(stagingBuffer, size);
}
return std::move(buffer);
auto buffer = this->createBuffer(size, intendedType, kStatic_GrAccessPattern);
if (!buffer) {
return nullptr;
}
return nullptr;
// We shouldn't bin and/or cache static buffers.
SkASSERT(buffer->size() == size);
SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
buffer->resourcePriv().setUniqueKey(uniqueKey);
// Map the buffer. Use a staging buffer on the heap if mapping isn't supported.
skgpu::VertexWriter vertexWriter = {buffer->map(), size};
SkAutoTMalloc<char> stagingBuffer;
if (!vertexWriter) {
SkASSERT(!buffer->isMapped());
vertexWriter = {stagingBuffer.reset(size), size};
}
initializeBufferFn(std::move(vertexWriter), size);
if (buffer->isMapped()) {
buffer->unmap();
} else {
buffer->updateData(stagingBuffer, size);
}
return std::move(buffer);
}
sk_sp<const GrGpuBuffer> GrResourceProvider::createPatternedIndexBuffer(
@ -571,19 +581,15 @@ int GrResourceProvider::NumVertsPerAAQuad() { return kVertsPerAAQuad; }
int GrResourceProvider::NumIndicesPerAAQuad() { return kIndicesPerAAQuad; }
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern,
const void* data) {
GrAccessPattern accessPattern) {
if (this->isAbandoned()) {
return nullptr;
}
if (kDynamic_GrAccessPattern != accessPattern) {
auto buffer = this->gpu()->createBuffer(size, intendedType, accessPattern);
if (buffer && data) {
buffer->updateData(data, size);
}
return buffer;
return this->gpu()->createBuffer(size, intendedType, accessPattern);
}
// bin by pow2+midpoint with a reasonable min
static const size_t MIN_SIZE = 1 << 12;
@ -602,12 +608,6 @@ sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size,
key)));
if (!buffer) {
buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrAccessPattern);
if (!buffer) {
return nullptr;
}
}
if (data) {
buffer->updateData(data, size);
}
return buffer;
}

View File

@ -286,17 +286,22 @@ public:
* Returns a buffer.
*
* @param size minimum size of buffer to return.
* @param intendedType hint to the graphics subsystem about what the buffer will be used for.
* @param GrGpuBufferType hint to the graphics subsystem about what the buffer will be used for.
* @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed.
* @param flags see Flags enum.
* @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,
const void* data = nullptr);
sk_sp<GrGpuBuffer> createBuffer(size_t size, GrGpuBufferType, GrAccessPattern);
/** Same as above but also fills the buffer from data. */
sk_sp<GrGpuBuffer> createBuffer(const void* data,
size_t size,
GrGpuBufferType type,
GrAccessPattern pattern) {
SkASSERT(data);
auto buffer = this->createBuffer(size, type, pattern);
return buffer && buffer->updateData(data, size) ? buffer : nullptr;
}
/**
* If passed in render target already has a stencil buffer on the specified surface, return

View File

@ -30,7 +30,9 @@ GrStagingBufferManager::Slice GrStagingBufferManager::allocateStagingBufferSlice
GrResourceProvider* resourceProvider = fGpu->getContext()->priv().resourceProvider();
size_t bufferSize = std::max(size, kMinStagingBufferSize);
sk_sp<GrGpuBuffer> newBuffer = resourceProvider->createBuffer(
bufferSize, GrGpuBufferType::kXferCpuToGpu, kDynamic_GrAccessPattern, nullptr);
bufferSize,
GrGpuBufferType::kXferCpuToGpu,
kDynamic_GrAccessPattern);
if (!newBuffer) {
return {}; // invalid slice
}

View File

@ -297,10 +297,10 @@ private:
if (fVertexData) {
if (!fVertexData->gpuBuffer()) {
sk_sp<GrGpuBuffer> buffer = rp->createBuffer(fVertexData->size(),
sk_sp<GrGpuBuffer> buffer = rp->createBuffer(fVertexData->vertices(),
fVertexData->size(),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern,
fVertexData->vertices());
kStatic_GrAccessPattern);
if (!buffer) {
return;
}

View File

@ -209,7 +209,10 @@ void GrVkBuffer::copyCpuDataToGpuBuffer(const void* src, size_t size) {
} else {
GrResourceProvider* resourceProvider = gpu->getContext()->priv().resourceProvider();
sk_sp<GrGpuBuffer> transferBuffer = resourceProvider->createBuffer(
size, GrGpuBufferType::kXferCpuToGpu, kDynamic_GrAccessPattern, src);
src,
size,
GrGpuBufferType::kXferCpuToGpu,
kDynamic_GrAccessPattern);
if (!transferBuffer) {
return;
}

View File

@ -182,8 +182,10 @@ bool GrVkMSAALoadManager::loadMSAAFromResolve(GrVkGpu* gpu,
// TODO: Is it worth holding onto the last used uniform buffer and tracking the width, height,
// dst width, and dst height so that we can use the buffer again without having to update the
// data?
sk_sp<GrGpuBuffer> uniformBuffer = resourceProvider->createBuffer(
4 * sizeof(float), GrGpuBufferType::kUniform, kDynamic_GrAccessPattern, uniData);
sk_sp<GrGpuBuffer> uniformBuffer = resourceProvider->createBuffer(uniData,
sizeof(uniData),
GrGpuBufferType::kUniform,
kDynamic_GrAccessPattern);
if (!uniformBuffer) {
return false;
}

View File

@ -50,9 +50,10 @@ std::pair<sk_sp<GrGpuBuffer>, bool> GrVkPipelineStateDataManager::uploadUniforms
} else {
if (fUniformsDirty) {
GrResourceProvider* resourceProvider = gpu->getContext()->priv().resourceProvider();
fUniformBuffer = resourceProvider->createBuffer(
fUniformSize, GrGpuBufferType::kUniform, kDynamic_GrAccessPattern,
fUniformData.get());
fUniformBuffer = resourceProvider->createBuffer(fUniformData.get(),
fUniformSize,
GrGpuBufferType::kUniform,
kDynamic_GrAccessPattern);
if (!fUniformBuffer) {
return std::make_pair(nullptr, false);
}

View File

@ -537,14 +537,18 @@ std::unique_ptr<GrGeometryProcessor::ProgramImpl> MeshTestProcessor::makeProgram
////////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<const GrBuffer> DrawMeshHelper::makeIndexBuffer(const uint16_t indices[], int count) {
return sk_sp<const GrBuffer>(fState->resourceProvider()->createBuffer(
count * sizeof(uint16_t), GrGpuBufferType::kIndex, kDynamic_GrAccessPattern, indices));
return fState->resourceProvider()->createBuffer(indices,
count*sizeof(uint16_t),
GrGpuBufferType::kIndex,
kDynamic_GrAccessPattern);
}
template<typename T>
sk_sp<const GrBuffer> DrawMeshHelper::makeVertexBuffer(const T* data, int count) {
return sk_sp<const GrBuffer>(fState->resourceProvider()->createBuffer(
count * sizeof(T), GrGpuBufferType::kVertex, kDynamic_GrAccessPattern, data));
return fState->resourceProvider()->createBuffer(data,
count*sizeof(T),
GrGpuBufferType::kVertex,
kDynamic_GrAccessPattern);
}
sk_sp<const GrBuffer> DrawMeshHelper::getIndexBuffer() {

View File

@ -222,8 +222,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrPipelineDynamicStateTest, reporter, ctxInfo
{d, d, kMeshColors[3]}
};
sk_sp<const GrBuffer> vbuff(rp->createBuffer(sizeof(vdata), GrGpuBufferType::kVertex,
kDynamic_GrAccessPattern, vdata));
sk_sp<const GrBuffer> vbuff(rp->createBuffer(vdata,
sizeof(vdata),
GrGpuBufferType::kVertex,
kDynamic_GrAccessPattern));
if (!vbuff) {
ERRORF(reporter, "vbuff is null.");
return;

View File

@ -539,10 +539,10 @@ private:
if (!failFillingIn) {
++fStats->fNumHWCreations;
sk_sp<GrGpuBuffer> tmp = rp->createBuffer(fVertexData->size(),
sk_sp<GrGpuBuffer> tmp = rp->createBuffer(fVertexData->vertices(),
fVertexData->size(),
GrGpuBufferType::kVertex,
kStatic_GrAccessPattern,
fVertexData->vertices());
kStatic_GrAccessPattern);
fVertexData->setGpuBuffer(std::move(tmp));
}
}