Amendment 3 of three: the paperdoll and creature-appraisal views render on the
Vulkan arm. Plan section 5.5.16 defect 3 named two backend fixes as the
precondition; both are here, and running it found two more the note could not
have known about.
Fix 1: a layered sampled view per render target. An ATTACHMENT view must be
VK_IMAGE_VIEW_TYPE_2D and the global texture table's descriptor array is
sampler2DArray, so the attachment view cannot legally be registered into it -
section 5.5.7 recorded that as invalid usage rather than a mismatch that samples
oddly, and V6k made RegisterTexture refuse it loudly and name this fix.
VulkanGpuTexture now creates a SECOND, layered view over the same image for a
colour render target: one image, one allocation, two ways of looking at it,
legal without any creation flag. SampledView is what the table registers for
every texture, so the question disappears rather than being answered.
Fix 2: sample-count pipeline variants for WbDrawDispatcher. Vulkan requires a
pipeline's rasterizationSamples to equal the pass it draws in, and this
dispatcher draws in two passes with different counts - the multisampled
backbuffer world pass and the single-sampled offscreen target, which the
contract fixes at one sample. Its five pipelines became a MeshPipelineSet with
two instances, selected at bind time from the live pass rather than from the
scope, which is the same shape section 5.5.8 gave the depth-format problem. When
the backbuffer is single-sampled the two sets are one object, so nothing is
built twice and nothing is freed twice. The offscreen target's DEPTH attachment
also had to take the device's own combined depth/stencil format rather than the
contract enum's literal D24_UNORM_S8_UINT: a pipeline bakes one depth/stencil
format under dynamic rendering and the same pipelines draw in both passes, so a
second format would make one of the two undefined.
Fix 3, which running it found: entity APPEARANCE composites were still
bindless-only, so no entity with a palette override could be drawn on the Vulkan
arm at all - the doll being one, and every creature and player besides. The
backend that serves it has existed since V6i-2 and had no production consumer;
it has one now. TextureCache builds the composite cache on both arms, and
EnsureCompositeTexturesAvailable stops asking about bindless. Nothing about the
cache itself changed: the sharing, the bounded unowned LRU, the metered upload
budget and the retirement fence were already backend-neutral.
Fix 4, which the first successful capture found: the doll rendered upside down.
UiViewport has flipped V since V4a because a GL framebuffer's origin is
bottom-left, so its colour texture samples bottom-up. A Vulkan image's origin is
top-left and the backend's negative viewport height stores the rendered image
that way round, so the same flip stands the doll on its head. That is a property
of the backend that made the texture, not of the widget that draws it, so
IUiViewportRenderer answers TextureIsBottomUp and UiViewport asks. The line this
replaces had predicted exactly this failure since it was written.
The seam. WbDrawDispatcher's RHI arm borrows its pass from IWorldPassScope
rather than opening one, so a viewport that opens a pass of its own has to
publish it there for the span of the draw. Publish is on the interface now for
that. It does not nest: the world phase has closed its own pass by the time
private presentation runs, which is where these viewports have always drawn.
Gates. Release build green. App tests 4,129/3 skips; complete Release suite
9,192/5 (one solution-wide run reported a single App failure that did not
reproduce in the App suite alone or in a second solution-wide run - the
documented rerun-singly flake class; the failing test name was not surfaced by
the runner and is not carried forward as a claim). Strict GL offline pixel gate
against 08ffe141: 3.55e-05, 20 differing pixels of 563,200, inside the
documented 9-31 band. GL connected -Runs 3: 3/3 RENDERED on the desktop witness
and 3/3 on the client capture. One offline Vulkan run with
VK_LAYER_KHRONOS_validation proven inserted by the loader: zero validation
errors, zero warnings.
And the two captures the offline gate cannot reach, both connected and both
inspected. The Vulkan paperdoll (artifacts/v6l-vk-paperdoll3) renders the doll
upright, in armour, at the right scale, over a transparent background, and is
indistinguishable from the same capture on GL taken minutes later
(artifacts/v6l-gl-paperdoll) - which is also the no-regression check for the V
change. Particles (artifacts/v6l-vk-poi versus artifacts/v6l-gl-poi, cropped
4x at artifacts/crop-vk-glow.png and crop-gl-glow.png): Holtburg's forge plume
and its field of glint sprites draw in the same places with the same alpha
compositing on both backends, the puffs differing only in phase because two
launches cannot agree on an emitter's age.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
70 lines
3.4 KiB
C#
70 lines
3.4 KiB
C#
using System.Numerics;
|
|
using AcDream.App.Rendering.Gpu;
|
|
|
|
namespace AcDream.App.UI;
|
|
|
|
/// <summary>Leaf widget for dat Type 0xD (UIElement_Viewport). Blits the texture produced by its
|
|
/// IUiViewportRenderer (run in the pre-UI hook) as a single sprite at its own rect. The 3-D render
|
|
/// does NOT happen here (OnDraw only has a 2-D context).</summary>
|
|
public sealed class UiViewport : UiElement
|
|
{
|
|
public override bool ConsumesDatChildren => true;
|
|
|
|
/// <summary>Optional click action. Non-null makes the viewport handle the press
|
|
/// itself instead of it being captured as a window move.</summary>
|
|
public System.Action? Clicked { get; set; }
|
|
/// <summary>Position-aware variant with viewport-local pixel coordinates.</summary>
|
|
public System.Action<int, int>? ClickedAt { get; set; }
|
|
|
|
public override bool HandlesClick => Clicked is not null || ClickedAt is not null;
|
|
|
|
public override bool OnEvent(in UiEvent e)
|
|
{
|
|
if (Clicked is null && ClickedAt is null) return base.OnEvent(e);
|
|
switch (e.Type)
|
|
{
|
|
case UiEventType.MouseDown: return true; // consume the press; act on Click
|
|
case UiEventType.Click:
|
|
Clicked?.Invoke();
|
|
ClickedAt?.Invoke(e.Data1, e.Data2);
|
|
return true;
|
|
}
|
|
return base.OnEvent(e);
|
|
}
|
|
|
|
/// <summary>Renderer that produces the off-screen texture. Set by GameWindow wiring (later task).</summary>
|
|
public IUiViewportRenderer? Renderer { get; set; }
|
|
|
|
/// <summary>
|
|
/// Campaign V slice V4a: the off-screen FBO colour texture produced by the
|
|
/// pre-UI hook, registered into the device's texture table by the
|
|
/// pre-approved paperdoll/appraisal transitional seam
|
|
/// (<c>GlGpuDevice.RegisterExternalColorTexture</c>, campaign doc §7.1) —
|
|
/// its owning renderer (<c>PrivateEntityViewportRenderer</c>) stays raw GL
|
|
/// until V4g. <see cref="GpuTextureSlot.Unassigned"/> = nothing to blit.
|
|
/// internal, not public: <see cref="GpuTextureSlot"/> is an internal type
|
|
/// (the pinned RHI contract); UiViewport stays public.
|
|
/// </summary>
|
|
internal GpuTextureSlot TextureSlot { get; set; } = GpuTextureSlot.Unassigned;
|
|
|
|
protected override void OnDraw(UiRenderContext ctx)
|
|
{
|
|
if (!Visible || !TextureSlot.IsAssigned) return;
|
|
uint textureHandle = AcDream.App.Rendering.TextRenderer.ResolveExternalTextureSlot(TextureSlot);
|
|
if (textureHandle == 0) return;
|
|
// Local origin is already at this widget's Left/Top (PushTransform applied by DrawSelfAndChildren).
|
|
//
|
|
// V depends on the backend that produced the texture, and slice V6l is
|
|
// where that stopped being a constant. A GL off-screen FBO colour texture
|
|
// has a BOTTOM-LEFT origin while the UI sprite convention is top-left, so
|
|
// its V is flipped (v0=1, v1=0) — without that the doll renders
|
|
// upside-down, which is what the line this replaces had always said. A
|
|
// Vulkan render target has a top-left origin and needs no flip; applying
|
|
// one drew the doll on its head in the first Vulkan capture. The renderer
|
|
// that made the texture is the one that knows.
|
|
bool bottomUp = Renderer?.TextureIsBottomUp ?? true;
|
|
float v0 = bottomUp ? 1f : 0f;
|
|
float v1 = bottomUp ? 0f : 1f;
|
|
ctx.DrawSprite(textureHandle, 0f, 0f, Width, Height, 0f, v0, 1f, v1, Vector4.One);
|
|
}
|
|
}
|