mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Move type::AddressSpace to builtin/
This CL moves the AddressSpace enum from type:: to builtin:: Change-Id: Ie8d533be4dd42b34eef164b64e2c9e0843de5c3d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120401 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
b6cc4cbf89
commit
2a65163c6d
@@ -1,84 +0,0 @@
|
||||
// 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 == "__in") {
|
||||
return AddressSpace::kIn;
|
||||
}
|
||||
if (str == "__out") {
|
||||
return AddressSpace::kOut;
|
||||
}
|
||||
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::kIn:
|
||||
return out << "__in";
|
||||
case AddressSpace::kOut:
|
||||
return out << "__out";
|
||||
case AddressSpace::kFunction:
|
||||
return out << "function";
|
||||
case AddressSpace::kHandle:
|
||||
return out << "handle";
|
||||
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
|
||||
@@ -1,25 +0,0 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
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
|
||||
@@ -1,68 +0,0 @@
|
||||
// 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,
|
||||
kIn,
|
||||
kOut,
|
||||
kFunction,
|
||||
kHandle, // 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[] = {
|
||||
"__in", "__out", "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_
|
||||
@@ -1,38 +0,0 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
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_
|
||||
@@ -1,102 +0,0 @@
|
||||
// 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) {
|
||||
const char* kStrings[] = {
|
||||
"ccin",
|
||||
"3",
|
||||
"_Vin",
|
||||
"__in",
|
||||
"1_in",
|
||||
"_qiJ",
|
||||
"_lli77",
|
||||
"__qHupp",
|
||||
"vt",
|
||||
"G_bt",
|
||||
"__out",
|
||||
"__viut",
|
||||
"__8WWt",
|
||||
"Mxxou",
|
||||
"fuXggton",
|
||||
"fuXtou",
|
||||
"funct3on",
|
||||
"function",
|
||||
"funEtion",
|
||||
"PPncTTion",
|
||||
"xxuncddon",
|
||||
"p44ivate",
|
||||
"prSSvaVVe",
|
||||
"RriR22e",
|
||||
"private",
|
||||
"pFva9e",
|
||||
"priate",
|
||||
"VOORRHte",
|
||||
"push_constyn",
|
||||
"punnh_crr77stallt",
|
||||
"pu4h_cons00ant",
|
||||
"push_constant",
|
||||
"puoo_costan",
|
||||
"ushzzcnstant",
|
||||
"push_coii11apt",
|
||||
"storaXXe",
|
||||
"9II5tnnrage",
|
||||
"stoaSSrHHYe",
|
||||
"storage",
|
||||
"stkke",
|
||||
"jtogRa",
|
||||
"sbrag",
|
||||
"unifojm",
|
||||
"niform",
|
||||
"qform",
|
||||
"uniform",
|
||||
"uniNNrm",
|
||||
"nifrvv",
|
||||
"QQiform",
|
||||
"workrorf",
|
||||
"workjroup",
|
||||
"wNNorkrou2",
|
||||
"workgroup",
|
||||
"workgrop",
|
||||
"rrorkgroup",
|
||||
"workgroGp",
|
||||
};
|
||||
for (auto _ : state) {
|
||||
for (auto* str : kStrings) {
|
||||
auto result = ParseAddressSpace(str);
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(AddressSpaceParser);
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
@@ -1,29 +0,0 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
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
|
||||
@@ -1,94 +0,0 @@
|
||||
// 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[] = {
|
||||
{"__in", AddressSpace::kIn},
|
||||
{"__out", AddressSpace::kOut},
|
||||
{"function", AddressSpace::kFunction},
|
||||
{"private", AddressSpace::kPrivate},
|
||||
{"push_constant", AddressSpace::kPushConstant},
|
||||
{"storage", AddressSpace::kStorage},
|
||||
{"uniform", AddressSpace::kUniform},
|
||||
{"workgroup", AddressSpace::kWorkgroup},
|
||||
};
|
||||
|
||||
static constexpr Case kInvalidCases[] = {
|
||||
{"ccin", AddressSpace::kUndefined}, {"3", AddressSpace::kUndefined},
|
||||
{"_Vin", AddressSpace::kUndefined}, {"__ou1", AddressSpace::kUndefined},
|
||||
{"qq_Jt", AddressSpace::kUndefined}, {"__oll7t", AddressSpace::kUndefined},
|
||||
{"qquntppHon", AddressSpace::kUndefined}, {"cnciv", AddressSpace::kUndefined},
|
||||
{"funGion", AddressSpace::kUndefined}, {"priviive", AddressSpace::kUndefined},
|
||||
{"8WWivate", AddressSpace::kUndefined}, {"pxxvate", AddressSpace::kUndefined},
|
||||
{"pXh_cggnstant", AddressSpace::kUndefined}, {"pX_Vonstanu", AddressSpace::kUndefined},
|
||||
{"push_consta3t", AddressSpace::kUndefined}, {"Etorage", AddressSpace::kUndefined},
|
||||
{"sPTTrage", AddressSpace::kUndefined}, {"storadxx", AddressSpace::kUndefined},
|
||||
{"u44iform", AddressSpace::kUndefined}, {"unSSfoVVm", AddressSpace::kUndefined},
|
||||
{"RniR22m", AddressSpace::kUndefined}, {"w9rFroup", AddressSpace::kUndefined},
|
||||
{"workgoup", AddressSpace::kUndefined}, {"woVROOrHup", 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
|
||||
@@ -1,30 +0,0 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
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
|
||||
@@ -24,7 +24,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Pointer);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
Pointer::Pointer(const Type* subtype, type::AddressSpace address_space, builtin::Access access)
|
||||
Pointer::Pointer(const Type* subtype, builtin::AddressSpace address_space, builtin::Access access)
|
||||
: Base(utils::Hash(TypeInfo::Of<Pointer>().full_hashcode, address_space, subtype, access),
|
||||
type::Flags{}),
|
||||
subtype_(subtype),
|
||||
@@ -45,7 +45,7 @@ bool Pointer::Equals(const UniqueNode& other) const {
|
||||
std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
out << "ptr<";
|
||||
if (address_space_ != AddressSpace::kUndefined) {
|
||||
if (address_space_ != builtin::AddressSpace::kUndefined) {
|
||||
out << address_space_ << ", ";
|
||||
}
|
||||
out << subtype_->FriendlyName(symbols) << ", " << access_;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/builtin/access.h"
|
||||
#include "src/tint/type/address_space.h"
|
||||
#include "src/tint/builtin/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, type::AddressSpace address_space, builtin::Access access);
|
||||
Pointer(const Type* subtype, builtin::AddressSpace address_space, builtin::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
|
||||
type::AddressSpace AddressSpace() const { return address_space_; }
|
||||
builtin::AddressSpace AddressSpace() const { return address_space_; }
|
||||
|
||||
/// @returns the access control of the reference
|
||||
builtin::Access Access() const { return access_; }
|
||||
@@ -59,7 +59,7 @@ class Pointer final : public Castable<Pointer, Type> {
|
||||
|
||||
private:
|
||||
Type const* const subtype_;
|
||||
type::AddressSpace const address_space_;
|
||||
builtin::AddressSpace const address_space_;
|
||||
builtin::Access const access_;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/builtin/address_space.h"
|
||||
#include "src/tint/type/test_helper.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
|
||||
@@ -21,14 +22,19 @@ namespace {
|
||||
using PointerTest = TestHelper;
|
||||
|
||||
TEST_F(PointerTest, Creation) {
|
||||
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* c = create<Pointer>(create<F32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* d = create<Pointer>(create<I32>(), AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
auto* e = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kRead);
|
||||
auto* a = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* c = create<Pointer>(create<F32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* d = create<Pointer>(create<I32>(), builtin::AddressSpace::kPrivate,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* e =
|
||||
create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage, builtin::Access::kRead);
|
||||
|
||||
EXPECT_TRUE(a->StoreType()->Is<I32>());
|
||||
EXPECT_EQ(a->AddressSpace(), AddressSpace::kStorage);
|
||||
EXPECT_EQ(a->AddressSpace(), builtin::AddressSpace::kStorage);
|
||||
EXPECT_EQ(a->Access(), builtin::Access::kReadWrite);
|
||||
|
||||
EXPECT_EQ(a, b);
|
||||
@@ -38,18 +44,25 @@ TEST_F(PointerTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, Hash) {
|
||||
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* a = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
|
||||
EXPECT_EQ(a->unique_hash, b->unique_hash);
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, Equals) {
|
||||
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* c = create<Pointer>(create<F32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* d = create<Pointer>(create<I32>(), AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
auto* e = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kRead);
|
||||
auto* a = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* c = create<Pointer>(create<F32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* d = create<Pointer>(create<I32>(), builtin::AddressSpace::kPrivate,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* e =
|
||||
create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage, builtin::Access::kRead);
|
||||
|
||||
EXPECT_TRUE(a->Equals(*b));
|
||||
EXPECT_FALSE(a->Equals(*c));
|
||||
@@ -59,24 +72,27 @@ TEST_F(PointerTest, Equals) {
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, FriendlyName) {
|
||||
auto* r = create<Pointer>(create<I32>(), AddressSpace::kUndefined, builtin::Access::kRead);
|
||||
auto* r =
|
||||
create<Pointer>(create<I32>(), builtin::AddressSpace::kUndefined, builtin::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, FriendlyNameWithAddressSpace) {
|
||||
auto* r = create<Pointer>(create<I32>(), AddressSpace::kWorkgroup, builtin::Access::kRead);
|
||||
auto* r =
|
||||
create<Pointer>(create<I32>(), builtin::AddressSpace::kWorkgroup, builtin::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ptr<workgroup, i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(PointerTest, Clone) {
|
||||
auto* a = create<Pointer>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* a = create<Pointer>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::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(), AddressSpace::kStorage);
|
||||
EXPECT_EQ(ptr->AddressSpace(), builtin::AddressSpace::kStorage);
|
||||
EXPECT_EQ(ptr->Access(), builtin::Access::kReadWrite);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Reference);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
Reference::Reference(const Type* subtype, type::AddressSpace address_space, builtin::Access access)
|
||||
Reference::Reference(const Type* subtype,
|
||||
builtin::AddressSpace address_space,
|
||||
builtin::Access access)
|
||||
: Base(utils::Hash(TypeInfo::Of<Reference>().full_hashcode, address_space, subtype, access),
|
||||
type::Flags{}),
|
||||
subtype_(subtype),
|
||||
@@ -44,7 +46,7 @@ bool Reference::Equals(const UniqueNode& other) const {
|
||||
std::string Reference::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
out << "ref<";
|
||||
if (address_space_ != AddressSpace::kUndefined) {
|
||||
if (address_space_ != builtin::AddressSpace::kUndefined) {
|
||||
out << address_space_ << ", ";
|
||||
}
|
||||
out << subtype_->FriendlyName(symbols) << ", " << access_;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/builtin/access.h"
|
||||
#include "src/tint/type/address_space.h"
|
||||
#include "src/tint/builtin/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, type::AddressSpace address_space, builtin::Access access);
|
||||
Reference(const Type* subtype, builtin::AddressSpace address_space, builtin::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
|
||||
type::AddressSpace AddressSpace() const { return address_space_; }
|
||||
builtin::AddressSpace AddressSpace() const { return address_space_; }
|
||||
|
||||
/// @returns the resolved access control of the reference.
|
||||
builtin::Access Access() const { return access_; }
|
||||
@@ -59,7 +59,7 @@ class Reference final : public Castable<Reference, Type> {
|
||||
|
||||
private:
|
||||
Type const* const subtype_;
|
||||
type::AddressSpace const address_space_;
|
||||
builtin::AddressSpace const address_space_;
|
||||
builtin::Access const access_;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/type/reference.h"
|
||||
#include "src/tint/builtin/address_space.h"
|
||||
#include "src/tint/type/test_helper.h"
|
||||
|
||||
namespace tint::type {
|
||||
@@ -21,14 +22,19 @@ namespace {
|
||||
using ReferenceTest = TestHelper;
|
||||
|
||||
TEST_F(ReferenceTest, Creation) {
|
||||
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* c = create<Reference>(create<F32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* d = create<Reference>(create<I32>(), AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
auto* e = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kRead);
|
||||
auto* a = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* c = create<Reference>(create<F32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* d = create<Reference>(create<I32>(), builtin::AddressSpace::kPrivate,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* e =
|
||||
create<Reference>(create<I32>(), builtin::AddressSpace::kStorage, builtin::Access::kRead);
|
||||
|
||||
EXPECT_TRUE(a->StoreType()->Is<I32>());
|
||||
EXPECT_EQ(a->AddressSpace(), AddressSpace::kStorage);
|
||||
EXPECT_EQ(a->AddressSpace(), builtin::AddressSpace::kStorage);
|
||||
EXPECT_EQ(a->Access(), builtin::Access::kReadWrite);
|
||||
|
||||
EXPECT_EQ(a, b);
|
||||
@@ -38,18 +44,25 @@ TEST_F(ReferenceTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, Hash) {
|
||||
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* a = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
|
||||
EXPECT_EQ(a->unique_hash, b->unique_hash);
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, Equals) {
|
||||
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* c = create<Reference>(create<F32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* d = create<Reference>(create<I32>(), AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
auto* e = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kRead);
|
||||
auto* a = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* b = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* c = create<Reference>(create<F32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* d = create<Reference>(create<I32>(), builtin::AddressSpace::kPrivate,
|
||||
builtin::Access::kReadWrite);
|
||||
auto* e =
|
||||
create<Reference>(create<I32>(), builtin::AddressSpace::kStorage, builtin::Access::kRead);
|
||||
|
||||
EXPECT_TRUE(a->Equals(*b));
|
||||
EXPECT_FALSE(a->Equals(*c));
|
||||
@@ -59,24 +72,27 @@ TEST_F(ReferenceTest, Equals) {
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, FriendlyName) {
|
||||
auto* r = create<Reference>(create<I32>(), AddressSpace::kUndefined, builtin::Access::kRead);
|
||||
auto* r =
|
||||
create<Reference>(create<I32>(), builtin::AddressSpace::kUndefined, builtin::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, FriendlyNameWithAddressSpace) {
|
||||
auto* r = create<Reference>(create<I32>(), AddressSpace::kWorkgroup, builtin::Access::kRead);
|
||||
auto* r =
|
||||
create<Reference>(create<I32>(), builtin::AddressSpace::kWorkgroup, builtin::Access::kRead);
|
||||
EXPECT_EQ(r->FriendlyName(Symbols()), "ref<workgroup, i32, read>");
|
||||
}
|
||||
|
||||
TEST_F(ReferenceTest, Clone) {
|
||||
auto* a = create<Reference>(create<I32>(), AddressSpace::kStorage, builtin::Access::kReadWrite);
|
||||
auto* a = create<Reference>(create<I32>(), builtin::AddressSpace::kStorage,
|
||||
builtin::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(), AddressSpace::kStorage);
|
||||
EXPECT_EQ(ref->AddressSpace(), builtin::AddressSpace::kStorage);
|
||||
EXPECT_EQ(ref->Access(), builtin::Access::kReadWrite);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "src/tint/builtin/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(AddressSpace usage) { address_space_usage_.emplace(usage); }
|
||||
void AddUsage(builtin::AddressSpace usage) { address_space_usage_.emplace(usage); }
|
||||
|
||||
/// @returns the set of address space uses of this structure
|
||||
const std::unordered_set<AddressSpace>& AddressSpaceUsage() const {
|
||||
const std::unordered_set<builtin::AddressSpace>& AddressSpaceUsage() const {
|
||||
return address_space_usage_;
|
||||
}
|
||||
|
||||
/// @param usage the AddressSpace usage type to query
|
||||
/// @returns true iff this structure has been used as the given address space
|
||||
bool UsedAs(AddressSpace usage) const { return address_space_usage_.count(usage) > 0; }
|
||||
bool UsedAs(builtin::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 (type::IsHostShareable(sc)) {
|
||||
if (builtin::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<AddressSpace> address_space_usage_;
|
||||
std::unordered_set<builtin::AddressSpace> address_space_usage_;
|
||||
std::unordered_set<PipelineStageUsage> pipeline_stage_uses_;
|
||||
utils::Vector<const Struct*, 2> concrete_types_;
|
||||
};
|
||||
|
||||
@@ -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, AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
create<Reference>(u32, builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite);
|
||||
const Struct* str_f32 = create<Struct>(Source{},
|
||||
Sym("str_f32"),
|
||||
utils::Vector{
|
||||
|
||||
Reference in New Issue
Block a user