Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

[opengl] query GL_MAX_CLIP_DISTANCES instead of hardcoding 8 (#4095)

BoiledElectricity5ebb5b877245
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<u32>(GL_MAX_VARYING_VECTORS);
max_compute_shared_memory_size = GetInteger<u32>(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE);
max_glasm_storage_buffer_blocks = GetInteger<u32>(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS);
+ max_user_clip_distances = GetInteger<u32>(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<u32>(device.GetMaxUserClipDistances(), Maxwell::Regs::NumClipDistances),
},
host_info{
.support_float64 = true,