[Mesa-dev] [PATCH 021/133] i965/fs: Don't pass through the coordinate type

Jason Ekstrand jason at jlekstrand.net
Mon Dec 15 22:04:31 PST 2014


From: Connor Abbott <connor.abbott at intel.com>

All we really need is the number of components.
---
 src/mesa/drivers/dri/i965/brw_fs.h           |  4 ++--
 src/mesa/drivers/dri/i965/brw_fs_fp.cpp      | 12 ++++++------
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 27 +++++++++++++--------------
 3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index b270623..0559d00 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -484,7 +484,7 @@ public:
    void emit_interpolation_setup_gen4();
    void emit_interpolation_setup_gen6();
    void compute_sample_position(fs_reg dst, fs_reg int_sample_pos);
-   fs_reg rescale_texcoord(fs_reg coordinate, const glsl_type *coord_type,
+   fs_reg rescale_texcoord(fs_reg coordinate, int coord_components,
                            bool is_rect, uint32_t sampler, int texunit);
    fs_inst *emit_texture_gen4(ir_texture_opcode op, fs_reg dst,
                               fs_reg coordinate, int coord_components,
@@ -505,7 +505,7 @@ public:
                               fs_reg offset_value);
    void emit_texture(ir_texture_opcode op,
                      const glsl_type *dest_type,
-                     fs_reg coordinate, const struct glsl_type *coord_type,
+                     fs_reg coordinate, int components,
                      fs_reg shadow_c,
                      fs_reg lod, fs_reg dpdy, int grad_components,
                      fs_reg sample_index,
diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
index acef9de..0454014 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
@@ -423,26 +423,26 @@ fs_visitor::emit_fragment_program_code()
             unreachable("not reached");
          }
 
-         const glsl_type *coordinate_type;
+         int coord_components;
          switch (fpi->TexSrcTarget) {
          case TEXTURE_1D_INDEX:
-            coordinate_type = glsl_type::float_type;
+            coord_components = 1;
             break;
 
          case TEXTURE_2D_INDEX:
          case TEXTURE_1D_ARRAY_INDEX:
          case TEXTURE_RECT_INDEX:
          case TEXTURE_EXTERNAL_INDEX:
-            coordinate_type = glsl_type::vec2_type;
+            coord_components = 2;
             break;
 
          case TEXTURE_3D_INDEX:
          case TEXTURE_2D_ARRAY_INDEX:
-            coordinate_type = glsl_type::vec3_type;
+            coord_components = 3;
             break;
 
          case TEXTURE_CUBE_INDEX: {
-            coordinate_type = glsl_type::vec3_type;
+            coord_components = 4;
 
             fs_reg temp = fs_reg(this, glsl_type::float_type);
             fs_reg cubecoord = fs_reg(this, glsl_type::vec3_type);
@@ -470,7 +470,7 @@ fs_visitor::emit_fragment_program_code()
          if (fpi->TexShadow)
             shadow_c = offset(coordinate, 2);
 
-         emit_texture(op, glsl_type::vec4_type, coordinate, coordinate_type,
+         emit_texture(op, glsl_type::vec4_type, coordinate, coord_components,
                       shadow_c, lod, dpdy, 0, sample_index,
                       reg_undef, 0, /* offset, components */
                       reg_undef, /* mcs */
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 593c6e9..025cac5 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1835,7 +1835,7 @@ get_tex(gl_shader_stage stage, const void *key)
 }
 
 fs_reg
-fs_visitor::rescale_texcoord(fs_reg coordinate, const glsl_type *coord_type,
+fs_visitor::rescale_texcoord(fs_reg coordinate, int coord_components,
                              bool is_rect, uint32_t sampler, int texunit)
 {
    fs_inst *inst = NULL;
@@ -1894,7 +1894,7 @@ fs_visitor::rescale_texcoord(fs_reg coordinate, const glsl_type *coord_type,
     * tracking to get the scaling factor.
     */
    if (brw->gen < 6 && is_rect) {
-      fs_reg dst = fs_reg(this, coord_type);
+      fs_reg dst = fs_reg(GRF, virtual_grf_alloc(coord_components));
       fs_reg src = coordinate;
       coordinate = dst;
 
@@ -1934,8 +1934,8 @@ fs_visitor::rescale_texcoord(fs_reg coordinate, const glsl_type *coord_type,
       }
    }
 
-   if (coord_type && needs_gl_clamp) {
-      for (unsigned int i = 0; i < MIN2(coord_type->vector_elements, 3); i++) {
+   if (coord_components > 0 && needs_gl_clamp) {
+      for (int i = 0; i < MIN2(coord_components, 3); i++) {
 	 if (tex->gl_clamp_mask[i] & (1 << sampler)) {
 	    fs_reg chan = coordinate;
 	    chan = offset(chan, i);
@@ -1982,7 +1982,7 @@ fs_visitor::emit_mcs_fetch(fs_reg coordinate, int components, fs_reg sampler)
 void
 fs_visitor::emit_texture(ir_texture_opcode op,
                          const glsl_type *dest_type,
-                         fs_reg coordinate, const struct glsl_type *coord_type,
+                         fs_reg coordinate, int coord_components,
                          fs_reg shadow_c,
                          fs_reg lod, fs_reg lod2, int grad_components,
                          fs_reg sample_index,
@@ -2019,7 +2019,7 @@ fs_visitor::emit_texture(ir_texture_opcode op,
       /* FINISHME: Texture coordinate rescaling doesn't work with non-constant
        * samplers.  This should only be a problem with GL_CLAMP on Gen7.
        */
-      coordinate = rescale_texcoord(coordinate, coord_type, is_rect,
+      coordinate = rescale_texcoord(coordinate, coord_components, is_rect,
                                     sampler, texunit);
    }
 
@@ -2028,8 +2028,6 @@ fs_visitor::emit_texture(ir_texture_opcode op,
     */
    fs_reg dst(this, glsl_type::get_instance(dest_type->base_type, 4, 1));
 
-   int coord_components = coord_type ? coord_type->vector_elements : 0;
-
    if (brw->gen >= 7) {
       inst = emit_texture_gen7(op, dst, coordinate, coord_components,
                                shadow_c, lod, lod2, grad_components,
@@ -2140,9 +2138,9 @@ fs_visitor::visit(ir_texture *ir)
     * generating these values may involve SEND messages that need the MRFs.
     */
    fs_reg coordinate;
-   const glsl_type *coord_type = NULL;
+   int coord_components = 0;
    if (ir->coordinate) {
-      coord_type = ir->coordinate->type;
+      coord_components = ir->coordinate->type->vector_elements;
       ir->coordinate->accept(this);
       coordinate = this->result;
    }
@@ -2224,10 +2222,11 @@ fs_visitor::visit(ir_texture *ir)
       ir->sampler->type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE &&
       ir->sampler->type->sampler_array;
 
-   emit_texture(ir->op, ir->type, coordinate, coord_type, shadow_comparitor,
-                lod, lod2, grad_components, sample_index, offset_value,
-                offset_components, mcs, gather_component,
-                is_cube_array, is_rect, sampler, sampler_reg, texunit);
+   emit_texture(ir->op, ir->type, coordinate, coord_components,
+                shadow_comparitor, lod, lod2, grad_components,
+                sample_index, offset_value, offset_components, mcs,
+                gather_component, is_cube_array, is_rect, sampler,
+                sampler_reg, texunit);
 }
 
 /**
-- 
2.2.0



More information about the mesa-dev mailing list