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

Side by Side Diff: src/sksl/SkSLIRGenerator.cpp

Issue 2185393003: added initial GLSL support to skslc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: added initial GLSL support to skslc Created 4 years, 4 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
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 "SkSLIRGenerator.h" 8 #include "SkSLIRGenerator.h"
9 9
10 #include "limits.h" 10 #include "limits.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 type = new Type(name, Type::kArray_Kind, *type, (int) count); 176 type = new Type(name, Type::kArray_Kind, *type, (int) count);
177 fSymbolTable->takeOwnership((Type*) type); 177 fSymbolTable->takeOwnership((Type*) type);
178 currentVarSizes.push_back(std::move(size)); 178 currentVarSizes.push_back(std::move(size));
179 } else { 179 } else {
180 type = new Type(type->fName + "[]", Type::kArray_Kind, *type, -1 ); 180 type = new Type(type->fName + "[]", Type::kArray_Kind, *type, -1 );
181 fSymbolTable->takeOwnership((Type*) type); 181 fSymbolTable->takeOwnership((Type*) type);
182 currentVarSizes.push_back(nullptr); 182 currentVarSizes.push_back(nullptr);
183 } 183 }
184 } 184 }
185 sizes.push_back(std::move(currentVarSizes));
186 auto var = std::unique_ptr<Variable>(new Variable(decl.fPosition, modifi ers, decl.fNames[i], 185 auto var = std::unique_ptr<Variable>(new Variable(decl.fPosition, modifi ers, decl.fNames[i],
187 *type, storage)); 186 *type, storage));
188 std::unique_ptr<Expression> value; 187 std::unique_ptr<Expression> value;
189 if (decl.fValues[i]) { 188 if (decl.fValues[i]) {
190 value = this->convertExpression(*decl.fValues[i]); 189 value = this->convertExpression(*decl.fValues[i]);
191 if (!value) { 190 if (!value) {
192 return nullptr; 191 return nullptr;
193 } 192 }
194 value = this->coerce(std::move(value), *type); 193 value = this->coerce(std::move(value), *type);
195 } 194 }
196 variables.push_back(var.get()); 195 if ("gl_FragCoord" == decl.fNames[i] && (*fSymbolTable)[decl.fNames[i]]) {
197 fSymbolTable->add(decl.fNames[i], std::move(var)); 196 // already defined, just update the modifiers
198 values.push_back(std::move(value)); 197 Variable* old = (Variable*) (*fSymbolTable)[decl.fNames[i]];
198 old->fModifiers = var->fModifiers;
199 } else {
200 variables.push_back(var.get());
201 fSymbolTable->add(decl.fNames[i], std::move(var));
202 values.push_back(std::move(value));
203 sizes.push_back(std::move(currentVarSizes));
204 }
199 } 205 }
200 return std::unique_ptr<VarDeclaration>(new VarDeclaration(decl.fPosition, st d::move(variables), 206 return std::unique_ptr<VarDeclaration>(new VarDeclaration(decl.fPosition, st d::move(variables),
201 std::move(sizes), std::move(values))); 207 std::move(sizes), std::move(values)));
202 } 208 }
203 209
204 std::unique_ptr<Statement> IRGenerator::convertIf(const ASTIfStatement& s) { 210 std::unique_ptr<Statement> IRGenerator::convertIf(const ASTIfStatement& s) {
205 std::unique_ptr<Expression> test = this->coerce(this->convertExpression(*s.f Test), 211 std::unique_ptr<Expression> test = this->coerce(this->convertExpression(*s.f Test),
206 *fContext.fBool_Type); 212 *fContext.fBool_Type);
207 if (!test) { 213 if (!test) {
208 return nullptr; 214 return nullptr;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 case Symbol::kVariable_Kind: { 573 case Symbol::kVariable_Kind: {
568 const Variable* var = (const Variable*) result; 574 const Variable* var = (const Variable*) result;
569 this->markReadFrom(*var); 575 this->markReadFrom(*var);
570 return std::unique_ptr<VariableReference>(new VariableReference(iden tifier.fPosition, 576 return std::unique_ptr<VariableReference>(new VariableReference(iden tifier.fPosition,
571 *var )); 577 *var ));
572 } 578 }
573 case Symbol::kField_Kind: { 579 case Symbol::kField_Kind: {
574 const Field* field = (const Field*) result; 580 const Field* field = (const Field*) result;
575 VariableReference* base = new VariableReference(identifier.fPosition , field->fOwner); 581 VariableReference* base = new VariableReference(identifier.fPosition , field->fOwner);
576 return std::unique_ptr<Expression>(new FieldAccess(std::unique_ptr<E xpression>(base), 582 return std::unique_ptr<Expression>(new FieldAccess(std::unique_ptr<E xpression>(base),
577 field->fFieldInde x)); 583 field->fFieldInde x,
584 true));
dogben 2016/07/31 23:20:20 nit: use enum, or "/*inAnonymousInterfaceBlock*/ t
ethannicholas 2016/08/02 16:13:18 Done.
578 } 585 }
579 case Symbol::kType_Kind: { 586 case Symbol::kType_Kind: {
580 const Type* t = (const Type*) result; 587 const Type* t = (const Type*) result;
581 return std::unique_ptr<TypeReference>(new TypeReference(fContext, id entifier.fPosition, 588 return std::unique_ptr<TypeReference>(new TypeReference(fContext, id entifier.fPosition,
582 *t)); 589 *t));
583 } 590 }
584 default: 591 default:
585 ABORT("unsupported symbol type %d\n", result->fKind); 592 ABORT("unsupported symbol type %d\n", result->fKind);
586 } 593 }
587 594
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 case Token::LOGICALOREQ: // fall through 651 case Token::LOGICALOREQ: // fall through
645 case Token::LOGICALANDEQ: // fall through 652 case Token::LOGICALANDEQ: // fall through
646 case Token::LOGICALXOREQ: 653 case Token::LOGICALXOREQ:
647 *outLeftType = context.fBool_Type.get(); 654 *outLeftType = context.fBool_Type.get();
648 *outRightType = context.fBool_Type.get(); 655 *outRightType = context.fBool_Type.get();
649 *outResultType = context.fBool_Type.get(); 656 *outResultType = context.fBool_Type.get();
650 return left.canCoerceTo(*context.fBool_Type) && 657 return left.canCoerceTo(*context.fBool_Type) &&
651 right.canCoerceTo(*context.fBool_Type); 658 right.canCoerceTo(*context.fBool_Type);
652 case Token::STAR: // fall through 659 case Token::STAR: // fall through
653 case Token::STAREQ: 660 case Token::STAREQ:
654 // FIXME need to handle non-square matrices
655 if (left.kind() == Type::kMatrix_Kind && right.kind() == Type::kVect or_Kind) { 661 if (left.kind() == Type::kMatrix_Kind && right.kind() == Type::kVect or_Kind) {
656 *outLeftType = &left; 662 // determine final component type
657 *outRightType = &right; 663 if (determine_binary_type(context, Token::STAR, left.componentTy pe(),
658 *outResultType = &right; 664 right.componentType(), outLeftType, ou tRightType,
659 return left.rows() == right.columns(); 665 outResultType, false)) {
666 *outLeftType = &left;
dogben 2016/07/31 23:20:21 Seems like you need *outLeftType = &(*outResultTyp
ethannicholas 2016/08/02 16:13:18 Completely reworked this.
667 *outRightType = &right;
668 *outResultType = &(*outResultType)->toCompound(context, left .rows(), 1);
669 return left.rows() == right.columns();
dogben 2016/07/31 23:20:20 Should be left.columns() == right.columns() becaus
670 } else {
671 return false;
672 }
660 } 673 }
661 if (left.kind() == Type::kVector_Kind && right.kind() == Type::kMatr ix_Kind) { 674 if (left.kind() == Type::kVector_Kind && right.kind() == Type::kMatr ix_Kind) {
662 *outLeftType = &left; 675 // determine final component type
663 *outRightType = &right; 676 if (determine_binary_type(context, Token::STAR, left.componentTy pe(),
664 *outResultType = &left; 677 right.componentType(), outLeftType, ou tRightType,
665 return left.columns() == right.columns(); 678 outResultType, false)) {
679 *outLeftType = &left;
680 *outRightType = &right;
681 *outResultType = &(*outResultType)->toCompound(context, righ t.columns(), 1);
682 return left.columns() == right.rows();
683 } else {
684 return false;
685 }
666 } 686 }
667 // fall through 687 // fall through
668 default: 688 default:
669 isLogical = false; 689 isLogical = false;
670 } 690 }
671 // FIXME: need to disallow illegal operations like vec3 > vec3. Also do not currently have 691 // FIXME: need to disallow illegal operations like vec3 > vec3. Also do not currently have
672 // full support for numbers other than float. 692 // full support for numbers other than float.
673 if (left == right) { 693 if (left == right) {
674 *outLeftType = &left; 694 *outLeftType = &left;
675 *outRightType = &left; 695 *outRightType = &left;
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 } 1056 }
1037 return std::unique_ptr<Expression>(new IndexExpression(fContext, std::move(b ase), 1057 return std::unique_ptr<Expression>(new IndexExpression(fContext, std::move(b ase),
1038 std::move(converted)) ); 1058 std::move(converted)) );
1039 } 1059 }
1040 1060
1041 std::unique_ptr<Expression> IRGenerator::convertField(std::unique_ptr<Expression > base, 1061 std::unique_ptr<Expression> IRGenerator::convertField(std::unique_ptr<Expression > base,
1042 const std::string& field) { 1062 const std::string& field) {
1043 auto fields = base->fType.fields(); 1063 auto fields = base->fType.fields();
1044 for (size_t i = 0; i < fields.size(); i++) { 1064 for (size_t i = 0; i < fields.size(); i++) {
1045 if (fields[i].fName == field) { 1065 if (fields[i].fName == field) {
1046 return std::unique_ptr<Expression>(new FieldAccess(std::move(base), (int) i)); 1066 return std::unique_ptr<Expression>(new FieldAccess(std::move(base), (int) i, false));
1047 } 1067 }
1048 } 1068 }
1049 fErrors.error(base->fPosition, "type '" + base->fType.description() + "' doe s not have a " 1069 fErrors.error(base->fPosition, "type '" + base->fType.description() + "' doe s not have a "
1050 "field named '" + field + ""); 1070 "field named '" + field + "");
1051 return nullptr; 1071 return nullptr;
1052 } 1072 }
1053 1073
1054 std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expressi on> base, 1074 std::unique_ptr<Expression> IRGenerator::convertSwizzle(std::unique_ptr<Expressi on> base,
1055 const std::string& field s) { 1075 const std::string& field s) {
1056 if (base->fType.kind() != Type::kVector_Kind) { 1076 if (base->fType.kind() != Type::kVector_Kind) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 case Expression::kIndex_Kind: 1238 case Expression::kIndex_Kind:
1219 this->markWrittenTo(*((IndexExpression&) expr).fBase); 1239 this->markWrittenTo(*((IndexExpression&) expr).fBase);
1220 break; 1240 break;
1221 default: 1241 default:
1222 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio n() + "'"); 1242 fErrors.error(expr.fPosition, "cannot assign to '" + expr.descriptio n() + "'");
1223 break; 1243 break;
1224 } 1244 }
1225 } 1245 }
1226 1246
1227 } 1247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698