freedreno/ir3: fix register usage calculations
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_sample.h
index ddd450b7be93dadbfbb3aec15147cf4e05732522..be05b136edbe564be2588eab750f506a808839bd 100644 (file)
@@ -56,17 +56,25 @@ struct lp_build_context;
  */
 struct lp_derivatives
 {
-   LLVMValueRef ddx_ddy[2];
+   LLVMValueRef ddx[3];
+   LLVMValueRef ddy[3];
+};
+
+
+enum lp_sampler_lod_property {
+   LP_SAMPLER_LOD_SCALAR,
+   LP_SAMPLER_LOD_PER_ELEMENT,
+   LP_SAMPLER_LOD_PER_QUAD
 };
 
 
 /**
- * Sampler static state.
+ * Texture static state.
  *
- * These are the bits of state from pipe_resource and pipe_sampler_state that
+ * These are the bits of state from pipe_resource/pipe_sampler_view that
  * are embedded in the generated code.
  */
-struct lp_sampler_static_state
+struct lp_static_texture_state
 {
    /* pipe_sampler_view's state */
    enum pipe_format format;
@@ -76,11 +84,22 @@ struct lp_sampler_static_state
    unsigned swizzle_a:3;
 
    /* pipe_texture's state */
-   unsigned target:3;        /**< PIPE_TEXTURE_* */
+   unsigned target:4;        /**< PIPE_TEXTURE_* */
    unsigned pot_width:1;     /**< is the width a power of two? */
    unsigned pot_height:1;
    unsigned pot_depth:1;
+   unsigned level_zero_only:1;
+};
 
+
+/**
+ * Sampler static state.
+ *
+ * These are the bits of state from pipe_sampler_state that
+ * are embedded in the generated code.
+ */
+struct lp_static_sampler_state
+{
    /* pipe_sampler_state's state */
    unsigned wrap_s:3;
    unsigned wrap_t:3;
@@ -95,6 +114,7 @@ struct lp_sampler_static_state
    unsigned lod_bias_non_zero:1;
    unsigned apply_min_lod:1;  /**< min_lod > 0 ? */
    unsigned apply_max_lod:1;  /**< max_lod < last_level ? */
+   unsigned seamless_cube_map:1;
 
    /* Hacks */
    unsigned force_nearest_s:1;
@@ -105,8 +125,8 @@ struct lp_sampler_static_state
 /**
  * Sampler dynamic state.
  *
- * These are the bits of state from pipe_resource and pipe_sampler_state that
- * are computed in runtime.
+ * These are the bits of state from pipe_resource/pipe_sampler_view
+ * as well as from sampler state that are computed at runtime.
  *
  * There are obtained through callbacks, as we don't want to tie the texture
  * sampling code generation logic to any particular texture layout or pipe
@@ -114,80 +134,83 @@ struct lp_sampler_static_state
  */
 struct lp_sampler_dynamic_state
 {
+   /* First callbacks for sampler view state */
 
-   /** Obtain the base texture width (returns int32) */
+   /** Obtain the base texture width (or number of elements) (returns int32) */
    LLVMValueRef
    (*width)( const struct lp_sampler_dynamic_state *state,
              struct gallivm_state *gallivm,
-             unsigned unit);
+             unsigned texture_unit);
 
    /** Obtain the base texture height (returns int32) */
    LLVMValueRef
    (*height)( const struct lp_sampler_dynamic_state *state,
               struct gallivm_state *gallivm,
-              unsigned unit);
+              unsigned texture_unit);
 
-   /** Obtain the base texture depth (returns int32) */
+   /** Obtain the base texture depth (or array size) (returns int32) */
    LLVMValueRef
    (*depth)( const struct lp_sampler_dynamic_state *state,
              struct gallivm_state *gallivm,
-             unsigned unit);
+             unsigned texture_unit);
 
    /** Obtain the first mipmap level (base level) (returns int32) */
    LLVMValueRef
    (*first_level)( const struct lp_sampler_dynamic_state *state,
                    struct gallivm_state *gallivm,
-                   unsigned unit);
+                   unsigned texture_unit);
 
    /** Obtain the number of mipmap levels minus one (returns int32) */
    LLVMValueRef
    (*last_level)( const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
-                  unsigned unit);
+                  unsigned texture_unit);
 
    /** Obtain stride in bytes between image rows/blocks (returns int32) */
    LLVMValueRef
    (*row_stride)( const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
-                  unsigned unit);
+                  unsigned texture_unit);
 
    /** Obtain stride in bytes between image slices (returns int32) */
    LLVMValueRef
    (*img_stride)( const struct lp_sampler_dynamic_state *state,
                   struct gallivm_state *gallivm,
-                  unsigned unit);
+                  unsigned texture_unit);
 
    /** Obtain pointer to base of texture */
    LLVMValueRef
    (*base_ptr)( const struct lp_sampler_dynamic_state *state,
                 struct gallivm_state *gallivm,
-                unsigned unit);
+                unsigned texture_unit);
 
    /** Obtain pointer to array of mipmap offsets */
    LLVMValueRef
    (*mip_offsets)( const struct lp_sampler_dynamic_state *state,
                    struct gallivm_state *gallivm,
-                   unsigned unit);
+                   unsigned texture_unit);
+
+   /* These are callbacks for sampler state */
 
    /** Obtain texture min lod (returns float) */
    LLVMValueRef
    (*min_lod)(const struct lp_sampler_dynamic_state *state,
-              struct gallivm_state *gallivm, unsigned unit);
+              struct gallivm_state *gallivm, unsigned sampler_unit);
 
    /** Obtain texture max lod (returns float) */
    LLVMValueRef
    (*max_lod)(const struct lp_sampler_dynamic_state *state,
-              struct gallivm_state *gallivm, unsigned unit);
+              struct gallivm_state *gallivm, unsigned sampler_unit);
 
    /** Obtain texture lod bias (returns float) */
    LLVMValueRef
    (*lod_bias)(const struct lp_sampler_dynamic_state *state,
-               struct gallivm_state *gallivm, unsigned unit);
+               struct gallivm_state *gallivm, unsigned sampler_unit);
 
    /** Obtain texture border color (returns ptr to float[4]) */
    LLVMValueRef
    (*border_color)(const struct lp_sampler_dynamic_state *state,
-                   struct gallivm_state *gallivm, unsigned unit);
+                   struct gallivm_state *gallivm, unsigned sampler_unit);
 };
 
 
@@ -198,7 +221,8 @@ struct lp_build_sample_context
 {
    struct gallivm_state *gallivm;
 
-   const struct lp_sampler_static_state *static_state;
+   const struct lp_static_texture_state *static_texture_state;
+   const struct lp_static_sampler_state *static_sampler_state;
 
    struct lp_sampler_dynamic_state *dynamic_state;
 
@@ -210,7 +234,10 @@ struct lp_build_sample_context
    /** SIMD vector width */
    unsigned vector_width;
 
-   /** number of lod values (valid are 1, length/4, length) */
+   /** number of mipmaps (valid are 1, length/4, length) */
+   unsigned num_mips;
+
+   /** number of lod values (valid are 1, length/4, length) */
    unsigned num_lods;
 
    /** regular scalar float type */
@@ -252,13 +279,21 @@ struct lp_build_sample_context
    struct lp_type texel_type;
    struct lp_build_context texel_bld;
 
-   /** Float per-quad type */
-   struct lp_type perquadf_type;
-   struct lp_build_context perquadf_bld;
+   /** Float level type */
+   struct lp_type levelf_type;
+   struct lp_build_context levelf_bld;
 
-   /** Int per-quad type */
-   struct lp_type perquadi_type;
-   struct lp_build_context perquadi_bld;
+   /** Int level type */
+   struct lp_type leveli_type;
+   struct lp_build_context leveli_bld;
+
+   /** Float lod type */
+   struct lp_type lodf_type;
+   struct lp_build_context lodf_bld;
+
+   /** Int lod type */
+   struct lp_type lodi_type;
+   struct lp_build_context lodi_bld;
 
    /* Common dynamic state values */
    LLVMValueRef row_stride_array;
@@ -268,6 +303,8 @@ struct lp_build_sample_context
 
    /** Integer vector with texture width, height, depth */
    LLVMValueRef int_size;
+
+   LLVMValueRef border_color_clamped;
 };
 
 
@@ -295,10 +332,10 @@ apply_sampler_swizzle(struct lp_build_sample_context *bld,
 {
    unsigned char swizzles[4];
 
-   swizzles[0] = bld->static_state->swizzle_r;
-   swizzles[1] = bld->static_state->swizzle_g;
-   swizzles[2] = bld->static_state->swizzle_b;
-   swizzles[3] = bld->static_state->swizzle_a;
+   swizzles[0] = bld->static_texture_state->swizzle_r;
+   swizzles[1] = bld->static_texture_state->swizzle_g;
+   swizzles[2] = bld->static_texture_state->swizzle_b;
+   swizzles[3] = bld->static_texture_state->swizzle_a;
 
    lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles);
 }
@@ -319,6 +356,7 @@ texture_dims(enum pipe_texture_target tex)
    case PIPE_TEXTURE_2D_ARRAY:
    case PIPE_TEXTURE_RECT:
    case PIPE_TEXTURE_CUBE:
+   case PIPE_TEXTURE_CUBE_ARRAY:
       return 2;
    case PIPE_TEXTURE_3D:
       return 3;
@@ -328,6 +366,21 @@ texture_dims(enum pipe_texture_target tex)
    }
 }
 
+static INLINE boolean
+has_layer_coord(enum pipe_texture_target tex)
+{
+   switch (tex) {
+   case PIPE_TEXTURE_1D_ARRAY:
+   case PIPE_TEXTURE_2D_ARRAY:
+   /* cube is not layered but 3rd coord (after cube mapping) behaves the same */
+   case PIPE_TEXTURE_CUBE:
+   case PIPE_TEXTURE_CUBE_ARRAY:
+      return TRUE;
+   default:
+      return FALSE;
+   }
+}
+
 
 boolean
 lp_sampler_wrap_mode_uses_border_color(unsigned mode,
@@ -338,30 +391,41 @@ lp_sampler_wrap_mode_uses_border_color(unsigned mode,
  * Derive the sampler static state.
  */
 void
-lp_sampler_static_state(struct lp_sampler_static_state *state,
-                        const struct pipe_sampler_view *view,
-                        const struct pipe_sampler_state *sampler);
+lp_sampler_static_sampler_state(struct lp_static_sampler_state *state,
+                                const struct pipe_sampler_state *sampler);
+
+
+void
+lp_sampler_static_texture_state(struct lp_static_texture_state *state,
+                                const struct pipe_sampler_view *view);
 
 
 void
 lp_build_lod_selector(struct lp_build_sample_context *bld,
-                      unsigned unit,
+                      unsigned texture_index,
+                      unsigned sampler_index,
+                      LLVMValueRef s,
+                      LLVMValueRef t,
+                      LLVMValueRef r,
+                      LLVMValueRef cube_rho,
                       const struct lp_derivatives *derivs,
                       LLVMValueRef lod_bias, /* optional */
                       LLVMValueRef explicit_lod, /* optional */
                       unsigned mip_filter,
                       LLVMValueRef *out_lod_ipart,
-                      LLVMValueRef *out_lod_fpart);
+                      LLVMValueRef *out_lod_fpart,
+                      LLVMValueRef *out_lod_positive);
 
 void
 lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
-                           unsigned unit,
+                           unsigned texture_unit,
                            LLVMValueRef lod,
-                           LLVMValueRef *level_out);
+                           LLVMValueRef *level_out,
+                           LLVMValueRef *out_of_bounds);
 
 void
 lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
-                           unsigned unit,
+                           unsigned texture_unit,
                            LLVMValueRef lod_ipart,
                            LLVMValueRef *lod_fpart_inout,
                            LLVMValueRef *level0_out,
@@ -405,12 +469,24 @@ lp_build_unnormalized_coords(struct lp_build_sample_context *bld,
 
 void
 lp_build_cube_lookup(struct lp_build_sample_context *bld,
-                     LLVMValueRef s,
-                     LLVMValueRef t,
-                     LLVMValueRef r,
-                     LLVMValueRef *face,
-                     LLVMValueRef *face_s,
-                     LLVMValueRef *face_t);
+                     LLVMValueRef *coords,
+                     const struct lp_derivatives *derivs_in, /* optional */
+                     LLVMValueRef *rho,
+                     struct lp_derivatives *derivs_out, /* optional */
+                     boolean need_derivs);
+
+
+void
+lp_build_cube_new_coords(struct lp_build_context *ivec_bld,
+                         LLVMValueRef face,
+                         LLVMValueRef x0,
+                         LLVMValueRef x1,
+                         LLVMValueRef y0,
+                         LLVMValueRef y1,
+                         LLVMValueRef max_coord,
+                         LLVMValueRef new_faces[4],
+                         LLVMValueRef new_xcoords[4][2],
+                         LLVMValueRef new_ycoords[4][2]);
 
 
 void
@@ -437,16 +513,19 @@ lp_build_sample_offset(struct lp_build_context *bld,
 
 void
 lp_build_sample_soa(struct gallivm_state *gallivm,
-                    const struct lp_sampler_static_state *static_state,
-                    struct lp_sampler_dynamic_state *dynamic_state,
+                    const struct lp_static_texture_state *static_texture_state,
+                    const struct lp_static_sampler_state *static_sampler_state,
+                    struct lp_sampler_dynamic_state *dynamic_texture_state,
                     struct lp_type fp_type,
                     boolean is_fetch,
-                    unsigned unit,
+                    unsigned texture_index,
+                    unsigned sampler_index,
                     const LLVMValueRef *coords,
                     const LLVMValueRef *offsets,
                     const struct lp_derivatives *derivs,
                     LLVMValueRef lod_bias,
                     LLVMValueRef explicit_lod,
+                    enum lp_sampler_lod_property lod_property,
                     LLVMValueRef texel_out[4]);
 
 
@@ -461,10 +540,13 @@ lp_build_coord_repeat_npot_linear(struct lp_build_sample_context *bld,
 
 void
 lp_build_size_query_soa(struct gallivm_state *gallivm,
-                        const struct lp_sampler_static_state *static_state,
+                        const struct lp_static_texture_state *static_state,
                         struct lp_sampler_dynamic_state *dynamic_state,
                         struct lp_type int_type,
-                        unsigned unit,
+                        unsigned texture_unit,
+                        unsigned target,
+                        boolean is_sviewinfo,
+                        enum lp_sampler_lod_property lod_property,
                         LLVMValueRef explicit_lod,
                         LLVMValueRef *sizes_out);
 
@@ -478,7 +560,8 @@ lp_build_sample_nop(struct gallivm_state *gallivm,
 LLVMValueRef
 lp_build_minify(struct lp_build_context *bld,
                 LLVMValueRef base_size,
-                LLVMValueRef level);
+                LLVMValueRef level,
+                boolean lod_scalar);
 
 
 #endif /* LP_BLD_SAMPLE_H */