Move ast/address_space to type/

This CL moves the ast/address_space to type/address_space. This breaks
the type dependency on ast for AddressSpace.

Change-Id: Icb48e7423e18904865ec735024eb3b9864c947c2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117604
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2023-01-21 19:56:49 +00:00
committed by Dawn LUCI CQ
parent 3cbf3fc4c5
commit 18b2158b4e
216 changed files with 1936 additions and 1935 deletions

View File

@@ -0,0 +1,80 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/address_space.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h"
namespace tint::type {
/// ParseAddressSpace parses a AddressSpace from a string.
/// @param str the string to parse
/// @returns the parsed enum, or AddressSpace::kUndefined if the string could not be parsed.
AddressSpace ParseAddressSpace(std::string_view str) {
if (str == "function") {
return AddressSpace::kFunction;
}
if (str == "private") {
return AddressSpace::kPrivate;
}
if (str == "push_constant") {
return AddressSpace::kPushConstant;
}
if (str == "storage") {
return AddressSpace::kStorage;
}
if (str == "uniform") {
return AddressSpace::kUniform;
}
if (str == "workgroup") {
return AddressSpace::kWorkgroup;
}
return AddressSpace::kUndefined;
}
std::ostream& operator<<(std::ostream& out, AddressSpace value) {
switch (value) {
case AddressSpace::kUndefined:
return out << "undefined";
case AddressSpace::kFunction:
return out << "function";
case AddressSpace::kHandle:
return out << "handle";
case AddressSpace::kIn:
return out << "in";
case AddressSpace::kNone:
return out << "none";
case AddressSpace::kOut:
return out << "out";
case AddressSpace::kPrivate:
return out << "private";
case AddressSpace::kPushConstant:
return out << "push_constant";
case AddressSpace::kStorage:
return out << "storage";
case AddressSpace::kUniform:
return out << "uniform";
case AddressSpace::kWorkgroup:
return out << "workgroup";
}
return out << "<unknown>";
}
} // namespace tint::type

View File

@@ -0,0 +1,25 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate address_space.cc
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h"
namespace tint::type {
{{ Eval "ParseEnum" $enum}}
{{ Eval "EnumOStream" $enum}}
} // namespace tint::type

View File

@@ -0,0 +1,69 @@
// Copyright 2022 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/address_space.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_TYPE_ADDRESS_SPACE_H_
#define SRC_TINT_TYPE_ADDRESS_SPACE_H_
#include <ostream>
namespace tint::type {
/// Address space of a given pointer.
enum class AddressSpace {
kUndefined,
kFunction,
kHandle, // Tint-internal enum entry - not parsed
kIn, // Tint-internal enum entry - not parsed
kNone, // Tint-internal enum entry - not parsed
kOut, // Tint-internal enum entry - not parsed
kPrivate,
kPushConstant,
kStorage,
kUniform,
kWorkgroup,
};
/// @param out the std::ostream to write to
/// @param value the AddressSpace
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, AddressSpace value);
/// ParseAddressSpace parses a AddressSpace from a string.
/// @param str the string to parse
/// @returns the parsed enum, or AddressSpace::kUndefined if the string could not be parsed.
AddressSpace ParseAddressSpace(std::string_view str);
constexpr const char* kAddressSpaceStrings[] = {
"function", "private", "push_constant", "storage", "uniform", "workgroup",
};
/// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
inline bool IsHostShareable(AddressSpace address_space) {
return address_space == AddressSpace::kUniform || address_space == AddressSpace::kStorage ||
address_space == AddressSpace::kPushConstant;
}
} // namespace tint::type
#endif // SRC_TINT_TYPE_ADDRESS_SPACE_H_

View File

@@ -0,0 +1,38 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate address_space.h
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}}
#ifndef SRC_TINT_TYPE_ADDRESS_SPACE_H_
#define SRC_TINT_TYPE_ADDRESS_SPACE_H_
#include <ostream>
namespace tint::type {
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $enum}}
/// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
inline bool IsHostShareable(AddressSpace address_space) {
return address_space == AddressSpace::kUniform ||
address_space == AddressSpace::kStorage ||
address_space == AddressSpace::kPushConstant;
}
} // namespace tint::type
#endif // SRC_TINT_TYPE_ADDRESS_SPACE_H_

View File

@@ -0,0 +1,55 @@
// Copyright 2022 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/address_space_bench.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h"
#include <array>
#include "benchmark/benchmark.h"
namespace tint::type {
namespace {
void AddressSpaceParser(::benchmark::State& state) {
std::array kStrings{
"fccnctin", "ucti3", "functVon", "function", "1unction",
"unJtqqon", "llun77tion", "ppqqivtHH", "prcv", "bivaGe",
"private", "priviive", "8WWivate", "pxxvate", "pXh_cggnstant",
"pX_Vonstanu", "push_consta3t", "push_constant", "push_constanE", "push_TTPnstant",
"puxxdh_constan", "s44orage", "stSSraVVe", "RtoR22e", "storage",
"sFra9e", "stoage", "VOORRHge", "unfoym", "llnnrrf77rm",
"unif4r00", "uniform", "nfoom", "zzform", "uiiippo1",
"workgrouXX", "wor55gro99nII", "wrrrkgroSSaHH", "workgroup", "kkrHoup",
"jgkrouRR", "wokroub",
};
for (auto _ : state) {
for (auto& str : kStrings) {
auto result = ParseAddressSpace(str);
benchmark::DoNotOptimize(result);
}
}
}
BENCHMARK(AddressSpaceParser);
} // namespace
} // namespace tint::type

View File

@@ -0,0 +1,29 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate address_space_bench.cc
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h"
#include <array>
#include "benchmark/benchmark.h"
namespace tint::type {
namespace {
{{ Eval "BenchmarkParseEnum" $enum }}
} // namespace
} // namespace tint::type

View File

@@ -0,0 +1,89 @@
// Copyright 2022 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/address_space_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/address_space.h"
#include <string>
#include "src/tint/type/test_helper.h"
#include "src/tint/utils/string.h"
namespace tint::type {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
AddressSpace value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"function", AddressSpace::kFunction},
{"private", AddressSpace::kPrivate},
{"push_constant", AddressSpace::kPushConstant},
{"storage", AddressSpace::kStorage},
{"uniform", AddressSpace::kUniform},
{"workgroup", AddressSpace::kWorkgroup},
};
static constexpr Case kInvalidCases[] = {
{"fccnctin", AddressSpace::kUndefined}, {"ucti3", AddressSpace::kUndefined},
{"functVon", AddressSpace::kUndefined}, {"priv1te", AddressSpace::kUndefined},
{"pqiJate", AddressSpace::kUndefined}, {"privat7ll", AddressSpace::kUndefined},
{"pqqsh_pponstHnt", AddressSpace::kUndefined}, {"pus_cnstat", AddressSpace::kUndefined},
{"bus_Gonstant", AddressSpace::kUndefined}, {"storiive", AddressSpace::kUndefined},
{"8WWorage", AddressSpace::kUndefined}, {"sxxrage", AddressSpace::kUndefined},
{"uXforgg", AddressSpace::kUndefined}, {"nfoXm", AddressSpace::kUndefined},
{"unif3rm", AddressSpace::kUndefined}, {"workgroEp", AddressSpace::kUndefined},
{"woTTPkroup", AddressSpace::kUndefined}, {"ddorkroxxp", AddressSpace::kUndefined},
};
using AddressSpaceParseTest = testing::TestWithParam<Case>;
TEST_P(AddressSpaceParseTest, Parse) {
const char* string = GetParam().string;
AddressSpace expect = GetParam().value;
EXPECT_EQ(expect, ParseAddressSpace(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, AddressSpaceParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, AddressSpaceParseTest, testing::ValuesIn(kInvalidCases));
using AddressSpacePrintTest = testing::TestWithParam<Case>;
TEST_P(AddressSpacePrintTest, Print) {
AddressSpace value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, AddressSpacePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::type

View File

@@ -0,0 +1,30 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate address_space_test.cc
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/type/address_space.h"
#include <string>
#include "src/tint/type/test_helper.h"
#include "src/tint/utils/string.h"
namespace tint::type {
namespace {
{{ Eval "TestParsePrintEnum" $enum}}
} // namespace
} // namespace tint::type

View File

@@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Pointer);
namespace tint::type {
Pointer::Pointer(const Type* subtype, ast::AddressSpace address_space, ast::Access access)
Pointer::Pointer(const Type* subtype, type::AddressSpace address_space, ast::Access access)
: Base(utils::Hash(TypeInfo::Of<Pointer>().full_hashcode, address_space, subtype, access),
type::Flags{}),
subtype_(subtype),
@@ -43,7 +43,7 @@ bool Pointer::Equals(const UniqueNode& other) const {
std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "ptr<";
if (address_space_ != ast::AddressSpace::kNone) {
if (address_space_ != AddressSpace::kNone) {
out << address_space_ << ", ";
}
out << subtype_->FriendlyName(symbols) << ", " << access_;

View File

@@ -18,7 +18,7 @@
#include <string>
#include "src/tint/ast/access.h"
#include "src/tint/ast/address_space.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/type.h"
namespace tint::type {
@@ -30,7 +30,7 @@ class Pointer final : public Castable<Pointer, Type> {
/// @param subtype the pointee type
/// @param address_space the address space of the pointer
/// @param access the resolved access control of the reference
Pointer(const Type* subtype, ast::AddressSpace address_space, ast::Access access);
Pointer(const Type* subtype, type::AddressSpace address_space, ast::Access access);
/// Destructor
~Pointer() override;
@@ -43,7 +43,7 @@ class Pointer final : public Castable<Pointer, Type> {
const Type* StoreType() const { return subtype_; }
/// @returns the address space of the pointer
ast::AddressSpace AddressSpace() const { return address_space_; }
type::AddressSpace AddressSpace() const { return address_space_; }
/// @returns the access control of the reference
ast::Access Access() const { return access_; }
@@ -59,7 +59,7 @@ class Pointer final : public Castable<Pointer, Type> {
private:
Type const* const subtype_;
ast::AddressSpace const address_space_;
type::AddressSpace const address_space_;
ast::Access const access_;
};

View File

@@ -21,14 +21,14 @@ namespace {
using PointerTest = TestHelper;
TEST_F(PointerTest, Creation) {
auto* a = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Pointer>(create<F32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Pointer>(create<I32>(), ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kRead);
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Pointer>(create<F32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Pointer>(create<I32>(), AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kRead);
EXPECT_TRUE(a->StoreType()->Is<I32>());
EXPECT_EQ(a->AddressSpace(), ast::AddressSpace::kStorage);
EXPECT_EQ(a->AddressSpace(), AddressSpace::kStorage);
EXPECT_EQ(a->Access(), ast::Access::kReadWrite);
EXPECT_EQ(a, b);
@@ -38,18 +38,18 @@ TEST_F(PointerTest, Creation) {
}
TEST_F(PointerTest, Hash) {
auto* a = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(PointerTest, Equals) {
auto* a = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Pointer>(create<F32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Pointer>(create<I32>(), ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kRead);
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Pointer>(create<F32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Pointer>(create<I32>(), AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kRead);
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -59,24 +59,24 @@ TEST_F(PointerTest, Equals) {
}
TEST_F(PointerTest, FriendlyName) {
auto* r = create<Pointer>(create<I32>(), ast::AddressSpace::kNone, ast::Access::kRead);
auto* r = create<Pointer>(create<I32>(), AddressSpace::kNone, ast::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32, read>");
}
TEST_F(PointerTest, FriendlyNameWithAddressSpace) {
auto* r = create<Pointer>(create<I32>(), ast::AddressSpace::kWorkgroup, ast::Access::kRead);
auto* r = create<Pointer>(create<I32>(), AddressSpace::kWorkgroup, ast::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<workgroup, i32, read>");
}
TEST_F(PointerTest, Clone) {
auto* a = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* ptr = a->Clone(ctx);
EXPECT_TRUE(ptr->StoreType()->Is<I32>());
EXPECT_EQ(ptr->AddressSpace(), ast::AddressSpace::kStorage);
EXPECT_EQ(ptr->AddressSpace(), AddressSpace::kStorage);
EXPECT_EQ(ptr->Access(), ast::Access::kReadWrite);
}

View File

@@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Reference);
namespace tint::type {
Reference::Reference(const Type* subtype, ast::AddressSpace address_space, ast::Access access)
Reference::Reference(const Type* subtype, type::AddressSpace address_space, ast::Access access)
: Base(utils::Hash(TypeInfo::Of<Reference>().full_hashcode, address_space, subtype, access),
type::Flags{}),
subtype_(subtype),
@@ -42,7 +42,7 @@ bool Reference::Equals(const UniqueNode& other) const {
std::string Reference::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "ref<";
if (address_space_ != ast::AddressSpace::kNone) {
if (address_space_ != AddressSpace::kNone) {
out << address_space_ << ", ";
}
out << subtype_->FriendlyName(symbols) << ", " << access_;

View File

@@ -18,7 +18,7 @@
#include <string>
#include "src/tint/ast/access.h"
#include "src/tint/ast/address_space.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/type.h"
namespace tint::type {
@@ -30,7 +30,7 @@ class Reference final : public Castable<Reference, Type> {
/// @param subtype the pointee type
/// @param address_space the address space of the reference
/// @param access the resolved access control of the reference
Reference(const Type* subtype, ast::AddressSpace address_space, ast::Access access);
Reference(const Type* subtype, type::AddressSpace address_space, ast::Access access);
/// Destructor
~Reference() override;
@@ -43,7 +43,7 @@ class Reference final : public Castable<Reference, Type> {
const Type* StoreType() const { return subtype_; }
/// @returns the address space of the reference
ast::AddressSpace AddressSpace() const { return address_space_; }
type::AddressSpace AddressSpace() const { return address_space_; }
/// @returns the resolved access control of the reference.
ast::Access Access() const { return access_; }
@@ -59,7 +59,7 @@ class Reference final : public Castable<Reference, Type> {
private:
Type const* const subtype_;
ast::AddressSpace const address_space_;
type::AddressSpace const address_space_;
ast::Access const access_;
};

View File

@@ -21,18 +21,14 @@ namespace {
using ReferenceTest = TestHelper;
TEST_F(ReferenceTest, Creation) {
auto* a =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c =
create<Reference>(create<F32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d =
create<Reference>(create<I32>(), ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kRead);
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Reference>(create<F32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Reference>(create<I32>(), AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kRead);
EXPECT_TRUE(a->StoreType()->Is<I32>());
EXPECT_EQ(a->AddressSpace(), ast::AddressSpace::kStorage);
EXPECT_EQ(a->AddressSpace(), AddressSpace::kStorage);
EXPECT_EQ(a->Access(), ast::Access::kReadWrite);
EXPECT_EQ(a, b);
@@ -42,24 +38,18 @@ TEST_F(ReferenceTest, Creation) {
}
TEST_F(ReferenceTest, Hash) {
auto* a =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(ReferenceTest, Equals) {
auto* a =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c =
create<Reference>(create<F32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d =
create<Reference>(create<I32>(), ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kRead);
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* c = create<Reference>(create<F32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
auto* d = create<Reference>(create<I32>(), AddressSpace::kPrivate, ast::Access::kReadWrite);
auto* e = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kRead);
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -69,25 +59,24 @@ TEST_F(ReferenceTest, Equals) {
}
TEST_F(ReferenceTest, FriendlyName) {
auto* r = create<Reference>(create<I32>(), ast::AddressSpace::kNone, ast::Access::kRead);
auto* r = create<Reference>(create<I32>(), AddressSpace::kNone, ast::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32, read>");
}
TEST_F(ReferenceTest, FriendlyNameWithAddressSpace) {
auto* r = create<Reference>(create<I32>(), ast::AddressSpace::kWorkgroup, ast::Access::kRead);
auto* r = create<Reference>(create<I32>(), AddressSpace::kWorkgroup, ast::Access::kRead);
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<workgroup, i32, read>");
}
TEST_F(ReferenceTest, Clone) {
auto* a =
create<Reference>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, ast::Access::kReadWrite);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* ref = a->Clone(ctx);
EXPECT_TRUE(ref->StoreType()->Is<I32>());
EXPECT_EQ(ref->AddressSpace(), ast::AddressSpace::kStorage);
EXPECT_EQ(ref->AddressSpace(), AddressSpace::kStorage);
EXPECT_EQ(ref->Access(), ast::Access::kReadWrite);
}

View File

@@ -21,8 +21,8 @@
#include <string>
#include <unordered_set>
#include "src/tint/ast/address_space.h"
#include "src/tint/symbol.h"
#include "src/tint/type/address_space.h"
#include "src/tint/type/node.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/vector.h"
@@ -100,22 +100,22 @@ class Struct : public Castable<Struct, Type> {
/// Adds the AddressSpace usage to the structure.
/// @param usage the storage usage
void AddUsage(ast::AddressSpace usage) { address_space_usage_.emplace(usage); }
void AddUsage(AddressSpace usage) { address_space_usage_.emplace(usage); }
/// @returns the set of address space uses of this structure
const std::unordered_set<ast::AddressSpace>& AddressSpaceUsage() const {
const std::unordered_set<AddressSpace>& AddressSpaceUsage() const {
return address_space_usage_;
}
/// @param usage the ast::AddressSpace usage type to query
/// @param usage the AddressSpace usage type to query
/// @returns true iff this structure has been used as the given address space
bool UsedAs(ast::AddressSpace usage) const { return address_space_usage_.count(usage) > 0; }
bool UsedAs(AddressSpace usage) const { return address_space_usage_.count(usage) > 0; }
/// @returns true iff this structure has been used by address space that's
/// host-shareable.
bool IsHostShareable() const {
for (auto sc : address_space_usage_) {
if (ast::IsHostShareable(sc)) {
if (type::IsHostShareable(sc)) {
return true;
}
}
@@ -160,7 +160,7 @@ class Struct : public Castable<Struct, Type> {
const uint32_t align_;
const uint32_t size_;
const uint32_t size_no_padding_;
std::unordered_set<ast::AddressSpace> address_space_usage_;
std::unordered_set<AddressSpace> address_space_usage_;
std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
utils::Vector<const Struct*, 2> concrete_types_;
};

View File

@@ -15,7 +15,6 @@
#ifndef SRC_TINT_TYPE_TEXTURE_H_
#define SRC_TINT_TYPE_TEXTURE_H_
#include "src/tint/ast/texture.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/type/type.h"

View File

@@ -44,7 +44,7 @@ struct TypeTest : public TestHelper {
const Matrix* mat4x3_f16 = create<Matrix>(vec3_f16, 4u);
const Matrix* mat4x3_af = create<Matrix>(vec3_af, 4u);
const Reference* ref_u32 =
create<Reference>(u32, ast::AddressSpace::kPrivate, ast::Access::kReadWrite);
create<Reference>(u32, AddressSpace::kPrivate, ast::Access::kReadWrite);
const Struct* str_f32 = create<Struct>(Source{},
Sym("str_f32"),
utils::Vector{