-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HLSL 2021] Ternary error with non scalar #4070
Comments
Hi @Mrarnal! This is expected behavior described in this wiki page: https://github.com/microsoft/DirectXShaderCompiler/wiki/HLSL-2021#logical-operation-short-circuiting-for-scalars . The intent is to open up logical short-circuiting for scalar operators not possible with vectors. You can get the pre-2021 behavior using the new float2 PackNormalOct(float3 n) {
n *= rcp(dot(abs(n), 1.0));
float t = saturate(-n.z);
return n.xy + select(n.xy >= 0.0, t, -t);
}
float3 UnpackNormalOct(float2 f) {
float3 n = float3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
float t = max(-n.z, 0.0);
n.xy += select(n.xy >= 0.0, -t , t);
return normalize(n);
} |
Hi @pow2clk |
The information we gathered revealed that, most of the time when vectors were used in logical binary and ternary operators, it was with the expectation of short-circuit behavior. Instead, the result was slow code that executed every possibility. We wanted to enable the short-circuit behavior that authors have come to expect from C++. A big part of the HLSL 2021 plan was to narrow the gap between HLSL and C++. We didn't want the same operators to have such a dramatic difference in behavior based only on the arity of the operands. Also, irritating as it is, we wanted shader authors who were using these operators with vectors expecting short circuit behavior to take notice of the places they were and possibly, instead of converting them to use As a result of this issue and others, we will be adding more information to the error message to make it clearer what the intent is in the future. |
Great, make sense! Thank you for your time! |
While compiling this code, we got this error using the hlsl 2021: condition for short-circuiting ternary operator must be scalar (for the n.xy >= 0.0 ? t : -t)
The text was updated successfully, but these errors were encountered: