Module bool_arith

Module bool_arith 

Source
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 a select(0.0/vecN, …) wrap based on the shape of the bool-producing expression. A scalar comparison (e.g. rs.z > 0) keeps the scalar 0.0/1.0; a vector comparison (e.g. noise >= 0.1) needs vecN<f32>(0.0)/vecN<f32>(1.0) so the resulting select(...) 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_types pass will produce β€” for the purpose of deciding whether the RHS should be bool-coerced. Treats int, half, double and their vector siblings as float-kind, mirroring the substitution rules in crate::replace_types.
infer_bool_shape πŸ”’
Walks the bool-producing subtree and returns the inferred vector shape of the underlying values being compared. Returns F32 for scalar bool (so the caller emits scalar literals), VecN for vector bool, Unknown when 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 e is one that produces a bool value in WGSL (comparison, short-circuit boolean, or a swizzle over one). We follow Swizzle so that (vec >= 0).xyz reaches this function during a vec3 assignment and the bool-vec3 result still gets the select(...) 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 with the type of 'mask' is expected to be 'f32'; but got 'bool' (or cannot convert elements of vec3<bool> to f32 for 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 around e if its top-level operator is a boolean producer. Mirrors try_wrap_bool_rhs but is called from arithmetic context, and also emits the vector-shape form select(vec3<f32>(0.0), vec3<f32>(1.0), (vec_cmp)) when the bool’s operands are vector-typed, since WGSL select(scalar, scalar, vecN<bool>) is invalid.
try_wrap_bool_rhs πŸ”’
If rhs is a comparison / boolean operator and target_ty is a numeric float type, emit two zero-length edits to wrap the RHS in select(<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 every Binary whose operator expects numeric operands, wrap any bool-producing child (comparison or short-circuit) in select(0.0, 1.0, …). Targets a dominant validate-stage failure (InvalidBinaryOperandTypes), exemplified by the MD2 gating idiom value * (rs.z > 0) * (rs.z < hlim).
walk_stmt_for_bool πŸ”’