Skip to content

Commit 1e46ec2

Browse files
authored
[0040] Add alternative approach (#812)
This PR documents an alternative approach that came up during discussion where `select` only supports value types and sampler support in DXC is reverted.
1 parent 4eb4e5e commit 1e46ec2

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

proposals/0040-select-type-support.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ implementation to support additional result types beyond scalar, vector, and
1818
matrix 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

2733
While Clang aims to match HLSL intrinsic behaviors to DXC, it wouldn't make much
2834
sense for Clang's `select` implementation to have the same restrictions as
@@ -45,3 +51,20 @@ would not support arrays.*
4551
This proposal does not suggest making similar changes to DXC, as DXC’s ternary
4652
operator intentionally limits its supported types. Clang’s divergence here is
4753
justified 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

Comments
 (0)