|
@@ -600,18 +600,29 @@ Value *TrivialBarrier(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
|
|
Value *TranslateD3DColorToUByte4(CallInst *CI, IntrinsicOp IOP,
|
|
Value *TranslateD3DColorToUByte4(CallInst *CI, IntrinsicOp IOP,
|
|
OP::OpCode opcode,
|
|
OP::OpCode opcode,
|
|
HLOperationLowerHelper &helper, HLObjectOperationLowerHelper *pObjHelper, bool &Translated) {
|
|
HLOperationLowerHelper &helper, HLObjectOperationLowerHelper *pObjHelper, bool &Translated) {
|
|
- hlsl::OP *hlslOP = &helper.hlslOP;
|
|
|
|
IRBuilder<> Builder(CI);
|
|
IRBuilder<> Builder(CI);
|
|
Value *val = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
|
|
Value *val = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
|
|
Type *Ty = val->getType();
|
|
Type *Ty = val->getType();
|
|
|
|
|
|
- Constant *toByteConst = ConstantFP::get(Ty->getScalarType(), 255);
|
|
|
|
- if (Ty != Ty->getScalarType()) {
|
|
|
|
- toByteConst =
|
|
|
|
- ConstantVector::getSplat(Ty->getVectorNumElements(), toByteConst);
|
|
|
|
|
|
+ // Use the same scaling factor used by FXC (i.e., 255.001953)
|
|
|
|
+ // Excerpt from stackoverflow discussion:
|
|
|
|
+ // "Built-in rounding, necessary because of truncation. 0.001953 * 256 = 0.5"
|
|
|
|
+ Constant *toByteConst = ConstantFP::get(Ty->getScalarType(), 255.001953);
|
|
|
|
+
|
|
|
|
+ if (Ty->isVectorTy()) {
|
|
|
|
+ static constexpr int supportedVecElemCount = 4;
|
|
|
|
+ if (Ty->getVectorNumElements() == supportedVecElemCount) {
|
|
|
|
+ toByteConst = ConstantVector::getSplat(supportedVecElemCount, toByteConst);
|
|
|
|
+ // Swizzle the input val -> val.zyxw
|
|
|
|
+ std::vector<int> mask { 2, 1, 0, 3 };
|
|
|
|
+ val = Builder.CreateShuffleVector(val, val, mask);
|
|
|
|
+ } else {
|
|
|
|
+ CI->getContext().emitError(CI, "Unsupported input type for intrinsic D3DColorToUByte4");
|
|
|
|
+ return UndefValue::get(CI->getType());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
Value *byte4 = Builder.CreateFMul(toByteConst, val);
|
|
Value *byte4 = Builder.CreateFMul(toByteConst, val);
|
|
- byte4 = TrivialDxilUnaryOperation(OP::OpCode::Round_ne, byte4, hlslOP, Builder);
|
|
|
|
return Builder.CreateCast(Instruction::CastOps::FPToSI, byte4, CI->getType());
|
|
return Builder.CreateCast(Instruction::CastOps::FPToSI, byte4, CI->getType());
|
|
}
|
|
}
|
|
|
|
|