Merge pull request #661 from Sergio0694/dev/native-library-sample-winrt

Add WinRT component sample
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2024-06-30 15:30:36 -07:00
コミット 6e92adff15
4ファイル変更
+157 -1

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

+7
ファイルの表示
@@ -316,6 +316,13 @@ jobs:
- name: Publish ComputeSharp.NativeLibrary
run: dotnet publish samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj -r win-${{matrix.platform}} -v n
# Publish the WinRT component with NativeAOT as well
- if: matrix.platform == 'x64'
name: Publish ComputeSharp.NativeLibrary.WinRT
run: >
msbuild samples\ComputeSharp.NativeLibrary.WinRT\ComputeSharp.NativeLibrary.WinRT.csproj /restore -t:publish
/p:Configuration=Release /p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}}
# Download the NuGet packages generated in the previous job and use them
# to build and run the sample project referencing them. This is used as
# a test to ensure the NuGet packages work in a consuming project.
+12 -1
ファイルの表示
@@ -164,7 +164,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "arm64", "arm64", "{B4F6A41C
libs\arm64\WinPixEventRuntime_UAP.dll = libs\arm64\WinPixEventRuntime_UAP.dll
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.NativeLibrary", "samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj", "{1A3E20B3-F711-41C0-82EA-3B53A575955C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.NativeLibrary", "samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj", "{1A3E20B3-F711-41C0-82EA-3B53A575955C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.NativeLibrary.WinRT", "samples\ComputeSharp.NativeLibrary.WinRT\ComputeSharp.NativeLibrary.WinRT.csproj", "{551EF4FB-F34F-412A-B3E6-E345797560ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -454,6 +456,14 @@ Global
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|ARM64.Build.0 = Release|Any CPU
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.ActiveCfg = Release|Any CPU
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.Build.0 = Release|Any CPU
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.ActiveCfg = Debug|ARM64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|ARM64.Build.0 = Debug|ARM64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.ActiveCfg = Debug|x64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Debug|x64.Build.0 = Debug|x64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.ActiveCfg = Release|ARM64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|ARM64.Build.0 = Release|ARM64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.ActiveCfg = Release|x64
{551EF4FB-F34F-412A-B3E6-E345797560ED}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -492,6 +502,7 @@ Global
{79FD7862-4707-4DE0-8777-3872558E4C1C} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104}
{B4F6A41C-AA9A-4302-92B3-AC64CF2E30F5} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104}
{1A3E20B3-F711-41C0-82EA-3B53A575955C} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
{551EF4FB-F34F-412A-B3E6-E345797560ED} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
+56
ファイルの表示
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<WindowsSdkPackageVersion>10.0.22621.35-preview</WindowsSdkPackageVersion>
<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup>
<CsWinRTComponent>true</CsWinRTComponent>
<!--
CsWinRT uses the assembly name to find the root namespace to use to crawl for exported types.
We are changing this to exclude the 'WinRT' suffix, since that is not actually necessary.
-->
<AssemblyName>ComputeSharp.NativeLibrary</AssemblyName>
<!-- CsWinRT size saving options (also disabling some features that aren't needed) -->
<CsWinRTEnableDynamicObjectsSupport>false</CsWinRTEnableDynamicObjectsSupport>
<CsWinRTUseExceptionResourceKeys>true</CsWinRTUseExceptionResourceKeys>
<CsWinRTEnableDefaultCustomTypeMappings>false</CsWinRTEnableDefaultCustomTypeMappings>
<CsWinRTEnableICustomPropertyProviderSupport>false</CsWinRTEnableICustomPropertyProviderSupport>
<CsWinRTEnableIReferenceSupport>false</CsWinRTEnableIReferenceSupport>
<CsWinRTEnableIDynamicInterfaceCastableSupport>false</CsWinRTEnableIDynamicInterfaceCastableSupport>
<!--
WinRT component warning suppression due to a default MSVC warning:
"LNK4104: export of symbol 'DllCanUnloadNow' should be PRIVATE".
See: https://github.com/dotnet/runtime/issues/98047.
-->
<NoWarn>$(NoWarn);LNK4104</NoWarn>
</PropertyGroup>
<!-- NativeAOT configuration -->
<PropertyGroup>
<PublishAot>true</PublishAot>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<InvariantGlobalization>true</InvariantGlobalization>
<OptimizationPreference>Size</OptimizationPreference>
<StackTraceSupport>false</StackTraceSupport>
<IlcGenerateMstatFile>false</IlcGenerateMstatFile>
<IlcGenerateDgmlFile>false</IlcGenerateDgmlFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240602.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
</ItemGroup>
</Project>
+82
ファイルの表示
@@ -0,0 +1,82 @@
using ComputeSharp.D2D1;
using ComputeSharp.D2D1.WinUI;
using Windows.Foundation;
namespace ComputeSharp.NativeLibrary;
/// <summary>
/// A hello world effect that displays a color gradient.
/// </summary>
public sealed partial class HelloWorldEffect : CanvasEffect
{
/// <summary>
/// The <see cref="PixelShaderEffect{T}"/> node in use.
/// </summary>
private static readonly CanvasEffectNode<PixelShaderEffect<Shader>> EffectNode = new();
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='time']/node()"/></summary>
private float time;
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='dispatchSize']/node()"/></summary>
private Rect dispatchArea;
/// <summary>
/// Gets or sets the current time since the start of the application.
/// </summary>
public float Time
{
get => this.time;
set => SetAndInvalidateEffectGraph(ref this.time, value);
}
/// <summary>
/// Gets or sets the dispatch area for the current output.
/// </summary>
public Rect DispatchArea
{
get => this.dispatchArea;
set => SetAndInvalidateEffectGraph(ref this.dispatchArea, value);
}
/// <inheritdoc/>
protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
{
effectGraph.RegisterOutputNode(EffectNode, new PixelShaderEffect<Shader>());
}
/// <inheritdoc/>
protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph)
{
effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader(
time: this.time,
dispatchSize: new int2(
x: (int)double.Round(this.dispatchArea.Width),
y: (int)double.Round(this.dispatchArea.Height)));
}
/// <summary>
/// A hello world effect that displays a color gradient.
/// </summary>
/// <param name="time">The current time since the start of the application.</param>
/// <param name="dispatchSize">The dispatch size for the current output.</param>
[D2DEffectDisplayName(nameof(HelloWorldEffect))]
[D2DEffectDescription("A hello world effect that displays a color gradient.")]
[D2DEffectCategory("Render")]
[D2DEffectAuthor("ComputeSharp.D2D1")]
[D2DInputCount(0)]
[D2DRequiresScenePosition]
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
[D2DGeneratedPixelShaderDescriptor]
internal readonly partial struct Shader(float time, int2 dispatchSize) : ID2D1PixelShader
{
/// <inheritdoc/>
public float4 Execute()
{
int2 xy = (int2)D2D.GetScenePosition().XY;
float2 uv = xy / (float2)dispatchSize;
float3 color = 0.5f + (0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4)));
return new(color, 1f);
}
}
}