Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .sdk-revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56d67609927a7787900026e445fe63dea659ff3b
efda89f3e1ad50fe4cac20124ad8a89f75b1c002
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<PropertyGroup>
<DndBuildNative Condition="'$(DndBuildNative)' == ''">false</DndBuildNative>
<IsPackable>false</IsPackable>
<DolphinDotNetPackageVersion>0.1.0-preview.305.1</DolphinDotNetPackageVersion>
<DolphinDotNetPackageVersion>0.1.0-preview.315.1</DolphinDotNetPackageVersion>
<HypercubeNativePasses Condition="'$(HypercubeNativePasses)' == ''">true</HypercubeNativePasses>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
11 changes: 6 additions & 5 deletions docs/ordered-mesh-passes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions src/Hypercube.GameCube/OrderedMeshPasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Hypercube.GameCube;

/// <summary>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.</summary>
/// SDK MeshPasses replays cached indices with one native call by default.
/// HypercubeNativePasses=false retains the portable comparison path.</summary>
public sealed class OrderedMeshPasses
{
#if HYPERCUBE_NATIVE_PASSES
Expand Down
4 changes: 3 additions & 1 deletion tests/OrderedMeshPasses.Tests/OrderedMeshPasses.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType></PropertyGroup>
<PropertyGroup><OutputType>Exe</OutputType>
<DefineConstants Condition="'$(HypercubeNativePasses)' == 'true'">$(DefineConstants);HYPERCUBE_NATIVE_PASSES</DefineConstants>
</PropertyGroup>
<ItemGroup><Compile Include="../../src/Hypercube.GameCube/OrderedMeshPasses.cs" Link="OrderedMeshPasses.cs" /></ItemGroup>
</Project>
15 changes: 14 additions & 1 deletion tests/OrderedMeshPasses.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;}}
Expand All @@ -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<passes.Count;n++){int i=Calls++;if(FailAt==i)throw new InvalidOperationException();if(passes.Colors[n].Value!=i||passes.Uv[n].Value!=i)throw new Exception("Reordered native passes");}}
}
}
14 changes: 14 additions & 0 deletions tests/nuget_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class Program {static void Main(){var q=new OpaqueDrawQueue(2);q.TryAdd(1,2,0xff
compiler=work/'packages/dolphindotnet.sdk'/sdk/'tools/compiler/DolphinDotNet.Compiler.dll'
run('dotnet',str(compiler),'--bundle',str(app/'bin/Release/net8.0/GameCube.dll'),str(work/'native-consumer'))
if not (work/'native-consumer/source/generated_program.c').is_file():raise AssertionError('No consumer AOT bundle')
# Exercise the distributed default backend, rather than only compiling
# the stubbed contract test or the source-checkout adapter.
ordered=work/'Ordered';ordered.mkdir()
(ordered/'Ordered.csproj').write_text((app/'GameCube.csproj').read_text())
(ordered/'Program.cs').write_text('''using Dolphin.Graphics;using Hypercube.GameCube;
var vertices=new[]{new VertexPositionColorTexture(new Vector3(0,0,0),Color32.White,Vector2.Zero),new VertexPositionColorTexture(new Vector3(1,0,0),Color32.White,Vector2.Zero),new VertexPositionColorTexture(new Vector3(0,1,0),Color32.White,Vector2.Zero)};
using var mesh=Mesh.Create(vertices);using var texture=Texture2D.CreateNative(8,8,NativeTextureFormat.I8);
var passes=new OrderedMeshPasses(mesh,2);passes.Set(0,Color32.White,new UvTransform(Vector2.Zero,new Vector2(1,1)));
var renderer=new Renderer();var device=GraphicsDevice.Default;device.BeginFrame(Color32.Black);renderer.Begin3D(new Camera(60,4f/3,.1f,100));passes.Draw(renderer,new Material{Texture=texture},new Transform());renderer.End3D();device.EndFrame();
''')
run('dotnet','build',str(ordered),'-c','Release','-p:DndBuildNative=false')
run('dotnet',str(compiler),'--bundle',str(ordered/'bin/Release/net8.0/Ordered.dll'),str(work/'native-ordered'))
if 'dnd_mesh_draw_passes(' not in (work/'native-ordered/source/generated_program.c').read_text():
raise AssertionError('Published engine did not select SDK native ordered passes')
if args.native:
run('dotnet','build',str(app),'-c','Release','-p:DndBuildBackend=Docker')
if not list(app.rglob('*.dol')) or not list(app.rglob('*.elf')):raise AssertionError('No external native executable')
Expand Down
Loading