SPIRV-Cross/reference
comex c80cbde7aa spirv_msl: Don't add fixup hooks for builtin variables if they're unused.
This is necessary to avoid invalid output because of how implicit
dependencies on builtins work.

For example, the fixup for `BuiltInSubgroupEqMask` initializes the
variable based on `builtin_subgroup_invocation_id_id`, a field storing
the ID for a variable with decoration `BuiltInSubgroupLocalInvocationId`.
This could be either a variable that already exists in the input
(spirv_msl.cpp:300) or, if necessary, a newly created one
(spirv_msl.cpp:621).  In both cases, though,
`builtin_subgroup_invocation_id_id` is only set under the condition
`need_subgroup_mask || needs_subgroup_invocation_id`.
`need_subgroup_mask` is true if any of the `BuiltInSubgroupXXMask` are
set in `active_input_builtins`.

Normally, if the program contains `BuiltInSubgroupEqMask`,
`Compiler::ActiveBuiltinHandler` will set it in `active_input_builtins`.
But this only happens if the variable is actually used, whereas
`fix_up_shader_inputs_outputs` loops over all variables in the program
regardless of whether they're used.

If `BuiltInSubgroupEqMask` is not used,
`builtin_subgroup_invocation_id_id` is never set, but before this patch
the fixup hook would try to use it anyway, producing MSL that references
a nonexistent variable named `_0`.

Avoid this by changing `fix_up_shader_inputs_outputs` to skip builtins
which are not set in `active_input_builtins` or
`active_output_builtins`.  And add a test case.
2020-11-25 13:41:12 -05:00
..
opt MSL: Adjust FragCoord for sample-rate shading. 2020-11-23 10:30:24 -06:00
shaders GLSL: Emit storage qualifiers for buffer_reference. 2020-11-23 16:26:33 +01:00
shaders-hlsl Normalize all internal workaround methods to use spv prefix. 2020-11-23 15:42:27 +01:00
shaders-hlsl-no-opt HLSL: Fix validation with FXC for test. 2020-11-23 16:03:35 +01:00
shaders-msl MSL: Adjust FragCoord for sample-rate shading. 2020-11-23 10:30:24 -06:00
shaders-msl-no-opt spirv_msl: Don't add fixup hooks for builtin variables if they're unused. 2020-11-25 13:41:12 -05:00
shaders-no-opt GLSL: Fix buffer_reference with aliased names. 2020-11-23 16:36:49 +01:00
shaders-reflection Parser: Don't assume OpTypePointer will always take a SPIRType. 2020-11-03 10:53:37 +01:00
shaders-ue4/asm MSL: Adjust FragCoord for sample-rate shading. 2020-11-23 10:30:24 -06:00
shaders-ue4-no-opt/asm Implement context-sensitive expression read tracking. 2020-06-29 12:20:35 +02:00