blob: e76cbda9597b26ea9c42a38a54d6fb0abc70bca6 [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).
Chris Dalton51ebd662017-10-24 16:10:48 -060017// These are designated in the Vulkan spec, section 14.5.4 "Offset and Stride Assignment".
18// https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/html/vkspec.html#interfaces-resources-layout
Greg Daniel164a9f02016-02-22 09:56:40 -050019uint32_t grsltype_to_alignment_mask(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050020 switch(type) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -040021 case kShort_GrSLType: // fall through
Chris Dalton51ebd662017-10-24 16:10:48 -060022 case kUShort_GrSLType:
23 return 0x1;
24 case kShort2_GrSLType: // fall through
25 case kUShort2_GrSLType:
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000026 return 0x3;
Chris Dalton51ebd662017-10-24 16:10:48 -060027 case kShort3_GrSLType: // fall through
28 case kShort4_GrSLType:
29 case kUShort3_GrSLType:
30 case kUShort4_GrSLType:
31 return 0x7;
32 case kInt_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050033 case kUint_GrSLType:
34 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040035 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040036 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050037 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040038 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040039 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050040 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040041 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040042 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050043 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040044 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040045 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050046 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040047 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -060048 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040049 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050050 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050052 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040053 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050054 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040055 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040056 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050057 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040058 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040059 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050060 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040061 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040062 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050063 return 0xF;
64
65 // This query is only valid for certain types.
66 case kVoid_GrSLType:
67 case kBool_GrSLType:
68 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -050069 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050070 case kTextureExternalSampler_GrSLType:
71 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -070072 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050073 case kTexture2D_GrSLType:
74 case kSampler_GrSLType:
75 break;
76 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040077 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -050078 return 0;
Greg Daniel164a9f02016-02-22 09:56:40 -050079}
80
Chris Dalton51ebd662017-10-24 16:10:48 -060081/** Returns the size in bytes taken up in vulkanbuffers for GrSLTypes. */
egdaniel4ee1cda2016-02-26 08:18:49 -080082static inline uint32_t grsltype_to_vk_size(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050083 switch(type) {
Chris Dalton51ebd662017-10-24 16:10:48 -060084 case kShort_GrSLType:
85 return sizeof(int16_t);
86 case kShort2_GrSLType:
87 return 2 * sizeof(int16_t);
88 case kShort3_GrSLType:
89 return 3 * sizeof(int16_t);
90 case kShort4_GrSLType:
91 return 4 * sizeof(int16_t);
92 case kUShort_GrSLType:
93 return sizeof(uint16_t);
94 case kUShort2_GrSLType:
95 return 2 * sizeof(uint16_t);
96 case kUShort3_GrSLType:
97 return 3 * sizeof(uint16_t);
98 case kUShort4_GrSLType:
99 return 4 * sizeof(uint16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500100 case kInt_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500101 return sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500102 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500103 return sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400104 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400105 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500106 return sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400107 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400108 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500109 return 2 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400110 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400111 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500112 return 3 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400113 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400114 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500115 return 4 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400116 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -0600117 return 2 * sizeof(uint32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400118 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500119 return 2 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400120 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500121 return 3 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400122 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500123 return 4 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400124 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400125 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500126 //TODO: this will be 4 * szof(float) on std430.
127 return 8 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400128 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400129 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500130 return 12 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400131 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400132 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500133 return 16 * sizeof(float);
egdaniel4ee1cda2016-02-26 08:18:49 -0800134
Brian Salomonfa26e662016-11-14 11:27:00 -0500135 // This query is only valid for certain types.
136 case kVoid_GrSLType:
137 case kBool_GrSLType:
138 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500139 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500140 case kTextureExternalSampler_GrSLType:
141 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700142 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500143 case kTexture2D_GrSLType:
144 case kSampler_GrSLType:
145 break;
146 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400147 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500148 return 0;
egdaniel4ee1cda2016-02-26 08:18:49 -0800149}
150
151
Greg Daniel164a9f02016-02-22 09:56:40 -0500152// Given the current offset into the ubo, calculate the offset for the uniform we're trying to add
153// taking into consideration all alignment requirements. The uniformOffset is set to the offset for
154// the new uniform, and currentOffset is updated to be the offset to the end of the new uniform.
155void get_ubo_aligned_offset(uint32_t* uniformOffset,
156 uint32_t* currentOffset,
157 GrSLType type,
158 int arrayCount) {
159 uint32_t alignmentMask = grsltype_to_alignment_mask(type);
egdaniel4ee1cda2016-02-26 08:18:49 -0800160 // We want to use the std140 layout here, so we must make arrays align to 16 bytes.
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400161 if (arrayCount || type == kFloat2x2_GrSLType) {
egdaniel4ee1cda2016-02-26 08:18:49 -0800162 alignmentMask = 0xF;
163 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500164 uint32_t offsetDiff = *currentOffset & alignmentMask;
165 if (offsetDiff != 0) {
166 offsetDiff = alignmentMask - offsetDiff + 1;
167 }
168 *uniformOffset = *currentOffset + offsetDiff;
169 SkASSERT(sizeof(float) == 4);
egdaniel4ee1cda2016-02-26 08:18:49 -0800170 if (arrayCount) {
171 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type));
172 SkASSERT(0 == (elementSize & 0xF));
173 *currentOffset = *uniformOffset + elementSize * arrayCount;
174 } else {
175 *currentOffset = *uniformOffset + grsltype_to_vk_size(type);
176 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500177}
178
179GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
180 uint32_t visibility,
181 GrSLType type,
182 GrSLPrecision precision,
183 const char* name,
184 bool mangleName,
185 int arrayCount,
186 const char** outName) {
187 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400188 // For now asserting the the visibility is either geometry types (vertex, tesselation, geometry,
189 // etc.) or only fragment.
190 SkASSERT(kVertex_GrShaderFlag == visibility ||
191 kGeometry_GrShaderFlag == visibility ||
192 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == visibility ||
193 kFragment_GrShaderFlag == visibility);
Greg Daniel164a9f02016-02-22 09:56:40 -0500194 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
egdaniel09aa1fc2016-04-20 07:09:46 -0700195 GrSLTypeIsFloatType(type);
Greg Daniel164a9f02016-02-22 09:56:40 -0500196
197 UniformInfo& uni = fUniforms.push_back();
198 uni.fVariable.setType(type);
199 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
200 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
201 // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
202 // the names will mismatch. I think the correct solution is to have all GPs which need the
203 // uniform view matrix, they should upload the view matrix in their setData along with regular
204 // uniforms.
205 char prefix = 'u';
Robert Phillipsfe8da172018-01-24 14:52:02 +0000206 if ('u' == name[0] || !strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX))) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500207 prefix = '\0';
208 }
209 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
210 uni.fVariable.setArrayCount(arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500211 uni.fVisibility = visibility;
212 uni.fVariable.setPrecision(precision);
egdaniel09aa1fc2016-04-20 07:09:46 -0700213 // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
214 // we set the modifier to none for all uniforms declared inside the block.
Brian Salomon99938a82016-11-21 13:41:08 -0500215 uni.fVariable.setTypeModifier(GrShaderVar::kNone_TypeModifier);
Greg Daniel164a9f02016-02-22 09:56:40 -0500216
Greg Daniel18f96022017-05-04 15:09:03 -0400217 uint32_t* currentOffset;
218 uint32_t geomStages = kVertex_GrShaderFlag | kGeometry_GrShaderFlag;
219 if (geomStages & visibility) {
220 currentOffset = &fCurrentGeometryUBOOffset;
221 } else {
222 SkASSERT(kFragment_GrShaderFlag == visibility);
223 currentOffset = &fCurrentFragmentUBOOffset;
224 }
egdaniel09aa1fc2016-04-20 07:09:46 -0700225 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500226
Greg Danieldbd44c72017-01-24 15:12:12 -0500227 SkString layoutQualifier;
228 layoutQualifier.appendf("offset=%d", uni.fUBOffset);
229 uni.fVariable.addLayoutQualifier(layoutQualifier.c_str());
230
egdaniel09aa1fc2016-04-20 07:09:46 -0700231 if (outName) {
232 *outName = uni.fVariable.c_str();
Greg Daniel164a9f02016-02-22 09:56:40 -0500233 }
234
235 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
236}
237
Brian Salomon101b8442016-11-18 11:58:54 -0500238GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(uint32_t visibility,
239 GrSwizzle swizzle,
240 GrSLType type,
241 GrSLPrecision precision,
242 const char* name) {
egdaniel09aa1fc2016-04-20 07:09:46 -0700243 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400244 // For now asserting the the visibility is either only vertex, geometry, or fragment
245 SkASSERT(kVertex_GrShaderFlag == visibility ||
246 kFragment_GrShaderFlag == visibility ||
247 kGeometry_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700248 SkString mangleName;
249 char prefix = 'u';
250 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
Brian Salomon101b8442016-11-18 11:58:54 -0500251
252 UniformInfo& info = fSamplers.push_back();
253 SkASSERT(GrSLTypeIsCombinedSamplerType(type));
254 info.fVariable.setType(type);
Brian Salomon99938a82016-11-21 13:41:08 -0500255 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
Brian Salomon101b8442016-11-18 11:58:54 -0500256 info.fVariable.setPrecision(precision);
257 info.fVariable.setName(mangleName);
258 SkString layoutQualifier;
259 layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1);
Brian Salomon60397682016-11-22 15:06:46 -0500260 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
Brian Salomon101b8442016-11-18 11:58:54 -0500261 info.fVisibility = visibility;
262 info.fUBOffset = 0;
263 fSamplerSwizzles.push_back(swizzle);
264 SkASSERT(fSamplerSwizzles.count() == fSamplers.count());
egdaniel09aa1fc2016-04-20 07:09:46 -0700265 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
266}
267
Greg Daniel31ec1442017-05-08 10:30:59 -0400268GrGLSLUniformHandler::TexelBufferHandle GrVkUniformHandler::addTexelBuffer(uint32_t visibility,
269 GrSLPrecision precision,
270 const char* name) {
271 SkASSERT(name && strlen(name));
Greg Danielaa352de2017-07-17 09:05:16 -0400272 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag |
273 kGeometry_GrShaderFlag |
274 kFragment_GrShaderFlag);
Greg Daniel31ec1442017-05-08 10:30:59 -0400275 SkASSERT(0 == (~kVisMask & visibility));
276 SkASSERT(0 != visibility);
277 SkString mangleName;
278 char prefix = 'u';
279 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
280
281 UniformInfo& info = fTexelBuffers.push_back();
282 info.fVariable.setType(kBufferSampler_GrSLType);
283 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
284 info.fVariable.setPrecision(precision);
285 info.fVariable.setName(mangleName);
286 SkString layoutQualifier;
287 layoutQualifier.appendf("set=%d, binding=%d", kTexelBufferDescSet, fTexelBuffers.count()- 1);
288 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
289 info.fVisibility = visibility;
290 info.fUBOffset = 0;
291 return GrGLSLUniformHandler::TexelBufferHandle(fTexelBuffers.count() - 1);
292}
293
Greg Daniel164a9f02016-02-22 09:56:40 -0500294void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
Greg Daniel18f96022017-05-04 15:09:03 -0400295 SkASSERT(kVertex_GrShaderFlag == visibility ||
296 kGeometry_GrShaderFlag == visibility ||
297 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700298
299 for (int i = 0; i < fSamplers.count(); ++i) {
Brian Salomon101b8442016-11-18 11:58:54 -0500300 const UniformInfo& sampler = fSamplers[i];
301 SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType);
302 if (visibility == sampler.fVisibility) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500303 sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
egdaniel09aa1fc2016-04-20 07:09:46 -0700304 out->append(";\n");
305 }
306 }
307
Greg Daniel31ec1442017-05-08 10:30:59 -0400308 for (int i = 0; i < fTexelBuffers.count(); ++i) {
309 const UniformInfo& texelBuffer = fTexelBuffers[i];
310 if (visibility == texelBuffer.fVisibility) {
311 texelBuffer.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
312 out->append(";\n");
313 }
314 }
315
Greg Danielaa352de2017-07-17 09:05:16 -0400316#ifdef SK_DEBUG
317 bool firstGeomOffsetCheck = false;
318 bool firstFragOffsetCheck = false;
319 for (int i = 0; i < fUniforms.count(); ++i) {
320 const UniformInfo& localUniform = fUniforms[i];
321 if (kVertex_GrShaderFlag == localUniform.fVisibility ||
322 kGeometry_GrShaderFlag == localUniform.fVisibility ||
323 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == localUniform.fVisibility) {
324 if (!firstGeomOffsetCheck) {
325 // Check to make sure we are starting our offset at 0 so the offset qualifier we
326 // set on each variable in the uniform block is valid.
327 SkASSERT(0 == localUniform.fUBOffset);
328 firstGeomOffsetCheck = true;
329 }
330 } else {
331 SkASSERT(kFragment_GrShaderFlag == localUniform.fVisibility);
332 if (!firstFragOffsetCheck) {
333 // Check to make sure we are starting our offset at 0 so the offset qualifier we
334 // set on each variable in the uniform block is valid.
335 SkASSERT(0 == localUniform.fUBOffset);
336 firstFragOffsetCheck = true;
337 }
338 }
339 }
340#endif
341
egdaniel09aa1fc2016-04-20 07:09:46 -0700342 SkString uniformsString;
Greg Daniel164a9f02016-02-22 09:56:40 -0500343 for (int i = 0; i < fUniforms.count(); ++i) {
344 const UniformInfo& localUniform = fUniforms[i];
Greg Daniel18f96022017-05-04 15:09:03 -0400345 if (visibility & localUniform.fVisibility) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500346 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500347 localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
Greg Daniel164a9f02016-02-22 09:56:40 -0500348 uniformsString.append(";\n");
Greg Daniel164a9f02016-02-22 09:56:40 -0500349 }
350 }
351 }
Greg Danielaa352de2017-07-17 09:05:16 -0400352
Greg Daniel164a9f02016-02-22 09:56:40 -0500353 if (!uniformsString.isEmpty()) {
Greg Daniel18f96022017-05-04 15:09:03 -0400354 uint32_t uniformBinding;
355 const char* stage;
356 if (kVertex_GrShaderFlag == visibility) {
357 uniformBinding = kGeometryBinding;
358 stage = "vertex";
359 } else if (kGeometry_GrShaderFlag == visibility) {
360 uniformBinding = kGeometryBinding;
361 stage = "geometry";
362 } else {
363 SkASSERT(kFragment_GrShaderFlag == visibility);
364 uniformBinding = kFragBinding;
365 stage = "fragment";
366 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500367 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
368 kUniformBufferDescSet, uniformBinding, stage);
369 out->appendf("%s\n};\n", uniformsString.c_str());
370 }
egdaniel4ee1cda2016-02-26 08:18:49 -0800371}