X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Fgallivm%2Flp_bld_sample.h;h=9b42d3faad5c17f2cc28d1f3fd2a3cf2577acd0f;hb=3ca3b07fc1b46824fb7589fe06f9455d9f85bb12;hp=51e98ab2f9eb03c90de346081d932f54d56c3e74;hpb=bcc13b74443137043e8a34f8cb64a5add0d8af93;p=mesa.git diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 51e98ab2f9e..9b42d3faad5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -36,23 +36,130 @@ #define LP_BLD_SAMPLE_H +#include "pipe/p_format.h" +#include "util/u_debug.h" #include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_swizzle.h" + +#ifdef __cplusplus +extern "C" { +#endif struct pipe_resource; struct pipe_sampler_view; struct pipe_sampler_state; +struct pipe_image_view; struct util_format_description; struct lp_type; struct lp_build_context; /** - * Sampler static state. + * Helper struct holding all derivatives needed for sampling + */ +struct lp_derivatives +{ + LLVMValueRef ddx[3]; + LLVMValueRef ddy[3]; +}; + + +enum lp_sampler_lod_property { + LP_SAMPLER_LOD_SCALAR, + LP_SAMPLER_LOD_PER_ELEMENT, + LP_SAMPLER_LOD_PER_QUAD +}; + + +enum lp_sampler_lod_control { + LP_SAMPLER_LOD_IMPLICIT, + LP_SAMPLER_LOD_BIAS, + LP_SAMPLER_LOD_EXPLICIT, + LP_SAMPLER_LOD_DERIVATIVES, +}; + + +enum lp_sampler_op_type { + LP_SAMPLER_OP_TEXTURE, + LP_SAMPLER_OP_FETCH, + LP_SAMPLER_OP_GATHER, + LP_SAMPLER_OP_LODQ +}; + + +#define LP_SAMPLER_SHADOW (1 << 0) +#define LP_SAMPLER_OFFSETS (1 << 1) +#define LP_SAMPLER_OP_TYPE_SHIFT 2 +#define LP_SAMPLER_OP_TYPE_MASK (3 << 2) +#define LP_SAMPLER_LOD_CONTROL_SHIFT 4 +#define LP_SAMPLER_LOD_CONTROL_MASK (3 << 4) +#define LP_SAMPLER_LOD_PROPERTY_SHIFT 6 +#define LP_SAMPLER_LOD_PROPERTY_MASK (3 << 6) +#define LP_SAMPLER_GATHER_COMP_SHIFT 8 +#define LP_SAMPLER_GATHER_COMP_MASK (3 << 8) +#define LP_SAMPLER_FETCH_MS (1 << 10) + +struct lp_sampler_params +{ + struct lp_type type; + unsigned texture_index; + unsigned sampler_index; + LLVMValueRef texture_index_offset; + unsigned sample_key; + LLVMValueRef context_ptr; + LLVMValueRef thread_data_ptr; + const LLVMValueRef *coords; + const LLVMValueRef *offsets; + LLVMValueRef ms_index; + LLVMValueRef lod; + const struct lp_derivatives *derivs; + LLVMValueRef *texel; +}; + +struct lp_sampler_size_query_params +{ + struct lp_type int_type; + unsigned texture_unit; + LLVMValueRef texture_unit_offset; + unsigned target; + LLVMValueRef context_ptr; + boolean is_sviewinfo; + bool samples_only; + enum lp_sampler_lod_property lod_property; + LLVMValueRef explicit_lod; + LLVMValueRef *sizes_out; +}; + +#define LP_IMG_LOAD 0 +#define LP_IMG_STORE 1 +#define LP_IMG_ATOMIC 2 +#define LP_IMG_ATOMIC_CAS 3 + +struct lp_img_params +{ + struct lp_type type; + unsigned image_index; + LLVMValueRef image_index_offset; + unsigned img_op; + unsigned target; + LLVMAtomicRMWBinOp op; + LLVMValueRef exec_mask; + LLVMValueRef context_ptr; + LLVMValueRef thread_data_ptr; + const LLVMValueRef *coords; + LLVMValueRef ms_index; + LLVMValueRef indata[4]; + LLVMValueRef indata2[4]; + LLVMValueRef *outdata; +}; +/** + * Texture static state. * - * These are the bits of state from pipe_resource and pipe_sampler_state that + * These are the bits of state from pipe_resource/pipe_sampler_view that * are embedded in the generated code. */ -struct lp_sampler_static_state +struct lp_static_texture_state { /* pipe_sampler_view's state */ enum pipe_format format; @@ -62,11 +169,22 @@ struct lp_sampler_static_state unsigned swizzle_a:3; /* pipe_texture's state */ - unsigned target:3; /**< PIPE_TEXTURE_* */ + unsigned target:4; /**< PIPE_TEXTURE_* */ unsigned pot_width:1; /**< is the width a power of two? */ unsigned pot_height:1; unsigned pot_depth:1; + unsigned level_zero_only:1; +}; + +/** + * Sampler static state. + * + * These are the bits of state from pipe_sampler_state that + * are embedded in the generated code. + */ +struct lp_static_sampler_state +{ /* pipe_sampler_state's state */ unsigned wrap_s:3; unsigned wrap_t:3; @@ -77,16 +195,24 @@ struct lp_sampler_static_state unsigned compare_mode:1; unsigned compare_func:3; unsigned normalized_coords:1; - float lod_bias, min_lod, max_lod; - float border_color[4]; + unsigned min_max_lod_equal:1; /**< min_lod == max_lod ? */ + unsigned lod_bias_non_zero:1; + unsigned max_lod_pos:1; + unsigned apply_min_lod:1; /**< min_lod > 0 ? */ + unsigned apply_max_lod:1; /**< max_lod < last_level ? */ + unsigned seamless_cube_map:1; + + /* Hacks */ + unsigned force_nearest_s:1; + unsigned force_nearest_t:1; }; /** * Sampler dynamic state. * - * These are the bits of state from pipe_resource and pipe_sampler_state that - * are computed in runtime. + * These are the bits of state from pipe_resource/pipe_sampler_view + * as well as from sampler state that are computed at runtime. * * There are obtained through callbacks, as we don't want to tie the texture * sampling code generation logic to any particular texture layout or pipe @@ -94,91 +220,513 @@ struct lp_sampler_static_state */ struct lp_sampler_dynamic_state { + /* First callbacks for sampler view state */ + + /** Obtain the base texture width (or number of elements) (returns int32) */ + LLVMValueRef + (*width)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); - /** Obtain the base texture width. */ + /** Obtain the base texture height (returns int32) */ LLVMValueRef - (*width)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*height)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); - /** Obtain the base texture height. */ + /** Obtain the base texture depth (or array size) (returns int32) */ LLVMValueRef - (*height)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*depth)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); - /** Obtain the base texture depth. */ + /** Obtain the first mipmap level (base level) (returns int32) */ LLVMValueRef - (*depth)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*first_level)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); - /** Obtain the number of mipmap levels (minus one). */ + /** Obtain the number of mipmap levels minus one (returns int32) */ LLVMValueRef - (*last_level)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*last_level)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + /** Obtain stride in bytes between image rows/blocks (returns int32) */ LLVMValueRef - (*row_stride)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*row_stride)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + /** Obtain stride in bytes between image slices (returns int32) */ LLVMValueRef - (*img_stride)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, - unsigned unit); + (*img_stride)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + /** Obtain pointer to base of texture */ LLVMValueRef - (*data_ptr)( const struct lp_sampler_dynamic_state *state, - LLVMBuilderRef builder, + (*base_ptr)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain pointer to array of mipmap offsets */ + LLVMValueRef + (*mip_offsets)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain number of samples (returns int32) */ + LLVMValueRef + (*num_samples)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /** Obtain multisample stride (returns int32) */ + LLVMValueRef + (*sample_stride)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned texture_unit, LLVMValueRef texture_unit_offset); + + /* These are callbacks for sampler state */ + + /** Obtain texture min lod (returns float) */ + LLVMValueRef + (*min_lod)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture max lod (returns float) */ + LLVMValueRef + (*max_lod)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture lod bias (returns float) */ + LLVMValueRef + (*lod_bias)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** Obtain texture border color (returns ptr to float[4]) */ + LLVMValueRef + (*border_color)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef context_ptr, + unsigned sampler_unit); + + /** + * Obtain texture cache (returns ptr to lp_build_format_cache). + * + * It's optional: no caching will be done if it's NULL. + */ + LLVMValueRef + (*cache_ptr)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + LLVMValueRef thread_data_ptr, unsigned unit); +}; + + +/** + * Keep all information for sampling code generation in a single place. + */ +struct lp_build_sample_context +{ + struct gallivm_state *gallivm; + + const struct lp_static_texture_state *static_texture_state; + const struct lp_static_sampler_state *static_sampler_state; + + struct lp_sampler_dynamic_state *dynamic_state; + + const struct util_format_description *format_desc; + + /* See texture_dims() */ + unsigned dims; + + /** SIMD vector width */ + unsigned vector_width; + + /** number of mipmaps (valid are 1, length/4, length) */ + unsigned num_mips; + + /** number of lod values (valid are 1, length/4, length) */ + unsigned num_lods; + + unsigned gather_comp; + boolean no_quad_lod; + boolean no_brilinear; + boolean no_rho_approx; + boolean fetch_ms; + + /** regular scalar float type */ + struct lp_type float_type; + struct lp_build_context float_bld; + + /** float vector type */ + struct lp_build_context float_vec_bld; + + /** regular scalar int type */ + struct lp_type int_type; + struct lp_build_context int_bld; + + /** Incoming coordinates type and build context */ + struct lp_type coord_type; + struct lp_build_context coord_bld; + + /** Signed integer coordinates */ + struct lp_type int_coord_type; + struct lp_build_context int_coord_bld; + + /** Unsigned integer texture size */ + struct lp_type int_size_in_type; + struct lp_build_context int_size_in_bld; + + /** Float incoming texture size */ + struct lp_type float_size_in_type; + struct lp_build_context float_size_in_bld; + + /** Unsigned integer texture size (might be per quad) */ + struct lp_type int_size_type; + struct lp_build_context int_size_bld; + /** Float texture size (might be per quad) */ + struct lp_type float_size_type; + struct lp_build_context float_size_bld; + + /** Output texels type and build context */ + struct lp_type texel_type; + struct lp_build_context texel_bld; + + /** Float level type */ + struct lp_type levelf_type; + struct lp_build_context levelf_bld; + + /** Int level type */ + struct lp_type leveli_type; + struct lp_build_context leveli_bld; + + /** Float lod type */ + struct lp_type lodf_type; + struct lp_build_context lodf_bld; + + /** Int lod type */ + struct lp_type lodi_type; + struct lp_build_context lodi_bld; + + /* Common dynamic state values */ + LLVMValueRef row_stride_array; + LLVMValueRef img_stride_array; + LLVMValueRef base_ptr; + LLVMValueRef mip_offsets; + LLVMValueRef cache; + LLVMValueRef sample_stride; + + /** Integer vector with texture width, height, depth */ + LLVMValueRef int_size; + + LLVMValueRef border_color_clamped; + + LLVMValueRef context_ptr; }; +/* + * Indirect texture access context + * + * This is used to store info across building + * and indirect texture switch statement. + */ +struct lp_build_sample_array_switch { + struct gallivm_state *gallivm; + struct lp_sampler_params params; + unsigned base, range; + LLVMValueRef switch_ref; + LLVMBasicBlockRef merge_ref; + LLVMValueRef phi; +}; + + +/** + * We only support a few wrap modes in lp_build_sample_wrap_linear_int() at + * this time. Return whether the given mode is supported by that function. + */ +static inline boolean +lp_is_simple_wrap_mode(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return TRUE; + default: + return FALSE; + } +} + + +static inline void +apply_sampler_swizzle(struct lp_build_sample_context *bld, + LLVMValueRef *texel) +{ + unsigned char swizzles[4]; + + swizzles[0] = bld->static_texture_state->swizzle_r; + swizzles[1] = bld->static_texture_state->swizzle_g; + swizzles[2] = bld->static_texture_state->swizzle_b; + swizzles[3] = bld->static_texture_state->swizzle_a; + + lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles); +} + +/* + * not really dimension as such, this indicates the amount of + * "normal" texture coords subject to minification, wrapping etc. + */ +static inline unsigned +texture_dims(enum pipe_texture_target tex) +{ + switch (tex) { + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_BUFFER: + return 1; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_2D_ARRAY: + case PIPE_TEXTURE_RECT: + case PIPE_TEXTURE_CUBE: + case PIPE_TEXTURE_CUBE_ARRAY: + return 2; + case PIPE_TEXTURE_3D: + return 3; + default: + assert(0 && "bad texture target in texture_dims()"); + return 2; + } +} + +static inline boolean +has_layer_coord(enum pipe_texture_target tex) +{ + switch (tex) { + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_TEXTURE_2D_ARRAY: + /* cube is not layered but 3rd coord (after cube mapping) behaves the same */ + case PIPE_TEXTURE_CUBE: + case PIPE_TEXTURE_CUBE_ARRAY: + return TRUE; + default: + return FALSE; + } +} + + +boolean +lp_sampler_wrap_mode_uses_border_color(unsigned mode, + unsigned min_img_filter, + unsigned mag_img_filter); /** * Derive the sampler static state. */ void -lp_sampler_static_state(struct lp_sampler_static_state *state, - const struct pipe_sampler_view *view, - const struct pipe_sampler_state *sampler); +lp_sampler_static_sampler_state(struct lp_static_sampler_state *state, + const struct pipe_sampler_state *sampler); + + +void +lp_sampler_static_texture_state(struct lp_static_texture_state *state, + const struct pipe_sampler_view *view); + +void +lp_sampler_static_texture_state_image(struct lp_static_texture_state *state, + const struct pipe_image_view *view); + +void +lp_build_lod_selector(struct lp_build_sample_context *bld, + boolean is_lodq, + unsigned texture_index, + unsigned sampler_index, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef cube_rho, + const struct lp_derivatives *derivs, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + unsigned mip_filter, + LLVMValueRef *out_lod, + LLVMValueRef *out_lod_ipart, + LLVMValueRef *out_lod_fpart, + LLVMValueRef *out_lod_positive); + +void +lp_build_nearest_mip_level(struct lp_build_sample_context *bld, + unsigned texture_unit, + LLVMValueRef lod, + LLVMValueRef *level_out, + LLVMValueRef *out_of_bounds); +void +lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + unsigned texture_unit, + LLVMValueRef lod_ipart, + LLVMValueRef *lod_fpart_inout, + LLVMValueRef *level0_out, + LLVMValueRef *level1_out); LLVMValueRef -lp_build_gather(LLVMBuilderRef builder, - unsigned length, - unsigned src_width, - unsigned dst_width, - LLVMValueRef base_ptr, - LLVMValueRef offsets); +lp_build_get_mipmap_level(struct lp_build_sample_context *bld, + LLVMValueRef level); LLVMValueRef +lp_build_get_mip_offsets(struct lp_build_sample_context *bld, + LLVMValueRef level); + + +void +lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld, + LLVMValueRef ilevel, + LLVMValueRef *out_size_vec, + LLVMValueRef *row_stride_vec, + LLVMValueRef *img_stride_vec); + + +void +lp_build_extract_image_sizes(struct lp_build_sample_context *bld, + struct lp_build_context *size_bld, + struct lp_type coord_type, + LLVMValueRef size, + LLVMValueRef *out_width, + LLVMValueRef *out_height, + LLVMValueRef *out_depth); + + +void +lp_build_unnormalized_coords(struct lp_build_sample_context *bld, + LLVMValueRef flt_size, + LLVMValueRef *s, + LLVMValueRef *t, + LLVMValueRef *r); + + +void +lp_build_cube_lookup(struct lp_build_sample_context *bld, + LLVMValueRef *coords, + const struct lp_derivatives *derivs_in, /* optional */ + LLVMValueRef *rho, + struct lp_derivatives *derivs_out, /* optional */ + boolean need_derivs); + + +void +lp_build_cube_new_coords(struct lp_build_context *ivec_bld, + LLVMValueRef face, + LLVMValueRef x0, + LLVMValueRef x1, + LLVMValueRef y0, + LLVMValueRef y1, + LLVMValueRef max_coord, + LLVMValueRef new_faces[4], + LLVMValueRef new_xcoords[4][2], + LLVMValueRef new_ycoords[4][2]); + + +void +lp_build_sample_partial_offset(struct lp_build_context *bld, + unsigned block_length, + LLVMValueRef coord, + LLVMValueRef stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_i); + + +void lp_build_sample_offset(struct lp_build_context *bld, const struct util_format_description *format_desc, LLVMValueRef x, LLVMValueRef y, LLVMValueRef z, LLVMValueRef y_stride, - LLVMValueRef z_stride); + LLVMValueRef z_stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_i, + LLVMValueRef *out_j); + + +void +lp_build_sample_soa(const struct lp_static_texture_state *static_texture_state, + const struct lp_static_sampler_state *static_sampler_state, + struct lp_sampler_dynamic_state *dynamic_texture_state, + struct gallivm_state *gallivm, + const struct lp_sampler_params *params); void -lp_build_sample_soa(LLVMBuilderRef builder, - const struct lp_sampler_static_state *static_state, - struct lp_sampler_dynamic_state *dynamic_state, - struct lp_type fp_type, - unsigned unit, - unsigned num_coords, +lp_build_coord_repeat_npot_linear(struct lp_build_sample_context *bld, + LLVMValueRef coord_f, + LLVMValueRef length_i, + LLVMValueRef length_f, + LLVMValueRef *coord0_i, + LLVMValueRef *weight_f); + + +void +lp_build_size_query_soa(struct gallivm_state *gallivm, + const struct lp_static_texture_state *static_state, + struct lp_sampler_dynamic_state *dynamic_state, + const struct lp_sampler_size_query_params *params); + +void +lp_build_sample_nop(struct gallivm_state *gallivm, + struct lp_type type, const LLVMValueRef *coords, - const LLVMValueRef *ddx, - const LLVMValueRef *ddy, - LLVMValueRef lod_bias, - LLVMValueRef explicit_lod, LLVMValueRef texel_out[4]); +LLVMValueRef +lp_build_minify(struct lp_build_context *bld, + LLVMValueRef base_size, + LLVMValueRef level, + boolean lod_scalar); + +void +lp_build_img_op_soa(const struct lp_static_texture_state *static_texture_state, + struct lp_sampler_dynamic_state *dynamic_state, + struct gallivm_state *gallivm, + const struct lp_img_params *params); + +void +lp_build_sample_array_init_soa(struct lp_build_sample_array_switch *switch_info, + struct gallivm_state *gallivm, + const struct lp_sampler_params *params, + LLVMValueRef idx, + unsigned base, unsigned range); + +void +lp_build_sample_array_case_soa(struct lp_build_sample_array_switch *switch_info, + int idx, + const struct lp_static_texture_state *static_texture_state, + const struct lp_static_sampler_state *static_sampler_state, + struct lp_sampler_dynamic_state *dynamic_texture_state); + +void lp_build_sample_array_fini_soa(struct lp_build_sample_array_switch *switch_info); +#ifdef __cplusplus +} +#endif #endif /* LP_BLD_SAMPLE_H */