diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp index 4819a28cf..013969bbb 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp @@ -39,18 +39,25 @@ void DrawTriangleCodegen::Generate(TriDrawVariant variant, bool truecolor, SSAVa LoopBlockY(variant, truecolor); } +SSAInt DrawTriangleCodegen::FloatTo28_4(SSAFloat v) +{ + // SSAInt(SSAFloat::round(16.0f * v), false); + SSAInt a = SSAInt(v * 32.0f, false); + return (a + (a.ashr(31) | SSAInt(1))).ashr(1); +} + void DrawTriangleCodegen::Setup(TriDrawVariant variant, bool truecolor) { int pixelsize = truecolor ? 4 : 1; // 28.4 fixed-point coordinates - Y1 = SSAInt(SSAFloat::round(16.0f * v1.y), false); - Y2 = SSAInt(SSAFloat::round(16.0f * v2.y), false); - Y3 = SSAInt(SSAFloat::round(16.0f * v3.y), false); + Y1 = FloatTo28_4(v1.y); + Y2 = FloatTo28_4(v2.y); + Y3 = FloatTo28_4(v3.y); - X1 = SSAInt(SSAFloat::round(16.0f * v1.x), false); - X2 = SSAInt(SSAFloat::round(16.0f * v2.x), false); - X3 = SSAInt(SSAFloat::round(16.0f * v3.x), false); + X1 = FloatTo28_4(v1.x); + X2 = FloatTo28_4(v2.x); + X3 = FloatTo28_4(v3.x); // Deltas DX12 = X1 - X2; diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.h b/src/r_compiler/fixedfunction/drawtrianglecodegen.h index 6f9a6c32a..eba1caf4f 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.h +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.h @@ -40,6 +40,7 @@ private: SSATriVertex LoadTriVertex(SSAValue v); void LoadUniforms(SSAValue uniforms); void Setup(TriDrawVariant variant, bool truecolor); + SSAInt FloatTo28_4(SSAFloat v); void LoopBlockY(TriDrawVariant variant, bool truecolor); void LoopBlockX(TriDrawVariant variant, bool truecolor); void LoopFullBlock(TriDrawVariant variant, bool truecolor); diff --git a/src/r_compiler/ssa/ssa_float.cpp b/src/r_compiler/ssa/ssa_float.cpp index 77cef29ff..a45bee613 100644 --- a/src/r_compiler/ssa/ssa_float.cpp +++ b/src/r_compiler/ssa/ssa_float.cpp @@ -112,12 +112,15 @@ SSAFloat SSAFloat::fma(SSAFloat a, SSAFloat b, SSAFloat c) return SSAFloat::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::fma, params), args, SSAScope::hint())); } +/* This intrinsic isn't always available.. SSAFloat SSAFloat::round(SSAFloat val) { + std::vector params; params.push_back(SSAFloat::llvm_type()); return SSAFloat::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::round, params), val.v, SSAScope::hint())); } +*/ SSAFloat SSAFloat::floor(SSAFloat val) { diff --git a/src/r_compiler/ssa/ssa_float.h b/src/r_compiler/ssa/ssa_float.h index 9386db017..69fb81a75 100644 --- a/src/r_compiler/ssa/ssa_float.h +++ b/src/r_compiler/ssa/ssa_float.h @@ -43,7 +43,7 @@ public: static SSAFloat exp(SSAFloat val); static SSAFloat log(SSAFloat val); static SSAFloat fma(SSAFloat a, SSAFloat b, SSAFloat c); - static SSAFloat round(SSAFloat val); + //static SSAFloat round(SSAFloat val); static SSAFloat floor(SSAFloat val); static SSAFloat MIN(SSAFloat a, SSAFloat b); static SSAFloat MAX(SSAFloat a, SSAFloat b);