-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #661 from Sergio0694/dev/native-library-sample-winrt
Add WinRT component sample
- Loading branch information
Showing
4 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 82 additions & 0 deletions
82
samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |