@@ -7957,6 +7957,7 @@ Value *SPIRVToLLVM::transGLSLExtInst(SPIRVExtInst *extInst, BasicBlock *bb) {
79577957
79587958 case GLSLstd450PackSnorm4x8: {
79597959 // Convert <4 x float> into signed normalized <4 x i8> then pack into i32.
7960+ // round(clamp(c, -1, +1) * 127.0)
79607961 Value *val = getBuilder ()->CreateFClamp (args[0 ], ConstantFP::get (args[0 ]->getType (), -1.0 ),
79617962 ConstantFP::get (args[0 ]->getType (), 1.0 ));
79627963 val = getBuilder ()->CreateFMul (val, ConstantFP::get (args[0 ]->getType (), 127.0 ));
@@ -7967,28 +7968,33 @@ Value *SPIRVToLLVM::transGLSLExtInst(SPIRVExtInst *extInst, BasicBlock *bb) {
79677968
79687969 case GLSLstd450PackUnorm4x8: {
79697970 // Convert <4 x float> into unsigned normalized <4 x i8> then pack into i32.
7971+ // round(clamp(c, 0, +1) * 255.0)
79707972 Value *val = getBuilder ()->CreateFClamp (args[0 ], Constant::getNullValue (args[0 ]->getType ()),
79717973 ConstantFP::get (args[0 ]->getType (), 1.0 ));
79727974 val = getBuilder ()->CreateFMul (val, ConstantFP::get (args[0 ]->getType (), 255.0 ));
7975+ val = getBuilder ()->CreateUnaryIntrinsic (Intrinsic::rint, val);
79737976 val = getBuilder ()->CreateFPToUI (val, FixedVectorType::get (getBuilder ()->getInt8Ty (), 4 ));
79747977 return getBuilder ()->CreateBitCast (val, getBuilder ()->getInt32Ty ());
79757978 }
79767979
79777980 case GLSLstd450PackSnorm2x16: {
79787981 // Convert <2 x float> into signed normalized <2 x i16> then pack into i32.
7982+ // round(clamp(c, -1, +1) * 32767.0)
79797983 Value *val = getBuilder ()->CreateFClamp (args[0 ], ConstantFP::get (args[0 ]->getType (), -1.0 ),
79807984 ConstantFP::get (args[0 ]->getType (), 1.0 ));
79817985 val = getBuilder ()->CreateFMul (val, ConstantFP::get (args[0 ]->getType (), 32767.0 ));
7986+ val = getBuilder ()->CreateUnaryIntrinsic (Intrinsic::rint, val);
79827987 val = getBuilder ()->CreateFPToSI (val, FixedVectorType::get (getBuilder ()->getInt16Ty (), 2 ));
79837988 return getBuilder ()->CreateBitCast (val, getBuilder ()->getInt32Ty ());
79847989 }
79857990
79867991 case GLSLstd450PackUnorm2x16: {
7987- // Convert <2 x float> into unsigned normalized <2 x i16> then pack into
7988- // i32.
7992+ // Convert <2 x float> into unsigned normalized <2 x i16> then pack into i32.
7993+ // round(clamp(c, 0, +1) * 65535.0)
79897994 Value *val = getBuilder ()->CreateFClamp (args[0 ], Constant::getNullValue (args[0 ]->getType ()),
79907995 ConstantFP::get (args[0 ]->getType (), 1.0 ));
79917996 val = getBuilder ()->CreateFMul (val, ConstantFP::get (args[0 ]->getType (), 65535.0 ));
7997+ val = getBuilder ()->CreateUnaryIntrinsic (Intrinsic::rint, val);
79927998 val = getBuilder ()->CreateFPToUI (val, FixedVectorType::get (getBuilder ()->getInt16Ty (), 2 ));
79937999 return getBuilder ()->CreateBitCast (val, getBuilder ()->getInt32Ty ());
79948000 }
0 commit comments