const Expression* indexExpr = ConstantFolder::GetConstantValueForVariable(*index); if (indexExpr->isIntLiteral()) {
SKSL_INT indexValue = indexExpr->as<Literal>().intValue(); if (!index_out_of_range(context, index->fPosition, indexValue, *base)) { if (baseType.isVector()) { // Constant array indexes on vectors can be converted to swizzles: `v[2]` --> `v.z`. // Swizzling is harmless and can unlock further simplifications for some base types. return Swizzle::Make(context, pos, std::move(base),
ComponentArray{(int8_t)indexValue});
}
if (baseType.isArray() && !Analysis::HasSideEffects(*base)) { // Indexing an constant array constructor with a constant index can just pluck out // the requested value from the array. const Expression* baseExpr = ConstantFolder::GetConstantValueForVariable(*base); if (baseExpr->is<ConstructorArray>()) { const ConstructorArray& arrayCtor = baseExpr->as<ConstructorArray>(); const ExpressionArray& arguments = arrayCtor.arguments();
SkASSERT(arguments.size() == baseType.columns());
return arguments[indexValue]->clone(pos);
}
}
if (baseType.isMatrix() && !Analysis::HasSideEffects(*base)) { // Matrices can be constructed with vectors that don't line up on column boundaries, // so extracting out the values from the constructor can be tricky. Fortunately, we // can reconstruct an equivalent vector using `getConstantValue`. If we // can't extract the data using `getConstantValue`, it wasn't constant and // we're not obligated to simplify anything. const Expression* baseExpr = ConstantFolder::GetConstantValueForVariable(*base); int vecWidth = baseType.rows(); const Type& vecType = baseType.columnType(context);
indexValue *= vecWidth;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.