Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
skgpu::graphite::ComputePathAtlas Class Referenceabstract

#include <ComputePathAtlas.h>

Inheritance diagram for skgpu::graphite::ComputePathAtlas:
skgpu::graphite::PathAtlas

Public Member Functions

virtual std::unique_ptr< DispatchGrouprecordDispatches (Recorder *) const =0
 
void reset ()
 
- Public Member Functions inherited from skgpu::graphite::PathAtlas
 PathAtlas (Recorder *recorder, uint32_t requestedWidth, uint32_t requestedHeight)
 
virtual ~PathAtlas ()
 
std::pair< const Renderer *, std::optional< MaskAndOrigin > > addShape (const Rect &transformedShapeBounds, const Shape &shape, const Transform &localToDevice, const SkStrokeRec &style)
 
uint32_t width () const
 
uint32_t height () const
 

Static Public Member Functions

static std::unique_ptr< ComputePathAtlasCreateDefault (Recorder *)
 

Protected Member Functions

 ComputePathAtlas (Recorder *)
 
const TextureProxytexture () const
 
const TextureProxyaddRect (skvx::half2 maskSize, SkIPoint16 *outPos)
 
bool isSuitableForAtlasing (const Rect &transformedShapeBounds) const override
 
virtual void onReset ()=0
 
- Protected Member Functions inherited from skgpu::graphite::PathAtlas
virtual const TextureProxyonAddShape (const Shape &, const Transform &transform, const SkStrokeRec &, skvx::half2 maskSize, skvx::half2 *outPos)=0
 

Additional Inherited Members

- Public Types inherited from skgpu::graphite::PathAtlas
using MaskAndOrigin = std::pair< CoverageMaskShape, SkIPoint >
 
- Protected Attributes inherited from skgpu::graphite::PathAtlas
RecorderfRecorder
 
uint32_t fWidth = 0
 
uint32_t fHeight = 0
 
- Static Protected Attributes inherited from skgpu::graphite::PathAtlas
static constexpr int kEntryPadding = 1
 

Detailed Description

Base class for PathAtlas implementations that rasterize coverage masks on the GPU using compute shaders.

When a new shape gets added, it gets tracked as input to a series of GPU compute passes. This data is recorded by recordDispatches() into a DispatchGroup which can be added to a ComputeTask.

After a successful call to recordDispatches(), the client is free to call reset() and start adding new shapes for a future atlas render.

Definition at line 36 of file ComputePathAtlas.h.

Constructor & Destructor Documentation

◆ ComputePathAtlas()

skgpu::graphite::ComputePathAtlas::ComputePathAtlas ( Recorder recorder)
explicitprotected

Definition at line 32 of file ComputePathAtlas.cpp.

33 : PathAtlas(recorder, kComputeAtlasDim, kComputeAtlasDim)
34 , fRectanizer(this->width(), this->height()) {}
uint32_t height() const
Definition PathAtlas.h:95
PathAtlas(Recorder *recorder, uint32_t requestedWidth, uint32_t requestedHeight)
Definition PathAtlas.cpp:26
uint32_t width() const
Definition PathAtlas.h:94

Member Function Documentation

◆ addRect()

const TextureProxy * skgpu::graphite::ComputePathAtlas::addRect ( skvx::half2  maskSize,
SkIPoint16 outPos 
)
protected

Definition at line 73 of file ComputePathAtlas.cpp.

74 {
75 if (!this->initializeTextureIfNeeded()) {
76 SKGPU_LOG_E("Failed to instantiate an atlas texture");
77 return nullptr;
78 }
79
80 // An empty mask always fits, so just return the texture.
81 // TODO: This may not be needed if we can handle clipped out bounds with inverse fills
82 // another way. See PathAtlas::addShape().
83 if (!all(maskSize)) {
84 *outPos = {0, 0};
85 return fTexture.get();
86 }
87
88 if (!fRectanizer.addPaddedRect(maskSize.x(), maskSize.y(), kEntryPadding, outPos)) {
89 return nullptr;
90 }
91
92 return fTexture.get();
93}
#define SKGPU_LOG_E(fmt,...)
Definition Log.h:38
bool addPaddedRect(int width, int height, int16_t padding, SkIPoint16 *loc)
Definition Rectanizer.h:34
static constexpr int kEntryPadding
Definition PathAtlas.h:101
SIT bool all(const Vec< 1, T > &x)
Definition SkVx.h:582

◆ CreateDefault()

std::unique_ptr< ComputePathAtlas > skgpu::graphite::ComputePathAtlas::CreateDefault ( Recorder recorder)
static

Definition at line 243 of file ComputePathAtlas.cpp.

243 {
244#ifdef SK_ENABLE_VELLO_SHADERS
245 return std::make_unique<VelloComputePathAtlas>(recorder);
246#else
247 return nullptr;
248#endif
249}

◆ isSuitableForAtlasing()

bool skgpu::graphite::ComputePathAtlas::isSuitableForAtlasing ( const Rect transformedShapeBounds) const
overrideprotectedvirtual

Returns true if a path coverage mask with the given device-space bounds is sufficiently small to benefit from atlasing without causing too many atlas renders.

Reimplemented from skgpu::graphite::PathAtlas.

Definition at line 49 of file ComputePathAtlas.cpp.

49 {
50 Rect maskBounds = transformedShapeBounds.makeRoundOut();
51 skvx::float2 maskSize = maskBounds.size();
52 float width = maskSize.x(), height = maskSize.y();
53
54 if (width > this->width() || height > this->height()) {
55 return false;
56 }
57
58 // For now we're allowing paths that are smaller than 1/32nd of the full 4096x4096 atlas size
59 // to prevent the atlas texture from filling up too often. There are several approaches we
60 // should explore to alleviate the cost of atlasing large paths.
61 //
62 // 1. Rendering multiple atlas textures requires an extra compute pass for each texture. This
63 // impairs performance because there is a fixed cost to each dispatch and all dispatches get
64 // serialized by pipeline barrier synchronization. We should explore ways to render to multiple
65 // textures by issuing more workgroups in fewer dispatches as well as removing pipeline barriers
66 // across dispatches that target different atlas pages.
67 //
68 // 2. Implement a compressed "sparse" mask rendering scheme to render paths with a large
69 // bounding box using less texture space.
70 return (width * height) <= (1024 * 512);
71}
TRect< Scalar > Rect
Definition rect.h:746

◆ onReset()

virtual void skgpu::graphite::ComputePathAtlas::onReset ( )
protectedpure virtual

◆ recordDispatches()

virtual std::unique_ptr< DispatchGroup > skgpu::graphite::ComputePathAtlas::recordDispatches ( Recorder ) const
pure virtual

◆ reset()

void skgpu::graphite::ComputePathAtlas::reset ( )

Definition at line 95 of file ComputePathAtlas.cpp.

95 {
96 fRectanizer.reset();
97
98 this->onReset();
99}

◆ texture()

const TextureProxy * skgpu::graphite::ComputePathAtlas::texture ( ) const
inlineprotected

Definition at line 52 of file ComputePathAtlas.h.

52{ return fTexture.get(); }

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