gfx-rs/wgpu

Backends should not need two passes to handle wrapped functions

Open

#7,106 建立於 2025年2月11日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Rust (9,290 star) (703 fork)batch import
area: naga back-endgood first issuekind: refactorlang: HLSLlang: Metallang: SPIR-Vnaga

描述

Once #7012 lands, Naga's Metal Shading Language, HLSL, and SPIR-V backends will make a prepass over each function's expressions to see which wrapped functions it will need, and then generate their definitions before the function's own translation. This means that both the prepass and the actual code generation need to repeat the logic for deciding which expressions need wrapped functions.

Instead, we should generate output for the Module's functions, and note which wrapped functions we needed by adding them to the backend's wrapped_functions table. Then, after all the Module's functions have been translated, we should simply iterate over the wrapped_functions table and generate the definitions we need.

Since MSL and HLSL require the wrapped function definitions to precede their uses, in those backends the two stages should write to separate Strings, which the backend should concatenate as a final step. Those copies should be pretty cheap. SPIR-V allows OpFunctionCall to refer to functions defined later, so in that case no reordering is necessary.

貢獻者指南

Backends should not need two passes to handle wrapped functions · gfx-rs/wgpu#7106 | Good First Issue