From 587518fa62f39cd32915873fc928770b105a6c57 Mon Sep 17 00:00:00 2001 From: Aaron Carter <89698828+atcarter714@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:34:18 -0600 Subject: [PATCH 1/2] Add optional WPF viewport and shared CharacterLab host Add dispatcher-owned D3D12 HWND hosting with physical pixel sizing, fenced retirement, focus/capture handling, restart and failure reporting. Share CharacterScene across WinForms, native Win32 and WPF, and qualify WPF lifecycle and isolated package consumption on both runtimes. Align package validation and release publishing with the candidate manifest. --- .github/workflows/release.yml | 9 +- DXSharp.sln | 30 +++ README.md | 1 + build/VerifyPackages.ps1 | 15 +- build/VerifySamples.ps1 | 2 + build/release_packages.py | 2 +- build/verify_sample_packages.py | 8 +- doc/Framework-Vision.md | 4 +- doc/Publishing-Previews.md | 6 +- doc/SDK-Architecture.md | 1 + doc/Sample-Showcase-Plan.md | 2 +- doc/Support-Matrix.md | 2 +- doc/Wpf-Hosting.md | 38 +++ .../CharacterLab.Native.csproj | 1 + .../CharacterLab.Wpf/CharacterLab.Wpf.csproj | 13 + samples/CharacterLab.Wpf/CharacterWindow.xaml | 50 ++++ .../CharacterLab.Wpf/CharacterWindow.xaml.cs | 53 +++++ samples/CharacterLab.Wpf/Program.cs | 38 +++ samples/CharacterLab.Wpf/README.md | 5 + .../CharacterLab.Wpf/WpfHostQualification.cs | 110 +++++++++ samples/CharacterLab.Wpf/packages.lock.json | 62 +++++ .../CharacterLab.Wpf/packages.net11.lock.json | 62 +++++ samples/CharacterLab/CharacterScene.cs | 54 +++++ samples/CharacterLab/OrbitCamera.cs | 11 +- samples/CharacterLab/Program.cs | 43 +--- samples/README.md | 2 + src/DXSharp.Framework.Wpf/D3D12Viewport.cs | 225 ++++++++++++++++++ .../DXSharp.Framework.Wpf.csproj | 11 + src/DXSharp.Framework.Wpf/packages.lock.json | 107 +++++++++ 29 files changed, 912 insertions(+), 55 deletions(-) create mode 100644 doc/Wpf-Hosting.md create mode 100644 samples/CharacterLab.Wpf/CharacterLab.Wpf.csproj create mode 100644 samples/CharacterLab.Wpf/CharacterWindow.xaml create mode 100644 samples/CharacterLab.Wpf/CharacterWindow.xaml.cs create mode 100644 samples/CharacterLab.Wpf/Program.cs create mode 100644 samples/CharacterLab.Wpf/README.md create mode 100644 samples/CharacterLab.Wpf/WpfHostQualification.cs create mode 100644 samples/CharacterLab.Wpf/packages.lock.json create mode 100644 samples/CharacterLab.Wpf/packages.net11.lock.json create mode 100644 samples/CharacterLab/CharacterScene.cs create mode 100644 src/DXSharp.Framework.Wpf/D3D12Viewport.cs create mode 100644 src/DXSharp.Framework.Wpf/DXSharp.Framework.Wpf.csproj create mode 100644 src/DXSharp.Framework.Wpf/packages.lock.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03c8e62..9b86f74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -176,8 +176,9 @@ jobs: echo "::error::The release tag does not point to the qualified commit." exit 1 fi - for id in dxsharp.native dxsharp.assets dxsharp.core dxsharp.directml dxsharp.framework.desktop; do - url="https://api.nuget.org/v3-flatcontainer/$id/$RELEASE_VERSION/$id.$RELEASE_VERSION.nupkg" + for id in $(python -c 'from build.release_packages import PACKAGE_IDS; print(" ".join(PACKAGE_IDS))'); do + lower_id="${id,,}" + url="https://api.nuget.org/v3-flatcontainer/$lower_id/$RELEASE_VERSION/$lower_id.$RELEASE_VERSION.nupkg" status=$(curl --silent --show-error --head --max-time 30 --output /dev/null --write-out '%{http_code}' "$url") if [[ "$status" != 404 ]]; then echo "::error::Expected $id $RELEASE_VERSION to be unpublished, got HTTP $status." @@ -201,13 +202,13 @@ jobs: env: NUGET_API_KEY: ${{ steps.nuget.outputs.NUGET_API_KEY }} run: | - for id in DXSharp.Native DXSharp.Assets DXSharp.Core DXSharp.DirectML DXSharp.Framework.Desktop DXSharp.Framework; do + for id in $(python -c 'from build.release_packages import PACKAGE_IDS; print(" ".join(PACKAGE_IDS))'); do dotnet nuget push "candidate/$id.$RELEASE_VERSION.nupkg" \ --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json done - name: Record successful NuGet upload on the release run: | cp "doc/releases/$RELEASE_VERSION.md" published-notes.md - printf '\nNuGet.org accepted the six packages and their symbols from [this publishing run](%s/%s/actions/runs/%s). Feed indexing and symbol validation may take additional time.\n' \ + printf '\nNuGet.org accepted the qualified packages and their symbols from [this publishing run](%s/%s/actions/runs/%s). Feed indexing and symbol validation may take additional time.\n' \ "$GITHUB_SERVER_URL" "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID" >> published-notes.md gh release edit "v$RELEASE_VERSION" --notes-file published-notes.md diff --git a/DXSharp.sln b/DXSharp.sln index 6325683..036d79b 100644 --- a/DXSharp.sln +++ b/DXSharp.sln @@ -162,6 +162,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CharacterLab", "samples\Cha EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CharacterLab.Native", "samples\CharacterLab.Native\CharacterLab.Native.csproj", "{3F26D680-7549-4ED0-B6E6-F940B2E2E8C1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CharacterLab.Wpf", "samples\CharacterLab.Wpf\CharacterLab.Wpf.csproj", "{AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DXSharp.Framework.Wpf", "src\DXSharp.Framework.Wpf\DXSharp.Framework.Wpf.csproj", "{CA095DE4-9BC3-49E4-A764-D4406AA4D795}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -482,6 +486,30 @@ Global {F2B18F42-2A58-413A-921F-71648DB0C250}.Release|x64.Build.0 = Release|x64 {F2B18F42-2A58-413A-921F-71648DB0C250}.Release|x86.ActiveCfg = Release|x86 {F2B18F42-2A58-413A-921F-71648DB0C250}.Release|x86.Build.0 = Release|x86 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|x64.ActiveCfg = Debug|x64 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|x64.Build.0 = Debug|x64 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|x86.ActiveCfg = Debug|x86 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Debug|x86.Build.0 = Debug|x86 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|Any CPU.Build.0 = Release|Any CPU + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|x64.ActiveCfg = Release|x64 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|x64.Build.0 = Release|x64 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|x86.ActiveCfg = Release|x86 + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151}.Release|x86.Build.0 = Release|x86 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|x64.ActiveCfg = Debug|x64 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|x64.Build.0 = Debug|x64 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|x86.ActiveCfg = Debug|x86 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Debug|x86.Build.0 = Debug|x86 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|Any CPU.Build.0 = Release|Any CPU + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|x64.ActiveCfg = Release|x64 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|x64.Build.0 = Release|x64 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|x86.ActiveCfg = Release|x86 + {CA095DE4-9BC3-49E4-A764-D4406AA4D795}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -526,6 +554,8 @@ Global {970D21A9-6343-49A1-A8F5-CA87B42D62FF} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8} {8B69B142-8E89-4ECB-AB6D-5D6E7A6925F4} = {AF35E6EE-C244-4E1F-84A6-DED8F9BD0EC7} {F2B18F42-2A58-413A-921F-71648DB0C250} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8} + {AEDF6FCA-CFF8-47EB-9DF1-D62C776BE151} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8} + {CA095DE4-9BC3-49E4-A764-D4406AA4D795} = {29411031-4490-4542-B2D1-02D223BFD605} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7C4990EC-248E-49D5-A254-EA8AD214C338} diff --git a/README.md b/README.md index 4940827..fe48ad1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The first command presents four frames and exits. The second verifies GPU comput | `DXSharp.Assets` | Static glTF/GLB models, materials, transforms, and decoded textures | | `DXSharp.Core` | D3D12, DXGI, DXC, and generated COM interop | | `DXSharp.Framework.Desktop` | WinForms presentation loop, swap-chain resize, and frame-slot retirement | +| `DXSharp.Framework.Wpf` | Optional WPF child-HWND viewport using the shared frame renderer; [hosting contract](doc/Wpf-Hosting.md) | | `DXSharp.DirectML` | Device and operator ownership, tensor binding, and DirectML execution | | `DXSharp`, `DXSharp.Framework`, `DXSharp.Dxc` | Compatibility packages for the original RCW-based SDK | diff --git a/build/VerifyPackages.ps1 b/build/VerifyPackages.ps1 index a2163ee..b4c201f 100644 --- a/build/VerifyPackages.ps1 +++ b/build/VerifyPackages.ps1 @@ -17,14 +17,25 @@ try { if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($version)) { throw 'Unable to evaluate the package version.' } - foreach ($name in @('DXSharp', 'DXSharp.Dxc', 'DXSharp.Framework', 'DXSharp.Framework.Desktop', 'DXSharp.Native', 'DXSharp.Assets', 'DXSharp.Core', 'DXSharp.DirectML')) { + foreach ($name in @('DXSharp', 'DXSharp.Dxc', 'DXSharp.Framework', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Native', 'DXSharp.Assets', 'DXSharp.Core', 'DXSharp.DirectML')) { $path = Join-Path $packageDirectory "$name.$version.nupkg" if (-not (Test-Path $path)) { throw "Missing package: $path" } $archive = [System.IO.Compression.ZipFile]::OpenRead($path) try { + $reader = [System.IO.StreamReader]::new($archive.GetEntry("$name.nuspec").Open()) + try { [xml] $metadata = $reader.ReadToEnd() } finally { $reader.Dispose() } + $frameworkReferences = @($metadata.SelectNodes("//*[local-name()='frameworkReference']") | ForEach-Object { $_.GetAttribute('name') }) + if ($name -eq 'DXSharp.Framework.Wpf' -and + ('Microsoft.WindowsDesktop.App.WPF' -notin $frameworkReferences -or 'Microsoft.WindowsDesktop.App.WindowsForms' -in $frameworkReferences)) { + throw 'The WPF package must declare WPF without acquiring Windows Forms.' + } + if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.Framework', 'DXSharp.Assets') -and + @($frameworkReferences | Where-Object { $_ -like 'Microsoft.WindowsDesktop*' }).Count -gt 0) { + throw "Optional desktop framework leaked into $name." + } $assemblies = @($archive.Entries | Where-Object FullName -CLike "lib/*/$name.dll") if ($assemblies.Count -eq 0) { throw "No library assembly found in $path" } - if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.DirectML', 'DXSharp.Framework.Desktop', 'DXSharp.Assets', 'DXSharp.Framework')) { + if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.DirectML', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Assets', 'DXSharp.Framework')) { foreach ($major in '10', '11') { # NuGet normalizes the trailing zero of the Windows platform version. $framework = if ($name -eq 'DXSharp.Assets') { "net$major.0" } else { "net$major.0-windows10.0.26100" } diff --git a/build/VerifySamples.ps1 b/build/VerifySamples.ps1 index e85f049..92dab50 100644 --- a/build/VerifySamples.ps1 +++ b/build/VerifySamples.ps1 @@ -20,6 +20,8 @@ try { } Invoke-Sample 'CharacterLab-native' @('run', '--project', 'samples/CharacterLab.Native', '-c', 'Debug', '--', '--warp', '--frames=9', '--resize-test') + Invoke-Sample 'CharacterLab-wpf' @('run', '--project', 'samples/CharacterLab.Wpf', '-c', 'Debug', '--', '--warp', '--frames=9') + Invoke-Sample 'CharacterLab-wpf-host' @('run', '--project', 'samples/CharacterLab.Wpf', '-c', 'Debug', '--', '--warp', '--host-test') Invoke-Sample 'DepthStencil' @('run', '--project', 'samples/DepthStencil', '-c', 'Debug', '--', '--warp') Invoke-Sample 'ModernTriangle' @('run', '--project', 'samples/ModernTriangle', '-c', 'Debug', '--', diff --git a/build/release_packages.py b/build/release_packages.py index 6da78ec..09df28b 100644 --- a/build/release_packages.py +++ b/build/release_packages.py @@ -9,7 +9,7 @@ import xml.etree.ElementTree as ET from zipfile import ZipFile -PACKAGE_IDS = ("DXSharp.Native", "DXSharp.Assets", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Framework", "DXSharp.Tools.Builds") +PACKAGE_IDS = ("DXSharp.Native", "DXSharp.Assets", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Framework", "DXSharp.Framework.Wpf", "DXSharp.Tools.Builds") PREVIEW = re.compile(r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-(?:net10-)?preview\.[1-9][0-9]*") diff --git a/build/verify_sample_packages.py b/build/verify_sample_packages.py index 38322a6..93630b8 100644 --- a/build/verify_sample_packages.py +++ b/build/verify_sample_packages.py @@ -9,7 +9,7 @@ import tempfile import xml.etree.ElementTree as ET -SDK_PACKAGES = ("DXSharp.Native", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Assets", "DXSharp.Framework") +SDK_PACKAGES = ("DXSharp.Native", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Framework.Wpf", "DXSharp.Assets", "DXSharp.Framework") EXCLUDED = {"bin", "obj", "artifacts", ".vs"} @@ -117,6 +117,12 @@ def qualify(configuration, runtime_major): if path.exists(): raise RuntimeError(f'Native precompiled consumer deployed {name}') run([str(native), "--warp", "--frames=9", "--resize-test"], consumer, evidence / "character-native-runtime.log") + wpf = consumer / "samples/CharacterLab.Wpf/bin" / configuration / framework / "CharacterLab.Wpf.dll" + for name in ('dxcompiler.dll', 'dxil.dll'): + if (wpf.parent / name).exists(): + raise RuntimeError(f'WPF precompiled consumer deployed {name}') + run([str(wpf), "--warp", "--frames=9"], consumer, evidence / "character-wpf-runtime.log") + run([str(wpf), "--warp", "--host-test"], consumer, evidence / "character-wpf-host.log") (evidence / "samples.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8") print(f"PASS: all {len(manifest)} runnable samples consume packaged SDK {version} outside the checkout.") diff --git a/doc/Framework-Vision.md b/doc/Framework-Vision.md index 40d8a92..0e8da9c 100644 --- a/doc/Framework-Vision.md +++ b/doc/Framework-Vision.md @@ -36,4 +36,6 @@ Acceptance remains workload-based: CPU/GPU deformation agreement; clear allocati ## Shader and host continuation -The next working slice adds precompiled Framework shader resources, typed runtime compiler options and a packaged incremental DXC task. FrameRenderer now separates frame slots/presentation from UI scheduling; DesktopGame keeps its API and NativeGame supplies an independent Win32 host. CharacterLab.Native shares the existing scene and has no WinForms reference. See [the shader/host contract](Shader-Build-and-Hosting.md) for packaging, cross-compilation limits and qualification. WinUI/WPF adapters and the full application lifecycle remain continuation work. +The shader/host slice adds precompiled Framework shader resources, typed runtime compiler options and a packaged incremental DXC task. FrameRenderer separates frame slots/presentation from UI scheduling; DesktopGame keeps its API and NativeGame supplies an independent Win32 host. CharacterLab.Native shares the existing scene and has no WinForms reference. See [the shader/host contract](Shader-Build-and-Hosting.md) for packaging, cross-compilation limits and qualification. + +The optional `DXSharp.Framework.Wpf` adapter now hosts the shared CharacterLab scene with dispatcher scheduling, physical-pixel resize and explicit stop/drain ownership. See [WPF hosting](Wpf-Hosting.md). WinUI composition and the full Game/Application lifecycle remain continuation work; WPF/BAML NativeAOT is not inferred from the separate native interop gates. diff --git a/doc/Publishing-Previews.md b/doc/Publishing-Previews.md index 70bf8aa..40b3fce 100644 --- a/doc/Publishing-Previews.md +++ b/doc/Publishing-Previews.md @@ -1,18 +1,18 @@ # Publishing DXSharp previews -The first public version is `0.4.0-net10-preview.1`. Preview 2 is `0.4.0-net10-preview.2`; the next candidate is `0.4.0-preview.3`, with .NET 10 and .NET 11 assets. Neutral preview names are accepted alongside the earlier net10-preview versions. Publish `DXSharp.Native`, `DXSharp.Assets`, `DXSharp.Core`, `DXSharp.DirectML`, and `DXSharp.Framework.Desktop` for Windows x64. The legacy projects continue to build and produce CI artifacts for migration. The public preview depends only on the modern packages and their pinned upstream native dependencies. +Preview 3 shipped five modern package IDs. Preview 4 development adds Framework, the DXC build tool and the optional WPF host. The candidate set is defined in `build/release_packages.py`: `DXSharp.Native`, `DXSharp.Assets`, `DXSharp.Core`, `DXSharp.DirectML`, `DXSharp.Framework.Desktop`, `DXSharp.Framework`, `DXSharp.Framework.Wpf` and `DXSharp.Tools.Builds`. Library assets target .NET 10/11 for Windows x64 (Assets is portable; the build tool targets netstandard2.0). Legacy compatibility projects remain independently buildable CI artifacts. Published versions remain immutable. ## One-time configuration 1. In GitHub, create the `nuget` environment and restrict deployments to `main`. Enable a required reviewer if supported by the repository plan. Set the environment secret `NUGET_USER` to the nuget.org profile name of the publishing account. -2. On nuget.org, create a [Trusted Publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing) policy owned by the account or organization that will own the packages. Set repository owner `atcarter714`, repository `DXSharp`, workflow filename `release.yml`, and environment `nuget`. Enable creation and updates for the five package IDs above. The first publish requires creation scope. Disable it once all five IDs have owners and versions on the feed. +2. On nuget.org, create a [Trusted Publishing](https://learn.microsoft.com/nuget/nuget-org/trusted-publishing) policy owned by the account or organization that will own the packages. Set repository owner `atcarter714`, repository `DXSharp`, workflow filename `release.yml`, and environment `nuget`. Enable creation and updates for the candidate package IDs above. The first publish requires creation scope. Disable it once all candidate IDs have owners and versions on the feed. 3. In Azure DevOps, keep `devops/azure-pipelines.yml` configured as the build definition and use build validation on the integration branch. The Azure Release build retains an independently qualified candidate artifact. GitHub Actions holds the public publishing identity. [Azure build and retention](../devops/readme.md) ## Release 1. Prepare the intended `PackageVersion` in `Directory.Build.props` and its matching `doc/releases/.md` notes. Review the [qualification checklist](SDK-Release-Qualification.md) and attach hardware logs to the release review. 2. A merge to `main` that changes a versioned release note starts **DXSharp preview release** automatically. The workflow qualifies the exact triggering commit with Release builds, package consumption, WARP, and Windows and Linux NativeAOT. -3. After qualification, it publishes a GitHub prerelease at that commit and attaches the five packages, symbols, and a SHA-256 manifest. The separate NuGet job verifies the downloaded candidate, tag commit, and package version availability, then requests a temporary NuGet credential. It pushes Native, then Core, and then its dependents. The release notes distinguish the GitHub assets from NuGet publication and record the publishing run after successful upload. +3. After qualification, it publishes a GitHub prerelease at that commit and attaches the qualified package set, symbols, and a SHA-256 manifest. The separate NuGet job verifies the downloaded candidate, tag commit, and package version availability, then requests a temporary NuGet credential. It pushes Native, then Core, and then its dependents. The release notes distinguish the GitHub assets from NuGet publication and record the publishing run after successful upload. 4. Verify each package and version in nuget.org and verify the release tag and manifest against the qualifying run. Use a clean consumer with NuGet.org as the only package source to confirm public restore. For a manual dry run before merging, dispatch the workflow with the exact committed version and **publish** unchecked. A manual publishing run is restricted to `main`. Keep the release tag bound to the manifest's commit. diff --git a/doc/SDK-Architecture.md b/doc/SDK-Architecture.md index 3b832f0..b934004 100644 --- a/doc/SDK-Architecture.md +++ b/doc/SDK-Architecture.md @@ -28,6 +28,7 @@ flowchart TD | `DXSharp.Core` | Device and queue ownership, buffers and resource states, descriptors, pipelines, HWND swap chains, DXC, and a bounded DXR surface | | `DXSharp.DirectML` | Same-device tensor binding and synchronous compiled Add and GEMM execution with optional fused ReLU | | `DXSharp.Framework.Desktop` | A WinForms-owned STA loop, one or two fenced frame slots, resize, depth target, and presentation | +| `DXSharp.Framework.Wpf` | Optional WPF dispatcher scheduling and a child-HWND viewport over the shared frame renderer | | `DXSharp`, `DXSharp.Dxc`, `DXSharp.Framework` | Compatibility types, RCWs, older wrappers and framework. The compatibility tests still exercise this path. BasicSample uses the current desktop host. | ### Release documentation diff --git a/doc/Sample-Showcase-Plan.md b/doc/Sample-Showcase-Plan.md index 22f680a..16fed8b 100644 --- a/doc/Sample-Showcase-Plan.md +++ b/doc/Sample-Showcase-Plan.md @@ -16,7 +16,7 @@ Keep Core and Framework independent of WPF and Windows App SDK dependencies. Eac | --- | --- | --- | | Native Win32 | Existing DXSharp.Framework | NativeGame and HWND FrameRenderer; no Windows Forms dependency | | Windows Forms | Existing DXSharp.Framework.Desktop | Existing DesktopGame adapter | -| WPF | Proposed DXSharp.Framework.Wpf | HwndHost child HWND using the existing frame renderer; WPF dispatcher owns scheduling and teardown | +| WPF | DXSharp.Framework.Wpf | D3D12Viewport child HWND and shared CharacterLab.Wpf scene; dispatcher scheduling and fenced teardown; see [contract](Wpf-Hosting.md) | | WinUI 3 | Proposed DXSharp.Framework.WinUI | Composition swap chain attached through Microsoft.UI.Xaml ISwapChainPanelNative; Windows App SDK dependency stays in this adapter | WPF's child HWND has airspace restrictions: WPF elements cannot freely overlap or transform it as ordinary composed content. D3DImage is a different path requiring a Direct3D9 surface bridge and synchronization; it is not a direct D3D12 swap-chain target. Start with an honest HwndHost sample and assess a composed surface bridge separately if editor overlays require it. diff --git a/doc/Support-Matrix.md b/doc/Support-Matrix.md index 011d992..6d50476 100644 --- a/doc/Support-Matrix.md +++ b/doc/Support-Matrix.md @@ -14,7 +14,7 @@ This matrix distinguishes declarations, managed workflows and runtime qualificat | Native runtime dependencies | Agility 1.620.2, DXC 1.9.2609.5, optional DirectML 1.15.4 | | Native declarations | CsWin32 0.3.371, Win32Metadata 71.0.45-preview, Agility 1.620.2 WinMD | | Compatibility packages | Existing RCW surface remains separate; modern AOT promises do not apply to it | -| Desktop host | WinForms HWND swap chain | +| Desktop hosts | Native Win32 and WinForms HWND presentation; optional WPF child-HWND viewport ([contract](Wpf-Hosting.md)); WinUI composition remains planned | | Linux | Portable native COM fixture only; no D3D12 renderer support | Samples default to .NET 10. Select the newer runtime with `-p:DXSharpRuntimeMajor=11` or the qualification scripts' `-RuntimeMajor 11` option. Each runtime has its own JIT/NativeAOT CI jobs and evidence. Building the checkout requires the pinned SDK; consuming the net10 package assets does not require changing an application's target to net11. diff --git a/doc/Wpf-Hosting.md b/doc/Wpf-Hosting.md new file mode 100644 index 0000000..2e3f3bb --- /dev/null +++ b/doc/Wpf-Hosting.md @@ -0,0 +1,38 @@ +# WPF hosting + +`DXSharp.Framework.Wpf` is an optional Preview 4 assembly containing `D3D12Viewport`, a WPF `HwndHost` over the existing Framework `FrameRenderer`. It references Framework/Core/Assets and the WPF desktop framework. Core, Framework and the native Win32 host do not acquire WPF, Windows Forms or Windows App SDK dependencies through it. Windows x64 JIT on .NET 10 and 11 is the qualification target for this adapter; the SDK's separate NativeAOT fixture does not establish WPF/BAML NativeAOT support. + +## Using the control + +Reference the WPF package (or its project when developing in this repository), enable `UseWPF`, and place the control in a WPF layout: + +```xml + + + +``` + +Initialize it on the dispatcher with a caller-owned device and scene: + +```csharp +Viewport.Start( device, new WindowRenderOptions { + EnableDepth = true, FramesInFlight = 2 +}, frame => scene.Draw( frame ) ); +``` + +`Start` may precede `Loaded`. `Rendering` scheduling uses WPF's composition callback; the control invokes the supplied draw callback once per composition timestamp and presents through the shared fenced frame slots. `RenderFrame.Size` and `PixelSize` are physical child-window pixels read using `GetClientRect`. Do not multiply them by the WPF DPI scale again. Arrange the control in device-independent WPF units normally. Resize rebuilds the shared swap-chain/depth resources after prior work retires. Minimized, invisible and unloaded controls stop presenting; restoration resets the elapsed-time boundary. An unloaded session can resume when the control is loaded again. + +`FramePresented` runs after recording/presentation has returned. Use it for statistics and bounded shutdown. `RenderFailed` reports a stopped and drained session; `Failure` retains the error. Restart requires a completed stop. Call `StopAsync` outside the draw callback, then dispose the control before disposing scene resources and the device. In a WPF `Closing` handler, cancel the first close, await `StopAsync`, dispose the viewport, and issue the final close. `CharacterWindow.xaml.cs` implements that complete sequence. Forced disposal and native-window destruction also retire the renderer while the child HWND remains alive. + +`HasInputFocus` distinguishes the child HWND from WPF text editors. `AcceptsPointerInput` restricts pointer polling to the focused viewport or its captured drag. Clicking the viewport acquires focus and pointer capture; release and focus loss relinquish capture. Tab navigation enters and leaves the native region. Applications remain responsible for their action mapping and text/IME policy; this control is not a replacement for GameInput. + +## CharacterLab.Wpf and qualification + +Run `dotnet run --project samples/CharacterLab.Wpf`; use `--warp --frames=9` for bounded presentation or `--warp --host-test` for host qualification. WPF controls select clips, pause playback, change speed, reset the camera and demonstrate independent text input. The same `CharacterScene` and camera sources serve WinForms, native Win32 and WPF. Skinning shaders remain precompiled. + +The Windows gate runs resize and current-DPI pixel-size checks, focus transfer and tab entry/exit, minimize/restore, visibility suspension, unload/reload, intentional render failure, restart, close from a presentation callback and native-handle teardown. Both runtime versions also build and execute the same sample from isolated fresh packages in Debug/Release. Physical monitor-to-monitor DPI transitions and hardware frame pacing require separate interactive hardware review; these checks do not simulate a second monitor. The standalone sample rejects a loaded Windows Forms assembly and deployed runtime DXC binaries. + +WPF HWND airspace restrictions apply: arbitrary WPF overlays, opacity and transforms over the native viewport are not supported. Adjacent WPF panels and separate popup windows are suitable. A `D3DImage` composed-surface bridge would be a separate Direct3D9 interop design, not this D3D12 swap-chain host. WinUI composition remains an independent next adapter. + +References: [WPF/Win32 interoperation](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/wpf-and-win32-interoperation), [hosting Win32 content](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/hosting-win32-content-in-wpf), and [composition rendering](https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.compositiontarget.rendering). diff --git a/samples/CharacterLab.Native/CharacterLab.Native.csproj b/samples/CharacterLab.Native/CharacterLab.Native.csproj index 620d133..dbb0625 100644 --- a/samples/CharacterLab.Native/CharacterLab.Native.csproj +++ b/samples/CharacterLab.Native/CharacterLab.Native.csproj @@ -8,6 +8,7 @@ + diff --git a/samples/CharacterLab.Wpf/CharacterLab.Wpf.csproj b/samples/CharacterLab.Wpf/CharacterLab.Wpf.csproj new file mode 100644 index 0000000..e96c0e5 --- /dev/null +++ b/samples/CharacterLab.Wpf/CharacterLab.Wpf.csproj @@ -0,0 +1,13 @@ + + + Exe$(DotNetTargets) + truefalse + false + + + + + + + + diff --git a/samples/CharacterLab.Wpf/CharacterWindow.xaml b/samples/CharacterLab.Wpf/CharacterWindow.xaml new file mode 100644 index 0000000..bcb93cc --- /dev/null +++ b/samples/CharacterLab.Wpf/CharacterWindow.xaml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + +