/src/skia/src/sksl/ir/SkSLConstructorSplat.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021 Google LLC |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #include "src/sksl/SkSLConstantFolder.h" |
9 | | #include "src/sksl/ir/SkSLConstructorSplat.h" |
10 | | |
11 | | namespace SkSL { |
12 | | |
13 | | std::unique_ptr<Expression> ConstructorSplat::Make(const Context& context, |
14 | | int offset, |
15 | | const Type& type, |
16 | 270k | std::unique_ptr<Expression> arg) { |
17 | 270k | SkASSERT(arg->type().scalarTypeForLiteral() == type.componentType().scalarTypeForLiteral()); |
18 | 270k | SkASSERT(arg->type().isScalar()); |
19 | | |
20 | | // A "splat" to a scalar type is a no-op and can be eliminated. |
21 | 270k | if (type.isScalar()) { |
22 | 59.1k | return arg; |
23 | 59.1k | } |
24 | | |
25 | 211k | if (context.fConfig->fSettings.fOptimize) { |
26 | | // Replace constant variables with their corresponding values, so `float3(five)` can |
27 | | // compile down to `float3(5.0)` (the latter is a compile-time constant). |
28 | 211k | arg = ConstantFolder::MakeConstantValueForVariable(std::move(arg)); |
29 | 211k | } |
30 | | |
31 | 211k | SkASSERT(type.isVector()); |
32 | 211k | return std::make_unique<ConstructorSplat>(offset, type, std::move(arg)); |
33 | 211k | } SkSL::ConstructorSplat::Make(SkSL::Context const&, int, SkSL::Type const&, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >) Line | Count | Source | 16 | 19 | std::unique_ptr<Expression> arg) { | 17 | 19 | SkASSERT(arg->type().scalarTypeForLiteral() == type.componentType().scalarTypeForLiteral()); | 18 | 19 | SkASSERT(arg->type().isScalar()); | 19 | | | 20 | | // A "splat" to a scalar type is a no-op and can be eliminated. | 21 | 19 | if (type.isScalar()) { | 22 | 6 | return arg; | 23 | 6 | } | 24 | | | 25 | 13 | if (context.fConfig->fSettings.fOptimize) { | 26 | | // Replace constant variables with their corresponding values, so `float3(five)` can | 27 | | // compile down to `float3(5.0)` (the latter is a compile-time constant). | 28 | 13 | arg = ConstantFolder::MakeConstantValueForVariable(std::move(arg)); | 29 | 13 | } | 30 | | | 31 | 13 | SkASSERT(type.isVector()); | 32 | 13 | return std::make_unique<ConstructorSplat>(offset, type, std::move(arg)); | 33 | 13 | } |
SkSL::ConstructorSplat::Make(SkSL::Context const&, int, SkSL::Type const&, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >) Line | Count | Source | 16 | 270k | std::unique_ptr<Expression> arg) { | 17 | 270k | SkASSERT(arg->type().scalarTypeForLiteral() == type.componentType().scalarTypeForLiteral()); | 18 | 270k | SkASSERT(arg->type().isScalar()); | 19 | | | 20 | | // A "splat" to a scalar type is a no-op and can be eliminated. | 21 | 270k | if (type.isScalar()) { | 22 | 59.1k | return arg; | 23 | 59.1k | } | 24 | | | 25 | 211k | if (context.fConfig->fSettings.fOptimize) { | 26 | | // Replace constant variables with their corresponding values, so `float3(five)` can | 27 | | // compile down to `float3(5.0)` (the latter is a compile-time constant). | 28 | 211k | arg = ConstantFolder::MakeConstantValueForVariable(std::move(arg)); | 29 | 211k | } | 30 | | | 31 | 211k | SkASSERT(type.isVector()); | 32 | 211k | return std::make_unique<ConstructorSplat>(offset, type, std::move(arg)); | 33 | 211k | } |
|
34 | | |
35 | | } // namespace SkSL |