Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ jobs:
if: runner.os == 'Windows'
shell: pwsh
run: dotnet run --project samples/ModernTriangle -c Debug -- --warp --resize-test --evidence=artifacts/triangle-resize
- name: WARP texture and depth samples
if: runner.os == 'Windows'
shell: pwsh
run: |
dotnet run --project samples/HelloTexture -c Debug -- --warp --frames=4
if ($LASTEXITCODE -ne 0) { throw 'HelloTexture failed.' }
dotnet run --project samples/AdvancedSample -c Debug -- --warp --frames=4
if ($LASTEXITCODE -ne 0) { throw 'AdvancedSample failed.' }
- name: WARP compute and DirectML numerical qualification
if: runner.os == 'Windows'
shell: pwsh
Expand Down
16 changes: 15 additions & 1 deletion DXSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernTriangle", "samples\M
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernCompute", "samples\ModernCompute\ModernCompute.csproj", "{2BB6521A-B6BC-4BD3-AC2E-67E8042386E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DXSharp.Framework.Desktop", "src\DXSharp.Framework.Desktop\DXSharp.Framework.Desktop.csproj", "{2ABFBD91-D516-4267-88F3-F232D822D38B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -302,6 +304,18 @@ Global
{2BB6521A-B6BC-4BD3-AC2E-67E8042386E4}.Release|x64.Build.0 = Release|x64
{2BB6521A-B6BC-4BD3-AC2E-67E8042386E4}.Release|x86.ActiveCfg = Release|x86
{2BB6521A-B6BC-4BD3-AC2E-67E8042386E4}.Release|x86.Build.0 = Release|x86
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|x64.ActiveCfg = Debug|x64
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|x64.Build.0 = Debug|x64
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|x86.ActiveCfg = Debug|x86
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Debug|x86.Build.0 = Debug|x86
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|Any CPU.Build.0 = Release|Any CPU
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|x64.ActiveCfg = Release|x64
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|x64.Build.0 = Release|x64
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|x86.ActiveCfg = Release|x86
{2ABFBD91-D516-4267-88F3-F232D822D38B}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -333,12 +347,12 @@ Global
{6D81F5A7-1D01-49DF-8D02-ECD9183FDF6F} = {4A52D278-0251-4FD5-BF3A-5C52C294480A}
{AA296E18-E027-4E92-A7D7-42FC5086A052} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8}
{2BB6521A-B6BC-4BD3-AC2E-67E8042386E4} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8}
{2ABFBD91-D516-4267-88F3-F232D822D38B} = {29411031-4490-4542-B2D1-02D223BFD605}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7C4990EC-248E-49D5-A254-EA8AD214C338}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
samples\shared\DXSharp.Samples.Shared\DXSharp.Samples.Shared.projitems*{29e67012-6798-43e1-befe-f9270f595779}*SharedItemsImports = 13
samples\shared\DXSharp.Samples.Shared\DXSharp.Samples.Shared.projitems*{f3c57f0f-8540-4e97-b28d-a34091c53755}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion build/VerifyPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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.Core', 'DXSharp.DirectML')) {
foreach ($name in @('DXSharp', 'DXSharp.Dxc', 'DXSharp.Framework', 'DXSharp.Framework.Desktop', 'DXSharp.Core', 'DXSharp.DirectML')) {
if (-not (Test-Path (Join-Path $packageDirectory "$name.$version.nupkg"))) {
throw "Missing package: $name.$version.nupkg"
}
Expand All @@ -34,6 +34,7 @@ try {
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DXSharp.Framework" Version="$version" />
<PackageReference Include="DXSharp.Framework.Desktop" Version="$version" />
<PackageReference Include="DXSharp.DirectML" Version="$version" />
</ItemGroup>
</Project>
Expand All @@ -42,6 +43,7 @@ try {
System.Console.WriteLine(typeof(DXSharp.Direct3D12.IDevice).Assembly.FullName);
System.Console.WriteLine(typeof(DXSharp.Dxc.ShaderBuilder).Assembly.FullName);
System.Console.WriteLine(typeof(DXSharp.Graphics.GraphicsDevice).Assembly.FullName);
System.Console.WriteLine(typeof(DXSharp.Framework.Desktop.DesktopGame).Assembly.FullName);
System.Console.WriteLine(typeof(DXSharp.MachineLearning.DirectMlDevice).Assembly.FullName);
'@ | Set-Content (Join-Path $consumerDirectory 'Program.cs')
@"
Expand Down
12 changes: 12 additions & 0 deletions doc/Generated-Com-Foundation.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ If Developer PowerShell selects an `x64` platform subdirectory, use the matching
The launcher records the executable hash, arguments, OS, architecture and SDK/runtime inventory, and asks ProcDump to launch only that executable and capture a full dump on an unhandled exception. It does not change global crash settings. ModernTriangle also writes `diagnostics.json` and managed failures under its evidence directory. Next investigation requires the crashing native instruction, native/managed stacks, loaded-module versions and device-removal evidence from that exact run.

Primary references: [source-generated COM](https://learn.microsoft.com/dotnet/standard/native-interop/comwrappers-source-generation), [unique ComObject.FinalRelease](https://learn.microsoft.com/dotnet/api/system.runtime.interopservices.marshalling.comobject.finalrelease), [DirectML binding](https://learn.microsoft.com/windows/ai/directml/dml-binding), [Microsoft's HelloDirectML](https://github.com/microsoft/DirectML/blob/master/Samples/HelloDirectML/main.cpp), [ProcDump](https://learn.microsoft.com/sysinternals/downloads/procdump).

## Desktop samples

`DXSharp.Framework.Desktop` hosts the WinForms window, frame timing, back buffers, resize, optional depth target, presentation, and shutdown. The caller owns its device, shaders, pipelines, and scene resources. The draw callback records into the frame's borrowed command list. The host currently uses one allocator and waits for each draw submission.

- **ModernTriangle** exercises the shared host, including its existing `--resize-test`.
- **HelloTexture** ports the checkerboard triangle from [Microsoft's D3D12 Hello Texture](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12HelloWorld/src/HelloTexture). It uploads a single-mip RGBA8 texture with row padding and samples it through an SRV and static sampler.
- **AdvancedSample** exercises per-frame matrices, lighting, and a D32 depth target with a rotating cube. See [the sample README](../samples/AdvancedSample/readme.md).

Run either new sample with `--warp --frames=4` for the bounded Windows software-adapter check. With no arguments, the sample uses the hardware adapter and runs until its window closes.

The next Microsoft port candidates are [Hello Frame Buffering](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12HelloWorld/src/HelloFrameBuffering) for multiple frames in flight, [ExecuteIndirect](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12ExecuteIndirect) for GPU-driven draws, and [D3D12 Multithreading](https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12Multithreading) for a shadow pass and parallel recording.
81 changes: 12 additions & 69 deletions samples/AdvancedSample/AdvancedSample.csproj
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Common Project Properties :: -->
<PropertyGroup Label="CommonProjectProperties">
<UsingDxcCompiler>false</UsingDxcCompiler>
<OutputType Condition=" '$(Configuration)' == 'Debug' ">Exe</OutputType>
<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType>
<FileVersion>0.1.0</FileVersion>
<AssemblyVersion>0.1.0</AssemblyVersion>

<Product>Advanced DXSharp Sample</Product>
<RootNamespace>AdvancedDXS</RootNamespace>
<ApplicationIcon>Assets\DXSharp_ICON_256.ico</ApplicationIcon>

<Platforms>$(TargetCPUs);</Platforms>
<TargetFramework>$(DotNetTargets)</TargetFramework>
</PropertyGroup>



<!-- References :: -->
<ItemGroup Label="ProjectRefs">
<ProjectReference Include="..\..\src\DXSharp.Dxc\DXSharp.Dxc.csproj" />
<ProjectReference Include="..\..\src\DXSharp.Framework\DXSharp.Framework.csproj" />
<ProjectReference Include="..\..\src\DXSharp\DXSharp.csproj" />
</ItemGroup>

<ItemGroup Label="ProjectContentProperties"
Condition=" '$(DXC_COMPILE)'!='false' ">
<Content Include="Assets\Shaders\*.hlsl"
CopyToOutputDirectory="PreserveNewest" />

<DxcShaderIncludes Include="Assets\Shaders\include\*.h" />
<DxcShaderIncludes Include="Assets\Shaders\include\*.inc" />
<DxcShaderFiles Include="Assets\Shaders\src\*.hlsl" />
<DxcShaderFiles Include="Assets\Shaders\src\*.compute" />

<DxcShaderBlobs Include="Assets\Shaders\obj\*.blob" />
<DxcShaderBlobs Include="Assets\Shaders\obj\*.cso" />

<DxcFragmentShader Include="Assets\Shaders\src\*.ps" />
<DxcVertexShader Include="Assets\Shaders\src\*.vs" />
<DxcGeometryShader Include="Assets\Shaders\src\*.geo" />
<DxcComputeShader Include="Assets\Shaders\src\*.compute" />

<DxcShader Include="@(DxcShaderFiles)">
<OutputHeader>Assets\Shaders\obj\%(Filename).blob</OutputHeader>
<OutputBlob>Assets\Shaders\obj\%(Filename).cso</OutputBlob>
<ShaderModel>5_0</ShaderModel> <!-- Default Shader Model -->
<ShaderTypes>vs;ps;</ShaderTypes>
</DxcShader>
</ItemGroup>

<ItemGroup Label="ContentFolderItemsGroup">
<Folder Include="Assets\Meshes\" />
<Folder Include="Assets\Textures\" />

<Folder Include="Assets\Shaders\include\" />
<Folder Include="Assets\Shaders\src\" />
<Folder Include="Assets\Shaders\obj\" />
</ItemGroup>


<!-- Advanced Project Properties :: -->
<PropertyGroup Label="AdvancedProjectProperties">
<ApplicationManifest>./app.manifest</ApplicationManifest>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<!-- NOTE: Currently, trimming and NativeAOT is not supported! -->
<!--<PublishTrimmed>true</PublishTrimmed>-->
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(DotNetTargets)</TargetFramework>
<RootNamespace>AdvancedDXS</RootNamespace>
<ApplicationIcon>Assets/DXSharp_ICON_256.ico</ApplicationIcon>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/DXSharp.Framework.Desktop/DXSharp.Framework.Desktop.csproj" />
<!-- Keep the earlier shadow-map and scene experiments available as reference source. -->
<Compile Remove="Framework/**/*.cs;Assets/AssetManager.cs" />
</ItemGroup>
</Project>
116 changes: 80 additions & 36 deletions samples/AdvancedSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,85 @@
#region Using Directives
using System.Drawing ;
using System.Numerics;
using System.Runtime.InteropServices;
using DXSharp.Framework.Desktop;
using DXSharp.Graphics;
using DXSharp.Shaders;

using DXSharp ;
using DXSharp.Applications ;
using AdvancedDXS.Framework ;

#if DEBUG || DEBUG_COM
using DXSharp.Framework.Debugging ;
using IDebugD3D = DXSharp.Direct3D12.IDebug6 ;
using IDebugDXGI = DXSharp.DXGI.Debugging.IDebug1 ;
#endif
#endregion


//! Create the app startup settings:
AppSettings Settings = new( "DXSharp: Advanced Sample",
(1920 , 1080),
new AppSettings.Style {
FontSize = 13,
FontName = "Consolas",
BackBufferColor = Color.Black,
ForegroundColor = Color.Black,
BackgroundColor = SystemColors.Window,
} ) ;
namespace AdvancedDXS;

internal static class Program {
private const string Shader = """
cbuffer Scene : register(b0) {
row_major float4x4 WorldViewProjection;
row_major float4x4 World;
};
struct Vertex { float4 position : SV_Position; float3 color : COLOR; };
Vertex VS(uint id : SV_VertexID) {
const float3 corners[8] = {
float3(-1,-1,-1), float3(1,-1,-1), float3(1,1,-1), float3(-1,1,-1),
float3(-1,-1, 1), float3(1,-1, 1), float3(1,1, 1), float3(-1,1, 1)
};
const uint indices[36] = {
0,3,2, 0,2,1, 4,5,6, 4,6,7, 0,4,7, 0,7,3,
1,2,6, 1,6,5, 3,7,6, 3,6,2, 0,1,5, 0,5,4
};
const float3 normals[6] = {
float3(0,0,-1), float3(0,0,1), float3(-1,0,0),
float3(1,0,0), float3(0,1,0), float3(0,-1,0)
};
const float3 colors[6] = {
float3(0.18,0.7,0.92), float3(0.27,0.85,0.68), float3(0.25,0.4,0.82),
float3(0.97,0.55,0.22), float3(0.8,0.9,1), float3(0.62,0.34,0.88)
};
uint face = id / 6;
float3 normal = mul(normals[face], (float3x3)World);
float light = 0.28 + 0.72 * saturate(dot(normal, normalize(float3(0.45, 0.8, 0.65))));
Vertex output;
output.position = mul(float4(corners[indices[id]], 1), WorldViewProjection);
output.color = colors[face] * light;
return output;
}
float4 PS(Vertex input) : SV_Target { return float4(input.color, 1); }
""";

//! Enable the debug layer in debug mode:
#if DEBUG || DEBUG_COM
await using DebugSystem< IDebugD3D, IDebugDXGI > dbg = new( ) ;
dbg.Enable( ) ;
[STAThread]
public static int Main( string[] args ) {
Application.SetUnhandledExceptionMode( UnhandledExceptionMode.ThrowException );
ApplicationConfiguration.Initialize( );
#if DEBUG
const bool debugLayer = true;
#else
const bool debugLayer = false;
#endif
int frameLimit = int.Parse( args.FirstOrDefault( x => x.StartsWith( "--frames=", StringComparison.Ordinal ) )?[9..] ?? "0" );
using var device = GraphicsDevice.Create( new( ) {
UseWarp = args.Contains( "--warp" ),
UseAgility = !args.Contains( "--system-runtime" ),
EnableDebugLayer = debugLayer && !args.Contains( "--no-debug" )
} );
Console.WriteLine( device.AdapterName );
using var compiler = new ShaderCompiler( );
using var root = device.CreateGraphicsConstantsRootSignature( 32 );
using var pipeline = device.CreateGraphicsPipeline( root, compiler.Compile( Shader, "VS", "vs_6_0" ),
compiler.Compile( Shader, "PS", "ps_6_0" ), PixelFormat.Rgba8Unorm, depthEnabled: true );



// Initialize & run the app:
var app = new DXSApp( Settings )
.Initialize( ) ;

app.Run( ) ;
app?.Shutdown( ) ;
var view = Matrix4x4.CreateLookAt( new Vector3( 0, 1.4f, 5.8f ), Vector3.Zero, Vector3.UnitY );
float angle = 0.65f;
var result = DesktopGame.Run( device, new( ) {
Title = "DXSharp · Advanced Sample · Lit Cube", FrameLimit = frameLimit, EnableDepth = true
}, frame => {
angle += Math.Min( (float)frame.Elapsed.TotalSeconds, 0.1f ) * 0.9f;
var world = Matrix4x4.CreateRotationX( 0.45f ) * Matrix4x4.CreateRotationY( angle );
var projection = Matrix4x4.CreatePerspectiveFieldOfView( MathF.PI / 3, (float)frame.Size.Width / frame.Size.Height, 0.1f, 100 );
ReadOnlySpan<Matrix4x4> matrices = [world * view * projection, world];
frame.Commands.SetGraphicsPipeline( pipeline );
frame.Commands.SetGraphicsConstants( MemoryMarshal.Cast<Matrix4x4, uint>( matrices ) );
frame.Commands.Draw( 36 );
} );
var diagnostics = device.GetDiagnostics( );
foreach ( string message in diagnostics.Messages ) Console.WriteLine( message );
if ( diagnostics.DeviceRemovedReason < 0 || diagnostics.Messages.Any( x => x.Contains( "SEVERITY_ERROR" ) || x.Contains( "SEVERITY_CORRUPTION" ) ) ) return 1;
if ( frameLimit > 0 && result.Frames != frameLimit ) return 1;
Console.WriteLine( $"AdvancedSample closed cleanly after {result.Frames} frames." );
return 0;
}
}
25 changes: 17 additions & 8 deletions samples/AdvancedSample/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@
"version": 2,
"dependencies": {
"net10.0-windows10.0.26100": {
"dxsharp": {
"type": "Project"
},
"dxsharp.dxc": {
"dxsharp.core": {
"type": "Project",
"dependencies": {
"DXSharp": "[0.4.0-net10-preview.1, )"
"Microsoft.Direct3D.D3D12": "[1.620.1, 1.620.1]",
"Microsoft.Direct3D.DXC": "[1.9.2609.5, 1.9.2609.5]"
}
},
"dxsharp.framework": {
"dxsharp.framework.desktop": {
"type": "Project",
"dependencies": {
"DXSharp": "[0.4.0-net10-preview.1, )",
"DXSharp.Dxc": "[0.4.0-net10-preview.1, )"
"DXSharp.Core": "[0.4.0-net10-preview.1, )"
}
},
"Microsoft.Direct3D.D3D12": {
"type": "CentralTransitive",
"requested": "[1.620.1, )",
"resolved": "1.620.1",
"contentHash": "oQCFTys3PZ0IHtS3I/u0/1IWgpuG7aQa+84AGiraqc8bMOCM8QpDLwLBshEbJ1J7LmuctZReXhF8c0eCiu2Xcw=="
},
"Microsoft.Direct3D.DXC": {
"type": "CentralTransitive",
"requested": "[1.9.2609.5, )",
"resolved": "1.9.2609.5",
"contentHash": "jTWr7a2bMpqV+b0Uc7oxOo8ualplaUw3fsQ+p0kp9TwlWvvmREvt3SA4+Drl2Y0M31iscqZolrL3vpdnLoPpdg=="
}
}
}
Expand Down
Loading
Loading