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

Side by Side Diff: src/gpu/instanced/InstanceProcessor.cpp

Issue 2288033003: Turned on SkSL->GLSL compiler (Closed)
Patch Set: changed <iostream> to <ostream> Created 4 years, 2 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/glsl/GrGLSLShaderVar.h ('k') | src/sksl/README » ('j') | 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 "InstanceProcessor.h" 8 #include "InstanceProcessor.h"
9 9
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 class GLSLInstanceProcessor::VertexInputs { 101 class GLSLInstanceProcessor::VertexInputs {
102 public: 102 public:
103 VertexInputs(const InstanceProcessor& instProc, GrGLSLVertexBuilder* vertexB uilder) 103 VertexInputs(const InstanceProcessor& instProc, GrGLSLVertexBuilder* vertexB uilder)
104 : fInstProc(instProc), 104 : fInstProc(instProc),
105 fVertexBuilder(vertexBuilder) { 105 fVertexBuilder(vertexBuilder) {
106 } 106 }
107 107
108 void initParams(const SamplerHandle paramsBuffer) { 108 void initParams(const SamplerHandle paramsBuffer) {
109 fParamsBuffer = paramsBuffer; 109 fParamsBuffer = paramsBuffer;
110 fVertexBuilder->definef("PARAMS_IDX_MASK", "0x%xu", kParamsIdx_InfoMask) ;
111 fVertexBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); 110 fVertexBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
112 fVertexBuilder->codeAppendf("int paramsIdx = int(%s & PARAMS_IDX_MASK);" , 111 fVertexBuilder->codeAppendf("int paramsIdx = int(%s & 0x%x);",
113 this->attr(Attrib::kInstanceInfo)); 112 this->attr(Attrib::kInstanceInfo),
113 kParamsIdx_InfoMask);
114 } 114 }
115 115
116 const char* attr(Attrib attr) const { return fInstProc.getAttrib((int)attr). fName; } 116 const char* attr(Attrib attr) const { return fInstProc.getAttrib((int)attr). fName; }
117 117
118 void fetchNextParam(GrSLType type = kVec4f_GrSLType) const { 118 void fetchNextParam(GrSLType type = kVec4f_GrSLType) const {
119 SkASSERT(fParamsBuffer.isValid()); 119 SkASSERT(fParamsBuffer.isValid());
120 if (type != kVec4f_GrSLType) { 120 if (type != kVec4f_GrSLType) {
121 fVertexBuilder->codeAppendf("%s(", GrGLSLTypeString(type)); 121 fVertexBuilder->codeAppendf("%s(", GrGLSLTypeString(type));
122 } 122 }
123 fVertexBuilder->appendTexelFetch(fParamsBuffer, "paramsIdx++"); 123 fVertexBuilder->appendTexelFetch(fParamsBuffer, "paramsIdx++");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 VertexInputs inputs(ip, v); 217 VertexInputs inputs(ip, v);
218 if (ip.batchInfo().fHasParams) { 218 if (ip.batchInfo().fHasParams) {
219 SkASSERT(1 == ip.numBuffers()); 219 SkASSERT(1 == ip.numBuffers());
220 inputs.initParams(args.fBufferSamplers[0]); 220 inputs.initParams(args.fBufferSamplers[0]);
221 } 221 }
222 222
223 if (!ip.batchInfo().fHasPerspective) { 223 if (!ip.batchInfo().fHasPerspective) {
224 v->codeAppendf("mat2x3 shapeMatrix = mat2x3(%s, %s);", 224 v->codeAppendf("mat2x3 shapeMatrix = mat2x3(%s, %s);",
225 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k ShapeMatrixY)); 225 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k ShapeMatrixY));
226 } else { 226 } else {
227 v->definef("PERSPECTIVE_FLAG", "0x%xu", kPerspective_InfoFlag); 227 v->defineConstantf("int", "PERSPECTIVE_FLAG", "0x%x", kPerspective_InfoF lag);
228 v->codeAppendf("mat3 shapeMatrix = mat3(%s, %s, vec3(0, 0, 1));", 228 v->codeAppendf("mat3 shapeMatrix = mat3(%s, %s, vec3(0, 0, 1));",
229 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k ShapeMatrixY)); 229 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k ShapeMatrixY));
230 v->codeAppendf("if (0u != (%s & PERSPECTIVE_FLAG)) {", 230 v->codeAppendf("if (0 != (%s & PERSPECTIVE_FLAG)) {",
231 inputs.attr(Attrib::kInstanceInfo)); 231 inputs.attr(Attrib::kInstanceInfo));
232 v->codeAppend ( "shapeMatrix[2] = "); 232 v->codeAppend ( "shapeMatrix[2] = ");
233 inputs.fetchNextParam(kVec3f_GrSLType); 233 inputs.fetchNextParam(kVec3f_GrSLType);
234 v->codeAppend ( ";"); 234 v->codeAppend ( ";");
235 v->codeAppend ("}"); 235 v->codeAppend ("}");
236 } 236 }
237 237
238 bool hasSingleShapeType = SkIsPow2(ip.batchInfo().fShapeTypes); 238 bool hasSingleShapeType = SkIsPow2(ip.batchInfo().fShapeTypes);
239 if (!hasSingleShapeType) { 239 if (!hasSingleShapeType) {
240 v->define("SHAPE_TYPE_BIT", kShapeType_InfoBit); 240 v->defineConstant("SHAPE_TYPE_BIT", kShapeType_InfoBit);
241 v->codeAppendf("uint shapeType = %s >> SHAPE_TYPE_BIT;", 241 v->codeAppendf("uint shapeType = %s >> SHAPE_TYPE_BIT;",
242 inputs.attr(Attrib::kInstanceInfo)); 242 inputs.attr(Attrib::kInstanceInfo));
243 } 243 }
244 244
245 SkAutoTDelete<Backend> backend(Backend::Create(pipeline, ip.batchInfo(), inp uts)); 245 SkAutoTDelete<Backend> backend(Backend::Create(pipeline, ip.batchInfo(), inp uts));
246 backend->init(varyingHandler, v); 246 backend->init(varyingHandler, v);
247 247
248 int usedShapeDefinitions = 0; 248 int usedShapeDefinitions = 0;
249 249
250 if (hasSingleShapeType || !(ip.batchInfo().fShapeTypes & ~kRRect_ShapesMask) ) { 250 if (hasSingleShapeType || !(ip.batchInfo().fShapeTypes & ~kRRect_ShapesMask) ) {
(...skipping 27 matching lines...) Expand all
278 if (ip.batchInfo().fShapeTypes & kRect_ShapeFlag) { 278 if (ip.batchInfo().fShapeTypes & kRect_ShapeFlag) {
279 v->codeAppend ("else {"); 279 v->codeAppend ("else {");
280 backend->setupRect(v); 280 backend->setupRect(v);
281 v->codeAppend ("}"); 281 v->codeAppend ("}");
282 } 282 }
283 } 283 }
284 284
285 if (ip.batchInfo().fInnerShapeTypes) { 285 if (ip.batchInfo().fInnerShapeTypes) {
286 bool hasSingleInnerShapeType = SkIsPow2(ip.batchInfo().fInnerShapeTypes) ; 286 bool hasSingleInnerShapeType = SkIsPow2(ip.batchInfo().fInnerShapeTypes) ;
287 if (!hasSingleInnerShapeType) { 287 if (!hasSingleInnerShapeType) {
288 v->definef("INNER_SHAPE_TYPE_MASK", "0x%xu", kInnerShapeType_InfoMas k); 288 v->defineConstantf("int", "INNER_SHAPE_TYPE_MASK", "0x%x", kInnerSha peType_InfoMask);
289 v->define("INNER_SHAPE_TYPE_BIT", kInnerShapeType_InfoBit); 289 v->defineConstant("INNER_SHAPE_TYPE_BIT", kInnerShapeType_InfoBit);
290 v->codeAppendf("uint innerShapeType = ((%s & INNER_SHAPE_TYPE_MASK) >> " 290 v->codeAppendf("uint innerShapeType = ((%s & INNER_SHAPE_TYPE_MASK) >> "
291 "INNER_SHAPE_TYPE_BIT);", 291 "INNER_SHAPE_TYPE_BIT);",
292 inputs.attr(Attrib::kInstanceInfo)); 292 inputs.attr(Attrib::kInstanceInfo));
293 } 293 }
294 // Here we take advantage of the fact that outerRect == localRect in rec ordDRRect. 294 // Here we take advantage of the fact that outerRect == localRect in rec ordDRRect.
295 v->codeAppendf("vec4 outer = %s;", inputs.attr(Attrib::kLocalRect)); 295 v->codeAppendf("vec4 outer = %s;", inputs.attr(Attrib::kLocalRect));
296 v->codeAppend ("vec4 inner = "); 296 v->codeAppend ("vec4 inner = ");
297 inputs.fetchNextParam(); 297 inputs.fetchNextParam();
298 v->codeAppend (";"); 298 v->codeAppend (";");
299 // outer2Inner is a transform from shape coords to inner shape coords: 299 // outer2Inner is a transform from shape coords to inner shape coords:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 if (ip.batchInfo().fInnerShapeTypes & kRect_ShapeFlag) { 340 if (ip.batchInfo().fInnerShapeTypes & kRect_ShapeFlag) {
341 v->codeAppend("else {"); 341 v->codeAppend("else {");
342 backend->setupInnerRect(v); 342 backend->setupInnerRect(v);
343 v->codeAppend("}"); 343 v->codeAppend("}");
344 } 344 }
345 } 345 }
346 } 346 }
347 347
348 if (usedShapeDefinitions & kOval_ShapeFlag) { 348 if (usedShapeDefinitions & kOval_ShapeFlag) {
349 v->definef("OVAL_SHAPE_TYPE", "%du", (int)ShapeType::kOval); 349 v->defineConstant("OVAL_SHAPE_TYPE", (int)ShapeType::kOval);
350 } 350 }
351 if (usedShapeDefinitions & kSimpleRRect_ShapeFlag) { 351 if (usedShapeDefinitions & kSimpleRRect_ShapeFlag) {
352 v->definef("SIMPLE_R_RECT_SHAPE_TYPE", "%du", (int)ShapeType::kSimpleRRe ct); 352 v->defineConstant("SIMPLE_R_RECT_SHAPE_TYPE", (int)ShapeType::kSimpleRRe ct);
353 } 353 }
354 if (usedShapeDefinitions & kNinePatch_ShapeFlag) { 354 if (usedShapeDefinitions & kNinePatch_ShapeFlag) {
355 v->definef("NINE_PATCH_SHAPE_TYPE", "%du", (int)ShapeType::kNinePatch); 355 v->defineConstant("NINE_PATCH_SHAPE_TYPE", (int)ShapeType::kNinePatch);
356 } 356 }
357 SkASSERT(!(usedShapeDefinitions & (kRect_ShapeFlag | kComplexRRect_ShapeFlag ))); 357 SkASSERT(!(usedShapeDefinitions & (kRect_ShapeFlag | kComplexRRect_ShapeFlag )));
358 358
359 backend->emitCode(v, f, pipeline.ignoresCoverage() ? nullptr : args.fOutputC overage, 359 backend->emitCode(v, f, pipeline.ignoresCoverage() ? nullptr : args.fOutputC overage,
360 args.fOutputColor); 360 args.fOutputColor);
361 361
362 const char* localCoords = nullptr; 362 const char* localCoords = nullptr;
363 if (ip.batchInfo().fUsesLocalCoords) { 363 if (ip.batchInfo().fUsesLocalCoords) {
364 localCoords = "localCoords"; 364 localCoords = "localCoords";
365 v->codeAppendf("vec2 t = 0.5 * (%s + vec2(1));", backend->outShapeCoords ()); 365 v->codeAppendf("vec2 t = 0.5 * (%s + vec2(1));", backend->outShapeCoords ());
366 v->codeAppendf("vec2 localCoords = (1.0 - t) * %s.xy + t * %s.zw;", 366 v->codeAppendf("vec2 localCoords = (1.0 - t) * %s.xy + t * %s.zw;",
367 inputs.attr(Attrib::kLocalRect), inputs.attr(Attrib::kLoc alRect)); 367 inputs.attr(Attrib::kLocalRect), inputs.attr(Attrib::kLoc alRect));
368 } 368 }
369 if (ip.batchInfo().fHasLocalMatrix && ip.batchInfo().fHasParams) { 369 if (ip.batchInfo().fHasLocalMatrix && ip.batchInfo().fHasParams) {
370 v->definef("LOCAL_MATRIX_FLAG", "0x%xu", kLocalMatrix_InfoFlag); 370 v->defineConstantf("int", "LOCAL_MATRIX_FLAG", "0x%x", kLocalMatrix_Info Flag);
371 v->codeAppendf("if (0u != (%s & LOCAL_MATRIX_FLAG)) {", 371 v->codeAppendf("if (0 != (%s & LOCAL_MATRIX_FLAG)) {",
372 inputs.attr(Attrib::kInstanceInfo)); 372 inputs.attr(Attrib::kInstanceInfo));
373 if (!ip.batchInfo().fUsesLocalCoords) { 373 if (!ip.batchInfo().fUsesLocalCoords) {
374 inputs.skipParams(2); 374 inputs.skipParams(2);
375 } else { 375 } else {
376 v->codeAppendf( "mat2x3 localMatrix;"); 376 v->codeAppendf( "mat2x3 localMatrix;");
377 v->codeAppend ( "localMatrix[0] = "); 377 v->codeAppend ( "localMatrix[0] = ");
378 inputs.fetchNextParam(kVec3f_GrSLType); 378 inputs.fetchNextParam(kVec3f_GrSLType);
379 v->codeAppend ( ";"); 379 v->codeAppend ( ";");
380 v->codeAppend ( "localMatrix[1] = "); 380 v->codeAppend ( "localMatrix[1] = ");
381 inputs.fetchNextParam(kVec3f_GrSLType); 381 inputs.fetchNextParam(kVec3f_GrSLType);
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 } else if (fBatchInfo.fShapeTypes & kOval_ShapeFlag) { 1172 } else if (fBatchInfo.fShapeTypes & kOval_ShapeFlag) {
1173 fArcCoords = fShapeCoords; 1173 fArcCoords = fShapeCoords;
1174 fArcInverseMatrix = fShapeInverseMatrix; 1174 fArcInverseMatrix = fShapeInverseMatrix;
1175 fFragArcHalfSpan = fFragShapeHalfSpan; 1175 fFragArcHalfSpan = fFragShapeHalfSpan;
1176 if (fBatchInfo.fShapeTypes & kRect_ShapeFlag) { 1176 if (fBatchInfo.fShapeTypes & kRect_ShapeFlag) {
1177 varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, 1177 varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc,
1178 kLow_GrSLPrecision); 1178 kLow_GrSLPrecision);
1179 } 1179 }
1180 } 1180 }
1181 if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { 1181 if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) {
1182 v->definef("SAMPLE_MASK_ALL", "0x%x", (1 << fEffectiveSampleCnt) - 1) ; 1182 v->defineConstantf("int", "SAMPLE_MASK_ALL", "0x%x", (1 << fEffective SampleCnt) - 1);
1183 varyingHandler->addFlatVarying("earlyAccept", &fEarlyAccept, kHigh_Gr SLPrecision); 1183 varyingHandler->addFlatVarying("earlyAccept", &fEarlyAccept, kHigh_Gr SLPrecision);
1184 } 1184 }
1185 } 1185 }
1186 if (!fBatchInfo.fHasPerspective) { 1186 if (!fBatchInfo.fHasPerspective) {
1187 v->codeAppend("mat2 shapeInverseMatrix = inverse(mat2(shapeMatrix));"); 1187 v->codeAppend("mat2 shapeInverseMatrix = inverse(mat2(shapeMatrix));");
1188 v->codeAppend("vec2 fragShapeSpan = abs(vec4(shapeInverseMatrix).xz) + " 1188 v->codeAppend("vec2 fragShapeSpan = abs(vec4(shapeInverseMatrix).xz) + "
1189 "abs(vec4(shapeInverseMatrix).yw);"); 1189 "abs(vec4(shapeInverseMatrix).yw);");
1190 } 1190 }
1191 } 1191 }
1192 1192
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 v->codeAppendf("innerRadii = max(innerRadii, 2e-1 * %s);", fFragInnerSha peHalfSpan.vsOut()); 1353 v->codeAppendf("innerRadii = max(innerRadii, 2e-1 * %s);", fFragInnerSha peHalfSpan.vsOut());
1354 } else { 1354 } else {
1355 v->codeAppend ("innerRadii = max(innerRadii, vec2(1e-4));"); 1355 v->codeAppend ("innerRadii = max(innerRadii, vec2(1e-4));");
1356 } 1356 }
1357 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect .vsOut()); 1357 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect .vsOut());
1358 } 1358 }
1359 1359
1360 void GLSLInstanceProcessor::BackendMultisample::onEmitCode(GrGLSLVertexBuilder*, 1360 void GLSLInstanceProcessor::BackendMultisample::onEmitCode(GrGLSLVertexBuilder*,
1361 GrGLSLPPFragmentBuild er* f, 1361 GrGLSLPPFragmentBuild er* f,
1362 const char*, const ch ar*) { 1362 const char*, const ch ar*) {
1363 f->define("SAMPLE_COUNT", fEffectiveSampleCnt); 1363 f->defineConstant("SAMPLE_COUNT", fEffectiveSampleCnt);
1364 if (this->isMixedSampled()) { 1364 if (this->isMixedSampled()) {
1365 f->definef("SAMPLE_MASK_ALL", "0x%x", (1 << fEffectiveSampleCnt) - 1); 1365 f->defineConstantf("int", "SAMPLE_MASK_ALL", "0x%x", (1 << fEffectiveSam pleCnt) - 1);
1366 f->definef("SAMPLE_MASK_MSB", "0x%x", 1 << (fEffectiveSampleCnt - 1)); 1366 f->defineConstantf("int", "SAMPLE_MASK_MSB", "0x%x", 1 << (fEffectiveSam pleCnt - 1));
1367 } 1367 }
1368 1368
1369 if (kRect_ShapeFlag != (fBatchInfo.fShapeTypes | fBatchInfo.fInnerShapeTypes )) { 1369 if (kRect_ShapeFlag != (fBatchInfo.fShapeTypes | fBatchInfo.fInnerShapeTypes )) {
1370 GrGLSLShaderVar x("x", kVec2f_GrSLType, GrGLSLShaderVar::kNonArray, kHig h_GrSLPrecision); 1370 GrGLSLShaderVar x("x", kVec2f_GrSLType, GrGLSLShaderVar::kNonArray, kHig h_GrSLPrecision);
1371 f->emitFunction(kFloat_GrSLType, "square", 1, &x, "return dot(x, x);", & fSquareFun); 1371 f->emitFunction(kFloat_GrSLType, "square", 1, &x, "return dot(x, x);", & fSquareFun);
1372 } 1372 }
1373 1373
1374 EmitShapeCoords shapeCoords; 1374 EmitShapeCoords shapeCoords;
1375 shapeCoords.fVarying = &fShapeCoords; 1375 shapeCoords.fVarying = &fShapeCoords;
1376 shapeCoords.fInverseMatrix = fShapeInverseMatrix.fsIn(); 1376 shapeCoords.fInverseMatrix = fShapeInverseMatrix.fsIn();
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 2114
2115 case kCorneredRect_FirstIndex: return "basic_round_rect"; 2115 case kCorneredRect_FirstIndex: return "basic_round_rect";
2116 case kCorneredFramedRect_FirstIndex: return "coverage_round_rect"; 2116 case kCorneredFramedRect_FirstIndex: return "coverage_round_rect";
2117 case kCorneredRectFanned_FirstIndex: return "mixed_samples_round_rect"; 2117 case kCorneredRectFanned_FirstIndex: return "mixed_samples_round_rect";
2118 2118
2119 default: return "unknown"; 2119 default: return "unknown";
2120 } 2120 }
2121 } 2121 }
2122 2122
2123 } 2123 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLShaderVar.h ('k') | src/sksl/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698