mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Move array to type/
This CL moves array to the type/ folder. Namespaces are updated as needed. A FriendlyName method was added to ArrayCount so the sem:: ArrayCount entries do not need to be referenced inside type/. Bug: tint:1718 Change-Id: I16a8f32b3fab1131b284a6981a5c386081138b08 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113427 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dan Sinclair
parent
f53b2b5b2e
commit
946858ad56
109
src/tint/type/array.cc
Normal file
109
src/tint/type/array.cc
Normal file
@@ -0,0 +1,109 @@
|
||||
// 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.
|
||||
|
||||
#include "src/tint/type/array.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/variable.h"
|
||||
#include "src/tint/debug.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::Array);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
namespace {
|
||||
|
||||
type::TypeFlags FlagsFrom(const type::Type* element, const type::ArrayCount* count) {
|
||||
type::TypeFlags flags;
|
||||
// Only constant-expression sized arrays are constructible
|
||||
if (count->Is<type::ConstantArrayCount>()) {
|
||||
if (element->IsConstructible()) {
|
||||
flags.Add(type::TypeFlag::kConstructable);
|
||||
}
|
||||
if (element->HasCreationFixedFootprint()) {
|
||||
flags.Add(type::TypeFlag::kCreationFixedFootprint);
|
||||
}
|
||||
}
|
||||
if (!count->Is<type::RuntimeArrayCount>()) {
|
||||
if (element->HasFixedFootprint()) {
|
||||
flags.Add(type::TypeFlag::kFixedFootprint);
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* const Array::kErrExpectedConstantCount =
|
||||
"array size is an override-expression, when expected a constant-expression.\n"
|
||||
"Was the SubstituteOverride transform run?";
|
||||
|
||||
Array::Array(const type::Type* element,
|
||||
const type::ArrayCount* count,
|
||||
uint32_t align,
|
||||
uint32_t size,
|
||||
uint32_t stride,
|
||||
uint32_t implicit_stride)
|
||||
: Base(FlagsFrom(element, count)),
|
||||
element_(element),
|
||||
count_(count),
|
||||
align_(align),
|
||||
size_(size),
|
||||
stride_(stride),
|
||||
implicit_stride_(implicit_stride) {
|
||||
TINT_ASSERT(Type, element_);
|
||||
}
|
||||
|
||||
size_t Array::Hash() const {
|
||||
return utils::Hash(TypeInfo::Of<Array>().full_hashcode, count_, align_, size_, stride_);
|
||||
}
|
||||
|
||||
bool Array::Equals(const type::Type& other) const {
|
||||
if (auto* o = other.As<Array>()) {
|
||||
// Note: implicit_stride is not part of the type_name string as this is
|
||||
// derived from the element type
|
||||
return o->element_ == element_ && o->count_ == count_ && o->align_ == align_ &&
|
||||
o->size_ == size_ && o->stride_ == stride_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
if (!IsStrideImplicit()) {
|
||||
out << "@stride(" << stride_ << ") ";
|
||||
}
|
||||
out << "array<" << element_->FriendlyName(symbols);
|
||||
|
||||
auto count_str = count_->FriendlyName(symbols);
|
||||
if (!count_str.empty()) {
|
||||
out << ", " << count_str;
|
||||
}
|
||||
|
||||
out << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
uint32_t Array::Align() const {
|
||||
return align_;
|
||||
}
|
||||
|
||||
uint32_t Array::Size() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
115
src/tint/type/array.h
Normal file
115
src/tint/type/array.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2021 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_TINT_TYPE_ARRAY_H_
|
||||
#define SRC_TINT_TYPE_ARRAY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "src/tint/type/array_count.h"
|
||||
#include "src/tint/type/type.h"
|
||||
#include "src/tint/utils/compiler_macros.h"
|
||||
#include "src/tint/utils/unique_vector.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// Array holds the type information for Array nodes.
|
||||
class Array final : public Castable<Array, type::Type> {
|
||||
public:
|
||||
/// An error message string stating that the array count was expected to be a constant
|
||||
/// expression. Used by multiple writers and transforms.
|
||||
static const char* const kErrExpectedConstantCount;
|
||||
|
||||
/// Constructor
|
||||
/// @param element the array element type
|
||||
/// @param count the number of elements in the array.
|
||||
/// @param align the byte alignment of the array
|
||||
/// @param size the byte size of the array. The size will be 0 if the array element count is
|
||||
/// pipeline overridable.
|
||||
/// @param stride the number of bytes from the start of one element of the
|
||||
/// array to the start of the next element
|
||||
/// @param implicit_stride the number of bytes from the start of one element
|
||||
/// of the array to the start of the next element, if there was no `@stride`
|
||||
/// attribute applied.
|
||||
Array(type::Type const* element,
|
||||
const type::ArrayCount* count,
|
||||
uint32_t align,
|
||||
uint32_t size,
|
||||
uint32_t stride,
|
||||
uint32_t implicit_stride);
|
||||
|
||||
/// @returns a hash of the type.
|
||||
size_t Hash() const override;
|
||||
|
||||
/// @param other the other type to compare against
|
||||
/// @returns true if the this type is equal to the given type
|
||||
bool Equals(const type::Type& other) const override;
|
||||
|
||||
/// @return the array element type
|
||||
type::Type const* ElemType() const { return element_; }
|
||||
|
||||
/// @returns the number of elements in the array.
|
||||
const type::ArrayCount* Count() const { return count_; }
|
||||
|
||||
/// @returns the array count if the count is a const-expression, otherwise returns nullopt.
|
||||
inline std::optional<uint32_t> ConstantCount() const {
|
||||
if (auto* count = count_->As<type::ConstantArrayCount>()) {
|
||||
return count->value;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/// @returns the byte alignment of the array
|
||||
/// @note this may differ from the alignment of a structure member of this
|
||||
/// array type, if the member is annotated with the `@align(n)` attribute.
|
||||
uint32_t Align() const override;
|
||||
|
||||
/// @returns the byte size of the array
|
||||
/// @note this may differ from the size of a structure member of this array
|
||||
/// type, if the member is annotated with the `@size(n)` attribute.
|
||||
uint32_t Size() const override;
|
||||
|
||||
/// @returns the number of bytes from the start of one element of the
|
||||
/// array to the start of the next element
|
||||
uint32_t Stride() const { return stride_; }
|
||||
|
||||
/// @returns the number of bytes from the start of one element of the
|
||||
/// array to the start of the next element, if there was no `@stride`
|
||||
/// attribute applied
|
||||
uint32_t ImplicitStride() const { return implicit_stride_; }
|
||||
|
||||
/// @returns true if the value returned by Stride() matches the element's
|
||||
/// natural stride
|
||||
bool IsStrideImplicit() const { return stride_ == implicit_stride_; }
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
private:
|
||||
type::Type const* const element_;
|
||||
const type::ArrayCount* count_;
|
||||
const uint32_t align_;
|
||||
const uint32_t size_;
|
||||
const uint32_t stride_;
|
||||
const uint32_t implicit_stride_;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_ARRAY_H_
|
||||
@@ -37,6 +37,10 @@ bool ConstantArrayCount::Equals(const ArrayCount& other) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ConstantArrayCount::FriendlyName(const SymbolTable&) const {
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
RuntimeArrayCount::RuntimeArrayCount() : Base() {}
|
||||
RuntimeArrayCount::~RuntimeArrayCount() = default;
|
||||
|
||||
@@ -48,4 +52,8 @@ bool RuntimeArrayCount::Equals(const ArrayCount& other) const {
|
||||
return other.Is<RuntimeArrayCount>();
|
||||
}
|
||||
|
||||
std::string RuntimeArrayCount::FriendlyName(const SymbolTable&) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
#define SRC_TINT_TYPE_ARRAY_COUNT_H_
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/type/node.h"
|
||||
|
||||
namespace tint::type {
|
||||
@@ -33,6 +35,10 @@ class ArrayCount : public Castable<ArrayCount, Node> {
|
||||
/// @returns true if this array count is equal to the given array count
|
||||
virtual bool Equals(const ArrayCount& t) const = 0;
|
||||
|
||||
/// @param symbols the symbol table
|
||||
/// @returns the friendly name for this array count
|
||||
virtual std::string FriendlyName(const SymbolTable& symbols) const = 0;
|
||||
|
||||
protected:
|
||||
ArrayCount();
|
||||
};
|
||||
@@ -57,6 +63,10 @@ class ConstantArrayCount final : public Castable<ConstantArrayCount, ArrayCount>
|
||||
/// @returns true if this array count is equal to the given array count
|
||||
bool Equals(const ArrayCount& t) const override;
|
||||
|
||||
/// @param symbols the symbol table
|
||||
/// @returns the friendly name for this array count
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// The array count constant-expression value.
|
||||
uint32_t value;
|
||||
};
|
||||
@@ -78,6 +88,10 @@ class RuntimeArrayCount final : public Castable<RuntimeArrayCount, ArrayCount> {
|
||||
/// @param t other array count
|
||||
/// @returns true if this array count is equal to the given array count
|
||||
bool Equals(const ArrayCount& t) const override;
|
||||
|
||||
/// @param symbols the symbol table
|
||||
/// @returns the friendly name for this array count
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
209
src/tint/type/array_test.cc
Normal file
209
src/tint/type/array_test.cc
Normal file
@@ -0,0 +1,209 @@
|
||||
// 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/tint/sem/array_count.h"
|
||||
#include "src/tint/type/test_helper.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
|
||||
namespace tint::type {
|
||||
namespace {
|
||||
|
||||
using ArrayTest = TestHelper;
|
||||
|
||||
TEST_F(ArrayTest, CreateSizedArray) {
|
||||
auto* a =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* b =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* c =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(3u), 4u, 8u, 32u, 16u);
|
||||
auto* d =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 5u, 8u, 32u, 16u);
|
||||
auto* e =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 9u, 32u, 16u);
|
||||
auto* f =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 16u);
|
||||
auto* g =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 17u);
|
||||
|
||||
EXPECT_EQ(a->ElemType(), create<type::U32>());
|
||||
EXPECT_EQ(a->Count(), create<type::ConstantArrayCount>(2u));
|
||||
EXPECT_EQ(a->Align(), 4u);
|
||||
EXPECT_EQ(a->Size(), 8u);
|
||||
EXPECT_EQ(a->Stride(), 32u);
|
||||
EXPECT_EQ(a->ImplicitStride(), 16u);
|
||||
EXPECT_FALSE(a->IsStrideImplicit());
|
||||
EXPECT_FALSE(a->Count()->Is<type::RuntimeArrayCount>());
|
||||
|
||||
EXPECT_EQ(a, b);
|
||||
EXPECT_NE(a, c);
|
||||
EXPECT_NE(a, d);
|
||||
EXPECT_NE(a, e);
|
||||
EXPECT_NE(a, f);
|
||||
EXPECT_NE(a, g);
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, CreateRuntimeArray) {
|
||||
auto* a =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 32u, 32u);
|
||||
auto* b =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 32u, 32u);
|
||||
auto* c =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 5u, 8u, 32u, 32u);
|
||||
auto* d =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 9u, 32u, 32u);
|
||||
auto* e =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 33u, 32u);
|
||||
auto* f =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 33u, 17u);
|
||||
|
||||
EXPECT_EQ(a->ElemType(), create<type::U32>());
|
||||
EXPECT_EQ(a->Count(), create<type::RuntimeArrayCount>());
|
||||
EXPECT_EQ(a->Align(), 4u);
|
||||
EXPECT_EQ(a->Size(), 8u);
|
||||
EXPECT_EQ(a->Stride(), 32u);
|
||||
EXPECT_EQ(a->ImplicitStride(), 32u);
|
||||
EXPECT_TRUE(a->IsStrideImplicit());
|
||||
EXPECT_TRUE(a->Count()->Is<type::RuntimeArrayCount>());
|
||||
|
||||
EXPECT_EQ(a, b);
|
||||
EXPECT_NE(a, c);
|
||||
EXPECT_NE(a, d);
|
||||
EXPECT_NE(a, e);
|
||||
EXPECT_NE(a, f);
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, Hash) {
|
||||
auto* a =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* b =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* c =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(3u), 4u, 8u, 32u, 16u);
|
||||
auto* d =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 5u, 8u, 32u, 16u);
|
||||
auto* e =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 9u, 32u, 16u);
|
||||
auto* f =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 16u);
|
||||
auto* g =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 17u);
|
||||
|
||||
EXPECT_EQ(a->Hash(), b->Hash());
|
||||
EXPECT_NE(a->Hash(), c->Hash());
|
||||
EXPECT_NE(a->Hash(), d->Hash());
|
||||
EXPECT_NE(a->Hash(), e->Hash());
|
||||
EXPECT_NE(a->Hash(), f->Hash());
|
||||
EXPECT_NE(a->Hash(), g->Hash());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, Equals) {
|
||||
auto* a =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* b =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* c =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(3u), 4u, 8u, 32u, 16u);
|
||||
auto* d =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 5u, 8u, 32u, 16u);
|
||||
auto* e =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 9u, 32u, 16u);
|
||||
auto* f =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 16u);
|
||||
auto* g =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 33u, 17u);
|
||||
|
||||
EXPECT_TRUE(a->Equals(*b));
|
||||
EXPECT_FALSE(a->Equals(*c));
|
||||
EXPECT_FALSE(a->Equals(*d));
|
||||
EXPECT_FALSE(a->Equals(*e));
|
||||
EXPECT_FALSE(a->Equals(*f));
|
||||
EXPECT_FALSE(a->Equals(*g));
|
||||
EXPECT_FALSE(a->Equals(type::Void{}));
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, FriendlyNameRuntimeSized) {
|
||||
auto* arr =
|
||||
create<Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 0u, 4u, 4u, 4u);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32>");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, FriendlyNameStaticSized) {
|
||||
auto* arr =
|
||||
create<Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u, 20u, 4u, 4u);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, FriendlyNameRuntimeSizedNonImplicitStride) {
|
||||
auto* arr =
|
||||
create<Array>(create<type::I32>(), create<type::RuntimeArrayCount>(), 0u, 4u, 8u, 4u);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(8) array<i32>");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, FriendlyNameStaticSizedNonImplicitStride) {
|
||||
auto* arr =
|
||||
create<Array>(create<type::I32>(), create<type::ConstantArrayCount>(5u), 4u, 20u, 8u, 4u);
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(8) array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, IsConstructable) {
|
||||
auto* fixed_sized =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* named_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::NamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* unnamed_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::UnnamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* runtime_sized =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 32u, 16u);
|
||||
|
||||
EXPECT_TRUE(fixed_sized->IsConstructible());
|
||||
EXPECT_FALSE(named_override_sized->IsConstructible());
|
||||
EXPECT_FALSE(unnamed_override_sized->IsConstructible());
|
||||
EXPECT_FALSE(runtime_sized->IsConstructible());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, HasCreationFixedFootprint) {
|
||||
auto* fixed_sized =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* named_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::NamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* unnamed_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::UnnamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* runtime_sized =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 32u, 16u);
|
||||
|
||||
EXPECT_TRUE(fixed_sized->HasCreationFixedFootprint());
|
||||
EXPECT_FALSE(named_override_sized->HasCreationFixedFootprint());
|
||||
EXPECT_FALSE(unnamed_override_sized->HasCreationFixedFootprint());
|
||||
EXPECT_FALSE(runtime_sized->HasCreationFixedFootprint());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTest, HasFixedFootprint) {
|
||||
auto* fixed_sized =
|
||||
create<Array>(create<type::U32>(), create<type::ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
|
||||
auto* named_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::NamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* unnamed_override_sized = create<Array>(
|
||||
create<type::U32>(), create<sem::UnnamedOverrideArrayCount>(nullptr), 4u, 8u, 32u, 16u);
|
||||
auto* runtime_sized =
|
||||
create<Array>(create<type::U32>(), create<type::RuntimeArrayCount>(), 4u, 8u, 32u, 16u);
|
||||
|
||||
EXPECT_TRUE(fixed_sized->HasFixedFootprint());
|
||||
EXPECT_TRUE(named_override_sized->HasFixedFootprint());
|
||||
EXPECT_TRUE(unnamed_override_sized->HasFixedFootprint());
|
||||
EXPECT_FALSE(runtime_sized->HasFixedFootprint());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
@@ -14,10 +14,9 @@
|
||||
|
||||
#include "src/tint/type/type.h"
|
||||
|
||||
#include "src/tint/sem/array.h"
|
||||
#include "src/tint/sem/struct.h"
|
||||
#include "src/tint/type/abstract_float.h"
|
||||
#include "src/tint/type/abstract_int.h"
|
||||
#include "src/tint/type/array.h"
|
||||
#include "src/tint/type/bool.h"
|
||||
#include "src/tint/type/f16.h"
|
||||
#include "src/tint/type/f32.h"
|
||||
@@ -26,6 +25,7 @@
|
||||
#include "src/tint/type/pointer.h"
|
||||
#include "src/tint/type/reference.h"
|
||||
#include "src/tint/type/sampler.h"
|
||||
#include "src/tint/type/struct.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
#include "src/tint/type/u32.h"
|
||||
#include "src/tint/type/vector.h"
|
||||
@@ -181,7 +181,7 @@ bool Type::HoldsAbstract() const {
|
||||
[&](const type::AbstractNumeric*) { return true; },
|
||||
[&](const type::Vector* v) { return v->type()->HoldsAbstract(); },
|
||||
[&](const type::Matrix* m) { return m->type()->HoldsAbstract(); },
|
||||
[&](const sem::Array* a) { return a->ElemType()->HoldsAbstract(); },
|
||||
[&](const type::Array* a) { return a->ElemType()->HoldsAbstract(); },
|
||||
[&](const type::StructBase* s) {
|
||||
for (auto* m : s->Members()) {
|
||||
if (m->Type()->HoldsAbstract()) {
|
||||
@@ -232,8 +232,8 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
|
||||
}
|
||||
return kNoConversion;
|
||||
},
|
||||
[&](const sem::Array* from_arr) {
|
||||
if (auto* to_arr = to->As<sem::Array>()) {
|
||||
[&](const type::Array* from_arr) {
|
||||
if (auto* to_arr = to->As<type::Array>()) {
|
||||
if (from_arr->Count() == to_arr->Count()) {
|
||||
return ConversionRank(from_arr->ElemType(), to_arr->ElemType());
|
||||
}
|
||||
@@ -273,7 +273,7 @@ const Type* Type::ElementOf(const Type* ty, uint32_t* count /* = nullptr */) {
|
||||
}
|
||||
return m->ColumnType();
|
||||
},
|
||||
[&](const sem::Array* a) {
|
||||
[&](const type::Array* a) {
|
||||
if (count) {
|
||||
if (auto* const_count = a->Count()->As<type::ConstantArrayCount>()) {
|
||||
*count = const_count->value;
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/sem/struct.h"
|
||||
#include "src/tint/type/array_count.h"
|
||||
#include "src/tint/type/node.h"
|
||||
#include "src/tint/type/struct.h"
|
||||
#include "src/tint/type/type.h"
|
||||
#include "src/tint/utils/unique_allocator.h"
|
||||
|
||||
|
||||
@@ -93,63 +93,63 @@ struct TypeTest : public TestHelper {
|
||||
/* align*/ 4u,
|
||||
/* size*/ 4u,
|
||||
/* size_no_padding*/ 4u);
|
||||
const sem::Array* arr_i32 = create<sem::Array>(
|
||||
const type::Array* arr_i32 = create<type::Array>(
|
||||
/* element */ i32,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 4u,
|
||||
/* size */ 5u * 4u,
|
||||
/* stride */ 5u * 4u,
|
||||
/* implicit_stride */ 5u * 4u);
|
||||
const sem::Array* arr_ai = create<sem::Array>(
|
||||
const type::Array* arr_ai = create<type::Array>(
|
||||
/* element */ ai,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 4u,
|
||||
/* size */ 5u * 4u,
|
||||
/* stride */ 5u * 4u,
|
||||
/* implicit_stride */ 5u * 4u);
|
||||
const sem::Array* arr_vec3_i32 = create<sem::Array>(
|
||||
const type::Array* arr_vec3_i32 = create<type::Array>(
|
||||
/* element */ vec3_i32,
|
||||
/* count */ create<ConstantArrayCount>(5u),
|
||||
/* align */ 16u,
|
||||
/* size */ 5u * 16u,
|
||||
/* stride */ 5u * 16u,
|
||||
/* implicit_stride */ 5u * 16u);
|
||||
const sem::Array* arr_vec3_ai = create<sem::Array>(
|
||||
const type::Array* arr_vec3_ai = create<type::Array>(
|
||||
/* element */ vec3_ai,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 16u,
|
||||
/* size */ 5u * 16u,
|
||||
/* stride */ 5u * 16u,
|
||||
/* implicit_stride */ 5u * 16u);
|
||||
const sem::Array* arr_mat4x3_f16 = create<sem::Array>(
|
||||
const type::Array* arr_mat4x3_f16 = create<type::Array>(
|
||||
/* element */ mat4x3_f16,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 32u,
|
||||
/* size */ 5u * 32u,
|
||||
/* stride */ 5u * 32u,
|
||||
/* implicit_stride */ 5u * 32u);
|
||||
const sem::Array* arr_mat4x3_f32 = create<sem::Array>(
|
||||
const type::Array* arr_mat4x3_f32 = create<type::Array>(
|
||||
/* element */ mat4x3_f32,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 64u,
|
||||
/* size */ 5u * 64u,
|
||||
/* stride */ 5u * 64u,
|
||||
/* implicit_stride */ 5u * 64u);
|
||||
const sem::Array* arr_mat4x3_af = create<sem::Array>(
|
||||
const type::Array* arr_mat4x3_af = create<type::Array>(
|
||||
/* element */ mat4x3_af,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 64u,
|
||||
/* size */ 5u * 64u,
|
||||
/* stride */ 5u * 64u,
|
||||
/* implicit_stride */ 5u * 64u);
|
||||
const sem::Array* arr_str_f16 = create<sem::Array>(
|
||||
const type::Array* arr_str_f16 = create<type::Array>(
|
||||
/* element */ str_f16,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 4u,
|
||||
/* size */ 5u * 4u,
|
||||
/* stride */ 5u * 4u,
|
||||
/* implicit_stride */ 5u * 4u);
|
||||
const sem::Array* arr_str_af = create<sem::Array>(
|
||||
const type::Array* arr_str_af = create<type::Array>(
|
||||
/* element */ str_af,
|
||||
/* count */ create<type::ConstantArrayCount>(5u),
|
||||
/* align */ 4u,
|
||||
|
||||
Reference in New Issue
Block a user