-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Naga IR should be changed to eliminate the need to bake expressions.
Baked expressions are a Naga-specific piece of ugly magic: subexpressions that we identify as needing to be evaluated in isolation, not as part of the Statement that actually refers to them. Baking an expression means that it's emitted as an initialized temporary variable. References to the expression are then rendered as uses of that variable.
Examples would be Load expressions, which need to be ordered properly with respect to Call statements that could assign to the variables they read. But it also includes stuff like the operands of MathFunction::Dot applications on Metal, which open-codes the dot product operation, and wants its operands to be cached in locals in advance to avoid repeated evaluation.
We flag expressions for baking pessimistically. For example, most Load
s do not need to be separated out from the rest of the expression, but we produce (in WGSL output) a separate let
declaration for every load. For the GLSL input:
vec4 color = Color;
we generate the WGSL:
let _e4 = global.Color;
color = _e4;
That _e4
temporary is the result of baking.
The semantics of Naga IR should be such that backends don't need to filter through the expressions covered by an Emit
and play strange games with reference count thresholds to decide what to generate.
A better approach would not only simplify Emit
statement processing in backends, but also accommodate backend-specific needs like inlined Dot
calls (or the broad selection of functions in the HLSL backend).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status