Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
donner::gpu::shader::IrType Class Reference

An immutable shader IR type with deep value equality. More...

#include "donner/gpu/shader/IrType.h"

Classes

struct  Member
 One named member of a struct type. More...

Public Types

enum class  Kind : uint8_t {
  Scalar ,
  Vector ,
  Matrix4x4f ,
  SizedArray ,
  RuntimeArray ,
  Struct ,
  Texture2dF32 ,
  Sampler
}
 Type category. More...

Public Member Functions

Kind kind () const
 Type category.
ScalarKind scalarKind () const
 Scalar kind of a scalar or vector type.
uint32_t vectorSize () const
 Component count of a vector type (2..4).
const IrType & elementType () const
 Element type of a sized or runtime array.
uint32_t arrayCount () const
 Element count of a sized array.
const RcStringstructName () const
 Name of a struct type.
std::span< const MemberstructMembers () const
 Members of a struct type.
bool isScalar () const
 True for bool/i32/u32/f32.
bool isVector () const
 True for vecN types.
bool isNumericScalar () const
 True for i32/u32/f32 scalars.
bool isNumericVector () const
 True for vectors of i32/u32/f32.
bool isNumeric () const
 True for i32/u32/f32 scalars and their vectors.
bool isFloatScalarOrVector () const
 True for f32 and vectors of f32.
bool isPlainData () const
 True for types that can be stored in arrays and structs (everything except runtime arrays, textures, and samplers).
bool operator== (const IrType &other) const
 Deep structural equality.
std::string toString () const
 Formats this type, e.g. vec2<f32> or array<Band>.

Static Public Member Functions

static IrType Scalar (ScalarKind kind)
 Scalar type of the given kind.
static IrType Bool ()
 bool type.
static IrType I32 ()
 i32 type.
static IrType U32 ()
 u32 type.
static IrType F32 ()
 f32 type.
static IrType Vec2 (ScalarKind element)
 vec2<element> type.
static IrType Vec3 (ScalarKind element)
 vec3<element> type.
static IrType Vec4 (ScalarKind element)
 vec4<element> type.
static IrType Vec2f ()
 vec2<f32> convenience factory.
static IrType Vec3f ()
 vec3<f32> convenience factory.
static IrType Vec4f ()
 vec4<f32> convenience factory.
static IrType Vec2i ()
 vec2<i32> convenience factory.
static IrType Vec2u ()
 vec2<u32> convenience factory.
static IrType Mat4x4f ()
 mat4x4<f32> type.
static IrType Texture2dF32 ()
 texture_2d<f32> resource type.
static IrType SamplerType ()
 Filtering sampler resource type.
static ShaderResult< IrType > SizedArray (const IrType &element, uint32_t count, const RcString &label="array")
 array<element, count> type.
static ShaderResult< IrType > RuntimeArray (const IrType &element, const RcString &label="runtimeArray")
 array<element> runtime-sized type, usable only as a read-only storage buffer root.
static ShaderResult< IrType > Struct (const RcString &name, std::vector< Member > members, const RcString &label="struct")
 Named struct type.

Friends

std::ostream & operator<< (std::ostream &os, const IrType &type)
 Ostream output operator.

Detailed Description

An immutable shader IR type with deep value equality.

Construct through the static factories. Factories that can receive invalid input (arrays, structs) return ShaderResult and fail closed; the fixed factories (scalars, vectors, matrix, resource types) cannot fail.


Class Documentation

◆ donner::gpu::shader::IrType::Member

struct donner::gpu::shader::IrType::Member

One named member of a struct type.

Class Members
RcString name Member name; unique within the struct.
IrType type Member type.

Member Enumeration Documentation

◆ Kind

enum class donner::gpu::shader::IrType::Kind : uint8_t
strong

Type category.

Enumerator
Scalar 

bool / i32 / u32 / f32.

Vector 

vecN<T>, N in 2..4.

Matrix4x4f 

mat4x4f (the only matrix type in scope).

SizedArray 

array<E, N>.

RuntimeArray 

array<E>; storage buffer roots only.

Struct 

Named struct with named members.

Texture2dF32 

texture_2d<f32>.

Sampler 

Filtering sampler.

Member Function Documentation

◆ arrayCount()

uint32_t donner::gpu::shader::IrType::arrayCount ( ) const

Element count of a sized array.

Precondition
kind() is SizedArray.

◆ elementType()

const IrType & donner::gpu::shader::IrType::elementType ( ) const

Element type of a sized or runtime array.

Precondition
kind() is SizedArray or RuntimeArray.

◆ operator==()

bool donner::gpu::shader::IrType::operator== ( const IrType & other) const

Deep structural equality.

Parameters
otherType to compare against.

◆ RuntimeArray()

ShaderResult< IrType > donner::gpu::shader::IrType::RuntimeArray ( const IrType & element,
const RcString & label = "runtimeArray" )
static

array<element> runtime-sized type, usable only as a read-only storage buffer root.

Fails closed if element is not plain data.

Parameters
elementElement type.
labelDiagnostic label for errors.

◆ Scalar()

IrType donner::gpu::shader::IrType::Scalar ( ScalarKind kind)
static

Scalar type of the given kind.

Parameters
kindScalar kind.

◆ scalarKind()

ScalarKind donner::gpu::shader::IrType::scalarKind ( ) const

Scalar kind of a scalar or vector type.

Precondition
kind() is Scalar or Vector.

◆ SizedArray()

ShaderResult< IrType > donner::gpu::shader::IrType::SizedArray ( const IrType & element,
uint32_t count,
const RcString & label = "array" )
static

array<element, count> type.

Fails closed if count is zero or element is not plain data (runtime arrays, textures, and samplers cannot be array elements).

Parameters
elementElement type.
countElement count; must be nonzero.
labelDiagnostic label for errors.

◆ Struct()

ShaderResult< IrType > donner::gpu::shader::IrType::Struct ( const RcString & name,
std::vector< Member > members,
const RcString & label = "struct" )
static

Named struct type.

Fails closed on empty member lists, duplicate member names, or member types that are not plain data (runtime arrays are only supported as storage binding roots in this packet, so they cannot be struct members).

Parameters
nameStruct name.
membersStruct members in declaration order.
labelDiagnostic label for errors.

◆ structMembers()

std::span< const Member > donner::gpu::shader::IrType::structMembers ( ) const

Members of a struct type.

Precondition
kind() is Struct.

◆ structName()

const RcString & donner::gpu::shader::IrType::structName ( ) const

Name of a struct type.

Precondition
kind() is Struct.

◆ Vec2()

IrType donner::gpu::shader::IrType::Vec2 ( ScalarKind element)
static

vec2<element> type.

Parameters
elementComponent scalar kind.

◆ Vec3()

IrType donner::gpu::shader::IrType::Vec3 ( ScalarKind element)
static

vec3<element> type.

Parameters
elementComponent scalar kind.

◆ Vec4()

IrType donner::gpu::shader::IrType::Vec4 ( ScalarKind element)
static

vec4<element> type.

Parameters
elementComponent scalar kind.

◆ vectorSize()

uint32_t donner::gpu::shader::IrType::vectorSize ( ) const

Component count of a vector type (2..4).

Precondition
kind() is Vector.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const IrType & type )
friend

Ostream output operator.

Parameters
osOutput stream.
typeType to output.

The documentation for this class was generated from the following file: