mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 23:56:16 +00:00
tint/writer/spirv: Inline constant expressions
This is required to handle materialized values, and for constant expressions. Bug: tint:1504 Change-Id: If0a49e9b03566c06aa6e4e4c284fc427e1541e91 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92082 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
609ce6de8d
commit
8e3485248e
@@ -27,6 +27,7 @@
|
||||
#include "src/tint/sem/atomic.h"
|
||||
#include "src/tint/sem/builtin.h"
|
||||
#include "src/tint/sem/call.h"
|
||||
#include "src/tint/sem/constant.h"
|
||||
#include "src/tint/sem/depth_multisampled_texture.h"
|
||||
#include "src/tint/sem/depth_texture.h"
|
||||
#include "src/tint/sem/function.h"
|
||||
@@ -406,6 +407,11 @@ bool Builder::GenerateLabel(uint32_t id) {
|
||||
|
||||
bool Builder::GenerateAssignStatement(const ast::AssignmentStatement* assign) {
|
||||
if (assign->lhs->Is<ast::PhonyExpression>()) {
|
||||
if (builder_.Sem().Get(assign->rhs)->ConstantValue()) {
|
||||
// RHS of phony assignment is constant.
|
||||
// Constants can't have side-effects, so just drop this.
|
||||
return true;
|
||||
}
|
||||
auto rhs_id = GenerateExpression(assign->rhs);
|
||||
if (rhs_id == 0) {
|
||||
return false;
|
||||
@@ -566,8 +572,14 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
|
||||
}
|
||||
|
||||
uint32_t Builder::GenerateExpression(const ast::Expression* expr) {
|
||||
if (auto* sem = builder_.Sem().Get(expr)) {
|
||||
if (auto constant = sem->ConstantValue()) {
|
||||
return GenerateConstantIfNeeded(constant);
|
||||
}
|
||||
}
|
||||
return Switch(
|
||||
expr, [&](const ast::IndexAccessorExpression* a) { return GenerateAccessorExpression(a); },
|
||||
expr, //
|
||||
[&](const ast::IndexAccessorExpression* a) { return GenerateAccessorExpression(a); },
|
||||
[&](const ast::BinaryExpression* b) { return GenerateBinaryExpression(b); },
|
||||
[&](const ast::BitcastExpression* b) { return GenerateBitcastExpression(b); },
|
||||
[&](const ast::CallExpression* c) { return GenerateCallExpression(c); },
|
||||
@@ -743,7 +755,15 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* var) {
|
||||
|
||||
uint32_t init_id = 0;
|
||||
if (var->constructor) {
|
||||
init_id = GenerateConstructorExpression(var, var->constructor);
|
||||
if (!var->is_overridable) {
|
||||
auto* ctor = builder_.Sem().Get(var->constructor);
|
||||
if (auto constant = ctor->ConstantValue()) {
|
||||
init_id = GenerateConstantIfNeeded(std::move(constant));
|
||||
}
|
||||
}
|
||||
if (init_id == 0) {
|
||||
init_id = GenerateConstructorExpression(var, var->constructor);
|
||||
}
|
||||
if (init_id == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -1662,6 +1682,116 @@ uint32_t Builder::GenerateLiteralIfNeeded(const ast::Variable* var,
|
||||
return GenerateConstantIfNeeded(constant);
|
||||
}
|
||||
|
||||
uint32_t Builder::GenerateConstantIfNeeded(const sem::Constant& constant) {
|
||||
if (constant.AllZero()) {
|
||||
return GenerateConstantNullIfNeeded(constant.Type());
|
||||
}
|
||||
|
||||
static constexpr size_t kOpsResultIdx = 1; // operand index of the result
|
||||
auto& global_scope = scope_stack_[0];
|
||||
|
||||
auto gen_bool = [&](size_t element_idx) {
|
||||
bool val = constant.Element<AInt>(element_idx);
|
||||
return GenerateConstantIfNeeded(ScalarConstant::Bool(val));
|
||||
};
|
||||
auto gen_f32 = [&](size_t element_idx) {
|
||||
auto val = f32(constant.Element<AFloat>(element_idx));
|
||||
return GenerateConstantIfNeeded(ScalarConstant::F32(val.value));
|
||||
};
|
||||
auto gen_i32 = [&](size_t element_idx) {
|
||||
auto val = i32(constant.Element<AInt>(element_idx));
|
||||
return GenerateConstantIfNeeded(ScalarConstant::I32(val.value));
|
||||
};
|
||||
auto gen_u32 = [&](size_t element_idx) {
|
||||
auto val = u32(constant.Element<AInt>(element_idx));
|
||||
return GenerateConstantIfNeeded(ScalarConstant::U32(val.value));
|
||||
};
|
||||
auto gen_els = [&](std::vector<Operand>& ids, size_t start, size_t end, auto gen_el) {
|
||||
for (size_t i = start; i < end; i++) {
|
||||
auto id = gen_el(i);
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
ids.emplace_back(id);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
auto gen_vector = [&](const sem::Vector* ty, size_t start, size_t end) -> uint32_t {
|
||||
auto type_id = GenerateTypeIfNeeded(ty);
|
||||
if (!type_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<Operand> ops;
|
||||
ops.reserve(end - start + 2);
|
||||
ops.emplace_back(type_id);
|
||||
ops.push_back(Operand(0u)); // Placeholder for the result ID
|
||||
auto ok = Switch(
|
||||
constant.ElementType(), //
|
||||
[&](const sem::Bool*) { return gen_els(ops, start, end, gen_bool); }, //
|
||||
[&](const sem::F32*) { return gen_els(ops, start, end, gen_f32); }, //
|
||||
[&](const sem::I32*) { return gen_els(ops, start, end, gen_i32); }, //
|
||||
[&](const sem::U32*) { return gen_els(ops, start, end, gen_u32); }, //
|
||||
[&](Default) {
|
||||
error_ = "unhandled constant element type: " + builder_.FriendlyName(ty);
|
||||
return false;
|
||||
});
|
||||
if (!ok) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return utils::GetOrCreate(global_scope.type_ctor_to_id_, OperandListKey{ops},
|
||||
[&]() -> uint32_t {
|
||||
auto result = result_op();
|
||||
ops[kOpsResultIdx] = result;
|
||||
push_type(spv::Op::OpConstantComposite, std::move(ops));
|
||||
return std::get<uint32_t>(result);
|
||||
});
|
||||
};
|
||||
auto gen_matrix = [&](const sem::Matrix* m) -> uint32_t {
|
||||
auto mat_type_id = GenerateTypeIfNeeded(m);
|
||||
if (!mat_type_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<Operand> ops;
|
||||
ops.reserve(m->columns() + 2);
|
||||
ops.emplace_back(mat_type_id);
|
||||
ops.push_back(Operand(0u)); // Placeholder for the result ID
|
||||
|
||||
for (size_t column_idx = 0; column_idx < m->columns(); column_idx++) {
|
||||
size_t start = m->rows() * column_idx;
|
||||
size_t end = m->rows() * (column_idx + 1);
|
||||
auto column_id = gen_vector(m->ColumnType(), start, end);
|
||||
if (!column_id) {
|
||||
return 0;
|
||||
}
|
||||
ops.emplace_back(column_id);
|
||||
}
|
||||
|
||||
return utils::GetOrCreate(global_scope.type_ctor_to_id_, OperandListKey{ops},
|
||||
[&]() -> uint32_t {
|
||||
auto result = result_op();
|
||||
ops[kOpsResultIdx] = result;
|
||||
push_type(spv::Op::OpConstantComposite, std::move(ops));
|
||||
return std::get<uint32_t>(result);
|
||||
});
|
||||
};
|
||||
|
||||
return Switch(
|
||||
constant.Type(), //
|
||||
[&](const sem::Bool*) { return gen_bool(0); }, //
|
||||
[&](const sem::F32*) { return gen_f32(0); }, //
|
||||
[&](const sem::I32*) { return gen_i32(0); }, //
|
||||
[&](const sem::U32*) { return gen_u32(0); }, //
|
||||
[&](const sem::Vector* v) { return gen_vector(v, 0, constant.ElementCount()); }, //
|
||||
[&](const sem::Matrix* m) { return gen_matrix(m); }, //
|
||||
[&](Default) {
|
||||
error_ = "unhandled constant type: " + builder_.FriendlyName(constant.Type());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
uint32_t Builder::GenerateConstantIfNeeded(const ScalarConstant& constant) {
|
||||
auto it = const_to_id_.find(constant);
|
||||
if (it != const_to_id_.end()) {
|
||||
@@ -2174,12 +2304,7 @@ bool Builder::GenerateBlockStatementWithoutScoping(const ast::BlockStatement* st
|
||||
}
|
||||
|
||||
uint32_t Builder::GenerateCallExpression(const ast::CallExpression* expr) {
|
||||
auto* sem = builder_.Sem().Get(expr);
|
||||
if (auto* m = sem->As<sem::Materialize>()) {
|
||||
// TODO(crbug.com/tint/1504): Just emit the constant value.
|
||||
sem = m->Expr();
|
||||
}
|
||||
auto* call = sem->As<sem::Call>();
|
||||
auto* call = builder_.Sem().Get<sem::Call>(expr);
|
||||
auto* target = call->Target();
|
||||
return Switch(
|
||||
target, [&](const sem::Function* func) { return GenerateFunctionCall(call, func); },
|
||||
@@ -2936,10 +3061,9 @@ bool Builder::GenerateTextureBuiltin(const sem::Call* call,
|
||||
}
|
||||
spirv_params.emplace_back(gen_arg(Usage::kDepthRef));
|
||||
|
||||
ast::FloatLiteralExpression float_0(ProgramID(), Source{}, 0.0,
|
||||
ast::FloatLiteralExpression::Suffix::kF);
|
||||
image_operands.emplace_back(ImageOperand{
|
||||
SpvImageOperandsLodMask, Operand(GenerateLiteralIfNeeded(nullptr, &float_0))});
|
||||
image_operands.emplace_back(
|
||||
ImageOperand{SpvImageOperandsLodMask,
|
||||
Operand(GenerateConstantIfNeeded(ScalarConstant::F32(0.0)))});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
// Forward declarations
|
||||
namespace tint::sem {
|
||||
class Call;
|
||||
class Constant;
|
||||
class Reference;
|
||||
class TypeConstructor;
|
||||
class TypeConversion;
|
||||
@@ -550,6 +551,11 @@ class Builder {
|
||||
/// @param expr the expression
|
||||
const sem::Type* TypeOf(const ast::Expression* expr) const { return builder_.TypeOf(expr); }
|
||||
|
||||
/// Generates a constant value if needed
|
||||
/// @param constant the constant to generate.
|
||||
/// @returns the ID on success or 0 on failure
|
||||
uint32_t GenerateConstantIfNeeded(const sem::Constant& constant);
|
||||
|
||||
/// Generates a scalar constant if needed
|
||||
/// @param constant the constant to generate.
|
||||
/// @returns the ID on success or 0 on failure
|
||||
|
||||
@@ -326,7 +326,7 @@ TEST_F(BuilderTest, MemberAccessor_NonPointer) {
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeStruct %2 %2
|
||||
%3 = OpConstant %2 0
|
||||
%3 = OpConstantNull %2
|
||||
%4 = OpConstantComposite %1 %3 %3
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
@@ -367,7 +367,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_NonPointer) {
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypeStruct %3 %3
|
||||
%1 = OpTypeStruct %2
|
||||
%4 = OpConstant %3 0
|
||||
%4 = OpConstantNull %3
|
||||
%5 = OpConstantComposite %2 %4 %4
|
||||
%6 = OpConstantComposite %1 %5
|
||||
)");
|
||||
@@ -729,7 +729,7 @@ TEST_F(BuilderTest, IndexAccessor_Mixed_ArrayAndMember) {
|
||||
%2 = OpTypePointer Function %3
|
||||
%13 = OpConstantNull %3
|
||||
%14 = OpTypeInt 32 1
|
||||
%15 = OpConstant %14 0
|
||||
%15 = OpConstantNull %14
|
||||
%16 = OpConstant %10 0
|
||||
%17 = OpConstant %14 2
|
||||
%18 = OpTypePointer Function %8
|
||||
@@ -916,7 +916,7 @@ TEST_F(BuilderTest, IndexAccessor_Array_Literal) {
|
||||
%7 = OpTypeInt 32 0
|
||||
%8 = OpConstant %7 3
|
||||
%5 = OpTypeArray %6 %8
|
||||
%9 = OpConstant %6 0
|
||||
%9 = OpConstantNull %6
|
||||
%10 = OpConstant %6 0.5
|
||||
%11 = OpConstant %6 1
|
||||
%12 = OpConstantComposite %5 %9 %10 %11
|
||||
@@ -954,7 +954,7 @@ TEST_F(BuilderTest, IndexAccessor_Array_Dynamic) {
|
||||
%7 = OpTypeInt 32 0
|
||||
%8 = OpConstant %7 3
|
||||
%5 = OpTypeArray %6 %8
|
||||
%9 = OpConstant %6 0
|
||||
%9 = OpConstantNull %6
|
||||
%10 = OpConstant %6 0.5
|
||||
%11 = OpConstant %6 1
|
||||
%12 = OpConstantComposite %5 %9 %10 %11
|
||||
|
||||
@@ -98,7 +98,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorNestedVector) {
|
||||
auto* init = vec3<f32>(vec2<f32>(1_f, 2_f), 3_f);
|
||||
|
||||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||
@@ -121,17 +121,13 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||
%2 = OpTypePointer Private %3
|
||||
%5 = OpConstantNull %3
|
||||
%1 = OpVariable %2 Private %5
|
||||
%6 = OpTypeVector %4 2
|
||||
%7 = OpConstant %4 1
|
||||
%8 = OpConstant %4 2
|
||||
%9 = OpConstantComposite %6 %7 %8
|
||||
%12 = OpConstant %4 3
|
||||
%6 = OpConstant %4 1
|
||||
%7 = OpConstant %4 2
|
||||
%8 = OpConstant %4 3
|
||||
%9 = OpConstantComposite %3 %6 %7 %8
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%10 = OpCompositeExtract %4 %9 0
|
||||
%11 = OpCompositeExtract %4 %9 1
|
||||
%13 = OpCompositeConstruct %3 %10 %11 %12
|
||||
OpStore %1 %13
|
||||
R"(OpStore %1 %9
|
||||
)");
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ TEST_P(BinaryOperatorBoolTest, Scalar) {
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
%3 = OpConstantFalse %1
|
||||
%3 = OpConstantNull %1
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
"%4 = " + param.name + " %1 %2 %3\n");
|
||||
@@ -724,7 +724,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
||||
%3 = OpConstantTrue %2
|
||||
%5 = OpTypePointer Private %2
|
||||
%4 = OpVariable %5 Private %3
|
||||
%6 = OpConstantFalse %2
|
||||
%6 = OpConstantNull %2
|
||||
%7 = OpVariable %5 Private %6
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
@@ -761,7 +761,7 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
%8 = OpConstantNull %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%1 = OpLabel
|
||||
@@ -801,7 +801,7 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
%8 = OpConstantNull %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%1 = OpLabel
|
||||
@@ -877,7 +877,7 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
||||
%3 = OpConstantTrue %2
|
||||
%5 = OpTypePointer Private %2
|
||||
%4 = OpVariable %5 Private %3
|
||||
%6 = OpConstantFalse %2
|
||||
%6 = OpConstantNull %2
|
||||
%7 = OpVariable %5 Private %6
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
|
||||
@@ -589,7 +589,7 @@ OpCapability ImageQuery
|
||||
%16 = OpConstant %4 2
|
||||
%17 = OpConstantComposite %14 %15 %16
|
||||
%18 = OpTypeInt 32 1
|
||||
%19 = OpConstant %18 0
|
||||
%19 = OpConstantNull %18
|
||||
)",
|
||||
R"(
|
||||
%10 = OpLoad %7 %5
|
||||
@@ -615,7 +615,7 @@ OpCapability ImageQuery
|
||||
%16 = OpConstant %4 2
|
||||
%17 = OpConstantComposite %14 %15 %16
|
||||
%18 = OpTypeInt 32 1
|
||||
%19 = OpConstant %18 0
|
||||
%19 = OpConstantNull %18
|
||||
%20 = OpTypeVector %18 2
|
||||
%21 = OpConstant %18 3
|
||||
%22 = OpConstant %18 4
|
||||
@@ -645,7 +645,7 @@ OpCapability ImageQuery
|
||||
%16 = OpConstant %4 2
|
||||
%18 = OpTypeInt 32 1
|
||||
%19 = OpConstant %18 3
|
||||
%21 = OpConstant %18 0
|
||||
%21 = OpConstantNull %18
|
||||
)",
|
||||
R"(
|
||||
%10 = OpLoad %7 %5
|
||||
@@ -673,7 +673,7 @@ OpCapability ImageQuery
|
||||
%16 = OpConstant %4 2
|
||||
%18 = OpTypeInt 32 1
|
||||
%19 = OpConstant %18 3
|
||||
%21 = OpConstant %18 0
|
||||
%21 = OpConstantNull %18
|
||||
%22 = OpTypeVector %18 2
|
||||
%23 = OpConstant %18 4
|
||||
%24 = OpConstant %18 5
|
||||
@@ -706,7 +706,7 @@ OpCapability ImageQuery
|
||||
%17 = OpConstant %4 3
|
||||
%18 = OpConstantComposite %14 %15 %16 %17
|
||||
%19 = OpTypeInt 32 1
|
||||
%20 = OpConstant %19 0
|
||||
%20 = OpConstantNull %19
|
||||
)",
|
||||
R"(
|
||||
%10 = OpLoad %7 %5
|
||||
@@ -732,7 +732,7 @@ OpCapability ImageQuery
|
||||
%16 = OpConstant %4 3
|
||||
%18 = OpTypeInt 32 1
|
||||
%19 = OpConstant %18 4
|
||||
%21 = OpConstant %18 0
|
||||
%21 = OpConstantNull %18
|
||||
)",
|
||||
R"(
|
||||
%10 = OpLoad %7 %5
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorNestedVector) {
|
||||
auto* init = vec3<f32>(vec2<f32>(1_f, 2_f), 3_f);
|
||||
|
||||
auto* v = GlobalConst("var", ty.vec3<f32>(), init);
|
||||
@@ -112,17 +112,10 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpTypeVector %2 2
|
||||
%4 = OpConstant %2 1
|
||||
%5 = OpConstant %2 2
|
||||
%6 = OpConstantComposite %3 %4 %5
|
||||
%8 = OpTypeInt 32 0
|
||||
%9 = OpConstant %8 0
|
||||
%7 = OpSpecConstantOp %2 CompositeExtract %6 9
|
||||
%11 = OpConstant %8 1
|
||||
%10 = OpSpecConstantOp %2 CompositeExtract %6 11
|
||||
%12 = OpConstant %2 3
|
||||
%13 = OpSpecConstantComposite %1 %7 %10 %12
|
||||
%3 = OpConstant %2 1
|
||||
%4 = OpConstant %2 2
|
||||
%5 = OpConstant %2 3
|
||||
%6 = OpConstantComposite %1 %3 %4 %5
|
||||
)");
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
||||
%6 = OpConstantTrue %5
|
||||
%10 = OpConstant %3 2
|
||||
%14 = OpConstant %3 3
|
||||
%15 = OpConstantFalse %5
|
||||
%15 = OpConstantNull %5
|
||||
%19 = OpConstant %3 4
|
||||
%20 = OpConstant %3 5
|
||||
)");
|
||||
@@ -472,7 +472,7 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%1 = OpTypeFunction %2
|
||||
%5 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
%8 = OpConstantNull %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(OpSelectionMerge %6 None
|
||||
@@ -542,7 +542,7 @@ TEST_F(BuilderTest, If_WithNestedBlockReturnValue) {
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%1 = OpTypeFunction %2
|
||||
%5 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
%8 = OpConstantNull %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(OpSelectionMerge %6 None
|
||||
@@ -600,7 +600,7 @@ TEST_F(BuilderTest, If_ElseIf_WithReturn) {
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%5 = OpTypeBool
|
||||
%6 = OpConstantFalse %5
|
||||
%6 = OpConstantNull %5
|
||||
%10 = OpConstantTrue %5
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
@@ -638,7 +638,7 @@ TEST_F(BuilderTest, Loop_If_ElseIf_WithBreak) {
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%9 = OpTypeBool
|
||||
%10 = OpConstantFalse %9
|
||||
%10 = OpConstantNull %9
|
||||
%14 = OpConstantTrue %9
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
|
||||
@@ -79,7 +79,7 @@ TEST_F(BuilderTest, UnaryOp_Not) {
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantFalse %2
|
||||
%3 = OpConstantNull %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(%1 = OpLogicalNot %2 %3
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "src/tint/transform/canonicalize_entry_point_io.h"
|
||||
#include "src/tint/transform/disable_uniformity_analysis.h"
|
||||
#include "src/tint/transform/expand_compound_assignment.h"
|
||||
#include "src/tint/transform/fold_constants.h"
|
||||
#include "src/tint/transform/for_loop_to_loop.h"
|
||||
#include "src/tint/transform/manager.h"
|
||||
#include "src/tint/transform/promote_side_effects_to_decl.h"
|
||||
@@ -73,7 +72,6 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
|
||||
manager.Add<transform::PromoteSideEffectsToDecl>();
|
||||
manager.Add<transform::UnwindDiscardFunctions>();
|
||||
manager.Add<transform::SimplifyPointers>(); // Required for arrayLength()
|
||||
manager.Add<transform::FoldConstants>();
|
||||
manager.Add<transform::VectorizeScalarMatrixConstructors>();
|
||||
manager.Add<transform::ForLoopToLoop>(); // Must come after
|
||||
// ZeroInitWorkgroupMemory
|
||||
|
||||
Reference in New Issue
Block a user