diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index 720a8e15d5f..40f148ba96a 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -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', diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index b4ee15eefb7..868d4915311 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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. diff --git a/src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.c b/src/compiler/nir/nir_lower_tex_shadow.c similarity index 87% rename from src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.c rename to src/compiler/nir/nir_lower_tex_shadow.c index 5bf1087fd8b..c59d9d47d00 100644 --- a/src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.c +++ b/src/compiler/nir/nir_lower_tex_shadow.c @@ -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; } diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp index 541aafc22d4..d3376c3010c 100644 --- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp +++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp @@ -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); diff --git a/src/gallium/drivers/d3d12/d3d12_context.h b/src/gallium/drivers/d3d12/d3d12_context.h index 6c480e94273..0b94a863ef2 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.h +++ b/src/gallium/drivers/d3d12/d3d12_context.h @@ -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" diff --git a/src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.h b/src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.h deleted file mode 100644 index 2bb3707f597..00000000000 --- a/src/gallium/drivers/d3d12/d3d12_nir_lower_texcmp.h +++ /dev/null @@ -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 diff --git a/src/gallium/drivers/d3d12/meson.build b/src/gallium/drivers/d3d12/meson.build index 97ea47fb60b..41fe141d68b 100644 --- a/src/gallium/drivers/d3d12/meson.build +++ b/src/gallium/drivers/d3d12/meson.build @@ -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',