mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-03 18:00:10 +01:00
nir: Move ST's force-persample-shading NIR pass to shared code.
This is about to grow a little. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36496>
This commit is contained in:
parent
c550cfce88
commit
d3ada77a6a
4 changed files with 52 additions and 15 deletions
|
|
@ -215,6 +215,7 @@ else
|
|||
'nir_lower_returns.c',
|
||||
'nir_lower_robust_access.c',
|
||||
'nir_lower_samplers.c',
|
||||
'nir_lower_sample_shading.c',
|
||||
'nir_lower_scratch.c',
|
||||
'nir_lower_scratch_to_var.c',
|
||||
'nir_lower_shader_calls.c',
|
||||
|
|
|
|||
|
|
@ -5417,6 +5417,7 @@ bool nir_lower_uniforms_to_ubo(nir_shader *shader, bool dword_packed, bool load_
|
|||
bool nir_lower_is_helper_invocation(nir_shader *shader);
|
||||
|
||||
bool nir_lower_single_sampled(nir_shader *shader);
|
||||
bool nir_lower_sample_shading(nir_shader *shader);
|
||||
|
||||
bool nir_lower_atomics(nir_shader *shader, nir_instr_filter_cb filter);
|
||||
|
||||
|
|
|
|||
49
src/compiler/nir/nir_lower_sample_shading.c
Normal file
49
src/compiler/nir/nir_lower_sample_shading.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright © 2025 Igalia SL
|
||||
*
|
||||
* 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
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
|
||||
#include "compiler/nir/nir.h"
|
||||
#include "compiler/nir/nir_builder.h"
|
||||
|
||||
static bool
|
||||
force_persample_shading(struct nir_builder *b, nir_intrinsic_instr *intr,
|
||||
void *data)
|
||||
{
|
||||
if (intr->intrinsic == nir_intrinsic_load_barycentric_pixel ||
|
||||
intr->intrinsic == nir_intrinsic_load_barycentric_centroid) {
|
||||
intr->intrinsic = nir_intrinsic_load_barycentric_sample;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Lowering to set up interpolation for sample shading. */
|
||||
bool
|
||||
nir_lower_sample_shading(nir_shader *nir)
|
||||
{
|
||||
assert(nir->info.stage == MESA_SHADER_FRAGMENT);
|
||||
assert(nir->info.fs.uses_sample_shading);
|
||||
|
||||
return nir_shader_intrinsics_pass(nir, force_persample_shading,
|
||||
nir_metadata_all, NULL);
|
||||
}
|
||||
|
|
@ -693,19 +693,6 @@ lower_ucp(struct st_context *st,
|
|||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
force_persample_shading(struct nir_builder *b, nir_intrinsic_instr *intr,
|
||||
void *data)
|
||||
{
|
||||
if (intr->intrinsic == nir_intrinsic_load_barycentric_pixel ||
|
||||
intr->intrinsic == nir_intrinsic_load_barycentric_centroid) {
|
||||
intr->intrinsic = nir_intrinsic_load_barycentric_sample;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int
|
||||
xfb_compare_dst_offset(const void *a, const void *b)
|
||||
{
|
||||
|
|
@ -1075,8 +1062,6 @@ st_create_fp_variant(struct st_context *st,
|
|||
|
||||
if (key->persample_shading) {
|
||||
nir_shader *shader = state.ir.nir;
|
||||
nir_shader_intrinsics_pass(shader, force_persample_shading,
|
||||
nir_metadata_all, NULL);
|
||||
|
||||
/* In addition to requiring per-sample interpolation, sample shading
|
||||
* changes the behaviour of gl_SampleMaskIn, so we need per-sample shading
|
||||
|
|
@ -1084,6 +1069,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
* uses_sample_shading won't be set by glsl_to_nir. We need to do so here.
|
||||
*/
|
||||
shader->info.fs.uses_sample_shading = true;
|
||||
nir_lower_sample_shading(shader);
|
||||
|
||||
finalize = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue