1 /* 2 * Copyright 2019 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "src/gpu/dawn/GrDawnRingBuffer.h" 9 10 #include "src/gpu/dawn/GrDawnGpu.h" 11 #include "src/gpu/dawn/GrDawnUtil.h" 12 13 namespace { 14 const int kDefaultSize = 64 * 1024; 15 } 16 GrDawnRingBuffer(GrDawnGpu * gpu,wgpu::BufferUsage usage)17GrDawnRingBuffer::GrDawnRingBuffer(GrDawnGpu* gpu, wgpu::BufferUsage usage) 18 : fGpu(gpu) , fUsage(usage) { 19 } 20 ~GrDawnRingBuffer()21GrDawnRingBuffer::~GrDawnRingBuffer() { 22 } 23 allocate(int size)24GrDawnRingBuffer::Slice GrDawnRingBuffer::allocate(int size) { 25 if (!fBuffer || fOffset + size > kDefaultSize) { 26 wgpu::BufferDescriptor desc; 27 desc.usage = fUsage | wgpu::BufferUsage::CopyDst; 28 desc.size = kDefaultSize; 29 fBuffer = fGpu->device().CreateBuffer(&desc); 30 fOffset = 0; 31 } 32 33 size_t offset = fOffset; 34 fOffset += size; 35 fOffset = GrDawnRoundRowBytes(fOffset); 36 return Slice(fBuffer, offset); 37 } 38