[ganesh][dawn] Use GrRingBuffer for uniform buffer allocation
The Dawn backend used its own GrDawnRingBuffer type to manage uniform buffer slices which always made new wgpu::Buffer allocations on-demand. It now uses the GrRingBuffer type for this purpose. While the Dawn backend does not use mapped buffers for uniform data uploads and buffers are ref-counted and freed by Dawn automatically after use, using GrRingBuffer allows it to share the same GrResourceProvider infrastructure as the other backends. Change-Id: Id2697f306f9ce3d5c6c85745b135585b092b6fb0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/553525 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Arman Uguray <armansito@google.com>
This commit is contained in:
parent
79a71e7fd2
commit
9da66d2a57
@ -704,8 +704,6 @@ skia_dawn_sources = [
|
||||
"$_src/gpu/ganesh/dawn/GrDawnProgramDataManager.h",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnRenderTarget.cpp",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnRenderTarget.h",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnRingBuffer.cpp",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnRingBuffer.h",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnTexture.cpp",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnTexture.h",
|
||||
"$_src/gpu/ganesh/dawn/GrDawnTextureRenderTarget.cpp",
|
||||
|
@ -23,8 +23,6 @@ DAWN_FILES = [
|
||||
"GrDawnProgramDataManager.h",
|
||||
"GrDawnRenderTarget.cpp",
|
||||
"GrDawnRenderTarget.h",
|
||||
"GrDawnRingBuffer.cpp",
|
||||
"GrDawnRingBuffer.h",
|
||||
"GrDawnTexture.cpp",
|
||||
"GrDawnTexture.h",
|
||||
"GrDawnTextureRenderTarget.cpp",
|
||||
|
@ -21,6 +21,8 @@ namespace {
|
||||
return wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
|
||||
case GrGpuBufferType::kXferGpuToCpu:
|
||||
return wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
|
||||
case GrGpuBufferType::kUniform:
|
||||
return wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst;
|
||||
default:
|
||||
SkASSERT(!"buffer type not supported by Dawn");
|
||||
return wgpu::BufferUsage::Vertex;
|
||||
|
@ -128,7 +128,7 @@ GrDawnGpu::GrDawnGpu(GrDirectContext* direct,
|
||||
: INHERITED(direct)
|
||||
, fDevice(device)
|
||||
, fQueue(device.GetQueue())
|
||||
, fUniformRingBuffer(this, wgpu::BufferUsage::Uniform)
|
||||
, fUniformsRingBuffer(this, 128 * 1024, 256, GrGpuBufferType::kUniform)
|
||||
, fStagingBufferManager(this)
|
||||
, fPendingMapAsyncRequests(device)
|
||||
, fRenderPipelineCache(kMaxRenderPipelineEntries)
|
||||
@ -962,8 +962,8 @@ wgpu::Sampler GrDawnGpu::getOrCreateSampler(GrSamplerState samplerState) {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
GrDawnRingBuffer::Slice GrDawnGpu::allocateUniformRingBufferSlice(int size) {
|
||||
return fUniformRingBuffer.allocate(size);
|
||||
GrRingBuffer::Slice GrDawnGpu::allocateUniformRingBufferSlice(int size) {
|
||||
return fUniformsRingBuffer.suballocate(size);
|
||||
}
|
||||
|
||||
void GrDawnGpu::appendCommandBuffer(wgpu::CommandBuffer commandBuffer) {
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include "src/core/SkLRUCache.h"
|
||||
#include "src/gpu/ganesh/GrFinishCallbacks.h"
|
||||
#include "src/gpu/ganesh/GrProgramDesc.h"
|
||||
#include "src/gpu/ganesh/GrRingBuffer.h"
|
||||
#include "src/gpu/ganesh/GrStagingBufferManager.h"
|
||||
#include "src/gpu/ganesh/dawn/GrDawnAsyncWait.h"
|
||||
#include "src/gpu/ganesh/dawn/GrDawnRingBuffer.h"
|
||||
#include "src/sksl/ir/SkSLProgram.h"
|
||||
#include "webgpu/webgpu_cpp.h"
|
||||
|
||||
@ -97,7 +97,7 @@ public:
|
||||
|
||||
wgpu::Sampler getOrCreateSampler(GrSamplerState samplerState);
|
||||
|
||||
GrDawnRingBuffer::Slice allocateUniformRingBufferSlice(int size);
|
||||
GrRingBuffer::Slice allocateUniformRingBufferSlice(int size);
|
||||
wgpu::CommandEncoder getCopyEncoder();
|
||||
void flushCopyEncoder();
|
||||
void appendCommandBuffer(wgpu::CommandBuffer commandBuffer);
|
||||
@ -232,7 +232,7 @@ private:
|
||||
wgpu::Device fDevice;
|
||||
wgpu::Queue fQueue;
|
||||
std::unique_ptr<GrDawnOpsRenderPass> fOpsRenderPass;
|
||||
GrDawnRingBuffer fUniformRingBuffer;
|
||||
GrRingBuffer fUniformsRingBuffer;
|
||||
wgpu::CommandEncoder fCopyEncoder;
|
||||
std::vector<wgpu::CommandBuffer> fCommandBuffers;
|
||||
GrStagingBufferManager fStagingBufferManager;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/gpu/ganesh/dawn/GrDawnProgramDataManager.h"
|
||||
|
||||
#include "src/gpu/ganesh/dawn/GrDawnBuffer.h"
|
||||
#include "src/gpu/ganesh/dawn/GrDawnGpu.h"
|
||||
|
||||
GrDawnProgramDataManager::GrDawnProgramDataManager(const UniformInfoArray& uniforms,
|
||||
@ -43,11 +44,12 @@ wgpu::BindGroup GrDawnProgramDataManager::uploadUniformBuffers(GrDawnGpu* gpu,
|
||||
wgpu::BindGroupLayout layout) {
|
||||
if (fUniformsDirty && 0 != fUniformSize) {
|
||||
std::vector<wgpu::BindGroupEntry> bindings;
|
||||
GrDawnRingBuffer::Slice slice;
|
||||
slice = gpu->allocateUniformRingBufferSlice(fUniformSize);
|
||||
gpu->queue().WriteBuffer(slice.fBuffer, slice.fOffset, fUniformData.get(), fUniformSize);
|
||||
|
||||
GrRingBuffer::Slice slice = gpu->allocateUniformRingBufferSlice(fUniformSize);
|
||||
GrDawnBuffer* buffer = static_cast<GrDawnBuffer*>(slice.fBuffer);
|
||||
gpu->queue().WriteBuffer(buffer->get(), slice.fOffset, fUniformData.get(), fUniformSize);
|
||||
bindings.push_back(make_bind_group_entry(GrSPIRVUniformHandler::kUniformBinding,
|
||||
slice.fBuffer, slice.fOffset,
|
||||
buffer->get(), slice.fOffset,
|
||||
fUniformSize));
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "src/gpu/ganesh/GrUniformDataManager.h"
|
||||
|
||||
#include "src/gpu/ganesh/GrSPIRVUniformHandler.h"
|
||||
#include "src/gpu/ganesh/dawn/GrDawnRingBuffer.h"
|
||||
#include "webgpu/webgpu_cpp.h"
|
||||
|
||||
#include "src/core/SkAutoMalloc.h"
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "src/gpu/ganesh/dawn/GrDawnRingBuffer.h"
|
||||
|
||||
#include "src/gpu/ganesh/dawn/GrDawnGpu.h"
|
||||
#include "src/gpu/ganesh/dawn/GrDawnUtil.h"
|
||||
|
||||
namespace {
|
||||
const int kDefaultSize = 64 * 1024;
|
||||
}
|
||||
|
||||
GrDawnRingBuffer::GrDawnRingBuffer(GrDawnGpu* gpu, wgpu::BufferUsage usage)
|
||||
: fGpu(gpu) , fUsage(usage) {
|
||||
}
|
||||
|
||||
GrDawnRingBuffer::~GrDawnRingBuffer() {
|
||||
}
|
||||
|
||||
GrDawnRingBuffer::Slice GrDawnRingBuffer::allocate(int size) {
|
||||
if (!fBuffer || fOffset + size > kDefaultSize) {
|
||||
wgpu::BufferDescriptor desc;
|
||||
desc.usage = fUsage | wgpu::BufferUsage::CopyDst;
|
||||
desc.size = kDefaultSize;
|
||||
fBuffer = fGpu->device().CreateBuffer(&desc);
|
||||
fOffset = 0;
|
||||
}
|
||||
|
||||
size_t offset = fOffset;
|
||||
fOffset += size;
|
||||
fOffset = GrDawnRoundRowBytes(fOffset);
|
||||
return Slice(fBuffer, offset);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrDawnRingBuffer_DEFINED
|
||||
#define GrDawnRingBuffer_DEFINED
|
||||
|
||||
#include "src/gpu/ganesh/dawn/GrDawnBuffer.h"
|
||||
|
||||
class GrDawnGpu;
|
||||
|
||||
class GrDawnRingBuffer : public SkRefCnt {
|
||||
public:
|
||||
GrDawnRingBuffer(GrDawnGpu* gpu, wgpu::BufferUsage usage);
|
||||
~GrDawnRingBuffer() override;
|
||||
|
||||
struct Slice {
|
||||
Slice(wgpu::Buffer buffer, int offset)
|
||||
: fBuffer(buffer), fOffset(offset) {}
|
||||
Slice()
|
||||
: fBuffer(nullptr), fOffset(0) {}
|
||||
Slice(const Slice& other)
|
||||
: fBuffer(other.fBuffer), fOffset(other.fOffset) {}
|
||||
Slice& operator=(const Slice& other) {
|
||||
fBuffer = other.fBuffer;
|
||||
fOffset = other.fOffset;
|
||||
return *this;
|
||||
}
|
||||
wgpu::Buffer fBuffer;
|
||||
int fOffset;
|
||||
};
|
||||
Slice allocate(int size);
|
||||
|
||||
private:
|
||||
GrDawnGpu* fGpu;
|
||||
wgpu::BufferUsage fUsage;
|
||||
wgpu::Buffer fBuffer;
|
||||
int fOffset = 0;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user