KhronosGroup / KhronosGroup/SPIRV-Tools
Handle an exception case of interface-variable-scalar-replacement spirv-opt pass
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 709
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
We recently added the interface variable SROA (PR #4779 ).
The `interface-variable-scalar-replacement` pass fails with the input SPIR-V [spv_with_error.txt](https://github.com/KhronosGroup/SPIRV-Tools/files/8654315/spv_with_error.txt).
See the stack trace [bt.txt](https://github.com/KhronosGroup/SPIRV-Tools/files/8654335/bt.txt) from GDB.
`InterfaceVariableScalarReplacement::CreateAccessChainToVar(..)` [method](https://github.com/KhronosGroup/SPIRV-Tools/blob/ad3514b73237beb75a780ee8922e48798266b98f/source/opt/interface_var_sroa.cpp#L463
) tries to create an access chain to the scalar variable to replace the access chain user of the interface variable:
```
// Before
%z = OpVariable %_ptr_Output__arr_uint_uint_2 Output
...
%z1_ptr = OpAccessChain %_ptr_Output_uint %z %uint_1
OpStore %z1_ptr %w1
// After
%z0 = OpVariable %_ptr_Output__uint Output
%z1 = OpVariable %_ptr_Output__uint Output
...
%ptr0 = OpAccessChain .. %z0 ..
OpStore %ptr0 ..
%ptr1 = OpAccessChain .. %z1 ..
OpStore %ptr1 ..
```
However, `%z0` is not an aggregate type, so we must not create an access chain. Instead, we have to choose one of the scalar variables i.e., `%z0` or `%z1` for `%z1_ptr = OpAccessChain %_ptr_Output_uint %z %uint_1`.
Contributor guide
Assessment
This issue has not been assessed yet.