From 34641b44c6d24385ba774da049b4be502db48b84 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 29 Aug 2025 07:09:41 -0400 Subject: [PATCH] mesa: support GL_NV_representative_fragment test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Part-of: --- docs/gallium/screen.rst | 1 + src/gallium/include/pipe/p_defines.h | 1 + src/gallium/include/pipe/p_state.h | 2 ++ src/mesa/glapi/glapi/gen/gl_API.xml | 4 ++++ src/mesa/main/consts_exts.h | 1 + src/mesa/main/enable.c | 14 ++++++++++++++ src/mesa/main/extensions_table.h | 1 + src/mesa/main/get_hash_params.py | 3 +++ src/mesa/main/mtypes.h | 2 ++ src/mesa/state_tracker/st_atom_rasterizer.c | 2 ++ src/mesa/state_tracker/st_extensions.c | 1 + 11 files changed, 32 insertions(+) diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst index c7c2b3b2b75..11e7073f793 100644 --- a/docs/gallium/screen.rst +++ b/docs/gallium/screen.rst @@ -653,6 +653,7 @@ Capability about the features and limits of the driver/GPU. * ``pipe_caps.shader_subgroup_quad_all_stages``: Whether shader subgroup quad operations are supported by shader stages other than fragment shader. * ``pipe_caps.multiview``: Whether multiview rendering of array textures is supported. A return of ``1`` indicates support for OVR_multiview, and ``2`` additionally supports OVR_multiview2. * ``pipe_caps.call_finalize_nir_in_linker``: Whether ``pipe_screen::finalize_nir`` can be called in the GLSL linker before the NIR is stored in the shader cache. It's always called again after st/mesa adds code for shader variants. It must be 1 if the driver wants to report compile failures to the GLSL linker. It must be 0 if two consecutive ``finalize_nir`` calls on the same shader can break it, or if ``finalize_nir`` can't handle NIR that isn't fully lowered for the driver, or if ``finalize_nir`` breaks passes that st/mesa runs after it. Setting it to 1 is generally safe for drivers that expose nir_io_has_intrinsics and that don't enable any optional shader variants in st/mesa. Since it's difficult to support, any future refactoring can change it to 0. +* ``pipe_caps.representative_fragment_test``: Support for GL_NV_representative_fragment_test. * ``pipe_caps.min_line_width``: The minimum width of a regular line. * ``pipe_caps.min_line_width_aa``: The minimum width of a smoothed line. * ``pipe_caps.max_line_width``: The maximum width of a regular line. diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 5f9065fc89c..3a89bde9dc3 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -1043,6 +1043,7 @@ struct pipe_caps { bool shader_subgroup_quad_all_stages; bool call_finalize_nir_in_linker; bool mesh_shader; + bool representative_fragment_test; int accelerated; int min_texel_offset; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 733d21ac6db..208ac317400 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -203,6 +203,8 @@ struct pipe_rasterizer_state */ unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES; + unsigned representative_fragment_test:1; + unsigned line_stipple_factor:8; /**< [1..256] actually */ unsigned line_stipple_pattern:16; diff --git a/src/mesa/glapi/glapi/gen/gl_API.xml b/src/mesa/glapi/glapi/gen/gl_API.xml index a592cfae909..aa5ddda68a0 100644 --- a/src/mesa/glapi/glapi/gen/gl_API.xml +++ b/src/mesa/glapi/glapi/gen/gl_API.xml @@ -9310,6 +9310,10 @@ + + + + diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index 526078f9ce3..57aaed546e3 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -288,6 +288,7 @@ struct gl_extensions GLboolean NV_viewport_array2; GLboolean NV_viewport_swizzle; GLboolean NV_timeline_semaphore; + GLboolean NV_representative_fragment_test; GLboolean NVX_gpu_memory_info; GLboolean TDFX_texture_compression_FXT1; GLboolean OES_EGL_image; diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index eae474f72a1..214684b8f57 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -616,6 +616,15 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state) ST_SET_STATE(ctx->NewDriverState, ST_NEW_RASTERIZER); ctx->ConservativeRasterization = state; break; + case GL_REPRESENTATIVE_FRAGMENT_TEST_NV: + if (!_mesa_has_NV_representative_fragment_test(ctx)) + goto invalid_enum_error; + if (ctx->RepresentativeFragmentTest == state) + return; + FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT); + ST_SET_STATE(ctx->NewDriverState, ST_NEW_RASTERIZER); + ctx->RepresentativeFragmentTest = state; + break; case GL_COLOR_LOGIC_OP: if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES) goto invalid_enum_error; @@ -1983,6 +1992,11 @@ _mesa_IsEnabled( GLenum cap ) goto invalid_enum_error; return ctx->ConservativeRasterization; + case GL_REPRESENTATIVE_FRAGMENT_TEST_NV: + if (!_mesa_has_NV_representative_fragment_test(ctx)) + goto invalid_enum_error; + return ctx->RepresentativeFragmentTest; + case GL_TILE_RASTER_ORDER_FIXED_MESA: if (!_mesa_has_MESA_tile_raster_order(ctx)) goto invalid_enum_error; diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h index cc6244878e6..d96a957ceb9 100644 --- a/src/mesa/main/extensions_table.h +++ b/src/mesa/main/extensions_table.h @@ -434,6 +434,7 @@ EXT(NV_read_buffer , dummy_true EXT(NV_read_depth , dummy_true , x , x , x , ES2, 2011) EXT(NV_read_depth_stencil , dummy_true , x , x , x , ES2, 2011) EXT(NV_read_stencil , dummy_true , x , x , x , ES2, 2011) +EXT(NV_representative_fragment_test , NV_representative_fragment_test , GLL, GLC, x , 32, 2019) EXT(NV_sample_locations , ARB_sample_locations , GLL, GLC, x , ES2, 2015) EXT(NV_shader_atomic_float , NV_shader_atomic_float , GLL, GLC, x , x , 2012) EXT(NV_shader_atomic_int64 , NV_shader_atomic_int64 , GLL, GLC, x , x , 2014) diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py index b670dc67883..9af400986f3 100644 --- a/src/mesa/main/get_hash_params.py +++ b/src/mesa/main/get_hash_params.py @@ -895,6 +895,9 @@ descriptor=[ [ "EDGE_FLAG_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride), NO_EXTRA" ], [ "EDGE_FLAG_ARRAY_COUNT_EXT", "CONST(0), NO_EXTRA" ], +# GL_NV_representative_fragment_test + [ "REPRESENTATIVE_FRAGMENT_TEST_NV", "CONTEXT_BOOL(RepresentativeFragmentTest), NO_EXTRA" ], + # GL_ARB_texture_compression [ "TEXTURE_COMPRESSION_HINT_ARB", "CONTEXT_ENUM16(Hint.TextureCompression), NO_EXTRA" ], diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 7214818f02e..484be1f09a0 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3589,6 +3589,8 @@ struct gl_context GLfloat ConservativeRasterDilate; GLenum16 ConservativeRasterMode; + GLboolean RepresentativeFragmentTest; /**< GL_REPRESENTATIVE_FRAGMENT_TEST_NV */ + GLboolean IntelBlackholeRender; /**< GL_INTEL_blackhole_render */ /** Does glVertexAttrib(0) alias glVertex()? */ diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index 160860d4463..8e536754c31 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -165,6 +165,8 @@ st_update_rasterizer(struct st_context *st) raster->poly_stipple_enable = ctx->Polygon.StippleFlag; + raster->representative_fragment_test = ctx->RepresentativeFragmentTest; + /* Multisampling disables point, line, and polygon smoothing. * * GL_ARB_multisample says: diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 02f9d4c523c..bbd3fd06a94 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -1146,6 +1146,7 @@ void st_init_extensions(struct pipe_screen *screen, EXT_CAP(NV_conditional_render, conditional_render); EXT_CAP(NV_fill_rectangle, polygon_mode_fill_rectangle); EXT_CAP(NV_primitive_restart, primitive_restart); + EXT_CAP(NV_representative_fragment_test, representative_fragment_test); EXT_CAP(NV_shader_atomic_float, image_atomic_float_add); EXT_CAP(NV_shader_atomic_int64, shader_atomic_int64); EXT_CAP(NV_texture_barrier, texture_barrier);