8#ifndef skgpu_UniformManager_DEFINED
9#define skgpu_UniformManager_DEFINED
34class UniformDataBlock;
166namespace LayoutRules {
181 int size()
const {
return fOffset; }
195 int fReqAlignment = 0;
209 void write(
float f) { this->write<SkSLType::kFloat>(&f); }
210 void write(int32_t i) { this->write<SkSLType::kInt >(&i); }
211 void writeHalf(
float f) { this->write<SkSLType::kHalf >(&f); }
225 this->writeArray<SkSLType::kFloat4>(v.
data(), v.
size());
228 this->writeArray<SkSLType::kFloat4>(c.
data(), c.
size());
231 this->writeArray<SkSLType::kHalf4>(c.
data(), c.
size());
270 float colMajor[9] = {m[0], m[3], m[6],
273 this->writeArray<SkSLType::kFloat3>(colMajor, 3);
276 float colMajor[9] = {m[0], m[3], m[6],
279 this->writeArray<SkSLType::kHalf3>(colMajor, 3);
288 if (fWrotePaintColor) {
293 this->write<SkSLType::kFloat4>(&
color);
294 fWrotePaintColor =
true;
303 bool isReset()
const;
305 void doneWithExpectedUniforms();
322 template <SkSLType Type>
void write(
const void* src) {
341 inline char* append(
int alignment,
int size);
346 int fReqAlignment = 0;
348 bool fWrotePaintColor =
false;
353 UniformOffsetCalculator fOffsetCalculator;
355 int fExpectedUniformIndex = 0;
365template <
int N,
bool Half>
367 static_assert(1 <=
N &&
N <= 4);
375 static void Copy(
const void* src,
void* dst) {
376 if constexpr (Half) {
379 if constexpr (
N == 3) {
382 const float* srcF =
static_cast<const float*
>(src);
383 srcData = VecF{srcF[0], srcF[1], srcF[2], 0.f};
385 srcData = VecF::Load(src);
388 auto dstData = to_half(srcData);
391 memcpy(dst, &dstData,
kSize);
393 memcpy(dst, src,
kSize);
407 if constexpr (Half) {
419template<
int N,
bool Half>
421 using L = LayoutTraits<N, Half>;
426 ? this->append(L::kAlign, L::kSize + L::kElemSize)
427 : this->append(
L::kAlign,
L::
kSize);
428 SkASSERT(this->checkExpected(dst,
type, Uniform::kNonArray));
432 memset(dst + L::kSize, 0, L::kElemSize);
436template<
int N,
bool Half>
438 using L = LayoutTraits<N, Half>;
439 static constexpr int kSrcStride =
N * 4;
447 static constexpr int kStride = Half ? L::kAlign : 4*L::kElemSize;
450 const char* srcBytes =
reinterpret_cast<const char*
>(
src);
451 char*
dst = this->append(kStride, kStride*
count);
454 for (
int i = 0; i <
count; ++i) {
455 L::Copy(srcBytes, dst);
456 if constexpr (kStride - L::kSize > 0) {
457 memset(dst + L::kSize, 0, kStride - L::kSize);
461 srcBytes += kSrcStride;
465 SkASSERT(L::kAlign == L::kSize && kSrcStride == L::kSize);
466 char*
dst = this->append(L::kAlign, L::kSize*
count);
469 memcpy(dst, src, L::kSize*
count);
473char* UniformManager::append(
int alignment,
int size) {
482 SkASSERT(std::numeric_limits<int>::max() -
size >= padding);
486 memset(dst, 0, padding);
490 fReqAlignment = std::max(fReqAlignment, alignment);
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
static constexpr bool SkIsAlign4(T x)
constexpr int SkNextPow2_portable(int value)
bool SkSLTypeIsFullPrecisionNumericType(SkSLType type)
static constexpr bool SkSLTypeCanBeUniformValue(SkSLType type)
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
static constexpr int SkSLTypeVecLength(SkSLType type)
static const SkScalar * M44ColMajor(const SkM44 &m)
constexpr T * data() const
constexpr size_t size() const
static constexpr int kSize
static constexpr bool UseFullPrecision(Layout layout)
static constexpr bool AlignArraysAsVec4(Layout layout)
static constexpr bool PadVec3Size(Layout layout)
const float * vec() const
const float * asScalars() const
const float * ptr() const
const float * ptr() const
const float * ptr() const
static constexpr int kSize
static constexpr int kElemSize
static void Copy(const void *src, void *dst)
static constexpr int kAlign