From 92222aafa94f375b93745b9b7846bb7cd1940aa9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Feb 2023 22:17:45 +0100 Subject: [PATCH 01/15] Add empty ComputeSharp.D2D1.WinUI project fix --- ComputeSharp.sln | 10 +++++++ .../ComputeSharp.D2D1.WinUI.csproj | 30 +++++++++++++++++++ .../Directory.Build.props | 12 ++++++++ .../ComputeSharp.WinUI.csproj | 1 - 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj create mode 100644 src/ComputeSharp.D2D1.WinUI/Directory.Build.props diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 62a59ed2..07eb1e13 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -136,6 +136,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Uwp", "sr 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 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D2D1.WinUI", "src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj", "{BD9E6556-357E-4C20-BFCD-FB131F9372FA}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{568E7009-5C13-4153-9C94-0AC7A3E6883C}" ProjectSection(SolutionItems) = preProject samples\Directory.Build.props = samples\Directory.Build.props @@ -397,6 +399,14 @@ Global {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|ARM64.Build.0 = Release|ARM64 {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|x64.ActiveCfg = Release|x64 {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|x64.Build.0 = Release|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|ARM64.Build.0 = Debug|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|x64.ActiveCfg = Debug|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|x64.Build.0 = Debug|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|ARM64.ActiveCfg = Release|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|ARM64.Build.0 = Release|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|x64.ActiveCfg = Release|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj new file mode 100644 index 00000000..c1d01f79 --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj @@ -0,0 +1,30 @@ + + + + net6.0-windows10.0.22621.0 + 10.0.17763.0 + ComputeSharp.D2D1.WinUI + x64;ARM64 + win10-x64;win10-arm64 + + + + ComputeSharp.D2D1.WinUI + ComputeSharp.D2D1.WinUI + A WinUI 3 library with APIs to leverage D2D1 functionality with D2D1 pixel shaders powered by ComputeSharp.D2D1 + $(PackageTags) winui winui3 wasdk + + + + + + + + + + + + + + + diff --git a/src/ComputeSharp.D2D1.WinUI/Directory.Build.props b/src/ComputeSharp.D2D1.WinUI/Directory.Build.props new file mode 100644 index 00000000..4ec7dd9c --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/Directory.Build.props @@ -0,0 +1,12 @@ + + + + + + + $(NoWarn);CS0419 + + + $(NoWarn);IDE0065 + + \ No newline at end of file diff --git a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj index a37c0b0e..5e539907 100644 --- a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj +++ b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj @@ -5,7 +5,6 @@ ComputeSharp.WinUI x64;ARM64 win10-x64;win10-arm64 - true From 1bcf612cea24d8de5758d265b7bbf300b478f2f0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 24 Feb 2023 13:07:41 +0100 Subject: [PATCH 02/15] Move ComputeSharp.D2D1.Uwp code into shared project --- ComputeSharp.sln | 6 ++- .../ICanvasDevice.cs | 0 .../ICanvasEffect.cs | 0 .../ICanvasFactoryNative.cs | 0 .../ICanvasImageInterop.cs | 0 .../ICanvasResourceCreator.cs | 0 .../ICanvasResourceCreatorWithDpi.cs | 0 .../ICanvasResourceWrapperNative.cs | 0 .../ID2D1DeviceContextLease.cs | 0 .../ID2D1DeviceContextPool.cs | 0 .../WIN2D_GET_D2D_IMAGE_FLAGS.cs | 0 .../WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs | 0 .../ABI.Microsoft.Graphics.Canvas/Win2D.cs | 0 .../Buffers/GraphicsEffectSourceBuffer.cs | 0 .../Buffers/ResourceTextureManagerBuffer.cs | 0 .../Buffers/SourceReference.cs | 0 .../CanvasEffect.Interop.cs | 0 .../CanvasEffect.cs | 0 .../Collections/FixedCountList{T}.cs | 0 .../Collections/IFixedCountList{T}.cs | 0 .../ComputeSharp.D2D1.UI.projitems | 51 +++++++++++++++++++ .../ComputeSharp.D2D1.UI.shproj | 13 +++++ .../Extensions/ICanvasDeviceExtensions.cs | 0 .../ID2D1DeviceContextExtensions.cs | 0 .../Extensions/ID2D1EffectExtensions.cs | 0 .../Extensions/IUnknownExtensions.cs | 0 .../Helpers/ResourceManager.cs | 0 ...eArrayResourceTextureDescriptionsLoader.cs | 0 ...itmaskResourceTextureDescriptionsLoader.cs | 0 .../PixelShaderEffect{T}.ICanvasEffect.cs | 0 .../PixelShaderEffect{T}.ICanvasImage.cs | 0 ...ixelShaderEffect{T}.ICanvasImageInterop.cs | 0 ...derEffect{T}.Properties.Interop.Sources.cs | 0 ...PixelShaderEffect{T}.Properties.Interop.cs | 0 ...erties.ResourceTextureManagerCollection.cs | 0 ...erEffect{T}.Properties.SourceCollection.cs | 0 .../PixelShaderEffect{T}.Properties.cs | 0 .../PixelShaderEffect{T}.ReferenceTracking.cs | 0 .../PixelShaderEffect{T}.cs | 0 .../ComputeSharp.D2D1.Uwp.csproj | 7 +-- 40 files changed, 71 insertions(+), 6 deletions(-) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/ABI.Microsoft.Graphics.Canvas/Win2D.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Buffers/GraphicsEffectSourceBuffer.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Buffers/ResourceTextureManagerBuffer.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Buffers/SourceReference.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/CanvasEffect.Interop.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/CanvasEffect.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Collections/FixedCountList{T}.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Collections/IFixedCountList{T}.cs (100%) create mode 100644 src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems create mode 100644 src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Extensions/ICanvasDeviceExtensions.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Extensions/ID2D1DeviceContextExtensions.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Extensions/ID2D1EffectExtensions.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Extensions/IUnknownExtensions.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Helpers/ResourceManager.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.ICanvasEffect.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.ICanvasImage.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.ICanvasImageInterop.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.Properties.Interop.Sources.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.Properties.Interop.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.Properties.SourceCollection.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.Properties.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.ReferenceTracking.cs (100%) rename src/{ComputeSharp.D2D1.Uwp => ComputeSharp.D2D1.UI}/PixelShaderEffect{T}.cs (100%) diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 07eb1e13..265428f4 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -136,7 +136,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Uwp", "sr 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 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.D2D1.WinUI", "src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj", "{BD9E6556-357E-4C20-BFCD-FB131F9372FA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.WinUI", "src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj", "{BD9E6556-357E-4C20-BFCD-FB131F9372FA}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.D2D1.UI", "src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.shproj", "{902D7B44-2C6C-4FCD-840B-EBCAE811EE63}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{568E7009-5C13-4153-9C94-0AC7A3E6883C}" ProjectSection(SolutionItems) = preProject @@ -462,6 +464,7 @@ Global samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{751bb05b-563d-4b3a-94c6-15e2d79d35ea}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{764bc0f5-0c5e-49ad-abaa-e3874c0f3286}*SharedItemsImports = 5 src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{76c66257-fdaa-47ab-85e7-ef757eab10c0}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{902d7b44-2c6c-4fcd-840b-ebcae811ee63}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{9ac496a3-bbf0-4c8f-a50d-a20bf01c5e05}*SharedItemsImports = 13 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 @@ -473,6 +476,7 @@ Global src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{e60a3b1e-fc5d-41ac-acf0-c2d75b6590d2}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/Win2D.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Win2D.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/Win2D.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Win2D.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/GraphicsEffectSourceBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Buffers/GraphicsEffectSourceBuffer.cs rename to src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/ResourceTextureManagerBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Buffers/ResourceTextureManagerBuffer.cs rename to src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/SourceReference.cs b/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Buffers/SourceReference.cs rename to src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs diff --git a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs rename to src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs diff --git a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/CanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/CanvasEffect.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs rename to src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Collections/IFixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Collections/IFixedCountList{T}.cs rename to src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems new file mode 100644 index 00000000..cc372c6a --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems @@ -0,0 +1,51 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 902d7b44-2c6c-4fcd-840b-ebcae811ee63 + + + ComputeSharp.D2D1.UI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj new file mode 100644 index 00000000..7cb7c873 --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj @@ -0,0 +1,13 @@ + + + + 902d7b44-2c6c-4fcd-840b-ebcae811ee63 + 14.0 + + + + + + + + diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1DeviceContextExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1DeviceContextExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs rename to src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs rename to src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs rename to src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImage.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.SourceCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.SourceCollection.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj index 8b654835..64066056 100644 --- a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj +++ b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj @@ -25,11 +25,6 @@ $(PackageTags) uwp winui - - - - - @@ -41,4 +36,6 @@ + + \ No newline at end of file From a7a3073c8fbe3bc760fd182b0adb7120cd73bb02 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Feb 2023 23:04:42 +0100 Subject: [PATCH 03/15] Add shared code to ComputeSharp.D2D1.WinUI --- ComputeSharp.sln | 1 + src/ComputeSharp.Core/ComputeSharp.Core.csproj | 1 + src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs | 2 ++ .../PixelShaderEffect{T}.ICanvasImage.cs | 3 +-- ...t{T}.Properties.ResourceTextureManagerCollection.cs | 10 +++++----- ...PixelShaderEffect{T}.Properties.SourceCollection.cs | 10 +++++----- .../ComputeSharp.D2D1.WinUI.csproj | 3 ++- src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj | 1 + 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 265428f4..7b49c5d0 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -469,6 +469,7 @@ Global src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 src\ComputeSharp.UI\ComputeSharp.UI.projitems*{afaafdc9-be42-45d4-8c79-0ee8c8edbf52}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{bd9e6556-357e-4c20-bfcd-fb131f9372fa}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{c12d7ace-98ed-4813-8118-6667c34f484f}*SharedItemsImports = 5 diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index 52fe9c3d..6a4268e3 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -14,6 +14,7 @@ + diff --git a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs index bd37235c..ed3b24a0 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs @@ -8,6 +8,8 @@ using Windows.Graphics.Effects; namespace ComputeSharp.D2D1.Uwp.Helpers; +using WinRT = TerraFX.Interop.WinRT.WinRT; + /// /// A helper type to replicate Win2D's ResourceManager type. /// diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs index d0f24e97..2204fe5a 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs @@ -3,7 +3,6 @@ using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; using ComputeSharp.Interop; -using Microsoft.Graphics.Canvas; using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator; @@ -25,7 +24,7 @@ unsafe partial class PixelShaderEffect return GetBounds(resourceCreator, &transform); } - /// + /// private Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2* transform) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index e458491f..faac63e3 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -117,7 +117,7 @@ partial class PixelShaderEffect } /// - int IList.Add(object value) + int IList.Add(object? value) { return default(NotSupportedException).Throw(); } @@ -141,7 +141,7 @@ partial class PixelShaderEffect } /// - bool IList.Contains(object value) + bool IList.Contains(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value) != -1; } @@ -177,7 +177,7 @@ partial class PixelShaderEffect } /// - int IList.IndexOf(object value) + int IList.IndexOf(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value); } @@ -189,7 +189,7 @@ partial class PixelShaderEffect } /// - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } @@ -201,7 +201,7 @@ partial class PixelShaderEffect } /// - void IList.Remove(object value) + void IList.Remove(object? value) { default(NotSupportedException).Throw(); } diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs index 167d43cf..8b146b97 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs @@ -103,7 +103,7 @@ partial class PixelShaderEffect } /// - int IList.Add(object value) + int IList.Add(object? value) { return default(NotSupportedException).Throw(); } @@ -127,7 +127,7 @@ partial class PixelShaderEffect } /// - bool IList.Contains(object value) + bool IList.Contains(object? value) { return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value) != -1; } @@ -163,7 +163,7 @@ partial class PixelShaderEffect } /// - int IList.IndexOf(object value) + int IList.IndexOf(object? value) { return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value); } @@ -175,7 +175,7 @@ partial class PixelShaderEffect } /// - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } @@ -187,7 +187,7 @@ partial class PixelShaderEffect } /// - void IList.Remove(object value) + void IList.Remove(object? value) { default(NotSupportedException).Throw(); } diff --git a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj index c1d01f79..1baee968 100644 --- a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj +++ b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj @@ -20,11 +20,12 @@ - + + diff --git a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj index c1ce7b65..75c00014 100644 --- a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj +++ b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj @@ -8,6 +8,7 @@ + From fe665a232ff01dfada68cd4cdd244e87f8176b89 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Feb 2023 23:12:41 +0100 Subject: [PATCH 04/15] Adjust namespaces in ComputeSharp.D2D1.WinUI --- .../Buffers/GraphicsEffectSourceBuffer.cs | 4 ++++ .../Buffers/ResourceTextureManagerBuffer.cs | 4 ++++ src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs | 9 +++++++++ src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs | 4 ++++ src/ComputeSharp.D2D1.UI/CanvasEffect.cs | 4 ++++ .../Collections/FixedCountList{T}.cs | 4 ++++ .../Collections/IFixedCountList{T}.cs | 4 ++++ .../Extensions/ICanvasDeviceExtensions.cs | 4 ++++ .../Extensions/ID2D1DeviceContextExtensions.cs | 4 ++++ .../Extensions/ID2D1EffectExtensions.cs | 4 ++++ .../Extensions/IUnknownExtensions.cs | 4 ++++ src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs | 4 ++++ .../PixelShaderEffect{T}.ICanvasEffect.cs | 4 ++++ .../PixelShaderEffect{T}.ICanvasImage.cs | 4 ++++ .../PixelShaderEffect{T}.ICanvasImageInterop.cs | 8 ++++++++ .../PixelShaderEffect{T}.Properties.Interop.Sources.cs | 9 +++++++++ .../PixelShaderEffect{T}.Properties.Interop.cs | 8 ++++++++ ...ect{T}.Properties.ResourceTextureManagerCollection.cs | 9 +++++++++ .../PixelShaderEffect{T}.Properties.SourceCollection.cs | 9 +++++++++ .../PixelShaderEffect{T}.Properties.cs | 4 ++++ .../PixelShaderEffect{T}.ReferenceTracking.cs | 4 ++++ src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs | 4 ++++ 22 files changed, 116 insertions(+) diff --git a/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs index 56a0bfba..f689c6df 100644 --- a/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A fixed buffer type containing 16 fields. diff --git a/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs index af57a6db..5efb789a 100644 --- a/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A fixed buffer type containing 16 fields. diff --git a/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs b/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs index b128c63a..d9f917b2 100644 --- a/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs @@ -1,13 +1,22 @@ using System; using System.Runtime.CompilerServices; using ABI.Microsoft.Graphics.Canvas; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A wrapper type for an input and its underlying native D2D images. diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs index 875e71a3..155c4081 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs @@ -9,7 +9,11 @@ using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class CanvasEffect diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs index 96bf107c..050a4421 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs @@ -4,7 +4,11 @@ using System.Diagnostics.CodeAnalysis; using ABI.Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// /// A base type to implement packaged and easy to use -based effects that can be used with Win2D. diff --git a/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs index 74dd8fe9..8f93a9b0 100644 --- a/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs @@ -1,7 +1,11 @@ using System; using System.Collections.Generic; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Collections; +#else +namespace ComputeSharp.D2D1.WinUI.Collections; +#endif /// /// Shared helpers for all types implementing . diff --git a/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs index 2cc4b735..c3672855 100644 --- a/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs @@ -1,7 +1,11 @@ using System.Collections.Generic; using System.Collections.Immutable; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Collections; +#else +namespace ComputeSharp.D2D1.WinUI.Collections; +#endif /// /// An interface for a list with a fixed collection. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs index bea0e059..ed84a11b 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs @@ -4,7 +4,11 @@ using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs index c2304839..7a3b47db 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs @@ -2,7 +2,11 @@ using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs index 7e3cfc78..e00f5304 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs @@ -11,7 +11,11 @@ using TerraFX.Interop.Windows; #pragma warning disable CS0618 +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs index f3847d30..37a6ca88 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs @@ -3,7 +3,11 @@ using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.Windows; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// Helper methods for working with the type. diff --git a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs index ed3b24a0..0795aac8 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs @@ -6,9 +6,13 @@ using TerraFX.Interop.Windows; using TerraFX.Interop.WinRT; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Helpers; +#else +namespace ComputeSharp.D2D1.WinUI.Helpers; using WinRT = TerraFX.Interop.WinRT.WinRT; +#endif /// /// A helper type to replicate Win2D's ResourceManager type. diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs index 8cf7ff40..6e5e63d0 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs @@ -9,7 +9,11 @@ using Windows.Foundation; using ICanvasEffect = Microsoft.Graphics.Canvas.Effects.ICanvasEffect; using ICanvasResourceCreatorWithDpi = Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs index 2204fe5a..26b33d5b 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs @@ -7,7 +7,11 @@ using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs index fb7eb262..d68da8ab 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -5,7 +5,11 @@ using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Interop.Effects; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +#endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -14,7 +18,11 @@ using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS; using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 30db4eda..0f622d59 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -3,8 +3,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Extensions; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Extensions; +#endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -17,7 +22,11 @@ using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_PROP; using static TerraFX.Interop.DirectX.D2D1_PROPERTY_TYPE; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs index 88862939..30546024 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs @@ -1,10 +1,18 @@ using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +#endif using ComputeSharp.Interop; using Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index faac63e3..94dbdfad 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -6,12 +6,21 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Loaders; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Collections; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Collections; +#endif #pragma warning disable CS0618, CS8767 +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs index 8b146b97..8fe5889b 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs @@ -4,11 +4,20 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Collections; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Collections; +#endif using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs index 71882ab1..d171e39f 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using ComputeSharp.D2D1.Interop; using Microsoft.Graphics.Canvas; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs index 08548bb1..dd5695ee 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs @@ -2,7 +2,11 @@ using System; using ComputeSharp.Interop; using System.Runtime.CompilerServices; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs index 7c3c389c..99d2a0c9 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs @@ -6,7 +6,11 @@ using Microsoft.Graphics.Canvas.Effects; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// /// A custom implementation powered by a supplied shader type. From 805e1555fe815fa820194ec9d932b7d17cefedba Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Feb 2023 23:23:52 +0100 Subject: [PATCH 05/15] Implement ICanvasImageInterop with CsWinRT --- .../ICanvasImageInterop.cs | 102 +++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs index a4bb8cb9..b63aed7f 100644 --- a/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using TerraFX.Interop; +#if !WINDOWS_UWP +using WinRT; +using WinRT.Interop; +#endif #pragma warning disable CS0649, IDE1006 @@ -79,20 +83,29 @@ internal unsafe struct ICanvasImageInterop } /// - /// The implementation of . + /// The managed implementation of . /// - [ComImport] [Guid("E042D1F7-F9AD-4479-A713-67627EA31863")] +#if WINDOWS_UWP + [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +#else + [WindowsRuntimeType] + [WindowsRuntimeHelperType(typeof(Interface))] +#endif public interface Interface { /// +#if WINDOWS_UWP [PreserveSig] +#endif [return: NativeTypeName("HRESULT")] int GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type); /// +#if WINDOWS_UWP [PreserveSig] +#endif [return: NativeTypeName("HRESULT")] int GetD2DImage( ICanvasDevice* device, @@ -101,5 +114,90 @@ internal unsafe struct ICanvasImageInterop float targetDpi, float* realizeDpi, ID2D1Image** ppImage); + +#if !WINDOWS_UWP + /// + /// The vtable type for . + /// + [Guid("E042D1F7-F9AD-4479-A713-67627EA31863")] + public struct Vftbl + { + /// + /// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention). + /// + public static readonly IntPtr AbiToProjectionVftablePtr = InitVtbl(); + + /// + /// Builds the custom method table pointer for . + /// + /// The method table pointer for . + private static IntPtr InitVtbl() + { + Vftbl* lpVtbl = (Vftbl*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(Vftbl)); + + lpVtbl->IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl; + lpVtbl->GetDevice = &GetDeviceFromAbi; + lpVtbl->GetD2DImage = &GetD2DImageFromAbi; + + return (IntPtr)lpVtbl; + } + + /// + /// The IUnknown vtable. + /// + internal IUnknownVftbl IUnknownVftbl; + + /// + /// Function pointer for . + /// + internal delegate* unmanaged[Stdcall] GetDevice; + + /// + /// Function pointer for . + /// + internal delegate* unmanaged[Stdcall] GetD2DImage; + + /// + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [return: NativeTypeName("HRESULT")] + private static int GetDeviceFromAbi(IntPtr thisPtr, ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type) + { + try + { + return ComWrappersSupport.FindObject(thisPtr).GetDevice(device, type); + } + catch (Exception e) + { + ExceptionHelpers.SetErrorInfo(e); + + return Marshal.GetHRForException(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [return: NativeTypeName("HRESULT")] + private static int GetD2DImageFromAbi( + IntPtr thisPtr, + ICanvasDevice* device, + ID2D1DeviceContext* deviceContext, + WIN2D_GET_D2D_IMAGE_FLAGS flags, + float targetDpi, + float* realizeDpi, + ID2D1Image** ppImage) + { + try + { + return ComWrappersSupport.FindObject(thisPtr).GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage); + } + catch (Exception e) + { + ExceptionHelpers.SetErrorInfo(e); + + return Marshal.GetHRForException(e); + } + } + } +#endif } } \ No newline at end of file From a5d15b0a262a80a27b8d538c26e2d4eda775a4c7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 18 Feb 2023 23:32:14 +0100 Subject: [PATCH 06/15] Add ComputeSharp.D2D1.WinUI to pipeline script --- .github/workflows/dotnet.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c7347cf0..eaa46939 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -58,6 +58,12 @@ jobs: run: > msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:restore /p:Configuration=Release; msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:pack /p:Configuration=Release + - name: Build ComputeSharp.D2D1.WinUI project + run: > + msbuild src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj -t:restore /p:Configuration=Release; + msbuild src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj -t:pack /p:Configuration=Release + + # Upload the packages to the pipeline artifacts - name: Upload package artifacts uses: actions/upload-artifact@v3 with: @@ -96,13 +102,13 @@ jobs: name: Run ComputeSharp.Tests.SourceGenerators run: dotnet test tests\ComputeSharp.Tests.SourceGenerators\ComputeSharp.Tests.SourceGenerators.csproj -v n -l "console;verbosity=detailed" - # DirectX 12 device lost unit tests. - # These tests are run one class at a time to ensure there's no accidental conflicts between any of them. This is because - # the code paths being tested in this project are heavily dependent on process-wide mutable state (ie. DirectX 12 devices). + # DirectX 12 device lost unit tests. + # These tests are run one class at a time to ensure there's no accidental conflicts between any of them. This is because + # the code paths being tested in this project are heavily dependent on process-wide mutable state (ie. DirectX 12 devices). - name: Run ComputeSharp.Tests.DeviceLost "DeviceDisposal" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=DeviceDisposal" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - # These tests are failing randomly in the CI on .NET Framework, disabling them just for now + # These tests are failing randomly in the CI on .NET Framework, disabling them just for now - if: matrix.framework != 'net472' name: Run ComputeSharp.Tests.DeviceLost "DeviceLost" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=DeviceLost" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" @@ -110,7 +116,7 @@ jobs: name: Run ComputeSharp.Tests.DeviceLost "GetDefaultDevice" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=GetDefaultDevice" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - # D2D1 unit tests + # D2D1 unit tests - name: Run ComputeSharp.D2D1.Tests run: dotnet test tests\ComputeSharp.D2D1.Tests\ComputeSharp.D2D1.Tests.csproj -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - name: Run ComputeSharp.D2D1.Tests.AssemblyLevelAttributes From 63ce21aa0650e5d2901441213c83c3e2abe7d396 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 Feb 2023 15:57:14 +0100 Subject: [PATCH 07/15] Add CanvasAnimatedControl polyfill to WinUI sample Fix --- .../ComputeSharp.SwapChain.WinUI.csproj | 1 + .../CanvasAnimatedControl.cs | 135 ++++++++++++++++++ .../CanvasAnimatedDrawEventArgs.cs | 15 ++ .../ICanvasAnimatedControl.cs | 15 ++ .../CanvasTimingInformation.cs | 15 ++ 5 files changed, 181 insertions(+) create mode 100644 samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs create mode 100644 samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs create mode 100644 samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs create mode 100644 samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 84899a9f..92d30ae7 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -33,6 +33,7 @@ + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs new file mode 100644 index 00000000..f7c98bc1 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs @@ -0,0 +1,135 @@ +using System; +using System.Diagnostics; +using System.Threading; +using Microsoft.UI.Xaml.Controls; +using Windows.Foundation; + +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// XAML control intended for displaying animating content. +/// +public sealed class CanvasAnimatedControl : Grid, ICanvasAnimatedControl, IDisposable +{ + /// + /// The instance to use. + /// + private readonly CanvasControl canvasControl; + + /// + /// The used to track the elapsed time. + /// + private readonly Stopwatch stopwatch; + + /// + /// The used to render frames. + /// + private readonly Timer timer; + + /// + /// Indicates whether rendering is paused. + /// + private bool isPaused; + + /// + /// Indicates whether a new frame is currently being drawn. + /// + private volatile int isDrawing; + + /// + /// Hook this event to draw the contents of the control. + /// + public TypedEventHandler? Draw; + + /// + /// Creates a new instance. + /// + public CanvasAnimatedControl() + { + this.canvasControl = new CanvasControl(); + this.stopwatch = new Stopwatch(); + this.timer = new Timer( + callback: static canvasControl => ((CanvasControl)canvasControl!).Invalidate(), + state: this.canvasControl, + dueTime: TimeSpan.Zero, + period: TimeSpan.FromSeconds(1 / 60.0)); + + // Register the draw callback for the canvas control + this.canvasControl.Draw += CanvasControl_Draw; + + // Start the render stopwatch (the render timer has already started) + this.stopwatch.Start(); + + // Add the canvas control to the visual tree + Children.Add(this.canvasControl); + } + + /// + /// Gets or sets whether rendering has paused + /// + public bool IsPaused + { + get => this.isPaused; + set + { + if (this.isPaused != value) + { + this.isPaused = value; + + // Start or stop the timers as needed + if (value) + { + _ = this.timer.Change(Timeout.Infinite, Timeout.Infinite); + + this.stopwatch.Stop(); + } + else + { + _ = this.timer.Change(TimeSpan.Zero, TimeSpan.FromSeconds(1 / 60.0f)); + + this.stopwatch.Start(); + } + } + } + } + + /// + public void Dispose() + { + this.timer.Dispose(); + } + + // Forward the Draw event as a CanvasAnimatedControl sender + private void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) + { + // If another frame is already being concurrently drawn, do nothing + if (Interlocked.CompareExchange(ref this.isDrawing, 1, 0) == 1) + { + return; + } + + try + { + this.Draw?.Invoke( + sender: this, + args: new CanvasAnimatedDrawEventArgs + { + DrawingSession = args.DrawingSession, + Timing = new CanvasTimingInformation { TotalTime = this.stopwatch.Elapsed } + }); + } + finally + { + this.isDrawing = 0; + } + } + + /// + Size ICanvasAnimatedControl.Size => this.canvasControl.Size; + + /// + int ICanvasAnimatedControl.ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding) + { + return this.canvasControl.ConvertDipsToPixels(dips, dpiRounding); + } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs new file mode 100644 index 00000000..10deefba --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs @@ -0,0 +1,15 @@ +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// Provides data for the event. +/// +public sealed class CanvasAnimatedDrawEventArgs +{ + /// + public required CanvasDrawingSession DrawingSession { get; init; } + + /// + /// Gets the control's timing information for use by the event handler. + /// + public required CanvasTimingInformation Timing { get; init; } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs new file mode 100644 index 00000000..e7eb1646 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs @@ -0,0 +1,15 @@ +using Windows.Foundation; + +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// XAML control intended for displaying animating content. +/// +public interface ICanvasAnimatedControl +{ + /// + Size Size { get; } + + /// + int ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding); +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs new file mode 100644 index 00000000..54e3a9c8 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.Graphics.Canvas.UI.Xaml; + +namespace Microsoft.Graphics.Canvas.UI; + +/// +/// Contains information about a 's timer. +/// +public readonly struct CanvasTimingInformation +{ + /// + /// Represents the elapsed time, in ticks, for which this control has ever been running. + /// + public required TimeSpan TotalTime { get; init; } +} From 7254f1774c8da1b58ec90c2b0c4cc8da9c42e083 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 Feb 2023 16:08:16 +0100 Subject: [PATCH 08/15] Share D2D1 rendering code between UWP/WinUI samples --- ...omputeSharp.SwapChain.Core.Shared.projitems | 1 + .../Controls/D2D1AnimatedPixelShaderPanel.cs | 11 ++++++++++- .../Shaders/D2D1ShaderRunner{T}.cs | 18 ++++++++++-------- .../Shaders/ID2D1ShaderRunner.cs | 4 ---- .../Runners/D2D1ContouredLayersRunner.cs | 16 ++++++++++------ .../ComputeSharp.SwapChain.Uwp.csproj | 1 - .../Controls/D2D1AnimatedPixelShaderPanel.xaml | 6 +++--- .../ComputeSharp.SwapChain.WinUI.csproj | 9 +++++++++ .../Controls/D2D1AnimatedPixelShaderPanel.xaml | 16 ++++++++++++++++ .../CanvasAnimatedControl.cs | 10 +++++----- 10 files changed, 64 insertions(+), 28 deletions(-) rename samples/{ComputeSharp.SwapChain.Uwp => ComputeSharp.SwapChain.Core.Shared}/Controls/D2D1AnimatedPixelShaderPanel.cs (96%) create mode 100644 samples/ComputeSharp.SwapChain.WinUI/Controls/D2D1AnimatedPixelShaderPanel.xaml diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems index 35a54357..80831f63 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems @@ -11,6 +11,7 @@ + diff --git a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs similarity index 96% rename from samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs rename to samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs index cf7bbeba..a3889ca3 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs @@ -1,11 +1,20 @@ using ComputeSharp.SwapChain.Core.Shaders; using Microsoft.Graphics.Canvas.UI.Xaml; +#if WINDOWS_UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +#else +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +#endif #nullable enable +#if WINDOWS_UWP namespace ComputeSharp.SwapChain.Uwp.Views; +#else +namespace ComputeSharp.SwapChain.WinUI.Views; +#endif /// /// A custom that can be used to render animated backgrounds via Win2D. @@ -134,7 +143,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control if (@this.canvasAnimatedControl is { } canvasAnimatedControl) { - bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is ID2D1ShaderRunner; + bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is not null; canvasAnimatedControl.Paused = !shouldRender; } diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs index 7a01a45c..259c3993 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs @@ -3,9 +3,11 @@ using CommunityToolkit.Diagnostics; using ComputeSharp.D2D1; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; +#else +using ComputeSharp.D2D1.WinUI; +#endif using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.UI.Xaml; -#endif namespace ComputeSharp.SwapChain.Core.Shaders; @@ -13,10 +15,9 @@ namespace ComputeSharp.SwapChain.Core.Shaders; /// A simple implementation powered by a supplied shader type. /// /// The type of shader to use to render frames. -public sealed class D2D1ShaderRunner : ID2D1ShaderRunner +public sealed class D2D1ShaderRunner : ID2D1ShaderRunner, IDisposable where T : unmanaged, ID2D1PixelShader { -#if WINDOWS_UWP /// /// The instance used to create shaders to run. /// @@ -26,7 +27,6 @@ public sealed class D2D1ShaderRunner : ID2D1ShaderRunner /// The reusable instance to use to render frames. /// private readonly PixelShaderEffect pixelShaderEffect; -#endif /// /// Creates a new instance. @@ -36,13 +36,10 @@ public sealed class D2D1ShaderRunner : ID2D1ShaderRunner { Guard.IsNotNull(shaderFactory); -#if WINDOWS_UWP this.shaderFactory = shaderFactory; this.pixelShaderEffect = new PixelShaderEffect(); -#endif } -#if WINDOWS_UWP /// public void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { @@ -55,5 +52,10 @@ public sealed class D2D1ShaderRunner : ID2D1ShaderRunner // Draw the shader args.DrawingSession.DrawImage(this.pixelShaderEffect); } -#endif + + /// + public void Dispose() + { + this.pixelShaderEffect.Dispose(); + } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs index cb1a3bb4..f62bdd65 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs @@ -1,6 +1,4 @@ -#if WINDOWS_UWP using Microsoft.Graphics.Canvas.UI.Xaml; -#endif namespace ComputeSharp.SwapChain.Core.Shaders; @@ -9,12 +7,10 @@ namespace ComputeSharp.SwapChain.Core.Shaders; /// public interface ID2D1ShaderRunner { -#if WINDOWS_UWP /// /// Draws a new frame on a target instance. /// /// The target instance. /// The instance to use to draw the new frame. void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args); -#endif } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs index 225da1b1..9b0d89fc 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -1,16 +1,16 @@ -#if WINDOWS_UWP using System; using System.IO; using ComputeSharp.D2D1; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; +#else +using ComputeSharp.D2D1.WinUI; #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 @@ -19,9 +19,8 @@ namespace ComputeSharp.SwapChain.Core.Shaders.Runners; /// /// A specialized for . /// -public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner +public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable { -#if WINDOWS_UWP /// /// The reusable instance to use to render frames. /// @@ -72,5 +71,10 @@ public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner // Draw the shader args.DrawingSession.DrawImage(this.pixelShaderEffect); } -#endif + + /// + public void Dispose() + { + this.pixelShaderEffect?.Dispose(); + } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index 7efde0fe..440921fd 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -79,7 +79,6 @@ App.xaml - diff --git a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml b/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml index 3ca0e723..b7c172e8 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml @@ -1,14 +1,14 @@ + xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"> + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs index f7c98bc1..24002362 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs @@ -29,7 +29,7 @@ public sealed class CanvasAnimatedControl : Grid, ICanvasAnimatedControl, IDispo /// /// Indicates whether rendering is paused. /// - private bool isPaused; + private bool paused; /// /// Indicates whether a new frame is currently being drawn. @@ -67,14 +67,14 @@ public sealed class CanvasAnimatedControl : Grid, ICanvasAnimatedControl, IDispo /// /// Gets or sets whether rendering has paused /// - public bool IsPaused + public bool Paused { - get => this.isPaused; + get => this.paused; set { - if (this.isPaused != value) + if (this.paused != value) { - this.isPaused = value; + this.paused = value; // Start or stop the timers as needed if (value) From 0eee72ff29d452b1bf3fef93532b5bd30b58a7de Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 Feb 2023 16:22:36 +0100 Subject: [PATCH 09/15] Update WinUI sample XAML to be on par with UWP --- samples/ComputeSharp.SwapChain.Uwp/App.xaml | 2 +- .../Views/MainView.xaml | 8 +- samples/ComputeSharp.SwapChain.WinUI/App.xaml | 1 + .../Views/MainWindow.xaml | 89 +++++++++++++++---- .../Views/MainWindow.xaml.cs | 16 +++- 5 files changed, 92 insertions(+), 24 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.Uwp/App.xaml b/samples/ComputeSharp.SwapChain.Uwp/App.xaml index 8d04ab03..69db7e92 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/App.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/App.xaml @@ -6,7 +6,7 @@ - + diff --git a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml index 31029efd..2cfb1d41 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml @@ -148,7 +148,7 @@ - + + ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" /> - + diff --git a/samples/ComputeSharp.SwapChain.WinUI/App.xaml b/samples/ComputeSharp.SwapChain.WinUI/App.xaml index daf641e3..4e2888ba 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/App.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/App.xaml @@ -6,6 +6,7 @@ + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index 9d8692d9..9368dd8e 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -6,13 +6,12 @@ xmlns:computesharp="using:ComputeSharp.WinUI" xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" xmlns:converters="using:ComputeSharp.SwapChain.Core.Converters" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:enums="using:ComputeSharp.SwapChain.Core.Enums" xmlns:media="using:CommunityToolkit.WinUI.UI.Media" xmlns:ui="using:CommunityToolkit.WinUI.UI" xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels" - SizeChanged="UserControl_SizeChanged" - mc:Ignorable="d"> + xmlns:views="using:ComputeSharp.SwapChain.WinUI.Views" + SizeChanged="Window_SizeChanged"> @@ -119,7 +118,10 @@ - + - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs index 59f54119..b9846241 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs @@ -9,7 +9,7 @@ using Microsoft.UI.Xaml.Input; namespace ComputeSharp.SwapChain.WinUI.Views; /// -/// A view for . +/// A view for . /// public sealed partial class MainWindow : Window { @@ -62,7 +62,7 @@ public sealed partial class MainWindow : Window } // Updates the size of the shaders list panel - private void UserControl_SizeChanged(object sender, WindowSizeChangedEventArgs e) + private void Window_SizeChanged(object sender, WindowSizeChangedEventArgs e) { this.ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35); } @@ -72,4 +72,16 @@ public sealed partial class MainWindow : Window { this.shaderPanels.AddOrUpdate((AnimatedComputeShaderPanel)sender, null); } + + // Logs rendering failed in the main panel + private void MainShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, RenderingFailedEventArgs args) + { + this.RenderingErrorInfoBar.IsOpen = true; + } + + // Logs rendering failed in a secondary panel + private void SelectionShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, RenderingFailedEventArgs args) + { + this.RenderingErrorInfoBar.IsOpen = true; + } } \ No newline at end of file From df8a4c250b9635bb25fcaa52077198c0bce9f6d4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 26 Feb 2023 18:17:46 +0100 Subject: [PATCH 10/15] Support CsWinRT RCW marshalling in WinUI project --- .../CanvasEffect.Interop.cs | 23 +++------- .../ComputeSharp.D2D1.UI.projitems | 1 + .../Helpers/RcwMarshaller.cs | 45 +++++++++++++++++++ .../PixelShaderEffect{T}.ICanvasEffect.cs | 24 ++++------ .../PixelShaderEffect{T}.ICanvasImage.cs | 14 +++--- ...ixelShaderEffect{T}.ICanvasImageInterop.cs | 8 ++-- ...derEffect{T}.Properties.Interop.Sources.cs | 9 ++-- 7 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs index 155c4081..e8cdf977 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs @@ -1,8 +1,12 @@ using System; using System.Numerics; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -35,7 +39,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - GetCanvasImageInterop(canvasImageInterop.GetAddressOf()); + RcwMarshaller.QueryInterface(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetDevice(device, type); } @@ -51,7 +55,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - GetCanvasImageInterop(canvasImageInterop.GetAddressOf()); + RcwMarshaller.QueryInterface(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage); } @@ -79,17 +83,4 @@ unsafe partial class CanvasEffect return this.canvasImage; } } - - /// - /// Gets the object currently in use. - /// - /// A pointer to the object currently in use. - private void GetCanvasImageInterop(ICanvasImageInterop** canvasImageInterop) - { - using ComPtr canvasImageUnknown = default; - - canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(GetCanvasImage())); - - canvasImageUnknown.CopyTo(canvasImageInterop).Assert(); - } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems index cc372c6a..086fc849 100644 --- a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems @@ -32,6 +32,7 @@ + diff --git a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs new file mode 100644 index 00000000..1fff576c --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs @@ -0,0 +1,45 @@ +#if WINDOWS_UWP +using System.Runtime.InteropServices; +#endif +using TerraFX.Interop.Windows; +#if !WINDOWS_UWP +using WinRT; +#endif + +#if WINDOWS_UWP +namespace ComputeSharp.D2D1.Uwp.Helpers; +#else +namespace ComputeSharp.D2D1.WinUI.Helpers; +#endif + +/// +/// A helper type to handle marshalling of RCW instances. +/// +internal static class RcwMarshaller +{ + /// + /// Retrieves the underlying native object for an input RCW and casts it to the specified type. + /// + /// The interface type to retrieve an instance of. + /// The input RCW instance to unwrap. + /// A pointer to the resulting native object to retrieve. + /// The for the operation. + public static unsafe HRESULT QueryInterface(object managedObject, T** nativeObject) + where T : unmanaged // IUnknown + { + using ComPtr unknownObject = default; + +#if WINDOWS_UWP + // On UWP, due to built-in COM/WinRT support, Marshal.GetIUnknownForObject can handle all the logic + unknownObject.Attach((IUnknown*)Marshal.GetIUnknownForObject(managedObject)); +#else + // On WinUI 3, delegate the RCW unwrapping or CCW creation logic to CsWinRT's APIs + ObjectReferenceValue objectReference = MarshalInspectable.CreateMarshaler2(managedObject); + + unknownObject.Attach((IUnknown*)objectReference.Detach()); +#endif + + // QueryInterface to the specific interface we need + return unknownObject.CopyTo(nativeObject); + } +} diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs index 6e5e63d0..c3f7d459 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs @@ -3,6 +3,11 @@ using System.Buffers; using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; using TerraFX.Interop.Windows; using Windows.Foundation; @@ -93,12 +98,10 @@ unsafe partial class PixelShaderEffect Rect result; - using ComPtr canvasEffectUnknown = default; using ComPtr canvasEffectAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object from the input interface - canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffect)); - canvasEffectUnknown.CopyTo(canvasEffectAbi.GetAddressOf()).Assert(); + RcwMarshaller.QueryInterface(sourceEffect, canvasEffectAbi.GetAddressOf()).Assert(); Win2D.GetRequiredSourceRectanglesForICanvasImageInterop( resourceCreator: resourceCreatorWithDpi.Get(), @@ -152,10 +155,7 @@ unsafe partial class PixelShaderEffect // Get the underlying ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object for each input effect for (int i = 0; i < sourceEffects.Length; i++) { - using ComPtr canvasEffectUnknown = default; - - canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffects[i])); - canvasEffectUnknown.CopyTo(canvasEffects[i].GetAddressOf()).Assert(); + RcwMarshaller.QueryInterface(sourceEffects[i], canvasEffects[i].GetAddressOf()).Assert(); } Rect[] result = new Rect[sourceEffects.Length]; @@ -209,16 +209,10 @@ unsafe partial class PixelShaderEffect ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi** resourceCreatorWithDpi, ICanvasImageInterop** canvasImageInterop) { - using ComPtr resourceCreatorUnknown = default; - // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi object from the input interface - resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator)); - resourceCreatorUnknown.CopyTo(resourceCreatorWithDpi).Assert(); - - using ComPtr canvasImageInteropUnknown = default; + RcwMarshaller.QueryInterface(resourceCreator, resourceCreatorWithDpi).Assert(); // Get the ICanvasImageInterop object from the current instance - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this)); - canvasImageInteropUnknown.CopyTo(canvasImageInterop).Assert(); + RcwMarshaller.QueryInterface(this, canvasImageInterop).Assert(); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs index 26b33d5b..19f26b60 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs @@ -1,7 +1,11 @@ using System.Numerics; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; using TerraFX.Interop.Windows; using Windows.Foundation; @@ -33,19 +37,15 @@ unsafe partial class PixelShaderEffect { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); - using ComPtr resourceCreatorUnknown = default; using ComPtr resourceCreatorAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator object from the input interface - resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator)); - resourceCreatorUnknown.CopyTo(resourceCreatorAbi.GetAddressOf()).Assert(); + RcwMarshaller.QueryInterface(resourceCreator, resourceCreatorAbi.GetAddressOf()).Assert(); - using ComPtr canvasImageInteropUnknown = default; using ComPtr canvasImageInterop = default; // Get the ICanvasImageInterop object from the current instance - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this)); - canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.QueryInterface(this, canvasImageInterop.GetAddressOf()).Assert(); Rect bounds; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs index d68da8ab..a425de9e 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -7,8 +7,10 @@ using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Interop.Effects; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; +using ComputeSharp.D2D1.Uwp.Helpers; #else using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; #endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; @@ -361,14 +363,10 @@ unsafe partial class PixelShaderEffect } else { - using ComPtr canvasImageInteropUnknown = default; using ComPtr canvasImageInterop = default; - // Get the underlying IUnknown object for the current source - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(source)); - // Convert to ICanvasImageInterop (this must always succeed, and throws if it doesn't) - canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.QueryInterface(source, canvasImageInterop.GetAddressOf()).Assert(); using ComPtr d2D1Image = default; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 0f622d59..87198f0e 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -6,9 +6,11 @@ using ComputeSharp.D2D1.Extensions; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Extensions; +using ComputeSharp.D2D1.Uwp.Helpers; #else using ComputeSharp.D2D1.WinUI.Buffers; using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; #endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; @@ -136,15 +138,10 @@ unsafe partial class PixelShaderEffect if (value is not null) { - using ComPtr canvasImageUnknown = default; - - // Get the underlying IUnknown object for the input source - canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(value)); - using ComPtr canvasImageInterop = default; // Try to get the ICanvasImageInterop interface from the input source - HRESULT hresult = canvasImageUnknown.CopyTo(canvasImageInterop.GetAddressOf()); + HRESULT hresult = RcwMarshaller.QueryInterface(value, canvasImageInterop.GetAddressOf()); if (!Win32.SUCCEEDED(hresult)) { From 2578cf30288bc561e1a07de1053ec9f68200d034 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Mar 2023 21:46:23 +0100 Subject: [PATCH 11/15] Support CsWinRT CCW marshalling in WinUI project --- .../CanvasEffect.Interop.cs | 4 +-- .../Helpers/RcwMarshaller.cs | 30 +++++++++++++++---- .../Helpers/ResourceManager.cs | 5 +--- .../PixelShaderEffect{T}.ICanvasEffect.cs | 8 ++--- .../PixelShaderEffect{T}.ICanvasImage.cs | 4 +-- ...ixelShaderEffect{T}.ICanvasImageInterop.cs | 2 +- ...derEffect{T}.Properties.Interop.Sources.cs | 2 +- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs index e8cdf977..0da3a77e 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs @@ -39,7 +39,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - RcwMarshaller.QueryInterface(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetDevice(device, type); } @@ -55,7 +55,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - RcwMarshaller.QueryInterface(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage); } diff --git a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs index 1fff576c..93d99753 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs @@ -1,3 +1,4 @@ +using System; #if WINDOWS_UWP using System.Runtime.InteropServices; #endif @@ -18,14 +19,33 @@ namespace ComputeSharp.D2D1.WinUI.Helpers; internal static class RcwMarshaller { /// - /// Retrieves the underlying native object for an input RCW and casts it to the specified type. + /// Gets or creates a managed object of a specified type for an input native object. /// /// The interface type to retrieve an instance of. + /// A pointer to the native object to get a managed wrapper for. + /// The resulting managed object wrapping . + public static unsafe T GetOrCreateManagedObject(IUnknown* nativeObject) + where T : class + { +#if WINDOWS_UWP + // On UWP, Marshal.GetObjectForIUnknown handles all the marshalling/wrapping logic + return (T)Marshal.GetObjectForIUnknown((IntPtr)nativeObject); +#else + return MarshalInspectable.FromAbi((IntPtr)nativeObject); +#endif + } + + /// + /// Retrieves the underlying native object for an input RCW and casts it to the specified type. + /// + /// The type of managed object to unwrap. + /// The interface type to retrieve an instance of. /// The input RCW instance to unwrap. /// A pointer to the resulting native object to retrieve. /// The for the operation. - public static unsafe HRESULT QueryInterface(object managedObject, T** nativeObject) - where T : unmanaged // IUnknown + public static unsafe HRESULT GetNativeObject(TFrom managedObject, TTo** nativeObject) + where TFrom : class + where TTo : unmanaged // IUnknown { using ComPtr unknownObject = default; @@ -34,9 +54,7 @@ internal static class RcwMarshaller unknownObject.Attach((IUnknown*)Marshal.GetIUnknownForObject(managedObject)); #else // On WinUI 3, delegate the RCW unwrapping or CCW creation logic to CsWinRT's APIs - ObjectReferenceValue objectReference = MarshalInspectable.CreateMarshaler2(managedObject); - - unknownObject.Attach((IUnknown*)objectReference.Detach()); + unknownObject.Attach((IUnknown*)MarshalInspectable.FromManaged(managedObject)); #endif // QueryInterface to the specific interface we need diff --git a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs index 0795aac8..798354a8 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.Windows; @@ -67,8 +66,6 @@ internal static class ResourceManager wrapper: wrapperUnknown.GetVoidAddressOf()).Assert(); // Get the runtime-provided RCW for the resulting WinRT wrapper - object wrapper = Marshal.GetObjectForIUnknown((IntPtr)wrapperUnknown.Get()); - - return (IGraphicsEffectSource)wrapper; + return RcwMarshaller.GetOrCreateManagedObject(wrapperUnknown.Get()); } } diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs index c3f7d459..ac6a5cc2 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs @@ -101,7 +101,7 @@ unsafe partial class PixelShaderEffect using ComPtr canvasEffectAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object from the input interface - RcwMarshaller.QueryInterface(sourceEffect, canvasEffectAbi.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(sourceEffect, canvasEffectAbi.GetAddressOf()).Assert(); Win2D.GetRequiredSourceRectanglesForICanvasImageInterop( resourceCreator: resourceCreatorWithDpi.Get(), @@ -155,7 +155,7 @@ unsafe partial class PixelShaderEffect // Get the underlying ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object for each input effect for (int i = 0; i < sourceEffects.Length; i++) { - RcwMarshaller.QueryInterface(sourceEffects[i], canvasEffects[i].GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(sourceEffects[i], canvasEffects[i].GetAddressOf()).Assert(); } Rect[] result = new Rect[sourceEffects.Length]; @@ -210,9 +210,9 @@ unsafe partial class PixelShaderEffect ICanvasImageInterop** canvasImageInterop) { // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi object from the input interface - RcwMarshaller.QueryInterface(resourceCreator, resourceCreatorWithDpi).Assert(); + RcwMarshaller.GetNativeObject(resourceCreator, resourceCreatorWithDpi).Assert(); // Get the ICanvasImageInterop object from the current instance - RcwMarshaller.QueryInterface(this, canvasImageInterop).Assert(); + RcwMarshaller.GetNativeObject(this, canvasImageInterop).Assert(); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs index 19f26b60..be000836 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs @@ -40,12 +40,12 @@ unsafe partial class PixelShaderEffect using ComPtr resourceCreatorAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator object from the input interface - RcwMarshaller.QueryInterface(resourceCreator, resourceCreatorAbi.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(resourceCreator, resourceCreatorAbi.GetAddressOf()).Assert(); using ComPtr canvasImageInterop = default; // Get the ICanvasImageInterop object from the current instance - RcwMarshaller.QueryInterface(this, canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(this, canvasImageInterop.GetAddressOf()).Assert(); Rect bounds; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs index a425de9e..5f376fdf 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -366,7 +366,7 @@ unsafe partial class PixelShaderEffect using ComPtr canvasImageInterop = default; // Convert to ICanvasImageInterop (this must always succeed, and throws if it doesn't) - RcwMarshaller.QueryInterface(source, canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(source, canvasImageInterop.GetAddressOf()).Assert(); using ComPtr d2D1Image = default; diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 87198f0e..264b610a 100644 --- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -141,7 +141,7 @@ unsafe partial class PixelShaderEffect using ComPtr canvasImageInterop = default; // Try to get the ICanvasImageInterop interface from the input source - HRESULT hresult = RcwMarshaller.QueryInterface(value, canvasImageInterop.GetAddressOf()); + HRESULT hresult = RcwMarshaller.GetNativeObject(value, canvasImageInterop.GetAddressOf()); if (!Win32.SUCCEEDED(hresult)) { From a291685affa862d698e0f3132b0701a9e94626dc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Mar 2023 22:25:12 +0100 Subject: [PATCH 12/15] Switch D2D1 UWP/WinUI samples to use CanvasEffect This replaces the ID2D1ShaderRunner interface in the sample apps --- ...mputeSharp.SwapChain.Core.Shared.projitems | 3 +- .../Controls/D2D1AnimatedPixelShaderPanel.cs | 50 +++++--- .../Shaders/D2D1ShaderRunner{T}.cs | 61 --------- .../Shaders/ID2D1ShaderRunner.cs | 16 --- .../Shaders/PixelShaderEffect.cs | 121 ++++++++++++++++++ .../Runners/D2D1ContouredLayersRunner.cs | 82 ++++++------ .../ViewModels/MainViewModel.cs | 20 +-- .../ViewModels/ShaderRunnerViewModel.cs | 10 +- .../Views/MainView.xaml | 2 +- .../Views/MainWindow.xaml | 2 +- .../CanvasEffect.Interop.cs | 2 + src/ComputeSharp.D2D1.UI/CanvasEffect.cs | 16 +-- 12 files changed, 219 insertions(+), 166 deletions(-) delete mode 100644 samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs delete mode 100644 samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs create mode 100644 samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems index 80831f63..8fd7c01f 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems @@ -17,8 +17,7 @@ - - + diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs index a3889ca3..38351f58 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs @@ -1,4 +1,5 @@ using ComputeSharp.SwapChain.Core.Shaders; +using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.UI.Xaml; #if WINDOWS_UWP using Windows.UI.Xaml; @@ -28,9 +29,9 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control private CanvasAnimatedControl? canvasAnimatedControl; /// - /// The instance currently in use, if any. + /// The instance currently in use, if any. /// - private volatile ID2D1ShaderRunner? shaderRunner; + private volatile PixelShaderEffect? pixelShaderEffect; /// /// Creates a new instance. @@ -56,7 +57,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control private void D2D1AnimatedPixelShaderPanel_Loaded(object sender, RoutedEventArgs e) { if (this.canvasAnimatedControl is { } canvasAnimatedControl && - ShaderRunner is not null && + PixelShaderEffect is not null && !IsPaused) { canvasAnimatedControl.Paused = false; @@ -75,43 +76,50 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control /// /// Draws a new frame on the wrapped instance. /// - /// + /// The source instance. + /// The object to perform drawing with. private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { - this.shaderRunner?.Execute(sender, args); + // Set the effect properties + this.pixelShaderEffect!.ElapsedTime = args.Timing.TotalTime; + this.pixelShaderEffect.ScreenWidth = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round); + this.pixelShaderEffect.ScreenHeight = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round); + + // Draw the effect + args.DrawingSession.DrawImage(this.pixelShaderEffect); } /// - /// Gets or sets the instance to use to render content. + /// Gets or sets the instance to use to render content. /// - public ID2D1ShaderRunner? ShaderRunner + public PixelShaderEffect? PixelShaderEffect { - get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty); - set => SetValue(ShaderRunnerProperty, value); + get => (PixelShaderEffect?)GetValue(PixelShaderEffectProperty); + set => SetValue(PixelShaderEffectProperty, value); } /// - /// The backing . + /// The backing . /// - public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register( - nameof(ShaderRunner), - typeof(ID2D1ShaderRunner), + public static readonly DependencyProperty PixelShaderEffectProperty = DependencyProperty.Register( + nameof(PixelShaderEffect), + typeof(PixelShaderEffect), typeof(D2D1AnimatedPixelShaderPanel), - new PropertyMetadata(null, OnShaderRunnerPropertyChanged)); + new PropertyMetadata(null, OnPixelShaderEffectPropertyChanged)); /// - private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnPixelShaderEffectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d; - ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue; + PixelShaderEffect? pixelShaderEffect = (PixelShaderEffect?)e.NewValue; - // Save the new shader runner for later (as the dependency property cannot be accessed by the render thread) - @this.shaderRunner = shaderRunner; + // Save the new pixel shader effect for later (as the dependency property cannot be accessed by the render thread) + @this.pixelShaderEffect = pixelShaderEffect; - // Pause or start the render thread if a runner is available + // Pause or start the render thread if an effect is available if (@this.canvasAnimatedControl is { } canvasAnimatedControl) { - bool shouldRender = @this.IsLoaded && !@this.IsPaused && shaderRunner is not null; + bool shouldRender = @this.IsLoaded && !@this.IsPaused && pixelShaderEffect is not null; canvasAnimatedControl.Paused = !shouldRender; } @@ -143,7 +151,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control if (@this.canvasAnimatedControl is { } canvasAnimatedControl) { - bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is not null; + bool shouldRender = @this.IsLoaded && !isPaused && @this.PixelShaderEffect is not null; canvasAnimatedControl.Paused = !shouldRender; } diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs deleted file mode 100644 index 259c3993..00000000 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using CommunityToolkit.Diagnostics; -using ComputeSharp.D2D1; -#if WINDOWS_UWP -using ComputeSharp.D2D1.Uwp; -#else -using ComputeSharp.D2D1.WinUI; -#endif -using Microsoft.Graphics.Canvas; -using Microsoft.Graphics.Canvas.UI.Xaml; - -namespace ComputeSharp.SwapChain.Core.Shaders; - -/// -/// A simple implementation powered by a supplied shader type. -/// -/// The type of shader to use to render frames. -public sealed class D2D1ShaderRunner : ID2D1ShaderRunner, IDisposable - where T : unmanaged, ID2D1PixelShader -{ - /// - /// The instance used to create shaders to run. - /// - private readonly Func shaderFactory; - - /// - /// The reusable instance to use to render frames. - /// - private readonly PixelShaderEffect pixelShaderEffect; - - /// - /// Creates a new instance. - /// - /// The instance used to create shaders to run. - public D2D1ShaderRunner(Func shaderFactory) - { - Guard.IsNotNull(shaderFactory); - - this.shaderFactory = shaderFactory; - this.pixelShaderEffect = new PixelShaderEffect(); - } - - /// - 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); - } - - /// - public void Dispose() - { - this.pixelShaderEffect.Dispose(); - } -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs deleted file mode 100644 index f62bdd65..00000000 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.Graphics.Canvas.UI.Xaml; - -namespace ComputeSharp.SwapChain.Core.Shaders; - -/// -/// An interface for a shader runner to be used with a Win2D renderer. -/// -public interface ID2D1ShaderRunner -{ - /// - /// Draws a new frame on a target instance. - /// - /// The target instance. - /// The instance to use to draw the new frame. - void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args); -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs new file mode 100644 index 00000000..e0257d28 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs @@ -0,0 +1,121 @@ +using System; +using ComputeSharp.D2D1; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp; +#else +using ComputeSharp.D2D1.WinUI; +#endif +using Microsoft.Graphics.Canvas; + +#nullable enable + +namespace ComputeSharp.SwapChain.Core.Shaders; + +/// +/// An base effect for an animated pixel shader. +/// +public abstract class PixelShaderEffect : CanvasEffect +{ + /// + /// The current elapsed time. + /// + private TimeSpan elapsedTime; + + /// + /// The current screen width in raw pixels. + /// + private int screenWidth; + + /// + /// The current screen height in raw pixels. + /// + private int screenHeight; + + /// + /// Gets or sets the total elapsed time. + /// + public TimeSpan ElapsedTime + { + get => this.elapsedTime; + set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value); + } + + /// + /// Gets or sets the screen width in raw pixels. + /// + public int ScreenWidth + { + get => this.screenWidth; + set => SetAndInvalidateEffectGraph(ref this.screenWidth, value); + } + + /// + /// Gets or sets the screen height in raw pixels. + /// + public int ScreenHeight + { + get => this.screenHeight; + set => SetAndInvalidateEffectGraph(ref this.screenHeight, value); + } + + /// + /// An effect for an animated pixel shader. + /// + /// The type of pixel shader to render. + public sealed class For : PixelShaderEffect + where T : unmanaged, ID2D1PixelShader + { + /// + /// The factory to use. + /// + private readonly Factory factory; + + /// + /// The instance in use. + /// + private PixelShaderEffect? effect; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The input factory. + public For(Factory factory) + { + this.factory = factory; + } + + /// + protected override ICanvasImage BuildEffectGraph() + { + this.effect = new PixelShaderEffect(); + + return this.effect; + } + + /// + protected override void ConfigureEffectGraph() + { + this.effect!.ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight); + } + + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + this.effect?.Dispose(); + } + } + + /// + /// A factory of a given shader instance. + /// + /// The total elapsed time. + /// The screen width in raw pixels. + /// The screen height in raw pixels. + /// A shader instance to render. + public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight); + } +} diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs index 9b0d89fc..9707c246 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -9,7 +9,6 @@ using ComputeSharp.D2D1.WinUI; #endif using ComputeSharp.SwapChain.Shaders.D2D1; using Microsoft.Graphics.Canvas; -using Microsoft.Graphics.Canvas.UI.Xaml; using Windows.ApplicationModel; #nullable enable @@ -17,9 +16,9 @@ using Windows.ApplicationModel; namespace ComputeSharp.SwapChain.Core.Shaders.Runners; /// -/// A specialized for . +/// A specialized for . /// -public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable +public sealed class D2D1ContouredLayersEffect : PixelShaderEffect { /// /// The reusable instance to use to render frames. @@ -27,54 +26,55 @@ public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable private PixelShaderEffect? pixelShaderEffect; /// - public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) + protected override unsafe ICanvasImage BuildEffectGraph() { - if (this.pixelShaderEffect is null) - { - string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png"); + 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 readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename); - using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height); + // 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 readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename); + using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height); - readOnlyTexture.CopyTo(readBackTexture); + 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)); + // 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(dataBuffer, bufferSize), - strides: stackalloc uint[] { (uint)strideInBytes }); + // 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(dataBuffer, bufferSize), + strides: stackalloc uint[] { (uint)strideInBytes }); - // Create the new pixel shader effect - this.pixelShaderEffect = new PixelShaderEffect() { ResourceTextureManagers = { [0] = resourceTextureManager } }; - } + // Create the new pixel shader effect + this.pixelShaderEffect = new PixelShaderEffect() { 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); + return this.pixelShaderEffect; } /// - public void Dispose() + protected override void ConfigureEffectGraph() { - this.pixelShaderEffect?.Dispose(); + this.pixelShaderEffect!.ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight)); + } + + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + this.pixelShaderEffect?.Dispose(); + } } } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs index 076a6dc0..3944abaa 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs @@ -95,40 +95,40 @@ public sealed partial class MainViewModel : ObservableObject new( nameof(ColorfulInfinity), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(FractalTiling), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(MengerJourney), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(Octagrams), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(ProteanClouds), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(TwoTiledTruchet), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(PyramidPattern), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(TriangleGridContouring), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersEffect()), new( nameof(TerracedHills), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), }; /// diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs index eb8d1ef6..7ff1af01 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs @@ -18,12 +18,12 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject /// /// The name of the shader type to execute. /// The instance to execute. - /// The instance to execute. - public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner) + /// The instance to execute. + public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect) { ShaderType = shaderType; ShaderRunner = shaderRunner; - D2D1ShaderRunner = d2D1ShaderRunner; + PixelShaderEffect = pixelShaderEffect; } /// @@ -37,9 +37,9 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject public IShaderRunner ShaderRunner { get; } /// - /// Gets the instance to execute. + /// Gets the instance to execute. /// - public ID2D1ShaderRunner D2D1ShaderRunner { get; } + public PixelShaderEffect PixelShaderEffect { get; } /// /// Gets or sets whether the current shader is selected. diff --git a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml index 2cfb1d41..ea7f8a1d 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/Views/MainView.xaml @@ -162,7 +162,7 @@ - + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index 9368dd8e..410e1310 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -165,7 +165,7 @@ - + diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs index 0da3a77e..58399b07 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Numerics; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; @@ -65,6 +66,7 @@ unsafe partial class CanvasEffect /// /// The current instance. /// Thrown if the current instance is disposed. + [MemberNotNull(nameof(canvasImage))] private ICanvasImage GetCanvasImage() { lock (this.lockObject) diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs index 050a4421..efef99d5 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs @@ -155,14 +155,6 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I InvalidateEffectGraph(invalidationType); } - /// - public void Dispose() - { - Dispose(disposing: true); - - GC.SuppressFinalize(this); - } - /// /// Disposes any disposable resources in the current instance. /// @@ -211,6 +203,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I this.isDisposed = true; } + /// + public void Dispose() + { + Dispose(disposing: true); + + GC.SuppressFinalize(this); + } + /// /// Indicates the invalidation type to request when invoking and related methods. /// From 1c18b3624f40912d7784d63b224c4c889b130b93 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 27 Mar 2023 13:20:51 +0200 Subject: [PATCH 13/15] Fix trimming in WinUI projects --- .../Helpers/RcwMarshaller.cs | 5 +++-- src/Directory.Build.targets | 22 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs index 93d99753..c7afd40d 100644 --- a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; #if WINDOWS_UWP using System.Runtime.InteropServices; #endif @@ -24,7 +25,7 @@ internal static class RcwMarshaller /// The interface type to retrieve an instance of. /// A pointer to the native object to get a managed wrapper for. /// The resulting managed object wrapping . - public static unsafe T GetOrCreateManagedObject(IUnknown* nativeObject) + public static unsafe T GetOrCreateManagedObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] T>(IUnknown* nativeObject) where T : class { #if WINDOWS_UWP @@ -43,7 +44,7 @@ internal static class RcwMarshaller /// The input RCW instance to unwrap. /// A pointer to the resulting native object to retrieve. /// The for the operation. - public static unsafe HRESULT GetNativeObject(TFrom managedObject, TTo** nativeObject) + public static unsafe HRESULT GetNativeObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] TFrom, TTo>(TFrom managedObject, TTo** nativeObject) where TFrom : class where TTo : unmanaged // IUnknown { diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index f7812f87..7ef82c2f 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -2,14 +2,16 @@ - - - - true - true - - + + + true + true + - + - + <_Parameter1>false From 0852e77b582e76ae6fff4548db4d306295d2b5d5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 27 Mar 2023 13:23:10 +0200 Subject: [PATCH 14/15] Suppress DNG02 warning --- src/Directory.Build.props | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c21734fc..33e5456a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,16 @@ + + + + $(NoWarn);DNG02 + + From 99b1ccfbe7130ffdd1ef9216f7680bd5ab55bd7e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 20 Apr 2023 20:19:12 +0200 Subject: [PATCH 15/15] Update WIn2D and WinAppSDK references to latest stable --- .../ComputeSharp.SwapChain.WinUI.csproj | 2 +- src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj | 2 +- src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj | 3 ++- src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index c06f0f3b..9e347f33 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj index 64066056..1c8ecc34 100644 --- a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj +++ b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj @@ -30,7 +30,7 @@ - + diff --git a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj index 1baee968..cb372053 100644 --- a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj +++ b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj @@ -20,7 +20,8 @@ - + + diff --git a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj index 5e539907..c4f220cb 100644 --- a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj +++ b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj @@ -19,7 +19,7 @@ - +