Skip to content

vkd3d-shader/ir: Transform clip/cull input/outputs into arrays, version 2.

This is a reimplementation of !564 (closed), and supersedes !1506 (closed).

This takes care of translating clip/cull sysvals in the DirectX convention of 2 4-component registers, into the SPIR-V/GLSL convention of 2 8-element arrays.

This allows to avoid a segfault on clip-cull-distance.shader_test on Mesa 25.1.1-arch1.2, and opens the possibility of properly supporting multiple clip/cull system values once these can be handled by the HLSL compiler.

For more information on the current behavior see !1506 (closed).


My original approach to solve this problem was to create indexable temp arrays for every input/output clip/cull combination, and replace all srcs to point to the input indexable temps and dsts to point the the output indexable temps.

This while copying from the new input arrays to the input indexable temps at the beginning of the program after declarations (and the control point phase of hull shaders) and to copy from the output indexable temps to the new output arrays at the end of the program (before ret and emits).

While this worked, it had a considerable complexity since temp arrays have only 1-dimension so they had to be extended to account for control points and extra instructions to perform arithmetic on indexes were needed. Furthermore it failed to account for the theoretical possibility of the control point phase of the hull shader writing to the outputs of other control points, which would have resulted in race conditions.

In the end I came up with this approach that consists on replacing the srcs and dsts to clip/cull signature elements in an instruction with temps. Around the instruction, MOVs are prepended so that every src temp component used is initialized using the new input arrays and MOV instructions are appended so that every dst temp component is copied to the new output arrays. This is considerably simpler.

While I originally intended to split 3/5 into two patches, I can't do it without having some d3d12.c tests fail in the intermediate state.

Merge request reports

Loading