Merge pull request #653 from Sergio0694/dev/use-primary-constructors
Use primary constructors and collection expressions
このコミットが含まれているのは:
106ファイル変更
+531
-1028
検索条件に一致するファイルはありません
@@ -46,7 +46,7 @@
|
||||
This is used eg. to replace Unsafe.SizeOf<T>() calls with just sizeof(T). The warning is not necessary
|
||||
since in order to use these APIs the caller already has to be in an unsafe context.
|
||||
-->
|
||||
<NoWarn>$(NoWarn);CS8500;IDE0290;IDE0305;IDE0028;IDE0300;IDE0301;IDE0302</NoWarn>
|
||||
<NoWarn>$(NoWarn);CS8500</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Centralized location for all generated artifacts -->
|
||||
|
||||
@@ -11,28 +11,19 @@ namespace SixLabors.ImageSharp;
|
||||
/// <remarks>
|
||||
/// This is a more efficient version of the <see cref="Complex64"/> type.
|
||||
/// </remarks>
|
||||
internal readonly struct Complex64
|
||||
/// <param name="real">The real part in the complex number.</param>
|
||||
/// <param name="imaginary">The imaginary part in the complex number.</param>
|
||||
internal readonly struct Complex64(float real, float imaginary)
|
||||
{
|
||||
/// <summary>
|
||||
/// The real part of the complex number.
|
||||
/// </summary>
|
||||
public readonly float Real;
|
||||
public readonly float Real = real;
|
||||
|
||||
/// <summary>
|
||||
/// The imaginary part of the complex number.
|
||||
/// </summary>
|
||||
public readonly float Imaginary;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Complex64"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="real">The real part in the complex number.</param>
|
||||
/// <param name="imaginary">The imaginary part in the complex number.</param>
|
||||
public Complex64(float real, float imaginary)
|
||||
{
|
||||
this.Real = real;
|
||||
this.Imaginary = imaginary;
|
||||
}
|
||||
public readonly float Imaginary = imaginary;
|
||||
|
||||
/// <summary>
|
||||
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
|
||||
|
||||
+56
-62
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -58,7 +57,61 @@ public sealed partial class HlslBokehBlurProcessor
|
||||
/// <summary>
|
||||
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor"/> instances.
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = new();
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = [];
|
||||
|
||||
/// <summary>
|
||||
/// The kernel scales to adjust the component values in each kernel.
|
||||
/// </summary>
|
||||
private static readonly float[] KernelScales = [1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f];
|
||||
|
||||
/// <summary>
|
||||
/// The available bokeh blur kernel parameters.
|
||||
/// </summary>
|
||||
private static readonly Vector4[][] KernelComponents =
|
||||
[
|
||||
// 1 component
|
||||
[new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f)],
|
||||
|
||||
// 2 components
|
||||
[
|
||||
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
|
||||
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
|
||||
],
|
||||
|
||||
// 3 components
|
||||
[
|
||||
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
|
||||
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
|
||||
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
|
||||
],
|
||||
|
||||
// 4 components
|
||||
[
|
||||
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
|
||||
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
|
||||
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
|
||||
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
|
||||
],
|
||||
|
||||
// 5 components
|
||||
[
|
||||
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
|
||||
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
|
||||
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
|
||||
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
|
||||
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
|
||||
],
|
||||
|
||||
// 6 components
|
||||
[
|
||||
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
|
||||
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
|
||||
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
|
||||
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
|
||||
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
|
||||
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
|
||||
]
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Implementation"/> class.
|
||||
@@ -97,72 +150,13 @@ public sealed partial class HlslBokehBlurProcessor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kernel scales to adjust the component values in each kernel.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<float> KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available bokeh blur kernel parameters.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<Vector4[]> KernelComponents { get; } = new[]
|
||||
{
|
||||
// 1 component
|
||||
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
|
||||
|
||||
// 2 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
|
||||
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
|
||||
},
|
||||
|
||||
// 3 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
|
||||
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
|
||||
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
|
||||
},
|
||||
|
||||
// 4 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
|
||||
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
|
||||
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
|
||||
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
|
||||
},
|
||||
|
||||
// 5 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
|
||||
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
|
||||
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
|
||||
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
|
||||
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
|
||||
},
|
||||
|
||||
// 6 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
|
||||
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
|
||||
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
|
||||
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
|
||||
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
|
||||
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kernel parameters and scaling factor for the current count value in the current instance.
|
||||
/// </summary>
|
||||
private (Vector4[] Parameters, float Scale) GetParameters()
|
||||
{
|
||||
// Prepare the kernel components
|
||||
int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count));
|
||||
int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Length));
|
||||
|
||||
return (KernelComponents[index], KernelScales[index]);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,6 +5,8 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -56,7 +56,8 @@ internal abstract class PixelShaderEffect : CanvasEffect
|
||||
/// An effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
|
||||
public sealed class For<T> : PixelShaderEffect
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public sealed class For<T>(For<T>.Factory factory) : PixelShaderEffect
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
/// <summary>
|
||||
@@ -64,20 +65,6 @@ internal abstract class PixelShaderEffect : CanvasEffect
|
||||
/// </summary>
|
||||
private static readonly EffectNode<PixelShaderEffect<T>> Effect = new();
|
||||
|
||||
/// <summary>
|
||||
/// The <typeparamref name="T"/> factory to use.
|
||||
/// </summary>
|
||||
private readonly Factory factory;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public For(Factory factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void BuildEffectGraph(EffectGraph effectGraph)
|
||||
{
|
||||
@@ -87,7 +74,7 @@ internal abstract class PixelShaderEffect : CanvasEffect
|
||||
/// <inheritdoc/>
|
||||
protected override void ConfigureEffectGraph(EffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -56,7 +56,8 @@ public abstract class PixelShaderEffect : CanvasEffect
|
||||
/// An effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
|
||||
public sealed class For<T> : PixelShaderEffect
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public sealed class For<T>(For<T>.Factory factory) : PixelShaderEffect
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
/// <summary>
|
||||
@@ -64,20 +65,6 @@ public abstract class PixelShaderEffect : CanvasEffect
|
||||
/// </summary>
|
||||
private static readonly EffectNode<PixelShaderEffect<T>> Effect = new();
|
||||
|
||||
/// <summary>
|
||||
/// The <typeparamref name="T"/> factory to use.
|
||||
/// </summary>
|
||||
private readonly Factory factory;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public For(Factory factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void BuildEffectGraph(EffectGraph effectGraph)
|
||||
{
|
||||
@@ -87,7 +74,7 @@ public abstract class PixelShaderEffect : CanvasEffect
|
||||
/// <inheritdoc/>
|
||||
protected override void ConfigureEffectGraph(EffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.GetNode(Effect).ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -40,13 +40,13 @@ public sealed class D2D1ContouredLayersEffect : PixelShaderEffect
|
||||
|
||||
// Create the resource texture manager to use in the shader
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
|
||||
extents: [(uint)readBackTexture.Height, (uint)readBackTexture.Width],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipLinear,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
|
||||
extendModes: [D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror],
|
||||
data: new ReadOnlySpan<byte>(dataBuffer, bufferSize),
|
||||
strides: stackalloc uint[] { (uint)strideInBytes });
|
||||
strides: [(uint)strideInBytes]);
|
||||
|
||||
// Create the new pixel shader effect
|
||||
PixelShaderEffect<ContouredLayers> pixelShaderEffect = new() { ResourceTextureManagers = { [0] = resourceTextureManager } };
|
||||
|
||||
@@ -7,35 +7,28 @@ namespace ComputeSharp.SwapChain.Core.ViewModels;
|
||||
/// <summary>
|
||||
/// A viewmodel for a compute shader.
|
||||
/// </summary>
|
||||
public sealed partial class ShaderRunnerViewModel : ObservableObject
|
||||
/// <param name="shaderType">The name of the shader type to execute.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
|
||||
public sealed partial class ShaderRunnerViewModel(
|
||||
string shaderType,
|
||||
IShaderRunner shaderRunner,
|
||||
PixelShaderEffect pixelShaderEffect) : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderRunnerViewModel"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="shaderType">The name of the shader type to execute.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
|
||||
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect)
|
||||
{
|
||||
ShaderType = shaderType;
|
||||
ShaderRunner = shaderRunner;
|
||||
PixelShaderEffect = pixelShaderEffect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the shader type to execute.
|
||||
/// </summary>
|
||||
public string ShaderType { get; }
|
||||
public string ShaderType => shaderType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IShaderRunner"/> instance to execute.
|
||||
/// </summary>
|
||||
public IShaderRunner ShaderRunner { get; }
|
||||
public IShaderRunner ShaderRunner => shaderRunner;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PixelShaderEffect"/> instance to execute.
|
||||
/// </summary>
|
||||
public PixelShaderEffect PixelShaderEffect { get; }
|
||||
public PixelShaderEffect PixelShaderEffect => pixelShaderEffect;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the current shader is selected.
|
||||
|
||||
@@ -16,7 +16,7 @@ public sealed partial class MainWindow : Window
|
||||
/// <summary>
|
||||
/// The mapping of currently alive shader panels.
|
||||
/// </summary>
|
||||
private readonly ConditionalWeakTable<AnimatedComputeShaderPanel, object?> shaderPanels = new();
|
||||
private readonly ConditionalWeakTable<AnimatedComputeShaderPanel, object?> shaderPanels = [];
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
|
||||
@@ -8,13 +8,9 @@ namespace ComputeSharp.SwapChain.Backend;
|
||||
/// <summary>
|
||||
/// A class representing a simple Win32 application.
|
||||
/// </summary>
|
||||
internal sealed unsafe class Win32Application
|
||||
/// <param name="shaderCallback">The function pointer used to run a shader on a target texture.</param>
|
||||
internal sealed unsafe class Win32Application(delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback)
|
||||
{
|
||||
/// <summary>
|
||||
/// The function pointer used to run a shader on a target texture.
|
||||
/// </summary>
|
||||
private readonly delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
|
||||
/// </summary>
|
||||
@@ -75,15 +71,6 @@ internal sealed unsafe class Win32Application
|
||||
/// </summary>
|
||||
private volatile bool isResizePending;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Win32Application"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderCallback">The function pointer used to run a shader on a target texture.</param>
|
||||
public Win32Application(delegate*<IReadWriteNormalizedTexture2D<float4>, TimeSpan, void> shaderCallback)
|
||||
{
|
||||
this.shaderCallback = shaderCallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the current application.
|
||||
/// </summary>
|
||||
@@ -241,7 +228,7 @@ internal sealed unsafe class Win32Application
|
||||
}
|
||||
|
||||
// Generate the new frame by invoking the callback
|
||||
this.shaderCallback(this.texture!, time);
|
||||
shaderCallback(this.texture!, time);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ public sealed class MissingComputeShaderDescriptorOnComputeShaderCodeFixer : Mis
|
||||
/// <summary>
|
||||
/// The set of type names for all attributes that can be over shader types.
|
||||
/// </summary>
|
||||
private static readonly string[] D2DAttributeTypeNames = new[]
|
||||
{
|
||||
private static readonly string[] D2DAttributeTypeNames =
|
||||
[
|
||||
"ComputeSharp.EmbeddedBytecodeAttribute",
|
||||
"ComputeSharp.GroupSharedAttribute"
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MissingAttributeCodeFixer"/> instance with the specified parameters.
|
||||
|
||||
@@ -184,22 +184,9 @@ public abstract class MissingAttributeCodeFixer : CodeFixProvider
|
||||
/// <summary>
|
||||
/// A custom <see cref="FixAllProvider"/> with the logic from <see cref="MissingAttributeCodeFixer"/>.
|
||||
/// </summary>
|
||||
private sealed class FixAllProvider : DocumentBasedFixAllProvider
|
||||
/// <param name="codeFixer">The owning <see cref="MissingAttributeCodeFixer"/> instance.</param>
|
||||
private sealed class FixAllProvider(MissingAttributeCodeFixer codeFixer) : DocumentBasedFixAllProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="MissingAttributeCodeFixer"/> instance.
|
||||
/// </summary>
|
||||
private readonly MissingAttributeCodeFixer codeFixer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="FixAllProvider"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="codeFixer">The owning <see cref="MissingAttributeCodeFixer"/> instance.</param>
|
||||
public FixAllProvider(MissingAttributeCodeFixer codeFixer)
|
||||
{
|
||||
this.codeFixer = codeFixer;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<Document?> FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
|
||||
{
|
||||
@@ -220,7 +207,7 @@ public abstract class MissingAttributeCodeFixer : CodeFixProvider
|
||||
}
|
||||
|
||||
// Get the syntax node with the updated declaration
|
||||
SyntaxNode updatedStructDeclaration = await this.codeFixer.AddMissingAttribute(
|
||||
SyntaxNode updatedStructDeclaration = await codeFixer.AddMissingAttribute(
|
||||
document,
|
||||
structDeclaration,
|
||||
fixAllContext.CancellationToken);
|
||||
|
||||
@@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
#pragma warning disable CS0618, IDE0300
|
||||
|
||||
namespace ComputeSharp.Core.SourceGenerators;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,23 +6,15 @@ namespace ComputeSharp.Core.Intrinsics.Attributes;
|
||||
/// <summary>
|
||||
/// An attribute indicating the native member name of a given HLSL intrinsic.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the HLSL intrinsic.</param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
[Conditional("SOURCE_GENERATOR")]
|
||||
internal sealed class HlslIntrinsicNameAttribute : Attribute
|
||||
internal sealed class HlslIntrinsicNameAttribute(string name) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="HlslIntrinsicNameAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the HLSL intrinsic.</param>
|
||||
public HlslIntrinsicNameAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the HLSL intrinsic.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
public string Name { get; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not matching parameters is also required to extract the name of this intrinsic.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma warning disable CS0660, CS0661
|
||||
#pragma warning disable CS0660, CS0661, IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma warning disable CS0660, CS0661
|
||||
#pragma warning disable CS0660, CS0661, IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Numerics;
|
||||
|
||||
#pragma warning disable CS0660, CS0661
|
||||
#pragma warning disable CS0660, CS0661, IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma warning disable CS0660, CS0661
|
||||
#pragma warning disable CS0660, CS0661, IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma warning disable CS0660, CS0661
|
||||
#pragma warning disable CS0660, CS0661, IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
|
||||
+3
-3
@@ -16,8 +16,8 @@ public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : Missing
|
||||
/// <summary>
|
||||
/// The set of type names for all D2D attributes that can be over shader types.
|
||||
/// </summary>
|
||||
private static readonly string[] D2DAttributeTypeNames = new[]
|
||||
{
|
||||
private static readonly string[] D2DAttributeTypeNames =
|
||||
[
|
||||
"ComputeSharp.D2D1.D2DCompileOptionsAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectAuthorAttribute",
|
||||
"ComputeSharp.D2D1.D2DEffectCategoryAttribute",
|
||||
@@ -32,7 +32,7 @@ public sealed class MissingPixelShaderDescriptorOnPixelShaderCodeFixer : Missing
|
||||
"ComputeSharp.D2D1.D2DPixelOptionsAttribute",
|
||||
"ComputeSharp.D2D1.D2DRequiresScenePositionAttribute",
|
||||
"ComputeSharp.D2D1.D2DShaderProfileAttribute"
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MissingAttributeCodeFixer"/> instance with the specified parameters.
|
||||
|
||||
+2
-2
@@ -216,14 +216,14 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
EmbeddedBytecodeFailedWithWin32Exception,
|
||||
structDeclarationSymbol,
|
||||
new object[] { structDeclarationSymbol, win32Error.HResult, win32Error.Message });
|
||||
[structDeclarationSymbol, win32Error.HResult, win32Error.Message]);
|
||||
}
|
||||
else if (info is HlslBytecodeInfo.CompilerError fxcError)
|
||||
{
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
EmbeddedBytecodeFailedWithFxcCompilationException,
|
||||
structDeclarationSymbol,
|
||||
new object[] { structDeclarationSymbol, fxcError.Message });
|
||||
[structDeclarationSymbol, fxcError.Message]);
|
||||
}
|
||||
|
||||
if (diagnostic is not null)
|
||||
|
||||
@@ -140,14 +140,14 @@ partial class D2DPixelShaderSourceGenerator
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
D2DPixelShaderSourceCompilationFailedWithWin32Exception,
|
||||
methodSymbol,
|
||||
new object[] { methodSymbol, methodSymbol.ContainingType, win32Error.HResult, win32Error.Message });
|
||||
[methodSymbol, methodSymbol.ContainingType, win32Error.HResult, win32Error.Message]);
|
||||
}
|
||||
else if (info is HlslBytecodeInfo.CompilerError fxcError)
|
||||
{
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
D2DPixelShaderSourceCompilationFailedWithFxcCompilationException,
|
||||
methodSymbol,
|
||||
new object[] { methodSymbol, methodSymbol.ContainingType, fxcError.Message });
|
||||
[methodSymbol, methodSymbol.ContainingType, fxcError.Message]);
|
||||
}
|
||||
|
||||
if (diagnostic is not null)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
@@ -94,7 +93,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
|
||||
item.Hierarchy.WriteSyntax(
|
||||
state: item,
|
||||
writer: writer,
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
baseTypes: [],
|
||||
memberCallbacks: new IndentedTextWriter.Callback<D2D1PixelShaderSourceInfo>[] { Execute.WriteSyntax });
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{item.MethodName}.g.cs", writer.ToString());
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ internal unsafe struct ICanvasEffectFactoryNative
|
||||
private delegate* unmanaged[Stdcall]<IntPtr, ICanvasDevice*, ID2D1Effect*, float, IInspectable**, int> CreateWrapper;
|
||||
|
||||
/// <inheritdoc cref="Interface.CreateWrapper"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
private static int CreateWrapperFromAbi(IntPtr thisPtr, ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
{
|
||||
|
||||
@@ -142,7 +142,7 @@ internal unsafe struct ICanvasImageInterop
|
||||
private delegate* unmanaged[Stdcall]<IntPtr, ICanvasDevice*, ID2D1DeviceContext*, WIN2D_GET_D2D_IMAGE_FLAGS, float, float*, ID2D1Image**, int> GetD2DImage;
|
||||
|
||||
/// <inheritdoc cref="Interface.GetDevice"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
private static int GetDeviceFromAbi(IntPtr thisPtr, ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ internal unsafe struct ICanvasImageInterop
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Interface.GetDevice"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
private static int GetD2DImageFromAbi(
|
||||
IntPtr thisPtr,
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
|
||||
/// <remarks>
|
||||
/// When not empty (ie. when an effect graph has been built), this will always also include <see cref="canvasImage"/>.
|
||||
/// </remarks>
|
||||
private readonly Dictionary<object, ICanvasImage> transformNodes = new();
|
||||
private readonly Dictionary<object, ICanvasImage> transformNodes = [];
|
||||
|
||||
/// <summary>
|
||||
/// The current cached result for <see cref="GetCanvasImage"/>, if available.
|
||||
|
||||
+1
-1
@@ -244,7 +244,7 @@ partial class PixelShaderEffect<T>
|
||||
// Skip the array allocation if there are no resource texture descriptions
|
||||
if (descriptions.IsEmpty)
|
||||
{
|
||||
return ImmutableArray<int>.Empty;
|
||||
return [];
|
||||
}
|
||||
|
||||
int[] indices = new int[descriptions.Length];
|
||||
|
||||
@@ -213,7 +213,7 @@ partial class PixelShaderEffect<T>
|
||||
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return ImmutableArray<int>.Empty;
|
||||
return [];
|
||||
}
|
||||
|
||||
int[] indices = new int[inputCount];
|
||||
|
||||
@@ -24,20 +24,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="options">The compiler options to use to compile the shader.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class D2DCompileOptionsAttribute : Attribute
|
||||
public sealed class D2DCompileOptionsAttribute(D2D1CompileOptions options) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2DCompileOptionsAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="options">The compiler options to use to compile the shader.</param>
|
||||
public D2DCompileOptionsAttribute(D2D1CompileOptions options)
|
||||
{
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads in each thread group for the X axis
|
||||
/// </summary>
|
||||
public D2D1CompileOptions Options { get; }
|
||||
public D2D1CompileOptions Options { get; } = options;
|
||||
}
|
||||
@@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
/// <param name="value">The value for the author.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)]
|
||||
public sealed class D2DEffectAuthorAttribute : Attribute
|
||||
public sealed class D2DEffectAuthorAttribute(string value) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DEffectAuthorAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the author.</param>
|
||||
public D2DEffectAuthorAttribute(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the author value.
|
||||
/// </summary>
|
||||
public string Value { get; }
|
||||
public string Value { get; } = value;
|
||||
}
|
||||
@@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
/// <param name="value">The value for the category.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = false)]
|
||||
public sealed class D2DEffectCategoryAttribute : Attribute
|
||||
public sealed class D2DEffectCategoryAttribute(string value) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DEffectCategoryAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the category.</param>
|
||||
public D2DEffectCategoryAttribute(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category value.
|
||||
/// </summary>
|
||||
public string Value { get; }
|
||||
public string Value { get; } = value;
|
||||
}
|
||||
@@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
/// <param name="value">The value for the description.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DEffectDescriptionAttribute : Attribute
|
||||
public sealed class D2DEffectDescriptionAttribute(string value) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DEffectDescriptionAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the description.</param>
|
||||
public D2DEffectDescriptionAttribute(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description value.
|
||||
/// </summary>
|
||||
public string Value { get; }
|
||||
public string Value { get; } = value;
|
||||
}
|
||||
@@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
/// <param name="value">The value for the display name.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DEffectDisplayNameAttribute : Attribute
|
||||
public sealed class D2DEffectDisplayNameAttribute(string value) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DEffectDisplayNameAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the display name.</param>
|
||||
public D2DEffectDisplayNameAttribute(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name value.
|
||||
/// </summary>
|
||||
public string Value { get; }
|
||||
public string Value { get; } = value;
|
||||
}
|
||||
@@ -8,20 +8,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
|
||||
/// </remarks>
|
||||
/// <param name="value">The value for the effect id.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DEffectIdAttribute : Attribute
|
||||
public sealed class D2DEffectIdAttribute(string value) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DEffectIdAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the effect id.</param>
|
||||
public D2DEffectIdAttribute(string value)
|
||||
{
|
||||
Value = Guid.Parse(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the effect id value.
|
||||
/// </summary>
|
||||
public Guid Value { get; }
|
||||
public Guid Value { get; } = Guid.Parse(value);
|
||||
}
|
||||
@@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <para>This attribute directly maps to <c>#define D2D_INPUT<N>_COMPLEX</c>.</para>
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct2d/hlsl-helpers"/>.</para>
|
||||
/// </remarks>
|
||||
/// <param name="index">The index of the resource to declare as using complex sampling.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)]
|
||||
public sealed class D2DInputComplexAttribute : Attribute
|
||||
public sealed class D2DInputComplexAttribute(int index) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DInputComplexAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the resource to declare as using complex sampling.</param>
|
||||
public D2DInputComplexAttribute(int index)
|
||||
{
|
||||
Index = index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the resource declared as using complex sampling.
|
||||
/// </summary>
|
||||
public int Index { get; }
|
||||
public int Index { get; } = index;
|
||||
}
|
||||
@@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <para>This attribute directly maps to <c>#define D2D_INPUT_COUNT <N></c>.</para>
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct2d/hlsl-helpers"/>.</para>
|
||||
/// </remarks>
|
||||
/// <param name="count">The number of texture inputs for the shader.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DInputCountAttribute : Attribute
|
||||
public sealed class D2DInputCountAttribute(int count) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DInputCountAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of texture inputs for the shader.</param>
|
||||
public D2DInputCountAttribute(int count)
|
||||
{
|
||||
Count = count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of texture inputs for the shader.
|
||||
/// </summary>
|
||||
public int Count { get; }
|
||||
public int Count { get; } = count;
|
||||
}
|
||||
@@ -10,29 +10,20 @@ namespace ComputeSharp.D2D1;
|
||||
/// <para>This attribute exposes the options that can be set via <c>D2D1_INPUT_DESCRIPTION</c>.</para>
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/ns-d2d1effectauthor-d2d1_input_description"/>.</para>
|
||||
/// </remarks>
|
||||
/// <param name="index">The index of the resource to declare the description for.</param>
|
||||
/// <param name="filter">The type of filter to apply to the input texture.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)]
|
||||
public sealed class D2DInputDescriptionAttribute : Attribute
|
||||
public sealed class D2DInputDescriptionAttribute(int index, D2D1Filter filter) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DInputDescriptionAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the resource to declare the description for.</param>
|
||||
/// <param name="filter">The type of filter to apply to the input texture.</param>
|
||||
public D2DInputDescriptionAttribute(int index, D2D1Filter filter)
|
||||
{
|
||||
Index = index;
|
||||
Filter = filter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the resource to declare the description for.
|
||||
/// </summary>
|
||||
public int Index { get; }
|
||||
public int Index { get; } = index;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of filter to apply to the input texture.
|
||||
/// </summary>
|
||||
public D2D1Filter Filter { get; }
|
||||
public D2D1Filter Filter { get; } = filter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mip level to retrieve from the upstream transform, if specified.
|
||||
|
||||
@@ -10,20 +10,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <para>This attribute directly maps to <c>#define D2D_INPUT<N>_SIMPLE</c>.</para>
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/direct2d/hlsl-helpers"/>.</para>
|
||||
/// </remarks>
|
||||
/// <param name="index">The index of the resource to declare as using simple sampling.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)]
|
||||
public sealed class D2DInputSimpleAttribute : Attribute
|
||||
public sealed class D2DInputSimpleAttribute(int index) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DInputSimpleAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the resource to declare as using simple sampling.</param>
|
||||
public D2DInputSimpleAttribute(int index)
|
||||
{
|
||||
Index = index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the resource declared as using simple sampling.
|
||||
/// </summary>
|
||||
public int Index { get; }
|
||||
public int Index { get; } = index;
|
||||
}
|
||||
@@ -9,20 +9,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/ne-d2d1effectauthor-d2d1_pixel_options"/>.
|
||||
/// </remarks>
|
||||
/// <param name="options">The options to specify for the shader.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class D2DPixelOptionsAttribute : Attribute
|
||||
public sealed class D2DPixelOptionsAttribute(D2D1PixelOptions options) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DPixelOptionsAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="options">The options to specify for the shader.</param>
|
||||
public D2DPixelOptionsAttribute(D2D1PixelOptions options)
|
||||
{
|
||||
Options = options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the options to specify for the shader.
|
||||
/// </summary>
|
||||
public D2D1PixelOptions Options { get; }
|
||||
public D2D1PixelOptions Options { get; } = options;
|
||||
}
|
||||
@@ -32,20 +32,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// to further customize the shader profile to use when compiling the HLSL source, and the compile options to use.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The number of texture inputs for the shader.</param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class D2DPixelShaderSourceAttribute : Attribute
|
||||
public sealed class D2DPixelShaderSourceAttribute([StringSyntax("Hlsl")] string hlslSource) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DPixelShaderSourceAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The number of texture inputs for the shader.</param>
|
||||
public D2DPixelShaderSourceAttribute([StringSyntax("Hlsl")] string hlslSource)
|
||||
{
|
||||
HlslSource = hlslSource;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of texture inputs for the shader.
|
||||
/// </summary>
|
||||
public string HlslSource { get; }
|
||||
public string HlslSource { get; } = hlslSource;
|
||||
}
|
||||
@@ -9,20 +9,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// <remarks>
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1drawinfo-setresourcetexture"/>.</para>
|
||||
/// </remarks>
|
||||
/// <param name="index">The index of the annotated resource field.</param>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
|
||||
public sealed class D2DResourceTextureIndexAttribute : Attribute
|
||||
public sealed class D2DResourceTextureIndexAttribute(int index) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="D2DResourceTextureIndexAttribute"/> type with the specified arguments.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the annotated resource field.</param>
|
||||
public D2DResourceTextureIndexAttribute(int index)
|
||||
{
|
||||
Index = index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the annotated resource field.
|
||||
/// </summary>
|
||||
public int Index { get; }
|
||||
public int Index { get; } = index;
|
||||
}
|
||||
@@ -24,20 +24,12 @@ namespace ComputeSharp.D2D1;
|
||||
/// This attribute can also be added to a whole assembly, and will be used by default if not overridden by a shader type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="shaderProfile">The target shader profile to use to compile the shader.</param>
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class D2DShaderProfileAttribute : Attribute
|
||||
public sealed class D2DShaderProfileAttribute(D2D1ShaderProfile shaderProfile) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2DShaderProfileAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderProfile">The target shader profile to use to compile the shader.</param>
|
||||
public D2DShaderProfileAttribute(D2D1ShaderProfile shaderProfile)
|
||||
{
|
||||
ShaderProfile = shaderProfile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The shader profile used to compile the annotated D2D1 pixel shader.
|
||||
/// </summary>
|
||||
public D2D1ShaderProfile ShaderProfile { get; }
|
||||
public D2D1ShaderProfile ShaderProfile { get; } = shaderProfile;
|
||||
}
|
||||
@@ -10,7 +10,8 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Buffers;
|
||||
/// <summary>
|
||||
/// Represents a heap-based, array-backed output sink into which binary data can be written.
|
||||
/// </summary>
|
||||
internal ref struct ArrayPoolBinaryWriter
|
||||
/// <param name="capacity">The initial capacity of the writer object.</param>
|
||||
internal ref struct ArrayPoolBinaryWriter(int capacity)
|
||||
{
|
||||
/// <summary>
|
||||
/// The default buffer size to use to expand empty arrays.
|
||||
@@ -20,21 +21,12 @@ internal ref struct ArrayPoolBinaryWriter
|
||||
/// <summary>
|
||||
/// The underlying <see cref="byte"/> array.
|
||||
/// </summary>
|
||||
private byte[]? array;
|
||||
private byte[]? array = ArrayPool<byte>.Shared.Rent(capacity);
|
||||
|
||||
/// <summary>
|
||||
/// The starting offset within <see cref="array"/>.
|
||||
/// </summary>
|
||||
private int index;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArrayPoolBinaryWriter"/> type.
|
||||
/// </summary>
|
||||
public ArrayPoolBinaryWriter(int capacity)
|
||||
{
|
||||
this.array = ArrayPool<byte>.Shared.Rent(capacity);
|
||||
this.index = 0;
|
||||
}
|
||||
private int index = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data written to the underlying buffer so far, as a <see cref="ReadOnlySpan{T}"/>.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -140,8 +140,8 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
ReadOnlySpan<byte>.Empty,
|
||||
ReadOnlySpan<uint>.Empty)
|
||||
[],
|
||||
[])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
ReadOnlySpan<byte>.Empty,
|
||||
ReadOnlySpan<uint>.Empty)
|
||||
[],
|
||||
[])
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -8,36 +8,17 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Helpers;
|
||||
/// <summary>
|
||||
/// A 64-bit version of the <see cref="Point"/> type.
|
||||
/// </summary>
|
||||
internal readonly struct Point64
|
||||
/// <param name="x">The horizontal coordinate of the point.</param>
|
||||
/// <param name="y">The vertical coordinate of the point.</param>
|
||||
internal readonly struct Point64(long x, long y)
|
||||
{
|
||||
/// <summary>
|
||||
/// The left coordinate of the current point.
|
||||
/// </summary>
|
||||
private readonly long x;
|
||||
|
||||
/// <summary>
|
||||
/// The top coordinate of the current point.
|
||||
/// </summary>
|
||||
private readonly long y;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Point64"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal coordinate of the point.</param>
|
||||
/// <param name="y">The vertical coordinate of the point.</param>
|
||||
public Point64(long x, long y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal coordinate of the current point.
|
||||
/// </summary>
|
||||
public readonly long X
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => this.x;
|
||||
get => x;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,7 +27,7 @@ internal readonly struct Point64
|
||||
public readonly long Y
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => this.y;
|
||||
get => y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,7 +58,7 @@ internal readonly struct Point64
|
||||
// [ M21, M22 ]
|
||||
// [ x, y] [ M31, M32 ] = [ x * M11 + y * M21 + M31, x * M12 + y * M22 + m32]
|
||||
return (
|
||||
Math.Round(((double)this.x * matrix.M11) + ((double)this.y * matrix.M21) + matrix.M31),
|
||||
Math.Round(((double)this.x * matrix.M12) + ((double)this.y * matrix.M22) + matrix.M32));
|
||||
Math.Round(((double)x * matrix.M11) + ((double)y * matrix.M21) + matrix.M31),
|
||||
Math.Round(((double)x * matrix.M12) + ((double)y * matrix.M22) + matrix.M32));
|
||||
}
|
||||
}
|
||||
@@ -7,42 +7,21 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Helpers;
|
||||
/// <summary>
|
||||
/// A 64-bit version of the <see cref="Rectangle"/> type.
|
||||
/// </summary>
|
||||
internal struct Rectangle64
|
||||
/// <param name="x">The left coordinate of the rectangle.</param>
|
||||
/// <param name="y">The top coordinate of the rectangle.</param>
|
||||
/// <param name="width">The width of the rectangle.</param>
|
||||
/// <param name="height">The height of the rectangle.</param>
|
||||
internal struct Rectangle64(long x, long y, long width, long height)
|
||||
{
|
||||
/// <summary>
|
||||
/// The left coordinate of the current rectangle.
|
||||
/// </summary>
|
||||
private long x;
|
||||
private long x = x;
|
||||
|
||||
/// <summary>
|
||||
/// The top coordinate of the current rectangle.
|
||||
/// </summary>
|
||||
private long y;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the current rectangle.
|
||||
/// </summary>
|
||||
private long width;
|
||||
|
||||
/// <summary>
|
||||
/// The height of the current rectangle.
|
||||
/// </summary>
|
||||
private long height;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Rectangle64"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The left coordinate of the rectangle.</param>
|
||||
/// <param name="y">The top coordinate of the rectangle.</param>
|
||||
/// <param name="width">The width of the rectangle.</param>
|
||||
/// <param name="height">The height of the rectangle.</param>
|
||||
public Rectangle64(long x, long y, long width, long height)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
private long y = y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left coordinate of the current rectangle.
|
||||
@@ -68,7 +47,7 @@ internal struct Rectangle64
|
||||
public readonly long Right
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => this.x + this.width;
|
||||
get => this.x + width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,7 +56,7 @@ internal struct Rectangle64
|
||||
public readonly long Bottom
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => this.y + this.height;
|
||||
get => this.y + height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,8 +81,9 @@ internal struct Rectangle64
|
||||
|
||||
this.x = left;
|
||||
this.y = top;
|
||||
this.width = right - left;
|
||||
this.height = bottom - top;
|
||||
|
||||
width = right - left;
|
||||
height = bottom - top;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -119,8 +99,9 @@ internal struct Rectangle64
|
||||
|
||||
this.x = left;
|
||||
this.y = top;
|
||||
this.width = Math.Max(right - left, 0);
|
||||
this.height = Math.Max(bottom - top, 0);
|
||||
|
||||
width = Math.Max(right - left, 0);
|
||||
height = Math.Max(bottom - top, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,8 +115,9 @@ internal struct Rectangle64
|
||||
{
|
||||
this.x -= left;
|
||||
this.y -= top;
|
||||
this.width += left + right;
|
||||
this.height += top + bottom;
|
||||
|
||||
width += left + right;
|
||||
height += top + bottom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,7 +128,7 @@ internal struct Rectangle64
|
||||
{
|
||||
Intersect(new Rectangle64(int.MinValue / 2, int.MinValue / 2, int.MaxValue, int.MaxValue));
|
||||
|
||||
return new((int)this.x, (int)this.y, (int)this.width, (int)this.height);
|
||||
return new((int)this.x, (int)this.y, (int)width, (int)height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,27 +6,13 @@ namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
/// <summary>
|
||||
/// A type providing <see cref="SemanticModel"/> instances for nodes.
|
||||
/// </summary>
|
||||
internal sealed class SemanticModelProvider
|
||||
/// <param name="compilation">The source <see cref="Compilation"/> instance.</param>
|
||||
internal sealed class SemanticModelProvider(Compilation compilation)
|
||||
{
|
||||
/// <summary>
|
||||
/// The source <see cref="Compilation"/> instance.
|
||||
/// </summary>
|
||||
private readonly Compilation compilation;
|
||||
|
||||
/// <summary>
|
||||
/// The map of loaded <see cref="SemanticModel"/> instances.
|
||||
/// </summary>
|
||||
private readonly Dictionary<SyntaxTree, SemanticModel> semanticModelsMap;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SemanticModelProvider"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="compilation">The source <see cref="Compilation"/> instance.</param>
|
||||
public SemanticModelProvider(Compilation compilation)
|
||||
{
|
||||
this.compilation = compilation;
|
||||
this.semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
|
||||
}
|
||||
private readonly Dictionary<SyntaxTree, SemanticModel> semanticModelsMap = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="SemanticModel"/> instance with info on a given <see cref="SyntaxNode"/>.
|
||||
@@ -37,7 +23,7 @@ internal sealed class SemanticModelProvider
|
||||
{
|
||||
if (!this.semanticModelsMap.TryGetValue(syntaxNode.SyntaxTree, out SemanticModel semanticModel))
|
||||
{
|
||||
semanticModel = this.compilation.GetSemanticModel(syntaxNode.SyntaxTree);
|
||||
semanticModel = compilation.GetSemanticModel(syntaxNode.SyntaxTree);
|
||||
|
||||
this.semanticModelsMap.Add(syntaxNode.SyntaxTree, semanticModel);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
|
||||
#pragma warning disable IDE0055
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
/// <summary>
|
||||
@@ -11,7 +13,7 @@ internal static class SyntaxFormattingHelper
|
||||
/// A mapping of precomputed literals for all <see cref="byte"/> values.
|
||||
/// </summary>
|
||||
private static readonly string[] FormattedBytes =
|
||||
{
|
||||
[
|
||||
"0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x0A", "0x0B", "0x0C", "0x0D", "0x0E", "0x0F",
|
||||
"0x10", "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18", "0x19", "0x1A", "0x1B", "0x1C", "0x1D", "0x1E", "0x1F",
|
||||
"0x20", "0x21", "0x22", "0x23", "0x24", "0x25", "0x26", "0x27", "0x28", "0x29", "0x2A", "0x2B", "0x2C", "0x2D", "0x2E", "0x2F",
|
||||
@@ -28,7 +30,7 @@ internal static class SyntaxFormattingHelper
|
||||
"0xD0", "0xD1", "0xD2", "0xD3", "0xD4", "0xD5", "0xD6", "0xD7", "0xD8", "0xD9", "0xDA", "0xDB", "0xDC", "0xDD", "0xDE", "0xDF",
|
||||
"0xE0", "0xE1", "0xE2", "0xE3", "0xE4", "0xE5", "0xE6", "0xE7", "0xE8", "0xE9", "0xEA", "0xEB", "0xEC", "0xED", "0xEE", "0xEF",
|
||||
"0xF0", "0xF1", "0xF2", "0xF3", "0xF4", "0xF5", "0xF6", "0xF7", "0xF8", "0xF9", "0xFA", "0xFB", "0xFC", "0xFD", "0xFE", "0xFF"
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Gets an expression representing a single byte.
|
||||
|
||||
@@ -166,7 +166,7 @@ internal static partial class HlslKnownMethods
|
||||
{
|
||||
ILookup<string, MethodInfo> methodsLookup = typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static).ToLookup(static method => method.Name);
|
||||
|
||||
Dictionary<string, string> knownMethods = new();
|
||||
Dictionary<string, string> knownMethods = [];
|
||||
|
||||
// Go through the previously discovered methods to find the ones requiring parameters mapping
|
||||
foreach (KeyValuePair<string, string> pair in KnownMethods)
|
||||
|
||||
@@ -21,7 +21,7 @@ internal static partial class HlslKnownOperators
|
||||
/// </summary>
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownOperatorsMap()
|
||||
{
|
||||
Dictionary<string, string> knownOperators = new();
|
||||
Dictionary<string, string> knownOperators = [];
|
||||
|
||||
// Programmatically load mappings for the intrinsic operators on each HLSL primitive type
|
||||
foreach ((Type Type, MethodInfo Operator, string IntrinsicName, bool RequiresParametersMatching) item in
|
||||
|
||||
@@ -24,7 +24,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
/// <summary>
|
||||
/// An array with the <c>'.'</c> and <c>'E'</c> characters.
|
||||
/// </summary>
|
||||
private static readonly char[] FloatLiteralSpecialCharacters = { '.', 'E' };
|
||||
private static readonly char[] FloatLiteralSpecialCharacters = ['.', 'E'];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="HlslSourceRewriter"/> instance with the specified parameters.
|
||||
|
||||
@@ -87,8 +87,8 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
this.shaderType = shaderType;
|
||||
this.staticMethods = staticMethods;
|
||||
this.instanceMethods = instanceMethods;
|
||||
this.localFunctions = new();
|
||||
this.implicitVariables = new();
|
||||
this.localFunctions = [];
|
||||
this.implicitVariables = [];
|
||||
this.isEntryPoint = isEntryPoint;
|
||||
}
|
||||
|
||||
@@ -112,8 +112,8 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
{
|
||||
this.staticMethods = staticMethods;
|
||||
this.instanceMethods = instanceMethods;
|
||||
this.implicitVariables = new();
|
||||
this.localFunctions = new();
|
||||
this.implicitVariables = [];
|
||||
this.localFunctions = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,7 +150,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray());
|
||||
|
||||
// Add the tracked implicit declarations (at the start of the body)
|
||||
updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray());
|
||||
updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
@@ -184,7 +184,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
{
|
||||
BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray());
|
||||
|
||||
updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray());
|
||||
updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
|
||||
@@ -19,24 +19,16 @@ namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that processes C# static field to convert to HLSL static fields (possibly constant).
|
||||
/// </summary>
|
||||
internal sealed partial class StaticFieldRewriter : HlslSourceRewriter
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the target syntax tree.</param>
|
||||
/// <param name="discoveredTypes">The set of discovered custom types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
internal sealed partial class StaticFieldRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics) : HlslSourceRewriter(semanticModel, discoveredTypes, constantDefinitions, diagnostics)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="StaticFieldRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the target syntax tree.</param>
|
||||
/// <param name="discoveredTypes">The set of discovered custom types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
public StaticFieldRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public ExpressionSyntax? Visit(VariableDeclaratorSyntax? node)
|
||||
{
|
||||
|
||||
@@ -148,17 +148,18 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// <summary>
|
||||
/// An entry to use in <see cref="DynamicCache{TKey, TValue}"/>.
|
||||
/// </summary>
|
||||
private sealed class Entry
|
||||
/// <param name="key">The key to use for the entry.</param>
|
||||
private sealed class Entry(TKey key)
|
||||
{
|
||||
/// <summary>
|
||||
/// A weak reference to the actual entry instance.
|
||||
/// </summary>
|
||||
private readonly WeakReference<TKey> reference;
|
||||
private readonly WeakReference<TKey> reference = new(key);
|
||||
|
||||
/// <summary>
|
||||
/// The hashcode of the target key (so it's available even after the key is gone).
|
||||
/// </summary>
|
||||
private readonly int hashCode;
|
||||
private readonly int hashCode = EqualityComparer<TKey>.Default.GetHashCode(key);
|
||||
|
||||
/// <summary>
|
||||
/// The last key matched from <see cref="Equals(object?)"/>, if available.
|
||||
@@ -170,16 +171,6 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// </summary>
|
||||
private bool isPerformingLookup;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Entry"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="key">The key to use for the entry.</param>
|
||||
public Entry(TKey key)
|
||||
{
|
||||
this.reference = new WeakReference<TKey>(key);
|
||||
this.hashCode = EqualityComparer<TKey>.Default.GetHashCode(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the current entry is alive.
|
||||
/// </summary>
|
||||
@@ -265,33 +256,19 @@ internal sealed class DynamicCache<TKey, TValue>
|
||||
/// <summary>
|
||||
/// An object reponsible for removing dead <see cref="Entry"/> instance from the table.
|
||||
/// </summary>
|
||||
private sealed class EntryRemover
|
||||
/// <remarks>
|
||||
/// Creates a new <see cref="EntryRemover"/> instance with the specified parameters.
|
||||
/// </remarks>
|
||||
/// <param name="map"><inheritdoc cref="DynamicCache{TKey, TValue}.map" path="/node()"/></param>
|
||||
/// <param name="entry">The target <see cref="Entry"/> instance to remove from <see cref="map"/>.</param>
|
||||
private sealed class EntryRemover(ConcurrentDictionary<Entry, TValue> map, Entry entry)
|
||||
{
|
||||
/// <inheritdoc cref="DynamicCache{TKey, TValue}.map"/>
|
||||
private readonly ConcurrentDictionary<Entry, TValue> map;
|
||||
|
||||
/// <summary>
|
||||
/// The target <see cref="Entry"/> instance to remove from <see cref="map"/>.
|
||||
/// </summary>
|
||||
private readonly Entry entry;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EntryRemover"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="map"><inheritdoc cref="DynamicCache{TKey, TValue}.map" path="/node()"/></param>
|
||||
/// <param name="entry"><inheritdoc cref="entry" path="/node()"/></param>
|
||||
public EntryRemover(ConcurrentDictionary<Entry, TValue> map, Entry entry)
|
||||
{
|
||||
this.map = map;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes <see cref="entry"/> from <see cref="map"/> when the current instance is finalized.
|
||||
/// Removes the target entry from the map when the current instance is finalized.
|
||||
/// </summary>
|
||||
~EntryRemover()
|
||||
{
|
||||
_ = this.map.TryRemove(this.entry, out _);
|
||||
_ = map.TryRemove(entry, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,22 +34,14 @@ internal static class EquatableArray
|
||||
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values in the array.</typeparam>
|
||||
internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
|
||||
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
|
||||
internal readonly struct EquatableArray<T>(ImmutableArray<T> array) : IEquatable<EquatableArray<T>>, IEnumerable<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The underlying <typeparamref name="T"/> array.
|
||||
/// </summary>
|
||||
private readonly T[]? array;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="EquatableArray{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
|
||||
public EquatableArray(ImmutableArray<T> array)
|
||||
{
|
||||
this.array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
|
||||
}
|
||||
private readonly T[]? array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to an item at a specified position within the array.
|
||||
@@ -170,7 +162,7 @@ internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnu
|
||||
/// <returns>The newly instantiated array.</returns>
|
||||
public T[] ToArray()
|
||||
{
|
||||
return AsImmutableArray().ToArray();
|
||||
return [.. AsImmutableArray()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
@@ -64,7 +63,7 @@ internal struct ImmutableHashSetBuilder<T> : IDisposable
|
||||
/// <inheritdoc cref="ImmutableArray{T}.Builder.ToImmutable"/>
|
||||
public readonly ImmutableArray<T> ToImmutable()
|
||||
{
|
||||
T[] array = this.set!.ToArray();
|
||||
T[] array = [.. this.set!];
|
||||
|
||||
return Unsafe.As<T[], ImmutableArray<T>>(ref array);
|
||||
}
|
||||
@@ -72,7 +71,7 @@ internal struct ImmutableHashSetBuilder<T> : IDisposable
|
||||
/// <inheritdoc cref="ImmutableArray{T}.Builder.ToArray"/>
|
||||
public readonly T[] ToArray()
|
||||
{
|
||||
return this.set!.ToArray();
|
||||
return [.. this.set!];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -8,6 +8,8 @@ using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
|
||||
/// <summary>
|
||||
@@ -351,21 +353,13 @@ internal sealed class IndentedTextWriter : IDisposable
|
||||
/// <summary>
|
||||
/// Represents an indented block that needs to be closed.
|
||||
/// </summary>
|
||||
public struct Block : IDisposable
|
||||
/// <param name="writer">The input <see cref="IndentedTextWriter"/> instance to wrap.</param>
|
||||
public struct Block(IndentedTextWriter writer) : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IndentedTextWriter"/> instance to write to.
|
||||
/// </summary>
|
||||
private IndentedTextWriter? writer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Block"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="writer">The input <see cref="IndentedTextWriter"/> instance to wrap.</param>
|
||||
public Block(IndentedTextWriter writer)
|
||||
{
|
||||
this.writer = writer;
|
||||
}
|
||||
private IndentedTextWriter? writer = writer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
|
||||
@@ -37,19 +37,19 @@ namespace ComputeSharp.SourceGeneration.Helpers;
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of objects to pool.</typeparam>
|
||||
internal sealed class ObjectPool<T>
|
||||
/// <param name="factory">The input factory to produce <typeparamref name="T"/> items.</param>
|
||||
/// <remarks>
|
||||
/// The factory is stored for the lifetime of the pool. We will call this only when pool needs to
|
||||
/// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()".
|
||||
/// </remarks>
|
||||
/// <param name="size">The pool size to use.</param>
|
||||
internal sealed class ObjectPool<T>(Func<T> factory, int size)
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// The factory is stored for the lifetime of the pool. We will call this only when pool needs to
|
||||
/// expand. compared to "new T()", Func gives more flexibility to implementers and faster than "new T()".
|
||||
/// </summary>
|
||||
private readonly Func<T> factory;
|
||||
|
||||
/// <summary>
|
||||
/// The array of cached items.
|
||||
/// </summary>
|
||||
private readonly Element[] items;
|
||||
private readonly Element[] items = new Element[size - 1];
|
||||
|
||||
/// <summary>
|
||||
/// Storage for the pool objects. The first item is stored in a dedicated field
|
||||
@@ -66,17 +66,6 @@ internal sealed class ObjectPool<T>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ObjectPool{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="factory">The input factory to produce <typeparamref name="T"/> items.</param>
|
||||
/// <param name="size">The pool size to use.</param>
|
||||
public ObjectPool(Func<T> factory, int size)
|
||||
{
|
||||
this.factory = factory;
|
||||
this.items = new Element[size - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces a <typeparamref name="T"/> instance.
|
||||
/// </summary>
|
||||
@@ -131,7 +120,7 @@ internal sealed class ObjectPool<T>
|
||||
}
|
||||
}
|
||||
|
||||
return this.factory();
|
||||
return factory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -143,7 +143,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
|
||||
/// <returns>A <see cref="CompilationUnitSyntax"/> instance for the current hierarchy.</returns>
|
||||
public CompilationUnitSyntax GetSyntax(params MemberDeclarationSyntax[] memberDeclarations)
|
||||
{
|
||||
return GetSyntax(memberDeclarations, Array.Empty<MemberDeclarationSyntax>());
|
||||
return GetSyntax(memberDeclarations, []);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -90,14 +90,14 @@ partial class ComputeShaderDescriptorGenerator
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
EmbeddedBytecodeFailedWithWin32Exception,
|
||||
structDeclarationSymbol,
|
||||
new object[] { structDeclarationSymbol, win32Error.HResult, win32Error.Message });
|
||||
[structDeclarationSymbol, win32Error.HResult, win32Error.Message]);
|
||||
}
|
||||
else if (info is HlslBytecodeInfo.CompilerError dxcError)
|
||||
{
|
||||
diagnostic = DiagnosticInfo.Create(
|
||||
EmbeddedBytecodeFailedWithDxcCompilationException,
|
||||
structDeclarationSymbol,
|
||||
new object[] { structDeclarationSymbol, dxcError.Message });
|
||||
[structDeclarationSymbol, dxcError.Message]);
|
||||
}
|
||||
|
||||
if (diagnostic is not null)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Dxc;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -121,7 +121,7 @@ internal sealed unsafe class DxcShaderCompiler
|
||||
pEntryPoint: "Execute",
|
||||
pTargetProfile: "cs_6_0",
|
||||
pArguments: arguments.AsSpan(0, 3),
|
||||
pDefines: ReadOnlySpan<DxcDefine>.Empty,
|
||||
pDefines: [],
|
||||
pIncludeHandler: this.dxcIncludeHandler.Get(),
|
||||
ppResult: dxcOperationResult.GetAddressOf());
|
||||
|
||||
|
||||
@@ -9,21 +9,13 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that does postprocessing fixups on the shader main method.
|
||||
/// </summary>
|
||||
internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <param name="shaderSourceRewriter">The <see cref="SourceGeneration.SyntaxRewriters.ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
internal abstract class ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter) : CSharpSyntaxRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Compute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderSourceRewriter">The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter)
|
||||
{
|
||||
ShaderSourceRewriter = shaderSourceRewriter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ShaderSourceRewriter"/> instance used to process the input tree.
|
||||
/// </summary>
|
||||
protected ShaderSourceRewriter ShaderSourceRewriter { get; }
|
||||
protected ShaderSourceRewriter ShaderSourceRewriter => shaderSourceRewriter;
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public TNode? Visit<TNode>(TNode? node)
|
||||
@@ -60,17 +52,12 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Compute : ExecuteMethodRewriter
|
||||
/// <remarks>
|
||||
/// Creates a new <see cref="Compute"/> instance with the specified parameters.
|
||||
/// </remarks>
|
||||
/// <param name="shaderSourceRewriter">The <see cref="SourceGeneration.SyntaxRewriters.ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public sealed class Compute(ShaderSourceRewriter shaderSourceRewriter) : ExecuteMethodRewriter(shaderSourceRewriter)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Compute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderSourceRewriter">The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public Compute(ShaderSourceRewriter shaderSourceRewriter)
|
||||
: base(shaderSourceRewriter)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
@@ -115,17 +102,9 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Pixel : ExecuteMethodRewriter
|
||||
/// <param name="shaderSourceRewriter">The <see cref="SourceGeneration.SyntaxRewriters.ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public sealed class Pixel(ShaderSourceRewriter shaderSourceRewriter) : ExecuteMethodRewriter(shaderSourceRewriter)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Pixel"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderSourceRewriter">The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public Pixel(ShaderSourceRewriter shaderSourceRewriter)
|
||||
: base(shaderSourceRewriter)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitReturnStatement(ReturnStatementSyntax node)
|
||||
{
|
||||
|
||||
@@ -38,4 +38,5 @@ dotnet_diagnostic.IDE0060.severity = none
|
||||
dotnet_diagnostic.IDE0090.severity = none
|
||||
dotnet_diagnostic.IDE0160.severity = none
|
||||
dotnet_diagnostic.IDE0180.severity = none
|
||||
dotnet_diagnostic.IDE0290.severity = none
|
||||
dotnet_diagnostic.IDE1006.severity = none
|
||||
@@ -38,4 +38,5 @@ dotnet_diagnostic.IDE0060.severity = none
|
||||
dotnet_diagnostic.IDE0090.severity = none
|
||||
dotnet_diagnostic.IDE0160.severity = none
|
||||
dotnet_diagnostic.IDE0180.severity = none
|
||||
dotnet_diagnostic.IDE0290.severity = none
|
||||
dotnet_diagnostic.IDE1006.severity = none
|
||||
@@ -3,7 +3,7 @@ using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
#pragma warning disable CS0618, IDE0290
|
||||
|
||||
namespace ComputeSharp.WinUI.Extensions;
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,27 +10,13 @@ namespace ComputeSharp.Graphics.Commands.Interop;
|
||||
/// <summary>
|
||||
/// A type that acts as a pool to get new <see cref="ID3D12CommandList"/> instances wheen needed.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct ID3D12CommandListPool : IDisposable
|
||||
/// <param name="d3D12CommandListType">The command list type to use.</param>
|
||||
internal readonly unsafe struct ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The command list type being used by the current instance.
|
||||
/// </summary>
|
||||
private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType;
|
||||
|
||||
/// <summary>
|
||||
/// The queue of <see cref="D3D12CommandListBundle"/> items with the available command lists.
|
||||
/// </summary>
|
||||
private readonly Queue<D3D12CommandListBundle> d3D12CommandListBundleQueue;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ID3D12CommandListPool"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CommandListType">The command list type to use.</param>
|
||||
public ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType)
|
||||
{
|
||||
this.d3D12CommandListType = d3D12CommandListType;
|
||||
this.d3D12CommandListBundleQueue = new Queue<D3D12CommandListBundle>();
|
||||
}
|
||||
private readonly Queue<D3D12CommandListBundle> d3D12CommandListBundleQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// Rents a <see cref="ID3D12GraphicsCommandList"/> and <see cref="ID3D12CommandAllocator"/> pair.
|
||||
@@ -107,8 +93,8 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void CreateCommandListAndAllocator(ID3D12Device* d3D12Device, ID3D12PipelineState* d3D12PipelineState, out ID3D12GraphicsCommandList* d3D12CommandList, out ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
using ComPtr<ID3D12CommandAllocator> d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(this.d3D12CommandListType);
|
||||
using ComPtr<ID3D12GraphicsCommandList> d3D12CommandListComPtr = d3D12Device->CreateCommandList(this.d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState);
|
||||
using ComPtr<ID3D12CommandAllocator> d3D12CommandAllocatorComPtr = d3D12Device->CreateCommandAllocator(d3D12CommandListType);
|
||||
using ComPtr<ID3D12GraphicsCommandList> d3D12CommandListComPtr = d3D12Device->CreateCommandList(d3D12CommandListType, d3D12CommandAllocatorComPtr.Get(), d3D12PipelineState);
|
||||
|
||||
fixed (ID3D12GraphicsCommandList** d3D12CommandListPtr = &d3D12CommandList)
|
||||
fixed (ID3D12CommandAllocator** d3D12CommandAllocatorPtr = &d3D12CommandAllocator)
|
||||
@@ -121,27 +107,18 @@ internal readonly unsafe struct ID3D12CommandListPool : IDisposable
|
||||
/// <summary>
|
||||
/// A type representing a bundle of a cached command list and related allocator.
|
||||
/// </summary>
|
||||
private readonly struct D3D12CommandListBundle
|
||||
/// <param name="d3D12CommandList">The <see cref="ID3D12GraphicsCommandList"/> value to wrap.</param>
|
||||
/// <param name="d3D12CommandAllocator">The <see cref="ID3D12CommandAllocator"/> value to wrap.</param>
|
||||
private readonly struct D3D12CommandListBundle(ID3D12GraphicsCommandList* d3D12CommandList, ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly ID3D12GraphicsCommandList* D3D12CommandList;
|
||||
public readonly ID3D12GraphicsCommandList* D3D12CommandList = d3D12CommandList;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandAllocator"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly ID3D12CommandAllocator* D3D12CommandAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D3D12CommandListBundle"/> instance with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CommandList">The <see cref="ID3D12GraphicsCommandList"/> value to wrap.</param>
|
||||
/// <param name="d3D12CommandAllocator">The <see cref="ID3D12CommandAllocator"/> value to wrap.</param>
|
||||
public D3D12CommandListBundle(ID3D12GraphicsCommandList* d3D12CommandList, ID3D12CommandAllocator* d3D12CommandAllocator)
|
||||
{
|
||||
this.D3D12CommandList = d3D12CommandList;
|
||||
this.D3D12CommandAllocator = d3D12CommandAllocator;
|
||||
}
|
||||
public readonly ID3D12CommandAllocator* D3D12CommandAllocator = d3D12CommandAllocator;
|
||||
}
|
||||
}
|
||||
@@ -5,36 +5,26 @@ namespace ComputeSharp.Graphics.Commands.Interop;
|
||||
/// <summary>
|
||||
/// A type representing a bundle of reusable resource descriptor handles.
|
||||
/// </summary>
|
||||
internal readonly struct ID3D12ResourceDescriptorHandles
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
internal readonly struct ID3D12ResourceDescriptorHandles(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value for the current entry.
|
||||
/// </summary>
|
||||
public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
public readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle = d3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value for the current entry, non shader visible.
|
||||
/// </summary>
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ID3D12ResourceDescriptorHandles"/> instance with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandleNonShaderVisible">The non shader visible <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value to wrap.</param>
|
||||
public ID3D12ResourceDescriptorHandles(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandleNonShaderVisible)
|
||||
{
|
||||
this.D3D12CpuDescriptorHandle = d3D12CpuDescriptorHandle;
|
||||
this.D3D12GpuDescriptorHandle = d3D12GpuDescriptorHandle;
|
||||
this.D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
}
|
||||
public readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandleNonShaderVisible = d3D12CpuDescriptorHandleNonShaderVisible;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public sealed unsafe partial class GraphicsDevice : IReferenceTrackedObject
|
||||
IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0;
|
||||
|
||||
this.deviceRemovedReason = S.S_OK;
|
||||
this.cachedPipelineData = new List<PipelineData>();
|
||||
this.cachedPipelineData = [];
|
||||
|
||||
RegisterDeviceLostCallback(this, out this.deviceHandle, out this.deviceRemovedEvent, out this.deviceRemovedWaitHandle);
|
||||
}
|
||||
|
||||
@@ -19,21 +19,13 @@ partial class DeviceHelper
|
||||
/// <summary>
|
||||
/// A custom query type that iterates through devices matching a given predicate.
|
||||
/// </summary>
|
||||
public sealed unsafe class DeviceQuery : IEnumerable<GraphicsDevice>
|
||||
/// <param name="predicate">The input predicate to select devices to create.</param>
|
||||
public sealed unsafe class DeviceQuery(Predicate<GraphicsDeviceInfo>? predicate) : IEnumerable<GraphicsDevice>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Predicate{T}"/> instance to use to select devices to create.
|
||||
/// </summary>
|
||||
private readonly Predicate<GraphicsDeviceInfo>? predicate;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Enumerator"/> instance for the given predicate.
|
||||
/// </summary>
|
||||
/// <param name="predicate">The input predicate to select devices to create.</param>
|
||||
public DeviceQuery(Predicate<GraphicsDeviceInfo>? predicate)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
}
|
||||
private readonly Predicate<GraphicsDeviceInfo>? predicate = predicate;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator<GraphicsDevice> GetEnumerator()
|
||||
@@ -50,12 +42,13 @@ partial class DeviceHelper
|
||||
/// <summary>
|
||||
/// The enumerator type for a <see cref="DeviceQuery"/> instance.
|
||||
/// </summary>
|
||||
private sealed unsafe class Enumerator : ReferenceTrackedObject, IEnumerator<GraphicsDevice>
|
||||
/// <param name="predicate">The input predicate to select devices to create.</param>
|
||||
private sealed unsafe class Enumerator(Predicate<GraphicsDeviceInfo>? predicate) : ReferenceTrackedObject, IEnumerator<GraphicsDevice>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Predicate{T}"/> instance to use to select devices to create, if present.
|
||||
/// </summary>
|
||||
private readonly Predicate<GraphicsDeviceInfo>? predicate;
|
||||
private readonly Predicate<GraphicsDeviceInfo>? predicate = predicate;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDXGIFactory6"/> instance used to enumerate devices.
|
||||
@@ -82,15 +75,6 @@ partial class DeviceHelper
|
||||
/// </summary>
|
||||
private GraphicsDevice? graphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Enumerator"/> instance for the given predicate.
|
||||
/// </summary>
|
||||
/// <param name="predicate">The input predicate to select devices to create.</param>
|
||||
public Enumerator(Predicate<GraphicsDeviceInfo>? predicate)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GraphicsDevice Current => this.graphicsDevice!;
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ unsafe partial class DeviceHelper
|
||||
/// <summary>
|
||||
/// The local cache of <see cref="GraphicsDevice"/> instances that are currently usable.
|
||||
/// </summary>
|
||||
internal static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = new();
|
||||
internal static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = [];
|
||||
|
||||
/// <summary>
|
||||
/// The local map of <see cref="ID3D12InfoQueue"/> instances for the existing devices.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = new();
|
||||
private static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = [];
|
||||
|
||||
/// <summary>
|
||||
/// The cached default <see cref="GraphicsDevice"/> instance, if any.
|
||||
|
||||
@@ -2,9 +2,9 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace ComputeSharp.Interop;
|
||||
#pragma warning disable CS0618, IDE0290
|
||||
|
||||
#pragma warning disable CS0618
|
||||
namespace ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// An object acting as reference tracked for a given managed object.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable IDE0290
|
||||
|
||||
namespace ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,7 +10,7 @@ using ComputeSharp.Win32;
|
||||
using static ComputeSharp.Win32.D3D12_FEATURE;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
|
||||
#pragma warning disable CA1063
|
||||
#pragma warning disable CA1063, CA2213
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
@@ -147,21 +147,13 @@ public abstract unsafe partial class TransferBuffer<T> : IReferenceTrackedObject
|
||||
/// <summary>
|
||||
/// A <see cref="MemoryManager{T}"/> implementation wrapping a <see cref="TransferBuffer{T}"/> instance.
|
||||
/// </summary>
|
||||
private sealed class MemoryManager : MemoryManager<T>
|
||||
/// <param name="buffer">The <see cref="TransferBuffer{T}"/> in use.</param>
|
||||
private sealed class MemoryManager(TransferBuffer<T> buffer) : MemoryManager<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="TransferBuffer{T}"/> in use.
|
||||
/// </summary>
|
||||
private readonly TransferBuffer<T> buffer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MemoryManager"/> instance for a given buffer.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The <see cref="TransferBuffer{T}"/> in use.</param>
|
||||
public MemoryManager(TransferBuffer<T> buffer)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
}
|
||||
private readonly TransferBuffer<T> buffer = buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Memory<T> Memory
|
||||
|
||||
@@ -9,7 +9,7 @@ using ComputeSharp.Win32;
|
||||
using static ComputeSharp.Win32.D3D12_FORMAT_SUPPORT1;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
|
||||
#pragma warning disable CA1063
|
||||
#pragma warning disable CA1063, CA2213
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
@@ -152,21 +152,13 @@ public abstract unsafe partial class TransferTexture1D<T> : IReferenceTrackedObj
|
||||
/// <summary>
|
||||
/// A <see cref="MemoryManager{T}"/> implementation wrapping a <see cref="TransferTexture1D{T}"/> instance.
|
||||
/// </summary>
|
||||
private sealed class MemoryManager : MemoryManager<T>
|
||||
/// <param name="buffer">The <see cref="TransferTexture1D{T}"/> in use.</param>
|
||||
private sealed class MemoryManager(TransferTexture1D<T> buffer) : MemoryManager<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="TransferTexture1D{T}"/> in use.
|
||||
/// </summary>
|
||||
private readonly TransferTexture1D<T> buffer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MemoryManager"/> instance for a given buffer.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The <see cref="TransferTexture1D{T}"/> in use.</param>
|
||||
public MemoryManager(TransferTexture1D<T> buffer)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
}
|
||||
private readonly TransferTexture1D<T> buffer = buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Memory<T> Memory
|
||||
|
||||
@@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug;
|
||||
/// A debug proxy used to display items in a <see cref="TransferTexture1D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to display.</typeparam>
|
||||
internal sealed class TransferTexture1DDebugView<T>
|
||||
/// <param name="texture">The input <see cref="TransferTexture1D{T}"/> instance with the items to display.</param>
|
||||
internal sealed class TransferTexture1DDebugView<T>(TransferTexture1D<T>? texture)
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TransferTexture1DDebugView{T}"/> class with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="texture">The input <see cref="TransferTexture1D{T}"/> instance with the items to display.</param>
|
||||
public TransferTexture1DDebugView(TransferTexture1D<T>? texture)
|
||||
{
|
||||
Items = texture?.Span.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the items to display for the current instance.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
|
||||
public T[]? Items { get; }
|
||||
public T[]? Items { get; } = texture?.Span.ToArray();
|
||||
}
|
||||
@@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug;
|
||||
/// A debug proxy used to display items in a <see cref="TransferTexture2D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to display.</typeparam>
|
||||
internal sealed class TransferTexture2DDebugView<T>
|
||||
/// <param name="texture">The input <see cref="TransferTexture2D{T}"/> instance with the items to display.</param>
|
||||
internal sealed class TransferTexture2DDebugView<T>(TransferTexture2D<T>? texture)
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TransferTexture2DDebugView{T}"/> class with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="texture">The input <see cref="TransferTexture2D{T}"/> instance with the items to display.</param>
|
||||
public TransferTexture2DDebugView(TransferTexture2D<T>? texture)
|
||||
{
|
||||
Items = texture?.View.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the items to display for the current instance.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
|
||||
public T[,]? Items { get; }
|
||||
public T[,]? Items { get; } = texture?.View.ToArray();
|
||||
}
|
||||
@@ -6,21 +6,13 @@ namespace ComputeSharp.Resources.Debug;
|
||||
/// A debug proxy used to display items in a <see cref="TransferTexture3D{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to display.</typeparam>
|
||||
internal sealed class TransferTexture3DDebugView<T>
|
||||
/// <param name="texture">The input <see cref="TransferTexture3D{T}"/> instance with the items to display.</param>
|
||||
internal sealed class TransferTexture3DDebugView<T>(TransferTexture3D<T>? texture)
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TransferTexture3DDebugView{T}"/> class with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="texture">The input <see cref="TransferTexture3D{T}"/> instance with the items to display.</param>
|
||||
public TransferTexture3DDebugView(TransferTexture3D<T>? texture)
|
||||
{
|
||||
Items = texture?.View.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the items to display for the current instance.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
|
||||
public T[,,]? Items { get; }
|
||||
public T[,,]? Items { get; } = texture?.View.ToArray();
|
||||
}
|
||||
@@ -8,35 +8,20 @@ namespace ComputeSharp.Graphics.Resources.Interop;
|
||||
/// <summary>
|
||||
/// A type representing a mapped memory resource.
|
||||
/// </summary>
|
||||
internal readonly unsafe ref struct ID3D12ResourceMap
|
||||
/// <param name="d3D12Resource">The input <see cref="ID3D12Resource"/> instance to map.</param>
|
||||
/// <param name="pointer">The pointer to the mapped resource.</param>
|
||||
[method: MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal readonly unsafe ref struct ID3D12ResourceMap(ID3D12Resource* d3D12Resource, void* pointer)
|
||||
{
|
||||
/// <summary>
|
||||
/// The target <see cref="ID3D12Resource"/> to map.
|
||||
/// </summary>
|
||||
private readonly ID3D12Resource* d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the mapped resource.
|
||||
/// </summary>
|
||||
public readonly void* Pointer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ID3D12ResourceMap"/> instance for a given <see cref="ID3D12Resource"/> value.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Resource">The input <see cref="ID3D12Resource"/> instance to map.</param>
|
||||
/// <param name="pointer">The pointer to the mapped resource.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ID3D12ResourceMap(ID3D12Resource* d3D12Resource, void* pointer)
|
||||
{
|
||||
this.d3D12Resource = d3D12Resource;
|
||||
|
||||
this.Pointer = pointer;
|
||||
}
|
||||
public readonly void* Pointer = pointer;
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
this.d3D12Resource->Unmap();
|
||||
d3D12Resource->Unmap();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ internal static unsafe class PipelineDataLoader<T>
|
||||
/// <summary>
|
||||
/// The map of cached <see cref="PipelineData"/> instances for each GPU in use.
|
||||
/// </summary>
|
||||
private static readonly ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines = new();
|
||||
private static readonly ConditionalWeakTable<GraphicsDevice, PipelineData> CachedPipelines = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PipelineData"/> instance for a given shader.
|
||||
|
||||
@@ -69,11 +69,11 @@ public partial class D2D1PixelShaderEffectTests
|
||||
public unsafe void SetResourceTextureManagerForD2D1Effect_RCW_NullD2D1Effect()
|
||||
{
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { 64 },
|
||||
extents: [64],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinLinearMagMipPoint,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp });
|
||||
extendModes: [D2D1ExtendMode.Clamp]);
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(null, resourceTextureManager, 0);
|
||||
}
|
||||
|
||||
@@ -629,9 +629,7 @@ namespace ComputeSharp.D2D1.Tests
|
||||
{
|
||||
ShaderWithNoCapturedValues shader = default;
|
||||
|
||||
byte[] buffer = Array.Empty<byte>();
|
||||
|
||||
int bytesWritten = D2D1PixelShader.GetConstantBuffer(in shader, buffer);
|
||||
int bytesWritten = D2D1PixelShader.GetConstantBuffer(in shader, []);
|
||||
|
||||
Assert.AreEqual(bytesWritten, 0);
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
public unsafe void VerifyInterfaces_RCW()
|
||||
{
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { 64 },
|
||||
extents: [64],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinLinearMagMipPoint,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp });
|
||||
extendModes: [D2D1ExtendMode.Clamp]);
|
||||
|
||||
using ComPtr<IUnknown> unknown = default;
|
||||
using ComPtr<IUnknown> resourceTextureManager2 = default;
|
||||
@@ -153,13 +153,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyShaderWithResourceTexture>(d2D1Factory2.Get(), out _);
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { 128, 128 },
|
||||
extents: [128, 128],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: ReadOnlySpan<byte>.Empty,
|
||||
strides: ReadOnlySpan<uint>.Empty);
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: [],
|
||||
strides: []);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
@@ -218,13 +218,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
extents: [(uint)expected.Width, (uint)expected.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected.Width)]);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
@@ -277,13 +277,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
extents: [(uint)expected.Width, (uint)expected.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected.Width)]);
|
||||
|
||||
for (int i = 0; i < drawCount; i++)
|
||||
{
|
||||
@@ -334,13 +334,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
extents: [(uint)expected.Width, (uint)expected.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected.Width)]);
|
||||
|
||||
using ComPtr<IUnknown> unknown = default;
|
||||
|
||||
@@ -399,24 +399,24 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager0.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected0.Width, (uint)expected0.Height },
|
||||
extents: [(uint)expected0.Width, (uint)expected0.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels0.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected0.Width) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected0.Width)]);
|
||||
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager1.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected0.Width, (uint)expected0.Height },
|
||||
extents: [(uint)expected0.Width, (uint)expected0.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels1.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected0.Width) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected0.Width)]);
|
||||
|
||||
using (ComPtr<ID2D1Effect> d2D1Effect = default)
|
||||
{
|
||||
@@ -509,13 +509,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)(expected.Height / 4), 4u },
|
||||
extents: [(uint)expected.Width, (uint)(expected.Height / 4), 4u],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width), (uint)(sizeof(Rgba32) * expected.Width * (expected.Height / 4)) });
|
||||
strides: [(uint)(sizeof(Rgba32) * expected.Width), (uint)(sizeof(Rgba32) * expected.Width * (expected.Height / 4))]);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
@@ -581,11 +581,11 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
byte[] texture = new byte[width];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width },
|
||||
extents: [(uint)width],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp],
|
||||
data: texture,
|
||||
strides: null);
|
||||
|
||||
@@ -594,9 +594,9 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
RandomNumberGenerator.Create().GetBytes(data);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffset },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffset + updateLength) },
|
||||
strides: ReadOnlySpan<uint>.Empty,
|
||||
minimumExtents: [(uint)startOffset],
|
||||
maximimumExtents: [(uint)(startOffset + updateLength)],
|
||||
strides: [],
|
||||
data: data);
|
||||
|
||||
data.CopyTo(texture.AsSpan(startOffset));
|
||||
@@ -668,22 +668,22 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
byte[] texture = new byte[width * height];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width, (uint)height },
|
||||
extents: [(uint)width, (uint)height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: texture,
|
||||
strides: stackalloc uint[] { (uint)width });
|
||||
strides: [(uint)width]);
|
||||
|
||||
byte[] data = new byte[updateLengthX * updateLengthY];
|
||||
|
||||
RandomNumberGenerator.Create().GetBytes(data);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY) },
|
||||
strides: stackalloc uint[] { (uint)updateLengthX },
|
||||
minimumExtents: [(uint)startOffsetX, (uint)startOffsetY],
|
||||
maximimumExtents: [(uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY)],
|
||||
strides: [(uint)updateLengthX],
|
||||
data: data);
|
||||
|
||||
for (int y = 0; y < updateLengthY; y++)
|
||||
@@ -740,13 +740,13 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
byte[] texture = new byte[width * height];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width, (uint)height },
|
||||
extents: [(uint)width, (uint)height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: texture,
|
||||
strides: stackalloc uint[] { width });
|
||||
strides: [width]);
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0);
|
||||
|
||||
@@ -755,9 +755,9 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
// Thread As are constantly updating the resource texture
|
||||
void UpdateResourceTexture()
|
||||
{
|
||||
ReadOnlySpan<uint> minimumExtents = stackalloc uint[] { 0, 0 };
|
||||
ReadOnlySpan<uint> maximumExtents = stackalloc uint[] { width, height };
|
||||
ReadOnlySpan<uint> strides = stackalloc uint[] { width };
|
||||
ReadOnlySpan<uint> minimumExtents = [0, 0];
|
||||
ReadOnlySpan<uint> maximumExtents = [width, height];
|
||||
ReadOnlySpan<uint> strides = [width];
|
||||
|
||||
while (!cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
@@ -841,22 +841,22 @@ public partial class D2D1ResourceTextureManagerTests
|
||||
byte[] texture = new byte[width * height * depth];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width, (uint)height, (uint)depth },
|
||||
extents: [(uint)width, (uint)height, (uint)depth],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp],
|
||||
data: texture,
|
||||
strides: stackalloc uint[] { (uint)width, (uint)(width * height) });
|
||||
strides: [(uint)width, (uint)(width * height)]);
|
||||
|
||||
byte[] data = new byte[updateLengthX * updateLengthY * updateLengthZ];
|
||||
|
||||
RandomNumberGenerator.Create().GetBytes(data);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY, (uint)startOffsetZ },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY), (uint)(startOffsetZ + updateLengthZ) },
|
||||
strides: stackalloc uint[] { (uint)updateLengthX, (uint)(updateLengthX * updateLengthY) },
|
||||
minimumExtents: [(uint)startOffsetX, (uint)startOffsetY, (uint)startOffsetZ],
|
||||
maximimumExtents: [(uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY), (uint)(startOffsetZ + updateLengthZ)],
|
||||
strides: [(uint)updateLengthX, (uint)(updateLengthX * updateLengthY)],
|
||||
data: data);
|
||||
|
||||
for (int z = 0; z < updateLengthZ; z++)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -22,7 +21,61 @@ public sealed partial class BokehBlurEffect
|
||||
/// <summary>
|
||||
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="BokehBlurEffect"/> instances.
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, (float[] Real, float[] Imaginary)[] Kernels)> Cache = new();
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, (float[] Real, float[] Imaginary)[] Kernels)> Cache = [];
|
||||
|
||||
/// <summary>
|
||||
/// The kernel scales to adjust the component values in each kernel.
|
||||
/// </summary>
|
||||
private static readonly float[] KernelScales = [1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f];
|
||||
|
||||
/// <summary>
|
||||
/// The available bokeh blur kernel parameters.
|
||||
/// </summary>
|
||||
private static readonly Vector4[][] KernelComponents =
|
||||
[
|
||||
// 1 component
|
||||
[new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f)],
|
||||
|
||||
// 2 components
|
||||
[
|
||||
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
|
||||
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
|
||||
],
|
||||
|
||||
// 3 components
|
||||
[
|
||||
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
|
||||
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
|
||||
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
|
||||
],
|
||||
|
||||
// 4 components
|
||||
[
|
||||
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
|
||||
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
|
||||
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
|
||||
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
|
||||
],
|
||||
|
||||
// 5 components
|
||||
[
|
||||
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
|
||||
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
|
||||
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
|
||||
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
|
||||
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
|
||||
],
|
||||
|
||||
// 6 components
|
||||
[
|
||||
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
|
||||
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
|
||||
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
|
||||
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
|
||||
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
|
||||
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
|
||||
]
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The kernel radius.
|
||||
@@ -90,72 +143,13 @@ public sealed partial class BokehBlurEffect
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kernel scales to adjust the component values in each kernel.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<float> KernelScales { get; } = new[] { 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.2f };
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available bokeh blur kernel parameters.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<Vector4[]> KernelComponents { get; } = new[]
|
||||
{
|
||||
// 1 component
|
||||
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
|
||||
|
||||
// 2 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(0.886528f, 5.268909f, 0.411259f, -0.548794f),
|
||||
new Vector4(1.960518f, 1.558213f, 0.513282f, 4.56111f)
|
||||
},
|
||||
|
||||
// 3 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(2.17649f, 5.043495f, 1.621035f, -2.105439f),
|
||||
new Vector4(1.019306f, 9.027613f, -0.28086f, -0.162882f),
|
||||
new Vector4(2.81511f, 1.597273f, -0.366471f, 10.300301f)
|
||||
},
|
||||
|
||||
// 4 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(4.338459f, 1.553635f, -5.767909f, 46.164397f),
|
||||
new Vector4(3.839993f, 4.693183f, 9.795391f, -15.227561f),
|
||||
new Vector4(2.791880f, 8.178137f, -3.048324f, 0.302959f),
|
||||
new Vector4(1.342190f, 12.328289f, 0.010001f, 0.244650f)
|
||||
},
|
||||
|
||||
// 5 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(4.892608f, 1.685979f, -22.356787f, 85.91246f),
|
||||
new Vector4(4.71187f, 4.998496f, 35.918936f, -28.875618f),
|
||||
new Vector4(4.052795f, 8.244168f, -13.212253f, -1.578428f),
|
||||
new Vector4(2.929212f, 11.900859f, 0.507991f, 1.816328f),
|
||||
new Vector4(1.512961f, 16.116382f, 0.138051f, -0.01f)
|
||||
},
|
||||
|
||||
// 6 components
|
||||
new[]
|
||||
{
|
||||
new Vector4(5.143778f, 2.079813f, -82.326596f, 111.231024f),
|
||||
new Vector4(5.612426f, 6.153387f, 113.878661f, 58.004879f),
|
||||
new Vector4(5.982921f, 9.802895f, 39.479083f, -162.028887f),
|
||||
new Vector4(6.505167f, 11.059237f, -71.286026f, 95.027069f),
|
||||
new Vector4(3.869579f, 14.81052f, 1.405746f, -3.704914f),
|
||||
new Vector4(2.201904f, 19.032909f, -0.152784f, -0.107988f)
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kernel parameters and scaling factor for the current count value in the current instance.
|
||||
/// </summary>
|
||||
private (Vector4[] Parameters, float Scale) GetParameters()
|
||||
{
|
||||
// Prepare the kernel components
|
||||
int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Count));
|
||||
int index = Math.Max(0, Math.Min(this.componentsCount - 1, KernelComponents.Length));
|
||||
|
||||
return (KernelComponents[index], KernelScales[index]);
|
||||
}
|
||||
@@ -383,9 +377,9 @@ public sealed partial class BokehBlurEffect
|
||||
bufferPrecision: D2D1BufferPrecision.Float32,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(this.kernels[i].Real.AsSpan()),
|
||||
strides: ReadOnlySpan<uint>.Empty);
|
||||
strides: []);
|
||||
|
||||
// Also create the one for the imaginary kernel
|
||||
D2D1ResourceTextureManager kernelImaginary = new(
|
||||
@@ -393,9 +387,9 @@ public sealed partial class BokehBlurEffect
|
||||
bufferPrecision: D2D1BufferPrecision.Float32,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp },
|
||||
extendModes: [D2D1ExtendMode.Clamp],
|
||||
data: MemoryMarshal.AsBytes(this.kernels[i].Imaginary.AsSpan()),
|
||||
strides: ReadOnlySpan<uint>.Empty);
|
||||
strides: []);
|
||||
|
||||
kernels[i] = (kernelReals, kernelImaginary);
|
||||
}
|
||||
|
||||
@@ -94,13 +94,13 @@ public class ShadersTests
|
||||
}
|
||||
|
||||
resourceTextureManager = new D2D1ResourceTextureManager(
|
||||
extents: stackalloc uint[] { (uint)texture.Width, (uint)texture.Height },
|
||||
extents: [(uint)texture.Width, (uint)texture.Height],
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipLinear,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
|
||||
extendModes: [D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror],
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc uint[] { (uint)(texture.Width * sizeof(Rgba32)) });
|
||||
strides: [(uint)(texture.Width * sizeof(Rgba32))]);
|
||||
}
|
||||
|
||||
ContouredLayers shader = new(0f, new int2(1280, 720));
|
||||
|
||||
@@ -87,31 +87,17 @@ internal static class TolerantImageComparer
|
||||
/// <summary>
|
||||
/// A simple model repressenting info about a difference between two pixels.
|
||||
/// </summary>
|
||||
private readonly struct PixelDifference
|
||||
private readonly struct PixelDifference(Point position, Color expected, Color actual)
|
||||
{
|
||||
public PixelDifference(Point position, Color expected, Color actual)
|
||||
{
|
||||
this.Position = position;
|
||||
this.RedDifference = actual.R - expected.R;
|
||||
this.GreenDifference = actual.G - expected.G;
|
||||
this.BlueDifference = actual.B - expected.B;
|
||||
this.AlphaDifference = actual.A - expected.A;
|
||||
}
|
||||
|
||||
public readonly Point Position;
|
||||
|
||||
public readonly int RedDifference;
|
||||
|
||||
public readonly int GreenDifference;
|
||||
|
||||
public readonly int BlueDifference;
|
||||
|
||||
public readonly int AlphaDifference;
|
||||
private readonly int redDifference = actual.R - expected.R;
|
||||
private readonly int greenDifference = actual.G - expected.G;
|
||||
private readonly int blueDifference = actual.B - expected.B;
|
||||
private readonly int alphaDifference = actual.A - expected.A;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[delta({this.RedDifference},{this.GreenDifference},{this.BlueDifference},{this.AlphaDifference}) @ ({this.Position.X},{this.Position.Y})]";
|
||||
return $"[delta({this.redDifference},{this.greenDifference},{this.blueDifference},{this.alphaDifference}) @ ({position.X},{position.Y})]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -644,9 +644,9 @@ public partial class CanvasEffectTests
|
||||
private static readonly EffectNode<DummyCanvasImageTrackingDisposal> EffectNode1 = new();
|
||||
private static readonly EffectNode<DummyCanvasImageTrackingDisposal> EffectNode2 = new();
|
||||
private static readonly EffectNode<DummyCanvasImageTrackingDisposal> EffectNode3 = new();
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects1 = new();
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects2 = new();
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects3 = new();
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects1 = [];
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects2 = [];
|
||||
public readonly List<DummyCanvasImageTrackingDisposal> Effects3 = [];
|
||||
|
||||
public void InvalidateCreation()
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DeviceLostTests
|
||||
{
|
||||
GraphicsDeviceHelper.GetD3D12Device(graphicsDevice, in d3D12Device);
|
||||
|
||||
List<(object? Sender, DeviceLostEventArgs Args)> args = new();
|
||||
List<(object? Sender, DeviceLostEventArgs Args)> args = [];
|
||||
|
||||
// Register the device lost callback
|
||||
graphicsDevice.DeviceLost += (s, e) => args.Add((s, e));
|
||||
|
||||
@@ -17,7 +17,7 @@ internal struct DebugDispatchDataLoader : IConstantBufferLoader, IGraphicsResour
|
||||
/// <summary>
|
||||
/// The list of loaded resources.
|
||||
/// </summary>
|
||||
private readonly List<(IGraphicsResource Resource, uint Index)> graphicsResources = new();
|
||||
private readonly List<(IGraphicsResource Resource, uint Index)> graphicsResources = [];
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DebugDispatchDataLoader"/> instance.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
extern alias Core;
|
||||
extern alias D3D12;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
@@ -1421,19 +1420,13 @@ public class DiagnosticsTests
|
||||
private static void VerifyGeneratedDiagnostics<TGenerator>(string source, params string[] diagnosticsIds)
|
||||
where TGenerator : class, IIncrementalGenerator, new()
|
||||
{
|
||||
// Ensure ComputeSharp.Core and ComputeSharp are loaded
|
||||
Type hlslType = typeof(Core::ComputeSharp.Hlsl);
|
||||
Type computeShaderType = typeof(D3D12::ComputeSharp.IComputeShader);
|
||||
|
||||
// Prepare the two additional metadata references
|
||||
IEnumerable<MetadataReference> additionalReferences = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(hlslType.Assembly.Location),
|
||||
MetadataReference.CreateFromFile(computeShaderType.Assembly.Location)
|
||||
};
|
||||
|
||||
// Get all assembly references for the loaded assemblies (easy way to pull in all necessary dependencies)
|
||||
IEnumerable<MetadataReference> metadataReferences = Net80.References.All.Concat(additionalReferences);
|
||||
// Get all assembly references for the .NET TFM and ComputeSharp
|
||||
IEnumerable<MetadataReference> metadataReferences =
|
||||
[
|
||||
.. Net80.References.All,
|
||||
MetadataReference.CreateFromFile(typeof(Core::ComputeSharp.Hlsl).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(D3D12::ComputeSharp.IComputeShader).Assembly.Location)
|
||||
];
|
||||
|
||||
// Parse the source text (C# 11)
|
||||
SyntaxTree sourceTree = CSharpSyntaxTree.ParseText(
|
||||
@@ -1466,8 +1459,5 @@ public class DiagnosticsTests
|
||||
|
||||
Assert.IsTrue(outputCompilationDiagnostics.Count == 0, $"resultingIds: {string.Join(", ", outputCompilationDiagnostics)}");
|
||||
}
|
||||
|
||||
GC.KeepAlive(hlslType);
|
||||
GC.KeepAlive(computeShaderType);
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
|
||||
/// <summary>
|
||||
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> adding additional arbitrary input data.
|
||||
/// </summary>
|
||||
/// <param name="data">The additional input data.</param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class AdditionalDataAttribute : Attribute
|
||||
public sealed class AdditionalDataAttribute(params object[] data) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="AdditionalDataAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="data">The additional input data.</param>
|
||||
public AdditionalDataAttribute(params object[] data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional input data for the current attribute.
|
||||
/// </summary>
|
||||
public object[] Data { get; }
|
||||
public object[] Data { get; } = data;
|
||||
}
|
||||
@@ -5,20 +5,12 @@ namespace ComputeSharp.Tests.Attributes;
|
||||
/// <summary>
|
||||
/// An attribute to use with <see cref="CombinatorialTestMethodAttribute"/> targeting an additional specific resource type.
|
||||
/// </summary>
|
||||
/// <param name="type">The additional resource type.</param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class AdditionalResourceAttribute : Attribute
|
||||
public sealed class AdditionalResourceAttribute(Type type) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="AdditionalResourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="type">The additional resource type.</param>
|
||||
public AdditionalResourceAttribute(Type type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional resource type for the current attribute.
|
||||
/// </summary>
|
||||
public Type Type { get; }
|
||||
public Type Type { get; } = type;
|
||||
}
|
||||
106ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。
さらに表示
新しいイシューから参照
ユーザーをブロックする