[spirv] fix vector size 1 argument bug of seturate() (#2228)

Fixes #2223
This commit is contained in:
Jaebaek Seo 2019-06-04 17:49:46 -04:00 коммит произвёл Ehsan
Родитель 9d31464b57
Коммит b61633ad00
2 изменённых файлов: 17 добавлений и 5 удалений

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

@ -8736,16 +8736,16 @@ SpirvEmitter::processIntrinsicSaturate(const CallExpr *callExpr) {
const QualType returnType = callExpr->getType();
auto *glslInstSet = spvBuilder.getGLSLExtInstSet();
if (argType->isFloatingType()) {
auto *floatZero = getValueZero(argType);
auto *floatOne = getValueOne(argType);
QualType elemType = {};
uint32_t vecSize = 0;
if (isScalarType(argType, &elemType)) {
auto *floatZero = getValueZero(elemType);
auto *floatOne = getValueOne(elemType);
return spvBuilder.createExtInst(returnType, glslInstSet,
GLSLstd450::GLSLstd450FClamp,
{argId, floatZero, floatOne}, loc);
}
QualType elemType = {};
uint32_t vecSize = 0;
if (isVectorType(argType, &elemType, &vecSize)) {
auto *vecZero = getVecValueZero(elemType, vecSize);
auto *vecOne = getVecValueOne(elemType, vecSize);

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

@ -10,6 +10,8 @@ void main() {
float a, sata;
float4 b, satb;
float2x3 c, satc;
float1 d;
float1x1 e;
// CHECK: [[a:%\d+]] = OpLoad %float %a
// CHECK-NEXT: [[sata:%\d+]] = OpExtInst %float [[glsl]] FClamp [[a]] %float_0 %float_1
@ -29,4 +31,14 @@ void main() {
// CHECK-NEXT: [[satc:%\d+]] = OpCompositeConstruct %mat2v3float [[sat0]] [[sat1]]
// CHECK-NEXT: OpStore %satc [[satc]]
satc = saturate(c);
// CHECK: [[d:%\d+]] = OpLoad %float %d
// CHECK-NEXT: [[a:%\d+]] = OpExtInst %float [[glsl]] FClamp [[d]] %float_0 %float_1
// CHECK-NEXT: OpStore %a [[a]]
a = saturate(d);
// CHECK: [[e:%\d+]] = OpLoad %float %e
// CHECK-NEXT: [[a:%\d+]] = OpExtInst %float [[glsl]] FClamp [[e]] %float_0 %float_1
// CHECK-NEXT: OpStore %a [[a]]
a = saturate(e);
}