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::FunctionBuilder Class Reference

Builds one function or entry point. More...

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

Public Member Functions

 FunctionBuilder (FunctionBuilder &&other) noexcept
 Move constructor; other becomes an inert moved-from shell.
 FunctionBuilder (const FunctionBuilder &)=delete
FunctionBuilderoperator= (const FunctionBuilder &)=delete
FunctionBuilderoperator= (FunctionBuilder &&)=delete
 ~FunctionBuilder ()
 Destructor. Destroying an unfinished builder abandons the function, letting the module builder start a new one (the abandoned function is not registered).
ShaderResult< IrExprref (const RcString &name) const
 Resolves name to a reference expression: function parameters, lets, vars, then module-scope constants and resource bindings.
ShaderResult< IrExpraddLet (const RcString &name, const IrExpr &value)
 Declares let name = value; and returns a reference to it.
ShaderResult< IrExpraddVar (const RcString &name, const IrType &type, const std::optional< IrExpr > &init=std::nullopt)
 Declares var name: type (= init); and returns a (mutable) reference to it.
ShaderStatus assign (const IrExpr &lhs, const IrExpr &rhs)
 Records lhs = rhs;.
ShaderStatus beginIf (const IrExpr &condition)
 Opens if (condition) { ... }.
ShaderStatus elseBranch ()
 Switches the innermost open if to its else-branch.
ShaderStatus endIf ()
 Closes the innermost open if.
ShaderResult< IrExprbeginFor (const RcString &name, const IrExpr &init)
 Opens for (var name = init; ...) and returns a reference to the loop variable.
ShaderStatus forCondition (const IrExpr &condition)
 Sets the condition of the innermost open for.
ShaderStatus forContinuing (const IrExpr &lhs, const IrExpr &rhs)
 Sets the continuing assignment of the innermost open for.
ShaderStatus endFor ()
 Closes the innermost open for.
ShaderStatus breakStmt ()
 Records break; (valid inside a loop).
ShaderStatus continueStmt ()
 Records continue; (valid inside a loop).
ShaderStatus returnValue (const IrExpr &value)
 Records return expr; for a plain function with a return type.
ShaderStatus returnVoid ()
 Records return; for a void plain function.
ShaderStatus returnOutputs (std::vector< IrExpr > outputs)
 Records the entry point return: one expression per declared output member, in order.
ShaderStatus discard ()
 Records discard; (fragment entry points only).
ShaderResult< IrExprcallFunction (const RcString &name, std::vector< IrExpr > args)
 Calls a previously finished module function.
ShaderStatus finish ()
 Finishes the function, registering it with the module builder. Fails if any prior operation failed or a block is still open.

Friends

class ModuleBuilder

Detailed Description

Builds one function or entry point.

Created by ModuleBuilder; validates scope, types, loop/stage context, and stage IO before recording statements. The first error latches: every subsequent operation and finish return it, so an ill-typed build cannot silently succeed.

Constructor & Destructor Documentation

◆ FunctionBuilder()

donner::gpu::shader::FunctionBuilder::FunctionBuilder ( FunctionBuilder && other)
noexcept

Move constructor; other becomes an inert moved-from shell.

Parameters
otherBuilder to move from.

Member Function Documentation

◆ addLet()

ShaderResult< IrExpr > donner::gpu::shader::FunctionBuilder::addLet ( const RcString & name,
const IrExpr & value )

Declares let name = value; and returns a reference to it.

Parameters
nameBinding name; must be unique within the function.
valueInitializer.

◆ addVar()

ShaderResult< IrExpr > donner::gpu::shader::FunctionBuilder::addVar ( const RcString & name,
const IrType & type,
const std::optional< IrExpr > & init = std::nullopt )

Declares var name: type (= init); and returns a (mutable) reference to it.

Parameters
nameVariable name; must be unique within the function.
typeDeclared type; must be plain data.
initOptional initializer; must match type.

◆ assign()

ShaderStatus donner::gpu::shader::FunctionBuilder::assign ( const IrExpr & lhs,
const IrExpr & rhs )

Records lhs = rhs;.

lhs must be a mutable lvalue (a var or a member/index/ single-component-swizzle chain rooted at one) and types must match.

Parameters
lhsAssignment target.
rhsValue.

◆ beginFor()

ShaderResult< IrExpr > donner::gpu::shader::FunctionBuilder::beginFor ( const RcString & name,
const IrExpr & init )

Opens for (var name = init; ...) and returns a reference to the loop variable.

Follow with forCondition and forContinuing, then body statements, then endFor.

Parameters
nameLoop variable name; must be unique within the function.
initLoop variable initializer.

◆ beginIf()

ShaderStatus donner::gpu::shader::FunctionBuilder::beginIf ( const IrExpr & condition)

Opens if (condition) { ... }.

Statements recorded until elseBranch or endIf go to the then-branch.

Parameters
conditionBool condition.

◆ callFunction()

ShaderResult< IrExpr > donner::gpu::shader::FunctionBuilder::callFunction ( const RcString & name,
std::vector< IrExpr > args )

Calls a previously finished module function.

Parameters
nameCallee name.
argsArguments; must match the callee's parameter types.

◆ forCondition()

ShaderStatus donner::gpu::shader::FunctionBuilder::forCondition ( const IrExpr & condition)

Sets the condition of the innermost open for.

Parameters
conditionBool condition.

◆ forContinuing()

ShaderStatus donner::gpu::shader::FunctionBuilder::forContinuing ( const IrExpr & lhs,
const IrExpr & rhs )

Sets the continuing assignment of the innermost open for.

The update expression may reference the loop variable and enclosing scope only, never body-block locals: this builder models for (init; cond; update) where the body block closes before the update runs, unlike a raw WGSL loop/continuing where the continuing block is nested inside the body scope.

Parameters
lhsContinuing assignment target (normally the loop variable).
rhsContinuing assignment value.

◆ ref()

ShaderResult< IrExpr > donner::gpu::shader::FunctionBuilder::ref ( const RcString & name) const

Resolves name to a reference expression: function parameters, lets, vars, then module-scope constants and resource bindings.

Parameters
nameName to resolve.

◆ returnOutputs()

ShaderStatus donner::gpu::shader::FunctionBuilder::returnOutputs ( std::vector< IrExpr > outputs)

Records the entry point return: one expression per declared output member, in order.

Parameters
outputsOutput values matching the entry point's output member types.

◆ returnValue()

ShaderStatus donner::gpu::shader::FunctionBuilder::returnValue ( const IrExpr & value)

Records return expr; for a plain function with a return type.

Parameters
valueReturn value; must match the declared return type.

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