Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_depth_test.c
index 67bc67cf463d8895f84cb0b5ea8578f3aa927219..e8433814c34edd349b0480e6518f894eb892975a 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * Copyright 2010 VMware, Inc.
  * All Rights Reserved.
  * 
@@ -31,7 +31,7 @@
  */
 
 #include "pipe/p_defines.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "tgsi/tgsi_scan.h"
@@ -51,6 +51,8 @@ struct depth_data {
    boolean use_shader_stencil_refs;
    ubyte shader_stencil_refs[TGSI_QUAD_SIZE];
    struct softpipe_cached_tile *tile;
+   float minval, maxval;
+   bool clamp;
 };
 
 
@@ -152,6 +154,7 @@ convert_quad_depth( struct depth_data *data,
                     const struct quad_header *quad )
 {
    unsigned j;
+   float dvals[TGSI_QUAD_SIZE];
 
    /* Convert quad's float depth values to int depth values (qzzzz).
     * If the Z buffer stores integer values, we _have_ to do the depth
@@ -159,13 +162,23 @@ convert_quad_depth( struct depth_data *data,
     * conversion of Z values (which isn't an identity function) will cause
     * Z-fighting errors.
     */
+   if (data->clamp) {
+      for (j = 0; j < TGSI_QUAD_SIZE; j++) {
+         dvals[j] = CLAMP(quad->output.depth[j], data->minval, data->maxval);
+      }
+   } else {
+      for (j = 0; j < TGSI_QUAD_SIZE; j++) {
+         dvals[j] = quad->output.depth[j];
+      }
+   }
+
    switch (data->format) {
    case PIPE_FORMAT_Z16_UNORM:
       {
          float scale = 65535.0;
 
          for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-            data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
+            data->qzzzz[j] = (unsigned) (dvals[j] * scale);
          }
       }
       break;
@@ -174,7 +187,7 @@ convert_quad_depth( struct depth_data *data,
          double scale = (double) (uint) ~0UL;
 
          for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-            data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
+            data->qzzzz[j] = (unsigned) (dvals[j] * scale);
          }
       }
       break;
@@ -184,7 +197,7 @@ convert_quad_depth( struct depth_data *data,
          float scale = (float) ((1 << 24) - 1);
 
          for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-            data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
+            data->qzzzz[j] = (unsigned) (dvals[j] * scale);
          }
       }
       break;
@@ -194,7 +207,7 @@ convert_quad_depth( struct depth_data *data,
          float scale = (float) ((1 << 24) - 1);
 
          for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-            data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
+            data->qzzzz[j] = (unsigned) (dvals[j] * scale);
          }
       }
       break;
@@ -204,7 +217,7 @@ convert_quad_depth( struct depth_data *data,
          union fi fui;
 
          for (j = 0; j < TGSI_QUAD_SIZE; j++) {
-            fui.f = quad->output.depth[j];
+            fui.f = dvals[j];
             data->qzzzz[j] = fui.ui;
          }
       }
@@ -769,9 +782,10 @@ depth_test_quads_fallback(struct quad_stage *qs,
 {
    unsigned i, pass = 0;
    const struct tgsi_shader_info *fsInfo = &qs->softpipe->fs_variant->info;
-   boolean interp_depth = !fsInfo->writes_z;
+   boolean interp_depth = !fsInfo->writes_z || qs->softpipe->early_depth;
    boolean shader_stencil_ref = fsInfo->writes_stencil;
    struct depth_data data;
+   unsigned vp_idx = quads[0]->input.viewport_index;
 
    data.use_shader_stencil_refs = FALSE;
 
@@ -782,12 +796,19 @@ depth_test_quads_fallback(struct quad_stage *qs,
    if (qs->softpipe->framebuffer.zsbuf &&
          (qs->softpipe->depth_stencil->depth.enabled ||
           qs->softpipe->depth_stencil->stencil[0].enabled)) {
+      float near_val, far_val;
 
       data.ps = qs->softpipe->framebuffer.zsbuf;
       data.format = data.ps->format;
       data.tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, 
                                      quads[0]->input.x0, 
-                                     quads[0]->input.y0);
+                                     quads[0]->input.y0, quads[0]->input.layer);
+      data.clamp = !qs->softpipe->rasterizer->depth_clip_near;
+
+      near_val = qs->softpipe->viewports[vp_idx].translate[2] - qs->softpipe->viewports[vp_idx].scale[2];
+      far_val = near_val + (qs->softpipe->viewports[vp_idx].scale[2] * 2.0);
+      data.minval = MIN2(near_val, far_val);
+      data.maxval = MAX2(near_val, far_val);
 
       for (i = 0; i < nr; i++) {
          get_depth_stencil_values(&data, quads[i]);
@@ -881,7 +902,7 @@ choose_depth_test(struct quad_stage *qs,
 {
    const struct tgsi_shader_info *fsInfo = &qs->softpipe->fs_variant->info;
 
-   boolean interp_depth = !fsInfo->writes_z;
+   boolean interp_depth = !fsInfo->writes_z || qs->softpipe->early_depth;
 
    boolean alpha = qs->softpipe->depth_stencil->alpha.enabled;
 
@@ -895,6 +916,8 @@ choose_depth_test(struct quad_stage *qs,
 
    boolean occlusion = qs->softpipe->active_query_count;
 
+   boolean clipped = !qs->softpipe->rasterizer->depth_clip_near;
+
    if(!qs->softpipe->framebuffer.zsbuf)
       depth = depthwrite = stencil = FALSE;
 
@@ -905,6 +928,7 @@ choose_depth_test(struct quad_stage *qs,
    if (!alpha &&
        !depth &&
        !occlusion &&
+       !clipped &&
        !stencil) {
       qs->run = depth_noop;
    }
@@ -913,6 +937,7 @@ choose_depth_test(struct quad_stage *qs,
             depth && 
             depthwrite && 
             !occlusion &&
+            !clipped &&
             !stencil) 
    {
       if (qs->softpipe->framebuffer.zsbuf->format == PIPE_FORMAT_Z16_UNORM) {