i965: Lower textureGrad() with samplerCubeShadow on pre-Haswell.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 16 Jan 2013 19:14:14 +0000 (11:14 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 18 Jan 2013 18:30:54 +0000 (10:30 -0800)
Fixes regressions since commit 899017fc54c40c969b5239b33f3a17b311878b0d
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Fri Jan 4 07:53:09 2013 -0800

    i965: Use Haswell's sample_d_c for textureGrad with shadow samplers.

That patch assumed that all instances were lowered.  However, we weren't
lowering textureGrad() with samplerCubeShadow because I couldn't figure
out the LOD calculations.  It turns out they're easy: you just have to
use 1 for the depth.  This causes it to pass oglconform's four tests.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Tested-by: Anuj Phogat <anuj.phogat@gmail.com>
Tested-by: Ian Romanick <idr@freedesktop.org>
src/mesa/drivers/dri/i965/brw_lower_texture_gradients.cpp

index dfbb983b726c55a3c67082e3988b4c1da48a4530..9e661a1b5a0f54743d36e8cf64ae1a15479d9151 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "glsl/ir.h"
 #include "glsl/ir_builder.h"
+#include "program/prog_instruction.h"
 
 using namespace ir_builder;
 
@@ -89,10 +90,6 @@ lower_texture_grad_visitor::visit_leave(ir_texture *ir)
    if (ir->op != ir_txd || !ir->shadow_comparitor)
       return visit_continue;
 
-   /* Cubes are broken.  Avoid assertion failures when swizzling. */
-   if (ir->sampler->type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE)
-      return visit_continue;
-
    void *mem_ctx = ralloc_parent(ir);
 
    const glsl_type *grad_type = ir->lod_info.grad.dPdx->type;
@@ -106,8 +103,14 @@ lower_texture_grad_visitor::visit_leave(ir_texture *ir)
    txs->lod_info.lod = new(mem_ctx) ir_constant(0);
    ir_variable *size =
       new(mem_ctx) ir_variable(grad_type, "size", ir_var_temporary);
-   emit(size, expr(ir_unop_i2f,
-                  swizzle_for_size(txs, grad_type->vector_elements)));
+   if (ir->sampler->type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE) {
+      base_ir->insert_before(size);
+      base_ir->insert_before(assign(size, expr(ir_unop_i2f, txs), WRITEMASK_XY));
+      base_ir->insert_before(assign(size, new(mem_ctx) ir_constant(1.0f), WRITEMASK_Z));
+   } else {
+      emit(size, expr(ir_unop_i2f,
+                      swizzle_for_size(txs, grad_type->vector_elements)));
+   }
 
    /* Scale the gradients by width and height.  Effectively, the incoming
     * gradients are s'(x,y), t'(x,y), and r'(x,y) from equation 3.19 in the