chromium/third_party/dawn/src/tint/lang/core/fluent_types.h

// Copyright 2023 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef SRC_TINT_LANG_CORE_FLUENT_TYPES_H_
#define SRC_TINT_LANG_CORE_FLUENT_TYPES_H_

#include <stdint.h>

#include "src/tint/lang/core/access.h"
#include "src/tint/lang/core/address_space.h"
#include "src/tint/lang/core/number.h"

namespace tint::core::fluent_types {

f16;
f32;
i32;
i8;
u32;
u8;
AFloat;
AInt;

// A sentinel type used by some template arguments to signal that the a type should be inferred.
struct Infer {};

/// A 'fluent' type helper used to construct an ast::Array or type::Array.
/// @tparam T the array element type
/// @tparam N the array length. 0 represents a runtime-sized array.
/// @see https://www.w3.org/TR/WGSL/#array-types
template <typename T, uint32_t N = 0>
struct array {};

/// A 'fluent' type helper used to construct an ast::Atomic or type::Atomic.
/// @tparam T the atomic element type
/// @see https://www.w3.org/TR/WGSL/#atomic-types
template <typename T>
struct atomic {};

/// A 'fluent' type helper used to construct an ast::Vector or type::Vector.
/// @tparam N the vector width
/// @tparam T the vector element type
template <uint32_t N, typename T>
struct vec {};

/// A 'fluent' type helper used to construct an ast::Matrix or type::Matrix.
/// @tparam C the number of columns of the matrix
/// @tparam R the number of rows of the matrix
/// @tparam T the matrix element type
/// @see https://www.w3.org/TR/WGSL/#matrix-types
template <uint32_t C, uint32_t R, typename T>
struct mat {};

/// A 'fluent' type helper used to construct an ast::Pointer or type::Pointer.
/// @tparam ADDRESS the pointer address space
/// @tparam T the pointer storage type
/// @tparam ACCESS the pointer access control
template <core::AddressSpace ADDRESS, typename T, core::Access ACCESS = core::Access::kUndefined>
struct ptr {};

////////////////////////////////////////////////////////////////////////////////
// Aliases
//
// Shorthand aliases for the types declared above
////////////////////////////////////////////////////////////////////////////////

//! @cond Doxygen_Suppress
mat2x2;

mat2x3;

mat2x4;

mat3x2;

mat3x3;

mat3x4;

mat4x2;

mat4x3;

mat4x4;

vec2;

vec3;

vec4;

//! @endcond

////////////////////////////////////////////////////////////////////////////////
// Address space aliases
////////////////////////////////////////////////////////////////////////////////
static constexpr core::AddressSpace function =;
static constexpr core::AddressSpace handle =;
static constexpr core::AddressSpace private_ =;
static constexpr core::AddressSpace push_constant =;
static constexpr core::AddressSpace storage =;
static constexpr core::AddressSpace uniform =;
static constexpr core::AddressSpace workgroup =;

////////////////////////////////////////////////////////////////////////////////
// Access control aliases
////////////////////////////////////////////////////////////////////////////////
static constexpr core::Access read =;
static constexpr core::Access read_write =;
static constexpr core::Access write =;

////////////////////////////////////////////////////////////////////////////////
// Traits
////////////////////////////////////////////////////////////////////////////////
namespace detail {

//! @cond Doxygen_Suppress
template <typename T>
struct IsArray {};

IsArray<array<T, N>>;

template <typename T>
struct IsAtomic {};

IsAtomic<atomic<T>>;

template <typename T>
struct IsMatrix {};

IsMatrix<mat<C, R, T>>;

template <typename T>
struct IsVector {};

IsVector<vec<N, T>>;

template <typename T>
struct IsPointer {};

IsPointer<ptr<ADDRESS, T, ACCESS>>;
//! @endcond

}  // namespace detail

/// Evaluates to true if `T` is a array
IsArray;

/// Evaluates to true if `T` is a atomic
IsAtomic;

/// Evaluates to true if `T` is a mat
IsMatrix;

/// Evaluates to true if `T` is a vec
IsVector;

/// Evaluates to true if `T` is a ptr
IsPointer;

}  // namespace tint::core::fluent_types

#endif  // SRC_TINT_LANG_CORE_FLUENT_TYPES_H_