@@ -18,11 +18,17 @@ implementation to support additional result types beyond scalar, vector, and
1818matrix types (e.g. structs).
1919
2020## Motivation
21- The ` select ` intrinsic was introduced in HLSL 2021 to replace the
22- non-short-circuiting vector ternary operators that existed in earlier versions
23- of HLSL. In DXC, this pre-HLSL-2021 ternary operator only supported scalar,
24- vector, matrix, and SamplerState result types. DXC’s ` select ` implementation
25- mirrors these restrictions.
21+ The ` select ` intrinsic was introduced in HLSL 2021 to preserve the
22+ non-short-circuiting behavior of pre-HLSL-2021 ternary operators, where both
23+ sides are evaluated regardless of the condition. Its primary use is supporting
24+ vector selection of components.
25+
26+ In DXC, the pre-HLSL-2021 ternary operator supported value types (scalar,
27+ vector, and matrix) as well as some other arbitrary types (namely SamplerState).
28+ DXC's ` select ` implementation was initially restricted to value types only;
29+ sampler support was [ added
30+ later] ( https://github.com/microsoft/DirectXShaderCompiler/pull/5508 ) due to user
31+ requests, but support for other types was not.
2632
2733While Clang aims to match HLSL intrinsic behaviors to DXC, it wouldn't make much
2834sense for Clang's ` select ` implementation to have the same restrictions as
@@ -45,3 +51,20 @@ would not support arrays.*
4551This proposal does not suggest making similar changes to DXC, as DXC’s ternary
4652operator intentionally limits its supported types. Clang’s divergence here is
4753justified by its alignment with C++ semantics.
54+
55+ ## Alternatives considered
56+ An alternative approach would be to restrict Clang's ` select ` to value types
57+ only, rather than supporting more general types. Since ` select ` 's main purpose
58+ was to support vector selection of components, extending it to other types (like
59+ resources) doesn't align with its original intent. Allowing the scalar
60+ degenerate case to accept arbitrary types could also enable code that should
61+ otherwise be illegal.
62+
63+ Under this approach, the manually added sampler support in DXC should be
64+ reverted for consistency. Users who rely on ` select ` with SamplerState should
65+ use the ternary operator instead.
66+
67+ Regardless of which approach is chosen, Clang's ` select ` should not mirror DXC's
68+ current behavior of supporting only value types with a special case for
69+ samplers. Clang should either support more general types (as proposed) or
70+ restrict to value types only (this alternative).
0 commit comments