Derive GrMtlPipelineStateDataManager from GrUniformDataManager.
Fixes some bugs in both classes as well.
Bug: skia:10585
Change-Id: I97c4cf0a7eeb9dff8262909a4c5ef25b1e3e0d4f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368817
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrUniformDataManager.cpp b/src/gpu/GrUniformDataManager.cpp
index 549057a..69842d0 100644
--- a/src/gpu/GrUniformDataManager.cpp
+++ b/src/gpu/GrUniformDataManager.cpp
@@ -9,6 +9,10 @@
#include "src/gpu/GrShaderVar.h"
+// ensure that these types are the sizes the uniform data is expecting
+static_assert(sizeof(int32_t) == 4);
+static_assert(sizeof(float) == 4);
+
GrUniformDataManager::GrUniformDataManager(uint32_t uniformCount, uint32_t uniformSize)
: fUniformSize(uniformSize)
, fUniformsDirty(false) {
@@ -40,7 +44,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(int32_t) == 4);
for (int i = 0; i < arrayCount; ++i) {
const int32_t* curVec = &v[i];
memcpy(buffer, curVec, sizeof(int32_t));
@@ -53,7 +56,6 @@
SkASSERT(uni.fType == kFloat_GrSLType || uni.fType == kHalf_GrSLType);
SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount);
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
memcpy(buffer, &v0, sizeof(float));
}
@@ -67,7 +69,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
for (int i = 0; i < arrayCount; ++i) {
const float* curVec = &v[i];
memcpy(buffer, curVec, sizeof(float));
@@ -94,7 +95,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(int32_t) == 4);
for (int i = 0; i < arrayCount; ++i) {
const int32_t* curVec = &v[2 * i];
memcpy(buffer, curVec, 2 * sizeof(int32_t));
@@ -107,7 +107,6 @@
SkASSERT(uni.fType == kFloat2_GrSLType || uni.fType == kHalf2_GrSLType);
SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount);
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
float v[2] = { v0, v1 };
memcpy(buffer, v, 2 * sizeof(float));
}
@@ -122,7 +121,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
for (int i = 0; i < arrayCount; ++i) {
const float* curVec = &v[2 * i];
memcpy(buffer, curVec, 2 * sizeof(float));
@@ -152,7 +150,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(int32_t) == 4);
for (int i = 0; i < arrayCount; ++i) {
const int32_t* curVec = &v[3 * i];
memcpy(buffer, curVec, 3 * sizeof(int32_t));
@@ -165,7 +162,6 @@
SkASSERT(uni.fType == kFloat3_GrSLType || uni.fType == kHalf3_GrSLType);
SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount);
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
float v[3] = { v0, v1, v2 };
memcpy(buffer, v, 3 * sizeof(float));
}
@@ -180,7 +176,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
for (int i = 0; i < arrayCount; ++i) {
const float* curVec = &v[3 * i];
memcpy(buffer, curVec, 3 * sizeof(float));
@@ -211,12 +206,7 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(int32_t) == 4);
- for (int i = 0; i < arrayCount; ++i) {
- const int32_t* curVec = &v[4 * i];
- memcpy(buffer, curVec, 4 * sizeof(int32_t));
- buffer = static_cast<char*>(buffer) + 4*sizeof(int32_t);
- }
+ memcpy(buffer, v, arrayCount * 4 * sizeof(int32_t));
}
void GrUniformDataManager::set4f(UniformHandle u,
@@ -228,7 +218,6 @@
SkASSERT(uni.fType == kFloat4_GrSLType || uni.fType == kHalf4_GrSLType);
SkASSERT(GrShaderVar::kNonArray == uni.fArrayCount);
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
float v[4] = { v0, v1, v2, v3 };
memcpy(buffer, v, 4 * sizeof(float));
}
@@ -243,7 +232,6 @@
(1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
void* buffer = this->getBufferPtrAndMarkDirty(uni);
- SkASSERT(sizeof(float) == 4);
memcpy(buffer, v, arrayCount * 4 * sizeof(float));
}
@@ -251,9 +239,7 @@
this->setMatrices<2>(u, 1, matrix);
}
-void GrUniformDataManager::setMatrix2fv(UniformHandle u,
- int arrayCount,
- const float m[]) const {
+void GrUniformDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const float m[]) const {
this->setMatrices<2>(u, arrayCount, m);
}
@@ -261,9 +247,7 @@
this->setMatrices<3>(u, 1, matrix);
}
-void GrUniformDataManager::setMatrix3fv(UniformHandle u,
- int arrayCount,
- const float m[]) const {
+void GrUniformDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const float m[]) const {
this->setMatrices<3>(u, arrayCount, m);
}
@@ -271,17 +255,15 @@
this->setMatrices<4>(u, 1, matrix);
}
-void GrUniformDataManager::setMatrix4fv(UniformHandle u,
- int arrayCount,
- const float m[]) const {
+void GrUniformDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const float m[]) const {
this->setMatrices<4>(u, arrayCount, m);
}
template<int N> struct set_uniform_matrix;
template<int N> inline void GrUniformDataManager::setMatrices(UniformHandle u,
- int arrayCount,
- const float matrices[]) const {
+ int arrayCount,
+ const float matrices[]) const {
const Uniform& uni = fUniforms[u.toIndex()];
SkASSERT(uni.fType == kFloat2x2_GrSLType + (N - 2) ||
uni.fType == kHalf2x2_GrSLType + (N - 2));
@@ -297,7 +279,6 @@
template<int N> struct set_uniform_matrix {
inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
- static_assert(sizeof(float) == 4);
buffer = static_cast<char*>(buffer) + uniformOffset;
for (int i = 0; i < count; ++i) {
const float* matrix = &matrices[N * N * i];
@@ -311,7 +292,6 @@
template<> struct set_uniform_matrix<4> {
inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
- static_assert(sizeof(float) == 4);
buffer = static_cast<char*>(buffer) + uniformOffset;
memcpy(buffer, matrices, count * 16 * sizeof(float));
}