Campaign V slice V6d, commit 2 of 3. TextRenderer and DebugLineRenderer were the only two renderers speaking the RHI, and both refused any device that was not a GlGpuDevice. They now refuse nothing: this is the first production rendering acdream can do on Vulkan.
Three things had to go.
The loose uniforms. debug_line declared uView and uProjection separately and DebugLineRenderer set them straight against the compiled GL program, because the pinned push-constant block carries one combined matrix and IGpuPassEncoder has no verb for arbitrary named uniforms. That was never portable — Vulkan has no default uniform block at all — so the shader converged on uViewProjection and Flush multiplies on the CPU. System.Numerics is row-vector convention while GLSL reads the floats column-major, which transposes, so the CPU equivalent of the old per-vertex uProjection * uView is view * projection. The product now rounds once per frame rather than once per vertex; these lines only draw when collision wireframes are switched on, so the offline gate sees nothing of it. ui_text's uScreenSize became the block's two spare scalars, uParamA and uParamB, with the same two divisions and the same NDC mapping around them.
The sampling mode. uUseTexture selected between font coverage, RGBA modulate and flat colour, and no field of the 96-byte block means that. It did not need one: which of the two texture-table slots is assigned IS the mode. uTextureIndexB assigned means a single-channel coverage source, uTextureIndexA assigned means an RGBA colour source, neither assigned means the vertex colour alone. GpuTextureSlot.Unassigned is already a loud sentinel for exactly this kind of question, and both branches guard so it never reaches a sampler. That also retired the 1x1 white fill texture: DrawFill routed solid quads through the sprite bucket relying on white times colour, and the untextured branch produces the same value with no texture at all. Multiplying by 1.0 changes no bits, and the gate agrees.
The texture binding. The classic glActiveTexture/glBindTexture path survived V4a because DrawSprite takes an arbitrary texture from sixty-odd widget call sites. But TextureCache had already registered every one of those into the device's table — the classic path was consuming the raw GL name that registration also produced. The UI's currency is now UiTextureTableHandle, a one-based table index whose zero is the same "no texture" every widget already guards on; a raw slot index would have turned all of those guards into silent false negatives, since slot 0 is perfectly valid. One-based rather than the slot itself because GpuTextureSlot is internal to the pinned contract while UiRenderContext.DrawSprite, TextureCache.GetOrUploadRenderSurface and a dozen widget properties are public, and neither publishing a contract type nor converting the retained UI to internal belongs in this slice.
Two consequences worth stating. The two backends disagree about what a 2-D table entry is — GL reconstructs a sampler2D from the bindless handle, Vulkan reads layer 0 of its sampler2DArray descriptor array — and ACDREAM_SAMPLE_2D is the one place that lives. Keeping GL on sampler2D is what leaves the UI's textures exactly as they are, including the paperdoll/appraisal FBO colour texture, which is an externally-owned GL_TEXTURE_2D from the §7.1 transitional seam and cannot become an array before V4g. On the Vulkan side, sampled views are now always layered, which also removes a latent invalid usage V6c shipped: it registered a Type2D offscreen view into a descriptor array whose element type is sampler2DArray.
And one real fix. Sampling through the table means a bound sampler object overrides the texture's own parameters. Nearest-requested UI art used to get its point filtering from a glTexParameter applied before the bindless handle went resident, so registering it with the stock WorldRepeat sampler would have made every retail icon and dat-font glyph silently bilinear. Those now register with a nearest-and-repeat sampler.
Supporting moves: GlGpuDevice.CreatePipeline splices common.glsl the same way Shader does, since an RHI shader that reads the table needs the table declared; GlGpuPassEncoder binds the device's table with the pipeline, which is the GL analogue of Vulkan binding descriptor set 2 per draw, and has to be per-bind because every raw-GL world renderer puts its own privately-numbered table at that binding; and the encoder derives GL_MULTISAMPLE from the pass's SampleCount, which is where the retained UI's hand-rolled glDisable belonged all along. TextRenderGlStateScope is deleted — the encoder's ambient capture restored a strict superset of it — and its failure-safety test follows the guarantee to GlAmbientCapabilityState, which gains a fakeable seam and, with it, the multisample-dimension coverage #249 recorded as missing.
App tests 4,057 passed / 3 skipped, unchanged from commit 1. Offline pixel gate against 871c406b: differing fraction 2.31e-05, 13 pixels of 563,200 compared — below the documented 15-23 pixel same-commit noise band, on a change that redraws every pixel of the retained UI through a different sampling path. The capture was inspected: vitals, spell bar, radar, toolbar icons and slot digits, chat window and Send button all present and correctly placed. Both new .spv pairs compile; the manifest records ui_text and debug_line as Vulkan-ready, leaving six pairs blocked on the world-renderer slices.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
56 lines
3.4 KiB
GLSL
56 lines
3.4 KiB
GLSL
// Campaign V slice V2 shared preamble (docs/plans/2026-07-27-vulkan-campaign.md
|
|
// §3.4, §5.2). GL has no #include, so AcDream.App.Rendering.Shader
|
|
// concatenates this file's text into every shader source that opts in
|
|
// (Shader(gl, vertPath, fragPath, includeCommonPreamble: true)), inserted
|
|
// right after the leading #version / #extension block so it can declare new
|
|
// layout bindings and macros before the rest of the shader body runs.
|
|
//
|
|
// --- set 1 (uniform buffers) ------------------------------------------------
|
|
// GL keeps the SSBO and UBO binding-number namespaces separate, so today's
|
|
// SceneLighting UBO (binding=1) never collides with BatchBuffer's SSBO
|
|
// (also binding=1). Vulkan has ONE binding namespace per set, so the Vulkan
|
|
// backend (from V6 on) moves every uniform buffer to its own set (1) to keep
|
|
// both binding numbers. ACDREAM_UBO_SET is a no-op under GL today and is
|
|
// redefined to `set = 1,` when the same source is compiled for Vulkan, so
|
|
// applying it to every UBO layout now costs nothing and needs no source edit
|
|
// at the call sites later.
|
|
#define ACDREAM_UBO_SET
|
|
|
|
// --- set 0 binding 9 / set 2 (the global texture table) --------------------
|
|
// GL emulates Vulkan's set 2 variable-count sampled-texture descriptor array
|
|
// (GpuBindingModel.TextureTableSet) with a plain storage buffer of packed
|
|
// GL_ARB_bindless_texture handles at set 0 binding 9
|
|
// (GpuBindingModel.StorageTextureTable). A batch/pass no longer carries a
|
|
// 64-bit bindless handle directly into its GPU-visible struct; it carries a
|
|
// small integer slot index into this table instead, which is what makes the
|
|
// CPU-side data model backend-neutral (Campaign V slice V2). The table itself
|
|
// — and every per-renderer GL-side handle-slot allocator that fills it
|
|
// (WbDrawDispatcher, EnvCellRenderer, TerrainModernRenderer, ParticleRenderer)
|
|
// — is deleted once each renderer moves onto IGpuDevice's own retirement-gated
|
|
// table at V4c/V4d/V4e; see the campaign doc's §5.2 for why V2 cannot reach
|
|
// that table yet.
|
|
layout(std430, binding = 9) readonly buffer TextureTableBuf {
|
|
uvec2 gTextureTable[];
|
|
};
|
|
|
|
// Looks up the packed bindless handle for table slot `idx`. Callers still
|
|
// wrap the result in `sampler2DArray(...)` themselves at the use site (kept
|
|
// explicit rather than folded into one sampler-returning macro) because every
|
|
// existing call site already follows that exact pattern and a function cannot
|
|
// return an opaque sampler type built from a runtime value in GLSL.
|
|
#define ACDREAM_TEXTURE_HANDLE(idx) gTextureTable[idx]
|
|
|
|
// Campaign V slice V6d: samples a table slot that holds a plain 2-D texture.
|
|
//
|
|
// The two backends disagree about what a 2-D table entry IS, and this macro is
|
|
// the one place that difference lives. Under GL a bindless handle carries its
|
|
// own texture type, so a GL_TEXTURE_2D entry is reconstructed as a sampler2D
|
|
// and read with a 2-component UV. Under Vulkan the table is one descriptor
|
|
// array whose element type is fixed at sampler2DArray, so the same entry is a
|
|
// one-layer array read at layer 0 (see tools/ShaderCompiler/VulkanGlslPreamble.cs).
|
|
//
|
|
// That asymmetry is deliberate and is what keeps the retained UI's textures
|
|
// exactly as they are on GL — including the paperdoll/appraisal FBO colour
|
|
// texture, which is an externally-owned GL_TEXTURE_2D registered by the §7.1
|
|
// transitional seam and cannot be made an array before V4g moves its renderer.
|
|
#define ACDREAM_SAMPLE_2D(idx, uv) texture(sampler2D(gTextureTable[idx]), uv)
|