Merge pull request #167 from Sergio0694/feature/winui3-shader-panel

WinUI 3 shader panel
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2021-11-20 14:10:39 +01:00
コミット c8c5d839f9
41ファイル変更
+1797 -50

検索条件に一致するファイルはありません

+69 -3
ファイルの表示
@@ -19,7 +19,7 @@ jobs:
run: dotnet build src\ComputeSharp\ComputeSharp.csproj -c Release
shell: cmd
# Run all the unit tests referencing the ComputeSharp project directly.
# Run all the unit tests referencing the ComputeSharp project directly
run-tests:
if: success()
needs: [build-project]
@@ -57,7 +57,7 @@ jobs:
run: dotnet test tests\ComputeSharp.Tests.SourceGenerators\ComputeSharp.Tests.SourceGenerators.csproj -v n -l "console;verbosity=detailed"
shell: cmd
# Run all the local samples to ensure they build and run with no errors.
# Run all the local samples to ensure they build and run with no errors
run-samples:
if: success()
needs: [run-tests]
@@ -199,4 +199,70 @@ jobs:
dotnet-version: 6.0.x
- name: Run ComputeSharp.Tests.NativeLibrariesResolver
run: dotnet test tests\ComputeSharp.Tests.NativeLibrariesResolver\ComputeSharp.Tests.NativeLibrariesResolver.csproj -v n -l "console;verbosity=detailed"
shell: cmd
shell: cmd
# Build the WinUI panel project
build-project-winui:
runs-on: windows-2022
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/[email protected]
with:
vs-prerelease: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Build
run: msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:restore,build /p:Configuration=Release
shell: cmd
# Build the WinUI project again to generate a NuGet package from it.
# This workflow also uploads the resulting package as an artifact.
build-package-winui:
if: success()
needs: [build-project-winui]
runs-on: windows-2022
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Build
run: msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:restore,build /p:Configuration=Release
shell: cmd
- name: Pack
run: msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:pack /p:Configuration=Release /p:ContinuousIntegrationBuild=True
shell: cmd
- name: Upload package artifact
uses: actions/upload-artifact@v2
with:
name: ComputeSharp.WinUI.nupkg
path: src\ComputeSharp.WinUI\bin\Release\*.nupkg
# Build the local WinUI sample to ensure it builds with no errors
build-samples-winui:
if: success()
needs: [build-project-winui]
runs-on: windows-2022
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore ComputeSharp.SwapChain.WinUI sample
run: msbuild samples\ComputeSharp.SwapChain.WinUI\ComputeSharp.SwapChain.WinUI.csproj -t:restore /p:Configuration=Release /p:Platform=x64
shell: cmd
- name: Build ComputeSharp.SwapChain.WinUI sample
run: msbuild samples\ComputeSharp.SwapChain.WinUI\ComputeSharp.SwapChain.WinUI.csproj -t:build /p:Configuration=Release /p:Platform=x64
shell: cmd # the build of the sample has to be a separate step, as '-t:restore,build' causes the build to fail
-2
ファイルの表示
@@ -55,7 +55,6 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
@@ -172,7 +171,6 @@ publish/
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
+20
ファイルの表示
@@ -0,0 +1,20 @@
{
"solution": {
"path": "ComputeSharp.sln",
"projects": [
"samples\\ComputeSharp.Benchmark\\ComputeSharp.Benchmark.csproj",
"samples\\ComputeSharp.ImageProcessing\\ComputeSharp.ImageProcessing.csproj",
"samples\\ComputeSharp.Sample.FSharp.Shaders\\ComputeSharp.Sample.FSharp.Shaders.csproj",
"samples\\ComputeSharp.Sample.FSharp\\ComputeSharp.Sample.FSharp.fsproj",
"samples\\ComputeSharp.Sample.Shared\\ComputeSharp.Sample.Shared.shproj",
"samples\\ComputeSharp.Sample\\ComputeSharp.Sample.csproj",
"samples\\ComputeSharp.SwapChain\\ComputeSharp.SwapChain.csproj",
"src\\ComputeSharp.SourceGenerators\\ComputeSharp.SourceGenerators.csproj",
"src\\ComputeSharp\\ComputeSharp.csproj",
"tests\\ComputeSharp.Tests.Internals\\ComputeSharp.Tests.Internals.csproj",
"tests\\ComputeSharp.Tests.NativeLibrariesResolver\\ComputeSharp.Tests.NativeLibrariesResolver.csproj",
"tests\\ComputeSharp.Tests.SourceGenerators\\ComputeSharp.Tests.SourceGenerators.csproj",
"tests\\ComputeSharp.Tests\\ComputeSharp.Tests.csproj"
]
}
}
+55 -20
ファイルの表示
@@ -54,6 +54,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.NetStandard",
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TerraFX.Interop.Windows", "src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.shproj", "{514FF00E-BBF0-4D55-A47C-EEEB6208ADCE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.WinUI", "src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj", "{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SwapChain.WinUI", "samples\ComputeSharp.SwapChain.WinUI\ComputeSharp.SwapChain.WinUI.csproj", "{0071701E-B9C5-4098-BE5F-EF556C4553C6}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5
@@ -112,26 +116,26 @@ Global
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|ARM64.Build.0 = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|x64.ActiveCfg = Debug|x64
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|x64.Build.0 = Debug|x64
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|x64.ActiveCfg = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Debug|x64.Build.0 = Debug|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|Any CPU.Build.0 = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|ARM64.ActiveCfg = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|ARM64.Build.0 = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|x64.ActiveCfg = Release|x64
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|x64.Build.0 = Release|x64
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|x64.ActiveCfg = Release|Any CPU
{E91F4D24-922A-4921-A8D7-9C45A143C45D}.Release|x64.Build.0 = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|ARM64.Build.0 = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|x64.ActiveCfg = Debug|x64
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|x64.Build.0 = Debug|x64
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|x64.ActiveCfg = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Debug|x64.Build.0 = Debug|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|Any CPU.Build.0 = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|ARM64.ActiveCfg = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|ARM64.Build.0 = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.ActiveCfg = Release|x64
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.Build.0 = Release|x64
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.ActiveCfg = Release|Any CPU
{E889E6D6-A814-4950-AAC1-68F1ECFC5BD6}.Release|x64.Build.0 = Release|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB52CB67-4162-4722-874B-44EA8DA5450E}.Debug|ARM64.ActiveCfg = Debug|Any CPU
@@ -180,18 +184,18 @@ Global
{BF52326F-E415-49E6-8595-62762216762B}.Release|ARM64.Build.0 = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|x64.ActiveCfg = Release|Any CPU
{BF52326F-E415-49E6-8595-62762216762B}.Release|x64.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|ARM64.Build.0 = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.Build.0 = Debug|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|ARM64.ActiveCfg = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|ARM64.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.ActiveCfg = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.Build.0 = Release|Any CPU
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.ActiveCfg = Debug|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|Any CPU.Build.0 = Debug|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|ARM64.ActiveCfg = Debug|ARM64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|ARM64.Build.0 = Debug|ARM64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.ActiveCfg = Debug|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Debug|x64.Build.0 = Debug|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.ActiveCfg = Release|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.Build.0 = Release|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|ARM64.ActiveCfg = Release|ARM64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|ARM64.Build.0 = Release|ARM64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.ActiveCfg = Release|x64
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.Build.0 = Release|x64
{7C625EC4-F599-4350-A915-F046DF2406D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C625EC4-F599-4350-A915-F046DF2406D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C625EC4-F599-4350-A915-F046DF2406D3}.Debug|ARM64.ActiveCfg = Debug|Any CPU
@@ -216,6 +220,36 @@ Global
{1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|ARM64.Build.0 = Release|Any CPU
{1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x64.ActiveCfg = Release|Any CPU
{1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x64.Build.0 = Release|Any CPU
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|Any CPU.ActiveCfg = Debug|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|Any CPU.Build.0 = Debug|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|ARM64.ActiveCfg = Debug|ARM64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|ARM64.Build.0 = Debug|ARM64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|x64.ActiveCfg = Debug|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Debug|x64.Build.0 = Debug|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|Any CPU.ActiveCfg = Release|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|Any CPU.Build.0 = Release|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|ARM64.ActiveCfg = Release|ARM64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|ARM64.Build.0 = Release|ARM64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|x64.ActiveCfg = Release|x64
{FA18BA9F-76BF-4DE0-8D24-02FC7657E6CB}.Release|x64.Build.0 = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|Any CPU.ActiveCfg = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|Any CPU.Build.0 = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|Any CPU.Deploy.0 = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|ARM64.Build.0 = Debug|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|ARM64.Deploy.0 = Debug|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|x64.ActiveCfg = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|x64.Build.0 = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Debug|x64.Deploy.0 = Debug|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|Any CPU.ActiveCfg = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|Any CPU.Build.0 = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|Any CPU.Deploy.0 = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|ARM64.ActiveCfg = Release|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|ARM64.Build.0 = Release|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|ARM64.Deploy.0 = Release|ARM64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|x64.ActiveCfg = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|x64.Build.0 = Release|x64
{0071701E-B9C5-4098-BE5F-EF556C4553C6}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -234,6 +268,7 @@ Global
{1F37A704-3CDF-45BB-8114-ED9137E5F2CF} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{A5997814-D8D2-4541-87AC-C3E53CAA67C0} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA}
{514FF00E-BBF0-4D55-A47C-EEEB6208ADCE} = {8DCE343F-BA78-4FE1-B562-B57C603A8BAA}
{0071701E-B9C5-4098-BE5F-EF556C4553C6} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
+21 -1
ファイルの表示
@@ -3,9 +3,29 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Company>Sergio Pedri</Company>
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
<NoWarn>$(NoWarn);MSB3270</NoWarn>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<PackageVersion>2.0.0</PackageVersion>
<RepositoryUrl>https://github.com/Sergio0694/ComputeSharp/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp/</ProjectUrl>
<Authors>Sergio Pedri</Authors>
<Owners>Sergio Pedri</Owners>
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl>https://user-images.githubusercontent.com/10199417/110238403-b8811080-7f41-11eb-8cfe-e47e7e58f05b.png</PackageIconUrl>
<PackageTags>dotnet net netcore netstandard csharp library graphics directx shader hlsl compute gpu performance parallel windows</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="0.1.66" PrivateAssets="all" />
</ItemGroup>
</Project>
+12
ファイルの表示
@@ -0,0 +1,12 @@
<Application
x:Class="ComputeSharp.SwapChain.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
+32
ファイルの表示
@@ -0,0 +1,32 @@
using ComputeSharp.SwapChain.WinUI.Views;
using Microsoft.UI.Xaml;
namespace ComputeSharp.SwapChain.WinUI;
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// The main application window
/// </summary>
private Window? mainWindow;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}
/// <inheritdoc/>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
mainWindow = new MainWindow();
mainWindow.Closed += (_, _) => Exit();
mainWindow.Activate();
}
}
バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 432 B

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 208 KiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 5.2 KiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 1.7 KiB

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 637 B

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 283 B

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 456 B

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 2.0 KiB

+63
ファイルの表示
@@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>ComputeSharp.SwapChain.WinUI</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
<Content Include="Assets\Misc\noise_low.png" />
<Content Include="..\ComputeSharp.SwapChain\Textures\RustyMetal.png">
<Link>Assets\Textures\RustyMetal.png</Link>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="..\ComputeSharp.SwapChain\Shaders\ColorfulInfinity.cs" Link="Shaders\ColorfulInfinity.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\ContouredLayers.cs" Link="Shaders\ContouredLayers.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\ExtrudedTruchetPattern.cs" Link="Shaders\ExtrudedTruchetPattern.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\FractalTiling.cs" Link="Shaders\FractalTiling.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\MengerJourney.cs" Link="Shaders\MengerJourney.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\TwoTiledTruchet.cs" Link="Shaders\TwoTiledTruchet.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\Octagrams.cs" Link="Shaders\Octagrams.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\ProteanClouds.cs" Link="Shaders\ProteanClouds.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\PyramidPattern.cs" Link="Shaders\PyramidPattern.cs" />
<Compile Include="..\ComputeSharp.SwapChain\Shaders\TriangleGridContouring.cs" Link="Shaders\TriangleGridContouring.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22504-preview" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Core" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Media" Version="7.1.2" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
PrivateAssets="contentfiles;build" />
</ItemGroup>
</Project>
+19
ファイルの表示
@@ -0,0 +1,19 @@
using Microsoft.UI.Xaml.Controls;
namespace ComputeSharp.SwapChain.WinUI.Converters;
/// <summary>
/// A class with some static converters for rendering state.
/// </summary>
public static class RenderingPauseConverter
{
/// <summary>
/// Gets a symbol for an input rendering state.
/// </summary>
/// <param name="value">Whether or not the rendering is currently paaused.</param>
/// <returns>A symbol representing the next action for the rendering.</returns>
public static Symbol ConvertPausedToSymbol(bool value)
{
return value ? Symbol.Play : Symbol.Pause;
}
}
+27
ファイルの表示
@@ -0,0 +1,27 @@
namespace ComputeSharp.SwapChain.WinUI.Converters;
/// <summary>
/// A class with some static converters for resolution scale settings.
/// </summary>
public static class ResolutionScaleConverter
{
/// <summary>
/// Converts a resolution scale to a formatted string.
/// </summary>
/// <param name="value">The input resolution scale (in percentage).</param>
/// <returns>A formatted percentage string for <paramref name="value"/>.</returns>
public static string ConvertPercentageToFormattedString(int value)
{
return $"{value}%";
}
/// <summary>
/// Converts a percentage value to a scaled value in the [0, 1] range.
/// </summary>
/// <param name="value">The input percentage value to scale.</param>
/// <returns>The input percentage scaled to the [0, 1] range.</returns>
public static double ConvertPercentageToScale(int value)
{
return value / 100.0;
}
}
+43
ファイルの表示
@@ -0,0 +1,43 @@
using CommunityToolkit.Mvvm.ComponentModel;
using ComputeSharp.WinUI;
namespace ComputeSharp.SwapChain.WinUI.Models;
/// <summary>
/// A model for a compute shader.
/// </summary>
/// <remarks>This can be converted to a record when bindings are fixed, see notes in the XAML code.</remarks>
public sealed class ComputeShader : ObservableObject
{
/// <summary>
/// Creates a new <see cref="ComputeShader"/> instance.
/// </summary>
/// <param name="name">The name of the shader.</param>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
public ComputeShader(string name, IShaderRunner shaderRunner)
{
Name = name;
ShaderRunner = shaderRunner;
}
/// <summary>
/// Gets the name of the shader.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the <see cref="IShaderRunner"/> instance to execute.
/// </summary>
public IShaderRunner ShaderRunner { get; }
private bool isSelected;
/// <summary>
/// Gets or sets whether the current shader is selected.
/// </summary>
public bool IsSelected
{
get => this.isSelected;
set => SetProperty(ref this.isSelected, value);
}
}
+48
ファイルの表示
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="0500384f-0d39-4588-96ba-14ccff63085b"
Publisher="CN=Sergio"
Version="1.0.0.0" />
<Properties>
<DisplayName>ComputeSharp.SwapChain.WinUI</DisplayName>
<PublisherDisplayName>Sergio</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="ComputeSharp.SwapChain.WinUI"
Description="ComputeSharp.SwapChain.WinUI"
BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
+19
ファイルの表示
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x64</Platform>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
</PropertyGroup>
</Project>
+7
ファイルの表示
@@ -0,0 +1,7 @@
{
"profiles": {
"ComputeSharp.SwapChain.WinUI": {
"commandName": "MsixPackage"
}
}
}
+31
ファイルの表示
@@ -0,0 +1,31 @@
using System;
using System.IO;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.WinUI;
using Windows.ApplicationModel;
namespace ComputeSharp.SwapChain.WinUI.Shaders.Runners;
/// <summary>
/// A specialized <see cref="IShaderRunner"/> for <see cref="ContouredLayers"/>.
/// </summary>
public sealed class ContouredLayersRunner : IShaderRunner
{
/// <summary>
/// A texture for <c>\Textures\RustyMetal.png</c>.
/// </summary>
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
/// <inheritdoc/>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan)
{
if (this.texture is null)
{
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
}
Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
}
}
+130
ファイルの表示
@@ -0,0 +1,130 @@
using System.Collections.Generic;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.SwapChain.WinUI.Models;
using ComputeSharp.WinUI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ComputeSharp.SwapChain.WinUI.Shaders.Runners;
namespace ComputeSharp.SwapChain.WinUI.ViewModels;
/// <summary>
/// The viewmodel for for a view that allows users to select shaders and customize settings.
/// </summary>
public sealed class MainViewModel : ObservableObject
{
/// <summary>
/// Creates a new <see cref="MainViewModel"/> instance.
/// </summary>
public MainViewModel()
{
this.isDynamicResolutionEnabled = true;
this.selectedResolutionScale = 100;
this.selectedComputeShader = ComputeShaderOptions[0];
this.selectedComputeShader.IsSelected = true;
SetResolutionScaleCommand = new RelayCommand<int>(SetResolutionScale);
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
}
/// <summary>
/// Gets the available resolution scaling options (as percentage values).
/// </summary>
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
private bool isDynamicResolutionEnabled;
/// <summary>
/// Gets or sets whether the dynamic resolution is enabled.
/// </summary>
public bool IsDynamicResolutionEnabled
{
get => this.isDynamicResolutionEnabled;
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
}
private int selectedResolutionScale;
/// <summary>
/// Gets the currently selected resolution scale setting (as percentage valaue).
/// </summary>
public int SelectedResolutionScale
{
get => this.selectedResolutionScale;
private set => SetProperty(ref this.selectedResolutionScale, value);
}
/// <summary>
/// Gets the command that sets <see cref="SelectedResolutionScale"/>.
/// </summary>
public IRelayCommand SetResolutionScaleCommand { get; }
/// <summary>
/// Sets <see cref="SelectedResolutionScale"/>.
/// </summary>
private void SetResolutionScale(int resolutionScale)
{
SelectedResolutionScale = resolutionScale;
}
/// <summary>
/// Gets the collection of available compute shader.
/// </summary>
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
{
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
new("Contoured layers", new ContouredLayersRunner())
};
private ComputeShader selectedComputeShader;
/// <summary>
/// Gets or sets the currently selected compute shader.
/// </summary>
public ComputeShader SelectedComputeShader
{
get => this.selectedComputeShader;
set
{
this.selectedComputeShader.IsSelected = false;
if (SetProperty(ref this.selectedComputeShader, value) &&
value is not null)
{
value.IsSelected = true;
}
}
}
private bool isRenderingPaused;
/// <summary>
/// Gets or sets whether the rendering is currently paused.
/// </summary>
public bool IsRenderingPaused
{
get => this.isRenderingPaused;
set => SetProperty(ref this.isRenderingPaused, value);
}
/// <summary>
/// Gets the command that toggles <see cref="IsRenderingPaused"/>.
/// </summary>
public IRelayCommand ToggleRenderingPausedCommand { get; }
/// <summary>
/// Toggles <see cref="IsRenderingPaused"/>.
/// </summary>
private void ToggleRenderingPaused()
{
IsRenderingPaused = !IsRenderingPaused;
}
}
+212
ファイルの表示
@@ -0,0 +1,212 @@
<Window
x:Class="ComputeSharp.SwapChain.WinUI.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
xmlns:animations="using:CommunityToolkit.WinUI.UI.Animations"
xmlns:media="using:CommunityToolkit.WinUI.UI.Media"
xmlns:computesharp="using:ComputeSharp.WinUI"
xmlns:converters="using:ComputeSharp.SwapChain.WinUI.Converters"
xmlns:viewmodels="using:ComputeSharp.SwapChain.WinUI.ViewModels"
xmlns:models="using:ComputeSharp.SwapChain.WinUI.Models"
mc:Ignorable="d">
<Grid x:Name="Root">
<Grid.DataContext>
<viewmodels:MainViewModel x:Name="ViewModel"/>
</Grid.DataContext>
<Grid.Resources>
<!--Shader selection panel. This is declared as a resource and then added and removed to the visual
tree entirely instead of just changing its visibility, so that the loaded panels can detect the
change and stop their render loops. This avoids wasting GPU resources when the panel isn't visible.-->
<Border
x:Key="ShaderSelectionPanel"
x:Name="ShaderSelectionPanel"
IsTapEnabled="True"
Tapped="ShaderSelectionPanel_Tapped">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation Duration="0:0:0.5" From="0" To="1.0"/>
</animations:Implicit.ShowAnimations>
<animations:Implicit.HideAnimations>
<animations:OpacityAnimation Duration="0:0:0.5" From="1.0" To="0"/>
</animations:Implicit.HideAnimations>
<Border.Background>
<media:AcrylicBrush
TintColor="#FF222222"
TintOpacity="0.2"
BlurAmount="12"
TextureUri="ms-appx:///Assets/Misc/noise_low.png"/>
</Border.Background>
<!--Shadow panel with the shaders list-->
<controls:DropShadowPanel
ShadowOpacity="1"
BlurRadius="20"
OffsetY="-2"
OffsetX="-12"
IsMasked="True"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Bottom">
<animations:Implicit.ShowAnimations>
<animations:TranslationAnimation Duration="0:0:0.5" From="0,320,0" To="0"/>
</animations:Implicit.ShowAnimations>
<animations:Implicit.HideAnimations>
<animations:TranslationAnimation Duration="0:0:0.5" From="0" To="0,320,0"/>
</animations:Implicit.HideAnimations>
<Border
Height="320"
Margin="-20,0,-20,0"
Background="#FF222222">
<!--Shaders list-->
<ListView
ItemsSource="{x:Bind ViewModel.ComputeShaderOptions}"
SelectionMode="Single"
SelectedItem="{x:Bind ViewModel.SelectedComputeShader, Mode=TwoWay}"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ListView.Resources>
<!--Lightweight styling to remove the selection background with the accent color, and
to remove the padding and stretch the list items to occupy all the available space-->
<SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="Transparent"/>
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="Transparent"/>
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPressed" Color="Transparent"/>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.Resources>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<!--Shader template-->
<DataTemplate x:DataType="models:ComputeShader">
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ui:UIElementExtensions.ClipToBounds="True">
<!--Shader preview-->
<computesharp:ComputeShaderPanel
Width="568"
ShaderRunner="{x:Bind ShaderRunner}"/>
<!--Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
current template scope. Once that's fixed in WinUI 3, this can be rewritten as a multi-binding like this:
Visibility="{x:Bind system:Object.ReferenceEquals((local:ComputeShader), ViewModel.SelectedComputeShader), Mode=OneWay}".
When that is working, the ComputeShader.IsSelected property can also be removed, as it will no longer be needed.-->
<Border
BorderThickness="4"
BorderBrush="White"
Visibility="{x:Bind IsSelected, Mode=OneWay}">
<Polygon
VerticalAlignment="Top"
HorizontalAlignment="Right"
Points="0,0 32,0 32,32"
Fill="White"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
</controls:DropShadowPanel>
</Border>
</Grid.Resources>
<!--Shader-->
<computesharp:ComputeShaderPanel
x:Name="ShaderPanel"
Grid.Row="1"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"/>
<!--Settings panel-->
<StackPanel
Orientation="Horizontal"
Spacing="20"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="48">
<!--Shader pause button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Command="{x:Bind ViewModel.ToggleRenderingPausedCommand}">
<SymbolIcon Symbol="{x:Bind converters:RenderingPauseConverter.ConvertPausedToSymbol(ViewModel.IsRenderingPaused), Mode=OneWay}"/>
</Button>
<!--Shader selection button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Click="OpenShaderSelectionPanelButton_Click">
<SymbolIcon Symbol="Pictures"/>
</Button>
<!--Settings button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Settings">
<SymbolIcon Symbol="Setting"/>
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem
Text="Dynamic resolution"
IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}"/>
<MenuFlyoutSeparator/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[0])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[0]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[0]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[1])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[1]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[1]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[2])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[2]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[2]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[3])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[3]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[3]), Mode=OneWay}"/>
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
<!--Invisible title bar-->
<Rectangle
x:Name="TitleBarRectangle"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Height="32"
Fill="Transparent"/>
</Grid>
</Window>
+31
ファイルの表示
@@ -0,0 +1,31 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
namespace ComputeSharp.SwapChain.WinUI.Views;
/// <summary>
/// A view for <see cref="MainViewModel"/>.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true;
SetTitleBar(TitleBarRectangle);
}
// Opens the shader selection panel
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
{
Root.Resources.Remove("ShaderSelectionPanel");
Root.Children.Add(ShaderSelectionPanel);
}
// Hides the shader selection panel
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
{
Root.Children.Remove(ShaderSelectionPanel);
}
}
+15
ファイルの表示
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="ComputeSharp.SwapChain.WinUI.app"/>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- The combination of below two tags have the following effect:
1) Per-Monitor for >= Windows 10 Anniversary Update
2) System < Windows 10 Anniversary Update
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
</assembly>
+1
ファイルの表示
@@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Platforms>x64;ARM64</Platforms>
</PropertyGroup>
<ItemGroup>
-13
ファイルの表示
@@ -8,19 +8,6 @@
<PackageId>ComputeSharp</PackageId>
<Title>ComputeSharp</Title>
<Description>A library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders</Description>
<PackageVersion>2.0.0</PackageVersion>
<RepositoryUrl>https://github.com/Sergio0694/ComputeSharp/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp/</ProjectUrl>
<Authors>Sergio Pedri</Authors>
<Owners>Sergio Pedri</Owners>
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl>https://user-images.githubusercontent.com/10199417/110238403-b8811080-7f41-11eb-8cfe-e47e7e58f05b.png</PackageIconUrl>
<PackageTags>dotnet net netcore netstandard csharp library graphics shader hlsl compute gpu performance parallel</PackageTags>
</PropertyGroup>
<ItemGroup>
+30
ファイルの表示
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>ComputeSharp.WinUI</RootNamespace>
<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
</PropertyGroup>
<PropertyGroup>
<PackageId>ComputeSharp.WinUI</PackageId>
<Title>ComputeSharp.WinUI</Title>
<Description>A WinUI 3 library with controls to render DX12 shaders powered by ComputeSharp</Description>
<PackageTags>$(PackageTags) winui winui3 wasdk</PackageTags>
</PropertyGroup>
<ItemGroup>
<None Include="..\ComputeSharp.Package\icon.png" Pack="true" PackagePath="\icon.png" Visible="False" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22504-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp\ComputeSharp.csproj" />
</ItemGroup>
</Project>
+123
ファイルの表示
@@ -0,0 +1,123 @@
using System;
using Microsoft.UI.Xaml;
namespace ComputeSharp.WinUI;
/// <inheritdoc cref="ComputeShaderPanel"/>
public sealed unsafe partial class ComputeShaderPanel
{
/// <summary>
/// Gets or sets the <see cref="IShaderRunner"/> instance to use to render content.
/// </summary>
public IShaderRunner? ShaderRunner
{
get => (IShaderRunner?)GetValue(ShaderFactoryProperty);
set => SetValue(ShaderFactoryProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="ShaderRunner"/>.
/// </summary>
public static readonly DependencyProperty ShaderFactoryProperty = DependencyProperty.Register(
nameof(ShaderRunner),
typeof(IShaderRunner),
typeof(ComputeShaderPanel),
new PropertyMetadata(null, static (d, e) => ((ComputeShaderPanel)d).shaderRunner = (IShaderRunner?)e.NewValue));
/// <summary>
/// Gets or sets the resolution scale to be used to render frames.
/// This can help achieve higher framerates with more complex shaders.
/// </summary>
/// <remarks>The accepted range is [0.1 and 1] (default is 1, exceeding values will be clamped).</remarks>
public double ResolutionScale
{
get => (double)GetValue(ResolutionScaleProperty);
set => SetValue(ResolutionScaleProperty, Math.Clamp(value, 0.1, 1.0));
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="ResolutionScale"/>.
/// </summary>
public static readonly DependencyProperty ResolutionScaleProperty = DependencyProperty.Register(
nameof(ResolutionScale),
typeof(double),
typeof(ComputeShaderPanel),
new PropertyMetadata(1.0, OnResolutionScalePropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnResolutionScalePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (ComputeShaderPanel)d;
var resolutionScale = (double)e.NewValue;
@this.targetResolutionScale = (float)resolutionScale;
if (!@this.isDynamicResolutionEnabled)
{
@this.OnResize();
}
}
/// <summary>
/// Gets or sets whether dynamic resolution is enabled. If it is, the internal render
/// resolution of the shader being run will be automatically adjusted to reach 60fps.
/// <para>The default value for this property is <see langword="true"/>.</para>
/// </summary>
public bool IsDynamicResolutionEnabled
{
get => (bool)GetValue(IsDynamicResolutionEnabledProperty);
set => SetValue(IsDynamicResolutionEnabledProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="IsDynamicResolutionEnabled"/>.
/// </summary>
public static readonly DependencyProperty IsDynamicResolutionEnabledProperty = DependencyProperty.Register(
nameof(IsDynamicResolutionEnabled),
typeof(bool),
typeof(ComputeShaderPanel),
new PropertyMetadata(true, OnIsDynamicResolutionEnabledPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnIsDynamicResolutionEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (ComputeShaderPanel)d;
var isDynamicResolutionEnabled = (bool)e.NewValue;
@this.isDynamicResolutionEnabled = isDynamicResolutionEnabled;
}
/// <summary>
/// Gets or sets whether or not the rendering is paused.
/// </summary>
public bool IsPaused
{
get => (bool)GetValue(IsPausedProperty);
set => SetValue(IsPausedProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="IsPaused"/>.
/// </summary>
public static readonly DependencyProperty IsPausedProperty = DependencyProperty.Register(
nameof(IsPaused),
typeof(bool),
typeof(ComputeShaderPanel),
new PropertyMetadata(false, OnIsPausedPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnIsPausedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (ComputeShaderPanel)d;
var isPaused = (bool)e.NewValue;
if (isPaused)
{
@this.OnStopRenderLoop();
}
else
{
@this.OnStartRenderLoop();
}
}
}
+525
ファイルの表示
@@ -0,0 +1,525 @@
using System;
using System.Diagnostics;
using System.Threading;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Interop;
using ComputeSharp.WinUI.Helpers;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using TerraFX.Interop.WinRT;
using WinRT;
using Win32 = TerraFX.Interop.Windows.Windows;
#pragma warning disable CS0420
namespace ComputeSharp.WinUI;
/// <inheritdoc cref="ComputeShaderPanel"/>
public sealed partial class ComputeShaderPanel
{
/// <summary>
/// The render thread in use, if any.
/// </summary>
private Thread? renderThread;
/// <summary>
/// The <see cref="IShaderRunner"/> instance used to create shaders to run.
/// </summary>
private IShaderRunner? shaderRunner;
/// <summary>
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
/// </summary>
private ComPtr<ID3D12Device> d3D12Device;
/// <summary>
/// The <see cref="ID3D12CommandQueue"/> instance to use for graphics operations.
/// </summary>
private ComPtr<ID3D12CommandQueue> d3D12CommandQueue;
/// <summary>
/// The <see cref="ID3D12Fence"/> instance used for graphics operations.
/// </summary>
private ComPtr<ID3D12Fence> d3D12Fence;
/// <summary>
/// The next fence value for graphics operations using <see cref="d3D12CommandQueue"/>.
/// </summary>
private ulong nextD3D12FenceValue = 1;
/// <summary>
/// The <see cref="ID3D12CommandAllocator"/> object to create command lists.
/// </summary>
private ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator;
/// <summary>
/// The <see cref="ID3D12GraphicsCommandList"/> instance used to copy data to the back buffers.
/// </summary>
private ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList;
/// <summary>
/// The <see cref="IDXGISwapChain3"/> instance used to display content onto the target window.
/// </summary>
private ComPtr<IDXGISwapChain3> dxgiSwapChain3;
/// <summary>
/// The awaitable object for <see cref="IDXGISwapChain1.Present"/> calls.
/// </summary>
private HANDLE frameLatencyWaitableObject;
/// <summary>
/// The first buffer within <see cref="dxgiSwapChain3"/>.
/// </summary>
private ComPtr<ID3D12Resource> d3D12Resource0;
/// <summary>
/// The second buffer within <see cref="dxgiSwapChain3"/>.
/// </summary>
private ComPtr<ID3D12Resource> d3D12Resource1;
/// <summary>
/// The index of the next buffer that can be used to present content.
/// </summary>
private uint currentBufferIndex;
/// <summary>
/// The <see cref="ReadWriteTexture2D{T, TPixel}"/> instance used to prepare frames to display.
/// </summary>
private ReadWriteTexture2D<Rgba32, Float4>? texture;
/// <summary>
/// Whether or not the window has been resized and requires the buffers to be updated.
/// </summary>
private volatile bool isResizePending;
/// <summary>
/// The backing store for <see cref="ActualWidth"/> for the render thread.
/// </summary>
private volatile float width;
/// <summary>
/// The backing store for <see cref="ActualHeight"/> for the render thread.
/// </summary>
private volatile float height;
/// <summary>
/// The backing store for <see cref="CompositionScaleX"/> for the render thread.
/// </summary>
private volatile float compositionScaleX;
/// <summary>
/// The backing store for <see cref="CompositionScaleY"/> for the render thread.
/// </summary>
private volatile float compositionScaleY;
/// <summary>
/// The resolution scale used to render frames when explicitly controlled by the user.
/// </summary>
private volatile float resolutionScale;
/// <summary>
/// The resolution scale used to render frames, in either render mode.
/// </summary>
private volatile float targetResolutionScale;
/// <summary>
/// Whether dynamic resolution is currently enabled.
/// </summary>
private volatile bool isDynamicResolutionEnabled;
/// <summary>
/// Indicates whether or not the rendering has been canceled.
/// </summary>
private volatile bool isCancellationRequested;
/// <summary>
/// The <see cref="Stopwatch"/> instance tracking time since the first rendered frame.
/// </summary>
private Stopwatch? renderStopwatch;
/// <summary>
/// Indicates whether or not <see cref="OnInitialize"/> has already been called.
/// </summary>
private bool isInitialized;
/// <summary>
/// Initializes the current application.
/// </summary>
private unsafe void OnInitialize()
{
if (this.isInitialized)
{
return;
}
this.isInitialized = true;
// Get the underlying ID3D12Device in use
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
{
InteropServices.TryGetID3D12Device(Gpu.Default, Win32.__uuidof<ID3D12Device>(), (void**)d3D12Device).Assert();
}
// Create the direct command queue to use
fixed (ID3D12CommandQueue** d3D12CommandQueue = this.d3D12CommandQueue)
{
D3D12_COMMAND_QUEUE_DESC d3D12CommandQueueDesc;
d3D12CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT;
d3D12CommandQueueDesc.Priority = (int)D3D12_COMMAND_QUEUE_PRIORITY.D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
d3D12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAGS.D3D12_COMMAND_QUEUE_FLAG_NONE;
d3D12CommandQueueDesc.NodeMask = 0;
this.d3D12Device.Get()->CreateCommandQueue(
&d3D12CommandQueueDesc,
Win32.__uuidof<ID3D12CommandQueue>(),
(void**)d3D12CommandQueue).Assert();
}
// Create the direct fence
fixed (ID3D12Fence** d3D12Fence = this.d3D12Fence)
{
this.d3D12Device.Get()->CreateFence(
0,
D3D12_FENCE_FLAGS.D3D12_FENCE_FLAG_NONE,
Win32.__uuidof<ID3D12Fence>(),
(void**)d3D12Fence).Assert();
}
// Create the swap chain to display frames
using (ComPtr<IDXGIFactory6> dxgiFactory6 = default)
{
DeviceHelper.CreateDXGIFactory6(dxgiFactory6.GetAddressOf());
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE;
dxgiSwapChainDesc1.BufferCount = 2;
dxgiSwapChainDesc1.Flags = (uint)DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
dxgiSwapChainDesc1.Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
dxgiSwapChainDesc1.Width = (uint)Math.Max(Math.Ceiling(this.width * this.compositionScaleX * this.targetResolutionScale), 1.0);
dxgiSwapChainDesc1.Height = (uint)Math.Max(Math.Ceiling(this.height * this.compositionScaleY * this.targetResolutionScale), 1.0);
dxgiSwapChainDesc1.SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0);
dxgiSwapChainDesc1.Scaling = DXGI_SCALING.DXGI_SCALING_STRETCH;
dxgiSwapChainDesc1.Stereo = 0;
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
dxgiSwapChainDesc1.BufferUsage = DXGI.DXGI_USAGE_RENDER_TARGET_OUTPUT;
using ComPtr<IDXGISwapChain1> dxgiSwapChain1 = default;
dxgiFactory6.Get()->CreateSwapChainForComposition(
(IUnknown*)this.d3D12CommandQueue.Get(),
&dxgiSwapChainDesc1,
null,
(IDXGISwapChain1**)&dxgiSwapChain1).Assert();
fixed (IDXGISwapChain3** dxgiSwapChain3 = this.dxgiSwapChain3)
{
dxgiSwapChain1.CopyTo(dxgiSwapChain3).Assert();
}
}
// Get the awaitable object to synchronizize present calls
this.frameLatencyWaitableObject = this.dxgiSwapChain3.Get()->GetFrameLatencyWaitableObject();
// Create the command allocator to use
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
{
this.d3D12Device.Get()->CreateCommandAllocator(
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
Win32.__uuidof<ID3D12CommandAllocator>(),
(void**)d3D12CommandAllocator).Assert();
}
// Create the reusable command list to copy data to the back buffers
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
{
this.d3D12Device.Get()->CreateCommandList(
0,
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
this.d3D12CommandAllocator,
null,
Win32.__uuidof<ID3D12GraphicsCommandList>(),
(void**)d3D12GraphicsCommandList).Assert();
}
// Close the command list to prepare it for future use
this.d3D12GraphicsCommandList.Get()->Close().Assert();
// Extract the ISwapChainPanelNative reference from the current panel, then query the
// IDXGISwapChain reference just created and set that as the swap chain panel to use.
using ComPtr<ISwapChainPanelNative> swapChainPanelNative = default;
IUnknown* swapChainPanel = (IUnknown*)((IWinRTObject)this).NativeObject.ThisPtr;
Guid iSwapChainPanelNativeUuid = new(0x63AAD0B8, 0x7C24, 0x40FF, 0x85, 0xA8, 0x64, 0x0D, 0x94, 0x4C, 0xC3, 0x25);
swapChainPanel->QueryInterface(
&iSwapChainPanelNativeUuid,
(void**)&swapChainPanelNative).Assert();
using (ComPtr<IDXGISwapChain> idxgiSwapChain = default)
{
this.dxgiSwapChain3.CopyTo(&idxgiSwapChain).Assert();
swapChainPanelNative.Get()->SetSwapChain(idxgiSwapChain.Get()).Assert();
}
GC.KeepAlive(this);
}
/// <summary>
/// Resizes the current application.
/// </summary>
private void OnResize()
{
this.isResizePending = true;
}
/// <summary>
/// Applies the actual resize logic that was scheduled from <see cref="OnResize"/>.
/// </summary>
private unsafe void ApplyResize()
{
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue).Assert();
// Wait for the fence again to ensure there are no pending operations
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default).Assert();
this.nextD3D12FenceValue++;
// Dispose the old buffers before resizing the buffer
this.d3D12Resource0.Dispose();
this.d3D12Resource1.Dispose();
// Resize the swap chain buffers
this.dxgiSwapChain3.Get()->ResizeBuffers(
2,
(uint)Math.Max(Math.Ceiling(this.width * this.compositionScaleX * this.targetResolutionScale), 1.0),
(uint)Math.Max(Math.Ceiling(this.height * this.compositionScaleY * this.targetResolutionScale), 1.0),
DXGI_FORMAT.DXGI_FORMAT_UNKNOWN,
(uint)DXGI_SWAP_CHAIN_FLAG.DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT).Assert();
// Apply the necessary scale transform
DXGI_MATRIX_3X2_F transformMatrix = default;
transformMatrix._11 = (1 / this.compositionScaleX) * (1 / this.targetResolutionScale);
transformMatrix._22 = (1 / this.compositionScaleY) * (1 / this.targetResolutionScale);
this.dxgiSwapChain3.Get()->SetMatrixTransform(&transformMatrix).Assert();
// Retrieve the back buffers for the swap chain
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
{
this.dxgiSwapChain3.Get()->GetBuffer(0, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0).Assert();
this.dxgiSwapChain3.Get()->GetBuffer(1, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1).Assert();
}
// Get the index of the initial back buffer
this.currentBufferIndex = this.dxgiSwapChain3.Get()->GetCurrentBackBufferIndex();
this.texture?.Dispose();
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
// Create the 2D texture to use to generate frames to display
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Float4>(
(int)d3D12Resource0Description.Width,
(int)d3D12Resource0Description.Height);
}
/// <summary>
/// Updates the render resolution, if needed, and renders a new frame.
/// </summary>
/// <param name="time">The current time since the start of the application.</param>
private unsafe void OnUpdate(TimeSpan time)
{
if (this.isResizePending)
{
ApplyResize();
this.isResizePending = false;
}
// Skip if no factory is available
if (this.shaderRunner is null)
{
return;
}
// Generate the new frame
this.shaderRunner.Execute(this.texture!, time);
}
/// <summary>
/// Presents the last rendered frame for the current application.
/// </summary>
private unsafe void OnPresent()
{
_ = Win32.WaitForSingleObjectEx(frameLatencyWaitableObject, 1000, 1);
using ComPtr<ID3D12Resource> d3D12Resource = default;
// Get the underlying ID3D12Resource pointer for the texture
InteropServices.TryGetID3D12Resource(this.texture!, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf()).Assert();
// Get the target back buffer to update
ID3D12Resource* d3D12ResourceBackBuffer = this.currentBufferIndex switch
{
0 => this.d3D12Resource0.Get(),
1 => this.d3D12Resource1.Get(),
_ => null
};
this.currentBufferIndex ^= 1;
// Reset the command list and command allocator
this.d3D12CommandAllocator.Get()->Reset().Assert();
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null).Assert();
D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
{
D3D12_RESOURCE_BARRIER.InitTransition(
d3D12Resource.Get(),
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE),
D3D12_RESOURCE_BARRIER.InitTransition(
d3D12ResourceBackBuffer,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST)
};
// Transition the resources to COPY_DEST and COPY_SOURCE respectively
this.d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
// Copy the generated frame to the target back buffer
this.d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
d3D12ResourceBarriers[0] = D3D12_RESOURCE_BARRIER.InitTransition(
d3D12Resource.Get(),
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
d3D12ResourceBarriers[1] = D3D12_RESOURCE_BARRIER.InitTransition(
d3D12ResourceBackBuffer,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON);
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
this.d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
this.d3D12GraphicsCommandList.Get()->Close().Assert();
// Execute the command list to perform the copy
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)this.d3D12GraphicsCommandList.GetAddressOf());
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue).Assert();
// Present the new frame
this.dxgiSwapChain3.Get()->Present(0, 0).Assert();
if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
{
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default).Assert();
}
this.nextD3D12FenceValue++;
}
/// <summary>
/// Executes the render loop for the current panel.
/// </summary>
/// <remarks>This method assumes to be invoked from a background thread.</remarks>
private void OnStartRenderLoop()
{
static void ExecuteRenderLoop(ComputeShaderPanel @this)
{
Stopwatch
renderStopwatch = @this.renderStopwatch ??= new(),
frameStopwatch = Stopwatch.StartNew();
DynamicResolutionManager.Create(out DynamicResolutionManager frameTimeWatcher);
bool isDynamicResolutionEnabled = @this.isDynamicResolutionEnabled;
// Start the initial frame separately, before the timer starts. This ensures that
// resuming after a pause correctly renders the first frame at the right time.
@this.OnUpdate(renderStopwatch.Elapsed);
@this.OnPresent();
renderStopwatch.Start();
const long targetFrameTimeInTicksFor61fps = 163934;
// Main render loop, until cancellation is requested
while (!@this.isCancellationRequested)
{
// Update the resolution mode, if needed
if (isDynamicResolutionEnabled != @this.isDynamicResolutionEnabled)
{
isDynamicResolutionEnabled = !isDynamicResolutionEnabled;
if (isDynamicResolutionEnabled)
{
DynamicResolutionManager.Create(out frameTimeWatcher);
}
else
{
@this.targetResolutionScale = @this.resolutionScale;
}
}
// Evaluate the dynamic resolution frame time step, if the mode is enabled
if (isDynamicResolutionEnabled &&
frameTimeWatcher.Advance(frameStopwatch.ElapsedTicks, ref @this.targetResolutionScale))
{
@this.isResizePending = true;
}
while (frameStopwatch.ElapsedTicks < targetFrameTimeInTicksFor61fps)
{
}
frameStopwatch.Restart();
@this.OnUpdate(renderStopwatch.Elapsed);
@this.OnPresent();
}
renderStopwatch.Stop();
}
this.isCancellationRequested = false;
this.renderThread = new Thread(static args => ExecuteRenderLoop((ComputeShaderPanel)args!));
this.renderThread.Start(this);
}
/// <summary>
/// Stops the current render loop, if one is running.
/// </summary>
private void OnStopRenderLoop()
{
this.isCancellationRequested = true;
}
/// <summary>
/// Stops the current render loop, and releases all resources.
/// </summary>
private void OnDisposed()
{
this.isCancellationRequested = true;
// Ensure the rendering has stopped
if (this.renderThread is Thread renderThread)
{
renderThread.Join();
}
this.d3D12Device.Dispose();
this.d3D12CommandQueue.Dispose();
this.d3D12Fence.Dispose();
this.d3D12CommandAllocator.Dispose();
this.d3D12GraphicsCommandList.Dispose();
this.dxgiSwapChain3.Dispose();
this.d3D12Resource0.Dispose();
this.d3D12Resource1.Dispose();
this.texture?.Dispose();
}
}
+69
ファイルの表示
@@ -0,0 +1,69 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace ComputeSharp.WinUI;
/// <summary>
/// A custom <see cref="SwapChainPanel"/> that can be used to render animated backgrounds.
/// It is powered by ComputeSharp and leverages compute shaders to create frames to display.
/// </summary>
public sealed unsafe partial class ComputeShaderPanel : SwapChainPanel
{
/// <summary>
/// Creates a new <see cref="ComputeShaderPanel"/> instance.
/// </summary>
public ComputeShaderPanel()
{
this.Loaded += ComputeShaderPanel_Loaded;
this.Unloaded += ComputeShaderPanel_Unloaded;
this.SizeChanged += ComputeShaderPanel_SizeChanged;
this.CompositionScaleChanged += ComputeShaderPanel_CompositionScaleChanged;
}
/// <summary>
/// Finalizes the current <see cref="ComputeShaderPanel"/> instance and releases all resources.
/// </summary>
~ComputeShaderPanel()
{
OnDisposed();
}
// Initializes the swap chain and starts the render thread
private void ComputeShaderPanel_Loaded(object sender, RoutedEventArgs e)
{
this.width = (float)ActualWidth;
this.height = (float)ActualHeight;
this.compositionScaleX = CompositionScaleX;
this.compositionScaleY = CompositionScaleY;
this.resolutionScale = (float)ResolutionScale;
this.targetResolutionScale = 1.0f;
this.isDynamicResolutionEnabled = true;
OnInitialize();
OnStartRenderLoop();
}
// Requests a cancellation for the render thread
private void ComputeShaderPanel_Unloaded(object sender, RoutedEventArgs e)
{
OnStopRenderLoop();
}
// Updates the background store for the frame size factors used by the render thread
private void ComputeShaderPanel_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.width = (float)e.NewSize.Width;
this.height = (float)e.NewSize.Height;
OnResize();
}
// Updates the background store for the composition scale factors used by the render thread
private void ComputeShaderPanel_CompositionScaleChanged(SwapChainPanel sender, object args)
{
this.compositionScaleX = CompositionScaleX;
this.compositionScaleY = CompositionScaleY;
OnResize();
}
}
+3
ファイルの表示
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\..\Directory.Build.props" />
</Project>
+128
ファイルの表示
@@ -0,0 +1,128 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace ComputeSharp.WinUI.Helpers;
/// <summary>
/// A helper type that is responsible for applying dynamic resolution changes.
/// </summary>
internal unsafe ref struct DynamicResolutionManager
{
/// <summary>
/// The target frame time in ticks to reach 60fps (set to 64fps).
/// </summary>
public const long TargetFrameTimeInTicksFor60fps = 156250;
/// <summary>
/// The upper frame time threshold in ticks to reach 60fps.
/// </summary>
private const long UpperFrameTimeThresholdInTicksFor60fps = 166666;
/// <summary>
/// The lower frame time threshold in ticks to reach 60fps (set to 68fps).
/// </summary>
private const long LowerFrameTimeThresholdInTicksFor60fps = 147058;
/// <summary>
/// The size of the sliding frame time window to monitor frame times.
/// </summary>
private const int SlidingFrameTimeWindowLength = 32;
/// <summary>
/// The threshold for scale factor updates.
/// </summary>
private const float ScaleFactorDeltaThreshold = 0.005f;
/// <summary>
/// The constant multiplicative factor for the scale factor.
/// </summary>
private const float ScaleFactorDeltaK = 0.8f;
/// <summary>
/// The window of registered frame times for previous frames.
/// </summary>
private fixed long frameTimesInTicks[SlidingFrameTimeWindowLength];
/// <summary>
/// The current index into <see cref="frameTimesInTicks"/>.
/// </summary>
/// <remarks>
/// This will have a value of <c>-1</c> when a scale factor update has just been applied, indicating
/// that the following frame update should not be tracked to contribute towards the next dynamic resolution
/// check. This is done to avoid having the swap chain resize cost influence the moving average of frame times.
/// </remarks>
private int frameTimeOffset;
/// <summary>
/// The current sum of values within <see cref="frameTimesInTicks"/>.
/// </summary>
private long slidingFrameTimeWindowSum;
/// <summary>
/// Initializes a new <see cref="DynamicResolutionManager"/> instance.
/// </summary>
/// <param name="manager">The resulting <see cref="DynamicResolutionManager"/> instance.</param>
public static void Create(out DynamicResolutionManager manager)
{
manager.frameTimeOffset = 0;
manager.slidingFrameTimeWindowSum = TargetFrameTimeInTicksFor60fps * SlidingFrameTimeWindowLength;
MemoryMarshal.CreateSpan(ref manager.frameTimesInTicks[0], SlidingFrameTimeWindowLength).Fill(TargetFrameTimeInTicksFor60fps);
}
/// <summary>
/// Advances one frame and updates the scale factor, if needed.
/// </summary>
/// <param name="frameTimeInTicks">The frame time in ticks for the last rendered frame.</param>
/// <param name="scaleFactor">The current scale factor value being used to render frames.</param>
/// <returns>Whether or not <paramref name="scaleFactor"/> has been updated and a resize is needed.</returns>
public bool Advance(long frameTimeInTicks, ref float scaleFactor)
{
// Ignore the current frame if a resize has just happened
if (this.frameTimeOffset == -1)
{
this.frameTimeOffset = 0;
return false;
}
ref long previousFrameTimeInTicks = ref this.frameTimesInTicks[this.frameTimeOffset];
this.slidingFrameTimeWindowSum -= previousFrameTimeInTicks;
this.slidingFrameTimeWindowSum += frameTimeInTicks;
previousFrameTimeInTicks = frameTimeInTicks;
this.frameTimeOffset = (int)(((uint)this.frameTimeOffset + 1) % SlidingFrameTimeWindowLength);
// Check for a dynamic resolution update if the end of the sliding window has been reached.
// This is not done every frame to reduce the overhead and amortize for render time fluctuations.
if (this.frameTimeOffset == 0)
{
// This formula is adapted from https://software.intel.com/content/www/us/en/develop/articles/dynamic-resolution-rendering-article.html.
long averageFrameTimeInTicks = this.slidingFrameTimeWindowSum / SlidingFrameTimeWindowLength;
if (averageFrameTimeInTicks is < LowerFrameTimeThresholdInTicksFor60fps or > UpperFrameTimeThresholdInTicksFor60fps)
{
float
frameTimeDelta = (TargetFrameTimeInTicksFor60fps - averageFrameTimeInTicks) / (float)averageFrameTimeInTicks,
scaleFactorDelta = scaleFactor * frameTimeDelta * ScaleFactorDeltaK,
updatedScaleFactor = Math.Clamp(scaleFactor + scaleFactorDelta, 0.10f, 1.0f);
// Apply the scale factor update if the target scale has changed enough. This helps to avoid
// too frequence resolution changes if the scale factor only changes very little every time.
if (Math.Abs(scaleFactor - updatedScaleFactor) >= ScaleFactorDeltaThreshold)
{
Volatile.Write(ref scaleFactor, updatedScaleFactor);
this.frameTimeOffset = -1;
return true;
}
}
}
return false;
}
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
using System;
namespace ComputeSharp.WinUI;
/// <summary>
/// An interface for a shader runner to be used with <see cref="ComputeShaderPanel"/>.
/// </summary>
public interface IShaderRunner
{
/// <summary>
/// Renders a single frame to a texture.
/// </summary>
/// <param name="texture">The target texture to render the frame to.</param>
/// <param name="timespan">The timespan for the current frame.</param>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan);
}
+41
ファイルの表示
@@ -0,0 +1,41 @@
using System;
namespace ComputeSharp.WinUI;
/// <summary>
/// An <see cref="IShaderRunner"/> implementation powered by a supplied shader type.
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed class ShaderRunner<T> : IShaderRunner
where T : struct, IPixelShader<Float4>
{
/// <summary>
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
/// </summary>
private readonly Func<TimeSpan, T> shaderFactory;
/// <summary>
/// Creates a new <see cref="ShaderRunner{T}"/> instance that will create shader instances with
/// the default constructor. Only use this constructor if the shader doesn't require any additional
/// resources or other parameters being initialized before being dispatched on the GPU.
/// </summary>
public ShaderRunner()
{
this.shaderFactory = static _ => default;
}
/// <summary>
/// Creates a new <see cref="ShaderRunner{T}"/> instance.
/// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param>
public ShaderRunner(Func<TimeSpan, T> shaderFactory)
{
this.shaderFactory = shaderFactory;
}
/// <inheritdoc/>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time)
{
Gpu.Default.ForEach(texture, this.shaderFactory(time));
}
}
-2
ファイルの表示
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<OutputPath>bin\Release</OutputPath>
@@ -298,5 +297,4 @@
<LastGenOutput>UIntMxN.g.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
+5 -3
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using ComputeSharp.Core.Extensions;
using TerraFX.Interop.DirectX;
@@ -31,11 +30,13 @@ internal static partial class DeviceHelper
/// Creates a new <see cref="IDXGIFactory6"/> instance to be used to enumerate devices.
/// </summary>
/// <param name="dxgiFactory6">The resulting <see cref="IDXGIFactory6"/> instance.</param>
private static unsafe void CreateDXGIFactory6(IDXGIFactory6** dxgiFactory6)
internal static unsafe void CreateDXGIFactory6(IDXGIFactory6** dxgiFactory6)
{
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
#if DEBUG
EnableDebugMode();
#endif
DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
@@ -58,10 +59,10 @@ internal static partial class DeviceHelper
return;
}
#if DEBUG
/// <summary>
/// Enables the debug layer for DirectX APIs.
/// </summary>
[Conditional("DEBUG")]
private static unsafe void EnableDebugMode()
{
using ComPtr<ID3D12Debug> d3D12Debug = default;
@@ -77,6 +78,7 @@ internal static partial class DeviceHelper
d3D12Debug1.Get()->SetEnableSynchronizedCommandQueueValidation(Windows.TRUE);
}
}
#endif
/// <summary>
/// A custom <see cref="IDXGIFactory6"/> fallback implementation to use on systems with no support for it.
+1
ファイルの表示
@@ -3,3 +3,4 @@
[module: SkipLocalsInit]
[assembly: InternalsVisibleTo("ComputeSharp.Tests.Internals")]
[assembly: InternalsVisibleTo("ComputeSharp.WinUI")]
+1 -6
ファイルの表示
@@ -1,10 +1,5 @@
<Project>
<PropertyGroup>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="0.1.66" PrivateAssets="all" />
<ItemGroup>
<PackageReference Include="NuGetizer" Version="0.7.5" PrivateAssets="all" />
</ItemGroup>