14static_assert(
sizeof(int32_t) == 4);
15static_assert(
sizeof(
float) == 4);
16static_assert(
sizeof(short) == 2);
17static_assert(
sizeof(
SkHalf) == 2);
20 : fUniformSize(uniformSize)
21 , fUniformsDirty(false) {
37 switch (uniformType) {
45 const float* floatBits =
static_cast<const float*
>(src);
47 while (numUniforms-- > 0) {
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++);
75 memcpy(dest, src, numUniforms * 4);
79template <
int N, SkSLType FullType, SkSLType HalfType>
88template <
int N, SkSLType FullType, SkSLType HalfType>
93 SkASSERT(arrayCount <= uni.fArrayCount ||
97 if constexpr (
N == 4) {
100 for (
int i = 0; i < arrayCount; ++i) {
103 v =
static_cast<const char*
>(v) +
N * 4;
109 this->set<1, SkSLType::kInt, SkSLType::kShort>(u, &i0);
114 const int32_t v[])
const {
115 this->setv<1, SkSLType::kInt, SkSLType::kShort>(u, arrayCount, v);
119 this->set<1, SkSLType::kFloat, SkSLType::kHalf>(u, &v0);
124 const float v[])
const {
125 this->setv<1, SkSLType::kFloat, SkSLType::kHalf>(u, arrayCount, v);
129 int32_t v[2] = { i0, i1 };
130 this->set<2, SkSLType::kInt2, SkSLType::kShort2>(u, v);
135 const int32_t v[])
const {
136 this->setv<2, SkSLType::kInt2, SkSLType::kShort2>(u, arrayCount, v);
140 float v[2] = { v0, v1 };
141 this->set<2, SkSLType::kFloat2, SkSLType::kHalf2>(u, v);
146 const float v[])
const {
147 this->setv<2, SkSLType::kFloat2, SkSLType::kHalf2>(u, arrayCount, v);
154 int32_t v[3] = { i0, i1, i2 };
155 this->set<3, SkSLType::kInt3, SkSLType::kShort3>(u, v);
160 const int32_t v[])
const {
161 this->setv<3, SkSLType::kInt3, SkSLType::kShort3>(u, arrayCount, v);
165 float v[3] = { v0, v1,
v2 };
166 this->set<3, SkSLType::kFloat3, SkSLType::kHalf3>(u, v);
171 const float v[])
const {
172 this->setv<3, SkSLType::kFloat3, SkSLType::kHalf3>(u, arrayCount, v);
180 int32_t v[4] = { i0, i1, i2, i3 };
181 this->set<4, SkSLType::kInt4, SkSLType::kShort4>(u, v);
186 const int32_t v[])
const {
187 this->setv<4, SkSLType::kInt4, SkSLType::kShort4>(u, arrayCount, v);
195 float v[4] = { v0, v1,
v2, v3 };
196 this->set<4, SkSLType::kFloat4, SkSLType::kHalf4>(u, v);
201 const float v[])
const {
202 this->setv<4, SkSLType::kFloat4, SkSLType::kHalf4>(u, arrayCount, v);
206 this->setMatrices<2, SkSLType::kFloat2x2, SkSLType::kHalf2x2>(u, 1, matrix);
210 this->setMatrices<2, SkSLType::kFloat2x2, SkSLType::kHalf2x2>(u, arrayCount, m);
214 this->setMatrices<3, SkSLType::kFloat3x3, SkSLType::kHalf3x3>(u, 1, matrix);
218 this->setMatrices<3, SkSLType::kFloat3x3, SkSLType::kHalf3x3>(u, arrayCount, m);
222 this->setMatrices<4, SkSLType::kFloat4x4, SkSLType::kHalf4x4>(u, 1, matrix);
226 this->setMatrices<4, SkSLType::kFloat4x4, SkSLType::kHalf4x4>(u, arrayCount, m);
229template <
int N, SkSLType FullType, SkSLType HalfType>
232 const float matrices[])
const {
236 SkASSERT(arrayCount <= uni.fArrayCount ||
240 if constexpr (
N == 4) {
243 for (
int i = 0; i < arrayCount; ++i) {
244 const float* matrix = &matrices[
N *
N * i];
245 for (
int j = 0; j <
N; ++j) {
SkHalf SkFloatToHalf(float f)
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
static const uint8_t buffer[]