-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement the select
HLSL Function
#75377
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
Comments
select
intrinsicselect
HLSL Function
looking at this |
Implement support for HLSL intrinsic select. This would close issue #75377
@llvm/issue-subscribers-clang-codegen Author: Chris B (llvm-beanz)
HLSL 2021 introduced the `select` intrinsic as a replacement for the ternary operator on vector types.
The template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
vector<T, Sz> Result;
for (int I = 0; I < Sz; ++I) {
if (Conds[I])
Result[I] = TrueVals[I];
else
Result[I] = FalseVals[I];
}
return Result;
}
template<typename T>
void select(bool Cond, T TrueVal, T FalseVal) {
if (T)
return TrueVal;
return FalseVal;
} The vector case can lower to a shufflevector mask: template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
vector<int, Sz> Mask;
for (int I = 0; I < Sz; ++I) {
Mask[I] = I;
if (!Conds[I])
Mask[I] += Sz;
}
return __builtin_shufflevector(TrueVals, FalseVals, Mask);
} Acceptance Criteria
DirectXThere were no DXIL opcodes found for SPIR-VOpSelect:Description:Select between two objects. Before version 1.4, results are only Before version 1.4, Result Type must be a pointer, scalar, or The types of Object 1 and Object 2 must be the same as Result Condition must be a scalar or vector of Boolean type. If Condition is a scalar and true, the result is Object 1. If If Condition is a vector, Result Type must be a vector with the same <table style="width:100%;"> Test Case(s)Example 1//dxc select_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
export float4 fn(bool4 p1, float4 p2, float4 p3) {
return select(p1, p2, p3);
} Example 2//dxc select_1_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
export float4 fn(bool p1, float4 p2, float4 p3) {
return select(p1, p2, p3);
} HLSL:Syntaxany<> select(bool<> cond, any<> t, any<> f); any_sampler select(bool cond, any_sampler t, any_sampler f); Type Description
Type Description
Minimum Shader ModelThis function is supported in the following shader models.
Shader StagesRemarksIn HLSL 2021 int3 X = {1, 1, 1};
int3 Z = X ? 1 : 0; See also |
@llvm/issue-subscribers-clang-frontend Author: Chris B (llvm-beanz)
HLSL 2021 introduced the `select` intrinsic as a replacement for the ternary operator on vector types.
The template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
vector<T, Sz> Result;
for (int I = 0; I < Sz; ++I) {
if (Conds[I])
Result[I] = TrueVals[I];
else
Result[I] = FalseVals[I];
}
return Result;
}
template<typename T>
void select(bool Cond, T TrueVal, T FalseVal) {
if (T)
return TrueVal;
return FalseVal;
} The vector case can lower to a shufflevector mask: template<typename T, int Sz>
void select(vector<bool, Sz> Conds, vector<T, Sz> TrueVals, vector<T, Sz> FalseVals) {
vector<int, Sz> Mask;
for (int I = 0; I < Sz; ++I) {
Mask[I] = I;
if (!Conds[I])
Mask[I] += Sz;
}
return __builtin_shufflevector(TrueVals, FalseVals, Mask);
} Acceptance Criteria
DirectXThere were no DXIL opcodes found for SPIR-VOpSelect:Description:Select between two objects. Before version 1.4, results are only Before version 1.4, Result Type must be a pointer, scalar, or The types of Object 1 and Object 2 must be the same as Result Condition must be a scalar or vector of Boolean type. If Condition is a scalar and true, the result is Object 1. If If Condition is a vector, Result Type must be a vector with the same <table style="width:100%;"> Test Case(s)Example 1//dxc select_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
export float4 fn(bool4 p1, float4 p2, float4 p3) {
return select(p1, p2, p3);
} Example 2//dxc select_1_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
export float4 fn(bool p1, float4 p2, float4 p3) {
return select(p1, p2, p3);
} HLSL:Syntaxany<> select(bool<> cond, any<> t, any<> f); any_sampler select(bool cond, any_sampler t, any_sampler f); Type Description
Type Description
Minimum Shader ModelThis function is supported in the following shader models.
Shader StagesRemarksIn HLSL 2021 int3 X = {1, 1, 1};
int3 Z = X ? 1 : 0; See also |
HLSL 2021 introduced the
select
intrinsic as a replacement for the ternary operator on vector types.The
select
intrinsic has the following approximate forms:The vector case can lower to a shufflevector mask:
Acceptance Criteria
Implementation of the select intrinsic in the HLSL builtin headers and corresponding lowering to LLVM IR with appropriate test coverage.
select
clang builtin,select
clang builtin withhlsl_intrinsics.h
select
toCheckHLSLBuiltinFunctionCall
inSemaChecking.cpp
select
toEmitHLSLBuiltinExpr
inCGBuiltin.cpp
clang/test/CodeGenHLSL/builtins/select.hlsl
clang/test/SemaHLSL/BuiltIns/select-errors.hlsl
int_spv_select
intrinsic inIntrinsicsSPIRV.td
select
lowering and map it toint_spv_select
inSPIRVInstructionSelector::selectIntrinsic
.llvm/test/CodeGen/SPIRV/hlsl-intrinsics/select.ll
DirectX
There were no DXIL opcodes found for
select
.SPIR-V
OpSelect:
Description:
Select between two objects. Before version 1.4, results are only
computed per component.
Before version 1.4, Result Type must be a pointer, scalar, or
vector. Starting with version 1.4, Result Type can additionally be
a composite type other than a vector.
The types of Object 1 and Object 2 must be the same as Result
Type.
Condition must be a scalar or vector of Boolean type.
If Condition is a scalar and true, the result is Object 1. If
Condition is a scalar and false, the result is Object 2.
If Condition is a vector, Result Type must be a vector with the same
number of components as Condition and the result is a mix of Object
1 and Object 2: If a component of Condition is true, the
corresponding component in the result is taken from Object 1,
otherwise it is taken from Object 2.
6
169
<id>
Result Type
Result <id>
<id>
Condition
<id>
Object 1
<id>
Object 2
Test Case(s)
Example 1
Example 2
HLSL:
Syntax
any<> select(bool<> cond, any<> t, any<> f);
any_sampler select(bool cond, any_sampler t, any_sampler f);
Type Description
Type Description
Minimum Shader Model
This function is supported in the following shader models.
Shader Stages
Remarks
In HLSL 2021
int3 Z = select(X, 1, 0);
is a replacement forSee also
The text was updated successfully, but these errors were encountered: