nir/lower_tex: 'txs free' tex_rect lowering
GPUs without native txs support (and without an emulation in sw) can use this new lowering. Also it saves us from doing int/float conversions. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8898>
This commit is contained in:
parent
3fbde2fd93
commit
a403ff4d70
|
@ -214,6 +214,27 @@ lower_rect(nir_builder *b, nir_tex_instr *tex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lower_rect_tex_scale(nir_builder *b, nir_tex_instr *tex)
|
||||||
|
{
|
||||||
|
b->cursor = nir_before_instr(&tex->instr);
|
||||||
|
|
||||||
|
nir_ssa_def *idx = nir_imm_int(b, tex->texture_index);
|
||||||
|
nir_ssa_def *scale = nir_build_load_texture_rect_scaling(b, 32, idx);
|
||||||
|
|
||||||
|
/* Walk through the sources normalizing the requested arguments. */
|
||||||
|
for (unsigned i = 0; i < tex->num_srcs; i++) {
|
||||||
|
if (tex->src[i].src_type != nir_tex_src_coord)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
nir_ssa_def *coords =
|
||||||
|
nir_ssa_for_src(b, tex->src[i].src, tex->coord_components);
|
||||||
|
nir_instr_rewrite_src(&tex->instr,
|
||||||
|
&tex->src[i].src,
|
||||||
|
nir_src_for_ssa(nir_fmul(b, coords, scale)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lower_implicit_lod(nir_builder *b, nir_tex_instr *tex)
|
lower_implicit_lod(nir_builder *b, nir_tex_instr *tex)
|
||||||
{
|
{
|
||||||
|
@ -1090,7 +1111,8 @@ nir_lower_txs_lod(nir_builder *b, nir_tex_instr *tex)
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
nir_lower_tex_block(nir_block *block, nir_builder *b,
|
nir_lower_tex_block(nir_block *block, nir_builder *b,
|
||||||
const nir_lower_tex_options *options)
|
const nir_lower_tex_options *options,
|
||||||
|
const struct nir_shader_compiler_options *compiler_options)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
|
|
||||||
|
@ -1127,7 +1149,12 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
|
||||||
|
|
||||||
if ((tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) && options->lower_rect &&
|
if ((tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) && options->lower_rect &&
|
||||||
tex->op != nir_texop_txf && !nir_tex_instr_is_query(tex)) {
|
tex->op != nir_texop_txf && !nir_tex_instr_is_query(tex)) {
|
||||||
lower_rect(b, tex);
|
|
||||||
|
if (compiler_options->has_txs)
|
||||||
|
lower_rect(b, tex);
|
||||||
|
else
|
||||||
|
lower_rect_tex_scale(b, tex);
|
||||||
|
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1269,14 +1296,15 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
nir_lower_tex_impl(nir_function_impl *impl,
|
nir_lower_tex_impl(nir_function_impl *impl,
|
||||||
const nir_lower_tex_options *options)
|
const nir_lower_tex_options *options,
|
||||||
|
const struct nir_shader_compiler_options *compiler_options)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
nir_builder builder;
|
nir_builder builder;
|
||||||
nir_builder_init(&builder, impl);
|
nir_builder_init(&builder, impl);
|
||||||
|
|
||||||
nir_foreach_block(block, impl) {
|
nir_foreach_block(block, impl) {
|
||||||
progress |= nir_lower_tex_block(block, &builder, options);
|
progress |= nir_lower_tex_block(block, &builder, options, compiler_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
nir_metadata_preserve(impl, nir_metadata_block_index |
|
||||||
|
@ -1291,7 +1319,7 @@ nir_lower_tex(nir_shader *shader, const nir_lower_tex_options *options)
|
||||||
|
|
||||||
nir_foreach_function(function, shader) {
|
nir_foreach_function(function, shader) {
|
||||||
if (function->impl)
|
if (function->impl)
|
||||||
progress |= nir_lower_tex_impl(function->impl, options);
|
progress |= nir_lower_tex_impl(function->impl, options, shader->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
return progress;
|
return progress;
|
||||||
|
|
Loading…
Reference in New Issue