Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GrUniformDataManager Class Reference

#include <GrUniformDataManager.h>

Inheritance diagram for GrUniformDataManager:
GrGLSLProgramDataManager GrD3DPipelineStateDataManager GrMtlPipelineStateDataManager GrVkPipelineStateDataManager

Classes

struct  Uniform
 

Public Member Functions

 GrUniformDataManager (uint32_t uniformCount, uint32_t uniformSize)
 
void set1i (UniformHandle, int32_t) const override
 
void set1iv (UniformHandle, int arrayCount, const int32_t v[]) const override
 
void set1f (UniformHandle, float v0) const override
 
void set1fv (UniformHandle, int arrayCount, const float v[]) const override
 
void set2i (UniformHandle, int32_t, int32_t) const override
 
void set2iv (UniformHandle, int arrayCount, const int32_t v[]) const override
 
void set2f (UniformHandle, float, float) const override
 
void set2fv (UniformHandle, int arrayCount, const float v[]) const override
 
void set3i (UniformHandle, int32_t, int32_t, int32_t) const override
 
void set3iv (UniformHandle, int arrayCount, const int32_t v[]) const override
 
void set3f (UniformHandle, float, float, float) const override
 
void set3fv (UniformHandle, int arrayCount, const float v[]) const override
 
void set4i (UniformHandle, int32_t, int32_t, int32_t, int32_t) const override
 
void set4iv (UniformHandle, int arrayCount, const int32_t v[]) const override
 
void set4f (UniformHandle, float, float, float, float) const override
 
void set4fv (UniformHandle, int arrayCount, const float v[]) const override
 
void setMatrix2f (UniformHandle, const float matrix[]) const override
 
void setMatrix3f (UniformHandle, const float matrix[]) const override
 
void setMatrix4f (UniformHandle, const float matrix[]) const override
 
void setMatrix2fv (UniformHandle, int arrayCount, const float matrices[]) const override
 
void setMatrix3fv (UniformHandle, int arrayCount, const float matrices[]) const override
 
void setMatrix4fv (UniformHandle, int arrayCount, const float matrices[]) const override
 
void markDirty ()
 
- Public Member Functions inherited from GrGLSLProgramDataManager
virtual ~GrGLSLProgramDataManager ()
 
virtual void set1i (UniformHandle, int32_t) const =0
 
virtual void set1iv (UniformHandle, int arrayCount, const int v[]) const =0
 
virtual void set1f (UniformHandle, float v0) const =0
 
virtual void set1fv (UniformHandle, int arrayCount, const float v[]) const =0
 
virtual void set2i (UniformHandle, int32_t, int32_t) const =0
 
virtual void set2iv (UniformHandle, int arrayCount, const int v[]) const =0
 
virtual void set2f (UniformHandle, float, float) const =0
 
virtual void set2fv (UniformHandle, int arrayCount, const float v[]) const =0
 
virtual void set3i (UniformHandle, int32_t, int32_t, int32_t) const =0
 
virtual void set3iv (UniformHandle, int arrayCount, const int v[]) const =0
 
virtual void set3f (UniformHandle, float, float, float) const =0
 
virtual void set3fv (UniformHandle, int arrayCount, const float v[]) const =0
 
virtual void set4i (UniformHandle, int32_t, int32_t, int32_t, int32_t) const =0
 
virtual void set4iv (UniformHandle, int arrayCount, const int v[]) const =0
 
virtual void set4f (UniformHandle, float, float, float, float) const =0
 
virtual void set4fv (UniformHandle, int arrayCount, const float v[]) const =0
 
virtual void setMatrix2f (UniformHandle, const float matrix[]) const =0
 
virtual void setMatrix3f (UniformHandle, const float matrix[]) const =0
 
virtual void setMatrix4f (UniformHandle, const float matrix[]) const =0
 
virtual void setMatrix2fv (UniformHandle, int arrayCount, const float matrices[]) const =0
 
virtual void setMatrix3fv (UniformHandle, int arrayCount, const float matrices[]) const =0
 
virtual void setMatrix4fv (UniformHandle, int arrayCount, const float matrices[]) const =0
 
void setSkMatrix (UniformHandle, const SkMatrix &) const
 
void setSkM44 (UniformHandle, const SkM44 &) const
 
void setRuntimeEffectUniforms (SkSpan< const SkRuntimeEffect::Uniform >, SkSpan< const UniformHandle >, SkSpan< const Specialized >, const void *src) const
 
void setRuntimeEffectUniforms (SkSpan< const SkRuntimeEffect::Uniform > uniforms, SkSpan< const UniformHandle > handles, const void *src) const
 

Protected Member Functions

int copyUniforms (void *dest, const void *src, int numUniforms, SkSLType uniformType) const
 
template<int N, SkSLType kFullType, SkSLType kHalfType>
void set (UniformHandle u, const void *v) const
 
template<int N, SkSLType kFullType, SkSLType kHalfType>
void setv (UniformHandle u, int arrayCount, const void *v) const
 
template<int N, SkSLType FullType, SkSLType HalfType>
void setMatrices (UniformHandle, int arrayCount, const float matrices[]) const
 
void * getBufferPtrAndMarkDirty (const Uniform &uni) const
 
- Protected Member Functions inherited from GrGLSLProgramDataManager
 GrGLSLProgramDataManager ()
 

Protected Attributes

uint32_t fUniformSize
 
bool fWrite16BitUniforms = false
 
skia_private::TArray< Uniform, truefUniforms
 
SkAutoMalloc fUniformData
 
bool fUniformsDirty = false
 

Additional Inherited Members

- Public Types inherited from GrGLSLProgramDataManager
enum class  Specialized : bool { kNo = false , kYes = true }
 

Detailed Description

Subclass of GrGLSLProgramDataManager used to store uniforms for a program in a CPU buffer that can be uploaded to a UBO. This currently assumes uniform layouts that are compatible with Vulkan, Dawn, and D3D12. It could be used more broadly if this aspect was made configurable.

Definition at line 23 of file GrUniformDataManager.h.

Constructor & Destructor Documentation

◆ GrUniformDataManager()

GrUniformDataManager::GrUniformDataManager ( uint32_t  uniformCount,
uint32_t  uniformSize 
)

Definition at line 19 of file GrUniformDataManager.cpp.

20 : fUniformSize(uniformSize)
21 , fUniformsDirty(false) {
22 fUniformData.reset(uniformSize);
23 fUniforms.push_back_n(uniformCount);
24 // subclasses fill in the uniforms in their constructor
25}
skia_private::TArray< Uniform, true > fUniforms
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
Definition: SkAutoMalloc.h:53
T * push_back_n(int n)
Definition: SkTArray.h:267

Member Function Documentation

◆ copyUniforms()

int GrUniformDataManager::copyUniforms ( void *  dest,
const void *  src,
int  numUniforms,
SkSLType  uniformType 
) const
protected

Definition at line 32 of file GrUniformDataManager.cpp.

35 {
37 switch (uniformType) {
38 case SkSLType::kHalf:
44 case SkSLType::kHalf4x4: {
45 const float* floatBits = static_cast<const float*>(src);
46 SkHalf* halfBits = static_cast<SkHalf*>(dest);
47 while (numUniforms-- > 0) {
48 *halfBits++ = SkFloatToHalf(*floatBits++);
49 }
50 return 2;
51 }
52
60 case SkSLType::kUShort4: {
61 const int32_t* intBits = static_cast<const int32_t*>(src);
62 short* shortBits = static_cast<short*>(dest);
63 while (numUniforms-- > 0) {
64 *shortBits++ = (short)(*intBits++);
65 }
66 return 2;
67 }
68
69 default:
70 // Fall through to memcpy below.
71 break;
72 }
73 }
74
75 memcpy(dest, src, numUniforms * 4);
76 return 4;
77}
SkHalf SkFloatToHalf(float f)
Definition: SkHalf.cpp:16
uint16_t SkHalf
Definition: SkHalf.h:16
dest
Definition: zip.py:79

◆ getBufferPtrAndMarkDirty()

void * GrUniformDataManager::getBufferPtrAndMarkDirty ( const Uniform uni) const
protected

Definition at line 27 of file GrUniformDataManager.cpp.

27 {
28 fUniformsDirty = true;
29 return static_cast<char*>(fUniformData.get()) + uni.fOffset;
30}
void * get()
Definition: SkAutoMalloc.h:64

◆ markDirty()

void GrUniformDataManager::markDirty ( )
inline

Definition at line 53 of file GrUniformDataManager.h.

53{ fUniformsDirty = true; }

◆ set()

template<int N, SkSLType FullType, SkSLType HalfType>
void GrUniformDataManager::set ( UniformHandle  u,
const void *  v 
) const
inlineprotected

Definition at line 80 of file GrUniformDataManager.cpp.

80 {
81 const Uniform& uni = fUniforms[u.toIndex()];
82 SkASSERT(uni.fType == FullType || uni.fType == HalfType);
83 SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount);
84 void* buffer = this->getBufferPtrAndMarkDirty(uni);
85 this->copyUniforms(buffer, v, N, uni.fType);
86}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define N
Definition: beziers.cpp:19
void * getBufferPtrAndMarkDirty(const Uniform &uni) const
int copyUniforms(void *dest, const void *src, int numUniforms, SkSLType uniformType) const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ set1f()

void GrUniformDataManager::set1f ( UniformHandle  u,
float  v0 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 118 of file GrUniformDataManager.cpp.

118 {
119 this->set<1, SkSLType::kFloat, SkSLType::kHalf>(u, &v0);
120}

◆ set1fv()

void GrUniformDataManager::set1fv ( UniformHandle  u,
int  arrayCount,
const float  v[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Reimplemented in GrMtlPipelineStateDataManager, and GrVkPipelineStateDataManager.

Definition at line 122 of file GrUniformDataManager.cpp.

124 {
125 this->setv<1, SkSLType::kFloat, SkSLType::kHalf>(u, arrayCount, v);
126}

◆ set1i()

void GrUniformDataManager::set1i ( UniformHandle  ,
int32_t   
) const
overridevirtual

Functions for uploading uniform values. The varities ending in v can be used to upload to an array of uniforms. arrayCount must be <= the array count of the uniform.

Implements GrGLSLProgramDataManager.

Definition at line 108 of file GrUniformDataManager.cpp.

108 {
109 this->set<1, SkSLType::kInt, SkSLType::kShort>(u, &i0);
110}

◆ set1iv()

void GrUniformDataManager::set1iv ( UniformHandle  u,
int  arrayCount,
const int32_t  v[] 
) const
override

Definition at line 112 of file GrUniformDataManager.cpp.

114 {
115 this->setv<1, SkSLType::kInt, SkSLType::kShort>(u, arrayCount, v);
116}

◆ set2f()

void GrUniformDataManager::set2f ( UniformHandle  u,
float  v0,
float  v1 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 139 of file GrUniformDataManager.cpp.

139 {
140 float v[2] = { v0, v1 };
141 this->set<2, SkSLType::kFloat2, SkSLType::kHalf2>(u, v);
142}

◆ set2fv()

void GrUniformDataManager::set2fv ( UniformHandle  u,
int  arrayCount,
const float  v[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Reimplemented in GrMtlPipelineStateDataManager, and GrVkPipelineStateDataManager.

Definition at line 144 of file GrUniformDataManager.cpp.

146 {
147 this->setv<2, SkSLType::kFloat2, SkSLType::kHalf2>(u, arrayCount, v);
148}

◆ set2i()

void GrUniformDataManager::set2i ( UniformHandle  u,
int32_t  i0,
int32_t  i1 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 128 of file GrUniformDataManager.cpp.

128 {
129 int32_t v[2] = { i0, i1 };
130 this->set<2, SkSLType::kInt2, SkSLType::kShort2>(u, v);
131}

◆ set2iv()

void GrUniformDataManager::set2iv ( UniformHandle  u,
int  arrayCount,
const int32_t  v[] 
) const
override

Definition at line 133 of file GrUniformDataManager.cpp.

135 {
136 this->setv<2, SkSLType::kInt2, SkSLType::kShort2>(u, arrayCount, v);
137}

◆ set3f()

void GrUniformDataManager::set3f ( UniformHandle  u,
float  v0,
float  v1,
float  v2 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 164 of file GrUniformDataManager.cpp.

164 {
165 float v[3] = { v0, v1, v2 };
166 this->set<3, SkSLType::kFloat3, SkSLType::kHalf3>(u, v);
167}
Vec2Value v2

◆ set3fv()

void GrUniformDataManager::set3fv ( UniformHandle  u,
int  arrayCount,
const float  v[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 169 of file GrUniformDataManager.cpp.

171 {
172 this->setv<3, SkSLType::kFloat3, SkSLType::kHalf3>(u, arrayCount, v);
173}

◆ set3i()

void GrUniformDataManager::set3i ( UniformHandle  u,
int32_t  i0,
int32_t  i1,
int32_t  i2 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 150 of file GrUniformDataManager.cpp.

153 {
154 int32_t v[3] = { i0, i1, i2 };
155 this->set<3, SkSLType::kInt3, SkSLType::kShort3>(u, v);
156}

◆ set3iv()

void GrUniformDataManager::set3iv ( UniformHandle  u,
int  arrayCount,
const int32_t  v[] 
) const
override

Definition at line 158 of file GrUniformDataManager.cpp.

160 {
161 this->setv<3, SkSLType::kInt3, SkSLType::kShort3>(u, arrayCount, v);
162}

◆ set4f()

void GrUniformDataManager::set4f ( UniformHandle  u,
float  v0,
float  v1,
float  v2,
float  v3 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 190 of file GrUniformDataManager.cpp.

194 {
195 float v[4] = { v0, v1, v2, v3 };
196 this->set<4, SkSLType::kFloat4, SkSLType::kHalf4>(u, v);
197}

◆ set4fv()

void GrUniformDataManager::set4fv ( UniformHandle  u,
int  arrayCount,
const float  v[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 199 of file GrUniformDataManager.cpp.

201 {
202 this->setv<4, SkSLType::kFloat4, SkSLType::kHalf4>(u, arrayCount, v);
203}

◆ set4i()

void GrUniformDataManager::set4i ( UniformHandle  u,
int32_t  i0,
int32_t  i1,
int32_t  i2,
int32_t  i3 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 175 of file GrUniformDataManager.cpp.

179 {
180 int32_t v[4] = { i0, i1, i2, i3 };
181 this->set<4, SkSLType::kInt4, SkSLType::kShort4>(u, v);
182}

◆ set4iv()

void GrUniformDataManager::set4iv ( UniformHandle  u,
int  arrayCount,
const int32_t  v[] 
) const
override

Definition at line 184 of file GrUniformDataManager.cpp.

186 {
187 this->setv<4, SkSLType::kInt4, SkSLType::kShort4>(u, arrayCount, v);
188}

◆ setMatrices()

template<int N, SkSLType FullType, SkSLType HalfType>
void GrUniformDataManager::setMatrices ( UniformHandle  u,
int  arrayCount,
const float  matrices[] 
) const
inlineprotected

Definition at line 230 of file GrUniformDataManager.cpp.

232 {
233 const Uniform& uni = fUniforms[u.toIndex()];
234 SkASSERT(uni.fType == FullType || uni.fType == HalfType);
235 SkASSERT(arrayCount > 0);
236 SkASSERT(arrayCount <= uni.fArrayCount ||
237 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
238
239 void* buffer = this->getBufferPtrAndMarkDirty(uni);
240 if constexpr (N == 4) {
241 this->copyUniforms(buffer, matrices, arrayCount * 16, uni.fType);
242 } else {
243 for (int i = 0; i < arrayCount; ++i) {
244 const float* matrix = &matrices[N * N * i];
245 for (int j = 0; j < N; ++j) {
246 int uniformSize = this->copyUniforms(buffer, &matrix[j * N], N, uni.fType);
247 buffer = SkTAddOffset<void>(buffer, /*numUniforms*/4 * uniformSize);
248 }
249 }
250 }
251}
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ setMatrix2f()

void GrUniformDataManager::setMatrix2f ( UniformHandle  u,
const float  matrix[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Reimplemented in GrMtlPipelineStateDataManager.

Definition at line 205 of file GrUniformDataManager.cpp.

205 {
206 this->setMatrices<2, SkSLType::kFloat2x2, SkSLType::kHalf2x2>(u, 1, matrix);
207}

◆ setMatrix2fv()

void GrUniformDataManager::setMatrix2fv ( UniformHandle  u,
int  arrayCount,
const float  matrices[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Reimplemented in GrMtlPipelineStateDataManager, and GrVkPipelineStateDataManager.

Definition at line 209 of file GrUniformDataManager.cpp.

209 {
210 this->setMatrices<2, SkSLType::kFloat2x2, SkSLType::kHalf2x2>(u, arrayCount, m);
211}

◆ setMatrix3f()

void GrUniformDataManager::setMatrix3f ( UniformHandle  u,
const float  matrix[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 213 of file GrUniformDataManager.cpp.

213 {
214 this->setMatrices<3, SkSLType::kFloat3x3, SkSLType::kHalf3x3>(u, 1, matrix);
215}

◆ setMatrix3fv()

void GrUniformDataManager::setMatrix3fv ( UniformHandle  u,
int  arrayCount,
const float  matrices[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 217 of file GrUniformDataManager.cpp.

217 {
218 this->setMatrices<3, SkSLType::kFloat3x3, SkSLType::kHalf3x3>(u, arrayCount, m);
219}

◆ setMatrix4f()

void GrUniformDataManager::setMatrix4f ( UniformHandle  u,
const float  matrix[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 221 of file GrUniformDataManager.cpp.

221 {
222 this->setMatrices<4, SkSLType::kFloat4x4, SkSLType::kHalf4x4>(u, 1, matrix);
223}

◆ setMatrix4fv()

void GrUniformDataManager::setMatrix4fv ( UniformHandle  u,
int  arrayCount,
const float  matrices[] 
) const
overridevirtual

Implements GrGLSLProgramDataManager.

Definition at line 225 of file GrUniformDataManager.cpp.

225 {
226 this->setMatrices<4, SkSLType::kFloat4x4, SkSLType::kHalf4x4>(u, arrayCount, m);
227}

◆ setv()

template<int N, SkSLType FullType, SkSLType HalfType>
void GrUniformDataManager::setv ( UniformHandle  u,
int  arrayCount,
const void *  v 
) const
inlineprotected

Definition at line 89 of file GrUniformDataManager.cpp.

89 {
90 const Uniform& uni = fUniforms[u.toIndex()];
91 SkASSERT(uni.fType == FullType || uni.fType == HalfType);
92 SkASSERT(arrayCount > 0);
93 SkASSERT(arrayCount <= uni.fArrayCount ||
94 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
95
96 void* buffer = this->getBufferPtrAndMarkDirty(uni);
97 if constexpr (N == 4) {
98 this->copyUniforms(buffer, v, arrayCount * 4, uni.fType);
99 } else {
100 for (int i = 0; i < arrayCount; ++i) {
101 int uniformSize = this->copyUniforms(buffer, v, N, uni.fType);
102 buffer = SkTAddOffset<void>(buffer, /*numUniforms*/4 * uniformSize);
103 v = static_cast<const char*>(v) + N * 4;
104 }
105 }
106}

Member Data Documentation

◆ fUniformData

SkAutoMalloc GrUniformDataManager::fUniformData
mutableprotected

Definition at line 80 of file GrUniformDataManager.h.

◆ fUniforms

skia_private::TArray<Uniform, true> GrUniformDataManager::fUniforms
protected

Definition at line 78 of file GrUniformDataManager.h.

◆ fUniformsDirty

bool GrUniformDataManager::fUniformsDirty = false
mutableprotected

Definition at line 81 of file GrUniformDataManager.h.

◆ fUniformSize

uint32_t GrUniformDataManager::fUniformSize
protected

Definition at line 75 of file GrUniformDataManager.h.

◆ fWrite16BitUniforms

bool GrUniformDataManager::fWrite16BitUniforms = false
protected

Definition at line 76 of file GrUniformDataManager.h.


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