diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 98f47273..0e925cb2 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -58,7 +58,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.WinUI", "src\C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SwapChain.WinUI", "samples\ComputeSharp.SwapChain.WinUI\ComputeSharp.SwapChain.WinUI.csproj", "{0071701E-B9C5-4098-BE5F-EF556C4553C6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.Uwp", "src\ComputeSharp.Uwp\ComputeSharp.Uwp.csproj", "{AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Uwp", "src\ComputeSharp.Uwp\ComputeSharp.Uwp.csproj", "{AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.SwapChain.Uwp", "samples\ComputeSharp.SwapChain.Uwp\ComputeSharp.SwapChain.Uwp.csproj", "{FBD388A5-7855-4408-98FF-E689F509DB5A}" EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution @@ -332,6 +334,58 @@ Global {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 + {1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x86.ActiveCfg = Release|Any CPU + {1F37A704-3CDF-45BB-8114-ED9137E5F2CF}.Release|x86.Build.0 = Release|Any CPU + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|Any CPU.ActiveCfg = Debug|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|Any CPU.Build.0 = Debug|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|ARM.ActiveCfg = Debug|ARM + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|ARM.Build.0 = Debug|ARM + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|ARM64.Build.0 = Debug|ARM64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|x64.ActiveCfg = Debug|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|x64.Build.0 = Debug|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|x86.ActiveCfg = Debug|x86 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Debug|x86.Build.0 = Debug|x86 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|Any CPU.Build.0 = Release|Any CPU + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|ARM.ActiveCfg = Release|ARM + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|ARM.Build.0 = Release|ARM + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|ARM64.ActiveCfg = Release|ARM64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|ARM64.Build.0 = Release|ARM64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|x64.ActiveCfg = Release|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|x64.Build.0 = Release|x64 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|x86.ActiveCfg = Release|x86 + {AFAAFDC9-BE42-45D4-8C79-0EE8C8EDBF52}.Release|x86.Build.0 = Release|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|Any CPU.ActiveCfg = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|Any CPU.Build.0 = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|Any CPU.Deploy.0 = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM.ActiveCfg = Debug|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM.Build.0 = Debug|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM.Deploy.0 = Debug|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM64.Build.0 = Debug|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x64.ActiveCfg = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x64.Build.0 = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x64.Deploy.0 = Debug|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x86.ActiveCfg = Debug|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x86.Build.0 = Debug|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Debug|x86.Deploy.0 = Debug|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|Any CPU.ActiveCfg = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|Any CPU.Build.0 = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|Any CPU.Deploy.0 = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM.ActiveCfg = Release|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM.Build.0 = Release|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM.Deploy.0 = Release|ARM + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM64.ActiveCfg = Release|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM64.Build.0 = Release|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|ARM64.Deploy.0 = Release|ARM64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x64.ActiveCfg = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x64.Build.0 = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x64.Deploy.0 = Release|x64 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x86.ActiveCfg = Release|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x86.Build.0 = Release|x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A}.Release|x86.Deploy.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -351,6 +405,7 @@ Global {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} + {FBD388A5-7855-4408-98FF-E689F509DB5A} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC} diff --git a/samples/ComputeSharp.SwapChain.Uwp/App.xaml b/samples/ComputeSharp.SwapChain.Uwp/App.xaml new file mode 100644 index 00000000..e516409e --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/App.xaml @@ -0,0 +1,6 @@ + + + diff --git a/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs b/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs new file mode 100644 index 00000000..720413f7 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/App.xaml.cs @@ -0,0 +1,72 @@ +using ComputeSharp.SwapChain.Uwp.Views; +using Windows.ApplicationModel.Activation; +using Windows.ApplicationModel.Core; +using Windows.UI; +using Windows.UI.ViewManagement; +using Windows.UI.Xaml; + +namespace ComputeSharp.SwapChain.Uwp; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +sealed partial class App : Application +{ + /// + /// 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(). + /// + public App() + { + this.InitializeComponent(); + } + + /// + protected override void OnLaunched(LaunchActivatedEventArgs e) + { + if (Window.Current.Content is not MainView) + { + StyleTitleBar(); + ExpandViewIntoTitleBar(); + + Window.Current.Content = new MainView(); + } + + if (!e.PrelaunchActivated) + { + Window.Current.Activate(); + } + } + + /// + /// Styles the title bar buttons according to the theme in use + /// + private static void StyleTitleBar() + { + ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; + + // Transparent colors + titleBar.ForegroundColor = Colors.Transparent; + titleBar.BackgroundColor = Colors.Transparent; + titleBar.ButtonBackgroundColor = Colors.Transparent; + titleBar.InactiveBackgroundColor = Colors.Transparent; + titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; + + // Theme aware colors + titleBar.ButtonForegroundColor = titleBar.ButtonHoverForegroundColor = titleBar.ButtonPressedForegroundColor = Colors.White; + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0x20, 0xFF, 0xFF, 0xFF); + titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0x40, 0xFF, 0xFF, 0xFF); + titleBar.ButtonInactiveForegroundColor = Color.FromArgb(0xC0, 0xFF, 0xFF, 0xFF); + titleBar.InactiveForegroundColor = Color.FromArgb(0xA0, 0xA0, 0xA0, 0xA0); + } + + /// + /// Sets up the app UI to be expanded into the title bar + /// + private static void ExpandViewIntoTitleBar() + { + CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; + + coreTitleBar.ExtendViewIntoTitleBar = true; + } +} diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/LockScreenLogo.scale-200.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 00000000..735f57ad Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/LockScreenLogo.scale-200.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/Misc/noise_low.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/Misc/noise_low.png new file mode 100644 index 00000000..0784c124 Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/Misc/noise_low.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/SplashScreen.scale-200.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/SplashScreen.scale-200.png new file mode 100644 index 00000000..023e7f1f Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/SplashScreen.scale-200.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/Square150x150Logo.scale-200.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 00000000..af49fec1 Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square150x150Logo.scale-200.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.scale-200.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 00000000..ce342a2e Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.scale-200.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 00000000..f6c02ce9 Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/StoreLogo.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/StoreLogo.png new file mode 100644 index 00000000..7385b56c Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/StoreLogo.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/Assets/Wide310x150Logo.scale-200.png b/samples/ComputeSharp.SwapChain.Uwp/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 00000000..288995b3 Binary files /dev/null and b/samples/ComputeSharp.SwapChain.Uwp/Assets/Wide310x150Logo.scale-200.png differ diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj new file mode 100644 index 00000000..d903484e --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -0,0 +1,209 @@ + + + + + Debug + x86 + {FBD388A5-7855-4408-98FF-E689F509DB5A} + AppContainerExe + Properties + ComputeSharp.SwapChain.Uwp + ComputeSharp.SwapChain.Uwp + en-US + UAP + 10.0.19041.0 + 10.0.17763.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + true + false + + + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x86 + false + prompt + true + + + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x86 + false + prompt + true + true + + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM + false + prompt + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM + false + prompt + true + true + + + true + bin\ARM64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM64 + false + prompt + true + true + + + bin\ARM64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM64 + false + prompt + true + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + true + + + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + true + true + + + PackageReference + + + + App.xaml + + + + + + + + + MainView.xaml + + + + + Designer + + + + + PreserveNewest + + + Assets\Textures\RustyMetal.png + PreserveNewest + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + Designer + + + + + 6.2.13 + + + 7.1.1 + + + 7.1.1 + + + 7.1.1 + + + + + + + + + + + Designer + MSBuild:Compile + + + + 14.0 + + + + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Converters/RenderingPauseConverter.cs b/samples/ComputeSharp.SwapChain.Uwp/Converters/RenderingPauseConverter.cs new file mode 100644 index 00000000..2407f8ae --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Converters/RenderingPauseConverter.cs @@ -0,0 +1,20 @@ +using Windows.UI.Xaml.Controls; + +namespace ComputeSharp.SwapChain.Uwp.Converters +{ + /// + /// A class with some static converters for rendering state. + /// + public static class RenderingPauseConverter + { + /// + /// Gets a symbol for an input rendering state. + /// + /// Whether or not the rendering is currently paaused. + /// A symbol representing the next action for the rendering. + public static Symbol ConvertPausedToSymbol(bool value) + { + return value ? Symbol.Play : Symbol.Pause; + } + } +} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Converters/ResolutionScaleConverter.cs b/samples/ComputeSharp.SwapChain.Uwp/Converters/ResolutionScaleConverter.cs new file mode 100644 index 00000000..0831ff76 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Converters/ResolutionScaleConverter.cs @@ -0,0 +1,28 @@ +namespace ComputeSharp.SwapChain.Uwp.Converters +{ + /// + /// A class with some static converters for resolution scale settings. + /// + public static class ResolutionScaleConverter + { + /// + /// Converts a resolution scale to a formatted string. + /// + /// The input resolution scale (in percentage). + /// A formatted percentage string for . + public static string ConvertPercentageToFormattedString(int value) + { + return $"{value}%"; + } + + /// + /// Converts a percentage value to a scaled value in the [0, 1] range. + /// + /// The input percentage value to scale. + /// The input percentage scaled to the [0, 1] range. + public static double ConvertPercentageToScale(int value) + { + return value / 100.0; + } + } +} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Models/ComputeShader.cs b/samples/ComputeSharp.SwapChain.Uwp/Models/ComputeShader.cs new file mode 100644 index 00000000..3ac72447 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Models/ComputeShader.cs @@ -0,0 +1,44 @@ +using Microsoft.Toolkit.Mvvm.ComponentModel; +using ComputeSharp.Uwp; + +namespace ComputeSharp.SwapChain.Uwp.Models +{ + /// + /// A model for a compute shader. + /// + /// This can be converted to a record when bindings are fixed, see notes in the XAML code. + public sealed class ComputeShader : ObservableObject + { + /// + /// Creates a new instance. + /// + /// The name of the shader. + /// The instance to execute. + public ComputeShader(string name, IShaderRunner shaderRunner) + { + Name = name; + ShaderRunner = shaderRunner; + } + + /// + /// Gets the name of the shader. + /// + public string Name { get; } + + /// + /// Gets the instance to execute. + /// + public IShaderRunner ShaderRunner { get; } + + private bool isSelected; + + /// + /// Gets or sets whether the current shader is selected. + /// + public bool IsSelected + { + get => this.isSelected; + set => SetProperty(ref this.isSelected, value); + } + } +} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Package.appxmanifest b/samples/ComputeSharp.SwapChain.Uwp/Package.appxmanifest new file mode 100644 index 00000000..9d334cee --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Package.appxmanifest @@ -0,0 +1,50 @@ + + + + + + + + + + ComputeSharp.SwapChain.Uwp + Sergio + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs b/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..84399f6d --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ComputeSharp.SwapChain.Uwp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ComputeSharp.SwapChain.Uwp")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml b/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml new file mode 100644 index 00000000..819be7a4 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Properties/Default.rd.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Shaders/Runners/ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Uwp/Shaders/Runners/ContouredLayersRunner.cs new file mode 100644 index 00000000..d6bf8f11 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Shaders/Runners/ContouredLayersRunner.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using ComputeSharp.SwapChain.Shaders; +using ComputeSharp.Uwp; +using Windows.ApplicationModel; + +#nullable enable + +namespace ComputeSharp.SwapChain.Uwp.Shaders.Runners +{ + /// + /// A specialized for . + /// + public sealed class ContouredLayersRunner : IShaderRunner + { + /// + /// A texture for \Textures\RustyMetal.png. + /// + private ReadOnlyTexture2D? texture; + + /// + public void Execute(IReadWriteTexture2D 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(filename.AsSpan()); + } + + Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture)); + } + } +} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.Uwp/ViewModels/MainViewModel.cs new file mode 100644 index 00000000..35792641 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/ViewModels/MainViewModel.cs @@ -0,0 +1,131 @@ +using System.Collections.Generic; +using ComputeSharp.SwapChain.Shaders; +using ComputeSharp.SwapChain.Uwp.Models; +using ComputeSharp.SwapChain.Uwp.Shaders.Runners; +using ComputeSharp.Uwp; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; + +namespace ComputeSharp.SwapChain.Uwp.ViewModels +{ + /// + /// The viewmodel for for a view that allows users to select shaders and customize settings. + /// + public sealed class MainViewModel : ObservableObject + { + /// + /// Creates a new instance. + /// + public MainViewModel() + { + this.isDynamicResolutionEnabled = true; + this.selectedResolutionScale = 100; + this.selectedComputeShader = ComputeShaderOptions[0]; + this.selectedComputeShader.IsSelected = true; + + SetResolutionScaleCommand = new RelayCommand(SetResolutionScale); + ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused); + } + + /// + /// Gets the available resolution scaling options (as percentage values). + /// + public IList ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 }; + + private bool isDynamicResolutionEnabled; + + /// + /// Gets or sets whether the dynamic resolution is enabled. + /// + public bool IsDynamicResolutionEnabled + { + get => this.isDynamicResolutionEnabled; + set => SetProperty(ref this.isDynamicResolutionEnabled, value); + } + + private int selectedResolutionScale; + + /// + /// Gets the currently selected resolution scale setting (as percentage valaue). + /// + public int SelectedResolutionScale + { + get => this.selectedResolutionScale; + private set => SetProperty(ref this.selectedResolutionScale, value); + } + + /// + /// Gets the command that sets . + /// + public IRelayCommand SetResolutionScaleCommand { get; } + + /// + /// Sets . + /// + private void SetResolutionScale(int resolutionScale) + { + SelectedResolutionScale = resolutionScale; + } + + /// + /// Gets the collection of available compute shader. + /// + public IReadOnlyList ComputeShaderOptions { get; } = new ComputeShader[] + { + new("Colorful infinity", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Extruded truchet", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Fractal tiling", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Menger Journey", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Octagrams", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Protean clouds", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Two tiled truchet", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Pyramid pattern", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Triangle grid contouring", new ShaderRunner(static time => new((float)time.TotalSeconds))), + new("Contoured layers", new ContouredLayersRunner()) + }; + + private ComputeShader selectedComputeShader; + + /// + /// Gets or sets the currently selected compute shader. + /// + 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; + + /// + /// Gets or sets whether the rendering is currently paused. + /// + public bool IsRenderingPaused + { + get => this.isRenderingPaused; + set => SetProperty(ref this.isRenderingPaused, value); + } + + /// + /// Gets the command that toggles . + /// + public IRelayCommand ToggleRenderingPausedCommand { get; } + + /// + /// Toggles . + /// + private void ToggleRenderingPaused() + { + IsRenderingPaused = !IsRenderingPaused; + } + } +} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml new file mode 100644 index 00000000..76f2ed9c --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml.cs b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml.cs new file mode 100644 index 00000000..0caf4436 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml.cs @@ -0,0 +1,26 @@ +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Input; + +namespace ComputeSharp.SwapChain.Uwp.Views; + +public sealed partial class MainView : UserControl +{ + public MainView() + { + this.InitializeComponent(); + } + + // 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); + } +}