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

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

Issue 1896013003: Revert of Refactor how we store and use samplers in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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);
140 139
141 UniformInfo& uni = fUniforms.push_back(); 140 UniformInfo& uni = fUniforms.push_back();
142 uni.fVariable.setType(type); 141 uni.fVariable.setType(type);
143 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use 142 // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
144 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB 143 // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
145 // exactly what name it wants to use for the uniform view matrix. If we pre fix anythings, then 144 // exactly what name it wants to use for the uniform view matrix. If we pre fix anythings, then
146 // the names will mismatch. I think the correct solution is to have all GPs which need the 145 // the names will mismatch. I think the correct solution is to have all GPs which need the
147 // uniform view matrix, they should upload the view matrix in their setData along with regular 146 // uniform view matrix, they should upload the view matrix in their setData along with regular
148 // uniforms. 147 // uniforms.
149 char prefix = 'u'; 148 char prefix = 'u';
150 if ('u' == name[0]) { 149 if ('u' == name[0]) {
151 prefix = '\0'; 150 prefix = '\0';
152 } 151 }
153 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mang leName); 152 fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mang leName);
154 uni.fVariable.setArrayCount(arrayCount); 153 uni.fVariable.setArrayCount(arrayCount);
155 // For now asserting the the visibility is either only vertex or only fragme nt 154 // For now asserting the the visibility is either only vertex or only fragme nt
156 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility); 155 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility);
157 uni.fVisibility = visibility; 156 uni.fVisibility = visibility;
158 uni.fVariable.setPrecision(precision); 157 uni.fVariable.setPrecision(precision);
159 // When outputing the GLSL, only the outer uniform block will get the Unifor m modifier. Thus 158 if (GrSLTypeIsFloatType(type)) {
160 // we set the modifier to none for all uniforms declared inside the block. 159 // When outputing the GLSL, only the outer uniform block will get the Un iform modifier. Thus
161 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier); 160 // we set the modifier to none for all uniforms declared inside the bloc k.
161 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kNone_TypeModifier);
162 162
163 uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrentVert exUBOOffset 163 uint32_t* currentOffset = kVertex_GrShaderFlag == visibility ? &fCurrent VertexUBOOffset
164 : &fCurrentFr agmentUBOOffset; 164 : &fCurrent FragmentUBOOffset;
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;
166 168
167 if (outName) { 169 if (outName) {
168 *outName = uni.fVariable.c_str(); 170 *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());
169 } 182 }
170 183
171 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); 184 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
172 } 185 }
173 186
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
191 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const { 187 void GrVkUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out) const {
188 SkTArray<UniformInfo*> uniformBufferUniform;
189 // Used to collect all the variables that will be place inside the uniform b uffer
190 SkString uniformsString;
192 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility); 191 SkASSERT(kVertex_GrShaderFlag == visibility || kFragment_GrShaderFlag == vis ibility);
193 192 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertexBind ing : kFragBinding;
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
203 SkString uniformsString;
204 for (int i = 0; i < fUniforms.count(); ++i) { 193 for (int i = 0; i < fUniforms.count(); ++i) {
205 const UniformInfo& localUniform = fUniforms[i]; 194 const UniformInfo& localUniform = fUniforms[i];
206 if (visibility == localUniform.fVisibility) { 195 if (visibility == localUniform.fVisibility) {
207 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) { 196 if (GrSLTypeIsFloatType(localUniform.fVariable.getType())) {
197 SkASSERT(uniformBinding == localUniform.fBinding);
198 SkASSERT(kUniformBufferDescSet == localUniform.fSetNumber);
208 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), & uniformsString); 199 localUniform.fVariable.appendDecl(fProgramBuilder->glslCaps(), & uniformsString);
209 uniformsString.append(";\n"); 200 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");
210 } 206 }
211 } 207 }
212 } 208 }
213 if (!uniformsString.isEmpty()) { 209 if (!uniformsString.isEmpty()) {
214 uint32_t uniformBinding = (visibility == kVertex_GrShaderFlag) ? kVertex Binding
215 : kFragBi nding;
216 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f ragment"; 210 const char* stage = (visibility == kVertex_GrShaderFlag) ? "vertex" : "f ragment";
217 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n", 211 out->appendf("layout (set=%d, binding=%d) uniform %sUniformBuffer\n{\n",
218 kUniformBufferDescSet, uniformBinding, stage); 212 kUniformBufferDescSet, uniformBinding, stage);
219 out->appendf("%s\n};\n", uniformsString.c_str()); 213 out->appendf("%s\n};\n", uniformsString.c_str());
220 } 214 }
221 } 215 }
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