summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw/draw_llvm_sample.c
diff options
context:
space:
mode:
authorRoland Scheidegger <sroland@vmware.com>2013-01-28 06:50:36 -0800
committerRoland Scheidegger <sroland@vmware.com>2013-01-28 06:50:36 -0800
commitc789b981b244333cfc903bcd1e2fefc010500013 (patch)
tree0f0c5375916677240e11a1046af81bb2d5443030 /src/gallium/auxiliary/draw/draw_llvm_sample.c
parent87592cff57feef29565150b9203e220b50623f30 (diff)
downloadexternal_mesa3d-c789b981b244333cfc903bcd1e2fefc010500013.zip
external_mesa3d-c789b981b244333cfc903bcd1e2fefc010500013.tar.gz
external_mesa3d-c789b981b244333cfc903bcd1e2fefc010500013.tar.bz2
gallivm: split sampler and texture state
Split the sampler interface to use separate sampler and texture (sampler_view) state. This is needed to support dx10-style sampling instructions. This is not quite complete since both draw/llvmpipe don't really track textures/samplers independently yet, as well as the gallivm code not quite using the right sampler or texture index respectively (but it should work for the sampling codes used by opengl). We are however losing some optimizations in the process, apply_max_lod will no longer work, and we potentially could end up with more (unnecessary) recompiles (if switching textures with/without mipmaps only so it shouldn't be too bad). v2: don't use different callback structs for sampler/sampler view functions (which just complicates things), fix up sampling code to actually use the right texture or sampler index, and similar for llvmpipe/draw actually distinguish between samplers and sampler views. v3: fix more of PIPE_MAX_SAMPLER / PIPE_MAX_SHADER_SAMPLER_VIEWS mismatches (both in draw and llvmpipe), based on feedback from José get rid of unneeded static sampler derived state.(which also fixes the only 2 piglit regressions due to a forgotten assignment), fix comments based on Brian's feedback. v4: remove some accidental unrelated whitespace changes Reviewed-by: José Fonseca <jfonseca@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_llvm_sample.c')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm_sample.c95
1 files changed, 79 insertions, 16 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c
index 67d4e93..9932b91 100644
--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c
+++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c
@@ -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;
};
@@ -98,7 +98,7 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
LLVMValueRef ptr;
LLVMValueRef res;
- debug_assert(unit < PIPE_MAX_SAMPLERS);
+ debug_assert(unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
/* context[0] */
indices[0] = lp_build_const_int32(gallivm, 0);
@@ -123,6 +123,53 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
/**
+ * 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 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(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, 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", unit, member_name);
+
+ return res;
+}
+
+
+/**
* Helper macro to instantiate the functions that generate the code to
* fetch the members of lp_jit_texture to fulfill the sampler code
* generator requests.
@@ -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 unit) \
+ { \
+ return draw_llvm_sampler_member(base, gallivm, 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
@@ -172,7 +231,8 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
struct gallivm_state *gallivm,
struct lp_type type,
boolean is_fetch,
- unsigned unit,
+ unsigned texture_index,
+ unsigned sampler_index,
const LLVMValueRef *coords,
const LLVMValueRef *offsets,
const struct lp_derivatives *derivs,
@@ -182,14 +242,17 @@ 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,
is_fetch,
- unit,
+ texture_index,
+ sampler_index,
coords,
offsets,
derivs,
@@ -214,7 +277,7 @@ draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
assert(unit < PIPE_MAX_SAMPLERS);
lp_build_size_query_soa(gallivm,
- &sampler->dynamic_state.static_state[unit],
+ &sampler->dynamic_state.static_state[unit].texture_state,
&sampler->dynamic_state.base,
type,
unit,
@@ -223,7 +286,7 @@ draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
}
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;
@@ -244,10 +307,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;