gallium/u_threaded: align batches and call slots to 16 bytes
[mesa.git] / src / gallium / drivers / swr / swr_tex_sample.cpp
index 8e01e32e2803043556ee7704e1784deb51bb7f12..f1ac41b0895920467a52f15ff5c54e9de5bfe94a 100644 (file)
@@ -46,7 +46,7 @@
 
 #include "state.h"
 #include "JitManager.h"
-#include "state_llvm.h"
+#include "gen_state_llvm.h"
 
 #include "pipe/p_defines.h"
 #include "pipe/p_shader_tokens.h"
@@ -58,8 +58,9 @@
 #include "util/u_memory.h"
 
 #include "swr_tex_sample.h"
-#include "swr_context_llvm.h"
+#include "gen_swr_context_llvm.h"
 
+using namespace SwrJit;
 
 /**
  * This provides the bridge between the sampler state store in
@@ -72,6 +73,8 @@ struct swr_sampler_dynamic_state {
    struct lp_sampler_dynamic_state base;
 
    const struct swr_sampler_static_state *static_state;
+
+   enum pipe_shader_type shader_type;
 };
 
 
@@ -112,13 +115,27 @@ swr_texture_member(const struct lp_sampler_dynamic_state *base,
    /* context[0] */
    indices[0] = lp_build_const_int32(gallivm, 0);
    /* context[0].textures */
-   indices[1] = lp_build_const_int32(gallivm, swr_draw_context_texturesFS);
+   auto dynamic = (const struct swr_sampler_dynamic_state *)base;
+   switch (dynamic->shader_type) {
+   case PIPE_SHADER_FRAGMENT:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_texturesFS);
+      break;
+   case PIPE_SHADER_VERTEX:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_texturesVS);
+      break;
+   case PIPE_SHADER_GEOMETRY:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_texturesGS);
+      break;
+   default:
+      assert(0 && "unsupported shader type");
+      break;
+   }
    /* context[0].textures[unit] */
    indices[2] = lp_build_const_int32(gallivm, texture_unit);
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
-   ptr = LLVMBuildGEP(builder, context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -195,13 +212,27 @@ swr_sampler_member(const struct lp_sampler_dynamic_state *base,
    /* context[0] */
    indices[0] = lp_build_const_int32(gallivm, 0);
    /* context[0].samplers */
-   indices[1] = lp_build_const_int32(gallivm, swr_draw_context_samplersFS);
+   auto dynamic = (const struct swr_sampler_dynamic_state *)base;
+   switch (dynamic->shader_type) {
+   case PIPE_SHADER_FRAGMENT:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_samplersFS);
+      break;
+   case PIPE_SHADER_VERTEX:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_samplersVS);
+      break;
+   case PIPE_SHADER_GEOMETRY:
+      indices[1] = lp_build_const_int32(gallivm, swr_draw_context_samplersGS);
+      break;
+   default:
+      assert(0 && "unsupported shader type");
+      break;
+   }
    /* 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, context_ptr, indices, Elements(indices), "");
+   ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), "");
 
    if (emit_load)
       res = LLVMBuildLoad(builder, ptr, "");
@@ -278,36 +309,23 @@ swr_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
 static void
 swr_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
                                 struct gallivm_state *gallivm,
-                                struct lp_type type,
-                                unsigned texture_unit,
-                                unsigned target,
-                                LLVMValueRef context_ptr,
-                                boolean is_sviewinfo,
-                                enum lp_sampler_lod_property lod_property,
-                                LLVMValueRef explicit_lod, /* optional */
-                                LLVMValueRef *sizes_out)
+                                const struct lp_sampler_size_query_params *params)
 {
    struct swr_sampler_soa *sampler = (struct swr_sampler_soa *)base;
 
-   assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+   assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    lp_build_size_query_soa(
       gallivm,
-      &sampler->dynamic_state.static_state[texture_unit].texture_state,
+      &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
       &sampler->dynamic_state.base,
-      type,
-      texture_unit,
-      target,
-      context_ptr,
-      is_sviewinfo,
-      lod_property,
-      explicit_lod,
-      sizes_out);
+      params);
 }
 
 
 struct lp_build_sampler_soa *
-swr_sampler_soa_create(const struct swr_sampler_static_state *static_state)
+swr_sampler_soa_create(const struct swr_sampler_static_state *static_state,
+                       enum pipe_shader_type shader_type)
 {
    struct swr_sampler_soa *sampler;
 
@@ -334,5 +352,7 @@ swr_sampler_soa_create(const struct swr_sampler_static_state *static_state)
 
    sampler->dynamic_state.static_state = static_state;
 
+   sampler->dynamic_state.shader_type = shader_type;
+
    return &sampler->base;
 }