OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrVkUniformHandler.h" | 8 #include "GrVkUniformHandler.h" |
9 #include "glsl/GrGLSLProgramBuilder.h" | 9 #include "glsl/GrGLSLProgramBuilder.h" |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 46 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
47 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); | 47 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
48 GR_STATIC_ASSERT(12 == kBool_GrSLType); | 48 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
49 GR_STATIC_ASSERT(13 == kInt_GrSLType); | 49 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
50 GR_STATIC_ASSERT(14 == kUint_GrSLType); | 50 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
51 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAlignmentMask) == kGrSLTypeCount); | 51 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kAlignmentMask) == kGrSLTypeCount); |
52 return kAlignmentMask[type]; | 52 return kAlignmentMask[type]; |
53 } | 53 } |
54 | 54 |
55 /** Returns the size in bytes taken up in vulkanbuffers for floating point GrSLT
ypes. | 55 /** Returns the size in bytes taken up in vulkanbuffers for floating point GrSLT
ypes. |
56 For non floating point type returns 0 */ | 56 For non floating point type returns 0. Currently this reflects the std140 al
ignment |
| 57 so a mat22 takes up 8 floats. */ |
57 static inline uint32_t grsltype_to_vk_size(GrSLType type) { | 58 static inline uint32_t grsltype_to_vk_size(GrSLType type) { |
58 SkASSERT(GrSLTypeIsFloatType(type)); | 59 SkASSERT(GrSLTypeIsFloatType(type)); |
59 SkASSERT(kMat22f_GrSLType != type); // TODO: handle mat2 differences between
std140 and std430. | |
60 static const uint32_t kSizes[] = { | 60 static const uint32_t kSizes[] = { |
61 0, // kVoid_GrSLType | 61 0, // kVoid_GrSLType |
62 sizeof(float), // kFloat_GrSLType | 62 sizeof(float), // kFloat_GrSLType |
63 2 * sizeof(float), // kVec2f_GrSLType | 63 2 * sizeof(float), // kVec2f_GrSLType |
64 3 * sizeof(float), // kVec3f_GrSLType | 64 3 * sizeof(float), // kVec3f_GrSLType |
65 4 * sizeof(float), // kVec4f_GrSLType | 65 4 * sizeof(float), // kVec4f_GrSLType |
66 8 * sizeof(float), // kMat22f_GrSLType. TODO: this will be 4 * sz
of(float) on std430. | 66 8 * sizeof(float), // kMat22f_GrSLType. TODO: this will be 4 * sz
of(float) on std430. |
67 12 * sizeof(float), // kMat33f_GrSLType | 67 12 * sizeof(float), // kMat33f_GrSLType |
68 16 * sizeof(float), // kMat44f_GrSLType | 68 16 * sizeof(float), // kMat44f_GrSLType |
69 0, // kSampler2D_GrSLType | 69 0, // kSampler2D_GrSLType |
(...skipping 27 matching lines...) Expand all Loading... |
97 | 97 |
98 // Given the current offset into the ubo, calculate the offset for the uniform w
e're trying to add | 98 // Given the current offset into the ubo, calculate the offset for the uniform w
e're trying to add |
99 // taking into consideration all alignment requirements. The uniformOffset is se
t to the offset for | 99 // taking into consideration all alignment requirements. The uniformOffset is se
t to the offset for |
100 // the new uniform, and currentOffset is updated to be the offset to the end of
the new uniform. | 100 // the new uniform, and currentOffset is updated to be the offset to the end of
the new uniform. |
101 void get_ubo_aligned_offset(uint32_t* uniformOffset, | 101 void get_ubo_aligned_offset(uint32_t* uniformOffset, |
102 uint32_t* currentOffset, | 102 uint32_t* currentOffset, |
103 GrSLType type, | 103 GrSLType type, |
104 int arrayCount) { | 104 int arrayCount) { |
105 uint32_t alignmentMask = grsltype_to_alignment_mask(type); | 105 uint32_t alignmentMask = grsltype_to_alignment_mask(type); |
106 // We want to use the std140 layout here, so we must make arrays align to 16
bytes. | 106 // We want to use the std140 layout here, so we must make arrays align to 16
bytes. |
107 SkASSERT(type != kMat22f_GrSLType); // TODO: support mat2. | 107 if (arrayCount || type == kMat22f_GrSLType) { |
108 if (arrayCount) { | |
109 alignmentMask = 0xF; | 108 alignmentMask = 0xF; |
110 } | 109 } |
111 uint32_t offsetDiff = *currentOffset & alignmentMask; | 110 uint32_t offsetDiff = *currentOffset & alignmentMask; |
112 if (offsetDiff != 0) { | 111 if (offsetDiff != 0) { |
113 offsetDiff = alignmentMask - offsetDiff + 1; | 112 offsetDiff = alignmentMask - offsetDiff + 1; |
114 } | 113 } |
115 *uniformOffset = *currentOffset + offsetDiff; | 114 *uniformOffset = *currentOffset + offsetDiff; |
116 SkASSERT(sizeof(float) == 4); | 115 SkASSERT(sizeof(float) == 4); |
117 if (arrayCount) { | 116 if (arrayCount) { |
118 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type)); | 117 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 211 } |
213 if (!uniformsString.isEmpty()) { | 212 if (!uniformsString.isEmpty()) { |
214 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex
Binding | 213 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex
Binding |
215 : kFragBi
nding; | 214 : kFragBi
nding; |
216 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f
ragment"; | 215 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f
ragment"; |
217 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", | 216 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", |
218 kUniformBufferDescSet, uniformBinding, stage); | 217 kUniformBufferDescSet, uniformBinding, stage); |
219 out->appendf("%s\n};\n", uniformsString.c_str()); | 218 out->appendf("%s\n};\n", uniformsString.c_str()); |
220 } | 219 } |
221 } | 220 } |
OLD | NEW |