blob: 261355025bb513cc8dbf00cd70df6bf020459379 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/vk/GrVkUniformHandler.h"
Greg Daniel9a51a862018-11-30 10:18:14 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrTexturePriv.h"
11#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
12#include "src/gpu/vk/GrVkGpu.h"
13#include "src/gpu/vk/GrVkPipelineStateBuilder.h"
14#include "src/gpu/vk/GrVkTexture.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050015
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,
Greg Daniel164a9f02016-02-22 09:56:40 -0500206 const char* name,
207 bool mangleName,
208 int arrayCount,
209 const char** outName) {
210 SkASSERT(name && strlen(name));
Greg Daniel18f96022017-05-04 15:09:03 -0400211 // For now asserting the the visibility is either geometry types (vertex, tesselation, geometry,
212 // etc.) or only fragment.
213 SkASSERT(kVertex_GrShaderFlag == visibility ||
214 kGeometry_GrShaderFlag == visibility ||
215 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == visibility ||
216 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700217 GrSLTypeIsFloatType(type);
Greg Daniel164a9f02016-02-22 09:56:40 -0500218
219 UniformInfo& uni = fUniforms.push_back();
220 uni.fVariable.setType(type);
221 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
222 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
223 // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
224 // the names will mismatch. I think the correct solution is to have all GPs which need the
225 // uniform view matrix, they should upload the view matrix in their setData along with regular
226 // uniforms.
227 char prefix = 'u';
Robert Phillipsfe8da172018-01-24 14:52:02 +0000228 if ('u' == name[0] || !strncmp(name, GR_NO_MANGLE_PREFIX, strlen(GR_NO_MANGLE_PREFIX))) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500229 prefix = '\0';
230 }
231 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
232 uni.fVariable.setArrayCount(arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500233 uni.fVisibility = visibility;
egdaniel09aa1fc2016-04-20 07:09:46 -0700234 // When outputing the GLSL, only the outer uniform block will get the Uniform modifier. Thus
235 // we set the modifier to none for all uniforms declared inside the block.
Brian Salomon99938a82016-11-21 13:41:08 -0500236 uni.fVariable.setTypeModifier(GrShaderVar::kNone_TypeModifier);
Greg Daniel164a9f02016-02-22 09:56:40 -0500237
Greg Daniel18f96022017-05-04 15:09:03 -0400238 uint32_t* currentOffset;
239 uint32_t geomStages = kVertex_GrShaderFlag | kGeometry_GrShaderFlag;
240 if (geomStages & visibility) {
241 currentOffset = &fCurrentGeometryUBOOffset;
242 } else {
243 SkASSERT(kFragment_GrShaderFlag == visibility);
244 currentOffset = &fCurrentFragmentUBOOffset;
245 }
egdaniel09aa1fc2016-04-20 07:09:46 -0700246 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
Greg Daniel164a9f02016-02-22 09:56:40 -0500247
Greg Danieldbd44c72017-01-24 15:12:12 -0500248 SkString layoutQualifier;
249 layoutQualifier.appendf("offset=%d", uni.fUBOffset);
250 uni.fVariable.addLayoutQualifier(layoutQualifier.c_str());
251
egdaniel09aa1fc2016-04-20 07:09:46 -0700252 if (outName) {
253 *outName = uni.fVariable.c_str();
Greg Daniel164a9f02016-02-22 09:56:40 -0500254 }
255
256 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
257}
258
Greg Daniel9a51a862018-11-30 10:18:14 -0500259GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::addSampler(const GrTexture* texture,
260 const GrSamplerState& state,
Greg Daniel2c3398d2019-06-19 11:58:01 -0400261 const GrSwizzle& swizzle,
Greg Daniel9a51a862018-11-30 10:18:14 -0500262 const char* name,
263 const GrShaderCaps* shaderCaps) {
egdaniel09aa1fc2016-04-20 07:09:46 -0700264 SkASSERT(name && strlen(name));
egdaniel09aa1fc2016-04-20 07:09:46 -0700265 SkString mangleName;
266 char prefix = 'u';
267 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
Brian Salomon101b8442016-11-18 11:58:54 -0500268
Greg Daniel9a51a862018-11-30 10:18:14 -0500269 GrTextureType type = texture->texturePriv().textureType();
270
Brian Salomon101b8442016-11-18 11:58:54 -0500271 UniformInfo& info = fSamplers.push_back();
Brian Salomon60dd8c72018-07-30 10:24:13 -0400272 info.fVariable.setType(GrSLCombinedSamplerTypeForTextureType(type));
Brian Salomon99938a82016-11-21 13:41:08 -0500273 info.fVariable.setTypeModifier(GrShaderVar::kUniform_TypeModifier);
Brian Salomon101b8442016-11-18 11:58:54 -0500274 info.fVariable.setName(mangleName);
275 SkString layoutQualifier;
276 layoutQualifier.appendf("set=%d, binding=%d", kSamplerDescSet, fSamplers.count() - 1);
Brian Salomon60397682016-11-22 15:06:46 -0500277 info.fVariable.addLayoutQualifier(layoutQualifier.c_str());
Greg Daniel0f70be82018-10-08 17:35:08 +0000278 info.fVisibility = kFragment_GrShaderFlag;
Brian Salomon101b8442016-11-18 11:58:54 -0500279 info.fUBOffset = 0;
Greg Daniel9a51a862018-11-30 10:18:14 -0500280
281 // Check if we are dealing with an external texture and store the needed information if so
282 const GrVkTexture* vkTexture = static_cast<const GrVkTexture*>(texture);
283 if (vkTexture->ycbcrConversionInfo().isValid()) {
284 SkASSERT(type == GrTextureType::kExternal);
285 GrVkGpu* gpu = static_cast<GrVkPipelineStateBuilder*>(fProgramBuilder)->gpu();
286 info.fImmutableSampler = gpu->resourceProvider().findOrCreateCompatibleSampler(
287 state, vkTexture->ycbcrConversionInfo());
288 SkASSERT(info.fImmutableSampler);
289 }
290
Brian Salomon68ba1172019-06-05 11:15:08 -0400291 SkASSERT(shaderCaps->textureSwizzleAppliedInShader());
Brian Salomon101b8442016-11-18 11:58:54 -0500292 fSamplerSwizzles.push_back(swizzle);
293 SkASSERT(fSamplerSwizzles.count() == fSamplers.count());
egdaniel09aa1fc2016-04-20 07:09:46 -0700294 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
295}
296
Greg Daniel164a9f02016-02-22 09:56:40 -0500297void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
Greg Daniel18f96022017-05-04 15:09:03 -0400298 SkASSERT(kVertex_GrShaderFlag == visibility ||
299 kGeometry_GrShaderFlag == visibility ||
300 kFragment_GrShaderFlag == visibility);
egdaniel09aa1fc2016-04-20 07:09:46 -0700301
302 for (int i = 0; i < fSamplers.count(); ++i) {
Brian Salomon101b8442016-11-18 11:58:54 -0500303 const UniformInfo& sampler = fSamplers[i];
304 SkASSERT(sampler.fVariable.getType() == kTexture2DSampler_GrSLType);
305 if (visibility == sampler.fVisibility) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500306 sampler.fVariable.appendDecl(fProgramBuilder->shaderCaps(), out);
egdaniel09aa1fc2016-04-20 07:09:46 -0700307 out->append(";\n");
308 }
309 }
310
Greg Danielaa352de2017-07-17 09:05:16 -0400311#ifdef SK_DEBUG
312 bool firstGeomOffsetCheck = false;
313 bool firstFragOffsetCheck = false;
314 for (int i = 0; i < fUniforms.count(); ++i) {
315 const UniformInfo& localUniform = fUniforms[i];
316 if (kVertex_GrShaderFlag == localUniform.fVisibility ||
317 kGeometry_GrShaderFlag == localUniform.fVisibility ||
318 (kVertex_GrShaderFlag | kGeometry_GrShaderFlag) == localUniform.fVisibility) {
319 if (!firstGeomOffsetCheck) {
320 // Check to make sure we are starting our offset at 0 so the offset qualifier we
321 // set on each variable in the uniform block is valid.
322 SkASSERT(0 == localUniform.fUBOffset);
323 firstGeomOffsetCheck = true;
324 }
325 } else {
326 SkASSERT(kFragment_GrShaderFlag == localUniform.fVisibility);
327 if (!firstFragOffsetCheck) {
328 // Check to make sure we are starting our offset at 0 so the offset qualifier we
329 // set on each variable in the uniform block is valid.
330 SkASSERT(0 == localUniform.fUBOffset);
331 firstFragOffsetCheck = true;
332 }
333 }
334 }
335#endif
336
egdaniel09aa1fc2016-04-20 07:09:46 -0700337 SkString uniformsString;
Greg Daniel164a9f02016-02-22 09:56:40 -0500338 for (int i = 0; i < fUniforms.count(); ++i) {
339 const UniformInfo& localUniform = fUniforms[i];
Greg Daniel18f96022017-05-04 15:09:03 -0400340 if (visibility & localUniform.fVisibility) {
Greg Daniel164a9f02016-02-22 09:56:40 -0500341 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
Brian Salomon94efbf52016-11-29 13:43:05 -0500342 localUniform.fVariable.appendDecl(fProgramBuilder->shaderCaps(), &uniformsString);
Greg Daniel164a9f02016-02-22 09:56:40 -0500343 uniformsString.append(";\n");
Greg Daniel164a9f02016-02-22 09:56:40 -0500344 }
345 }
346 }
Greg Danielaa352de2017-07-17 09:05:16 -0400347
Greg Daniel164a9f02016-02-22 09:56:40 -0500348 if (!uniformsString.isEmpty()) {
Greg Daniel18f96022017-05-04 15:09:03 -0400349 uint32_t uniformBinding;
350 const char* stage;
351 if (kVertex_GrShaderFlag == visibility) {
352 uniformBinding = kGeometryBinding;
353 stage = "vertex";
354 } else if (kGeometry_GrShaderFlag == visibility) {
355 uniformBinding = kGeometryBinding;
356 stage = "geometry";
357 } else {
358 SkASSERT(kFragment_GrShaderFlag == visibility);
359 uniformBinding = kFragBinding;
360 stage = "fragment";
361 }
Greg Daniel164a9f02016-02-22 09:56:40 -0500362 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
363 kUniformBufferDescSet, uniformBinding, stage);
364 out->appendf("%s\n};\n", uniformsString.c_str());
365 }
egdaniel4ee1cda2016-02-26 08:18:49 -0800366}