aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw/draw_pipe_offset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_pipe_offset.c')
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_offset.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_offset.c b/src/gallium/auxiliary/draw/draw_pipe_offset.c
index 3578525051f..8071bc77b80 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_offset.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_offset.c
@@ -32,6 +32,7 @@
* \author Brian Paul
*/
+#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "draw_pipe.h"
@@ -89,7 +90,22 @@ static void do_offset_tri( struct draw_stage *stage,
float dzdx = fabsf(a * inv_det);
float dzdy = fabsf(b * inv_det);
- float zoffset = offset->units + MAX2(dzdx, dzdy) * offset->scale;
+ float zoffset, maxz, bias, mult;
+
+ mult = MAX2(dzdx, dzdy) * offset->scale;
+
+ if (stage->draw->floating_point_depth) {
+ maxz = MAX3(v0[2], v1[2], v2[2]);
+
+ /**
+ * XXX: TODO optimize this to quickly resolve a pow2 number through
+ * an exponent only operation.
+ */
+ bias = offset->units * util_fast_exp2(util_get_float32_exponent(maxz) - 23);
+ zoffset = bias + mult;
+ } else {
+ zoffset = offset->units + mult;
+ }
if (offset->clamp)
zoffset = (offset->clamp < 0.0f) ? MAX2(zoffset, offset->clamp) :
@@ -157,7 +173,17 @@ static void offset_first_tri( struct draw_stage *stage,
if (do_offset) {
offset->scale = rast->offset_scale;
offset->clamp = rast->offset_clamp;
- offset->units = (float) (rast->offset_units * stage->draw->mrd);
+
+ /*
+ * If depth is floating point, depth bias is calculated with respect
+ * to the primitive's maximum Z value. Retain the original depth bias
+ * value until that stage.
+ */
+ if (stage->draw->floating_point_depth) {
+ offset->units = (float) rast->offset_units;
+ } else {
+ offset->units = (float) (rast->offset_units * stage->draw->mrd);
+ }
}
else {
offset->scale = 0.0f;