[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:
parent
9a452c11ae
commit
2a59901483
50
BUILD.gn
50
BUILD.gn
|
@ -56,6 +56,12 @@ config("tint_public_config") {
|
|||
defines += [ "TINT_BUILD_WGSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_msl_writer) {
|
||||
defines += [ "TINT_BUILD_MSL_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_MSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"${tint_root_dir}/",
|
||||
"${tint_root_dir}/include/",
|
||||
|
@ -353,6 +359,10 @@ source_set("libtint_core_src") {
|
|||
"src/validator.h",
|
||||
"src/validator_impl.cc",
|
||||
"src/validator_impl.h",
|
||||
"src/writer/text.cc",
|
||||
"src/writer/text.h",
|
||||
"src/writer/text_generator.cc",
|
||||
"src/writer/text_generator.h",
|
||||
"src/writer/writer.cc",
|
||||
"src/writer/writer.h",
|
||||
]
|
||||
|
@ -472,6 +482,23 @@ source_set("libtint_wgsl_writer_src") {
|
|||
}
|
||||
}
|
||||
|
||||
source_set("libtint_msl_writer_src") {
|
||||
sources = [
|
||||
"src/writer/msl/generator.cc",
|
||||
"src/writer/msl/generator.h",
|
||||
"src/writer/msl/generator_impl.cc",
|
||||
"src/wrtier/msl/generator_impl.h",
|
||||
]
|
||||
|
||||
configs += [ ":tint_common_config" ]
|
||||
public_configs += [ ":tint_public_config" ]
|
||||
|
||||
if (build_with_chromium) {
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [ "//build/config/compiler:no_chromium_code" ]
|
||||
}
|
||||
}
|
||||
|
||||
source_set("libtint") {
|
||||
deps = [ ":libtint_core_src" ]
|
||||
|
||||
|
@ -491,6 +518,10 @@ source_set("libtint") {
|
|||
deps += [ ":libtint_wgsl_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_msl_writer) {
|
||||
deps += [ ":libtint_msl_writer_src" ]
|
||||
}
|
||||
|
||||
configs += [ ":tint_common_config" ]
|
||||
public_configs = [ ":tint_public_config" ]
|
||||
|
||||
|
@ -852,6 +883,21 @@ source_set("tint_unittests_wgsl_writer_src") {
|
|||
}
|
||||
}
|
||||
|
||||
source_set("tint_unittests_msl_writer_src") {
|
||||
sources = [ "src/writer/msl/generator_impl_test.cc" ]
|
||||
|
||||
configs += [
|
||||
":tint_common_config",
|
||||
":tint_unittests_config",
|
||||
]
|
||||
public_configs = [ ":tint_public_config" ]
|
||||
|
||||
if (build_with_chromium) {
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [ "//build/config/compiler:no_chromium_code" ]
|
||||
}
|
||||
}
|
||||
|
||||
source_set("tint_unittests_src") {
|
||||
deps = [ ":tint_unittests_core_src" ]
|
||||
|
||||
|
@ -871,6 +917,10 @@ source_set("tint_unittests_src") {
|
|||
deps += [ ":tint_unittests_wgsl_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_msl_writer) {
|
||||
deps += [ ":tint_unittests_msl_writer_src" ]
|
||||
}
|
||||
|
||||
configs += [
|
||||
":tint_common_config",
|
||||
":tint_unittests_config",
|
||||
|
|
|
@ -29,6 +29,7 @@ endif()
|
|||
option(TINT_BUILD_DOCS "Build documentation" ON)
|
||||
option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ON)
|
||||
option(TINT_BUILD_WGSL_READER "Builde the WGSL input reader" ON)
|
||||
option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ON)
|
||||
option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON)
|
||||
option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
|
||||
option(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
|
||||
|
@ -50,6 +51,7 @@ endif(WIN32)
|
|||
message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
|
||||
message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
|
||||
message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
|
||||
message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
|
||||
message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
|
||||
message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
|
||||
message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
|
||||
|
@ -116,6 +118,8 @@ function(tint_default_compile_options TARGET)
|
|||
-DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>)
|
||||
target_compile_definitions(${TARGET} PRIVATE
|
||||
-DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>)
|
||||
target_compile_definitions(${TARGET} PRIVATE
|
||||
-DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>)
|
||||
target_compile_definitions(${TARGET} PRIVATE
|
||||
-DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
|
||||
target_compile_definitions(${TARGET} PRIVATE
|
||||
|
|
|
@ -42,4 +42,8 @@
|
|||
#include "src/writer/wgsl/generator.h"
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
#include "src/writer/msl/generator.h"
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
|
||||
#endif // INCLUDE_TINT_TINT_H_
|
||||
|
|
|
@ -32,6 +32,7 @@ enum class Format {
|
|||
kSpirv,
|
||||
kSpvAsm,
|
||||
kWgsl,
|
||||
kMsl,
|
||||
};
|
||||
|
||||
struct Options {
|
||||
|
@ -49,12 +50,13 @@ struct Options {
|
|||
const char kUsage[] = R"(Usage: tint [options] <input-file>
|
||||
|
||||
options:
|
||||
--format <spirv|spvasm|wgsl> -- Output format.
|
||||
--format <spirv|spvasm|wgsl|msl> -- Output format.
|
||||
If not provided, will be inferred from output
|
||||
filename extension:
|
||||
.spvasm -> spvasm
|
||||
.spv -> spirv
|
||||
.wgsl -> wgsl
|
||||
.metal -> msl
|
||||
If none matches, then default to SPIR-V assembly.
|
||||
--output-file <name> -- Output file name. Use "-" for standard output
|
||||
-o <name> -- Output file name. Use "-" for standard output
|
||||
|
@ -79,6 +81,11 @@ Format parse_format(const std::string& fmt) {
|
|||
return Format::kWgsl;
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
if (fmt == "msl")
|
||||
return Format::kMsl;
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
|
||||
return Format::kNone;
|
||||
}
|
||||
|
||||
|
@ -95,16 +102,32 @@ bool ends_with(const std::string& input, const std::string& suffix) {
|
|||
|
||||
/// @param filename the filename to inspect
|
||||
/// @returns the inferred format for the filename suffix
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
Format infer_format(const std::string& filename) {
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#if TINT_BUILD_SPV_WRITER
|
||||
if (ends_with(filename, ".spv")) {
|
||||
return Format::kSpirv;
|
||||
}
|
||||
if (ends_with(filename, ".spvasm")) {
|
||||
return Format::kSpvAsm;
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_WRITER
|
||||
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
if (ends_with(filename, ".wgsl")) {
|
||||
return Format::kWgsl;
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
if (ends_with(filename, ".metal")) {
|
||||
return Format::kMsl;
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
return Format::kNone;
|
||||
}
|
||||
|
||||
|
@ -417,6 +440,12 @@ int main(int argc, const char** argv) {
|
|||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
if (options.format == Format::kMsl) {
|
||||
writer = std::make_unique<tint::writer::msl::Generator>(std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILDER_MSL_WRITER
|
||||
|
||||
if (!writer) {
|
||||
std::cerr << "Unknown output format specified" << std::endl;
|
||||
return 1;
|
||||
|
@ -443,14 +472,14 @@ int main(int argc, const char** argv) {
|
|||
}
|
||||
#endif // TINT_BUILD_SPV_WRITER
|
||||
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
if (options.format == Format::kWgsl) {
|
||||
auto* w = static_cast<tint::writer::wgsl::Generator*>(writer.get());
|
||||
#if TINT_BUILD_WGSL_WRITER || TINT_BUILD_MSL_WRITER
|
||||
if (options.format == Format::kWgsl || options.format == Format::kMsl) {
|
||||
auto* w = static_cast<tint::writer::Text*>(writer.get());
|
||||
if (!WriteFile(options.output_file, "w", w->result())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
#endif // TINT_BUILD_WGSL_WRITER || TINT_BUILD_MSL_WRITER
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -184,6 +184,10 @@ set(TINT_LIB_SRCS
|
|||
validator.h
|
||||
validator_impl.cc
|
||||
validator_impl.h
|
||||
writer/text.cc
|
||||
writer/text.h
|
||||
writer/text_generator.cc
|
||||
writer/text_generator.h
|
||||
writer/writer.cc
|
||||
writer/writer.h
|
||||
)
|
||||
|
@ -245,6 +249,15 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
)
|
||||
endif()
|
||||
|
||||
if(${TINT_BUILD_MSL_WRITER})
|
||||
list(APPEND TINT_LIB_SRCS
|
||||
writer/msl/generator.cc
|
||||
writer/msl/generator.h
|
||||
writer/msl/generator_impl.cc
|
||||
writer/msl/generator_impl.h
|
||||
)
|
||||
endif()
|
||||
|
||||
set(TINT_TEST_SRCS
|
||||
ast/array_accessor_expression_test.cc
|
||||
ast/as_expression_test.cc
|
||||
|
@ -477,6 +490,13 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
writer/wgsl/generator_impl_variable_test.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${TINT_BUILD_MSL_WRITER})
|
||||
list(APPEND TINT_TEST_SRCS
|
||||
writer/msl/generator_impl_test.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(tint_unittests ${TINT_TEST_SRCS})
|
||||
|
||||
if(NOT MSVC)
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"))
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/writer/msl/generator.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
|
||||
Generator::Generator(ast::Module module) : Text(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
bool Generator::Generate() {
|
||||
return impl_.Generate(module_);
|
||||
}
|
||||
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_WRITER_MSL_GENERATOR_H_
|
||||
#define SRC_WRITER_MSL_GENERATOR_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/text.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
|
||||
/// Class to generate WGSL source from a WGSL module
|
||||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
~Generator() override;
|
||||
|
||||
/// Generates the result data
|
||||
/// @returns true on successful generation; false otherwise
|
||||
bool Generate() override;
|
||||
|
||||
/// @returns the result data
|
||||
std::string result() const override { return impl_.result(); }
|
||||
|
||||
/// @returns the error
|
||||
std::string error() const { return impl_.error(); }
|
||||
|
||||
private:
|
||||
GeneratorImpl impl_;
|
||||
};
|
||||
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_WRITER_MSL_GENERATOR_H_
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
|
||||
GeneratorImpl::GeneratorImpl() = default;
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
bool GeneratorImpl::Generate(const ast::Module&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_WRITER_MSL_GENERATOR_IMPL_H_
|
||||
#define SRC_WRITER_MSL_GENERATOR_IMPL_H_
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/text_generator.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
|
||||
/// Implementation class for WGSL generator
|
||||
class GeneratorImpl : public TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
GeneratorImpl();
|
||||
~GeneratorImpl();
|
||||
|
||||
/// Generates the result data
|
||||
/// @param module the module to generate
|
||||
/// @returns true on successful generation; false otherwise
|
||||
bool Generate(const ast::Module& module);
|
||||
};
|
||||
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_WRITER_MSL_GENERATOR_IMPL_H_
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/entry_point.h"
|
||||
#include "src/ast/function.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/pipeline_stage.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, DISABLED_Generate) {
|
||||
ast::type::VoidType void_type;
|
||||
ast::Module m;
|
||||
m.AddFunction(std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type));
|
||||
m.AddEntryPoint(std::make_unique<ast::EntryPoint>(
|
||||
ast::PipelineStage::kCompute, "my_func", ""));
|
||||
|
||||
GeneratorImpl g;
|
||||
|
||||
ASSERT_TRUE(g.Generate(m)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#import <metal_lib>
|
||||
|
||||
compute void my_func() {
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/writer/text.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
Text::Text(ast::Module module) : Writer(std::move(module)) {}
|
||||
|
||||
Text::~Text() = default;
|
||||
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_WRITER_TEXT_H_
|
||||
#define SRC_WRITER_TEXT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/writer/writer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
/// Class to generate text source
|
||||
class Text : public Writer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param module the module to convert
|
||||
explicit Text(ast::Module module);
|
||||
~Text() override;
|
||||
|
||||
/// @returns the result data
|
||||
virtual std::string result() const = 0;
|
||||
};
|
||||
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_WRITER_TEXT_H_
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/writer/text_generator.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
TextGenerator::TextGenerator() = default;
|
||||
|
||||
TextGenerator::~TextGenerator() = default;
|
||||
|
||||
void TextGenerator::make_indent() {
|
||||
for (size_t i = 0; i < indent_; i++) {
|
||||
out_ << " ";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_WRITER_TEXT_GENERATOR_H_
|
||||
#define SRC_WRITER_TEXT_GENERATOR_H_
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
/// Helper methods for generators which are creating text output
|
||||
class TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
TextGenerator();
|
||||
~TextGenerator();
|
||||
|
||||
/// Increment the emitter indent level
|
||||
void increment_indent() { indent_ += 2; }
|
||||
/// Decrement the emiter indent level
|
||||
void decrement_indent() {
|
||||
if (indent_ < 2) {
|
||||
indent_ = 0;
|
||||
return;
|
||||
}
|
||||
indent_ -= 2;
|
||||
}
|
||||
|
||||
/// Writes the current indent to the output stream
|
||||
void make_indent();
|
||||
|
||||
/// @returns the result data
|
||||
std::string result() const { return out_.str(); }
|
||||
|
||||
/// @returns the error
|
||||
std::string error() const { return error_; }
|
||||
|
||||
protected:
|
||||
/// The text output stream
|
||||
std::ostringstream out_;
|
||||
/// Error generated by the generator
|
||||
std::string error_;
|
||||
|
||||
private:
|
||||
size_t indent_ = 0;
|
||||
};
|
||||
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_WRITER_TEXT_GENERATOR_H_
|
|
@ -20,7 +20,7 @@ namespace tint {
|
|||
namespace writer {
|
||||
namespace wgsl {
|
||||
|
||||
Generator::Generator(ast::Module module) : writer::Writer(std::move(module)) {}
|
||||
Generator::Generator(ast::Module module) : Text(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
|
|
|
@ -17,15 +17,15 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "src/writer/text.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
#include "src/writer/writer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace wgsl {
|
||||
|
||||
/// Class to generate WGSL source from a WGSL module
|
||||
class Generator : public writer::Writer {
|
||||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param module the module to convert
|
||||
|
@ -37,7 +37,7 @@ class Generator : public writer::Writer {
|
|||
bool Generate() override;
|
||||
|
||||
/// @returns the result data
|
||||
std::string result() const { return impl_.result(); }
|
||||
std::string result() const override { return impl_.result(); }
|
||||
|
||||
/// @returns the error
|
||||
std::string error() const { return impl_.error(); }
|
||||
|
|
|
@ -110,12 +110,6 @@ bool GeneratorImpl::Generate(const ast::Module& module) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void GeneratorImpl::make_indent() {
|
||||
for (size_t i = 0; i < indent_; i++) {
|
||||
out_ << " ";
|
||||
}
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitAliasType(const ast::type::AliasType* alias) {
|
||||
make_indent();
|
||||
out_ << "type " << alias->name() << " = ";
|
||||
|
|
|
@ -29,13 +29,14 @@
|
|||
#include "src/ast/type/type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/writer/text_generator.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace wgsl {
|
||||
|
||||
/// Implementation class for WGSL generator
|
||||
class GeneratorImpl {
|
||||
class GeneratorImpl : public TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
GeneratorImpl();
|
||||
|
@ -46,26 +47,6 @@ class GeneratorImpl {
|
|||
/// @returns true on successful generation; false otherwise
|
||||
bool Generate(const ast::Module& module);
|
||||
|
||||
/// @returns the result data
|
||||
std::string result() const { return out_.str(); }
|
||||
|
||||
/// @returns the error from the generator
|
||||
std::string error() const { return error_; }
|
||||
|
||||
/// Increment the emitter indent level
|
||||
void increment_indent() { indent_ += 2; }
|
||||
/// Decrement the emiter indent level
|
||||
void decrement_indent() {
|
||||
if (indent_ < 2) {
|
||||
indent_ = 0;
|
||||
return;
|
||||
}
|
||||
indent_ -= 2;
|
||||
}
|
||||
|
||||
/// Writes the current indent to the output stream
|
||||
void make_indent();
|
||||
|
||||
/// Handles generating an alias
|
||||
/// @param alias the alias to generate
|
||||
/// @returns true if the alias was emitted
|
||||
|
@ -202,11 +183,6 @@ class GeneratorImpl {
|
|||
/// @param var the decorated variable
|
||||
/// @returns true if the variable decoration was emitted
|
||||
bool EmitVariableDecorations(ast::DecoratedVariable* var);
|
||||
|
||||
private:
|
||||
size_t indent_ = 0;
|
||||
std::ostringstream out_;
|
||||
std::string error_;
|
||||
};
|
||||
|
||||
} // namespace wgsl
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitAliasType_F32) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitAliasType_F32) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("a", &f32);
|
||||
|
||||
|
@ -39,7 +39,7 @@ TEST_F(GeneratorImplTest, EmitAliasType_F32) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitAliasType_Struct) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitAliasType_Struct) {
|
||||
ast::type::I32Type i32;
|
||||
ast::type::F32Type f32;
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||
ast::type::I32Type i32;
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, 5);
|
||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit));
|
||||
|
@ -42,7 +42,7 @@ TEST_F(GeneratorImplTest, EmitExpression_ArrayAccessor) {
|
|||
EXPECT_EQ(g.result(), "ary[5]");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitArrayAccessor) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitArrayAccessor) {
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto idx = std::make_unique<ast::IdentifierExpression>("idx");
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_As) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_As) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::AsExpression as(&f32, std::move(id));
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Assign) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Assign) {
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Break) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Break) {
|
||||
ast::BreakStatement b;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
|
||||
ast::CallExpression call(std::move(id), {});
|
||||
|
||||
|
@ -35,7 +35,7 @@ TEST_F(GeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
|||
EXPECT_EQ(g.result(), "my_func()");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param1"));
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Case) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::StatementList body;
|
||||
|
@ -49,7 +49,7 @@ TEST_F(GeneratorImplTest, Emit_Case) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::StatementList body;
|
||||
|
@ -70,7 +70,7 @@ TEST_F(GeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Case_Default) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Case_Default) {
|
||||
ast::CaseStatement c;
|
||||
|
||||
ast::StatementList body;
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_Cast) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_Cast) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::CastExpression cast(&f32, std::move(id));
|
||||
|
|
|
@ -32,9 +32,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Bool) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Bool) {
|
||||
ast::type::BoolType bool_type;
|
||||
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
@ -44,7 +44,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Bool) {
|
|||
EXPECT_EQ(g.result(), "false");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Int) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Int) {
|
||||
ast::type::I32Type i32;
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
@ -54,7 +54,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Int) {
|
|||
EXPECT_EQ(g.result(), "-12345");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_UInt) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_UInt) {
|
||||
ast::type::U32Type u32;
|
||||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
@ -64,7 +64,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_UInt) {
|
|||
EXPECT_EQ(g.result(), "56779u");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Float) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Float) {
|
||||
ast::type::F32Type f32;
|
||||
auto lit = std::make_unique<ast::FloatLiteral>(&f32, 1.5e27);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
@ -74,7 +74,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Float) {
|
|||
EXPECT_EQ(g.result(), "1.49999995e+27");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto lit = std::make_unique<ast::FloatLiteral>(&f32, -1.2e-5);
|
||||
|
@ -89,7 +89,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Float) {
|
|||
EXPECT_EQ(g.result(), "f32(-1.20000004e-05)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
ast::type::BoolType b;
|
||||
|
||||
auto lit = std::make_unique<ast::BoolLiteral>(&b, true);
|
||||
|
@ -104,7 +104,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) {
|
|||
EXPECT_EQ(g.result(), "bool(true)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
|
@ -119,7 +119,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
|
|||
EXPECT_EQ(g.result(), "i32(-12345)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
ast::type::U32Type u32;
|
||||
|
||||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 12345);
|
||||
|
@ -134,7 +134,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Uint) {
|
|||
EXPECT_EQ(g.result(), "u32(12345u)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Vec) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
|
@ -156,7 +156,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Vec) {
|
|||
EXPECT_EQ(g.result(), "vec3<f32>(1.00000000, 2.00000000, 3.00000000)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat(&f32, 3, 2);
|
||||
|
||||
|
@ -190,7 +190,7 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
"vec2<f32>(5.00000000, 6.00000000))");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitConstructor_Type_Array) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitConstructor_Type_Array) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 3);
|
||||
ast::type::ArrayType ary(&vec, 3);
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Continue) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Continue) {
|
||||
ast::ContinueStatement c;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Else) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Else) {
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
||||
|
@ -42,7 +42,7 @@ TEST_F(GeneratorImplTest, Emit_Else) {
|
|||
})");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_ElseWithCondition) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_ElseWithCondition) {
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
|
||||
ast::StatementList body;
|
||||
|
|
|
@ -20,9 +20,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitEntryPoint_NoName) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitEntryPoint_NoName) {
|
||||
ast::EntryPoint ep(ast::PipelineStage::kFragment, "", "frag_main");
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -31,7 +31,7 @@ TEST_F(GeneratorImplTest, EmitEntryPoint_NoName) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitEntryPoint_WithName) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitEntryPoint_WithName) {
|
||||
ast::EntryPoint ep(ast::PipelineStage::kFragment, "main", "frag_main");
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Fallthrough) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Fallthrough) {
|
||||
ast::FallthroughStatement f;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Function) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function) {
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
body.push_back(std::make_unique<ast::ReturnStatement>());
|
||||
|
@ -49,7 +49,7 @@ TEST_F(GeneratorImplTest, Emit_Function) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Function_WithParams) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
body.push_back(std::make_unique<ast::ReturnStatement>());
|
||||
|
|
|
@ -20,9 +20,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_Identifier) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_Identifier) {
|
||||
ast::IdentifierExpression i(std::vector<std::string>{"std", "glsl"});
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -30,7 +30,7 @@ TEST_F(GeneratorImplTest, EmitExpression_Identifier) {
|
|||
EXPECT_EQ(g.result(), "std::glsl");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitIdentifierExpression_Single) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitIdentifierExpression_Single) {
|
||||
ast::IdentifierExpression i("glsl");
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -38,7 +38,7 @@ TEST_F(GeneratorImplTest, EmitIdentifierExpression_Single) {
|
|||
EXPECT_EQ(g.result(), "glsl");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitIdentifierExpression_MultipleNames) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitIdentifierExpression_MultipleNames) {
|
||||
ast::IdentifierExpression i({"std", "glsl", "init"});
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_If) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_If) {
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
@ -43,7 +43,7 @@ TEST_F(GeneratorImplTest, Emit_If) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_IfWithElseIf) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond");
|
||||
|
||||
ast::StatementList else_body;
|
||||
|
@ -72,7 +72,7 @@ TEST_F(GeneratorImplTest, Emit_IfWithElseIf) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_IfWithElse) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) {
|
||||
ast::StatementList else_body;
|
||||
else_body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
||||
|
@ -98,7 +98,7 @@ TEST_F(GeneratorImplTest, Emit_IfWithElse) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_IfWithMultiple) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond");
|
||||
|
||||
ast::StatementList else_body;
|
||||
|
|
|
@ -20,9 +20,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitImport) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitImport) {
|
||||
ast::Import import("GLSL.std.450", "std::glsl");
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_kill) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_kill) {
|
||||
ast::KillStatement k;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Loop) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Loop) {
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
||||
|
@ -42,7 +42,7 @@ TEST_F(GeneratorImplTest, Emit_Loop) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||
ast::StatementList body;
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||
auto str = std::make_unique<ast::IdentifierExpression>("str");
|
||||
auto mem = std::make_unique<ast::IdentifierExpression>("mem");
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ TEST_P(BinaryTest, Emit) {
|
|||
EXPECT_EQ(g.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
GeneratorImplTest,
|
||||
WgslGeneratorImplTest,
|
||||
BinaryTest,
|
||||
testing::Values(
|
||||
BinaryData{"(left & right)", ast::BinaryOp::kAnd},
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Return) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Return) {
|
||||
ast::ReturnStatement r;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -37,7 +37,7 @@ TEST_F(GeneratorImplTest, Emit_Return) {
|
|||
EXPECT_EQ(g.result(), " return;\n");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_ReturnWithValue) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_ReturnWithValue) {
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
ast::ReturnStatement r(std::move(expr));
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Switch) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Switch) {
|
||||
auto def = std::make_unique<ast::CaseStatement>();
|
||||
ast::StatementList def_body;
|
||||
def_body.push_back(std::make_unique<ast::BreakStatement>());
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Generate) {
|
||||
TEST_F(WgslGeneratorImplTest, Generate) {
|
||||
ast::Module m;
|
||||
m.AddImport(std::make_unique<ast::Import>("GLSL.std.430", "a"));
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Alias) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Alias) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("alias", &f32);
|
||||
|
||||
|
@ -46,7 +46,7 @@ TEST_F(GeneratorImplTest, EmitType_Alias) {
|
|||
EXPECT_EQ(g.result(), "alias");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Array) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Array) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
|
@ -55,7 +55,7 @@ TEST_F(GeneratorImplTest, EmitType_Array) {
|
|||
EXPECT_EQ(g.result(), "array<bool, 4>");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_RuntimeArray) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b);
|
||||
|
||||
|
@ -64,7 +64,7 @@ TEST_F(GeneratorImplTest, EmitType_RuntimeArray) {
|
|||
EXPECT_EQ(g.result(), "array<bool>");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Bool) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Bool) {
|
||||
ast::type::BoolType b;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -72,7 +72,7 @@ TEST_F(GeneratorImplTest, EmitType_Bool) {
|
|||
EXPECT_EQ(g.result(), "bool");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_F32) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_F32) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -80,7 +80,7 @@ TEST_F(GeneratorImplTest, EmitType_F32) {
|
|||
EXPECT_EQ(g.result(), "f32");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_I32) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_I32) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -88,7 +88,7 @@ TEST_F(GeneratorImplTest, EmitType_I32) {
|
|||
EXPECT_EQ(g.result(), "i32");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Matrix) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Matrix) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType m(&f32, 3, 2);
|
||||
|
||||
|
@ -97,7 +97,7 @@ TEST_F(GeneratorImplTest, EmitType_Matrix) {
|
|||
EXPECT_EQ(g.result(), "mat2x3<f32>");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Pointer) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Pointer) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::PointerType p(&f32, ast::StorageClass::kWorkgroup);
|
||||
|
||||
|
@ -106,7 +106,7 @@ TEST_F(GeneratorImplTest, EmitType_Pointer) {
|
|||
EXPECT_EQ(g.result(), "ptr<workgroup, f32>");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Struct) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
|
||||
ast::type::I32Type i32;
|
||||
ast::type::F32Type f32;
|
||||
|
||||
|
@ -132,7 +132,7 @@ TEST_F(GeneratorImplTest, EmitType_Struct) {
|
|||
})");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Struct_WithDecoration) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithDecoration) {
|
||||
ast::type::I32Type i32;
|
||||
ast::type::F32Type f32;
|
||||
|
||||
|
@ -159,7 +159,7 @@ TEST_F(GeneratorImplTest, EmitType_Struct_WithDecoration) {
|
|||
})");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_U32) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_U32) {
|
||||
ast::type::U32Type u32;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
@ -167,7 +167,7 @@ TEST_F(GeneratorImplTest, EmitType_U32) {
|
|||
EXPECT_EQ(g.result(), "u32");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Vector) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Vector) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType v(&f32, 3);
|
||||
|
||||
|
@ -176,7 +176,7 @@ TEST_F(GeneratorImplTest, EmitType_Vector) {
|
|||
EXPECT_EQ(g.result(), "vec3<f32>");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitType_Void) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Void) {
|
||||
ast::type::VoidType v;
|
||||
|
||||
GeneratorImpl g;
|
||||
|
|
|
@ -44,7 +44,7 @@ TEST_P(UnaryOpTest, Emit) {
|
|||
ASSERT_TRUE(g.EmitExpression(&op)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string(params.name) + "(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(GeneratorImplTest,
|
||||
INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest,
|
||||
UnaryOpTest,
|
||||
testing::Values(UnaryOpData{"!", ast::UnaryOp::kNot},
|
||||
UnaryOpData{"-",
|
||||
|
|
|
@ -26,9 +26,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
|
@ -42,7 +42,7 @@ TEST_F(GeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
EXPECT_EQ(g.result(), " var a : f32;\n");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_VariableDeclStatement_Function) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Function) {
|
||||
// Variable declarations with Function storage class don't mention their
|
||||
// storage class. Rely on defaulting.
|
||||
// https://github.com/gpuweb/gpuweb/issues/654
|
||||
|
@ -59,7 +59,7 @@ TEST_F(GeneratorImplTest, Emit_VariableDeclStatement_Function) {
|
|||
EXPECT_EQ(g.result(), " var a : f32;\n");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
using WgslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable) {
|
||||
ast::type::F32Type f32;
|
||||
ast::Variable v("a", ast::StorageClass::kNone, &f32);
|
||||
|
||||
|
@ -41,7 +41,7 @@ TEST_F(GeneratorImplTest, EmitVariable) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable_StorageClass) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
|
||||
ast::type::F32Type f32;
|
||||
ast::Variable v("a", ast::StorageClass::kInput, &f32);
|
||||
|
||||
|
@ -51,7 +51,7 @@ TEST_F(GeneratorImplTest, EmitVariable_StorageClass) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable_Decorated) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
|
@ -68,7 +68,7 @@ TEST_F(GeneratorImplTest, EmitVariable_Decorated) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
|
@ -90,7 +90,7 @@ TEST_F(GeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable_Constructor) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("initializer");
|
||||
|
||||
ast::type::F32Type f32;
|
||||
|
@ -103,7 +103,7 @@ TEST_F(GeneratorImplTest, EmitVariable_Constructor) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(GeneratorImplTest, EmitVariable_Const) {
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Const) {
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("initializer");
|
||||
|
||||
ast::type::F32Type f32;
|
||||
|
|
|
@ -56,4 +56,9 @@ declare_args() {
|
|||
if (!defined(tint_build_wgsl_writer)) {
|
||||
tint_build_wgsl_writer = false
|
||||
}
|
||||
|
||||
# Build the MSL output writer
|
||||
if (!defined(tint_build_msl_writer)) {
|
||||
tint_build_msl_writer = false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue