Skip to content

Commit e4a8770

Browse files
authored
Merge pull request #889 from Sergio0694/dev/use-generated-canvas-effect-property
Use '[GeneratedCanvasEffectProperty]' in samples
2 parents 0f45b09 + 51cd173 commit e4a8770

File tree

9 files changed

+31
-110
lines changed

9 files changed

+31
-110
lines changed

samples/ComputeSharp.NativeLibrary.WinRT/ComputeSharp.NativeLibrary.WinRT.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
5151
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
5252
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
53+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI.SourceGenerators\ComputeSharp.D2D1.WinUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
5354
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
5455
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
5556
</ItemGroup>

samples/ComputeSharp.NativeLibrary.WinRT/HelloWorldEffect.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,17 @@ public sealed partial class HelloWorldEffect : CanvasEffect
1414
/// </summary>
1515
private static readonly CanvasEffectNode<PixelShaderEffect<Shader>> EffectNode = new();
1616

17-
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='time']/node()"/></summary>
18-
private float time;
19-
20-
/// <summary><inheritdoc cref="Shader(float, Int2)" path="/param[@name='dispatchSize']/node()"/></summary>
21-
private Rect dispatchArea;
22-
2317
/// <summary>
2418
/// Gets or sets the current time since the start of the application.
2519
/// </summary>
26-
public float Time
27-
{
28-
get => this.time;
29-
set => SetPropertyAndInvalidateEffectGraph(ref this.time, value);
30-
}
20+
[GeneratedCanvasEffectProperty]
21+
public partial float Time { get; set; }
3122

3223
/// <summary>
3324
/// Gets or sets the dispatch area for the current output.
3425
/// </summary>
35-
public Rect DispatchArea
36-
{
37-
get => this.dispatchArea;
38-
set => SetPropertyAndInvalidateEffectGraph(ref this.dispatchArea, value);
39-
}
26+
[GeneratedCanvasEffectProperty]
27+
public partial Rect DispatchArea { get; set; }
4028

4129
/// <inheritdoc/>
4230
protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
@@ -48,10 +36,10 @@ protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
4836
protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph)
4937
{
5038
effectGraph.GetNode(EffectNode).ConstantBuffer = new Shader(
51-
time: this.time,
39+
time: Time,
5240
dispatchSize: new int2(
53-
x: (int)double.Round(this.dispatchArea.Width),
54-
y: (int)double.Round(this.dispatchArea.Height)));
41+
x: (int)double.Round(DispatchArea.Width),
42+
y: (int)double.Round(DispatchArea.Height)));
5543
}
5644

5745
/// <summary>

samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend;
1010
/// </summary>
1111
internal abstract partial class PixelShaderEffect : CanvasEffect
1212
{
13-
/// <summary>
14-
/// The current elapsed time.
15-
/// </summary>
16-
private TimeSpan elapsedTime;
17-
18-
/// <summary>
19-
/// The current screen width in raw pixels.
20-
/// </summary>
21-
private int screenWidth;
22-
23-
/// <summary>
24-
/// The current screen height in raw pixels.
25-
/// </summary>
26-
private int screenHeight;
27-
2813
/// <summary>
2914
/// Gets or sets the total elapsed time.
3015
/// </summary>
31-
public TimeSpan ElapsedTime
32-
{
33-
get => this.elapsedTime;
34-
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
35-
}
16+
[GeneratedCanvasEffectProperty]
17+
public partial TimeSpan ElapsedTime { get; set; }
3618

3719
/// <summary>
3820
/// Gets or sets the screen width in raw pixels.
3921
/// </summary>
40-
public int ScreenWidth
41-
{
42-
get => this.screenWidth;
43-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
44-
}
22+
[GeneratedCanvasEffectProperty]
23+
public partial int ScreenWidth { get; set; }
4524

4625
/// <summary>
4726
/// Gets or sets the screen height in raw pixels.
4827
/// </summary>
49-
public int ScreenHeight
50-
{
51-
get => this.screenHeight;
52-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
53-
}
28+
[GeneratedCanvasEffectProperty]
29+
public partial int ScreenHeight { get; set; }
5430

5531
/// <summary>
5632
/// An effect for an animated pixel shader.

samples/ComputeSharp.SwapChain.D2D1.Cli/ComputeSharp.SwapChain.D2D1.Cli.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" SetPlatform="Platform=AnyCPU" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
7575
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
7676
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" SetPlatform="Platform=AnyCPU" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
77+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI.SourceGenerators\ComputeSharp.D2D1.WinUI.SourceGenerators.csproj" SetPlatform="Platform=AnyCPU" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
7778
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
7879
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
7980
</ItemGroup>

samples/ComputeSharp.SwapChain.D2D1.Uwp/Backend/PixelShaderEffect.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,23 @@ namespace ComputeSharp.SwapChain.D2D1.Backend;
1010
/// </summary>
1111
internal abstract partial class PixelShaderEffect : CanvasEffect
1212
{
13-
/// <summary>
14-
/// The current elapsed time.
15-
/// </summary>
16-
private TimeSpan elapsedTime;
17-
18-
/// <summary>
19-
/// The current screen width in raw pixels.
20-
/// </summary>
21-
private int screenWidth;
22-
23-
/// <summary>
24-
/// The current screen height in raw pixels.
25-
/// </summary>
26-
private int screenHeight;
27-
2813
/// <summary>
2914
/// Gets or sets the total elapsed time.
3015
/// </summary>
31-
public TimeSpan ElapsedTime
32-
{
33-
get => this.elapsedTime;
34-
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
35-
}
16+
[GeneratedCanvasEffectProperty]
17+
public partial TimeSpan ElapsedTime { get; set; }
3618

3719
/// <summary>
3820
/// Gets or sets the screen width in raw pixels.
3921
/// </summary>
40-
public int ScreenWidth
41-
{
42-
get => this.screenWidth;
43-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
44-
}
22+
[GeneratedCanvasEffectProperty]
23+
public partial int ScreenWidth { get; set; }
4524

4625
/// <summary>
4726
/// Gets or sets the screen height in raw pixels.
4827
/// </summary>
49-
public int ScreenHeight
50-
{
51-
get => this.screenHeight;
52-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
53-
}
28+
[GeneratedCanvasEffectProperty]
29+
public partial int ScreenHeight { get; set; }
5430

5531
/// <summary>
5632
/// An effect for an animated pixel shader.

samples/ComputeSharp.SwapChain.D2D1.Uwp/ComputeSharp.SwapChain.D2D1.Uwp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141

4242
<ItemGroup>
4343
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
44+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp.SourceGenerators\ComputeSharp.D2D1.Uwp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
4445
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
45-
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
4646
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
47+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
4748
</ItemGroup>
4849

4950
<!-- Shared projects for the D2D1 shaders -->

samples/ComputeSharp.SwapChain.UI/Shaders/PixelShaderEffect.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,23 @@ namespace ComputeSharp.SwapChain.Core.Shaders;
1414
/// </summary>
1515
public abstract partial class PixelShaderEffect : CanvasEffect
1616
{
17-
/// <summary>
18-
/// The current elapsed time.
19-
/// </summary>
20-
private TimeSpan elapsedTime;
21-
22-
/// <summary>
23-
/// The current screen width in raw pixels.
24-
/// </summary>
25-
private int screenWidth;
26-
27-
/// <summary>
28-
/// The current screen height in raw pixels.
29-
/// </summary>
30-
private int screenHeight;
31-
3217
/// <summary>
3318
/// Gets or sets the total elapsed time.
3419
/// </summary>
35-
public TimeSpan ElapsedTime
36-
{
37-
get => this.elapsedTime;
38-
set => SetPropertyAndInvalidateEffectGraph(ref this.elapsedTime, value);
39-
}
20+
[GeneratedCanvasEffectProperty]
21+
public partial TimeSpan ElapsedTime { get; set; }
4022

4123
/// <summary>
4224
/// Gets or sets the screen width in raw pixels.
4325
/// </summary>
44-
public int ScreenWidth
45-
{
46-
get => this.screenWidth;
47-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenWidth, value);
48-
}
26+
[GeneratedCanvasEffectProperty]
27+
public partial int ScreenWidth { get; set; }
4928

5029
/// <summary>
5130
/// Gets or sets the screen height in raw pixels.
5231
/// </summary>
53-
public int ScreenHeight
54-
{
55-
get => this.screenHeight;
56-
set => SetPropertyAndInvalidateEffectGraph(ref this.screenHeight, value);
57-
}
32+
[GeneratedCanvasEffectProperty]
33+
public partial int ScreenHeight { get; set; }
5834

5935
/// <summary>
6036
/// An effect for an animated pixel shader.

samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
<ItemGroup>
6161
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
62+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp.SourceGenerators\ComputeSharp.D2D1.Uwp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
6263
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
6364
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
6465
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />

samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
<ItemGroup>
7878
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
79+
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI.SourceGenerators\ComputeSharp.D2D1.WinUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
7980
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
8081
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
8182
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />

0 commit comments

Comments
 (0)