gallivm,draw,llvmpipe: Support wider native registers.
[mesa.git] / src / gallium / auxiliary / draw / draw_llvm_sample.c
index ac1fbb179c6b4a4b076d04d90d567557bc8e6035..1dbe5f5bd19c133b132762eafa9606cb64fff7bc 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "pipe/p_defines.h"
 #include "pipe/p_shader_tokens.h"
+#include "gallivm/lp_bld_const.h"
 #include "gallivm/lp_bld_debug.h"
 #include "gallivm/lp_bld_type.h"
 #include "gallivm/lp_bld_sample.h"
@@ -84,12 +85,13 @@ struct draw_llvm_sampler_soa
  */
 static LLVMValueRef
 draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
-                         LLVMBuilderRef builder,
+                         struct gallivm_state *gallivm,
                          unsigned 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];
@@ -99,13 +101,13 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    debug_assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
 
    /* context[0] */
-   indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+   indices[0] = lp_build_const_int32(gallivm, 0);
    /* context[0].textures */
-   indices[1] = LLVMConstInt(LLVMInt32Type(), DRAW_JIT_CTX_TEXTURES, 0);
+   indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
    /* context[0].textures[unit] */
-   indices[2] = LLVMConstInt(LLVMInt32Type(), unit, 0);
+   indices[2] = lp_build_const_int32(gallivm, unit);
    /* context[0].textures[unit].member */
-   indices[3] = LLVMConstInt(LLVMInt32Type(), member_index, 0);
+   indices[3] = lp_build_const_int32(gallivm, member_index);
 
    ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
 
@@ -132,16 +134,17 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
 #define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load)  \
    static LLVMValueRef \
    draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
-                              LLVMBuilderRef builder,                   \
+                              struct gallivm_state *gallivm,               \
                               unsigned unit)                            \
    { \
-      return draw_llvm_texture_member(base, builder, unit, _index, #_name, _emit_load ); \
+      return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \
    }
 
 
 DRAW_LLVM_TEXTURE_MEMBER(width,      DRAW_JIT_TEXTURE_WIDTH, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(height,     DRAW_JIT_TEXTURE_HEIGHT, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(depth,      DRAW_JIT_TEXTURE_DEPTH, TRUE)
+DRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE)
 DRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, 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)
@@ -165,13 +168,12 @@ draw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
  */
 static void
 draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
-                                       LLVMBuilderRef builder,
+                                       struct gallivm_state *gallivm,
                                        struct lp_type type,
                                        unsigned unit,
                                        unsigned num_coords,
                                        const LLVMValueRef *coords,
-                                       const LLVMValueRef *ddx,
-                                       const LLVMValueRef *ddy,
+                                       const struct lp_derivatives *derivs,
                                        LLVMValueRef lod_bias, /* optional */
                                        LLVMValueRef explicit_lod, /* optional */
                                        LLVMValueRef *texel)
@@ -180,18 +182,42 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 
    assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
 
-   lp_build_sample_soa(builder,
+   lp_build_sample_soa(gallivm,
                        &sampler->dynamic_state.static_state[unit],
                        &sampler->dynamic_state.base,
                        type,
                        unit,
                        num_coords, coords,
-                       ddx, ddy,
+                       derivs,
                        lod_bias, explicit_lod,
                        texel);
 }
 
 
+/**
+ * Fetch the texture size.
+ */
+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,
+                                      LLVMValueRef explicit_lod, /* optional */
+                                      LLVMValueRef *sizes_out)
+{
+   struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
+
+   assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
+
+   lp_build_size_query_soa(gallivm,
+                           &sampler->dynamic_state.static_state[unit],
+                           &sampler->dynamic_state.base,
+                          type,
+                           unit,
+                           explicit_lod,
+                           sizes_out);
+}
+
 struct lp_build_sampler_soa *
 draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
                              LLVMValueRef context_ptr)
@@ -204,9 +230,11 @@ draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
 
    sampler->base.destroy = draw_llvm_sampler_soa_destroy;
    sampler->base.emit_fetch_texel = draw_llvm_sampler_soa_emit_fetch_texel;
+   sampler->base.emit_size_query = draw_llvm_sampler_soa_emit_size_query;
    sampler->dynamic_state.base.width = draw_llvm_texture_width;
    sampler->dynamic_state.base.height = draw_llvm_texture_height;
    sampler->dynamic_state.base.depth = draw_llvm_texture_depth;
+   sampler->dynamic_state.base.first_level = draw_llvm_texture_first_level;
    sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level;
    sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride;
    sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride;