Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::graphite::UniformOffsetCalculator Class Reference

#include <UniformManager.h>

Public Member Functions

 UniformOffsetCalculator ()=default
 
 UniformOffsetCalculator (Layout layout, int offset)
 
int size () const
 
int requiredAlignment () const
 
int advanceOffset (SkSLType type, int count=Uniform::kNonArray)
 

Detailed Description

Definition at line 173 of file UniformManager.h.

Constructor & Destructor Documentation

◆ UniformOffsetCalculator() [1/2]

skgpu::graphite::UniformOffsetCalculator::UniformOffsetCalculator ( )
default

◆ UniformOffsetCalculator() [2/2]

skgpu::graphite::UniformOffsetCalculator::UniformOffsetCalculator ( Layout  layout,
int  offset 
)
inline

Definition at line 176 of file UniformManager.h.

176: fLayout(layout), fOffset(offset) {}
SeparatedVector2 offset

Member Function Documentation

◆ advanceOffset()

int skgpu::graphite::UniformOffsetCalculator::advanceOffset ( SkSLType  type,
int  count = Uniform::kNonArray 
)

Definition at line 19 of file UniformManager.cpp.

19 {
21
22 int dimension = SkSLTypeMatrixSize(type);
23 if (dimension > 0) {
24 // All SkSL matrices are square and can be interpreted as an array of column vectors
25 count = std::max(count, 1) * dimension;
26 } else {
27 dimension = SkSLTypeVecLength(type);
28 }
29 SkASSERT(1 <= dimension && dimension <= 4);
30
31 // Bump dimension up to 4 if the array or vec3 consumes 4 primitives per element
32 // NOTE: This affects the size, alignment already rounds up to a power of 2 automatically.
33 const bool isArray = count > Uniform::kNonArray;
34 if ((isArray && LayoutRules::AlignArraysAsVec4(fLayout)) ||
35 (dimension == 3 && (isArray || LayoutRules::PadVec3Size(fLayout)))) {
36 dimension = 4;
37 }
38
39 const int primitiveSize = LayoutRules::UseFullPrecision(fLayout) ||
41 const int align = SkNextPow2(dimension) * primitiveSize;
42 const int alignedOffset = SkAlignTo(fOffset, align);
43 fOffset = alignedOffset + dimension * primitiveSize * std::max(count, 1);
44 fReqAlignment = std::max(fReqAlignment, align);
45
46 return alignedOffset;
47}
int count
Definition: FontMgrTest.cpp:50
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int SkNextPow2(int value)
Definition: SkMathPriv.h:272
int SkSLTypeMatrixSize(SkSLType type)
bool SkSLTypeIsFullPrecisionNumericType(SkSLType type)
static constexpr bool SkSLTypeCanBeUniformValue(SkSLType type)
static constexpr int SkSLTypeVecLength(SkSLType type)
GLenum type
static constexpr int kNonArray
Definition: Uniform.h:25
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static constexpr bool UseFullPrecision(Layout layout)
static constexpr bool AlignArraysAsVec4(Layout layout)
static constexpr bool PadVec3Size(Layout layout)

◆ requiredAlignment()

int skgpu::graphite::UniformOffsetCalculator::requiredAlignment ( ) const
inline

Definition at line 182 of file UniformManager.h.

182{ return fReqAlignment; }

◆ size()

int skgpu::graphite::UniformOffsetCalculator::size ( ) const
inline

Definition at line 181 of file UniformManager.h.

181{ return fOffset; }

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