From 63deaf3bfe591099414d22a9b99a853496a2b688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 9 May 2026 18:09:03 -0400 Subject: [PATCH] nir: add nir_frag_coord_use_pixel_coord for OpenGL Reviewed-by: Samuel Pitoiset Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/compiler/nir/nir_builder.c | 12 +++++++++++- src/compiler/nir/nir_shader_compiler_options.h | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_builder.c b/src/compiler/nir/nir_builder.c index 4dd43dd364d..3d140bb8187 100644 --- a/src/compiler/nir/nir_builder.c +++ b/src/compiler/nir/nir_builder.c @@ -810,7 +810,17 @@ nir_build_frag_coord(nir_builder *b, unsigned num_components) assert(num_components && num_components <= 4); if (b->shader->options->frag_coord_form & nir_frag_coord_xy_z_w_separate) { - nir_def *xy = nir_load_frag_coord_xy(b); + nir_def *xy; + + if (b->shader->options->frag_coord_form & + nir_frag_coord_use_pixel_coord) { + xy = nir_u2f32(b, nir_load_pixel_coord(b)); + + if (!b->shader->info.fs.pixel_center_integer) + xy = nir_fadd_imm(b, nir_u2f32(b, nir_load_pixel_coord(b)), 0.5); + } else { + xy = nir_load_frag_coord_xy(b); + } if (num_components <= 2) return nir_trim_vector(b, xy, num_components); diff --git a/src/compiler/nir/nir_shader_compiler_options.h b/src/compiler/nir/nir_shader_compiler_options.h index d61e39394fc..c1e03b87f4f 100644 --- a/src/compiler/nir/nir_shader_compiler_options.h +++ b/src/compiler/nir/nir_shader_compiler_options.h @@ -251,6 +251,12 @@ typedef enum { /* Use frag_coord_w_rcp instead of frag_coord_w. */ nir_frag_coord_use_w_rcp = BITFIELD_BIT(1), + + /* Use pixel_coord + (pixel_center_integer ? 0 : 0.5) instead of + * frag_coord_xy. This is always correct for OpenGL without VRS because + * even sample shading must have gl_FragCoord at pixel center. + */ + nir_frag_coord_use_pixel_coord = BITFIELD_BIT(2), } nir_frag_coord_form; typedef struct nir_shader_compiler_options {