collect_global_var_types

Function collect_global_var_types 

Source
pub(crate) fn collect_global_var_types(hlsl: &str) -> HashMap<String, String>
Expand description

Re-parse hlsl (the original input, before any rewriter touched it) and return a map of name → wgsl_type for top-level Item::GlobalVar items. Used by hoist_global_vars to decide which body-level var declarations belong at module scope.

Skips any name that collides with a WGSL builtin function. A few MD2 authors declare locals named sin / cos / pow / dot etc. (the Isosceles preset’s kaleidoscope state line) — hoisting these to module scope as var<private> would shadow the builtin globally, breaking every other site that calls sin(x) as a function. Leaving them as fs_main locals preserves the per-scope shadowing the author expected.

Returned types are in WGSL form (vec2<f32>, mat3x3<f32>, …) so the hoist pass can compare them against the in-body var X: T lines and only transform exact-type matches — re-declarations like float2 rss,uv2; at top level followed by float3 uv2 = …; in shader_body are shadowing the global and must keep their local declaration intact.