2020-03-02 20:47:43 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-01-21 15:42:10 +00:00
|
|
|
#include "src/type/type.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2021-01-21 15:42:10 +00:00
|
|
|
#include "src/type/access_control_type.h"
|
|
|
|
#include "src/type/alias_type.h"
|
|
|
|
#include "src/type/array_type.h"
|
|
|
|
#include "src/type/bool_type.h"
|
|
|
|
#include "src/type/f32_type.h"
|
|
|
|
#include "src/type/i32_type.h"
|
|
|
|
#include "src/type/matrix_type.h"
|
|
|
|
#include "src/type/pointer_type.h"
|
|
|
|
#include "src/type/sampler_type.h"
|
|
|
|
#include "src/type/struct_type.h"
|
|
|
|
#include "src/type/texture_type.h"
|
|
|
|
#include "src/type/u32_type.h"
|
|
|
|
#include "src/type/vector_type.h"
|
|
|
|
#include "src/type/void_type.h"
|
|
|
|
|
|
|
|
TINT_INSTANTIATE_CLASS_ID(tint::type::Type);
|
2020-12-02 18:19:28 +00:00
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
namespace tint {
|
|
|
|
namespace type {
|
|
|
|
|
|
|
|
Type::Type() = default;
|
|
|
|
|
2020-11-30 23:30:58 +00:00
|
|
|
Type::Type(Type&&) = default;
|
2020-11-30 23:30:58 +00:00
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
Type::~Type() = default;
|
|
|
|
|
2020-04-23 22:26:52 +00:00
|
|
|
Type* Type::UnwrapPtrIfNeeded() {
|
2020-12-01 21:07:27 +00:00
|
|
|
if (auto* ptr = As<type::Pointer>()) {
|
|
|
|
return ptr->type();
|
2020-04-23 22:26:52 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-10-28 20:32:22 +00:00
|
|
|
Type* Type::UnwrapIfNeeded() {
|
2020-06-22 20:30:33 +00:00
|
|
|
auto* where = this;
|
2020-10-28 20:32:22 +00:00
|
|
|
while (true) {
|
2020-12-01 21:07:27 +00:00
|
|
|
if (auto* alias = where->As<type::Alias>()) {
|
|
|
|
where = alias->type();
|
|
|
|
} else if (auto* access = where->As<type::AccessControl>()) {
|
|
|
|
where = access->type();
|
2020-10-28 20:32:22 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2020-06-22 20:30:33 +00:00
|
|
|
}
|
|
|
|
return where;
|
|
|
|
}
|
|
|
|
|
2020-10-28 20:32:22 +00:00
|
|
|
Type* Type::UnwrapAll() {
|
|
|
|
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
|
2020-06-22 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 16:53:59 +00:00
|
|
|
uint64_t Type::MinBufferBindingSize(MemoryLayout) const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Type::BaseAlignment(MemoryLayout) const {
|
2020-10-22 19:31:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-24 14:38:44 +00:00
|
|
|
bool Type::is_scalar() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return is_float_scalar() || is_integer_scalar() || Is<Bool>();
|
2020-09-24 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 14:07:43 +00:00
|
|
|
bool Type::is_float_scalar() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<F32>();
|
2020-04-20 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_float_matrix() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<Matrix>() && As<Matrix>()->type()->is_float_scalar();
|
2020-04-20 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_float_vector() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<Vector>() && As<Vector>()->type()->is_float_scalar();
|
2020-04-20 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_float_scalar_or_vector() {
|
|
|
|
return is_float_scalar() || is_float_vector();
|
|
|
|
}
|
|
|
|
|
2020-06-08 19:01:07 +00:00
|
|
|
bool Type::is_integer_scalar() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<U32>() || Is<I32>();
|
2020-06-08 19:01:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 23:48:07 +00:00
|
|
|
bool Type::is_unsigned_integer_vector() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<Vector>() && As<Vector>()->type()->Is<U32>();
|
2020-06-08 23:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_signed_integer_vector() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<Vector>() && As<Vector>()->type()->Is<I32>();
|
2020-06-08 19:01:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 14:07:43 +00:00
|
|
|
bool Type::is_unsigned_scalar_or_vector() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<U32>() || (Is<Vector>() && As<Vector>()->type()->Is<U32>());
|
2020-04-20 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_signed_scalar_or_vector() {
|
2020-11-30 23:30:58 +00:00
|
|
|
return Is<I32>() || (Is<Vector>() && As<Vector>()->type()->Is<I32>());
|
2020-04-20 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Type::is_integer_scalar_or_vector() {
|
|
|
|
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
} // namespace type
|
|
|
|
} // namespace tint
|