Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: src/gpu/vk/GrVkProgramDataManager.cpp

Issue 1755483002: Add support for 2x2 matrices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: vk updates Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkProgramDataManager.h ('k') | src/gpu/vk/GrVkUniformHandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 buffer = fVertexUniformData.get(); 202 buffer = fVertexUniformData.get();
203 } else { 203 } else {
204 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); 204 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding);
205 buffer = fFragmentUniformData.get(); 205 buffer = fFragmentUniformData.get();
206 } 206 }
207 buffer = static_cast<char*>(buffer) + uni.fOffset; 207 buffer = static_cast<char*>(buffer) + uni.fOffset;
208 SkASSERT(sizeof(float) == 4); 208 SkASSERT(sizeof(float) == 4);
209 memcpy(buffer, v, arrayCount * 4 * sizeof(float)); 209 memcpy(buffer, v, arrayCount * 4 * sizeof(float));
210 } 210 }
211 211
212 void GrVkProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { 212 void GrVkProgramDataManager::setMatrix2f(UniformHandle u, const float matrix[]) const {
213 const Uniform& uni = fUniforms[u.toIndex()]; 213 this->setMatrices<2>(u, 1, matrix);
214 SkASSERT(uni.fType == kMat33f_GrSLType);
215 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
216 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber);
217 void* buffer;
218 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) {
219 buffer = fVertexUniformData.get();
220 } else {
221 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding);
222 buffer = fFragmentUniformData.get();
223 }
224
225 SkASSERT(sizeof(float) == 4);
226 buffer = static_cast<char*>(buffer) + uni.fOffset;
227 memcpy(buffer, &matrix[0], 3 * sizeof(float));
228 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
229 memcpy(buffer, &matrix[3], 3 * sizeof(float));
230 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
231 memcpy(buffer, &matrix[6], 3 * sizeof(float));
232 } 214 }
233 215
234 void GrVkProgramDataManager::setMatrix3fv(UniformHandle u, 216 void GrVkProgramDataManager::setMatrix2fv(UniformHandle u, int arrayCount, const float m[]) const {
235 int arrayCount, 217 this->setMatrices<2>(u, arrayCount, m);
236 const float matrices[]) const { 218 }
219
220 void GrVkProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const {
221 this->setMatrices<3>(u, 1, matrix);
222 }
223
224 void GrVkProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, const float m[]) const {
225 this->setMatrices<3>(u, arrayCount, m);
226 }
227
228 void GrVkProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const {
229 this->setMatrices<4>(u, 1, matrix);
230 }
231
232 void GrVkProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, const float m[]) const {
233 this->setMatrices<4>(u, arrayCount, m);
234 }
235
236 template<int N> struct set_uniform_matrix;
237
238 template<int N> inline void GrVkProgramDataManager::setMatrices(UniformHandle u,
239 int arrayCoun t,
240 const float m atrices[]) const {
237 const Uniform& uni = fUniforms[u.toIndex()]; 241 const Uniform& uni = fUniforms[u.toIndex()];
238 SkASSERT(uni.fType == kMat33f_GrSLType); 242 SkASSERT(uni.fType == kMat22f_GrSLType + (N - 2));
239 SkASSERT(arrayCount > 0); 243 SkASSERT(arrayCount > 0);
240 SkASSERT(arrayCount <= uni.fArrayCount || 244 SkASSERT(arrayCount <= uni.fArrayCount ||
241 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount)) ; 245 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount)) ;
242 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber);
243
244 void* buffer;
245 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) {
246 buffer = fVertexUniformData.get();
247 } else {
248 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding);
249 buffer = fFragmentUniformData.get();
250 }
251 SkASSERT(sizeof(float) == 4);
252 buffer = static_cast<char*>(buffer)+uni.fOffset;
253 for (int i = 0; i < arrayCount; ++i) {
254 const float* matrix = &matrices[9 * i];
255 memcpy(buffer, &matrix[0], 3 * sizeof(float));
256 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
257 memcpy(buffer, &matrix[3], 3 * sizeof(float));
258 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
259 memcpy(buffer, &matrix[6], 3 * sizeof(float));
260 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
261 }
262 }
263
264
265 void GrVkProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const {
266 const Uniform& uni = fUniforms[u.toIndex()];
267 SkASSERT(uni.fType == kMat44f_GrSLType);
268 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount);
269 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber);
270 void* buffer;
271 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) {
272 buffer = fVertexUniformData.get();
273 } else {
274 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding);
275 buffer = fFragmentUniformData.get();
276 }
277 buffer = static_cast<char*>(buffer) + uni.fOffset;
278 SkASSERT(sizeof(float) == 4);
279 memcpy(buffer, matrix, 16 * sizeof(float));
280 }
281
282 void GrVkProgramDataManager::setMatrix4fv(UniformHandle u,
283 int arrayCount,
284 const float matrices[]) const {
285 const Uniform& uni = fUniforms[u.toIndex()];
286 SkASSERT(uni.fType == kMat44f_GrSLType);
287 SkASSERT(arrayCount > 0);
288 SkASSERT(arrayCount <= uni.fArrayCount ||
289 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount)) ;
290 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); 246 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber);
291 247
292 void* buffer; 248 void* buffer;
293 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { 249 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) {
294 buffer = fVertexUniformData.get(); 250 buffer = fVertexUniformData.get();
295 } else { 251 } else {
296 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); 252 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding);
297 buffer = fFragmentUniformData.get(); 253 buffer = fFragmentUniformData.get();
298 } 254 }
299 buffer = static_cast<char*>(buffer) + uni.fOffset; 255
300 SkASSERT(sizeof(float) == 4); 256 set_uniform_matrix<N>::set(buffer, uni.fOffset, arrayCount, matrices);
301 memcpy(buffer, matrices, arrayCount * 16 * sizeof(float));
302 } 257 }
303 258
259 template<int N> struct set_uniform_matrix {
260 inline static void set(void* buffer, int uniformOffset, int count, const flo at matrices[]) {
261 GR_STATIC_ASSERT(sizeof(float) == 4);
262 buffer = static_cast<char*>(buffer) + uniformOffset;
263 for (int i = 0; i < count; ++i) {
264 const float* matrix = &matrices[N * N * i];
265 memcpy(buffer, &matrix[0], N * sizeof(float));
266 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
267 memcpy(buffer, &matrix[3], N * sizeof(float));
268 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
269 memcpy(buffer, &matrix[6], N * sizeof(float));
270 buffer = static_cast<char*>(buffer) + 4*sizeof(float);
271 }
272 }
273 };
274
275 template<> struct set_uniform_matrix<4> {
276 inline static void set(void* buffer, int uniformOffset, int count, const flo at matrices[]) {
277 GR_STATIC_ASSERT(sizeof(float) == 4);
278 buffer = static_cast<char*>(buffer) + uniformOffset;
279 memcpy(buffer, matrices, count * 16 * sizeof(float));
280 }
281 };
282
304 void GrVkProgramDataManager::uploadUniformBuffers(const GrVkGpu* gpu, 283 void GrVkProgramDataManager::uploadUniformBuffers(const GrVkGpu* gpu,
305 GrVkUniformBuffer* vertexBuffe r, 284 GrVkUniformBuffer* vertexBuffe r,
306 GrVkUniformBuffer* fragmentBuf fer) const { 285 GrVkUniformBuffer* fragmentBuf fer) const {
307 if (vertexBuffer) { 286 if (vertexBuffer) {
308 vertexBuffer->addMemoryBarrier(gpu, 287 vertexBuffer->addMemoryBarrier(gpu,
309 VK_ACCESS_UNIFORM_READ_BIT, 288 VK_ACCESS_UNIFORM_READ_BIT,
310 VK_ACCESS_HOST_WRITE_BIT, 289 VK_ACCESS_HOST_WRITE_BIT,
311 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 290 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
312 VK_PIPELINE_STAGE_HOST_BIT, 291 VK_PIPELINE_STAGE_HOST_BIT,
313 false); 292 false);
314 SkAssertResult(vertexBuffer->updateData(gpu, fVertexUniformData.get(), f VertexUniformSize)); 293 SkAssertResult(vertexBuffer->updateData(gpu, fVertexUniformData.get(), f VertexUniformSize));
315 } 294 }
316 295
317 if (fragmentBuffer) { 296 if (fragmentBuffer) {
318 fragmentBuffer->addMemoryBarrier(gpu, 297 fragmentBuffer->addMemoryBarrier(gpu,
319 VK_ACCESS_UNIFORM_READ_BIT, 298 VK_ACCESS_UNIFORM_READ_BIT,
320 VK_ACCESS_HOST_WRITE_BIT, 299 VK_ACCESS_HOST_WRITE_BIT,
321 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 300 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
322 VK_PIPELINE_STAGE_HOST_BIT, 301 VK_PIPELINE_STAGE_HOST_BIT,
323 false); 302 false);
324 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get( ), 303 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get( ),
325 fFragmentUniformSize)); 304 fFragmentUniformSize));
326 } 305 }
327 } 306 }
328 307
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkProgramDataManager.h ('k') | src/gpu/vk/GrVkUniformHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698