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

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

Issue 2369013006: Update vulkan varying locations to correctly handle arrays (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | 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 "GrVkVaryingHandler.h" 8 #include "GrVkVaryingHandler.h"
9 9
10 /** Returns the number of locations take up by a given GrSLType. We assume that all
11 scalar values are 32 bits. */
12 static inline int grsltype_to_location_size(GrSLType type) {
13 static const uint32_t kSizes[] = {
14 0, // kVoid_GrSLType
15 1, // kFloat_GrSLType
16 1, // kVec2f_GrSLType
17 1, // kVec3f_GrSLType
18 1, // kVec4f_GrSLType
19 2, // kMat22f_GrSLType
20 3, // kMat33f_GrSLType
21 4, // kMat44f_GrSLType
22 0, // kTexture2DSampler_GrSLType
23 0, // kTextureExternalSampler_GrSLType
24 0, // kTexture2DRectSampler_GrSLType
25 0, // kTextureBufferSampler_GrSLType
26 1, // kBool_GrSLType
27 1, // kInt_GrSLType
28 1, // kUint_GrSLType
29 0, // kTexture2D_GrSLType
30 0, // kSampler_GrSLType
31 };
32 return kSizes[type];
33
34 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
35 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
36 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
37 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
38 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
39 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
40 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
41 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
42 GR_STATIC_ASSERT(8 == kTexture2DSampler_GrSLType);
43 GR_STATIC_ASSERT(9 == kTextureExternalSampler_GrSLType);
44 GR_STATIC_ASSERT(10 == kTexture2DRectSampler_GrSLType);
45 GR_STATIC_ASSERT(11 == kTextureBufferSampler_GrSLType);
46 GR_STATIC_ASSERT(12 == kBool_GrSLType);
47 GR_STATIC_ASSERT(13 == kInt_GrSLType);
48 GR_STATIC_ASSERT(14 == kUint_GrSLType);
49 GR_STATIC_ASSERT(15 == kTexture2D_GrSLType);
50 GR_STATIC_ASSERT(16 == kSampler_GrSLType);
51 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kSizes) == kGrSLTypeCount);
52 }
10 53
11 void finalize_helper(GrVkVaryingHandler::VarArray& vars) { 54 void finalize_helper(GrVkVaryingHandler::VarArray& vars) {
55 int locationIndex = 0;
12 for (int i = 0; i < vars.count(); ++i) { 56 for (int i = 0; i < vars.count(); ++i) {
57 GrGLSLShaderVar& var = vars[i];
13 SkString location; 58 SkString location;
14 location.appendf("location = %d", i); 59 location.appendf("location = %d", locationIndex);
15 vars[i].setLayoutQualifier(location.c_str()); 60 var.setLayoutQualifier(location.c_str());
61
62 int elementSize = grsltype_to_location_size(var.getType());
63 SkASSERT(elementSize);
64 int numElements = 1;
65 if (var.isArray()) {
66 numElements = var.getArrayCount();
67 }
68 locationIndex += elementSize * numElements;
16 } 69 }
70 // Vulkan requires at least 64 locations to be supported for both vertex out put and fragment
71 // input. If we ever hit this assert, then we'll need to add a cap to actual ly check the
72 // supported input and output values and adjust our supported shaders based on those values.
73 SkASSERT(locationIndex <= 64);
17 } 74 }
18 75
19 void GrVkVaryingHandler::onFinalize() { 76 void GrVkVaryingHandler::onFinalize() {
20 finalize_helper(fVertexInputs); 77 finalize_helper(fVertexInputs);
21 finalize_helper(fVertexOutputs); 78 finalize_helper(fVertexOutputs);
22 finalize_helper(fGeomInputs); 79 finalize_helper(fGeomInputs);
23 finalize_helper(fGeomOutputs); 80 finalize_helper(fGeomOutputs);
24 finalize_helper(fFragInputs); 81 finalize_helper(fFragInputs);
25 finalize_helper(fFragOutputs); 82 finalize_helper(fFragOutputs);
26 } 83 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698