vc4: Add support for computed depth writes.
authorEric Anholt <eric@anholt.net>
Tue, 16 Sep 2014 19:55:16 +0000 (12:55 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 16 Sep 2014 20:03:41 +0000 (13:03 -0700)
Fixes piglit glsl-1.10-fragdepth and early-z.

src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h

index 8a83913bbe54f576ac89237700c7585d0b5bcbcf..a662dc2ce5490bf46d9c5deca0667f00b359329b 100644 (file)
@@ -891,6 +891,16 @@ emit_tgsi_declaration(struct vc4_compile *c,
         case TGSI_FILE_OUTPUT:
                 resize_qreg_array(c, &c->outputs, &c->outputs_array_size,
                                   (decl->Range.Last + 1) * 4);
+
+                switch (decl->Semantic.Name) {
+                case TGSI_SEMANTIC_POSITION:
+                        c->output_position_index = decl->Range.First * 4;
+                        break;
+                case TGSI_SEMANTIC_COLOR:
+                        c->output_color_index = decl->Range.First * 4;
+                        break;
+                }
+
                 break;
         }
 }
@@ -1206,7 +1216,9 @@ emit_frag_end(struct vc4_compile *c)
                 c->undef, c->undef, c->undef, c->undef
         };
         vc4_blend(c, blend_color, dst_color,
-                  c->outputs ? c->outputs : undef_array);
+                  (c->output_color_index != -1 ?
+                   c->outputs + c->output_color_index :
+                   undef_array));
 
         /* If the bit isn't set in the color mask, then just return the
          * original dst color, instead.
@@ -1238,7 +1250,14 @@ emit_frag_end(struct vc4_compile *c)
                 qir_TLB_DISCARD_SETUP(c, c->discard);
 
         if (c->fs_key->depth_enabled) {
-                qir_TLB_Z_WRITE(c, qir_FRAG_Z(c));
+                struct qreg z;
+                if (c->output_position_index != -1) {
+                        z = qir_FTOI(c, qir_FMUL(c, c->outputs[c->output_position_index + 2],
+                                                 qir_uniform_f(c, 0xffffff)));
+                } else {
+                        z = qir_FRAG_Z(c);
+                }
+                qir_TLB_Z_WRITE(c, z);
         }
 
         bool color_written = false;
index 640589d23c09217e3d69af3219f92576fa53b61c..216abb37828cac952384f08db502ce37a759b65b 100644 (file)
@@ -279,6 +279,9 @@ qir_compile_init(void)
 
         make_empty_list(&c->instructions);
 
+        c->output_position_index = -1;
+        c->output_color_index = -1;
+
         return c;
 }
 
index f26f8963f34b71360b9561f1389dd93948c069b0..f3dad5ed67c8607aac8fc508a1483bf5bb7859ea 100644 (file)
@@ -227,6 +227,8 @@ struct vc4_compile {
         uint32_t num_uniforms;
         uint32_t num_outputs;
         uint32_t num_texture_samples;
+        uint32_t output_position_index;
+        uint32_t output_color_index;
 
         struct qreg undef;
         enum qstage stage;