From 4d1a7977cbadb7fe7f04e0b80ef4315865f5c077 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 8 May 2026 19:31:02 +0200 Subject: [PATCH] phase(N.5) Task 1: ArbBindlessTexture wrapper + capability detection Adds Silk.NET.OpenGL.Extensions.ARB 2.23.0 package and a thin BindlessSupport wrapper exposing GetResidentHandle / MakeNonResident / HasShaderDrawParameters. TryCreate returns false if the bindless extension isn't present, letting WbFoundationFlag fall back to legacy. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/AcDream.App/AcDream.App.csproj | 1 + .../Rendering/Wb/BindlessSupport.cs | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/AcDream.App/Rendering/Wb/BindlessSupport.cs diff --git a/src/AcDream.App/AcDream.App.csproj b/src/AcDream.App/AcDream.App.csproj index e93dab8..84eb67a 100644 --- a/src/AcDream.App/AcDream.App.csproj +++ b/src/AcDream.App/AcDream.App.csproj @@ -14,6 +14,7 @@ + diff --git a/src/AcDream.App/Rendering/Wb/BindlessSupport.cs b/src/AcDream.App/Rendering/Wb/BindlessSupport.cs new file mode 100644 index 0000000..25b7241 --- /dev/null +++ b/src/AcDream.App/Rendering/Wb/BindlessSupport.cs @@ -0,0 +1,67 @@ +using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Extensions.ARB; + +namespace AcDream.App.Rendering.Wb; + +/// +/// Thin wrapper around + capability detection +/// for the modern rendering path. Constructed once at startup. Throws if the +/// extension isn't available — callers must check +/// before constructing for production use. +/// +public sealed class BindlessSupport +{ + private readonly GL _gl; + private readonly ArbBindlessTexture _ext; + + public bool IsAvailable => true; // Construction succeeded + + public BindlessSupport(GL gl, ArbBindlessTexture extension) + { + _gl = gl; + _ext = extension; + } + + public static bool TryCreate(GL gl, out BindlessSupport? support) + { + if (gl.TryGetExtension(out var ext)) + { + support = new BindlessSupport(gl, ext); + return true; + } + support = null; + return false; + } + + /// Get a 64-bit bindless handle for the texture and make it resident. + /// Idempotent: handle is the same for a given texture name. + public ulong GetResidentHandle(uint textureName) + { + ulong h = _ext.GetTextureHandle(textureName); + if (!_ext.IsTextureHandleResident(h)) + _ext.MakeTextureHandleResident(h); + return h; + } + + /// Release residency for a handle. Call before deleting the underlying texture. + public void MakeNonResident(ulong handle) + { + if (_ext.IsTextureHandleResident(handle)) + _ext.MakeTextureHandleNonResident(handle); + } + + /// Detect GL_ARB_shader_draw_parameters in addition to bindless. + /// N.5's vertex shader uses gl_BaseInstanceARB and gl_DrawIDARB + /// from this extension. + public bool HasShaderDrawParameters(GL gl) + { + int n = 0; + gl.GetInteger(GLEnum.NumExtensions, out n); + for (int i = 0; i < n; i++) + { + string ext = gl.GetStringS(StringName.Extensions, (uint)i); + if (ext == "GL_ARB_shader_draw_parameters") return true; + } + return false; + } +}