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
14 changes: 14 additions & 0 deletions .github/workflows/nuget-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: sdk
run: echo "revision=$(cat .sdk-revision)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
if: github.event_name == 'pull_request'
with:
repository: capz/DolphinDotNet
ref: ${{ steps.sdk.outputs.revision }}
path: vendor/sdk
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
Expand All @@ -35,7 +43,11 @@ jobs:
- id: version
run: echo "version=0.1.0-preview.${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}" >> "$GITHUB_OUTPUT"
- name: Pack against the published SDK
if: github.event_name != 'pull_request'
run: python3 eng/pack.py --version '${{ steps.version.outputs.version }}'
- name: Verify the exact pinned SDK before its release
if: github.event_name == 'pull_request'
run: python3 eng/pack.py --sdk-source vendor/sdk --version '${{ steps.version.outputs.version }}'
- name: Verify relocated packages and external consumers
run: python3 tests/nuget_consumer.py --workspace "$RUNNER_TEMP/external engine consumer" --native
- uses: actions/upload-artifact@v4
Expand All @@ -44,6 +56,7 @@ jobs:
path: |
out/packages/*.nupkg
out/packages/packages.json
out/packages/sdk-feed/*.nupkg
if-no-files-found: error
publish:
if: startsWith(github.ref, 'refs/tags/nuget-preview-') || (github.event_name == 'workflow_dispatch' && inputs.publish && github.ref == 'refs/heads/main')
Expand All @@ -70,6 +83,7 @@ jobs:
env:
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
run: |
python3 -c 'import json; assert not json.load(open("packages/packages.json")).get("sdkSourcePreview"), "Publish the pinned SDK before distributing engine packages"'
test -n "$NUGET_API_KEY"
dotnet nuget push packages/Capz.Hypercube.Core.*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate
dotnet nuget push packages/Capz.Hypercube.GameCube.*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate
48 changes: 47 additions & 1 deletion .github/workflows/progressive-textures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,61 @@ permissions:
jobs:
contracts:
runs-on: ubuntu-24.04
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- id: sdk
run: echo "revision=$(cat .sdk-revision)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: capz/DolphinDotNet
ref: ${{ steps.sdk.outputs.revision }}
path: vendor/sdk
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python3 tests/progressive_fixtures.py
- run: python3 -m unittest discover -s tests -p test_progressive_textures.py
- run: python3 -m unittest discover -s tests -p 'test_progressive*.py'
- run: dotnet run --project tests/TextureFamilies.Tests -c Debug
- run: dotnet run --project tests/TextureFamilies.Tests -c Release
- run: python3 tools/test_progressive_runtime.py
dolphin:
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
configuration: [Debug, Release]
steps:
- uses: actions/checkout@v4
- id: sdk
run: echo "revision=$(cat .sdk-revision)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: capz/DolphinDotNet
ref: ${{ steps.sdk.outputs.revision }}
path: vendor/sdk
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- run: tools/build_progressive.sh
env:
CONFIGURATION: ${{ matrix.configuration }}
- run: docker build -t hypercube-progressive -f tools/Dockerfile.dolphin .
- run: >-
docker run --rm --init --shm-size=1g
--mount "type=bind,src=$PWD,dst=/work" -w /work hypercube-progressive
python3 tools/progressive_validation.py out/native-progressive-${{ matrix.configuration }}/Game.dol
--disc out/progressive/textures.iso --logs out/dolphin-progressive-${{ matrix.configuration }} --seconds 60
- uses: actions/upload-artifact@v4
if: always()
with:
name: progressive-${{ matrix.configuration }}
path: |
out/dolphin-progressive-${{ matrix.configuration }}/results.json
out/dolphin-progressive-${{ matrix.configuration }}/states.json
out/dolphin-progressive-${{ matrix.configuration }}/*.png
out/dolphin-progressive-${{ matrix.configuration }}/*.log
4 changes: 3 additions & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ jobs:
configuration: [Debug, Release]
steps:
- uses: actions/checkout@v4
- id: sdk
run: echo "revision=$(cat .sdk-revision)" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
repository: capz/DolphinDotNet
ref: f5dbd0a69c762708875890b5be73116f64589e4b
ref: ${{ steps.sdk.outputs.revision }}
path: vendor/sdk
- uses: actions/setup-dotnet@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .sdk-revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
858577c63aaf191fce7c83fd4308075d3775f43a
dd8a187b9c35d526b479511846a92bef5873fb29
Binary file added docs/measurements/progressive/coarse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/measurements/progressive/fine-dual-uv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions docs/measurements/progressive/phase-four-dolphin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"platform": "Dolphin",
"hardwarePerformanceClaim": false,
"sampledFrames": 325,
"last": {
"magic": 18516,
"phase": 10,
"frame": 1945,
"publications": 8,
"crcFailures": 1,
"failures": 2,
"stale": 25,
"active32": 0,
"upload32": 0,
"retired32": 0,
"aram32": 0,
"coarseMask": 15,
"deferred": 2,
"retirements": 8,
"frame99ms": 17,
"aramHits": 25,
"detailMask": 0,
"peakKiB": 652,
"audioActive": 1,
"coarseReady": 5,
"detailReady": 7,
"coarseMeanMs": 164,
"detailMeanMs": 203,
"maxPumpUs": 2378,
"storageKiB": 1190,
"coldKiB": 14,
"uploadedKiB": 1171,
"cancelled": 26,
"frame95ms": 17,
"readBufferKiB": 0,
"poolBytes": 0,
"checksum": 17474
},
"coarsePixelFrames": 5,
"fineDualUvPixelFrames": 9,
"pixelPatches": 12,
"audio": [
{
"file": "ID-Game_2026-11-11_12-17-39_dspdump1.wav",
"seconds": 32.675180050788896,
"activeWindows": 327,
"longestQuietMs": 0
}
],
"implementationRevision": "334e80307cb9b54f6009aa4e1286c5083a2fc4d8",
"sdkRevision": "dd8a187b9c35d526b479511846a92bef5873fb29",
"dolSha256": "30a1d1bd7bc3dc24ade989a04e5d173f82a4f070d2eb4189aff2c833aa579cb6",
"packSha256": "1ad90536c358b56ed773c9f822231fc0026b8765608460a723ba404d131bfcad"
}
107 changes: 107 additions & 0 deletions docs/progressive-textures.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,110 @@ Run `python3 tests/progressive_fixtures.py`,
`python3 -m unittest discover -s tests -p test_progressive_textures.py` and
`dotnet run --project tests/TextureFamilies.Tests -c Release` for format,
corruption, alpha-preserving native import, selection and request-churn checks.

## Streaming and draw ownership

```csharp
using var source = new PackedAssetSource("dvd:/materials.hcp");
using var lods = new TextureLodStreamer(source.Catalog, source.Assets,
budgetBytes: 2 * 1024 * 1024);
var grass = lods.Get("terrain/grass", TextureQualityPolicy.DistanceMip);
var draw = new StreamedMaterialBinding(lods, authoredMaterial, grass);

// Each frame, between GPU submissions:
lods.BeginFrame(frame, completedFrame);
lods.Demand(grass, TextureFootprint.Project(width, height, distance, radius,
fovDegrees, viewportHeight, repeatsU, repeatsV));
lods.Pump(uploadBudgetBytes: 32768, cpuBudgetUs: 1000);
device.BeginFrame(clear);
renderer.Begin3D(camera);
draw.Draw(renderer, meshWithNormalizedUvs, transform, frame);
renderer.End3D();
lods.EndFrame(device.InsertFence());
device.EndFrame();
```

Resolve/pin at actual submission; keep bindings in queued commands and resolve
when executing them. `SortKey()` includes both family identities and resident
generations; refresh it each frame and combine it with effect/blend/material
state. A stale `ResolvedTextureLod` fails `Pin`. The binding copies its shared
template's state into a private material and composes authored animation before
the resident level's usable UV rectangle for both texture slots. The complete
affine matrix preserves rotated animation with unequal U/V gutters.

Geometry uses normalized source UVs. Repeated standalone textures should have
no atlas gutter; a padded atlas rectangle expects coordinates within that
rectangle (split tiled geometry at repeat boundaries). GX repeat wraps the
whole physical image. `TerrainUv` exposes the old tile mapping for normalized
terrain meshes without baking a selected texture level into geometry.

Every family becomes usable at coarse first. An upgrade is queued only after
the coarse image was pinned into a submitted frame. One private destination is
read in bounded native chunks, staged by the SDK service executor, checked by
incremental CRC, and published on the application executor. Cancellation joins
reads, copies and ARAM users before reusing the staging buffer or freeing the
destination. A superseded scheduler generation cannot publish. Budget rejection,
CRC failure and short reads preserve the old image and use scheduler retry
backoff. GPU fences, rather than promotion-time GPU waits, retire old images.

`ActiveBytes`, `UploadBytes`, `ReadBufferBytes`, `RetiredBytes`, `PoolBytes`,
`PhysicalBytes` and `AramBytes` are separate counters. Standalone streams own a
32-KiB native read buffer; a world-integrated stream shares the existing 128-KiB
buffer. The physical cap includes transient destination, retired images and
placeholder. ARAM has its own cap and is not GX-visible memory. `PeakBytes`
records physical texture peaks; counts include the minimum native tile padding.
The byte budget bounds each chunk; the CPU budget bounds issuing more work.
A single native allocation, CRC slice or copy cannot be preempted.

The optional ARAM tier retains complete records that fit a single read chunk;
larger images remain on storage. In-flight stores/fetches cannot be evicted.
`StrictReleaseColdCopies` removes superseded cold copies as well as MEM1 images.
`TrimUnwanted` frees undemanded images after their final fence. Shutdown calls
`Stop()` while continuing application pumping and completed frame fences, then
`Dispose()`; disposal refuses outstanding transfer/GPU ownership. Explicit trim
and final fences reduce unwanted image, read-buffer, placeholder and ARAM bytes
to zero.

## Shared world scheduling

An HCPK v2 `PackedWorld` exposes `WorldStreamer.TextureLods`. Use the world's
`BeginDemand`, `Pump`, `Frame` and `CompletedFrame`, and forward each submitted
frame fence through `WorldStreamer.EndFrame`. Family demand shares the existing
`ResourceScheduler`, `AssetStream`, staging buffer and `AramCache`. Gameplay and
collision can preempt between large texture chunks. Missing visible coarse
images precede upgrades; upgrade ties use projected error before FIFO age.

`WorldStreamer(..., normalizedTextureUvs: true)` opts dynamic terrain geometry
into normalized tile/atlas coordinates; use streamed material mappings at draw
time. Permanent v1 fallback meshes retain their original mapping. The v1-only
fixed-size `TexturePool`, validation path and its historical accounting remain
unchanged. A v2 world's `PhysicalBytes`/`PeakPhysicalBytes` also count permanent
world meshes and textures plus shared staging. Promotions never evict a demanded
family's fallback simply to obtain replacement headroom.

## Validation and SDK availability

The SDK source pin includes the reviewed streamable assets and detached-upload
PRs. Build source checkouts using `.sdk-revision`. Before that SDK revision has
a public NuGet release, `python3 eng/pack.py --sdk-source vendor/sdk --version
0.1.0-preview.local.1` creates an exact-revision SDK dependency feed for isolated
consumer validation. Its manifest marks these as source-preview artifacts;
publication refuses them. Public engine distribution requires publishing the
pinned SDK and updating `DolphinDotNetPackageVersion` first.

`python3 tools/test_progressive_runtime.py` executes standalone and mixed-world
scenarios in Debug and Release through actual SDK AOT, native storage/graphics,
ARAM and GC stress. It covers coarse presentation, CRC/short-read failures,
generation churn, both material slots, pressure rejection, physical accounting,
collision preemption during >128-KiB upgrades, and complete shutdown. The
standalone path permits only five resource-cleanup waits and the AOT device
shutdown wait, with none during texture replacement.

`tools/build_progressive.sh` builds the PowerPC fixture and data ISO.
`python3 tools/progressive_validation.py Game.dol --disc textures.iso --logs
out/fresh-capture --seconds 60` checks independent coarse/fine pixel patches,
rotated gutter UVs in both texture slots, request reversal, live DSP audio,
failure/retirement counters, and zero bytes after final trim. It records p95/p99
frame times and readiness latency as emulator observations, with an explicit
`hardwarePerformanceClaim: false` marker. Real GameCube SD2SP2/disc/audio pressure
and latency gates still require physical-console captures.
20 changes: 14 additions & 6 deletions eng/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
IDS=('Capz.Hypercube.Core','Capz.Hypercube.GameCube')

def run(*args):subprocess.run(args,cwd=ROOT,check=True)
def inspect(package,identity,version):
def inspect(package,identity,version,sdk_version=None):
with ZipFile(package) as z:
root=ET.fromstring(z.read(identity+'.nuspec'));metadata=next(e for e in root if e.tag.endswith('metadata'))
def value(name):return next(e.text for e in metadata if e.tag.endswith('}'+name) or e.tag==name)
Expand All @@ -22,20 +22,28 @@ def value(name):return next(e.text for e in metadata if e.tag.endswith('}'+name)
assert not any(e.startswith('DolphinDotNet') for e in dependencies) if identity==IDS[0] else True
if identity==IDS[1]:
assert dependencies[IDS[0]]==version,dependencies
sdk=ET.parse(ROOT/'Directory.Build.props').find('.//DolphinDotNetPackageVersion').text
sdk=sdk_version or ET.parse(ROOT/'Directory.Build.props').find('.//DolphinDotNetPackageVersion').text
assert dependencies['DolphinDotNet.GameCube']=='['+sdk+']',dependencies
assert not any(n.startswith('lib/') and '/DolphinDotNet.' in n for n in z.namelist())
return dependencies

def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--version',required=True);p.add_argument('--output',type=Path,default=ROOT/'out/packages');args=p.parse_args()
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--version',required=True);p.add_argument('--output',type=Path,default=ROOT/'out/packages');p.add_argument('--sdk-source',type=Path,help='Build a test-only dependency feed from the exact pinned SDK before it is published');args=p.parse_args()
if not re.fullmatch(r'0\.\d+\.\d+(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?',args.version):p.error('Use a 0.x.y stable or preview NuGet version')
output=args.output.resolve();output.mkdir(parents=True,exist_ok=True)
commit=subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip()
sdk_revision=(ROOT/'.sdk-revision').read_text().strip();sdk_version=ET.parse(ROOT/'Directory.Build.props').find('.//DolphinDotNetPackageVersion').text;extra=[]
if args.sdk_source:
sdk_root=args.sdk_source.resolve();actual=subprocess.check_output(['git','rev-parse','HEAD'],cwd=sdk_root,text=True).strip()
if actual!=sdk_revision:p.error('SDK checkout must match .sdk-revision exactly')
if subprocess.check_output(['git','status','--porcelain','--untracked-files=no'],cwd=sdk_root,text=True).strip():p.error('Pinned SDK must have no tracked changes')
sdk_version='0.1.0-preview.source.'+sdk_revision[:12];sdk_feed=output/'sdk-feed'
subprocess.run(['python3',str(sdk_root/'eng/pack.py'),'--version',sdk_version,'--output',str(sdk_feed)],cwd=sdk_root,check=True)
extra=['-p:DolphinDotNetPackageVersion='+sdk_version,'-p:RestoreAdditionalProjectSources='+str(sdk_feed)]
for identity in IDS:
project=ROOT/'src'/identity.removeprefix('Capz.')/(identity.removeprefix('Capz.')+'.csproj')
run('dotnet','pack',str(project),'-c','Release','-o',str(output),'-p:Version='+args.version,'-p:PackageVersion='+args.version,'-p:RepositoryCommit='+commit,'-p:ContinuousIntegrationBuild=true','-p:HypercubeUsePublishedSdk=true')
inspect(output/(identity+'.'+args.version+'.nupkg'),identity,args.version)
(output/'packages.json').write_text(json.dumps({'version':args.version,'commit':commit,'packages':list(IDS)},indent=2)+'\n')
run('dotnet','pack',str(project),'-c','Release','-o',str(output),'-p:Version='+args.version,'-p:PackageVersion='+args.version,'-p:RepositoryCommit='+commit,'-p:ContinuousIntegrationBuild=true','-p:HypercubeUsePublishedSdk=true',*extra)
inspect(output/(identity+'.'+args.version+'.nupkg'),identity,args.version,sdk_version)
(output/'packages.json').write_text(json.dumps({'version':args.version,'commit':commit,'packages':list(IDS),'sdkVersion':sdk_version,'sdkRevision':sdk_revision,'sdkSourcePreview':bool(args.sdk_source)},indent=2)+'\n')
print('Engine packages and NuGet dependency metadata verified')
if __name__=='__main__':main()
21 changes: 21 additions & 0 deletions samples/ProgressiveTextures/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Dolphin.Storage;
using Dolphin.Memory;
using System.Threading.Tasks;
using Dolphin.Audio;

internal static class Program
{
static int Main()
{
if(!Aram.Initialize(2*1024*1024))throw new System.Exception("ARAM initialization failed.");
string path=Storage.MountDisc()?"dvd:/world.hcp":"sd:/hypercube/textures.hcp";
if(!System.IO.File.Exists(path))
{
Storage.Mount(StorageDevice.SdSerialPort2);path="sd:/hypercube/textures.hcp";
}
var tone=new byte[8000];for(int i=0;i<tone.Length;i++)tone[i]=(byte)(128+32*System.Math.Sin(i*System.Math.PI*440/8000));
using var sound=Sound.FromPcm8(tone,16000);sound.Volume=.2f;var voice=sound.Play(true);
using var scenario=new TextureRuntimeScenario(path,()=>voice.IsPlaying);
while(true){scenario.Step();Task.Delay(1).GetAwaiter().GetResult();}
}
}
1 change: 1 addition & 0 deletions samples/ProgressiveTextures/ProgressiveTextures.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project><Import Project="../../Directory.Build.props" /><PropertyGroup><ImportDirectoryBuildProps>false</ImportDirectoryBuildProps></PropertyGroup><Import Project="$(DolphinDotNetRoot)/sdk/DolphinDotNet.Sdk/Sdk/Sdk.props" /><PropertyGroup><OutputType>Exe</OutputType></PropertyGroup><ItemGroup><ProjectReference Include="../../src/Hypercube.GameCube/Hypercube.GameCube.csproj" /></ItemGroup><Import Project="$(DolphinDotNetRoot)/sdk/DolphinDotNet.Sdk/Sdk/Sdk.targets" /></Project>
Loading
Loading