Refactored code to use file scoped using declarations
このコミットが含まれているのは:
1 親
52ec5a79b0
コミット
d5e3114f7c
275ファイル変更
+91970
-92271
検索条件に一致するファイルはありません
@@ -3,160 +3,159 @@ using System.Buffers;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Engines;
|
||||
|
||||
namespace ComputeSharp.Benchmark.Blas
|
||||
namespace ComputeSharp.Benchmark.Blas;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that benchmarks the APIs in the <see cref="BlasHelpers"/> class, on both CPU and GPU.
|
||||
/// </summary>
|
||||
[SimpleJob(RunStrategy.Monitoring)]
|
||||
public class BlasBenchmark : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that benchmarks the APIs in the <see cref="BlasHelpers"/> class, on both CPU and GPU.
|
||||
/// The number of samples.
|
||||
/// </summary>
|
||||
[SimpleJob(RunStrategy.Monitoring)]
|
||||
public class BlasBenchmark : IDisposable
|
||||
private const int C = 128;
|
||||
|
||||
/// <summary>
|
||||
/// The nummber of rows in the <see cref="X"/> matrix.
|
||||
/// </summary>
|
||||
private const int N = 512;
|
||||
|
||||
/// <summary>
|
||||
/// The number of columns in the <see cref="X"/> matrix (same as the number of rows in the <see cref="W"/> matrix)
|
||||
/// </summary>
|
||||
private const int M = 512;
|
||||
|
||||
/// <summary>
|
||||
/// The number of columns in the <see cref="W"/> matrix.
|
||||
/// </summary>
|
||||
private const int P = 256;
|
||||
|
||||
/// <summary>
|
||||
/// The input tensor.
|
||||
/// </summary>
|
||||
private float[]? X;
|
||||
|
||||
/// <summary>
|
||||
/// The weights tensor.
|
||||
/// </summary>
|
||||
private float[]? W;
|
||||
|
||||
/// <summary>
|
||||
/// The bias tensor.
|
||||
/// </summary>
|
||||
private float[]? B;
|
||||
|
||||
/// <summary>
|
||||
/// The result tensor.
|
||||
/// </summary>
|
||||
private float[]? Y;
|
||||
|
||||
/// <summary>
|
||||
/// The input tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferX;
|
||||
|
||||
/// <summary>
|
||||
/// The weights tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferW;
|
||||
|
||||
/// <summary>
|
||||
/// The bias tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferB;
|
||||
|
||||
/// <summary>
|
||||
/// The result tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadWriteBuffer<float>? BufferY;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="System.Random"/> instance to initialize the tensors.
|
||||
/// </summary>
|
||||
private readonly Random Random = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Initial setup for a benchmarking session.
|
||||
/// </summary>
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of samples.
|
||||
/// </summary>
|
||||
private const int C = 128;
|
||||
|
||||
/// <summary>
|
||||
/// The nummber of rows in the <see cref="X"/> matrix.
|
||||
/// </summary>
|
||||
private const int N = 512;
|
||||
|
||||
/// <summary>
|
||||
/// The number of columns in the <see cref="X"/> matrix (same as the number of rows in the <see cref="W"/> matrix)
|
||||
/// </summary>
|
||||
private const int M = 512;
|
||||
|
||||
/// <summary>
|
||||
/// The number of columns in the <see cref="W"/> matrix.
|
||||
/// </summary>
|
||||
private const int P = 256;
|
||||
|
||||
/// <summary>
|
||||
/// The input tensor.
|
||||
/// </summary>
|
||||
private float[]? X;
|
||||
|
||||
/// <summary>
|
||||
/// The weights tensor.
|
||||
/// </summary>
|
||||
private float[]? W;
|
||||
|
||||
/// <summary>
|
||||
/// The bias tensor.
|
||||
/// </summary>
|
||||
private float[]? B;
|
||||
|
||||
/// <summary>
|
||||
/// The result tensor.
|
||||
/// </summary>
|
||||
private float[]? Y;
|
||||
|
||||
/// <summary>
|
||||
/// The input tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferX;
|
||||
|
||||
/// <summary>
|
||||
/// The weights tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferW;
|
||||
|
||||
/// <summary>
|
||||
/// The bias tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadOnlyBuffer<float>? BufferB;
|
||||
|
||||
/// <summary>
|
||||
/// The result tensor (GPU).
|
||||
/// </summary>
|
||||
private ReadWriteBuffer<float>? BufferY;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="System.Random"/> instance to initialize the tensors.
|
||||
/// </summary>
|
||||
private readonly Random Random = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Initial setup for a benchmarking session.
|
||||
/// </summary>
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
// Creates a new random normalized float[] array of a given size
|
||||
float[] CreateRandomArray(int size)
|
||||
{
|
||||
// Creates a new random normalized float[] array of a given size
|
||||
float[] CreateRandomArray(int size)
|
||||
float[] array = ArrayPool<float>.Shared.Rent(size);
|
||||
|
||||
foreach (ref float x in array.AsSpan())
|
||||
{
|
||||
float[] array = ArrayPool<float>.Shared.Rent(size);
|
||||
|
||||
foreach (ref float x in array.AsSpan())
|
||||
{
|
||||
x = (float)Random.NextDouble();
|
||||
}
|
||||
|
||||
return array;
|
||||
x = (float)Random.NextDouble();
|
||||
}
|
||||
|
||||
X = CreateRandomArray(C * N * M);
|
||||
W = CreateRandomArray(M * P);
|
||||
B = CreateRandomArray(P);
|
||||
Y = CreateRandomArray(C * N * P);
|
||||
|
||||
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
|
||||
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
|
||||
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
|
||||
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
|
||||
|
||||
Cpu();
|
||||
GpuWithNoTemporaryBuffers();
|
||||
GpuWithTemporaryBuffers();
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[GlobalCleanup]
|
||||
public void Dispose()
|
||||
{
|
||||
ArrayPool<float>.Shared.Return(X!);
|
||||
ArrayPool<float>.Shared.Return(W!);
|
||||
ArrayPool<float>.Shared.Return(B!);
|
||||
ArrayPool<float>.Shared.Return(Y!);
|
||||
X = CreateRandomArray(C * N * M);
|
||||
W = CreateRandomArray(M * P);
|
||||
B = CreateRandomArray(P);
|
||||
Y = CreateRandomArray(C * N * P);
|
||||
|
||||
BufferX!.Dispose();
|
||||
BufferW!.Dispose();
|
||||
BufferB!.Dispose();
|
||||
BufferY!.Dispose();
|
||||
}
|
||||
BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
|
||||
BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
|
||||
BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
|
||||
BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
public void Cpu()
|
||||
{
|
||||
BlasHelpers.FullyConnectedForwardCpu(C, N, M, P, X!, W!, B!, Y!);
|
||||
}
|
||||
Cpu();
|
||||
GpuWithNoTemporaryBuffers();
|
||||
GpuWithTemporaryBuffers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuWithNoTemporaryBuffers()
|
||||
{
|
||||
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
[GlobalCleanup]
|
||||
public void Dispose()
|
||||
{
|
||||
ArrayPool<float>.Shared.Return(X!);
|
||||
ArrayPool<float>.Shared.Return(W!);
|
||||
ArrayPool<float>.Shared.Return(B!);
|
||||
ArrayPool<float>.Shared.Return(Y!);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the GPU, creating temporary GPU buffers to perform the operations.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuWithTemporaryBuffers()
|
||||
{
|
||||
using ReadOnlyBuffer<float> x = Gpu.Default.AllocateReadOnlyBuffer(X!);
|
||||
using ReadOnlyBuffer<float> w = Gpu.Default.AllocateReadOnlyBuffer(W!);
|
||||
using ReadOnlyBuffer<float> b = Gpu.Default.AllocateReadOnlyBuffer(B!);
|
||||
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(Y!.Length);
|
||||
BufferX!.Dispose();
|
||||
BufferW!.Dispose();
|
||||
BufferB!.Dispose();
|
||||
BufferY!.Dispose();
|
||||
}
|
||||
|
||||
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
public void Cpu()
|
||||
{
|
||||
BlasHelpers.FullyConnectedForwardCpu(C, N, M, P, X!, W!, B!, Y!);
|
||||
}
|
||||
|
||||
y.CopyTo(Y);
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuWithNoTemporaryBuffers()
|
||||
{
|
||||
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, BufferX!, BufferW!, BufferB!, BufferY!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a fully connected forward operation on the GPU, creating temporary GPU buffers to perform the operations.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
public void GpuWithTemporaryBuffers()
|
||||
{
|
||||
using ReadOnlyBuffer<float> x = Gpu.Default.AllocateReadOnlyBuffer(X!);
|
||||
using ReadOnlyBuffer<float> w = Gpu.Default.AllocateReadOnlyBuffer(W!);
|
||||
using ReadOnlyBuffer<float> b = Gpu.Default.AllocateReadOnlyBuffer(B!);
|
||||
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(Y!.Length);
|
||||
|
||||
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);
|
||||
|
||||
y.CopyTo(Y);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +1,108 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputeSharp.Benchmark.Blas
|
||||
namespace ComputeSharp.Benchmark.Blas;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains primitives to run certain operations of a neural network.
|
||||
/// </summary>
|
||||
internal static partial class BlasHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains primitives to run certain operations of a neural network.
|
||||
/// Executes the forward pass on a fully connected layer on the CPU.
|
||||
/// </summary>
|
||||
internal static partial class BlasHelpers
|
||||
/// <param name="c">The number of samples in the input tensor.</param>
|
||||
/// <param name="n">The number of rows in the input matrix.</param>
|
||||
/// <param name="m">The number of columns in the input matrix.</param>
|
||||
/// <param name="p">The number of columns in the output matrix.</param>
|
||||
/// <param name="x">The input tensor.</param>
|
||||
/// <param name="w">The weights tensor.</param>
|
||||
/// <param name="b">The bias tensor.</param>
|
||||
/// <param name="y">The result tensor.</param>
|
||||
public static void FullyConnectedForwardCpu(int c, int n, int m, int p, float[] x, float[] w, float[] b, float[] y)
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the forward pass on a fully connected layer on the CPU.
|
||||
/// </summary>
|
||||
/// <param name="c">The number of samples in the input tensor.</param>
|
||||
/// <param name="n">The number of rows in the input matrix.</param>
|
||||
/// <param name="m">The number of columns in the input matrix.</param>
|
||||
/// <param name="p">The number of columns in the output matrix.</param>
|
||||
/// <param name="x">The input tensor.</param>
|
||||
/// <param name="w">The weights tensor.</param>
|
||||
/// <param name="b">The bias tensor.</param>
|
||||
/// <param name="y">The result tensor.</param>
|
||||
public static void FullyConnectedForwardCpu(int c, int n, int m, int p, float[] x, float[] w, float[] b, float[] y)
|
||||
void Kernel(int s)
|
||||
{
|
||||
void Kernel(int s)
|
||||
ref float rx = ref x[s * n * m];
|
||||
ref float rw = ref w[0];
|
||||
ref float rb = ref b[0];
|
||||
ref float ry = ref y[s * n * p];
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
ref float rx = ref x[s * n * m];
|
||||
ref float rw = ref w[0];
|
||||
ref float rb = ref b[0];
|
||||
ref float ry = ref y[s * n * p];
|
||||
int x_offset = i * m;
|
||||
int y_offset = i * p;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int j = 0; j < p; j++)
|
||||
{
|
||||
int x_offset = i * m;
|
||||
int y_offset = i * p;
|
||||
float result = 0f;
|
||||
|
||||
for (int j = 0; j < p; j++)
|
||||
for (int k = 0; k < m; k++)
|
||||
{
|
||||
float result = 0f;
|
||||
|
||||
for (int k = 0; k < m; k++)
|
||||
{
|
||||
result += Unsafe.Add(ref rx, x_offset + k) * Unsafe.Add(ref rw, k * p + j);
|
||||
}
|
||||
|
||||
Unsafe.Add(ref ry, y_offset + j) = result + Unsafe.Add(ref rb, j);
|
||||
result += Unsafe.Add(ref rx, x_offset + k) * Unsafe.Add(ref rw, k * p + j);
|
||||
}
|
||||
|
||||
Unsafe.Add(ref ry, y_offset + j) = result + Unsafe.Add(ref rb, j);
|
||||
}
|
||||
}
|
||||
|
||||
Parallel.For(0, c, Kernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the forward pass on a fully connected layer on the GPU.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to run the computation on.</param>
|
||||
/// <param name="c">The number of samples in the input tensor.</param>
|
||||
/// <param name="n">The number of rows in the input matrix.</param>
|
||||
/// <param name="m">The number of columns in the input matrix.</param>
|
||||
/// <param name="p">The number of columns in the output matrix.</param>
|
||||
/// <param name="x">The input tensor.</param>
|
||||
/// <param name="w">The weights tensor.</param>
|
||||
/// <param name="b">The bias tensor.</param>
|
||||
/// <param name="y">The result tensor.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FullyConnectedForwardGpu(
|
||||
GraphicsDevice device,
|
||||
int c,
|
||||
int n,
|
||||
int m,
|
||||
int p,
|
||||
ReadOnlyBuffer<float> x,
|
||||
ReadOnlyBuffer<float> w,
|
||||
ReadOnlyBuffer<float> b,
|
||||
ReadWriteBuffer<float> y)
|
||||
{
|
||||
device.For(c, n, p, new FullyConnectedForwardKernel(n, m, p, x, w, b, y));
|
||||
}
|
||||
Parallel.For(0, c, Kernel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for <see cref="FullyConnectedForwardGpu"/>.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
public readonly partial struct FullyConnectedForwardKernel : IComputeShader
|
||||
{
|
||||
public readonly int n;
|
||||
public readonly int m;
|
||||
public readonly int p;
|
||||
public readonly ReadOnlyBuffer<float> x;
|
||||
public readonly ReadOnlyBuffer<float> w;
|
||||
public readonly ReadOnlyBuffer<float> b;
|
||||
public readonly ReadWriteBuffer<float> y;
|
||||
/// <summary>
|
||||
/// Executes the forward pass on a fully connected layer on the GPU.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to run the computation on.</param>
|
||||
/// <param name="c">The number of samples in the input tensor.</param>
|
||||
/// <param name="n">The number of rows in the input matrix.</param>
|
||||
/// <param name="m">The number of columns in the input matrix.</param>
|
||||
/// <param name="p">The number of columns in the output matrix.</param>
|
||||
/// <param name="x">The input tensor.</param>
|
||||
/// <param name="w">The weights tensor.</param>
|
||||
/// <param name="b">The bias tensor.</param>
|
||||
/// <param name="y">The result tensor.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FullyConnectedForwardGpu(
|
||||
GraphicsDevice device,
|
||||
int c,
|
||||
int n,
|
||||
int m,
|
||||
int p,
|
||||
ReadOnlyBuffer<float> x,
|
||||
ReadOnlyBuffer<float> w,
|
||||
ReadOnlyBuffer<float> b,
|
||||
ReadWriteBuffer<float> y)
|
||||
{
|
||||
device.For(c, n, p, new FullyConnectedForwardKernel(n, m, p, x, w, b, y));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
/// <summary>
|
||||
/// Kernel for <see cref="FullyConnectedForwardGpu"/>.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
public readonly partial struct FullyConnectedForwardKernel : IComputeShader
|
||||
{
|
||||
public readonly int n;
|
||||
public readonly int m;
|
||||
public readonly int p;
|
||||
public readonly ReadOnlyBuffer<float> x;
|
||||
public readonly ReadOnlyBuffer<float> w;
|
||||
public readonly ReadOnlyBuffer<float> b;
|
||||
public readonly ReadWriteBuffer<float> y;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
int x_offset = ThreadIds.X * n * p + ThreadIds.Y * m;
|
||||
float result = 0f;
|
||||
|
||||
for (int k = 0; k < m; k++)
|
||||
{
|
||||
int x_offset = ThreadIds.X * n * p + ThreadIds.Y * m;
|
||||
float result = 0f;
|
||||
|
||||
for (int k = 0; k < m; k++)
|
||||
{
|
||||
result += x[x_offset + k] * w[k * p + ThreadIds.Z];
|
||||
}
|
||||
|
||||
y[ThreadIds.X * n * p + ThreadIds.Y * p + ThreadIds.Z] = result + b[ThreadIds.Z];
|
||||
result += x[x_offset + k] * w[k * p + ThreadIds.Z];
|
||||
}
|
||||
|
||||
y[ThreadIds.X * n * p + ThreadIds.Y * p + ThreadIds.Z] = result + b[ThreadIds.Z];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,82 +10,81 @@ using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Processing.Processors.Convolution;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.Benchmark.Imaging
|
||||
namespace ComputeSharp.Benchmark.Imaging;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that benchmarks the image processors against the reference in ImageSharp.
|
||||
/// </summary>
|
||||
[SimpleJob(RunStrategy.Monitoring)]
|
||||
[CategoriesColumn]
|
||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
||||
public class ImagingBenchmark : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that benchmarks the image processors against the reference in ImageSharp.
|
||||
/// The loaded image.
|
||||
/// </summary>
|
||||
[SimpleJob(RunStrategy.Monitoring)]
|
||||
[CategoriesColumn]
|
||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
||||
public class ImagingBenchmark : IDisposable
|
||||
private Image<ImageSharpRgba32>? image;
|
||||
|
||||
/// <summary>
|
||||
/// Initial setup for a benchmarking session.
|
||||
/// </summary>
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
/// <summary>
|
||||
/// The loaded image.
|
||||
/// </summary>
|
||||
private Image<ImageSharpRgba32>? image;
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
/// <summary>
|
||||
/// Initial setup for a benchmarking session.
|
||||
/// </summary>
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
this.image = Image.Load<ImageSharpRgba32>(path);
|
||||
|
||||
this.image = Image.Load<ImageSharpRgba32>(path);
|
||||
Bokeh_Cpu();
|
||||
Bokeh_Gpu();
|
||||
Gaussian_Cpu();
|
||||
Gaussian_Gpu();
|
||||
}
|
||||
|
||||
Bokeh_Cpu();
|
||||
Bokeh_Gpu();
|
||||
Gaussian_Cpu();
|
||||
Gaussian_Gpu();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
[GlobalCleanup]
|
||||
public void Dispose()
|
||||
{
|
||||
this.image!.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[GlobalCleanup]
|
||||
public void Dispose()
|
||||
{
|
||||
this.image!.Dispose();
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs a bokeh blur effect on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("BOKEH")]
|
||||
public void Bokeh_Cpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new BokehBlurProcessor(80, 2, 3)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a bokeh blur effect on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("BOKEH")]
|
||||
public void Bokeh_Cpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new BokehBlurProcessor(80, 2, 3)));
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs a bokeh blur effect on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("BOKEH")]
|
||||
public void Bokeh_Gpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a bokeh blur effect on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("BOKEH")]
|
||||
public void Bokeh_Gpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2)));
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs a gaussian blur effect on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("GAUSSIAN")]
|
||||
public void Gaussian_Cpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new GaussianBlurProcessor(80)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a gaussian blur effect on the CPU.
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("GAUSSIAN")]
|
||||
public void Gaussian_Cpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new GaussianBlurProcessor(80)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a gaussian blur effect on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("GAUSSIAN")]
|
||||
public void Gaussian_Gpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(80)));
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs a gaussian blur effect on the GPU.
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("GAUSSIAN")]
|
||||
public void Gaussian_Gpu()
|
||||
{
|
||||
this.image!.Mutate(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(80)));
|
||||
}
|
||||
}
|
||||
@@ -3,44 +3,43 @@
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace SixLabors.ImageSharp
|
||||
namespace SixLabors.ImageSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a complex number, where the real and imaginary parts are stored as <see cref="float"/> values.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a more efficient version of the <see cref="Complex64"/> type.
|
||||
/// </remarks>
|
||||
internal readonly struct Complex64
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a complex number, where the real and imaginary parts are stored as <see cref="float"/> values.
|
||||
/// The real part of the complex number.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a more efficient version of the <see cref="Complex64"/> type.
|
||||
/// </remarks>
|
||||
internal readonly struct Complex64
|
||||
public readonly float 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)
|
||||
{
|
||||
/// <summary>
|
||||
/// The real part of the complex number.
|
||||
/// </summary>
|
||||
public readonly float 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Complex64"/> value to multiply.</param>
|
||||
/// <param name="scalar">The <see cref="float"/> scalar to use to multiply the <see cref="Complex64"/> value.</param>
|
||||
/// <returns>The <see cref="Complex64"/> result.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Complex64 operator *(Complex64 value, float scalar) => new Complex64(value.Real * scalar, value.Imaginary * scalar);
|
||||
this.Real = real;
|
||||
this.Imaginary = imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the multiplication operation between a <see cref="Complex64"/> instance and a <see cref="float"/> scalar.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Complex64"/> value to multiply.</param>
|
||||
/// <param name="scalar">The <see cref="float"/> scalar to use to multiply the <see cref="Complex64"/> value.</param>
|
||||
/// <returns>The <see cref="Complex64"/> result.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Complex64 operator *(Complex64 value, float scalar) => new Complex64(value.Real * scalar, value.Imaginary * scalar);
|
||||
}
|
||||
@@ -5,81 +5,80 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// Applies bokeh blur processing to the image.
|
||||
/// </summary>
|
||||
public sealed partial class HlslBokehBlurProcessor : IImageProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies bokeh blur processing to the image.
|
||||
/// The default radius used by the parameterless constructor.
|
||||
/// </summary>
|
||||
public sealed partial class HlslBokehBlurProcessor : IImageProcessor
|
||||
public const int DefaultRadius = 32;
|
||||
|
||||
/// <summary>
|
||||
/// The default component count used by the parameterless constructor.
|
||||
/// </summary>
|
||||
public const int DefaultComponents = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslBokehBlurProcessor()
|
||||
: this(Gpu.Default, DefaultRadius, DefaultComponents)
|
||||
{
|
||||
/// <summary>
|
||||
/// The default radius used by the parameterless constructor.
|
||||
/// </summary>
|
||||
public const int DefaultRadius = 32;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default component count used by the parameterless constructor.
|
||||
/// </summary>
|
||||
public const int DefaultComponents = 2;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(int radius, int components)
|
||||
: this(Gpu.Default, radius, components)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslBokehBlurProcessor()
|
||||
: this(Gpu.Default, DefaultRadius, DefaultComponents)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Radius = radius;
|
||||
Components = components;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the radius.
|
||||
/// </summary>
|
||||
public int Radius { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of components.
|
||||
/// </summary>
|
||||
public int Components { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
|
||||
where TPixel : unmanaged, IPixel<TPixel>
|
||||
{
|
||||
if (typeof(TPixel) != typeof(ImageSharpRgba32))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(int radius, int components)
|
||||
: this(Gpu.Default, radius, components)
|
||||
{
|
||||
}
|
||||
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Radius = radius;
|
||||
Components = components;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the radius.
|
||||
/// </summary>
|
||||
public int Radius { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of components.
|
||||
/// </summary>
|
||||
public int Components { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
|
||||
where TPixel : unmanaged, IPixel<TPixel>
|
||||
{
|
||||
if (typeof(TPixel) != typeof(ImageSharpRgba32))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
|
||||
}
|
||||
|
||||
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
|
||||
|
||||
return Unsafe.As<IImageProcessor<TPixel>>(processor);
|
||||
}
|
||||
return Unsafe.As<IImageProcessor<TPixel>>(processor);
|
||||
}
|
||||
}
|
||||
@@ -9,417 +9,416 @@ using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class HlslBokehBlurProcessor
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class HlslBokehBlurProcessor
|
||||
/// <summary>
|
||||
/// Applies bokeh blur processing to the image.
|
||||
/// </summary>
|
||||
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a>.</remarks>
|
||||
public sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies bokeh blur processing to the image.
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a>.</remarks>
|
||||
public sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel radius.
|
||||
/// </summary>
|
||||
private readonly int Radius;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum size of the kernel in either direction.
|
||||
/// </summary>
|
||||
private readonly int KernelSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of components to use when applying the bokeh blur.
|
||||
/// </summary>
|
||||
private readonly int ComponentsCount;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel parameters to use for the current instance (a: X, b: Y, A: Z, B: W)
|
||||
/// </summary>
|
||||
private readonly Vector4[] KernelParameters;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel components for the current instance.
|
||||
/// </summary>
|
||||
private readonly Complex64[][] Kernels;
|
||||
|
||||
/// <summary>
|
||||
/// The scaling factor for kernel values.
|
||||
/// </summary>
|
||||
private readonly float KernelsScale;
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor{TPixel}"/> instances.
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Implementation"/> class.
|
||||
/// </summary>
|
||||
/// <param name="definition">The <see cref="HlslBokehBlurProcessor"/> defining the processor parameters.</param>
|
||||
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
|
||||
/// <param name="source">The source <see cref="Image{TPixel}"/> instance to modify.</param>
|
||||
/// <param name="sourceRectangle">The source <see cref="Rectangle"/> that indicates the area to edit.</param>
|
||||
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
|
||||
: base(configuration, source, sourceRectangle)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
GraphicsDevice = definition.GraphicsDevice;
|
||||
Radius = definition.Radius;
|
||||
KernelSize = Radius * 2 + 1;
|
||||
ComponentsCount = definition.Components;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel radius.
|
||||
/// </summary>
|
||||
private readonly int Radius;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum size of the kernel in either direction.
|
||||
/// </summary>
|
||||
private readonly int KernelSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of components to use when applying the bokeh blur.
|
||||
/// </summary>
|
||||
private readonly int ComponentsCount;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel parameters to use for the current instance (a: X, b: Y, A: Z, B: W)
|
||||
/// </summary>
|
||||
private readonly Vector4[] KernelParameters;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel components for the current instance.
|
||||
/// </summary>
|
||||
private readonly Complex64[][] Kernels;
|
||||
|
||||
/// <summary>
|
||||
/// The scaling factor for kernel values.
|
||||
/// </summary>
|
||||
private readonly float KernelsScale;
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of initialized complex kernels and parameters, to speed up the initialization of new <see cref="HlslBokehBlurProcessor{TPixel}"/> instances.
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<(int Radius, int ComponentsCount), (Vector4[] Parameters, float Scale, Complex64[][] Kernels)> Cache = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Implementation"/> class.
|
||||
/// </summary>
|
||||
/// <param name="definition">The <see cref="HlslBokehBlurProcessor"/> defining the processor parameters.</param>
|
||||
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
|
||||
/// <param name="source">The source <see cref="Image{TPixel}"/> instance to modify.</param>
|
||||
/// <param name="sourceRectangle">The source <see cref="Rectangle"/> that indicates the area to edit.</param>
|
||||
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
|
||||
: base(configuration, source, sourceRectangle)
|
||||
// Reuse the initialized values from the cache, if possible
|
||||
var parameters = (Radius, ComponentsCount);
|
||||
if (Cache.TryGetValue(parameters, out var info))
|
||||
{
|
||||
GraphicsDevice = definition.GraphicsDevice;
|
||||
Radius = definition.Radius;
|
||||
KernelSize = Radius * 2 + 1;
|
||||
ComponentsCount = definition.Components;
|
||||
KernelParameters = info.Parameters;
|
||||
KernelsScale = info.Scale;
|
||||
Kernels = info.Kernels;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initialize the complex kernels and parameters with the current arguments
|
||||
(KernelParameters, KernelsScale) = GetParameters();
|
||||
Kernels = CreateComplexKernels();
|
||||
NormalizeKernels();
|
||||
|
||||
// Reuse the initialized values from the cache, if possible
|
||||
var parameters = (Radius, ComponentsCount);
|
||||
if (Cache.TryGetValue(parameters, out var info))
|
||||
{
|
||||
KernelParameters = info.Parameters;
|
||||
KernelsScale = info.Scale;
|
||||
Kernels = info.Kernels;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initialize the complex kernels and parameters with the current arguments
|
||||
(KernelParameters, KernelsScale) = GetParameters();
|
||||
Kernels = CreateComplexKernels();
|
||||
NormalizeKernels();
|
||||
// Store them in the cache for future use
|
||||
Cache.TryAdd(parameters, (KernelParameters, KernelsScale, Kernels));
|
||||
}
|
||||
}
|
||||
|
||||
// Store them in the cache for future use
|
||||
Cache.TryAdd(parameters, (KernelParameters, KernelsScale, Kernels));
|
||||
}
|
||||
/// <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(ComponentsCount - 1, KernelComponents.Count));
|
||||
return (KernelComponents[index], KernelScales[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the collection of complex 1D kernels with the specified parameters.
|
||||
/// </summary>
|
||||
private Complex64[][] CreateComplexKernels()
|
||||
{
|
||||
var kernels = new Complex64[KernelParameters.Length][];
|
||||
ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
|
||||
for (int i = 0; i < KernelParameters.Length; i++)
|
||||
{
|
||||
ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i);
|
||||
kernels[i] = CreateComplex1DKernel(paramsRef.X, paramsRef.Y);
|
||||
}
|
||||
|
||||
/// <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 };
|
||||
return kernels;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available bokeh blur kernel parameters.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<Vector4[]> KernelComponents { get; } = new[]
|
||||
/// <summary>
|
||||
/// Creates a complex 1D kernel with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="a">The exponential parameter for each complex component.</param>
|
||||
/// <param name="b">The angle component for each complex component.</param>
|
||||
private Complex64[] CreateComplex1DKernel(float a, float b)
|
||||
{
|
||||
var kernel = new Complex64[KernelSize];
|
||||
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
|
||||
int r = Radius, n = -r;
|
||||
|
||||
for (int i = 0; i < KernelSize; i++, n++)
|
||||
{
|
||||
// 1 component
|
||||
new[] { new Vector4(0.862325f, 1.624835f, 0.767583f, 1.862321f) },
|
||||
// Incrementally compute the range values
|
||||
float value = n * KernelsScale * (1f / r);
|
||||
value *= value;
|
||||
|
||||
// 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(ComponentsCount - 1, KernelComponents.Count));
|
||||
return (KernelComponents[index], KernelScales[index]);
|
||||
// Fill in the complex kernel values
|
||||
Unsafe.Add(ref baseRef, i) = new Complex64(
|
||||
MathF.Exp(-a * value) * MathF.Cos(b * value),
|
||||
MathF.Exp(-a * value) * MathF.Sin(b * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the collection of complex 1D kernels with the specified parameters.
|
||||
/// </summary>
|
||||
private Complex64[][] CreateComplexKernels()
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes the kernels with respect to A * real + B * imaginary.
|
||||
/// </summary>
|
||||
private void NormalizeKernels()
|
||||
{
|
||||
// Calculate the complex weighted sum
|
||||
float total = 0;
|
||||
Span<Complex64[]> kernelsSpan = Kernels.AsSpan();
|
||||
ref Complex64[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan);
|
||||
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
|
||||
|
||||
for (int i = 0; i < KernelParameters.Length; i++)
|
||||
{
|
||||
var kernels = new Complex64[KernelParameters.Length][];
|
||||
ref Vector4 baseRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
|
||||
for (int i = 0; i < KernelParameters.Length; i++)
|
||||
ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i);
|
||||
int length = kernelRef.Length;
|
||||
ref Complex64 valueRef = ref kernelRef[0];
|
||||
ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i);
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
{
|
||||
ref Vector4 paramsRef = ref Unsafe.Add(ref baseRef, i);
|
||||
kernels[i] = CreateComplex1DKernel(paramsRef.X, paramsRef.Y);
|
||||
}
|
||||
|
||||
return kernels;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a complex 1D kernel with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="a">The exponential parameter for each complex component.</param>
|
||||
/// <param name="b">The angle component for each complex component.</param>
|
||||
private Complex64[] CreateComplex1DKernel(float a, float b)
|
||||
{
|
||||
var kernel = new Complex64[KernelSize];
|
||||
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel.AsSpan());
|
||||
int r = Radius, n = -r;
|
||||
|
||||
for (int i = 0; i < KernelSize; i++, n++)
|
||||
{
|
||||
// Incrementally compute the range values
|
||||
float value = n * KernelsScale * (1f / r);
|
||||
value *= value;
|
||||
|
||||
// Fill in the complex kernel values
|
||||
Unsafe.Add(ref baseRef, i) = new Complex64(
|
||||
MathF.Exp(-a * value) * MathF.Cos(b * value),
|
||||
MathF.Exp(-a * value) * MathF.Sin(b * value));
|
||||
}
|
||||
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes the kernels with respect to A * real + B * imaginary.
|
||||
/// </summary>
|
||||
private void NormalizeKernels()
|
||||
{
|
||||
// Calculate the complex weighted sum
|
||||
float total = 0;
|
||||
Span<Complex64[]> kernelsSpan = Kernels.AsSpan();
|
||||
ref Complex64[] baseKernelsRef = ref MemoryMarshal.GetReference(kernelsSpan);
|
||||
ref Vector4 baseParamsRef = ref MemoryMarshal.GetReference(KernelParameters.AsSpan());
|
||||
|
||||
for (int i = 0; i < KernelParameters.Length; i++)
|
||||
{
|
||||
ref Complex64[] kernelRef = ref Unsafe.Add(ref baseKernelsRef, i);
|
||||
int length = kernelRef.Length;
|
||||
ref Complex64 valueRef = ref kernelRef[0];
|
||||
ref Vector4 paramsRef = ref Unsafe.Add(ref baseParamsRef, i);
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
for (int k = 0; k < length; k++)
|
||||
{
|
||||
for (int k = 0; k < length; k++)
|
||||
{
|
||||
ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j);
|
||||
ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k);
|
||||
total +=
|
||||
paramsRef.Z * (jRef.Real * kRef.Real - jRef.Imaginary * kRef.Imaginary)
|
||||
+ paramsRef.W * (jRef.Real * kRef.Imaginary + jRef.Imaginary * kRef.Real);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize the kernels
|
||||
float scalar = 1f / MathF.Sqrt(total);
|
||||
for (int i = 0; i < kernelsSpan.Length; i++)
|
||||
{
|
||||
ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i);
|
||||
int length = kernelsRef.Length;
|
||||
ref Complex64 valueRef = ref kernelsRef[0];
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
{
|
||||
Unsafe.Add(ref valueRef, j) *= scalar;
|
||||
ref Complex64 jRef = ref Unsafe.Add(ref valueRef, j);
|
||||
ref Complex64 kRef = ref Unsafe.Add(ref valueRef, k);
|
||||
total +=
|
||||
paramsRef.Z * (jRef.Real * kRef.Real - jRef.Imaginary * kRef.Imaginary)
|
||||
+ paramsRef.W * (jRef.Real * kRef.Imaginary + jRef.Imaginary * kRef.Real);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize the kernels
|
||||
float scalar = 1f / MathF.Sqrt(total);
|
||||
for (int i = 0; i < kernelsSpan.Length; i++)
|
||||
{
|
||||
ref Complex64[] kernelsRef = ref Unsafe.Add(ref baseKernelsRef, i);
|
||||
int length = kernelsRef.Length;
|
||||
ref Complex64 valueRef = ref kernelsRef[0];
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
{
|
||||
Unsafe.Add(ref valueRef, j) *= scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
|
||||
{
|
||||
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
|
||||
}
|
||||
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
|
||||
using ReadWriteTexture2D<Vector4> reals = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
|
||||
// Preliminary gamma highlight pass
|
||||
GraphicsDevice.For<GammaHighlightProcessor>(source.Height, new(texture));
|
||||
|
||||
// Perform two 1D convolutions for each component in the current instance
|
||||
for (int j = 0; j < Kernels.Length; j++)
|
||||
{
|
||||
Vector4 parameters = KernelParameters[j];
|
||||
|
||||
kernel.CopyFrom(Kernels[j]);
|
||||
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(texture, reals, imaginaries, kernel));
|
||||
|
||||
GraphicsDevice.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
|
||||
}
|
||||
|
||||
// Apply the inverse gamma exposure pass
|
||||
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
|
||||
|
||||
// Write the final pixel data
|
||||
texture.CopyTo(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public IReadWriteTexture2D<Vector4> source;
|
||||
public ReadWriteTexture2D<Vector4> reals;
|
||||
public ReadWriteTexture2D<Vector4> imaginaries;
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
|
||||
public void Execute()
|
||||
{
|
||||
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
|
||||
Vector4 real = Vector4.Zero;
|
||||
Vector4 imaginary = Vector4.Zero;
|
||||
int maxY = source.Height;
|
||||
int maxX = source.Width;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusY = kernelLength >> 1;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
Complex64 factors = kernel[i];
|
||||
|
||||
real += factors.Real * color;
|
||||
imaginary += factors.Imaginary * color;
|
||||
}
|
||||
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
|
||||
using ReadWriteTexture2D<Vector4> reals = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
|
||||
// Preliminary gamma highlight pass
|
||||
GraphicsDevice.For<GammaHighlightProcessor>(source.Height, new(texture));
|
||||
|
||||
// Perform two 1D convolutions for each component in the current instance
|
||||
for (int j = 0; j < Kernels.Length; j++)
|
||||
{
|
||||
Vector4 parameters = KernelParameters[j];
|
||||
|
||||
kernel.CopyFrom(Kernels[j]);
|
||||
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(texture, reals, imaginaries, kernel));
|
||||
|
||||
GraphicsDevice.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
|
||||
}
|
||||
|
||||
// Apply the inverse gamma exposure pass
|
||||
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
|
||||
|
||||
// Write the final pixel data
|
||||
texture.CopyTo(span);
|
||||
reals[ThreadIds.XY] = real;
|
||||
imaginaries[ThreadIds.XY] = imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
|
||||
{
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
public ReadWriteTexture2D<Vector4> reals;
|
||||
public ReadWriteTexture2D<Vector4> imaginaries;
|
||||
public ReadWriteTexture2D<Vector4> target;
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
public IReadWriteTexture2D<Vector4> source;
|
||||
public ReadWriteTexture2D<Vector4> reals;
|
||||
public ReadWriteTexture2D<Vector4> imaginaries;
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
Vector4 real = Vector4.Zero;
|
||||
Vector4 imaginary = Vector4.Zero;
|
||||
int maxY = target.Height;
|
||||
int maxX = target.Width;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusX = kernelLength >> 1;
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
Vector4 real = Vector4.Zero;
|
||||
Vector4 imaginary = Vector4.Zero;
|
||||
int maxY = source.Height;
|
||||
int maxX = source.Width;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusY = kernelLength >> 1;
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 sourceReal = reals[offsetX, offsetY];
|
||||
Vector4 sourceImaginary = imaginaries[offsetX, offsetY];
|
||||
Complex64 factors = kernel[i];
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
Complex64 factors = kernel[i];
|
||||
real += factors.Real * sourceReal - factors.Imaginary * sourceImaginary;
|
||||
imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
|
||||
}
|
||||
|
||||
real += factors.Real * color;
|
||||
imaginary += factors.Imaginary * color;
|
||||
}
|
||||
target[ThreadIds.XY] += real * z + imaginary * w;
|
||||
}
|
||||
}
|
||||
|
||||
reals[ThreadIds.XY] = real;
|
||||
imaginaries[ThreadIds.XY] = imaginary;
|
||||
/// <summary>
|
||||
/// Kernel for the gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct GammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
int width = source.Width;
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float4 v = source[i, ThreadIds.X];
|
||||
|
||||
v.XYZ = v.XYZ * v.XYZ * v.XYZ;
|
||||
|
||||
source[i, ThreadIds.X] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
|
||||
/// <summary>
|
||||
/// Kernel for the inverse gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
public float z;
|
||||
public float w;
|
||||
int width = source.Width;
|
||||
|
||||
public ReadWriteTexture2D<Vector4> reals;
|
||||
public ReadWriteTexture2D<Vector4> imaginaries;
|
||||
public ReadWriteTexture2D<Vector4> target;
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
Vector4 real = Vector4.Zero;
|
||||
Vector4 imaginary = Vector4.Zero;
|
||||
int maxY = target.Height;
|
||||
int maxX = target.Width;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusX = kernelLength >> 1;
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
float4 v = source[i, ThreadIds.X];
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 sourceReal = reals[offsetX, offsetY];
|
||||
Vector4 sourceImaginary = imaginaries[offsetX, offsetY];
|
||||
Complex64 factors = kernel[i];
|
||||
v = Hlsl.Clamp(v, 0, float.MaxValue);
|
||||
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
|
||||
|
||||
real += factors.Real * sourceReal - factors.Imaginary * sourceImaginary;
|
||||
imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
|
||||
}
|
||||
|
||||
target[ThreadIds.XY] += real * z + imaginary * w;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct GammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
int width = source.Width;
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float4 v = source[i, ThreadIds.X];
|
||||
|
||||
v.XYZ = v.XYZ * v.XYZ * v.XYZ;
|
||||
|
||||
source[i, ThreadIds.X] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the inverse gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
int width = source.Width;
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
float4 v = source[i, ThreadIds.X];
|
||||
|
||||
v = Hlsl.Clamp(v, 0, float.MaxValue);
|
||||
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
|
||||
|
||||
target[i, ThreadIds.X] = v;
|
||||
}
|
||||
target[i, ThreadIds.X] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,85 +5,84 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// Defines Gaussian blur by a (Sigma, Radius) pair.
|
||||
/// </summary>
|
||||
public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines Gaussian blur by a (Sigma, Radius) pair.
|
||||
/// The default value for <see cref="Sigma"/>.
|
||||
/// </summary>
|
||||
public sealed partial class HlslGaussianBlurProcessor : IImageProcessor
|
||||
public const float DefaultSigma = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslGaussianBlurProcessor()
|
||||
: this(Gpu.Default, DefaultSigma, 9)
|
||||
{
|
||||
/// <summary>
|
||||
/// The default value for <see cref="Sigma"/>.
|
||||
/// </summary>
|
||||
public const float DefaultSigma = 3f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslGaussianBlurProcessor()
|
||||
: this(Gpu.Default, DefaultSigma, 9)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(int radius)
|
||||
: this(Gpu.Default, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
|
||||
: this(device, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="sigma"> The sigma value representing the weight of the blur. </param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample (this should be at least twice the sigma value)</param>
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Sigma = sigma;
|
||||
Radius = radius;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sigma value representing the weight of the blur.
|
||||
/// </summary>
|
||||
public float Sigma { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the radius defining the size of the area to sample.
|
||||
/// </summary>
|
||||
public int Radius { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
|
||||
where TPixel : unmanaged, IPixel<TPixel>
|
||||
{
|
||||
if (typeof(TPixel) != typeof(ImageSharpRgba32))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(int radius)
|
||||
: this(Gpu.Default, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
|
||||
: this(device, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="sigma"> The sigma value representing the weight of the blur. </param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample (this should be at least twice the sigma value)</param>
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Sigma = sigma;
|
||||
Radius = radius;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sigma value representing the weight of the blur.
|
||||
/// </summary>
|
||||
public float Sigma { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the radius defining the size of the area to sample.
|
||||
/// </summary>
|
||||
public int Radius { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
|
||||
where TPixel : unmanaged, IPixel<TPixel>
|
||||
{
|
||||
if (typeof(TPixel) != typeof(ImageSharpRgba32))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("This processor only supports the RGBA32 pixel format");
|
||||
}
|
||||
|
||||
var processor = new Implementation(this, configuration, Unsafe.As<Image<ImageSharpRgba32>>(source), sourceRectangle);
|
||||
|
||||
return Unsafe.As<IImageProcessor<TPixel>>(processor);
|
||||
}
|
||||
return Unsafe.As<IImageProcessor<TPixel>>(processor);
|
||||
}
|
||||
}
|
||||
+136
-137
@@ -7,172 +7,171 @@ using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.BokehBlur.Processors
|
||||
namespace ComputeSharp.BokehBlur.Processors;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class HlslGaussianBlurProcessor
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class HlslGaussianBlurProcessor
|
||||
/// <summary>
|
||||
/// Applies Gaussian blur processing to an image.
|
||||
/// </summary>
|
||||
internal sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies Gaussian blur processing to an image.
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
internal sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The 1D kernel to apply.
|
||||
/// </summary>
|
||||
private readonly float[] Kernel;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Implementation"/> class.
|
||||
/// </summary>
|
||||
/// <param name="definition">The <see cref="Implementation"/> defining the processor parameters.</param>
|
||||
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
|
||||
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
|
||||
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
|
||||
public Implementation(HlslGaussianBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
|
||||
: base(configuration, source, sourceRectangle)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
int kernelSize = definition.Radius * 2 + 1;
|
||||
|
||||
/// <summary>
|
||||
/// The 1D kernel to apply.
|
||||
/// </summary>
|
||||
private readonly float[] Kernel;
|
||||
GraphicsDevice = definition.GraphicsDevice;
|
||||
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Implementation"/> class.
|
||||
/// </summary>
|
||||
/// <param name="definition">The <see cref="Implementation"/> defining the processor parameters.</param>
|
||||
/// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param>
|
||||
/// <param name="source">The source <see cref="Image{TPixel}"/> for the current processor instance.</param>
|
||||
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
|
||||
public Implementation(HlslGaussianBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> source, Rectangle sourceRectangle)
|
||||
: base(configuration, source, sourceRectangle)
|
||||
/// <summary>
|
||||
/// Creates a 1 dimensional Gaussian kernel using the Gaussian G(x) function.
|
||||
/// </summary>
|
||||
private static float[] CreateGaussianBlurKernel(int size, float weight)
|
||||
{
|
||||
float[] kernel = new float[size];
|
||||
ref float rKernel = ref kernel[0];
|
||||
|
||||
float sum = 0F;
|
||||
float midpoint = (size - 1) / 2F;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
int kernelSize = definition.Radius * 2 + 1;
|
||||
|
||||
GraphicsDevice = definition.GraphicsDevice;
|
||||
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
|
||||
float x = i - midpoint;
|
||||
float gx = Gaussian(x, weight);
|
||||
sum += gx;
|
||||
Unsafe.Add(ref rKernel, i) = gx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a 1 dimensional Gaussian kernel using the Gaussian G(x) function.
|
||||
/// </summary>
|
||||
private static float[] CreateGaussianBlurKernel(int size, float weight)
|
||||
// Normalize kernel so that the sum of all weights equals 1
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float[] kernel = new float[size];
|
||||
ref float rKernel = ref kernel[0];
|
||||
|
||||
float sum = 0F;
|
||||
float midpoint = (size - 1) / 2F;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float x = i - midpoint;
|
||||
float gx = Gaussian(x, weight);
|
||||
sum += gx;
|
||||
Unsafe.Add(ref rKernel, i) = gx;
|
||||
}
|
||||
|
||||
// Normalize kernel so that the sum of all weights equals 1
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Unsafe.Add(ref rKernel, i) /= sum;
|
||||
}
|
||||
|
||||
return kernel;
|
||||
Unsafe.Add(ref rKernel, i) /= sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of 1D Gaussian G(x) function.
|
||||
/// </summary>
|
||||
/// <param name="x">The x provided to G(x)</param>
|
||||
/// <param name="sigma">The spread of the blur.</param>
|
||||
/// <returns>The Gaussian G(x)</returns>
|
||||
private static float Gaussian(float x, float sigma)
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of 1D Gaussian G(x) function.
|
||||
/// </summary>
|
||||
/// <param name="x">The x provided to G(x)</param>
|
||||
/// <param name="sigma">The spread of the blur.</param>
|
||||
/// <returns>The Gaussian G(x)</returns>
|
||||
private static float Gaussian(float x, float sigma)
|
||||
{
|
||||
const float Numerator = 1.0f;
|
||||
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma;
|
||||
|
||||
float exponentNumerator = -x * x;
|
||||
float exponentDenominator = 2 * sigma * sigma;
|
||||
|
||||
float left = Numerator / denominator;
|
||||
float right = MathF.Exp(exponentNumerator / exponentDenominator);
|
||||
|
||||
return left * right;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
|
||||
{
|
||||
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
|
||||
{
|
||||
const float Numerator = 1.0f;
|
||||
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma;
|
||||
|
||||
float exponentNumerator = -x * x;
|
||||
float exponentDenominator = 2 * sigma * sigma;
|
||||
|
||||
float left = Numerator / denominator;
|
||||
float right = MathF.Exp(exponentNumerator / exponentDenominator);
|
||||
|
||||
return left * right;
|
||||
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
|
||||
}
|
||||
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
|
||||
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
|
||||
GraphicsDevice.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
|
||||
|
||||
sourceTexture.CopyTo(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnFrameApply(ImageFrame<ImageSharpRgba32> source)
|
||||
public void Execute()
|
||||
{
|
||||
if (!source.TryGetSinglePixelSpan(out Span<ImageSharpRgba32> pixelSpan))
|
||||
Vector4 result = Vector4.Zero;
|
||||
int maxY = source.Height - 1;
|
||||
int maxX = source.Width - 1;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusY = kernelLength >> 1;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory");
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
|
||||
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
|
||||
GraphicsDevice.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
|
||||
|
||||
sourceTexture.CopyTo(span);
|
||||
target[ThreadIds.XY] = result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
Vector4 result = Vector4.Zero;
|
||||
int maxY = source.Height - 1;
|
||||
int maxX = source.Width - 1;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusX = kernelLength >> 1;
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
Vector4 result = Vector4.Zero;
|
||||
int maxY = source.Height - 1;
|
||||
int maxX = source.Width - 1;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusY = kernelLength >> 1;
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
target[ThreadIds.XY] = result;
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
Vector4 result = Vector4.Zero;
|
||||
int maxY = source.Height - 1;
|
||||
int maxX = source.Width - 1;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusX = kernelLength >> 1;
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
target[ThreadIds.XY] = result;
|
||||
}
|
||||
target[ThreadIds.XY] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,32 +7,31 @@ using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Processing.Processors;
|
||||
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
|
||||
|
||||
namespace ComputeSharp.ImageProcessing
|
||||
namespace ComputeSharp.ImageProcessing;
|
||||
|
||||
class Program
|
||||
{
|
||||
class Program
|
||||
static void Main()
|
||||
{
|
||||
static void Main()
|
||||
Console.WriteLine(">> Loading image");
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "city.jpg");
|
||||
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(path);
|
||||
|
||||
// Apply a series of processors and save the results
|
||||
foreach (var effect in new (string Name, IImageProcessor Processor)[]
|
||||
{
|
||||
Console.WriteLine(">> Loading image");
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "city.jpg");
|
||||
using Image<ImageSharpRgba32> image = Image.Load<ImageSharpRgba32>(path);
|
||||
("bokeh", new HlslBokehBlurProcessor(80, 2)),
|
||||
("gaussian", new HlslGaussianBlurProcessor(80))
|
||||
})
|
||||
{
|
||||
Console.WriteLine($">> Applying {effect.Name}");
|
||||
using Image copy = image.Clone(c => c.ApplyProcessor(effect.Processor));
|
||||
|
||||
// Apply a series of processors and save the results
|
||||
foreach (var effect in new (string Name, IImageProcessor Processor)[]
|
||||
{
|
||||
("bokeh", new HlslBokehBlurProcessor(80, 2)),
|
||||
("gaussian", new HlslGaussianBlurProcessor(80))
|
||||
})
|
||||
{
|
||||
Console.WriteLine($">> Applying {effect.Name}");
|
||||
using Image copy = image.Clone(c => c.ApplyProcessor(effect.Processor));
|
||||
|
||||
Console.WriteLine($">> Saving {effect.Name} to disk");
|
||||
string targetPath = Path.Combine(
|
||||
Path.GetRelativePath(Path.GetDirectoryName(path)!, @"..\..\..\"),
|
||||
$"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}");
|
||||
copy.Save(targetPath);
|
||||
}
|
||||
Console.WriteLine($">> Saving {effect.Name} to disk");
|
||||
string targetPath = Path.Combine(
|
||||
Path.GetRelativePath(Path.GetDirectoryName(path)!, @"..\..\..\"),
|
||||
$"{Path.GetFileNameWithoutExtension(path)}_{effect.Name}{Path.GetExtension(path)}");
|
||||
copy.Save(targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
namespace ComputeSharp.Sample.FSharp.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// A sample shader thaat just multiplies items in a buffer by two.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
public readonly partial struct MultiplyByTwo : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
namespace ComputeSharp.Sample.FSharp.Shaders;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
/// <summary>
|
||||
/// A sample shader thaat just multiplies items in a buffer by two.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
public readonly partial struct MultiplyByTwo : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
@@ -2,71 +2,69 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace ComputeSharp.Sample
|
||||
namespace ComputeSharp.Sample;
|
||||
|
||||
partial class Program
|
||||
{
|
||||
partial class Program
|
||||
static void Main()
|
||||
{
|
||||
static void Main()
|
||||
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
|
||||
// Create the graphics buffer
|
||||
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
Gpu.Default.For(100, new MainKernel(gpuBuffer));
|
||||
|
||||
// Print the initial matrix
|
||||
PrintMatrix(array, 10, 10, "BEFORE");
|
||||
|
||||
// Get the data back
|
||||
gpuBuffer.CopyTo(array);
|
||||
|
||||
// Print the updated matrix
|
||||
PrintMatrix(array, 10, 10, "AFTER");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for <see cref="Main"/>.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MainKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray();
|
||||
|
||||
// Create the graphics buffer
|
||||
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
Gpu.Default.For(100, new MainKernel(gpuBuffer));
|
||||
|
||||
// Print the initial matrix
|
||||
PrintMatrix(array, 10, 10, "BEFORE");
|
||||
|
||||
// Get the data back
|
||||
gpuBuffer.CopyTo(array);
|
||||
|
||||
// Print the updated matrix
|
||||
PrintMatrix(array, 10, 10, "AFTER");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for <see cref="Main"/>.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MainKernel : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a matrix in a properly formatted way.
|
||||
/// </summary>
|
||||
/// <param name="array">The input <see langword="float"/> array representing the matrix to print.</param>
|
||||
/// <param name="width">The width of the array to print.</param>
|
||||
/// <param name="height">The height of the array to print.</param>
|
||||
/// <param name="name">The name of the matrix to print.</param>
|
||||
private static void PrintMatrix(float[] array, int width, int height, string name)
|
||||
{
|
||||
int pad = 48 - name.Length;
|
||||
string title = $"{new string('=', pad / 2)} {name} {new string('=', (pad + 1) / 2)}";
|
||||
|
||||
Console.WriteLine(title);
|
||||
|
||||
int numberWidth = Math.Max(array.Max().ToString(CultureInfo.InvariantCulture).Length, 4);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
var row = array[(i * width)..((i + 1) * width)];
|
||||
var text = string.Join(",", row.Select(x => x.ToString(CultureInfo.InvariantCulture).PadLeft(numberWidth)));
|
||||
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
|
||||
Console.WriteLine(new string('=', 50));
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a matrix in a properly formatted way.
|
||||
/// </summary>
|
||||
/// <param name="array">The input <see langword="float"/> array representing the matrix to print.</param>
|
||||
/// <param name="width">The width of the array to print.</param>
|
||||
/// <param name="height">The height of the array to print.</param>
|
||||
/// <param name="name">The name of the matrix to print.</param>
|
||||
private static void PrintMatrix(float[] array, int width, int height, string name)
|
||||
{
|
||||
int pad = 48 - name.Length;
|
||||
string title = $"{new string('=', pad / 2)} {name} {new string('=', (pad + 1) / 2)}";
|
||||
|
||||
Console.WriteLine(title);
|
||||
|
||||
int numberWidth = Math.Max(array.Max().ToString(CultureInfo.InvariantCulture).Length, 4);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
var row = array[(i * width)..((i + 1) * width)];
|
||||
var text = string.Join(",", row.Select(x => x.ToString(CultureInfo.InvariantCulture).PadLeft(numberWidth)));
|
||||
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
|
||||
Console.WriteLine(new string('=', 50));
|
||||
}
|
||||
}
|
||||
@@ -3,301 +3,300 @@ using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Backend
|
||||
namespace ComputeSharp.SwapChain.Backend;
|
||||
|
||||
internal sealed class SwapChainApplication<T> : Win32Application
|
||||
where T : struct, IPixelShader<float4>
|
||||
{
|
||||
internal sealed class SwapChainApplication<T> : Win32Application
|
||||
where T : struct, IPixelShader<float4>
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
private readonly Func<TimeSpan, T> shaderFactory;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Device> d3D12Device;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandQueue"/> instance to use for graphics operations.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12CommandQueue> d3D12CommandQueue;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Fence"/> instance used for graphics operations.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Fence> d3D12Fence;
|
||||
|
||||
/// <summary>
|
||||
/// The next fence value for graphics operations using <see cref="d3D12CommandQueue"/>.
|
||||
/// </summary>
|
||||
private ulong nextD3D12FenceValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandAllocator"/> object to create command lists.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> instance used to copy data to the back buffers.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDXGISwapChain1"/> instance used to display content onto the target window.
|
||||
/// </summary>
|
||||
private ComPtr<IDXGISwapChain1> dxgiSwapChain1;
|
||||
|
||||
/// <summary>
|
||||
/// The first buffer within <see cref="dxgiSwapChain1"/>.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Resource> d3D12Resource0;
|
||||
|
||||
/// <summary>
|
||||
/// The second buffer within <see cref="dxgiSwapChain1"/>.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Resource> d3D12Resource1;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the next buffer that can be used to present content.
|
||||
/// </summary>
|
||||
private uint currentBufferIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ReadWriteTexture2D{T, TPixel}"/> instance used to prepare frames to display.
|
||||
/// </summary>
|
||||
private ReadWriteTexture2D<Rgba32, float4>? texture;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the window has been resized and requires the buffers to be updated.
|
||||
/// </summary>
|
||||
private bool isResizePending;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SwapChainApplication"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.</param>
|
||||
public SwapChainApplication(Func<TimeSpan, T> shaderFactory)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
private readonly Func<TimeSpan, T> shaderFactory;
|
||||
this.shaderFactory = shaderFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Device"/> pointer for the device currently in use.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Device> d3D12Device;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandQueue"/> instance to use for graphics operations.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12CommandQueue> d3D12CommandQueue;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Fence"/> instance used for graphics operations.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Fence> d3D12Fence;
|
||||
|
||||
/// <summary>
|
||||
/// The next fence value for graphics operations using <see cref="d3D12CommandQueue"/>.
|
||||
/// </summary>
|
||||
private ulong nextD3D12FenceValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12CommandAllocator"/> object to create command lists.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12CommandAllocator> d3D12CommandAllocator;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> instance used to copy data to the back buffers.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12GraphicsCommandList> d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IDXGISwapChain1"/> instance used to display content onto the target window.
|
||||
/// </summary>
|
||||
private ComPtr<IDXGISwapChain1> dxgiSwapChain1;
|
||||
|
||||
/// <summary>
|
||||
/// The first buffer within <see cref="dxgiSwapChain1"/>.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Resource> d3D12Resource0;
|
||||
|
||||
/// <summary>
|
||||
/// The second buffer within <see cref="dxgiSwapChain1"/>.
|
||||
/// </summary>
|
||||
private ComPtr<ID3D12Resource> d3D12Resource1;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the next buffer that can be used to present content.
|
||||
/// </summary>
|
||||
private uint currentBufferIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ReadWriteTexture2D{T, TPixel}"/> instance used to prepare frames to display.
|
||||
/// </summary>
|
||||
private ReadWriteTexture2D<Rgba32, float4>? texture;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the window has been resized and requires the buffers to be updated.
|
||||
/// </summary>
|
||||
private bool isResizePending;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SwapChainApplication"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.</param>
|
||||
public SwapChainApplication(Func<TimeSpan, T> shaderFactory)
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnInitialize(HWND hwnd)
|
||||
{
|
||||
// Get the underlying ID3D12Device in use
|
||||
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
|
||||
{
|
||||
this.shaderFactory = shaderFactory;
|
||||
_ = InteropServices.TryGetID3D12Device(Gpu.Default, FX.__uuidof<ID3D12Device>(), (void**)d3D12Device);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnInitialize(HWND hwnd)
|
||||
// Create the direct command queue to use
|
||||
fixed (ID3D12CommandQueue** d3D12CommandQueue = this.d3D12CommandQueue)
|
||||
{
|
||||
// Get the underlying ID3D12Device in use
|
||||
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
|
||||
{
|
||||
_ = InteropServices.TryGetID3D12Device(Gpu.Default, FX.__uuidof<ID3D12Device>(), (void**)d3D12Device);
|
||||
}
|
||||
D3D12_COMMAND_QUEUE_DESC d3D12CommandQueueDesc;
|
||||
d3D12CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
d3D12CommandQueueDesc.Priority = (int)D3D12_COMMAND_QUEUE_PRIORITY.D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
|
||||
d3D12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAGS.D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
d3D12CommandQueueDesc.NodeMask = 0;
|
||||
|
||||
// Create the direct command queue to use
|
||||
fixed (ID3D12CommandQueue** d3D12CommandQueue = this.d3D12CommandQueue)
|
||||
{
|
||||
D3D12_COMMAND_QUEUE_DESC d3D12CommandQueueDesc;
|
||||
d3D12CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
d3D12CommandQueueDesc.Priority = (int)D3D12_COMMAND_QUEUE_PRIORITY.D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
|
||||
d3D12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAGS.D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
d3D12CommandQueueDesc.NodeMask = 0;
|
||||
|
||||
_ = d3D12Device.Get()->CreateCommandQueue(
|
||||
&d3D12CommandQueueDesc,
|
||||
FX.__uuidof<ID3D12CommandQueue>(),
|
||||
(void**)d3D12CommandQueue);
|
||||
}
|
||||
|
||||
// Create the direct fence
|
||||
fixed (ID3D12Fence** d3D12Fence = this.d3D12Fence)
|
||||
{
|
||||
_ = this.d3D12Device.Get()->CreateFence(
|
||||
0,
|
||||
D3D12_FENCE_FLAGS.D3D12_FENCE_FLAG_NONE,
|
||||
FX.__uuidof<ID3D12Fence>(),
|
||||
(void**)d3D12Fence);
|
||||
}
|
||||
|
||||
// Create the swap chain to display frames
|
||||
fixed (IDXGISwapChain1** dxgiSwapChain1 = this.dxgiSwapChain1)
|
||||
{
|
||||
using ComPtr<IDXGIFactory2> dxgiFactory2 = default;
|
||||
|
||||
_ = FX.CreateDXGIFactory2(FX.DXGI_CREATE_FACTORY_DEBUG, FX.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf());
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
|
||||
dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE;
|
||||
dxgiSwapChainDesc1.BufferCount = 2;
|
||||
dxgiSwapChainDesc1.Flags = 0;
|
||||
dxgiSwapChainDesc1.Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
dxgiSwapChainDesc1.Width = 0;
|
||||
dxgiSwapChainDesc1.Height = 0;
|
||||
dxgiSwapChainDesc1.SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0);
|
||||
dxgiSwapChainDesc1.Scaling = DXGI_SCALING.DXGI_SCALING_STRETCH;
|
||||
dxgiSwapChainDesc1.Stereo = 0;
|
||||
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
|
||||
_ = dxgiFactory2.Get()->CreateSwapChainForHwnd(
|
||||
(IUnknown*)d3D12CommandQueue.Get(),
|
||||
hwnd,
|
||||
&dxgiSwapChainDesc1,
|
||||
null,
|
||||
null,
|
||||
dxgiSwapChain1);
|
||||
}
|
||||
|
||||
// Create the command allocator to use
|
||||
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
|
||||
{
|
||||
this.d3D12Device.Get()->CreateCommandAllocator(
|
||||
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
FX.__uuidof<ID3D12CommandAllocator>(),
|
||||
(void**)d3D12CommandAllocator);
|
||||
}
|
||||
|
||||
// Create the reusable command list to copy data to the back buffers
|
||||
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
|
||||
{
|
||||
this.d3D12Device.Get()->CreateCommandList(
|
||||
0,
|
||||
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
d3D12CommandAllocator,
|
||||
null,
|
||||
FX.__uuidof<ID3D12GraphicsCommandList>(),
|
||||
(void**)d3D12GraphicsCommandList);
|
||||
}
|
||||
|
||||
// Close the command list to prepare it for future use
|
||||
this.d3D12GraphicsCommandList.Get()->Close();
|
||||
_ = d3D12Device.Get()->CreateCommandQueue(
|
||||
&d3D12CommandQueueDesc,
|
||||
FX.__uuidof<ID3D12CommandQueue>(),
|
||||
(void**)d3D12CommandQueue);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnResize()
|
||||
// Create the direct fence
|
||||
fixed (ID3D12Fence** d3D12Fence = this.d3D12Fence)
|
||||
{
|
||||
this.isResizePending = true;
|
||||
_ = this.d3D12Device.Get()->CreateFence(
|
||||
0,
|
||||
D3D12_FENCE_FLAGS.D3D12_FENCE_FLAG_NONE,
|
||||
FX.__uuidof<ID3D12Fence>(),
|
||||
(void**)d3D12Fence);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the actual resize logic that was scheduled from <see cref="OnResize"/>.
|
||||
/// </summary>
|
||||
private unsafe void ApplyResize()
|
||||
// Create the swap chain to display frames
|
||||
fixed (IDXGISwapChain1** dxgiSwapChain1 = this.dxgiSwapChain1)
|
||||
{
|
||||
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
|
||||
using ComPtr<IDXGIFactory2> dxgiFactory2 = default;
|
||||
|
||||
// Wait for the fence again to ensure there are no pending operations
|
||||
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
|
||||
_ = FX.CreateDXGIFactory2(FX.DXGI_CREATE_FACTORY_DEBUG, FX.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf());
|
||||
|
||||
this.nextD3D12FenceValue++;
|
||||
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
|
||||
dxgiSwapChainDesc1.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_IGNORE;
|
||||
dxgiSwapChainDesc1.BufferCount = 2;
|
||||
dxgiSwapChainDesc1.Flags = 0;
|
||||
dxgiSwapChainDesc1.Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
dxgiSwapChainDesc1.Width = 0;
|
||||
dxgiSwapChainDesc1.Height = 0;
|
||||
dxgiSwapChainDesc1.SampleDesc = new DXGI_SAMPLE_DESC(count: 1, quality: 0);
|
||||
dxgiSwapChainDesc1.Scaling = DXGI_SCALING.DXGI_SCALING_STRETCH;
|
||||
dxgiSwapChainDesc1.Stereo = 0;
|
||||
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
|
||||
// Dispose the old buffers before resizing the buffer
|
||||
this.d3D12Resource0.Dispose();
|
||||
this.d3D12Resource1.Dispose();
|
||||
|
||||
// Resize the swap chain buffers
|
||||
this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
|
||||
|
||||
// Get the index of the initial back buffer
|
||||
using (ComPtr<IDXGISwapChain3> dxgiSwapChain3 = default)
|
||||
{
|
||||
_ = this.dxgiSwapChain1.CopyTo(dxgiSwapChain3.GetAddressOf());
|
||||
|
||||
this.currentBufferIndex = dxgiSwapChain3.Get()->GetCurrentBackBufferIndex();
|
||||
}
|
||||
|
||||
// Retrieve the back buffers for the swap chain
|
||||
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
|
||||
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
|
||||
}
|
||||
|
||||
this.texture?.Dispose();
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
|
||||
|
||||
// Create the 2D texture to use to generate frames to display
|
||||
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, float4>(
|
||||
(int)d3D12Resource0Description.Width,
|
||||
(int)d3D12Resource0Description.Height);
|
||||
_ = dxgiFactory2.Get()->CreateSwapChainForHwnd(
|
||||
(IUnknown*)d3D12CommandQueue.Get(),
|
||||
hwnd,
|
||||
&dxgiSwapChainDesc1,
|
||||
null,
|
||||
null,
|
||||
dxgiSwapChain1);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnUpdate(TimeSpan time)
|
||||
// Create the command allocator to use
|
||||
fixed (ID3D12CommandAllocator** d3D12CommandAllocator = this.d3D12CommandAllocator)
|
||||
{
|
||||
if (this.isResizePending)
|
||||
{
|
||||
ApplyResize();
|
||||
this.d3D12Device.Get()->CreateCommandAllocator(
|
||||
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
FX.__uuidof<ID3D12CommandAllocator>(),
|
||||
(void**)d3D12CommandAllocator);
|
||||
}
|
||||
|
||||
this.isResizePending = false;
|
||||
}
|
||||
// Create the reusable command list to copy data to the back buffers
|
||||
fixed (ID3D12GraphicsCommandList** d3D12GraphicsCommandList = this.d3D12GraphicsCommandList)
|
||||
{
|
||||
this.d3D12Device.Get()->CreateCommandList(
|
||||
0,
|
||||
D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
d3D12CommandAllocator,
|
||||
null,
|
||||
FX.__uuidof<ID3D12GraphicsCommandList>(),
|
||||
(void**)d3D12GraphicsCommandList);
|
||||
}
|
||||
|
||||
// Generate the new frame
|
||||
Gpu.Default.ForEach(this.texture!, this.shaderFactory(time));
|
||||
// Close the command list to prepare it for future use
|
||||
this.d3D12GraphicsCommandList.Get()->Close();
|
||||
}
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnResize()
|
||||
{
|
||||
this.isResizePending = true;
|
||||
}
|
||||
|
||||
// Get the underlying ID3D12Resource pointer for the texture
|
||||
_ = InteropServices.TryGetID3D12Resource(this.texture!, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
|
||||
/// <summary>
|
||||
/// Applies the actual resize logic that was scheduled from <see cref="OnResize"/>.
|
||||
/// </summary>
|
||||
private unsafe void ApplyResize()
|
||||
{
|
||||
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
|
||||
|
||||
// Get the target back buffer to update
|
||||
ID3D12Resource* d3D12ResourceBackBuffer = this.currentBufferIndex switch
|
||||
{
|
||||
0 => this.d3D12Resource0.Get(),
|
||||
1 => this.d3D12Resource1.Get(),
|
||||
_ => null
|
||||
};
|
||||
// Wait for the fence again to ensure there are no pending operations
|
||||
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
|
||||
|
||||
this.currentBufferIndex ^= 1;
|
||||
this.nextD3D12FenceValue++;
|
||||
|
||||
// Reset the command list and command allocator
|
||||
this.d3D12CommandAllocator.Get()->Reset();
|
||||
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
|
||||
// Dispose the old buffers before resizing the buffer
|
||||
this.d3D12Resource0.Dispose();
|
||||
this.d3D12Resource1.Dispose();
|
||||
|
||||
D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12Resource.Get(),
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE),
|
||||
D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12ResourceBackBuffer,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST)
|
||||
};
|
||||
// Resize the swap chain buffers
|
||||
this.dxgiSwapChain1.Get()->ResizeBuffers(0, 0, 0, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, 0);
|
||||
|
||||
// Transition the resources to COPY_DEST and COPY_SOURCE respectively
|
||||
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
|
||||
// Get the index of the initial back buffer
|
||||
using (ComPtr<IDXGISwapChain3> dxgiSwapChain3 = default)
|
||||
{
|
||||
_ = this.dxgiSwapChain1.CopyTo(dxgiSwapChain3.GetAddressOf());
|
||||
|
||||
// Copy the generated frame to the target back buffer
|
||||
d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
|
||||
this.currentBufferIndex = dxgiSwapChain3.Get()->GetCurrentBackBufferIndex();
|
||||
}
|
||||
|
||||
d3D12ResourceBarriers[0] = D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
// Retrieve the back buffers for the swap chain
|
||||
fixed (ID3D12Resource** d3D12Resource0 = this.d3D12Resource0)
|
||||
fixed (ID3D12Resource** d3D12Resource1 = this.d3D12Resource1)
|
||||
{
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(0, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource0);
|
||||
_ = dxgiSwapChain1.Get()->GetBuffer(1, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource1);
|
||||
}
|
||||
|
||||
this.texture?.Dispose();
|
||||
|
||||
D3D12_RESOURCE_DESC d3D12Resource0Description = this.d3D12Resource0.Get()->GetDesc();
|
||||
|
||||
// Create the 2D texture to use to generate frames to display
|
||||
this.texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, float4>(
|
||||
(int)d3D12Resource0Description.Width,
|
||||
(int)d3D12Resource0Description.Height);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe void OnUpdate(TimeSpan time)
|
||||
{
|
||||
if (this.isResizePending)
|
||||
{
|
||||
ApplyResize();
|
||||
|
||||
this.isResizePending = false;
|
||||
}
|
||||
|
||||
// Generate the new frame
|
||||
Gpu.Default.ForEach(this.texture!, this.shaderFactory(time));
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
// Get the underlying ID3D12Resource pointer for the texture
|
||||
_ = InteropServices.TryGetID3D12Resource(this.texture!, FX.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
|
||||
|
||||
// Get the target back buffer to update
|
||||
ID3D12Resource* d3D12ResourceBackBuffer = this.currentBufferIndex switch
|
||||
{
|
||||
0 => this.d3D12Resource0.Get(),
|
||||
1 => this.d3D12Resource1.Get(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
this.currentBufferIndex ^= 1;
|
||||
|
||||
// Reset the command list and command allocator
|
||||
this.d3D12CommandAllocator.Get()->Reset();
|
||||
this.d3D12GraphicsCommandList.Get()->Reset(this.d3D12CommandAllocator.Get(), null);
|
||||
|
||||
D3D12_RESOURCE_BARRIER* d3D12ResourceBarriers = stackalloc D3D12_RESOURCE_BARRIER[]
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12Resource.Get(),
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
d3D12ResourceBarriers[1] = D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE),
|
||||
D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12ResourceBackBuffer,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON);
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST)
|
||||
};
|
||||
|
||||
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
|
||||
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
|
||||
// Transition the resources to COPY_DEST and COPY_SOURCE respectively
|
||||
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
|
||||
|
||||
d3D12GraphicsCommandList.Get()->Close();
|
||||
// Copy the generated frame to the target back buffer
|
||||
d3D12GraphicsCommandList.Get()->CopyResource(d3D12ResourceBackBuffer, d3D12Resource.Get());
|
||||
|
||||
// Execute the command list to perform the copy
|
||||
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)d3D12GraphicsCommandList.GetAddressOf());
|
||||
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
|
||||
d3D12ResourceBarriers[0] = D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12Resource.Get(),
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_SOURCE,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
// Present the new frame
|
||||
this.dxgiSwapChain1.Get()->Present(0, 0);
|
||||
d3D12ResourceBarriers[1] = D3D12_RESOURCE_BARRIER.InitTransition(
|
||||
d3D12ResourceBackBuffer,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
D3D12_RESOURCE_STATES.D3D12_RESOURCE_STATE_COMMON);
|
||||
|
||||
if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
|
||||
{
|
||||
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
|
||||
}
|
||||
// Transition the resources back to COMMON and UNORDERED_ACCESS respectively
|
||||
d3D12GraphicsCommandList.Get()->ResourceBarrier(2, d3D12ResourceBarriers);
|
||||
|
||||
this.nextD3D12FenceValue++;
|
||||
d3D12GraphicsCommandList.Get()->Close();
|
||||
|
||||
// Execute the command list to perform the copy
|
||||
this.d3D12CommandQueue.Get()->ExecuteCommandLists(1, (ID3D12CommandList**)d3D12GraphicsCommandList.GetAddressOf());
|
||||
this.d3D12CommandQueue.Get()->Signal(this.d3D12Fence.Get(), this.nextD3D12FenceValue);
|
||||
|
||||
// Present the new frame
|
||||
this.dxgiSwapChain1.Get()->Present(0, 0);
|
||||
|
||||
if (this.nextD3D12FenceValue > this.d3D12Fence.Get()->GetCompletedValue())
|
||||
{
|
||||
this.d3D12Fence.Get()->SetEventOnCompletion(this.nextD3D12FenceValue, default);
|
||||
}
|
||||
|
||||
this.nextD3D12FenceValue++;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,27 @@
|
||||
using System;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Backend
|
||||
namespace ComputeSharp.SwapChain.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// A class representing a simple Win32 application.
|
||||
/// </summary>
|
||||
internal abstract class Win32Application
|
||||
{
|
||||
/// <summary>
|
||||
/// A class representing a simple Win32 application.
|
||||
/// Initializes the current application.
|
||||
/// </summary>
|
||||
internal abstract class Win32Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the current application.
|
||||
/// </summary>
|
||||
/// <param name="hwnd">The handle for the window.</param>
|
||||
public abstract void OnInitialize(HWND hwnd);
|
||||
/// <param name="hwnd">The handle for the window.</param>
|
||||
public abstract void OnInitialize(HWND hwnd);
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the current application.
|
||||
/// </summary>
|
||||
public abstract void OnResize();
|
||||
/// <summary>
|
||||
/// Resizes the current application.
|
||||
/// </summary>
|
||||
public abstract void OnResize();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the current application.
|
||||
/// </summary>
|
||||
/// <param name="time">The current time since the start of the application.</param>
|
||||
public abstract void OnUpdate(TimeSpan time);
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the current application.
|
||||
/// </summary>
|
||||
/// <param name="time">The current time since the start of the application.</param>
|
||||
public abstract void OnUpdate(TimeSpan time);
|
||||
}
|
||||
@@ -7,95 +7,291 @@ using System.Threading;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Backend
|
||||
namespace ComputeSharp.SwapChain.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// A helper class to manage the creation and execution of Win32 applications.
|
||||
/// </summary>
|
||||
internal unsafe static class Win32ApplicationRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class to manage the creation and execution of Win32 applications.
|
||||
/// Whether or not a resize operation is in progress.
|
||||
/// </summary>
|
||||
internal unsafe static class Win32ApplicationRunner
|
||||
private static bool isResizing = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the application is currently paused.
|
||||
/// </summary>
|
||||
private static bool isPaused = false;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="HWND"/> for the application window.
|
||||
/// </summary>
|
||||
private static HWND hwnd;
|
||||
|
||||
/// <summary>
|
||||
/// The application being run.
|
||||
/// </summary>
|
||||
private static Win32Application application = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The thread running the render loop.
|
||||
/// </summary>
|
||||
private static Thread renderThread = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Runs a specified application and starts the main loop to update its state.
|
||||
/// This is the entry point for a given application of type <typeparamref name="T"/>, and it should be
|
||||
/// called as soon as the process is launched, excluding any other additional initialization needed.
|
||||
/// <para>To launch an application, simply add this line to the project being used:</para>
|
||||
/// <c>Win32ApplicationRunner.Run<MyApplication>();</c>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of application being launched.</typeparam>
|
||||
/// <returns>The exit code for the application.</returns>
|
||||
public static int Run(Win32Application application)
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether or not a resize operation is in progress.
|
||||
/// </summary>
|
||||
private static bool isResizing = false;
|
||||
Win32ApplicationRunner.application = application;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the application is currently paused.
|
||||
/// </summary>
|
||||
private static bool isPaused = false;
|
||||
IntPtr hInstance = FX.GetModuleHandleW(null);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="HWND"/> for the application window.
|
||||
/// </summary>
|
||||
private static HWND hwnd;
|
||||
|
||||
/// <summary>
|
||||
/// The application being run.
|
||||
/// </summary>
|
||||
private static Win32Application application = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The thread running the render loop.
|
||||
/// </summary>
|
||||
private static Thread renderThread = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Runs a specified application and starts the main loop to update its state.
|
||||
/// This is the entry point for a given application of type <typeparamref name="T"/>, and it should be
|
||||
/// called as soon as the process is launched, excluding any other additional initialization needed.
|
||||
/// <para>To launch an application, simply add this line to the project being used:</para>
|
||||
/// <c>Win32ApplicationRunner.Run<MyApplication>();</c>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of application being launched.</typeparam>
|
||||
/// <returns>The exit code for the application.</returns>
|
||||
public static int Run(Win32Application application)
|
||||
fixed (char* name = Assembly.GetExecutingAssembly().FullName)
|
||||
fixed (char* windowTitle = application.GetType().ToString())
|
||||
{
|
||||
Win32ApplicationRunner.application = application;
|
||||
|
||||
IntPtr hInstance = FX.GetModuleHandleW(null);
|
||||
|
||||
fixed (char* name = Assembly.GetExecutingAssembly().FullName)
|
||||
fixed (char* windowTitle = application.GetType().ToString())
|
||||
// Initialize the window class
|
||||
WNDCLASSEXW windowClassEx = new()
|
||||
{
|
||||
// Initialize the window class
|
||||
WNDCLASSEXW windowClassEx = new()
|
||||
cbSize = (uint)sizeof(WNDCLASSEXW),
|
||||
style = FX.CS_HREDRAW | FX.CS_VREDRAW,
|
||||
lpfnWndProc = &WindowProc,
|
||||
hInstance = hInstance,
|
||||
hCursor = FX.LoadCursorW(IntPtr.Zero, FX.MAKEINTRESOURCE(32512)),
|
||||
lpszClassName = (ushort*)name
|
||||
};
|
||||
|
||||
// Register the window class
|
||||
_ = FX.RegisterClassExW(&windowClassEx);
|
||||
|
||||
Rectangle windowRect = new(0, 0, 1280, 720);
|
||||
|
||||
// Set the target window size
|
||||
_ = FX.AdjustWindowRect((RECT*)&windowRect, FX.WS_OVERLAPPEDWINDOW, FX.FALSE);
|
||||
|
||||
uint
|
||||
height = (uint)(windowRect.Bottom - windowRect.Top),
|
||||
width = (uint)(windowRect.Right - windowRect.Left);
|
||||
|
||||
// Create the window and store a handle to it
|
||||
hwnd = FX.CreateWindowExW(
|
||||
0,
|
||||
windowClassEx.lpszClassName,
|
||||
(ushort*)windowTitle,
|
||||
FX.WS_OVERLAPPEDWINDOW,
|
||||
FX.CW_USEDEFAULT,
|
||||
FX.CW_USEDEFAULT,
|
||||
(int)width,
|
||||
(int)height,
|
||||
HWND.NULL,
|
||||
HMENU.NULL,
|
||||
hInstance,
|
||||
(void*)GCHandle.ToIntPtr(GCHandle.Alloc(application))
|
||||
);
|
||||
|
||||
MARGINS margins = default;
|
||||
margins.cxLeftWidth = -1;
|
||||
margins.cxRightWidth = -1;
|
||||
margins.cyTopHeight = -1;
|
||||
margins.cyBottomHeight = -1;
|
||||
|
||||
_ = FX.DwmExtendFrameIntoClientArea(hwnd, &margins);
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
application.OnInitialize(hwnd);
|
||||
|
||||
// Display the window
|
||||
_ = FX.ShowWindow(hwnd, FX.SW_SHOWDEFAULT);
|
||||
|
||||
MSG msg = default;
|
||||
|
||||
// Setup the render thread that enables smooth resizing of the window
|
||||
renderThread = new Thread(static args =>
|
||||
{
|
||||
(Win32Application application, CancellationToken token) = ((Win32Application, CancellationToken))args!;
|
||||
|
||||
Stopwatch
|
||||
startStopwatch = Stopwatch.StartNew(),
|
||||
frameStopwatch = Stopwatch.StartNew();
|
||||
|
||||
const long targetFrameTimeInTicksFor60fps = 166666;
|
||||
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
if (frameStopwatch.ElapsedTicks >= targetFrameTimeInTicksFor60fps)
|
||||
{
|
||||
cbSize = (uint)sizeof(WNDCLASSEXW),
|
||||
style = FX.CS_HREDRAW | FX.CS_VREDRAW,
|
||||
lpfnWndProc = &WindowProc,
|
||||
hInstance = hInstance,
|
||||
hCursor = FX.LoadCursorW(IntPtr.Zero, FX.MAKEINTRESOURCE(32512)),
|
||||
lpszClassName = (ushort*)name
|
||||
};
|
||||
frameStopwatch.Restart();
|
||||
|
||||
// Register the window class
|
||||
_ = FX.RegisterClassExW(&windowClassEx);
|
||||
application.OnUpdate(startStopwatch.Elapsed);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Rectangle windowRect = new(0, 0, 1280, 720);
|
||||
CancellationTokenSource tokenSource = new();
|
||||
|
||||
// Set the target window size
|
||||
_ = FX.AdjustWindowRect((RECT*)&windowRect, FX.WS_OVERLAPPEDWINDOW, FX.FALSE);
|
||||
renderThread.Start((application, tokenSource.Token));
|
||||
|
||||
uint
|
||||
height = (uint)(windowRect.Bottom - windowRect.Top),
|
||||
width = (uint)(windowRect.Right - windowRect.Left);
|
||||
// Process any messages in the queue
|
||||
while (msg.message != FX.WM_QUIT)
|
||||
{
|
||||
if (FX.PeekMessageW(&msg, HWND.NULL, 0, 0, FX.PM_REMOVE) != 0)
|
||||
{
|
||||
_ = FX.TranslateMessage(&msg);
|
||||
_ = FX.DispatchMessageW(&msg);
|
||||
}
|
||||
else if (isPaused)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the window and store a handle to it
|
||||
hwnd = FX.CreateWindowExW(
|
||||
0,
|
||||
windowClassEx.lpszClassName,
|
||||
(ushort*)windowTitle,
|
||||
FX.WS_OVERLAPPEDWINDOW,
|
||||
FX.CW_USEDEFAULT,
|
||||
FX.CW_USEDEFAULT,
|
||||
(int)width,
|
||||
(int)height,
|
||||
HWND.NULL,
|
||||
HMENU.NULL,
|
||||
hInstance,
|
||||
(void*)GCHandle.ToIntPtr(GCHandle.Alloc(application))
|
||||
);
|
||||
tokenSource.Cancel();
|
||||
|
||||
renderThread.Join();
|
||||
|
||||
// Return this part of the WM_QUIT message to Windows
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes incoming messages for a window.
|
||||
/// </summary>
|
||||
/// <param name="hwnd">A handle to the window.</param>
|
||||
/// <param name="uMsg">The message.</param>
|
||||
/// <param name="wParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
|
||||
/// <param name="lParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
|
||||
/// <returns>The result of the message processing for the input message.</returns>
|
||||
[UnmanagedCallersOnly]
|
||||
private static nint WindowProc(IntPtr hwnd, uint uMsg, nuint wParam, nint lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
// Change the paused state on window activation
|
||||
case FX.WM_ACTIVATE:
|
||||
{
|
||||
if (FX.LOWORD(wParam) == FX.WA_INACTIVE)
|
||||
{
|
||||
isPaused = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isPaused = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Change the paused state when ESC is pressed
|
||||
case FX.WM_KEYDOWN:
|
||||
{
|
||||
if ((ConsoleKey)wParam == ConsoleKey.Escape)
|
||||
{
|
||||
|
||||
if (isPaused)
|
||||
{
|
||||
FX.SetCapture(hwnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
FX.ReleaseCapture();
|
||||
}
|
||||
|
||||
isPaused = !isPaused;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Window resize started
|
||||
case FX.WM_ENTERSIZEMOVE:
|
||||
{
|
||||
isResizing = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Window resize completed
|
||||
case FX.WM_EXITSIZEMOVE:
|
||||
{
|
||||
isResizing = false;
|
||||
application.OnResize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Size update
|
||||
case FX.WM_SIZE:
|
||||
{
|
||||
if (!isResizing && wParam != FX.SIZE_MINIMIZED)
|
||||
{
|
||||
application.OnResize();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Size and position of the window (needed to enable the borderless mode)
|
||||
case FX.WM_NCCALCSIZE:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enable dragging the window
|
||||
case FX.WM_NCHITTEST:
|
||||
{
|
||||
POINT point;
|
||||
RECT rect;
|
||||
|
||||
_ = FX.GetCursorPos(&point);
|
||||
_ = FX.GetWindowRect(hwnd, &rect);
|
||||
|
||||
bool
|
||||
isAtTop = Math.Abs(point.y - rect.top) < 12,
|
||||
isAtRight = Math.Abs(point.x - rect.right) < 12,
|
||||
isAtBottom = Math.Abs(point.y - rect.bottom) < 12,
|
||||
isAtLeft = Math.Abs(point.x - rect.left) < 12;
|
||||
|
||||
if (isAtTop)
|
||||
{
|
||||
if (isAtRight) return FX.HTTOPRIGHT;
|
||||
if (isAtLeft) return FX.HTTOPLEFT;
|
||||
return FX.HTTOP;
|
||||
}
|
||||
|
||||
if (isAtRight)
|
||||
{
|
||||
if (isAtTop) return FX.HTTOPRIGHT;
|
||||
if (isAtBottom) return FX.HTBOTTOMRIGHT;
|
||||
return FX.HTRIGHT;
|
||||
}
|
||||
|
||||
if (isAtBottom)
|
||||
{
|
||||
if (isAtRight) return FX.HTBOTTOMRIGHT;
|
||||
if (isAtLeft) return FX.HTBOTTOMLEFT;
|
||||
return FX.HTBOTTOM;
|
||||
}
|
||||
|
||||
if (isAtLeft)
|
||||
{
|
||||
if (isAtTop) return FX.HTTOPLEFT;
|
||||
if (isAtBottom) return FX.HTBOTTOMLEFT;
|
||||
return FX.HTLEFT;
|
||||
}
|
||||
|
||||
return FX.HTCAPTION;
|
||||
}
|
||||
|
||||
// Restore the drop shadow
|
||||
case FX.WM_DWMCOMPOSITIONCHANGED:
|
||||
{
|
||||
MARGINS margins = default;
|
||||
margins.cxLeftWidth = -1;
|
||||
margins.cxRightWidth = -1;
|
||||
@@ -103,215 +299,18 @@ namespace ComputeSharp.SwapChain.Backend
|
||||
margins.cyBottomHeight = -1;
|
||||
|
||||
_ = FX.DwmExtendFrameIntoClientArea(hwnd, &margins);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
application.OnInitialize(hwnd);
|
||||
|
||||
// Display the window
|
||||
_ = FX.ShowWindow(hwnd, FX.SW_SHOWDEFAULT);
|
||||
|
||||
MSG msg = default;
|
||||
|
||||
// Setup the render thread that enables smooth resizing of the window
|
||||
renderThread = new Thread(static args =>
|
||||
// Shutdown
|
||||
case FX.WM_DESTROY:
|
||||
{
|
||||
(Win32Application application, CancellationToken token) = ((Win32Application, CancellationToken))args!;
|
||||
|
||||
Stopwatch
|
||||
startStopwatch = Stopwatch.StartNew(),
|
||||
frameStopwatch = Stopwatch.StartNew();
|
||||
|
||||
const long targetFrameTimeInTicksFor60fps = 166666;
|
||||
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
if (frameStopwatch.ElapsedTicks >= targetFrameTimeInTicksFor60fps)
|
||||
{
|
||||
frameStopwatch.Restart();
|
||||
|
||||
application.OnUpdate(startStopwatch.Elapsed);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CancellationTokenSource tokenSource = new();
|
||||
|
||||
renderThread.Start((application, tokenSource.Token));
|
||||
|
||||
// Process any messages in the queue
|
||||
while (msg.message != FX.WM_QUIT)
|
||||
{
|
||||
if (FX.PeekMessageW(&msg, HWND.NULL, 0, 0, FX.PM_REMOVE) != 0)
|
||||
{
|
||||
_ = FX.TranslateMessage(&msg);
|
||||
_ = FX.DispatchMessageW(&msg);
|
||||
}
|
||||
else if (isPaused)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
FX.PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
tokenSource.Cancel();
|
||||
|
||||
renderThread.Join();
|
||||
|
||||
// Return this part of the WM_QUIT message to Windows
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes incoming messages for a window.
|
||||
/// </summary>
|
||||
/// <param name="hwnd">A handle to the window.</param>
|
||||
/// <param name="uMsg">The message.</param>
|
||||
/// <param name="wParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
|
||||
/// <param name="lParam">Additional message information (the contents depend on the value of <paramref name="uMsg"/>).</param>
|
||||
/// <returns>The result of the message processing for the input message.</returns>
|
||||
[UnmanagedCallersOnly]
|
||||
private static nint WindowProc(IntPtr hwnd, uint uMsg, nuint wParam, nint lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
// Change the paused state on window activation
|
||||
case FX.WM_ACTIVATE:
|
||||
{
|
||||
if (FX.LOWORD(wParam) == FX.WA_INACTIVE)
|
||||
{
|
||||
isPaused = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isPaused = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Change the paused state when ESC is pressed
|
||||
case FX.WM_KEYDOWN:
|
||||
{
|
||||
if ((ConsoleKey)wParam == ConsoleKey.Escape)
|
||||
{
|
||||
|
||||
if (isPaused)
|
||||
{
|
||||
FX.SetCapture(hwnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
FX.ReleaseCapture();
|
||||
}
|
||||
|
||||
isPaused = !isPaused;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Window resize started
|
||||
case FX.WM_ENTERSIZEMOVE:
|
||||
{
|
||||
isResizing = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Window resize completed
|
||||
case FX.WM_EXITSIZEMOVE:
|
||||
{
|
||||
isResizing = false;
|
||||
application.OnResize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Size update
|
||||
case FX.WM_SIZE:
|
||||
{
|
||||
if (!isResizing && wParam != FX.SIZE_MINIMIZED)
|
||||
{
|
||||
application.OnResize();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Size and position of the window (needed to enable the borderless mode)
|
||||
case FX.WM_NCCALCSIZE:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enable dragging the window
|
||||
case FX.WM_NCHITTEST:
|
||||
{
|
||||
POINT point;
|
||||
RECT rect;
|
||||
|
||||
_ = FX.GetCursorPos(&point);
|
||||
_ = FX.GetWindowRect(hwnd, &rect);
|
||||
|
||||
bool
|
||||
isAtTop = Math.Abs(point.y - rect.top) < 12,
|
||||
isAtRight = Math.Abs(point.x - rect.right) < 12,
|
||||
isAtBottom = Math.Abs(point.y - rect.bottom) < 12,
|
||||
isAtLeft = Math.Abs(point.x - rect.left) < 12;
|
||||
|
||||
if (isAtTop)
|
||||
{
|
||||
if (isAtRight) return FX.HTTOPRIGHT;
|
||||
if (isAtLeft) return FX.HTTOPLEFT;
|
||||
return FX.HTTOP;
|
||||
}
|
||||
|
||||
if (isAtRight)
|
||||
{
|
||||
if (isAtTop) return FX.HTTOPRIGHT;
|
||||
if (isAtBottom) return FX.HTBOTTOMRIGHT;
|
||||
return FX.HTRIGHT;
|
||||
}
|
||||
|
||||
if (isAtBottom)
|
||||
{
|
||||
if (isAtRight) return FX.HTBOTTOMRIGHT;
|
||||
if (isAtLeft) return FX.HTBOTTOMLEFT;
|
||||
return FX.HTBOTTOM;
|
||||
}
|
||||
|
||||
if (isAtLeft)
|
||||
{
|
||||
if (isAtTop) return FX.HTTOPLEFT;
|
||||
if (isAtBottom) return FX.HTBOTTOMLEFT;
|
||||
return FX.HTLEFT;
|
||||
}
|
||||
|
||||
return FX.HTCAPTION;
|
||||
}
|
||||
|
||||
// Restore the drop shadow
|
||||
case FX.WM_DWMCOMPOSITIONCHANGED:
|
||||
{
|
||||
MARGINS margins = default;
|
||||
margins.cxLeftWidth = -1;
|
||||
margins.cxRightWidth = -1;
|
||||
margins.cyTopHeight = -1;
|
||||
margins.cyBottomHeight = -1;
|
||||
|
||||
_ = FX.DwmExtendFrameIntoClientArea(hwnd, &margins);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Shutdown
|
||||
case FX.WM_DESTROY:
|
||||
{
|
||||
FX.PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return FX.DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
return FX.DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,70 +6,69 @@ using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.SwapChain.Backend;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
namespace ComputeSharp.SwapChain
|
||||
namespace ComputeSharp.SwapChain;
|
||||
|
||||
class Program
|
||||
{
|
||||
class Program
|
||||
/// <summary>
|
||||
/// A texture for <c>\Textures\RustyMetal.png</c>.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyTexture2D<float4> RustyMetal = LoadTexture();
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of available samples to choose from.
|
||||
/// </summary>
|
||||
private static readonly Win32Application[] Samples = new Win32Application[]
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture for <c>\Textures\RustyMetal.png</c>.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyTexture2D<float4> RustyMetal = LoadTexture();
|
||||
new SwapChainApplication<HelloWorld>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<FractalTiling>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<MengerJourney>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<Octagrams>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ProteanClouds>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<PyramidPattern>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ContouredLayers>(static time => new((float)time.TotalSeconds, RustyMetal))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of available samples to choose from.
|
||||
/// </summary>
|
||||
private static readonly Win32Application[] Samples = new Win32Application[]
|
||||
static void Main()
|
||||
{
|
||||
Console.WriteLine("Available samples:");
|
||||
Console.WriteLine();
|
||||
|
||||
for (int i = 0; i < Samples.Length; i++)
|
||||
{
|
||||
new SwapChainApplication<HelloWorld>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<FractalTiling>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<MengerJourney>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<Octagrams>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ProteanClouds>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<PyramidPattern>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
|
||||
new SwapChainApplication<ContouredLayers>(static time => new((float)time.TotalSeconds, RustyMetal))
|
||||
};
|
||||
|
||||
static void Main()
|
||||
{
|
||||
Console.WriteLine("Available samples:");
|
||||
Console.WriteLine();
|
||||
|
||||
for (int i = 0; i < Samples.Length; i++)
|
||||
{
|
||||
Console.WriteLine($"{i}: {Samples[i].GetType().GenericTypeArguments[0].Name}");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
int index;
|
||||
|
||||
do
|
||||
{
|
||||
Console.Write("Enter the index of the sample to run: ");
|
||||
}
|
||||
while (!int.TryParse(Console.ReadLine(), out index));
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Starting {Samples[index].GetType().GenericTypeArguments[0].Name}...");
|
||||
|
||||
Win32ApplicationRunner.Run(Samples[index]);
|
||||
Console.WriteLine($"{i}: {Samples[i].GetType().GenericTypeArguments[0].Name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="ReadOnlyTexture2D{T, TPixel}"/> instance with the specified texture data.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the texture to load.</param>
|
||||
/// <returns>A texture with the data from the image at the specified name.</returns>
|
||||
[Pure]
|
||||
private static ReadOnlyTexture2D<Rgba32, float4> LoadTexture([CallerMemberName] string name = null!)
|
||||
{
|
||||
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png");
|
||||
Console.WriteLine();
|
||||
|
||||
return Gpu.Default.LoadReadOnlyTexture2D<Rgba32, float4>(filename);
|
||||
int index;
|
||||
|
||||
do
|
||||
{
|
||||
Console.Write("Enter the index of the sample to run: ");
|
||||
}
|
||||
while (!int.TryParse(Console.ReadLine(), out index));
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Starting {Samples[index].GetType().GenericTypeArguments[0].Name}...");
|
||||
|
||||
Win32ApplicationRunner.Run(Samples[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new <see cref="ReadOnlyTexture2D{T, TPixel}"/> instance with the specified texture data.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the texture to load.</param>
|
||||
/// <returns>A texture with the data from the image at the specified name.</returns>
|
||||
[Pure]
|
||||
private static ReadOnlyTexture2D<Rgba32, float4> LoadTexture([CallerMemberName] string name = null!)
|
||||
{
|
||||
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png");
|
||||
|
||||
return Gpu.Default.LoadReadOnlyTexture2D<Rgba32, float4>(filename);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,68 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A shader creating an abstract and colorful animation.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/WtjyzR"/>.
|
||||
/// <para>Created by Benoit Marini.</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A shader creating an abstract and colorful animation.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/WtjyzR"/>.
|
||||
/// <para>Created by Benoit Marini.</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ColorfulInfinity : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// The total number of layers for the final animation.
|
||||
/// </summary>
|
||||
private const float NumberOfLayers = 16.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The number of iterations to calculate a texel value.
|
||||
/// </summary>
|
||||
private const int NumberOfIterations = 23;
|
||||
|
||||
/// <summary>
|
||||
/// Makes some magic happen.
|
||||
/// </summary>
|
||||
private float4 Tex(float3 p)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float t = time + 78.0f;
|
||||
float4 o = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f));
|
||||
float4 dec =
|
||||
new float4(1.0f, 0.9f, 0.1f, 0.15f) +
|
||||
new float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f));
|
||||
|
||||
/// <summary>
|
||||
/// The total number of layers for the final animation.
|
||||
/// </summary>
|
||||
private const float NumberOfLayers = 16.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The number of iterations to calculate a texel value.
|
||||
/// </summary>
|
||||
private const int NumberOfIterations = 23;
|
||||
|
||||
/// <summary>
|
||||
/// Makes some magic happen.
|
||||
/// </summary>
|
||||
private float4 Tex(float3 p)
|
||||
for (int i = 0; i++ < NumberOfIterations;)
|
||||
{
|
||||
float t = time + 78.0f;
|
||||
float4 o = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f));
|
||||
float4 dec =
|
||||
new float4(1.0f, 0.9f, 0.1f, 0.15f) +
|
||||
new float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f));
|
||||
|
||||
for (int i = 0; i++ < NumberOfIterations;)
|
||||
{
|
||||
o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec);
|
||||
}
|
||||
|
||||
return o;
|
||||
o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
return o;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float3 col = 0;
|
||||
float t = time * 0.3f;
|
||||
|
||||
for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
|
||||
{
|
||||
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float3 col = 0;
|
||||
float t = time * 0.3f;
|
||||
float d = Hlsl.Frac(i + t);
|
||||
float s = Hlsl.Lerp(5.0f, 0.5f, d);
|
||||
float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d);
|
||||
|
||||
for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers)
|
||||
{
|
||||
float d = Hlsl.Frac(i + t);
|
||||
float s = Hlsl.Lerp(5.0f, 0.5f, d);
|
||||
float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d);
|
||||
|
||||
col += Tex(new float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ * f;
|
||||
}
|
||||
|
||||
col /= NumberOfLayers;
|
||||
col *= new float3(2, 1.0f, 2.0f);
|
||||
col = Hlsl.Pow(col, 0.5f);
|
||||
|
||||
return new(col.X, col.Y, col.Z, 1.0f);
|
||||
col += Tex(new float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ * f;
|
||||
}
|
||||
|
||||
col /= NumberOfLayers;
|
||||
col *= new float3(2, 1.0f, 2.0f);
|
||||
col = Hlsl.Pow(col, 0.5f);
|
||||
|
||||
return new(col.X, col.Y, col.Z, 1.0f);
|
||||
}
|
||||
}
|
||||
@@ -1,197 +1,196 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// Constructing some concise contoured layers, then applying various edge and shading effects to produce some faux depth.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/3lj3zt"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ContouredLayers : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructing some concise contoured layers, then applying various edge and shading effects to produce some faux depth.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/3lj3zt"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ContouredLayers : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// The background texture to sample.
|
||||
/// </summary>
|
||||
public readonly IReadOnlyTexture2D<float4> texture;
|
||||
|
||||
// float3 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289))) * 45758.5453f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The background texture to sample.
|
||||
/// </summary>
|
||||
public readonly IReadOnlyTexture2D<float4> texture;
|
||||
// float2 to float2 hash.
|
||||
private float2 Hash22(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(1, 113)));
|
||||
|
||||
// float3 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
p = Hlsl.Frac(new float2(262144, 32768) * n);
|
||||
|
||||
return Hlsl.Sin(p * 6.2831853f + time);
|
||||
}
|
||||
|
||||
// float2 to float2 hash.
|
||||
private static float2 Hash22B(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
|
||||
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
|
||||
}
|
||||
|
||||
// Smooth 2D noise
|
||||
private static float Noise2D(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22B(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22B(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * (3.0f - 2.0f * p);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private float Noise2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Map function with noise layers
|
||||
private float MapNoise(float3 p, float i)
|
||||
{
|
||||
return Noise2D3G(p.XY * 3.0f) * 0.66f + Noise2D3G(p.XY * 6.0f) * 0.34f + i / 10.0f * 1.0f - 0.15f;
|
||||
}
|
||||
|
||||
// 2D derivative function.
|
||||
private float3 GetNormal(in float3 p, float m, float i)
|
||||
{
|
||||
float2 e = new(0.001f, 0);
|
||||
|
||||
return new float3(m - MapNoise(p - e.XYY, i), m - MapNoise(p - e.YXY, i), 0.0f) / e.X * 1.4142f;
|
||||
}
|
||||
|
||||
// The map layer and its derivative
|
||||
private float4 MapLayer(in float3 p, float i)
|
||||
{
|
||||
float4 d = default;
|
||||
|
||||
d.X = MapNoise(p, i);
|
||||
d.YZW = GetNormal(p, d.X, i);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// Layer color. Based on the shade, layer number and smoothing factor.
|
||||
private float3 GetColor(float2 p, float sh, float fi)
|
||||
{
|
||||
float3 tx = texture[p + Hash21(new float2(sh, fi))].XYZ;
|
||||
|
||||
tx *= tx;
|
||||
|
||||
float3 col;
|
||||
|
||||
col = (float3)1.0 * (1.0f - 0.75f / (1.0f + sh * sh * 2.0f));
|
||||
col = Hlsl.Min(col * tx * 3.0f, 1.0f);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
// A hatch-like algorithm, or a stipple... or some kind of textured pattern.
|
||||
private float Hatch(float2 p, float res)
|
||||
{
|
||||
p *= res / 16.0f;
|
||||
|
||||
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
|
||||
|
||||
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
|
||||
if (hRnd > 0.66f) hatch = hRnd;
|
||||
|
||||
hatch = hatch * 0.75f + 0.5f;
|
||||
|
||||
return hatch;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 fragCoord = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float res = Hlsl.Min(DispatchSize.Y, 700.0f);
|
||||
float2 uv = (fragCoord - (float2)DispatchSize.XY * 0.5f) / res;
|
||||
float sf = 1.0f / DispatchSize.Y;
|
||||
float3 col = GetColor(uv, 0.0f, 0.0f);
|
||||
float pL = 0.0f;
|
||||
float hatch = Hatch(uv, res);
|
||||
|
||||
col *= hatch;
|
||||
|
||||
const int lNum = 5;
|
||||
float flNum = lNum;
|
||||
|
||||
for (int i = 0; i < lNum; i++)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289))) * 45758.5453f);
|
||||
float fi = i;
|
||||
|
||||
hatch = Hatch(uv + Hlsl.Sin(new float2(41.0f, 289.0f) * (fi + 1.0f)), res);
|
||||
|
||||
float4 c = MapLayer(new float3(uv, 1.0f), fi);
|
||||
float4 cSh = MapLayer(new float3(uv - new float2(0.03f, -0.03f) * ((flNum - fi) / flNum * 0.5f + 0.5f), 1.0f), fi);
|
||||
float sh = (fi + 1.0f) / (flNum);
|
||||
float3 lCol = GetColor(uv, sh, fi + 1.0f);
|
||||
float3 ld = Hlsl.Normalize(new float3(-1, 1, -0.25f));
|
||||
float3 n = Hlsl.Normalize(new float3(0.0f, 0.0f, -1.0f) + c.YZW);
|
||||
float diff = Hlsl.Max(Hlsl.Dot(ld, n), 0.0f);
|
||||
|
||||
diff *= 2.5f;
|
||||
|
||||
float3 eCol = lCol * (diff + 1.0f);
|
||||
float sfL = sf * Hlsl.Length(c.YZX) * 2.0f;
|
||||
float sfLSh = sf * Hlsl.Length(cSh.YZX) * 6.0f;
|
||||
const float shF = 0.5f;
|
||||
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfLSh, Hlsl.Max(cSh.X, pL))) * shF);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL * 3.0f, c.X)) * 0.25f);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X)) * 0.85f);
|
||||
col = Hlsl.Lerp(col, eCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.003f)));
|
||||
col = Hlsl.Lerp(col, lCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.006f)));
|
||||
|
||||
pL = c.X;
|
||||
}
|
||||
|
||||
// float2 to float2 hash.
|
||||
private float2 Hash22(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(1, 113)));
|
||||
col *= Hlsl.Lerp(new float3(1.8f, 1, 0.7f).ZYX, new float3(1.8f, 1, 0.7f).XZY, Noise2D(uv * 2.0f));
|
||||
|
||||
p = Hlsl.Frac(new float2(262144, 32768) * n);
|
||||
float3 rn3 = Noise2D(uv * DispatchSize.Y / 1.0f + 1.7f) - Noise2D(uv * DispatchSize.Y / 1.0f + 3.4f);
|
||||
|
||||
return Hlsl.Sin(p * 6.2831853f + time);
|
||||
}
|
||||
col *= 0.93f + 0.07f * rn3.XYZ + 0.07f * Hlsl.Dot(rn3, new float3(0.299f, 0.587f, 0.114f));
|
||||
|
||||
// float2 to float2 hash.
|
||||
private static float2 Hash22B(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
uv = fragCoord / DispatchSize.XY;
|
||||
|
||||
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
|
||||
}
|
||||
col *= Hlsl.Pow(16.0f * uv.X * uv.Y * (1.0f - uv.X) * (1.0f - uv.Y), 0.0625f);
|
||||
|
||||
// Smooth 2D noise
|
||||
private static float Noise2D(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22B(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22B(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * (3.0f - 2.0f * p);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private float Noise2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Map function with noise layers
|
||||
private float MapNoise(float3 p, float i)
|
||||
{
|
||||
return Noise2D3G(p.XY * 3.0f) * 0.66f + Noise2D3G(p.XY * 6.0f) * 0.34f + i / 10.0f * 1.0f - 0.15f;
|
||||
}
|
||||
|
||||
// 2D derivative function.
|
||||
private float3 GetNormal(in float3 p, float m, float i)
|
||||
{
|
||||
float2 e = new(0.001f, 0);
|
||||
|
||||
return new float3(m - MapNoise(p - e.XYY, i), m - MapNoise(p - e.YXY, i), 0.0f) / e.X * 1.4142f;
|
||||
}
|
||||
|
||||
// The map layer and its derivative
|
||||
private float4 MapLayer(in float3 p, float i)
|
||||
{
|
||||
float4 d = default;
|
||||
|
||||
d.X = MapNoise(p, i);
|
||||
d.YZW = GetNormal(p, d.X, i);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// Layer color. Based on the shade, layer number and smoothing factor.
|
||||
private float3 GetColor(float2 p, float sh, float fi)
|
||||
{
|
||||
float3 tx = texture[p + Hash21(new float2(sh, fi))].XYZ;
|
||||
|
||||
tx *= tx;
|
||||
|
||||
float3 col;
|
||||
|
||||
col = (float3)1.0 * (1.0f - 0.75f / (1.0f + sh * sh * 2.0f));
|
||||
col = Hlsl.Min(col * tx * 3.0f, 1.0f);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
// A hatch-like algorithm, or a stipple... or some kind of textured pattern.
|
||||
private float Hatch(float2 p, float res)
|
||||
{
|
||||
p *= res / 16.0f;
|
||||
|
||||
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
|
||||
|
||||
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
|
||||
if (hRnd > 0.66f) hatch = hRnd;
|
||||
|
||||
hatch = hatch * 0.75f + 0.5f;
|
||||
|
||||
return hatch;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 fragCoord = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float res = Hlsl.Min(DispatchSize.Y, 700.0f);
|
||||
float2 uv = (fragCoord - (float2)DispatchSize.XY * 0.5f) / res;
|
||||
float sf = 1.0f / DispatchSize.Y;
|
||||
float3 col = GetColor(uv, 0.0f, 0.0f);
|
||||
float pL = 0.0f;
|
||||
float hatch = Hatch(uv, res);
|
||||
|
||||
col *= hatch;
|
||||
|
||||
const int lNum = 5;
|
||||
float flNum = lNum;
|
||||
|
||||
for (int i = 0; i < lNum; i++)
|
||||
{
|
||||
float fi = i;
|
||||
|
||||
hatch = Hatch(uv + Hlsl.Sin(new float2(41.0f, 289.0f) * (fi + 1.0f)), res);
|
||||
|
||||
float4 c = MapLayer(new float3(uv, 1.0f), fi);
|
||||
float4 cSh = MapLayer(new float3(uv - new float2(0.03f, -0.03f) * ((flNum - fi) / flNum * 0.5f + 0.5f), 1.0f), fi);
|
||||
float sh = (fi + 1.0f) / (flNum);
|
||||
float3 lCol = GetColor(uv, sh, fi + 1.0f);
|
||||
float3 ld = Hlsl.Normalize(new float3(-1, 1, -0.25f));
|
||||
float3 n = Hlsl.Normalize(new float3(0.0f, 0.0f, -1.0f) + c.YZW);
|
||||
float diff = Hlsl.Max(Hlsl.Dot(ld, n), 0.0f);
|
||||
|
||||
diff *= 2.5f;
|
||||
|
||||
float3 eCol = lCol * (diff + 1.0f);
|
||||
float sfL = sf * Hlsl.Length(c.YZX) * 2.0f;
|
||||
float sfLSh = sf * Hlsl.Length(cSh.YZX) * 6.0f;
|
||||
const float shF = 0.5f;
|
||||
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfLSh, Hlsl.Max(cSh.X, pL))) * shF);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL * 3.0f, c.X)) * 0.25f);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X)) * 0.85f);
|
||||
col = Hlsl.Lerp(col, eCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.003f)));
|
||||
col = Hlsl.Lerp(col, lCol * hatch, (1.0f - Hlsl.SmoothStep(0.0f, sfL, c.X + Hlsl.Length(c.YZX) * 0.006f)));
|
||||
|
||||
pL = c.X;
|
||||
}
|
||||
|
||||
col *= Hlsl.Lerp(new float3(1.8f, 1, 0.7f).ZYX, new float3(1.8f, 1, 0.7f).XZY, Noise2D(uv * 2.0f));
|
||||
|
||||
float3 rn3 = Noise2D(uv * DispatchSize.Y / 1.0f + 1.7f) - Noise2D(uv * DispatchSize.Y / 1.0f + 3.4f);
|
||||
|
||||
col *= 0.93f + 0.07f * rn3.XYZ + 0.07f * Hlsl.Dot(rn3, new float3(0.299f, 0.587f, 0.114f));
|
||||
|
||||
uv = fragCoord / DispatchSize.XY;
|
||||
|
||||
col *= Hlsl.Pow(16.0f * uv.X * uv.Y * (1.0f - uv.X) * (1.0f - uv.Y), 0.0625f);
|
||||
|
||||
return new float4(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
return new float4(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
}
|
||||
@@ -1,293 +1,292 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A basic extruded square grid-based blobby Truchet pattern.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/ttVBzd"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic extruded square grid-based blobby Truchet pattern.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/ttVBzd"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ExtrudedTruchetPattern : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// Curve shape - Round: 0, Semi-round: 1, Octagonal: 2, Superellipse: 3, Straight: 4.
|
||||
/// </summary>
|
||||
private static readonly int SHAPE = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Object ID: Either the back plane or the metaballs.
|
||||
/// </summary>
|
||||
private static int objID;
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
/// <summary>
|
||||
/// Curve shape - Round: 0, Semi-round: 1, Octagonal: 2, Superellipse: 3, Straight: 4.
|
||||
/// </summary>
|
||||
private static readonly int SHAPE = 0;
|
||||
return new(c, -s, s, c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Object ID: Either the back plane or the metaballs.
|
||||
/// </summary>
|
||||
private static int objID;
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(float a)
|
||||
// Various distance metrics.
|
||||
private static float Distance(float2 p)
|
||||
{
|
||||
if (SHAPE == 0)
|
||||
{
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
return new(c, -s, s, c);
|
||||
return Hlsl.Length(p);
|
||||
}
|
||||
else p = Hlsl.Abs(p);
|
||||
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
switch (SHAPE)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// Various distance metrics.
|
||||
private static float Distance(float2 p)
|
||||
{
|
||||
if (SHAPE == 0)
|
||||
{
|
||||
return Hlsl.Length(p);
|
||||
}
|
||||
else p = Hlsl.Abs(p);
|
||||
|
||||
switch (SHAPE)
|
||||
{
|
||||
case 1: return Hlsl.Max(Hlsl.Length(p), (p.X + p.Y) * 0.7071f + 0.015f);
|
||||
case 2: return Hlsl.Max((p.X + p.Y) * 0.7071f, Hlsl.Max(p.X, p.Y));
|
||||
case 3: return Hlsl.Pow(Hlsl.Dot(Hlsl.Pow(p, 3), 1), 1.0f / 3.0f);
|
||||
default: return (p.X + p.Y) * 0.7071f;
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL's mod function
|
||||
private static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
// A standard square grid 2D blobby Truchet routine: Render circles
|
||||
// in opposite corners of a tile, reverse the pattern on alternate
|
||||
// checker tiles, and randomly rotate.
|
||||
private static float Truchet(float2 p)
|
||||
{
|
||||
const float sc = 0.5f;
|
||||
float2 ip = Hlsl.Floor(p / sc) + 0.5f;
|
||||
|
||||
p -= ip * sc;
|
||||
|
||||
float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new float2(1, 113))) * 45758.5453f);
|
||||
|
||||
if (rnd < .5) p.Y = -p.Y;
|
||||
|
||||
float d = Hlsl.Min(Distance(p - 0.5f * sc), Distance(p + 0.5f * sc)) - 0.5f * sc;
|
||||
|
||||
if (SHAPE == 4)
|
||||
{
|
||||
d += (0.5f - 0.5f / Hlsl.Sqrt(2.0f)) * sc;
|
||||
}
|
||||
|
||||
if (rnd < 0.5f) d = -d;
|
||||
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f) d = -d;
|
||||
|
||||
return d - 0.03f;
|
||||
}
|
||||
|
||||
// The scene's distance function: There'd be faster ways to do this, but it's
|
||||
// more readable this way. Plus, this is a pretty simple scene, so it's
|
||||
// efficient enough.
|
||||
private static float M(float3 p)
|
||||
{
|
||||
float fl = -p.Z;
|
||||
float obj = Truchet(p.XY);
|
||||
|
||||
obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f;
|
||||
|
||||
float studs = 1e5f;
|
||||
const float sc = 0.5f;
|
||||
float2 q = p.XY + 0.5f * sc;
|
||||
float2 iq = Hlsl.Floor(q / sc) + 0.5f;
|
||||
|
||||
q -= iq * sc;
|
||||
|
||||
if (Mod(iq.X + iq.Y, 2.0f) > 0.5f)
|
||||
{
|
||||
studs = Hlsl.Max(Hlsl.Length(q) - 0.1f * sc - 0.02f, Hlsl.Abs(p.Z) - 0.26f);
|
||||
}
|
||||
|
||||
objID = fl < obj && fl < studs ? 0 : obj < studs ? 1 : 2;
|
||||
|
||||
return Hlsl.Min(Hlsl.Min(fl, obj), studs);
|
||||
}
|
||||
|
||||
// Cheap shadows are hard. In fact, I'd almost say, shadowing particular scenes with limited
|
||||
// iterations is impossible... However, I'd be very grateful if someone could prove me wrong. :)
|
||||
private static float SoftShadow(float3 ro, float3 lp, float3 n, float k)
|
||||
{
|
||||
const int iter = 24;
|
||||
|
||||
ro += n * 0.0015f;
|
||||
|
||||
float3 rd = lp - ro;
|
||||
float shade = 1.0f;
|
||||
float t = 0;
|
||||
float end = Hlsl.Max(Hlsl.Length(rd), 0.0001f);
|
||||
|
||||
rd /= end;
|
||||
|
||||
for (int i = 0; i < iter; i++)
|
||||
{
|
||||
float d = M(ro + rd * t);
|
||||
|
||||
shade = Hlsl.Min(shade, k * d / t);
|
||||
t += Hlsl.Clamp(d, 0.01f, 0.25f);
|
||||
|
||||
if (d < 0.0f || t > end) break;
|
||||
}
|
||||
|
||||
return Hlsl.Max(shade, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
// I keep a collection of occlusion routines... OK, that sounded really nerdy. :)
|
||||
// Anyway, I like this one. I'm assuHlsl.Ming it's based on IQ's original.
|
||||
private float CalculateAO(in float3 p, in float3 n)
|
||||
{
|
||||
float sca = 2.0f, occ = 0.0f;
|
||||
|
||||
for (int i = (int)Hlsl.Min(time, 0f); i < 5; i++)
|
||||
{
|
||||
float hr = (i + 1f) * 0.15f / 5.0f;
|
||||
float d = M(p + n * hr);
|
||||
occ += (hr - d) * sca;
|
||||
sca *= 0.7f;
|
||||
|
||||
if (sca > 1e5f) break;
|
||||
}
|
||||
|
||||
return Hlsl.Clamp(1.0f - occ, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Standard normal function.
|
||||
private static float3 Normal(in float3 p)
|
||||
{
|
||||
float2 e = new(0.001f, 0);
|
||||
|
||||
return Hlsl.Normalize(new float3(
|
||||
M(p + e.XYY) - M(p - e.XYY),
|
||||
M(p + e.YXY) - M(p - e.YXY),
|
||||
M(p + e.YYX) - M(p - e.YYX)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float2 u = (coords - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float3
|
||||
r = Hlsl.Normalize(new float3(u, 1)),
|
||||
o = new(0, time / 2.0f, -3),
|
||||
l = o + new float3(0.25f, 0.25f, 2.0f);
|
||||
|
||||
r.YZ = Hlsl.Mul(Rotate2x2(0.15f), r.YZ);
|
||||
r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(time * 3.14159f / 32.0f) / 8.0f), r.XZ);
|
||||
r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(time * 3.14159f / 32.0f) / 8.0f), r.XY);
|
||||
|
||||
float d, t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f, glow = 0;
|
||||
|
||||
for (int i = 0; i < 96; i++)
|
||||
{
|
||||
d = M(o + r * t);
|
||||
|
||||
if (Hlsl.Abs(d) < .001) break;
|
||||
|
||||
t += d * 0.7f;
|
||||
glow += 0.2f / (1.0f + Hlsl.Abs(d) * 5.0f);
|
||||
}
|
||||
|
||||
int gObjID = objID;
|
||||
float3 p = o + r * t, n = Normal(p);
|
||||
float2 uv = p.XY;
|
||||
float sc = 0.5f;
|
||||
float2 iuv = Hlsl.Floor(uv / sc) + 0.5f;
|
||||
|
||||
uv -= iuv * sc;
|
||||
|
||||
float2 uv2 = p.XY + 0.5f * sc;
|
||||
float2 iuv2 = Hlsl.Floor(uv2 / sc) + 0.5f;
|
||||
|
||||
uv2 -= iuv2 * sc;
|
||||
|
||||
float bord = Hlsl.Max(Hlsl.Abs(uv.X), Hlsl.Abs(uv.Y)) - 0.5f * sc;
|
||||
|
||||
bord = Hlsl.Abs(bord) - 0.002f;
|
||||
d = Truchet(p.XY);
|
||||
|
||||
float lSc = 20.0f;
|
||||
float pat = (Hlsl.Abs(Hlsl.Frac((uv.X - uv.Y) * lSc - 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
|
||||
float pat2 = (Hlsl.Abs(Hlsl.Frac((uv.X + uv.Y) * lSc + 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
|
||||
float sf = Hlsl.Dot(Hlsl.Sin(p.XY - Hlsl.Cos(p.YX * 2.0f)), 0.5f);
|
||||
float sf2 = Hlsl.Dot(Hlsl.Sin(p.XY * 1.5f - Hlsl.Cos(p.YX * 3.0f)), 0.5f);
|
||||
float4 col1 = Hlsl.Lerp(new float4(1, 0.75f, 0.6f, 0), new float4(1, 0.85f, 0.65f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf));
|
||||
float4 col2 = Hlsl.Lerp(new float4(0.4f, 0.7f, 1, 0), new float4(0.3f, 0.85f, 0.95f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf2) * 0.5f);
|
||||
|
||||
col1 = Hlsl.Pow(col1, 1.6f);
|
||||
col2 = Hlsl.Lerp(col1.ZYXW, Hlsl.Pow(col2, 1.4f), 0.666f);
|
||||
|
||||
float4 oCol;
|
||||
|
||||
if (gObjID == 0)
|
||||
{
|
||||
oCol = Hlsl.Lerp(col2, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat2)) * 0.35f);
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
|
||||
|
||||
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f) oCol *= 0.8f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, d - 0.015f)) * 0.8f);
|
||||
}
|
||||
else if (gObjID == 1)
|
||||
{
|
||||
oCol = Hlsl.Lerp(1, 0, 1.0f - Hlsl.SmoothStep(0, 0.01f, d + 0.05f));
|
||||
float4 fCol = Hlsl.Lerp(col1, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat)) * 0.35f);
|
||||
fCol = Hlsl.Lerp(fCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
|
||||
|
||||
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f) fCol *= 0.8f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, fCol, 1 - Hlsl.SmoothStep(0, 0.01f, d + 0.08f));
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, Hlsl.Length(uv2) - 0.08f)) * 0.8f);
|
||||
}
|
||||
else
|
||||
{
|
||||
oCol = col1;
|
||||
|
||||
float ht = 0.26f;
|
||||
|
||||
if (Mod(iuv2.X + iuv2.Y + 1.0f, 2.0f) > 0.5f)
|
||||
{
|
||||
float tmp = pat; pat = pat2; pat2 = tmp;
|
||||
|
||||
oCol = col2;
|
||||
ht = 0.05f;
|
||||
}
|
||||
|
||||
float mark = Hlsl.Length(uv2);
|
||||
float markRim = Hlsl.Max(Hlsl.Abs(mark - 0.07f), Hlsl.Abs(p.Z + ht)) - 0.003f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, markRim)) * 0.8f);
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, mark - 0.015f)) * 0.8f);
|
||||
}
|
||||
|
||||
float3 ld = l - p;
|
||||
float lDist = Hlsl.Length(ld);
|
||||
|
||||
ld /= lDist;
|
||||
|
||||
float at = 1.0f / (1.0f + lDist * lDist * 0.125f);
|
||||
float sh = SoftShadow(p, l, n, 8);
|
||||
float ao = CalculateAO(p, n);
|
||||
float df = Hlsl.Max(Hlsl.Dot(n, ld), 0);
|
||||
float sp = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(r, n), ld), 0), 32);
|
||||
|
||||
float4 c = oCol * (df * sh + sp * sh + 0.5f) * at * ao;
|
||||
|
||||
c = Hlsl.Sqrt(Hlsl.Max(c, 0));
|
||||
|
||||
return c;
|
||||
case 1: return Hlsl.Max(Hlsl.Length(p), (p.X + p.Y) * 0.7071f + 0.015f);
|
||||
case 2: return Hlsl.Max((p.X + p.Y) * 0.7071f, Hlsl.Max(p.X, p.Y));
|
||||
case 3: return Hlsl.Pow(Hlsl.Dot(Hlsl.Pow(p, 3), 1), 1.0f / 3.0f);
|
||||
default: return (p.X + p.Y) * 0.7071f;
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL's mod function
|
||||
private static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
// A standard square grid 2D blobby Truchet routine: Render circles
|
||||
// in opposite corners of a tile, reverse the pattern on alternate
|
||||
// checker tiles, and randomly rotate.
|
||||
private static float Truchet(float2 p)
|
||||
{
|
||||
const float sc = 0.5f;
|
||||
float2 ip = Hlsl.Floor(p / sc) + 0.5f;
|
||||
|
||||
p -= ip * sc;
|
||||
|
||||
float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new float2(1, 113))) * 45758.5453f);
|
||||
|
||||
if (rnd < .5) p.Y = -p.Y;
|
||||
|
||||
float d = Hlsl.Min(Distance(p - 0.5f * sc), Distance(p + 0.5f * sc)) - 0.5f * sc;
|
||||
|
||||
if (SHAPE == 4)
|
||||
{
|
||||
d += (0.5f - 0.5f / Hlsl.Sqrt(2.0f)) * sc;
|
||||
}
|
||||
|
||||
if (rnd < 0.5f) d = -d;
|
||||
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f) d = -d;
|
||||
|
||||
return d - 0.03f;
|
||||
}
|
||||
|
||||
// The scene's distance function: There'd be faster ways to do this, but it's
|
||||
// more readable this way. Plus, this is a pretty simple scene, so it's
|
||||
// efficient enough.
|
||||
private static float M(float3 p)
|
||||
{
|
||||
float fl = -p.Z;
|
||||
float obj = Truchet(p.XY);
|
||||
|
||||
obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f;
|
||||
|
||||
float studs = 1e5f;
|
||||
const float sc = 0.5f;
|
||||
float2 q = p.XY + 0.5f * sc;
|
||||
float2 iq = Hlsl.Floor(q / sc) + 0.5f;
|
||||
|
||||
q -= iq * sc;
|
||||
|
||||
if (Mod(iq.X + iq.Y, 2.0f) > 0.5f)
|
||||
{
|
||||
studs = Hlsl.Max(Hlsl.Length(q) - 0.1f * sc - 0.02f, Hlsl.Abs(p.Z) - 0.26f);
|
||||
}
|
||||
|
||||
objID = fl < obj && fl < studs ? 0 : obj < studs ? 1 : 2;
|
||||
|
||||
return Hlsl.Min(Hlsl.Min(fl, obj), studs);
|
||||
}
|
||||
|
||||
// Cheap shadows are hard. In fact, I'd almost say, shadowing particular scenes with limited
|
||||
// iterations is impossible... However, I'd be very grateful if someone could prove me wrong. :)
|
||||
private static float SoftShadow(float3 ro, float3 lp, float3 n, float k)
|
||||
{
|
||||
const int iter = 24;
|
||||
|
||||
ro += n * 0.0015f;
|
||||
|
||||
float3 rd = lp - ro;
|
||||
float shade = 1.0f;
|
||||
float t = 0;
|
||||
float end = Hlsl.Max(Hlsl.Length(rd), 0.0001f);
|
||||
|
||||
rd /= end;
|
||||
|
||||
for (int i = 0; i < iter; i++)
|
||||
{
|
||||
float d = M(ro + rd * t);
|
||||
|
||||
shade = Hlsl.Min(shade, k * d / t);
|
||||
t += Hlsl.Clamp(d, 0.01f, 0.25f);
|
||||
|
||||
if (d < 0.0f || t > end) break;
|
||||
}
|
||||
|
||||
return Hlsl.Max(shade, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
// I keep a collection of occlusion routines... OK, that sounded really nerdy. :)
|
||||
// Anyway, I like this one. I'm assuHlsl.Ming it's based on IQ's original.
|
||||
private float CalculateAO(in float3 p, in float3 n)
|
||||
{
|
||||
float sca = 2.0f, occ = 0.0f;
|
||||
|
||||
for (int i = (int)Hlsl.Min(time, 0f); i < 5; i++)
|
||||
{
|
||||
float hr = (i + 1f) * 0.15f / 5.0f;
|
||||
float d = M(p + n * hr);
|
||||
occ += (hr - d) * sca;
|
||||
sca *= 0.7f;
|
||||
|
||||
if (sca > 1e5f) break;
|
||||
}
|
||||
|
||||
return Hlsl.Clamp(1.0f - occ, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Standard normal function.
|
||||
private static float3 Normal(in float3 p)
|
||||
{
|
||||
float2 e = new(0.001f, 0);
|
||||
|
||||
return Hlsl.Normalize(new float3(
|
||||
M(p + e.XYY) - M(p - e.XYY),
|
||||
M(p + e.YXY) - M(p - e.YXY),
|
||||
M(p + e.YYX) - M(p - e.YYX)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coords = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float2 u = (coords - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float3
|
||||
r = Hlsl.Normalize(new float3(u, 1)),
|
||||
o = new(0, time / 2.0f, -3),
|
||||
l = o + new float3(0.25f, 0.25f, 2.0f);
|
||||
|
||||
r.YZ = Hlsl.Mul(Rotate2x2(0.15f), r.YZ);
|
||||
r.XZ = Hlsl.Mul(Rotate2x2(-Hlsl.Cos(time * 3.14159f / 32.0f) / 8.0f), r.XZ);
|
||||
r.XY = Hlsl.Mul(Rotate2x2(Hlsl.Sin(time * 3.14159f / 32.0f) / 8.0f), r.XY);
|
||||
|
||||
float d, t = Hash21(r.XY * 57.0f + Hlsl.Frac(time)) * 0.5f, glow = 0;
|
||||
|
||||
for (int i = 0; i < 96; i++)
|
||||
{
|
||||
d = M(o + r * t);
|
||||
|
||||
if (Hlsl.Abs(d) < .001) break;
|
||||
|
||||
t += d * 0.7f;
|
||||
glow += 0.2f / (1.0f + Hlsl.Abs(d) * 5.0f);
|
||||
}
|
||||
|
||||
int gObjID = objID;
|
||||
float3 p = o + r * t, n = Normal(p);
|
||||
float2 uv = p.XY;
|
||||
float sc = 0.5f;
|
||||
float2 iuv = Hlsl.Floor(uv / sc) + 0.5f;
|
||||
|
||||
uv -= iuv * sc;
|
||||
|
||||
float2 uv2 = p.XY + 0.5f * sc;
|
||||
float2 iuv2 = Hlsl.Floor(uv2 / sc) + 0.5f;
|
||||
|
||||
uv2 -= iuv2 * sc;
|
||||
|
||||
float bord = Hlsl.Max(Hlsl.Abs(uv.X), Hlsl.Abs(uv.Y)) - 0.5f * sc;
|
||||
|
||||
bord = Hlsl.Abs(bord) - 0.002f;
|
||||
d = Truchet(p.XY);
|
||||
|
||||
float lSc = 20.0f;
|
||||
float pat = (Hlsl.Abs(Hlsl.Frac((uv.X - uv.Y) * lSc - 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
|
||||
float pat2 = (Hlsl.Abs(Hlsl.Frac((uv.X + uv.Y) * lSc + 0.5f) - 0.5f) * 2.0f - 0.5f) / lSc;
|
||||
float sf = Hlsl.Dot(Hlsl.Sin(p.XY - Hlsl.Cos(p.YX * 2.0f)), 0.5f);
|
||||
float sf2 = Hlsl.Dot(Hlsl.Sin(p.XY * 1.5f - Hlsl.Cos(p.YX * 3.0f)), 0.5f);
|
||||
float4 col1 = Hlsl.Lerp(new float4(1, 0.75f, 0.6f, 0), new float4(1, 0.85f, 0.65f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf));
|
||||
float4 col2 = Hlsl.Lerp(new float4(0.4f, 0.7f, 1, 0), new float4(0.3f, 0.85f, 0.95f, 0), Hlsl.SmoothStep(-0.5f, 0.5f, sf2) * 0.5f);
|
||||
|
||||
col1 = Hlsl.Pow(col1, 1.6f);
|
||||
col2 = Hlsl.Lerp(col1.ZYXW, Hlsl.Pow(col2, 1.4f), 0.666f);
|
||||
|
||||
float4 oCol;
|
||||
|
||||
if (gObjID == 0)
|
||||
{
|
||||
oCol = Hlsl.Lerp(col2, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat2)) * 0.35f);
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
|
||||
|
||||
if (Mod(iuv.X + iuv.Y, 2.0f) > 0.5f) oCol *= 0.8f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, d - 0.015f)) * 0.8f);
|
||||
}
|
||||
else if (gObjID == 1)
|
||||
{
|
||||
oCol = Hlsl.Lerp(1, 0, 1.0f - Hlsl.SmoothStep(0, 0.01f, d + 0.05f));
|
||||
float4 fCol = Hlsl.Lerp(col1, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, pat)) * 0.35f);
|
||||
fCol = Hlsl.Lerp(fCol, 0, (1.0f - Hlsl.SmoothStep(0, 0.01f, bord)) * 0.8f);
|
||||
|
||||
if (Mod(iuv.X + iuv.Y, 2.0f) < 0.5f) fCol *= 0.8f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, fCol, 1 - Hlsl.SmoothStep(0, 0.01f, d + 0.08f));
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, Hlsl.Length(uv2) - 0.08f)) * 0.8f);
|
||||
}
|
||||
else
|
||||
{
|
||||
oCol = col1;
|
||||
|
||||
float ht = 0.26f;
|
||||
|
||||
if (Mod(iuv2.X + iuv2.Y + 1.0f, 2.0f) > 0.5f)
|
||||
{
|
||||
float tmp = pat; pat = pat2; pat2 = tmp;
|
||||
|
||||
oCol = col2;
|
||||
ht = 0.05f;
|
||||
}
|
||||
|
||||
float mark = Hlsl.Length(uv2);
|
||||
float markRim = Hlsl.Max(Hlsl.Abs(mark - 0.07f), Hlsl.Abs(p.Z + ht)) - 0.003f;
|
||||
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, markRim)) * 0.8f);
|
||||
oCol = Hlsl.Lerp(oCol, 0, (1 - Hlsl.SmoothStep(0, 0.01f, mark - 0.015f)) * 0.8f);
|
||||
}
|
||||
|
||||
float3 ld = l - p;
|
||||
float lDist = Hlsl.Length(ld);
|
||||
|
||||
ld /= lDist;
|
||||
|
||||
float at = 1.0f / (1.0f + lDist * lDist * 0.125f);
|
||||
float sh = SoftShadow(p, l, n, 8);
|
||||
float ao = CalculateAO(p, n);
|
||||
float df = Hlsl.Max(Hlsl.Dot(n, ld), 0);
|
||||
float sp = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(r, n), ld), 0), 32);
|
||||
|
||||
float4 c = oCol * (df * sh + sp * sh + 0.5f) * at * ao;
|
||||
|
||||
c = Hlsl.Sqrt(Hlsl.Max(c, 0));
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,45 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A shader creating a fractal tiling animation.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/Ml2GWy"/>.
|
||||
/// <para>Created by Inigo Quilez.</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct FractalTiling : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A shader creating a fractal tiling animation.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/Ml2GWy"/>.
|
||||
/// <para>Created by Inigo Quilez.</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct FractalTiling : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time;
|
||||
float4 color = 0;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time;
|
||||
float4 color = 0;
|
||||
float2 a = Hlsl.Floor(position);
|
||||
float2 b = Hlsl.Frac(position);
|
||||
float4 w = Hlsl.Frac(
|
||||
(Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) +
|
||||
new float4(0.035f, 0.01f, 0, 0.7f))
|
||||
* 13.545317f);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float2 a = Hlsl.Floor(position);
|
||||
float2 b = Hlsl.Frac(position);
|
||||
float4 w = Hlsl.Frac(
|
||||
(Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) +
|
||||
new float4(0.035f, 0.01f, 0, 0.7f))
|
||||
* 13.545317f);
|
||||
color.XYZ += w.XYZ *
|
||||
2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) *
|
||||
Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y));
|
||||
|
||||
color.XYZ += w.XYZ *
|
||||
2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) *
|
||||
Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y));
|
||||
|
||||
position /= 2.0f;
|
||||
color /= 2.0f;
|
||||
}
|
||||
|
||||
color.XYZ = Hlsl.Pow(color.XYZ, new float3(0.7f, 0.8f, 0.5f));
|
||||
color.W = 1.0f;
|
||||
|
||||
return color;
|
||||
position /= 2.0f;
|
||||
color /= 2.0f;
|
||||
}
|
||||
|
||||
color.XYZ = Hlsl.Pow(color.XYZ, new float3(0.7f, 0.8f, 0.5f));
|
||||
color.W = 1.0f;
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -1,170 +1,169 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A shader creating a flythrough in a Menger system.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/Mdf3z7"/>.
|
||||
/// <para>Created by Syntopia.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MengerJourney : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A shader creating a flythrough in a Menger system.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/Mdf3z7"/>.
|
||||
/// <para>Created by Syntopia.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MengerJourney : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
private const int MaxSteps = 30;
|
||||
private const float MinimumDistance = 0.0009f;
|
||||
private const float NormalDistance = 0.0002f;
|
||||
private const int Iterations = 7;
|
||||
private const float Scale = 3.0f;
|
||||
private const float FieldOfView = 1.0f;
|
||||
private const float Jitter = 0.05f;
|
||||
private const float FudgeFactor = 0.7f;
|
||||
private const float NonLinearPerspective = 2.0f;
|
||||
private const float Ambient = 0.32184f;
|
||||
private const float Diffuse = 0.5f;
|
||||
|
||||
private static readonly float3 LightDir = 1.0f;
|
||||
private static readonly float3 LightColor = new(1.0f, 1.0f, 0.858824f);
|
||||
private static readonly float3 LightDir2 = new(1.0f, -1.0f, 1.0f);
|
||||
private static readonly float3 LightColor2 = new(0, 0.333333f, 1.0f);
|
||||
private static readonly float3 Offset = new(0.92858f, 0.92858f, 0.32858f);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates a given <see cref="float2"/> value by a specified amount.
|
||||
/// </summary>
|
||||
private static float2 Rotate(float2 v, float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
return new(Hlsl.Cos(a) * v.X + Hlsl.Sin(a) * v.Y, -Hlsl.Sin(a) * v.X + Hlsl.Cos(a) * v.Y);
|
||||
}
|
||||
|
||||
private const int MaxSteps = 30;
|
||||
private const float MinimumDistance = 0.0009f;
|
||||
private const float NormalDistance = 0.0002f;
|
||||
private const int Iterations = 7;
|
||||
private const float Scale = 3.0f;
|
||||
private const float FieldOfView = 1.0f;
|
||||
private const float Jitter = 0.05f;
|
||||
private const float FudgeFactor = 0.7f;
|
||||
private const float NonLinearPerspective = 2.0f;
|
||||
private const float Ambient = 0.32184f;
|
||||
private const float Diffuse = 0.5f;
|
||||
/// <summary>
|
||||
/// Calculates the light at a specified normal and starting color.
|
||||
/// Uses two light sources and no specular lights.
|
||||
/// </summary>
|
||||
private static float3 GetLight(in float3 color, in float3 normal)
|
||||
{
|
||||
float3 lightDir = Hlsl.Normalize(LightDir);
|
||||
float diffuse = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir));
|
||||
|
||||
private static readonly float3 LightDir = 1.0f;
|
||||
private static readonly float3 LightColor = new(1.0f, 1.0f, 0.858824f);
|
||||
private static readonly float3 LightDir2 = new(1.0f, -1.0f, 1.0f);
|
||||
private static readonly float3 LightColor2 = new(0, 0.333333f, 1.0f);
|
||||
private static readonly float3 Offset = new(0.92858f, 0.92858f, 0.32858f);
|
||||
float3 lightDir2 = Hlsl.Normalize(LightDir2);
|
||||
float diffuse2 = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir2));
|
||||
|
||||
/// <summary>
|
||||
/// Rotates a given <see cref="float2"/> value by a specified amount.
|
||||
/// </summary>
|
||||
private static float2 Rotate(float2 v, float a)
|
||||
return
|
||||
(diffuse * Diffuse) * (LightColor * color) +
|
||||
(diffuse2 * Diffuse) * (LightColor2 * color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DE: Infinitely tiled Menger IFS.
|
||||
/// For more info on KIFS, see <a href="http://www.fractalforums.com/3d-fractal-generation/kaleidoscopic-%28escape-time-ifs%29/"/>
|
||||
/// </summary>
|
||||
private float DE(float3 z)
|
||||
{
|
||||
// Performs the GLSL mod function.
|
||||
static float3 Mod(float3 x, float y)
|
||||
{
|
||||
return new(Hlsl.Cos(a) * v.X + Hlsl.Sin(a) * v.Y, -Hlsl.Sin(a) * v.X + Hlsl.Cos(a) * v.Y);
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the light at a specified normal and starting color.
|
||||
/// Uses two light sources and no specular lights.
|
||||
/// </summary>
|
||||
private static float3 GetLight(in float3 color, in float3 normal)
|
||||
z = Hlsl.Abs(1.0f - Mod(z, 2.0f));
|
||||
|
||||
float d = 1000.0f;
|
||||
|
||||
for (int n = 0; n < Iterations; n++)
|
||||
{
|
||||
float3 lightDir = Hlsl.Normalize(LightDir);
|
||||
float diffuse = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir));
|
||||
z.XY = Rotate(z.XY, 4.0f + 2.0f * Hlsl.Cos(time / 8.0f));
|
||||
z = Hlsl.Abs(z);
|
||||
|
||||
float3 lightDir2 = Hlsl.Normalize(LightDir2);
|
||||
float diffuse2 = Hlsl.Max(0.0f, Hlsl.Dot(-normal, lightDir2));
|
||||
if (z.X < z.Y) { z.XY = z.YX; }
|
||||
if (z.X < z.Z) { z.XZ = z.ZX; }
|
||||
if (z.Y < z.Z) { z.YZ = z.ZY; }
|
||||
|
||||
return
|
||||
(diffuse * Diffuse) * (LightColor * color) +
|
||||
(diffuse2 * Diffuse) * (LightColor2 * color);
|
||||
}
|
||||
z = Scale * z - Offset * (Scale - 1.0f);
|
||||
|
||||
/// <summary>
|
||||
/// DE: Infinitely tiled Menger IFS.
|
||||
/// For more info on KIFS, see <a href="http://www.fractalforums.com/3d-fractal-generation/kaleidoscopic-%28escape-time-ifs%29/"/>
|
||||
/// </summary>
|
||||
private float DE(float3 z)
|
||||
{
|
||||
// Performs the GLSL mod function.
|
||||
static float3 Mod(float3 x, float y)
|
||||
if (z.Z < -0.5f * Offset.Z * (Scale - 1.0))
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
z.Z += Offset.Z * (Scale - 1.0f);
|
||||
}
|
||||
|
||||
z = Hlsl.Abs(1.0f - Mod(z, 2.0f));
|
||||
|
||||
float d = 1000.0f;
|
||||
|
||||
for (int n = 0; n < Iterations; n++)
|
||||
{
|
||||
z.XY = Rotate(z.XY, 4.0f + 2.0f * Hlsl.Cos(time / 8.0f));
|
||||
z = Hlsl.Abs(z);
|
||||
|
||||
if (z.X < z.Y) { z.XY = z.YX; }
|
||||
if (z.X < z.Z) { z.XZ = z.ZX; }
|
||||
if (z.Y < z.Z) { z.YZ = z.ZY; }
|
||||
|
||||
z = Scale * z - Offset * (Scale - 1.0f);
|
||||
|
||||
if (z.Z < -0.5f * Offset.Z * (Scale - 1.0))
|
||||
{
|
||||
z.Z += Offset.Z * (Scale - 1.0f);
|
||||
}
|
||||
|
||||
d = Hlsl.Min(d, Hlsl.Length(z) * Hlsl.Pow(Scale, -n - 1.0f));
|
||||
}
|
||||
|
||||
return d - 0.001f;
|
||||
d = Hlsl.Min(d, Hlsl.Length(z) * Hlsl.Pow(Scale, -n - 1.0f));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the finite difference normal at a given position.
|
||||
/// </summary>
|
||||
private float3 getNormal(in float3 pos)
|
||||
return d - 0.001f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the finite difference normal at a given position.
|
||||
/// </summary>
|
||||
private float3 getNormal(in float3 pos)
|
||||
{
|
||||
float3 e = new(0.0f, NormalDistance, 0.0f);
|
||||
|
||||
return Hlsl.Normalize(new float3(
|
||||
DE(pos + e.YXX) - DE(pos - e.YXX),
|
||||
DE(pos + e.XYX) - DE(pos - e.XYX),
|
||||
DE(pos + e.XXY) - DE(pos - e.XXY)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a ray march operation on a specific position.
|
||||
/// </summary>
|
||||
private float4 RayMarch(in float3 from, float3 dir, in float2 fragCoord)
|
||||
{
|
||||
// Computes a pseudo-random number
|
||||
static float Rand(float2 co)
|
||||
{
|
||||
float3 e = new(0.0f, NormalDistance, 0.0f);
|
||||
|
||||
return Hlsl.Normalize(new float3(
|
||||
DE(pos + e.YXX) - DE(pos - e.YXX),
|
||||
DE(pos + e.XYX) - DE(pos - e.XYX),
|
||||
DE(pos + e.XXY) - DE(pos - e.XXY)));
|
||||
return Hlsl.Frac(Hlsl.Cos(Hlsl.Dot(co, new float2(4.898f, 7.23f))) * 23421.631f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a ray march operation on a specific position.
|
||||
/// </summary>
|
||||
private float4 RayMarch(in float3 from, float3 dir, in float2 fragCoord)
|
||||
float totalDistance = Jitter * Rand(fragCoord.XY + time);
|
||||
float3 dir2 = dir;
|
||||
float distance = 0;
|
||||
int steps = 0;
|
||||
float3 pos = 0;
|
||||
|
||||
for (int i = 0; i < MaxSteps; i++)
|
||||
{
|
||||
// Computes a pseudo-random number
|
||||
static float Rand(float2 co)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Cos(Hlsl.Dot(co, new float2(4.898f, 7.23f))) * 23421.631f);
|
||||
}
|
||||
dir.ZY = Rotate(dir2.ZY, totalDistance * Hlsl.Cos(time / 4.0f) * NonLinearPerspective);
|
||||
pos = from + totalDistance * dir;
|
||||
distance = DE(pos) * FudgeFactor;
|
||||
totalDistance += distance;
|
||||
|
||||
float totalDistance = Jitter * Rand(fragCoord.XY + time);
|
||||
float3 dir2 = dir;
|
||||
float distance = 0;
|
||||
int steps = 0;
|
||||
float3 pos = 0;
|
||||
if (distance < MinimumDistance) break;
|
||||
|
||||
for (int i = 0; i < MaxSteps; i++)
|
||||
{
|
||||
dir.ZY = Rotate(dir2.ZY, totalDistance * Hlsl.Cos(time / 4.0f) * NonLinearPerspective);
|
||||
pos = from + totalDistance * dir;
|
||||
distance = DE(pos) * FudgeFactor;
|
||||
totalDistance += distance;
|
||||
|
||||
if (distance < MinimumDistance) break;
|
||||
|
||||
steps = i;
|
||||
}
|
||||
|
||||
float smoothStep = steps + distance / MinimumDistance;
|
||||
float ao = 1.1f - smoothStep / MaxSteps;
|
||||
float3 normal = getNormal(pos - dir * NormalDistance * 3.0f);
|
||||
float3 color = 1.0f;
|
||||
float3 light = GetLight(color, normal);
|
||||
|
||||
color = (color * Ambient + light) * ao;
|
||||
|
||||
return new(color.X, color.Y, color.Z, 1.0f);
|
||||
steps = i;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float3 camPos = 0.5f * time * new float3(1.0f, 0.0f, 0.0f);
|
||||
float3 target = camPos + new float3(1.0f, 0.0f * Hlsl.Cos(time), 0.0f * Hlsl.Sin(0.4f * time));
|
||||
float3 camDir = Hlsl.Normalize(target - camPos);
|
||||
float3 camUp = new(0.0f, 1.0f, 0.0f);
|
||||
float smoothStep = steps + distance / MinimumDistance;
|
||||
float ao = 1.1f - smoothStep / MaxSteps;
|
||||
float3 normal = getNormal(pos - dir * NormalDistance * 3.0f);
|
||||
float3 color = 1.0f;
|
||||
float3 light = GetLight(color, normal);
|
||||
|
||||
camUp = Hlsl.Normalize(camUp - Hlsl.Dot(camDir, camUp) * camDir);
|
||||
color = (color * Ambient + light) * ao;
|
||||
|
||||
float3 camRight = Hlsl.Normalize(Hlsl.Cross(camDir, camUp));
|
||||
float2 coord = -1.0f + 2.0f * (float2)ThreadIds.XY / DispatchSize.XY;
|
||||
return new(color.X, color.Y, color.Z, 1.0f);
|
||||
}
|
||||
|
||||
coord.X *= (float)DispatchSize.X / DispatchSize.Y;
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float3 camPos = 0.5f * time * new float3(1.0f, 0.0f, 0.0f);
|
||||
float3 target = camPos + new float3(1.0f, 0.0f * Hlsl.Cos(time), 0.0f * Hlsl.Sin(0.4f * time));
|
||||
float3 camDir = Hlsl.Normalize(target - camPos);
|
||||
float3 camUp = new(0.0f, 1.0f, 0.0f);
|
||||
|
||||
float3 rayDir = Hlsl.Normalize(camDir + (coord.X * camRight + coord.Y * camUp) * FieldOfView);
|
||||
camUp = Hlsl.Normalize(camUp - Hlsl.Dot(camDir, camUp) * camDir);
|
||||
|
||||
return RayMarch(camPos, rayDir, ThreadIds.XY);
|
||||
}
|
||||
float3 camRight = Hlsl.Normalize(Hlsl.Cross(camDir, camUp));
|
||||
float2 coord = -1.0f + 2.0f * (float2)ThreadIds.XY / DispatchSize.XY;
|
||||
|
||||
coord.X *= (float)DispatchSize.X / DispatchSize.Y;
|
||||
|
||||
float3 rayDir = Hlsl.Normalize(camDir + (coord.X * camRight + coord.Y * camUp) * FieldOfView);
|
||||
|
||||
return RayMarch(camPos, rayDir, ThreadIds.XY);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +1,122 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A shader creating an octagram animation, inspired by arabesque.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/tlVGDt"/>.
|
||||
/// <para>Created by whisky_shusuky.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct Octagrams : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A shader creating an octagram animation, inspired by arabesque.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/tlVGDt"/>.
|
||||
/// <para>Created by whisky_shusuky.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct Octagrams : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
private static float2x2 Rotate(float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
private static float2x2 Rotate(float a)
|
||||
return new(c, s, -s, c);
|
||||
}
|
||||
|
||||
private static float Box(float3 pos, float scale)
|
||||
{
|
||||
static float SDBox(float3 p, float3 b)
|
||||
{
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
float3 q = Hlsl.Abs(p) - b;
|
||||
|
||||
return new(c, s, -s, c);
|
||||
return Hlsl.Length(Hlsl.Max(q, 0.0f)) +
|
||||
Hlsl.Min(Hlsl.Max(q.X, Hlsl.Max(q.Y, q.Z)), 0.0f);
|
||||
}
|
||||
|
||||
private static float Box(float3 pos, float scale)
|
||||
{
|
||||
static float SDBox(float3 p, float3 b)
|
||||
{
|
||||
float3 q = Hlsl.Abs(p) - b;
|
||||
pos *= scale;
|
||||
|
||||
return Hlsl.Length(Hlsl.Max(q, 0.0f)) +
|
||||
Hlsl.Min(Hlsl.Max(q.X, Hlsl.Max(q.Y, q.Z)), 0.0f);
|
||||
float b = SDBox(pos, new(0.4f, 0.4f, 0.1f)) / 1.5f;
|
||||
|
||||
pos.XY *= 5.0f;
|
||||
pos.Y -= 3.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.75f));
|
||||
|
||||
return -b;
|
||||
}
|
||||
|
||||
private static float BoxSet(float3 pos, float gTime)
|
||||
{
|
||||
float3 pos_origin = pos;
|
||||
|
||||
pos = pos_origin;
|
||||
pos.Y += Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box1 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.Y -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box2 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.X += Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box3 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.X -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box4 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box5 = Box(pos, 0.5f) * 6.0f;
|
||||
|
||||
pos = pos_origin;
|
||||
|
||||
float box6 = Box(pos, 0.5f) * 6.0f;
|
||||
float result = Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(box1, box2), box3), box4), box5), box6);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 p = ((float2)ThreadIds.XY * 2.0f - DispatchSize.XY) / Hlsl.Min(DispatchSize.X, DispatchSize.Y);
|
||||
float3 ro = new(0.0f, -0.2f, time * 4.0f);
|
||||
float3 ray = Hlsl.Normalize(new float3(p, 1.5f));
|
||||
|
||||
ray.XY = Hlsl.Mul(ray.XY, Rotate(Hlsl.Sin(time * 0.03f) * 5.0f));
|
||||
ray.YZ = Hlsl.Mul(ray.YZ, Rotate(Hlsl.Sin(time * 0.05f) * 0.2f));
|
||||
|
||||
float t = 0.1f;
|
||||
float ac = 0.0f;
|
||||
|
||||
for (int i = 0; i < 99; i++)
|
||||
{
|
||||
static float3 Mod(float3 x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
pos *= scale;
|
||||
float3 pos = ro + ray * t;
|
||||
|
||||
float b = SDBox(pos, new(0.4f, 0.4f, 0.1f)) / 1.5f;
|
||||
pos = Mod(pos - 2.0f, 4.0f) - 2.0f;
|
||||
|
||||
pos.XY *= 5.0f;
|
||||
pos.Y -= 3.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.75f));
|
||||
float gTime = time - i * 0.01f;
|
||||
float d = BoxSet(pos, gTime);
|
||||
|
||||
return -b;
|
||||
d = Hlsl.Max(Hlsl.Abs(d), 0.01f);
|
||||
ac += Hlsl.Exp(-d * 23.0f);
|
||||
t += d * 0.55f;
|
||||
}
|
||||
|
||||
private static float BoxSet(float3 pos, float gTime)
|
||||
{
|
||||
float3 pos_origin = pos;
|
||||
float3 col = ac * 0.02f + new float3(0.0f, 0.2f * Hlsl.Abs(Hlsl.Sin(time)), 0.5f + Hlsl.Sin(time) * 0.2f);
|
||||
float4 color = new(col, 1.0f - t * (0.02f + 0.02f * Hlsl.Sin(time)));
|
||||
|
||||
pos = pos_origin;
|
||||
pos.Y += Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box1 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.Y -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box2 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.X += Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box3 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.X -= Hlsl.Sin(gTime * 0.4f) * 2.5f;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box4 = Box(pos, 2.0f - Hlsl.Abs(Hlsl.Sin(gTime * 0.4f)) * 1.5f);
|
||||
|
||||
pos = pos_origin;
|
||||
pos.XY = Hlsl.Mul(pos.XY, Rotate(0.8f));
|
||||
|
||||
float box5 = Box(pos, 0.5f) * 6.0f;
|
||||
|
||||
pos = pos_origin;
|
||||
|
||||
float box6 = Box(pos, 0.5f) * 6.0f;
|
||||
float result = Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(Hlsl.Max(box1, box2), box3), box4), box5), box6);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 p = ((float2)ThreadIds.XY * 2.0f - DispatchSize.XY) / Hlsl.Min(DispatchSize.X, DispatchSize.Y);
|
||||
float3 ro = new(0.0f, -0.2f, time * 4.0f);
|
||||
float3 ray = Hlsl.Normalize(new float3(p, 1.5f));
|
||||
|
||||
ray.XY = Hlsl.Mul(ray.XY, Rotate(Hlsl.Sin(time * 0.03f) * 5.0f));
|
||||
ray.YZ = Hlsl.Mul(ray.YZ, Rotate(Hlsl.Sin(time * 0.05f) * 0.2f));
|
||||
|
||||
float t = 0.1f;
|
||||
float ac = 0.0f;
|
||||
|
||||
for (int i = 0; i < 99; i++)
|
||||
{
|
||||
static float3 Mod(float3 x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
float3 pos = ro + ray * t;
|
||||
|
||||
pos = Mod(pos - 2.0f, 4.0f) - 2.0f;
|
||||
|
||||
float gTime = time - i * 0.01f;
|
||||
float d = BoxSet(pos, gTime);
|
||||
|
||||
d = Hlsl.Max(Hlsl.Abs(d), 0.01f);
|
||||
ac += Hlsl.Exp(-d * 23.0f);
|
||||
t += d * 0.55f;
|
||||
}
|
||||
|
||||
float3 col = ac * 0.02f + new float3(0.0f, 0.2f * Hlsl.Abs(Hlsl.Sin(time)), 0.5f + Hlsl.Sin(time) * 0.2f);
|
||||
float4 color = new(col, 1.0f - t * (0.02f + 0.02f * Hlsl.Sin(time)));
|
||||
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -1,168 +1,167 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// Fully procedural 3D animated volume with three evaluations per step (for shading).
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/3l23Rh"/>.
|
||||
/// <para>Created by nimitz (twitter: @stormoid).</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ProteanClouds : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Fully procedural 3D animated volume with three evaluations per step (for shading).
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/3l23Rh"/>.
|
||||
/// <para>Created by nimitz (twitter: @stormoid).</para>
|
||||
/// <para>License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.</para>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct ProteanClouds : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
private static readonly float3x3 m3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
|
||||
|
||||
private static float2x2 Rotate(in float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
return new(c, s, -s, c);
|
||||
}
|
||||
|
||||
private static readonly float3x3 m3 = new float3x3(0.33338f, 0.56034f, -0.71817f, -0.87887f, 0.32651f, -0.15323f, 0.15162f, 0.69596f, 0.61339f) * 1.93f;
|
||||
private static float LinStep(in float mn, in float mx, in float x)
|
||||
{
|
||||
return Hlsl.Clamp((x - mn) / (mx - mn), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
private static float2x2 Rotate(in float a)
|
||||
private static float2 Disp(float t)
|
||||
{
|
||||
return new float2(Hlsl.Sin(t * 0.22f) * 1.0f, Hlsl.Cos(t * 0.175f) * 1.0f) * 2.0f;
|
||||
}
|
||||
|
||||
private float2 Map(float3 p, float prm1, float2 bsMo)
|
||||
{
|
||||
float3 p2 = p;
|
||||
|
||||
p2.XY -= Disp(p.Z).XY;
|
||||
p.XY = Hlsl.Mul(p.XY, Rotate(Hlsl.Sin(p.Z + time) * (0.1f + prm1 * 0.05f) + time * 0.09f));
|
||||
|
||||
float cl = Hlsl.Dot(p2.XY, p2.XY);
|
||||
float d = 0.0f;
|
||||
|
||||
p *= 0.61f;
|
||||
|
||||
float z = 1.0f;
|
||||
float trk = 1.0f;
|
||||
float dspAmp = 0.1f + prm1 * 0.2f;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
return new(c, s, -s, c);
|
||||
p += Hlsl.Sin(p.ZXY * 0.75f * trk + time * trk * 0.8f) * dspAmp;
|
||||
d -= Hlsl.Abs(Hlsl.Dot(Hlsl.Cos(p), Hlsl.Sin(p.YZX)) * z);
|
||||
z *= 0.57f;
|
||||
trk *= 1.4f;
|
||||
|
||||
p = Hlsl.Mul(p, m3);
|
||||
}
|
||||
|
||||
private static float LinStep(in float mn, in float mx, in float x)
|
||||
d = Hlsl.Abs(d + prm1 * 3.0f) + prm1 * 0.3f - 2.5f + bsMo.Y;
|
||||
|
||||
return new float2(d + cl * 0.2f + 0.25f, cl);
|
||||
}
|
||||
|
||||
private float4 Render(float3 ro, float3 rd, float time, float prm1, float2 bsMo)
|
||||
{
|
||||
float4 rez = 0;
|
||||
float t = 1.5f;
|
||||
float fogT = 0;
|
||||
|
||||
for (int i = 0; i < 130; i++)
|
||||
{
|
||||
return Hlsl.Clamp((x - mn) / (mx - mn), 0.0f, 1.0f);
|
||||
}
|
||||
if (rez.A > 0.99f) break;
|
||||
|
||||
private static float2 Disp(float t)
|
||||
{
|
||||
return new float2(Hlsl.Sin(t * 0.22f) * 1.0f, Hlsl.Cos(t * 0.175f) * 1.0f) * 2.0f;
|
||||
}
|
||||
float3 pos = ro + t * rd;
|
||||
float2 mpv = Map(pos, prm1, bsMo);
|
||||
float den = Hlsl.Clamp(mpv.X - 0.3f, 0.0f, 1.0f) * 1.12f;
|
||||
float dn = Hlsl.Clamp((mpv.X + 2.0f), 0.0f, 3.0f);
|
||||
float4 col = 0f;
|
||||
|
||||
private float2 Map(float3 p, float prm1, float2 bsMo)
|
||||
{
|
||||
float3 p2 = p;
|
||||
|
||||
p2.XY -= Disp(p.Z).XY;
|
||||
p.XY = Hlsl.Mul(p.XY, Rotate(Hlsl.Sin(p.Z + time) * (0.1f + prm1 * 0.05f) + time * 0.09f));
|
||||
|
||||
float cl = Hlsl.Dot(p2.XY, p2.XY);
|
||||
float d = 0.0f;
|
||||
|
||||
p *= 0.61f;
|
||||
|
||||
float z = 1.0f;
|
||||
float trk = 1.0f;
|
||||
float dspAmp = 0.1f + prm1 * 0.2f;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
if (mpv.X > 0.6f)
|
||||
{
|
||||
p += Hlsl.Sin(p.ZXY * 0.75f * trk + time * trk * 0.8f) * dspAmp;
|
||||
d -= Hlsl.Abs(Hlsl.Dot(Hlsl.Cos(p), Hlsl.Sin(p.YZX)) * z);
|
||||
z *= 0.57f;
|
||||
trk *= 1.4f;
|
||||
|
||||
p = Hlsl.Mul(p, m3);
|
||||
col = new float4(Hlsl.Sin(new float3(5.0f, 0.4f, 0.2f) + mpv.Y * 0.1f + Hlsl.Sin(pos.Z * 0.4f) * 0.5f + 1.8f) * 0.5f + 0.5f, 0.08f);
|
||||
col *= den * den * den;
|
||||
col.RGB *= LinStep(4.0f, -2.5f, mpv.X) * 2.3f;
|
||||
|
||||
float dif = Hlsl.Clamp((den - Map(pos + 0.8f, prm1, bsMo).X) / 9.0f, 0.001f, 1.0f);
|
||||
|
||||
dif += Hlsl.Clamp((den - Map(pos + 0.35f, prm1, bsMo).X) / 2.5f, 0.001f, 1.0f);
|
||||
col.XYZ *= den * (new float3(0.005f, 0.045f, 0.075f) + 1.5f * new float3(0.033f, 0.07f, 0.03f) * dif);
|
||||
}
|
||||
|
||||
d = Hlsl.Abs(d + prm1 * 3.0f) + prm1 * 0.3f - 2.5f + bsMo.Y;
|
||||
float fogC = Hlsl.Exp(t * 0.2f - 2.2f);
|
||||
|
||||
return new float2(d + cl * 0.2f + 0.25f, cl);
|
||||
col += new float4(0.06f, 0.11f, 0.11f, 0.1f) * Hlsl.Clamp(fogC - fogT, 0.0f, 1.0f);
|
||||
fogT = fogC;
|
||||
rez += col * (1.0f - rez.A);
|
||||
t += Hlsl.Clamp(0.5f - dn * dn * 0.05f, 0.09f, 0.3f);
|
||||
}
|
||||
|
||||
private float4 Render(float3 ro, float3 rd, float time, float prm1, float2 bsMo)
|
||||
{
|
||||
float4 rez = 0;
|
||||
float t = 1.5f;
|
||||
float fogT = 0;
|
||||
return Hlsl.Clamp(rez, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 130; i++)
|
||||
{
|
||||
if (rez.A > 0.99f) break;
|
||||
private static float GetSaturation(float3 c)
|
||||
{
|
||||
float mi = Hlsl.Min(Hlsl.Min(c.X, c.Y), c.Z);
|
||||
float ma = Hlsl.Max(Hlsl.Max(c.X, c.Y), c.Z);
|
||||
|
||||
float3 pos = ro + t * rd;
|
||||
float2 mpv = Map(pos, prm1, bsMo);
|
||||
float den = Hlsl.Clamp(mpv.X - 0.3f, 0.0f, 1.0f) * 1.12f;
|
||||
float dn = Hlsl.Clamp((mpv.X + 2.0f), 0.0f, 3.0f);
|
||||
float4 col = 0f;
|
||||
return (ma - mi) / (ma + (float)1e-7);
|
||||
}
|
||||
|
||||
if (mpv.X > 0.6f)
|
||||
{
|
||||
private static float3 ILerp(in float3 a, in float3 b, in float x)
|
||||
{
|
||||
float3 ic = Hlsl.Lerp(a, b, x) + new float3((float)1e-6, 0.0f, 0.0f);
|
||||
float sd = Hlsl.Abs(GetSaturation(ic) - Hlsl.Lerp(GetSaturation(a), GetSaturation(b), x));
|
||||
float3 dir = Hlsl.Normalize(new float3(2.0f * ic.X - ic.Y - ic.Z, 2.0f * ic.Y - ic.X - ic.Z, 2.0f * ic.Z - ic.Y - ic.X));
|
||||
float lgt = Hlsl.Dot(1.0f, ic);
|
||||
float ff = Hlsl.Dot(dir, Hlsl.Normalize(ic));
|
||||
|
||||
col = new float4(Hlsl.Sin(new float3(5.0f, 0.4f, 0.2f) + mpv.Y * 0.1f + Hlsl.Sin(pos.Z * 0.4f) * 0.5f + 1.8f) * 0.5f + 0.5f, 0.08f);
|
||||
col *= den * den * den;
|
||||
col.RGB *= LinStep(4.0f, -2.5f, mpv.X) * 2.3f;
|
||||
ic += 1.5f * dir * sd * ff * lgt;
|
||||
|
||||
float dif = Hlsl.Clamp((den - Map(pos + 0.8f, prm1, bsMo).X) / 9.0f, 0.001f, 1.0f);
|
||||
return Hlsl.Clamp(ic, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
dif += Hlsl.Clamp((den - Map(pos + 0.35f, prm1, bsMo).X) / 2.5f, 0.001f, 1.0f);
|
||||
col.XYZ *= den * (new float3(0.005f, 0.045f, 0.075f) + 1.5f * new float3(0.033f, 0.07f, 0.03f) * dif);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 q = (float2)ThreadIds.XY / DispatchSize.XY;
|
||||
float2 p = (ThreadIds.XY - 0.5f * (float2)DispatchSize.XY) / DispatchSize.Y;
|
||||
float2 bsMo = -0.5f * (float2)DispatchSize.XY / DispatchSize.Y;
|
||||
float scaledTime = time * 3.0f;
|
||||
float3 ro = new(0, 0, scaledTime);
|
||||
|
||||
float fogC = Hlsl.Exp(t * 0.2f - 2.2f);
|
||||
ro += new float3(Hlsl.Sin(time) * 0.5f, Hlsl.Sin(time * 1.0f) * 0.0f, 0);
|
||||
|
||||
col += new float4(0.06f, 0.11f, 0.11f, 0.1f) * Hlsl.Clamp(fogC - fogT, 0.0f, 1.0f);
|
||||
fogT = fogC;
|
||||
rez += col * (1.0f - rez.A);
|
||||
t += Hlsl.Clamp(0.5f - dn * dn * 0.05f, 0.09f, 0.3f);
|
||||
}
|
||||
float dspAmp = 0.85f;
|
||||
|
||||
return Hlsl.Clamp(rez, 0.0f, 1.0f);
|
||||
}
|
||||
ro.XY += Disp(ro.Z) * dspAmp;
|
||||
|
||||
private static float GetSaturation(float3 c)
|
||||
{
|
||||
float mi = Hlsl.Min(Hlsl.Min(c.X, c.Y), c.Z);
|
||||
float ma = Hlsl.Max(Hlsl.Max(c.X, c.Y), c.Z);
|
||||
float tgtDst = 3.5f;
|
||||
float3 target = Hlsl.Normalize(ro - new float3(Disp(scaledTime + tgtDst) * dspAmp, scaledTime + tgtDst));
|
||||
|
||||
return (ma - mi) / (ma + (float)1e-7);
|
||||
}
|
||||
ro.X -= bsMo.X * 2.0f;
|
||||
|
||||
private static float3 ILerp(in float3 a, in float3 b, in float x)
|
||||
{
|
||||
float3 ic = Hlsl.Lerp(a, b, x) + new float3((float)1e-6, 0.0f, 0.0f);
|
||||
float sd = Hlsl.Abs(GetSaturation(ic) - Hlsl.Lerp(GetSaturation(a), GetSaturation(b), x));
|
||||
float3 dir = Hlsl.Normalize(new float3(2.0f * ic.X - ic.Y - ic.Z, 2.0f * ic.Y - ic.X - ic.Z, 2.0f * ic.Z - ic.Y - ic.X));
|
||||
float lgt = Hlsl.Dot(1.0f, ic);
|
||||
float ff = Hlsl.Dot(dir, Hlsl.Normalize(ic));
|
||||
float3 rightdir = Hlsl.Normalize(Hlsl.Cross(target, new float3(0, 1, 0)));
|
||||
float3 updir = Hlsl.Normalize(Hlsl.Cross(rightdir, target));
|
||||
|
||||
ic += 1.5f * dir * sd * ff * lgt;
|
||||
rightdir = Hlsl.Normalize(Hlsl.Cross(updir, target));
|
||||
|
||||
return Hlsl.Clamp(ic, 0.0f, 1.0f);
|
||||
}
|
||||
float3 rd = Hlsl.Normalize((p.X * rightdir + p.Y * updir) * 1.0f - target);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 q = (float2)ThreadIds.XY / DispatchSize.XY;
|
||||
float2 p = (ThreadIds.XY - 0.5f * (float2)DispatchSize.XY) / DispatchSize.Y;
|
||||
float2 bsMo = -0.5f * (float2)DispatchSize.XY / DispatchSize.Y;
|
||||
float scaledTime = time * 3.0f;
|
||||
float3 ro = new(0, 0, scaledTime);
|
||||
rd.XY = Hlsl.Mul(rd.XY, Rotate(-Disp(scaledTime + 3.5f).X * 0.2f + bsMo.X));
|
||||
|
||||
ro += new float3(Hlsl.Sin(time) * 0.5f, Hlsl.Sin(time * 1.0f) * 0.0f, 0);
|
||||
float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(time * 0.3f));
|
||||
float4 scn = Render(ro, rd, scaledTime, prm1, bsMo);
|
||||
float3 col = scn.RGB;
|
||||
|
||||
float dspAmp = 0.85f;
|
||||
col = ILerp(col.BGR, col.RGB, Hlsl.Clamp(1.0f - prm1, 0.05f, 1.0f));
|
||||
col = Hlsl.Pow(col, new float3(0.55f, 0.65f, 0.6f)) * new float3(1.0f, 0.97f, 0.9f);
|
||||
col *= Hlsl.Pow(16.0f * q.X * q.Y * (1.0f - q.X) * (1.0f - q.Y), 0.12f) * 0.7f + 0.3f;
|
||||
|
||||
ro.XY += Disp(ro.Z) * dspAmp;
|
||||
|
||||
float tgtDst = 3.5f;
|
||||
float3 target = Hlsl.Normalize(ro - new float3(Disp(scaledTime + tgtDst) * dspAmp, scaledTime + tgtDst));
|
||||
|
||||
ro.X -= bsMo.X * 2.0f;
|
||||
|
||||
float3 rightdir = Hlsl.Normalize(Hlsl.Cross(target, new float3(0, 1, 0)));
|
||||
float3 updir = Hlsl.Normalize(Hlsl.Cross(rightdir, target));
|
||||
|
||||
rightdir = Hlsl.Normalize(Hlsl.Cross(updir, target));
|
||||
|
||||
float3 rd = Hlsl.Normalize((p.X * rightdir + p.Y * updir) * 1.0f - target);
|
||||
|
||||
rd.XY = Hlsl.Mul(rd.XY, Rotate(-Disp(scaledTime + 3.5f).X * 0.2f + bsMo.X));
|
||||
|
||||
float prm1 = Hlsl.SmoothStep(-0.4f, 0.4f, Hlsl.Sin(time * 0.3f));
|
||||
float4 scn = Render(ro, rd, scaledTime, prm1, bsMo);
|
||||
float3 col = scn.RGB;
|
||||
|
||||
col = ILerp(col.BGR, col.RGB, Hlsl.Clamp(1.0f - prm1, 0.05f, 1.0f));
|
||||
col = Hlsl.Pow(col, new float3(0.55f, 0.65f, 0.6f)) * new float3(1.0f, 0.97f, 0.9f);
|
||||
col *= Hlsl.Pow(16.0f * q.X * q.Y * (1.0f - q.X) * (1.0f - q.Y), 0.12f) * 0.7f + 0.3f;
|
||||
|
||||
return new(col, 1.0f);
|
||||
}
|
||||
return new(col, 1.0f);
|
||||
}
|
||||
}
|
||||
@@ -1,176 +1,175 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// An offset grid of square-based pyramids whose tips have been offset according to an underlying directional noise field.
|
||||
/// The faux lighting is provided via bump mapping. No raymarching was harmed during the making of this example.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/wlscWX"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct PyramidPattern : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// An offset grid of square-based pyramids whose tips have been offset according to an underlying directional noise field.
|
||||
/// The faux lighting is provided via bump mapping. No raymarching was harmed during the making of this example.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/wlscWX"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct PyramidPattern : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(in float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(in float a)
|
||||
return new(c, -s, s, c);
|
||||
}
|
||||
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// float2 to float2 hash.
|
||||
private static float2 Hash22B(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
|
||||
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
|
||||
}
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private static float N2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22B(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22B(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * (3.0f - 2.0f * p);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Two layers of noise.
|
||||
private static float FBM(float2 p)
|
||||
{
|
||||
return N2D3G(p) * 0.66f + N2D3G(p * 2.0f) * 0.34f;
|
||||
}
|
||||
|
||||
// HLSL mod from GLSL
|
||||
private static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
private float BMap(float2 p)
|
||||
{
|
||||
p = Hlsl.Mul(p, Rotate2x2(-3.14159f / 5.0f));
|
||||
|
||||
if (Mod(Hlsl.Floor(p.Y), 2.0f) < 0.5f)
|
||||
{
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
return new(c, -s, s, c);
|
||||
p.X += 0.5f;
|
||||
}
|
||||
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
float2 ip = Hlsl.Floor(p);
|
||||
|
||||
// float2 to float2 hash.
|
||||
private static float2 Hash22B(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
p -= ip + 0.5f;
|
||||
|
||||
return Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f;
|
||||
}
|
||||
float ang = -3.14159f * 3.0f / 5.0f + (FBM(ip / 8.0f + time / 3.0f)) * 6.2831f * 2.0f;
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private static float N2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
float2 offs = new float2(Hlsl.Cos(ang), Hlsl.Sin(ang)) * 0.35f;
|
||||
|
||||
float4 v = default;
|
||||
if (p.X < offs.X) p.X = 1.0f - (p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f);
|
||||
else p.X = (p.X - offs.X) / (0.5f - offs.X);
|
||||
|
||||
v.X = Hlsl.Dot(Hash22B(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22B(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22B(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22B(i + 1.0f), p - 1.0f);
|
||||
if (p.Y < offs.Y) p.Y = 1.0f - (p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f);
|
||||
else p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
|
||||
|
||||
p = p * p * (3.0f - 2.0f * p);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
// Two layers of noise.
|
||||
private static float FBM(float2 p)
|
||||
{
|
||||
return N2D3G(p) * 0.66f + N2D3G(p * 2.0f) * 0.34f;
|
||||
}
|
||||
|
||||
// HLSL mod from GLSL
|
||||
private static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
private float BMap(float2 p)
|
||||
{
|
||||
p = Hlsl.Mul(p, Rotate2x2(-3.14159f / 5.0f));
|
||||
|
||||
if (Mod(Hlsl.Floor(p.Y), 2.0f) < 0.5f)
|
||||
{
|
||||
p.X += 0.5f;
|
||||
}
|
||||
|
||||
float2 ip = Hlsl.Floor(p);
|
||||
|
||||
p -= ip + 0.5f;
|
||||
|
||||
float ang = -3.14159f * 3.0f / 5.0f + (FBM(ip / 8.0f + time / 3.0f)) * 6.2831f * 2.0f;
|
||||
|
||||
float2 offs = new float2(Hlsl.Cos(ang), Hlsl.Sin(ang)) * 0.35f;
|
||||
|
||||
if (p.X < offs.X) p.X = 1.0f - (p.X + 0.5f) / Hlsl.Abs(offs.X + 0.5f);
|
||||
else p.X = (p.X - offs.X) / (0.5f - offs.X);
|
||||
|
||||
if (p.Y < offs.Y) p.Y = 1.0f - (p.Y + 0.5f) / Hlsl.Abs(offs.Y + 0.5f);
|
||||
else p.Y = (p.Y - offs.Y) / (0.5f - offs.Y);
|
||||
|
||||
return 1.0f - Hlsl.Max(p.X, p.Y);
|
||||
}
|
||||
return 1.0f - Hlsl.Max(p.X, p.Y);
|
||||
}
|
||||
|
||||
|
||||
// Standard function-based bump mapping function, with an edge value included for good measure
|
||||
private float3 DoBumpMap(in float2 p, in float3 n, float bumpfactor, ref float edge)
|
||||
{
|
||||
float2 e = new(0.025f, 0);
|
||||
// Standard function-based bump mapping function, with an edge value included for good measure
|
||||
private float3 DoBumpMap(in float2 p, in float3 n, float bumpfactor, ref float edge)
|
||||
{
|
||||
float2 e = new(0.025f, 0);
|
||||
|
||||
float f = BMap(p);
|
||||
float fx = BMap(p - e.XY);
|
||||
float fy = BMap(p - e.YX);
|
||||
float fx2 = BMap(p + e.XY);
|
||||
float fy2 = BMap(p + e.YX);
|
||||
float f = BMap(p);
|
||||
float fx = BMap(p - e.XY);
|
||||
float fy = BMap(p - e.YX);
|
||||
float fx2 = BMap(p + e.XY);
|
||||
float fy2 = BMap(p + e.YX);
|
||||
|
||||
float3 grad = (new float3(fx - fx2, fy - fx2, 0)) / e.X / 2.0f;
|
||||
float3 grad = (new float3(fx - fx2, fy - fx2, 0)) / e.X / 2.0f;
|
||||
|
||||
edge = Hlsl.Length(new float2(fx, fy) + new float2(fx2, fy2) - f * 2.0f);
|
||||
edge = Hlsl.SmoothStep(0.0f, 1.0f, edge / e.X);
|
||||
edge = Hlsl.Length(new float2(fx, fy) + new float2(fx2, fy2) - f * 2.0f);
|
||||
edge = Hlsl.SmoothStep(0.0f, 1.0f, edge / e.X);
|
||||
|
||||
grad -= n * Hlsl.Dot(n, grad);
|
||||
grad -= n * Hlsl.Dot(n, grad);
|
||||
|
||||
return Hlsl.Normalize(n + grad * bumpfactor);
|
||||
}
|
||||
return Hlsl.Normalize(n + grad * bumpfactor);
|
||||
}
|
||||
|
||||
|
||||
// A hatch-like algorithm, or a stipple... or some kind of textured pattern
|
||||
private float DoHatch(float2 p, float res)
|
||||
{
|
||||
p *= res / 16.0f;
|
||||
// A hatch-like algorithm, or a stipple... or some kind of textured pattern
|
||||
private float DoHatch(float2 p, float res)
|
||||
{
|
||||
p *= res / 16.0f;
|
||||
|
||||
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
|
||||
float hatch = Hlsl.Clamp(Hlsl.Sin((p.X - p.Y) * 3.14159f * 200.0f) * 2.0f + 0.5f, 0.0f, 1.0f);
|
||||
|
||||
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
|
||||
if (hRnd > 0.66f) hatch = hRnd;
|
||||
float hRnd = Hash21(Hlsl.Floor(p * 6.0f) + 0.73f);
|
||||
if (hRnd > 0.66f) hatch = hRnd;
|
||||
|
||||
return hatch;
|
||||
}
|
||||
return hatch;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float iRes = Hlsl.Min(DispatchSize.Y, 800.0f);
|
||||
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / iRes;
|
||||
float3 rd = Hlsl.Normalize(new float3(uv, 0.5f));
|
||||
const float gSc = 10.0f;
|
||||
float2 p = uv * gSc + new float2(0, time / 2.0f);
|
||||
float2 oP = p;
|
||||
float m = BMap(p);
|
||||
float3 n = new(0, 0, -1);
|
||||
float
|
||||
edge = 0.0f,
|
||||
bumpFactor = 0.25f;
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float iRes = Hlsl.Min(DispatchSize.Y, 800.0f);
|
||||
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / iRes;
|
||||
float3 rd = Hlsl.Normalize(new float3(uv, 0.5f));
|
||||
const float gSc = 10.0f;
|
||||
float2 p = uv * gSc + new float2(0, time / 2.0f);
|
||||
float2 oP = p;
|
||||
float m = BMap(p);
|
||||
float3 n = new(0, 0, -1);
|
||||
float
|
||||
edge = 0.0f,
|
||||
bumpFactor = 0.25f;
|
||||
|
||||
n = DoBumpMap(p, n, bumpFactor, ref edge);
|
||||
n = DoBumpMap(p, n, bumpFactor, ref edge);
|
||||
|
||||
float3 lp = new float3(-0.0f + Hlsl.Sin(time) * 0.3f, 0.0f + Hlsl.Cos(time * 1.3f) * 0.3f, -1) - new float3(uv, 0);
|
||||
float lDist = Hlsl.Max(Hlsl.Length(lp), 0.001f);
|
||||
float3 ld = lp / lDist;
|
||||
float diff = Hlsl.Max(Hlsl.Dot(n, ld), 0.0f);
|
||||
float3 lp = new float3(-0.0f + Hlsl.Sin(time) * 0.3f, 0.0f + Hlsl.Cos(time * 1.3f) * 0.3f, -1) - new float3(uv, 0);
|
||||
float lDist = Hlsl.Max(Hlsl.Length(lp), 0.001f);
|
||||
float3 ld = lp / lDist;
|
||||
float diff = Hlsl.Max(Hlsl.Dot(n, ld), 0.0f);
|
||||
|
||||
diff = Hlsl.Pow(diff, 4.0f);
|
||||
diff = Hlsl.Pow(diff, 4.0f);
|
||||
|
||||
float spec = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(-ld, n), -rd), 0.0f), 16.0f);
|
||||
float fre = Hlsl.Min(Hlsl.Pow(Hlsl.Max(1.0f + Hlsl.Dot(n, rd), 0.0f), 4.0f), 3.0f);
|
||||
float3 col = 0.15f * (diff + 0.251f + spec * new float3(1, 0.7f, 0.3f) * 9.0f + fre * new float3(0.1f, 0.3f, 1) * 12.0f);
|
||||
float rf = Hlsl.SmoothStep(0.0f, 0.35f, BMap(Hlsl.Reflect(rd, n).XY * 2.0f) * FBM(Hlsl.Reflect(rd, n).XY * 3.0f) + 0.1f);
|
||||
float spec = Hlsl.Pow(Hlsl.Max(Hlsl.Dot(Hlsl.Reflect(-ld, n), -rd), 0.0f), 16.0f);
|
||||
float fre = Hlsl.Min(Hlsl.Pow(Hlsl.Max(1.0f + Hlsl.Dot(n, rd), 0.0f), 4.0f), 3.0f);
|
||||
float3 col = 0.15f * (diff + 0.251f + spec * new float3(1, 0.7f, 0.3f) * 9.0f + fre * new float3(0.1f, 0.3f, 1) * 12.0f);
|
||||
float rf = Hlsl.SmoothStep(0.0f, 0.35f, BMap(Hlsl.Reflect(rd, n).XY * 2.0f) * FBM(Hlsl.Reflect(rd, n).XY * 3.0f) + 0.1f);
|
||||
|
||||
col += col * col * rf * rf * new float3(1, 0.1f, 0.1f) * 15.0f;
|
||||
col += col * col * rf * rf * new float3(1, 0.1f, 0.1f) * 15.0f;
|
||||
|
||||
float shade = m * 0.83f + 0.17f;
|
||||
float shade = m * 0.83f + 0.17f;
|
||||
|
||||
col *= shade;
|
||||
col *= 1.0f - edge * 0.8f;
|
||||
col *= shade;
|
||||
col *= 1.0f - edge * 0.8f;
|
||||
|
||||
float hatch = DoHatch(oP / gSc, iRes);
|
||||
float hatch = DoHatch(oP / gSc, iRes);
|
||||
|
||||
col *= hatch * 0.5f + 0.7f;
|
||||
col *= hatch * 0.5f + 0.7f;
|
||||
|
||||
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
}
|
||||
@@ -1,279 +1,278 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// Utilizing a 2D simplex grid to construct the isolines of a noise function.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/WtfGDX"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilizing a 2D simplex grid to construct the isolines of a noise function.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/WtfGDX"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TriangleGridContouring : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(in float a)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time Hlsl.Since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
|
||||
// Standard 2D rotation formula.
|
||||
private static float2x2 Rotate2x2(in float a)
|
||||
return new(c, -s, s, c);
|
||||
}
|
||||
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// float2 to float2 hash.
|
||||
private float2 Hash22(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
|
||||
p = Hlsl.Frac(new float2(262144, 32768) * n);
|
||||
|
||||
return Hlsl.Sin(p * 6.2831853f + time);
|
||||
}
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private float N2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
}
|
||||
|
||||
|
||||
// The isofunction. Just a Hlsl.Single noise function, but it can be more elaborate.
|
||||
private float IsoFunction(in float2 p)
|
||||
{
|
||||
return N2D3G(p / 4.0f + 0.07f);
|
||||
}
|
||||
|
||||
// Unsigned distance to the segment joining "a" and "b".
|
||||
private static float DistLine(float2 a, float2 b)
|
||||
{
|
||||
b = a - b;
|
||||
|
||||
float h = Hlsl.Clamp(Hlsl.Dot(a, b) / Hlsl.Dot(b, b), 0.0f, 1.0f);
|
||||
|
||||
return Hlsl.Length(a - b * h);
|
||||
}
|
||||
|
||||
// Based on IQ's signed distance to the segment joining "a" and "b".
|
||||
private static float distEdge(float2 a, float2 b)
|
||||
{
|
||||
return Hlsl.Dot((a + b) * 0.5f, Hlsl.Normalize((b - a).YX * new float2(-1, 1)));
|
||||
}
|
||||
|
||||
// Interpolating along the edge connecting vertices v1 and v2 with respect to the isovalue.
|
||||
private static float2 Interpolate(in float2 p1, in float2 p2, float v1, float v2, float isovalue)
|
||||
{
|
||||
return Hlsl.Lerp(p1, p2, (isovalue - v1) / (v2 - v1) * 0.75f + 0.25f / 2.0f);
|
||||
}
|
||||
|
||||
// Isoline function.
|
||||
private static int IsoLine(
|
||||
float3 n3,
|
||||
float2 ip0,
|
||||
float2 ip1,
|
||||
float2 ip2,
|
||||
float isovalue,
|
||||
float i,
|
||||
ref float2 p0,
|
||||
ref float2 p1)
|
||||
{
|
||||
p0 = 1e5f;
|
||||
p1 = 1e5f;
|
||||
|
||||
int iTh = 0;
|
||||
|
||||
if (n3.X > isovalue) iTh += 4;
|
||||
if (n3.Y > isovalue) iTh += 2;
|
||||
if (n3.Z > isovalue) iTh += 1;
|
||||
|
||||
if (iTh == 1 || iTh == 6)
|
||||
{
|
||||
float c = Hlsl.Cos(a), s = Hlsl.Sin(a);
|
||||
p0 = Interpolate(ip1, ip2, n3.Y, n3.Z, isovalue);
|
||||
p1 = Interpolate(ip2, ip0, n3.Z, n3.X, isovalue);
|
||||
|
||||
return new(c, -s, s, c);
|
||||
}
|
||||
else if (iTh == 2 || iTh == 5)
|
||||
{
|
||||
p0 = Interpolate(ip0, ip1, n3.X, n3.Y, isovalue);
|
||||
p1 = Interpolate(ip1, ip2, n3.Y, n3.Z, isovalue);
|
||||
|
||||
}
|
||||
else if (iTh == 3 || iTh == 4)
|
||||
{
|
||||
p0 = Interpolate(ip0, ip1, n3.X, n3.Y, isovalue);
|
||||
p1 = Interpolate(ip2, ip0, n3.Z, n3.X, isovalue);
|
||||
}
|
||||
|
||||
// IQ's float2 to float hash.
|
||||
private static float Hash21(float2 p)
|
||||
if (iTh >= 4 && iTh <= 6)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// float2 to float2 hash.
|
||||
private float2 Hash22(float2 p)
|
||||
{
|
||||
float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289)));
|
||||
|
||||
p = Hlsl.Frac(new float2(262144, 32768) * n);
|
||||
|
||||
return Hlsl.Sin(p * 6.2831853f + time);
|
||||
}
|
||||
|
||||
// Based on IQ's gradient noise formula.
|
||||
private float N2D3G(float2 p)
|
||||
{
|
||||
float2 i = Hlsl.Floor(p);
|
||||
float2 tmp = p0;
|
||||
|
||||
p -= i;
|
||||
|
||||
float4 v = default;
|
||||
|
||||
v.X = Hlsl.Dot(Hash22(i), p);
|
||||
v.Y = Hlsl.Dot(Hash22(i + float2.UnitX), p - float2.UnitX);
|
||||
v.Z = Hlsl.Dot(Hash22(i + float2.UnitY), p - float2.UnitY);
|
||||
v.W = Hlsl.Dot(Hash22(i + 1.0f), p - 1.0f);
|
||||
|
||||
p = p * p * p * (p * (p * 6.0f - 15.0f) + 10.0f);
|
||||
|
||||
return Hlsl.Lerp(Hlsl.Lerp(v.X, v.Y, p.X), Hlsl.Lerp(v.Z, v.W, p.X), p.Y);
|
||||
p0 = p1;
|
||||
p1 = tmp;
|
||||
}
|
||||
|
||||
|
||||
// The isofunction. Just a Hlsl.Single noise function, but it can be more elaborate.
|
||||
private float IsoFunction(in float2 p)
|
||||
if (i == 0.0f)
|
||||
{
|
||||
return N2D3G(p / 4.0f + 0.07f);
|
||||
float2 tmp = p0;
|
||||
|
||||
p0 = p1;
|
||||
p1 = tmp;
|
||||
}
|
||||
|
||||
// Unsigned distance to the segment joining "a" and "b".
|
||||
private static float DistLine(float2 a, float2 b)
|
||||
return iTh;
|
||||
}
|
||||
|
||||
private float3 SimplexContour(float2 p)
|
||||
{
|
||||
const float gSc = 8.0f;
|
||||
|
||||
p *= gSc;
|
||||
|
||||
float2 oP = p;
|
||||
|
||||
p += new float2(N2D3G(p * 3.5f), N2D3G(p * 3.5f + 7.3f)) * 0.015f;
|
||||
|
||||
float2 s = Hlsl.Floor(p + (p.X + p.Y) * 0.36602540378f);
|
||||
|
||||
p -= s - (s.X + s.Y) * 0.211324865f;
|
||||
|
||||
float i = p.X < p.Y ? 1.0f : 0.0f;
|
||||
float2
|
||||
ioffs = new(1.0f - i, i),
|
||||
ip0 = 0,
|
||||
ip1 = ioffs - 0.2113248654f,
|
||||
ip2 = 0.577350269f,
|
||||
ctr = (ip0 + ip1 + ip2) / 3.0f;
|
||||
|
||||
ip0 -= ctr;
|
||||
ip1 -= ctr;
|
||||
ip2 -= ctr;
|
||||
p -= ctr;
|
||||
|
||||
float3 n3 = default;
|
||||
|
||||
n3.X = IsoFunction(s);
|
||||
n3.Y = IsoFunction(s + ioffs);
|
||||
n3.Z = IsoFunction(s + 1.0f);
|
||||
|
||||
float
|
||||
d = 1e5f,
|
||||
d2 = 1e5f,
|
||||
d3 = 1e5f,
|
||||
d4 = 1e5f,
|
||||
d5 = 1e5f;
|
||||
|
||||
float isovalue = 0;
|
||||
float2 p0 = default, p1 = default;
|
||||
int iTh = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
|
||||
|
||||
d = Hlsl.Min(d, distEdge(p - p0, p - p1));
|
||||
|
||||
if (iTh == 7)
|
||||
{
|
||||
b = a - b;
|
||||
|
||||
float h = Hlsl.Clamp(Hlsl.Dot(a, b) / Hlsl.Dot(b, b), 0.0f, 1.0f);
|
||||
|
||||
return Hlsl.Length(a - b * h);
|
||||
d = 0;
|
||||
}
|
||||
|
||||
// Based on IQ's signed distance to the segment joining "a" and "b".
|
||||
private static float distEdge(float2 a, float2 b)
|
||||
{
|
||||
return Hlsl.Dot((a + b) * 0.5f, Hlsl.Normalize((b - a).YX * new float2(-1, 1)));
|
||||
}
|
||||
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
|
||||
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
|
||||
|
||||
// Interpolating along the edge connecting vertices v1 and v2 with respect to the isovalue.
|
||||
private static float2 Interpolate(in float2 p1, in float2 p2, float v1, float v2, float isovalue)
|
||||
{
|
||||
return Hlsl.Lerp(p1, p2, (isovalue - v1) / (v2 - v1) * 0.75f + 0.25f / 2.0f);
|
||||
}
|
||||
float tri = Hlsl.Min(Hlsl.Min(DistLine(p - ip0, p - ip1), DistLine(p - ip1, p - ip2)), DistLine(p - ip2, p - ip0));
|
||||
|
||||
// Isoline function.
|
||||
private static int IsoLine(
|
||||
float3 n3,
|
||||
float2 ip0,
|
||||
float2 ip1,
|
||||
float2 ip2,
|
||||
float isovalue,
|
||||
float i,
|
||||
ref float2 p0,
|
||||
ref float2 p1)
|
||||
{
|
||||
p0 = 1e5f;
|
||||
p1 = 1e5f;
|
||||
d5 = Hlsl.Min(d5, tri);
|
||||
d5 = Hlsl.Min(d5, Hlsl.Length(p) - 0.02f);
|
||||
isovalue = -0.15f;
|
||||
|
||||
int iTh = 0;
|
||||
int iTh2 = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
|
||||
|
||||
if (n3.X > isovalue) iTh += 4;
|
||||
if (n3.Y > isovalue) iTh += 2;
|
||||
if (n3.Z > isovalue) iTh += 1;
|
||||
d2 = Hlsl.Min(d2, distEdge(p - p0, p - p1));
|
||||
|
||||
if (iTh == 1 || iTh == 6)
|
||||
{
|
||||
p0 = Interpolate(ip1, ip2, n3.Y, n3.Z, isovalue);
|
||||
p1 = Interpolate(ip2, ip0, n3.Z, n3.X, isovalue);
|
||||
float oldD2 = d2;
|
||||
|
||||
}
|
||||
else if (iTh == 2 || iTh == 5)
|
||||
{
|
||||
p0 = Interpolate(ip0, ip1, n3.X, n3.Y, isovalue);
|
||||
p1 = Interpolate(ip1, ip2, n3.Y, n3.Z, isovalue);
|
||||
if (iTh2 == 7) d2 = 0.0f;
|
||||
if (iTh == 7) d2 = 1e5f;
|
||||
|
||||
}
|
||||
else if (iTh == 3 || iTh == 4)
|
||||
{
|
||||
p0 = Interpolate(ip0, ip1, n3.X, n3.Y, isovalue);
|
||||
p1 = Interpolate(ip2, ip0, n3.Z, n3.X, isovalue);
|
||||
}
|
||||
d2 = Hlsl.Max(d2, -d);
|
||||
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
|
||||
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
|
||||
d4 -= 0.075f;
|
||||
d3 -= 0.0125f;
|
||||
d /= gSc;
|
||||
d2 /= gSc;
|
||||
d3 /= gSc;
|
||||
d4 /= gSc;
|
||||
d5 /= gSc;
|
||||
|
||||
if (iTh >= 4 && iTh <= 6)
|
||||
{
|
||||
float2 tmp = p0;
|
||||
|
||||
p0 = p1;
|
||||
p1 = tmp;
|
||||
}
|
||||
float3 col = new(1, 0.85f, 0.6f);
|
||||
float sf = 0.004f;
|
||||
|
||||
if (i == 0.0f)
|
||||
{
|
||||
float2 tmp = p0;
|
||||
|
||||
p0 = p1;
|
||||
p1 = tmp;
|
||||
}
|
||||
if (d > 0.0f && d2 > 0.0f) col = new float3(1, 1.8f, 3) * 0.45f;
|
||||
if (d > 0.0f) col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f)));
|
||||
|
||||
return iTh;
|
||||
}
|
||||
col = Hlsl.Lerp(col, new float3(1.1f, 0.85f, 0.6f), (1.0f - Hlsl.SmoothStep(0.0f, sf, d2)));
|
||||
col = Hlsl.Lerp(col, new float3(1.5f, 0.9f, 0.6f) * 0.6f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d - 0.012f)));
|
||||
col = Hlsl.Lerp(col, new float3(1, 0.8f, 0.6f) * new float3(0.7f, 1.0f, 0.75f) * 0.95f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d)));
|
||||
|
||||
private float3 SimplexContour(float2 p)
|
||||
{
|
||||
const float gSc = 8.0f;
|
||||
if (d2 > 0.0f) col *= (Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f + 1.25f) / 2.0f;
|
||||
else col *= Hlsl.Max(2.0f - (Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f, 0.0f);
|
||||
|
||||
p *= gSc;
|
||||
float pat = Hlsl.Abs(Hlsl.Frac(tri * 12.5f + 0.4f) - 0.5f) * 2.0f;
|
||||
|
||||
float2 oP = p;
|
||||
col *= pat * 0.425f + 0.75f;
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d5)) * 0.95f);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d3)));
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4)));
|
||||
col = Hlsl.Lerp(col, float3.One, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4 + 0.005f)));
|
||||
|
||||
p += new float2(N2D3G(p * 3.5f), N2D3G(p * 3.5f + 7.3f)) * 0.015f;
|
||||
float2 q = oP * 1.5f;
|
||||
|
||||
float2 s = Hlsl.Floor(p + (p.X + p.Y) * 0.36602540378f);
|
||||
col = Hlsl.Min(col, 1.0f);
|
||||
|
||||
p -= s - (s.X + s.Y) * 0.211324865f;
|
||||
float gr = Hlsl.Sqrt(Hlsl.Dot(col, new float3(0.299f, 0.587f, 0.114f))) * 1.25f;
|
||||
float ns = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
|
||||
|
||||
float i = p.X < p.Y ? 1.0f : 0.0f;
|
||||
float2
|
||||
ioffs = new(1.0f - i, i),
|
||||
ip0 = 0,
|
||||
ip1 = ioffs - 0.2113248654f,
|
||||
ip2 = 0.577350269f,
|
||||
ctr = (ip0 + ip1 + ip2) / 3.0f;
|
||||
ns = gr - ns;
|
||||
q = Hlsl.Mul(q, Rotate2x2(3.14159f / 3.0f));
|
||||
|
||||
ip0 -= ctr;
|
||||
ip1 -= ctr;
|
||||
ip2 -= ctr;
|
||||
p -= ctr;
|
||||
float ns2 = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
|
||||
|
||||
float3 n3 = default;
|
||||
ns2 = gr - ns2;
|
||||
ns = Hlsl.SmoothStep(0.0f, 1.0f, Hlsl.Min(ns, ns2));
|
||||
col = Hlsl.Lerp(col, col * (ns + 0.35f), 0.4f);
|
||||
|
||||
n3.X = IsoFunction(s);
|
||||
n3.Y = IsoFunction(s + ioffs);
|
||||
n3.Z = IsoFunction(s + 1.0f);
|
||||
return col;
|
||||
}
|
||||
|
||||
float
|
||||
d = 1e5f,
|
||||
d2 = 1e5f,
|
||||
d3 = 1e5f,
|
||||
d4 = 1e5f,
|
||||
d5 = 1e5f;
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / Hlsl.Min(650.0f, DispatchSize.Y);
|
||||
float2 p = Hlsl.Mul(Rotate2x2(3.14159f / 12.0f), uv) + new float2(0.8660254f, 0.5f) * time / 16.0f;
|
||||
float3 col = SimplexContour(p);
|
||||
|
||||
float isovalue = 0;
|
||||
float2 p0 = default, p1 = default;
|
||||
int iTh = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
|
||||
uv = coordinate / (float2)DispatchSize.XY;
|
||||
col *= Hlsl.Pow(16.0f * uv.X * uv.Y * (1.0f - uv.X) * (1.0f - uv.Y), 0.0625f) + 0.1f;
|
||||
|
||||
d = Hlsl.Min(d, distEdge(p - p0, p - p1));
|
||||
|
||||
if (iTh == 7)
|
||||
{
|
||||
d = 0;
|
||||
}
|
||||
|
||||
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
|
||||
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
|
||||
|
||||
float tri = Hlsl.Min(Hlsl.Min(DistLine(p - ip0, p - ip1), DistLine(p - ip1, p - ip2)), DistLine(p - ip2, p - ip0));
|
||||
|
||||
d5 = Hlsl.Min(d5, tri);
|
||||
d5 = Hlsl.Min(d5, Hlsl.Length(p) - 0.02f);
|
||||
isovalue = -0.15f;
|
||||
|
||||
int iTh2 = IsoLine(n3, ip0, ip1, ip2, isovalue, i, ref p0, ref p1);
|
||||
|
||||
d2 = Hlsl.Min(d2, distEdge(p - p0, p - p1));
|
||||
|
||||
float oldD2 = d2;
|
||||
|
||||
if (iTh2 == 7) d2 = 0.0f;
|
||||
if (iTh == 7) d2 = 1e5f;
|
||||
|
||||
d2 = Hlsl.Max(d2, -d);
|
||||
d3 = Hlsl.Min(d3, DistLine((p - p0), (p - p1)));
|
||||
d4 = Hlsl.Min(d4, Hlsl.Min(Hlsl.Length(p - p0), Hlsl.Length(p - p1)));
|
||||
d4 -= 0.075f;
|
||||
d3 -= 0.0125f;
|
||||
d /= gSc;
|
||||
d2 /= gSc;
|
||||
d3 /= gSc;
|
||||
d4 /= gSc;
|
||||
d5 /= gSc;
|
||||
|
||||
float3 col = new(1, 0.85f, 0.6f);
|
||||
float sf = 0.004f;
|
||||
|
||||
if (d > 0.0f && d2 > 0.0f) col = new float3(1, 1.8f, 3) * 0.45f;
|
||||
if (d > 0.0f) col = Hlsl.Lerp(col, new float3(1, 1.85f, 3) * 0.3f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d2 - 0.012f)));
|
||||
|
||||
col = Hlsl.Lerp(col, new float3(1.1f, 0.85f, 0.6f), (1.0f - Hlsl.SmoothStep(0.0f, sf, d2)));
|
||||
col = Hlsl.Lerp(col, new float3(1.5f, 0.9f, 0.6f) * 0.6f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d - 0.012f)));
|
||||
col = Hlsl.Lerp(col, new float3(1, 0.8f, 0.6f) * new float3(0.7f, 1.0f, 0.75f) * 0.95f, (1.0f - Hlsl.SmoothStep(0.0f, sf, d)));
|
||||
|
||||
if (d2 > 0.0f) col *= (Hlsl.Abs(Hlsl.Dot(n3, float3.One)) * 1.25f + 1.25f) / 2.0f;
|
||||
else col *= Hlsl.Max(2.0f - (Hlsl.Dot(n3, float3.One) + 1.45f) / 1.25f, 0.0f);
|
||||
|
||||
float pat = Hlsl.Abs(Hlsl.Frac(tri * 12.5f + 0.4f) - 0.5f) * 2.0f;
|
||||
|
||||
col *= pat * 0.425f + 0.75f;
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d5)) * 0.95f);
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d3)));
|
||||
col = Hlsl.Lerp(col, float3.Zero, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4)));
|
||||
col = Hlsl.Lerp(col, float3.One, (1.0f - Hlsl.SmoothStep(0.0f, sf, d4 + 0.005f)));
|
||||
|
||||
float2 q = oP * 1.5f;
|
||||
|
||||
col = Hlsl.Min(col, 1.0f);
|
||||
|
||||
float gr = Hlsl.Sqrt(Hlsl.Dot(col, new float3(0.299f, 0.587f, 0.114f))) * 1.25f;
|
||||
float ns = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
|
||||
|
||||
ns = gr - ns;
|
||||
q = Hlsl.Mul(q, Rotate2x2(3.14159f / 3.0f));
|
||||
|
||||
float ns2 = (N2D3G(q * 4.0f * new float2(1.0f / 3.0f, 3)) * 0.64f + N2D3G(q * 8.0f * new float2(1.0f / 3.0f, 3)) * 0.34f) * 0.5f + 0.5f;
|
||||
|
||||
ns2 = gr - ns2;
|
||||
ns = Hlsl.SmoothStep(0.0f, 1.0f, Hlsl.Min(ns, ns2));
|
||||
col = Hlsl.Lerp(col, col * (ns + 0.35f), 0.4f);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 coordinate = new(ThreadIds.X, DispatchSize.Y - ThreadIds.Y);
|
||||
float2 uv = (coordinate - (float2)DispatchSize.XY * 0.5f) / Hlsl.Min(650.0f, DispatchSize.Y);
|
||||
float2 p = Hlsl.Mul(Rotate2x2(3.14159f / 12.0f), uv) + new float2(0.8660254f, 0.5f) * time / 16.0f;
|
||||
float3 col = SimplexContour(p);
|
||||
|
||||
uv = coordinate / (float2)DispatchSize.XY;
|
||||
col *= Hlsl.Pow(16.0f * uv.X * uv.Y * (1.0f - uv.X) * (1.0f - uv.Y), 0.0625f) + 0.1f;
|
||||
|
||||
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
return new(Hlsl.Sqrt(Hlsl.Max(col, 0.0f)), 1);
|
||||
}
|
||||
}
|
||||
@@ -1,144 +1,143 @@
|
||||
namespace ComputeSharp.SwapChain.Shaders
|
||||
namespace ComputeSharp.SwapChain.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A shader creating an animated two-tiles Truchet arrangement.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/tsSfWK"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// A shader creating an animated two-tiles Truchet arrangement.
|
||||
/// Ported from <see href="https://www.shadertoy.com/view/tsSfWK"/>.
|
||||
/// <para>Created by Shane.</para>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct TwoTiledTruchet : IPixelShader<float4>
|
||||
public readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Truchet distance field.
|
||||
/// </summary>
|
||||
/// <param name="p">The input value to compute the distance field for.</param>
|
||||
/// <param name="ang">The resulting Truchet angle.</param>
|
||||
/// <returns>The distance field for the input value.</returns>
|
||||
private float2 DistanceField(float2 p, out float2 ang)
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
public readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the Truchet distance field.
|
||||
/// </summary>
|
||||
/// <param name="p">The input value to compute the distance field for.</param>
|
||||
/// <param name="ang">The resulting Truchet angle.</param>
|
||||
/// <returns>The distance field for the input value.</returns>
|
||||
private float2 DistanceField(float2 p, out float2 ang)
|
||||
// Fast hash for a pair of floats
|
||||
static float Hash21(float2 p)
|
||||
{
|
||||
// Fast hash for a pair of floats
|
||||
static float Hash21(float2 p)
|
||||
{
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
// HLSL's port of the GLSL mod intrinsic
|
||||
static float Mod(float x, float y)
|
||||
{
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
float2 ip2 = Hlsl.Floor(p / 2.0f);
|
||||
float2 ip = Hlsl.Floor(p);
|
||||
float rnd = Hash21(ip);
|
||||
float rnd3 = Hash21(ip + 0.57f);
|
||||
float2 d = 1e5f;
|
||||
|
||||
p -= ip + 0.5f;
|
||||
|
||||
if (Mod(ip2.X + ip2.Y, 2.0f) < 0.5f)
|
||||
{
|
||||
d = Hlsl.Abs(p);
|
||||
ang = p.YX;
|
||||
|
||||
if (Mod(ip.X + 1.0f, 2.0f) < 0.5f)
|
||||
{
|
||||
ang.X *= -1.0f;
|
||||
|
||||
}
|
||||
|
||||
if (Mod(ip.Y + 1.0f, 2.0f) > 0.5f)
|
||||
{
|
||||
ang.Y *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd3 < .5)
|
||||
{
|
||||
d = d.YX;
|
||||
ang = ang.YX;
|
||||
}
|
||||
|
||||
ang += 0.5f;
|
||||
ang *= 3.0f;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rnd < .5)
|
||||
{
|
||||
p = p.YX * new float2(1, -1);
|
||||
}
|
||||
|
||||
d.X = Hlsl.Length(p - 0.5f) - 0.5f;
|
||||
d.Y = Hlsl.Length(p + 0.5f) - 0.5f;
|
||||
|
||||
d = Hlsl.Abs(d);
|
||||
|
||||
ang = 0;
|
||||
ang.X = -Hlsl.Atan((p.Y - 0.5f) / (p.X - 0.5f));
|
||||
ang.Y = -Hlsl.Atan((p.Y + 0.5f) / (p.X + 0.5f));
|
||||
|
||||
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
|
||||
{
|
||||
ang *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd < 0.5f)
|
||||
{
|
||||
ang *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd3 < 0.5f)
|
||||
{
|
||||
d = d.YX;
|
||||
ang = ang.YX;
|
||||
}
|
||||
|
||||
ang *= 4.0f / 6.2831853f;
|
||||
ang *= 2.0f;
|
||||
}
|
||||
|
||||
ang = Hlsl.Frac(ang + time / 4.0f);
|
||||
|
||||
return d;
|
||||
return Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
// HLSL's port of the GLSL mod intrinsic
|
||||
static float Mod(float x, float y)
|
||||
{
|
||||
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float gSc = 7.0f;
|
||||
float2 p = uv * gSc - new float2(-1, -0.5f) * time / 2.0f;
|
||||
float sf = 2.0f / DispatchSize.Y * gSc;
|
||||
float lSc = 6.0f;
|
||||
float lw = 1.0f / lSc / gSc;
|
||||
float2 d = DistanceField(p, out float2 ang) - 2.5f / lSc;
|
||||
float3 col = new(1.0f, 0.9f, 0.8f);
|
||||
return x - y * Hlsl.Floor(x / y);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
float2 ip2 = Hlsl.Floor(p / 2.0f);
|
||||
float2 ip = Hlsl.Floor(p);
|
||||
float rnd = Hash21(ip);
|
||||
float rnd3 = Hash21(ip + 0.57f);
|
||||
float2 d = 1e5f;
|
||||
|
||||
p -= ip + 0.5f;
|
||||
|
||||
if (Mod(ip2.X + ip2.Y, 2.0f) < 0.5f)
|
||||
{
|
||||
d = Hlsl.Abs(p);
|
||||
ang = p.YX;
|
||||
|
||||
if (Mod(ip.X + 1.0f, 2.0f) < 0.5f)
|
||||
{
|
||||
float di = d[i] - lw / 4.0f;
|
||||
float tracks = Hlsl.Clamp(Hlsl.Sin(ang[i] * 6.2831f + time * 6.0f) * 4.0f, 0.0f, 1.0f);
|
||||
float gap = 1.0f + lw;
|
||||
ang.X *= -1.0f;
|
||||
|
||||
col = Hlsl.Lerp(col, 0, (1.0f - Hlsl.SmoothStep(0.0f, sf * 6.0f, di)) * 0.35f);
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di));
|
||||
col = Hlsl.Lerp(col, new(1.0f, 0.9f, 0.8f), 1.0f - Hlsl.SmoothStep(0.0f, sf, di + lw * 2.0f));
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc));
|
||||
col = Hlsl.Lerp(col, 1, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc + lw));
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc));
|
||||
col = Hlsl.Lerp(col, 1 * tracks, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc + lw));
|
||||
}
|
||||
|
||||
float3 rgb = Hlsl.Sqrt(Hlsl.Max(col, 0.0f));
|
||||
float4 color = new(rgb.X, rgb.Y, rgb.Z, 1.0f);
|
||||
if (Mod(ip.Y + 1.0f, 2.0f) > 0.5f)
|
||||
{
|
||||
ang.Y *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd3 < .5)
|
||||
{
|
||||
d = d.YX;
|
||||
ang = ang.YX;
|
||||
}
|
||||
|
||||
ang += 0.5f;
|
||||
ang *= 3.0f;
|
||||
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rnd < .5)
|
||||
{
|
||||
p = p.YX * new float2(1, -1);
|
||||
}
|
||||
|
||||
d.X = Hlsl.Length(p - 0.5f) - 0.5f;
|
||||
d.Y = Hlsl.Length(p + 0.5f) - 0.5f;
|
||||
|
||||
d = Hlsl.Abs(d);
|
||||
|
||||
ang = 0;
|
||||
ang.X = -Hlsl.Atan((p.Y - 0.5f) / (p.X - 0.5f));
|
||||
ang.Y = -Hlsl.Atan((p.Y + 0.5f) / (p.X + 0.5f));
|
||||
|
||||
if (Mod(ip.X + ip.Y, 2.0f) < 0.5f)
|
||||
{
|
||||
ang *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd < 0.5f)
|
||||
{
|
||||
ang *= -1.0f;
|
||||
}
|
||||
|
||||
if (rnd3 < 0.5f)
|
||||
{
|
||||
d = d.YX;
|
||||
ang = ang.YX;
|
||||
}
|
||||
|
||||
ang *= 4.0f / 6.2831853f;
|
||||
ang *= 2.0f;
|
||||
}
|
||||
|
||||
ang = Hlsl.Frac(ang + time / 4.0f);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y;
|
||||
float gSc = 7.0f;
|
||||
float2 p = uv * gSc - new float2(-1, -0.5f) * time / 2.0f;
|
||||
float sf = 2.0f / DispatchSize.Y * gSc;
|
||||
float lSc = 6.0f;
|
||||
float lw = 1.0f / lSc / gSc;
|
||||
float2 d = DistanceField(p, out float2 ang) - 2.5f / lSc;
|
||||
float3 col = new(1.0f, 0.9f, 0.8f);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
float di = d[i] - lw / 4.0f;
|
||||
float tracks = Hlsl.Clamp(Hlsl.Sin(ang[i] * 6.2831f + time * 6.0f) * 4.0f, 0.0f, 1.0f);
|
||||
float gap = 1.0f + lw;
|
||||
|
||||
col = Hlsl.Lerp(col, 0, (1.0f - Hlsl.SmoothStep(0.0f, sf * 6.0f, di)) * 0.35f);
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di));
|
||||
col = Hlsl.Lerp(col, new(1.0f, 0.9f, 0.8f), 1.0f - Hlsl.SmoothStep(0.0f, sf, di + lw * 2.0f));
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc));
|
||||
col = Hlsl.Lerp(col, 1, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + gap / lSc + lw));
|
||||
col = Hlsl.Lerp(col, 0, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc));
|
||||
col = Hlsl.Lerp(col, 1 * tracks, 1.0f - Hlsl.SmoothStep(0.0f, sf, di + 2.0f * gap / lSc + lw));
|
||||
}
|
||||
|
||||
float3 rgb = Hlsl.Sqrt(Hlsl.Max(col, 0.0f));
|
||||
float4 color = new(rgb.X, rgb.Y, rgb.Z, 1.0f);
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -4,53 +4,51 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class AutoConstructorGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class AutoConstructorGenerator
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
if (context.Node is StructDeclarationSyntax { AttributeLists: { Count: > 0 } } structDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(structDeclaration) is INamedTypeSymbol structSymbol &&
|
||||
context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(AutoConstructorAttribute).FullName) is INamedTypeSymbol attributeSymbol &&
|
||||
structSymbol.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol)) is AttributeData attributeData &&
|
||||
attributeData.ApplicationSyntaxReference is SyntaxReference syntaxReference &&
|
||||
syntaxReference.GetSyntax() is AttributeSyntax attributeSyntax)
|
||||
{
|
||||
if (context.Node is StructDeclarationSyntax { AttributeLists: { Count: > 0 } } structDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(structDeclaration) is INamedTypeSymbol structSymbol &&
|
||||
context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(AutoConstructorAttribute).FullName) is INamedTypeSymbol attributeSymbol &&
|
||||
structSymbol.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol)) is AttributeData attributeData &&
|
||||
attributeData.ApplicationSyntaxReference is SyntaxReference syntaxReference &&
|
||||
syntaxReference.GetSyntax() is AttributeSyntax attributeSyntax)
|
||||
{
|
||||
this.gatheredInfo.Add(new Item(structDeclaration, structSymbol, attributeSyntax, attributeData));
|
||||
}
|
||||
this.gatheredInfo.Add(new Item(structDeclaration, structSymbol, attributeSyntax, attributeData));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered type to process.
|
||||
/// </summary>
|
||||
/// <param name="StructDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the target struct declaration.</param>
|
||||
/// <param name="StructSymbol">The <see cref="INamedTypeSymbol"/> instance for <paramref name="StructDeclaration"/>.</param>
|
||||
/// <param name="AttributeSyntax">The <see cref="AttributeSyntax"/> instance for the target attribute over <paramref name="StructDeclaration"/>.</param>
|
||||
/// <param name="AttributeData">The <see cref="AttributeData"/> instance for <paramref name="AttributeSyntax"/>.</param>
|
||||
public sealed record Item(
|
||||
StructDeclarationSyntax StructDeclaration,
|
||||
INamedTypeSymbol StructSymbol,
|
||||
AttributeSyntax AttributeSyntax,
|
||||
AttributeData AttributeData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered type to process.
|
||||
/// </summary>
|
||||
/// <param name="StructDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the target struct declaration.</param>
|
||||
/// <param name="StructSymbol">The <see cref="INamedTypeSymbol"/> instance for <paramref name="StructDeclaration"/>.</param>
|
||||
/// <param name="AttributeSyntax">The <see cref="AttributeSyntax"/> instance for the target attribute over <paramref name="StructDeclaration"/>.</param>
|
||||
/// <param name="AttributeData">The <see cref="AttributeData"/> instance for <paramref name="AttributeSyntax"/>.</param>
|
||||
public sealed record Item(
|
||||
StructDeclarationSyntax StructDeclaration,
|
||||
INamedTypeSymbol StructSymbol,
|
||||
AttributeSyntax AttributeSyntax,
|
||||
AttributeData AttributeData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,102 +11,100 @@ using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
using static Microsoft.CodeAnalysis.SymbolDisplayTypeQualificationStyle;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A source generator creating constructors for types annotated with <see cref="AutoConstructorAttribute"/>.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class AutoConstructorGenerator : ISourceGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A source generator creating constructors for types annotated with <see cref="AutoConstructorAttribute"/>.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class AutoConstructorGenerator : ISourceGenerator
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
{
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
return;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
try
|
||||
{
|
||||
return;
|
||||
OnExecute(context, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
OnExecute(context, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.ReportDiagnostic(AutoConstructorGeneratorError, item.AttributeSyntax, item.StructSymbol);
|
||||
}
|
||||
context.ReportDiagnostic(AutoConstructorGeneratorError, item.AttributeSyntax, item.StructSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target type.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
// Extract the info on the type to process
|
||||
var namespaceName = structDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
|
||||
var structName = structDeclaration.Identifier.Text;
|
||||
var structModifiers = structDeclaration.Modifiers;
|
||||
var fields = (
|
||||
from fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>()
|
||||
where !fieldSymbol.IsConst && !fieldSymbol.IsStatic && !fieldSymbol.IsFixedSizeBuffer
|
||||
let typeName = fieldSymbol.Type!.ToDisplayString()
|
||||
let fieldFullType = ParseTypeName(typeName)
|
||||
select (Type: fieldFullType, Identifier: Identifier(fieldSymbol.Name))).ToImmutableArray();
|
||||
|
||||
// Create the constructor declaration for the type. This will
|
||||
// produce a constructor with simple initialization of all variables:
|
||||
//
|
||||
// public MyType(Foo a, Bar b, Baz c, ...)
|
||||
// {
|
||||
// this.a = a;
|
||||
// this.b = b;
|
||||
// this.c = c;
|
||||
// ...
|
||||
// }
|
||||
var structDeclarationSyntax =
|
||||
StructDeclaration(structName).WithModifiers(structModifiers).AddMembers(
|
||||
ConstructorDeclaration(structName)
|
||||
.AddModifiers(Token(SyntaxKind.PublicKeyword))
|
||||
.AddParameterListParameters(fields.Select(field => Parameter(field.Identifier).WithType(field.Type)).ToArray())
|
||||
.AddBodyStatements(fields.Select(field => ParseStatement($"this.{field.Identifier} = {field.Identifier};")).ToArray()));
|
||||
|
||||
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
|
||||
|
||||
// Add all parent types in ascending order, if any
|
||||
foreach (var parentType in structDeclaration.Ancestors().OfType<TypeDeclarationSyntax>())
|
||||
{
|
||||
typeDeclarationSyntax = parentType
|
||||
.WithMembers(SingletonList<MemberDeclarationSyntax>(typeDeclarationSyntax))
|
||||
.WithConstraintClauses(List<TypeParameterConstraintClauseSyntax>())
|
||||
.WithBaseList(null)
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithoutTrivia();
|
||||
}
|
||||
|
||||
// Create the compilation unit with the namespace and target member.
|
||||
// From this, we can finally generate the source code to output.
|
||||
var source =
|
||||
CompilationUnit().AddMembers(
|
||||
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the partial type
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target type.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
// Extract the info on the type to process
|
||||
var namespaceName = structDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
|
||||
var structName = structDeclaration.Identifier.Text;
|
||||
var structModifiers = structDeclaration.Modifiers;
|
||||
var fields = (
|
||||
from fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>()
|
||||
where !fieldSymbol.IsConst && !fieldSymbol.IsStatic && !fieldSymbol.IsFixedSizeBuffer
|
||||
let typeName = fieldSymbol.Type!.ToDisplayString()
|
||||
let fieldFullType = ParseTypeName(typeName)
|
||||
select (Type: fieldFullType, Identifier: Identifier(fieldSymbol.Name))).ToImmutableArray();
|
||||
|
||||
// Create the constructor declaration for the type. This will
|
||||
// produce a constructor with simple initialization of all variables:
|
||||
//
|
||||
// public MyType(Foo a, Bar b, Baz c, ...)
|
||||
// {
|
||||
// this.a = a;
|
||||
// this.b = b;
|
||||
// this.c = c;
|
||||
// ...
|
||||
// }
|
||||
var structDeclarationSyntax =
|
||||
StructDeclaration(structName).WithModifiers(structModifiers).AddMembers(
|
||||
ConstructorDeclaration(structName)
|
||||
.AddModifiers(Token(SyntaxKind.PublicKeyword))
|
||||
.AddParameterListParameters(fields.Select(field => Parameter(field.Identifier).WithType(field.Type)).ToArray())
|
||||
.AddBodyStatements(fields.Select(field => ParseStatement($"this.{field.Identifier} = {field.Identifier};")).ToArray()));
|
||||
|
||||
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
|
||||
|
||||
// Add all parent types in ascending order, if any
|
||||
foreach (var parentType in structDeclaration.Ancestors().OfType<TypeDeclarationSyntax>())
|
||||
{
|
||||
typeDeclarationSyntax = parentType
|
||||
.WithMembers(SingletonList<MemberDeclarationSyntax>(typeDeclarationSyntax))
|
||||
.WithConstraintClauses(List<TypeParameterConstraintClauseSyntax>())
|
||||
.WithBaseList(null)
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithoutTrivia();
|
||||
}
|
||||
|
||||
// Create the compilation unit with the namespace and target member.
|
||||
// From this, we can finally generate the source code to output.
|
||||
var source =
|
||||
CompilationUnit().AddMembers(
|
||||
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the partial type
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IShader
|
||||
{
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IShader
|
||||
{
|
||||
}
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -1,43 +1,42 @@
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Diagnostics
|
||||
namespace ComputeSharp.SourceGenerators.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="GeneratorExecutionContext"/>, specifically for reporting diagnostics.
|
||||
/// </summary>
|
||||
internal static class DiagnosticsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="GeneratorExecutionContext"/>, specifically for reporting diagnostics.
|
||||
/// Adds a new diagnostics to the current compilation.
|
||||
/// </summary>
|
||||
internal static class DiagnosticsExtensions
|
||||
/// <param name="context">The <see cref="GeneratorEditContext"/> instance currently in use.</param>
|
||||
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
|
||||
/// <param name="symbol">The source <see cref="ISymbol"/> to attach the diagnostics to.</param>
|
||||
/// <param name="args">The optional arguments for the formatted message to include.</param>
|
||||
public static void ReportDiagnostic(
|
||||
this GeneratorExecutionContext context,
|
||||
DiagnosticDescriptor descriptor,
|
||||
ISymbol symbol,
|
||||
params object[] args)
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a new diagnostics to the current compilation.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="GeneratorEditContext"/> instance currently in use.</param>
|
||||
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
|
||||
/// <param name="symbol">The source <see cref="ISymbol"/> to attach the diagnostics to.</param>
|
||||
/// <param name="args">The optional arguments for the formatted message to include.</param>
|
||||
public static void ReportDiagnostic(
|
||||
this GeneratorExecutionContext context,
|
||||
DiagnosticDescriptor descriptor,
|
||||
ISymbol symbol,
|
||||
params object[] args)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args));
|
||||
}
|
||||
context.ReportDiagnostic(Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new diagnostics to the current compilation.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="GeneratorEditContext"/> instance currently in use.</param>
|
||||
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
|
||||
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
|
||||
/// <param name="args">The optional arguments for the formatted message to include.</param>
|
||||
public static void ReportDiagnostic(
|
||||
this GeneratorExecutionContext context,
|
||||
DiagnosticDescriptor descriptor,
|
||||
SyntaxNode node,
|
||||
params object[] args)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(descriptor, node.GetLocation(), args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a new diagnostics to the current compilation.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="GeneratorEditContext"/> instance currently in use.</param>
|
||||
/// <param name="descriptor">The input <see cref="DiagnosticDescriptor"/> for the diagnostics to create.</param>
|
||||
/// <param name="node">The source <see cref="SyntaxNode"/> to attach the diagnostics to.</param>
|
||||
/// <param name="args">The optional arguments for the formatted message to include.</param>
|
||||
public static void ReportDiagnostic(
|
||||
this GeneratorExecutionContext context,
|
||||
DiagnosticDescriptor descriptor,
|
||||
SyntaxNode node,
|
||||
params object[] args)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(descriptor, node.GetLocation(), args));
|
||||
}
|
||||
}
|
||||
@@ -92,4 +92,4 @@ global using uint3x4 = global::ComputeSharp.UInt3x4;
|
||||
global using uint4x1 = global::ComputeSharp.UInt4x1;
|
||||
global using uint4x2 = global::ComputeSharp.UInt4x2;
|
||||
global using uint4x3 = global::ComputeSharp.UInt4x3;
|
||||
global using uint4x4 = global::ComputeSharp.UInt4x4;
|
||||
global using uint4x4 = global::ComputeSharp.UInt4x4;
|
||||
@@ -7,145 +7,144 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Extensions
|
||||
namespace ComputeSharp.SourceGenerators.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ISymbol"/> types.
|
||||
/// </summary>
|
||||
internal static class ISymbolExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ISymbol"/> types.
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global::.
|
||||
/// </summary>
|
||||
internal static class ISymbolExtensions
|
||||
public static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat = new(
|
||||
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
|
||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
|
||||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global:: and parameters.
|
||||
/// </summary>
|
||||
private static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalAndParametersFormat =
|
||||
FullyQualifiedWithoutGlobalFormat
|
||||
.WithMemberOptions(SymbolDisplayMemberOptions.IncludeContainingType)
|
||||
.WithParameterOptions(SymbolDisplayParameterOptions.None);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ITypeSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this ITypeSymbol symbol)
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global::.
|
||||
/// </summary>
|
||||
public static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalFormat = new(
|
||||
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
|
||||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
|
||||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters);
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="SymbolDisplayFormat"/> instance with fully qualified style, without global:: and parameters.
|
||||
/// </summary>
|
||||
private static readonly SymbolDisplayFormat FullyQualifiedWithoutGlobalAndParametersFormat =
|
||||
FullyQualifiedWithoutGlobalFormat
|
||||
.WithMemberOptions(SymbolDisplayMemberOptions.IncludeContainingType)
|
||||
.WithParameterOptions(SymbolDisplayParameterOptions.None);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ITypeSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this ITypeSymbol symbol)
|
||||
static StringBuilder BuildFrom(ISymbol? symbol, StringBuilder builder)
|
||||
{
|
||||
static StringBuilder BuildFrom(ISymbol? symbol, StringBuilder builder)
|
||||
return symbol switch
|
||||
{
|
||||
return symbol switch
|
||||
{
|
||||
INamespaceSymbol ns when ns.IsGlobalNamespace => builder,
|
||||
INamespaceSymbol ns when ns.ContainingNamespace is { IsGlobalNamespace: false }
|
||||
=> BuildFrom(ns.ContainingNamespace, builder.Insert(0, $".{ns.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingType is ISymbol pt => BuildFrom(pt, builder.Insert(0, $"+{ts.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingNamespace is ISymbol pn => BuildFrom(pn, builder.Insert(0, $".{ts.MetadataName}")),
|
||||
ISymbol => BuildFrom(symbol.ContainingSymbol, builder.Insert(0, symbol.MetadataName)),
|
||||
_ => builder
|
||||
};
|
||||
}
|
||||
|
||||
return BuildFrom(symbol, new StringBuilder(256)).ToString();
|
||||
INamespaceSymbol ns when ns.IsGlobalNamespace => builder,
|
||||
INamespaceSymbol ns when ns.ContainingNamespace is { IsGlobalNamespace: false }
|
||||
=> BuildFrom(ns.ContainingNamespace, builder.Insert(0, $".{ns.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingType is ISymbol pt => BuildFrom(pt, builder.Insert(0, $"+{ts.MetadataName}")),
|
||||
ITypeSymbol ts when ts.ContainingNamespace is ISymbol pn => BuildFrom(pn, builder.Insert(0, $".{ts.MetadataName}")),
|
||||
ISymbol => BuildFrom(symbol.ContainingSymbol, builder.Insert(0, symbol.MetadataName)),
|
||||
_ => builder
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IMethodSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IMethodSymbol"/> instance.</param>
|
||||
/// <param name="includeParameters">Whether or not to also include parameter types.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IMethodSymbol symbol, bool includeParameters = false)
|
||||
return BuildFrom(symbol, new StringBuilder(256)).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IMethodSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IMethodSymbol"/> instance.</param>
|
||||
/// <param name="includeParameters">Whether or not to also include parameter types.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IMethodSymbol symbol, bool includeParameters = false)
|
||||
{
|
||||
if (includeParameters)
|
||||
{
|
||||
if (includeParameters)
|
||||
{
|
||||
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
|
||||
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
|
||||
|
||||
return $"{symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat)}({parameters})";
|
||||
}
|
||||
|
||||
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat);
|
||||
return $"{symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat)}({parameters})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IPropertySymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IPropertySymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IPropertySymbol symbol)
|
||||
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IPropertySymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IPropertySymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IPropertySymbol symbol)
|
||||
{
|
||||
string declaringTypeName = symbol.ContainingType.GetFullMetadataName();
|
||||
|
||||
if (symbol.IsIndexer)
|
||||
{
|
||||
string declaringTypeName = symbol.ContainingType.GetFullMetadataName();
|
||||
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
|
||||
|
||||
if (symbol.IsIndexer)
|
||||
{
|
||||
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
|
||||
|
||||
return $"{declaringTypeName}.this[{parameters}]";
|
||||
}
|
||||
|
||||
return $"{declaringTypeName}.{symbol.Name}";
|
||||
return $"{declaringTypeName}.this[{parameters}]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IFieldSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IFieldSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IFieldSymbol symbol)
|
||||
return $"{declaringTypeName}.{symbol.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IFieldSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IFieldSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IFieldSymbol symbol)
|
||||
{
|
||||
return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a target symbol and generator type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol being processed.</param>
|
||||
/// <returns>A filename in the form "<SYMBOL_FULLNAME>"</returns>
|
||||
[Pure]
|
||||
public static string GetGeneratedFileName(this INamedTypeSymbol symbol)
|
||||
{
|
||||
return symbol.GetFullMetadataName().Replace('`', '-').Replace('+', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a target symbol and generator type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol being processed.</param>
|
||||
/// <returns>A filename in the form "<SYMBOL_FULLNAME>"</returns>
|
||||
[Pure]
|
||||
public static string GetGeneratedFileName(this IMethodSymbol symbol)
|
||||
{
|
||||
return symbol.GetFullMetadataName(true).Replace('`', '-').Replace('+', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an <see cref="ITypeSymbol"/> instance and returns an HLSL compatible <see cref="TypeSyntax"/> object.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input <see cref="ITypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TypeSyntax TrackType(this ITypeSymbol typeSymbol, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
string typeName = typeSymbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}";
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a target symbol and generator type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol being processed.</param>
|
||||
/// <returns>A filename in the form "<SYMBOL_FULLNAME>"</returns>
|
||||
[Pure]
|
||||
public static string GetGeneratedFileName(this INamedTypeSymbol symbol)
|
||||
{
|
||||
return symbol.GetFullMetadataName().Replace('`', '-').Replace('+', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a target symbol and generator type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol being processed.</param>
|
||||
/// <returns>A filename in the form "<SYMBOL_FULLNAME>"</returns>
|
||||
[Pure]
|
||||
public static string GetGeneratedFileName(this IMethodSymbol symbol)
|
||||
{
|
||||
return symbol.GetFullMetadataName(true).Replace('`', '-').Replace('+', '.');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an <see cref="ITypeSymbol"/> instance and returns an HLSL compatible <see cref="TypeSyntax"/> object.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input <see cref="ITypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TypeSyntax TrackType(this ITypeSymbol typeSymbol, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
string typeName = typeSymbol.ToDisplayString(FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
return ParseTypeName(typeName.ToHlslIdentifierName());
|
||||
}
|
||||
return ParseTypeName(typeName.ToHlslIdentifierName());
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Extensions
|
||||
namespace ComputeSharp.SourceGenerators.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="string"/> types.
|
||||
/// </summary>
|
||||
internal static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="string"/> types.
|
||||
/// Converts a given <see cref="string"/> instance to a valid HLSL identifier name.
|
||||
/// </summary>
|
||||
internal static class StringExtensions
|
||||
/// <param name="text">The input <see cref="string"/> instance to convert.</param>
|
||||
/// <returns>An valid HLSL identifier name from <paramref name="text"/>.</returns>
|
||||
[Pure]
|
||||
public static string ToHlslIdentifierName(this string text)
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a given <see cref="string"/> instance to a valid HLSL identifier name.
|
||||
/// </summary>
|
||||
/// <param name="text">The input <see cref="string"/> instance to convert.</param>
|
||||
/// <returns>An valid HLSL identifier name from <paramref name="text"/>.</returns>
|
||||
[Pure]
|
||||
public static string ToHlslIdentifierName(this string text)
|
||||
{
|
||||
return text.Replace('.', '_').Replace('+', '_');
|
||||
}
|
||||
return text.Replace('.', '_').Replace('+', '_');
|
||||
}
|
||||
}
|
||||
@@ -7,202 +7,201 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Extensions
|
||||
namespace ComputeSharp.SourceGenerators.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with some extension methods for C# syntax nodes.
|
||||
/// </summary>
|
||||
internal static class SyntaxNodeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with some extension methods for C# syntax nodes.
|
||||
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
|
||||
/// </summary>
|
||||
internal static class SyntaxNodeExtensions
|
||||
/// <typeparam name="TRoot">The type of the input <see cref="TypeSyntax"/> instance.</typeparam>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
|
||||
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
where TRoot : TypeSyntax
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoot">The type of the input <see cref="TypeSyntax"/> instance.</typeparam>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
|
||||
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
where TRoot : TypeSyntax
|
||||
return node.ReplaceAndTrackType(node, sourceType, semanticModel, discoveredTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance.</typeparam>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
|
||||
/// <param name="targetType">The target <see cref="TypeSyntax"/> node to replace.</param>
|
||||
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
where TRoot : SyntaxNode
|
||||
{
|
||||
// Skip immediately for function pointers
|
||||
if (sourceType is FunctionPointerTypeSyntax)
|
||||
{
|
||||
return node.ReplaceAndTrackType(node, sourceType, semanticModel, discoveredTypes);
|
||||
return node.ReplaceNode(targetType, ParseTypeName("void*"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance.</typeparam>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
|
||||
/// <param name="targetType">The target <see cref="TypeSyntax"/> node to replace.</param>
|
||||
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
where TRoot : SyntaxNode
|
||||
// Handle the various possible type kinds
|
||||
ITypeSymbol typeSymbol = sourceType switch
|
||||
{
|
||||
// Skip immediately for function pointers
|
||||
if (sourceType is FunctionPointerTypeSyntax)
|
||||
{
|
||||
return node.ReplaceNode(targetType, ParseTypeName("void*"));
|
||||
}
|
||||
RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type).Type!,
|
||||
PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType).Type!,
|
||||
_ => semanticModel.GetTypeInfo(sourceType).Type!
|
||||
};
|
||||
|
||||
// Handle the various possible type kinds
|
||||
ITypeSymbol typeSymbol = sourceType switch
|
||||
// Do nothing if the type is just void
|
||||
if (typeSymbol.SpecialType == SpecialType.System_Void)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
TypeSyntax newType = ParseTypeName(mappedName!);
|
||||
|
||||
return node.ReplaceNode(targetType, newType);
|
||||
}
|
||||
|
||||
return node.ReplaceNode(targetType, ParseTypeName(typeName.ToHlslIdentifierName()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the associated type for a <see cref="SyntaxNode"/> value and returns the HLSL compatible <see cref="TypeSyntax"/>.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TypeSyntax TrackType(this SyntaxNode node, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(node).Type!;
|
||||
string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
return ParseTypeName(typeName.ToHlslIdentifierName());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> with a block body.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but always with a block body.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax WithBlockBody(this MethodDeclarationSyntax node)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax arrow)
|
||||
{
|
||||
StatementSyntax statement = node.ReturnType switch
|
||||
{
|
||||
RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type).Type!,
|
||||
PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType).Type!,
|
||||
_ => semanticModel.GetTypeInfo(sourceType).Type!
|
||||
PredefinedTypeSyntax pts when pts.Keyword.IsKind(SyntaxKind.VoidKeyword) => ExpressionStatement(arrow.Expression),
|
||||
_ => ReturnStatement(arrow.Expression)
|
||||
};
|
||||
|
||||
// Do nothing if the type is just void
|
||||
if (typeSymbol.SpecialType == SpecialType.System_Void)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
TypeSyntax newType = ParseTypeName(mappedName!);
|
||||
|
||||
return node.ReplaceNode(targetType, newType);
|
||||
}
|
||||
|
||||
return node.ReplaceNode(targetType, ParseTypeName(typeName.ToHlslIdentifierName()));
|
||||
return node
|
||||
.WithBody(Block(statement))
|
||||
.WithExpressionBody(null)
|
||||
.WithSemicolonToken(MissingToken(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the associated type for a <see cref="SyntaxNode"/> value and returns the HLSL compatible <see cref="TypeSyntax"/>.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="SyntaxNode"/> to check.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
|
||||
[Pure]
|
||||
public static TypeSyntax TrackType(this SyntaxNode node, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> as a method definition.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but just as a definition.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax AsDefinition(this MethodDeclarationSyntax node)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax)
|
||||
{
|
||||
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(node).Type!;
|
||||
string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat);
|
||||
|
||||
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
|
||||
|
||||
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
|
||||
{
|
||||
return ParseTypeName(mappedName!);
|
||||
}
|
||||
|
||||
return ParseTypeName(typeName.ToHlslIdentifierName());
|
||||
return node.WithExpressionBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> with a block body.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but always with a block body.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax WithBlockBody(this MethodDeclarationSyntax node)
|
||||
return node.WithBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="LocalFunctionStatementSyntax"/> with a block body.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="LocalFunctionStatementSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but always with a block body.</returns>
|
||||
/// <remarks>
|
||||
/// This method is the same as <see cref="WithBlockBody(MethodDeclarationSyntax)"/>, but it is necessary to
|
||||
/// duplicate the code because the two types don't have a common base type or interface that can be leveraged.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
public static LocalFunctionStatementSyntax WithBlockBody(this LocalFunctionStatementSyntax node)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax arrow)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax arrow)
|
||||
StatementSyntax statement = node.ReturnType switch
|
||||
{
|
||||
StatementSyntax statement = node.ReturnType switch
|
||||
{
|
||||
PredefinedTypeSyntax pts when pts.Keyword.IsKind(SyntaxKind.VoidKeyword) => ExpressionStatement(arrow.Expression),
|
||||
_ => ReturnStatement(arrow.Expression)
|
||||
};
|
||||
PredefinedTypeSyntax pts when pts.Keyword.IsKind(SyntaxKind.VoidKeyword) => ExpressionStatement(arrow.Expression),
|
||||
_ => ReturnStatement(arrow.Expression)
|
||||
};
|
||||
|
||||
return node
|
||||
.WithBody(Block(statement))
|
||||
.WithExpressionBody(null)
|
||||
.WithSemicolonToken(MissingToken(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
return node;
|
||||
return node
|
||||
.WithBody(Block(statement))
|
||||
.WithExpressionBody(null)
|
||||
.WithSemicolonToken(MissingToken(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> as a method definition.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but just as a definition.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax AsDefinition(this MethodDeclarationSyntax node)
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="LocalFunctionStatementSyntax"/> as a method definition.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="LocalFunctionStatementSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but just as a definition.</returns>
|
||||
[Pure]
|
||||
public static LocalFunctionStatementSyntax AsDefinition(this LocalFunctionStatementSyntax node)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax)
|
||||
{
|
||||
return node.WithExpressionBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
return node.WithBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
return node.WithExpressionBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="LocalFunctionStatementSyntax"/> with a block body.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="LocalFunctionStatementSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but always with a block body.</returns>
|
||||
/// <remarks>
|
||||
/// This method is the same as <see cref="WithBlockBody(MethodDeclarationSyntax)"/>, but it is necessary to
|
||||
/// duplicate the code because the two types don't have a common base type or interface that can be leveraged.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
public static LocalFunctionStatementSyntax WithBlockBody(this LocalFunctionStatementSyntax node)
|
||||
return node.WithBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> instance with no accessibility modifiers.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node just like <paramref name="node"/> but with no accessibility modifiers.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax WithoutAccessibilityModifiers(this MethodDeclarationSyntax node)
|
||||
{
|
||||
return node.WithModifiers(TokenList(node.Modifiers.Where(static modifier => modifier.Kind() switch
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax arrow)
|
||||
{
|
||||
StatementSyntax statement = node.ReturnType switch
|
||||
{
|
||||
PredefinedTypeSyntax pts when pts.Keyword.IsKind(SyntaxKind.VoidKeyword) => ExpressionStatement(arrow.Expression),
|
||||
_ => ReturnStatement(arrow.Expression)
|
||||
};
|
||||
|
||||
return node
|
||||
.WithBody(Block(statement))
|
||||
.WithExpressionBody(null)
|
||||
.WithSemicolonToken(MissingToken(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="LocalFunctionStatementSyntax"/> as a method definition.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="LocalFunctionStatementSyntax"/> node.</param>
|
||||
/// <returns>A node like the one in input, but just as a definition.</returns>
|
||||
[Pure]
|
||||
public static LocalFunctionStatementSyntax AsDefinition(this LocalFunctionStatementSyntax node)
|
||||
{
|
||||
if (node.ExpressionBody is ArrowExpressionClauseSyntax)
|
||||
{
|
||||
return node.WithExpressionBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
return node.WithBody(null).WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="MethodDeclarationSyntax"/> instance with no accessibility modifiers.
|
||||
/// </summary>
|
||||
/// <param name="node">The input <see cref="MethodDeclarationSyntax"/> node.</param>
|
||||
/// <returns>A node just like <paramref name="node"/> but with no accessibility modifiers.</returns>
|
||||
[Pure]
|
||||
public static MethodDeclarationSyntax WithoutAccessibilityModifiers(this MethodDeclarationSyntax node)
|
||||
{
|
||||
return node.WithModifiers(TokenList(node.Modifiers.Where(static modifier => modifier.Kind() switch
|
||||
{
|
||||
SyntaxKind.PublicKeyword => false,
|
||||
SyntaxKind.PrivateKeyword => false,
|
||||
SyntaxKind.ProtectedKeyword => false,
|
||||
SyntaxKind.InternalKeyword => false,
|
||||
_ => true
|
||||
}).ToArray()));
|
||||
}
|
||||
SyntaxKind.PublicKeyword => false,
|
||||
SyntaxKind.PrivateKeyword => false,
|
||||
SyntaxKind.ProtectedKeyword => false,
|
||||
SyntaxKind.InternalKeyword => false,
|
||||
_ => true
|
||||
}).ToArray()));
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,32 @@ using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A source generator to create global using directives for the HLSL primitive types.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed class GlobalUsingDirectivesGenerator : ISourceGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A source generator to create global using directives for the HLSL primitive types.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed class GlobalUsingDirectivesGenerator : ISourceGenerator
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
context.RegisterForPostInitialization(static context =>
|
||||
{
|
||||
context.RegisterForPostInitialization(static context =>
|
||||
{
|
||||
const string filename = "ComputeSharp.SourceGenerators.EmbeddedResources.GlobalUsingDirectives.cs";
|
||||
const string filename = "ComputeSharp.SourceGenerators.EmbeddedResources.GlobalUsingDirectives.cs";
|
||||
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename);
|
||||
using StreamReader reader = new(stream);
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename);
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
string globalUsingDirectives = reader.ReadToEnd();
|
||||
string globalUsingDirectives = reader.ReadToEnd();
|
||||
|
||||
context.AddSource("GlobalUsingDirectives.cs", SourceText.From(globalUsingDirectives, Encoding.UTF8));
|
||||
});
|
||||
}
|
||||
context.AddSource("GlobalUsingDirectives.cs", SourceText.From(globalUsingDirectives, Encoding.UTF8));
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.InteropServices.MemoryMarshal"/> on .NET 5.
|
||||
/// </summary>
|
||||
internal static class MemoryMarshal
|
||||
{
|
||||
/// <inheritdoc cref="System.Runtime.InteropServices.MemoryMarshal.GetReference{T}(Span{T})"/>
|
||||
public static ref T GetReference<T>(Span<T> span)
|
||||
{
|
||||
return ref System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
|
||||
}
|
||||
namespace ComputeSharp.SourceGenerators.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Span{T}"/> from a given reference.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of reference to wrap.</typeparam>
|
||||
/// <param name="value">The target reference.</param>
|
||||
/// <param name="length">The length of the <see cref="Span{T}"/> to create.</param>
|
||||
/// <returns>A new <see cref="Span{T}"/> wrapping <paramref name="value"/>.</returns>
|
||||
public static Span<T> CreateSpan<T>(ref T value, int length) => default;
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.InteropServices.MemoryMarshal"/> on .NET 5.
|
||||
/// </summary>
|
||||
internal static class MemoryMarshal
|
||||
{
|
||||
/// <inheritdoc cref="System.Runtime.InteropServices.MemoryMarshal.GetReference{T}(Span{T})"/>
|
||||
public static ref T GetReference<T>(Span<T> span)
|
||||
{
|
||||
return ref System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Span{T}"/> from a given reference.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of reference to wrap.</typeparam>
|
||||
/// <param name="value">The target reference.</param>
|
||||
/// <param name="length">The length of the <see cref="Span{T}"/> to create.</param>
|
||||
/// <returns>A new <see cref="Span{T}"/> wrapping <paramref name="value"/>.</returns>
|
||||
public static Span<T> CreateSpan<T>(ref T value, int length) => default;
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Helpers
|
||||
namespace ComputeSharp.SourceGenerators.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.CompilerServices.RuntimeHelpers"/> on .NET 5.
|
||||
/// </summary>
|
||||
internal static class RuntimeHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A polyfill type that mirrors some methods from <see cref="System.Runtime.CompilerServices.RuntimeHelpers"/> on .NET 5.
|
||||
/// Allocates some memory tied to the lifetime of a specific type.
|
||||
/// </summary>
|
||||
internal static class RuntimeHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Allocates some memory tied to the lifetime of a specific type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to associate the memory to.</param>
|
||||
/// <param name="size">The size in byte of the memory to allocate.</param>
|
||||
/// <returns>A pointer to the allocated memory.</returns>
|
||||
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => default;
|
||||
}
|
||||
/// <param name="type">The type to associate the memory to.</param>
|
||||
/// <param name="size">The size in byte of the memory to allocate.</param>
|
||||
/// <returns>A pointer to the allocated memory.</returns>
|
||||
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => default;
|
||||
}
|
||||
@@ -1,48 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Helpers
|
||||
namespace ComputeSharp.SourceGenerators.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A type providing <see cref="SemanticModel"/> instances for nodes.
|
||||
/// </summary>
|
||||
internal sealed class SemanticModelProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// A type providing <see cref="SemanticModel"/> instances for nodes.
|
||||
/// The source <see cref="Compilation"/> instance.
|
||||
/// </summary>
|
||||
internal sealed class SemanticModelProvider
|
||||
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)
|
||||
{
|
||||
/// <summary>
|
||||
/// The source <see cref="Compilation"/> instance.
|
||||
/// </summary>
|
||||
private readonly Compilation compilation;
|
||||
this.compilation = compilation;
|
||||
this.semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
/// <summary>
|
||||
/// Gets a <see cref="SemanticModel"/> instance with info on a given <see cref="SyntaxNode"/>.
|
||||
/// </summary>
|
||||
/// <param name="syntaxNode">The input <see cref="SyntaxNode"/> to get info for.</param>
|
||||
/// <returns>A <see cref="SemanticModel"/> instance containing info on <paramref name="syntaxNode"/>.</returns>
|
||||
public SemanticModel For(SyntaxNode syntaxNode)
|
||||
{
|
||||
if (!this.semanticModelsMap.TryGetValue(syntaxNode.SyntaxTree, out SemanticModel semanticModel))
|
||||
{
|
||||
this.compilation = compilation;
|
||||
this.semanticModelsMap = new Dictionary<SyntaxTree, SemanticModel>();
|
||||
semanticModel = this.compilation.GetSemanticModel(syntaxNode.SyntaxTree);
|
||||
|
||||
this.semanticModelsMap.Add(syntaxNode.SyntaxTree, semanticModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="SemanticModel"/> instance with info on a given <see cref="SyntaxNode"/>.
|
||||
/// </summary>
|
||||
/// <param name="syntaxNode">The input <see cref="SyntaxNode"/> to get info for.</param>
|
||||
/// <returns>A <see cref="SemanticModel"/> instance containing info on <paramref name="syntaxNode"/>.</returns>
|
||||
public SemanticModel For(SyntaxNode syntaxNode)
|
||||
{
|
||||
if (!this.semanticModelsMap.TryGetValue(syntaxNode.SyntaxTree, out SemanticModel semanticModel))
|
||||
{
|
||||
semanticModel = this.compilation.GetSemanticModel(syntaxNode.SyntaxTree);
|
||||
|
||||
this.semanticModelsMap.Add(syntaxNode.SyntaxTree, semanticModel);
|
||||
}
|
||||
|
||||
return semanticModel;
|
||||
}
|
||||
return semanticModel;
|
||||
}
|
||||
}
|
||||
@@ -5,40 +5,39 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Helpers
|
||||
namespace ComputeSharp.SourceGenerators.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A class containing additional factory methods for constructing syntax nodes, tokens and trivia.
|
||||
/// </summary>
|
||||
internal static class SyntaxFactoryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// A class containing additional factory methods for constructing syntax nodes, tokens and trivia.
|
||||
/// Creates an <see cref="object"/>[] array expression with the nested groups in the input sequence.
|
||||
/// <para>
|
||||
/// That it, it applies the following transformation:
|
||||
/// <code>
|
||||
/// { ("K1", "V1"), ("K2", "V2") } => new object[] { new string[] { "K1", "V1" }, new string[] { "K2", "V2" } }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
internal static class SyntaxFactoryHelper
|
||||
/// <param name="values">The input sequence of <see cref="string"/> groups.</param>
|
||||
/// <returns>An <see cref="ArrayCreationExpressionSyntax"/> instance with the described contents.</returns>
|
||||
[Pure]
|
||||
public static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<(string A, string B)> groups)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an <see cref="object"/>[] array expression with the nested groups in the input sequence.
|
||||
/// <para>
|
||||
/// That it, it applies the following transformation:
|
||||
/// <code>
|
||||
/// { ("K1", "V1"), ("K2", "V2") } => new object[] { new string[] { "K1", "V1" }, new string[] { "K2", "V2" } }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="values">The input sequence of <see cref="string"/> groups.</param>
|
||||
/// <returns>An <see cref="ArrayCreationExpressionSyntax"/> instance with the described contents.</returns>
|
||||
[Pure]
|
||||
public static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<(string A, string B)> groups)
|
||||
{
|
||||
return
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(groups.Select(static group =>
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword)))
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(groups.Select(static group =>
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.A)),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.B))))).ToArray()));
|
||||
}
|
||||
.AddExpressions(
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.A)),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.B))))).ToArray()));
|
||||
}
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -10,91 +10,89 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol)
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly int IShader.GetDispatchId()
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.IntKeyword)),
|
||||
Identifier("GetDispatchId"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithBody(GetShaderHashCodeBody(structDeclarationSymbol));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="BlockSyntax"/> instance with the logic to compute the hashcode of a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <returns>The <see cref="BlockSyntax"/> instance to hash the input shader.</returns>
|
||||
[Pure]
|
||||
private static BlockSyntax GetShaderHashCodeBody(INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
var delegateFields = structDeclarationSymbol
|
||||
.GetMembers()
|
||||
.OfType<IFieldSymbol>()
|
||||
.Where(static m => m.Type is INamedTypeSymbol { TypeKind: TypeKind.Delegate, IsStatic: false })
|
||||
.ToImmutableArray();
|
||||
|
||||
if (delegateFields.Length == 0)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly int IShader.GetDispatchId()
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
// return 0;
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.IntKeyword)),
|
||||
Identifier("GetDispatchId"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithBody(GetShaderHashCodeBody(structDeclarationSymbol));
|
||||
Block(ReturnStatement(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="BlockSyntax"/> instance with the logic to compute the hashcode of a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <returns>The <see cref="BlockSyntax"/> instance to hash the input shader.</returns>
|
||||
[Pure]
|
||||
private static BlockSyntax GetShaderHashCodeBody(INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
var delegateFields = structDeclarationSymbol
|
||||
.GetMembers()
|
||||
.OfType<IFieldSymbol>()
|
||||
.Where(static m => m.Type is INamedTypeSymbol { TypeKind: TypeKind.Delegate, IsStatic: false })
|
||||
.ToImmutableArray();
|
||||
List<StatementSyntax> blockStatements = new(4);
|
||||
|
||||
if (delegateFields.Length == 0)
|
||||
{
|
||||
// return 0;
|
||||
return
|
||||
Block(ReturnStatement(
|
||||
// HashCode hashCode = default;
|
||||
blockStatements.Add(LocalDeclarationStatement(
|
||||
VariableDeclaration(IdentifierName("HashCode"))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("hashCode"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))));
|
||||
}
|
||||
SyntaxKind.DefaultLiteralExpression,
|
||||
Token(SyntaxKind.DefaultKeyword)))))));
|
||||
|
||||
List<StatementSyntax> blockStatements = new(4);
|
||||
|
||||
// HashCode hashCode = default;
|
||||
blockStatements.Add(LocalDeclarationStatement(
|
||||
VariableDeclaration(IdentifierName("HashCode"))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("hashCode"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
LiteralExpression(
|
||||
SyntaxKind.DefaultLiteralExpression,
|
||||
Token(SyntaxKind.DefaultKeyword)))))));
|
||||
|
||||
foreach (IFieldSymbol fieldSymbol in delegateFields)
|
||||
{
|
||||
// hashCode.Add(delegateField.Method);
|
||||
blockStatements.Add(ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("hashCode"),
|
||||
IdentifierName("Add")))
|
||||
.AddArgumentListArguments(Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(fieldSymbol.Name),
|
||||
IdentifierName("Method"))))));
|
||||
}
|
||||
|
||||
// return hashCode.ToHashCode();
|
||||
blockStatements.Add(ReturnStatement(
|
||||
foreach (IFieldSymbol fieldSymbol in delegateFields)
|
||||
{
|
||||
// hashCode.Add(delegateField.Method);
|
||||
blockStatements.Add(ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("hashCode"),
|
||||
IdentifierName("ToHashCode")))));
|
||||
|
||||
return Block(blockStatements);
|
||||
IdentifierName("Add")))
|
||||
.AddArgumentListArguments(Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(fieldSymbol.Name),
|
||||
IdentifierName("Method"))))));
|
||||
}
|
||||
|
||||
// return hashCode.ToHashCode();
|
||||
blockStatements.Add(ReturnStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("hashCode"),
|
||||
IdentifierName("ToHashCode")))));
|
||||
|
||||
return Block(blockStatements);
|
||||
}
|
||||
}
|
||||
|
||||
+268
-270
@@ -14,327 +14,325 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchDataMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out IReadOnlyCollection<string> discoveredResources,
|
||||
out int root32BitConstantsCount)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchDataMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out IReadOnlyCollection<string> discoveredResources,
|
||||
out int root32BitConstantsCount)
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void IShader.LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.VoidKeyword)),
|
||||
Identifier("LoadDispatchData"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddTypeParameterListParameters(TypeParameter(Identifier("TDataLoader")))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("loader"))
|
||||
.AddModifiers(Token(SyntaxKind.RefKeyword))
|
||||
.WithType(IdentifierName("TDataLoader")),
|
||||
Parameter(Identifier("device")).WithType(IdentifierName("GraphicsDevice")),
|
||||
Parameter(Identifier("x")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("y")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("z")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))))
|
||||
.WithBody(Block(GetDispatchDataLoadingStatements(context, structDeclarationSymbol, out discoveredResources, out root32BitConstantsCount)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of statements to load the dispatch data for a given shader.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredResources">The collection of discovered resources in the current shader type.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the current shader type.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
|
||||
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(GeneratorExecutionContext context, INamedTypeSymbol structDeclarationSymbol, out IReadOnlyCollection<string> discoveredResources, out int root32BitConstantsCount)
|
||||
{
|
||||
List<StatementSyntax> statements = new();
|
||||
List<string> resources = new();
|
||||
|
||||
discoveredResources = resources;
|
||||
|
||||
var pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) });
|
||||
var isComputeShader = pixelShaderSymbol is null;
|
||||
int
|
||||
resourceOffset = 0,
|
||||
rawDataOffset = sizeof(int) * (isComputeShader ? 3 : 2);
|
||||
|
||||
// Append the statements for the dispatch ranges:
|
||||
//
|
||||
// span0[0] = (uint)x;
|
||||
// span0[1] = (uint)y;
|
||||
// span0[2] = (uint)z;
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("x")))));
|
||||
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("y")))));
|
||||
|
||||
if (isComputeShader)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void IShader.LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.VoidKeyword)),
|
||||
Identifier("LoadDispatchData"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddTypeParameterListParameters(TypeParameter(Identifier("TDataLoader")))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("loader"))
|
||||
.AddModifiers(Token(SyntaxKind.RefKeyword))
|
||||
.WithType(IdentifierName("TDataLoader")),
|
||||
Parameter(Identifier("device")).WithType(IdentifierName("GraphicsDevice")),
|
||||
Parameter(Identifier("x")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("y")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))),
|
||||
Parameter(Identifier("z")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))))
|
||||
.WithBody(Block(GetDispatchDataLoadingStatements(context, structDeclarationSymbol, out discoveredResources, out root32BitConstantsCount)));
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(2)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("z")))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of statements to load the dispatch data for a given shader.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="discoveredResources">The collection of discovered resources in the current shader type.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the current shader type.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
|
||||
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(GeneratorExecutionContext context, INamedTypeSymbol structDeclarationSymbol, out IReadOnlyCollection<string> discoveredResources, out int root32BitConstantsCount)
|
||||
// Append the statements to load all fields (both resources and other captured values)
|
||||
AppendFields(structDeclarationSymbol, Array.Empty<string>(), ref resourceOffset, ref rawDataOffset, resources, statements);
|
||||
|
||||
// After all the captured fields have been processed, ansure the reported byte size for
|
||||
// the local variables is padded to a multiple of a 32 bit value. This is necessary to
|
||||
// enable loading all the dispatch data after reinterpreting it to a sequence of values
|
||||
// of size 32 bits (via SetComputeRoot32BitConstants), without reading out of bounds.
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, sizeof(int));
|
||||
root32BitConstantsCount = rawDataOffset / sizeof(int);
|
||||
|
||||
// A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
|
||||
// Loaded values in the root signature have the following costs:
|
||||
// - Root constants cost 1 DWORD each, since they are 32-bit values.
|
||||
// - Descriptor tables cost 1 DWORD each.
|
||||
// - Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each.
|
||||
// So here we check whether the current signature respects that constraint,
|
||||
// and emit a build error otherwise. For more info on this, see the docs here:
|
||||
// https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
|
||||
int rootSignatureDwordSize = root32BitConstantsCount + resourceOffset;
|
||||
|
||||
if (rootSignatureDwordSize > 64)
|
||||
{
|
||||
List<StatementSyntax> statements = new();
|
||||
List<string> resources = new();
|
||||
context.ReportDiagnostic(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol);
|
||||
}
|
||||
|
||||
discoveredResources = resources;
|
||||
// Span<uint> span0 = stackalloc uint[<VARIABLES>];
|
||||
statements.Insert(0,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.UIntKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.UIntKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(root32BitConstantsCount)))))))))));
|
||||
|
||||
var pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) });
|
||||
var isComputeShader = pixelShaderSymbol is null;
|
||||
int
|
||||
resourceOffset = 0,
|
||||
rawDataOffset = sizeof(int) * (isComputeShader ? 3 : 2);
|
||||
// ref uint r0 = ref span0[0];
|
||||
statements.Insert(1,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.UIntKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))))))))));
|
||||
|
||||
// Append the statements for the dispatch ranges:
|
||||
//
|
||||
// span0[0] = (uint)x;
|
||||
// span0[1] = (uint)y;
|
||||
// span0[2] = (uint)z;
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("x")))));
|
||||
// loader.LoadCapturedValues(span0);
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("loader"),
|
||||
IdentifierName("LoadCapturedValues")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName("span0")))));
|
||||
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("y")))));
|
||||
|
||||
if (isComputeShader)
|
||||
{
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(2)))),
|
||||
CastExpression(PredefinedType(Token(SyntaxKind.UIntKeyword)), IdentifierName("z")))));
|
||||
}
|
||||
|
||||
// Append the statements to load all fields (both resources and other captured values)
|
||||
AppendFields(structDeclarationSymbol, Array.Empty<string>(), ref resourceOffset, ref rawDataOffset, resources, statements);
|
||||
|
||||
// After all the captured fields have been processed, ansure the reported byte size for
|
||||
// the local variables is padded to a multiple of a 32 bit value. This is necessary to
|
||||
// enable loading all the dispatch data after reinterpreting it to a sequence of values
|
||||
// of size 32 bits (via SetComputeRoot32BitConstants), without reading out of bounds.
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, sizeof(int));
|
||||
root32BitConstantsCount = rawDataOffset / sizeof(int);
|
||||
|
||||
// A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
|
||||
// Loaded values in the root signature have the following costs:
|
||||
// - Root constants cost 1 DWORD each, since they are 32-bit values.
|
||||
// - Descriptor tables cost 1 DWORD each.
|
||||
// - Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each.
|
||||
// So here we check whether the current signature respects that constraint,
|
||||
// and emit a build error otherwise. For more info on this, see the docs here:
|
||||
// https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
|
||||
int rootSignatureDwordSize = root32BitConstantsCount + resourceOffset;
|
||||
|
||||
if (rootSignatureDwordSize > 64)
|
||||
{
|
||||
context.ReportDiagnostic(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol);
|
||||
}
|
||||
|
||||
// Span<uint> span0 = stackalloc uint[<VARIABLES>];
|
||||
statements.Insert(0,
|
||||
if (resourceOffset > 0)
|
||||
{
|
||||
// Span<ulong> span1 = stackalloc ulong[<RESOURCES>];
|
||||
statements.Insert(1,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.UIntKeyword))))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ULongKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span0"))
|
||||
VariableDeclarator(Identifier("span1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.UIntKeyword)))
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ULongKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(root32BitConstantsCount)))))))))));
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(resourceOffset)))))))))));
|
||||
|
||||
// ref uint r0 = ref span0[0];
|
||||
statements.Insert(1,
|
||||
// ref ulong r1 = ref span1[0];
|
||||
statements.Insert(3,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.UIntKeyword))))
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.ULongKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r0"))
|
||||
VariableDeclarator(Identifier("r1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
ElementAccessExpression(IdentifierName("span1"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))))))))));
|
||||
|
||||
// loader.LoadCapturedValues(span0);
|
||||
// loader.LoadCapturedResources(span1);
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("loader"),
|
||||
IdentifierName("LoadCapturedValues")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName("span0")))));
|
||||
|
||||
if (resourceOffset > 0)
|
||||
{
|
||||
// Span<ulong> span1 = stackalloc ulong[<RESOURCES>];
|
||||
statements.Insert(1,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ULongKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ULongKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(resourceOffset)))))))))));
|
||||
|
||||
// ref ulong r1 = ref span1[0];
|
||||
statements.Insert(3,
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.ULongKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span1"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))))))))));
|
||||
|
||||
// loader.LoadCapturedResources(span1);
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("loader"),
|
||||
IdentifierName("LoadCapturedResources")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName("span1")))));
|
||||
}
|
||||
|
||||
return statements;
|
||||
IdentifierName("LoadCapturedResources")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName("span1")))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explores a given type hierarchy and generates statements to load fields.
|
||||
/// </summary>
|
||||
/// <param name="currentTypeSymbol">The current type being explored.</param>
|
||||
/// <param name="fieldPath">The current path of the field with respect to the shader instance.</param>
|
||||
/// <param name="resourceOffset">The current offset in the root table of loaded resources.</param>
|
||||
/// <param name="rawDataOffset">The current offset within the loaded data buffer.</param>
|
||||
/// <param name="resources">The target list of resources in the current shader type.</param>
|
||||
/// <param name="statements">The target list of statements being generated.</param>
|
||||
private static void AppendFields(ITypeSymbol currentTypeSymbol, IReadOnlyCollection<string> fieldPath, ref int resourceOffset, ref int rawDataOffset, ICollection<string> resources, ICollection<StatementSyntax> statements)
|
||||
return statements;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explores a given type hierarchy and generates statements to load fields.
|
||||
/// </summary>
|
||||
/// <param name="currentTypeSymbol">The current type being explored.</param>
|
||||
/// <param name="fieldPath">The current path of the field with respect to the shader instance.</param>
|
||||
/// <param name="resourceOffset">The current offset in the root table of loaded resources.</param>
|
||||
/// <param name="rawDataOffset">The current offset within the loaded data buffer.</param>
|
||||
/// <param name="resources">The target list of resources in the current shader type.</param>
|
||||
/// <param name="statements">The target list of statements being generated.</param>
|
||||
private static void AppendFields(ITypeSymbol currentTypeSymbol, IReadOnlyCollection<string> fieldPath, ref int resourceOffset, ref int rawDataOffset, ICollection<string> resources, ICollection<StatementSyntax> statements)
|
||||
{
|
||||
bool isFirstField = true;
|
||||
|
||||
foreach (
|
||||
IFieldSymbol fieldSymbol in
|
||||
from fieldSymbol in currentTypeSymbol.GetMembers().OfType<IFieldSymbol>()
|
||||
where fieldSymbol.Type is INamedTypeSymbol { IsStatic: false } &&
|
||||
!fieldSymbol.IsConst && !fieldSymbol.IsStatic && !fieldSymbol.IsFixedSizeBuffer
|
||||
select fieldSymbol)
|
||||
{
|
||||
bool isFirstField = true;
|
||||
string
|
||||
fieldName = fieldSymbol.Name,
|
||||
typeName = fieldSymbol.Type.GetFullMetadataName();
|
||||
|
||||
foreach (
|
||||
IFieldSymbol fieldSymbol in
|
||||
from fieldSymbol in currentTypeSymbol.GetMembers().OfType<IFieldSymbol>()
|
||||
where fieldSymbol.Type is INamedTypeSymbol { IsStatic: false } &&
|
||||
!fieldSymbol.IsConst && !fieldSymbol.IsStatic && !fieldSymbol.IsFixedSizeBuffer
|
||||
select fieldSymbol)
|
||||
// Disambiguates the name of target fields against the current input parameters
|
||||
if (fieldName is "loader" or "device" or "x" or "y" or "z")
|
||||
{
|
||||
string
|
||||
fieldName = fieldSymbol.Name,
|
||||
typeName = fieldSymbol.Type.GetFullMetadataName();
|
||||
|
||||
// Disambiguates the name of target fields against the current input parameters
|
||||
if (fieldName is "loader" or "device" or "x" or "y" or "z")
|
||||
{
|
||||
fieldName = $"this.{fieldName}";
|
||||
}
|
||||
|
||||
// The first item in each nested struct needs to be aligned to 16 bytes
|
||||
if (isFirstField && fieldPath.Count > 0)
|
||||
{
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16);
|
||||
|
||||
isFirstField = false;
|
||||
}
|
||||
|
||||
if (HlslKnownTypes.IsTypedResourceType(typeName))
|
||||
{
|
||||
resources.Add(typeName);
|
||||
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.Add(ref r1, {resourceOffset++})"),
|
||||
ParseExpression($"GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle({fieldName}, device)"))));
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownHlslType(typeName))
|
||||
{
|
||||
AppendHlslKnownTypeField(fieldPath.Concat(new[] { fieldName }), typeName, ref rawDataOffset, statements);
|
||||
}
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
// Custom struct type defined by the user
|
||||
AppendFields(fieldSymbol.Type, fieldPath.Concat(new[] { fieldName }).ToArray(), ref resourceOffset, ref rawDataOffset, resources, statements);
|
||||
}
|
||||
fieldName = $"this.{fieldName}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a loading statement for a known HLSL primitive type field (scalar, vector or matrix).
|
||||
/// </summary>
|
||||
/// <param name="fieldPath">The current path of the field with respect to the shader instance.</param>
|
||||
/// <param name="typeName">The type name currently being read.</param>
|
||||
/// <param name="rawDataOffset">The current offset within the loaded data buffer.</param>
|
||||
/// <param name="statements">The target list of statements being generated.</param>
|
||||
private static void AppendHlslKnownTypeField(IEnumerable<string> fieldPath, string typeName, ref int rawDataOffset, ICollection<StatementSyntax> statements)
|
||||
{
|
||||
// For scalar, vector and linear matrix types, serialize the value normally.
|
||||
// Only the initial alignment needs to be considered, while data is packed.
|
||||
var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName);
|
||||
|
||||
// Check if the current type is a matrix type with more than one row. In this
|
||||
// case, each row is aligned as if it was a separate array, so the start of
|
||||
// each row needs to be at a multiple of 16 bytes (a float4 register).
|
||||
if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns))
|
||||
// The first item in each nested struct needs to be aligned to 16 bytes
|
||||
if (isFirstField && fieldPath.Count > 0)
|
||||
{
|
||||
string
|
||||
rowTypeName = $"ComputeSharp.{elementName}{columns}",
|
||||
rowLocalName = $"__{string.Join("_", fieldPath)}__row0";
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16);
|
||||
|
||||
statements.Add(ParseStatement($"ref {rowTypeName} {rowLocalName} = ref Unsafe.As<{typeName}, {rowTypeName}>(ref Unsafe.AsRef(in {string.Join(".", fieldPath)}));"));
|
||||
|
||||
// Generate the loading code for each individual row, with proper alignment.
|
||||
// This will result in the following (assuming Float2x3 m):
|
||||
//
|
||||
// ref Float3 __m__row0 = ref Unsafe.As<Float2x3, Float3>(ref Unsafe.AsRef(in m));
|
||||
// Unsafe.As<uint, Float3>(ref Unsafe.AddByteOffset(ref r0, (nint)rawDataOffset)) =, Unsafe.Add(ref __m__row0, 0);
|
||||
// Unsafe.As<uint, Float3>(ref Unsafe.AddByteOffset(ref r0, (nint)(rawDataOffset + 16))) = Unsafe.Add(ref __m__row0, 1);
|
||||
for (int j = 0; j < rows; j++)
|
||||
{
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16);
|
||||
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.As<uint, {rowTypeName}>(ref Unsafe.AddByteOffset(ref r0, (nint){rawDataOffset}))"),
|
||||
ParseExpression($"Unsafe.Add(ref {rowLocalName}, {j})"))));
|
||||
|
||||
rawDataOffset += fieldPack * columns;
|
||||
}
|
||||
isFirstField = false;
|
||||
}
|
||||
else
|
||||
|
||||
if (HlslKnownTypes.IsTypedResourceType(typeName))
|
||||
{
|
||||
// Calculate the right offset with 16-bytes padding (HLSL constant buffer).
|
||||
// Since we're in a constant buffer, we need to both pad the starting offset
|
||||
// to be aligned to the packing size of the type, and also to align the initial
|
||||
// offset to ensure that values do not cross 16 bytes boundaries either.
|
||||
rawDataOffset = AlignmentHelper.AlignToBoundary(
|
||||
AlignmentHelper.Pad(rawDataOffset, fieldPack),
|
||||
fieldSize,
|
||||
16);
|
||||
resources.Add(typeName);
|
||||
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.As<uint, {typeName}>(ref Unsafe.AddByteOffset(ref r0, (nint){rawDataOffset}))"),
|
||||
ParseExpression($"{string.Join(".", fieldPath)}"))));
|
||||
|
||||
rawDataOffset += fieldSize;
|
||||
ParseExpression($"Unsafe.Add(ref r1, {resourceOffset++})"),
|
||||
ParseExpression($"GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle({fieldName}, device)"))));
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownHlslType(typeName))
|
||||
{
|
||||
AppendHlslKnownTypeField(fieldPath.Concat(new[] { fieldName }), typeName, ref rawDataOffset, statements);
|
||||
}
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
// Custom struct type defined by the user
|
||||
AppendFields(fieldSymbol.Type, fieldPath.Concat(new[] { fieldName }).ToArray(), ref resourceOffset, ref rawDataOffset, resources, statements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a loading statement for a known HLSL primitive type field (scalar, vector or matrix).
|
||||
/// </summary>
|
||||
/// <param name="fieldPath">The current path of the field with respect to the shader instance.</param>
|
||||
/// <param name="typeName">The type name currently being read.</param>
|
||||
/// <param name="rawDataOffset">The current offset within the loaded data buffer.</param>
|
||||
/// <param name="statements">The target list of statements being generated.</param>
|
||||
private static void AppendHlslKnownTypeField(IEnumerable<string> fieldPath, string typeName, ref int rawDataOffset, ICollection<StatementSyntax> statements)
|
||||
{
|
||||
// For scalar, vector and linear matrix types, serialize the value normally.
|
||||
// Only the initial alignment needs to be considered, while data is packed.
|
||||
var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName);
|
||||
|
||||
// Check if the current type is a matrix type with more than one row. In this
|
||||
// case, each row is aligned as if it was a separate array, so the start of
|
||||
// each row needs to be at a multiple of 16 bytes (a float4 register).
|
||||
if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns))
|
||||
{
|
||||
string
|
||||
rowTypeName = $"ComputeSharp.{elementName}{columns}",
|
||||
rowLocalName = $"__{string.Join("_", fieldPath)}__row0";
|
||||
|
||||
statements.Add(ParseStatement($"ref {rowTypeName} {rowLocalName} = ref Unsafe.As<{typeName}, {rowTypeName}>(ref Unsafe.AsRef(in {string.Join(".", fieldPath)}));"));
|
||||
|
||||
// Generate the loading code for each individual row, with proper alignment.
|
||||
// This will result in the following (assuming Float2x3 m):
|
||||
//
|
||||
// ref Float3 __m__row0 = ref Unsafe.As<Float2x3, Float3>(ref Unsafe.AsRef(in m));
|
||||
// Unsafe.As<uint, Float3>(ref Unsafe.AddByteOffset(ref r0, (nint)rawDataOffset)) =, Unsafe.Add(ref __m__row0, 0);
|
||||
// Unsafe.As<uint, Float3>(ref Unsafe.AddByteOffset(ref r0, (nint)(rawDataOffset + 16))) = Unsafe.Add(ref __m__row0, 1);
|
||||
for (int j = 0; j < rows; j++)
|
||||
{
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16);
|
||||
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.As<uint, {rowTypeName}>(ref Unsafe.AddByteOffset(ref r0, (nint){rawDataOffset}))"),
|
||||
ParseExpression($"Unsafe.Add(ref {rowLocalName}, {j})"))));
|
||||
|
||||
rawDataOffset += fieldPack * columns;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Calculate the right offset with 16-bytes padding (HLSL constant buffer).
|
||||
// Since we're in a constant buffer, we need to both pad the starting offset
|
||||
// to be aligned to the packing size of the type, and also to align the initial
|
||||
// offset to ensure that values do not cross 16 bytes boundaries either.
|
||||
rawDataOffset = AlignmentHelper.AlignToBoundary(
|
||||
AlignmentHelper.Pad(rawDataOffset, fieldPack),
|
||||
fieldSize,
|
||||
16);
|
||||
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.As<uint, {typeName}>(ref Unsafe.AddByteOffset(ref r0, (nint){rawDataOffset}))"),
|
||||
ParseExpression($"{string.Join(".", fieldPath)}"))));
|
||||
|
||||
rawDataOffset += fieldSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
+134
-136
@@ -8,152 +8,150 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchMetadataMethod(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchMetadataMethod(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed)
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void IShader.LoadDispatchMetadata<TMetadataLoader>(ref TMetadataLoader loader, out IntPtr result)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.VoidKeyword)),
|
||||
Identifier("LoadDispatchMetadata"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddTypeParameterListParameters(TypeParameter(Identifier("TMetadataLoader")))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("loader"))
|
||||
.AddModifiers(Token(SyntaxKind.RefKeyword))
|
||||
.WithType(IdentifierName("TMetadataLoader")),
|
||||
Parameter(Identifier("result"))
|
||||
.AddModifiers(Token(SyntaxKind.OutKeyword))
|
||||
.WithType(IdentifierName(typeof(IntPtr).Name)))
|
||||
.WithBody(Block(GetDispatchMetadataLoadingStatements(implicitTextureType, discoveredResources, root32BitConstantsCount, isSamplerUsed)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of statements to load the dispatch metadata for a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="discoveredResources">The collection of resources used by the shader.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the shader.</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the shader requires a static sampler to be available.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
|
||||
private static IEnumerable<StatementSyntax> GetDispatchMetadataLoadingStatements(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed)
|
||||
{
|
||||
// Span<byte> span0 = stackalloc byte[5];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(5))))))))));
|
||||
|
||||
// Compute the total number of resources (discovered ones and the implicit target texture, if present)
|
||||
int totalResourcesCount = discoveredResources.Count + (implicitTextureType is not null ? 1 : 0);
|
||||
|
||||
// Span<ResourceDescriptor> span1 = stackalloc ResourceDescriptor[<ADJUSTED_COUNT>];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(IdentifierName("ResourceDescriptor")))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(IdentifierName("ResourceDescriptor"))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(totalResourcesCount))))))))));
|
||||
|
||||
// ref byte r0 = ref span0[0];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))))));
|
||||
|
||||
// ref ResourceDescriptor r1 = ref span1[0];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(IdentifierName("ResourceDescriptor")))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span1"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))))));
|
||||
|
||||
// Serialized shader metadata
|
||||
yield return ParseStatement($"Unsafe.WriteUnaligned<int>(ref Unsafe.Add(ref r0, 0), {root32BitConstantsCount});");
|
||||
yield return ParseStatement($"Unsafe.WriteUnaligned<bool>(ref Unsafe.Add(ref r0, 4), {isSamplerUsed.ToString().ToLowerInvariant()});");
|
||||
|
||||
int
|
||||
constantBufferOffset = 1,
|
||||
readOnlyResourceOffset = 0,
|
||||
readWriteResourceOffset = 0,
|
||||
resourceOffset = 0;
|
||||
|
||||
// Add the implicit texture descriptor, if needed
|
||||
if (implicitTextureType is not null)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void IShader.LoadDispatchMetadata<TMetadataLoader>(ref TMetadataLoader loader, out IntPtr result)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(
|
||||
PredefinedType(Token(SyntaxKind.VoidKeyword)),
|
||||
Identifier("LoadDispatchMetadata"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName(nameof(IShader))))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddTypeParameterListParameters(TypeParameter(Identifier("TMetadataLoader")))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("loader"))
|
||||
.AddModifiers(Token(SyntaxKind.RefKeyword))
|
||||
.WithType(IdentifierName("TMetadataLoader")),
|
||||
Parameter(Identifier("result"))
|
||||
.AddModifiers(Token(SyntaxKind.OutKeyword))
|
||||
.WithType(IdentifierName(typeof(IntPtr).Name)))
|
||||
.WithBody(Block(GetDispatchMetadataLoadingStatements(implicitTextureType, discoveredResources, root32BitConstantsCount, isSamplerUsed)));
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(1, {readWriteResourceOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of statements to load the dispatch metadata for a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="discoveredResources">The collection of resources used by the shader.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the shader.</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the shader requires a static sampler to be available.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
|
||||
private static IEnumerable<StatementSyntax> GetDispatchMetadataLoadingStatements(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed)
|
||||
// Populate the sequence of resource descriptors
|
||||
foreach (var resource in discoveredResources)
|
||||
{
|
||||
// Span<byte> span0 = stackalloc byte[5];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(5))))))))));
|
||||
|
||||
// Compute the total number of resources (discovered ones and the implicit target texture, if present)
|
||||
int totalResourcesCount = discoveredResources.Count + (implicitTextureType is not null ? 1 : 0);
|
||||
|
||||
// Span<ResourceDescriptor> span1 = stackalloc ResourceDescriptor[<ADJUSTED_COUNT>];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("Span"))
|
||||
.AddTypeArgumentListArguments(IdentifierName("ResourceDescriptor")))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("span1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(IdentifierName("ResourceDescriptor"))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(totalResourcesCount))))))))));
|
||||
|
||||
// ref byte r0 = ref span0[0];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span0"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))))));
|
||||
|
||||
// ref ResourceDescriptor r1 = ref span1[0];
|
||||
yield return
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(IdentifierName("ResourceDescriptor")))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r1"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("span1"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))))));
|
||||
|
||||
// Serialized shader metadata
|
||||
yield return ParseStatement($"Unsafe.WriteUnaligned<int>(ref Unsafe.Add(ref r0, 0), {root32BitConstantsCount});");
|
||||
yield return ParseStatement($"Unsafe.WriteUnaligned<bool>(ref Unsafe.Add(ref r0, 4), {isSamplerUsed.ToString().ToLowerInvariant()});");
|
||||
|
||||
int
|
||||
constantBufferOffset = 1,
|
||||
readOnlyResourceOffset = 0,
|
||||
readWriteResourceOffset = 0,
|
||||
resourceOffset = 0;
|
||||
|
||||
// Add the implicit texture descriptor, if needed
|
||||
if (implicitTextureType is not null)
|
||||
if (HlslKnownTypes.IsConstantBufferType(resource))
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(2, {constantBufferOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(resource))
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(0, {readOnlyResourceOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(1, {readWriteResourceOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
|
||||
// Populate the sequence of resource descriptors
|
||||
foreach (var resource in discoveredResources)
|
||||
{
|
||||
if (HlslKnownTypes.IsConstantBufferType(resource))
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(2, {constantBufferOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyTypedResourceType(resource))
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(0, {readOnlyResourceOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return ParseStatement($"ResourceDescriptor.Create(1, {readWriteResourceOffset++}, out Unsafe.Add(ref r1, {resourceOffset++}));");
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke the value delegate to create the opaque root signature handle
|
||||
yield return ParseStatement("loader.LoadMetadataHandle(span0, span1, out result);");
|
||||
}
|
||||
|
||||
// Invoke the value delegate to create the opaque root signature handle
|
||||
yield return ParseStatement("loader.LoadMetadataHandle(span0, span1, out result);");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,46 +4,44 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class IShaderGenerator
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
if (context.Node is StructDeclarationSyntax structDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(structDeclaration) is INamedTypeSymbol structSymbol &&
|
||||
structSymbol.Interfaces.Any(static interfaceSymbol =>
|
||||
interfaceSymbol.Name == nameof(IComputeShader) ||
|
||||
interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) }))
|
||||
{
|
||||
if (context.Node is StructDeclarationSyntax structDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(structDeclaration) is INamedTypeSymbol structSymbol &&
|
||||
structSymbol.Interfaces.Any(static interfaceSymbol =>
|
||||
interfaceSymbol.Name == nameof(IComputeShader) ||
|
||||
interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) }))
|
||||
{
|
||||
this.gatheredInfo.Add(new Item(structDeclaration, structSymbol));
|
||||
}
|
||||
this.gatheredInfo.Add(new Item(structDeclaration, structSymbol));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered type to process.
|
||||
/// </summary>
|
||||
/// <param name="StructDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the target struct declaration.</param>
|
||||
/// <param name="StructSymbol">The <see cref="INamedTypeSymbol"/> instance for <paramref name="StructDeclaration"/>.</param>
|
||||
public sealed record Item(StructDeclarationSyntax StructDeclaration, INamedTypeSymbol StructSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered type to process.
|
||||
/// </summary>
|
||||
/// <param name="StructDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the target struct declaration.</param>
|
||||
/// <param name="StructSymbol">The <see cref="INamedTypeSymbol"/> instance for <paramref name="StructDeclaration"/>.</param>
|
||||
public sealed record Item(StructDeclarationSyntax StructDeclaration, INamedTypeSymbol StructSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,218 +11,216 @@ using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
using static Microsoft.CodeAnalysis.SymbolDisplayTypeQualificationStyle;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A source generator creating data loaders for <see cref="IComputeShader"/> and <see cref="IPixelShader{TPixel}"/> types.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A source generator creating data loaders for <see cref="IComputeShader"/> and <see cref="IPixelShader{TPixel}"/> types.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class IShaderGenerator : ISourceGenerator
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnExecute(context, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.ReportDiagnostic(IShaderGeneratorError, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target type.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
// Create the required interface methods for the current shader type
|
||||
MethodDeclarationSyntax
|
||||
getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol),
|
||||
loadDispatchDataMethod = CreateLoadDispatchDataMethod(context, structDeclarationSymbol, out var discoveredResources, out int root32BitConstants),
|
||||
buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed, out bool isHashSetDirectiveNeeded),
|
||||
loadDispatchMetadataMethod = CreateLoadDispatchMetadataMethod(implicitTextureType, discoveredResources, root32BitConstants, isSamplerUsed);
|
||||
|
||||
// Reorder the method declarations to respect the order in the interface definition
|
||||
MethodDeclarationSyntax[] methods =
|
||||
{
|
||||
getDispatchIdMethod,
|
||||
loadDispatchDataMethod,
|
||||
loadDispatchMetadataMethod,
|
||||
buildHlslStringMethod
|
||||
};
|
||||
|
||||
// Method attributes
|
||||
List<AttributeListSyntax> attributes = new()
|
||||
{
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("GeneratedCode")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).FullName))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).Assembly.GetName().Version.ToString())))))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
|
||||
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This method is not intended to be used directly by user code"))))))
|
||||
};
|
||||
|
||||
// Add [SkipLocalsInit] if the target project allows it
|
||||
if (context.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true })
|
||||
{
|
||||
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("SkipLocalsInit")))));
|
||||
}
|
||||
|
||||
string namespaceName = structDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
|
||||
string structName = structDeclaration.Identifier.Text;
|
||||
SyntaxTokenList structModifiers = structDeclaration.Modifiers;
|
||||
|
||||
// Create the partial shader type declaration with the hashcode interface method implementation.
|
||||
// This code produces a struct declaration as follows:
|
||||
//
|
||||
// public <MODIFIERS> struct ShaderType
|
||||
// {
|
||||
// <METHODS_LIST>
|
||||
// }
|
||||
var structDeclarationSyntax =
|
||||
StructDeclaration(structName)
|
||||
.WithModifiers(structModifiers)
|
||||
.AddMembers(methods.Select(m => m.AddAttributeLists(attributes.ToArray())).ToArray());
|
||||
|
||||
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
|
||||
|
||||
// Add all parent types in ascending order, if any
|
||||
foreach (var parentType in structDeclaration.Ancestors().OfType<TypeDeclarationSyntax>())
|
||||
{
|
||||
typeDeclarationSyntax = parentType
|
||||
.WithMembers(SingletonList<MemberDeclarationSyntax>(typeDeclarationSyntax))
|
||||
.WithConstraintClauses(List<TypeParameterConstraintClauseSyntax>())
|
||||
.WithBaseList(null)
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithoutTrivia();
|
||||
}
|
||||
|
||||
// Prepare the necessary using directives
|
||||
List<UsingDirectiveSyntax> usingDirectives = new()
|
||||
{
|
||||
UsingDirective(IdentifierName("System")),
|
||||
UsingDirective(IdentifierName("System.CodeDom.Compiler")),
|
||||
UsingDirective(IdentifierName("System.ComponentModel")),
|
||||
UsingDirective(IdentifierName("System.Diagnostics")),
|
||||
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis")),
|
||||
UsingDirective(IdentifierName("System.Runtime.CompilerServices")),
|
||||
UsingDirective(IdentifierName("ComputeSharp")),
|
||||
UsingDirective(IdentifierName("ComputeSharp.__Internals"))
|
||||
};
|
||||
|
||||
if (isHashSetDirectiveNeeded)
|
||||
{
|
||||
usingDirectives.Insert(2, UsingDirective(IdentifierName("System.Collections.Generic")));
|
||||
}
|
||||
|
||||
// Create a static method to create the combined hashcode for a given shader type.
|
||||
// This code takes a block syntax and produces a compilation unit as follows:
|
||||
//
|
||||
// using System;
|
||||
// using System.CodeDom.Compiler;
|
||||
// using System.ComponentModel;
|
||||
// using System.Diagnostics;
|
||||
// using System.Diagnostics.CodeAnalysis;
|
||||
// using System.Runtime.CompilerServices;
|
||||
// using ComputeSharp.__Internals;
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// namespace <SHADER_NAMESPACE>
|
||||
// {
|
||||
// <SHADER_DECLARATION>
|
||||
// }
|
||||
var source =
|
||||
CompilationUnit().AddUsings(usingDirectives.ToArray()).AddMembers(
|
||||
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax)
|
||||
.WithNamespaceKeyword(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.NamespaceKeyword, TriviaList())))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchDataMethod</c> method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <param name="discoveredResources">The collection of discovered resources in the current shader type.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the current shader type.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchDataMethod</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchDataMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out IReadOnlyCollection<string> discoveredResources,
|
||||
out int root32BitConstantsCount);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the current shader type requires a static sampler to be available.</param>
|
||||
/// <param name="isHashSetDirectiveNeeded">Indicates whether or not the <see langword="using"/> directive for <see cref="HashSet{T}"/> is needed.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateBuildHlslStringMethod(
|
||||
GeneratorExecutionContext context,
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out string? implicitTextureType,
|
||||
out bool isSamplerUsed,
|
||||
out bool isHashSetDirectiveNeeded);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchMetadata</c> method.
|
||||
/// </summary>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="discoveredResources">The collection of resources used by the shader.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the shader.</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the shader requires a static sampler to be available.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchMetadata</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchMetadataMethod(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed);
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnExecute(context, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.ReportDiagnostic(IShaderGeneratorError, item.StructDeclaration, item.StructSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target type.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, StructDeclarationSyntax structDeclaration, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
// Create the required interface methods for the current shader type
|
||||
MethodDeclarationSyntax
|
||||
getDispatchIdMethod = CreateGetDispatchIdMethod(structDeclarationSymbol),
|
||||
loadDispatchDataMethod = CreateLoadDispatchDataMethod(context, structDeclarationSymbol, out var discoveredResources, out int root32BitConstants),
|
||||
buildHlslStringMethod = CreateBuildHlslStringMethod(context, structDeclaration, structDeclarationSymbol, out string? implicitTextureType, out bool isSamplerUsed, out bool isHashSetDirectiveNeeded),
|
||||
loadDispatchMetadataMethod = CreateLoadDispatchMetadataMethod(implicitTextureType, discoveredResources, root32BitConstants, isSamplerUsed);
|
||||
|
||||
// Reorder the method declarations to respect the order in the interface definition
|
||||
MethodDeclarationSyntax[] methods =
|
||||
{
|
||||
getDispatchIdMethod,
|
||||
loadDispatchDataMethod,
|
||||
loadDispatchMetadataMethod,
|
||||
buildHlslStringMethod
|
||||
};
|
||||
|
||||
// Method attributes
|
||||
List<AttributeListSyntax> attributes = new()
|
||||
{
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("GeneratedCode")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).FullName))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(IShaderGenerator).Assembly.GetName().Version.ToString())))))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
|
||||
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
|
||||
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This method is not intended to be used directly by user code"))))))
|
||||
};
|
||||
|
||||
// Add [SkipLocalsInit] if the target project allows it
|
||||
if (context.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true })
|
||||
{
|
||||
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("SkipLocalsInit")))));
|
||||
}
|
||||
|
||||
string namespaceName = structDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
|
||||
string structName = structDeclaration.Identifier.Text;
|
||||
SyntaxTokenList structModifiers = structDeclaration.Modifiers;
|
||||
|
||||
// Create the partial shader type declaration with the hashcode interface method implementation.
|
||||
// This code produces a struct declaration as follows:
|
||||
//
|
||||
// public <MODIFIERS> struct ShaderType
|
||||
// {
|
||||
// <METHODS_LIST>
|
||||
// }
|
||||
var structDeclarationSyntax =
|
||||
StructDeclaration(structName)
|
||||
.WithModifiers(structModifiers)
|
||||
.AddMembers(methods.Select(m => m.AddAttributeLists(attributes.ToArray())).ToArray());
|
||||
|
||||
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
|
||||
|
||||
// Add all parent types in ascending order, if any
|
||||
foreach (var parentType in structDeclaration.Ancestors().OfType<TypeDeclarationSyntax>())
|
||||
{
|
||||
typeDeclarationSyntax = parentType
|
||||
.WithMembers(SingletonList<MemberDeclarationSyntax>(typeDeclarationSyntax))
|
||||
.WithConstraintClauses(List<TypeParameterConstraintClauseSyntax>())
|
||||
.WithBaseList(null)
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithoutTrivia();
|
||||
}
|
||||
|
||||
// Prepare the necessary using directives
|
||||
List<UsingDirectiveSyntax> usingDirectives = new()
|
||||
{
|
||||
UsingDirective(IdentifierName("System")),
|
||||
UsingDirective(IdentifierName("System.CodeDom.Compiler")),
|
||||
UsingDirective(IdentifierName("System.ComponentModel")),
|
||||
UsingDirective(IdentifierName("System.Diagnostics")),
|
||||
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis")),
|
||||
UsingDirective(IdentifierName("System.Runtime.CompilerServices")),
|
||||
UsingDirective(IdentifierName("ComputeSharp")),
|
||||
UsingDirective(IdentifierName("ComputeSharp.__Internals"))
|
||||
};
|
||||
|
||||
if (isHashSetDirectiveNeeded)
|
||||
{
|
||||
usingDirectives.Insert(2, UsingDirective(IdentifierName("System.Collections.Generic")));
|
||||
}
|
||||
|
||||
// Create a static method to create the combined hashcode for a given shader type.
|
||||
// This code takes a block syntax and produces a compilation unit as follows:
|
||||
//
|
||||
// using System;
|
||||
// using System.CodeDom.Compiler;
|
||||
// using System.ComponentModel;
|
||||
// using System.Diagnostics;
|
||||
// using System.Diagnostics.CodeAnalysis;
|
||||
// using System.Runtime.CompilerServices;
|
||||
// using ComputeSharp.__Internals;
|
||||
//
|
||||
// #pragma warning disable
|
||||
//
|
||||
// namespace <SHADER_NAMESPACE>
|
||||
// {
|
||||
// <SHADER_DECLARATION>
|
||||
// }
|
||||
var source =
|
||||
CompilationUnit().AddUsings(usingDirectives.ToArray()).AddMembers(
|
||||
NamespaceDeclaration(IdentifierName(namespaceName)).AddMembers(typeDeclarationSyntax)
|
||||
.WithNamespaceKeyword(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.NamespaceKeyword, TriviaList())))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(structDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>GetDispatchId</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateGetDispatchIdMethod(INamedTypeSymbol structDeclarationSymbol);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchDataMethod</c> method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <param name="discoveredResources">The collection of discovered resources in the current shader type.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the current shader type.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchDataMethod</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchDataMethod(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out IReadOnlyCollection<string> discoveredResources,
|
||||
out int root32BitConstantsCount);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="structDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="structDeclaration"/>.</param>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the current shader type requires a static sampler to be available.</param>
|
||||
/// <param name="isHashSetDirectiveNeeded">Indicates whether or not the <see langword="using"/> directive for <see cref="HashSet{T}"/> is needed.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateBuildHlslStringMethod(
|
||||
GeneratorExecutionContext context,
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
out string? implicitTextureType,
|
||||
out bool isSamplerUsed,
|
||||
out bool isHashSetDirectiveNeeded);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchMetadata</c> method.
|
||||
/// </summary>
|
||||
/// <param name="implicitTextureType">The implicit texture type, if available (if the shader is a pixel shader).</param>
|
||||
/// <param name="discoveredResources">The collection of resources used by the shader.</param>
|
||||
/// <param name="root32BitConstantsCount">The total number of 32 bit root constants being loaded for the shader.</param>
|
||||
/// <param name="isSamplerUsed">Whether or not the shader requires a static sampler to be available.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadDispatchMetadata</c> method.</returns>
|
||||
private static partial MethodDeclarationSyntax CreateLoadDispatchMetadataMethod(
|
||||
string? implicitTextureType,
|
||||
IReadOnlyCollection<string> discoveredResources,
|
||||
int root32BitConstantsCount,
|
||||
bool isSamplerUsed);
|
||||
}
|
||||
@@ -4,70 +4,69 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL identifier names valid HLSL names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownKeywords
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL identifier names valid HLSL names.
|
||||
/// The mapping of known HLSL keywords.
|
||||
/// </summary>
|
||||
internal static class HlslKnownKeywords
|
||||
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of all known HLSL keywords.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of known HLSL keywords.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownKeywords = BuildKnownKeywordsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of all known HLSL keywords.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownKeywordsMap()
|
||||
// HLSL keywords
|
||||
HashSet<string> knownKeywords = new(new[]
|
||||
{
|
||||
// HLSL keywords
|
||||
HashSet<string> knownKeywords = new(new[]
|
||||
{
|
||||
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
|
||||
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
|
||||
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
|
||||
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
});
|
||||
"asm", "asm_fragment", "cbuffer", "centroid", "column_major",
|
||||
"compile", "discard", "dword", "export", "fxgroup", "groupshared",
|
||||
"half", "inline", "inout", "line", "lineadj", "linear", "matrix",
|
||||
"nointerpolation", "noperspective", "NULL", "packoffset", "pass",
|
||||
"pixelfragment", "point", "precise", "register", "row_major", "sample",
|
||||
"sampler", "shared", "snorm", "stateblock", "stateblock_state", "tbuffer",
|
||||
"technique", "typedef", "triangle", "triangleadj", "uniform", "unorm",
|
||||
"unsigned", "vector", "vertexfragment", "zero"
|
||||
});
|
||||
|
||||
// Dispatch type names
|
||||
knownKeywords.Add(nameof(ThreadIds));
|
||||
knownKeywords.Add(nameof(GroupIds));
|
||||
knownKeywords.Add(nameof(GroupSize));
|
||||
knownKeywords.Add(nameof(GridIds));
|
||||
// Dispatch type names
|
||||
knownKeywords.Add(nameof(ThreadIds));
|
||||
knownKeywords.Add(nameof(GroupIds));
|
||||
knownKeywords.Add(nameof(GroupSize));
|
||||
knownKeywords.Add(nameof(GridIds));
|
||||
|
||||
// HLSL intrinsics method names
|
||||
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
// HLSL intrinsics method names
|
||||
foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
string name = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
return knownKeywords;
|
||||
knownKeywords.Add(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input identifier name.</param>
|
||||
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
|
||||
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
mapped = KnownKeywords.Contains(name) switch
|
||||
{
|
||||
true => $"__reserved__{name}",
|
||||
false => null
|
||||
};
|
||||
return knownKeywords;
|
||||
}
|
||||
|
||||
return mapped is not null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible identifier name for the input identifier name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input identifier name.</param>
|
||||
/// <param name="mapped">The mapped identifier name, if a replacement is needed.</param>
|
||||
/// <returns>The HLSL-compatible identifier name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
mapped = KnownKeywords.Contains(name) switch
|
||||
{
|
||||
true => $"__reserved__{name}",
|
||||
false => null
|
||||
};
|
||||
|
||||
return mapped is not null;
|
||||
}
|
||||
}
|
||||
@@ -7,434 +7,433 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL member names to common .NET members.
|
||||
/// </summary>
|
||||
internal static class HlslKnownMembers
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL member names to common .NET members.
|
||||
/// The mapping of supported known indexers to HLSL resource type names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownMembers
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownResourceIndexers = new Dictionary<string, string>
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known indexers to HLSL resource type names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownResourceIndexers = new Dictionary<string, string>
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known samplers to HLSL resource type names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = new Dictionary<string, string?>
|
||||
{
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null,
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null,
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float3).FullName}]"] = null
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known size accessors for HLSL resource types.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, (int Rank, int Axis)> KnownSizeAccessors = new Dictionary<string, (int, int)>
|
||||
{
|
||||
["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
|
||||
["ComputeSharp.Resources.Texture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.Resources.Texture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.Resources.Texture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.Resources.Texture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.Resources.Texture3D`1.Depth"] = (3, 2),
|
||||
["ComputeSharp.IReadOnlyTexture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.IReadOnlyTexture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Depth"] = (3, 2),
|
||||
["ComputeSharp.IReadWriteTexture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.IReadWriteTexture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Depth"] = (3, 2)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownMembers = BuildKnownMembersMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownMembersMap()
|
||||
{
|
||||
Dictionary<string, string> knownMembers = new()
|
||||
{
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadWriteTexture2D`2.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.IReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadWriteTexture3D`2.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.IReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.IReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.X)}"] = "x",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Y)}"] = "y",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Zero)}"] = "(float2)0",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.One)}"] = "float2(1.0f, 1.0f)",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.UnitX)}"] = "float2(1.0f, 0.0f)",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.UnitY)}"] = "float2(0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.X)}"] = "x",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Y)}"] = "y",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Z)}"] = "z",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Zero)}"] = "(float3)0",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.One)}"] = "float3(1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitX)}"] = "float3(1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitY)}"] = "float3(0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitZ)}"] = "float3(0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.X)}"] = "x",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Y)}"] = "y",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Z)}"] = "z",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.W)}"] = "w",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Zero)}"] = "(float4)0",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.One)}"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.False)}"] = "(bool2)0",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.True)}"] = "bool2(true, true)",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.TrueX)}"] = "bool2(true, false)",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.TrueY)}"] = "bool2(false, true)",
|
||||
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.False)}"] = "(bool3)0",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.True)}"] = "bool3(true, true, true)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueX)}"] = "bool3(true, false, false)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueY)}"] = "bool3(false, true, false)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueZ)}"] = "bool3(false, false, true)",
|
||||
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.False)}"] = "(bool4)0",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.True)}"] = "bool4(true, true, true, true)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueX)}"] = "bool4(true, false, false, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueY)}"] = "bool4(false, true, false, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueZ)}"] = "bool4(false, false, true, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueW)}"] = "bool4(false, false, false, true)",
|
||||
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.Zero)}"] = "(int2)0",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.One)}"] = "int2(1, 1)",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.UnitX)}"] = "int2(1, 0)",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.UnitY)}"] = "int2(0, 1)",
|
||||
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.Zero)}"] = "(int3)0",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.One)}"] = "int3(1, 1, 1)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitX)}"] = "int3(1, 0, 0)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitY)}"] = "int3(0, 1, 0)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitZ)}"] = "int3(0, 0, 1)",
|
||||
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.Zero)}"] = "(int4)0",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.One)}"] = "int4(1, 1, 1, 1)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitX)}"] = "int4(1, 0, 0, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitY)}"] = "int4(0, 1, 0, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitZ)}"] = "int4(0, 0, 1, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitW)}"] = "int4(0, 0, 0, 1)",
|
||||
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.Zero)}"] = "(uint2)0",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.One)}"] = "uint2(1u, 1u)",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.UnitX)}"] = "uint2(1u, 0u)",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.UnitY)}"] = "uint2(0u, 1u)",
|
||||
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.Zero)}"] = "(uint3)0",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.One)}"] = "uint3(1u, 1u, 1u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitX)}"] = "uint3(1u, 0u, 0u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitY)}"] = "uint3(0u, 1u, 0u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitZ)}"] = "uint3(0u, 0u, 1u)",
|
||||
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.Zero)}"] = "(uint4)0",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.One)}"] = "uint4(1u, 1u, 1u, 1u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitX)}"] = "uint4(1u, 0u, 0u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitY)}"] = "uint4(0u, 1u, 0u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitZ)}"] = "uint4(0u, 0u, 1u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitW)}"] = "uint4(0u, 0u, 0u, 1u)",
|
||||
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.Zero)}"] = "(float2)0",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.One)}"] = "float2(1.0f, 1.0f)",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.UnitX)}"] = "float2(1.0f, 0.0f)",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.UnitY)}"] = "float2(0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.Zero)}"] = "(float3)0",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.One)}"] = "float3(1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitX)}"] = "float3(1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitY)}"] = "float3(0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitZ)}"] = "float3(0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.Zero)}"] = "(float4)0",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.One)}"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitX)}"] = "float4(1.0f, 0.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitY)}"] = "float4(0.0f, 1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitZ)}"] = "float4(0.0f, 0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitW)}"] = "float4(0.0f, 0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.Zero)}"] = "(double2)0",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.One)}"] = "double2(1.0, 1.0)",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.UnitX)}"] = "double2(1.0, 0.0)",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.UnitY)}"] = "double2(0.0, 1.0)",
|
||||
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.Zero)}"] = "(double3)0",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.One)}"] = "double3(1.0, 1.0, 1.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitX)}"] = "double3(1.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitY)}"] = "double3(0.0, 1.0, 0.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitZ)}"] = "double3(0.0, 0.0, 1.0)",
|
||||
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.Zero)}"] = "(double4)0",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.One)}"] = "double4(1.0, 1.0, 1.0, 1.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitX)}"] = "double4(1.0, 0.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitY)}"] = "double4(0.0, 1.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitZ)}"] = "double4(0.0, 0.0, 1.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitW)}"] = "double4(0.0, 0.0, 0.0, 1.0)"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known samplers to HLSL resource type names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string?> KnownResourceSamplers = new Dictionary<string, string?>
|
||||
// Programmatically load mappings for the instance members of the HLSL vector types
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.KnownVectorTypes
|
||||
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
{
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`2.this[{typeof(Float2).FullName}]"] = null,
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}]"] = "float2",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float2).FullName}]"] = null,
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`2.this[{typeof(Float3).FullName}]"] = null,
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(float).FullName}, {typeof(float).FullName}, {typeof(float).FullName}]"] = "float3",
|
||||
[$"ComputeSharp.IReadOnlyTexture2D`1.this[{typeof(Float3).FullName}]"] = null
|
||||
};
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Property.Name.ToLower()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known size accessors for HLSL resource types.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, (int Rank, int Axis)> KnownSizeAccessors = new Dictionary<string, (int, int)>
|
||||
// Load mappings for the matrix properties as well
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.KnownMatrixTypes
|
||||
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
where Regex.IsMatch(property.Name, "^M[1-4]{2}$")
|
||||
select (Type: type, Property: property))
|
||||
{
|
||||
["ComputeSharp.Resources.Buffer`1.Length"] = (2, 0),
|
||||
["ComputeSharp.Resources.Texture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.Resources.Texture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.Resources.Texture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.Resources.Texture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.Resources.Texture3D`1.Depth"] = (3, 2),
|
||||
["ComputeSharp.IReadOnlyTexture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.IReadOnlyTexture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.IReadOnlyTexture3D`1.Depth"] = (3, 2),
|
||||
["ComputeSharp.IReadWriteTexture2D`1.Width"] = (2, 0),
|
||||
["ComputeSharp.IReadWriteTexture2D`1.Height"] = (2, 1),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Width"] = (3, 0),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Height"] = (3, 1),
|
||||
["ComputeSharp.IReadWriteTexture3D`1.Depth"] = (3, 2)
|
||||
};
|
||||
char
|
||||
row = (char)(item.Property.Name[1] - 1),
|
||||
column = (char)(item.Property.Name[2] - 1);
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownMembers = BuildKnownMembersMap();
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"_m{row}{column}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownMembersMap()
|
||||
// Store GroupIds.Index for a quicker comparison afterwards
|
||||
PropertyInfo groupindexProperty = typeof(GroupIds).GetProperty(nameof(GroupIds.Index), BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
// Programmatically load mappings for the dispatch types
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.HlslDispatchTypes
|
||||
from property in type.GetProperties(BindingFlags.Static | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
{
|
||||
Dictionary<string, string> knownMembers = new()
|
||||
if (item.Property == groupindexProperty)
|
||||
{
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.X)}"] = "x",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Y)}"] = "y",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Zero)}"] = "(float2)0",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.One)}"] = "float2(1.0f, 1.0f)",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.UnitX)}"] = "float2(1.0f, 0.0f)",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.UnitY)}"] = "float2(0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.X)}"] = "x",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Y)}"] = "y",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Z)}"] = "z",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Zero)}"] = "(float3)0",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.One)}"] = "float3(1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitX)}"] = "float3(1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitY)}"] = "float3(0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.UnitZ)}"] = "float3(0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.X)}"] = "x",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Y)}"] = "y",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Z)}"] = "z",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.W)}"] = "w",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Zero)}"] = "(float4)0",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.One)}"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.False)}"] = "(bool2)0",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.True)}"] = "bool2(true, true)",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.TrueX)}"] = "bool2(true, false)",
|
||||
[$"{typeof(Bool2).FullName}.{nameof(Bool2.TrueY)}"] = "bool2(false, true)",
|
||||
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.False)}"] = "(bool3)0",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.True)}"] = "bool3(true, true, true)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueX)}"] = "bool3(true, false, false)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueY)}"] = "bool3(false, true, false)",
|
||||
[$"{typeof(Bool3).FullName}.{nameof(Bool3.TrueZ)}"] = "bool3(false, false, true)",
|
||||
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.False)}"] = "(bool4)0",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.True)}"] = "bool4(true, true, true, true)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueX)}"] = "bool4(true, false, false, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueY)}"] = "bool4(false, true, false, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueZ)}"] = "bool4(false, false, true, false)",
|
||||
[$"{typeof(Bool4).FullName}.{nameof(Bool4.TrueW)}"] = "bool4(false, false, false, true)",
|
||||
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.Zero)}"] = "(int2)0",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.One)}"] = "int2(1, 1)",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.UnitX)}"] = "int2(1, 0)",
|
||||
[$"{typeof(Int2).FullName}.{nameof(Int2.UnitY)}"] = "int2(0, 1)",
|
||||
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.Zero)}"] = "(int3)0",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.One)}"] = "int3(1, 1, 1)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitX)}"] = "int3(1, 0, 0)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitY)}"] = "int3(0, 1, 0)",
|
||||
[$"{typeof(Int3).FullName}.{nameof(Int3.UnitZ)}"] = "int3(0, 0, 1)",
|
||||
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.Zero)}"] = "(int4)0",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.One)}"] = "int4(1, 1, 1, 1)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitX)}"] = "int4(1, 0, 0, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitY)}"] = "int4(0, 1, 0, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitZ)}"] = "int4(0, 0, 1, 0)",
|
||||
[$"{typeof(Int4).FullName}.{nameof(Int4.UnitW)}"] = "int4(0, 0, 0, 1)",
|
||||
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.Zero)}"] = "(uint2)0",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.One)}"] = "uint2(1u, 1u)",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.UnitX)}"] = "uint2(1u, 0u)",
|
||||
[$"{typeof(UInt2).FullName}.{nameof(UInt2.UnitY)}"] = "uint2(0u, 1u)",
|
||||
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.Zero)}"] = "(uint3)0",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.One)}"] = "uint3(1u, 1u, 1u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitX)}"] = "uint3(1u, 0u, 0u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitY)}"] = "uint3(0u, 1u, 0u)",
|
||||
[$"{typeof(UInt3).FullName}.{nameof(UInt3.UnitZ)}"] = "uint3(0u, 0u, 1u)",
|
||||
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.Zero)}"] = "(uint4)0",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.One)}"] = "uint4(1u, 1u, 1u, 1u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitX)}"] = "uint4(1u, 0u, 0u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitY)}"] = "uint4(0u, 1u, 0u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitZ)}"] = "uint4(0u, 0u, 1u, 0u)",
|
||||
[$"{typeof(UInt4).FullName}.{nameof(UInt4.UnitW)}"] = "uint4(0u, 0u, 0u, 1u)",
|
||||
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.Zero)}"] = "(float2)0",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.One)}"] = "float2(1.0f, 1.0f)",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.UnitX)}"] = "float2(1.0f, 0.0f)",
|
||||
[$"{typeof(Float2).FullName}.{nameof(Float2.UnitY)}"] = "float2(0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.Zero)}"] = "(float3)0",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.One)}"] = "float3(1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitX)}"] = "float3(1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitY)}"] = "float3(0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Float3).FullName}.{nameof(Float3.UnitZ)}"] = "float3(0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.Zero)}"] = "(float4)0",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.One)}"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitX)}"] = "float4(1.0f, 0.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitY)}"] = "float4(0.0f, 1.0f, 0.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitZ)}"] = "float4(0.0f, 0.0f, 1.0f, 0.0f)",
|
||||
[$"{typeof(Float4).FullName}.{nameof(Float4.UnitW)}"] = "float4(0.0f, 0.0f, 0.0f, 1.0f)",
|
||||
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.Zero)}"] = "(double2)0",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.One)}"] = "double2(1.0, 1.0)",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.UnitX)}"] = "double2(1.0, 0.0)",
|
||||
[$"{typeof(Double2).FullName}.{nameof(Double2.UnitY)}"] = "double2(0.0, 1.0)",
|
||||
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.Zero)}"] = "(double3)0",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.One)}"] = "double3(1.0, 1.0, 1.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitX)}"] = "double3(1.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitY)}"] = "double3(0.0, 1.0, 0.0)",
|
||||
[$"{typeof(Double3).FullName}.{nameof(Double3.UnitZ)}"] = "double3(0.0, 0.0, 1.0)",
|
||||
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.Zero)}"] = "(double4)0",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.One)}"] = "double4(1.0, 1.0, 1.0, 1.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitX)}"] = "double4(1.0, 0.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitY)}"] = "double4(0.0, 1.0, 0.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitZ)}"] = "double4(0.0, 0.0, 1.0, 0.0)",
|
||||
[$"{typeof(Double4).FullName}.{nameof(Double4.UnitW)}"] = "double4(0.0, 0.0, 0.0, 1.0)"
|
||||
};
|
||||
|
||||
// Programmatically load mappings for the instance members of the HLSL vector types
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.KnownVectorTypes
|
||||
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
{
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Property.Name.ToLower()}");
|
||||
// The thread group index is a standalone parameter, so if this property is used, we
|
||||
// just map the access directly to that implicit and hidden parameter name instead.
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"__{nameof(GroupIds)}__get_Index");
|
||||
}
|
||||
|
||||
// Load mappings for the matrix properties as well
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.KnownMatrixTypes
|
||||
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
where Regex.IsMatch(property.Name, "^M[1-4]{2}$")
|
||||
select (Type: type, Property: property))
|
||||
else
|
||||
{
|
||||
char
|
||||
row = (char)(item.Property.Name[1] - 1),
|
||||
column = (char)(item.Property.Name[2] - 1);
|
||||
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"_m{row}{column}");
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Type.Name}.{item.Property.Name.ToLower()}");
|
||||
}
|
||||
}
|
||||
|
||||
// Store GroupIds.Index for a quicker comparison afterwards
|
||||
PropertyInfo groupindexProperty = typeof(GroupIds).GetProperty(nameof(GroupIds.Index), BindingFlags.Static | BindingFlags.Public);
|
||||
// Programmatically load mappings for the normalized thread ids
|
||||
foreach (var property in typeof(ThreadIds.Normalized).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(ThreadIds).FullName}{Type.Delimiter}{typeof(ThreadIds.Normalized).Name}{Type.Delimiter}{property.Name}";
|
||||
|
||||
// Programmatically load mappings for the dispatch types
|
||||
foreach (var item in
|
||||
from type in HlslKnownTypes.HlslDispatchTypes
|
||||
from property in type.GetProperties(BindingFlags.Static | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
switch (property.Name)
|
||||
{
|
||||
if (item.Property == groupindexProperty)
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"{typeof(ThreadIds).Name}.{char.ToLower(name[0])} / (float)__{char.ToLower(name[0])}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
{
|
||||
// The thread group index is a standalone parameter, so if this property is used, we
|
||||
// just map the access directly to that implicit and hidden parameter name instead.
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"__{nameof(GroupIds)}__get_Index");
|
||||
string
|
||||
numerator = $"float2({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])})",
|
||||
denominator = $"float2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})";
|
||||
|
||||
knownMembers.Add(key, $"{numerator} / {denominator}");
|
||||
break;
|
||||
}
|
||||
else
|
||||
case string name when name.Length == 3:
|
||||
{
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Type.Name}.{item.Property.Name.ToLower()}");
|
||||
string
|
||||
numerator = $"float3({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])}, {typeof(ThreadIds).Name}.{char.ToLower(name[2])})",
|
||||
denominator = $"float3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})";
|
||||
|
||||
knownMembers.Add(key, $"{numerator} / {denominator}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the normalized thread ids
|
||||
foreach (var property in typeof(ThreadIds.Normalized).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
// Programmatically load mappings for the group size
|
||||
foreach (var property in typeof(GroupSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(GroupSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
switch (property.Name)
|
||||
{
|
||||
string key = $"{typeof(ThreadIds).FullName}{Type.Delimiter}{typeof(ThreadIds.Normalized).Name}{Type.Delimiter}{property.Name}";
|
||||
|
||||
switch (property.Name)
|
||||
{
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"{typeof(ThreadIds).Name}.{char.ToLower(name[0])} / (float)__{char.ToLower(name[0])}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
{
|
||||
string
|
||||
numerator = $"float2({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])})",
|
||||
denominator = $"float2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})";
|
||||
|
||||
knownMembers.Add(key, $"{numerator} / {denominator}");
|
||||
break;
|
||||
}
|
||||
case string name when name.Length == 3:
|
||||
{
|
||||
string
|
||||
numerator = $"float3({typeof(ThreadIds).Name}.{char.ToLower(name[0])}, {typeof(ThreadIds).Name}.{char.ToLower(name[1])}, {typeof(ThreadIds).Name}.{char.ToLower(name[2])})",
|
||||
denominator = $"float3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})";
|
||||
|
||||
knownMembers.Add(key, $"{numerator} / {denominator}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
case nameof(GroupSize.Count):
|
||||
knownMembers.Add(key, "__GroupSize__get_X * __GroupSize__get_Y * __GroupSize__get_Z");
|
||||
break;
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"__GroupSize__get_{name}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
knownMembers.Add(key, $"int2(__GroupSize__get_{name[0]}, __GroupSize__get_{name[1]})");
|
||||
break;
|
||||
case string name when name.Length == 3:
|
||||
knownMembers.Add(key, $"int3(__GroupSize__get_{name[0]}, __GroupSize__get_{name[1]}, __GroupSize__get_{name[2]})");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the group size
|
||||
foreach (var property in typeof(GroupSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
// Programmatically load mappings for the dispatch size
|
||||
foreach (var property in typeof(DispatchSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(DispatchSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
switch (property.Name)
|
||||
{
|
||||
string key = $"{typeof(GroupSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
switch (property.Name)
|
||||
{
|
||||
case nameof(GroupSize.Count):
|
||||
knownMembers.Add(key, "__GroupSize__get_X * __GroupSize__get_Y * __GroupSize__get_Z");
|
||||
break;
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"__GroupSize__get_{name}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
knownMembers.Add(key, $"int2(__GroupSize__get_{name[0]}, __GroupSize__get_{name[1]})");
|
||||
break;
|
||||
case string name when name.Length == 3:
|
||||
knownMembers.Add(key, $"int3(__GroupSize__get_{name[0]}, __GroupSize__get_{name[1]}, __GroupSize__get_{name[2]})");
|
||||
break;
|
||||
}
|
||||
case nameof(DispatchSize.Count):
|
||||
knownMembers.Add(key, "__x * __y * __z");
|
||||
break;
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"__{char.ToLower(name[0])}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
knownMembers.Add(key, $"int2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})");
|
||||
break;
|
||||
case string name when name.Length == 3:
|
||||
knownMembers.Add(key, $"int3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})");
|
||||
break;
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the dispatch size
|
||||
foreach (var property in typeof(DispatchSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(DispatchSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
switch (property.Name)
|
||||
{
|
||||
case nameof(DispatchSize.Count):
|
||||
knownMembers.Add(key, "__x * __y * __z");
|
||||
break;
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"__{char.ToLower(name[0])}");
|
||||
break;
|
||||
case string name when name.Length == 2:
|
||||
knownMembers.Add(key, $"int2(__{char.ToLower(name[0])}, __{char.ToLower(name[1])})");
|
||||
break;
|
||||
case string name when name.Length == 3:
|
||||
knownMembers.Add(key, $"int3(__{char.ToLower(name[0])}, __{char.ToLower(name[1])}, __{char.ToLower(name[2])})");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return knownMembers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownMatrixIndexers = BuildKnownMatrixIndexers();
|
||||
return knownMembers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of swizzled matrix indexer properties.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownMatrixIndexers()
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownMatrixIndexers = BuildKnownMatrixIndexers();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of swizzled matrix indexer properties.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownMatrixIndexers()
|
||||
{
|
||||
return (
|
||||
from type in Assembly.GetExecutingAssembly().ExportedTypes
|
||||
where Regex.IsMatch(type.FullName, @"ComputeSharp\.(Bool|Double|Float|Int|UInt)[1-4]x[1-4]")
|
||||
from property in type.GetProperties()
|
||||
let indices = property.GetIndexParameters()
|
||||
where indices.Length > 0 &&
|
||||
indices.All(static index => index.ParameterType == typeof(MatrixIndex))
|
||||
let metadataName = $"{type.FullName}.this[{string.Join(", ", indices.Select(index => index.ParameterType))}]"
|
||||
select metadataName).ToImmutableHashSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownMatrixIndices = BuildKnownMatrixIndices();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of swizzled matrix indices.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownMatrixIndices()
|
||||
{
|
||||
return (
|
||||
from name in Enum.GetNames(typeof(MatrixIndex))
|
||||
select $"{typeof(MatrixIndex).FullName}.{name}").ToImmutableHashSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given property fullname matches a matrix swizzled indexer.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <returns>Whether or not <paramref name="name"/> is a matrix swizzled indexer.</returns>
|
||||
[Pure]
|
||||
public static bool IsKnownMatrixIndexer(string name)
|
||||
{
|
||||
return KnownMatrixIndexers.Contains(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given property fullname matches a matrix swizzled index.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <returns>Whether or not <paramref name="name"/> is a matrix swizzled index.</returns>
|
||||
[Pure]
|
||||
public static bool IsKnownMatrixIndex(string name)
|
||||
{
|
||||
return KnownMatrixIndices.Contains(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible member name for the input member name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <param name="mapped">The mapped name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible member name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
return KnownMembers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible indexer resource type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedResourceIndexerTypeName(string name, out string? mapped)
|
||||
{
|
||||
return KnownResourceIndexers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given sampler.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
|
||||
{
|
||||
return KnownResourceSamplers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible indexer vector type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetAccessorRankAndAxis(string name, out int rank, out int axis)
|
||||
{
|
||||
if (KnownSizeAccessors.TryGetValue(name, out var info))
|
||||
{
|
||||
return (
|
||||
from type in Assembly.GetExecutingAssembly().ExportedTypes
|
||||
where Regex.IsMatch(type.FullName, @"ComputeSharp\.(Bool|Double|Float|Int|UInt)[1-4]x[1-4]")
|
||||
from property in type.GetProperties()
|
||||
let indices = property.GetIndexParameters()
|
||||
where indices.Length > 0 &&
|
||||
indices.All(static index => index.ParameterType == typeof(MatrixIndex))
|
||||
let metadataName = $"{type.FullName}.this[{string.Join(", ", indices.Select(index => index.ParameterType))}]"
|
||||
select metadataName).ToImmutableHashSet();
|
||||
(rank, axis) = info;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyCollection<string> KnownMatrixIndices = BuildKnownMatrixIndices();
|
||||
(rank, axis) = default((int, int));
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of swizzled matrix indices.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyCollection<string> BuildKnownMatrixIndices()
|
||||
{
|
||||
return (
|
||||
from name in Enum.GetNames(typeof(MatrixIndex))
|
||||
select $"{typeof(MatrixIndex).FullName}.{name}").ToImmutableHashSet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given property fullname matches a matrix swizzled indexer.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <returns>Whether or not <paramref name="name"/> is a matrix swizzled indexer.</returns>
|
||||
[Pure]
|
||||
public static bool IsKnownMatrixIndexer(string name)
|
||||
{
|
||||
return KnownMatrixIndexers.Contains(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given property fullname matches a matrix swizzled index.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <returns>Whether or not <paramref name="name"/> is a matrix swizzled index.</returns>
|
||||
[Pure]
|
||||
public static bool IsKnownMatrixIndex(string name)
|
||||
{
|
||||
return KnownMatrixIndices.Contains(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible member name for the input member name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified member name.</param>
|
||||
/// <param name="mapped">The mapped name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible member name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
return KnownMembers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible indexer resource type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedResourceIndexerTypeName(string name, out string? mapped)
|
||||
{
|
||||
return KnownResourceIndexers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible sampler resource type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given sampler.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedResourceSamplerAccessType(string name, out string? mapped)
|
||||
{
|
||||
return KnownResourceSamplers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible indexer vector type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetAccessorRankAndAxis(string name, out int rank, out int axis)
|
||||
{
|
||||
if (KnownSizeAccessors.TryGetValue(name, out var info))
|
||||
{
|
||||
(rank, axis) = info;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
(rank, axis) = default((int, int));
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
@@ -6,152 +6,151 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL method names to common .NET methods.
|
||||
/// </summary>
|
||||
internal static class HlslKnownMethods
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL method names to common .NET methods.
|
||||
/// The mapping of supported known methods to HLSL names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownMethods
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownMethods = BuildKnownMethodsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of supported known methods to HLSL names.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownMethodsMap()
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known methods to HLSL names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownMethods = BuildKnownMethodsMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of supported known methods to HLSL names.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownMethodsMap()
|
||||
Dictionary<string, string> knownMethods = new()
|
||||
{
|
||||
Dictionary<string, string> knownMethods = new()
|
||||
{
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Abs)}"] = "abs",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Max)}"] = "max",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Min)}"] = "min",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Pow)}"] = "pow",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sin)}"] = "sin",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sinh)}"] = "sinh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Asin)}"] = "asin",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Cos)}"] = "cos",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Cosh)}"] = "cosh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Acos)}"] = "acos",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Tan)}"] = "tan",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Tanh)}"] = "tanh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Atan)}"] = "atan",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Atan2)}"] = "atan2",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Ceiling)}"] = "ceil",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Floor)}"] = "floor",
|
||||
[$"{typeof(Math).FullName}.Clamp"] = "clamp",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Exp)}"] = "exp",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Log)}"] = "log",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Log10)}"] = "log10",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Max)}"] = "max",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Min)}"] = "min",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Round)}"] = "round",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sqrt)}"] = "sqrt",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sign)}"] = "sign",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Truncate)}"] = "trunc",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Abs)}"] = "abs",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Max)}"] = "max",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Min)}"] = "min",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Pow)}"] = "pow",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sin)}"] = "sin",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sinh)}"] = "sinh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Asin)}"] = "asin",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Cos)}"] = "cos",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Cosh)}"] = "cosh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Acos)}"] = "acos",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Tan)}"] = "tan",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Tanh)}"] = "tanh",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Atan)}"] = "atan",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Atan2)}"] = "atan2",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Ceiling)}"] = "ceil",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Floor)}"] = "floor",
|
||||
[$"{typeof(Math).FullName}.Clamp"] = "clamp",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Exp)}"] = "exp",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Log)}"] = "log",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Log10)}"] = "log10",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Max)}"] = "max",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Min)}"] = "min",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Round)}"] = "round",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sqrt)}"] = "sqrt",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Sign)}"] = "sign",
|
||||
[$"{typeof(Math).FullName}.{nameof(Math.Truncate)}"] = "trunc",
|
||||
|
||||
["System.MathF.Abs"] = "abs",
|
||||
["System.MathF.Max"] = "max",
|
||||
["System.MathF.Min"] = "min",
|
||||
["System.MathF.Pow"] = "pow",
|
||||
["System.MathF.Sin"] = "sin",
|
||||
["System.MathF.Sinh"] = "sinh",
|
||||
["System.MathF.Asin"] = "asin",
|
||||
["System.MathF.Cos"] = "cos",
|
||||
["System.MathF.Cosh"] = "cosh",
|
||||
["System.MathF.Acos"] = "acos",
|
||||
["System.MathF.Tan"] = "tan",
|
||||
["System.MathF.Tanh"] = "tanh",
|
||||
["System.MathF.Atan"] = "atan",
|
||||
["System.MathF.Atan2"] = "atan2",
|
||||
["System.MathF.Ceiling"] = "ceil",
|
||||
["System.MathF.Floor"] = "floor",
|
||||
["System.MathF.Clamp"] = "clamp",
|
||||
["System.MathF.Exp"] = "exp",
|
||||
["System.MathF.Log"] = "log",
|
||||
["System.MathF.Log10"] = "log10",
|
||||
["System.MathF.Max"] = "max",
|
||||
["System.MathF.Min"] = "min",
|
||||
["System.MathF.Round"] = "round",
|
||||
["System.MathF.Sqrt"] = "sqrt",
|
||||
["System.MathF.Sign"] = "sign",
|
||||
["System.MathF.Truncate"] = "trunc",
|
||||
["System.MathF.Abs"] = "abs",
|
||||
["System.MathF.Max"] = "max",
|
||||
["System.MathF.Min"] = "min",
|
||||
["System.MathF.Pow"] = "pow",
|
||||
["System.MathF.Sin"] = "sin",
|
||||
["System.MathF.Sinh"] = "sinh",
|
||||
["System.MathF.Asin"] = "asin",
|
||||
["System.MathF.Cos"] = "cos",
|
||||
["System.MathF.Cosh"] = "cosh",
|
||||
["System.MathF.Acos"] = "acos",
|
||||
["System.MathF.Tan"] = "tan",
|
||||
["System.MathF.Tanh"] = "tanh",
|
||||
["System.MathF.Atan"] = "atan",
|
||||
["System.MathF.Atan2"] = "atan2",
|
||||
["System.MathF.Ceiling"] = "ceil",
|
||||
["System.MathF.Floor"] = "floor",
|
||||
["System.MathF.Clamp"] = "clamp",
|
||||
["System.MathF.Exp"] = "exp",
|
||||
["System.MathF.Log"] = "log",
|
||||
["System.MathF.Log10"] = "log10",
|
||||
["System.MathF.Max"] = "max",
|
||||
["System.MathF.Min"] = "min",
|
||||
["System.MathF.Round"] = "round",
|
||||
["System.MathF.Sqrt"] = "sqrt",
|
||||
["System.MathF.Sign"] = "sign",
|
||||
["System.MathF.Truncate"] = "trunc",
|
||||
|
||||
[$"{typeof(float).FullName}.IsFinite"] = "isfinite",
|
||||
[$"{typeof(float).FullName}.{nameof(float.IsInfinity)}"] = "isinf",
|
||||
[$"{typeof(float).FullName}.{nameof(float.IsNaN)}"] = "isnan",
|
||||
[$"{typeof(float).FullName}.IsFinite"] = "isfinite",
|
||||
[$"{typeof(float).FullName}.{nameof(float.IsInfinity)}"] = "isinf",
|
||||
[$"{typeof(float).FullName}.{nameof(float.IsNaN)}"] = "isnan",
|
||||
|
||||
[$"{typeof(double).FullName}.IsFinite"] = "isfinite",
|
||||
[$"{typeof(double).FullName}.{nameof(double.IsInfinity)}"] = "isinf",
|
||||
[$"{typeof(double).FullName}.{nameof(double.IsNaN)}"] = "isnan",
|
||||
[$"{typeof(double).FullName}.IsFinite"] = "isfinite",
|
||||
[$"{typeof(double).FullName}.{nameof(double.IsInfinity)}"] = "isinf",
|
||||
[$"{typeof(double).FullName}.{nameof(double.IsNaN)}"] = "isnan",
|
||||
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Max)}"] = "max",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Min)}"] = "min",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Reflect)}"] = "reflect",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.TransformNormal)}"] = "mul",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Normalize)}"] = "normalize",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Max)}"] = "max",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Min)}"] = "min",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Reflect)}"] = "reflect",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.TransformNormal)}"] = "mul",
|
||||
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Normalize)}"] = "normalize",
|
||||
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Cross)}"] = "cross",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Max)}"] = "max",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Min)}"] = "min",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Reflect)}"] = "reflect",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.TransformNormal)}"] = "mul",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Normalize)}"] = "normalize",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Cross)}"] = "cross",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Max)}"] = "max",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Min)}"] = "min",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Reflect)}"] = "reflect",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.TransformNormal)}"] = "mul",
|
||||
[$"{typeof(Vector3).FullName}.{nameof(Vector3.Normalize)}"] = "normalize",
|
||||
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Max)}"] = "max",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Min)}"] = "min",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Normalize)}"] = "normalize"
|
||||
};
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Abs)}"] = "abs",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Clamp)}"] = "clamp",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Distance)}"] = "distance",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Dot)}"] = "dot",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Lerp)}"] = "lerp",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Max)}"] = "max",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Min)}"] = "min",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Transform)}"] = "mul",
|
||||
[$"{typeof(Vector4).FullName}.{nameof(Vector4.Normalize)}"] = "normalize"
|
||||
};
|
||||
|
||||
// Programmatically load mappings from the Hlsl class as well
|
||||
foreach (var method in
|
||||
from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static)
|
||||
group method by method.Name
|
||||
into groups
|
||||
select groups.First())
|
||||
{
|
||||
// Check whether the current method should be translated with the original name
|
||||
// or with the lowercase version. This is needed because all C# methods are exposed
|
||||
// with the upper camel case format, while HLSL intrinsics use multiple different formats.
|
||||
string hlslName = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
// Programmatically load mappings from the Hlsl class as well
|
||||
foreach (var method in
|
||||
from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static)
|
||||
group method by method.Name
|
||||
into groups
|
||||
select groups.First())
|
||||
{
|
||||
// Check whether the current method should be translated with the original name
|
||||
// or with the lowercase version. This is needed because all C# methods are exposed
|
||||
// with the upper camel case format, while HLSL intrinsics use multiple different formats.
|
||||
string hlslName = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()?.Name ?? method.Name;
|
||||
|
||||
knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName);
|
||||
}
|
||||
|
||||
return knownMethods;
|
||||
knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible method name for the input method name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified method name.</param>
|
||||
/// <param name="mapped">The mapped name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible member name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
return KnownMethods.TryGetValue(name, out mapped);
|
||||
}
|
||||
return knownMethods;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible method name for the input method name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified method name.</param>
|
||||
/// <param name="mapped">The mapped name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible member name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedName(string name, out string? mapped)
|
||||
{
|
||||
return KnownMethods.TryGetValue(name, out mapped);
|
||||
}
|
||||
}
|
||||
@@ -5,58 +5,57 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL types to their alignment sizes.
|
||||
/// </summary>
|
||||
internal static class HlslKnownSizes
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL types to their alignment sizes.
|
||||
/// The mapping of supported known sizes to HLSL type names.
|
||||
/// </summary>
|
||||
internal static class HlslKnownSizes
|
||||
private static IReadOnlyDictionary<string, (int, int)> KnownSizes = BuildKnownSizesMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of known type sizes and alignments.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, (int, int)> BuildKnownSizesMap()
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known sizes to HLSL type names.
|
||||
/// </summary>
|
||||
private static IReadOnlyDictionary<string, (int, int)> KnownSizes = BuildKnownSizesMap();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of known type sizes and alignments.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, (int, int)> BuildKnownSizesMap()
|
||||
Dictionary<string, (int, int)> knownSizes = new()
|
||||
{
|
||||
Dictionary<string, (int, int)> knownSizes = new()
|
||||
{
|
||||
[typeof(bool).FullName] = (4, 4),
|
||||
[typeof(int).FullName] = (4, 4),
|
||||
[typeof(uint).FullName] = (4, 4),
|
||||
[typeof(float).FullName] = (4, 4),
|
||||
[typeof(double).FullName] = (8, 8),
|
||||
[typeof(bool).FullName] = (4, 4),
|
||||
[typeof(int).FullName] = (4, 4),
|
||||
[typeof(uint).FullName] = (4, 4),
|
||||
[typeof(float).FullName] = (4, 4),
|
||||
[typeof(double).FullName] = (8, 8),
|
||||
|
||||
[typeof(Vector2).FullName] = (8, 4),
|
||||
[typeof(Vector3).FullName] = (12, 4),
|
||||
[typeof(Vector4).FullName] = (16, 4)
|
||||
};
|
||||
[typeof(Vector2).FullName] = (8, 4),
|
||||
[typeof(Vector3).FullName] = (12, 4),
|
||||
[typeof(Vector4).FullName] = (16, 4)
|
||||
};
|
||||
|
||||
foreach (
|
||||
var type in
|
||||
from type in Assembly.GetExecutingAssembly().ExportedTypes
|
||||
where Regex.IsMatch(type.FullName, @"^ComputeSharp\.(Bool|Double|Float|Int|UInt)")
|
||||
select type)
|
||||
{
|
||||
knownSizes.Add(type.FullName, (type.StructLayoutAttribute.Size, type.StructLayoutAttribute.Pack));
|
||||
}
|
||||
|
||||
return knownSizes;
|
||||
foreach (
|
||||
var type in
|
||||
from type in Assembly.GetExecutingAssembly().ExportedTypes
|
||||
where Regex.IsMatch(type.FullName, @"^ComputeSharp\.(Bool|Double|Float|Int|UInt)")
|
||||
select type)
|
||||
{
|
||||
knownSizes.Add(type.FullName, (type.StructLayoutAttribute.Size, type.StructLayoutAttribute.Pack));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size and alignment info for a specified primitive type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The type name to get info for.</param>
|
||||
/// <returns>The size and and alignment for the input type.</returns>
|
||||
[Pure]
|
||||
public static (int Size, int Pack) GetTypeInfo(string typeName)
|
||||
{
|
||||
return KnownSizes[typeName];
|
||||
}
|
||||
return knownSizes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size and alignment info for a specified primitive type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The type name to get info for.</param>
|
||||
/// <returns>The size and and alignment for the input type.</returns>
|
||||
[Pure]
|
||||
public static (int Size, int Pack) GetTypeInfo(string typeName)
|
||||
{
|
||||
return KnownSizes[typeName];
|
||||
}
|
||||
}
|
||||
@@ -9,301 +9,253 @@ using Microsoft.CodeAnalysis;
|
||||
|
||||
#pragma warning disable RS1024
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Mappings
|
||||
namespace ComputeSharp.SourceGenerators.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL type names to common .NET types.
|
||||
/// </summary>
|
||||
internal static class HlslKnownTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains and maps known HLSL type names to common .NET types.
|
||||
/// Gets the known HLSL dispatch types.
|
||||
/// </summary>
|
||||
internal static class HlslKnownTypes
|
||||
public static IReadOnlyCollection<Type> HlslDispatchTypes { get; } = new[]
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the known HLSL dispatch types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> HlslDispatchTypes { get; } = new[]
|
||||
typeof(ThreadIds),
|
||||
typeof(GroupIds),
|
||||
typeof(GridIds)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of HLSL vector types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> KnownVectorTypes { get; } = new[]
|
||||
{
|
||||
typeof(Bool2), typeof(Bool3), typeof(Bool4),
|
||||
typeof(Int2), typeof(Int3), typeof(Int4),
|
||||
typeof(UInt2), typeof(UInt3), typeof(UInt4),
|
||||
typeof(Float2), typeof(Float3), typeof(Float4),
|
||||
typeof(Double2), typeof(Double3), typeof(Double4)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of HLSL matrix types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> KnownMatrixTypes { get; } = new[]
|
||||
{
|
||||
typeof(Bool1x1), typeof(Bool1x2), typeof(Bool1x3), typeof(Bool1x4),
|
||||
typeof(Bool2x1), typeof(Bool2x2), typeof(Bool2x3), typeof(Bool2x4),
|
||||
typeof(Bool3x1), typeof(Bool3x2), typeof(Bool3x3), typeof(Bool3x4),
|
||||
typeof(Bool4x1), typeof(Bool4x2), typeof(Bool4x3), typeof(Bool4x4),
|
||||
typeof(Int1x1), typeof(Int1x2), typeof(Int1x3), typeof(Int1x4),
|
||||
typeof(Int2x1), typeof(Int2x2), typeof(Int2x3), typeof(Int2x4),
|
||||
typeof(Int3x1), typeof(Int3x2), typeof(Int3x3), typeof(Int3x4),
|
||||
typeof(Int4x1), typeof(Int4x2), typeof(Int4x3), typeof(Int4x4),
|
||||
typeof(UInt1x1), typeof(UInt1x2), typeof(UInt1x3), typeof(UInt1x4),
|
||||
typeof(UInt2x1), typeof(UInt2x2), typeof(UInt2x3), typeof(UInt2x4),
|
||||
typeof(UInt3x1), typeof(UInt3x2), typeof(UInt3x3), typeof(UInt3x4),
|
||||
typeof(UInt4x1), typeof(UInt4x2), typeof(UInt4x3), typeof(UInt4x4),
|
||||
typeof(Float1x1), typeof(Float1x2), typeof(Float1x3), typeof(Float1x4),
|
||||
typeof(Float2x1), typeof(Float2x2), typeof(Float2x3), typeof(Float2x4),
|
||||
typeof(Float3x1), typeof(Float3x2), typeof(Float3x3), typeof(Float3x4),
|
||||
typeof(Float4x1), typeof(Float4x2), typeof(Float4x3), typeof(Float4x4),
|
||||
typeof(Double1x1), typeof(Double1x2), typeof(Double1x3), typeof(Double1x4),
|
||||
typeof(Double2x1), typeof(Double2x2), typeof(Double2x3), typeof(Double2x4),
|
||||
typeof(Double3x1), typeof(Double3x2), typeof(Double3x3), typeof(Double3x4),
|
||||
typeof(Double4x1), typeof(Double4x2), typeof(Double4x3), typeof(Double4x4)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known types to HLSL types.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownHlslTypes = BuildKnownHlslTypes();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of known primitive types.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownHlslTypes()
|
||||
{
|
||||
Dictionary<string, string> knownTypes = new()
|
||||
{
|
||||
typeof(ThreadIds),
|
||||
typeof(GroupIds),
|
||||
typeof(GridIds)
|
||||
[typeof(bool).FullName] = "bool",
|
||||
[typeof(int).FullName] = "int",
|
||||
[typeof(uint).FullName] = "uint",
|
||||
[typeof(float).FullName] = "float",
|
||||
[typeof(Vector2).FullName] = "float2",
|
||||
[typeof(Vector3).FullName] = "float3",
|
||||
[typeof(Vector4).FullName] = "float4",
|
||||
[typeof(double).FullName] = "double"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of HLSL vector types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> KnownVectorTypes { get; } = new[]
|
||||
// Add all the vector types
|
||||
foreach (var type in KnownVectorTypes)
|
||||
{
|
||||
typeof(Bool2), typeof(Bool3), typeof(Bool4),
|
||||
typeof(Int2), typeof(Int3), typeof(Int4),
|
||||
typeof(UInt2), typeof(UInt3), typeof(UInt4),
|
||||
typeof(Float2), typeof(Float3), typeof(Float4),
|
||||
typeof(Double2), typeof(Double3), typeof(Double4)
|
||||
knownTypes.Add(type.FullName, type.Name.ToLower());
|
||||
}
|
||||
|
||||
// Add all the matrix types
|
||||
foreach (var type in KnownMatrixTypes)
|
||||
{
|
||||
knownTypes.Add(type.FullName, type.Name.ToLower());
|
||||
}
|
||||
|
||||
return knownTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a constant buffer type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a constant buffer type.</returns>
|
||||
public static bool IsConstantBufferType(string typeName)
|
||||
{
|
||||
return typeName == "ComputeSharp.ConstantBuffer`1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a structured buffer type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a structured buffer type.</returns>
|
||||
public static bool IsStructuredBufferType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ConstantBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadWriteBuffer`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of HLSL matrix types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> KnownMatrixTypes { get; } = new[]
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a readonly typed resource type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a readonly typed resource type.</returns>
|
||||
public static bool IsReadOnlyTypedResourceType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
typeof(Bool1x1), typeof(Bool1x2), typeof(Bool1x3), typeof(Bool1x4),
|
||||
typeof(Bool2x1), typeof(Bool2x2), typeof(Bool2x3), typeof(Bool2x4),
|
||||
typeof(Bool3x1), typeof(Bool3x2), typeof(Bool3x3), typeof(Bool3x4),
|
||||
typeof(Bool4x1), typeof(Bool4x2), typeof(Bool4x3), typeof(Bool4x4),
|
||||
typeof(Int1x1), typeof(Int1x2), typeof(Int1x3), typeof(Int1x4),
|
||||
typeof(Int2x1), typeof(Int2x2), typeof(Int2x3), typeof(Int2x4),
|
||||
typeof(Int3x1), typeof(Int3x2), typeof(Int3x3), typeof(Int3x4),
|
||||
typeof(Int4x1), typeof(Int4x2), typeof(Int4x3), typeof(Int4x4),
|
||||
typeof(UInt1x1), typeof(UInt1x2), typeof(UInt1x3), typeof(UInt1x4),
|
||||
typeof(UInt2x1), typeof(UInt2x2), typeof(UInt2x3), typeof(UInt2x4),
|
||||
typeof(UInt3x1), typeof(UInt3x2), typeof(UInt3x3), typeof(UInt3x4),
|
||||
typeof(UInt4x1), typeof(UInt4x2), typeof(UInt4x3), typeof(UInt4x4),
|
||||
typeof(Float1x1), typeof(Float1x2), typeof(Float1x3), typeof(Float1x4),
|
||||
typeof(Float2x1), typeof(Float2x2), typeof(Float2x3), typeof(Float2x4),
|
||||
typeof(Float3x1), typeof(Float3x2), typeof(Float3x3), typeof(Float3x4),
|
||||
typeof(Float4x1), typeof(Float4x2), typeof(Float4x3), typeof(Float4x4),
|
||||
typeof(Double1x1), typeof(Double1x2), typeof(Double1x3), typeof(Double1x4),
|
||||
typeof(Double2x1), typeof(Double2x2), typeof(Double2x3), typeof(Double2x4),
|
||||
typeof(Double3x1), typeof(Double3x2), typeof(Double3x3), typeof(Double3x4),
|
||||
typeof(Double4x1), typeof(Double4x2), typeof(Double4x3), typeof(Double4x4)
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" or
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known types to HLSL types.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownHlslTypes = BuildKnownHlslTypes();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the mapping of known primitive types.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
private static IReadOnlyDictionary<string, string> BuildKnownHlslTypes()
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a typed resource type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a typed resource type.</returns>
|
||||
public static bool IsTypedResourceType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
Dictionary<string, string> knownTypes = new()
|
||||
{
|
||||
[typeof(bool).FullName] = "bool",
|
||||
[typeof(int).FullName] = "int",
|
||||
[typeof(uint).FullName] = "uint",
|
||||
[typeof(float).FullName] = "float",
|
||||
[typeof(Vector2).FullName] = "float2",
|
||||
[typeof(Vector3).FullName] = "float3",
|
||||
[typeof(Vector4).FullName] = "float4",
|
||||
[typeof(double).FullName] = "double"
|
||||
};
|
||||
"ComputeSharp.ConstantBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadWriteBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" or
|
||||
"ComputeSharp.ReadWriteTexture2D`1" or
|
||||
"ComputeSharp.ReadWriteTexture2D`2" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" or
|
||||
"ComputeSharp.ReadWriteTexture3D`1" or
|
||||
"ComputeSharp.ReadWriteTexture3D`2" or
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.IReadWriteTexture2D`1" or
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.IReadWriteTexture3D`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
// Add all the vector types
|
||||
foreach (var type in KnownVectorTypes)
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a known HLSL primitive type (scalar, vector or matrix).
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a scalar, vector or matrix type.</returns>
|
||||
public static bool IsKnownHlslType(string typeName)
|
||||
{
|
||||
return KnownHlslTypes.ContainsKey(typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a vector type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a vector type.</returns>
|
||||
public static bool IsVectorType(string typeName)
|
||||
{
|
||||
return KnownVectorTypes.Any(type => type.FullName == typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a matrix type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a matrix type.</returns>
|
||||
public static bool IsMatrixType(string typeName)
|
||||
{
|
||||
return KnownMatrixTypes.Any(type => type.FullName == typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name is a non linear matrix type.
|
||||
/// That is, a matrix type with more than a single row (which affects the constant buffer alignment).
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <param name="elementName">The element name of the matrix type.</param>
|
||||
/// <param name="rows">The number of rows in the matrix type.</param>
|
||||
/// <param name="columns">The number of columns in the matrix type.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a non linear matrix type.</returns>
|
||||
public static bool IsNonLinearMatrixType(string typeName, out string? elementName, out int rows, out int columns)
|
||||
{
|
||||
if (KnownMatrixTypes.Any(type => type.FullName == typeName))
|
||||
{
|
||||
var match = Regex.Match(typeName, @"^ComputeSharp\.(Bool|Int|UInt|Float|Double)([2-4])x([1-4])$");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
knownTypes.Add(type.FullName, type.Name.ToLower());
|
||||
elementName = match.Groups[1].Value;
|
||||
rows = int.Parse(match.Groups[2].Value);
|
||||
columns = int.Parse(match.Groups[3].Value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add all the matrix types
|
||||
foreach (var type in KnownMatrixTypes)
|
||||
{
|
||||
knownTypes.Add(type.FullName, type.Name.ToLower());
|
||||
}
|
||||
|
||||
return knownTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a constant buffer type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a constant buffer type.</returns>
|
||||
public static bool IsConstantBufferType(string typeName)
|
||||
elementName = null;
|
||||
rows = columns = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type symbol.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedName(INamedTypeSymbol typeSymbol)
|
||||
{
|
||||
// Delegate types just return an empty string, as they're not actually
|
||||
// used in the generated shaders, but just mapped to a function at runtime.
|
||||
if (typeSymbol.TypeKind == TypeKind.Delegate) return "";
|
||||
|
||||
string typeName = typeSymbol.GetFullMetadataName();
|
||||
|
||||
// Special case for the resource types
|
||||
if (IsTypedResourceType(typeName))
|
||||
{
|
||||
return typeName == "ComputeSharp.ConstantBuffer`1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a structured buffer type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a structured buffer type.</returns>
|
||||
public static bool IsStructuredBufferType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ConstantBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadWriteBuffer`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a readonly typed resource type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a readonly typed resource type.</returns>
|
||||
public static bool IsReadOnlyTypedResourceType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" or
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a typed resource type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a typed resource type.</returns>
|
||||
public static bool IsTypedResourceType(string typeName)
|
||||
{
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ConstantBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyBuffer`1" or
|
||||
"ComputeSharp.ReadWriteBuffer`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" or
|
||||
"ComputeSharp.ReadWriteTexture2D`1" or
|
||||
"ComputeSharp.ReadWriteTexture2D`2" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" or
|
||||
"ComputeSharp.ReadWriteTexture3D`1" or
|
||||
"ComputeSharp.ReadWriteTexture3D`2" or
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" or
|
||||
"ComputeSharp.IReadWriteTexture2D`1" or
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" or
|
||||
"ComputeSharp.IReadWriteTexture3D`1" => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a known HLSL primitive type (scalar, vector or matrix).
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a scalar, vector or matrix type.</returns>
|
||||
public static bool IsKnownHlslType(string typeName)
|
||||
{
|
||||
return KnownHlslTypes.ContainsKey(typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a vector type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a vector type.</returns>
|
||||
public static bool IsVectorType(string typeName)
|
||||
{
|
||||
return KnownVectorTypes.Any(type => type.FullName == typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a matrix type.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a matrix type.</returns>
|
||||
public static bool IsMatrixType(string typeName)
|
||||
{
|
||||
return KnownMatrixTypes.Any(type => type.FullName == typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name is a non linear matrix type.
|
||||
/// That is, a matrix type with more than a single row (which affects the constant buffer alignment).
|
||||
/// </summary>
|
||||
/// <param name="typeName">The input type name to check.</param>
|
||||
/// <param name="elementName">The element name of the matrix type.</param>
|
||||
/// <param name="rows">The number of rows in the matrix type.</param>
|
||||
/// <param name="columns">The number of columns in the matrix type.</param>
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a non linear matrix type.</returns>
|
||||
public static bool IsNonLinearMatrixType(string typeName, out string? elementName, out int rows, out int columns)
|
||||
{
|
||||
if (KnownMatrixTypes.Any(type => type.FullName == typeName))
|
||||
{
|
||||
var match = Regex.Match(typeName, @"^ComputeSharp\.(Bool|Int|UInt|Float|Double)([2-4])x([1-4])$");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
elementName = match.Groups[1].Value;
|
||||
rows = int.Parse(match.Groups[2].Value);
|
||||
columns = int.Parse(match.Groups[3].Value);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
elementName = null;
|
||||
rows = columns = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type symbol.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedName(INamedTypeSymbol typeSymbol)
|
||||
{
|
||||
// Delegate types just return an empty string, as they're not actually
|
||||
// used in the generated shaders, but just mapped to a function at runtime.
|
||||
if (typeSymbol.TypeKind == TypeKind.Delegate) return "";
|
||||
|
||||
string typeName = typeSymbol.GetFullMetadataName();
|
||||
|
||||
// Special case for the resource types
|
||||
if (IsTypedResourceType(typeName))
|
||||
{
|
||||
string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.Last()).GetFullMetadataName();
|
||||
|
||||
// If the current type is a custom type, format it as needed
|
||||
if (!KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType))
|
||||
{
|
||||
mappedElementType = genericArgumentName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
// Construct the HLSL type name
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ConstantBuffer`1" => mappedElementType,
|
||||
"ComputeSharp.ReadOnlyBuffer`1" => $"StructuredBuffer<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteBuffer`1" => $"RWStructuredBuffer<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" => $"Texture2D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" => $"Texture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture2D`1" => $"RWTexture2D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture2D`2" => $"RWTexture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" => $"Texture3D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" => $"Texture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`2" => $"RWTexture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" => $"Texture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadWriteTexture2D`1" => $"RWTexture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" => $"Texture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadWriteTexture3D`1" => $"RWTexture3D<unorm {mappedElementType}>",
|
||||
_ => throw new ArgumentException()
|
||||
};
|
||||
}
|
||||
|
||||
// The captured field is of an HLSL primitive type
|
||||
if (KnownHlslTypes.TryGetValue(typeName, out string? mappedType))
|
||||
{
|
||||
return mappedType;
|
||||
}
|
||||
|
||||
// The captured field is of a custom struct type
|
||||
return typeName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the output texture of a pixel shader.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The pixel shader type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedNameForPixelShaderType(INamedTypeSymbol typeSymbol)
|
||||
{
|
||||
string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.First()).GetFullMetadataName();
|
||||
string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.Last()).GetFullMetadataName();
|
||||
|
||||
// If the current type is a custom type, format it as needed
|
||||
if (!KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType))
|
||||
@@ -312,124 +264,171 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
}
|
||||
|
||||
// Construct the HLSL type name
|
||||
return $"RWTexture2D<unorm {mappedElementType}>";
|
||||
return typeName switch
|
||||
{
|
||||
"ComputeSharp.ConstantBuffer`1" => mappedElementType,
|
||||
"ComputeSharp.ReadOnlyBuffer`1" => $"StructuredBuffer<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteBuffer`1" => $"RWStructuredBuffer<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture2D`1" => $"Texture2D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture2D`2" => $"Texture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture2D`1" => $"RWTexture2D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture2D`2" => $"RWTexture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture3D`1" => $"Texture3D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" => $"Texture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mappedElementType}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`2" => $"RWTexture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" => $"Texture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadWriteTexture2D`1" => $"RWTexture2D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" => $"Texture3D<unorm {mappedElementType}>",
|
||||
"ComputeSharp.IReadWriteTexture3D`1" => $"RWTexture3D<unorm {mappedElementType}>",
|
||||
_ => throw new ArgumentException()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input element type symbol.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedElementName(IArrayTypeSymbol typeSymbol)
|
||||
// The captured field is of an HLSL primitive type
|
||||
if (KnownHlslTypes.TryGetValue(typeName, out string? mappedType))
|
||||
{
|
||||
string elementTypeName = ((INamedTypeSymbol)typeSymbol.ElementType).GetFullMetadataName();
|
||||
return mappedType;
|
||||
}
|
||||
|
||||
if (KnownHlslTypes.TryGetValue(elementTypeName, out string? mapped))
|
||||
// The captured field is of a custom struct type
|
||||
return typeName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the output texture of a pixel shader.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The pixel shader type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedNameForPixelShaderType(INamedTypeSymbol typeSymbol)
|
||||
{
|
||||
string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.First()).GetFullMetadataName();
|
||||
|
||||
// If the current type is a custom type, format it as needed
|
||||
if (!KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType))
|
||||
{
|
||||
mappedElementType = genericArgumentName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
// Construct the HLSL type name
|
||||
return $"RWTexture2D<unorm {mappedElementType}>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input element type symbol.
|
||||
/// </summary>
|
||||
/// <param name="typeSymbol">The input type to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
[Pure]
|
||||
public static string GetMappedElementName(IArrayTypeSymbol typeSymbol)
|
||||
{
|
||||
string elementTypeName = ((INamedTypeSymbol)typeSymbol.ElementType).GetFullMetadataName();
|
||||
|
||||
if (KnownHlslTypes.TryGetValue(elementTypeName, out string? mapped))
|
||||
{
|
||||
return mapped;
|
||||
}
|
||||
|
||||
return elementTypeName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input type name to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
public static bool TryGetMappedName(string originalName, out string? mappedName)
|
||||
{
|
||||
return KnownHlslTypes.TryGetValue(originalName, out mappedName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of unique custom types from a collection of discovered types.
|
||||
/// </summary>
|
||||
/// <param name="discoveredTypes">The input collection of discovered types.</param>
|
||||
/// <returns>The list of unique custom types.</returns>
|
||||
public static IEnumerable<INamedTypeSymbol> GetCustomTypes(IEnumerable<INamedTypeSymbol> discoveredTypes)
|
||||
{
|
||||
// Local function to recursively gather nested types
|
||||
static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> customTypes)
|
||||
{
|
||||
if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName())) return;
|
||||
|
||||
if (!customTypes.Add(type)) return;
|
||||
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
return mapped;
|
||||
if (field.IsStatic) continue;
|
||||
|
||||
ExploreTypes((INamedTypeSymbol)field.Type, customTypes);
|
||||
}
|
||||
|
||||
return elementTypeName.ToHlslIdentifierName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input type name to map.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
public static bool TryGetMappedName(string originalName, out string? mappedName)
|
||||
HashSet<INamedTypeSymbol> customTypes = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore all input types and their nested types
|
||||
foreach (INamedTypeSymbol type in discoveredTypes)
|
||||
{
|
||||
return KnownHlslTypes.TryGetValue(originalName, out mappedName);
|
||||
ExploreTypes(type, customTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of unique custom types from a collection of discovered types.
|
||||
/// </summary>
|
||||
/// <param name="discoveredTypes">The input collection of discovered types.</param>
|
||||
/// <returns>The list of unique custom types.</returns>
|
||||
public static IEnumerable<INamedTypeSymbol> GetCustomTypes(IEnumerable<INamedTypeSymbol> discoveredTypes)
|
||||
return OrderByDependency(customTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orders the input sequence of types so that they can be declared in HLSL successfully.
|
||||
/// </summary>
|
||||
/// <param name="types">The input collection of types to declare.</param>
|
||||
/// <returns>The same list as input, but in a valid HLSL declaration order.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<INamedTypeSymbol> OrderByDependency(IEnumerable<INamedTypeSymbol> types)
|
||||
{
|
||||
Queue<(INamedTypeSymbol Type, HashSet<INamedTypeSymbol> Fields)> queue = new();
|
||||
|
||||
// Build a mapping of type dependencies for all the captured types. A type depends on another
|
||||
// when the latter is a field in the first type. HLSL requires custom types to be declared in
|
||||
// order of usage, so we need to ensure that types are declared in an order that guarantees
|
||||
// that no type will be referenced before being defined. To do so, we can create a mapping of
|
||||
// types and their dependencies, and iteratively remove items from the map when they have no
|
||||
// dependencies left. When one type is processed and removed, it is also removed from the list
|
||||
// of dependencies of all other remaining types in the map, until there is none left.
|
||||
foreach (var type in types)
|
||||
{
|
||||
// Local function to recursively gather nested types
|
||||
static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> customTypes)
|
||||
HashSet<INamedTypeSymbol> dependencies = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Only add other custom types as dependencies, and ignore HLSL types
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName())) return;
|
||||
if (field.IsStatic) continue;
|
||||
|
||||
if (!customTypes.Add(type)) return;
|
||||
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
|
||||
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
if (!KnownHlslTypes.ContainsKey(fieldType.GetFullMetadataName()))
|
||||
{
|
||||
if (field.IsStatic) continue;
|
||||
|
||||
ExploreTypes((INamedTypeSymbol)field.Type, customTypes);
|
||||
_ = dependencies.Add(fieldType);
|
||||
}
|
||||
}
|
||||
|
||||
HashSet<INamedTypeSymbol> customTypes = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore all input types and their nested types
|
||||
foreach (INamedTypeSymbol type in discoveredTypes)
|
||||
{
|
||||
ExploreTypes(type, customTypes);
|
||||
}
|
||||
|
||||
return OrderByDependency(customTypes);
|
||||
queue.Enqueue((type, dependencies));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orders the input sequence of types so that they can be declared in HLSL successfully.
|
||||
/// </summary>
|
||||
/// <param name="types">The input collection of types to declare.</param>
|
||||
/// <returns>The same list as input, but in a valid HLSL declaration order.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<INamedTypeSymbol> OrderByDependency(IEnumerable<INamedTypeSymbol> types)
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
Queue<(INamedTypeSymbol Type, HashSet<INamedTypeSymbol> Fields)> queue = new();
|
||||
var entry = queue.Dequeue();
|
||||
|
||||
// Build a mapping of type dependencies for all the captured types. A type depends on another
|
||||
// when the latter is a field in the first type. HLSL requires custom types to be declared in
|
||||
// order of usage, so we need to ensure that types are declared in an order that guarantees
|
||||
// that no type will be referenced before being defined. To do so, we can create a mapping of
|
||||
// types and their dependencies, and iteratively remove items from the map when they have no
|
||||
// dependencies left. When one type is processed and removed, it is also removed from the list
|
||||
// of dependencies of all other remaining types in the map, until there is none left.
|
||||
foreach (var type in types)
|
||||
// No dependencies left, we can declare this type
|
||||
if (entry.Fields.Count == 0)
|
||||
{
|
||||
HashSet<INamedTypeSymbol> dependencies = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Only add other custom types as dependencies, and ignore HLSL types
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
// Remove the current type from dependencies of others
|
||||
foreach (var pair in queue)
|
||||
{
|
||||
if (field.IsStatic) continue;
|
||||
|
||||
INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type;
|
||||
|
||||
if (!KnownHlslTypes.ContainsKey(fieldType.GetFullMetadataName()))
|
||||
{
|
||||
_ = dependencies.Add(fieldType);
|
||||
}
|
||||
_ = pair.Fields.Remove(entry.Type);
|
||||
}
|
||||
|
||||
queue.Enqueue((type, dependencies));
|
||||
}
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var entry = queue.Dequeue();
|
||||
|
||||
// No dependencies left, we can declare this type
|
||||
if (entry.Fields.Count == 0)
|
||||
{
|
||||
// Remove the current type from dependencies of others
|
||||
foreach (var pair in queue)
|
||||
{
|
||||
_ = pair.Fields.Remove(entry.Type);
|
||||
}
|
||||
|
||||
yield return entry.Type;
|
||||
}
|
||||
else queue.Enqueue(entry);
|
||||
yield return entry.Type;
|
||||
}
|
||||
else queue.Enqueue(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,45 +4,43 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class ShaderMethodSourceGenerator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class ShaderMethodSourceGenerator
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ISyntaxContextReceiver"/> that selects candidate nodes to process.
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private sealed class SyntaxReceiver : ISyntaxContextReceiver
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of info gathered during exploration.
|
||||
/// </summary>
|
||||
private readonly List<Item> gatheredInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of gathered info to process.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Item> GatheredInfo => this.gatheredInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
|
||||
if (context.Node is MethodDeclarationSyntax { AttributeLists: { Count: > 0 } } methodDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(methodDeclaration) is IMethodSymbol methodSymbol &&
|
||||
context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(ShaderMethodAttribute).FullName) is INamedTypeSymbol attributeSymbol &&
|
||||
methodSymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol)))
|
||||
{
|
||||
if (context.Node is MethodDeclarationSyntax { AttributeLists: { Count: > 0 } } methodDeclaration &&
|
||||
context.SemanticModel.GetDeclaredSymbol(methodDeclaration) is IMethodSymbol methodSymbol &&
|
||||
context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(ShaderMethodAttribute).FullName) is INamedTypeSymbol attributeSymbol &&
|
||||
methodSymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attributeSymbol)))
|
||||
{
|
||||
this.gatheredInfo.Add(new Item(methodDeclaration, methodSymbol));
|
||||
}
|
||||
this.gatheredInfo.Add(new Item(methodDeclaration, methodSymbol));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered method to process.
|
||||
/// </summary>
|
||||
/// <param name="MethodDeclaration">The <see cref="MethodDeclarationSyntax"/> instance for the target method declaration.</param>
|
||||
/// <param name="MethodSymbol">The <see cref="IMethodSymbol"/> instance for <paramref name="MethodDeclaration"/>.</param>
|
||||
public sealed record Item(MethodDeclarationSyntax MethodDeclaration, IMethodSymbol MethodSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A model for a group of item representing a discovered method to process.
|
||||
/// </summary>
|
||||
/// <param name="MethodDeclaration">The <see cref="MethodDeclarationSyntax"/> instance for the target method declaration.</param>
|
||||
/// <param name="MethodSymbol">The <see cref="IMethodSymbol"/> instance for <paramref name="MethodDeclaration"/>.</param>
|
||||
public sealed record Item(MethodDeclarationSyntax MethodDeclaration, IMethodSymbol MethodSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,130 +17,128 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618, RS1024
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <summary>
|
||||
/// A source generator for processing static methods referenced from compute shaders.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class ShaderMethodSourceGenerator : ISourceGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A source generator for processing static methods referenced from compute shaders.
|
||||
/// </summary>
|
||||
[Generator]
|
||||
public sealed partial class ShaderMethodSourceGenerator : ISourceGenerator
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
{
|
||||
context.RegisterForSyntaxNotifications(static () => new SyntaxReceiver());
|
||||
return;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
{
|
||||
// Get the syntax receiver with the candidate nodes
|
||||
if (context.SyntaxContextReceiver is not SyntaxReceiver syntaxReceiver)
|
||||
SemanticModelProvider semanticModel = new(context.Compilation);
|
||||
|
||||
try
|
||||
{
|
||||
return;
|
||||
OnExecute(context, item.MethodDeclaration, semanticModel, item.MethodSymbol);
|
||||
}
|
||||
|
||||
foreach (SyntaxReceiver.Item item in syntaxReceiver.GatheredInfo)
|
||||
catch
|
||||
{
|
||||
SemanticModelProvider semanticModel = new(context.Compilation);
|
||||
|
||||
try
|
||||
{
|
||||
OnExecute(context, item.MethodDeclaration, semanticModel, item.MethodSymbol);
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.ReportDiagnostic(ShaderMethodSourceGeneratorError, item.MethodDeclaration, item.MethodSymbol);
|
||||
}
|
||||
context.ReportDiagnostic(ShaderMethodSourceGeneratorError, item.MethodDeclaration, item.MethodSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> with metadata on the types being processed.</param>
|
||||
/// <param name="methodDeclarationSymbol">The <see cref="IMethodSymbol"/> for <paramref name="methodDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, MethodDeclarationSyntax methodDeclaration, SemanticModelProvider semanticModel, IMethodSymbol methodDeclarationSymbol)
|
||||
{
|
||||
// We need to sets to track all discovered custom types and static methods
|
||||
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var (invokeMethod, processedMethods) = GetProcessedMethods(context, methodDeclaration, semanticModel, discoveredTypes, constantDefinitions);
|
||||
var processedTypes = IShaderGenerator.GetProcessedTypes(discoveredTypes).ToArray();
|
||||
var processedConstants = IShaderGenerator.GetProcessedConstants(constantDefinitions);
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
CompilationUnit().AddAttributeLists(
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName(typeof(ShaderMethodSourceAttribute).FullName)).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(methodDeclarationSymbol.GetFullMetadataName(true)))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(invokeMethod))),
|
||||
AttributeArgument(NestedArrayExpression(processedTypes)),
|
||||
AttributeArgument(NestedArrayExpression(processedMethods)),
|
||||
AttributeArgument(NestedArrayExpression(processedConstants)))))
|
||||
.WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList()))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword))))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(methodDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of processed methods from a target method declaration.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> instance for the current method.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the method to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="methodDeclaration"/> (main method and all captured methods).</returns>
|
||||
[Pure]
|
||||
private static (string TargetMethod, IEnumerable<(string Signature, string Definition)> ProcessedMethods) GetProcessedMethods(
|
||||
GeneratorExecutionContext context,
|
||||
MethodDeclarationSyntax methodDeclaration,
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods = new(SymbolEqualityComparer.Default);
|
||||
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(semanticModel, discoveredTypes, staticMethods, constantDefinitions, context);
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var targetMethod = shaderSourceRewriter
|
||||
.Visit(methodDeclaration)!
|
||||
.WithIdentifier(Identifier(ShaderMethodSourceAttribute.InvokeMethodIdentifier))
|
||||
.WithoutTrivia()
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
List<(string, string)> processedMethods = new(shaderSourceRewriter.LocalFunctions.Count);
|
||||
|
||||
// Emit the extracted local functions
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
processedMethods.Add((
|
||||
localFunction.Value.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
localFunction.Value.NormalizeWhitespace(eol: "\n").ToFullString()));
|
||||
}
|
||||
|
||||
// Emit the discovered static methods
|
||||
foreach (var staticMethod in staticMethods.Values)
|
||||
{
|
||||
processedMethods.Add((
|
||||
staticMethod.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
staticMethod.NormalizeWhitespace(eol: "\n").ToFullString()));
|
||||
}
|
||||
|
||||
return (targetMethod, processedMethods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a given target method.
|
||||
/// </summary>
|
||||
/// <param name="context">The input <see cref="GeneratorExecutionContext"/> instance to use.</param>
|
||||
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> node to process.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> with metadata on the types being processed.</param>
|
||||
/// <param name="methodDeclarationSymbol">The <see cref="IMethodSymbol"/> for <paramref name="methodDeclaration"/>.</param>
|
||||
private static void OnExecute(GeneratorExecutionContext context, MethodDeclarationSyntax methodDeclaration, SemanticModelProvider semanticModel, IMethodSymbol methodDeclarationSymbol)
|
||||
{
|
||||
// We need to sets to track all discovered custom types and static methods
|
||||
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var (invokeMethod, processedMethods) = GetProcessedMethods(context, methodDeclaration, semanticModel, discoveredTypes, constantDefinitions);
|
||||
var processedTypes = IShaderGenerator.GetProcessedTypes(discoveredTypes).ToArray();
|
||||
var processedConstants = IShaderGenerator.GetProcessedConstants(constantDefinitions);
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
CompilationUnit().AddAttributeLists(
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName(typeof(ShaderMethodSourceAttribute).FullName)).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(methodDeclarationSymbol.GetFullMetadataName(true)))),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(invokeMethod))),
|
||||
AttributeArgument(NestedArrayExpression(processedTypes)),
|
||||
AttributeArgument(NestedArrayExpression(processedMethods)),
|
||||
AttributeArgument(NestedArrayExpression(processedConstants)))))
|
||||
.WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList()))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword))))
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
// Add the method source attribute
|
||||
context.AddSource(methodDeclarationSymbol.GetGeneratedFileName(), SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of processed methods from a target method declaration.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> instance for the current method.</param>
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the method to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="methodDeclaration"/> (main method and all captured methods).</returns>
|
||||
[Pure]
|
||||
private static (string TargetMethod, IEnumerable<(string Signature, string Definition)> ProcessedMethods) GetProcessedMethods(
|
||||
GeneratorExecutionContext context,
|
||||
MethodDeclarationSyntax methodDeclaration,
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods = new(SymbolEqualityComparer.Default);
|
||||
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(semanticModel, discoveredTypes, staticMethods, constantDefinitions, context);
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var targetMethod = shaderSourceRewriter
|
||||
.Visit(methodDeclaration)!
|
||||
.WithIdentifier(Identifier(ShaderMethodSourceAttribute.InvokeMethodIdentifier))
|
||||
.WithoutTrivia()
|
||||
.NormalizeWhitespace(eol: "\n")
|
||||
.ToFullString();
|
||||
|
||||
List<(string, string)> processedMethods = new(shaderSourceRewriter.LocalFunctions.Count);
|
||||
|
||||
// Emit the extracted local functions
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
processedMethods.Add((
|
||||
localFunction.Value.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
localFunction.Value.NormalizeWhitespace(eol: "\n").ToFullString()));
|
||||
}
|
||||
|
||||
// Emit the discovered static methods
|
||||
foreach (var staticMethod in staticMethods.Values)
|
||||
{
|
||||
processedMethods.Add((
|
||||
staticMethod.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
staticMethod.NormalizeWhitespace(eol: "\n").ToFullString()));
|
||||
}
|
||||
|
||||
return (targetMethod, processedMethods);
|
||||
}
|
||||
}
|
||||
@@ -3,159 +3,90 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that does postprocessing fixups on the shader main method.
|
||||
/// Creates a new <see cref="Compute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <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; }
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public TNode? Visit<TNode>(TNode? node)
|
||||
where TNode : SyntaxNode
|
||||
{
|
||||
return (TNode?)base.Visit(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitParameterList(ParameterListSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")));
|
||||
|
||||
if (ShaderSourceRewriter.IsGroupIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(GroupIds)} : SV_GroupThreadID")));
|
||||
}
|
||||
|
||||
if (ShaderSourceRewriter.IsGroupIdsIndexUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint __{nameof(GroupIds)}__get_Index : SV_GroupIndex")));
|
||||
}
|
||||
|
||||
if (ShaderSourceRewriter.IsGridIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(GridIds)} : SV_GroupID")));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Compute : ExecuteMethodRewriter
|
||||
{
|
||||
/// <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)
|
||||
public Compute(ShaderSourceRewriter shaderSourceRewriter)
|
||||
: base(shaderSourceRewriter)
|
||||
{
|
||||
ShaderSourceRewriter = shaderSourceRewriter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ShaderSourceRewriter"/> instance used to process the input tree.
|
||||
/// </summary>
|
||||
protected ShaderSourceRewriter ShaderSourceRewriter { get; }
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public TNode? Visit<TNode>(TNode? node)
|
||||
where TNode : SyntaxNode
|
||||
{
|
||||
return (TNode?)base.Visit(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitParameterList(ParameterListSyntax node)
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")));
|
||||
|
||||
if (ShaderSourceRewriter.IsGroupIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(GroupIds)} : SV_GroupThreadID")));
|
||||
}
|
||||
|
||||
if (ShaderSourceRewriter.IsGroupIdsIndexUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint __{nameof(GroupIds)}__get_Index : SV_GroupIndex")));
|
||||
}
|
||||
|
||||
if (ShaderSourceRewriter.IsGridIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(GridIds)} : SV_GroupID")));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Compute : ExecuteMethodRewriter
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// When we're rewriting the main compute shader method, we need to insert a range
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
// The following snippet creates this prologue before the user provided body:
|
||||
//
|
||||
// if (ThreadIds.x < __x &&
|
||||
// ThreadIds.y < __y &&
|
||||
// ThreadIds.z < __z)
|
||||
// {
|
||||
// <body>
|
||||
// }
|
||||
BinaryExpressionSyntax rangeCheckExpression =
|
||||
BinaryExpression(SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("x")),
|
||||
IdentifierName("__x")),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("y")),
|
||||
IdentifierName("__y"))),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("z")),
|
||||
IdentifierName("__z")));
|
||||
|
||||
return updatedNode.WithBody(Block(IfStatement(rangeCheckExpression, updatedNode.Body!)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Pixel : ExecuteMethodRewriter
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
var updatedNode = (ReturnStatementSyntax)base.VisitReturnStatement(node)!;
|
||||
|
||||
// __outputTexture[ThreadIds.xy] = <RETURN_EXPRESSION>;
|
||||
return
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("__outputTexture"))
|
||||
.AddArgumentListArguments(
|
||||
Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ThreadIds"),
|
||||
IdentifierName("xy")))),
|
||||
updatedNode.Expression!));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// Change the return type to void
|
||||
updatedNode = updatedNode.WithReturnType(PredefinedType(Token(SyntaxKind.VoidKeyword)));
|
||||
|
||||
// Same as above, but skipping the third check for the Z axis.
|
||||
// This is because pixel shaders only ever run on 2D textures.
|
||||
BinaryExpressionSyntax rangeCheckExpression =
|
||||
// When we're rewriting the main compute shader method, we need to insert a range
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
// The following snippet creates this prologue before the user provided body:
|
||||
//
|
||||
// if (ThreadIds.x < __x &&
|
||||
// ThreadIds.y < __y &&
|
||||
// ThreadIds.z < __z)
|
||||
// {
|
||||
// <body>
|
||||
// }
|
||||
BinaryExpressionSyntax rangeCheckExpression =
|
||||
BinaryExpression(SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
@@ -168,25 +99,93 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("y")),
|
||||
IdentifierName("__y")));
|
||||
IdentifierName("__y"))),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("z")),
|
||||
IdentifierName("__z")));
|
||||
|
||||
return updatedNode.WithBody(Block(IfStatement(rangeCheckExpression, updatedNode.Body!)));
|
||||
}
|
||||
return updatedNode.WithBody(Block(IfStatement(rangeCheckExpression, updatedNode.Body!)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
/// <summary>
|
||||
/// A custom <see cref="ExecuteMethodRewriter"/> type specialized for compute shaders.
|
||||
/// </summary>
|
||||
public sealed class Pixel : ExecuteMethodRewriter
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
var updatedNode = (ReturnStatementSyntax)base.VisitReturnStatement(node)!;
|
||||
|
||||
// __outputTexture[ThreadIds.xy] = <RETURN_EXPRESSION>;
|
||||
return
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("__outputTexture"))
|
||||
.AddArgumentListArguments(
|
||||
Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ThreadIds"),
|
||||
IdentifierName("xy")))),
|
||||
updatedNode.Expression!));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// Change the return type to void
|
||||
updatedNode = updatedNode.WithReturnType(PredefinedType(Token(SyntaxKind.VoidKeyword)));
|
||||
|
||||
// Same as above, but skipping the third check for the Z axis.
|
||||
// This is because pixel shaders only ever run on 2D textures.
|
||||
BinaryExpressionSyntax rangeCheckExpression =
|
||||
BinaryExpression(SyntaxKind.LogicalAndExpression,
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("x")),
|
||||
IdentifierName("__x")),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("y")),
|
||||
IdentifierName("__y")));
|
||||
|
||||
return updatedNode.WithBody(Block(IfStatement(rangeCheckExpression, updatedNode.Body!)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
{
|
||||
IdentifierNameSyntax updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
|
||||
// Since pixel shaders are only ever executed on 2D textures, the special __z field can
|
||||
// be removed and replaced with just numeric literal expressions, where the value is 1.
|
||||
if (updatedNode.Identifier.Text == "__z")
|
||||
{
|
||||
IdentifierNameSyntax updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
|
||||
// Since pixel shaders are only ever executed on 2D textures, the special __z field can
|
||||
// be removed and replaced with just numeric literal expressions, where the value is 1.
|
||||
if (updatedNode.Identifier.Text == "__z")
|
||||
{
|
||||
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
-148
@@ -4,203 +4,202 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
|
||||
|
||||
/// <inheritdoc cref="HlslSourceRewriter"/>
|
||||
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
/// <inheritdoc cref="HlslSourceRewriter"/>
|
||||
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (AnonymousObjectCreationExpressionSyntax)base.VisitAnonymousObjectCreationExpression(node)!;
|
||||
var updatedNode = (AnonymousObjectCreationExpressionSyntax)base.VisitAnonymousObjectCreationExpression(node)!;
|
||||
|
||||
Context.ReportDiagnostic(AnonymousObjectCreationExpression, node);
|
||||
Context.ReportDiagnostic(AnonymousObjectCreationExpression, node);
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitAwaitExpression(AwaitExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(AwaitExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitAwaitExpression(AwaitExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(AwaitExpression, node);
|
||||
|
||||
return base.VisitAwaitExpression(node);
|
||||
}
|
||||
return base.VisitAwaitExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitCheckedExpression(CheckedExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(CheckedExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitCheckedExpression(CheckedExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(CheckedExpression, node);
|
||||
|
||||
return base.VisitCheckedExpression(node);
|
||||
}
|
||||
return base.VisitCheckedExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitCheckedStatement(CheckedStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(CheckedStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitCheckedStatement(CheckedStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(CheckedStatement, node);
|
||||
|
||||
return base.VisitCheckedStatement(node);
|
||||
}
|
||||
return base.VisitCheckedStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitFixedStatement(FixedStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(FixedStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitFixedStatement(FixedStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(FixedStatement, node);
|
||||
|
||||
return base.VisitFixedStatement(node);
|
||||
}
|
||||
return base.VisitFixedStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitForEachStatement(ForEachStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ForEachStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitForEachStatement(ForEachStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ForEachStatement, node);
|
||||
|
||||
return base.VisitForEachStatement(node);
|
||||
}
|
||||
return base.VisitForEachStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitForEachVariableStatement(ForEachVariableStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ForEachStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitForEachVariableStatement(ForEachVariableStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ForEachStatement, node);
|
||||
|
||||
return base.VisitForEachVariableStatement(node);
|
||||
}
|
||||
return base.VisitForEachVariableStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLockStatement(LockStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(LockStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLockStatement(LockStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(LockStatement, node);
|
||||
|
||||
return base.VisitLockStatement(node);
|
||||
}
|
||||
return base.VisitLockStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitQueryExpression(QueryExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(QueryExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitQueryExpression(QueryExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(QueryExpression, node);
|
||||
|
||||
return base.VisitQueryExpression(node);
|
||||
}
|
||||
return base.VisitQueryExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRangeExpression(RangeExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RangeExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRangeExpression(RangeExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RangeExpression, node);
|
||||
|
||||
return base.VisitRangeExpression(node);
|
||||
}
|
||||
return base.VisitRangeExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRecursivePattern(RecursivePatternSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RecursivePattern, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRecursivePattern(RecursivePatternSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RecursivePattern, node);
|
||||
|
||||
return base.VisitRecursivePattern(node);
|
||||
}
|
||||
return base.VisitRecursivePattern(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRefType(RefTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RefType, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRefType(RefTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RefType, node);
|
||||
|
||||
return base.VisitRefType(node);
|
||||
}
|
||||
return base.VisitRefType(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRelationalPattern(RelationalPatternSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RelationalPattern, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitRelationalPattern(RelationalPatternSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(RelationalPattern, node);
|
||||
|
||||
return base.VisitRelationalPattern(node);
|
||||
}
|
||||
return base.VisitRelationalPattern(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitSizeOfExpression(SizeOfExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(SizeOfExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitSizeOfExpression(SizeOfExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(SizeOfExpression, node);
|
||||
|
||||
return base.VisitSizeOfExpression(node);
|
||||
}
|
||||
return base.VisitSizeOfExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitStackAllocArrayCreationExpression(StackAllocArrayCreationExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(StackAllocArrayCreationExpression, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitStackAllocArrayCreationExpression(StackAllocArrayCreationExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(StackAllocArrayCreationExpression, node);
|
||||
|
||||
return base.VisitStackAllocArrayCreationExpression(node);
|
||||
}
|
||||
return base.VisitStackAllocArrayCreationExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitThrowExpression(ThrowExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ThrowExpressionOrStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitThrowExpression(ThrowExpressionSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ThrowExpressionOrStatement, node);
|
||||
|
||||
return base.VisitThrowExpression(node);
|
||||
}
|
||||
return base.VisitThrowExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitThrowStatement(ThrowStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ThrowExpressionOrStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitThrowStatement(ThrowStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(ThrowExpressionOrStatement, node);
|
||||
|
||||
return base.VisitThrowStatement(node);
|
||||
}
|
||||
return base.VisitThrowStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitTryStatement(TryStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(TryStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitTryStatement(TryStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(TryStatement, node);
|
||||
|
||||
return base.VisitTryStatement(node);
|
||||
}
|
||||
return base.VisitTryStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitTupleType(TupleTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(TupleType, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitTupleType(TupleTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(TupleType, node);
|
||||
|
||||
return base.VisitTupleType(node);
|
||||
}
|
||||
return base.VisitTupleType(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitUsingStatement(UsingStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(UsingStatementOrDeclaration, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitUsingStatement(UsingStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(UsingStatementOrDeclaration, node);
|
||||
|
||||
return base.VisitUsingStatement(node);
|
||||
}
|
||||
return base.VisitUsingStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitYieldStatement(YieldStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(YieldStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitYieldStatement(YieldStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(YieldStatement, node);
|
||||
|
||||
return base.VisitYieldStatement(node);
|
||||
}
|
||||
return base.VisitYieldStatement(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitFunctionPointerType(FunctionPointerTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(FunctionPointer, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitFunctionPointerType(FunctionPointerTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(FunctionPointer, node);
|
||||
|
||||
return base.VisitFunctionPointerType(node);
|
||||
}
|
||||
return base.VisitFunctionPointerType(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitPointerType(PointerTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(PointerType, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitPointerType(PointerTypeSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(PointerType, node);
|
||||
|
||||
return base.VisitPointerType(node);
|
||||
}
|
||||
return base.VisitPointerType(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitUnsafeStatement(UnsafeStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(UnsafeStatement, node);
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitUnsafeStatement(UnsafeStatementSyntax node)
|
||||
{
|
||||
Context.ReportDiagnostic(UnsafeStatement, node);
|
||||
|
||||
return base.VisitUnsafeStatement(node);
|
||||
}
|
||||
return base.VisitUnsafeStatement(node);
|
||||
}
|
||||
}
|
||||
@@ -13,330 +13,329 @@ using Microsoft.CodeAnalysis.Operations;
|
||||
using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see cref="CSharpSyntaxRewriter"/> type that processes C# source to convert to HLSL compliant code.
|
||||
/// This class contains only the shared logic for all derived HLSL source rewriters.
|
||||
/// </summary>
|
||||
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// A base <see cref="CSharpSyntaxRewriter"/> type that processes C# source to convert to HLSL compliant code.
|
||||
/// This class contains only the shared logic for all derived HLSL source rewriters.
|
||||
/// The <see cref="SemanticModelProvider"/> instance with semantic info on the target syntax tree.
|
||||
/// </summary>
|
||||
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
protected readonly SemanticModelProvider SemanticModel;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered custom types.
|
||||
/// </summary>
|
||||
protected readonly ICollection<INamedTypeSymbol> DiscoveredTypes;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered constant definitions.
|
||||
/// </summary>
|
||||
protected readonly IDictionary<IFieldSymbol, string> ConstantDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// The current generator context in use.
|
||||
/// </summary>
|
||||
protected readonly GeneratorExecutionContext Context;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="HlslSourceRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> 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="context">The current generator context in use.</param>
|
||||
protected HlslSourceRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="SemanticModelProvider"/> instance with semantic info on the target syntax tree.
|
||||
/// </summary>
|
||||
protected readonly SemanticModelProvider SemanticModel;
|
||||
SemanticModel = semanticModel;
|
||||
DiscoveredTypes = discoveredTypes;
|
||||
ConstantDefinitions = constantDefinitions;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered custom types.
|
||||
/// </summary>
|
||||
protected readonly ICollection<INamedTypeSymbol> DiscoveredTypes;
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses a texture sampler at least once.
|
||||
/// </summary>
|
||||
public bool IsSamplerUsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered constant definitions.
|
||||
/// </summary>
|
||||
protected readonly IDictionary<IFieldSymbol, string> ConstantDefinitions;
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitCastExpression(CastExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (CastExpressionSyntax)base.VisitCastExpression(node)!;
|
||||
|
||||
/// <summary>
|
||||
/// The current generator context in use.
|
||||
/// </summary>
|
||||
protected readonly GeneratorExecutionContext Context;
|
||||
return updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="HlslSourceRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> 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="context">The current generator context in use.</param>
|
||||
protected HlslSourceRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitVariableDeclaration(VariableDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = (VariableDeclarationSyntax)base.VisitVariableDeclaration(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node.Type).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
SemanticModel = semanticModel;
|
||||
DiscoveredTypes = discoveredTypes;
|
||||
ConstantDefinitions = constantDefinitions;
|
||||
Context = context;
|
||||
Context.ReportDiagnostic(InvalidObjectDeclaration, node, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses a texture sampler at least once.
|
||||
/// </summary>
|
||||
public bool IsSamplerUsed { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitCastExpression(CastExpressionSyntax node)
|
||||
// If var is used, replace it with the explicit type
|
||||
if (updatedNode.Type is IdentifierNameSyntax { IsVar: true })
|
||||
{
|
||||
var updatedNode = (CastExpressionSyntax)base.VisitCastExpression(node)!;
|
||||
|
||||
return updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitVariableDeclaration(VariableDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = (VariableDeclarationSyntax)base.VisitVariableDeclaration(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node.Type).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
Context.ReportDiagnostic(InvalidObjectDeclaration, node, type);
|
||||
}
|
||||
|
||||
// If var is used, replace it with the explicit type
|
||||
if (updatedNode.Type is IdentifierNameSyntax { IsVar: true })
|
||||
{
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
Context.ReportDiagnostic(InvalidObjectCreationExpression, node, type);
|
||||
}
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// New objects use the default HLSL cast syntax, eg. (float4)0
|
||||
if (updatedNode.ArgumentList!.Arguments.Count == 0)
|
||||
{
|
||||
return CastExpression(updatedNode.Type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
// Add explicit casts for matrix constructors to help the overload resolution
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType &&
|
||||
HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName()))
|
||||
{
|
||||
for (int i = 0; i < node.ArgumentList!.Arguments.Count; i++)
|
||||
{
|
||||
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i])!;
|
||||
INamedTypeSymbol elementType = (INamedTypeSymbol)argumentOperation.Parameter!.Type;
|
||||
|
||||
updatedNode = updatedNode.ReplaceNode(
|
||||
updatedNode.ArgumentList!.Arguments[i].Expression,
|
||||
CastExpression(IdentifierName(HlslKnownTypes.GetMappedName(elementType)), updatedNode.ArgumentList.Arguments[i].Expression));
|
||||
}
|
||||
}
|
||||
|
||||
return InvocationExpression(updatedNode.Type, updatedNode.ArgumentList!);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ImplicitObjectCreationExpressionSyntax)base.VisitImplicitObjectCreationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
Context.ReportDiagnostic(InvalidObjectCreationExpression, node, type);
|
||||
}
|
||||
|
||||
TypeSyntax explicitType = IdentifierName("").ReplaceAndTrackType(node, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// Mutate the syntax like with explicit object creation expressions
|
||||
if (updatedNode.ArgumentList!.Arguments.Count == 0)
|
||||
{
|
||||
return CastExpression(explicitType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
// Add explicit casts like with the explicit object creation expressions above
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType &&
|
||||
HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName()))
|
||||
{
|
||||
for (int i = 0; i < node.ArgumentList.Arguments.Count; i++)
|
||||
{
|
||||
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i])!;
|
||||
INamedTypeSymbol elementType = (INamedTypeSymbol)argumentOperation.Parameter!.Type;
|
||||
|
||||
updatedNode = updatedNode.ReplaceNode(
|
||||
updatedNode.ArgumentList.Arguments[i].Expression,
|
||||
CastExpression(IdentifierName(HlslKnownTypes.GetMappedName(elementType)), updatedNode.ArgumentList.Arguments[i].Expression));
|
||||
}
|
||||
}
|
||||
|
||||
return InvocationExpression(explicitType, updatedNode.ArgumentList);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitDefaultExpression(DefaultExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (DefaultExpressionSyntax)base.VisitDefaultExpression(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
// A default expression becomes (T)0 in HLSL
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
Context.ReportDiagnostic(InvalidObjectCreationExpression, node, type);
|
||||
}
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// New objects use the default HLSL cast syntax, eg. (float4)0
|
||||
if (updatedNode.ArgumentList!.Arguments.Count == 0)
|
||||
{
|
||||
return CastExpression(updatedNode.Type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLiteralExpression(LiteralExpressionSyntax node)
|
||||
// Add explicit casts for matrix constructors to help the overload resolution
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType &&
|
||||
HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName()))
|
||||
{
|
||||
var updatedNode = (LiteralExpressionSyntax)base.VisitLiteralExpression(node)!;
|
||||
|
||||
if (updatedNode.IsKind(SyntaxKind.DefaultLiteralExpression))
|
||||
for (int i = 0; i < node.ArgumentList!.Arguments.Count; i++)
|
||||
{
|
||||
TypeSyntax type = node.TrackType(SemanticModel.For(node), DiscoveredTypes);
|
||||
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i])!;
|
||||
INamedTypeSymbol elementType = (INamedTypeSymbol)argumentOperation.Parameter!.Type;
|
||||
|
||||
// Same HLSL-style expression in the form (T)0
|
||||
return CastExpression(type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
updatedNode = updatedNode.ReplaceNode(
|
||||
updatedNode.ArgumentList!.Arguments[i].Expression,
|
||||
CastExpression(IdentifierName(HlslKnownTypes.GetMappedName(elementType)), updatedNode.ArgumentList.Arguments[i].Expression));
|
||||
}
|
||||
else if (updatedNode.IsKind(SyntaxKind.NumericLiteralExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is ILiteralOperation operation &&
|
||||
operation.Type is INamedTypeSymbol type)
|
||||
{
|
||||
// If the expression is a literal floating point value, we need to ensure the proper suffixes are
|
||||
// used in the HLSL representation. Floating point values accept either f or F, but they don't work
|
||||
// when the literal doesn't contain a decimal point. Since 32 bit floating point values are the default
|
||||
// in HLSL, we can remove the suffix entirely. As for 64 bit values, we simply use the 'L' suffix.
|
||||
if (type.GetFullMetadataName().Equals(typeof(float).FullName))
|
||||
{
|
||||
string literal = updatedNode.Token.ValueText;
|
||||
|
||||
// If the numeric literal is neither a decimal nor an exponential, add the ".0" suffix
|
||||
if (literal.IndexOfAny(new[] { '.', 'E' }) == -1)
|
||||
{
|
||||
literal += ".0";
|
||||
}
|
||||
|
||||
return updatedNode.WithToken(Literal(literal, 0f));
|
||||
}
|
||||
else if (type.GetFullMetadataName().Equals(typeof(double).FullName))
|
||||
{
|
||||
return updatedNode.WithToken(Literal(updatedNode.Token.ValueText + "L", 0d));
|
||||
}
|
||||
}
|
||||
else if (updatedNode.IsKind(SyntaxKind.StringLiteralExpression))
|
||||
{
|
||||
Context.ReportDiagnostic(StringLiteralExpression, node);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitElementAccessExpression(ElementAccessExpressionSyntax node)
|
||||
return InvocationExpression(updatedNode.Type, updatedNode.ArgumentList!);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ImplicitObjectCreationExpressionSyntax)base.VisitImplicitObjectCreationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol { IsUnmanagedType: false } type)
|
||||
{
|
||||
var updatedNode = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!;
|
||||
Context.ReportDiagnostic(InvalidObjectCreationExpression, node, type);
|
||||
}
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IPropertyReferenceOperation operation)
|
||||
TypeSyntax explicitType = IdentifierName("").ReplaceAndTrackType(node, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// Mutate the syntax like with explicit object creation expressions
|
||||
if (updatedNode.ArgumentList!.Arguments.Count == 0)
|
||||
{
|
||||
return CastExpression(explicitType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
// Add explicit casts like with the explicit object creation expressions above
|
||||
if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType &&
|
||||
HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName()))
|
||||
{
|
||||
for (int i = 0; i < node.ArgumentList.Arguments.Count; i++)
|
||||
{
|
||||
string propertyName = operation.Property.GetFullMetadataName();
|
||||
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i])!;
|
||||
INamedTypeSymbol elementType = (INamedTypeSymbol)argumentOperation.Parameter!.Type;
|
||||
|
||||
// Rewrite texture resource indices taking individual indices a vector argument, as per HLSL spec.
|
||||
// For instance: texture[ThreadIds.X, ThreadIds.Y] will be rewritten as texture[int2(ThreadIds.X, ThreadIds.Y)].
|
||||
if (HlslKnownMembers.TryGetMappedResourceIndexerTypeName(propertyName, out string? mapping))
|
||||
updatedNode = updatedNode.ReplaceNode(
|
||||
updatedNode.ArgumentList.Arguments[i].Expression,
|
||||
CastExpression(IdentifierName(HlslKnownTypes.GetMappedName(elementType)), updatedNode.ArgumentList.Arguments[i].Expression));
|
||||
}
|
||||
}
|
||||
|
||||
return InvocationExpression(explicitType, updatedNode.ArgumentList);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitDefaultExpression(DefaultExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (DefaultExpressionSyntax)base.VisitDefaultExpression(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// A default expression becomes (T)0 in HLSL
|
||||
return CastExpression(updatedNode.Type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLiteralExpression(LiteralExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (LiteralExpressionSyntax)base.VisitLiteralExpression(node)!;
|
||||
|
||||
if (updatedNode.IsKind(SyntaxKind.DefaultLiteralExpression))
|
||||
{
|
||||
TypeSyntax type = node.TrackType(SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// Same HLSL-style expression in the form (T)0
|
||||
return CastExpression(type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
else if (updatedNode.IsKind(SyntaxKind.NumericLiteralExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is ILiteralOperation operation &&
|
||||
operation.Type is INamedTypeSymbol type)
|
||||
{
|
||||
// If the expression is a literal floating point value, we need to ensure the proper suffixes are
|
||||
// used in the HLSL representation. Floating point values accept either f or F, but they don't work
|
||||
// when the literal doesn't contain a decimal point. Since 32 bit floating point values are the default
|
||||
// in HLSL, we can remove the suffix entirely. As for 64 bit values, we simply use the 'L' suffix.
|
||||
if (type.GetFullMetadataName().Equals(typeof(float).FullName))
|
||||
{
|
||||
string literal = updatedNode.Token.ValueText;
|
||||
|
||||
// If the numeric literal is neither a decimal nor an exponential, add the ".0" suffix
|
||||
if (literal.IndexOfAny(new[] { '.', 'E' }) == -1)
|
||||
{
|
||||
var index = InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments));
|
||||
|
||||
return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
|
||||
literal += ".0";
|
||||
}
|
||||
|
||||
// Rewrite texture resource sampled accesses, if needed
|
||||
if (HlslKnownMembers.TryGetMappedResourceSamplerAccessType(propertyName, out mapping))
|
||||
return updatedNode.WithToken(Literal(literal, 0f));
|
||||
}
|
||||
else if (type.GetFullMetadataName().Equals(typeof(double).FullName))
|
||||
{
|
||||
return updatedNode.WithToken(Literal(updatedNode.Token.ValueText + "L", 0d));
|
||||
}
|
||||
}
|
||||
else if (updatedNode.IsKind(SyntaxKind.StringLiteralExpression))
|
||||
{
|
||||
Context.ReportDiagnostic(StringLiteralExpression, node);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitElementAccessExpression(ElementAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IPropertyReferenceOperation operation)
|
||||
{
|
||||
string propertyName = operation.Property.GetFullMetadataName();
|
||||
|
||||
// Rewrite texture resource indices taking individual indices a vector argument, as per HLSL spec.
|
||||
// For instance: texture[ThreadIds.X, ThreadIds.Y] will be rewritten as texture[int2(ThreadIds.X, ThreadIds.Y)].
|
||||
if (HlslKnownMembers.TryGetMappedResourceIndexerTypeName(propertyName, out string? mapping))
|
||||
{
|
||||
var index = InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments));
|
||||
|
||||
return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
|
||||
}
|
||||
|
||||
// Rewrite texture resource sampled accesses, if needed
|
||||
if (HlslKnownMembers.TryGetMappedResourceSamplerAccessType(propertyName, out mapping))
|
||||
{
|
||||
IsSamplerUsed = true;
|
||||
|
||||
// Get the syntax for the argument syntax transformation as described above
|
||||
ArgumentSyntax coordinateSyntax = mapping switch
|
||||
{
|
||||
IsSamplerUsed = true;
|
||||
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
|
||||
null => updatedNode.ArgumentList.Arguments[0]
|
||||
};
|
||||
|
||||
// Get the syntax for the argument syntax transformation as described above
|
||||
ArgumentSyntax coordinateSyntax = mapping switch
|
||||
{
|
||||
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
|
||||
null => updatedNode.ArgumentList.Arguments[0]
|
||||
};
|
||||
|
||||
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture[uv] will be rewritten as texture.SampleLevel(__sampler, uv, 0).
|
||||
return
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
updatedNode.Expression,
|
||||
IdentifierName("SampleLevel")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(IdentifierName("__sampler")),
|
||||
coordinateSyntax,
|
||||
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
|
||||
}
|
||||
|
||||
// If the current property is a swizzled matrix indexer, ensure all the arguments are constants, and rewrite
|
||||
// the property access to the corresponding HLSL syntax. For instance, m[M11, M12] will become m._m00_m01.
|
||||
if (HlslKnownMembers.IsKnownMatrixIndexer(propertyName))
|
||||
{
|
||||
bool isValid = true;
|
||||
|
||||
// Validate the arguments
|
||||
foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
|
||||
{
|
||||
if (SemanticModel.For(node).GetOperation(argument.Expression) is not IFieldReferenceOperation fieldReference ||
|
||||
!HlslKnownMembers.IsKnownMatrixIndex(fieldReference.Field.GetFullMetadataName()))
|
||||
{
|
||||
Context.ReportDiagnostic(NonConstantMatrixSwizzledIndex, argument);
|
||||
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
// Rewrite the indexer as a property access
|
||||
string hlslPropertyName = string.Join("",
|
||||
from argument in node.ArgumentList.Arguments
|
||||
let fieldReference = (IFieldReferenceOperation)SemanticModel.For(node).GetOperation(argument.Expression)!
|
||||
let fieldName = fieldReference.Field.Name
|
||||
let row = (char)(fieldName[1] - 1)
|
||||
let column = (char)(fieldName[2] - 1)
|
||||
select $"_m{row}{column}");
|
||||
|
||||
return MemberAccessExpression(
|
||||
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture[uv] will be rewritten as texture.SampleLevel(__sampler, uv, 0).
|
||||
return
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
updatedNode.Expression,
|
||||
IdentifierName(hlslPropertyName));
|
||||
IdentifierName("SampleLevel")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(IdentifierName("__sampler")),
|
||||
coordinateSyntax,
|
||||
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
|
||||
}
|
||||
|
||||
// If the current property is a swizzled matrix indexer, ensure all the arguments are constants, and rewrite
|
||||
// the property access to the corresponding HLSL syntax. For instance, m[M11, M12] will become m._m00_m01.
|
||||
if (HlslKnownMembers.IsKnownMatrixIndexer(propertyName))
|
||||
{
|
||||
bool isValid = true;
|
||||
|
||||
// Validate the arguments
|
||||
foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
|
||||
{
|
||||
if (SemanticModel.For(node).GetOperation(argument.Expression) is not IFieldReferenceOperation fieldReference ||
|
||||
!HlslKnownMembers.IsKnownMatrixIndex(fieldReference.Field.GetFullMetadataName()))
|
||||
{
|
||||
Context.ReportDiagnostic(NonConstantMatrixSwizzledIndex, argument);
|
||||
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
if (isValid)
|
||||
{
|
||||
// Rewrite the indexer as a property access
|
||||
string hlslPropertyName = string.Join("",
|
||||
from argument in node.ArgumentList.Arguments
|
||||
let fieldReference = (IFieldReferenceOperation)SemanticModel.For(node).GetOperation(argument.Expression)!
|
||||
let fieldName = fieldReference.Field.Name
|
||||
let row = (char)(fieldName[1] - 1)
|
||||
let column = (char)(fieldName[2] - 1)
|
||||
select $"_m{row}{column}");
|
||||
|
||||
return MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
updatedNode.Expression,
|
||||
IdentifierName(hlslPropertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
{
|
||||
var updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation operation &&
|
||||
operation.Field.IsConst &&
|
||||
operation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
var updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
ConstantDefinitions[operation.Field] = ((IFormattable)operation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation operation &&
|
||||
operation.Field.IsConst &&
|
||||
operation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
ConstantDefinitions[operation.Field] = ((IFormattable)operation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
var ownerTypeName = ((INamedTypeSymbol)operation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{operation.Field.Name}";
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)operation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{operation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxToken VisitToken(SyntaxToken token)
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxToken VisitToken(SyntaxToken token)
|
||||
{
|
||||
SyntaxToken updatedToken = base.VisitToken(token);
|
||||
|
||||
// Replace all identifier tokens when needed, to avoid colliding with HLSL keywords
|
||||
if (updatedToken.IsKind(SyntaxKind.IdentifierToken) &&
|
||||
HlslKnownKeywords.TryGetMappedName(updatedToken.Text, out string? mapped))
|
||||
{
|
||||
SyntaxToken updatedToken = base.VisitToken(token);
|
||||
|
||||
// Replace all identifier tokens when needed, to avoid colliding with HLSL keywords
|
||||
if (updatedToken.IsKind(SyntaxKind.IdentifierToken) &&
|
||||
HlslKnownKeywords.TryGetMappedName(updatedToken.Text, out string? mapped))
|
||||
{
|
||||
return ParseToken(mapped!);
|
||||
}
|
||||
|
||||
return updatedToken.WithoutTrivia();
|
||||
return ParseToken(mapped!);
|
||||
}
|
||||
|
||||
return updatedToken.WithoutTrivia();
|
||||
}
|
||||
}
|
||||
@@ -13,432 +13,431 @@ using Microsoft.CodeAnalysis.Operations;
|
||||
using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that processes C# methods to convert to HLSL compliant code.
|
||||
/// </summary>
|
||||
internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that processes C# methods to convert to HLSL compliant code.
|
||||
/// The type symbol for the shader type.
|
||||
/// </summary>
|
||||
internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
private readonly INamedTypeSymbol? shaderType;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered static methods.
|
||||
/// </summary>
|
||||
private readonly IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of processed local functions in the current tree.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, LocalFunctionStatementSyntax> localFunctions;
|
||||
|
||||
/// <summary>
|
||||
/// The list of implicit variables to declare at the start of the body.
|
||||
/// </summary>
|
||||
private readonly List<VariableDeclarationSyntax> implicitVariables;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the current instance is processing a shader entry point.
|
||||
/// </summary>
|
||||
private readonly bool isEntryPoint;
|
||||
|
||||
/// <summary>
|
||||
/// The current <see cref="MethodDeclarationSyntax"/> tree being visited.
|
||||
/// </summary>
|
||||
private MethodDeclarationSyntax? currentMethod;
|
||||
|
||||
/// <summary>
|
||||
/// The current depth inside local declarations.
|
||||
/// </summary>
|
||||
private int localFunctionDepth;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderSourceRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderType">The type symbol for the shader type.</param>
|
||||
/// <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="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="isEntryPoint">Whether or not the current instance is processing a shader entry point.</param>
|
||||
public ShaderSourceRewriter(
|
||||
INamedTypeSymbol shaderType,
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context,
|
||||
bool isEntryPoint)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
{
|
||||
/// <summary>
|
||||
/// The type symbol for the shader type.
|
||||
/// </summary>
|
||||
private readonly INamedTypeSymbol? shaderType;
|
||||
this.shaderType = shaderType;
|
||||
this.staticMethods = staticMethods;
|
||||
this.localFunctions = new();
|
||||
this.implicitVariables = new();
|
||||
this.isEntryPoint = isEntryPoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered static methods.
|
||||
/// </summary>
|
||||
private readonly IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods;
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderSourceRewriter"/> 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="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
public ShaderSourceRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
{
|
||||
this.staticMethods = staticMethods;
|
||||
this.implicitVariables = new();
|
||||
this.localFunctions = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection of processed local functions in the current tree.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, LocalFunctionStatementSyntax> localFunctions;
|
||||
/// <summary>
|
||||
/// Gets the collection of processed local functions in the current tree.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, LocalFunctionStatementSyntax> LocalFunctions => this.localFunctions;
|
||||
|
||||
/// <summary>
|
||||
/// The list of implicit variables to declare at the start of the body.
|
||||
/// </summary>
|
||||
private readonly List<VariableDeclarationSyntax> implicitVariables;
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GroupIds"/> at least once (except <see cref="GroupIds.Index"/>).
|
||||
/// </summary>
|
||||
public bool IsGroupIdsUsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the current instance is processing a shader entry point.
|
||||
/// </summary>
|
||||
private readonly bool isEntryPoint;
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GroupIds.Index/> at least once.
|
||||
/// </summary>
|
||||
public bool IsGroupIdsIndexUsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current <see cref="MethodDeclarationSyntax"/> tree being visited.
|
||||
/// </summary>
|
||||
private MethodDeclarationSyntax? currentMethod;
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GridIds"/> at least once.
|
||||
/// </summary>
|
||||
public bool IsGridIdsUsed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current depth inside local declarations.
|
||||
/// </summary>
|
||||
private int localFunctionDepth;
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public MethodDeclarationSyntax? Visit(MethodDeclarationSyntax? node)
|
||||
{
|
||||
this.currentMethod = node;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderSourceRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderType">The type symbol for the shader type.</param>
|
||||
/// <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="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="isEntryPoint">Whether or not the current instance is processing a shader entry point.</param>
|
||||
public ShaderSourceRewriter(
|
||||
INamedTypeSymbol shaderType,
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context,
|
||||
bool isEntryPoint)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
var updatedNode = (MethodDeclarationSyntax?)base.Visit(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
|
||||
{
|
||||
this.shaderType = shaderType;
|
||||
this.staticMethods = staticMethods;
|
||||
this.localFunctions = new();
|
||||
this.implicitVariables = new();
|
||||
this.isEntryPoint = isEntryPoint;
|
||||
Context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderSourceRewriter"/> 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="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
public ShaderSourceRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
|
||||
{
|
||||
this.staticMethods = staticMethods;
|
||||
this.implicitVariables = new();
|
||||
this.localFunctions = new();
|
||||
Context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of processed local functions in the current tree.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, LocalFunctionStatementSyntax> LocalFunctions => this.localFunctions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GroupIds"/> at least once (except <see cref="GroupIds.Index"/>).
|
||||
/// </summary>
|
||||
public bool IsGroupIdsUsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GroupIds.Index/> at least once.
|
||||
/// </summary>
|
||||
public bool IsGroupIdsIndexUsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses <see cref="GridIds"/> at least once.
|
||||
/// </summary>
|
||||
public bool IsGridIdsUsed { get; set; }
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public MethodDeclarationSyntax? Visit(MethodDeclarationSyntax? node)
|
||||
if (updatedNode is not null)
|
||||
{
|
||||
this.currentMethod = node;
|
||||
var implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray());
|
||||
|
||||
var updatedNode = (MethodDeclarationSyntax?)base.Visit(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
if (updatedNode is not null)
|
||||
{
|
||||
var 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());
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
// Add the tracked implicit declarations (at the start of the body)
|
||||
updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitParameter(ParameterSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterSyntax)base.VisitParameter(node)!;
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
// Convert the C# parameter modifiers to the HLSL equivalent
|
||||
SyntaxToken modifier =
|
||||
node.Modifiers
|
||||
.Where(static m => m.Kind() is SyntaxKind.OutKeyword or SyntaxKind.RefKeyword or SyntaxKind.InKeyword)
|
||||
.Select(static m => m.Kind() switch
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitParameter(ParameterSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterSyntax)base.VisitParameter(node)!;
|
||||
|
||||
// Convert the C# parameter modifiers to the HLSL equivalent
|
||||
SyntaxToken modifier =
|
||||
node.Modifiers
|
||||
.Where(static m => m.Kind() is SyntaxKind.OutKeyword or SyntaxKind.RefKeyword or SyntaxKind.InKeyword)
|
||||
.Select(static m => m.Kind() switch
|
||||
{
|
||||
SyntaxKind.OutKeyword => m,
|
||||
SyntaxKind.InKeyword => m,
|
||||
SyntaxKind.RefKeyword => ParseToken("inout"),
|
||||
_ => Token(SyntaxKind.None)
|
||||
}).FirstOrDefault();
|
||||
|
||||
return updatedNode
|
||||
.WithAttributeLists(default)
|
||||
.ReplaceAndTrackType(updatedNode.Type!, node.Type!, SemanticModel.For(node), DiscoveredTypes)
|
||||
.WithModifiers(TokenList(modifier));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
|
||||
{
|
||||
var updatedNode = ((LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node)!);
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IOperation { Kind: OperationKind.UsingDeclaration })
|
||||
{
|
||||
Context.ReportDiagnostic(UsingStatementOrDeclaration, node);
|
||||
}
|
||||
|
||||
return updatedNode.ReplaceAndTrackType(updatedNode.Declaration.Type, node.Declaration.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitDeclarationExpression(DeclarationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (DeclarationExpressionSyntax)base.VisitDeclarationExpression(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// Add the variable to the list of implicit declarations
|
||||
this.implicitVariables.Add(VariableDeclaration(updatedNode.Type).AddVariables(VariableDeclarator(updatedNode.Designation.ToString())));
|
||||
|
||||
return IdentifierName(updatedNode.Designation.ToString());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
return
|
||||
((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!)
|
||||
.WithBlockBody()
|
||||
.WithoutAccessibilityModifiers()
|
||||
.WithAttributeLists(List<AttributeListSyntax>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLocalFunctionStatement(LocalFunctionStatementSyntax node)
|
||||
{
|
||||
this.localFunctionDepth++;
|
||||
|
||||
var updatedNode =
|
||||
((LocalFunctionStatementSyntax)base.VisitLocalFunctionStatement(node)!)
|
||||
.WithBlockBody()
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithIdentifier(Identifier($"__{this.currentMethod!.Identifier.Text}__{node.Identifier.Text}"));
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
this.localFunctionDepth--;
|
||||
|
||||
// HLSL doesn't support local functions, so we first process them as usual and then remove
|
||||
// them from the current syntax tree completely. These will be added to the shader source
|
||||
// as external static method with a special name to avoid conflicts with other methods.
|
||||
// The name will simply be in the format: "__<MethodName>__<FunctionName>".
|
||||
this.localFunctions.Add(updatedNode.Identifier.Text, updatedNode);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
|
||||
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
// If the current member access is a field or property access, check the lookup table
|
||||
// to see if the member should be rewritten for HLSL compliance, and rewrite if needed.
|
||||
if (HlslKnownMembers.TryGetMappedName(operation.Member.ToDisplayString(), out string? mapping))
|
||||
{
|
||||
// Mark which dispatch properties have been used, to optimize the declaration afterwards
|
||||
if (operation.Member.IsStatic)
|
||||
{
|
||||
SyntaxKind.OutKeyword => m,
|
||||
SyntaxKind.InKeyword => m,
|
||||
SyntaxKind.RefKeyword => ParseToken("inout"),
|
||||
_ => Token(SyntaxKind.None)
|
||||
}).FirstOrDefault();
|
||||
string typeName = operation.Member.ContainingType.GetFullMetadataName();
|
||||
|
||||
return updatedNode
|
||||
.WithAttributeLists(default)
|
||||
.ReplaceAndTrackType(updatedNode.Type!, node.Type!, SemanticModel.For(node), DiscoveredTypes)
|
||||
.WithModifiers(TokenList(modifier));
|
||||
}
|
||||
if (mapping == $"__{nameof(GroupIds)}__get_Index") IsGroupIdsIndexUsed = true;
|
||||
else if (typeName == typeof(GroupIds).FullName) IsGroupIdsUsed = true;
|
||||
else if (typeName == typeof(GridIds).FullName) IsGridIdsUsed = true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
|
||||
{
|
||||
var updatedNode = ((LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node)!);
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IOperation { Kind: OperationKind.UsingDeclaration })
|
||||
{
|
||||
Context.ReportDiagnostic(UsingStatementOrDeclaration, node);
|
||||
}
|
||||
|
||||
return updatedNode.ReplaceAndTrackType(updatedNode.Declaration.Type, node.Declaration.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitDeclarationExpression(DeclarationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (DeclarationExpressionSyntax)base.VisitDeclarationExpression(node)!;
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
// Add the variable to the list of implicit declarations
|
||||
this.implicitVariables.Add(VariableDeclaration(updatedNode.Type).AddVariables(VariableDeclarator(updatedNode.Designation.ToString())));
|
||||
|
||||
return IdentifierName(updatedNode.Designation.ToString());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
return
|
||||
((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!)
|
||||
.WithBlockBody()
|
||||
.WithoutAccessibilityModifiers()
|
||||
.WithAttributeLists(List<AttributeListSyntax>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitLocalFunctionStatement(LocalFunctionStatementSyntax node)
|
||||
{
|
||||
this.localFunctionDepth++;
|
||||
|
||||
var updatedNode =
|
||||
((LocalFunctionStatementSyntax)base.VisitLocalFunctionStatement(node)!)
|
||||
.WithBlockBody()
|
||||
.WithAttributeLists(List<AttributeListSyntax>())
|
||||
.WithIdentifier(Identifier($"__{this.currentMethod!.Identifier.Text}__{node.Identifier.Text}"));
|
||||
|
||||
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
|
||||
|
||||
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword)))
|
||||
{
|
||||
Context.ReportDiagnostic(UnsafeModifierOnMethodOrFunction, node);
|
||||
}
|
||||
|
||||
this.localFunctionDepth--;
|
||||
|
||||
// HLSL doesn't support local functions, so we first process them as usual and then remove
|
||||
// them from the current syntax tree completely. These will be added to the shader source
|
||||
// as external static method with a special name to avoid conflicts with other methods.
|
||||
// The name will simply be in the format: "__<MethodName>__<FunctionName>".
|
||||
this.localFunctions.Add(updatedNode.Identifier.Text, updatedNode);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
|
||||
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
// If the member access is a constant, track it and replace the tree with the processed constant name
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
// If the current member access is a field or property access, check the lookup table
|
||||
// to see if the member should be rewritten for HLSL compliance, and rewrite if needed.
|
||||
if (HlslKnownMembers.TryGetMappedName(operation.Member.ToDisplayString(), out string? mapping))
|
||||
{
|
||||
// Mark which dispatch properties have been used, to optimize the declaration afterwards
|
||||
if (operation.Member.IsStatic)
|
||||
// Check that the dispatch info types are only used from the main shader body
|
||||
if (!this.isEntryPoint || this.localFunctionDepth > 0)
|
||||
{
|
||||
string typeName = operation.Member.ContainingType.GetFullMetadataName();
|
||||
|
||||
if (mapping == $"__{nameof(GroupIds)}__get_Index") IsGroupIdsIndexUsed = true;
|
||||
else if (typeName == typeof(GroupIds).FullName) IsGroupIdsUsed = true;
|
||||
else if (typeName == typeof(GridIds).FullName) IsGridIdsUsed = true;
|
||||
|
||||
// Check that the dispatch info types are only used from the main shader body
|
||||
if (!this.isEntryPoint || this.localFunctionDepth > 0)
|
||||
DiagnosticDescriptor? descriptor = typeName switch
|
||||
{
|
||||
DiagnosticDescriptor? descriptor = typeName switch
|
||||
{
|
||||
_ when typeName == typeof(ThreadIds).FullName || typeName == typeof(ThreadIds.Normalized).FullName => InvalidThreadIdsUsage,
|
||||
_ when typeName == typeof(GroupIds).FullName => InvalidGroupIdsUsage,
|
||||
_ when typeName == typeof(GroupSize).FullName => InvalidGroupSizeUsage,
|
||||
_ when typeName == typeof(GridIds).FullName => InvalidGridIdsUsage,
|
||||
_ when typeName == typeof(DispatchSize).FullName => InvalidDispatchSizeUsage,
|
||||
_ => null
|
||||
};
|
||||
_ when typeName == typeof(ThreadIds).FullName || typeName == typeof(ThreadIds.Normalized).FullName => InvalidThreadIdsUsage,
|
||||
_ when typeName == typeof(GroupIds).FullName => InvalidGroupIdsUsage,
|
||||
_ when typeName == typeof(GroupSize).FullName => InvalidGroupSizeUsage,
|
||||
_ when typeName == typeof(GridIds).FullName => InvalidGridIdsUsage,
|
||||
_ when typeName == typeof(DispatchSize).FullName => InvalidDispatchSizeUsage,
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (descriptor is not null)
|
||||
{
|
||||
Context.ReportDiagnostic(descriptor, node);
|
||||
}
|
||||
if (descriptor is not null)
|
||||
{
|
||||
Context.ReportDiagnostic(descriptor, node);
|
||||
}
|
||||
}
|
||||
|
||||
// Static and instance members are handled differently, with static members being
|
||||
// converted into a literal expression, and instance getting an updated identifier.
|
||||
// For instance, consider these three cases:
|
||||
// - Vector3.One (static) => float3(1.0f, 1.0f, 1.0f)
|
||||
// - ThreadIds.X (custom) => ThreadIds.x
|
||||
// - uint3.X (instance) => [arg].x
|
||||
return operation.Member.IsStatic switch
|
||||
{
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
};
|
||||
}
|
||||
|
||||
// If the current member access is an access to any of the size properties in the available
|
||||
// resource types (either buffer or texture types), then rewrite the subtree to transform the
|
||||
// property access into an invocation of an autogenerated static helper method to get the target
|
||||
// dimension for the buffer in use. The helper method is added to the list of static helpers.
|
||||
if (operation is IPropertyReferenceOperation propertyOperation &&
|
||||
HlslKnownMembers.TryGetAccessorRankAndAxis(propertyOperation.Property.GetFullMetadataName(), out int rank, out int axis))
|
||||
// Static and instance members are handled differently, with static members being
|
||||
// converted into a literal expression, and instance getting an updated identifier.
|
||||
// For instance, consider these three cases:
|
||||
// - Vector3.One (static) => float3(1.0f, 1.0f, 1.0f)
|
||||
// - ThreadIds.X (custom) => ThreadIds.x
|
||||
// - uint3.X (instance) => [arg].x
|
||||
return operation.Member.IsStatic switch
|
||||
{
|
||||
IMethodSymbol key = propertyOperation.Property.GetMethod!;
|
||||
|
||||
if (!this.staticMethods.TryGetValue(key, out MethodDeclarationSyntax? methodSyntax))
|
||||
{
|
||||
INamedTypeSymbol resourceType = (INamedTypeSymbol)SemanticModel.For(node).GetTypeInfo(node.Expression).Type!;
|
||||
string resourceName = HlslKnownTypes.GetMappedName(resourceType);
|
||||
|
||||
// Create a static method to get a specified dimension for a target resource type.
|
||||
// The method will automatically create the necessary number of temporary variables
|
||||
// depending on the rank of the input resource (eg. 2 for Texture2D<T> resources).
|
||||
// For instance, this code will generate the following tree for Texture2D<float>.Width:
|
||||
//
|
||||
// static int __get_Dimension0(Texture2D<float> texture)
|
||||
// {
|
||||
// uint _0, _1;
|
||||
// texture.GetDimensions(_0, _1);
|
||||
//
|
||||
// return _0;
|
||||
// }
|
||||
methodSyntax =
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.IntKeyword)), $"__get_Dimension{axis}")
|
||||
.AddModifiers(Token(SyntaxKind.StaticKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("resource"))
|
||||
.WithType(IdentifierName(resourceName)))
|
||||
.WithBody(Block(
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)))
|
||||
.AddVariables(Enumerable.Range(0, rank).Select(static i => VariableDeclarator(Identifier("_" + i))).ToArray())),
|
||||
ExpressionStatement(
|
||||
InvocationExpression(MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("resource"),
|
||||
IdentifierName("GetDimensions")))
|
||||
.AddArgumentListArguments(Enumerable.Range(0, rank).Select(static i => Argument(IdentifierName("_" + i))).ToArray())),
|
||||
ReturnStatement(IdentifierName("_" + axis))));
|
||||
|
||||
this.staticMethods.Add(key, methodSyntax);
|
||||
}
|
||||
|
||||
return InvocationExpression(IdentifierName(methodSyntax.Identifier)).AddArgumentListArguments(Argument(updatedNode.Expression));
|
||||
}
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
};
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitInvocationExpression(InvocationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
|
||||
operation.TargetMethod is IMethodSymbol method &&
|
||||
method.IsStatic)
|
||||
// If the current member access is an access to any of the size properties in the available
|
||||
// resource types (either buffer or texture types), then rewrite the subtree to transform the
|
||||
// property access into an invocation of an autogenerated static helper method to get the target
|
||||
// dimension for the buffer in use. The helper method is added to the list of static helpers.
|
||||
if (operation is IPropertyReferenceOperation propertyOperation &&
|
||||
HlslKnownMembers.TryGetAccessorRankAndAxis(propertyOperation.Property.GetFullMetadataName(), out int rank, out int axis))
|
||||
{
|
||||
// If the invocation consists of invoking a static method that has a direct
|
||||
// mapping to HLSL, rewrite the expression in the current invocation node.
|
||||
// For instance: Math.Abs(expr) => abs(expr).
|
||||
if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping))
|
||||
IMethodSymbol key = propertyOperation.Property.GetMethod!;
|
||||
|
||||
if (!this.staticMethods.TryGetValue(key, out MethodDeclarationSyntax? methodSyntax))
|
||||
{
|
||||
return updatedNode.WithExpression(ParseExpression(mapping!));
|
||||
INamedTypeSymbol resourceType = (INamedTypeSymbol)SemanticModel.For(node).GetTypeInfo(node.Expression).Type!;
|
||||
string resourceName = HlslKnownTypes.GetMappedName(resourceType);
|
||||
|
||||
// Create a static method to get a specified dimension for a target resource type.
|
||||
// The method will automatically create the necessary number of temporary variables
|
||||
// depending on the rank of the input resource (eg. 2 for Texture2D<T> resources).
|
||||
// For instance, this code will generate the following tree for Texture2D<float>.Width:
|
||||
//
|
||||
// static int __get_Dimension0(Texture2D<float> texture)
|
||||
// {
|
||||
// uint _0, _1;
|
||||
// texture.GetDimensions(_0, _1);
|
||||
//
|
||||
// return _0;
|
||||
// }
|
||||
methodSyntax =
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.IntKeyword)), $"__get_Dimension{axis}")
|
||||
.AddModifiers(Token(SyntaxKind.StaticKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("resource"))
|
||||
.WithType(IdentifierName(resourceName)))
|
||||
.WithBody(Block(
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)))
|
||||
.AddVariables(Enumerable.Range(0, rank).Select(static i => VariableDeclarator(Identifier("_" + i))).ToArray())),
|
||||
ExpressionStatement(
|
||||
InvocationExpression(MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("resource"),
|
||||
IdentifierName("GetDimensions")))
|
||||
.AddArgumentListArguments(Enumerable.Range(0, rank).Select(static i => Argument(IdentifierName("_" + i))).ToArray())),
|
||||
ReturnStatement(IdentifierName("_" + axis))));
|
||||
|
||||
this.staticMethods.Add(key, methodSyntax);
|
||||
}
|
||||
|
||||
// Update the name if the target is a local function. The exact schema for the
|
||||
// updated name is detailed in the override handling the local function statement.
|
||||
if (method.MethodKind == MethodKind.LocalFunction)
|
||||
{
|
||||
var functionIdentifier = $"__{this.currentMethod!.Identifier.Text}__{method.Name}";
|
||||
|
||||
return updatedNode.WithExpression(ParseExpression(functionIdentifier));
|
||||
}
|
||||
|
||||
// If the method is an external static method, import and rewrite it as well.
|
||||
// This assumes that the target method is actually part of the same compilation.
|
||||
// We need to check the declaring type to avoid rewriting static methods in the shader
|
||||
// type as well, as they will be processed by the generator in a different path.
|
||||
if (!SymbolEqualityComparer.Default.Equals(this.shaderType, method.ContainingType))
|
||||
{
|
||||
var methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName();
|
||||
|
||||
if (!this.staticMethods.ContainsKey(method))
|
||||
{
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Context);
|
||||
MethodDeclarationSyntax
|
||||
methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(),
|
||||
processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia();
|
||||
|
||||
this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier)));
|
||||
}
|
||||
|
||||
return updatedNode.WithExpression(ParseExpression(methodIdentifier));
|
||||
}
|
||||
return InvocationExpression(IdentifierName(methodSyntax.Identifier)).AddArgumentListArguments(Argument(updatedNode.Expression));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitInvocationExpression(InvocationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
|
||||
operation.TargetMethod is IMethodSymbol method &&
|
||||
method.IsStatic)
|
||||
{
|
||||
var updatedNode = (ArgumentSyntax)base.VisitArgument(node)!;
|
||||
|
||||
// Strip the ref keywords from arguments
|
||||
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
|
||||
|
||||
// Track and rewrite the discarded declaration
|
||||
if (SemanticModel.For(node).GetOperation(node.Expression) is IDiscardOperation operation)
|
||||
// If the invocation consists of invoking a static method that has a direct
|
||||
// mapping to HLSL, rewrite the expression in the current invocation node.
|
||||
// For instance: Math.Abs(expr) => abs(expr).
|
||||
if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping))
|
||||
{
|
||||
TypeSyntax typeSyntax = operation.Type!.TrackType(DiscoveredTypes);
|
||||
string identifier = $"__implicit{this.implicitVariables.Count}";
|
||||
|
||||
// Add the variable to the list of implicit declarations
|
||||
this.implicitVariables.Add(VariableDeclaration(typeSyntax).AddVariables(VariableDeclarator(identifier)));
|
||||
|
||||
return updatedNode.WithExpression(IdentifierName(identifier));
|
||||
return updatedNode.WithExpression(ParseExpression(mapping!));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
// Update the name if the target is a local function. The exact schema for the
|
||||
// updated name is detailed in the override handling the local function statement.
|
||||
if (method.MethodKind == MethodKind.LocalFunction)
|
||||
{
|
||||
var functionIdentifier = $"__{this.currentMethod!.Identifier.Text}__{method.Name}";
|
||||
|
||||
return updatedNode.WithExpression(ParseExpression(functionIdentifier));
|
||||
}
|
||||
|
||||
// If the method is an external static method, import and rewrite it as well.
|
||||
// This assumes that the target method is actually part of the same compilation.
|
||||
// We need to check the declaring type to avoid rewriting static methods in the shader
|
||||
// type as well, as they will be processed by the generator in a different path.
|
||||
if (!SymbolEqualityComparer.Default.Equals(this.shaderType, method.ContainingType))
|
||||
{
|
||||
var methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName();
|
||||
|
||||
if (!this.staticMethods.ContainsKey(method))
|
||||
{
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Context);
|
||||
MethodDeclarationSyntax
|
||||
methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(),
|
||||
processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia();
|
||||
|
||||
this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier)));
|
||||
}
|
||||
|
||||
return updatedNode.WithExpression(ParseExpression(methodIdentifier));
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
|
||||
{
|
||||
var updatedNode = (ArgumentSyntax)base.VisitArgument(node)!;
|
||||
|
||||
// Strip the ref keywords from arguments
|
||||
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
|
||||
|
||||
// Track and rewrite the discarded declaration
|
||||
if (SemanticModel.For(node).GetOperation(node.Expression) is IDiscardOperation operation)
|
||||
{
|
||||
TypeSyntax typeSyntax = operation.Type!.TrackType(DiscoveredTypes);
|
||||
string identifier = $"__implicit{this.implicitVariables.Count}";
|
||||
|
||||
// Add the variable to the list of implicit declarations
|
||||
this.implicitVariables.Add(VariableDeclaration(typeSyntax).AddVariables(VariableDeclarator(identifier)));
|
||||
|
||||
return updatedNode.WithExpression(IdentifierName(identifier));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
}
|
||||
@@ -12,123 +12,122 @@ using Microsoft.CodeAnalysis.Operations;
|
||||
using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that processes C# static field to convert to HLSL static fields (possibly constant).
|
||||
/// </summary>
|
||||
internal sealed class StaticFieldRewriter : HlslSourceRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="CSharpSyntaxRewriter"/> type that processes C# static field to convert to HLSL static fields (possibly constant).
|
||||
/// Creates a new <see cref="StaticFieldRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
internal sealed 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="context">The current generator context in use.</param>
|
||||
public StaticFieldRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
{
|
||||
/// <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="context">The current generator context in use.</param>
|
||||
public StaticFieldRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
GeneratorExecutionContext context)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, context)
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public ExpressionSyntax? Visit(VariableDeclaratorSyntax? node)
|
||||
{
|
||||
if (node?.Initializer is EqualsValueClauseSyntax fieldInitializer)
|
||||
{
|
||||
return ((EqualsValueClauseSyntax)Visit(fieldInitializer))!.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public ExpressionSyntax? Visit(VariableDeclaratorSyntax? node)
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
|
||||
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
if (node?.Initializer is EqualsValueClauseSyntax fieldInitializer)
|
||||
// Track and replace constants
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
{
|
||||
return ((EqualsValueClauseSyntax)Visit(fieldInitializer))!.Value;
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
|
||||
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
|
||||
if (HlslKnownMembers.TryGetMappedName(operation.Member.ToDisplayString(), out string? mapping))
|
||||
{
|
||||
// Track and replace constants
|
||||
if (operation is IFieldReferenceOperation fieldOperation &&
|
||||
fieldOperation.Field.IsConst &&
|
||||
fieldOperation.Type!.TypeKind != TypeKind.Enum)
|
||||
if (operation.Member.IsStatic)
|
||||
{
|
||||
ConstantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
string typeName = operation.Member.ContainingType.GetFullMetadataName();
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{fieldOperation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
if (HlslKnownMembers.TryGetMappedName(operation.Member.ToDisplayString(), out string? mapping))
|
||||
{
|
||||
if (operation.Member.IsStatic)
|
||||
// Special dispatch types are not supported from static constants
|
||||
DiagnosticDescriptor? descriptor = typeName switch
|
||||
{
|
||||
string typeName = operation.Member.ContainingType.GetFullMetadataName();
|
||||
|
||||
// Special dispatch types are not supported from static constants
|
||||
DiagnosticDescriptor? descriptor = typeName switch
|
||||
{
|
||||
_ when typeName == typeof(ThreadIds).FullName || typeName == typeof(ThreadIds.Normalized).FullName => InvalidThreadIdsUsage,
|
||||
_ when typeName == typeof(GroupIds).FullName => InvalidGroupIdsUsage,
|
||||
_ when typeName == typeof(GroupSize).FullName => InvalidGroupSizeUsage,
|
||||
_ when typeName == typeof(GridIds).FullName => InvalidGridIdsUsage,
|
||||
_ when typeName == typeof(DispatchSize).FullName => InvalidDispatchSizeUsage,
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (descriptor is not null)
|
||||
{
|
||||
Context.ReportDiagnostic(descriptor, node);
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite static and instance mapped members
|
||||
return operation.Member.IsStatic switch
|
||||
{
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
_ when typeName == typeof(ThreadIds).FullName || typeName == typeof(ThreadIds.Normalized).FullName => InvalidThreadIdsUsage,
|
||||
_ when typeName == typeof(GroupIds).FullName => InvalidGroupIdsUsage,
|
||||
_ when typeName == typeof(GroupSize).FullName => InvalidGroupSizeUsage,
|
||||
_ when typeName == typeof(GridIds).FullName => InvalidGridIdsUsage,
|
||||
_ when typeName == typeof(DispatchSize).FullName => InvalidDispatchSizeUsage,
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (descriptor is not null)
|
||||
{
|
||||
Context.ReportDiagnostic(descriptor, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitInvocationExpression(InvocationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
|
||||
operation.TargetMethod is IMethodSymbol method &&
|
||||
method.IsStatic)
|
||||
{
|
||||
// Rewrite HLSL intrinsic methods
|
||||
if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping))
|
||||
// Rewrite static and instance mapped members
|
||||
return operation.Member.IsStatic switch
|
||||
{
|
||||
return updatedNode.WithExpression(ParseExpression(mapping!));
|
||||
}
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
};
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitInvocationExpression(InvocationExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
|
||||
|
||||
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
|
||||
operation.TargetMethod is IMethodSymbol method &&
|
||||
method.IsStatic)
|
||||
{
|
||||
var updatedNode = (ArgumentSyntax)base.VisitArgument(node)!;
|
||||
|
||||
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
|
||||
|
||||
return updatedNode;
|
||||
// Rewrite HLSL intrinsic methods
|
||||
if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping))
|
||||
{
|
||||
return updatedNode.WithExpression(ParseExpression(mapping!));
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
|
||||
{
|
||||
var updatedNode = (ArgumentSyntax)base.VisitArgument(node)!;
|
||||
|
||||
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,13 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
namespace System.Runtime.CompilerServices;
|
||||
|
||||
/// <summary>
|
||||
/// Reserved to be used by the compiler for tracking metadata.
|
||||
/// This class should not be used by developers in source code.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class IsExternalInit
|
||||
{
|
||||
/// <summary>
|
||||
/// Reserved to be used by the compiler for tracking metadata.
|
||||
/// This class should not be used by developers in source code.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal static class IsExternalInit
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a target shader type should get an automatic constructor for all fields.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class AutoConstructorAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a target shader type should get an automatic constructor for all fields.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class AutoConstructorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,45 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that indicates that an array static field in a shader type will be shared in a thread group.
|
||||
/// <para>
|
||||
/// This attribute can be used to declare fields as follows:
|
||||
/// <code>
|
||||
/// struct MyShader : IComputeShader
|
||||
/// {
|
||||
/// [GroupShared(32)]
|
||||
/// static float[] MyBuffer;
|
||||
/// }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// The buffer shouldn't be manually initialized, as each shader invocation will automatically receive the
|
||||
/// right buffer in use for the thread group it belongs to. If there is an assignment for the field, it
|
||||
/// will just be ignored in the shader. Additionally, buffer types are not allowed as array items.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
|
||||
public sealed class GroupSharedAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that indicates that an array static field in a shader type will be shared in a thread group.
|
||||
/// <para>
|
||||
/// This attribute can be used to declare fields as follows:
|
||||
/// <code>
|
||||
/// struct MyShader : IComputeShader
|
||||
/// {
|
||||
/// [GroupShared(32)]
|
||||
/// static float[] MyBuffer;
|
||||
/// }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// The buffer shouldn't be manually initialized, as each shader invocation will automatically receive the
|
||||
/// right buffer in use for the thread group it belongs to. If there is an assignment for the field, it
|
||||
/// will just be ignored in the shader. Additionally, buffer types are not allowed as array items.
|
||||
/// Creates a new <see cref="GroupSharedAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
|
||||
public sealed class GroupSharedAttribute : Attribute
|
||||
public GroupSharedAttribute()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GroupSharedAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
public GroupSharedAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GroupSharedAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the shared buffer to declare.</param>
|
||||
public GroupSharedAttribute(int size)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the shared buffer being declared.
|
||||
/// If <see langword="null"/>, the thread group size will be used.
|
||||
/// </summary>
|
||||
public int? Size { get; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GroupSharedAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the shared buffer to declare.</param>
|
||||
public GroupSharedAttribute(int size)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the shared buffer being declared.
|
||||
/// If <see langword="null"/>, the thread group size will be used.
|
||||
/// </summary>
|
||||
public int? Size { get; }
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a method will be indirectly used in a compute shader.
|
||||
/// This method is necessary for methods that are captured and used within a given shader
|
||||
/// through a <see cref="Delegate"/> field (of some custom type). In order to be processed
|
||||
/// correctly, wrapped methods need to have this attribute manually applied to them.
|
||||
/// Methods also need to be static, though this can only be tested at runtime.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class ShaderMethodAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a method will be indirectly used in a compute shader.
|
||||
/// This method is necessary for methods that are captured and used within a given shader
|
||||
/// through a <see cref="Delegate"/> field (of some custom type). In order to be processed
|
||||
/// correctly, wrapped methods need to have this attribute manually applied to them.
|
||||
/// Methods also need to be static, though this can only be tested at runtime.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class ShaderMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
-83
@@ -1,93 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class ShaderMethodSourceAttribute : Attribute
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public sealed partial class ShaderMethodSourceAttribute : Attribute
|
||||
/// <summary>
|
||||
/// Appends the mapped source code for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered constant names.</param>
|
||||
public void AppendConstants(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
/// <summary>
|
||||
/// Appends the mapped source code for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered constant names.</param>
|
||||
public void AppendConstants(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
foreach (KeyValuePair<string, string> constant in this.constants)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> constant in this.constants)
|
||||
if (mapping.Add(constant.Key))
|
||||
{
|
||||
if (mapping.Add(constant.Key))
|
||||
{
|
||||
builder.Append("#define ");
|
||||
builder.Append(constant.Key);
|
||||
builder.Append(' ');
|
||||
builder.Append(constant.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
builder.Append("#define ");
|
||||
builder.Append(constant.Key);
|
||||
builder.Append(' ');
|
||||
builder.Append(constant.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered types for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendTypes(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> type in this.types)
|
||||
{
|
||||
if (mapping.Add(type.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(type.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered forward declarations for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendForwardDeclarations(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> method in this.methods)
|
||||
{
|
||||
if (mapping.Add(method.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(method.Key);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered methods for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendMethods(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> method in this.methods)
|
||||
{
|
||||
if (mapping.Remove(method.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(method.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the mapped source code for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="name">The name to bind the method to.</param>
|
||||
public void AppendMappedInvokeMethod(ref ArrayPoolStringBuilder builder, string name)
|
||||
{
|
||||
builder.Append(this.invokeMethod.Replace(InvokeMethodIdentifier, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered types for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendTypes(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> type in this.types)
|
||||
{
|
||||
if (mapping.Add(type.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(type.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered forward declarations for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendForwardDeclarations(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> method in this.methods)
|
||||
{
|
||||
if (mapping.Add(method.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(method.Key);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the discovered methods for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="mapping">The mapping of already discovered type names.</param>
|
||||
public void AppendMethods(ref ArrayPoolStringBuilder builder, HashSet<string> mapping)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> method in this.methods)
|
||||
{
|
||||
if (mapping.Remove(method.Key))
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(method.Value);
|
||||
builder.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the mapped source code for the current method.
|
||||
/// </summary>
|
||||
/// <param name="builder">The target <see cref="ArrayPoolStringBuilder"/> instance to write to.</param>
|
||||
/// <param name="name">The name to bind the method to.</param>
|
||||
public void AppendMappedInvokeMethod(ref ArrayPoolStringBuilder builder, string name)
|
||||
{
|
||||
builder.Append(this.invokeMethod.Replace(InvokeMethodIdentifier, name));
|
||||
}
|
||||
}
|
||||
@@ -6,109 +6,108 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute that contains info on a processed shader method that can be executed within a shader.
|
||||
/// Instances of this attribute are generated from method annotated with <see cref="ShaderMethodAttribute"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This attribute is not meant to be directly used by applications using ComputeSharp.</remarks>
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This attribute is not intended to be used directly by user code")]
|
||||
public sealed partial class ShaderMethodSourceAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that contains info on a processed shader method that can be executed within a shader.
|
||||
/// Instances of this attribute are generated from method annotated with <see cref="ShaderMethodAttribute"/>.
|
||||
/// The identifier for the invoke method, for late binding.
|
||||
/// </summary>
|
||||
/// <remarks>This attribute is not meant to be directly used by applications using ComputeSharp.</remarks>
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This attribute is not intended to be used directly by user code")]
|
||||
public sealed partial class ShaderMethodSourceAttribute : Attribute
|
||||
internal const string InvokeMethodIdentifier = "__<NAME>__";
|
||||
|
||||
/// <summary>
|
||||
/// The fully qualified name of the current method.
|
||||
/// </summary>
|
||||
private readonly string methodName;
|
||||
|
||||
/// <summary>
|
||||
/// The source code for the target entry point method.
|
||||
/// </summary>
|
||||
private readonly string invokeMethod;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of custom types.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> types;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of processed methods.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> methods;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered constants.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> constants;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderMethodSourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="methodName">The fully qualified name of the current method.</param>
|
||||
/// <param name="invokeMethod">The source code for the target entry point method.</param>
|
||||
/// <param name="types">The collection of custom types.</param>
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
/// <param name="constants">The collection of discovered constants.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string invokeMethod, object[] types, object[] methods, object[] constants)
|
||||
{
|
||||
/// <summary>
|
||||
/// The identifier for the invoke method, for late binding.
|
||||
/// </summary>
|
||||
internal const string InvokeMethodIdentifier = "__<NAME>__";
|
||||
|
||||
/// <summary>
|
||||
/// The fully qualified name of the current method.
|
||||
/// </summary>
|
||||
private readonly string methodName;
|
||||
|
||||
/// <summary>
|
||||
/// The source code for the target entry point method.
|
||||
/// </summary>
|
||||
private readonly string invokeMethod;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of custom types.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> types;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of processed methods.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> methods;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered constants.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> constants;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderMethodSourceAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="methodName">The fully qualified name of the current method.</param>
|
||||
/// <param name="invokeMethod">The source code for the target entry point method.</param>
|
||||
/// <param name="types">The collection of custom types.</param>
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
/// <param name="constants">The collection of discovered constants.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string invokeMethod, object[] types, object[] methods, object[] constants)
|
||||
{
|
||||
this.methodName = methodName;
|
||||
this.invokeMethod = invokeMethod;
|
||||
this.types = types.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
this.methods = methods.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
this.constants = constants.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified delegate.
|
||||
/// </summary>
|
||||
/// <param name="function">The input <see cref="Delegate"/> instance to get info for.</param>
|
||||
/// <param name="name">The name of the shader field containing <paramref name="function"/>.</param>
|
||||
/// <returns>The associated <see cref="ShaderMethodSourceAttribute"/> instance for the given delegate.</returns>
|
||||
[Pure]
|
||||
public static ShaderMethodSourceAttribute GetForDelegate(Delegate function, string name)
|
||||
{
|
||||
if (!function.Method.IsStatic)
|
||||
{
|
||||
return ThrowArgumentExceptionForNonStaticMethod(name);
|
||||
}
|
||||
|
||||
var attributes = function.Method.DeclaringType!.Assembly.GetCustomAttributes<ShaderMethodSourceAttribute>();
|
||||
string methodName = function.Method.GetFullName();
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.methodName.Equals(methodName))
|
||||
{
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return ThrowArgumentExceptionForMissingShaderMethodAttribute(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when a given <see cref="Delegate"/> is not static.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader field containing the invalid method.</param>
|
||||
private static ShaderMethodSourceAttribute ThrowArgumentExceptionForNonStaticMethod(string name)
|
||||
{
|
||||
throw new ArgumentException($"The captured delegate \"{name}\" was wrapping a non static method (only static methods are supported for captured delegates).", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when a given <see cref="Delegate"/> doesn't have <see cref="ShaderMethodAttribute"/> applied to it.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader field containing the invalid method.</param>
|
||||
private static ShaderMethodSourceAttribute ThrowArgumentExceptionForMissingShaderMethodAttribute(string name)
|
||||
{
|
||||
throw new ArgumentException($"The captured delegate \"{name}\" was wrapping a method without the [ShaderMethod] attribute applied to it.", name);
|
||||
}
|
||||
this.methodName = methodName;
|
||||
this.invokeMethod = invokeMethod;
|
||||
this.types = types.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
this.methods = methods.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
this.constants = constants.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified delegate.
|
||||
/// </summary>
|
||||
/// <param name="function">The input <see cref="Delegate"/> instance to get info for.</param>
|
||||
/// <param name="name">The name of the shader field containing <paramref name="function"/>.</param>
|
||||
/// <returns>The associated <see cref="ShaderMethodSourceAttribute"/> instance for the given delegate.</returns>
|
||||
[Pure]
|
||||
public static ShaderMethodSourceAttribute GetForDelegate(Delegate function, string name)
|
||||
{
|
||||
if (!function.Method.IsStatic)
|
||||
{
|
||||
return ThrowArgumentExceptionForNonStaticMethod(name);
|
||||
}
|
||||
|
||||
var attributes = function.Method.DeclaringType!.Assembly.GetCustomAttributes<ShaderMethodSourceAttribute>();
|
||||
string methodName = function.Method.GetFullName();
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.methodName.Equals(methodName))
|
||||
{
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return ThrowArgumentExceptionForMissingShaderMethodAttribute(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when a given <see cref="Delegate"/> is not static.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader field containing the invalid method.</param>
|
||||
private static ShaderMethodSourceAttribute ThrowArgumentExceptionForNonStaticMethod(string name)
|
||||
{
|
||||
throw new ArgumentException($"The captured delegate \"{name}\" was wrapping a non static method (only static methods are supported for captured delegates).", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> when a given <see cref="Delegate"/> doesn't have <see cref="ShaderMethodAttribute"/> applied to it.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader field containing the invalid method.</param>
|
||||
private static ShaderMethodSourceAttribute ThrowArgumentExceptionForMissingShaderMethodAttribute(string name)
|
||||
{
|
||||
throw new ArgumentException($"The captured delegate \"{name}\" was wrapping a method without the [ShaderMethod] attribute applied to it.", name);
|
||||
}
|
||||
}
|
||||
@@ -1,211 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the size of the current shader dispatch being executed.
|
||||
/// That is, it enables a shader to access info on the targeted number of invocations along each axis.
|
||||
/// </summary>
|
||||
public static class DispatchSize
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the size of the current shader dispatch being executed.
|
||||
/// That is, it enables a shader to access info on the targeted number of invocations along each axis.
|
||||
/// Gets the total number of dispatch invocations being executed.
|
||||
/// </summary>
|
||||
public static class DispatchSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the total number of dispatch invocations being executed.
|
||||
/// </summary>
|
||||
public static int Count => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Count)}");
|
||||
public static int Count => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Count)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the X axis.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(X)}");
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the X axis.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the Y axis.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the Y axis.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the Z axis.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the number of dispatch invocations being executed on the Z axis.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(DispatchSize)}.{nameof(ZZZ)}");
|
||||
}
|
||||
@@ -1,206 +1,205 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of the current thread group within the dispatch grid.
|
||||
/// That is, it enables a shader to access info on the index of the current thread group with respect to the dispatch grid.
|
||||
/// </summary>
|
||||
public static class GridIds
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of the current thread group within the dispatch grid.
|
||||
/// That is, it enables a shader to access info on the index of the current thread group with respect to the dispatch grid.
|
||||
/// Gets the X id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static class GridIds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(X)}");
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GridIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
@@ -1,211 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader within a dispatch group.
|
||||
/// That is, it enables a shader to access info on the index of the current thread with respect to the currently running group.
|
||||
/// </summary>
|
||||
public static class GroupIds
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader within a dispatch group.
|
||||
/// That is, it enables a shader to access info on the index of the current thread with respect to the currently running group.
|
||||
/// Gets the flattened index of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static class GroupIds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the flattened index of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Index => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Index)}");
|
||||
public static int Index => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Index)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(X)}");
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GroupIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
@@ -1,211 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the size info of a given GPU thread group running a compute shader.
|
||||
/// That is, it enables a shader to access info on the size of the thread groups being used.
|
||||
/// </summary>
|
||||
public static class GroupSize
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the size info of a given GPU thread group running a compute shader.
|
||||
/// That is, it enables a shader to access info on the size of the thread groups being used.
|
||||
/// Gets the total size of the current thread group.
|
||||
/// </summary>
|
||||
public static class GroupSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the total size of the current thread group.
|
||||
/// </summary>
|
||||
public static int Count => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Count)}");
|
||||
public static int Count => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Count)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the X axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(X)}");
|
||||
/// <summary>
|
||||
/// Gets the size of the X axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the Y axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the size of the Y axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the Z axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the size of the Z axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(GroupSize)}.{nameof(ZZZ)}");
|
||||
}
|
||||
@@ -1,211 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <inheritdoc cref="ThreadIds"/>
|
||||
public static partial class ThreadIds
|
||||
{
|
||||
/// <inheritdoc cref="ThreadIds"/>
|
||||
public static partial class ThreadIds
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the normalized ids of a given GPU thread running a compute shader.
|
||||
/// These ids represent equivalent info to those from <see cref="ThreadIds"/>, but normalized in the [0, 1] range.
|
||||
/// The range used for the normalization is the one given by the target dispatch size (see <see cref="DispatchSize"/>).
|
||||
/// </summary>
|
||||
public static class Normalized
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the normalized ids of a given GPU thread running a compute shader.
|
||||
/// These ids represent equivalent info to those from <see cref="ThreadIds"/>, but normalized in the [0, 1] range.
|
||||
/// The range used for the normalization is the one given by the target dispatch size (see <see cref="DispatchSize"/>).
|
||||
/// Gets the normalized X id of the current thread.
|
||||
/// </summary>
|
||||
public static class Normalized
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the normalized X id of the current thread.
|
||||
/// </summary>
|
||||
public static float X => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(X)}");
|
||||
public static float X => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the normalized Y id of the current thread.
|
||||
/// </summary>
|
||||
public static float Y => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the normalized Y id of the current thread.
|
||||
/// </summary>
|
||||
public static float Y => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the normalized Z id of the current thread.
|
||||
/// </summary>
|
||||
public static float Z => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the normalized Z id of the current thread.
|
||||
/// </summary>
|
||||
public static float Z => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 XX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 XX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 XY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 XY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 XZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 XZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 YX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 YX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 YY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 YY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 YZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 YZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float2 ZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 XZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 YZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZXZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZYZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZX => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZY => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Float3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Float3 ZZZ => throw new InvalidExecutionContextException($"{typeof(Normalized)}.{nameof(ZZZ)}");
|
||||
}
|
||||
}
|
||||
@@ -1,206 +1,205 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader.
|
||||
/// That is, it enables a shader to access info on the current iteration index along each axis.
|
||||
/// </summary>
|
||||
public static partial class ThreadIds
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader.
|
||||
/// That is, it enables a shader to access info on the current iteration index along each axis.
|
||||
/// Gets the X id of the current thread.
|
||||
/// </summary>
|
||||
public static partial class ThreadIds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(X)}");
|
||||
public static int X => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(Y)}");
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(Z)}");
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the components <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="X"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Y"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="X"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYZ)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Y"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZX)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZY)}");
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the components <see cref="Z"/>, <see cref="Z"/>, <see cref="Z"/>.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{typeof(ThreadIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
namespace ComputeSharp.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="InvalidOperationException"/> that indicates when an HLSL-only API is called from C#
|
||||
/// </summary>
|
||||
public sealed class InvalidExecutionContextException : InvalidOperationException
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="InvalidOperationException"/> that indicates when an HLSL-only API is called from C#
|
||||
/// Creates a new <see cref="InvalidExecutionContextException"/> instance.
|
||||
/// </summary>
|
||||
public sealed class InvalidExecutionContextException : InvalidOperationException
|
||||
/// <param name="name">The name of the caller API.</param>
|
||||
internal InvalidExecutionContextException(string name)
|
||||
: base($"The API {name} can only be used from within an HLSL shader.")
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="InvalidExecutionContextException"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the caller API.</param>
|
||||
internal InvalidExecutionContextException(string name)
|
||||
: base($"The API {name} can only be used from within an HLSL shader.")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ComputeSharp.Core.Extensions
|
||||
namespace ComputeSharp.Core.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that provides extension methods for the <see cref="MethodInfo"/> type.
|
||||
/// </summary>
|
||||
internal static class MethodInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that provides extension methods for the <see cref="MethodInfo"/> type.
|
||||
/// Gets a fully qualified name for the input method, including parameters.
|
||||
/// </summary>
|
||||
internal static class MethodInfoExtensions
|
||||
/// <param name="method">The input <see cref="MethodInfo"/> instance.</param>
|
||||
/// <returns>A fully qualified name for <paramref name="method"/>, including parameters.</returns>
|
||||
[Pure]
|
||||
public static string GetFullName(this MethodInfo method)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a fully qualified name for the input method, including parameters.
|
||||
/// </summary>
|
||||
/// <param name="method">The input <see cref="MethodInfo"/> instance.</param>
|
||||
/// <returns>A fully qualified name for <paramref name="method"/>, including parameters.</returns>
|
||||
[Pure]
|
||||
public static string GetFullName(this MethodInfo method)
|
||||
var parameters = string.Join(", ", method.GetParameters().Select(static p => p.ParameterType.FullName));
|
||||
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
var parameters = string.Join(", ", method.GetParameters().Select(static p => p.ParameterType.FullName));
|
||||
var arguments = string.Join(", ", method.GetGenericArguments().Select(static t => t.FullName));
|
||||
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
var arguments = string.Join(", ", method.GetGenericArguments().Select(static t => t.FullName));
|
||||
|
||||
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}<{arguments}>({parameters})";
|
||||
}
|
||||
|
||||
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}({parameters})";
|
||||
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}<{arguments}>({parameters})";
|
||||
}
|
||||
|
||||
return $"{method.DeclaringType!.FullName!.Replace('+', '.')}.{method.Name}({parameters})";
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,42 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.Core.Helpers
|
||||
namespace ComputeSharp.Core.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helper methods to work with alignment and padding.
|
||||
/// </summary>
|
||||
internal static class AlignmentHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helper methods to work with alignment and padding.
|
||||
/// Pads the input size so that its pitch is aligned to a multiple of a specified length.
|
||||
/// </summary>
|
||||
internal static class AlignmentHelper
|
||||
/// <param name="size">The input size to pad, if needed.</param>
|
||||
/// <param name="alignment">The target alignment.</param>
|
||||
/// <returns>The padded value relative to the given inputs.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Pad(int size, int alignment)
|
||||
{
|
||||
/// <summary>
|
||||
/// Pads the input size so that its pitch is aligned to a multiple of a specified length.
|
||||
/// </summary>
|
||||
/// <param name="size">The input size to pad, if needed.</param>
|
||||
/// <param name="alignment">The target alignment.</param>
|
||||
/// <returns>The padded value relative to the given inputs.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Pad(int size, int alignment)
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
|
||||
/// </summary>
|
||||
/// <param name="offset">The starting offset to align, if needed.</param>
|
||||
/// <param name="size">The size increment to apply to <paramref name="offset"/>.</param>
|
||||
/// <param name="alignment">The alignment boundary to calculate the final offset.</param>
|
||||
/// <returns>A valid starting offset for the specified alignment.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int AlignToBoundary(int offset, int size, int alignment)
|
||||
{
|
||||
if ((uint)offset / (uint)alignment == (uint)(offset + size - 1) / (uint)alignment)
|
||||
{
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
return offset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
|
||||
/// </summary>
|
||||
/// <param name="offset">The starting offset to align, if needed.</param>
|
||||
/// <param name="size">The size increment to apply to <paramref name="offset"/>.</param>
|
||||
/// <param name="alignment">The alignment boundary to calculate the final offset.</param>
|
||||
/// <returns>A valid starting offset for the specified alignment.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int AlignToBoundary(int offset, int size, int alignment)
|
||||
{
|
||||
if ((uint)offset / (uint)alignment == (uint)(offset + size - 1) / (uint)alignment)
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
return (offset + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
return (offset + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,15 @@
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> representing a compute shader.
|
||||
/// </summary>
|
||||
public interface IComputeShader : IShader
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> representing a compute shader.
|
||||
/// Executes the current compute shader.
|
||||
/// </summary>
|
||||
public interface IComputeShader : IShader
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the current compute shader.
|
||||
/// </summary>
|
||||
void Execute();
|
||||
}
|
||||
void Execute();
|
||||
}
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> representing a pixel shader.
|
||||
/// </summary>
|
||||
public interface IPixelShader<TPixel> : IShader
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> representing a pixel shader.
|
||||
/// Executes the current pixel shader.
|
||||
/// </summary>
|
||||
public interface IPixelShader<TPixel> : IShader
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the current pixel shader.
|
||||
/// </summary>
|
||||
/// <returns>The pixel value for the current invocation.</returns>
|
||||
TPixel Execute();
|
||||
}
|
||||
/// <returns>The pixel value for the current invocation.</returns>
|
||||
TPixel Execute();
|
||||
}
|
||||
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a data loader for a shader being dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a data loader for a shader being dispatched.
|
||||
/// Loads the captured values used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the captured values used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized captured values.</param>
|
||||
void LoadCapturedValues(ReadOnlySpan<uint> data);
|
||||
/// <param name="data">The sequence of serialized captured values.</param>
|
||||
void LoadCapturedValues(ReadOnlySpan<uint> data);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the captured resources used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized resources.</param>
|
||||
void LoadCapturedResources(ReadOnlySpan<ulong> data);
|
||||
}
|
||||
/// <summary>
|
||||
/// Loads the captured resources used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized resources.</param>
|
||||
void LoadCapturedResources(ReadOnlySpan<ulong> data);
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a metadatadata loader for a shader being dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IDispatchMetadataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a metadatadata loader for a shader being dispatched.
|
||||
/// Loads an opaque metadata handle from the given shader metadata.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IDispatchMetadataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads an opaque metadata handle from the given shader metadata.
|
||||
/// </summary>
|
||||
/// <param name="serializedMetadata">The serialized metadata for the current shader.</param>
|
||||
/// <param name="resourceDescriptors">The sequence of resource descriptors for the current shader.</param>
|
||||
/// <param name="result">The resulting opaque metadata handle.</param>
|
||||
void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptor> resourceDescriptors, out IntPtr result);
|
||||
}
|
||||
/// <param name="serializedMetadata">The serialized metadata for the current shader.</param>
|
||||
/// <param name="resourceDescriptors">The sequence of resource descriptors for the current shader.</param>
|
||||
/// <param name="result">The resulting opaque metadata handle.</param>
|
||||
void LoadMetadataHandle(ReadOnlySpan<byte> serializedMetadata, ReadOnlySpan<ResourceDescriptor> resourceDescriptors, out IntPtr result);
|
||||
}
|
||||
@@ -1,69 +1,68 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IShader
|
||||
{
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
|
||||
/// Gets a unique dispatch identifier for the shader.
|
||||
/// </summary>
|
||||
/// <returns>The unique dispatch identifier for the shader.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IShader
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
int GetDispatchId()
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a unique dispatch identifier for the shader.
|
||||
/// </summary>
|
||||
/// <returns>The unique dispatch identifier for the shader.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
int GetDispatchId()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the dispatch data for the shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDataLoader">The type of data loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TDataLoader"/> instance to use to load the data.</param>
|
||||
/// <param name="device">The device the shader is being dispatched on.</param>
|
||||
/// <param name="x">The number of iterations to run on the X axis.</param>
|
||||
/// <param name="y">The number of iterations to run on the Y axis.</param>
|
||||
/// <param name="z">The number of iterations to run on the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
|
||||
where TDataLoader : struct, IDispatchDataLoader
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Loads the dispatch data for the shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDataLoader">The type of data loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TDataLoader"/> instance to use to load the data.</param>
|
||||
/// <param name="device">The device the shader is being dispatched on.</param>
|
||||
/// <param name="x">The number of iterations to run on the X axis.</param>
|
||||
/// <param name="y">The number of iterations to run on the Y axis.</param>
|
||||
/// <param name="z">The number of iterations to run on the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void LoadDispatchData<TDataLoader>(ref TDataLoader loader, GraphicsDevice device, int x, int y, int z)
|
||||
where TDataLoader : struct, IDispatchDataLoader
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an opaque metadata handle from the metadata of the current shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TMetadataLoader">The type of data loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TMetadataLoader"/> instance to use to load the data.</param>
|
||||
/// <param name="result">The resulting opaque metadata handle.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void LoadDispatchMetadata<TMetadataLoader>(ref TMetadataLoader loader, out IntPtr result)
|
||||
where TMetadataLoader : struct, IDispatchMetadataLoader
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Loads an opaque metadata handle from the metadata of the current shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TMetadataLoader">The type of data loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TMetadataLoader"/> instance to use to load the data.</param>
|
||||
/// <param name="result">The resulting opaque metadata handle.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void LoadDispatchMetadata<TMetadataLoader>(ref TMetadataLoader loader, out IntPtr result)
|
||||
where TMetadataLoader : struct, IDispatchMetadataLoader
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the HLSL source code for the current shader instance.
|
||||
/// </summary>
|
||||
/// <param name="builder">The resulting <see cref="ArrayPoolStringBuilder"/> instance containing the HLSL source.</param>
|
||||
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void BuildHlslString(out ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Builds the HLSL source code for the current shader instance.
|
||||
/// </summary>
|
||||
/// <param name="builder">The resulting <see cref="ArrayPoolStringBuilder"/> instance containing the HLSL source.</param>
|
||||
/// <param name="threadsX">The number of threads in each thread group for the X axis.</param>
|
||||
/// <param name="threadsY">The number of threads in each thread group for the Y axis.</param>
|
||||
/// <param name="threadsZ">The number of threads in each thread group for the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void BuildHlslString(out ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Core.Intrinsics.Attributes
|
||||
namespace ComputeSharp.Core.Intrinsics.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// An attribute indicating the native member name of a given HLSL intrinsic.
|
||||
/// </summary>
|
||||
internal sealed class HlslIntrinsicNameAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute indicating the native member name of a given HLSL intrinsic.
|
||||
/// Creates a new <see cref="HlslIntrinsicNameAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
internal sealed class HlslIntrinsicNameAttribute : Attribute
|
||||
/// <param name="name">The name of the HLSL intrinsic.</param>
|
||||
public HlslIntrinsicNameAttribute(string name)
|
||||
{
|
||||
/// <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; }
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the HLSL intrinsic.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
}
|
||||
@@ -1,320 +1,319 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that maps the supported HLSL intrinsic functions that can be used in compute shaders.
|
||||
/// </summary>
|
||||
public static partial class Hlsl
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that maps the supported HLSL intrinsic functions that can be used in compute shaders.
|
||||
/// Blocks execution of all threads in a group until all memory accesses have been completed.
|
||||
/// </summary>
|
||||
public static partial class Hlsl
|
||||
{
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all memory accesses have been completed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A memory barrier guarantees that outstanding memory operations have completed.
|
||||
/// Threads are synchronized at GroupSync barriers.
|
||||
/// This may stall a thread or threads if memory operations are in progress.
|
||||
/// <para>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</para>
|
||||
/// </remarks>
|
||||
public static void AllMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrier)}()");
|
||||
/// <remarks>
|
||||
/// A memory barrier guarantees that outstanding memory operations have completed.
|
||||
/// Threads are synchronized at GroupSync barriers.
|
||||
/// This may stall a thread or threads if memory operations are in progress.
|
||||
/// <para>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</para>
|
||||
/// </remarks>
|
||||
public static void AllMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrier)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A memory barrier guarantees that outstanding memory operations have completed.
|
||||
/// Threads are synchronized at GroupSync barriers.
|
||||
/// This may stall a thread or threads if memory operations are in progress.
|
||||
/// <para>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</para>
|
||||
/// </remarks>
|
||||
public static void AllMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrierWithGroupSync)}()");
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A memory barrier guarantees that outstanding memory operations have completed.
|
||||
/// Threads are synchronized at GroupSync barriers.
|
||||
/// This may stall a thread or threads if memory operations are in progress.
|
||||
/// <para>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</para>
|
||||
/// </remarks>
|
||||
public static void AllMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(AllMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all device memory accesses have been completed.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void DeviceMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrier)}()");
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all device memory accesses have been completed.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void DeviceMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrier)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void DeviceMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrierWithGroupSync)}()");
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all device memory accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void DeviceMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(DeviceMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all group shared accesses have been completed.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void GroupMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrier)}()");
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all group shared accesses have been completed.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void GroupMemoryBarrier() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrier)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void GroupMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrierWithGroupSync)}()");
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void GroupMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(GroupMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAdd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic and of a value to a destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedAnd(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Atomically compares the destination with the comparison value. If they are identical, the destination
|
||||
/// is overwritten with the input value. The original value is set to the destination's original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareExchange(ref int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Atomically compares the destination with the comparison value. If they are identical, the destination
|
||||
/// is overwritten with the input value. The original value is set to the destination's original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareExchange(ref int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Atomically compares the destination with the comparison value. If they are identical, the destination
|
||||
/// is overwritten with the input value. The original value is set to the destination's original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareExchange(ref uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Atomically compares the destination with the comparison value. If they are identical, the destination
|
||||
/// is overwritten with the input value. The original value is set to the destination's original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareExchange(ref uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Atomically compares the destination to the comparison value. If they
|
||||
/// are identical, the destination is overwritten with the input value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareStore(ref int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Atomically compares the destination to the comparison value. If they
|
||||
/// are identical, the destination is overwritten with the input value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareStore(ref int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Atomically compares the destination to the comparison value. If they
|
||||
/// are identical, the destination is overwritten with the input value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareStore(ref uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Atomically compares the destination to the comparison value. If they
|
||||
/// are identical, the destination is overwritten with the input value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="comparison">The comparison value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedCompareStore(ref uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Assigns value to dest and returns the original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedExchange(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Assigns value to dest and returns the original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedExchange(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Assigns value to dest and returns the original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedExchange(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Assigns value to dest and returns the original value.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedExchange(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic max.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMax(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic min.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedMin(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic or.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedOr(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)}, {typeof(int)})");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
}
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic xor.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination value.</param>
|
||||
/// <param name="value">The input value.</param>
|
||||
/// <param name="original">The original value.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static void InterlockedXor(ref uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})");
|
||||
}
|
||||
+18035
-18036
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -3,14 +3,13 @@ using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <inheritdoc cref="Hlsl"/>
|
||||
public static partial class Hlsl
|
||||
{
|
||||
/// <inheritdoc cref="Hlsl"/>
|
||||
public static partial class Hlsl
|
||||
{
|
||||
<#
|
||||
PushIndent(" ");
|
||||
PushIndent(" ");
|
||||
|
||||
bool isFirst = true;
|
||||
|
||||
@@ -61,8 +60,6 @@ foreach (var intrinsic in Intrinsics)
|
||||
}
|
||||
}
|
||||
|
||||
PopIndent();
|
||||
PopIndent();
|
||||
#>
|
||||
}
|
||||
}
|
||||
@@ -6,117 +6,116 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in blue, green, red, and alpha order (least significant to most significant byte).
|
||||
/// The format is binary compatible with System.Drawing.Imaging.PixelFormat.Format32bppArgb.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Bgra32 : IEquatable<Bgra32>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in blue, green, red, and alpha order (least significant to most significant byte).
|
||||
/// The format is binary compatible with System.Drawing.Imaging.PixelFormat.Format32bppArgb.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Bgra32 : IEquatable<Bgra32>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
public byte B;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public byte A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Bgra32(byte r, byte g, byte b)
|
||||
{
|
||||
/// <summary>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
public byte B;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public byte A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Bgra32(byte r, byte g, byte b)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = byte.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Bgra32(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Bgra32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Bgra32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Bgra32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Bgra32 left, Bgra32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Bgra32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Bgra32 other && Equals(other);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Bgra32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override readonly string ToString() => $"{nameof(Bgra32)}({this.B}, {this.G}, {this.R}, {this.A})";
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = byte.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Bgra32(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Bgra32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Bgra32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Bgra32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Bgra32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Bgra32 left, Bgra32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Bgra32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Bgra32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Bgra32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Bgra32 other && Equals(other);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Bgra32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override readonly string ToString() => $"{nameof(Bgra32)}({this.B}, {this.G}, {this.R}, {this.A})";
|
||||
}
|
||||
@@ -5,77 +5,76 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing a single 16-bit unsigned normalized channel value.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 0, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct R16 : IEquatable<R16>, IUnorm<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing a single 16-bit unsigned normalized channel value.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 0, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct R16 : IEquatable<R16>, IUnorm<float>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="R16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
public R16(ushort r)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="R16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
public R16(ushort r)
|
||||
{
|
||||
R = r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="R16"/> struct.
|
||||
/// </summary>
|
||||
public ushort PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<R16, ushort>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<R16, ushort>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(R16 left, R16 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(R16 left, R16 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is R16 R16 && Equals(R16);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(R16 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(R16)}({this.R})";
|
||||
R = r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="R16"/> struct.
|
||||
/// </summary>
|
||||
public ushort PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<R16, ushort>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<R16, ushort>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(R16 left, R16 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(R16 left, R16 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is R16 R16 && Equals(R16);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(R16 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(R16)}({this.R})";
|
||||
}
|
||||
@@ -5,77 +5,76 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing a single 8-bit unsigned normalized channel value.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 0, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct R8 : IEquatable<R8>, IUnorm<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing a single 8-bit unsigned normalized channel value.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 0, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct R8 : IEquatable<R8>, IUnorm<float>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="R8"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
public R8(byte r)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="R8"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
public R8(byte r)
|
||||
{
|
||||
R = r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="R8"/> struct.
|
||||
/// </summary>
|
||||
public byte PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<R8, byte>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<R8, byte>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R8"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R8"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R8"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(R8 left, R8 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R8"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R8"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R8"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(R8 left, R8 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is R8 R8 && Equals(R8);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(R8 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(R8)}({this.R})";
|
||||
R = r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="R8"/> struct.
|
||||
/// </summary>
|
||||
public byte PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<R8, byte>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<R8, byte>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R8"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R8"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R8"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(R8 left, R8 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="R8"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="R8"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="R8"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(R8 left, R8 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is R8 R8 && Equals(R8);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(R8 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(R8)}({this.R})";
|
||||
}
|
||||
@@ -6,84 +6,83 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing two 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rg16 : IEquatable<Rg16>, IUnorm<Vector2>, IUnorm<Float2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing two 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rg16 : IEquatable<Rg16>, IUnorm<Vector2>, IUnorm<Float2>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg16(byte r, byte g)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg16(byte r, byte g)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rg16"/> struct.
|
||||
/// </summary>
|
||||
public ushort PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rg16, ushort>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rg16, ushort>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rg16 left, Rg16 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rg16 left, Rg16 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rg16 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rg16 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rg16)}({this.R}, {this.G})";
|
||||
R = r;
|
||||
G = g;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rg16"/> struct.
|
||||
/// </summary>
|
||||
public ushort PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rg16, ushort>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rg16, ushort>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rg16 left, Rg16 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg16"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg16"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg16"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rg16 left, Rg16 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rg16 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rg16 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rg16)}({this.R}, {this.G})";
|
||||
}
|
||||
@@ -6,84 +6,83 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rg32 : IEquatable<Rg32>, IUnorm<Vector2>, IUnorm<Float2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 0, 0] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rg32 : IEquatable<Rg32>, IUnorm<Vector2>, IUnorm<Float2>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public ushort G;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg32(ushort r, ushort g)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public ushort G;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg32(ushort r, ushort g)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rg32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rg32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rg32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rg32 left, Rg32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rg32 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rg32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rg32)}({this.R}, {this.G})";
|
||||
R = r;
|
||||
G = g;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rg32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rg32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rg32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rg32 left, Rg32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rg32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rg32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rg32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rg32 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rg32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rg32)}({this.R}, {this.G})";
|
||||
}
|
||||
@@ -6,116 +6,115 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in red, green, blue, and alpha order (least significant to most significant byte).
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rgba32 : IEquatable<Rgba32>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in red, green, blue, and alpha order (least significant to most significant byte).
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rgba32 : IEquatable<Rgba32>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
public byte B;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public byte A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba32(byte r, byte g, byte b)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
public byte B;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public byte A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba32(byte r, byte g, byte b)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = byte.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba32(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rgba32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rgba32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rgba32 left, Rgba32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rgba32 left, Rgba32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rgba32 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rgba32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rgba32)}({this.R}, {this.G}, {this.B}, {this.A})";
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = byte.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba32(byte r, byte g, byte b, byte a)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rgba32"/> struct.
|
||||
/// </summary>
|
||||
public uint PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rgba32, uint>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rgba32, uint>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rgba32 left, Rgba32 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rgba32 left, Rgba32 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rgba32 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rgba32 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rgba32)}({this.R}, {this.G}, {this.B}, {this.A})";
|
||||
}
|
||||
@@ -6,116 +6,115 @@ using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in red, green, blue, and alpha order (least significant to most significant byte).
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rgba64 : IEquatable<Rgba64>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 255.
|
||||
/// The color components are stored in red, green, blue, and alpha order (least significant to most significant byte).
|
||||
/// <para>
|
||||
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
|
||||
/// </para>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
/// <remarks>This struct is fully mutable.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rgba64 : IEquatable<Rgba64>, IUnorm<Vector4>, IUnorm<Float4>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public ushort G;
|
||||
|
||||
/// <summary>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
public ushort B;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public ushort A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba64(ushort r, ushort g, ushort b)
|
||||
{
|
||||
/// <summary>
|
||||
/// The red component.
|
||||
/// </summary>
|
||||
public ushort R;
|
||||
|
||||
/// <summary>
|
||||
/// The green component.
|
||||
/// </summary>
|
||||
public ushort G;
|
||||
|
||||
/// <summary>
|
||||
/// The blue component.
|
||||
/// </summary>
|
||||
public ushort B;
|
||||
|
||||
/// <summary>
|
||||
/// The alpha component.
|
||||
/// </summary>
|
||||
public ushort A;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba64(ushort r, ushort g, ushort b)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = ushort.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba64(ushort r, ushort g, ushort b, ushort a)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
public ulong PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rgba64, ulong>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rgba64, ulong>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba64"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba64"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba64"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rgba64 left, Rgba64 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba64"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba64"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba64"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rgba64 left, Rgba64 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rgba64 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rgba64 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rgba64)}({this.R}, {this.G}, {this.B}, {this.A})";
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = ushort.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
/// <param name="b">The blue component.</param>
|
||||
/// <param name="a">The alpha component.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Rgba64(ushort r, ushort g, ushort b, ushort a)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
this.A = a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the packed representation of the <see cref="Rgba64"/> struct.
|
||||
/// </summary>
|
||||
public ulong PackedValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => Unsafe.As<Rgba64, ulong>(ref Unsafe.AsRef(this));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Rgba64, ulong>(ref this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba64"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba64"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba64"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Rgba64 left, Rgba64 right) => left.Equals(right);
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Rgba64"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The <see cref="Rgba64"/> on the left side of the operand.</param>
|
||||
/// <param name="right">The <see cref="Rgba64"/> on the right side of the operand.</param>
|
||||
/// <returns>
|
||||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Rgba64 left, Rgba64 right) => !left.Equals(right);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly bool Equals(object? obj) => obj is Rgba64 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(Rgba64 other) => PackedValue.Equals(other.PackedValue);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly int GetHashCode() => PackedValue.GetHashCode();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString() => $"{nameof(Rgba64)}({this.R}, {this.G}, {this.B}, {this.A})";
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the supported HLSL pixel types to represent a given normalized pixel type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates the supported HLSL pixel types to represent a given normalized pixel type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,75 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that can be used in place of the <see cref="bool"/> type in HLSL shaders.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = sizeof(int), Pack = 4)]
|
||||
public readonly struct Bool
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that can be used in place of the <see cref="bool"/> type in HLSL shaders.
|
||||
/// The wrapped <see cref="bool"/> value for the current instance.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = sizeof(int), Pack = 4)]
|
||||
public readonly struct Bool
|
||||
[FieldOffset(0)]
|
||||
private readonly bool Value;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool"/> instance for a given <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="value">.</param>
|
||||
private Bool(bool value)
|
||||
{
|
||||
/// <summary>
|
||||
/// The wrapped <see cref="bool"/> value for the current instance.
|
||||
/// </summary>
|
||||
[FieldOffset(0)]
|
||||
private readonly bool Value;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool"/> instance for a given <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="value">.</param>
|
||||
private Bool(bool value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Bool x && Value == x.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not two <see cref="Bool"/> instances represent the same <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="left">The left <see cref="Bool"/> instance.</param>
|
||||
/// <param name="right">The right <see cref="Bool"/> instance.</param>
|
||||
public static bool operator ==(Bool left, Bool right) => left.Value == right.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not two <see cref="Bool"/> instances represent a different <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="left">The left <see cref="Bool"/> instance.</param>
|
||||
/// <param name="right">The right <see cref="Bool"/> instance.</param>
|
||||
public static bool operator !=(Bool left, Bool right) => left.Value != right.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Inverts the <see cref="bool"/> value represented by a given <see cref="Bool"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static Bool operator !(Bool x) => new(!x.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a given <see cref="Bool"/> instance to its corresponding <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static implicit operator bool(Bool x) => x.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="bool"/> value to a corresponding <see cref="Bool"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="bool"/> value.</param>
|
||||
public static implicit operator Bool(bool x) => new(x);
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Bool x && Value == x.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not two <see cref="Bool"/> instances represent the same <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="left">The left <see cref="Bool"/> instance.</param>
|
||||
/// <param name="right">The right <see cref="Bool"/> instance.</param>
|
||||
public static bool operator ==(Bool left, Bool right) => left.Value == right.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not two <see cref="Bool"/> instances represent a different <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="left">The left <see cref="Bool"/> instance.</param>
|
||||
/// <param name="right">The right <see cref="Bool"/> instance.</param>
|
||||
public static bool operator !=(Bool left, Bool right) => left.Value != right.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Inverts the <see cref="bool"/> value represented by a given <see cref="Bool"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static Bool operator !(Bool x) => new(!x.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a given <see cref="Bool"/> instance to its corresponding <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static implicit operator bool(Bool x) => x.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="bool"/> value to a corresponding <see cref="Bool"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="bool"/> value.</param>
|
||||
public static implicit operator Bool(bool x) => new(x);
|
||||
}
|
||||
@@ -1,45 +1,44 @@
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool2"/> HLSL type.
|
||||
/// </summary>
|
||||
public partial struct Bool2
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool2"/> HLSL type.
|
||||
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public partial struct Bool2
|
||||
public static Bool2 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool2 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool2 TrueX => new(true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool2 TrueY => new(false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool2"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
public Bool2(bool x, bool y)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool2 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool2 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool2 TrueX => new(true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool2"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool2 TrueY => new(false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool2"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
public Bool2(bool x, bool y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool2"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool2"/> instance.</param>
|
||||
public static implicit operator Bool2(bool x) => new(x, x);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool2"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool2"/> instance.</param>
|
||||
public static implicit operator Bool2(bool x) => new(x, x);
|
||||
}
|
||||
@@ -8,405 +8,404 @@ using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <inheritdoc cref="Bool2"/>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)]
|
||||
public unsafe partial struct Bool2
|
||||
{
|
||||
/// <inheritdoc cref="Bool2"/>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)]
|
||||
public unsafe partial struct Bool2
|
||||
/// <summary>
|
||||
/// A private buffer to which the undefined properties will point to.
|
||||
/// </summary>
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2), sizeof(Bool4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private bool x;
|
||||
|
||||
[FieldOffset(4)]
|
||||
private bool y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Bool2"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="i">The index of the component to access.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref bool this[int i] => ref *(bool*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 XX => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 XY => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 YX => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 YY => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XXX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XXY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XYX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XYY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YXX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YXY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YYX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YYY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 RR => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 RG => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 GR => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 GG => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RRR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RRG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RGR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RGG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GRR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GRG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GGR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GGG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
/// <summary>
|
||||
/// A private buffer to which the undefined properties will point to.
|
||||
/// </summary>
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2), sizeof(Bool4));
|
||||
StringBuilder sb = new();
|
||||
|
||||
[FieldOffset(0)]
|
||||
private bool x;
|
||||
sb.Append('<');
|
||||
sb.Append(this.x);
|
||||
sb.Append(", ");
|
||||
sb.Append(this.y);
|
||||
sb.Append('>');
|
||||
|
||||
[FieldOffset(4)]
|
||||
private bool y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Bool2"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="i">The index of the component to access.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref bool this[int i] => ref *(bool*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 XX => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 XY => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 YX => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 YY => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XXX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XXY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XYX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 XYY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YXX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YXY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YYX => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 YYY => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XXYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 XYYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YXYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYXX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYXY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYYX => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 YYYY => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 RR => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 RG => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Bool2"/> value with the components <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Bool2 GR => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool2 GG => ref *(Bool2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RRR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RRG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RGR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 RGG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GRR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GRG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GGR => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool3 GGG => ref *(Bool3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RRGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 RGGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GRGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGRR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGRG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGGR => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Bool4 GGGG => ref *(Bool4*)UndefinedData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.Append('<');
|
||||
sb.Append(this.x);
|
||||
sb.Append(", ");
|
||||
sb.Append(this.y);
|
||||
sb.Append('>');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates a <see cref="Bool2"/> value.
|
||||
/// </summary>
|
||||
/// <param name="xy">The <see cref="Bool2"/> value to negate.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Bool2 operator !(Bool2 xy) => default;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates a <see cref="Bool2"/> value.
|
||||
/// </summary>
|
||||
/// <param name="xy">The <see cref="Bool2"/> value to negate.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Bool2 operator !(Bool2 xy) => default;
|
||||
}
|
||||
@@ -1,76 +1,75 @@
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool3"/> HLSL type.
|
||||
/// </summary>
|
||||
public partial struct Bool3
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool3"/> HLSL type.
|
||||
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public partial struct Bool3
|
||||
public static Bool3 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool3 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueX => new(true, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueY => new(false, true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueZ => new(false, false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Bool3(bool x, bool y, bool z)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool3 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueX => new(true, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueY => new(false, true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool3"/> value with the <see cref="Z"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool3 TrueZ => new(false, false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Bool3(bool x, bool y, bool z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Bool3(Bool2 xy, bool z)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yz">The value to assign to the second and thirt vector components.</param>
|
||||
public Bool3(bool x, Bool2 yz)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yz.X;
|
||||
this.z = yz.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool3"/> instance.</param>
|
||||
public static implicit operator Bool3(bool x) => new(x, x, x);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Bool3(Bool2 xy, bool z)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yz">The value to assign to the second and thirt vector components.</param>
|
||||
public Bool3(bool x, Bool2 yz)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yz.X;
|
||||
this.z = yz.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool3"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool3"/> instance.</param>
|
||||
public static implicit operator Bool3(bool x) => new(x, x, x);
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -1,126 +1,125 @@
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool4"/> HLSL type.
|
||||
/// </summary>
|
||||
public partial struct Bool4
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="bool4"/> HLSL type.
|
||||
/// Gets an <see cref="Bool4"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public partial struct Bool4
|
||||
public static Bool4 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool4 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueX => new(true, false, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueY => new(false, true, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="Z"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueZ => new(false, false, true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="W"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueW => new(false, false, false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(bool x, bool y, bool z, bool w)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with all components set to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 False => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with all components set to <see langword="true"/>.
|
||||
/// </summary>
|
||||
public static Bool4 True => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="X"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueX => new(true, false, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="Y"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueY => new(false, true, false, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="Z"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueZ => new(false, false, true, false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Bool4"/> value with the <see cref="W"/> component set to <see langword="true"/>, and the others to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public static Bool4 TrueW => new(false, false, false, true);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(bool x, bool y, bool z, bool w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(Bool2 xy, bool z, bool w)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
public Bool4(bool x, bool y, Bool2 zw)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = zw.X;
|
||||
this.w = zw.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
public Bool4(Bool2 xy, Bool2 zw)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = zw.X;
|
||||
this.w = zw.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The value to assign to the first, second and third vector components.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(Bool3 xyz, bool w)
|
||||
{
|
||||
this.x = xyz.X;
|
||||
this.y = xyz.Y;
|
||||
this.z = xyz.Z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yzw">The value to assign to the second, third and fourth vector components.</param>
|
||||
public Bool4(bool x, Bool3 yzw)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yzw.X;
|
||||
this.z = yzw.Y;
|
||||
this.w = yzw.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool4"/> instance.</param>
|
||||
public static implicit operator Bool4(bool x) => new(x, x, x, x);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(Bool2 xy, bool z, bool w)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
public Bool4(bool x, bool y, Bool2 zw)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = zw.X;
|
||||
this.w = zw.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
public Bool4(Bool2 xy, Bool2 zw)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = zw.X;
|
||||
this.w = zw.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The value to assign to the first, second and third vector components.</param>
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
public Bool4(Bool3 xyz, bool w)
|
||||
{
|
||||
this.x = xyz.X;
|
||||
this.y = xyz.Y;
|
||||
this.z = xyz.Z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yzw">The value to assign to the second, third and fourth vector components.</param>
|
||||
public Bool4(bool x, Bool3 yzw)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yzw.X;
|
||||
this.z = yzw.Y;
|
||||
this.w = yzw.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool4"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Bool4"/> instance.</param>
|
||||
public static implicit operator Bool4(bool x) => new(x, x, x, x);
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -1,66 +1,65 @@
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="double2"/> HLSL type.
|
||||
/// </summary>
|
||||
public partial struct Double2
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="double2"/> HLSL type.
|
||||
/// Gets an <see cref="Double2"/> value with all components set to 0.
|
||||
/// </summary>
|
||||
public partial struct Double2
|
||||
public static Double2 Zero => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with all components set to 1.
|
||||
/// </summary>
|
||||
public static Double2 One => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with the <see cref="X"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double2 UnitX => new(1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double2 UnitY => new(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double2"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
public Double2(double x, double y)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with all components set to 0.
|
||||
/// </summary>
|
||||
public static Double2 Zero => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with all components set to 1.
|
||||
/// </summary>
|
||||
public static Double2 One => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with the <see cref="X"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double2 UnitX => new(1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double2"/> value with the <see cref="Y"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double2 UnitY => new(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double2"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
public Double2(double x, double y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double2"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Double2"/> instance.</param>
|
||||
public static implicit operator Double2(double x) => new(x, x);
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="Int2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Int2(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="UInt2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator UInt2(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="Float2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Float2(Double2 xy) => default;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double2"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Double2"/> instance.</param>
|
||||
public static implicit operator Double2(double x) => new(x, x);
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="Int2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Int2(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="UInt2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator UInt2(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double2"/> value to a <see cref="Float2"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Double2"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Float2(Double2 xy) => default;
|
||||
}
|
||||
@@ -10,446 +10,445 @@ using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <inheritdoc cref="Double2"/>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)]
|
||||
public unsafe partial struct Double2 : IFormattable
|
||||
{
|
||||
/// <inheritdoc cref="Double2"/>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)]
|
||||
public unsafe partial struct Double2 : IFormattable
|
||||
/// <summary>
|
||||
/// A private buffer to which the undefined properties will point to.
|
||||
/// </summary>
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2), sizeof(Double4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private double x;
|
||||
|
||||
[FieldOffset(8)]
|
||||
private double y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Double2"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="i">The index of the component to access.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref double this[int i] => ref *(double*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 XX => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 XY => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 YX => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 YY => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XXX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XXY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XYX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XYY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YXX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YXY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YYX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YYY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 RR => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 RG => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 GR => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 GG => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RRR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RRG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RGR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RGG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GRR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GRG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GGR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GGG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
/// <summary>
|
||||
/// A private buffer to which the undefined properties will point to.
|
||||
/// </summary>
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2), sizeof(Double4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private double x;
|
||||
|
||||
[FieldOffset(8)]
|
||||
private double y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Double2"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="i">The index of the component to access.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref double this[int i] => ref *(double*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 XX => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 XY => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 YX => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 YY => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XXX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XXY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XYX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 XYY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YXX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YXY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YYX => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 YYY => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XXYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 XYYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YXYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYXX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYXY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="X"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYYX => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>, <see cref="Y"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 YYYY => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="double"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref double G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 RR => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 RG => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="Double2"/> value with the components <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref Double2 GR => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double2"/> value with the components <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double2 GG => ref *(Double2*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RRR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RRG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RGR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 RGG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GRR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GRG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GGR => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double3"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double3 GGG => ref *(Double3*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RRGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="R"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 RGGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="R"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GRGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGRR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="R"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGRG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="R"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGGR => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Double4"/> value with the components <see cref="G"/>, <see cref="G"/>, <see cref="G"/>, <see cref="G"/>.
|
||||
/// </summary>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public readonly ref readonly Double4 GGGG => ref *(Double4*)UndefinedData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return ToString("G", CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public readonly string ToString(string? format, IFormatProvider? formatProvider)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
|
||||
|
||||
sb.Append('<');
|
||||
sb.Append(this.x.ToString(format, formatProvider));
|
||||
sb.Append(separator);
|
||||
sb.Append(' ');
|
||||
sb.Append(this.y.ToString(format, formatProvider));
|
||||
sb.Append('>');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates a <see cref="Double2"/> value.
|
||||
/// </summary>
|
||||
/// <param name="xy">The <see cref="Double2"/> value to negate.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator -(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Sums two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to sum.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to sum.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator +(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Divides two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to divide.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to divide.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator /(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to multiply.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to multiply.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator *(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to subtract.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to subtract.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator -(Double2 left, Double2 right) => default;
|
||||
return ToString("G", CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public readonly string ToString(string? format, IFormatProvider? formatProvider)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
|
||||
|
||||
sb.Append('<');
|
||||
sb.Append(this.x.ToString(format, formatProvider));
|
||||
sb.Append(separator);
|
||||
sb.Append(' ');
|
||||
sb.Append(this.y.ToString(format, formatProvider));
|
||||
sb.Append('>');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates a <see cref="Double2"/> value.
|
||||
/// </summary>
|
||||
/// <param name="xy">The <see cref="Double2"/> value to negate.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator -(Double2 xy) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Sums two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to sum.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to sum.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator +(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Divides two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to divide.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to divide.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator /(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to multiply.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to multiply.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator *(Double2 left, Double2 right) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts two <see cref="Double2"/> values.
|
||||
/// </summary>
|
||||
/// <param name="left">The first <see cref="Double2"/> value to subtract.</param>
|
||||
/// <param name="right">The second <see cref="Double2"/> value to subtract.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static Double2 operator -(Double2 left, Double2 right) => default;
|
||||
}
|
||||
@@ -1,97 +1,96 @@
|
||||
namespace ComputeSharp
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="double3"/> HLSL type.
|
||||
/// </summary>
|
||||
public partial struct Double3
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that maps the <see langword="double3"/> HLSL type.
|
||||
/// Gets an <see cref="Double3"/> value with all components set to 0.
|
||||
/// </summary>
|
||||
public partial struct Double3
|
||||
public static Double3 Zero => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with all components set to 1.
|
||||
/// </summary>
|
||||
public static Double3 One => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="X"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitX => new(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitY => new(0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitZ => new(0, 0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Double3(double x, double y, double z)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with all components set to 0.
|
||||
/// </summary>
|
||||
public static Double3 Zero => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with all components set to 1.
|
||||
/// </summary>
|
||||
public static Double3 One => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="X"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitX => new(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="Y"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitY => new(0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Double3"/> value with the <see cref="Z"/> component set to 1, and the others to 0.
|
||||
/// </summary>
|
||||
public static Double3 UnitZ => new(0, 0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Double3(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Double3(Double2 xy, double z)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yz">The value to assign to the second and thirt vector components.</param>
|
||||
public Double3(double x, Double2 yz)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yz.X;
|
||||
this.z = yz.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Double3"/> instance.</param>
|
||||
public static implicit operator Double3(double x) => new(x, x, x);
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="Int3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Int3(Double3 xyz) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="UInt3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator UInt3(Double3 xyz) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="Float3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Float3(Double3 xyz) => default;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="xy">The value to assign to the first and second vector components.</param>
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
public Double3(Double2 xy, double z)
|
||||
{
|
||||
this.x = xy.X;
|
||||
this.y = xy.Y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to assign to the first vector component.</param>
|
||||
/// <param name="yz">The value to assign to the second and thirt vector components.</param>
|
||||
public Double3(double x, Double2 yz)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = yz.X;
|
||||
this.z = yz.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Double3"/> value with the same value for all its components.
|
||||
/// </summary>
|
||||
/// <param name="x">The value to use for the components of the new <see cref="Double3"/> instance.</param>
|
||||
public static implicit operator Double3(double x) => new(x, x, x);
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="Int3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Int3(Double3 xyz) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="UInt3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator UInt3(Double3 xyz) => default;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Double3"/> value to a <see cref="Float3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The input <see cref="Double3"/> value to cast.</param>
|
||||
/// <remarks>This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior.</remarks>
|
||||
public static explicit operator Float3(Double3 xyz) => default;
|
||||
}
|
||||
275ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。
さらに表示
新しいイシューから参照
ユーザーをブロックする