tgsi/ureg: make the dst register match the src indirection
[mesa.git] / src / gallium / auxiliary / draw / draw_llvm_sample.c
index 0892d16bd6dcb85aea64d6f53d335a778e52472a..e51e01101f6f7f19b73bf8674912589b9f59684b 100644 (file)
@@ -58,7 +58,7 @@ struct draw_llvm_sampler_dynamic_state
 {
    struct lp_sampler_dynamic_state base;
 
-   const struct lp_sampler_static_state *static_state;
+   const struct draw_sampler_static_state *static_state;
 
    LLVMValueRef context_ptr;
 };
@@ -86,7 +86,7 @@ struct draw_llvm_sampler_soa
 static LLVMValueRef
 draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
                          struct gallivm_state *gallivm,
-                         unsigned unit,
+                         unsigned texture_unit,
                          unsigned member_index,
                          const char *member_name,
                          boolean emit_load)
@@ -98,14 +98,14 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    LLVMValueRef ptr;
    LLVMValueRef res;
 
-   debug_assert(unit < PIPE_MAX_SAMPLERS);
+   debug_assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    /* context[0] */
    indices[0] = lp_build_const_int32(gallivm, 0);
    /* context[0].textures */
    indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
    /* context[0].textures[unit] */
-   indices[2] = lp_build_const_int32(gallivm, unit);
+   indices[2] = lp_build_const_int32(gallivm, texture_unit);
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
@@ -116,7 +116,54 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    else
       res = ptr;
 
-   lp_build_name(res, "context.texture%u.%s", unit, member_name);
+   lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
+
+   return res;
+}
+
+
+/**
+ * Fetch the specified member of the lp_jit_sampler structure.
+ * \param emit_load  if TRUE, emit the LLVM load instruction to actually
+ *                   fetch the field's value.  Otherwise, just emit the
+ *                   GEP code to address the field.
+ *
+ * @sa http://llvm.org/docs/GetElementPtr.html
+ */
+static LLVMValueRef
+draw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
+                         struct gallivm_state *gallivm,
+                         unsigned sampler_unit,
+                         unsigned member_index,
+                         const char *member_name,
+                         boolean emit_load)
+{
+   LLVMBuilderRef builder = gallivm->builder;
+   struct draw_llvm_sampler_dynamic_state *state =
+      (struct draw_llvm_sampler_dynamic_state *)base;
+   LLVMValueRef indices[4];
+   LLVMValueRef ptr;
+   LLVMValueRef res;
+
+   debug_assert(sampler_unit < PIPE_MAX_SAMPLERS);
+
+   /* context[0] */
+   indices[0] = lp_build_const_int32(gallivm, 0);
+   /* context[0].samplers */
+   indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_SAMPLERS);
+   /* context[0].samplers[unit] */
+   indices[2] = lp_build_const_int32(gallivm, sampler_unit);
+   /* context[0].samplers[unit].member */
+   indices[3] = lp_build_const_int32(gallivm, member_index);
+
+   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
+
+   if (emit_load)
+      res = LLVMBuildLoad(builder, ptr, "");
+   else
+      res = ptr;
+
+   lp_build_name(res, "context.sampler%u.%s", sampler_unit, member_name);
 
    return res;
 }
@@ -135,9 +182,9 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    static LLVMValueRef \
    draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
                               struct gallivm_state *gallivm,               \
-                              unsigned unit)                            \
+                              unsigned texture_unit)                       \
    { \
-      return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \
+      return draw_llvm_texture_member(base, gallivm, texture_unit, _index, #_name, _emit_load ); \
    }
 
 
@@ -150,10 +197,22 @@ DRAW_LLVM_TEXTURE_MEMBER(base_ptr,   DRAW_JIT_TEXTURE_BASE, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE)
 DRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE)
 DRAW_LLVM_TEXTURE_MEMBER(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE)
-DRAW_LLVM_TEXTURE_MEMBER(min_lod,    DRAW_JIT_TEXTURE_MIN_LOD, TRUE)
-DRAW_LLVM_TEXTURE_MEMBER(max_lod,    DRAW_JIT_TEXTURE_MAX_LOD, TRUE)
-DRAW_LLVM_TEXTURE_MEMBER(lod_bias,   DRAW_JIT_TEXTURE_LOD_BIAS, TRUE)
-DRAW_LLVM_TEXTURE_MEMBER(border_color, DRAW_JIT_TEXTURE_BORDER_COLOR, FALSE)
+
+
+#define DRAW_LLVM_SAMPLER_MEMBER(_name, _index, _emit_load)  \
+   static LLVMValueRef \
+   draw_llvm_sampler_##_name( const struct lp_sampler_dynamic_state *base, \
+                              struct gallivm_state *gallivm,               \
+                              unsigned sampler_unit)                       \
+   { \
+      return draw_llvm_sampler_member(base, gallivm, sampler_unit, _index, #_name, _emit_load ); \
+   }
+
+
+DRAW_LLVM_SAMPLER_MEMBER(min_lod,    DRAW_JIT_SAMPLER_MIN_LOD, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(max_lod,    DRAW_JIT_SAMPLER_MAX_LOD, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(lod_bias,   DRAW_JIT_SAMPLER_LOD_BIAS, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(border_color, DRAW_JIT_SAMPLER_BORDER_COLOR, FALSE)
 
 
 static void
@@ -171,9 +230,11 @@ static void
 draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
                                        struct gallivm_state *gallivm,
                                        struct lp_type type,
-                                       unsigned unit,
-                                       unsigned num_coords,
+                                       boolean is_fetch,
+                                       unsigned texture_index,
+                                       unsigned sampler_index,
                                        const LLVMValueRef *coords,
+                                       const LLVMValueRef *offsets,
                                        const struct lp_derivatives *derivs,
                                        LLVMValueRef lod_bias, /* optional */
                                        LLVMValueRef explicit_lod, /* optional */
@@ -181,14 +242,19 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 {
    struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
 
-   assert(unit < PIPE_MAX_SAMPLERS);
+   assert(texture_index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+   assert(sampler_index < PIPE_MAX_SAMPLERS);
 
    lp_build_sample_soa(gallivm,
-                       &sampler->dynamic_state.static_state[unit],
+                       &sampler->dynamic_state.static_state[texture_index].texture_state,
+                       &sampler->dynamic_state.static_state[sampler_index].sampler_state,
                        &sampler->dynamic_state.base,
                        type,
-                       unit,
-                       num_coords, coords,
+                       is_fetch,
+                       texture_index,
+                       sampler_index,
+                       coords,
+                       offsets,
                        derivs,
                        lod_bias, explicit_lod,
                        texel);
@@ -202,25 +268,27 @@ static void
 draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                       struct gallivm_state *gallivm,
                                       struct lp_type type,
-                                      unsigned unit,
+                                      unsigned texture_unit,
+                                      boolean need_nr_mips,
                                       LLVMValueRef explicit_lod, /* optional */
                                       LLVMValueRef *sizes_out)
 {
    struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
 
-   assert(unit < PIPE_MAX_SAMPLERS);
+   assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    lp_build_size_query_soa(gallivm,
-                           &sampler->dynamic_state.static_state[unit],
+                           &sampler->dynamic_state.static_state[texture_unit].texture_state,
                            &sampler->dynamic_state.base,
-                          type,
-                           unit,
+                           type,
+                           texture_unit,
+                           need_nr_mips,
                            explicit_lod,
                            sizes_out);
 }
 
 struct lp_build_sampler_soa *
-draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
+draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state,
                              LLVMValueRef context_ptr)
 {
    struct draw_llvm_sampler_soa *sampler;
@@ -241,10 +309,10 @@ draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
    sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride;
    sampler->dynamic_state.base.base_ptr = draw_llvm_texture_base_ptr;
    sampler->dynamic_state.base.mip_offsets = draw_llvm_texture_mip_offsets;
-   sampler->dynamic_state.base.min_lod = draw_llvm_texture_min_lod;
-   sampler->dynamic_state.base.max_lod = draw_llvm_texture_max_lod;
-   sampler->dynamic_state.base.lod_bias = draw_llvm_texture_lod_bias;
-   sampler->dynamic_state.base.border_color = draw_llvm_texture_border_color;
+   sampler->dynamic_state.base.min_lod = draw_llvm_sampler_min_lod;
+   sampler->dynamic_state.base.max_lod = draw_llvm_sampler_max_lod;
+   sampler->dynamic_state.base.lod_bias = draw_llvm_sampler_lod_bias;
+   sampler->dynamic_state.base.border_color = draw_llvm_sampler_border_color;
    sampler->dynamic_state.static_state = static_state;
    sampler->dynamic_state.context_ptr = context_ptr;