From 2fcebbe5008ccd4f602df51ee50b6c5bcc9cc5b2 Mon Sep 17 00:00:00 2001 From: leroy ketelaars Date: Tue, 17 Nov 2026 10:19:49 +0100 Subject: [PATCH] feat: replay prepared frames for full-resolution GX AA --- .sdk-revision | 2 +- Directory.Build.props | 2 +- README.md | 3 +++ docs/full-resolution-aa.md | 17 ++++++++++++ src/Hypercube.GameCube/FrameRenderer.cs | 24 +++++++++++++++++ .../OrderedMeshPasses.Tests.csproj | 2 +- tests/OrderedMeshPasses.Tests/Program.cs | 26 +++++++++++++++++-- 7 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 docs/full-resolution-aa.md create mode 100644 src/Hypercube.GameCube/FrameRenderer.cs diff --git a/.sdk-revision b/.sdk-revision index 2f5376a..ad877f0 100644 --- a/.sdk-revision +++ b/.sdk-revision @@ -1 +1 @@ -d53a65890222868d2329792569770b2294cd828e +82335d3971d3d98a4f85d2993809c272a4b7b108 diff --git a/Directory.Build.props b/Directory.Build.props index 7644228..f23ed5f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ false false - 0.1.0-preview.328.1 + 0.1.0-preview.372.1 true net8.0 enable diff --git a/README.md b/README.md index c779cd6..1702cf4 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ Experimental GameCube engine built on [DolphinDotNet](https://github.com/capz/Do [Indexed mesh caching](docs/indexed-mesh-cache.md) retains exact native geometry prefixes for stable assets and shares terrain vertices without capacity padding. +[Full-resolution hardware AA](docs/full-resolution-aa.md) replays prepared scenes +through `FrameRenderer` without a frame-sized recording buffer. + Open **Hypercube.sln** for the engine, runtime adapter, host checks and console validation sample. The existing DolphinDotNet texture stress/comparison samples remain in the SDK repository. ## Build diff --git a/docs/full-resolution-aa.md b/docs/full-resolution-aa.md new file mode 100644 index 0000000..063fe3a --- /dev/null +++ b/docs/full-resolution-aa.md @@ -0,0 +1,17 @@ +# Full-resolution GameCube AA + +Set `DisplayOptions.AntialiasingMode` to `AntialiasingMode.FullResolution` +for 640×480 output. Implement `IFrameScene.SubmitFramePart` and pass the prepared +scene to `FrameRenderer.Draw`. It submits once with AA off and twice with full AA. + +Update simulation, animation, visibility and resource residency **before** Draw. +Submission may reset and refill bounded draw batches, but must not advance time, +load/release assets, change display mode or consume input. Render world and HUD +inside the callback. Capture water/refraction within each part, then draw it. +The SDK crops perspective, orthographic and 2D projections and maps scissors. + +Full AA uses hardware three-sample RGB565/Z16, without destination alpha. +It retains 640×480 logical resolution and the existing double XFB allocation; +there is no extra full-screen AA texture. Submission/geometry work repeats and +resolve copies cost bandwidth. Applications should offer a persisted off/on +option and measure their own scenes. This is independent of emulator host MSAA. diff --git a/src/Hypercube.GameCube/FrameRenderer.cs b/src/Hypercube.GameCube/FrameRenderer.cs new file mode 100644 index 0000000..d65c2e7 --- /dev/null +++ b/src/Hypercube.GameCube/FrameRenderer.cs @@ -0,0 +1,24 @@ +using Dolphin.Graphics; +namespace Hypercube.GameCube; + +/// A prepared scene whose drawing can be replayed without updating +/// simulation, animation, input or resource ownership. +public interface IFrameScene +{ + void SubmitFramePart(); +} + +/// Owns one logical frame. Full-resolution GX AA submits the prepared +/// scene twice, resolving overlapping EFB bands into the existing XFB pair. +/// No display-list recording, frame-sized allocation or per-frame delegate. +public static class FrameRenderer +{ + public static void Draw(GraphicsDevice device,Color32 clear,IFrameScene scene) + { + if(device==null)throw new ArgumentNullException(nameof(device)); + if(scene==null)throw new ArgumentNullException(nameof(scene)); + device.BeginFrame(clear); + do{scene.SubmitFramePart();}while(device.NextFramePart()); + device.EndFrame(); + } +} diff --git a/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj b/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj index f2305a5..b212db1 100644 --- a/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj +++ b/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj @@ -2,5 +2,5 @@ Exe $(DefineConstants);HYPERCUBE_NATIVE_PASSES - + diff --git a/tests/OrderedMeshPasses.Tests/Program.cs b/tests/OrderedMeshPasses.Tests/Program.cs index a4246f3..1d7ba1e 100644 --- a/tests/OrderedMeshPasses.Tests/Program.cs +++ b/tests/OrderedMeshPasses.Tests/Program.cs @@ -4,7 +4,23 @@ static class Program { static void Check(bool b){if(!b)throw new Exception("Pass contract failed");} static void Reject(Action a){try{a();}catch(ArgumentException){return;}catch(InvalidOperationException){return;}throw new Exception("Expected rejection");} - static void Main(){ + private sealed class PreparedScene:IFrameScene { + internal int Calls;internal int Snapshot=17; + public void SubmitFramePart(){if(!GraphicsDevice.Default.IsFrameActive||Snapshot!=17)throw new Exception("Unprepared scene");Calls++;} + } + static void Frames(){ + var d=GraphicsDevice.Default;var scene=new PreparedScene(); + foreach(int parts in new[]{1,2}){ + d.Parts=parts;d.Begins=d.Presents=scene.Calls=0; + FrameRenderer.Draw(d,Color32.White,scene); + Check(d.Begins==1&&d.Presents==1&&scene.Calls==parts&&!d.IsFrameActive); + long before=GC.GetAllocatedBytesForCurrentThread(); + for(int n=0;n<1000;n++)FrameRenderer.Draw(d,Color32.White,scene); + Check(GC.GetAllocatedBytesForCurrentThread()==before); + } + Console.WriteLine("Prepared frame replay: single presentation, one/two scene submissions and zero allocations passed."); + } + static void Main(){Frames(); var mesh=new Mesh();Reject(()=>new OrderedMeshPasses(mesh,0));Reject(()=>new OrderedMeshPasses(mesh,257)); var p=new OrderedMeshPasses(mesh,3);var m=new Material{Texture=new Texture2D(),Color=new Color32(9),TextureTransform=new UvTransform(9)};var r=new Renderer();var t=new Transform(); for(int i=0;i<3;i++)p.Set(i,new Color32(i),new UvTransform(i)); @@ -32,7 +48,13 @@ public sealed class MeshPasses{ public enum LightingMode{Unlit,Diffuse}public enum TextureCoordinateMode{Uv0,ViewNormal} public readonly struct Color32{public readonly int Value;public Color32(int v){Value=v;}public static Color32 White=>new(255);} public readonly struct UvTransform{public readonly int Value;public UvTransform(int v){Value=v;}} - public sealed class GraphicsDevice{public static readonly GraphicsDevice Default=new();public bool IsFrameActive;} + public sealed class GraphicsDevice{ + public static readonly GraphicsDevice Default=new();public bool IsFrameActive; + public int Parts=1,Begins,Presents,Part; + public void BeginFrame(Color32 clear){if(IsFrameActive)throw new InvalidOperationException();IsFrameActive=true;Part=0;Begins++;} + public bool NextFramePart(){if(!IsFrameActive)throw new InvalidOperationException();return ++Part