blob: d9c25198a946c6b28e4cd15bebe361a28bfd89a8 [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:
Brian Salomonf9f45122016-11-29 11:59:17 -050075 case kImageStorage2D_GrSLType:
76 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050077 break;
78 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040079 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -050080 return 0;
Greg Daniel164a9f02016-02-22 09:56:40 -050081}
82
Chris Dalton51ebd662017-10-24 16:10:48 -060083/** Returns the size in bytes taken up in vulkanbuffers for GrSLTypes. */
egdaniel4ee1cda2016-02-26 08:18:49 -080084static inline uint32_t grsltype_to_vk_size(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050085 switch(type) {
Chris Dalton51ebd662017-10-24 16:10:48 -060086 case kShort_GrSLType:
87 return sizeof(int16_t);
88 case kShort2_GrSLType:
89 return 2 * sizeof(int16_t);
90 case kShort3_GrSLType:
91 return 3 * sizeof(int16_t);
92 case kShort4_GrSLType:
93 return 4 * sizeof(int16_t);
94 case kUShort_GrSLType:
95 return sizeof(uint16_t);
96 case kUShort2_GrSLType:
97 return 2 * sizeof(uint16_t);
98 case kUShort3_GrSLType:
99 return 3 * sizeof(uint16_t);
100 case kUShort4_GrSLType:
101 return 4 * sizeof(uint16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500102 case kInt_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500103 return sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500104 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500105 return sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400106 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400107 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500108 return sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400109 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400110 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500111 return 2 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400112 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400113 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500114 return 3 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400115 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400116 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500117 return 4 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400118 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -0600119 return 2 * sizeof(uint32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400120 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500121 return 2 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400122 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500123 return 3 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400124 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500125 return 4 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400126 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400127 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500128 //TODO: this will be 4 * szof(float) on std430.
129 return 8 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400130 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400131 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500132 return 12 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400133 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400134 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500135 return 16 * sizeof(float);
egdaniel4ee1cda2016-02-26 08:18:49 -0800136
Brian Salomonfa26e662016-11-14 11:27:00 -0500137 // This query is only valid for certain types.
138 case kVoid_GrSLType:
139 case kBool_GrSLType:
140 case kTexture2DSampler_GrSLType:
Brian Salomona8f00022016-11-16 12:55:57 -0500141 case kITexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500142 case kTextureExternalSampler_GrSLType:
143 case kTexture2DRectSampler_GrSLType:
csmartdalton22458032016-11-16 11:28:16 -0700144 case kBufferSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500145 case kTexture2D_GrSLType:
146 case kSampler_GrSLType:
Brian Salomonf9f45122016-11-29 11:59:17 -0500147 case kImageStorage2D_GrSLType:
148 case kIImageStorage2D_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500149 break;
150 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400151 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500152 return 0;
egdaniel4ee1cda2016-02-26 08:18:49 -0800153}
154
155
Greg Daniel164a9f02016-02-22 09:56:40 -0500156// Given the current offset into the ubo, calculate the offset for the uniform we're trying to add
157// taking into consideration all alignment requirements. The uniformOffset is set to the offset for
158// the new uniform, and currentOffset is updated to be the offset to the end of the new uniform.
159void get_ubo_aligned_offset(uint32_t* uniformOffset,
160 uint32_t* currentOffset,
161 GrSLType type,
162 int arrayCount) {
163 uint32_t alignmentMask = grsltype_to_alignment_mask(type);
egdaniel4ee1cda2016-02-26 08:18:49 -0800164 // We want to use the std140 layout here, so we must make arrays align to 16 bytes.
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400165 if (arrayCount || type == kFloat2x2_GrSLType) {
egdaniel4ee1cda2016-02-26 08:18:49 -0800166 alignmentMask = 0xF;
167 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500168 uint32_t offsetDiff = *currentOffset & alignmentMask;
169 if (offsetDiff != 0) {
170 offsetDiff = alignmentMask - offsetDiff + 1;
171 }
172 *uniformOffset = *currentOffset + offsetDiff;
173 SkASSERT(sizeof(float) == 4);
egdaniel4ee1cda2016-02-26 08:18:49 -0800174 if (arrayCount) {
175 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type));
176 SkASSERT(0 == (elementSize & 0xF));
177 *currentOffset = *uniformOffset + elementSize * arrayCount;
178 } else {
179 *currentOffset = *uniformOffset + grsltype_to_vk_size(type);
180 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500181}
182
183GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
184 uint32_t visibility,
185 GrSLType type,
186 GrSLPrecision precision,
187 const char* name,
188 bool mangleName,
189 int arrayCount,
190 const char** outName) {
191 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400192 // For now asserting the the visibility is either geometry types (vertex, tesselation, geometry,
193 // etc.) or only fragment.
194 SkASSERT(kVertex_GrShaderFlag == visibility ||
195 kGeometry_GrShaderFlag == visibility ||
196 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == visibility ||
197 kFragment_GrShaderFlag == visibility);
Greg Daniel164a9f02016-02-22 09:56:40 -0500198 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
egdaniel09aa1fc2016-04-20 07:09:46 -0700199 GrSLTypeIsFloatType(type);
Greg Daniel164a9f02016-02-22 09:56:40 -0500200
201 UniformInfo& uni = fUniforms.push_back();
202 uni.fVariable.setType(type);
203 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
204 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
205 // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
206 // the names will mismatch. I think the correct solution is to have all GPs which need the
207 // uniform view matrix, they should upload the view matrix in their setData along with regular
208 // uniforms.
209 char prefix = 'u';
210 if ('u' == name[0]) {
211 prefix = '\0';
212 }
213 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
214 uni.fVariable.setArrayCount(arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500215 uni.fVisibility = visibility;
216 uni.fVariable.setPrecision(precision);
egdaniel09aa1fc2016-04-20 07:09:46 -0700217 // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
218 // we set the modifier to none for all uniforms declared inside the block.
Brian Salomon99938a82016-11-21 13:41:08 -0500219 uni.fVariable.setTypeModifier(GrShaderVar::kNone_TypeModifier);
Greg Daniel164a9f02016-02-22 09:56:40 -0500220
Greg Daniel18f96022017-05-04 15:09:03 -0400221 uint32_t* currentOffset;
222 uint32_t geomStages = kVertex_GrShaderFlag | kGeometry_GrShaderFlag;
223 if (geomStages & visibility) {
224 currentOffset = &fCurrentGeometryUBOOffset;
225 } else {
226 SkASSERT(kFragment_GrShaderFlag == visibility);
227 currentOffset = &fCurrentFragmentUBOOffset;
228 }
egdaniel09aa1fc2016-04-20 07:09:46 -0700229 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500230
Greg Danieldbd44c72017-01-24 15:12:12 -0500231 SkString layoutQualifier;
232 layoutQualifier.appendf("offset=%d", uni.fUBOffset);
233 uni.fVariable.addLayoutQualifier(layoutQualifier.c_str());
234
egdaniel09aa1fc2016-04-20 07:09:46 -0700235 if (outName) {
236 *outName = uni.fVariable.c_str();
Greg Daniel164a9f02016-02-22 09:56:40 -0500237 }
238
239 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
240}
241
Brian Salomon101b8442016-11-18 11:58:54 -0500242GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(uint32_t visibility,
243 GrSwizzle swizzle,
244 GrSLType type,
245 GrSLPrecision precision,
246 const char* name) {
egdaniel09aa1fc2016-04-20 07:09:46 -0700247 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400248 // For now asserting the the visibility is either only vertex, geometry, or fragment
249 SkASSERT(kVertex_GrShaderFlag == visibility ||
250 kFragment_GrShaderFlag == visibility ||
251 kGeometry_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700252 SkString mangleName;
253 char prefix = 'u';
254 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
Brian Salomon101b8442016-11-18 11:58:54 -0500255
256 UniformInfo& info = fSamplers.push_back();
257 SkASSERT(GrSLTypeIsCombinedSamplerType(type));
258 info.fVariable.setType(type);
Brian Salomon99938a82016-11-21 13:41:08 -0500259 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
Brian Salomon101b8442016-11-18 11:58:54 -0500260 info.fVariable.setPrecision(precision);
261 info.fVariable.setName(mangleName);
262 SkString layoutQualifier;
263 layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1);
Brian Salomon60397682016-11-22 15:06:46 -0500264 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
Brian Salomon101b8442016-11-18 11:58:54 -0500265 info.fVisibility = visibility;
266 info.fUBOffset = 0;
267 fSamplerSwizzles.push_back(swizzle);
268 SkASSERT(fSamplerSwizzles.count() == fSamplers.count());
egdaniel09aa1fc2016-04-20 07:09:46 -0700269 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
270}
271
Greg Daniel31ec1442017-05-08 10:30:59 -0400272GrGLSLUniformHandler::TexelBufferHandle GrVkUniformHandler::addTexelBuffer(uint32_t visibility,
273 GrSLPrecision precision,
274 const char* name) {
275 SkASSERT(name && strlen(name));
Greg Danielaa352de2017-07-17 09:05:16 -0400276 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag |
277 kGeometry_GrShaderFlag |
278 kFragment_GrShaderFlag);
Greg Daniel31ec1442017-05-08 10:30:59 -0400279 SkASSERT(0 == (~kVisMask & visibility));
280 SkASSERT(0 != visibility);
281 SkString mangleName;
282 char prefix = 'u';
283 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
284
285 UniformInfo& info = fTexelBuffers.push_back();
286 info.fVariable.setType(kBufferSampler_GrSLType);
287 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
288 info.fVariable.setPrecision(precision);
289 info.fVariable.setName(mangleName);
290 SkString layoutQualifier;
291 layoutQualifier.appendf("set=%d, binding=%d", kTexelBufferDescSet, fTexelBuffers.count()- 1);
292 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
293 info.fVisibility = visibility;
294 info.fUBOffset = 0;
295 return GrGLSLUniformHandler::TexelBufferHandle(fTexelBuffers.count() - 1);
296}
297
Greg Daniel164a9f02016-02-22 09:56:40 -0500298void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
Greg Daniel18f96022017-05-04 15:09:03 -0400299 SkASSERT(kVertex_GrShaderFlag == visibility ||
300 kGeometry_GrShaderFlag == visibility ||
301 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700302
303 for (int i = 0; i < fSamplers.count(); ++i) {
Brian Salomon101b8442016-11-18 11:58:54 -0500304 const UniformInfo& sampler = fSamplers[i];
305 SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType);
306 if (visibility == sampler.fVisibility) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500307 sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
egdaniel09aa1fc2016-04-20 07:09:46 -0700308 out->append(";\n");
309 }
310 }
311
Greg Daniel31ec1442017-05-08 10:30:59 -0400312 for (int i = 0; i < fTexelBuffers.count(); ++i) {
313 const UniformInfo& texelBuffer = fTexelBuffers[i];
314 if (visibility == texelBuffer.fVisibility) {
315 texelBuffer.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
316 out->append(";\n");
317 }
318 }
319
Greg Danielaa352de2017-07-17 09:05:16 -0400320#ifdef SK_DEBUG
321 bool firstGeomOffsetCheck = false;
322 bool firstFragOffsetCheck = false;
323 for (int i = 0; i < fUniforms.count(); ++i) {
324 const UniformInfo& localUniform = fUniforms[i];
325 if (kVertex_GrShaderFlag == localUniform.fVisibility ||
326 kGeometry_GrShaderFlag == localUniform.fVisibility ||
327 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == localUniform.fVisibility) {
328 if (!firstGeomOffsetCheck) {
329 // Check to make sure we are starting our offset at 0 so the offset qualifier we
330 // set on each variable in the uniform block is valid.
331 SkASSERT(0 == localUniform.fUBOffset);
332 firstGeomOffsetCheck = true;
333 }
334 } else {
335 SkASSERT(kFragment_GrShaderFlag == localUniform.fVisibility);
336 if (!firstFragOffsetCheck) {
337 // Check to make sure we are starting our offset at 0 so the offset qualifier we
338 // set on each variable in the uniform block is valid.
339 SkASSERT(0 == localUniform.fUBOffset);
340 firstFragOffsetCheck = true;
341 }
342 }
343 }
344#endif
345
egdaniel09aa1fc2016-04-20 07:09:46 -0700346 SkString uniformsString;
Greg Daniel164a9f02016-02-22 09:56:40 -0500347 for (int i = 0; i < fUniforms.count(); ++i) {
348 const UniformInfo& localUniform = fUniforms[i];
Greg Daniel18f96022017-05-04 15:09:03 -0400349 if (visibility & localUniform.fVisibility) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500350 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500351 localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
Greg Daniel164a9f02016-02-22 09:56:40 -0500352 uniformsString.append(";\n");
Greg Daniel164a9f02016-02-22 09:56:40 -0500353 }
354 }
355 }
Greg Danielaa352de2017-07-17 09:05:16 -0400356
Greg Daniel164a9f02016-02-22 09:56:40 -0500357 if (!uniformsString.isEmpty()) {
Greg Daniel18f96022017-05-04 15:09:03 -0400358 uint32_t uniformBinding;
359 const char* stage;
360 if (kVertex_GrShaderFlag == visibility) {
361 uniformBinding = kGeometryBinding;
362 stage = "vertex";
363 } else if (kGeometry_GrShaderFlag == visibility) {
364 uniformBinding = kGeometryBinding;
365 stage = "geometry";
366 } else {
367 SkASSERT(kFragment_GrShaderFlag == visibility);
368 uniformBinding = kFragBinding;
369 stage = "fragment";
370 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500371 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
372 kUniformBufferDescSet, uniformBinding, stage);
373 out->appendf("%s\n};\n", uniformsString.c_str());
374 }
egdaniel4ee1cda2016-02-26 08:18:49 -0800375}