[spirv-reader] Simplify null composites
Use the shortcut for zero-values: a type constructor without any parameters. Scalars still use plain literals like false, 1u, 1.0. Change-Id: Ie436f1af28cbab0b4c87a07b057deb04632eb534 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23680 Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
parent
13d2a3b96c
commit
1ca5382749
|
@ -135,8 +135,6 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__u32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,8 +147,6 @@ VariableDeclStatement{
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__i32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +159,6 @@ VariableDeclStatement{
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,16 +189,6 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__mat_2_2__f32
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,8 +220,6 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,10 +250,6 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__alias_S__struct_S
|
||||
ScalarConstructor{false}
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,8 +492,6 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -526,8 +524,6 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType_Null) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__alias_Arr__array__u32_2_16
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -599,13 +595,6 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__alias_S__struct_S
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0.000000}
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/builtin_decoration.h"
|
||||
#include "src/ast/decorated_variable.h"
|
||||
#include "src/ast/expression.h"
|
||||
#include "src/ast/float_literal.h"
|
||||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/sint_literal.h"
|
||||
|
@ -969,10 +970,6 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
|||
|
||||
std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
|
||||
ast::type::Type* type) {
|
||||
// TODO(dneto): Use the no-operands constructor syntax when it becomes
|
||||
// available in Tint.
|
||||
// https://github.com/gpuweb/gpuweb/issues/685
|
||||
// https://bugs.chromium.org/p/tint/issues/detail?id=34
|
||||
|
||||
if (!type) {
|
||||
Fail() << "trying to create null value for a null type";
|
||||
|
@ -998,45 +995,10 @@ std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
|
|||
return std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(type, 0.0f));
|
||||
}
|
||||
if (type->IsVector()) {
|
||||
const auto* vec_ty = type->AsVector();
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < vec_ty->size(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
|
||||
}
|
||||
if (type->IsVector() || type->IsMatrix() || type->IsArray() ||
|
||||
type->IsStruct()) {
|
||||
return std::make_unique<ast::TypeConstructorExpression>(
|
||||
type, std::move(ast_components));
|
||||
}
|
||||
if (type->IsMatrix()) {
|
||||
const auto* mat_ty = type->AsMatrix();
|
||||
// Matrix components are columns
|
||||
auto* column_ty =
|
||||
ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
|
||||
mat_ty->type(), mat_ty->rows()));
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < mat_ty->columns(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(column_ty));
|
||||
}
|
||||
return std::make_unique<ast::TypeConstructorExpression>(
|
||||
type, std::move(ast_components));
|
||||
}
|
||||
if (type->IsArray()) {
|
||||
auto* arr_ty = type->AsArray();
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < arr_ty->size(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(arr_ty->type()));
|
||||
}
|
||||
return std::make_unique<ast::TypeConstructorExpression>(
|
||||
original_type, std::move(ast_components));
|
||||
}
|
||||
if (type->IsStruct()) {
|
||||
auto* struct_ty = type->AsStruct();
|
||||
ast::ExpressionList ast_components;
|
||||
for (auto& member : struct_ty->impl()->members()) {
|
||||
ast_components.emplace_back(MakeNullValue(member->type()));
|
||||
}
|
||||
return std::make_unique<ast::TypeConstructorExpression>(
|
||||
original_type, std::move(ast_components));
|
||||
original_type, ast::ExpressionList{});
|
||||
}
|
||||
Fail() << "can't make null value for type: " << type->type_name();
|
||||
return nullptr;
|
||||
|
|
|
@ -382,8 +382,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__bool
|
||||
ScalarConstructor{false}
|
||||
ScalarConstructor{false}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -405,8 +403,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__bool
|
||||
ScalarConstructor{false}
|
||||
ScalarConstructor{false}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -428,8 +424,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__u32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -451,8 +445,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__u32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -474,8 +466,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__i32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -497,8 +487,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__i32
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -520,8 +508,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -543,8 +529,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -608,21 +592,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__mat_2_3__f32
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -644,21 +613,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__mat_2_3__f32
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
TypeConstructor{
|
||||
__vec_2__f32
|
||||
ScalarConstructor{0.000000}
|
||||
ScalarConstructor{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -704,8 +658,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -727,8 +679,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
|
@ -781,13 +731,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_StructNullInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__alias_S__struct_S
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0.000000}
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"))
|
||||
|
@ -810,13 +753,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_StructUndefInitializer) {
|
|||
{
|
||||
TypeConstructor{
|
||||
__alias_S__struct_S
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0.000000}
|
||||
TypeConstructor{
|
||||
__array__u32_2
|
||||
ScalarConstructor{0}
|
||||
ScalarConstructor{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"))
|
||||
|
|
Loading…
Reference in New Issue