From c789b981b244333cfc903bcd1e2fefc010500013 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Mon, 28 Jan 2013 06:50:36 -0800 Subject: gallivm: split sampler and texture state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Brian Paul --- src/gallium/auxiliary/draw/draw_llvm.h | 66 +++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 17 deletions(-) (limited to 'src/gallium/auxiliary/draw/draw_llvm.h') diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index 892973c..a664857 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -52,12 +52,30 @@ struct draw_jit_texture uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]; +}; + + +struct draw_sampler_static_state +{ + /* + * These attributes are effectively interleaved for more sane key handling. + * However, there might be lots of null space if the amount of samplers and + * textures isn't the same. + */ + struct lp_static_sampler_state sampler_state; + struct lp_static_texture_state texture_state; +}; + + +struct draw_jit_sampler +{ float min_lod; float max_lod; float lod_bias; float border_color[4]; }; + enum { DRAW_JIT_TEXTURE_WIDTH = 0, DRAW_JIT_TEXTURE_HEIGHT, @@ -68,13 +86,19 @@ enum { DRAW_JIT_TEXTURE_ROW_STRIDE, DRAW_JIT_TEXTURE_IMG_STRIDE, DRAW_JIT_TEXTURE_MIP_OFFSETS, - DRAW_JIT_TEXTURE_MIN_LOD, - DRAW_JIT_TEXTURE_MAX_LOD, - DRAW_JIT_TEXTURE_LOD_BIAS, - DRAW_JIT_TEXTURE_BORDER_COLOR, DRAW_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ }; + +enum { + DRAW_JIT_SAMPLER_MIN_LOD, + DRAW_JIT_SAMPLER_MAX_LOD, + DRAW_JIT_SAMPLER_LOD_BIAS, + DRAW_JIT_SAMPLER_BORDER_COLOR, + DRAW_JIT_SAMPLER_NUM_FIELDS /* number of fields above */ +}; + + enum { DRAW_JIT_VERTEX_VERTEX_ID = 0, DRAW_JIT_VERTEX_CLIP, @@ -82,6 +106,9 @@ enum { DRAW_JIT_VERTEX_DATA }; +#define DRAW_JIT_CTX_TEXTURES 4 +#define DRAW_JIT_CTX_SAMPLERS 5 + /** * This structure is passed directly to the generated vertex shader. * @@ -100,7 +127,8 @@ struct draw_jit_context float (*planes) [DRAW_TOTAL_CLIP_PLANES][4]; float *viewport; - struct draw_jit_texture textures[PIPE_MAX_SAMPLERS]; + struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; + struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS]; }; @@ -117,10 +145,14 @@ struct draw_jit_context lp_build_struct_get(_gallivm, _ptr, 3, "viewport") #define DRAW_JIT_CTX_TEXTURES 4 +#define DRAW_JIT_CTX_SAMPLERS 5 #define draw_jit_context_textures(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures") +#define draw_jit_context_samplers(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers") + #define draw_jit_header_id(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id") @@ -166,6 +198,7 @@ struct draw_llvm_variant_key { unsigned nr_vertex_elements:8; unsigned nr_samplers:8; + unsigned nr_sampler_views:8; unsigned clamp_vertex_color:1; unsigned clip_xy:1; unsigned clip_z:1; @@ -174,7 +207,7 @@ struct draw_llvm_variant_key unsigned bypass_viewport:1; unsigned need_edgeflags:1; unsigned ucp_enable:PIPE_MAX_CLIP_PLANES; - unsigned pad:9-PIPE_MAX_CLIP_PLANES; + unsigned pad:33-PIPE_MAX_CLIP_PLANES; /* Variable number of vertex elements: */ @@ -182,34 +215,33 @@ struct draw_llvm_variant_key /* Followed by variable number of samplers: */ -/* struct lp_sampler_static_state sampler; */ +/* struct draw_sampler_static_state sampler; */ }; #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \ (sizeof(struct draw_llvm_variant_key) + \ - PIPE_MAX_SAMPLERS * sizeof(struct lp_sampler_static_state) + \ + PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \ (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element)) static INLINE size_t draw_llvm_variant_key_size(unsigned nr_vertex_elements, - unsigned nr_samplers) + unsigned nr_samplers) { return (sizeof(struct draw_llvm_variant_key) + - nr_samplers * sizeof(struct lp_sampler_static_state) + - (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element)); + nr_samplers * sizeof(struct draw_sampler_static_state) + + (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element)); } -static INLINE struct lp_sampler_static_state * +static INLINE struct draw_sampler_static_state * draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key) { - return (struct lp_sampler_static_state *) + return (struct draw_sampler_static_state *) &key->vertex_element[key->nr_vertex_elements]; } - struct draw_llvm_variant_list_item { struct draw_llvm_variant *base; @@ -275,8 +307,8 @@ draw_llvm_destroy(struct draw_llvm *llvm); struct draw_llvm_variant * draw_llvm_create_variant(struct draw_llvm *llvm, - unsigned num_vertex_header_attribs, - const struct draw_llvm_variant_key *key); + unsigned num_vertex_header_attribs, + const struct draw_llvm_variant_key *key); void draw_llvm_destroy_variant(struct draw_llvm_variant *variant); @@ -288,7 +320,7 @@ void draw_llvm_dump_variant_key(struct draw_llvm_variant_key *key); 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); void -- cgit v1.1