Move scalar types over to type/ folder.

This CL moves Bool, F16, F32, I32, U32, and Void over to the type folder
and updates namespaces as needed.

Bug: tint:1718
Change-Id: If3056521e5283ac2d9e1fd09c6daf0f647dd3846
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113342
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-12-08 16:39:59 +00:00
committed by Dawn LUCI CQ
parent c223ae26ec
commit d37ecf9055
90 changed files with 1572 additions and 1524 deletions

View File

@@ -473,7 +473,7 @@ struct BuiltinPolyfill::State {
uint32_t width = WidthOf(ty);
// Currently in WGSL parameters of insertBits must be i32, u32, vecN<i32> or vecN<u32>
if (!type::Type::DeepestElementOf(ty)->IsAnyOf<sem::I32, sem::U32>()) {
if (!type::Type::DeepestElementOf(ty)->IsAnyOf<type::I32, type::U32>()) {
TINT_ICE(Transform, b.Diagnostics())
<< "insertBits polyfill only support i32, u32, and vector of i32 or u32, got "
<< b.FriendlyName(ty);
@@ -895,7 +895,7 @@ Transform::ApplyResult BuiltinPolyfill::Apply(const Program* src,
auto& sig = builtin->Signature();
auto* tex = sig.Parameter(sem::ParameterUsage::kTexture);
if (auto* stex = tex->Type()->As<type::SampledTexture>()) {
if (stex->type()->Is<sem::F32>()) {
if (stex->type()->Is<type::F32>()) {
fn = builtin_polyfills.GetOrCreate(builtin, [&] {
return s.textureSampleBaseClampToEdge_2d_f32();
});

View File

@@ -396,7 +396,7 @@ struct CanonicalizeEntryPointIO::State {
AddOutput(name, member->Type(), member->Location(), std::move(attributes),
ctx.dst->MemberAccessor(original_result, name));
}
} else if (!inner_ret_type->Is<sem::Void>()) {
} else if (!inner_ret_type->Is<type::Void>()) {
auto attributes =
CloneShaderIOAttributes(func_ast->return_type_attributes, do_interpolate);
@@ -421,7 +421,7 @@ struct CanonicalizeEntryPointIO::State {
// No existing sample mask builtin was found, so create a new output value
// using the fixed sample mask.
AddOutput("fixed_sample_mask", ctx.dst->create<sem::U32>(), std::nullopt,
AddOutput("fixed_sample_mask", ctx.dst->create<type::U32>(), std::nullopt,
{ctx.dst->Builtin(ast::BuiltinValue::kSampleMask)},
ctx.dst->Expr(u32(cfg.fixed_sample_mask)));
}
@@ -429,7 +429,7 @@ struct CanonicalizeEntryPointIO::State {
/// Add a point size builtin to the wrapper function output.
void AddVertexPointSize() {
// Create a new output value and assign it a literal 1.0 value.
AddOutput("vertex_point_size", ctx.dst->create<sem::F32>(), std::nullopt,
AddOutput("vertex_point_size", ctx.dst->create<type::F32>(), std::nullopt,
{ctx.dst->Builtin(ast::BuiltinValue::kPointSize)}, ctx.dst->Expr(1_f));
}
@@ -576,7 +576,7 @@ struct CanonicalizeEntryPointIO::State {
}
// Exit early if there is no shader IO to handle.
if (func_sem->Parameters().Length() == 0 && func_sem->ReturnType()->Is<sem::Void>() &&
if (func_sem->Parameters().Length() == 0 && func_sem->ReturnType()->Is<type::Void>() &&
!needs_fixed_sample_mask && !needs_vertex_point_size &&
cfg.shader_style != ShaderStyle::kGlsl) {
return;
@@ -604,7 +604,7 @@ struct CanonicalizeEntryPointIO::State {
// Process the return type, and start building the wrapper function body.
std::function<const ast::Type*()> wrapper_ret_type = [&] { return ctx.dst->ty.void_(); };
if (func_sem->ReturnType()->Is<sem::Void>()) {
if (func_sem->ReturnType()->Is<type::Void>()) {
// The function call is just a statement with no result.
wrapper_body.Push(ctx.dst->CallStmt(call_inner));
} else {
@@ -760,7 +760,7 @@ struct CanonicalizeEntryPointIO::State {
case ast::BuiltinValue::kInstanceIndex:
case ast::BuiltinValue::kSampleIndex:
case ast::BuiltinValue::kSampleMask:
type = ctx.dst->create<sem::I32>();
type = ctx.dst->create<type::I32>();
value = ctx.dst->Bitcast(CreateASTTypeFor(ctx, type), value);
break;
default:

View File

@@ -76,7 +76,7 @@ struct OffsetExpr : Offset {
const ast::Expression* Build(CloneContext& ctx) const override {
auto* type = ctx.src->Sem().Get(expr)->Type()->UnwrapRef();
auto* res = ctx.Clone(expr);
if (!type->Is<sem::U32>()) {
if (!type->Is<type::U32>()) {
res = ctx.dst->Construct<u32>(res);
}
return res;
@@ -141,74 +141,74 @@ struct AtomicKey {
};
bool IntrinsicDataTypeFor(const type::Type* ty, DecomposeMemoryAccess::Intrinsic::DataType& out) {
if (ty->Is<sem::I32>()) {
if (ty->Is<type::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kI32;
return true;
}
if (ty->Is<sem::U32>()) {
if (ty->Is<type::U32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kU32;
return true;
}
if (ty->Is<sem::F32>()) {
if (ty->Is<type::F32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kF32;
return true;
}
if (ty->Is<sem::F16>()) {
if (ty->Is<type::F16>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kF16;
return true;
}
if (auto* vec = ty->As<sem::Vector>()) {
switch (vec->Width()) {
case 2:
if (vec->type()->Is<sem::I32>()) {
if (vec->type()->Is<type::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec2I32;
return true;
}
if (vec->type()->Is<sem::U32>()) {
if (vec->type()->Is<type::U32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec2U32;
return true;
}
if (vec->type()->Is<sem::F32>()) {
if (vec->type()->Is<type::F32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec2F32;
return true;
}
if (vec->type()->Is<sem::F16>()) {
if (vec->type()->Is<type::F16>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec2F16;
return true;
}
break;
case 3:
if (vec->type()->Is<sem::I32>()) {
if (vec->type()->Is<type::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec3I32;
return true;
}
if (vec->type()->Is<sem::U32>()) {
if (vec->type()->Is<type::U32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec3U32;
return true;
}
if (vec->type()->Is<sem::F32>()) {
if (vec->type()->Is<type::F32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec3F32;
return true;
}
if (vec->type()->Is<sem::F16>()) {
if (vec->type()->Is<type::F16>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec3F16;
return true;
}
break;
case 4:
if (vec->type()->Is<sem::I32>()) {
if (vec->type()->Is<type::I32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec4I32;
return true;
}
if (vec->type()->Is<sem::U32>()) {
if (vec->type()->Is<type::U32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec4U32;
return true;
}
if (vec->type()->Is<sem::F32>()) {
if (vec->type()->Is<type::F32>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec4F32;
return true;
}
if (vec->type()->Is<sem::F16>()) {
if (vec->type()->Is<type::F16>()) {
out = DecomposeMemoryAccess::Intrinsic::DataType::kVec4F16;
return true;
}

View File

@@ -573,7 +573,7 @@ struct DirectVariableAccess::State {
if (!idx->UnwrapMaterialize()
->Type()
->UnwrapRef()
->IsAnyOf<sem::U32, type::AbstractInt>()) {
->IsAnyOf<type::U32, type::AbstractInt>()) {
expr = b.Construct(b.ty.u32(), expr);
}
}

View File

@@ -201,8 +201,8 @@ struct SpirvAtomic::State {
const ast::Type* AtomicTypeFor(const type::Type* ty) {
return Switch(
ty, //
[&](const sem::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const sem::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const type::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const type::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); },
[&](const sem::Struct* str) { return b.ty.type_name(Fork(str->Declaration()).name); },
[&](const sem::Array* arr) -> const ast::Type* {
if (arr->Count()->Is<type::RuntimeArrayCount>()) {

View File

@@ -645,8 +645,8 @@ struct Std140::State {
return "mat" + std::to_string(mat->columns()) + "x" + std::to_string(mat->rows()) +
"_" + ConvertSuffix(mat->type());
},
[&](const sem::F32*) { return "f32"; }, //
[&](const sem::F16*) { return "f16"; },
[&](const type::F32*) { return "f32"; }, //
[&](const type::F16*) { return "f16"; },
[&](Default) {
TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for conversion name: " << src->FriendlyName(ty);

View File

@@ -81,11 +81,11 @@ Transform::ApplyResult SubstituteOverride::Apply(const Program* src,
auto value = iter->second;
auto* ctor = Switch(
sem->Type(),
[&](const sem::Bool*) { return b.Expr(!std::equal_to<double>()(value, 0.0)); },
[&](const sem::I32*) { return b.Expr(i32(value)); },
[&](const sem::U32*) { return b.Expr(u32(value)); },
[&](const sem::F32*) { return b.Expr(f32(value)); },
[&](const sem::F16*) { return b.Expr(f16(value)); });
[&](const type::Bool*) { return b.Expr(!std::equal_to<double>()(value, 0.0)); },
[&](const type::I32*) { return b.Expr(i32(value)); },
[&](const type::U32*) { return b.Expr(u32(value)); },
[&](const type::F32*) { return b.Expr(f32(value)); },
[&](const type::F16*) { return b.Expr(f16(value)); });
if (!ctor) {
b.Diagnostics().add_error(diag::System::Transform,

View File

@@ -74,22 +74,22 @@ void Transform::RemoveStatement(CloneContext& ctx, const ast::Statement* stmt) {
}
const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type* ty) {
if (ty->Is<sem::Void>()) {
if (ty->Is<type::Void>()) {
return ctx.dst->create<ast::Void>();
}
if (ty->Is<sem::I32>()) {
if (ty->Is<type::I32>()) {
return ctx.dst->create<ast::I32>();
}
if (ty->Is<sem::U32>()) {
if (ty->Is<type::U32>()) {
return ctx.dst->create<ast::U32>();
}
if (ty->Is<sem::F16>()) {
if (ty->Is<type::F16>()) {
return ctx.dst->create<ast::F16>();
}
if (ty->Is<sem::F32>()) {
if (ty->Is<type::F32>()) {
return ctx.dst->create<ast::F32>();
}
if (ty->Is<sem::Bool>()) {
if (ty->Is<type::Bool>()) {
return ctx.dst->create<ast::Bool>();
}
if (auto* m = ty->As<sem::Matrix>()) {

View File

@@ -41,16 +41,16 @@ struct CreateASTTypeForTest : public testing::Test, public Transform {
};
TEST_F(CreateASTTypeForTest, Basic) {
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<sem::I32>(); })->Is<ast::I32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<sem::U32>(); })->Is<ast::U32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<sem::F32>(); })->Is<ast::F32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<sem::Bool>(); })->Is<ast::Bool>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<sem::Void>(); })->Is<ast::Void>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::I32>(); })->Is<ast::I32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::U32>(); })->Is<ast::U32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::F32>(); })->Is<ast::F32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::Bool>(); })->Is<ast::Bool>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::Void>(); })->Is<ast::Void>());
}
TEST_F(CreateASTTypeForTest, Matrix) {
auto* mat = create([](ProgramBuilder& b) {
auto* column_type = b.create<sem::Vector>(b.create<sem::F32>(), 2u);
auto* column_type = b.create<sem::Vector>(b.create<type::F32>(), 2u);
return b.create<sem::Matrix>(column_type, 3u);
});
ASSERT_TRUE(mat->Is<ast::Matrix>());
@@ -61,7 +61,7 @@ TEST_F(CreateASTTypeForTest, Matrix) {
TEST_F(CreateASTTypeForTest, Vector) {
auto* vec =
create([](ProgramBuilder& b) { return b.create<sem::Vector>(b.create<sem::F32>(), 2u); });
create([](ProgramBuilder& b) { return b.create<sem::Vector>(b.create<type::F32>(), 2u); });
ASSERT_TRUE(vec->Is<ast::Vector>());
ASSERT_TRUE(vec->As<ast::Vector>()->type->Is<ast::F32>());
ASSERT_EQ(vec->As<ast::Vector>()->width, 2u);
@@ -69,7 +69,7 @@ TEST_F(CreateASTTypeForTest, Vector) {
TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<sem::F32>(), b.create<type::ConstantArrayCount>(2u),
return b.create<sem::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 32u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());
@@ -83,7 +83,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) {
auto* arr = create([](ProgramBuilder& b) {
return b.create<sem::Array>(b.create<sem::F32>(), b.create<type::ConstantArrayCount>(2u),
return b.create<sem::Array>(b.create<type::F32>(), b.create<type::ConstantArrayCount>(2u),
4u, 4u, 64u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());

View File

@@ -153,16 +153,16 @@ bool IsTypeCompatible(AttributeWGSLType wgslType, VertexFormatType vertexFormatT
AttributeWGSLType WGSLTypeOf(const type::Type* ty) {
return Switch(
ty,
[](const sem::I32*) -> AttributeWGSLType {
[](const type::I32*) -> AttributeWGSLType {
return {BaseWGSLType::kI32, 1};
},
[](const sem::U32*) -> AttributeWGSLType {
[](const type::U32*) -> AttributeWGSLType {
return {BaseWGSLType::kU32, 1};
},
[](const sem::F32*) -> AttributeWGSLType {
[](const type::F32*) -> AttributeWGSLType {
return {BaseWGSLType::kF32, 1};
},
[](const sem::F16*) -> AttributeWGSLType {
[](const type::F16*) -> AttributeWGSLType {
return {BaseWGSLType::kF16, 1};
},
[](const sem::Vector* vec) -> AttributeWGSLType {

View File

@@ -411,7 +411,7 @@ struct ZeroInitWorkgroupMemory::State {
// Constant value could not be found. Build expression instead.
workgroup_size_expr = [this, expr, size = workgroup_size_expr] {
auto* e = ctx.Clone(expr);
if (ctx.src->TypeOf(expr)->UnwrapRef()->Is<sem::I32>()) {
if (ctx.src->TypeOf(expr)->UnwrapRef()->Is<type::I32>()) {
e = b.Construct<u32>(e);
}
return size ? b.Mul(size(), e) : e;