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 "GrVkProgramDataManager.h" | 8 #include "GrVkProgramDataManager.h" |
9 | 9 |
10 #include "GrVkGpu.h" | 10 #include "GrVkGpu.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 void* buffer; | 68 void* buffer; |
69 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 69 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
70 buffer = fVertexUniformData.get(); | 70 buffer = fVertexUniformData.get(); |
71 } else { | 71 } else { |
72 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 72 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
73 buffer = fFragmentUniformData.get(); | 73 buffer = fFragmentUniformData.get(); |
74 } | 74 } |
75 buffer = static_cast<char*>(buffer) + uni.fOffset; | 75 buffer = static_cast<char*>(buffer) + uni.fOffset; |
76 SkASSERT(sizeof(float) == 4); | 76 SkASSERT(sizeof(float) == 4); |
77 memcpy(buffer, v, arrayCount * sizeof(float)); | 77 for (int i = 0; i < arrayCount; ++i) { |
| 78 const float* curVec = &v[i]; |
| 79 memcpy(buffer, curVec, sizeof(float)); |
| 80 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
| 81 } |
78 } | 82 } |
79 | 83 |
80 void GrVkProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { | 84 void GrVkProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { |
81 const Uniform& uni = fUniforms[u.toIndex()]; | 85 const Uniform& uni = fUniforms[u.toIndex()]; |
82 SkASSERT(uni.fType == kVec2f_GrSLType); | 86 SkASSERT(uni.fType == kVec2f_GrSLType); |
83 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 87 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
84 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); | 88 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
85 void* buffer; | 89 void* buffer; |
86 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 90 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
87 buffer = fVertexUniformData.get(); | 91 buffer = fVertexUniformData.get(); |
(...skipping 19 matching lines...) Expand all Loading... |
107 | 111 |
108 void* buffer; | 112 void* buffer; |
109 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 113 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
110 buffer = fVertexUniformData.get(); | 114 buffer = fVertexUniformData.get(); |
111 } else { | 115 } else { |
112 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 116 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
113 buffer = fFragmentUniformData.get(); | 117 buffer = fFragmentUniformData.get(); |
114 } | 118 } |
115 buffer = static_cast<char*>(buffer) + uni.fOffset; | 119 buffer = static_cast<char*>(buffer) + uni.fOffset; |
116 SkASSERT(sizeof(float) == 4); | 120 SkASSERT(sizeof(float) == 4); |
117 memcpy(buffer, v, arrayCount * 2* sizeof(float)); | 121 for (int i = 0; i < arrayCount; ++i) { |
| 122 const float* curVec = &v[2 * i]; |
| 123 memcpy(buffer, curVec, 2 * sizeof(float)); |
| 124 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
| 125 } |
118 } | 126 } |
119 | 127 |
120 void GrVkProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2
) const { | 128 void GrVkProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2
) const { |
121 const Uniform& uni = fUniforms[u.toIndex()]; | 129 const Uniform& uni = fUniforms[u.toIndex()]; |
122 SkASSERT(uni.fType == kVec3f_GrSLType); | 130 SkASSERT(uni.fType == kVec3f_GrSLType); |
123 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 131 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
124 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); | 132 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
125 void* buffer; | 133 void* buffer; |
126 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 134 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
127 buffer = fVertexUniformData.get(); | 135 buffer = fVertexUniformData.get(); |
(...skipping 19 matching lines...) Expand all Loading... |
147 | 155 |
148 void* buffer; | 156 void* buffer; |
149 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 157 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
150 buffer = fVertexUniformData.get(); | 158 buffer = fVertexUniformData.get(); |
151 } else { | 159 } else { |
152 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 160 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
153 buffer = fFragmentUniformData.get(); | 161 buffer = fFragmentUniformData.get(); |
154 } | 162 } |
155 buffer = static_cast<char*>(buffer) + uni.fOffset; | 163 buffer = static_cast<char*>(buffer) + uni.fOffset; |
156 SkASSERT(sizeof(float) == 4); | 164 SkASSERT(sizeof(float) == 4); |
157 memcpy(buffer, v, arrayCount * 3 * sizeof(float)); | 165 for (int i = 0; i < arrayCount; ++i) { |
| 166 const float* curVec = &v[3 * i]; |
| 167 memcpy(buffer, curVec, 3 * sizeof(float)); |
| 168 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
| 169 } |
158 } | 170 } |
159 | 171 |
160 void GrVkProgramDataManager::set4f(UniformHandle u, float v0, float v1, float v2
, float v3) const { | 172 void GrVkProgramDataManager::set4f(UniformHandle u, float v0, float v1, float v2
, float v3) const { |
161 const Uniform& uni = fUniforms[u.toIndex()]; | 173 const Uniform& uni = fUniforms[u.toIndex()]; |
162 SkASSERT(uni.fType == kVec4f_GrSLType); | 174 SkASSERT(uni.fType == kVec4f_GrSLType); |
163 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 175 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
164 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); | 176 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
165 void* buffer; | 177 void* buffer; |
166 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 178 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
167 buffer = fVertexUniformData.get(); | 179 buffer = fVertexUniformData.get(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } else { | 220 } else { |
209 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 221 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
210 buffer = fFragmentUniformData.get(); | 222 buffer = fFragmentUniformData.get(); |
211 } | 223 } |
212 | 224 |
213 SkASSERT(sizeof(float) == 4); | 225 SkASSERT(sizeof(float) == 4); |
214 buffer = static_cast<char*>(buffer) + uni.fOffset; | 226 buffer = static_cast<char*>(buffer) + uni.fOffset; |
215 memcpy(buffer, &matrix[0], 3 * sizeof(float)); | 227 memcpy(buffer, &matrix[0], 3 * sizeof(float)); |
216 buffer = static_cast<char*>(buffer) + 4*sizeof(float); | 228 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
217 memcpy(buffer, &matrix[3], 3 * sizeof(float)); | 229 memcpy(buffer, &matrix[3], 3 * sizeof(float)); |
218 buffer = static_cast<char*>(buffer) + 4 * sizeof(float); | 230 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
219 memcpy(buffer, &matrix[6], 3 * sizeof(float)); | 231 memcpy(buffer, &matrix[6], 3 * sizeof(float)); |
220 } | 232 } |
221 | 233 |
222 void GrVkProgramDataManager::setMatrix3fv(UniformHandle u, | 234 void GrVkProgramDataManager::setMatrix3fv(UniformHandle u, |
223 int arrayCount, | 235 int arrayCount, |
224 const float matrices[]) const { | 236 const float matrices[]) const { |
225 const Uniform& uni = fUniforms[u.toIndex()]; | 237 const Uniform& uni = fUniforms[u.toIndex()]; |
226 SkASSERT(uni.fType == kMat33f_GrSLType); | 238 SkASSERT(uni.fType == kMat33f_GrSLType); |
227 SkASSERT(arrayCount > 0); | 239 SkASSERT(arrayCount > 0); |
228 SkASSERT(arrayCount <= uni.fArrayCount || | 240 SkASSERT(arrayCount <= uni.fArrayCount || |
229 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 241 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
230 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); | 242 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
231 | 243 |
232 void* buffer; | 244 void* buffer; |
233 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 245 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
234 buffer = fVertexUniformData.get(); | 246 buffer = fVertexUniformData.get(); |
235 } else { | 247 } else { |
236 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 248 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
237 buffer = fFragmentUniformData.get(); | 249 buffer = fFragmentUniformData.get(); |
238 } | 250 } |
239 SkASSERT(sizeof(float) == 4); | 251 SkASSERT(sizeof(float) == 4); |
240 buffer = static_cast<char*>(buffer)+uni.fOffset; | 252 buffer = static_cast<char*>(buffer)+uni.fOffset; |
241 for (int i = 0; i < arrayCount; ++i) { | 253 for (int i = 0; i < arrayCount; ++i) { |
242 const float* matrix = &matrices[9 * i]; | 254 const float* matrix = &matrices[9 * i]; |
243 memcpy(buffer, &matrix[0], 3 * sizeof(float)); | 255 memcpy(buffer, &matrix[0], 3 * sizeof(float)); |
244 buffer = static_cast<char*>(buffer)+4 * sizeof(float); | 256 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
245 memcpy(buffer, &matrix[3], 3 * sizeof(float)); | 257 memcpy(buffer, &matrix[3], 3 * sizeof(float)); |
246 buffer = static_cast<char*>(buffer)+4 * sizeof(float); | 258 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
247 memcpy(buffer, &matrix[6], 3 * sizeof(float)); | 259 memcpy(buffer, &matrix[6], 3 * sizeof(float)); |
248 buffer = static_cast<char*>(buffer)+4 * sizeof(float); | 260 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
249 } | 261 } |
250 } | 262 } |
251 | 263 |
252 | 264 |
253 void GrVkProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[])
const { | 265 void GrVkProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[])
const { |
254 const Uniform& uni = fUniforms[u.toIndex()]; | 266 const Uniform& uni = fUniforms[u.toIndex()]; |
255 SkASSERT(uni.fType == kMat44f_GrSLType); | 267 SkASSERT(uni.fType == kMat44f_GrSLType); |
256 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 268 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
257 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); | 269 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
258 void* buffer; | 270 void* buffer; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 VK_ACCESS_UNIFORM_READ_BIT, | 319 VK_ACCESS_UNIFORM_READ_BIT, |
308 VK_ACCESS_HOST_WRITE_BIT, | 320 VK_ACCESS_HOST_WRITE_BIT, |
309 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, | 321 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, |
310 VK_PIPELINE_STAGE_HOST_BIT, | 322 VK_PIPELINE_STAGE_HOST_BIT, |
311 false); | 323 false); |
312 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get(
), | 324 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get(
), |
313 fFragmentUniformSize)); | 325 fFragmentUniformSize)); |
314 } | 326 } |
315 } | 327 } |
316 | 328 |
OLD | NEW |