blob: 3a35cfcce8fc93aebed9b3d7c84b018ac988c0cf [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"
Greg Daniel9a51a862018-11-30 10:18:14 -05009
10#include "GrTexturePriv.h"
11#include "GrVkGpu.h"
12#include "GrVkPipelineStateBuilder.h"
13#include "GrVkTexture.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014#include "glsl/GrGLSLProgramBuilder.h"
15
16// To determine whether a current offset is aligned, we can just 'and' the lowest bits with the
17// alignment mask. A value of 0 means aligned, any other value is how many bytes past alignment we
18// are. This works since all alignments are powers of 2. The mask is always (alignment - 1).
egdaniel4ee1cda2016-02-26 08:18:49 -080019// This alignment mask will give correct alignments for using the std430 block layout. If you want
20// the std140 alignment, you can use this, but then make sure if you have an array type it is
21// aligned to 16 bytes (i.e. has mask of 0xF).
Chris Dalton51ebd662017-10-24 16:10:48 -060022// These are designated in the Vulkan spec, section 14.5.4 "Offset and Stride Assignment".
23// https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/html/vkspec.html#interfaces-resources-layout
Mike Kleindc735592018-10-11 14:26:30 -040024static uint32_t grsltype_to_alignment_mask(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050025 switch(type) {
Ruiqi Maob609e6d2018-07-17 10:19:38 -040026 case kByte_GrSLType: // fall through
27 case kUByte_GrSLType:
28 return 0x0;
29 case kByte2_GrSLType: // fall through
30 case kUByte2_GrSLType:
31 return 0x1;
32 case kByte3_GrSLType: // fall through
33 case kByte4_GrSLType:
34 case kUByte3_GrSLType:
35 case kUByte4_GrSLType:
36 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040037 case kShort_GrSLType: // fall through
Chris Dalton51ebd662017-10-24 16:10:48 -060038 case kUShort_GrSLType:
39 return 0x1;
40 case kShort2_GrSLType: // fall through
41 case kUShort2_GrSLType:
Chris Dalton6dd0d8a2017-10-24 19:53:13 +000042 return 0x3;
Chris Dalton51ebd662017-10-24 16:10:48 -060043 case kShort3_GrSLType: // fall through
44 case kShort4_GrSLType:
45 case kUShort3_GrSLType:
46 case kUShort4_GrSLType:
47 return 0x7;
48 case kInt_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050049 case kUint_GrSLType:
50 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040051 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040052 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050053 return 0x3;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040054 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040055 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050056 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040057 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040058 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050059 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040060 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040061 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050062 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040063 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -060064 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040065 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050066 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040067 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050068 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040069 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -050070 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040071 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040072 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050073 return 0x7;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040074 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040075 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050076 return 0xF;
Ethan Nicholasf7b88202017-09-18 14:10:39 -040077 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -040078 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050079 return 0xF;
80
81 // This query is only valid for certain types.
82 case kVoid_GrSLType:
83 case kBool_GrSLType:
84 case kTexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050085 case kTextureExternalSampler_GrSLType:
86 case kTexture2DRectSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -050087 break;
88 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040089 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -050090 return 0;
Greg Daniel164a9f02016-02-22 09:56:40 -050091}
92
Chris Dalton51ebd662017-10-24 16:10:48 -060093/** Returns the size in bytes taken up in vulkanbuffers for GrSLTypes. */
egdaniel4ee1cda2016-02-26 08:18:49 -080094static inline uint32_t grsltype_to_vk_size(GrSLType type) {
Brian Salomonfa26e662016-11-14 11:27:00 -050095 switch(type) {
Ruiqi Maob609e6d2018-07-17 10:19:38 -040096 case kByte_GrSLType:
97 return sizeof(int8_t);
98 case kByte2_GrSLType:
99 return 2 * sizeof(int8_t);
100 case kByte3_GrSLType:
101 return 3 * sizeof(int8_t);
102 case kByte4_GrSLType:
103 return 4 * sizeof(int8_t);
104 case kUByte_GrSLType:
105 return sizeof(uint8_t);
106 case kUByte2_GrSLType:
107 return 2 * sizeof(uint8_t);
108 case kUByte3_GrSLType:
109 return 3 * sizeof(uint8_t);
110 case kUByte4_GrSLType:
111 return 4 * sizeof(uint8_t);
Chris Dalton51ebd662017-10-24 16:10:48 -0600112 case kShort_GrSLType:
113 return sizeof(int16_t);
114 case kShort2_GrSLType:
115 return 2 * sizeof(int16_t);
116 case kShort3_GrSLType:
117 return 3 * sizeof(int16_t);
118 case kShort4_GrSLType:
119 return 4 * sizeof(int16_t);
120 case kUShort_GrSLType:
121 return sizeof(uint16_t);
122 case kUShort2_GrSLType:
123 return 2 * sizeof(uint16_t);
124 case kUShort3_GrSLType:
125 return 3 * sizeof(uint16_t);
126 case kUShort4_GrSLType:
127 return 4 * sizeof(uint16_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500128 case kInt_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500129 return sizeof(int32_t);
Brian Salomonfa26e662016-11-14 11:27:00 -0500130 case kUint_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500131 return sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400132 case kHalf_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400133 case kFloat_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500134 return sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400135 case kHalf2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400136 case kFloat2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500137 return 2 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400138 case kHalf3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400139 case kFloat3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500140 return 3 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400141 case kHalf4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400142 case kFloat4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500143 return 4 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400144 case kUint2_GrSLType:
Chris Dalton51ebd662017-10-24 16:10:48 -0600145 return 2 * sizeof(uint32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400146 case kInt2_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500147 return 2 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400148 case kInt3_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500149 return 3 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400150 case kInt4_GrSLType:
csmartdaltonb37cb232017-02-08 14:56:27 -0500151 return 4 * sizeof(int32_t);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400152 case kHalf2x2_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400153 case kFloat2x2_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500154 //TODO: this will be 4 * szof(float) on std430.
155 return 8 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400156 case kHalf3x3_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400157 case kFloat3x3_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500158 return 12 * sizeof(float);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400159 case kHalf4x4_GrSLType: // fall through
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400160 case kFloat4x4_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500161 return 16 * sizeof(float);
egdaniel4ee1cda2016-02-26 08:18:49 -0800162
Brian Salomonfa26e662016-11-14 11:27:00 -0500163 // This query is only valid for certain types.
164 case kVoid_GrSLType:
165 case kBool_GrSLType:
166 case kTexture2DSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500167 case kTextureExternalSampler_GrSLType:
168 case kTexture2DRectSampler_GrSLType:
Brian Salomonfa26e662016-11-14 11:27:00 -0500169 break;
170 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400171 SK_ABORT("Unexpected type");
Brian Salomonfa26e662016-11-14 11:27:00 -0500172 return 0;
egdaniel4ee1cda2016-02-26 08:18:49 -0800173}
174
175
Greg Daniel164a9f02016-02-22 09:56:40 -0500176// Given the current offset into the ubo, calculate the offset for the uniform we're trying to add
177// taking into consideration all alignment requirements. The uniformOffset is set to the offset for
178// the new uniform, and currentOffset is updated to be the offset to the end of the new uniform.
Mike Kleindc735592018-10-11 14:26:30 -0400179static void get_ubo_aligned_offset(uint32_t* uniformOffset,
180 uint32_t* currentOffset,
181 GrSLType type,
182 int arrayCount) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500183 uint32_t alignmentMask = grsltype_to_alignment_mask(type);
egdaniel4ee1cda2016-02-26 08:18:49 -0800184 // We want to use the std140 layout here, so we must make arrays align to 16 bytes.
Ethan Nicholas8aa45692017-09-20 11:24:15 -0400185 if (arrayCount || type == kFloat2x2_GrSLType) {
egdaniel4ee1cda2016-02-26 08:18:49 -0800186 alignmentMask = 0xF;
187 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500188 uint32_t offsetDiff = *currentOffset & alignmentMask;
189 if (offsetDiff != 0) {
190 offsetDiff = alignmentMask - offsetDiff + 1;
191 }
192 *uniformOffset = *currentOffset + offsetDiff;
193 SkASSERT(sizeof(float) == 4);
egdaniel4ee1cda2016-02-26 08:18:49 -0800194 if (arrayCount) {
195 uint32_t elementSize = SkTMax<uint32_t>(16, grsltype_to_vk_size(type));
196 SkASSERT(0 == (elementSize & 0xF));
197 *currentOffset = *uniformOffset + elementSize * arrayCount;
198 } else {
199 *currentOffset = *uniformOffset + grsltype_to_vk_size(type);
200 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500201}
202
203GrGLSLUniformHandler::UniformHandle GrVkUniformHandler::internalAddUniformArray(
204 uint32_t visibility,
205 GrSLType type,
206 GrSLPrecision precision,
207 const char* name,
208 bool mangleName,
209 int arrayCount,
210 const char** outName) {
211 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400212 // For now asserting the the visibility is either geometry types (vertex, tesselation, geometry,
213 // etc.) or only fragment.
214 SkASSERT(kVertex_GrShaderFlag == visibility ||
215 kGeometry_GrShaderFlag == visibility ||
216 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == visibility ||
217 kFragment_GrShaderFlag == visibility);
Greg Daniel164a9f02016-02-22 09:56:40 -0500218 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
egdaniel09aa1fc2016-04-20 07:09:46 -0700219 GrSLTypeIsFloatType(type);
Greg Daniel164a9f02016-02-22 09:56:40 -0500220
221 UniformInfo& uni = fUniforms.push_back();
222 uni.fVariable.setType(type);
223 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
224 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
225 // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
226 // the names will mismatch. I think the correct solution is to have all GPs which need the
227 // uniform view matrix, they should upload the view matrix in their setData along with regular
228 // uniforms.
229 char prefix = 'u';
Robert Phillipsfe8da172018-01-24 14:52:02 +0000230 if ('u' == name[0] || !strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX))) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500231 prefix = '\0';
232 }
233 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
234 uni.fVariable.setArrayCount(arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500235 uni.fVisibility = visibility;
236 uni.fVariable.setPrecision(precision);
egdaniel09aa1fc2016-04-20 07:09:46 -0700237 // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
238 // we set the modifier to none for all uniforms declared inside the block.
Brian Salomon99938a82016-11-21 13:41:08 -0500239 uni.fVariable.setTypeModifier(GrShaderVar::kNone_TypeModifier);
Greg Daniel164a9f02016-02-22 09:56:40 -0500240
Greg Daniel18f96022017-05-04 15:09:03 -0400241 uint32_t* currentOffset;
242 uint32_t geomStages = kVertex_GrShaderFlag | kGeometry_GrShaderFlag;
243 if (geomStages & visibility) {
244 currentOffset = &fCurrentGeometryUBOOffset;
245 } else {
246 SkASSERT(kFragment_GrShaderFlag == visibility);
247 currentOffset = &fCurrentFragmentUBOOffset;
248 }
egdaniel09aa1fc2016-04-20 07:09:46 -0700249 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500250
Greg Danieldbd44c72017-01-24 15:12:12 -0500251 SkString layoutQualifier;
252 layoutQualifier.appendf("offset=%d", uni.fUBOffset);
253 uni.fVariable.addLayoutQualifier(layoutQualifier.c_str());
254
egdaniel09aa1fc2016-04-20 07:09:46 -0700255 if (outName) {
256 *outName = uni.fVariable.c_str();
Greg Daniel164a9f02016-02-22 09:56:40 -0500257 }
258
259 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
260}
261
Greg Daniel9a51a862018-11-30 10:18:14 -0500262GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(const GrTexture* texture,
263 const GrSamplerState& state,
264 const char* name,
265 const GrShaderCaps* shaderCaps) {
egdaniel09aa1fc2016-04-20 07:09:46 -0700266 SkASSERT(name && strlen(name));
egdaniel09aa1fc2016-04-20 07:09:46 -0700267 SkString mangleName;
268 char prefix = 'u';
269 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
Brian Salomon101b8442016-11-18 11:58:54 -0500270
Greg Daniel9a51a862018-11-30 10:18:14 -0500271 GrSLPrecision precision = GrSLSamplerPrecision(texture->config());
272 GrSwizzle swizzle = shaderCaps->configTextureSwizzle(texture->config());
273 GrTextureType type = texture->texturePriv().textureType();
274
Brian Salomon101b8442016-11-18 11:58:54 -0500275 UniformInfo& info = fSamplers.push_back();
Brian Salomon60dd8c72018-07-30 10:24:13 -0400276 info.fVariable.setType(GrSLCombinedSamplerTypeForTextureType(type));
Brian Salomon99938a82016-11-21 13:41:08 -0500277 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
Brian Salomon101b8442016-11-18 11:58:54 -0500278 info.fVariable.setPrecision(precision);
279 info.fVariable.setName(mangleName);
280 SkString layoutQualifier;
281 layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1);
Brian Salomon60397682016-11-22 15:06:46 -0500282 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
Greg Daniel0f70be82018-10-08 17:35:08 +0000283 info.fVisibility = kFragment_GrShaderFlag;
Brian Salomon101b8442016-11-18 11:58:54 -0500284 info.fUBOffset = 0;
Greg Daniel9a51a862018-11-30 10:18:14 -0500285
286 // Check if we are dealing with an external texture and store the needed information if so
287 const GrVkTexture* vkTexture = static_cast<const GrVkTexture*>(texture);
288 if (vkTexture->ycbcrConversionInfo().isValid()) {
289 SkASSERT(type == GrTextureType::kExternal);
290 GrVkGpu* gpu = static_cast<GrVkPipelineStateBuilder*>(fProgramBuilder)->gpu();
291 info.fImmutableSampler = gpu->resourceProvider().findOrCreateCompatibleSampler(
292 state, vkTexture->ycbcrConversionInfo());
293 SkASSERT(info.fImmutableSampler);
294 }
295
Brian Salomon101b8442016-11-18 11:58:54 -0500296 fSamplerSwizzles.push_back(swizzle);
297 SkASSERT(fSamplerSwizzles.count() == fSamplers.count());
egdaniel09aa1fc2016-04-20 07:09:46 -0700298 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
299}
300
Greg Daniel164a9f02016-02-22 09:56:40 -0500301void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
Greg Daniel18f96022017-05-04 15:09:03 -0400302 SkASSERT(kVertex_GrShaderFlag == visibility ||
303 kGeometry_GrShaderFlag == visibility ||
304 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700305
306 for (int i = 0; i < fSamplers.count(); ++i) {
Brian Salomon101b8442016-11-18 11:58:54 -0500307 const UniformInfo& sampler = fSamplers[i];
308 SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType);
309 if (visibility == sampler.fVisibility) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500310 sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
egdaniel09aa1fc2016-04-20 07:09:46 -0700311 out->append(";\n");
312 }
313 }
314
Greg Danielaa352de2017-07-17 09:05:16 -0400315#ifdef SK_DEBUG
316 bool firstGeomOffsetCheck = false;
317 bool firstFragOffsetCheck = false;
318 for (int i = 0; i < fUniforms.count(); ++i) {
319 const UniformInfo& localUniform = fUniforms[i];
320 if (kVertex_GrShaderFlag == localUniform.fVisibility ||
321 kGeometry_GrShaderFlag == localUniform.fVisibility ||
322 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == localUniform.fVisibility) {
323 if (!firstGeomOffsetCheck) {
324 // Check to make sure we are starting our offset at 0 so the offset qualifier we
325 // set on each variable in the uniform block is valid.
326 SkASSERT(0 == localUniform.fUBOffset);
327 firstGeomOffsetCheck = true;
328 }
329 } else {
330 SkASSERT(kFragment_GrShaderFlag == localUniform.fVisibility);
331 if (!firstFragOffsetCheck) {
332 // Check to make sure we are starting our offset at 0 so the offset qualifier we
333 // set on each variable in the uniform block is valid.
334 SkASSERT(0 == localUniform.fUBOffset);
335 firstFragOffsetCheck = true;
336 }
337 }
338 }
339#endif
340
egdaniel09aa1fc2016-04-20 07:09:46 -0700341 SkString uniformsString;
Greg Daniel164a9f02016-02-22 09:56:40 -0500342 for (int i = 0; i < fUniforms.count(); ++i) {
343 const UniformInfo& localUniform = fUniforms[i];
Greg Daniel18f96022017-05-04 15:09:03 -0400344 if (visibility & localUniform.fVisibility) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500345 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500346 localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
Greg Daniel164a9f02016-02-22 09:56:40 -0500347 uniformsString.append(";\n");
Greg Daniel164a9f02016-02-22 09:56:40 -0500348 }
349 }
350 }
Greg Danielaa352de2017-07-17 09:05:16 -0400351
Greg Daniel164a9f02016-02-22 09:56:40 -0500352 if (!uniformsString.isEmpty()) {
Greg Daniel18f96022017-05-04 15:09:03 -0400353 uint32_t uniformBinding;
354 const char* stage;
355 if (kVertex_GrShaderFlag == visibility) {
356 uniformBinding = kGeometryBinding;
357 stage = "vertex";
358 } else if (kGeometry_GrShaderFlag == visibility) {
359 uniformBinding = kGeometryBinding;
360 stage = "geometry";
361 } else {
362 SkASSERT(kFragment_GrShaderFlag == visibility);
363 uniformBinding = kFragBinding;
364 stage = "fragment";
365 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500366 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
367 kUniformBufferDescSet, uniformBinding, stage);
368 out->appendf("%s\n};\n", uniformsString.c_str());
369 }
egdaniel4ee1cda2016-02-26 08:18:49 -0800370}