Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
GrRingBuffer Class Reference

#include <GrRingBuffer.h>

Classes

struct  Slice
 

Public Member Functions

 GrRingBuffer (GrGpu *gpu, size_t size, size_t alignment, GrGpuBufferType intendedType)
 
Slice suballocate (size_t size)
 
void startSubmit (GrGpu *)
 
size_t size () const
 

Detailed Description

A wrapper for a GPU buffer that allocates slices in a continuous ring.

It's assumed that suballocate and startSubmit are always called in the same thread, and that finishSubmit could be called in a separate thread.

Definition at line 23 of file GrRingBuffer.h.

Constructor & Destructor Documentation

◆ GrRingBuffer()

GrRingBuffer::GrRingBuffer ( GrGpu gpu,
size_t  size,
size_t  alignment,
GrGpuBufferType  intendedType 
)
inline

Definition at line 25 of file GrRingBuffer.h.

26 : fGpu(gpu)
27 , fTotalSize(size)
28 , fAlignment(alignment)
29 , fType(intendedType)
30 , fNewAllocation(false)
31 , fHead(0)
32 , fTail(0)
33 , fGenID(0) {
34 // We increment fHead and fTail without bound and let overflow handle any wrapping.
35 // Because of this, size needs to be a power of two.
37 }
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr bool SkIsPow2(T value)
Definition SkMath.h:51
size_t size() const

Member Function Documentation

◆ size()

size_t GrRingBuffer::size ( ) const
inline

Definition at line 48 of file GrRingBuffer.h.

48{ return fTotalSize; }

◆ startSubmit()

void GrRingBuffer::startSubmit ( GrGpu gpu)

Definition at line 87 of file GrRingBuffer.cpp.

87 {
88 for (unsigned int i = 0; i < fPreviousBuffers.size(); ++i) {
89 fPreviousBuffers[i]->unmap();
90 gpu->takeOwnershipOfBuffer(std::move(fPreviousBuffers[i]));
91 }
92 fPreviousBuffers.clear();
93
94 if (fNewAllocation) {
95#ifdef SK_BUILD_FOR_MAC
96 // Since we're using a Managed buffer on MacOS we need to unmap to write back to GPU
97 // TODO: once we set up persistently mapped UPLOAD buffers on D3D, we can remove the
98 // platform restriction.
99 fCurrentBuffer->unmap();
100#endif
101 SubmitData* submitData = new SubmitData();
102 submitData->fOwner = this;
103 submitData->fLastHead = fHead;
104 submitData->fGenID = fGenID;
105 gpu->addFinishedProc(FinishSubmit, submitData);
106 fNewAllocation = false;
107 }
108}
virtual void addFinishedProc(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)=0
virtual void takeOwnershipOfBuffer(sk_sp< GrGpuBuffer >)
Definition GrGpu.h:432

◆ suballocate()

GrRingBuffer::Slice GrRingBuffer::suballocate ( size_t  size)

Definition at line 57 of file GrRingBuffer.cpp.

57 {
58 fNewAllocation = true;
59 if (fCurrentBuffer) {
60 size_t offset = this->getAllocationOffset(size);
61 if (offset < fTotalSize) {
62 return { fCurrentBuffer.get(), offset };
63 }
64
65 // Try to grow allocation (old allocation will age out).
66 fTotalSize *= 2;
67 // Add current buffer to be tracked for next submit.
68 fPreviousBuffers.push_back(std::move(fCurrentBuffer));
69 }
70
71 GrResourceProvider* resourceProvider = fGpu->getContext()->priv().resourceProvider();
72 fCurrentBuffer = resourceProvider->createBuffer(fTotalSize,
73 fType,
76
77 SkASSERT(fCurrentBuffer);
78 fHead = 0;
79 fTail = 0;
80 fGenID++;
81 size_t offset = this->getAllocationOffset(size);
82 SkASSERT(offset < fTotalSize);
83 return { fCurrentBuffer.get(), offset };
84}
@ kDynamic_GrAccessPattern
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition GrGpu.h:67
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
T * get() const
Definition SkRefCnt.h:303
Point offset

The documentation for this class was generated from the following files: