Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
Module.h File Reference

Bounded, typed intermediate representation for the supported WGSL frontend profile. More...

#include <array>
#include <concepts>
#include <cstdint>
#include <limits>
#include <string_view>
#include "donner/base/Utils.h"
Include dependency graph for Module.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::gpu::shader::wgsl::SourceSpan
 A half-open byte range in the WGSL input. More...
struct  donner::gpu::shader::wgsl::NameRef
 A module-owned identifier spelling. More...
struct  donner::gpu::shader::wgsl::Type
 A resolved scalar, vector, structure, or resource type. More...
struct  donner::gpu::shader::wgsl::InterfaceDecoration
 A scalar/vector leaf in an entry-point interface. More...
struct  donner::gpu::shader::wgsl::StructMember
 Storage layout of one structure member. More...
struct  donner::gpu::shader::wgsl::Struct
 One declared structure and its computed uniform layout. More...
struct  donner::gpu::shader::wgsl::Binding
 One module-scope resource binding. More...
struct  donner::gpu::shader::wgsl::Symbol
 One resolved identifier declaration. More...
struct  donner::gpu::shader::wgsl::Expression
 One typed expression node. Operands are in source order. More...
struct  donner::gpu::shader::wgsl::Statement
 One typed statement node. The next link preserves lexical statement order. More...
struct  donner::gpu::shader::wgsl::InterfaceVariable
 A flattened scalar/vector input or output of one entry point. More...
struct  donner::gpu::shader::wgsl::Function
 One declared function. More...
struct  donner::gpu::shader::wgsl::FoldedConstant
 An outermost constant f32 or abstract-float expression the parser folded. The WGSL projection spells its value exactly in place of the authored source, so a browser receives the value the native projections carry rather than evaluating the expression with WGSL's looser accuracy. More...
struct  donner::gpu::shader::wgsl::ModuleLimits
 Fixed capacities for one frontend module. More...
struct  donner::gpu::shader::wgsl::Module
 A complete, immutable-on-success frontend module backed by fixed arenas. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Typedefs

using donner::gpu::shader::wgsl::ArenaId = uint16_t
 Identifier for an item stored in one of Module's arenas.

Enumerations

enum class  donner::gpu::shader::wgsl::StorageTextureFormat : uint8_t {
  Rgba32Float ,
  Rgba8Unorm
}
 Storage format accepted by the frontend profile. More...
enum class  donner::gpu::shader::wgsl::TypeKind : uint8_t {
  Void ,
  Bool ,
  I32 ,
  U32 ,
  F32 ,
  AbstractInt ,
  AbstractFloat ,
  Struct ,
  Matrix ,
  Array ,
  Sampler ,
  SampledTexture2d ,
  StorageTexture2d ,
  Pointer
}
 Kind of a resolved WGSL value type. More...
enum class  donner::gpu::shader::wgsl::BuiltinValue : uint8_t {
  None ,
  GlobalInvocationId ,
  VertexIndex ,
  Position ,
  InstanceIndex
}
 Builtin value supported by a shader entry interface.
enum class  donner::gpu::shader::wgsl::BindingKind : uint8_t {
  Uniform ,
  ReadOnlyStorage ,
  Sampler ,
  SampledTexture ,
  StorageTexture
}
 Module-scope resource binding kind. More...
enum class  donner::gpu::shader::wgsl::SymbolKind : uint8_t {
  Constant ,
  Binding ,
  Parameter ,
  Let ,
  Var
}
 Scope category of one resolved name. More...
enum class  donner::gpu::shader::wgsl::UnaryOp : uint8_t {
  Negate ,
  Not
}
 Unary operator represented by Expression::payload. More...
enum class  donner::gpu::shader::wgsl::BinaryOp : uint8_t {
  BitAnd = 13 ,
  ShiftLeft = 14 ,
  ShiftRight = 15 ,
  Add = 0 ,
  Sub ,
  Mul ,
  Div ,
  Mod ,
  Lt ,
  Le ,
  Gt ,
  Ge ,
  Eq ,
  Ne ,
  And ,
  Or
}
 Binary operator represented by Expression::payload. More...
enum class  donner::gpu::shader::wgsl::Builtin : uint8_t {
  All ,
  Abs ,
  Max ,
  Round ,
  Sqrt ,
  Dot ,
  Length ,
  Normalize ,
  Saturate ,
  Fract ,
  Fwidth ,
  Any ,
  Clamp ,
  Select ,
  Min ,
  Ceil ,
  Exp ,
  TextureLoad ,
  TextureDimensions ,
  TextureStore ,
  Floor ,
  Sign ,
  Sin ,
  Cos ,
  Pow ,
  Mix ,
  TextureSample ,
  TextureSampleLevel
}
 Builtins accepted by the frontend profile. More...
enum class  donner::gpu::shader::wgsl::ExpressionKind : uint8_t {
  Zero ,
  Literal ,
  Symbol ,
  Unary ,
  Binary ,
  Member ,
  Swizzle ,
  Construct ,
  Convert ,
  BuiltinCall ,
  FunctionCall ,
  Index ,
  AddressOf ,
  Deref
}
 Kind of a typed expression node. More...
enum class  donner::gpu::shader::wgsl::StatementKind : uint8_t {
  Declaration ,
  Assign ,
  If ,
  For ,
  Return ,
  TextureStore ,
  Break ,
  Continue ,
  Discard ,
  Switch ,
  Case ,
  Call ,
  Loop ,
  While
}
 Kind of a typed statement node. More...
enum class  donner::gpu::shader::wgsl::Stage : uint8_t {
  None ,
  Compute ,
  Vertex ,
  Fragment
}
 Pipeline stage associated with a function. More...

Functions

constexpr std::array< ArenaId, kMaxExpressionOperands > donner::gpu::shader::wgsl::Operands (std::same_as< ArenaId > auto... ids)
 Builds an expression operand array, filling every slot past ids with donner::gpu::shader::wgsl::kInvalidArenaId.

Variables

constexpr ArenaId donner::gpu::shader::wgsl::kInvalidArenaId = std::numeric_limits<ArenaId>::max()
 Invalid arena identifier.
constexpr uint8_t donner::gpu::shader::wgsl::kMaxExpressionOperands = 8
 Maximum call arity and expression operands.

Detailed Description

Bounded, typed intermediate representation for the supported WGSL frontend profile.

Enumeration Type Documentation

◆ BinaryOp

enum class donner::gpu::shader::wgsl::BinaryOp : uint8_t
strong

Binary operator represented by Expression::payload.

Enumerator
BitAnd 

Integer bitwise AND.

ShiftLeft 

Integer <<; the u32 amount is taken modulo the 32-bit width.

ShiftRight 

Integer >>; arithmetic for i32, logical for u32, amount modulo 32.

Sub 

-.

Mul 

*.

Div 

/.

Mod 

%.

Lt 

<.

Le 

<=.

Gt 

>.

Ge 

>=.

Eq 

==.

Ne 

!=.

And 

&&.

Or 

||.

◆ BindingKind

enum class donner::gpu::shader::wgsl::BindingKind : uint8_t
strong

Module-scope resource binding kind.

Enumerator
Uniform 

var<uniform>.

ReadOnlyStorage 

var<storage, read>.

Sampler 

A filtering sampler.

SampledTexture 

texture_2d<f32>.

StorageTexture 

Write-only storage texture.

◆ Builtin

enum class donner::gpu::shader::wgsl::Builtin : uint8_t
strong

Builtins accepted by the frontend profile.

Enumerator
Any 

any.

Clamp 

clamp.

Select 

select.

Min 

min.

Ceil 

ceil.

Exp 

exp.

TextureLoad 

textureLoad.

TextureDimensions 

textureDimensions.

TextureStore 

textureStore.

Floor 

Floating-point floor.

Sign 

Floating-point sign.

Sin 

Floating-point sine.

Cos 

Floating-point cosine.

Pow 

Floating-point power.

Mix 

Floating-point linear interpolation.

TextureSample 

Implicit-level filtering in uniform fragment control.

TextureSampleLevel 

Explicit-level filtering.

◆ ExpressionKind

enum class donner::gpu::shader::wgsl::ExpressionKind : uint8_t
strong

Kind of a typed expression node.

Enumerator
Zero 

Zero initialization of a constructible value.

Literal 

A scalar literal; payload holds IEEE or integer bits.

Symbol 

A resolved Symbol; payload is its arena identifier.

Unary 

A UnaryOp and one operand.

Binary 

A BinaryOp and two operands.

Member 

A structure member; payload is its StructMember identifier.

Swizzle 

Vector swizzle; payload encodes lane indices.

Construct 

Vector construction.

Convert 

Explicit scalar or vector conversion.

BuiltinCall 

A Builtin call.

FunctionCall 

A declared Function call; payload is its arena identifier.

Index 

Fixed-array access with base and index operands.

AddressOf 

&localVar; yields a function-address-space pointer.

Deref 

*pointer; yields the pointee as an assignable value.

◆ Stage

enum class donner::gpu::shader::wgsl::Stage : uint8_t
strong

Pipeline stage associated with a function.

Enumerator
None 

Helper function.

Compute 

Compute entry point.

Vertex 

Vertex entry point.

Fragment 

Fragment entry point.

◆ StatementKind

enum class donner::gpu::shader::wgsl::StatementKind : uint8_t
strong

Kind of a typed statement node.

Enumerator
Declaration 

A let or var declaration.

Assign 

An assignment.

If 

A conditional branch.

For 

A for loop.

Return 

A return statement.

TextureStore 

textureStore(texture, coord, value).

Break 

Exit the innermost loop.

Continue 

Run the innermost loop continuation.

Discard 

Discard the current fragment invocation.

Switch 

An integer selection with case clauses.

Case 

One constant case or default clause.

Call 

A call to a helper that returns no value.

Loop 

A loop whose only exit is a break.

While 

A while loop with a bool condition.

◆ StorageTextureFormat

Storage format accepted by the frontend profile.

Enumerator
Rgba32Float 

rgba32float.

Rgba8Unorm 

rgba8unorm.

◆ SymbolKind

enum class donner::gpu::shader::wgsl::SymbolKind : uint8_t
strong

Scope category of one resolved name.

Enumerator
Constant 

A module-scope constant value.

Binding 

A module-scope resource binding.

Parameter 

A function parameter; a ptr<function, T> pointee is writable through it.

Let 

An immutable local binding.

Var 

A mutable local variable.

◆ TypeKind

enum class donner::gpu::shader::wgsl::TypeKind : uint8_t
strong

Kind of a resolved WGSL value type.

Enumerator
Void 

No value.

Bool 

bool.

I32 

i32.

U32 

u32.

F32 

f32.

AbstractInt 

Shader-creation-time signed integer.

AbstractFloat 

Shader-creation-time binary64 value.

Struct 

A declared structure.

Matrix 

A column-major f32 matrix.

Array 

A fixed-size array.

Sampler 

Filtering sampler resource.

SampledTexture2d 

texture_2d<f32>.

StorageTexture2d 

texture_storage_2d<rgba32float, write>.

Pointer 

ptr<function, T>; the pointee is stored in the array element fields.

◆ UnaryOp

enum class donner::gpu::shader::wgsl::UnaryOp : uint8_t
strong

Unary operator represented by Expression::payload.

Enumerator
Negate 

-.

Not 

!.

Function Documentation

◆ Operands()

std::array< ArenaId, kMaxExpressionOperands > donner::gpu::shader::wgsl::Operands ( std::same_as< ArenaId > auto... ids)
constexpr

Builds an expression operand array, filling every slot past ids with donner::gpu::shader::wgsl::kInvalidArenaId.

Zero is a valid arena identifier, so an unset slot left value-initialized would alias expression zero. Every operand array is built here so no call site has to spell the sentinel once per slot.

Parameters
idsOperand arena identifiers in source order.