Expand description
Pass: bool RHS in f32 context β select(0.0, 1.0, cond).
FunctionsΒ§
- bool_
shape_ πselect_ literals - Pick the
(zero, one)literals for aselect(0.0/vecN, β¦)wrap based on the shape of the bool-producing expression. A scalar comparison (e.g.rs.z > 0) keeps the scalar0.0/1.0; a vector comparison (e.g.noise >= 0.1) needsvecN<f32>(0.0)/vecN<f32>(1.0)so the resultingselect(...)typechecks under WGSLβs strict-shape rules. - decl_
target_ πfloat_ kind - Maps an HLSL declarationβs textual type to the WGSL type the
downstream
replace_typespass will produce β for the purpose of deciding whether the RHS should be bool-coerced. Treatsint,half,doubleand their vector siblings as float-kind, mirroring the substitution rules incrate::replace_types. - infer_
bool_ πshape - Walks the bool-producing subtree and returns the inferred vector
shape of the underlying values being compared. Returns
F32for scalar bool (so the caller emits scalar literals),VecNfor vector bool,Unknownwhen nothing can be inferred (caller falls back to scalar β which matches the conservative pre-AA behaviour). - is_
arith_ πop - is_
boolean_ πproducing - True when the top-level operator of
eis one that produces a bool value in WGSL (comparison, short-circuit boolean, or a swizzle over one). We followSwizzleso that(vec >= 0).xyzreaches this function during avec3assignment and the bool-vec3 result still gets theselect(...)wrap. - is_
chained_ πcomparison - is_
float_ πkind - looks_
like_ πwgsl_ generic - rewrite_
bool_ πto_ float - HLSL coerces bool β float silently (
float mask = uv.x > 0.5;yields 0.0/1.0). WGSL refuses withthe type of 'mask' is expected to be 'f32'; but got 'bool'(orcannot convert elements of vec3<bool> to f32for vector comparisons). One of the largest comp failure clusters in the corpus. - try_
wrap_ πbool_ arith_ operand - Emit a
select(0.0, 1.0, (<expr>))zero-length-insertion wrap aroundeif its top-level operator is a boolean producer. Mirrorstry_wrap_bool_rhsbut is called from arithmetic context, and also emits the vector-shape formselect(vec3<f32>(0.0), vec3<f32>(1.0), (vec_cmp))when the boolβs operands are vector-typed, since WGSLselect(scalar, scalar, vecN<bool>)is invalid. - try_
wrap_ πbool_ rhs - If
rhsis a comparison / boolean operator andtarget_tyis a numeric float type, emit two zero-length edits to wrap the RHS inselect(<zero>, <one>, <rhs>). Zero-length insertions donβt collide with inner edits emitted by other passes. - walk_
block_ πfor_ bool - walk_
expr_ πfor_ bool - Top-level walk for nested sub-statements; the bool-wrap heuristic only fires on the RHS of an assignment / decl, so this just recurses without emitting edits of its own.
- walk_
expr_ πfor_ bool_ arith - Walk an expression that lives in arithmetic context (the RHS of a
decl/assign, an
*=RHS, a*/+/-//sub-tree). For everyBinarywhose operator expects numeric operands, wrap any bool-producing child (comparison or short-circuit) inselect(0.0, 1.0, β¦). Targets a dominant validate-stage failure (InvalidBinaryOperandTypes), exemplified by the MD2 gating idiomvalue * (rs.z > 0) * (rs.z < hlim). - walk_
stmt_ πfor_ bool