[SPIRV] Do not ignore RValue cast for vertex id in GetAttributeAtVertex (#6263)

We are able to pass a variable as the index to GetAttributeAtVertex, but
only if it is signed. If the value is unsigned, no cast is needed, and
the current code will skip the LValueToRValue cast. This causes the
load to be skipped generating invalid code.
This commit is contained in:
Steven Perron 2024-02-12 10:10:51 -05:00 коммит произвёл GitHub
Родитель cadf3bfed1
Коммит 2872d2d0e7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -12133,7 +12133,7 @@ SpirvEmitter::processGetAttributeAtVertex(const CallExpr *expr) {
const auto exprRange = expr->getSourceRange();
// arg1 : vertexId
auto *arg1BaseExpr = doExpr(expr->getArg(1)->IgnoreParenLValueCasts());
auto *arg1BaseExpr = doExpr(expr->getArg(1));
// arg0 : <NoInterpolation> decorated input
// Tip : for input with boolean type, we need to ignore implicit cast first,

Просмотреть файл

@ -2,14 +2,21 @@
struct PSInput {
int idx: INPUT0;
uint uidx: INPUT1;
nointerpolation float4 fp_h: FPH;
};
float4 main(PSInput input) : SV_Target {
// CHECK: [[idx:%[0-9]+]] = OpLoad %int %in_var_INPUT0
// CHECK: [[bc:%[0-9]+]] = OpBitcast %uint [[idx]]
// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Input_v4float %in_var_FPH [[bc]]
// CHECK: [[ld:%[0-9]+]] = OpLoad %v4float [[ac]]
// CHECK: OpStore %out_var_SV_Target [[ld]]
return GetAttributeAtVertex(input.fp_h, input.idx);
// CHECK: [[idx:%[0-9]+]] = OpLoad %int %in_var_INPUT0
// CHECK: [[uidx:%[0-9]+]] = OpLoad %uint %in_var_INPUT1
// CHECK: [[bc:%[0-9]+]] = OpBitcast %uint [[idx]]
// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Input_v4float %in_var_FPH [[bc]]
// CHECK: [[a:%[0-9]+]] = OpLoad %v4float [[ac]]
// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Input_v4float %in_var_FPH %21
// CHECK: [[b:%[0-9]+]] = OpLoad %v4float %25
// CHECK: [[add:%[0-9]+]] = OpFAdd %v4float [[a]] [[b]]
// CHECK: OpStore %out_var_SV_Target [[add]]
float4 a = GetAttributeAtVertex(input.fp_h, input.idx);
float4 b = GetAttributeAtVertex(input.fp_h, input.uidx);
return a+b;
}