[Mesa-dev] [PATCH 1/4] gallivm: convert size query to using a set of parameters.
Dave Airlie
airlied at gmail.com
Mon Apr 18 02:49:16 UTC 2016
From: Dave Airlie <airlied at redhat.com>
This isn't currently that easy to expand, so fix it up
before expanding it later to include dynamic samplers.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/gallium/auxiliary/draw/draw_llvm_sample.c | 22 ++-----
src/gallium/auxiliary/gallivm/lp_bld_sample.h | 21 ++++---
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 71 +++++++++++------------
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 9 +--
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 18 +++---
src/gallium/drivers/llvmpipe/lp_tex_sample.c | 22 ++-----
src/gallium/drivers/swr/swr_tex_sample.cpp | 22 ++-----
7 files changed, 71 insertions(+), 114 deletions(-)
diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c
index cb31695..1845c05 100644
--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c
+++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c
@@ -251,30 +251,16 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
static void
draw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
struct gallivm_state *gallivm,
- struct lp_type type,
- unsigned texture_unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean is_sviewinfo,
- enum lp_sampler_lod_property lod_property,
- LLVMValueRef explicit_lod, /* optional */
- LLVMValueRef *sizes_out)
+ const struct lp_sampler_size_query_params *params)
{
struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
- assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+ assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
lp_build_size_query_soa(gallivm,
- &sampler->dynamic_state.static_state[texture_unit].texture_state,
+ &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
&sampler->dynamic_state.base,
- type,
- texture_unit,
- target,
- context_ptr,
- is_sviewinfo,
- lod_property,
- explicit_lod,
- sizes_out);
+ params);
}
struct lp_build_sampler_soa *
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index 902ae41..9ec051a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -110,7 +110,17 @@ struct lp_sampler_params
LLVMValueRef *texel;
};
-
+struct lp_sampler_size_query_params
+{
+ struct lp_type int_type;
+ unsigned texture_unit;
+ unsigned target;
+ LLVMValueRef context_ptr;
+ boolean is_sviewinfo;
+ enum lp_sampler_lod_property lod_property;
+ LLVMValueRef explicit_lod;
+ LLVMValueRef *sizes_out;
+};
/**
* Texture static state.
*
@@ -606,14 +616,7 @@ 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,
- struct lp_type int_type,
- unsigned texture_unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean is_sviewinfo,
- enum lp_sampler_lod_property lod_property,
- LLVMValueRef explicit_lod,
- LLVMValueRef *sizes_out);
+ const struct lp_sampler_size_query_params *params);
void
lp_build_sample_nop(struct gallivm_state *gallivm,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 937948b..c16b1c9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -3439,14 +3439,7 @@ 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,
- struct lp_type int_type,
- unsigned texture_unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean is_sviewinfo,
- enum lp_sampler_lod_property lod_property,
- LLVMValueRef explicit_lod,
- LLVMValueRef *sizes_out)
+ const struct lp_sampler_size_query_params *params)
{
LLVMValueRef lod, level, size;
LLVMValueRef first_level = NULL;
@@ -3461,9 +3454,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
* all zero as mandated by d3d10 in this case.
*/
unsigned chan;
- LLVMValueRef zero = lp_build_const_vec(gallivm, int_type, 0.0F);
+ LLVMValueRef zero = lp_build_const_vec(gallivm, params->int_type, 0.0F);
for (chan = 0; chan < 4; chan++) {
- sizes_out[chan] = zero;
+ params->sizes_out[chan] = zero;
}
return;
}
@@ -3478,26 +3471,26 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
* nothing bound (or rather a dummy texture, not that this case would
* return the right values).
*/
- if (0 && static_state->target != target) {
+ if (0 && static_state->target != params->target) {
if (static_state->target == PIPE_TEXTURE_1D)
- assert(target == PIPE_TEXTURE_1D_ARRAY);
+ assert(params->target == PIPE_TEXTURE_1D_ARRAY);
else if (static_state->target == PIPE_TEXTURE_1D_ARRAY)
- assert(target == PIPE_TEXTURE_1D);
+ assert(params->target == PIPE_TEXTURE_1D);
else if (static_state->target == PIPE_TEXTURE_2D)
- assert(target == PIPE_TEXTURE_2D_ARRAY);
+ assert(params->target == PIPE_TEXTURE_2D_ARRAY);
else if (static_state->target == PIPE_TEXTURE_2D_ARRAY)
- assert(target == PIPE_TEXTURE_2D);
+ assert(params->target == PIPE_TEXTURE_2D);
else if (static_state->target == PIPE_TEXTURE_CUBE)
- assert(target == PIPE_TEXTURE_CUBE_ARRAY);
+ assert(params->target == PIPE_TEXTURE_CUBE_ARRAY);
else if (static_state->target == PIPE_TEXTURE_CUBE_ARRAY)
- assert(target == PIPE_TEXTURE_CUBE);
+ assert(params->target == PIPE_TEXTURE_CUBE);
else
assert(0);
}
- dims = texture_dims(target);
+ dims = texture_dims(params->target);
- switch (target) {
+ switch (params->target) {
case PIPE_TEXTURE_1D_ARRAY:
case PIPE_TEXTURE_2D_ARRAY:
case PIPE_TEXTURE_CUBE_ARRAY:
@@ -3508,16 +3501,16 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
break;
}
- assert(!int_type.floating);
+ assert(!params->int_type.floating);
lp_build_context_init(&bld_int_vec4, gallivm, lp_type_int_vec(32, 128));
- if (explicit_lod) {
+ if (params->explicit_lod) {
/* FIXME: this needs to honor per-element lod */
- lod = LLVMBuildExtractElement(gallivm->builder, explicit_lod,
+ lod = LLVMBuildExtractElement(gallivm->builder, params->explicit_lod,
lp_build_const_int32(gallivm, 0), "");
first_level = dynamic_state->first_level(dynamic_state, gallivm,
- context_ptr, texture_unit);
+ params->context_ptr, params->texture_unit);
level = LLVMBuildAdd(gallivm->builder, lod, first_level, "level");
lod = lp_build_broadcast_scalar(&bld_int_vec4, level);
} else {
@@ -3528,20 +3521,23 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
size = LLVMBuildInsertElement(gallivm->builder, size,
dynamic_state->width(dynamic_state, gallivm,
- context_ptr, texture_unit),
+ params->context_ptr,
+ params->texture_unit),
lp_build_const_int32(gallivm, 0), "");
if (dims >= 2) {
size = LLVMBuildInsertElement(gallivm->builder, size,
dynamic_state->height(dynamic_state, gallivm,
- context_ptr, texture_unit),
+ params->context_ptr,
+ params->texture_unit),
lp_build_const_int32(gallivm, 1), "");
}
if (dims >= 3) {
size = LLVMBuildInsertElement(gallivm->builder, size,
dynamic_state->depth(dynamic_state, gallivm,
- context_ptr, texture_unit),
+ params->context_ptr,
+ params->texture_unit),
lp_build_const_int32(gallivm, 2), "");
}
@@ -3549,8 +3545,9 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
if (has_array) {
LLVMValueRef layers = dynamic_state->depth(dynamic_state, gallivm,
- context_ptr, texture_unit);
- if (target == PIPE_TEXTURE_CUBE_ARRAY) {
+ params->context_ptr,
+ params->texture_unit);
+ if (params->target == PIPE_TEXTURE_CUBE_ARRAY) {
/*
* It looks like GL wants number of cubes, d3d10.1 has it undefined?
* Could avoid this by passing in number of cubes instead of total
@@ -3568,14 +3565,15 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
* if level is out of bounds (note this can't cover unbound texture
* here, which also requires returning zero).
*/
- if (explicit_lod && is_sviewinfo) {
+ if (params->explicit_lod && params->is_sviewinfo) {
LLVMValueRef last_level, out, out1;
struct lp_build_context leveli_bld;
/* everything is scalar for now */
lp_build_context_init(&leveli_bld, gallivm, lp_type_int_vec(32, 32));
last_level = dynamic_state->last_level(dynamic_state, gallivm,
- context_ptr, texture_unit);
+ params->context_ptr,
+ params->texture_unit);
out = lp_build_cmp(&leveli_bld, PIPE_FUNC_LESS, level, first_level);
out1 = lp_build_cmp(&leveli_bld, PIPE_FUNC_GREATER, level, last_level);
@@ -3590,13 +3588,13 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
size = lp_build_andnot(&bld_int_vec4, size, out);
}
for (i = 0; i < dims + (has_array ? 1 : 0); i++) {
- sizes_out[i] = lp_build_extract_broadcast(gallivm, bld_int_vec4.type, int_type,
+ params->sizes_out[i] = lp_build_extract_broadcast(gallivm, bld_int_vec4.type, params->int_type,
size,
lp_build_const_int32(gallivm, i));
}
- if (is_sviewinfo) {
+ if (params->is_sviewinfo) {
for (; i < 4; i++) {
- sizes_out[i] = lp_build_const_vec(gallivm, int_type, 0.0);
+ params->sizes_out[i] = lp_build_const_vec(gallivm, params->int_type, 0.0);
}
}
@@ -3604,7 +3602,7 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
* if there's no explicit_lod (buffers, rects) queries requiring nr of
* mips would be illegal.
*/
- if (is_sviewinfo && explicit_lod) {
+ if (params->is_sviewinfo && params->explicit_lod) {
struct lp_build_context bld_int_scalar;
LLVMValueRef num_levels;
lp_build_context_init(&bld_int_scalar, gallivm, lp_type_int(32));
@@ -3616,11 +3614,12 @@ lp_build_size_query_soa(struct gallivm_state *gallivm,
LLVMValueRef last_level;
last_level = dynamic_state->last_level(dynamic_state, gallivm,
- context_ptr, texture_unit);
+ params->context_ptr,
+ params->texture_unit);
num_levels = lp_build_sub(&bld_int_scalar, last_level, first_level);
num_levels = lp_build_add(&bld_int_scalar, num_levels, bld_int_scalar.one);
}
- sizes_out[3] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, int_type),
+ params->sizes_out[3] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, params->int_type),
num_levels);
}
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index b005d7a..b9094dc 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -194,14 +194,7 @@ struct lp_build_sampler_soa
void
(*emit_size_query)( const struct lp_build_sampler_soa *sampler,
struct gallivm_state *gallivm,
- struct lp_type type,
- unsigned unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean need_nr_mips,
- enum lp_sampler_lod_property,
- LLVMValueRef explicit_lod, /* optional */
- LLVMValueRef *sizes_out);
+ const struct lp_sampler_size_query_params *params);
};
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index a19be8a..13fd877 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -2664,6 +2664,7 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld,
unsigned i;
unsigned unit = inst->Src[1].Register.Index;
unsigned target, pipe_target;
+ struct lp_sampler_size_query_params params;
if (is_sviewinfo) {
target = bld->sv[unit].Resource;
@@ -2701,15 +2702,18 @@ emit_size_query( struct lp_build_tgsi_soa_context *bld,
pipe_target = tgsi_to_pipe_tex_target(target);
+ params.int_type = bld->bld_base.int_bld.type;
+ params.texture_unit = unit;
+ params.target = pipe_target;
+ params.context_ptr = bld->context_ptr;
+ params.is_sviewinfo = TRUE;
+ params.lod_property = lod_property;
+ params.explicit_lod = explicit_lod;
+ params.sizes_out = sizes_out;
+
bld->sampler->emit_size_query(bld->sampler,
bld->bld_base.base.gallivm,
- bld->bld_base.int_bld.type,
- unit, pipe_target,
- bld->context_ptr,
- TRUE,
- lod_property,
- explicit_lod,
- sizes_out);
+ ¶ms);
}
static boolean
diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c
index 5762b7b..8adaa8e 100644
--- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c
+++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c
@@ -276,30 +276,16 @@ lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
static void
lp_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
struct gallivm_state *gallivm,
- struct lp_type type,
- unsigned texture_unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean is_sviewinfo,
- enum lp_sampler_lod_property lod_property,
- LLVMValueRef explicit_lod, /* optional */
- LLVMValueRef *sizes_out)
+ const struct lp_sampler_size_query_params *params)
{
struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base;
- assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+ assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
lp_build_size_query_soa(gallivm,
- &sampler->dynamic_state.static_state[texture_unit].texture_state,
+ &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
&sampler->dynamic_state.base,
- type,
- texture_unit,
- target,
- context_ptr,
- is_sviewinfo,
- lod_property,
- explicit_lod,
- sizes_out);
+ params);
}
diff --git a/src/gallium/drivers/swr/swr_tex_sample.cpp b/src/gallium/drivers/swr/swr_tex_sample.cpp
index 8172c82..66d6b0f 100644
--- a/src/gallium/drivers/swr/swr_tex_sample.cpp
+++ b/src/gallium/drivers/swr/swr_tex_sample.cpp
@@ -302,31 +302,17 @@ swr_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
static void
swr_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
struct gallivm_state *gallivm,
- struct lp_type type,
- unsigned texture_unit,
- unsigned target,
- LLVMValueRef context_ptr,
- boolean is_sviewinfo,
- enum lp_sampler_lod_property lod_property,
- LLVMValueRef explicit_lod, /* optional */
- LLVMValueRef *sizes_out)
+ const struct lp_sampler_size_query_params *params)
{
struct swr_sampler_soa *sampler = (struct swr_sampler_soa *)base;
- assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
+ assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
lp_build_size_query_soa(
gallivm,
- &sampler->dynamic_state.static_state[texture_unit].texture_state,
+ &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
&sampler->dynamic_state.base,
- type,
- texture_unit,
- target,
- context_ptr,
- is_sviewinfo,
- lod_property,
- explicit_lod,
- sizes_out);
+ params);
}
--
2.5.5
More information about the mesa-dev
mailing list