Skip to content

Commit

Permalink
Use '[GeneratedCanvasEffectProperty]' in samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 21, 2024
1 parent 0f45b09 commit 51cd173
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<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.SourceGenerators\ComputeSharp.D2D1.WinUI.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>
Expand Down
26 changes: 7 additions & 19 deletions samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,17 @@ public sealed partial class HelloWorldEffect : CanvasEffect
/// </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 => SetPropertyAndInvalidateEffectGraph(ref this.time, value);
}
[GeneratedCanvasEffectProperty]
public partial float Time { get; set; }

/// <summary>
/// Gets or sets the dispatch area for the current output.
/// </summary>
public Rect DispatchArea
{
get => this.dispatchArea;
set => SetPropertyAndInvalidateEffectGraph(ref this.dispatchArea, value);
}
[GeneratedCanvasEffectProperty]
public partial Rect DispatchArea { get; set; }

/// <inheritdoc/>
protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
Expand All @@ -48,10 +36,10 @@ protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph)
{
effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader(
time: this.time,
time: Time,
dispatchSize: new int2(
x: (int)double.Round(this.dispatchArea.Width),
y: (int)double.Round(this.dispatchArea.Height)));
x: (int)double.Round(DispatchArea.Width),
y: (int)double.Round(DispatchArea.Height)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend;
/// </summary>
internal abstract partial class PixelShaderEffect : CanvasEffect
{
/// <summary>
/// The current elapsed time.
/// </summary>
private TimeSpan elapsedTime;

/// <summary>
/// The current screen width in raw pixels.
/// </summary>
private int screenWidth;

/// <summary>
/// The current screen height in raw pixels.
/// </summary>
private int screenHeight;

/// <summary>
/// Gets or sets the total elapsed time.
/// </summary>
public TimeSpan ElapsedTime
{
get => this.elapsedTime;
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
}
[GeneratedCanvasEffectProperty]
public partial TimeSpan ElapsedTime { get; set; }

/// <summary>
/// Gets or sets the screen width in raw pixels.
/// </summary>
public int ScreenWidth
{
get => this.screenWidth;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenWidth { get; set; }

/// <summary>
/// Gets or sets the screen height in raw pixels.
/// </summary>
public int ScreenHeight
{
get => this.screenHeight;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenHeight { get; set; }

/// <summary>
/// An effect for an animated pixel shader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" SetPlatform="Platform=AnyCPU" 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" SetPlatform="Platform=AnyCPU" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI.SourceGenerators\ComputeSharp.D2D1.WinUI.SourceGenerators.csproj" SetPlatform="Platform=AnyCPU" 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend;
/// </summary>
internal abstract partial class PixelShaderEffect : CanvasEffect
{
/// <summary>
/// The current elapsed time.
/// </summary>
private TimeSpan elapsedTime;

/// <summary>
/// The current screen width in raw pixels.
/// </summary>
private int screenWidth;

/// <summary>
/// The current screen height in raw pixels.
/// </summary>
private int screenHeight;

/// <summary>
/// Gets or sets the total elapsed time.
/// </summary>
public TimeSpan ElapsedTime
{
get => this.elapsedTime;
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
}
[GeneratedCanvasEffectProperty]
public partial TimeSpan ElapsedTime { get; set; }

/// <summary>
/// Gets or sets the screen width in raw pixels.
/// </summary>
public int ScreenWidth
{
get => this.screenWidth;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenWidth { get; set; }

/// <summary>
/// Gets or sets the screen height in raw pixels.
/// </summary>
public int ScreenHeight
{
get => this.screenHeight;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenHeight { get; set; }

/// <summary>
/// An effect for an animated pixel shader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@

<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp.SourceGenerators\ComputeSharp.D2D1.Uwp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
</ItemGroup>

<!-- Shared projects for the D2D1 shaders -->
Expand Down
36 changes: 6 additions & 30 deletions samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,23 @@ namespace ComputeSharp.SwapChain.Core.Shaders;
/// </summary>
public abstract partial class PixelShaderEffect : CanvasEffect
{
/// <summary>
/// The current elapsed time.
/// </summary>
private TimeSpan elapsedTime;

/// <summary>
/// The current screen width in raw pixels.
/// </summary>
private int screenWidth;

/// <summary>
/// The current screen height in raw pixels.
/// </summary>
private int screenHeight;

/// <summary>
/// Gets or sets the total elapsed time.
/// </summary>
public TimeSpan ElapsedTime
{
get => this.elapsedTime;
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
}
[GeneratedCanvasEffectProperty]
public partial TimeSpan ElapsedTime { get; set; }

/// <summary>
/// Gets or sets the screen width in raw pixels.
/// </summary>
public int ScreenWidth
{
get => this.screenWidth;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenWidth { get; set; }

/// <summary>
/// Gets or sets the screen height in raw pixels.
/// </summary>
public int ScreenHeight
{
get => this.screenHeight;
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
}
[GeneratedCanvasEffectProperty]
public partial int ScreenHeight { get; set; }

/// <summary>
/// An effect for an animated pixel shader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp.SourceGenerators\ComputeSharp.D2D1.Uwp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI.SourceGenerators\ComputeSharp.D2D1.WinUI.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" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
Expand Down

0 comments on commit 51cd173

Please sign in to comment.