Backends should not need two passes to handle wrapped functions #7106
Labels
area: naga back-end
Outputs of naga shader conversion
good first issue
Good for newcomers
kind: refactor
Making existing function faster or nicer
lang: HLSL
D3D Shading Language
lang: Metal
Metal Shading Language
lang: SPIR-V
Vulkan's Shading Language
naga
Shader Translator
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'swrapped_functions
table. Then, after all theModule
's functions have been translated, we should simply iterate over thewrapped_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
String
s, which the backend should concatenate as a final step. Those copies should be pretty cheap. SPIR-V allowsOpFunctionCall
to refer to functions defined later, so in that case no reordering is necessary.The text was updated successfully, but these errors were encountered: