Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/gpu/vk/GrVkUniformHandler.cpp

Issue 1885863004: Refactor how we store and use samplers in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove unneeded assert Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkUniformHandler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVkUniformHandler.h" 8 #include "GrVkUniformHandler.h"
9 #include "glsl/GrGLSLProgramBuilder.h" 9 #include "glsl/GrGLSLProgramBuilder.h"
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 GrSL Precision precision, 129 GrSL Precision precision,
130 cons t char* name, 130 cons t char* name,
131 bool mangleName, 131 bool mangleName,
132 int arrayCount, 132 int arrayCount,
133 cons t char** outName) { 133 cons t char** outName) {
134 SkASSERT(name && strlen(name)); 134 SkASSERT(name && strlen(name));
135 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_GrShaderFlag|kFr agment_GrShaderFlag); 135 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_GrShaderFlag|kFr agment_GrShaderFlag);
136 SkASSERT(0 == (~kVisibilityMask & visibility)); 136 SkASSERT(0 == (~kVisibilityMask & visibility));
137 SkASSERT(0 != visibility); 137 SkASSERT(0 != visibility);
138 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); 138 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
139 GrSLTypeIsFloatType(type);
139 140
140 UniformInfo& uni = fUniforms.push_back(); 141 UniformInfo& uni = fUniforms.push_back();
141 uni.fVariable.setType(type); 142 uni.fVariable.setType(type);
142 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use 143 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
143 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB 144 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
144 // exactly what name it wants to use for the uniform view matrix. If we pre fix anythings, then 145 // exactly what name it wants to use for the uniform view matrix. If we pre fix anythings, then
145 // the names will mismatch. I think the correct solution is to have all GPs which need the 146 // the names will mismatch. I think the correct solution is to have all GPs which need the
146 // uniform view matrix, they should upload the view matrix in their setData along with regular 147 // uniform view matrix, they should upload the view matrix in their setData along with regular
147 // uniforms. 148 // uniforms.
148 char prefix = 'u'; 149 char prefix = 'u';
149 if ('u' == name[0]) { 150 if ('u' == name[0]) {
150 prefix = '\0'; 151 prefix = '\0';
151 } 152 }
152 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mang leName); 153 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mang leName);
153 uni.fVariable.setArrayCount(arrayCount); 154 uni.fVariable.setArrayCount(arrayCount);
154 // For now asserting the the visibility is either only vertex or only fragme nt 155 // For now asserting the the visibility is either only vertex or only fragme nt
155 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility); 156 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility);
156 uni.fVisibility = visibility; 157 uni.fVisibility = visibility;
157 uni.fVariable.setPrecision(precision); 158 uni.fVariable.setPrecision(precision);
158 if (GrSLTypeIsFloatType(type)) { 159 // When outputing the GLSL, only the outer uniform block will get the Unifor m modifier. Thus
159 // When outputing the GLSL, only the outer uniform block will get the Un iform modifier. Thus 160 // we set the modifier to none for all uniforms declared inside the block.
160 // we set the modifier to none for all uniforms declared inside the bloc k. 161 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier);
161 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier);
162 162
163 uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrent VertexUBOOffset 163 uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrentVert exUBOOffset
164 : &fCurrent FragmentUBOOffset; 164 : &fCurrentFr agmentUBOOffset;
165 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount); 165 get_ubo_aligned_offset(&uni.fUBOffset, currentOffset, type, arrayCount);
166 uni.fSetNumber = kUniformBufferDescSet;
167 uni.fBinding = kVertex_GrShaderFlag == visibility ? kVertexBinding : kFr agBinding;
168 166
169 if (outName) { 167 if (outName) {
170 *outName = uni.fVariable.c_str(); 168 *outName = uni.fVariable.c_str();
171 }
172 } else {
173 SkASSERT(type == kSampler2D_GrSLType);
174 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier);
175
176 uni.fSetNumber = kSamplerDescSet;
177 uni.fBinding = fCurrentSamplerBinding++;
178 uni.fUBOffset = 0; // This value will be ignored, but initializing to av oid any errors.
179 SkString layoutQualifier;
180 layoutQualifier.appendf("set=%d, binding=%d", uni.fSetNumber, uni.fBindi ng);
181 uni.fVariable.setLayoutQualifier(layoutQualifier.c_str());
182 } 169 }
183 170
184 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); 171 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
185 } 172 }
186 173
174 GrGLSLUniformHandler::SamplerHandle GrVkUniformHandler::internalAddSampler(uint3 2_t visibility,
175 GrPix elConfig config,
176 GrSLT ype type,
177 GrSLP recision precision,
178 const char* name) {
179 SkASSERT(name && strlen(name));
180 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag | kFragmen t_GrShaderFlag);
181 SkASSERT(0 == (~kVisMask & visibility));
182 SkASSERT(0 != visibility);
183 SkString mangleName;
184 char prefix = 'u';
185 fProgramBuilder->nameVariable(&mangleName, prefix, name, true);
186 fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str (),
187 (uint32_t)fSamplers.count(), kSamplerDescSet);
188 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1);
189 }
190
187 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const { 191 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
188 SkTArray<UniformInfo*> uniformBufferUniform; 192 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility);
189 // Used to collect all the variables that will be place inside the uniform b uffer 193
194 for (int i = 0; i < fSamplers.count(); ++i) {
195 const GrVkGLSLSampler& sampler = fSamplers[i];
196 SkASSERT(sampler.type() == kSampler2D_GrSLType);
197 if (visibility == sampler.visibility()) {
198 sampler.fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out);
199 out->append(";\n");
200 }
201 }
202
190 SkString uniformsString; 203 SkString uniformsString;
191 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility);
192 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertexBind ing : kFragBinding;
193 for (int i = 0; i < fUniforms.count(); ++i) { 204 for (int i = 0; i < fUniforms.count(); ++i) {
194 const UniformInfo& localUniform = fUniforms[i]; 205 const UniformInfo& localUniform = fUniforms[i];
195 if (visibility == localUniform.fVisibility) { 206 if (visibility == localUniform.fVisibility) {
196 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { 207 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
197 SkASSERT(uniformBinding == localUniform.fBinding);
198 SkASSERT(kUniformBufferDescSet == localUniform.fSetNumber);
199 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), & uniformsString); 208 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), & uniformsString);
200 uniformsString.append(";\n"); 209 uniformsString.append(";\n");
201 } else {
202 SkASSERT(localUniform.fVariable.getType() == kSampler2D_GrSLType );
203 SkASSERT(kSamplerDescSet == localUniform.fSetNumber);
204 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), o ut);
205 out->append(";\n");
206 } 210 }
207 } 211 }
208 } 212 }
209 if (!uniformsString.isEmpty()) { 213 if (!uniformsString.isEmpty()) {
214 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex Binding
215 : kFragBi nding;
210 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f ragment"; 216 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f ragment";
211 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", 217 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
212 kUniformBufferDescSet, uniformBinding, stage); 218 kUniformBufferDescSet, uniformBinding, stage);
213 out->appendf("%s\n};\n", uniformsString.c_str()); 219 out->appendf("%s\n};\n", uniformsString.c_str());
214 } 220 }
215 } 221 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkUniformHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698