From 5ebb5b8772452f6144358bb12c7bd0443e3711ae Mon Sep 17 00:00:00 2001 From: BoiledElectricity Date: Mon, 15 Jun 2026 04:30:40 +0200 Subject: [PATCH] [opengl] query GL_MAX_CLIP_DISTANCES instead of hardcoding 8 (#4095) The GL shader profile hardcoded max_user_clip_distances to 8. Query the device limit like the Vulkan path already does (it reads maxClipDistances), so we use what the host actually reports. Clamp to Maxwell's NumClipDistances (8) since the guest never produces more than that and the SPIR-V output array is sized for at most 8. So a host reporting fewer than 8 is respected, and one reporting more can't overrun anything. Fixes #3910 https://git.eden-emu.dev/eden-emu/eden/issues/3910 Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4095 Reviewed-by: MaranBr Reviewed-by: Lizzie --- src/video_core/renderer_opengl/gl_device.cpp | 1 + src/video_core/renderer_opengl/gl_device.h | 7 ++++++- src/video_core/renderer_opengl/gl_shader_cache.cpp | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index 0829e6dd33..924ba2bbed 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp @@ -203,6 +203,7 @@ Device::Device(Core::Frontend::EmuWindow& emu_window) { max_varyings = GetInteger(GL_MAX_VARYING_VECTORS); max_compute_shared_memory_size = GetInteger(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE); max_glasm_storage_buffer_blocks = GetInteger(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS); + max_user_clip_distances = GetInteger(GL_MAX_CLIP_DISTANCES); has_warp_intrinsics = GLAD_GL_NV_gpu_shader5 && GLAD_GL_NV_shader_thread_group && GLAD_GL_NV_shader_thread_shuffle; has_shader_ballot = GLAD_GL_ARB_shader_ballot; diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h index 17b5a828f2..200e77e6e4 100644 --- a/src/video_core/renderer_opengl/gl_device.h +++ b/src/video_core/renderer_opengl/gl_device.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project @@ -47,6 +47,10 @@ public: return max_compute_shared_memory_size; } + u32 GetMaxUserClipDistances() const { + return max_user_clip_distances; + } + u32 GetMaxGLASMStorageBufferBlocks() const { return max_glasm_storage_buffer_blocks; } @@ -202,6 +206,7 @@ private: u32 max_varyings{}; u32 max_compute_shared_memory_size{}; u32 max_glasm_storage_buffer_blocks{}; + u32 max_user_clip_distances{}; bool has_warp_intrinsics{}; bool has_shader_ballot{}; diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index deedf1aa6b..a6aa7bf159 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -238,7 +238,11 @@ ShaderCache::ShaderCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, .ignore_nan_fp_comparisons = true, .gl_max_compute_smem_size = device.GetMaxComputeSharedMemorySize(), .min_ssbo_alignment = device.GetShaderStorageBufferAlignment(), - .max_user_clip_distances = 8, + // Use the host limit, but never more than the guest can produce. Maxwell exposes 8 clip + // distances and the SPIR-V output array is sized for at most 8, so clamping here keeps a + // host that reports a different count from under- or over-running that array. + .max_user_clip_distances = + std::min(device.GetMaxUserClipDistances(), Maxwell::Regs::NumClipDistances), }, host_info{ .support_float64 = true,