[metal-writer] Stub out the Metal Shading Language backend.

This CL adds the basis of the Metal Shading Language backend.

Bug: tint:8
Change-Id: I85976250eb41ac12203a5db116444e993c3d09d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23700
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair
2020-06-23 17:48:40 +00:00
parent 9a452c11ae
commit 2a59901483
51 changed files with 740 additions and 143 deletions

View File

@@ -135,6 +135,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
{
TypeConstructor{
__vec_2__u32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
@@ -147,6 +149,8 @@ VariableDeclStatement{
{
TypeConstructor{
__vec_2__i32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
@@ -159,6 +163,8 @@ VariableDeclStatement{
{
TypeConstructor{
__vec_2__f32
ScalarConstructor{0.000000}
ScalarConstructor{0.000000}
}
}
}
@@ -189,6 +195,16 @@ 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}
}
}
}
}
@@ -220,6 +236,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
{
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
@@ -250,6 +268,10 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
{
TypeConstructor{
__alias_S__struct_S
ScalarConstructor{false}
ScalarConstructor{0}
ScalarConstructor{0}
ScalarConstructor{0.000000}
}
}
}

View File

@@ -492,6 +492,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
{
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
@@ -524,6 +526,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType_Null) {
{
TypeConstructor{
__alias_Arr__array__u32_2_16
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
@@ -595,6 +599,13 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
{
TypeConstructor{
__alias_S__struct_S
ScalarConstructor{0}
ScalarConstructor{0.000000}
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
}

View File

@@ -38,7 +38,6 @@
#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"
@@ -970,6 +969,10 @@ 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";
@@ -995,10 +998,45 @@ std::unique_ptr<ast::Expression> ParserImpl::MakeNullValue(
return std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(type, 0.0f));
}
if (type->IsVector() || type->IsMatrix() || type->IsArray() ||
type->IsStruct()) {
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()));
}
return std::make_unique<ast::TypeConstructorExpression>(
original_type, ast::ExpressionList{});
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));
}
Fail() << "can't make null value for type: " << type->type_name();
return nullptr;

View File

@@ -382,6 +382,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolNullInitializer) {
{
TypeConstructor{
__vec_2__bool
ScalarConstructor{false}
ScalarConstructor{false}
}
}
})"));
@@ -403,6 +405,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorBoolUndefInitializer) {
{
TypeConstructor{
__vec_2__bool
ScalarConstructor{false}
ScalarConstructor{false}
}
}
})"));
@@ -424,6 +428,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintNullInitializer) {
{
TypeConstructor{
__vec_2__u32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -445,6 +451,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorUintUndefInitializer) {
{
TypeConstructor{
__vec_2__u32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -466,6 +474,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntNullInitializer) {
{
TypeConstructor{
__vec_2__i32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -487,6 +497,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorIntUndefInitializer) {
{
TypeConstructor{
__vec_2__i32
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -508,6 +520,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatNullInitializer) {
{
TypeConstructor{
__vec_2__f32
ScalarConstructor{0.000000}
ScalarConstructor{0.000000}
}
}
})"));
@@ -529,6 +543,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_VectorFloatUndefInitializer) {
{
TypeConstructor{
__vec_2__f32
ScalarConstructor{0.000000}
ScalarConstructor{0.000000}
}
}
})"));
@@ -592,6 +608,21 @@ 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}
}
}
}
})"));
@@ -613,6 +644,21 @@ 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}
}
}
}
})"));
@@ -658,6 +704,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayNullInitializer) {
{
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -679,6 +727,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_ArrayUndefInitializer) {
{
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
})"));
@@ -731,6 +781,13 @@ TEST_F(SpvParserTest, ModuleScopeVar_StructNullInitializer) {
{
TypeConstructor{
__alias_S__struct_S
ScalarConstructor{0}
ScalarConstructor{0.000000}
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
})"))
@@ -753,6 +810,13 @@ TEST_F(SpvParserTest, ModuleScopeVar_StructUndefInitializer) {
{
TypeConstructor{
__alias_S__struct_S
ScalarConstructor{0}
ScalarConstructor{0.000000}
TypeConstructor{
__array__u32_2
ScalarConstructor{0}
ScalarConstructor{0}
}
}
}
})"))