Merge pull request #475 from Sergio0694/dev/d2d1-samples

Add Win2D renderer to UWP sample app
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-01-21 15:47:27 -08:00
コミット ee5128b832
44ファイル変更
+647 -194

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

+7
ファイルの表示
@@ -130,6 +130,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B86A48A7-18B
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Uwp", "src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj", "{E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.SwapChain.Shaders.D2D1.Shared", "samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.shproj", "{F8BF7666-7CCF-4FE4-B055-2EBA4BCD4564}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -411,16 +413,19 @@ Global
{5DE90C85-ED26-4B5A-A0D7-2FF966A210AC} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{669A414F-3B46-4B55-B587-061AF63C3067} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
{B86A48A7-18BD-4946-B995-3CE26B092DDF} = {1A9C4108-F61A-4ABE-B5CF-F524521EAE2D}
{F8BF7666-7CCF-4FE4-B055-2EBA4BCD4564} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0071701e-b9c5-4098-be5f-ef556c4553c6}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{0800bd51-499d-44c2-9417-fd1f7fdfe9c4}*SharedItemsImports = 13
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{0c82ede1-5b8a-4df3-87da-700b29d5e265}*SharedItemsImports = 13
src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{158f984d-cd96-4062-bd02-2268946031a0}*SharedItemsImports = 13
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{209c95a3-fa53-431b-b688-3299ca6c29d2}*SharedItemsImports = 5
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5
src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13
@@ -446,8 +451,10 @@ Global
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{f8bf7666-7ccf-4fe4-b055-2eba4bcd4564}*SharedItemsImports = 13
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{fa18ba9f-76bf-4de0-8d24-02fc7657e6cb}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
EndGlobalSection
EndGlobal
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.Sample.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
@@ -11,11 +11,14 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Constants\Error.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Constants\Event.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\BoolConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Enums\RenderingMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\DebugAnalyticsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\ID2D1ShaderRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\D2D1ShaderRunner{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\D2D1ContouredLayersRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ShaderRunnerViewModel.cs" />
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
+1
ファイルの表示
@@ -5,6 +5,7 @@ namespace ComputeSharp.SwapChain.Core.Constants;
/// </summary>
public static class Event
{
public const string SelectedRenderingModeChanged = "[SETTINGS] SelectedRenderingMode";
public const string IsVerticalSyncEnabledChanged = "[SETTINGS] IsVerticalSyncEnabled";
public const string IsDynamicResolutionEnabledChanged = "[SETTINGS] IsDynamicResolutionEnabled";
public const string SelectedResolutionScaleChanged = "[SETTINGS] SelectedResolutionScale";
-20
ファイルの表示
@@ -1,20 +0,0 @@
using System.Runtime.CompilerServices;
namespace ComputeSharp.SwapChain.Core.Converters;
/// <summary>
/// A class with some static converters for <see cref="bool"/> values.
/// </summary>
public static class BoolConverter
{
/// <summary>
/// Negates an input <see cref="bool"/> value.
/// </summary>
/// <param name="value">The <see cref="bool"/> value to negate.</param>
/// <returns>The negated value of <paramref name="value"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Not(bool value)
{
return !value;
}
}
+17
ファイルの表示
@@ -0,0 +1,17 @@
namespace ComputeSharp.SwapChain.Core.Enums;
/// <summary>
/// Indicates the rendering mode being used.
/// </summary>
public enum RenderingMode
{
/// <summary>
/// Render using DirectX 12 APIs.
/// </summary>
DirectX12,
/// <summary>
/// Render using Win2D (ie. Direct2D behind the scenes).
/// </summary>
Win2D
}
+59
ファイルの表示
@@ -0,0 +1,59 @@
using System;
using CommunityToolkit.Diagnostics;
using ComputeSharp.D2D1;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.UI.Xaml;
#endif
namespace ComputeSharp.SwapChain.Core.Shaders;
/// <summary>
/// A simple <see cref="ID2D1ShaderRunner"/> implementation powered by a supplied shader type.
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner
where T : unmanaged, ID2D1PixelShader
{
#if WINDOWS_UWP
/// <summary>
/// The <see cref="Func{T1,T2,T3TResult}"/> instance used to create shaders to run.
/// </summary>
private readonly Func<TimeSpan, int, int, T> shaderFactory;
/// <summary>
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
/// </summary>
private readonly PixelShaderEffect<T> pixelShaderEffect;
#endif
/// <summary>
/// Creates a new <see cref="D2D1ShaderRunner{T}"/> instance.
/// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.</param>
public D2D1ShaderRunner(Func<TimeSpan, int, int, T> shaderFactory)
{
Guard.IsNotNull(shaderFactory);
#if WINDOWS_UWP
this.shaderFactory = shaderFactory;
this.pixelShaderEffect = new PixelShaderEffect<T>();
#endif
}
#if WINDOWS_UWP
/// <inheritdoc/>
public void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
// Set the constant buffer
this.pixelShaderEffect.ConstantBuffer = this.shaderFactory(args.Timing.TotalTime, widthInPixels, heightInPixels);
// Draw the shader
args.DrawingSession.DrawImage(this.pixelShaderEffect);
}
#endif
}
+20
ファイルの表示
@@ -0,0 +1,20 @@
#if WINDOWS_UWP
using Microsoft.Graphics.Canvas.UI.Xaml;
#endif
namespace ComputeSharp.SwapChain.Core.Shaders;
/// <summary>
/// An interface for a shader runner to be used with a Win2D renderer.
/// </summary>
public interface ID2D1ShaderRunner
{
#if WINDOWS_UWP
/// <summary>
/// Draws a new frame on a target <see cref="ICanvasAnimatedControl"/> instance.
/// </summary>
/// <param name="sender">The target <see cref="ICanvasAnimatedControl"/> instance.</param>
/// <param name="args">The <see cref="CanvasAnimatedDrawEventArgs"/> instance to use to draw the new frame.</param>
void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args);
#endif
}
@@ -0,0 +1,76 @@
#if WINDOWS_UWP
using System;
using System.IO;
using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Uwp;
#endif
using ComputeSharp.SwapChain.Shaders.D2D1;
#if WINDOWS_UWP
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Windows.ApplicationModel;
#endif
#nullable enable
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
/// <summary>
/// A specialized <see cref="ID2D1ShaderRunner"/> for <see cref="ContouredLayers"/>.
/// </summary>
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner
{
#if WINDOWS_UWP
/// <summary>
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
/// </summary>
private PixelShaderEffect<ContouredLayers>? pixelShaderEffect;
/// <inheritdoc/>
public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
if (this.pixelShaderEffect is null)
{
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
// As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to
// keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we
// first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then
// copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read
// from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture.
using ReadOnlyTexture2D<Rgba32, float4> readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
using ReadBackTexture2D<Rgba32> readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D<Rgba32>(readOnlyTexture.Width, readOnlyTexture.Height);
readOnlyTexture.CopyTo(readBackTexture);
// Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding.
// That is, the area between the end of the data in the last row and the stride is not included.
Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes);
int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32));
// Create the resource texture manager to use in the shader
D2D1ResourceTextureManager resourceTextureManager = new(
extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
channelDepth: D2D1ChannelDepth.Four,
filter: D2D1Filter.MinMagMipLinear,
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
data: new ReadOnlySpan<byte>(dataBuffer, bufferSize),
strides: stackalloc uint[] { (uint)strideInBytes });
// Create the new pixel shader effect
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { ResourceTextureManagers = { [0] = resourceTextureManager } };
}
int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
// Set the constant buffer
this.pixelShaderEffect.ConstantBuffer = new ContouredLayers((float)args.Timing.TotalTime.TotalSeconds, new int2(widthInPixels, heightInPixels));
// Draw the shader
args.DrawingSession.DrawImage(this.pixelShaderEffect);
}
#endif
}
+118 -84
ファイルの表示
@@ -3,7 +3,9 @@ using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ComputeSharp.SwapChain.Core.Constants;
using ComputeSharp.SwapChain.Core.Enums;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.Shaders;
using ComputeSharp.SwapChain.Core.Shaders.Runners;
using ComputeSharp.SwapChain.Shaders;
#if WINDOWS_UWP
@@ -34,6 +36,7 @@ public sealed partial class MainViewModel : ObservableObject
Guard.IsNotNull(analyticsService);
this.analyticsService = analyticsService;
this.selectedRenderingMode = RenderingMode.DirectX12;
this.isVerticalSyncEnabled = true;
this.isDynamicResolutionEnabled = true;
this.selectedResolutionScale = 100;
@@ -42,116 +45,104 @@ public sealed partial class MainViewModel : ObservableObject
}
/// <summary>
/// Gets the available resolution scaling options (as percentage values).
/// Gets or sets the selected rendering mode.
/// </summary>
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
private bool isVerticalSyncEnabled;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsResolutionScaleOptionEnabled))]
private RenderingMode selectedRenderingMode;
/// <summary>
/// Gets or sets whether the vertical sync is enabled.
/// </summary>
public bool IsVerticalSyncEnabled
{
get => this.isVerticalSyncEnabled;
set
{
if (SetProperty(ref this.isVerticalSyncEnabled, value))
{
this.analyticsService.Log(Event.IsVerticalSyncEnabledChanged, (nameof(value), value));
}
}
}
private bool isDynamicResolutionEnabled;
[ObservableProperty]
private bool isVerticalSyncEnabled;
/// <summary>
/// Gets or sets whether the dynamic resolution is enabled.
/// </summary>
public bool IsDynamicResolutionEnabled
{
get => this.isDynamicResolutionEnabled;
set
{
if (SetProperty(ref this.isDynamicResolutionEnabled, value))
{
this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value));
}
}
}
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsResolutionScaleOptionEnabled))]
private bool isDynamicResolutionEnabled;
/// <summary>
/// Gets the currently selected resolution scale setting (as percentage value).
/// </summary>
[ObservableProperty]
private int selectedResolutionScale;
/// <summary>
/// Gets the currently selected resolution scale setting (as percentage valaue).
/// Gets or sets the currently selected compute shader.
/// </summary>
public int SelectedResolutionScale
{
get => this.selectedResolutionScale;
private set
{
if (SetProperty(ref this.selectedResolutionScale, value))
{
this.analyticsService.Log(Event.SelectedResolutionScaleChanged, (nameof(value), value));
}
}
}
[ObservableProperty]
private ShaderRunnerViewModel selectedComputeShader;
/// <summary>
/// Gets or sets whether the rendering is currently paused.
/// </summary>
[ObservableProperty]
private bool isRenderingPaused;
/// <summary>
/// Gets the available resolution scaling options (as percentage values).
/// </summary>
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
/// <summary>
/// Gets the collection of available compute shader.
/// </summary>
public IReadOnlyList<ShaderRunnerViewModel> ComputeShaderOptions { get; } = new ShaderRunnerViewModel[]
{
new(typeof(ColorfulInfinity), new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
new(typeof(ExtrudedTruchetPattern),new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
new(typeof(FractalTiling),new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
new(typeof(MengerJourney),new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
new(typeof(Octagrams),new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
new(typeof(ProteanClouds),new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
new(typeof(TwoTiledTruchet),new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
new(typeof(PyramidPattern),new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
new(typeof(TriangleGridContouring),new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
new(typeof(ContouredLayers),new ContouredLayersRunner()),
new(typeof(TerracedHills),new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds))),
new(
typeof(ColorfulInfinity),
new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(FractalTiling),
new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(MengerJourney),
new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(Octagrams),
new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(ProteanClouds),
new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(TwoTiledTruchet),
new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(PyramidPattern),
new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
typeof(TriangleGridContouring),
new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(typeof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()),
new(
typeof(TerracedHills),
new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
};
private ShaderRunnerViewModel selectedComputeShader;
/// <summary>
/// Checks whether the resolution scale can currently be expliclty set.
/// </summary>
public bool IsResolutionScaleOptionEnabled => SelectedRenderingMode == RenderingMode.DirectX12 && !IsDynamicResolutionEnabled;
/// <summary>
/// Gets or sets the currently selected compute shader.
/// Sets <see cref="SelectedRenderingMode"/>.
/// </summary>
public ShaderRunnerViewModel SelectedComputeShader
[RelayCommand]
private void SetRenderingMode(RenderingMode renderingMode)
{
get => this.selectedComputeShader;
set
{
this.selectedComputeShader.IsSelected = false;
if (SetProperty(ref this.selectedComputeShader, value) &&
value is not null)
{
this.analyticsService.Log(Event.SelectedComputeShaderChanged, (nameof(value.ShaderType), value.ShaderType.Name));
value.IsSelected = true;
}
}
}
private bool isRenderingPaused;
/// <summary>
/// Gets or sets whether the rendering is currently paused.
/// </summary>
public bool IsRenderingPaused
{
get => this.isRenderingPaused;
set
{
if (SetProperty(ref this.isRenderingPaused, value))
{
this.analyticsService.Log(Event.IsRenderingPausedChanged, (nameof(value), value));
}
}
SelectedRenderingMode = renderingMode;
}
/// <summary>
@@ -171,4 +162,47 @@ public sealed partial class MainViewModel : ObservableObject
{
IsRenderingPaused = !IsRenderingPaused;
}
/// <inheritdoc/>
partial void OnSelectedRenderingModeChanged(RenderingMode value)
{
this.analyticsService.Log(Event.SelectedRenderingModeChanged, (nameof(value), value));
}
/// <inheritdoc/>
partial void OnIsVerticalSyncEnabledChanged(bool value)
{
this.analyticsService.Log(Event.IsVerticalSyncEnabledChanged, (nameof(value), value));
}
/// <inheritdoc/>
partial void OnIsDynamicResolutionEnabledChanged(bool value)
{
this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value));
}
/// <inheritdoc/>
partial void OnSelectedResolutionScaleChanged(int value)
{
this.analyticsService.Log(Event.SelectedResolutionScaleChanged, (nameof(value), value));
}
/// <inheritdoc/>
partial void OnSelectedComputeShaderChanging(ShaderRunnerViewModel value)
{
SelectedComputeShader.IsSelected = false;
value.IsSelected = true;
}
/// <inheritdoc/>
partial void OnSelectedComputeShaderChanged(ShaderRunnerViewModel value)
{
this.analyticsService.Log(Event.SelectedComputeShaderChanged, (nameof(value.ShaderType), value.ShaderType.Name));
}
/// <inheritdoc/>
partial void OnIsRenderingPausedChanged(bool value)
{
this.analyticsService.Log(Event.IsRenderingPausedChanged, (nameof(value), value));
}
}
+11 -8
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using ComputeSharp.SwapChain.Core.Shaders;
#if WINDOWS_UWP
using ComputeSharp.Uwp;
#else
@@ -11,17 +12,19 @@ namespace ComputeSharp.SwapChain.Core.ViewModels;
/// <summary>
/// A viewmodel for a compute shader.
/// </summary>
public sealed class ShaderRunnerViewModel : ObservableObject
public sealed partial class ShaderRunnerViewModel : ObservableObject
{
/// <summary>
/// Creates a new <see cref="ShaderRunnerViewModel"/> instance.
/// </summary>
/// <param name="shaderType">The <see cref="Type"/> instance for the actual shader to execute.</param>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
public ShaderRunnerViewModel(Type shaderType, IShaderRunner shaderRunner)
/// <param name="d2D1ShaderRunner">The <see cref="ID2D1ShaderRunner"/> instance to execute.</param>
public ShaderRunnerViewModel(Type shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner)
{
ShaderType = shaderType;
ShaderRunner = shaderRunner;
D2D1ShaderRunner = d2D1ShaderRunner;
}
/// <summary>
@@ -34,14 +37,14 @@ public sealed class ShaderRunnerViewModel : ObservableObject
/// </summary>
public IShaderRunner ShaderRunner { get; }
private bool isSelected;
/// <summary>
/// Gets the <see cref="ID2D1ShaderRunner"/> instance to execute.
/// </summary>
public ID2D1ShaderRunner D2D1ShaderRunner { get; }
/// <summary>
/// Gets or sets whether the current shader is selected.
/// </summary>
public bool IsSelected
{
get => this.isSelected;
set => SetProperty(ref this.isSelected, value);
}
[ObservableProperty]
private bool isSelected;
}
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A shader creating an abstract and colorful animation.
@@ -15,12 +17,12 @@ internal readonly partial struct ColorfulInfinity : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
/// <summary>
/// The total number of layers for the final animation.
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>f8bf7666-7ccf-4fe4-b055-2eba4bcd4564</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>ComputeSharp.SwapChain.Shaders.D2D1.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ColorfulInfinity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ContouredLayers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FractalTiling.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HelloWorld.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MengerJourney.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Octagrams.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProteanClouds.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PyramidPattern.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TerracedHills.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TriangleGridContouring.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TwoTiledTruchet.cs" />
</ItemGroup>
</Project>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>f8bf7666-7ccf-4fe4-b055-2eba4bcd4564</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<Import Project="ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// Constructing some concise contoured layers, then applying various edge and shading effects to produce some faux depth.
@@ -19,7 +21,7 @@ internal readonly partial struct ContouredLayers : ID2D1PixelShader
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
/// <summary>
/// The background texture to sample.
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A shader creating a fractal tiling animation.
@@ -15,12 +17,12 @@ internal readonly partial struct FractalTiling : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
/// <inheritdoc/>
public float4 Execute()
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A simple shader to get started with based on shadertoy new shader template.
@@ -13,12 +15,12 @@ internal readonly partial struct HelloWorld : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
/// <inheritdoc/>
public float4 Execute()
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A shader creating a flythrough in a Menger system.
@@ -14,12 +16,12 @@ internal readonly partial struct MengerJourney : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
private const int MaxSteps = 30;
private const float MinimumDistance = 0.0009f;
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A shader creating an octagram animation, inspired by arabesque.
@@ -14,12 +16,12 @@ internal readonly partial struct Octagrams : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
private static float2x2 Rotate(float a)
{
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// Fully procedural 3D animated volume with three evaluations per step (for shading).
@@ -15,14 +17,14 @@ internal readonly partial struct ProteanClouds : ID2D1PixelShader
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
private static readonly float3x3 m3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
private static readonly float3x3 M3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
private static float2x2 Rotate(in float a)
{
@@ -65,7 +67,7 @@ internal readonly partial struct ProteanClouds : ID2D1PixelShader
z *= 0.57f;
trk *= 1.4f;
p = Hlsl.Mul(p, m3);
p = Hlsl.Mul(p, M3);
}
d = Hlsl.Abs(d + (prm1 * 3.0f)) + (prm1 * 0.3f) - 2.5f + bsMo.Y;
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// An offset grid of square-based pyramids whose tips have been offset according to an underlying directional noise field.
@@ -15,12 +17,12 @@ internal readonly partial struct PyramidPattern : ID2D1PixelShader
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
// Standard 2D rotation formula.
private static float2x2 Rotate2x2(in float a)
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// An abstract representation of some terraced hills. In essence, just a very basic terrain layout with a small code footprint.
@@ -19,7 +21,7 @@ internal readonly partial struct TerracedHills : ID2D1PixelShader
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
// 2x2 matrix rotation. Angle vector, courtesy of Fabrice
private static float2x2 Rot2(float th)
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// Utilizing a 2D simplex grid to construct the isolines of a noise function.
@@ -14,12 +16,12 @@ internal readonly partial struct TriangleGridContouring : ID2D1PixelShader
/// <summary>
/// The current time Hlsl.Since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
// Standard 2D rotation formula.
private static float2x2 Rotate2x2(in float a)
@@ -1,4 +1,6 @@
namespace ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.D2D1;
namespace ComputeSharp.SwapChain.Shaders.D2D1;
/// <summary>
/// A shader creating an animated two-tiles Truchet arrangement.
@@ -14,12 +16,12 @@ internal readonly partial struct TwoTiledTruchet : ID2D1PixelShader
/// <summary>
/// The current time since the start of the application.
/// </summary>
public readonly float time;
private readonly float time;
/// <summary>
/// The dispatch size for the current output.
/// </summary>
public readonly int2 dispatchSize;
private readonly int2 dispatchSize;
/// <summary>
/// Calculates the Truchet distance field.
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
+6 -1
ファイルの表示
@@ -3,6 +3,11 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="Controls/D2D1AnimatedPixelShaderPanel.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
+9 -1
ファイルの表示
@@ -79,6 +79,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Assets\Generated\ServiceTokens.g.cs" />
<Compile Include="Controls\D2D1AnimatedPixelShaderPanel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AppCenterService.cs" />
<Compile Include="Services\ServiceCollectionExtensions.cs" />
@@ -192,17 +193,24 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.Uwp\ComputeSharp.Uwp.csproj" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Controls\D2D1AnimatedPixelShaderPanel.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="..\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
+142
ファイルの表示
@@ -0,0 +1,142 @@
using ComputeSharp.SwapChain.Core.Shaders;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#nullable enable
namespace ComputeSharp.SwapChain.Uwp.Views;
/// <summary>
/// A custom <see cref="Control"/> that can be used to render animated backgrounds via Win2D.
/// </summary>
[TemplatePart(Name = "PART_CanvasAnimatedControl", Type = typeof(CanvasAnimatedControl))]
public sealed class D2D1AnimatedPixelShaderPanel : Control
{
/// <summary>
/// The wrapped <see cref="CanvasAnimatedControl"/> instance used to render frames.
/// </summary>
private CanvasAnimatedControl? canvasAnimatedControl;
/// <summary>
/// The <see cref="ID2D1ShaderRunner"/> instance currently in use, if any.
/// </summary>
private volatile ID2D1ShaderRunner? shaderRunner;
/// <summary>
/// Creates a new <see cref="D2D1AnimatedPixelShaderPanel"/> instance.
/// </summary>
public D2D1AnimatedPixelShaderPanel()
{
DefaultStyleKey = typeof(D2D1AnimatedPixelShaderPanel);
Loaded += D2D1AnimatedPixelShaderPanel_Loaded;
Unloaded += D2D1AnimatedPixelShaderPanel_Unloaded;
}
/// <inheritdoc/>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.canvasAnimatedControl = (CanvasAnimatedControl)GetTemplateChild("PART_CanvasAnimatedControl")!;
this.canvasAnimatedControl.Draw += CanvasAnimatedControl_Draw;
}
// Ensure the panel is not paused when the control is loaded
private void D2D1AnimatedPixelShaderPanel_Loaded(object sender, RoutedEventArgs e)
{
if (this.canvasAnimatedControl is { } canvasAnimatedControl &&
ShaderRunner is not null &&
!IsPaused)
{
canvasAnimatedControl.Paused = false;
}
}
// Always pause rendering when the control is unloaded
private void D2D1AnimatedPixelShaderPanel_Unloaded(object sender, RoutedEventArgs e)
{
if (this.canvasAnimatedControl is { } canvasAnimatedControl)
{
canvasAnimatedControl.Paused = true;
}
}
/// <summary>
/// Draws a new frame on the wrapped <see cref="CanvasAnimatedControl"/> instance.
/// </summary>
/// <inheritdoc cref="ID2D1ShaderRunner.Execute"/>
private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
this.shaderRunner?.Execute(sender, args);
}
/// <summary>
/// Gets or sets the <see cref="ID2D1ShaderRunner"/> instance to use to render content.
/// </summary>
public ID2D1ShaderRunner? ShaderRunner
{
get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty);
set => SetValue(ShaderRunnerProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="ShaderRunner"/>.
/// </summary>
public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register(
nameof(ShaderRunner),
typeof(ID2D1ShaderRunner),
typeof(D2D1AnimatedPixelShaderPanel),
new PropertyMetadata(null, OnShaderRunnerPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d;
ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue;
// Save the new shader runner for later (as the dependency property cannot be accessed by the render thread)
@this.shaderRunner = shaderRunner;
// Pause or start the render thread if a runner is available
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
{
bool shouldRender = @this.IsLoaded && !@this.IsPaused && shaderRunner is not null;
canvasAnimatedControl.Paused = !shouldRender;
}
}
/// <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(D2D1AnimatedPixelShaderPanel),
new PropertyMetadata(false, OnIsPausedPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnIsPausedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d;
bool isPaused = (bool)e.NewValue;
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
{
bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is ID2D1ShaderRunner;
canvasAnimatedControl.Paused = !shouldRender;
}
}
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="using:ComputeSharp.SwapChain.Uwp.Views"
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="local:D2D1AnimatedPixelShaderPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:D2D1AnimatedPixelShaderPanel">
<win2d:CanvasAnimatedControl x:Name="PART_CanvasAnimatedControl"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
+46 -16
ファイルの表示
@@ -6,10 +6,12 @@
xmlns:computesharp="using:ComputeSharp.Uwp"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:converters="using:ComputeSharp.SwapChain.Core.Converters"
xmlns:enums="using:ComputeSharp.SwapChain.Core.Enums"
xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels"
xmlns:views="using:ComputeSharp.SwapChain.Uwp.Views"
SizeChanged="UserControl_SizeChanged">
<Grid x:Name="Root">
@@ -144,16 +146,27 @@
</Border>
</Grid.Resources>
<!-- Shader -->
<computesharp:AnimatedComputeShaderPanel
x:Name="ShaderPanel"
Grid.Row="1"
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
IsVerticalSyncEnabled="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=OneWay}"
RenderingFailed="MainShaderPanel_RenderingFailed"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
<!-- Shader switches (for DirectX 12 or Win2D) -->
<controls:SwitchPresenter Grid.Row="1" Value="{x:Bind ViewModel.SelectedRenderingMode, Mode=OneWay}">
<controls:Case Value="{x:Bind enums:RenderingMode.DirectX12}" IsDefault="True">
<!-- DirectX 12 shader -->
<computesharp:AnimatedComputeShaderPanel
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
IsVerticalSyncEnabled="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=OneWay}"
RenderingFailed="MainShaderPanel_RenderingFailed"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"/>
</controls:Case>
<controls:Case Value="{x:Bind enums:RenderingMode.Win2D}">
<!-- Win2D shader -->
<views:D2D1AnimatedPixelShaderPanel
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.D2D1ShaderRunner, Mode=OneWay}"/>
</controls:Case>
</controls:SwitchPresenter>
<!-- Settings panel -->
<StackPanel
@@ -189,32 +202,49 @@
<SymbolIcon Symbol="Setting" />
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=TwoWay}" Text="Vertical sync" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}" Text="Dynamic resolution" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
CommandParameter="{x:Bind enums:RenderingMode.DirectX12}"
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="DirectX 12" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
CommandParameter="{x:Bind enums:RenderingMode.Win2D}"
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.Win2D), Mode=OneWay}"
Text="Win2D (Direct2D)" />
<MenuFlyoutSeparator />
<ToggleMenuFlyoutItem
IsChecked="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="Vertical sync" />
<ToggleMenuFlyoutItem
IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="Dynamic resolution" />
<MenuFlyoutSeparator />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[0]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[0]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[0])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[1]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[1]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[1])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[2]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[2]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[2])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[3]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[3]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[3])}" />
</MenuFlyout>
</Button.Flyout>
+4 -1
ファイルの表示
@@ -55,10 +55,13 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
</ItemGroup>
<Import Project="..\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
</Project>
+4 -4
ファイルの表示
@@ -196,25 +196,25 @@
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[0]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[0]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[0])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[1]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[1]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[1])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[2]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[2]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[2])}" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[3]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[3]), Mode=OneWay}"
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[3])}" />
</MenuFlyout>
</Button.Flyout>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.NetStandard.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.SourceGeneration.Hlsl.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.SourceGeneration.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-2
ファイルの表示
@@ -14,8 +14,6 @@
<!-- Same setup as ComputeSharp.Core.SourceGenerators, just with also APIs from ComputeSharp -->
<ItemGroup>
<!-- ComputeSharp.Core.SourceGenerator APIs -->
<!-- ComputeSharp.Core APIs -->
<Compile Include="..\ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" Link="ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" />
<Compile Include="..\ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" Link="ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" />
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.UI.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="TerraFX.Interop.Windows.D2D1.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="TerraFX.Interop.Windows.Dynamic.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
-1
ファイルの表示
@@ -7,7 +7,6 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="TerraFX.Interop.Windows.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
+2
ファイルの表示
@@ -100,4 +100,6 @@
<None Include="..\..\samples\ComputeSharp.SwapChain\Textures\RustyMetal.png" Link="Assets\Textures\RustyMetal.png" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<Import Project="..\..\samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
</Project>
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Helpers;
using ComputeSharp.D2D1.Tests.Shaders;
using ComputeSharp.SwapChain.Shaders.D2D1;
using ComputeSharp.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Win32;
+13 -12
ファイルの表示
@@ -4,6 +4,7 @@ using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Helpers;
using ComputeSharp.SwapChain.Shaders.D2D1;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
@@ -17,25 +18,25 @@ public class ShadersTests
[TestMethod]
public void HelloWorld()
{
RunTest<Shaders.HelloWorld>();
RunTest<HelloWorld>();
}
[TestMethod]
public void ColorfulInfinity()
{
RunTest<Shaders.ColorfulInfinity>();
RunTest<ColorfulInfinity>();
}
[TestMethod]
public void FractalTiling()
{
RunTest<Shaders.FractalTiling>();
RunTest<FractalTiling>();
}
[TestMethod]
public void MengerJourney()
{
RunTest<Shaders.MengerJourney>(0.000011f);
RunTest<MengerJourney>(0.000011f);
}
// This test and the other 3 below are skipped because they do produce valid result,
@@ -46,33 +47,33 @@ public class ShadersTests
[Ignore]
public void TwoTiledTruchet()
{
RunTest<Shaders.TwoTiledTruchet>();
RunTest<TwoTiledTruchet>();
}
[TestMethod]
public void Octagrams()
{
RunTest<Shaders.Octagrams>();
RunTest<Octagrams>();
}
[TestMethod]
public void ProteanClouds()
{
RunTest<Shaders.ProteanClouds>();
RunTest<ProteanClouds>();
}
[TestMethod]
[Ignore]
public void PyramidPattern()
{
RunTest<Shaders.PyramidPattern>();
RunTest<PyramidPattern>();
}
[TestMethod]
[Ignore]
public void TriangleGridContouring()
{
RunTest<Shaders.TriangleGridContouring>();
RunTest<TriangleGridContouring>();
}
[TestMethod]
@@ -101,15 +102,15 @@ public class ShadersTests
strides: stackalloc uint[] { (uint)(texture.Width * sizeof(Rgba32)) });
}
Shaders.ContouredLayers shader = new(0f, new int2(1280, 720));
ContouredLayers shader = new(0f, new int2(1280, 720));
D2D1TestRunner.RunAndCompareShader(in shader, 1280, 720, $"{nameof(Shaders.ContouredLayers)}.png", nameof(Shaders.ContouredLayers), resourceTextures: (0, resourceTextureManager));
D2D1TestRunner.RunAndCompareShader(in shader, 1280, 720, $"{nameof(ContouredLayers)}.png", nameof(ContouredLayers), resourceTextures: (0, resourceTextureManager));
}
[TestMethod]
public void TerracedHills()
{
RunTest<Shaders.TerracedHills>(0.000026f);
RunTest<TerracedHills>(0.000026f);
}
private static void RunTest<T>(float threshold = 0.00001f)