Revert "Campaign V slice V4a" - it lost world multisampling
This reverts ceec3bc4. Two independent reasons, either sufficient.
The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.
The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.
This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.
The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.
Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.
Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
ceec3bc440
commit
9aaf97e785
334 changed files with 3841 additions and 3661 deletions
|
|
@ -1,20 +1,20 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Silk.NET.OpenGL;
|
||||
using StbTrueTypeSharp;
|
||||
|
||||
namespace AcDream.App.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// A pixel-font atlas rasterized from a TTF at load time using stb_truetype.
|
||||
/// Glyphs are packed into a single-channel (R8) texture registered in the
|
||||
/// device's global texture table. Call <see cref="TryGetGlyph"/> to resolve an
|
||||
/// ASCII codepoint to UV + metrics.
|
||||
/// Glyphs are packed into a single-channel (R8) GL texture. Call
|
||||
/// <see cref="TryGetGlyph"/> to resolve an ASCII codepoint to UV + metrics.
|
||||
///
|
||||
/// Only printable ASCII (32..127) is supported for the debug overlay.
|
||||
/// </summary>
|
||||
internal sealed unsafe class BitmapFont : IDisposable
|
||||
public sealed unsafe class BitmapFont : IDisposable
|
||||
{
|
||||
internal readonly struct Glyph
|
||||
public readonly struct Glyph
|
||||
{
|
||||
public readonly float UvMinX;
|
||||
public readonly float UvMinY;
|
||||
|
|
@ -34,23 +34,23 @@ internal sealed unsafe class BitmapFont : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
private readonly GL _gl;
|
||||
private readonly Glyph[] _glyphs;
|
||||
private readonly int _firstChar;
|
||||
private readonly int _numChars;
|
||||
private readonly IGpuDevice _device;
|
||||
private readonly IGpuTexture _texture;
|
||||
private readonly ResourceCleanupGroup _resources;
|
||||
|
||||
public GpuTextureSlot TextureId { get; }
|
||||
public uint TextureId { get; }
|
||||
public float PixelHeight { get; }
|
||||
public float LineHeight { get; }
|
||||
public float Ascent { get; }
|
||||
public int AtlasWidth { get; }
|
||||
public int AtlasHeight { get; }
|
||||
|
||||
public BitmapFont(IGpuDevice device, byte[] ttfBytes, float pixelHeight,
|
||||
public BitmapFont(GL gl, byte[] ttfBytes, float pixelHeight,
|
||||
int atlasSize = 512, int firstChar = 32, int numChars = 96)
|
||||
{
|
||||
_device = device ?? throw new ArgumentNullException(nameof(device));
|
||||
_gl = gl;
|
||||
PixelHeight = pixelHeight;
|
||||
AtlasWidth = atlasSize;
|
||||
AtlasHeight = atlasSize;
|
||||
|
|
@ -96,31 +96,65 @@ internal sealed unsafe class BitmapFont : IDisposable
|
|||
adv: bc.xadvance);
|
||||
}
|
||||
|
||||
// Upload atlas as a single-channel texture (R8) and register it in the
|
||||
// device's global texture table. Linear + clamp-to-edge matches the
|
||||
// GL path's prior fixed sampler state exactly (mip filtering is moot —
|
||||
// the atlas is a single mip level).
|
||||
IGpuTexture texture = _device.CreateTexture(new GpuTextureDescription(
|
||||
"bitmap-font-atlas",
|
||||
GpuTextureKind.Texture2D,
|
||||
GpuTextureFormat.R8Unorm,
|
||||
Width: AtlasWidth,
|
||||
Height: AtlasHeight,
|
||||
LayerCount: 1,
|
||||
MipLevelCount: 1));
|
||||
// Upload atlas as a single-channel GL texture (R8). Publish the GL
|
||||
// name into the construction ledger before any later upload/state
|
||||
// command can fail.
|
||||
var resources = new ResourceCleanupGroup();
|
||||
uint texture = 0;
|
||||
try
|
||||
{
|
||||
texture.Upload(0, 0, pixels);
|
||||
IGpuSampler sampler = _device.CreateSampler(GpuSamplerDescription.WorldClamp);
|
||||
TextureId = _device.RegisterTexture(texture, sampler);
|
||||
texture = GlResourceCommand.CreateTexture(_gl, "BitmapFont atlas");
|
||||
uint ownedTexture = texture;
|
||||
resources.Add(
|
||||
"bitmap-font atlas",
|
||||
() => GlResourceCommand.DeleteTexture(
|
||||
_gl,
|
||||
ownedTexture,
|
||||
$"delete BitmapFont atlas {ownedTexture}"));
|
||||
_gl.GetInteger(GetPName.TextureBinding2D, out int previousTexture);
|
||||
_gl.GetInteger(GetPName.UnpackAlignment, out int previousAlignment);
|
||||
GlResourceCommand.Execute(_gl, "initialize BitmapFont atlas", () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_gl.BindTexture(TextureTarget.Texture2D, texture);
|
||||
_gl.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
fixed (byte* ptr = pixels)
|
||||
{
|
||||
_gl.TexImage2D(TextureTarget.Texture2D, 0,
|
||||
(int)InternalFormat.R8,
|
||||
(uint)AtlasWidth, (uint)AtlasHeight, 0,
|
||||
PixelFormat.Red, PixelType.UnsignedByte, ptr);
|
||||
}
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
|
||||
(int)TextureMinFilter.Linear);
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
|
||||
(int)TextureMagFilter.Linear);
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
|
||||
(int)TextureWrapMode.ClampToEdge);
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
|
||||
(int)TextureWrapMode.ClampToEdge);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_gl.PixelStore(
|
||||
PixelStoreParameter.UnpackAlignment,
|
||||
previousAlignment);
|
||||
_gl.BindTexture(
|
||||
TextureTarget.Texture2D,
|
||||
unchecked((uint)previousTexture));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch
|
||||
catch (Exception constructionFailure)
|
||||
{
|
||||
texture.Dispose();
|
||||
throw;
|
||||
resources.RollbackConstructionAndThrow(
|
||||
"BitmapFont construction failed and its GL atlas did not cleanly roll back.",
|
||||
constructionFailure);
|
||||
}
|
||||
|
||||
_texture = texture;
|
||||
TextureId = texture;
|
||||
_resources = resources;
|
||||
}
|
||||
|
||||
public bool TryGetGlyph(char c, out Glyph g)
|
||||
|
|
@ -149,8 +183,7 @@ internal sealed unsafe class BitmapFont : IDisposable
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
_device.ReleaseTextureSlot(TextureId);
|
||||
_texture.Dispose();
|
||||
_resources.RetryCleanup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue