summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw/draw_llvm.c
diff options
context:
space:
mode:
authorRoland Scheidegger <[email protected]>2013-01-28 06:50:36 -0800
committerRoland Scheidegger <[email protected]>2013-01-28 06:50:36 -0800
commitc789b981b244333cfc903bcd1e2fefc010500013 (patch)
tree0f0c5375916677240e11a1046af81bb2d5443030 /src/gallium/auxiliary/draw/draw_llvm.c
parent87592cff57feef29565150b9203e220b50623f30 (diff)
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 <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_llvm.c')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c126
1 files changed, 88 insertions, 38 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index a3a3bbfea48..afb10a6a33a 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -85,11 +85,6 @@ create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] =
elem_types[DRAW_JIT_TEXTURE_MIP_OFFSETS] =
LLVMArrayType(int32_type, PIPE_MAX_TEXTURE_LEVELS);
- elem_types[DRAW_JIT_TEXTURE_MIN_LOD] =
- elem_types[DRAW_JIT_TEXTURE_MAX_LOD] =
- elem_types[DRAW_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(gallivm->context);
- elem_types[DRAW_JIT_TEXTURE_BORDER_COLOR] =
- LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
texture_type = LLVMStructTypeInContext(gallivm->context, elem_types,
Elements(elem_types), 0);
@@ -130,18 +125,6 @@ create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, mip_offsets,
target, texture_type,
DRAW_JIT_TEXTURE_MIP_OFFSETS);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, min_lod,
- target, texture_type,
- DRAW_JIT_TEXTURE_MIN_LOD);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, max_lod,
- target, texture_type,
- DRAW_JIT_TEXTURE_MAX_LOD);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, lod_bias,
- target, texture_type,
- DRAW_JIT_TEXTURE_LOD_BIAS);
- LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, border_color,
- target, texture_type,
- DRAW_JIT_TEXTURE_BORDER_COLOR);
LP_CHECK_STRUCT_SIZE(struct draw_jit_texture, target, texture_type);
@@ -150,15 +133,63 @@ create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
/**
- * Create LLVM type for struct draw_jit_texture
+ * Create LLVM type for struct draw_jit_sampler
+ */
+static LLVMTypeRef
+create_jit_sampler_type(struct gallivm_state *gallivm, const char *struct_name)
+{
+ LLVMTargetDataRef target = gallivm->target;
+ LLVMTypeRef sampler_type;
+ LLVMTypeRef elem_types[DRAW_JIT_SAMPLER_NUM_FIELDS];
+
+ elem_types[DRAW_JIT_SAMPLER_MIN_LOD] =
+ elem_types[DRAW_JIT_SAMPLER_MAX_LOD] =
+ elem_types[DRAW_JIT_SAMPLER_LOD_BIAS] = LLVMFloatTypeInContext(gallivm->context);
+ elem_types[DRAW_JIT_SAMPLER_BORDER_COLOR] =
+ LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
+
+ sampler_type = LLVMStructTypeInContext(gallivm->context, elem_types,
+ Elements(elem_types), 0);
+
+#if HAVE_LLVM < 0x0300
+ LLVMAddTypeName(gallivm->module, struct_name, sampler_type);
+
+ /* Make sure the target's struct layout cache doesn't return
+ * stale/invalid data.
+ */
+ LLVMInvalidateStructLayout(gallivm->target, sampler_type);
+#endif
+
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, min_lod,
+ target, sampler_type,
+ DRAW_JIT_SAMPLER_MIN_LOD);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, max_lod,
+ target, sampler_type,
+ DRAW_JIT_SAMPLER_MAX_LOD);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, lod_bias,
+ target, sampler_type,
+ DRAW_JIT_SAMPLER_LOD_BIAS);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, border_color,
+ target, sampler_type,
+ DRAW_JIT_SAMPLER_BORDER_COLOR);
+
+ LP_CHECK_STRUCT_SIZE(struct draw_jit_sampler, target, sampler_type);
+
+ return sampler_type;
+}
+
+
+/**
+ * Create LLVM type for struct draw_jit_context
*/
static LLVMTypeRef
create_jit_context_type(struct gallivm_state *gallivm,
- LLVMTypeRef texture_type, const char *struct_name)
+ LLVMTypeRef texture_type, LLVMTypeRef sampler_type,
+ const char *struct_name)
{
LLVMTargetDataRef target = gallivm->target;
LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context);
- LLVMTypeRef elem_types[5];
+ LLVMTypeRef elem_types[6];
LLVMTypeRef context_type;
elem_types[0] = LLVMArrayType(LLVMPointerType(float_type, 0), /* vs_constants */
@@ -168,7 +199,9 @@ create_jit_context_type(struct gallivm_state *gallivm,
DRAW_TOTAL_CLIP_PLANES), 0);
elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */
elem_types[4] = LLVMArrayType(texture_type,
- PIPE_MAX_SAMPLERS); /* textures */
+ PIPE_MAX_SHADER_SAMPLER_VIEWS); /* textures */
+ elem_types[5] = LLVMArrayType(sampler_type,
+ PIPE_MAX_SAMPLERS); /* samplers */
context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
Elements(elem_types), 0);
#if HAVE_LLVM < 0x0300
@@ -183,9 +216,14 @@ create_jit_context_type(struct gallivm_state *gallivm,
target, context_type, 1);
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes,
target, context_type, 2);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, viewport,
+ target, context_type, 3);
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, textures,
target, context_type,
DRAW_JIT_CTX_TEXTURES);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, samplers,
+ target, context_type,
+ DRAW_JIT_CTX_SAMPLERS);
LP_CHECK_STRUCT_SIZE(struct draw_jit_context,
target, context_type);
@@ -291,11 +329,13 @@ static void
create_jit_types(struct draw_llvm_variant *variant)
{
struct gallivm_state *gallivm = variant->gallivm;
- LLVMTypeRef texture_type, context_type, buffer_type, vb_type;
+ LLVMTypeRef texture_type, sampler_type, context_type, buffer_type, vb_type;
texture_type = create_jit_texture_type(gallivm, "texture");
+ sampler_type = create_jit_sampler_type(gallivm, "sampler");
- context_type = create_jit_context_type(gallivm, texture_type, "draw_jit_context");
+ context_type = create_jit_context_type(gallivm, texture_type, sampler_type,
+ "draw_jit_context");
variant->context_ptr_type = LLVMPointerType(context_type, 0);
buffer_type = LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 8), 0);
@@ -1319,7 +1359,7 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
{
unsigned i;
struct draw_llvm_variant_key *key;
- struct lp_sampler_static_state *sampler;
+ struct draw_sampler_static_state *draw_sampler;
key = (struct draw_llvm_variant_key *)store;
@@ -1345,19 +1385,29 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
* sampler array.
*/
key->nr_samplers = llvm->draw->vs.vertex_shader->info.file_max[TGSI_FILE_SAMPLER] + 1;
+ if (llvm->draw->vs.vertex_shader->info.file_max[TGSI_FILE_SAMPLER_VIEW] != -1) {
+ key->nr_sampler_views =
+ llvm->draw->vs.vertex_shader->info.file_max[TGSI_FILE_SAMPLER_VIEW] + 1;
+ }
+ else {
+ key->nr_sampler_views = key->nr_samplers;
+ }
- sampler = draw_llvm_variant_key_samplers(key);
+ draw_sampler = draw_llvm_variant_key_samplers(key);
memcpy(key->vertex_element,
llvm->draw->pt.vertex_element,
sizeof(struct pipe_vertex_element) * key->nr_vertex_elements);
-
- memset(sampler, 0, key->nr_samplers * sizeof *sampler);
+
+ memset(draw_sampler, 0, MAX2(key->nr_samplers, key->nr_sampler_views) * sizeof *draw_sampler);
for (i = 0 ; i < key->nr_samplers; i++) {
- lp_sampler_static_state(&sampler[i],
- llvm->draw->sampler_views[PIPE_SHADER_VERTEX][i],
- llvm->draw->samplers[PIPE_SHADER_VERTEX][i]);
+ lp_sampler_static_sampler_state(&draw_sampler[i].sampler_state,
+ llvm->draw->samplers[PIPE_SHADER_VERTEX][i]);
+ }
+ for (i = 0 ; i < key->nr_sampler_views; i++) {
+ lp_sampler_static_texture_state(&draw_sampler[i].texture_state,
+ llvm->draw->sampler_views[PIPE_SHADER_VERTEX][i]);
}
return key;
@@ -1368,7 +1418,7 @@ void
draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key)
{
unsigned i;
- struct lp_sampler_static_state *sampler = draw_llvm_variant_key_samplers(key);
+ struct draw_sampler_static_state *sampler = draw_llvm_variant_key_samplers(key);
debug_printf("clamp_vertex_color = %u\n", key->clamp_vertex_color);
debug_printf("clip_xy = %u\n", key->clip_xy);
@@ -1386,8 +1436,8 @@ draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key)
debug_printf("vertex_element[%i].src_format = %s\n", i, util_format_name(key->vertex_element[i].src_format));
}
- for (i = 0 ; i < key->nr_samplers; i++) {
- debug_printf("sampler[%i].src_format = %s\n", i, util_format_name(sampler[i].format));
+ for (i = 0 ; i < key->nr_sampler_views; i++) {
+ debug_printf("sampler[%i].src_format = %s\n", i, util_format_name(sampler[i].texture_state.format));
}
}
@@ -1430,15 +1480,15 @@ draw_llvm_set_sampler_state(struct draw_context *draw)
unsigned i;
for (i = 0; i < draw->num_samplers[PIPE_SHADER_VERTEX]; i++) {
- struct draw_jit_texture *jit_tex = &draw->llvm->jit_context.textures[i];
+ struct draw_jit_sampler *jit_sam = &draw->llvm->jit_context.samplers[i];
if (draw->samplers[i]) {
const struct pipe_sampler_state *s
= draw->samplers[PIPE_SHADER_VERTEX][i];
- jit_tex->min_lod = s->min_lod;
- jit_tex->max_lod = s->max_lod;
- jit_tex->lod_bias = s->lod_bias;
- COPY_4V(jit_tex->border_color, s->border_color.f);
+ jit_sam->min_lod = s->min_lod;
+ jit_sam->max_lod = s->max_lod;
+ jit_sam->lod_bias = s->lod_bias;
+ COPY_4V(jit_sam->border_color, s->border_color.f);
}
}
}