blob: 8bc024941b2e65e952398428ded8c3716838b005 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
8#include "GrVkUniformHandler.h"
9#include "glsl/GrGLSLProgramBuilder.h"
10
11// To determine whether a current offset is aligned, we can just 'and' the lowest bits with the
12// alignment mask. A value of 0 means aligned, any other value is how many bytes past alignment we
13// are. This works since all alignments are powers of 2. The mask is always (alignment - 1).
egdaniel4ee1cda2016-02-26 08:18:49 -080014// This alignment mask will give correct alignments for using the std430 block layout. If you want
15// the std140 alignment, you can use this, but then make sure if you have an array type it is
16// aligned to 16 bytes (i.e. has mask of 0xF).
Greg Daniel164a9f02016-02-22 09:56:40 -050017uint32_t grsltype_to_alignment_mask(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050018 switch(type) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -040019 case kShort_GrSLType: // fall through
Chris Daltonaf37a532017-10-24 11:17:38 -060020 case kInt_GrSLType:
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000021 return 0x3;
22 case kUShort_GrSLType: // fall through
Brian Salomonfa26e662016-11-14 11:27:00 -050023 case kUint_GrSLType:
24 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040025 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040026 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050027 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040028 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040029 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050030 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040031 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040032 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050033 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040034 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040035 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050036 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040037 case kUint2_GrSLType:
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000038 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040039 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050040 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040041 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050042 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040043 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050044 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040045 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040046 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050047 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040048 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040049 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050050 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040052 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050053 return 0xF;
54
55 // This query is only valid for certain types.
56 case kVoid_GrSLType:
57 case kBool_GrSLType:
58 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -050059 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050060 case kTextureExternalSampler_GrSLType:
61 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -070062 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050063 case kTexture2D_GrSLType:
64 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -050065 case kImageStorage2D_GrSLType:
66 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050067 break;
68 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040069 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -050070 return 0;
Greg Daniel164a9f02016-02-22 09:56:40 -050071}
72
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000073/** Returns the size in bytes taken up in vulkanbuffers for floating point GrSLTypes.
74 For non floating point type returns 0. Currently this reflects the std140 alignment
75 so a float2x2 takes up 8 floats. */
egdaniel4ee1cda2016-02-26 08:18:49 -080076static inline uint32_t grsltype_to_vk_size(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050077 switch(type) {
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000078 case kShort_GrSLType: // fall through
Brian Salomonfa26e662016-11-14 11:27:00 -050079 case kInt_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050080 return sizeof(int32_t);
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000081 case kUShort_GrSLType: // fall through
Brian Salomonfa26e662016-11-14 11:27:00 -050082 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050083 return sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040084 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040085 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050086 return sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040087 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040088 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050089 return 2 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040090 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040091 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050092 return 3 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040093 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040094 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050095 return 4 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040096 case kUint2_GrSLType:
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000097 return 2 * sizeof(uint16_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -040098 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050099 return 2 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400100 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500101 return 3 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400102 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500103 return 4 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400104 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400105 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500106 //TODO: this will be 4 * szof(float) on std430.
107 return 8 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400108 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400109 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500110 return 12 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400111 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400112 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500113 return 16 * sizeof(float);
egdaniel4ee1cda2016-02-26 08:18:49 -0800114
Brian Salomonfa26e662016-11-14 11:27:00 -0500115 // This query is only valid for certain types.
116 case kVoid_GrSLType:
117 case kBool_GrSLType:
118 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500119 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500120 case kTextureExternalSampler_GrSLType:
121 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700122 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500123 case kTexture2D_GrSLType:
124 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500125 case kImageStorage2D_GrSLType:
126 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500127 break;
128 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400129 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500130 return 0;
egdaniel4ee1cda2016-02-26 08:18:49 -0800131}
132
133
Greg Daniel164a9f02016-02-22 09:56:40 -0500134// Given the current offset into the ubo, calculate the offset for the uniform we're trying to add
135// taking into consideration all alignment requirements. The uniformOffset is set to the offset for
136// the new uniform, and currentOffset is updated to be the offset to the end of the new uniform.
137void get_ubo_aligned_offset(uint32_t* uniformOffset,
138 uint32_t* currentOffset,
139 GrSLType type,
140 int arrayCount) {
141 uint32_t alignmentMask = grsltype_to_alignment_mask(type);
egdaniel4ee1cda2016-02-26 08:18:49 -0800142 // We want to use the std140 layout here, so we must make arrays align to 16 bytes.
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400143 if (arrayCount || type == kFloat2x2_GrSLType) {
egdaniel4ee1cda2016-02-26 08:18:49 -0800144 alignmentMask = 0xF;
145 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500146 uint32_t offsetDiff = *currentOffset & alignmentMask;
147 if (offsetDiff != 0) {
148 offsetDiff = alignmentMask - offsetDiff + 1;
149 }
150 *uniformOffset = *currentOffset + offsetDiff;
151 SkASSERT(sizeof(float) == 4);
egdaniel4ee1cda2016-02-26 08:18:49 -0800152 if (arrayCount) {
153 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type));
154 SkASSERT(0 == (elementSize & 0xF));
155 *currentOffset = *uniformOffset + elementSize * arrayCount;
156 } else {
157 *currentOffset = *uniformOffset + grsltype_to_vk_size(type);
158 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500159}
160
161GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
162 uint32_t visibility,
163 GrSLType type,
164 GrSLPrecision precision,
165 const char* name,
166 bool mangleName,
167 int arrayCount,
168 const char** outName) {
169 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400170 // For now asserting the the visibility is either geometry types (vertex, tesselation, geometry,
171 // etc.) or only fragment.
172 SkASSERT(kVertex_GrShaderFlag == visibility ||
173 kGeometry_GrShaderFlag == visibility ||
174 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == visibility ||
175 kFragment_GrShaderFlag == visibility);
Greg Daniel164a9f02016-02-22 09:56:40 -0500176 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
egdaniel09aa1fc2016-04-20 07:09:46 -0700177 GrSLTypeIsFloatType(type);
Greg Daniel164a9f02016-02-22 09:56:40 -0500178
179 UniformInfo& uni = fUniforms.push_back();
180 uni.fVariable.setType(type);
181 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
182 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
183 // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
184 // the names will mismatch. I think the correct solution is to have all GPs which need the
185 // uniform view matrix, they should upload the view matrix in their setData along with regular
186 // uniforms.
187 char prefix = 'u';
188 if ('u' == name[0]) {
189 prefix = '\0';
190 }
191 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
192 uni.fVariable.setArrayCount(arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500193 uni.fVisibility = visibility;
194 uni.fVariable.setPrecision(precision);
egdaniel09aa1fc2016-04-20 07:09:46 -0700195 // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
196 // we set the modifier to none for all uniforms declared inside the block.
Brian Salomon99938a82016-11-21 13:41:08 -0500197 uni.fVariable.setTypeModifier(GrShaderVar::kNone_TypeModifier);
Greg Daniel164a9f02016-02-22 09:56:40 -0500198
Greg Daniel18f96022017-05-04 15:09:03 -0400199 uint32_t* currentOffset;
200 uint32_t geomStages = kVertex_GrShaderFlag | kGeometry_GrShaderFlag;
201 if (geomStages & visibility) {
202 currentOffset = &fCurrentGeometryUBOOffset;
203 } else {
204 SkASSERT(kFragment_GrShaderFlag == visibility);
205 currentOffset = &fCurrentFragmentUBOOffset;
206 }
egdaniel09aa1fc2016-04-20 07:09:46 -0700207 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500208
Greg Danieldbd44c72017-01-24 15:12:12 -0500209 SkString layoutQualifier;
210 layoutQualifier.appendf("offset=%d", uni.fUBOffset);
211 uni.fVariable.addLayoutQualifier(layoutQualifier.c_str());
212
egdaniel09aa1fc2016-04-20 07:09:46 -0700213 if (outName) {
214 *outName = uni.fVariable.c_str();
Greg Daniel164a9f02016-02-22 09:56:40 -0500215 }
216
217 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
218}
219
Brian Salomon101b8442016-11-18 11:58:54 -0500220GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(uint32_t visibility,
221 GrSwizzle swizzle,
222 GrSLType type,
223 GrSLPrecision precision,
224 const char* name) {
egdaniel09aa1fc2016-04-20 07:09:46 -0700225 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400226 // For now asserting the the visibility is either only vertex, geometry, or fragment
227 SkASSERT(kVertex_GrShaderFlag == visibility ||
228 kFragment_GrShaderFlag == visibility ||
229 kGeometry_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700230 SkString mangleName;
231 char prefix = 'u';
232 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
Brian Salomon101b8442016-11-18 11:58:54 -0500233
234 UniformInfo& info = fSamplers.push_back();
235 SkASSERT(GrSLTypeIsCombinedSamplerType(type));
236 info.fVariable.setType(type);
Brian Salomon99938a82016-11-21 13:41:08 -0500237 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
Brian Salomon101b8442016-11-18 11:58:54 -0500238 info.fVariable.setPrecision(precision);
239 info.fVariable.setName(mangleName);
240 SkString layoutQualifier;
241 layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1);
Brian Salomon60397682016-11-22 15:06:46 -0500242 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
Brian Salomon101b8442016-11-18 11:58:54 -0500243 info.fVisibility = visibility;
244 info.fUBOffset = 0;
245 fSamplerSwizzles.push_back(swizzle);
246 SkASSERT(fSamplerSwizzles.count() == fSamplers.count());
egdaniel09aa1fc2016-04-20 07:09:46 -0700247 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
248}
249
Greg Daniel31ec1442017-05-08 10:30:59 -0400250GrGLSLUniformHandler::TexelBufferHandle GrVkUniformHandler::addTexelBuffer(uint32_t visibility,
251 GrSLPrecision precision,
252 const char* name) {
253 SkASSERT(name && strlen(name));
Greg Danielaa352de2017-07-17 09:05:16 -0400254 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag |
255 kGeometry_GrShaderFlag |
256 kFragment_GrShaderFlag);
Greg Daniel31ec1442017-05-08 10:30:59 -0400257 SkASSERT(0 == (~kVisMask & visibility));
258 SkASSERT(0 != visibility);
259 SkString mangleName;
260 char prefix = 'u';
261 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
262
263 UniformInfo& info = fTexelBuffers.push_back();
264 info.fVariable.setType(kBufferSampler_GrSLType);
265 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
266 info.fVariable.setPrecision(precision);
267 info.fVariable.setName(mangleName);
268 SkString layoutQualifier;
269 layoutQualifier.appendf("set=%d, binding=%d", kTexelBufferDescSet, fTexelBuffers.count()- 1);
270 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
271 info.fVisibility = visibility;
272 info.fUBOffset = 0;
273 return GrGLSLUniformHandler::TexelBufferHandle(fTexelBuffers.count() - 1);
274}
275
Greg Daniel164a9f02016-02-22 09:56:40 -0500276void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
Greg Daniel18f96022017-05-04 15:09:03 -0400277 SkASSERT(kVertex_GrShaderFlag == visibility ||
278 kGeometry_GrShaderFlag == visibility ||
279 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700280
281 for (int i = 0; i < fSamplers.count(); ++i) {
Brian Salomon101b8442016-11-18 11:58:54 -0500282 const UniformInfo& sampler = fSamplers[i];
283 SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType);
284 if (visibility == sampler.fVisibility) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500285 sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
egdaniel09aa1fc2016-04-20 07:09:46 -0700286 out->append(";\n");
287 }
288 }
289
Greg Daniel31ec1442017-05-08 10:30:59 -0400290 for (int i = 0; i < fTexelBuffers.count(); ++i) {
291 const UniformInfo& texelBuffer = fTexelBuffers[i];
292 if (visibility == texelBuffer.fVisibility) {
293 texelBuffer.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
294 out->append(";\n");
295 }
296 }
297
Greg Danielaa352de2017-07-17 09:05:16 -0400298#ifdef SK_DEBUG
299 bool firstGeomOffsetCheck = false;
300 bool firstFragOffsetCheck = false;
301 for (int i = 0; i < fUniforms.count(); ++i) {
302 const UniformInfo& localUniform = fUniforms[i];
303 if (kVertex_GrShaderFlag == localUniform.fVisibility ||
304 kGeometry_GrShaderFlag == localUniform.fVisibility ||
305 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == localUniform.fVisibility) {
306 if (!firstGeomOffsetCheck) {
307 // Check to make sure we are starting our offset at 0 so the offset qualifier we
308 // set on each variable in the uniform block is valid.
309 SkASSERT(0 == localUniform.fUBOffset);
310 firstGeomOffsetCheck = true;
311 }
312 } else {
313 SkASSERT(kFragment_GrShaderFlag == localUniform.fVisibility);
314 if (!firstFragOffsetCheck) {
315 // Check to make sure we are starting our offset at 0 so the offset qualifier we
316 // set on each variable in the uniform block is valid.
317 SkASSERT(0 == localUniform.fUBOffset);
318 firstFragOffsetCheck = true;
319 }
320 }
321 }
322#endif
323
egdaniel09aa1fc2016-04-20 07:09:46 -0700324 SkString uniformsString;
Greg Daniel164a9f02016-02-22 09:56:40 -0500325 for (int i = 0; i < fUniforms.count(); ++i) {
326 const UniformInfo& localUniform = fUniforms[i];
Greg Daniel18f96022017-05-04 15:09:03 -0400327 if (visibility & localUniform.fVisibility) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500328 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500329 localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
Greg Daniel164a9f02016-02-22 09:56:40 -0500330 uniformsString.append(";\n");
Greg Daniel164a9f02016-02-22 09:56:40 -0500331 }
332 }
333 }
Greg Danielaa352de2017-07-17 09:05:16 -0400334
Greg Daniel164a9f02016-02-22 09:56:40 -0500335 if (!uniformsString.isEmpty()) {
Greg Daniel18f96022017-05-04 15:09:03 -0400336 uint32_t uniformBinding;
337 const char* stage;
338 if (kVertex_GrShaderFlag == visibility) {
339 uniformBinding = kGeometryBinding;
340 stage = "vertex";
341 } else if (kGeometry_GrShaderFlag == visibility) {
342 uniformBinding = kGeometryBinding;
343 stage = "geometry";
344 } else {
345 SkASSERT(kFragment_GrShaderFlag == visibility);
346 uniformBinding = kFragBinding;
347 stage = "fragment";
348 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500349 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
350 kUniformBufferDescSet, uniformBinding, stage);
351 out->appendf("%s\n};\n", uniformsString.c_str());
352 }
egdaniel4ee1cda2016-02-26 08:18:49 -0800353}