diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 6c8471c..3e622c7 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v4 with: repository: capz/DolphinDotNet - ref: f5dbd0a69c762708875890b5be73116f64589e4b + ref: efda89f3e1ad50fe4cac20124ad8a89f75b1c002 path: vendor/sdk - uses: actions/setup-dotnet@v4 with: @@ -30,7 +30,9 @@ jobs: with: python-version: '3.12' - name: Test ordered mesh pass contracts - run: dotnet run --project tests/OrderedMeshPasses.Tests -c Release + run: | + dotnet run --project tests/OrderedMeshPasses.Tests -c Release + dotnet run --project tests/OrderedMeshPasses.Tests -c Release -p:HypercubeNativePasses=false - name: Build and test packed assets, scheduler and GameCube executable env: CONFIGURATION: ${{ matrix.configuration }} diff --git a/.sdk-revision b/.sdk-revision index c583e60..ec601f1 100644 --- a/.sdk-revision +++ b/.sdk-revision @@ -1 +1 @@ -56d67609927a7787900026e445fe63dea659ff3b +efda89f3e1ad50fe4cac20124ad8a89f75b1c002 diff --git a/Directory.Build.props b/Directory.Build.props index 760a900..dcaa848 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,8 @@ false false - 0.1.0-preview.305.1 + 0.1.0-preview.315.1 + true net8.0 enable enable diff --git a/docs/ordered-mesh-passes.md b/docs/ordered-mesh-passes.md index 8a40f1f..c8ba54a 100644 --- a/docs/ordered-mesh-passes.md +++ b/docs/ordered-mesh-passes.md @@ -13,12 +13,12 @@ a private working material during construction, so even a caller material with untouched lazy sampler/UV state cannot allocate in the first draw. The mesh and texture remain owned by the caller and must remain alive through the draw. -The published-SDK build uses the ordered portable loop. With the source SDK PR -that adds `MeshPasses`, build `Hypercube.GameCube` with -`-p:HypercubeNativePasses=true` and `-p:DolphinDotNetRoot=/path/to/sdk`. -That path stores variants once, prepares an aligned POS/UV index command list +The published package uses SDK 315's native `MeshPasses` backend by default. +Source builds use the same SDK revision recorded in `.sdk-revision`. +The backend stores variants once, prepares an aligned POS/UV index command list between frames, validates once per block and replays it natively. It saves CPU submission; it does not promise less GPU work. Neither path allocates during draw. +Use `-p:HypercubeNativePasses=false` to build the portable comparison backend. ```csharp var blur = new OrderedMeshPasses(panelMesh, 81); @@ -30,7 +30,8 @@ blur.Draw(renderer, backdropMaterial, identity); Run `dotnet run --project tests/OrderedMeshPasses.Tests -c Release` for portable ordering, validation, exceptional state restoration and allocation checks. -The source-SDK backend is also exercised by the real VideoMode integration DOL: +Run the same test with `-p:HypercubeNativePasses=false` for the portable backend. +The native backend is also exercised by the real VideoMode integration DOL: ``` python3 ci/build_videomode_source_sdk.py --sdk /path/to/DolphinDotNet \ diff --git a/src/Hypercube.GameCube/OrderedMeshPasses.cs b/src/Hypercube.GameCube/OrderedMeshPasses.cs index fdefbed..2ce89eb 100644 --- a/src/Hypercube.GameCube/OrderedMeshPasses.cs +++ b/src/Hypercube.GameCube/OrderedMeshPasses.cs @@ -3,8 +3,8 @@ namespace Hypercube.GameCube; /// Ordered color/UV variants of borrowed, uniform-color geometry. /// Configure between frames. Transparent passes keep their authored order. -/// Set HypercubeNativePasses=true when building against the source SDK that -/// provides MeshPasses to replay cached indices with one native call. +/// SDK MeshPasses replays cached indices with one native call by default. +/// HypercubeNativePasses=false retains the portable comparison path. public sealed class OrderedMeshPasses { #if HYPERCUBE_NATIVE_PASSES diff --git a/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj b/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj index 5ba6cd2..f2305a5 100644 --- a/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj +++ b/tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj @@ -1,4 +1,6 @@ - Exe + Exe + $(DefineConstants);HYPERCUBE_NATIVE_PASSES + diff --git a/tests/OrderedMeshPasses.Tests/Program.cs b/tests/OrderedMeshPasses.Tests/Program.cs index 0570c12..a4246f3 100644 --- a/tests/OrderedMeshPasses.Tests/Program.cs +++ b/tests/OrderedMeshPasses.Tests/Program.cs @@ -10,6 +10,11 @@ static void Main(){ for(int i=0;i<3;i++)p.Set(i,new Color32(i),new UvTransform(i)); GraphicsDevice.Default.IsFrameActive=true;Reject(()=>p.Set(0,new Color32(0),default));GraphicsDevice.Default.IsFrameActive=false; p.Draw(r,m,t);Check(r.Calls==3&&m.Color.Value==9&&m.TextureTransform.Value==9); +#if HYPERCUBE_NATIVE_PASSES + Check(r.NativeCalls==1); +#else + Check(r.NativeCalls==0); +#endif r.Calls=0;r.FailAt=1;try{p.Draw(r,m,t);}catch(InvalidOperationException){}Check(r.Calls==2&&m.Color.Value==9&&m.TextureTransform.Value==9); r.FailAt=-1;r.Calls=0;m.SecondaryTexture=new Texture2D();Reject(()=>p.Draw(r,m,t));Check(r.Calls==0);m.SecondaryTexture=null; var cold=new Material{Texture=m.Texture};p.Draw(r,m,t);r.Calls=0;long before=GC.GetAllocatedBytesForCurrentThread();for(int i=0;i<1000;i++){p.Draw(r,cold,t);r.Calls=0;}Check(GC.GetAllocatedBytesForCurrentThread()==before); @@ -19,6 +24,11 @@ static void Main(){ namespace Dolphin.Graphics { public sealed class Mesh{}public sealed class Texture2D{}public sealed class Transform{} + public sealed class MeshPasses{ + internal readonly Color32[] Colors;internal readonly UvTransform[] Uv;public int Count=>Colors.Length; + public MeshPasses(Mesh mesh,int count){if(GraphicsDevice.Default.IsFrameActive)throw new InvalidOperationException();Colors=new Color32[count];Uv=new UvTransform[count];} + public void Set(int i,Color32 color,UvTransform uv){Colors[i]=color;Uv[i]=uv;} + } 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;}} @@ -31,5 +41,8 @@ public sealed class Material{ public UvTransform TextureTransform{get=>uv;set{uv=value;options??=new float[40];}} public SamplerState Sampler{get=>sampler;set{sampler=value;options??=new float[40];}} } - public sealed class Renderer{public int Calls,FailAt=-1;public void DrawMesh(Mesh mesh,Material m,Transform t){int i=Calls++;if(FailAt==i)throw new InvalidOperationException();if(m.Color.Value!=i||m.TextureTransform.Value!=i)throw new Exception("Reordered passes");}} + public sealed class Renderer{public int Calls,NativeCalls,FailAt=-1; + public void DrawMesh(Mesh mesh,Material m,Transform t){int i=Calls++;if(FailAt==i)throw new InvalidOperationException();if(m.Color.Value!=i||m.TextureTransform.Value!=i)throw new Exception("Reordered passes");} + public void DrawMeshPasses(MeshPasses passes,Material m,Transform t){NativeCalls++;for(int n=0;n