mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-01 09:40:08 +01:00
llvmpipe: move to common sampler/image binding code
This leaves the cache stuff in place, but we should consider trying to consolidate that. Reviewed-by: Brian Paul <brianp@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22788>
This commit is contained in:
parent
f4c8a520c2
commit
36eb75d281
5 changed files with 14 additions and 245 deletions
|
|
@ -36,6 +36,7 @@
|
|||
#include "gallivm/lp_bld_gather.h"
|
||||
#include "gallivm/lp_bld_coro.h"
|
||||
#include "gallivm/lp_bld_nir.h"
|
||||
#include "gallivm/lp_bld_jit_sample.h"
|
||||
#include "lp_state_cs.h"
|
||||
#include "lp_context.h"
|
||||
#include "lp_debug.h"
|
||||
|
|
@ -187,7 +188,7 @@ generate_compute(struct llvmpipe_context *lp,
|
|||
sampler = lp_llvm_sampler_soa_create(lp_cs_variant_key_samplers(key),
|
||||
MAX2(key->nr_samplers,
|
||||
key->nr_sampler_views));
|
||||
image = lp_llvm_image_soa_create(lp_cs_variant_key_images(key), key->nr_images);
|
||||
image = lp_bld_llvm_image_soa_create(lp_cs_variant_key_images(key), key->nr_images);
|
||||
|
||||
struct lp_build_loop_state loop_state[4];
|
||||
LLVMValueRef num_x_loop;
|
||||
|
|
@ -482,8 +483,8 @@ generate_compute(struct llvmpipe_context *lp,
|
|||
LLVMBuildRet(builder, coro_hdl);
|
||||
}
|
||||
|
||||
lp_llvm_sampler_soa_destroy(sampler);
|
||||
lp_llvm_image_soa_destroy(image);
|
||||
lp_bld_llvm_sampler_soa_destroy(sampler);
|
||||
lp_bld_llvm_image_soa_destroy(image);
|
||||
|
||||
gallivm_verify_function(gallivm, coro);
|
||||
gallivm_verify_function(gallivm, function);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@
|
|||
#include "gallivm/lp_bld_format.h"
|
||||
#include "gallivm/lp_bld_quad.h"
|
||||
#include "gallivm/lp_bld_gather.h"
|
||||
#include "gallivm/lp_bld_jit_sample.h"
|
||||
|
||||
#include "lp_bld_alpha.h"
|
||||
#include "lp_bld_blend.h"
|
||||
|
|
@ -3291,7 +3292,7 @@ generate_fragment(struct llvmpipe_context *lp,
|
|||
MAX2(key->nr_samplers,
|
||||
key->nr_sampler_views));
|
||||
struct lp_build_image_soa *image =
|
||||
lp_llvm_image_soa_create(lp_fs_variant_key_images(key), key->nr_images);
|
||||
lp_bld_llvm_image_soa_create(lp_fs_variant_key_images(key), key->nr_images);
|
||||
|
||||
unsigned num_fs = 16 / fs_type.length; /* number of loops per 4x4 stamp */
|
||||
/* for 1d resources only run "upper half" of stamp */
|
||||
|
|
@ -3471,8 +3472,8 @@ generate_fragment(struct llvmpipe_context *lp,
|
|||
}
|
||||
}
|
||||
|
||||
lp_llvm_sampler_soa_destroy(sampler);
|
||||
lp_llvm_image_soa_destroy(image);
|
||||
lp_bld_llvm_sampler_soa_destroy(sampler);
|
||||
lp_bld_llvm_image_soa_destroy(image);
|
||||
|
||||
/* Loop over color outputs / color buffers to do blending */
|
||||
for (unsigned cbuf = 0; cbuf < key->nr_cbufs; cbuf++) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "pipe/p_state.h"
|
||||
#include "tgsi/tgsi_scan.h" /* for tgsi_shader_info */
|
||||
#include "gallivm/lp_bld_sample.h" /* for struct lp_sampler_static_state */
|
||||
#include "gallivm/lp_bld_jit_sample.h"
|
||||
#include "gallivm/lp_bld_tgsi.h" /* for lp_tgsi_info */
|
||||
#include "lp_bld_interp.h" /* for struct lp_shader_input */
|
||||
#include "util/u_inlines.h"
|
||||
|
|
@ -59,23 +60,6 @@ enum lp_fs_kind
|
|||
};
|
||||
|
||||
|
||||
struct lp_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 lp_image_static_state
|
||||
{
|
||||
struct lp_static_texture_state image_state;
|
||||
};
|
||||
|
||||
struct lp_depth_state
|
||||
{
|
||||
unsigned enabled:1; /**< depth test enabled? */
|
||||
|
|
|
|||
|
|
@ -53,52 +53,6 @@
|
|||
#include "lp_debug.h"
|
||||
|
||||
|
||||
/**
|
||||
* This provides the bridge between the sampler state store in
|
||||
* lp_jit_context and lp_jit_texture and the sampler code
|
||||
* generator. It provides the texture layout information required by
|
||||
* the texture sampler code generator in terms of the state stored in
|
||||
* lp_jit_context and lp_jit_texture in runtime.
|
||||
*/
|
||||
struct llvmpipe_sampler_dynamic_state
|
||||
{
|
||||
struct lp_sampler_dynamic_state base;
|
||||
|
||||
const struct lp_sampler_static_state *static_state;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This is the bridge between our sampler and the TGSI translator.
|
||||
*/
|
||||
struct lp_llvm_sampler_soa
|
||||
{
|
||||
struct lp_build_sampler_soa base;
|
||||
|
||||
struct llvmpipe_sampler_dynamic_state dynamic_state;
|
||||
unsigned nr_samplers;
|
||||
};
|
||||
|
||||
|
||||
struct llvmpipe_image_dynamic_state
|
||||
{
|
||||
struct lp_sampler_dynamic_state base;
|
||||
|
||||
const struct lp_image_static_state *static_state;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This is the bridge between our images and the TGSI translator.
|
||||
*/
|
||||
struct lp_llvm_image_soa
|
||||
{
|
||||
struct lp_build_image_soa base;
|
||||
|
||||
struct llvmpipe_image_dynamic_state dynamic_state;
|
||||
unsigned nr_images;
|
||||
};
|
||||
|
||||
#if LP_USE_TEXTURE_CACHE
|
||||
static LLVMValueRef
|
||||
lp_llvm_texture_cache_ptr(struct gallivm_state *gallivm,
|
||||
|
|
@ -112,166 +66,18 @@ lp_llvm_texture_cache_ptr(struct gallivm_state *gallivm,
|
|||
return lp_jit_thread_data_cache(gallivm, thread_data_type, thread_data_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Fetch filtered values from texture.
|
||||
* The 'texel' parameter returns four vectors corresponding to R, G, B, A.
|
||||
*/
|
||||
static void
|
||||
lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
|
||||
struct gallivm_state *gallivm,
|
||||
const struct lp_sampler_params *params)
|
||||
{
|
||||
struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base;
|
||||
const unsigned texture_index = params->texture_index;
|
||||
const unsigned sampler_index = params->sampler_index;
|
||||
|
||||
assert(sampler_index < PIPE_MAX_SAMPLERS);
|
||||
assert(texture_index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
|
||||
if (LP_PERF & PERF_NO_TEX) {
|
||||
lp_build_sample_nop(gallivm, params->type, params->coords, params->texel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (params->texture_index_offset) {
|
||||
LLVMValueRef unit =
|
||||
LLVMBuildAdd(gallivm->builder, params->texture_index_offset,
|
||||
lp_build_const_int32(gallivm, texture_index), "");
|
||||
|
||||
struct lp_build_sample_array_switch switch_info;
|
||||
memset(&switch_info, 0, sizeof(switch_info));
|
||||
lp_build_sample_array_init_soa(&switch_info, gallivm, params, unit,
|
||||
0, sampler->nr_samplers);
|
||||
// build the switch cases
|
||||
for (unsigned i = 0; i < sampler->nr_samplers; i++) {
|
||||
lp_build_sample_array_case_soa(&switch_info, i,
|
||||
&sampler->dynamic_state.static_state[i].texture_state,
|
||||
&sampler->dynamic_state.static_state[i].sampler_state,
|
||||
&sampler->dynamic_state.base);
|
||||
}
|
||||
lp_build_sample_array_fini_soa(&switch_info);
|
||||
} else {
|
||||
lp_build_sample_soa(&sampler->dynamic_state.static_state[texture_index].texture_state,
|
||||
&sampler->dynamic_state.static_state[sampler_index].sampler_state,
|
||||
&sampler->dynamic_state.base,
|
||||
gallivm, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch the texture size.
|
||||
*/
|
||||
static void
|
||||
lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
|
||||
struct gallivm_state *gallivm,
|
||||
const struct lp_sampler_size_query_params *params)
|
||||
{
|
||||
struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base;
|
||||
|
||||
assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
|
||||
lp_build_size_query_soa(gallivm,
|
||||
&sampler->dynamic_state.static_state[params->texture_unit].texture_state,
|
||||
&sampler->dynamic_state.base,
|
||||
params);
|
||||
}
|
||||
|
||||
|
||||
struct lp_build_sampler_soa *
|
||||
lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
|
||||
unsigned nr_samplers)
|
||||
{
|
||||
assert(static_state);
|
||||
struct lp_build_sampler_soa *sampler;
|
||||
|
||||
struct lp_llvm_sampler_soa *sampler = CALLOC_STRUCT(lp_llvm_sampler_soa);
|
||||
if (!sampler)
|
||||
return NULL;
|
||||
|
||||
sampler->base.emit_tex_sample = lp_llvm_sampler_soa_emit_fetch_texel;
|
||||
sampler->base.emit_size_query = lp_llvm_sampler_soa_emit_size_query;
|
||||
|
||||
lp_build_jit_fill_sampler_dynamic_state(&sampler->dynamic_state.base);
|
||||
sampler = lp_bld_llvm_sampler_soa_create(static_state, nr_samplers);
|
||||
|
||||
#if LP_USE_TEXTURE_CACHE
|
||||
sampler->dynamic_state.base.cache_ptr = lp_llvm_texture_cache_ptr;
|
||||
#endif
|
||||
|
||||
sampler->dynamic_state.static_state = static_state;
|
||||
|
||||
sampler->nr_samplers = nr_samplers;
|
||||
return &sampler->base;
|
||||
return sampler;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
lp_llvm_image_soa_emit_op(const struct lp_build_image_soa *base,
|
||||
struct gallivm_state *gallivm,
|
||||
const struct lp_img_params *params)
|
||||
{
|
||||
struct lp_llvm_image_soa *image = (struct lp_llvm_image_soa *)base;
|
||||
const unsigned image_index = params->image_index;
|
||||
assert(image_index < PIPE_MAX_SHADER_IMAGES);
|
||||
|
||||
if (params->image_index_offset) {
|
||||
struct lp_build_img_op_array_switch switch_info;
|
||||
memset(&switch_info, 0, sizeof(switch_info));
|
||||
LLVMValueRef unit = LLVMBuildAdd(gallivm->builder,
|
||||
params->image_index_offset,
|
||||
lp_build_const_int32(gallivm,
|
||||
image_index), "");
|
||||
|
||||
lp_build_image_op_switch_soa(&switch_info, gallivm, params,
|
||||
unit, 0, image->nr_images);
|
||||
|
||||
for (unsigned i = 0; i < image->nr_images; i++) {
|
||||
lp_build_image_op_array_case(&switch_info, i,
|
||||
&image->dynamic_state.static_state[i].image_state,
|
||||
&image->dynamic_state.base);
|
||||
}
|
||||
lp_build_image_op_array_fini_soa(&switch_info);
|
||||
} else {
|
||||
lp_build_img_op_soa(&image->dynamic_state.static_state[image_index].image_state,
|
||||
&image->dynamic_state.base,
|
||||
gallivm, params, params->outdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch the texture size.
|
||||
*/
|
||||
static void
|
||||
lp_llvm_image_soa_emit_size_query(const struct lp_build_image_soa *base,
|
||||
struct gallivm_state *gallivm,
|
||||
const struct lp_sampler_size_query_params *params)
|
||||
{
|
||||
struct lp_llvm_image_soa *image = (struct lp_llvm_image_soa *)base;
|
||||
|
||||
assert(params->texture_unit < PIPE_MAX_SHADER_IMAGES);
|
||||
|
||||
lp_build_size_query_soa(gallivm,
|
||||
&image->dynamic_state.static_state[params->texture_unit].image_state,
|
||||
&image->dynamic_state.base,
|
||||
params);
|
||||
}
|
||||
|
||||
|
||||
struct lp_build_image_soa *
|
||||
lp_llvm_image_soa_create(const struct lp_image_static_state *static_state,
|
||||
unsigned nr_images)
|
||||
{
|
||||
struct lp_llvm_image_soa *image = CALLOC_STRUCT(lp_llvm_image_soa);
|
||||
if (!image)
|
||||
return NULL;
|
||||
|
||||
image->base.emit_op = lp_llvm_image_soa_emit_op;
|
||||
image->base.emit_size_query = lp_llvm_image_soa_emit_size_query;
|
||||
|
||||
lp_build_jit_fill_image_dynamic_state(&image->dynamic_state.base);
|
||||
image->dynamic_state.static_state = static_state;
|
||||
|
||||
image->nr_images = nr_images;
|
||||
return &image->base;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,37 +31,14 @@
|
|||
|
||||
#include "gallivm/lp_bld.h"
|
||||
|
||||
|
||||
struct lp_build_sampler_soa;
|
||||
struct lp_sampler_static_state;
|
||||
struct lp_image_static_state;
|
||||
|
||||
/**
|
||||
* Whether texture cache is used for s3tc textures.
|
||||
*/
|
||||
#define LP_USE_TEXTURE_CACHE 0
|
||||
|
||||
/**
|
||||
* Pure-LLVM texture sampling code generator.
|
||||
*
|
||||
*/
|
||||
struct lp_build_sampler_soa *
|
||||
lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *key,
|
||||
lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
|
||||
unsigned nr_samplers);
|
||||
|
||||
static inline void
|
||||
lp_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
|
||||
{
|
||||
FREE(sampler);
|
||||
}
|
||||
|
||||
struct lp_build_image_soa *
|
||||
lp_llvm_image_soa_create(const struct lp_image_static_state *key,
|
||||
unsigned nr_images);
|
||||
|
||||
static inline void
|
||||
lp_llvm_image_soa_destroy(struct lp_build_image_soa *image)
|
||||
{
|
||||
FREE(image);
|
||||
}
|
||||
|
||||
#endif /* LP_TEX_SAMPLE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue