Fix matrix layout in Metal.
2x2 matrices are packed tightly, 3x3 have a pad of float at the end of each row. Bug: skia:8243 Change-Id: I07c3d051643aed13e37bc52a13cdd67a3728d71b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214364 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
b1e4a4e438
commit
bb66ac1e5e
@ -322,14 +322,22 @@ template<int N> inline void GrMtlPipelineStateDataManager::setMatrices(
|
||||
set_uniform_matrix<N>::set(buffer, uni.fOffset, arrayCount, matrices);
|
||||
}
|
||||
|
||||
template<int N> struct set_uniform_matrix {
|
||||
template<> struct set_uniform_matrix<2> {
|
||||
inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
|
||||
GR_STATIC_ASSERT(sizeof(float) == 4);
|
||||
buffer = static_cast<char*>(buffer) + uniformOffset;
|
||||
memcpy(buffer, matrices, count * 4 * sizeof(float));
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct set_uniform_matrix<3> {
|
||||
inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
|
||||
GR_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];
|
||||
for (int j = 0; j < N; ++j) {
|
||||
memcpy(buffer, &matrix[j * N], N * sizeof(float));
|
||||
const float* matrix = &matrices[3 * 3 * i];
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
memcpy(buffer, &matrix[j * 3], 3 * sizeof(float));
|
||||
buffer = static_cast<char*>(buffer) + 4 * sizeof(float);
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,7 @@ static inline uint32_t grsltype_to_mtl_size(GrSLType type) {
|
||||
return 4 * sizeof(int32_t);
|
||||
case kHalf2x2_GrSLType: // fall through
|
||||
case kFloat2x2_GrSLType:
|
||||
//TODO: this will be 4 * szof(float) on std430.
|
||||
return 8 * sizeof(float);
|
||||
return 4 * sizeof(float);
|
||||
case kHalf3x3_GrSLType: // fall through
|
||||
case kFloat3x3_GrSLType:
|
||||
return 12 * sizeof(float);
|
||||
|
Loading…
Reference in New Issue
Block a user