nir: make lower_sample_tex_compare a common pass

This pass was originally written for d3d12, but is useful for hardware
that lacks sample compare support like some etnaviv GPU models.

Also rename the lowering pass and some surrounding code to
nir_lower_tex_shadow as suggested by Emma.

I'd like to use the pass that's already in tree.

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14308>
This commit is contained in:
Christian Gmeiner
2021-12-23 13:25:53 +01:00
committed by Marge Bot
parent a78861b0fb
commit e67bca3fe7
7 changed files with 33 additions and 65 deletions

View File

@@ -193,6 +193,7 @@ files_libnir = files(
'nir_lower_ssbo.c',
'nir_lower_subgroups.c',
'nir_lower_system_values.c',
'nir_lower_tex_shadow.c',
'nir_lower_tex.c',
'nir_lower_texcoord_replace.c',
'nir_lower_to_source_mods.c',

View File

@@ -4924,6 +4924,20 @@ typedef struct nir_lower_tex_options {
bool nir_lower_tex(nir_shader *shader,
const nir_lower_tex_options *options);
typedef struct nir_lower_tex_shadow_swizzle {
unsigned swizzle_r:3;
unsigned swizzle_g:3;
unsigned swizzle_b:3;
unsigned swizzle_a:3;
} nir_lower_tex_shadow_swizzle;
bool
nir_lower_tex_shadow(nir_shader *s,
unsigned n_states,
enum compare_func *compare_func,
nir_lower_tex_shadow_swizzle *tex_swizzles);
typedef struct nir_lower_image_options {
/**
* If true, lower cube size operations.

View File

@@ -21,13 +21,13 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "d3d12_nir_lower_texcmp.h"
#include "nir.h"
#include "nir_builder.h"
#include "nir_builtin_builder.h"
static bool
lower_sample_tex_compare_filter(const nir_instr *instr,
UNUSED const void *_options)
nir_lower_tex_shadow_filter(const nir_instr *instr,
UNUSED const void *_options)
{
if (instr->type != nir_instr_type_tex)
return false;
@@ -69,12 +69,11 @@ strip_shadow_with_array(const struct glsl_type *type)
typedef struct {
unsigned n_states;
enum compare_func *compare_func;
dxil_texture_swizzle_state *tex_swizzles;
nir_lower_tex_shadow_swizzle *tex_swizzles;
} sampler_state;
static nir_ssa_def *
lower_sample_tex_compare_impl(nir_builder *b, nir_instr *instr,
void *options)
nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options)
{
nir_tex_instr *tex = nir_instr_as_tex(instr);
@@ -135,17 +134,17 @@ lower_sample_tex_compare_impl(nir_builder *b, nir_instr *instr,
}
bool
d3d12_lower_sample_tex_compare(nir_shader *s,
unsigned n_states,
enum compare_func *compare_func,
dxil_texture_swizzle_state *tex_swizzles)
nir_lower_tex_shadow(nir_shader *s,
unsigned n_states,
enum compare_func *compare_func,
nir_lower_tex_shadow_swizzle *tex_swizzles)
{
sampler_state state = {n_states, compare_func, tex_swizzles};
bool result =
nir_shader_lower_instructions(s,
lower_sample_tex_compare_filter,
lower_sample_tex_compare_impl,
nir_lower_tex_shadow_filter,
nir_lower_tex_shadow_impl,
&state);
return result;
}

View File

@@ -1045,9 +1045,13 @@ select_shader_variant(struct d3d12_selection_context *sel_ctx, d3d12_shader_sele
if (key.fs.manual_depth_range)
NIR_PASS_V(new_nir_variant, d3d12_lower_depth_range);
if (sel->compare_with_lod_bias_grad)
NIR_PASS_V(new_nir_variant, d3d12_lower_sample_tex_compare, key.n_texture_states,
key.sampler_compare_funcs, key.swizzle_state);
if (sel->compare_with_lod_bias_grad) {
STATIC_ASSERT(sizeof(dxil_texture_swizzle_state) ==
sizeof(nir_lower_tex_shadow_swizzle));
NIR_PASS_V(new_nir_variant, nir_lower_tex_shadow, key.n_texture_states,
key.sampler_compare_funcs, (nir_lower_tex_shadow_swizzle *)key.swizzle_state);
}
if (key.fs.cast_to_uint)
NIR_PASS_V(new_nir_variant, d3d12_lower_uint_cast, false);

View File

@@ -27,7 +27,6 @@
#include "d3d12_batch.h"
#include "d3d12_descriptor_pool.h"
#include "d3d12_pipeline_state.h"
#include "d3d12_nir_lower_texcmp.h"
#include "dxil_nir_lower_int_samplers.h"

View File

@@ -1,48 +0,0 @@
/*
* Copyright © Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef D3D12_NIR_LOWER_TEXCOMP_H
#define D3D12_NIR_LOWER_TEXCOMP_H
#include "dxil_nir_lower_int_samplers.h"
#include "pipe/p_state.h"
#include "compiler/shader_enums.h"
#include "nir.h"
#ifdef __cplusplus
extern "C" {
#endif
bool
d3d12_lower_sample_tex_compare(nir_shader *s,
unsigned n_states,
enum compare_func *compare_func,
dxil_texture_swizzle_state *tex_swizzles);
#ifdef __cplusplus
}
#endif
#endif // LALA_H

View File

@@ -36,7 +36,6 @@ files_libd3d12 = files(
'd3d12_lower_image_casts.c',
'd3d12_lower_int_cubemap_to_array.c',
'd3d12_lower_point_sprite.c',
'd3d12_nir_lower_texcmp.c',
'd3d12_nir_lower_vs_vertex_conversion.c',
'd3d12_nir_passes.c',
'd3d12_pipeline_state.cpp',