Merge pull request #91 from Sergio0694/feature/netstandard2_0
Unorm textures, more new APIs
このコミットが含まれているのは:
116ファイル変更
+2525
-1035
検索条件に一致するファイルはありません
+4
-1
@@ -330,4 +330,7 @@ ASALocalRun/
|
||||
.mfractor/
|
||||
|
||||
# Sample images
|
||||
**/city_*.jpg
|
||||
samples/**/city_*.jpg
|
||||
|
||||
# XML docs files
|
||||
src/**/ComputeSharp*.xml
|
||||
@@ -5,5 +5,6 @@
|
||||
<add key="BenchmarkDotNet-CI" value="https://ci.appveyor.com/nuget/benchmarkdotnet" />
|
||||
<add key="ComputeSharp-Local" value="src\ComputeSharp.Package\bin\Release" />
|
||||
<add key="SixLabors-CI" value="https://www.myget.org/F/sixlabors/api/v3/index.json" />
|
||||
<add key="TerraFX-Local" value="pkg" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -153,7 +153,7 @@ namespace ComputeSharp.Benchmark.Blas
|
||||
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(Y);
|
||||
using ReadWriteBuffer<float> y = Gpu.Default.AllocateReadWriteBuffer<float>(Y.Length);
|
||||
|
||||
BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.Graphics;
|
||||
|
||||
namespace ComputeSharp.Benchmark.Blas
|
||||
{
|
||||
@@ -93,17 +92,17 @@ namespace ComputeSharp.Benchmark.Blas
|
||||
public readonly ReadWriteBuffer<float> y;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
int x_offset = ids.X * n * p + ids.Y * m;
|
||||
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 + ids.Z];
|
||||
result += x[x_offset + k] * w[k * p + ThreadIds.Z];
|
||||
}
|
||||
|
||||
y[ids.X * n * p + ids.Y * p + ids.Z] = result + b[ids.Z];
|
||||
y[ThreadIds.X * n * p + ThreadIds.Y * p + ThreadIds.Z] = result + b[ThreadIds.Z];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -257,61 +256,38 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> processingTexture = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> realTexture = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaryTexture = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> temporary = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
|
||||
using ReadWriteTexture2D<Vector4> reals = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaries = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernel = Gpu.Default.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
|
||||
// Preliminary gamma highlight pass
|
||||
ApplyGammaHighlight(sourceTexture);
|
||||
|
||||
ref Vector4 param0 = ref MemoryMarshal.GetArrayDataReference(KernelParameters);
|
||||
Gpu.Default.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++)
|
||||
{
|
||||
kernelBuffer.SetData(Kernels[j]);
|
||||
Vector4 parameters = Unsafe.Add(ref param0, j);
|
||||
Vector4 parameters = KernelParameters[j];
|
||||
|
||||
ApplyVerticalConvolution(sourceTexture, realTexture, imaginaryTexture, kernelBuffer);
|
||||
ApplyHorizontalConvolutionAndAccumulatePartials(realTexture, imaginaryTexture, processingTexture, kernelBuffer, parameters.Z, parameters.W);
|
||||
kernel.SetData(Kernels[j]);
|
||||
|
||||
Gpu.Default.For<VerticalConvolutionProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(texture, reals, imaginaries, kernel));
|
||||
|
||||
Gpu.Default.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
|
||||
}
|
||||
|
||||
// Apply the inverse gamma exposure pass
|
||||
ApplyInverseGammaExposure(processingTexture, sourceTexture);
|
||||
Gpu.Default.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
|
||||
|
||||
// Write the final pixel data
|
||||
sourceTexture.GetData(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a vertical 1D complex convolution with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="source">The source <see cref="ReadOnlyTexture2D{T}"/> to read data from.</param>
|
||||
/// <param name="reals">The target <see cref="ReadWriteTexture2D{T}"/> to write the real results to.</param>
|
||||
/// <param name="imaginaries">The target <see cref="ReadWriteTexture2D{T}"/> to write the imaginary results to.</param>
|
||||
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ApplyVerticalConvolution(
|
||||
ReadWriteTexture2D<Rgba32, Vector4> source,
|
||||
ReadWriteTexture2D<Vector4> reals,
|
||||
ReadWriteTexture2D<Vector4> imaginaries,
|
||||
ReadOnlyBuffer<Complex64> kernel)
|
||||
{
|
||||
int height = Source.Height;
|
||||
int width = Source.Width;
|
||||
|
||||
VerticalConvolutionProcessor shader = new(
|
||||
maxY: height - 1,
|
||||
maxX: width - 1,
|
||||
kernelLength: kernel.Length,
|
||||
source,
|
||||
reals,
|
||||
imaginaries,
|
||||
kernel);
|
||||
|
||||
Gpu.Default.For(width, height, in shader);
|
||||
texture.GetData(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -320,27 +296,25 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
[AutoConstructor]
|
||||
internal partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public int maxY;
|
||||
public int maxX;
|
||||
public int kernelLength;
|
||||
|
||||
public ReadWriteTexture2D<Rgba32, Vector4> source;
|
||||
public IReadWriteTexture2D<Vector4> source;
|
||||
public ReadWriteTexture2D<Vector4> reals;
|
||||
public ReadWriteTexture2D<Vector4> imaginaries;
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
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 sourceOffsetColumnBase = ids.X;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase, 0, maxX);
|
||||
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];
|
||||
|
||||
@@ -348,54 +322,17 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
imaginary += factors.Imaginary * color;
|
||||
}
|
||||
|
||||
reals[ids.XY] = real;
|
||||
imaginaries[ids.XY] = imaginary;
|
||||
reals[ThreadIds.XY] = real;
|
||||
imaginaries[ThreadIds.XY] = imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an horizontal 1D complex convolution with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="reals">The source <see cref="ReadWriteTexture2D{T}"/> to read the real results from.</param>
|
||||
/// <param name="imaginaries">The source <see cref="ReadWriteTexture2D{T}"/> to read the imaginary results from.</param>
|
||||
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
|
||||
/// <param name="z">The weight factor for the real component of the complex pixel values.</param>
|
||||
/// <param name="w">The weight factor for the imaginary component of the complex pixel values.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ApplyHorizontalConvolutionAndAccumulatePartials(
|
||||
ReadWriteTexture2D<Vector4> reals,
|
||||
ReadWriteTexture2D<Vector4> imaginaries,
|
||||
ReadWriteTexture2D<Vector4> target,
|
||||
ReadOnlyBuffer<Complex64> kernel,
|
||||
float z,
|
||||
float w)
|
||||
{
|
||||
int height = Source.Height;
|
||||
int width = Source.Width;
|
||||
|
||||
HorizontalConvolutionAndAccumulatePartialsProcessor shader = new(
|
||||
maxY: height - 1,
|
||||
maxX: width - 1,
|
||||
kernelLength: kernel.Length,
|
||||
z,
|
||||
w,
|
||||
reals,
|
||||
imaginaries,
|
||||
target,
|
||||
kernel);
|
||||
|
||||
Gpu.Default.For(width, height, in shader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal partial struct HorizontalConvolutionAndAccumulatePartialsProcessor : IComputeShader
|
||||
{
|
||||
public int maxY;
|
||||
public int maxX;
|
||||
public int kernelLength;
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
@@ -405,17 +342,19 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
public ReadOnlyBuffer<Complex64> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
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 sourceOffsetColumnBase = ids.X;
|
||||
int offsetY = Hlsl.Clamp(ids.Y, 0, maxY);
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase + i - radiusX, 0, maxX);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 sourceReal = reals[offsetX, offsetY];
|
||||
Vector4 sourceImaginary = imaginaries[offsetX, offsetY];
|
||||
Complex64 factors = kernel[i];
|
||||
@@ -424,79 +363,56 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
|
||||
}
|
||||
|
||||
target[ids.XY] += real * z + imaginary * w;
|
||||
target[ThreadIds.XY] += real * z + imaginary * w;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the gamma highlight pass to compute the final pixel values for a target image.
|
||||
/// </summary>
|
||||
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> instance to modify.</param>
|
||||
[Pure]
|
||||
private void ApplyGammaHighlight(ReadWriteTexture2D<Rgba32, Vector4> source)
|
||||
{
|
||||
Gpu.Default.For(source.Height, new GammaHighlightProcessor(source.Width, source));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct GammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly int width;
|
||||
|
||||
public readonly ReadWriteTexture2D<Rgba32, Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
int width = source.Width;
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
Float4 v = source[i, ids.X];
|
||||
Float4 v = source[i, ThreadIds.X];
|
||||
|
||||
v.XYZ = v.XYZ * v.XYZ * v.XYZ;
|
||||
|
||||
source[i, ids.X] = v;
|
||||
source[i, ThreadIds.X] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the inverse gamma highlight pass to compute the final pixel values for a target image.
|
||||
/// </summary>
|
||||
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> instance to read from.</param>
|
||||
/// <param name="target">The target <see cref="ReadWriteTexture2D{T, TPixel}"/> instance to write to.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ApplyInverseGammaExposure(
|
||||
ReadWriteTexture2D<Vector4> source,
|
||||
ReadWriteTexture2D<Rgba32, Vector4> target)
|
||||
{
|
||||
Gpu.Default.For(source.Height, new InverseGammaHighlightProcessor(source.Width, source, target));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the inverse gamma highlight pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct InverseGammaHighlightProcessor : IComputeShader
|
||||
{
|
||||
public readonly int width;
|
||||
|
||||
public readonly ReadWriteTexture2D<Vector4> source;
|
||||
public readonly ReadWriteTexture2D<Rgba32, Vector4> target;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
int width = source.Width;
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
Float4 v = source[i, ids.X];
|
||||
Float4 v = source[i, ThreadIds.X];
|
||||
|
||||
v.XYZ = Hlsl.Clamp(v.XYZ, 0, float.MaxValue);
|
||||
v.XYZ = Hlsl.Pow(v.XYZ, 1 / 3f);
|
||||
|
||||
target[i, ids.X] = v;
|
||||
target[i, ThreadIds.X] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-77
@@ -95,132 +95,76 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
Span<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> firstPassTexture = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<float> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer(Kernel);
|
||||
|
||||
ApplyVerticalConvolution(sourceTexture, firstPassTexture, kernelBuffer);
|
||||
ApplyHorizontalConvolution(firstPassTexture, sourceTexture, kernelBuffer);
|
||||
Gpu.Default.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
|
||||
Gpu.Default.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
|
||||
|
||||
sourceTexture.GetData(span);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a vertical 1D complex convolution with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="source">The source <see cref="ReadWriteTexture2D{T, TPixel}"/> to read data from.</param>
|
||||
/// <param name="target">The target <see cref="ReadWriteTexture2D{T}"/> to write the results to.</param>
|
||||
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ApplyVerticalConvolution(
|
||||
ReadWriteTexture2D<Rgba32, Vector4> source,
|
||||
ReadWriteTexture2D<Vector4> target,
|
||||
ReadOnlyBuffer<float> kernel)
|
||||
{
|
||||
int height = Source.Height;
|
||||
int width = Source.Width;
|
||||
|
||||
VerticalConvolutionProcessor shader = new(
|
||||
maxY: height - 1,
|
||||
maxX: width - 1,
|
||||
kernel.Length,
|
||||
source,
|
||||
target,
|
||||
kernel);
|
||||
|
||||
Gpu.Default.For(width, height, in shader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the vertical convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct VerticalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly int maxY;
|
||||
public readonly int maxX;
|
||||
public readonly int kernelLength;
|
||||
|
||||
public readonly ReadWriteTexture2D<Rgba32, Vector4> source;
|
||||
public readonly ReadWriteTexture2D<Vector4> target;
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
Vector4 result = Vector4.Zero;
|
||||
int maxY = source.Height - 1;
|
||||
int maxX = source.Width - 1;
|
||||
int kernelLength = kernel.Length;
|
||||
int radiusY = kernelLength >> 1;
|
||||
int sourceOffsetColumnBase = ids.X;
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY);
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase, 0, maxX);
|
||||
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[ids.XY] = result;
|
||||
target[ThreadIds.XY] = result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an horizontal 1D complex convolution with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="source">The source <see cref="ReadWriteTexture2D{T}"/> to read data from.</param>
|
||||
/// <param name="target">The target <see cref="ReadWriteTexture2D{T, TPixel}"/> to write the results to.</param>
|
||||
/// <param name="kernel">The <see cref="ReadOnlyBuffer{T}"/> with the values for the current complex kernel.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ApplyHorizontalConvolution(
|
||||
ReadWriteTexture2D<Vector4> source,
|
||||
ReadWriteTexture2D<Rgba32, Vector4> target,
|
||||
ReadOnlyBuffer<float> kernel)
|
||||
{
|
||||
int height = Source.Height;
|
||||
int width = Source.Width;
|
||||
|
||||
HorizontalConvolutionProcessor shader = new(
|
||||
maxY: height - 1,
|
||||
maxX: width - 1,
|
||||
kernel.Length,
|
||||
source,
|
||||
target,
|
||||
kernel);
|
||||
|
||||
Gpu.Default.For(width, height, in shader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kernel for the horizontal convolution pass.
|
||||
/// </summary>
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HorizontalConvolutionProcessor : IComputeShader
|
||||
{
|
||||
public readonly int maxY;
|
||||
public readonly int maxX;
|
||||
public readonly int kernelLength;
|
||||
|
||||
public readonly ReadWriteTexture2D<Vector4> source;
|
||||
public readonly ReadWriteTexture2D<Rgba32, Vector4> target;
|
||||
public readonly IReadWriteTexture2D<Vector4> source;
|
||||
public readonly IReadWriteTexture2D<Vector4> target;
|
||||
public readonly ReadOnlyBuffer<float> kernel;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
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 sourceOffsetColumnBase = ids.X;
|
||||
int offsetY = Hlsl.Clamp(ids.Y, 0, maxY);
|
||||
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
|
||||
|
||||
for (int i = 0; i < kernelLength; i++)
|
||||
{
|
||||
int offsetX = Hlsl.Clamp(sourceOffsetColumnBase + i - radiusX, 0, maxX);
|
||||
int offsetX = Hlsl.Clamp(ThreadIds.X + i - radiusX, 0, maxX);
|
||||
Vector4 color = source[offsetX, offsetY];
|
||||
|
||||
result += kernel[i] * color;
|
||||
}
|
||||
|
||||
target[ids.XY] = result;
|
||||
target[ThreadIds.XY] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace ComputeSharp.Sample
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ThreadIds ids)
|
||||
public void Execute()
|
||||
{
|
||||
buffer[ids.X] *= 2;
|
||||
buffer[ThreadIds.X] *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// An attribute that indicates that a target shader type should get an automatic constructor for all fields.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Struct)]
|
||||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
|
||||
public sealed class AutoConstructorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
|
||||
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>
|
||||
/// 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; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace ComputeSharp
|
||||
/// 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)]
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class ShaderMethodAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute that contains info on the number of 32 bit constants for a given shader.
|
||||
/// </summary>
|
||||
/// <remarks>This attribute is not meant to be directly used by applications using ComputeSharp.</remarks>
|
||||
[AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This attribute is not intended to be used directly by user code")]
|
||||
public sealed class ComputeRoot32BitConstantsAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ComputeRoot32BitConstantsAttribute"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of 32 bit constants for the annotated method.</param>
|
||||
public ComputeRoot32BitConstantsAttribute(int count)
|
||||
{
|
||||
Count = count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of 32 bit constants for the annotated method.
|
||||
/// </summary>
|
||||
internal int Count { get; }
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,24 @@ namespace ComputeSharp.__Internals
|
||||
/// <param name="args">The mapped collection of shader fields.</param>
|
||||
/// <param name="executeMethod">The source code for the <see cref="IComputeShader.Execute"/> method.</param>
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
public IComputeShaderSourceAttribute(string shaderTypeName, string[] types, object[] args, string executeMethod, string[] methods)
|
||||
/// <param name="constants">The collection of discovered constants.</param>
|
||||
/// <param name="sharedBuffers">The collection of group shared buffers.</param>
|
||||
public IComputeShaderSourceAttribute(
|
||||
string shaderTypeName,
|
||||
string[] types,
|
||||
object[] args,
|
||||
string executeMethod,
|
||||
string[] methods,
|
||||
object[] constants,
|
||||
object[] sharedBuffers)
|
||||
{
|
||||
ShaderTypeName = shaderTypeName;
|
||||
Types = types;
|
||||
Fields = args.Cast<string[]>().ToDictionary(static arg => arg[0], static arg => (arg[1], arg[2]));
|
||||
ExecuteMethod = executeMethod;
|
||||
Methods = methods;
|
||||
Constants = constants.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
SharedBuffers = sharedBuffers.Cast<object[]>().ToDictionary(static t => (string)t[0], static t => ((string)t[1], (int?)t[2]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,6 +69,16 @@ namespace ComputeSharp.__Internals
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Methods { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of discovered constants.
|
||||
/// </summary>
|
||||
internal IReadOnlyDictionary<string, string> Constants { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of discovered constants.
|
||||
/// </summary>
|
||||
internal IReadOnlyDictionary<string, (string Type, int? Count)> SharedBuffers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="IComputeShaderSourceAttribute"/> instance for a specified type.
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Exceptions;
|
||||
@@ -35,13 +36,15 @@ namespace ComputeSharp.__Internals
|
||||
/// <param name="types">The collection of custom types.</param>
|
||||
/// <param name="invokeMethod">The source code for the target entry point method.</param>
|
||||
/// <param name="methods">The collection of processed methods.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string[] types, string invokeMethod, string[] methods)
|
||||
/// <param name="constants">The collection of discovered constants.</param>
|
||||
public ShaderMethodSourceAttribute(string methodName, string[] types, string invokeMethod, string[] methods, object[] constants)
|
||||
{
|
||||
this.invokeMethod = invokeMethod;
|
||||
|
||||
MethodName = methodName;
|
||||
Types = types;
|
||||
Methods = methods;
|
||||
Constants = constants.Cast<string[]>().ToDictionary(static c => c[0], static c => c[1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,6 +62,11 @@ namespace ComputeSharp.__Internals
|
||||
/// </summary>
|
||||
internal IReadOnlyCollection<string> Methods { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of discovered constants.
|
||||
/// </summary>
|
||||
internal IReadOnlyDictionary<string, string> Constants { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped source code for the current method.
|
||||
/// </summary>
|
||||
@@ -71,10 +79,10 @@ namespace ComputeSharp.__Internals
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified type.
|
||||
/// Gets the associated <see cref="ShaderMethodSourceAttribute"/> instance for a specified delegate.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The shader type to get the attribute for.</typeparam>
|
||||
/// <returns>The associated <see cref="IComputeShaderSourceAttribute"/> instance for type <typeparamref name="T"/>.</returns>
|
||||
/// <param name="function">The input <see cref="Delegate"/> instance to get info for.</param>
|
||||
/// <returns>The associated <see cref="ShaderMethodSourceAttribute"/> instance for the given delegate.</returns>
|
||||
[Pure]
|
||||
internal static ShaderMethodSourceAttribute GetForDelegate(Delegate function)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<DocumentationFile>ComputeSharp.Core.xml</DocumentationFile>
|
||||
<Description>ComputeSharp.Core</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader within a 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($"{nameof(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($"{nameof(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($"{nameof(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($"{nameof(GroupIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the size info of a given GPU thread group running a compute shader within.
|
||||
/// </summary>
|
||||
public static class GroupSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the total size of the current thread group.
|
||||
/// </summary>
|
||||
public static int Count => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Count)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the X axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the Y axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Y => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the Z axis of the current thread group.
|
||||
/// </summary>
|
||||
public static int Z => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZZ)}");
|
||||
}
|
||||
}
|
||||
+41
-41
@@ -3,203 +3,203 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that indicates the ids of a given GPU thread running a compute shader.
|
||||
/// A <see langword="class"/> that indicates the ids of a given GPU thread running a compute shader.
|
||||
/// </summary>
|
||||
public readonly ref struct ThreadIds
|
||||
public static class ThreadIds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread.
|
||||
/// </summary>
|
||||
public int X => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(X)}");
|
||||
public static int X => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(X)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y id of the current thread.
|
||||
/// </summary>
|
||||
public int Y => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Y)}");
|
||||
public static int Y => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Y)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Z id of the current thread.
|
||||
/// </summary>
|
||||
public int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}");
|
||||
public static int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public Int2 XX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XX)}");
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int2 XY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XY)}");
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int2 XZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZ)}");
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int2 YX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YX)}");
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public Int2 YY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YY)}");
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int2 YZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZ)}");
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int2 ZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZX)}");
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int2 ZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZY)}");
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZ)}");
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public Int3 XXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXX)}");
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 XXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXY)}");
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXZ)}");
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 XYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYX)}");
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 XYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYY)}");
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYZ)}");
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 XZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZX)}");
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 XZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZY)}");
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZZ)}");
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 YXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXX)}");
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 YXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXY)}");
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXZ)}");
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 YYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYX)}");
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public Int3 YYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYY)}");
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYZ)}");
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 YZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZX)}");
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 YZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZY)}");
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZZ)}");
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXX)}");
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXY)}");
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXZ)}");
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYX)}");
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYY)}");
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYZ)}");
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZX)}");
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZY)}");
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}");
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that indicates the ids of a given dispatch warp (a group of threads).
|
||||
/// </summary>
|
||||
public static class WarpIds
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the X id of the current thread with respect to the dispatch group.
|
||||
/// </summary>
|
||||
public static int X => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{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($"{nameof(WarpIds)}.{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($"{nameof(WarpIds)}.{nameof(Z)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int2"/> value with the <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int2"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="X"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Y"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="X"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Y"/> and <see cref="Z"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYZ)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="X"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZX)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/>, <see cref="Z"/> and <see cref="Y"/> values.
|
||||
/// </summary>
|
||||
public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZY)}");
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Int3"/> value with the <see cref="Z"/> value for all components.
|
||||
/// </summary>
|
||||
public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZZ)}");
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
/// <summary>
|
||||
/// Executes the current compute shader.
|
||||
/// </summary>
|
||||
/// <param name="ids">The <see cref="ThreadIds"/> value with the current execution indices.</param>
|
||||
void Execute(ThreadIds ids);
|
||||
void Execute();
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,28 @@ namespace ComputeSharp
|
||||
[Pure]
|
||||
public static bool All(Float4 x) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(All)}({nameof(Float4)})");
|
||||
|
||||
/// <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.
|
||||
/// </remarks>
|
||||
[PreserveMemberName]
|
||||
public static void AllMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(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.
|
||||
/// </remarks>
|
||||
[PreserveMemberName]
|
||||
public static void AllMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(AllMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Determines if any components of the specified value are non-zero.
|
||||
/// </summary>
|
||||
@@ -616,6 +638,18 @@ namespace ComputeSharp
|
||||
[Pure]
|
||||
public static Float3 Degrees(Float4 x) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(Degrees)}({nameof(Float4)})");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all device memory accesses have been completed.
|
||||
/// </summary>
|
||||
[PreserveMemberName]
|
||||
public static void DeviceMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(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>
|
||||
[PreserveMemberName]
|
||||
public static void DeviceMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(DeviceMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Returns a distance scalar between two <see cref="Float2"/> values.
|
||||
/// </summary>
|
||||
@@ -870,6 +904,18 @@ namespace ComputeSharp
|
||||
[Pure]
|
||||
public static Float4 Frexp(Float4 x, out Float4 exp) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(Frexp)}({nameof(Float4)},{nameof(Float4)})");
|
||||
|
||||
/// <summary>
|
||||
/// Blocks execution of all threads in a group until all group shared accesses have been completed.
|
||||
/// </summary>
|
||||
[PreserveMemberName]
|
||||
public static void GroupMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(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>
|
||||
[PreserveMemberName]
|
||||
public static void GroupMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(GroupMemoryBarrierWithGroupSync)}()");
|
||||
|
||||
/// <summary>
|
||||
/// Performs a guaranteed atomic add of a value to a destination.
|
||||
/// </summary>
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="x">The x-component</param>
|
||||
/// <param name="y">The y-component</param>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg16(byte r, byte g)
|
||||
{
|
||||
R = r;
|
||||
@@ -73,7 +73,7 @@ namespace ComputeSharp
|
||||
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);
|
||||
public override readonly bool Equals(object? obj) => obj is Rg16 rgba32 && Equals(rgba32);
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rg32"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="x">The x-component</param>
|
||||
/// <param name="y">The y-component</param>
|
||||
/// <param name="r">The red component.</param>
|
||||
/// <param name="g">The green component.</param>
|
||||
public Rg32(ushort r, ushort g)
|
||||
{
|
||||
R = r;
|
||||
|
||||
@@ -567,13 +567,13 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Float3"/> value to a <see cref="Vector3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Float3"/> value to cast.</param>
|
||||
/// <param name="xyz">The input <see cref="Float3"/> value to cast.</param>
|
||||
public static unsafe implicit operator Vector3(Float3 xyz) => *(Vector3*)&xyz;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Vector3"/> value to a <see cref="Float3"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Vector3"/> value to cast.</param>
|
||||
/// <param name="xyz">The input <see cref="Vector3"/> value to cast.</param>
|
||||
public static unsafe implicit operator Float3(Vector3 xyz) => *(Float3*)&xyz;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3972,13 +3972,13 @@ namespace ComputeSharp
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Float4"/> value to a <see cref="Vector4"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Float4"/> value to cast.</param>
|
||||
/// <param name="xyzw">The input <see cref="Float4"/> value to cast.</param>
|
||||
public static unsafe implicit operator Vector4(Float4 xyzw) => *(Vector4*)&xyzw;
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Vector4"/> value to a <see cref="Float4"/> one.
|
||||
/// </summary>
|
||||
/// <param name="xy">The input <see cref="Vector4"/> value to cast.</param>
|
||||
/// <param name="xyzw">The input <see cref="Vector4"/> value to cast.</param>
|
||||
public static unsafe implicit operator Float4(Vector4 xyzw) => *(Float4*)&xyzw;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
namespace ComputeSharp.Graphics.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// A command list to set and execute operaations on the GPU.
|
||||
/// A command list to set and execute operations on the GPU.
|
||||
/// </summary>
|
||||
internal unsafe ref struct CommandList
|
||||
{
|
||||
@@ -75,7 +75,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ID3D12CommandList** GetD3D12CommandListAddressOf()
|
||||
{
|
||||
return this.d3D12GraphicsCommandList.Upcast<ID3D12GraphicsCommandList, ID3D12CommandList>().GetAddressOf();
|
||||
return (ID3D12CommandList**)this.d3D12GraphicsCommandList.GetAddressOf();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,6 +120,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a texture) to read from.</param>
|
||||
/// <param name="x">The horizontal offset in the destination texture.</param>
|
||||
/// <param name="y">The vertical offset in the destination texture.</param>
|
||||
/// <param name="z">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="width">The width of the memory area to read from.</param>
|
||||
/// <param name="height">The height of the memory area to read from.</param>
|
||||
/// <param name="depth">The depth of the memory area to read from.</param>
|
||||
@@ -153,6 +154,18 @@ namespace ComputeSharp.Graphics.Commands
|
||||
this.d3D12GraphicsCommandList.Get()->ResourceBarrier(1, &d3D12ResourceBarrier);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds an input constant buffer to the first root parameter.
|
||||
/// </summary>
|
||||
/// <param name="data">The input buffer with the constant data to bind.</param>
|
||||
public readonly unsafe void SetComputeRoot32BitConstants(ReadOnlySpan<uint> data)
|
||||
{
|
||||
fixed (uint* p = data)
|
||||
{
|
||||
this.d3D12GraphicsCommandList.Get()->SetComputeRoot32BitConstants(0, (uint)data.Length, p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds an input <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value to a specified root parameter.
|
||||
/// </summary>
|
||||
@@ -166,7 +179,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
/// <summary>
|
||||
/// Sets a given <see cref="PipelineData"/> object ready to be executed.
|
||||
/// </summary>
|
||||
/// <param name="pipelineState">The input <see cref="PipelineData"/> to setup.</param>
|
||||
/// <param name="pipelineData">The input <see cref="PipelineData"/> to setup.</param>
|
||||
public readonly void SetPipelineData(PipelineData pipelineData)
|
||||
{
|
||||
this.d3D12GraphicsCommandList.Get()->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using System;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using System;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace ComputeSharp.Graphics.Commands.Interop
|
||||
/// Rents a new CPU and GPU handle pair to use in a memory buffer.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The resulting <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The resulting <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The resulting <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Rent(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
@@ -103,7 +103,7 @@ namespace ComputeSharp.Graphics.Commands.Interop
|
||||
/// Returns a CPU and GPU handle pair for later use.
|
||||
/// </summary>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The returned <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The returned <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
/// <param name="d3D12GpuDescriptorHandle">The returned <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> value.</param>
|
||||
public void Return(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Commands
|
||||
@@ -19,11 +19,10 @@ namespace ComputeSharp.Graphics.Commands
|
||||
private ComPtr<ID3D12PipelineState> d3D12PipelineState;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PipelineState"/> instance with the specified parameters.
|
||||
/// Creates a new <see cref="PipelineData"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> to use.</param>
|
||||
/// <param name="rootSignature">The <see cref="ID3D12RootSignature"/> value for the current shader.</param>
|
||||
/// <param name="computeShader">The bytecode for the compute shader to run.</param>
|
||||
/// <param name="d3D12RootSignature">The <see cref="ID3D12RootSignature"/> value for the current shader.</param>
|
||||
/// <param name="d3D12PipelineState">The compiled pipeline state to reuse for the current shader.</param>
|
||||
public PipelineData(ComPtr<ID3D12RootSignature> d3D12RootSignature, ComPtr<ID3D12PipelineState> d3D12PipelineState)
|
||||
{
|
||||
this.d3D12RootSignature = d3D12RootSignature;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<DocumentationFile>ComputeSharp.Graphics.xml</DocumentationFile>
|
||||
<Description>ComputeSharp.Graphics</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit" Version="7.0.0-preview4" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.19041-beta2-449553204" />
|
||||
<PackageReference Include="Microsoft.Toolkit" Version="7.0.0-preview4" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.19041-beta2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources;
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using ComputeSharp.Graphics;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
@@ -36,12 +35,12 @@ namespace ComputeSharp.Exceptions
|
||||
|
||||
builder.AppendLine(rank switch
|
||||
{
|
||||
2 => $"{nameof(GraphicsDevice.IsTexture2DSupportedForType)}<T>().",
|
||||
3 => $"{nameof(GraphicsDevice.IsTexture3DSupportedForType)}<T>().",
|
||||
2 => $"{nameof(GraphicsDevice.IsReadOnlyTexture2DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture2DSupportedForType)}<T>().",
|
||||
3 => $"{nameof(GraphicsDevice.IsReadOnlyTexture3DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture3DSupportedForType)}<T>().",
|
||||
_ => ThrowHelper.ThrowArgumentException<string>("Invalid texture rank")
|
||||
});
|
||||
|
||||
builder.AppendLine($"As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
|
||||
builder.Append("As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
|
||||
builder.ToString();
|
||||
|
||||
return new(builder.ToString());
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace ComputeSharp.Core.Extensions
|
||||
/// <summary>
|
||||
/// Helper methods for working with the <see cref="ComPtr{T}"/> type.
|
||||
/// </summary>
|
||||
public static class ComPtrExtensions
|
||||
internal static class ComPtrExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reinterprets the current <see cref="ComPtr{T}"/> instance as one of type <see cref="IUnknown"/>.
|
||||
@@ -59,25 +59,5 @@ namespace ComputeSharp.Core.Extensions
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upcasts the current <see cref="ComPtr{T}"/> instance as a base type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the current <see cref="ComPtr{T}"/> instance.</typeparam>
|
||||
/// <typeparam name="U">The type to cast the input instance to.</typeparam>
|
||||
/// <param name="ptr">The input <see cref="ComPtr{T}"/> instance to upcast.</param>
|
||||
/// <returns>A <see cref="ComPtr{T}"/> instance of type <typeparamref name="U"/>.</returns>
|
||||
/// <remarks>
|
||||
/// This method is meant to be used in a chained expression and it does not increment the reference
|
||||
/// count for the input pointer. Do not expose the return value of this extension to consumers.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ref readonly ComPtr<U> Upcast<T, U>(this in ComPtr<T> ptr)
|
||||
where T : unmanaged
|
||||
where U : unmanaged
|
||||
{
|
||||
return ref Unsafe.As<ComPtr<T>, ComPtr<U>>(ref Unsafe.AsRef(in ptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_QUEUE_FLAGS;
|
||||
@@ -101,15 +101,18 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="resourceType">The resource type currently in use.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="sizeInBytes">The size in bytes of the current buffer.</param>
|
||||
/// <param name="isCacheCoherentUMA">Indicates whether or not the current device has a cache coherent UMA architecture.</param>
|
||||
/// <returns>An <see cref="ID3D12Resource"/> reference for the current buffer.</returns>
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
ResourceType resourceType,
|
||||
AllocationMode allocationMode,
|
||||
ulong sizeInBytes,
|
||||
bool isCacheCoherentUMA)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
(D3D12_HEAP_TYPE d3D12HeapType,
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
|
||||
D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
|
||||
@@ -145,7 +148,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
d3D12HeapFlags,
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -160,6 +163,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="resourceType">The resource type currently in use.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
|
||||
/// <param name="width">The width of the texture resource.</param>
|
||||
/// <param name="height">The height of the texture resource.</param>
|
||||
@@ -169,12 +173,14 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
ResourceType resourceType,
|
||||
AllocationMode allocationMode,
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
uint width,
|
||||
uint height,
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
|
||||
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
|
||||
@@ -207,7 +213,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
d3D12HeapFlags,
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -222,6 +228,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="resourceType">The resource type currently in use.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
|
||||
/// <param name="width">The width of the texture resource.</param>
|
||||
/// <param name="height">The height of the texture resource.</param>
|
||||
@@ -232,6 +239,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
ResourceType resourceType,
|
||||
AllocationMode allocationMode,
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
uint width,
|
||||
uint height,
|
||||
@@ -239,6 +247,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
|
||||
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
|
||||
@@ -271,7 +280,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
d3D12HeapFlags,
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -423,6 +432,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the command list.</param>
|
||||
/// <param name="d3D12CommandListType">The type of command list to create.</param>
|
||||
/// <param name="d3D12CommandAllocator">The command allocator to use to create the command list.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12GraphicsCommandList"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the command list fails.</exception>
|
||||
public static ComPtr<ID3D12GraphicsCommandList> CreateCommandList(
|
||||
@@ -504,7 +514,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &d3D12FeatureDataFormatSupport, (uint)sizeof(D3D12_FEATURE_DATA_FORMAT_SUPPORT)).Assert();
|
||||
|
||||
return (d3D12FeatureDataFormatSupport.Support1 & d3D12FormatSupport1) != 0;
|
||||
return (d3D12FeatureDataFormatSupport.Support1 & d3D12FormatSupport1) == d3D12FormatSupport1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
/// <param name="z">The depthwise offset in the destination texture.</param>
|
||||
/// <param name="d3D12ResourceSource">The source <see cref="ID3D12Resource"/> (a buffer) to read from.</param>
|
||||
/// <param name="d3D12PlacedSubresourceFootprintSource">The <see cref="D3D12_PLACED_SUBRESOURCE_FOOTPRINT"/> value describing <paramref name="d3D12ResourceSource"/>.</param>
|
||||
|
||||
public static void CopyTextureRegion(
|
||||
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
|
||||
ID3D12Resource* d3D12ResourceDestination,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Buffers.Interop;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace ComputeSharp.Graphics.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that provides extension methods for the <see cref="Type"/> type.
|
||||
/// </summary>
|
||||
internal static class TypeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known types to display string.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<Type, string> KnownTypes = new Dictionary<Type, string>
|
||||
{
|
||||
[typeof(bool)] = "bool",
|
||||
[typeof(int)] = "int",
|
||||
[typeof(uint)] = "uint",
|
||||
[typeof(float)] = "float",
|
||||
[typeof(double)] = "double"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a friendly display <see langword="string"/> for the input type.
|
||||
/// </summary>
|
||||
/// <param name="type">The input type to analyze.</param>
|
||||
[Pure]
|
||||
public static string ToFriendlyString(this Type type)
|
||||
{
|
||||
// Array types of arbitrary rank
|
||||
if (type.IsArray)
|
||||
{
|
||||
int rank = type.GetArrayRank();
|
||||
return $"{type.GetElementType()!.ToFriendlyString()}[{new string(Enumerable.Repeat(',', rank - 1).ToArray())}]";
|
||||
}
|
||||
|
||||
// Non generic types
|
||||
string? name;
|
||||
if (type.GetGenericArguments().Length == 0) return KnownTypes.TryGetValue(type, out name) ? name : type.Name;
|
||||
|
||||
// Generic types
|
||||
Type[] genericArguments = type.GetGenericArguments();
|
||||
string typeDefeninition = KnownTypes.TryGetValue(type, out name) ? name : type.Name;
|
||||
string polishedName = typeDefeninition.Substring(0, typeDefeninition.IndexOf("`"));
|
||||
return $"{polishedName}<{string.Join(",", genericArguments.Select(ToFriendlyString))}>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
@@ -14,7 +14,7 @@ using static TerraFX.Interop.D3D12_FEATURE;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
using static TerraFX.Interop.DXGI_ADAPTER_FLAG;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that represents a DX12-compatible GPU device that can be used to run compute shaders.
|
||||
@@ -152,13 +152,13 @@ namespace ComputeSharp.Graphics
|
||||
internal bool IsCacheCoherentUMA { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current device supports the creation of <see cref="Buffers.Abstract.Texture2D{T}"/>
|
||||
/// resources for a specified type <typeparamref name="T"/>.
|
||||
/// Checks whether the current device supports the creation of
|
||||
/// <see cref="ReadOnlyTexture2D{T}"/> resources for a specified type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to check support for.</typeparam>
|
||||
/// <returns>Whether <see cref="Buffers.Abstract.Texture2D{T}"/> instances can be created by the current device.</returns>
|
||||
/// <returns>Whether <see cref="ReadOnlyTexture2D{T}"/> instances can be created by the current device.</returns>
|
||||
[Pure]
|
||||
public bool IsTexture2DSupportedForType<T>()
|
||||
public bool IsReadOnlyTexture2DSupportedForType<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
@@ -167,13 +167,30 @@ namespace ComputeSharp.Graphics
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current device supports the creation of <see cref="Buffers.Abstract.Texture3D{T}"/>
|
||||
/// resources for a specified type <typeparamref name="T"/>.
|
||||
/// Checks whether the current device supports the creation of
|
||||
/// <see cref="ReadWriteTexture2D{T}"/> resources for a specified type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to check support for.</typeparam>
|
||||
/// <returns>Whether <see cref="Buffers.Abstract.Texture3D{T}"/> instances can be created by the current device.</returns>
|
||||
/// <returns>Whether <see cref="ReadWriteTexture2D{T}"/> instances can be created by the current device.</returns>
|
||||
[Pure]
|
||||
public bool IsTexture3DSupportedForType<T>()
|
||||
public bool IsReadWriteTexture2DSupportedForType<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current device supports the creation of
|
||||
/// <see cref="ReadOnlyTexture3D{T}"/> resources for a specified type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to check support for.</typeparam>
|
||||
/// <returns>Whether <see cref="ReadOnlyTexture3D{T}"/> instances can be created by the current device.</returns>
|
||||
[Pure]
|
||||
public bool IsReadOnlyTexture3DSupportedForType<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
@@ -181,7 +198,24 @@ namespace ComputeSharp.Graphics
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE3D);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Allocate"/>
|
||||
/// <summary>
|
||||
/// Checks whether the current device supports the creation of
|
||||
/// <see cref="ReadWriteTexture3D{T}"/> resources for a specified type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to check support for.</typeparam>
|
||||
/// <returns>Whether <see cref="ReadWriteTexture3D{T}"/> instances can be created by the current device.</returns>
|
||||
[Pure]
|
||||
public bool IsReadWriteTexture3DSupportedForType<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
return this.d3D12Device.Get()->IsDxgiFormatSupported(
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12DescriptorHandleAllocator.Rent"/>
|
||||
internal void RentShaderResourceViewDescriptorHandles(
|
||||
out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle,
|
||||
out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.DXGI_ADAPTER_FLAG;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A type containing info on a given DX12.0 device that can be used.
|
||||
@@ -11,7 +11,7 @@ namespace ComputeSharp.Graphics
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsDeviceInfo"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="description">The available info for the associate device.</param>
|
||||
/// <param name="dxgiDescription1">The available info for the associated device.</param>
|
||||
internal unsafe GraphicsDeviceInfo(DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
using HRESULT = System.Int32;
|
||||
|
||||
@@ -174,7 +174,6 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// Copies the content of a source memory area to the 3D area pointed by an input pointer.
|
||||
/// The destination memory area has padding in each row, while the source does not.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to read.</typeparam>
|
||||
/// <param name="source">The source memory area to read from.</param>
|
||||
/// <param name="destination">The pointer that indicates the 3D memory area to write to.</param>
|
||||
/// <param name="height">The height of the 3D memory area to write to.</param>
|
||||
@@ -219,7 +218,6 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// Copies a 3D memory area pointed by a pointer value to a target memory area.
|
||||
/// The source memory area has padding in each row, while the target does not.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values to read.</typeparam>
|
||||
/// <param name="source">The pointer that indicates the memory area to read from.</param>
|
||||
/// <param name="height">The height of the 3D memory area to read.</param>
|
||||
/// <param name="depth">The depth of the 3D memory area to read.</param>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Resources;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.__Internals
|
||||
@@ -14,11 +14,26 @@ namespace ComputeSharp.__Internals
|
||||
[Obsolete("This type is not intended to be used directly by user code")]
|
||||
public static class GraphicsResourceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface for non-generic graphics resource types.
|
||||
/// </summary>
|
||||
internal interface IGraphicsResource
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the resource.</returns>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input buffer.</typeparam>
|
||||
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the buffer.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -32,37 +47,171 @@ namespace ComputeSharp.__Internals
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input <see cref="Texture2D{T}"/> instance to check.</param>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadOnlyTexture2D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(Texture2D<T> buffer, GraphicsDevice device)
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
buffer.ThrowIfDisposed();
|
||||
buffer.ThrowIfDeviceMismatch(device);
|
||||
texture.ThrowIfDisposed();
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle));
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input <see cref="Texture3D{T}"/> instance to check.</param>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(Texture3D<T> buffer, GraphicsDevice device)
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
buffer.ThrowIfDisposed();
|
||||
buffer.ThrowIfDeviceMismatch(device);
|
||||
texture.ThrowIfDisposed();
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in buffer.D3D12GpuDescriptorHandle));
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyTexture2D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyTexture2D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadWriteTexture2D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteTexture2D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadOnlyTexture3D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.ThrowIfDisposed();
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
texture.ThrowIfDisposed();
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
return Unsafe.As<D3D12_GPU_DESCRIPTOR_HANDLE, ulong>(ref Unsafe.AsRef(in texture.D3D12GpuDescriptorHandle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyTexture3D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyTexture3D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadWriteTexture3D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteTexture3D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowArgumentException<ulong>("The input texture is not a valid instance");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.Graphics.Interop
|
||||
namespace ComputeSharp.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for a <see cref="IDisposable"/> class.
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// A locally unique identifier for a graphics device.
|
||||
|
||||
+12
-10
@@ -2,14 +2,14 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
namespace ComputeSharp.Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed buffer stored on GPU memory.
|
||||
@@ -26,12 +26,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
/// <remarks>This field is dynamically accessed when loading shader dispatch data.</remarks>
|
||||
internal readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
@@ -46,7 +45,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <param name="length">The number of items to store in the current buffer.</param>
|
||||
/// <param name="elementSizeInBytes">The size in bytes of each buffer item (including padding, if any).</param>
|
||||
/// <param name="resourceType">The resource type for the current buffer.</param>
|
||||
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
private protected Buffer(GraphicsDevice device, int length, uint elementSizeInBytes, ResourceType resourceType, AllocationMode allocationMode)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
GraphicsDevice = device;
|
||||
Length = length;
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(resourceType, allocationMode, (ulong)SizeInBytes, device.IsCacheCoherentUMA);
|
||||
|
||||
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> associated with the current instance.
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
@@ -138,9 +138,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
|
||||
try
|
||||
{
|
||||
source.GetData(ref MemoryMarshal.GetArrayDataReference(array), source.Length, 0);
|
||||
ref T r0 = ref MemoryMarshal.GetArrayDataReference(array);
|
||||
|
||||
SetData(ref MemoryMarshal.GetArrayDataReference(array), source.Length, 0);
|
||||
source.GetData(ref r0, source.Length, 0);
|
||||
|
||||
SetData(ref r0, source.Length, 0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
+9
-8
@@ -1,13 +1,13 @@
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Interop;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
namespace ComputeSharp.Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed structured buffer stored on GPU memory.
|
||||
@@ -22,8 +22,9 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="length">The number of items to store in the current buffer.</param>
|
||||
/// <param name="resourceType">The buffer type for the current buffer.</param>
|
||||
private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType)
|
||||
: base(device, length, (uint)sizeof(T), resourceType)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType, AllocationMode allocationMode)
|
||||
: base(device, length, (uint)sizeof(T), resourceType, allocationMode)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize, false);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, (ulong)byteSize, false);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY))
|
||||
{
|
||||
@@ -109,7 +110,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
byteOffset = (nint)offset * sizeof(T),
|
||||
byteSize = size * sizeof(T);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize, false);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, (ulong)byteSize, false);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
+27
-14
@@ -1,27 +1,29 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Interop;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
|
||||
using static TerraFX.Interop.D3D12_SRV_DIMENSION;
|
||||
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed 2D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public unsafe abstract class Texture2D<T> : NativeObject
|
||||
public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,12 +34,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
/// <remarks>This field is dynamically accessed when loading shader dispatch data.</remarks>
|
||||
internal readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
@@ -53,18 +54,20 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="Graphics.GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="device">The <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="resourceType">The resource type for the current texture.</param>
|
||||
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
|
||||
private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
Guard.IsBetweenOrEqualTo(width, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width));
|
||||
Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height));
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
|
||||
}
|
||||
@@ -75,6 +78,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
|
||||
resourceType,
|
||||
allocationMode,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
@@ -99,7 +103,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> associated with the current instance.
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
@@ -149,7 +153,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
|
||||
{
|
||||
@@ -221,7 +225,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
@@ -281,5 +285,14 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
GraphicsDeviceMismatchException.Throw(this, device);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12GpuDescriptorHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-14
@@ -1,27 +1,29 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Interop;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
|
||||
using static TerraFX.Interop.D3D12_SRV_DIMENSION;
|
||||
using static TerraFX.Interop.D3D12_UAV_DIMENSION;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed 3D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public unsafe abstract class Texture3D<T> : NativeObject
|
||||
public unsafe abstract class Texture3D<T> : NativeObject, GraphicsResourceHelper.IGraphicsResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,12 +34,11 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
internal readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
private readonly D3D12_CPU_DESCRIPTOR_HANDLE D3D12CpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instance for the current resource.
|
||||
/// </summary>
|
||||
/// <remarks>This field is dynamically accessed when loading shader dispatch data.</remarks>
|
||||
internal readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
|
||||
|
||||
/// <summary>
|
||||
@@ -53,12 +54,14 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Texture3D{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="Graphics.GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="device">The <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="resourceType">The resource type for the current texture.</param>
|
||||
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <param name="d3D12FormatSupport">The format support for the current texture type.</param>
|
||||
private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport)
|
||||
{
|
||||
device.ThrowIfDisposed();
|
||||
|
||||
@@ -66,7 +69,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height));
|
||||
Guard.IsBetweenOrEqualTo(depth, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth));
|
||||
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), D3D12_FORMAT_SUPPORT1_TEXTURE2D))
|
||||
if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType<T>(), d3D12FormatSupport))
|
||||
{
|
||||
UnsupportedTextureTypeException.ThrowForTexture2D<T>();
|
||||
}
|
||||
@@ -78,6 +81,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
|
||||
this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
|
||||
resourceType,
|
||||
allocationMode,
|
||||
DXGIFormatHelper.GetForType<T>(),
|
||||
(uint)width,
|
||||
(uint)height,
|
||||
@@ -103,7 +107,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Graphics.GraphicsDevice"/> associated with the current instance.
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
@@ -163,7 +167,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
|
||||
{
|
||||
@@ -242,7 +246,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
out ulong rowSizeInBytes,
|
||||
out ulong totalSizeInBytes);
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, AllocationMode.Default, totalSizeInBytes, GraphicsDevice.IsCacheCoherentUMA);
|
||||
|
||||
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
|
||||
fixed (void* sourcePointer = &source)
|
||||
@@ -304,5 +308,14 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
GraphicsDeviceMismatchException.Throw(this, device);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12GpuDescriptorHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -3,14 +3,13 @@ using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Interop;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
@@ -36,8 +35,9 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="length">The number of items to store in the current buffer.</param>
|
||||
internal ConstantBuffer(GraphicsDevice device, int length)
|
||||
: base(device, length, (uint)GetPaddedSize(), ResourceType.Constant)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ConstantBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
|
||||
: base(device, length, (uint)GetPaddedSize(), ResourceType.Constant, allocationMode)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="enum"/> that indicates a mode to use when allocating resources.
|
||||
/// </summary>
|
||||
public enum AllocationMode
|
||||
{
|
||||
/// <summary>
|
||||
/// The default allocation mode for graphics resources. Allocated buffers are not explicitly cleared when created.
|
||||
/// They can still be cleared for security reasons in some situations, but this step will be skipped whenever possible.
|
||||
/// As such, always make sure not to read directly to buffers created this way before writing data to them first.
|
||||
/// </summary>
|
||||
Default,
|
||||
|
||||
/// <summary>
|
||||
/// Clear allocated buffers when creating them.
|
||||
/// </summary>
|
||||
Clear
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace ComputeSharp.Graphics.Buffers.Enums
|
||||
namespace ComputeSharp.Graphics.Resources.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="enum"/> that indicates the type of a given HLSL resource.
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface representing a typed readonly 2D texture containing normalized pixel data stored on GPU memory.
|
||||
/// This interface can only be used to wrap <see cref="ReadOnlyTexture2D{T, TPixel}"/> instances.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
|
||||
public interface IReadOnlyTexture2D<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the width of the current texture.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the current texture.
|
||||
/// </summary>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public TPixel this[int x, int y] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="xy">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public TPixel this[Int2 xy] { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface representing a typed readonly 3D texture containing normalized pixel data stored on GPU memory.
|
||||
/// This interface can only be used to wrap <see cref="ReadOnlyTexture3D{T, TPixel}"/> instances.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
|
||||
public interface IReadOnlyTexture3D<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the width of the current texture.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the current texture.
|
||||
/// </summary>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the depth of the current texture.
|
||||
/// </summary>
|
||||
public int Depth { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <param name="z">The depthwise offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public TPixel this[int x, int y, int z] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public TPixel this[Int3 xyz] { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory.
|
||||
/// This interface can only be used to wrap <see cref="ReadWriteTexture2D{T, TPixel}"/> instances.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
|
||||
public interface IReadWriteTexture2D<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the width of the current texture.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the current texture.
|
||||
/// </summary>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public ref TPixel this[int x, int y] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="xy">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public ref TPixel this[Int2 xy] { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace ComputeSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface representing a typed writeable 2D texture containing normalized pixel data stored on GPU memory.
|
||||
/// This interface can only be used to wrap <see cref="ReadWriteTexture3D{T, TPixel}"/> instances.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized pixels used on the GPU side.</typeparam>
|
||||
public interface IReadWriteTexture3D<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the width of the current texture.
|
||||
/// </summary>
|
||||
public int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the current texture.
|
||||
/// </summary>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the depth of the current texture.
|
||||
/// </summary>
|
||||
public int Depth { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <param name="z">The depthwise offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public ref TPixel this[int x, int y, int z] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public ref TPixel this[Int3 xyz] { get; }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Interop
|
||||
namespace ComputeSharp.Graphics.Resources.Interop
|
||||
{
|
||||
/// <summary>
|
||||
/// A type representing a mapped memory resource.
|
||||
+6
-6
@@ -1,9 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -21,8 +20,9 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="length">The number of items to store in the current buffer.</param>
|
||||
internal ReadOnlyBuffer(GraphicsDevice device, int length)
|
||||
: base(device, length, ResourceType.ReadOnly)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadOnlyBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
|
||||
: base(device, length, ResourceType.ReadOnly, allocationMode)
|
||||
{
|
||||
}
|
||||
|
||||
+10
-18
@@ -1,10 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
|
||||
[DebuggerDisplay("{ToString(),raw}")]
|
||||
public sealed class ReadOnlyTexture2D<T, TPixel> : Texture2D<T>
|
||||
public sealed class ReadOnlyTexture2D<T, TPixel> : Texture2D<T>, IReadOnlyTexture2D<TPixel>
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
@@ -27,24 +27,16 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height)
|
||||
: base(device, width, height, ResourceType.ReadOnly)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
|
||||
: base(device, width, height, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D<T, TPixel>)}<T>[int,int]");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="xy">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D<T,TPixel>)}<T>[Int2]");
|
||||
|
||||
/// <inheritdoc/>
|
||||
+7
-6
@@ -1,9 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -22,8 +22,9 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height)
|
||||
: base(device, width, height, ResourceType.ReadOnly)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadOnlyTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
|
||||
: base(device, width, height, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D)
|
||||
{
|
||||
}
|
||||
|
||||
+10
-19
@@ -1,10 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
|
||||
[DebuggerDisplay("{ToString(),raw}")]
|
||||
public sealed class ReadOnlyTexture3D<T, TPixel> : Texture3D<T>
|
||||
public sealed class ReadOnlyTexture3D<T, TPixel> : Texture3D<T>, IReadOnlyTexture3D<TPixel>
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
@@ -28,25 +28,16 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth)
|
||||
: base(device, width, height, depth, ResourceType.ReadOnly)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
|
||||
: base(device, width, height, depth, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <param name="y">The depthwise offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D<T, TPixel>)}<T>[int,int,int]");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D<T, TPixel>)}<T>[Int3]");
|
||||
|
||||
/// <inheritdoc/>
|
||||
+8
-7
@@ -1,9 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -23,8 +23,9 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth)
|
||||
: base(device, width, height, depth, ResourceType.ReadOnly)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
|
||||
: base(device, width, height, depth, ResourceType.ReadOnly, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <param name="y">The depthwise offset of the value to get.</param>
|
||||
/// <param name="z">The depthwise offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
public T this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D<T>)}<T>[int,int,int]");
|
||||
|
||||
+6
-6
@@ -1,9 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -21,8 +20,9 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="length">The number of items to store in the current buffer.</param>
|
||||
internal ReadWriteBuffer(GraphicsDevice device, int length)
|
||||
: base(device, length, ResourceType.ReadWrite)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadWriteBuffer(GraphicsDevice device, int length, AllocationMode allocationMode)
|
||||
: base(device, length, ResourceType.ReadWrite, allocationMode)
|
||||
{
|
||||
}
|
||||
|
||||
+10
-18
@@ -1,10 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
|
||||
[DebuggerDisplay("{ToString(),raw}")]
|
||||
public sealed class ReadWriteTexture2D<T, TPixel> : Texture2D<T>
|
||||
public sealed class ReadWriteTexture2D<T, TPixel> : Texture2D<T>, IReadWriteTexture2D<TPixel>
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
@@ -27,24 +27,16 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height)
|
||||
: base(device, width, height, ResourceType.ReadWrite)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
|
||||
: base(device, width, height, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public ref TPixel this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D<T, TPixel>)}<T>[int,int]");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="xy">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public ref TPixel this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D<T, TPixel>)}<T>[Int2]");
|
||||
|
||||
/// <inheritdoc/>
|
||||
+7
-6
@@ -1,9 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -22,8 +22,9 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height)
|
||||
: base(device, width, height, ResourceType.ReadWrite)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadWriteTexture2D(GraphicsDevice device, int width, int height, AllocationMode allocationMode)
|
||||
: base(device, width, height, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
|
||||
{
|
||||
}
|
||||
|
||||
+10
-19
@@ -1,10 +1,10 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
[DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
|
||||
[DebuggerDisplay("{ToString(),raw}")]
|
||||
public sealed class ReadWriteTexture3D<T, TPixel> : Texture3D<T>
|
||||
public sealed class ReadWriteTexture3D<T, TPixel> : Texture3D<T>, IReadWriteTexture3D<TPixel>
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
@@ -28,25 +28,16 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth)
|
||||
: base(device, width, height, depth, ResourceType.ReadWrite)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
|
||||
: base(device, width, height, depth, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal offset of the value to get.</param>
|
||||
/// <param name="y">The vertical offset of the value to get.</param>
|
||||
/// <param name="z">The depthwise offset of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public ref TPixel this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D<T, TPixel>)}<T>[int,int,int]");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single <typeparamref name="TPixel"/> value from the current writeable texture.
|
||||
/// </summary>
|
||||
/// <param name="xyz">The coordinates of the value to get.</param>
|
||||
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
|
||||
/// <inheritdoc/>
|
||||
public ref TPixel this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D<T, TPixel>)}<T>[Int3]");
|
||||
|
||||
/// <inheritdoc/>
|
||||
+7
-6
@@ -1,9 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers.Enums;
|
||||
using ComputeSharp.Graphics.Buffers.Views;
|
||||
using ComputeSharp.Graphics.Resources.Enums;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Resources.Views;
|
||||
using static TerraFX.Interop.D3D12_FORMAT_SUPPORT1;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -23,8 +23,9 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth)
|
||||
: base(device, width, height, depth, ResourceType.ReadWrite)
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode)
|
||||
: base(device, width, height, depth, ResourceType.ReadWrite, allocationMode, D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
|
||||
{
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Views
|
||||
namespace ComputeSharp.Resources.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// A debug proxy used to display items in a <see cref="Buffer{T}"/> instance.
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Views
|
||||
namespace ComputeSharp.Resources.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// A debug proxy used to display items in a <see cref="Texture2D{T}"/> instance.
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Views
|
||||
namespace ComputeSharp.Resources.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// A debug proxy used to display items in a <see cref="Texture3D{T}"/> instance.
|
||||
@@ -5,14 +5,14 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId>ComputeSharp</PackageId>
|
||||
<Description>A .NET 5 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders</Description>
|
||||
<Description>A library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders</Description>
|
||||
<PackageReleaseNotes>New interlocked intrinsics APIs, performance and memory optimizations</PackageReleaseNotes>
|
||||
<PackageVersion>2.0.0</PackageVersion>
|
||||
<RepositoryUrl>https://github.com/Sergio0694/ComputeSharp.git</RepositoryUrl>
|
||||
<ProjectUrl>https://github.com/Sergio0694/ComputeSharp</ProjectUrl>
|
||||
<Authors>Sergio Pedri</Authors>
|
||||
<Owners>Sergio Pedri</Owners>
|
||||
<Copyright>Copyright (c) 2020 Sergio Pedri</Copyright>
|
||||
<Copyright>Copyright (c) 2021 Sergio Pedri</Copyright>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<PackageIconUrl>https://i.imgur.com/ntvmD6P.png</PackageIconUrl>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<DocumentationFile>ComputeSharp.Shaders.xml</DocumentationFile>
|
||||
<Description>ComputeSharp.Shaders</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -15,11 +15,13 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
/// Creates a new <see cref="ID3D12RootSignature"/> for a given device.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The target <see cref="ID3D12Device"/> to use to create the root signature.</param>
|
||||
/// <param name="d3D12Root32BitConstantsCount">The number of 32 bit root constants to load.</param>
|
||||
/// <param name="d3D12DescriptorRanges1">The input descriptor ranges for the signature to create.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12RootSignature"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the root signature fails.</exception>
|
||||
public static ComPtr<ID3D12RootSignature> CreateRootSignature(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
int d3D12Root32BitConstantsCount,
|
||||
ReadOnlySpan<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1)
|
||||
{
|
||||
using ComPtr<ID3DBlob> d3D3Blob = default;
|
||||
@@ -28,18 +30,22 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
|
||||
fixed (D3D12_DESCRIPTOR_RANGE1* d3D12DescriptorRange1 = d3D12DescriptorRanges1)
|
||||
{
|
||||
D3D12_ROOT_PARAMETER1* d3D12RootParameters1 = stackalloc D3D12_ROOT_PARAMETER1[d3D12DescriptorRanges1.Length];
|
||||
D3D12_ROOT_PARAMETER1* d3D12RootParameters1 = stackalloc D3D12_ROOT_PARAMETER1[d3D12DescriptorRanges1.Length + 1];
|
||||
|
||||
// The initial constant buffer is initialized with 32 bit root constants.
|
||||
// This avoids having to manage an extra buffer for each shader dispatch.
|
||||
D3D12_ROOT_PARAMETER1.InitAsConstants(out *d3D12RootParameters1, (uint)d3D12Root32BitConstantsCount, 0);
|
||||
|
||||
// Pack each descriptor range into a root parameter with that single range as content
|
||||
for (int i = 0; i < d3D12DescriptorRanges1.Length; i++)
|
||||
{
|
||||
D3D12_ROOT_PARAMETER1.InitAsDescriptorTable(out d3D12RootParameters1[i], 1, d3D12DescriptorRange1 + i);
|
||||
D3D12_ROOT_PARAMETER1.InitAsDescriptorTable(out d3D12RootParameters1[i + 1], 1, d3D12DescriptorRange1 + i);
|
||||
}
|
||||
|
||||
// Root signature description wrapping the packed collection of root parameters
|
||||
D3D12_VERSIONED_ROOT_SIGNATURE_DESC.Init_1_1(
|
||||
out D3D12_VERSIONED_ROOT_SIGNATURE_DESC d3D12VersionedRootSignatureDescription,
|
||||
(uint)d3D12DescriptorRanges1.Length,
|
||||
(uint)d3D12DescriptorRanges1.Length + 1,
|
||||
d3D12RootParameters1);
|
||||
|
||||
// Serialize the root signature from the data just computed. When this is done
|
||||
|
||||
@@ -31,7 +31,25 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
builder.AppendLine("// AUTO GENERATED");
|
||||
builder.AppendLine("// ================================================");
|
||||
builder.AppendLine("// This shader was created by ComputeSharp.");
|
||||
builder.AppendLine("// See: https://github.com/Sergio0694/ComputeSharp.");
|
||||
builder.AppendLine("// See: https://github.com/Sergio0694/ComputeSharp.");
|
||||
|
||||
// Group size constants
|
||||
builder.AppendLine();
|
||||
builder.Append("#define __GroupSize__get_X ");
|
||||
builder.AppendLine(threadsX.ToString());
|
||||
builder.Append("#define __GroupSize__get_Y ");
|
||||
builder.AppendLine(threadsY.ToString());
|
||||
builder.Append("#define __GroupSize__get_Z ");
|
||||
builder.AppendLine(threadsZ.ToString());
|
||||
|
||||
// User defined onstants
|
||||
foreach (var constant in info.ConstantsInfo)
|
||||
{
|
||||
builder.Append("#define ");
|
||||
builder.Append(constant.Key);
|
||||
builder.Append(' ');
|
||||
builder.AppendLine(constant.Value);
|
||||
}
|
||||
|
||||
// Declared types
|
||||
foreach (var type in info.DeclaredTypes)
|
||||
@@ -100,6 +118,22 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
// Shared buffers
|
||||
foreach (var buffer in info.SharedBuffers)
|
||||
{
|
||||
builder.AppendLine();
|
||||
builder.Append("groupshared ");
|
||||
builder.Append(buffer.Value.Type);
|
||||
builder.Append(' ');
|
||||
builder.Append(buffer.Key);
|
||||
builder.Append('[');
|
||||
|
||||
if (buffer.Value.Count is int count) builder.Append(count.ToString());
|
||||
else builder.Append((threadsX * threadsY * threadsZ).ToString());
|
||||
|
||||
builder.AppendLine("];");
|
||||
}
|
||||
|
||||
// Captured methods
|
||||
foreach (var function in info.MethodsInfo)
|
||||
{
|
||||
@@ -109,13 +143,7 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
|
||||
// Entry point
|
||||
builder.AppendLine();
|
||||
builder.Append("[NumThreads(");
|
||||
builder.Append(threadsX.ToString());
|
||||
builder.Append(", ");
|
||||
builder.Append(threadsY.ToString());
|
||||
builder.Append(", ");
|
||||
builder.Append(threadsZ.ToString());
|
||||
builder.AppendLine(")]");
|
||||
builder.AppendLine("[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]");
|
||||
builder.AppendLine(info.EntryPoint);
|
||||
|
||||
return builder;
|
||||
@@ -163,11 +191,11 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
/// Appends the input sequence of characters to the current buffer.
|
||||
/// </summary>
|
||||
/// <param name="value">The input characters to write.</param>
|
||||
public void Append(ReadOnlySpan<char> value)
|
||||
public void Append(string value)
|
||||
{
|
||||
EnsureCapacity(value.Length);
|
||||
|
||||
value.CopyTo(this.array.AsSpan(this.index));
|
||||
value.AsSpan().CopyTo(this.array.AsSpan(this.index));
|
||||
|
||||
this.index += value.Length;
|
||||
}
|
||||
@@ -186,11 +214,11 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
/// Appends the input sequence of characters to the current buffer, with a trailing new line.
|
||||
/// </summary>
|
||||
/// <param name="value">The input characters to write.</param>
|
||||
public void AppendLine(ReadOnlySpan<char> value)
|
||||
public void AppendLine(string value)
|
||||
{
|
||||
EnsureCapacity(value.Length + 1);
|
||||
|
||||
value.CopyTo(this.array.AsSpan(this.index));
|
||||
value.AsSpan().CopyTo(this.array.AsSpan(this.index));
|
||||
|
||||
this.index += value.Length;
|
||||
|
||||
@@ -221,7 +249,7 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
/// <summary>
|
||||
/// Ensures that <see cref="array"/> has enough free space to contain a given number of new items.
|
||||
/// </summary>
|
||||
/// <param name="sizeHint">The minimum number of items to ensure space for in <see cref="array"/>.</param>
|
||||
/// <param name="requestedSize">The minimum number of items to ensure space for in <see cref="array"/>.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void EnsureCapacity(int requestedSize)
|
||||
{
|
||||
@@ -267,7 +295,7 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
internal sealed class DebugView
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DebugView{T}"/> class with the specified parameters.
|
||||
/// Initializes a new instance of the <see cref="DebugView"/> class with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="builder">The input <see cref="ArrayPoolStringBuilder"/> instance to display.</param>
|
||||
public DebugView(ArrayPoolStringBuilder builder)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/// </summary>
|
||||
/// <param name="FieldType">The type of the current field in the HLSL shader.</param>
|
||||
/// <param name="FieldName">The name to use for the current field.</param>
|
||||
/// <param name="BufferIndex">The register index to bind the resource to.</param>
|
||||
internal abstract record HlslResourceInfo(string FieldType, string FieldName, int BufferIndex)
|
||||
: CapturedFieldInfo(FieldType, FieldName)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Extensions;
|
||||
using ComputeSharp.Shaders.Renderer;
|
||||
@@ -16,32 +13,6 @@ using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
|
||||
|
||||
namespace ComputeSharp.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helper methods to support <see cref="ShaderRunner{T}"/>.
|
||||
/// This type is primarily needed to avoid having fields being repeated per generic instantiation.
|
||||
/// </summary>
|
||||
internal static class ShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// A thread-safe map of reusable GPU buffers for captured locals.
|
||||
/// </summary>
|
||||
[ThreadStatic]
|
||||
private static ConditionalWeakTable<GraphicsDevice, ConstantBuffer<Int4>>? variablesBuffers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reusable <see cref="ConstantBuffer{T}"/> instance for a shader invocation.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> to use to run the shader.</param>
|
||||
/// <returns>The reusable <see cref="ConstantBuffer{T}"/> instance to populate.</returns>
|
||||
[Pure]
|
||||
public static ConstantBuffer<Int4> GetVariablesBuffer(GraphicsDevice device)
|
||||
{
|
||||
ConditionalWeakTable<GraphicsDevice, ConstantBuffer<Int4>> map = variablesBuffers ??= new();
|
||||
|
||||
return map.GetValue(device, static gpu => new(gpu, 256));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> responsible for performing all the necessary operations to compile and run a compute shader.
|
||||
/// </summary>
|
||||
@@ -127,22 +98,17 @@ namespace ComputeSharp.Shaders
|
||||
// Extract the dispatch data for the shader invocation
|
||||
using DispatchData dispatchData = shaderData.Loader.GetDispatchData(device, in shader, x, y, z);
|
||||
|
||||
// Load the captured buffers
|
||||
// Initialize the loop targets and the captured values
|
||||
commandList.SetComputeRoot32BitConstants(dispatchData.Variables);
|
||||
|
||||
ReadOnlySpan<D3D12_GPU_DESCRIPTOR_HANDLE> resources = dispatchData.Resources;
|
||||
|
||||
for (int i = 0; i < resources.Length; i++)
|
||||
{
|
||||
// Load the captured buffers
|
||||
commandList.SetComputeRootDescriptorTable(i + 1, resources[i]);
|
||||
}
|
||||
|
||||
// Initialize the loop targets and the captured values
|
||||
ConstantBuffer<Int4> variablesBuffer = ShaderRunner.GetVariablesBuffer(device);
|
||||
ReadOnlySpan<Int4> variables = dispatchData.Variables;
|
||||
|
||||
variablesBuffer.SetData(ref MemoryMarshal.GetReference(variables), variables.Length, 0);
|
||||
|
||||
commandList.SetComputeRootDescriptorTable(0, variablesBuffer.D3D12GpuDescriptorHandle);
|
||||
|
||||
// Calculate the dispatch values
|
||||
int
|
||||
groupsX = Math.DivRem(x, threadsX, out int modX) + (modX == 0 ? 0 : 1),
|
||||
@@ -187,7 +153,7 @@ namespace ComputeSharp.Shaders
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static unsafe void CreatePipelineData(GraphicsDevice device, in CachedShader<T> shaderData, out PipelineData pipelineData)
|
||||
{
|
||||
using ComPtr<ID3D12RootSignature> d3D12RootSignature = device.D3D12Device->CreateRootSignature(shaderData.Loader.D3D12DescriptorRanges1);
|
||||
using ComPtr<ID3D12RootSignature> d3D12RootSignature = device.D3D12Device->CreateRootSignature(shaderData.Loader.D3D12Root32BitConstantsCount, shaderData.Loader.D3D12DescriptorRanges1);
|
||||
using ComPtr<ID3D12PipelineState> d3D12PipelineState = device.D3D12Device->CreateComputePipelineState(d3D12RootSignature.Get(), shaderData.Bytecode.D3D12ShaderBytecode);
|
||||
|
||||
pipelineData = new PipelineData(d3D12RootSignature.Move(), d3D12PipelineState.Move());
|
||||
|
||||
@@ -11,26 +11,36 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// <summary>
|
||||
/// Gets the generated source code for the method in the current shader.
|
||||
/// </summary>
|
||||
public string EntryPoint { get; }
|
||||
string EntryPoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of <see cref="Renderer.Models.HlslResourceInfo"/> items for the shader fields.
|
||||
/// </summary>
|
||||
public IReadOnlyList<HlslResourceInfo> HlslResourceInfo { get; }
|
||||
IReadOnlyList<HlslResourceInfo> HlslResourceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of <see cref="CapturedFieldInfo"/> items for the shader fields.
|
||||
/// </summary>
|
||||
public IReadOnlyList<CapturedFieldInfo> FieldsInfo { get; }
|
||||
IReadOnlyList<CapturedFieldInfo> FieldsInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of methods to be used in the shader.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> MethodsInfo { get; }
|
||||
IReadOnlyCollection<string> MethodsInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of constants to be declared in the shader.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<string, string> ConstantsInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of declared types for the shader.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> DeclaredTypes { get; }
|
||||
IReadOnlyCollection<string> DeclaredTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of discovered constants.
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<string, (string Type, int? Count)> SharedBuffers { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.Graphics.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Interop
|
||||
|
||||
@@ -79,7 +79,9 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
genericType == typeof(ReadOnlyTexture2D<>) ||
|
||||
genericType == typeof(ReadOnlyTexture2D<,>) ||
|
||||
genericType == typeof(ReadOnlyTexture3D<>) ||
|
||||
genericType == typeof(ReadOnlyTexture3D<,>);
|
||||
genericType == typeof(ReadOnlyTexture3D<,>) ||
|
||||
genericType == typeof(IReadOnlyTexture2D<>) ||
|
||||
genericType == typeof(IReadOnlyTexture3D<>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +101,9 @@ namespace ComputeSharp.Shaders.Mappings
|
||||
genericType == typeof(ReadWriteTexture2D<>) ||
|
||||
genericType == typeof(ReadWriteTexture2D<,>) ||
|
||||
genericType == typeof(ReadWriteTexture3D<>) ||
|
||||
genericType == typeof(ReadWriteTexture3D<,>);
|
||||
genericType == typeof(ReadWriteTexture3D<,>) ||
|
||||
genericType == typeof(IReadWriteTexture2D<>) ||
|
||||
genericType == typeof(IReadWriteTexture3D<>); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Shaders.Translation.Interop;
|
||||
|
||||
|
||||
@@ -64,14 +64,14 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
/// <summary>
|
||||
/// Gets a <see cref="ReadOnlySpan{T}"/> with the padded data representing all the captured variables.
|
||||
/// </summary>
|
||||
public unsafe ReadOnlySpan<Int4> Variables
|
||||
public unsafe ReadOnlySpan<uint> Variables
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ref byte r0 = ref MemoryMarshal.GetArrayDataReference(this.variablesArray);
|
||||
ref Int4 r1 = ref Unsafe.As<byte, Int4>(ref r0);
|
||||
int length = (int)((uint)this.variablesByteSize / (uint)sizeof(Int4));
|
||||
ref uint r1 = ref Unsafe.As<byte, uint>(ref r0);
|
||||
int length = (int)((uint)this.variablesByteSize / sizeof(uint));
|
||||
|
||||
return MemoryMarshal.CreateReadOnlySpan(ref r1, length);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
/// <inheritdoc cref="ShaderCompiler"/>
|
||||
internal static unsafe partial class ShaderCompiler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the DLL resolvers for the dxcompiler.dll and dxil.dll libraries.
|
||||
/// </summary>
|
||||
private static void InitializeDxcLibrariesLoading()
|
||||
{
|
||||
// Test whether the native libraries are present in the same folder of the executable
|
||||
// (which is the case when the program was built with a runtime identifier), or whether
|
||||
// they are in the "runtimes\win-x64\native" folder in the executable directory.
|
||||
string nugetNativeLibsPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native");
|
||||
bool isNuGetRuntimeLibrariesDirectoryPresent = Directory.Exists(nugetNativeLibsPath);
|
||||
|
||||
// Register a custom library resolver for the two DXC libraries. We need to either manually load the two
|
||||
// libraries from the NuGet directory, if an RID is not in use, or we need to ensure that dxil.dll is
|
||||
// loaded correctly in case the program was executed with the host being in another directory.
|
||||
// This happens when doing eg. "dotnet bin\Debug\net5.0\MyApp.dll", which would crash at runtime.
|
||||
FX.ResolveLibrary += (libraryName, assembly, searchPath) =>
|
||||
{
|
||||
if (libraryName is not "dxcompiler") return IntPtr.Zero;
|
||||
|
||||
if (isNuGetRuntimeLibrariesDirectoryPresent)
|
||||
{
|
||||
string
|
||||
dxcompilerPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native\dxcompiler.dll"),
|
||||
dxilPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native\dxil.dll");
|
||||
|
||||
// Load DXIL first so that DXC doesn't fail to load it, and then DXIL, both from the NuGet path
|
||||
if (NativeLibrary.TryLoad(dxilPath, out _) && NativeLibrary.TryLoad(dxcompilerPath, out IntPtr handle))
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Even when the two libraries are correctly copied next to the executable in use, we load them
|
||||
// manually to ensure the operation is successful. This is to avoid failures in cases such as when
|
||||
// doing "dotnet bin\MyApp.dll", ie. when the host is in another path than the executable in use.
|
||||
// This is probably because DXIL is a native dependency for DXC, but the way Windows loads these
|
||||
// libraries doesn't take into account the .NET concepts of "app directory": neither the current "bin"
|
||||
// directory nor the "process directory", which is "C:\Program Files\dotnet", actually contain the
|
||||
// native library we need, hence the runtime crash. Manually loading the library this way solves this.
|
||||
if (NativeLibrary.TryLoad("dxil", assembly, searchPath, out _) &&
|
||||
NativeLibrary.TryLoad("dxcompiler", assembly, searchPath, out IntPtr handle))
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Exceptions;
|
||||
using TerraFX.Interop;
|
||||
@@ -15,7 +11,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that uses the DXC APIs to compile compute shaders.
|
||||
/// </summary>
|
||||
internal static unsafe class ShaderCompiler
|
||||
internal static unsafe partial class ShaderCompiler
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IDxcCompiler"/> instance to use to create the bytecode for HLSL sources.
|
||||
@@ -56,64 +52,6 @@ namespace ComputeSharp.Shaders.Translation
|
||||
DxcIncludeHandler = dxcIncludeHandler.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the DLL resolvers for the dxcompiler.dll and dxil.dll libraries.
|
||||
/// </summary>
|
||||
private static void InitializeDxcLibrariesLoading()
|
||||
{
|
||||
// Test whether the native libraries are present in the same folder of the executable
|
||||
// (which is the case when the program was built with a runtime identifier), or whether
|
||||
// they are in the "runtimes\win-x64\native" folder in the executable directory.
|
||||
string nugetNativeLibsPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native");
|
||||
bool isNuGetRuntimeLibrariesDirectoryPresent = Directory.Exists(nugetNativeLibsPath);
|
||||
|
||||
// Register a custom library resolver for the two DXC libraries. We need to either manually load the two
|
||||
// libraries from the NuGet directory, if an RID is not in use, or we need to ensure that dxil.dll is
|
||||
// loaded correctly in case the program was executed with the host being in another directory.
|
||||
// This happens when doing eg. "dotnet bin\Debug\net5.0\MyApp.dll", which would crash at runtime.
|
||||
FX.ResolveLibrary += (n, a, s) => ResolveLibrary(n, a, s, isNuGetRuntimeLibrariesDirectoryPresent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom resolver to override the default library resolution behavior for the DXC and DXIL libraries.
|
||||
/// This either loads the libraries from the NuGet directory, or just ensures that DXIL is always loaded.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="DllImportResolver"/>
|
||||
private static IntPtr ResolveLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, bool isNuGetRuntimeLibrariesDirectoryPresent)
|
||||
{
|
||||
if (libraryName is not "dxcompiler") return IntPtr.Zero;
|
||||
|
||||
if (isNuGetRuntimeLibrariesDirectoryPresent)
|
||||
{
|
||||
string
|
||||
dxcompilerPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native\dxcompiler.dll"),
|
||||
dxilPath = Path.Combine(AppContext.BaseDirectory, @"runtimes\win-x64\native\dxil.dll");
|
||||
|
||||
// Load DXIL first so that DXC doesn't fail to load it, and then DXIL, both from the NuGet path
|
||||
if (NativeLibrary.TryLoad(dxilPath, out _) && NativeLibrary.TryLoad(dxcompilerPath, out IntPtr handle))
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Even when the two libraries are correctly copied next to the executable in use, we load them
|
||||
// manually to ensure the operation is successful. This is to avoid failures in cases such as when
|
||||
// doing "dotnet bin\MyApp.dll", ie. when the host is in another path than the executable in use.
|
||||
// This is probably because DXIL is a native dependency for DXC, but the way Windows loads these
|
||||
// libraries doesn't take into account the .NET concepts of "app directory": neither the current "bin"
|
||||
// directory nor the "process directory", which is "C:\Program Files\dotnet", actually contain the
|
||||
// native library we need, hence the runtime crash. Manually loading the library this way solves this.
|
||||
if (NativeLibrary.TryLoad("dxil", assembly, searchPath, out _) &&
|
||||
NativeLibrary.TryLoad("dxcompiler", assembly, searchPath, out IntPtr handle))
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles a new HLSL shader from the input source code.
|
||||
/// </summary>
|
||||
@@ -143,7 +81,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
fixed (char* optimization = "-O3")
|
||||
{
|
||||
DxcCompiler.Get()->Compile(
|
||||
dxcBlobEncoding.Upcast<IDxcBlobEncoding, IDxcBlob>().Get(),
|
||||
(IDxcBlob*)dxcBlobEncoding.Get(),
|
||||
(ushort*)shaderName,
|
||||
(ushort*)entryPoint,
|
||||
(ushort*)shaderProfile,
|
||||
@@ -175,7 +113,6 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
/// <param name="dxcOperationResult">The input (faulting) operation.</param>
|
||||
/// <returns>This method always throws and never actually returs.</returns>
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static ComPtr<IDxcBlob> ThrowHslsCompilationException(IDxcOperationResult* dxcOperationResult)
|
||||
{
|
||||
|
||||
@@ -5,10 +5,12 @@ using System.Diagnostics.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using TerraFX.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
/// <inheritdoc cref="ShaderLoader{T}"/>
|
||||
@@ -55,7 +57,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
// Resources and variables buffers
|
||||
ulong[] resources = ArrayPool<ulong>.Shared.Rent(this.totalResourceCount);
|
||||
byte[] variables = ArrayPool<byte>.Shared.Rent(4096);
|
||||
byte[] variables = ArrayPool<byte>.Shared.Rent(256);
|
||||
|
||||
ref ulong r0 = ref MemoryMarshal.GetArrayDataReference(resources);
|
||||
ref byte r1 = ref MemoryMarshal.GetArrayDataReference(variables);
|
||||
@@ -81,6 +83,10 @@ namespace ComputeSharp.Shaders.Translation
|
||||
Type type = typeof(T).Assembly.GetType("ComputeSharp.__Internals.DispatchDataLoader")!;
|
||||
MethodInfo method = type.GetMethod("LoadDispatchData", argumentTypes)!;
|
||||
|
||||
// Extract the computed count of 32 bit root constants to load
|
||||
D3D12Root32BitConstantsCount = ((ComputeRoot32BitConstantsAttribute)method.ReturnTypeCustomAttributes.GetCustomAttributes(false)[0]).Count;
|
||||
|
||||
// Create a delegate from the generated shader data loader
|
||||
this.dispatchDataLoader = method.CreateDelegate<DispatchDataLoader>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
using ComputeSharp.Shaders.Renderer.Models;
|
||||
@@ -43,9 +42,9 @@ namespace ComputeSharp.Shaders.Translation
|
||||
private uint readWriteBuffersCount;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="List{T}"/> of <see cref="D3D12_DESCRIPTOR_RANGE1"/> items that are required to load the captured values.
|
||||
/// The array of <see cref="D3D12_DESCRIPTOR_RANGE1"/> items that are required to load the captured values.
|
||||
/// </summary>
|
||||
private readonly List<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1 = new();
|
||||
private D3D12_DESCRIPTOR_RANGE1[] d3D12DescriptorRanges1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="List{T}"/> with the <see cref="Renderer.Models.HlslResourceInfo"/> items for the shader fields.
|
||||
@@ -62,6 +61,11 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
private readonly List<string> methodsInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Dictionary{TKey,TValue}"/> with the discovered constants for the shader.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> constantsInfo = new();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="List{T}"/> with the collected declared types for the shader.
|
||||
/// </summary>
|
||||
@@ -74,12 +78,17 @@ namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of 32 bit constants in the root signature for the shader.
|
||||
/// </summary>
|
||||
public int D3D12Root32BitConstantsCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Span{T}"/> with the loaded <see cref="D3D12_DESCRIPTOR_RANGE1"/> items for the shader.
|
||||
/// </summary>
|
||||
public ReadOnlySpan<D3D12_DESCRIPTOR_RANGE1> D3D12DescriptorRanges1
|
||||
{
|
||||
get => CollectionsMarshal.AsSpan(this.d3D12DescriptorRanges1);
|
||||
get => this.d3D12DescriptorRanges1;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -94,36 +103,59 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<string> MethodsInfo => this.methodsInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyDictionary<string, string> ConstantsInfo => this.constantsInfo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<string> DeclaredTypes => this.declaredTypes;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyDictionary<string, (string Type, int? Count)> SharedBuffers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads and processes an input<typeparamref name="T"/> shadeer.
|
||||
/// </summary>
|
||||
/// <param name="shader">The <typeparamref name="T"/> instance to use to build the shader.</param>
|
||||
/// <returns>A new <see cref="ShaderLoader"/> instance representing the input shader.</returns>
|
||||
/// <returns>A new <see cref="ShaderLoader{T}"/> instance representing the input shader.</returns>
|
||||
[Pure]
|
||||
public static ShaderLoader<T> Load(in T shader)
|
||||
{
|
||||
ShaderLoader<T> @this = new();
|
||||
|
||||
// Reading members through reflection requires an object parameter,
|
||||
// so here we're just boxing the input shader once to avoid allocating
|
||||
// it multiple times in the managed heap while processing the shader.
|
||||
object box = shader;
|
||||
|
||||
@this.LoadFieldsInfo(box);
|
||||
@this.LoadMethodMetadata();
|
||||
|
||||
// Reading members through reflection requires an object parameter, so here we're just boxing
|
||||
// the input shader once to avoid allocating it multiple times while processing the shader.
|
||||
@this.d3D12DescriptorRanges1 = @this.LoadFieldsInfo(shader);
|
||||
|
||||
@this.InitializeDispatchDataLoader();
|
||||
|
||||
return @this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the metadata info for the current shader.
|
||||
/// </summary>
|
||||
private void LoadMethodMetadata()
|
||||
{
|
||||
EntryPoint = Attribute.ExecuteMethod;
|
||||
SharedBuffers = Attribute.SharedBuffers;
|
||||
|
||||
this.declaredTypes.AddRange(Attribute.Types);
|
||||
this.methodsInfo.AddRange(Attribute.Methods);
|
||||
|
||||
foreach (var pair in Attribute.Constants)
|
||||
{
|
||||
this.constantsInfo.Add(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the fields info for the current shader being loaded.
|
||||
/// </summary>
|
||||
/// <param name="shader">The boxed <typeparamref name="T"/> instance to use to build the shader.</param>
|
||||
private void LoadFieldsInfo(object shader)
|
||||
/// <returns>The array of <see cref="D3D12_DESCRIPTOR_RANGE1"/> items that are required to load the captured values.</returns>
|
||||
private D3D12_DESCRIPTOR_RANGE1[] LoadFieldsInfo(object shader)
|
||||
{
|
||||
IReadOnlyList<FieldInfo> shaderFields = typeof(T).GetFields(
|
||||
BindingFlags.Instance |
|
||||
@@ -135,51 +167,48 @@ namespace ComputeSharp.Shaders.Translation
|
||||
ThrowHelper.ThrowInvalidOperationException("The shader body must contain at least one field");
|
||||
}
|
||||
|
||||
// Descriptor for the buffer for captured scalar/vector variables
|
||||
D3D12_DESCRIPTOR_RANGE1 d3D12DescriptorRange1 = new(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, this.constantBuffersCount++);
|
||||
|
||||
this.d3D12DescriptorRanges1.Add(d3D12DescriptorRange1);
|
||||
List<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1 = new();
|
||||
|
||||
// Inspect the captured fields
|
||||
foreach (FieldInfo fieldInfo in shaderFields)
|
||||
{
|
||||
LoadFieldInfo(shader, fieldInfo);
|
||||
LoadFieldInfo(shader, fieldInfo, d3D12DescriptorRanges1);
|
||||
}
|
||||
|
||||
return d3D12DescriptorRanges1.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a specified <see cref="ReadableMember"/> and adds it to the shader model.
|
||||
/// Loads a specified <see cref="FieldInfo"/> and adds it to the shader model.
|
||||
/// </summary>
|
||||
/// <param name="shader">The boxed <typeparamref name="T"/> instance to use to build the shader.</param>
|
||||
/// <param name="memberInfo">The target <see cref="FieldInfo"/> to load.</param>
|
||||
private void LoadFieldInfo(object shader, FieldInfo fieldInfo)
|
||||
/// <param name="fieldInfo">The target <see cref="FieldInfo"/> to load.</param>
|
||||
/// <param name="d3D12DescriptorRanges1">The list of discovered <see cref="D3D12_DESCRIPTOR_RANGE1"/> values.</param>
|
||||
private void LoadFieldInfo(object shader, FieldInfo fieldInfo, List<D3D12_DESCRIPTOR_RANGE1> d3D12DescriptorRanges1)
|
||||
{
|
||||
Type fieldType = fieldInfo.FieldType;
|
||||
(string hlslName, string hlslType) = Attribute.Fields[fieldInfo.Name];
|
||||
|
||||
if (HlslKnownTypes.IsConstantBufferType(fieldType))
|
||||
{
|
||||
D3D12_DESCRIPTOR_RANGE1 d3D12DescriptorRange1 = new(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, this.constantBuffersCount);
|
||||
d3D12DescriptorRanges1.Add(new D3D12_DESCRIPTOR_RANGE1(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, this.constantBuffersCount));
|
||||
|
||||
this.d3D12DescriptorRanges1.Add(d3D12DescriptorRange1);
|
||||
this.capturedFields.Add(fieldInfo);
|
||||
this.hlslResourceInfo.Add(new HlslResourceInfo.Constant(hlslType, hlslName, (int)this.constantBuffersCount++));
|
||||
this.totalResourceCount++;
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadOnlyResourceType(fieldType))
|
||||
{
|
||||
D3D12_DESCRIPTOR_RANGE1 d3D12DescriptorRange1 = new(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, this.readOnlyBuffersCount);
|
||||
d3D12DescriptorRanges1.Add(new D3D12_DESCRIPTOR_RANGE1(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, this.readOnlyBuffersCount));
|
||||
|
||||
this.d3D12DescriptorRanges1.Add(d3D12DescriptorRange1);
|
||||
this.capturedFields.Add(fieldInfo);
|
||||
this.hlslResourceInfo.Add(new HlslResourceInfo.ReadOnly(hlslType, hlslName, (int)this.readOnlyBuffersCount++));
|
||||
this.totalResourceCount++;
|
||||
}
|
||||
else if (HlslKnownTypes.IsReadWriteResourceType(fieldType))
|
||||
{
|
||||
D3D12_DESCRIPTOR_RANGE1 d3D12DescriptorRange1 = new(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, this.readWriteBuffersCount);
|
||||
d3D12DescriptorRanges1.Add(new D3D12_DESCRIPTOR_RANGE1(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, this.readWriteBuffersCount));
|
||||
|
||||
this.d3D12DescriptorRanges1.Add(d3D12DescriptorRange1);
|
||||
this.capturedFields.Add(fieldInfo);
|
||||
this.hlslResourceInfo.Add(new HlslResourceInfo.ReadWrite(hlslType, hlslName, (int)this.readWriteBuffersCount++));
|
||||
this.totalResourceCount++;
|
||||
@@ -197,19 +226,13 @@ namespace ComputeSharp.Shaders.Translation
|
||||
this.declaredTypes.AddRange(methodSource.Types);
|
||||
this.methodsInfo.Add(methodSource.GetMappedInvokeMethod(hlslName));
|
||||
this.methodsInfo.AddRange(methodSource.Methods);
|
||||
|
||||
foreach (var pair in methodSource.Constants)
|
||||
{
|
||||
this.constantsInfo[pair.Key] = pair.Value;
|
||||
}
|
||||
}
|
||||
else ThrowHelper.ThrowArgumentException("Invalid captured variable");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the metadata info for the current shader.
|
||||
/// </summary>
|
||||
private void LoadMethodMetadata()
|
||||
{
|
||||
EntryPoint = Attribute.ExecuteMethod;
|
||||
|
||||
this.methodsInfo.AddRange(Attribute.Methods);
|
||||
this.declaredTypes.AddRange(Attribute.Types);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,12 +42,11 @@ namespace ComputeSharp.SourceGenerators
|
||||
var structName = structDeclaration.Identifier.Text;
|
||||
var structModifiers = structDeclaration.Modifiers;
|
||||
var fields = (
|
||||
from fieldDeclaration in structDeclaration.Members.OfType<FieldDeclarationSyntax>()
|
||||
let fieldType = fieldDeclaration.Declaration.Type
|
||||
let typeName = semanticModel.GetTypeInfo(fieldType).Type!.ToDisplayString()
|
||||
from fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>()
|
||||
where !fieldSymbol.IsConst && !fieldSymbol.IsStatic
|
||||
let typeName = fieldSymbol.Type!.ToDisplayString()
|
||||
let fieldFullType = ParseTypeName(typeName)
|
||||
from fieldVariable in fieldDeclaration.Declaration.Variables
|
||||
select (Type: fieldFullType, fieldVariable.Identifier)).ToImmutableArray();
|
||||
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:
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackFolder>analyzers\dotnet\cs</PackFolder>
|
||||
<PackSymbols>false</PackSymbols>
|
||||
<Description>ComputeSharp.SourceGenerators</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--The source generator cannot contain package references or project references, so instead we're just
|
||||
@@ -16,9 +12,15 @@
|
||||
and to match members based on full name, so the types being in the generator assembly are not an issue.-->
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" Link="Core\Attributes\AutoConstructorAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\GroupSharedAttribute.cs" Link="Core\Attributes\GroupSharedAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\ShaderMethodAttribute.cs" Link="Core\Attributes\ShaderMethodAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\__Internals\ComputeRoot32BitConstantsAttribute.cs" Link="Core\Attributes\__Internals\ComputeRoot32BitConstantsAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\__Internals\IComputeShaderSourceAttribute.cs" Link="Core\Attributes\__Internals\IComputeShaderSourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" Link="Core\Attributes\__Internals\ShaderMethodSourceAttribute.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Dispatch\GroupIds.cs" Link="Core\Dispatch\GroupIds.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Dispatch\GroupSize.cs" Link="Core\Dispatch\GroupSize.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Dispatch\ThreadIds.cs" Link="Core\Dispatch\ThreadIds.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Dispatch\WarpIds.cs" Link="Core\Dispatch\WarpIds.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" Link="Core\Exceptions\InvalidExecutionContextException.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Exceptions\MissingMethodSourceException.cs" Link="Core\Exceptions\MissingMethodSourceException.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Extensions\MethodInfoExtensions.cs" Link="Core\Extensions\MethodInfoExtensions.cs" />
|
||||
@@ -39,7 +41,6 @@
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\Int\Int2.cs" Link="Core\Primitives\Int\Int2.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\Int\Int3.cs" Link="Core\Primitives\Int\Int3.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\Int\Int4.cs" Link="Core\Primitives\Int\Int4.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\ThreadIds.cs" Link="Core\Primitives\ThreadIds.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\UInt\UInt2.cs" Link="Core\Primitives\UInt\UInt2.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\UInt\UInt3.cs" Link="Core\Primitives\UInt\UInt3.cs" />
|
||||
<Compile Include="..\ComputeSharp.Core\Primitives\UInt\UInt4.cs" Link="Core\Primitives\UInt\UInt4.cs" />
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A class containing additional factory methods for constructing syntax nodes, tokens and trivia.
|
||||
/// </summary>
|
||||
internal static class SyntaxFactoryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="string"/>[] array expression from the given sequence of <see cref="string"/> instances.
|
||||
/// <para>
|
||||
/// That it, it applies the following transformation:
|
||||
/// <code>
|
||||
/// { "S1", "S2" } => new string[] { "S1", "S2" }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="values">The input sequence of <see cref="string"/> instances.</param>
|
||||
/// <returns>An <see cref="ArrayCreationExpression"/> instance with the described contents.</returns>
|
||||
[Pure]
|
||||
public static ArrayCreationExpressionSyntax ArrayExpression(IEnumerable<string> values)
|
||||
{
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(values.Select(static value => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(value))).ToArray()));
|
||||
}
|
||||
|
||||
/// <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[] { "K1", "V1" }, new[] { "K2", "V2" } }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="values">The input sequence of <see cref="string"/> groups.</param>
|
||||
/// <returns>An <see cref="ArrayCreationExpression"/> instance with the described contents.</returns>
|
||||
[Pure]
|
||||
public static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<IEnumerable<string>> groups)
|
||||
{
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(groups.Select(static group =>
|
||||
ImplicitArrayCreationExpression(InitializerExpression(SyntaxKind.ArrayInitializerExpression).AddExpressions(
|
||||
group.Select(static item => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(item))).ToArray()))).ToArray()));
|
||||
}
|
||||
|
||||
/// <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", I1), ("K2", "V2", null) } => new object[] { new object[] { "K1", "V1", I1 }, new object[] { "K2", "V2", null } }
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="values">The input sequence of <see cref="string"/> groups.</param>
|
||||
/// <returns>An <see cref="ArrayCreationExpression"/> instance with the described contents.</returns>
|
||||
[Pure]
|
||||
public static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<(string A, string B, int? C)> groups)
|
||||
{
|
||||
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)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.A)),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(group.B)),
|
||||
group.C is int i
|
||||
? LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(i))
|
||||
: LiteralExpression(SyntaxKind.NullLiteralExpression)))).ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Immutable;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using ComputeSharp.SourceGenerators.Mappings;
|
||||
@@ -13,6 +14,8 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
[Generator]
|
||||
@@ -54,7 +57,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
if (!structDeclarationSymbol.Interfaces.Any(static interfaceSymbol => interfaceSymbol.Name == nameof(IComputeShader))) continue;
|
||||
|
||||
TypeSyntax shaderType = ParseTypeName(structDeclarationSymbol.ToDisplayString());
|
||||
BlockSyntax block = Block(GetDispatchDataLoadingStatements(structDeclarationSymbol));
|
||||
BlockSyntax block = Block(GetDispatchDataLoadingStatements(structDeclarationSymbol, out int root32BitConstantsCount));
|
||||
|
||||
// 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:
|
||||
@@ -68,6 +71,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
// {
|
||||
// [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Never)]
|
||||
// [System.Obsolete("This method is not intended to be called directly by user code")]
|
||||
// [return: ComputeRoot32BitConstants(42)]
|
||||
// public static int LoadDispatchData(GraphicsDevice device, in ShaderType shader, ref ulong r0, ref byte r1)
|
||||
// {
|
||||
// ...
|
||||
@@ -94,10 +98,16 @@ namespace ComputeSharp.SourceGenerators
|
||||
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
|
||||
AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.StringLiteralExpression,
|
||||
Literal("This method is not intended to be called directly by user code"))))))).AddModifiers(
|
||||
Literal("This method is not intended to be called directly by user code")))))),
|
||||
AttributeList(SingletonSeparatedList(
|
||||
Attribute(IdentifierName(nameof(ComputeRoot32BitConstantsAttribute).Replace("Attribute", "")))
|
||||
.AddArgumentListArguments(AttributeArgument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(root32BitConstantsCount))))))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.ReturnKeyword)))).AddModifiers(
|
||||
Token(SyntaxKind.PublicKeyword),
|
||||
Token(SyntaxKind.StaticKeyword)).AddParameterListParameters(
|
||||
Parameter(Identifier("device")).WithType(IdentifierName("ComputeSharp.Graphics.GraphicsDevice")),
|
||||
Parameter(Identifier("device")).WithType(IdentifierName("ComputeSharp.GraphicsDevice")),
|
||||
Parameter(Identifier("shader")).WithModifiers(TokenList(Token(SyntaxKind.InKeyword))).WithType(shaderType),
|
||||
Parameter(Identifier("r0")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ULongKeyword))),
|
||||
Parameter(Identifier("r1")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
@@ -118,29 +128,36 @@ namespace ComputeSharp.SourceGenerators
|
||||
/// Gets a sequence of statements to load the dispatch data for a given shader
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="count">The total number of 32 bit root constants to load.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load shader dispatch data.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(INamedTypeSymbol structDeclarationSymbol)
|
||||
private static IEnumerable<StatementSyntax> GetDispatchDataLoadingStatements(INamedTypeSymbol structDeclarationSymbol, out int count)
|
||||
{
|
||||
List<StatementSyntax> statements = new();
|
||||
|
||||
int
|
||||
resourceOffset = 0,
|
||||
rawDataOffset = sizeof(int) * 3;
|
||||
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (fieldSymbol.IsStatic) continue;
|
||||
|
||||
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
|
||||
string typeName = typeSymbol.GetFullMetadataName();
|
||||
|
||||
if (HlslKnownTypes.IsTypedResourceType(typeName))
|
||||
{
|
||||
yield return ExpressionStatement(
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"Unsafe.Add(ref r0, {resourceOffset++})"),
|
||||
ParseExpression($"GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle(shader.{fieldSymbol.Name}, device)")));
|
||||
ParseExpression($"GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle(shader.{fieldSymbol.Name}, device)"))));
|
||||
}
|
||||
else if (HlslKnownTypes.IsScalarOrVectorType(typeName))
|
||||
{
|
||||
if (fieldSymbol.IsConst) continue;
|
||||
|
||||
var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName);
|
||||
|
||||
// Calculate the right offset with 16-bytes padding (HLSL constant buffer).
|
||||
@@ -152,20 +169,24 @@ namespace ComputeSharp.SourceGenerators
|
||||
fieldSize,
|
||||
16);
|
||||
|
||||
yield return ExpressionStatement(
|
||||
ParseExpression($"Unsafe.WriteUnaligned(ref Unsafe.Add(ref r1, {rawDataOffset}), shader.{fieldSymbol.Name})"));
|
||||
statements.Add(ExpressionStatement(
|
||||
ParseExpression($"Unsafe.WriteUnaligned(ref Unsafe.Add(ref r1, {rawDataOffset}), shader.{fieldSymbol.Name})")));
|
||||
|
||||
rawDataOffset += fieldSize;
|
||||
}
|
||||
}
|
||||
|
||||
// After all the captured fields have been processed, ansure the reported byte size for
|
||||
// the local variables is padded to the standard alignment for constant buffers. This is
|
||||
// necessary to enable loading all the dispatch data after reinterpreting it to a sequence
|
||||
// of values of size 16 bytes (in particular, Int4 is used), without reading out of bounds.
|
||||
rawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16);
|
||||
// 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));
|
||||
|
||||
yield return ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(rawDataOffset)));
|
||||
statements.Add(ReturnStatement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(rawDataOffset))));
|
||||
|
||||
count = rawDataOffset / sizeof(int);
|
||||
|
||||
return statements;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,8 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (fieldSymbol.IsStatic) continue;
|
||||
|
||||
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
|
||||
|
||||
if (typeSymbol.TypeKind != TypeKind.Delegate) continue;
|
||||
|
||||
@@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
using static ComputeSharp.SourceGenerators.Helpers.SyntaxFactoryHelper;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -45,40 +46,15 @@ namespace ComputeSharp.SourceGenerators
|
||||
// We need to sets to track all discovered custom types and static methods
|
||||
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Helper that converts a sequence of string sequences into a nested array expression.
|
||||
// That is, this applies the following transformation:
|
||||
// - { ("K1", "V1"), ("K2", "V2") } => new object[] { new[] { "K1", "V1" }, new[] { "K2", "V2" } }
|
||||
static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<IEnumerable<string>> groups)
|
||||
{
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(groups.Select(static group =>
|
||||
ImplicitArrayCreationExpression(InitializerExpression(SyntaxKind.ArrayInitializerExpression).AddExpressions(
|
||||
group.Select(static item => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(item))).ToArray()))).ToArray()));
|
||||
}
|
||||
|
||||
// Helper that converts a sequence of strings into an array expression.
|
||||
// That is, this applies the following transformation:
|
||||
// - { "S1", "S2" } => new string[] { "S1", "S2" }
|
||||
static ArrayCreationExpressionSyntax ArrayExpression(IEnumerable<string> values)
|
||||
{
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(values.Select(static value => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(value))).ToArray()));
|
||||
}
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var processedMembers = GetProcessedMembers(structDeclarationSymbol, discoveredTypes).ToArray();
|
||||
var (entryPoint, localFunctions) = GetProcessedMethods(structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods);
|
||||
var sharedBuffers = GetGroupSharedMembers(structDeclarationSymbol, discoveredTypes).ToArray();
|
||||
var (entryPoint, localFunctions) = GetProcessedMethods(structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
var processedTypes = GetProcessedTypes(discoveredTypes).ToArray();
|
||||
var processedMethods = localFunctions.Concat(staticMethods.Values.Select(static method => method.ToFullString())).ToArray();
|
||||
var processedMethods = localFunctions.Concat(staticMethods.Values).Select(static method => method.NormalizeWhitespace().ToFullString()).ToArray();
|
||||
var processedConstants = GetProcessedConstants(constantDefinitions);
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
@@ -90,7 +66,9 @@ namespace ComputeSharp.SourceGenerators
|
||||
AttributeArgument(ArrayExpression(processedTypes)),
|
||||
AttributeArgument(NestedArrayExpression(processedMembers)),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(entryPoint))),
|
||||
AttributeArgument(ArrayExpression(processedMethods)))))
|
||||
AttributeArgument(ArrayExpression(processedMethods)),
|
||||
AttributeArgument(NestedArrayExpression(processedConstants)),
|
||||
AttributeArgument(NestedArrayExpression(sharedBuffers)))))
|
||||
.WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList()))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword))))
|
||||
.NormalizeWhitespace()
|
||||
@@ -112,6 +90,8 @@ namespace ComputeSharp.SourceGenerators
|
||||
{
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (fieldSymbol.IsStatic) continue;
|
||||
|
||||
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type;
|
||||
|
||||
string typeName = HlslKnownTypes.GetMappedName(typeSymbol);
|
||||
@@ -130,6 +110,33 @@ namespace ComputeSharp.SourceGenerators
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of captured members and their mapped names.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="types">The collection of currently discovered types.</param>
|
||||
/// <returns>A sequence of captured members in <paramref name="structDeclarationSymbol"/>.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<(string Name, string Type, int? Count)> GetGroupSharedMembers(INamedTypeSymbol structDeclarationSymbol, ICollection<INamedTypeSymbol> types)
|
||||
{
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (!fieldSymbol.IsStatic) continue;
|
||||
|
||||
AttributeData attribute = fieldSymbol.GetAttributes().First(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
|
||||
int? bufferSize = (int?)attribute.ConstructorArguments.FirstOrDefault().Value;
|
||||
IArrayTypeSymbol typeSymbol = (IArrayTypeSymbol)fieldSymbol.Type;
|
||||
|
||||
string typeName = HlslKnownTypes.GetMappedElementName(typeSymbol);
|
||||
|
||||
_ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping);
|
||||
|
||||
yield return (mapping ?? fieldSymbol.Name, typeName, bufferSize);
|
||||
|
||||
types.Add((INamedTypeSymbol)typeSymbol.ElementType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of processed methods declared within a given type.
|
||||
/// </summary>
|
||||
@@ -138,14 +145,16 @@ namespace ComputeSharp.SourceGenerators
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance for the type to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="structDeclaration"/>, and the entry point.</returns>
|
||||
[Pure]
|
||||
private static (string EntryPoint, IEnumerable<string> Methods) GetProcessedMethods(
|
||||
private static (string EntryPoint, IEnumerable<SyntaxNode> Methods) GetProcessedMethods(
|
||||
StructDeclarationSyntax structDeclaration,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
SemanticModel semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods)
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
// Find all declared methods in the type
|
||||
ImmutableArray<MethodDeclarationSyntax> methodDeclarations = (
|
||||
@@ -154,41 +163,55 @@ namespace ComputeSharp.SourceGenerators
|
||||
select (MethodDeclarationSyntax)syntaxNode).ToImmutableArray();
|
||||
|
||||
string? entryPoint = null;
|
||||
List<string> methods = new();
|
||||
List<SyntaxNode> methods = new();
|
||||
|
||||
foreach (MethodDeclarationSyntax methodDeclaration in methodDeclarations)
|
||||
{
|
||||
IMethodSymbol methodDeclarationSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration)!;
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods);
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
|
||||
MethodDeclarationSyntax? processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia();
|
||||
|
||||
// If the method is the shader entry point, do additional processing
|
||||
if (methodDeclarationSymbol.Name == nameof(IComputeShader.Execute) &&
|
||||
methodDeclarationSymbol.ReturnsVoid &&
|
||||
methodDeclarationSymbol.TypeParameters.Length == 0 &&
|
||||
methodDeclarationSymbol.Parameters.Length == 1 &&
|
||||
methodDeclarationSymbol.Parameters[0].Type.ToDisplayString() == typeof(ThreadIds).FullName)
|
||||
methodDeclarationSymbol.Parameters.Length == 0)
|
||||
{
|
||||
var parameterName = methodDeclarationSymbol.Parameters[0].Name;
|
||||
|
||||
processedMethod = new ExecuteMethodRewriter(parameterName).Visit(processedMethod)!;
|
||||
processedMethod = new ExecuteMethodRewriter(shaderSourceRewriter).Visit(processedMethod)!;
|
||||
|
||||
entryPoint = processedMethod.NormalizeWhitespace().ToFullString();
|
||||
}
|
||||
else methods.Add(processedMethod.NormalizeWhitespace().ToFullString());
|
||||
else methods.Add(processedMethod);
|
||||
|
||||
// Emit the extracted local functions
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
methods.Add(localFunction.Value.NormalizeWhitespace().ToFullString());
|
||||
methods.Add(localFunction.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return (entryPoint!, methods);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of discovered constants.
|
||||
/// </summary>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of discovered constants to declare in the shader.</returns>
|
||||
[Pure]
|
||||
internal static IEnumerable<IEnumerable<string>> GetProcessedConstants(IReadOnlyDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
foreach (var constant in constantDefinitions)
|
||||
{
|
||||
var ownerTypeName = ((INamedTypeSymbol)constant.Key.ContainingSymbol).ToDisplayString().Replace(".", "__");
|
||||
var constantName = $"__{ownerTypeName}__{constant.Key.Name}";
|
||||
|
||||
yield return new string[] { constantName, constant.Value };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of processed discovered custom types.
|
||||
/// </summary>
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// 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 aa replacement is needed.</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)
|
||||
|
||||
@@ -21,10 +21,37 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
[$"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.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 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>
|
||||
@@ -163,6 +190,49 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.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 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))
|
||||
{
|
||||
if (item.Property == groupindexProperty)
|
||||
{
|
||||
// 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");
|
||||
}
|
||||
else
|
||||
{
|
||||
knownMembers.Add($"{item.Type.FullName}{Type.Delimiter}{item.Property.Name}", $"{item.Type.Name}.{item.Property.Name.ToLower()}");
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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 == 1:
|
||||
knownMembers.Add(key, $"__GroupSize__get_{name[0]} * __GroupSize__get_{name[1]}");
|
||||
break;
|
||||
case string name when name.Length == 1:
|
||||
knownMembers.Add(key, $"__GroupSize__get_{name[0]} * __GroupSize__get_{name[1]} * __GroupSize__get_{name[2]}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return knownMembers;
|
||||
}
|
||||
|
||||
@@ -189,5 +259,26 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
{
|
||||
return KnownIndexers.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
[typeof(double).FullName] = "double",
|
||||
[typeof(Double2).FullName] = "double2",
|
||||
[typeof(Double3).FullName] = "double3",
|
||||
[typeof(Double4).FullName] = "double4",
|
||||
[typeof(ThreadIds).FullName] = "int3"
|
||||
[typeof(Double4).FullName] = "double4"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +49,6 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> HlslMappedVectorTypes { get; } = new[]
|
||||
{
|
||||
typeof(ThreadIds),
|
||||
typeof(Bool2), typeof(Bool3), typeof(Bool4),
|
||||
typeof(Int2), typeof(Int3), typeof(Int4),
|
||||
typeof(UInt2), typeof(UInt3), typeof(UInt4),
|
||||
@@ -58,6 +56,16 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
typeof(Double2), typeof(Double3), typeof(Double4)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the known HLSL dispatch types.
|
||||
/// </summary>
|
||||
public static IReadOnlyCollection<Type> HlslDispatchTypes { get; } = new[]
|
||||
{
|
||||
typeof(ThreadIds),
|
||||
typeof(GroupIds),
|
||||
typeof(WarpIds)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given type name matches a typed resource type.
|
||||
/// </summary>
|
||||
@@ -78,6 +86,10 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
case "ComputeSharp.ReadOnlyTexture3D`2":
|
||||
case "ComputeSharp.ReadWriteTexture3D`1":
|
||||
case "ComputeSharp.ReadWriteTexture3D`2":
|
||||
case "ComputeSharp.IReadOnlyTexture2D`1":
|
||||
case "ComputeSharp.IReadWriteTexture2D`1":
|
||||
case "ComputeSharp.IReadOnlyTexture3D`1":
|
||||
case "ComputeSharp.IReadWriteTexture3D`1":
|
||||
return true;
|
||||
default: return false;
|
||||
};
|
||||
@@ -90,9 +102,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// <returns>Whether or not <paramref name="typeName"/> represents a typed resource type.</returns>
|
||||
public static bool IsScalarOrVectorType(string typeName)
|
||||
{
|
||||
return
|
||||
KnownTypes.ContainsKey(typeName) &&
|
||||
typeName != typeof(ThreadIds).FullName;
|
||||
return KnownTypes.ContainsKey(typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,6 +144,10 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
"ComputeSharp.ReadOnlyTexture3D`2" => $"Texture3D<unorm {mapped}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mapped}>",
|
||||
"ComputeSharp.ReadWriteTexture3D`2" => $"RWTexture3D<unorm {mapped}>",
|
||||
"ComputeSharp.IReadOnlyTexture2D`1" => $"Texture2D<unorm {mapped}>",
|
||||
"ComputeSharp.IReadWriteTexture2D`1" => $"RWTexture2D<unorm {mapped}>",
|
||||
"ComputeSharp.IReadOnlyTexture3D`1" => $"Texture3D<unorm {mapped}>",
|
||||
"ComputeSharp.IReadWriteTexture3D`1" => $"RWTexture3D<unorm {mapped}>",
|
||||
_ => throw new ArgumentException()
|
||||
};
|
||||
}
|
||||
@@ -141,6 +155,24 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
return KnownTypes[typeName];
|
||||
}
|
||||
|
||||
/// <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 (KnownTypes.TryGetValue(elementTypeName, out string? mapped))
|
||||
{
|
||||
return mapped;
|
||||
}
|
||||
|
||||
return elementTypeName.Replace(".", "__");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mapped HLSL-compatible type name for the input type name.
|
||||
/// </summary>
|
||||
|
||||
@@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
using static ComputeSharp.SourceGenerators.Helpers.SyntaxFactoryHelper;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
@@ -44,23 +45,12 @@ namespace ComputeSharp.SourceGenerators
|
||||
// We need to sets to track all discovered custom types and static methods
|
||||
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var (invokeMethod, processedMethods) = GetProcessedMethods(methodDeclaration, semanticModel, discoveredTypes, staticMethods);
|
||||
var (invokeMethod, processedMethods) = GetProcessedMethods(methodDeclaration, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
var processedTypes = IComputeShaderSourceGenerator.GetProcessedTypes(discoveredTypes).ToArray();
|
||||
|
||||
// Helper that converts a sequence of strings into an array expression.
|
||||
// That is, this applies the following transformation:
|
||||
// - { "S1", "S2" } => new string[] { "S1", "S2" }
|
||||
static ArrayCreationExpressionSyntax ArrayExpression(IEnumerable<string> values)
|
||||
{
|
||||
return
|
||||
ArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword)))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(values.Select(static value => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(value))).ToArray()));
|
||||
}
|
||||
var processedConstants = IComputeShaderSourceGenerator.GetProcessedConstants(constantDefinitions);
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
@@ -70,7 +60,8 @@ namespace ComputeSharp.SourceGenerators
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(methodDeclarationSymbol.GetFullMetadataName(true)))),
|
||||
AttributeArgument(ArrayExpression(processedTypes)),
|
||||
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(invokeMethod))),
|
||||
AttributeArgument(ArrayExpression(processedMethods)))))
|
||||
AttributeArgument(ArrayExpression(processedMethods)),
|
||||
AttributeArgument(NestedArrayExpression(processedConstants)))))
|
||||
.WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList()))
|
||||
.WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword))))
|
||||
.NormalizeWhitespace()
|
||||
@@ -88,15 +79,17 @@ namespace ComputeSharp.SourceGenerators
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance for the method to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="staticMethods">The set of discovered and processed static methods.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="methodDeclaration"/>.</returns>
|
||||
[Pure]
|
||||
private static (string InvokeMethod, IEnumerable<string> Methods) GetProcessedMethods(
|
||||
MethodDeclarationSyntax methodDeclaration,
|
||||
SemanticModel semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods)
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(semanticModel, discoveredTypes, staticMethods);
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
|
||||
// Rewrite the method syntax tree
|
||||
var processedMethod = shaderSourceRewriter
|
||||
|
||||
@@ -11,17 +11,17 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
internal sealed class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
/// <summary>
|
||||
/// The identifier name for the input <see langword="uint3"/> parameter.
|
||||
/// The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.
|
||||
/// </summary>
|
||||
private readonly string threadIdsIdentifier;
|
||||
private readonly ShaderSourceRewriter shaderSourceRewriter;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ExecuteMethodRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="threadIdsIdentifier">The identifier name for the input <see langword="uint3"/> parameter.</param>
|
||||
public ExecuteMethodRewriter(string threadIdsIdentifier)
|
||||
/// <param name="shaderSourceRewriter">The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter)
|
||||
{
|
||||
this.threadIdsIdentifier = threadIdsIdentifier;
|
||||
this.shaderSourceRewriter = shaderSourceRewriter;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
@@ -32,11 +32,28 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode VisitParameter(ParameterSyntax node)
|
||||
public override SyntaxNode? VisitParameterList(ParameterListSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterSyntax)base.VisitParameter(node)!;
|
||||
var updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
|
||||
return updatedNode.WithIdentifier(Identifier($"{updatedNode.Identifier.Text} : SV_DispatchThreadId"));
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")));
|
||||
|
||||
if (this.shaderSourceRewriter.IsGroupIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(GroupIds)} : SV_GroupThreadID")));
|
||||
}
|
||||
|
||||
if (this.shaderSourceRewriter.IsGroupIdsIndexUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint __{nameof(GroupIds)}__get_Index : SV_GroupIndex")));
|
||||
}
|
||||
|
||||
if (this.shaderSourceRewriter.IsWarpIdsUsed)
|
||||
{
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(WarpIds)} : SV_GroupID")));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -48,9 +65,9 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
// The following snippet creates this prologue before the user provided body:
|
||||
//
|
||||
// if (ids.X < __x &&
|
||||
// ids.Y < __y &&
|
||||
// ids.Z < __z)
|
||||
// if (ThreadIds.x < __x &&
|
||||
// ThreadIds.y < __y &&
|
||||
// ThreadIds.z < __z)
|
||||
// {
|
||||
// <body>
|
||||
// }
|
||||
@@ -60,19 +77,19 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("x")),
|
||||
IdentifierName("__x")),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("y")),
|
||||
IdentifierName("__y"))),
|
||||
BinaryExpression(SyntaxKind.LessThanExpression,
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName(this.threadIdsIdentifier),
|
||||
IdentifierName(nameof(ThreadIds)),
|
||||
IdentifierName("z")),
|
||||
IdentifierName("__z")));
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// </summary>
|
||||
private readonly IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of discovered constant definitions.
|
||||
/// </summary>
|
||||
private readonly IDictionary<IFieldSymbol, string> constantDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// The collection of processed local functions in the current tree.
|
||||
/// </summary>
|
||||
@@ -59,16 +64,19 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> 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>
|
||||
public ShaderSourceRewriter(
|
||||
INamedTypeSymbol shaderType,
|
||||
SemanticModel semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods)
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
this.shaderType = shaderType;
|
||||
this.semanticModel = semanticModel;
|
||||
this.discoveredTypes = discoveredTypes;
|
||||
this.staticMethods = staticMethods;
|
||||
this.constantDefinitions = constantDefinitions;
|
||||
this.localFunctions = new();
|
||||
this.implicitVariables = new();
|
||||
}
|
||||
@@ -79,14 +87,17 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// <param name="semanticModel">The <see cref="SemanticModel"/> 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>
|
||||
public ShaderSourceRewriter(
|
||||
SemanticModel semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods)
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
this.semanticModel = semanticModel;
|
||||
this.discoveredTypes = discoveredTypes;
|
||||
this.staticMethods = staticMethods;
|
||||
this.constantDefinitions = constantDefinitions;
|
||||
this.implicitVariables = new();
|
||||
this.localFunctions = new();
|
||||
}
|
||||
@@ -96,6 +107,21 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// </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="WarpIds"/> at least once.
|
||||
/// </summary>
|
||||
public bool IsWarpIdsUsed { get; set; }
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public MethodDeclarationSyntax? Visit(MethodDeclarationSyntax? node)
|
||||
{
|
||||
@@ -282,31 +308,93 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
this.semanticModel.GetOperation(node) is IMemberReferenceOperation operation)
|
||||
{
|
||||
// If the current member access is to a constant, hardcode the value in HLSL
|
||||
if (operation.ConstantValue is { HasValue: true } and { Value: object value })
|
||||
// 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)
|
||||
{
|
||||
return ParseExpression(value switch
|
||||
{
|
||||
IFormattable f => f.ToString(null, CultureInfo.InvariantCulture),
|
||||
_ => value.ToString()
|
||||
});
|
||||
this.constantDefinitions[fieldOperation.Field] = ((IFormattable)fieldOperation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)fieldOperation.Field.ContainingSymbol).ToDisplayString().Replace(".", "__");
|
||||
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)
|
||||
{
|
||||
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(WarpIds).FullName) IsWarpIdsUsed = true;
|
||||
}
|
||||
|
||||
// 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 two cases:
|
||||
// For instance, consider these three cases:
|
||||
// - Vector3.One (static) => float3(1.0f, 1.0f, 1.0f)
|
||||
// - ThredIds.X (instance) => [arg].x
|
||||
// - 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))
|
||||
{
|
||||
IMethodSymbol key = propertyOperation.Property.GetMethod!;
|
||||
|
||||
if (!this.staticMethods.TryGetValue(key, out MethodDeclarationSyntax? methodSyntax))
|
||||
{
|
||||
INamedTypeSymbol resourceType = (INamedTypeSymbol)this.semanticModel.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));
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
@@ -348,7 +436,7 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
|
||||
if (!this.staticMethods.ContainsKey(method))
|
||||
{
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(this.semanticModel, this.discoveredTypes, this.staticMethods);
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(this.semanticModel, this.discoveredTypes, this.staticMethods, this.constantDefinitions);
|
||||
MethodDeclarationSyntax
|
||||
methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax(),
|
||||
processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace().WithoutTrivia();
|
||||
@@ -402,6 +490,24 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
{
|
||||
var updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;
|
||||
|
||||
if (this.semanticModel.GetOperation(node) is IFieldReferenceOperation operation && operation.Field.IsConst)
|
||||
{
|
||||
this.constantDefinitions[operation.Field] = ((IFormattable)operation.Field.ConstantValue!).ToString(null, CultureInfo.InvariantCulture);
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)operation.Field.ContainingSymbol).ToDisplayString().Replace(".", "__");
|
||||
var constantName = $"__{ownerTypeName}__{operation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxToken VisitToken(SyntaxToken token)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TargetFrameworks>net5.0</TargetFrameworks>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<DocumentationFile>ComputeSharp.xml</DocumentationFile>
|
||||
<Description>ComputeSharp</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Resources;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp
|
||||
@@ -63,7 +63,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
|
||||
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="bufferOffset">The offset to start reading data from.</param>
|
||||
/// <param name="count">The number of items to read.</param>
|
||||
public static void GetData<T>(this Buffer<T> buffer, T[] destination, int destinationOffset, int bufferOffset, int count)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Resources;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp
|
||||
@@ -91,7 +91,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void GetData<T>(this Texture2D<T> texture, T[] destination, int offset)
|
||||
where T : unmanaged
|
||||
{
|
||||
@@ -104,7 +104,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
public static void GetData<T>(this Texture2D<T> texture, T[] destination, int offset, Range x, Range y)
|
||||
@@ -119,7 +119,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="width">The width of the memory area to copy.</param>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Resources;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp
|
||||
@@ -41,7 +41,7 @@ namespace ComputeSharp
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <remarks>
|
||||
/// The input 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
|
||||
/// layout of the input array has to be [<see cref="Depth"/>, <see cref="Height"/>, <see cref="Width"/>].
|
||||
/// layout of the input array has to be of shape [depth, height, width].
|
||||
/// </remarks>
|
||||
public static void GetData<T>(this Texture3D<T> texture, T[,,] destination)
|
||||
where T : unmanaged
|
||||
@@ -59,7 +59,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
public static void GetData<T>(this Texture3D<T> texture, T[] destination, int offset)
|
||||
where T : unmanaged
|
||||
{
|
||||
@@ -72,7 +72,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal range of items to copy.</param>
|
||||
/// <param name="y">The vertical range of items to copy.</param>
|
||||
/// <param name="z">The depthwise range of items to copy.</param>
|
||||
@@ -88,7 +88,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
|
||||
/// <param name="destination">The input array to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to write data to.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
|
||||
/// <param name="x">The horizontal offset in the source texture.</param>
|
||||
/// <param name="y">The vertical offset in the source texture.</param>
|
||||
/// <param name="z">The depthwise offset in the source texture.</param>
|
||||
@@ -158,7 +158,7 @@ namespace ComputeSharp
|
||||
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
|
||||
/// <remarks>
|
||||
/// The source 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
|
||||
/// layout of the input array has to be [<see cref="Depth"/>, <see cref="Height"/>, <see cref="Width"/>].
|
||||
/// layout of the input array has to be of shape [depth, height, width].
|
||||
/// </remarks>
|
||||
public static void SetData<T>(this Texture3D<T> texture, T[,,] source)
|
||||
where T : unmanaged
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Resources;
|
||||
using ComputeSharp.Shaders;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
@@ -20,12 +19,13 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
|
||||
/// <param name="length">The length of the buffer to allocate.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ConstantBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
|
||||
[Pure]
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, int length)
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, length);
|
||||
return new(device, length, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,7 +53,7 @@ namespace ComputeSharp
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
ConstantBuffer<T> buffer = new(device, span.Length);
|
||||
ConstantBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
|
||||
|
||||
buffer.SetData(span);
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace ComputeSharp
|
||||
public static ConstantBuffer<T> AllocateConstantBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
|
||||
where T : unmanaged
|
||||
{
|
||||
ConstantBuffer<T> constantBuffer = new(device, buffer.Length);
|
||||
ConstantBuffer<T> constantBuffer = new(device, buffer.Length, AllocationMode.Default);
|
||||
|
||||
constantBuffer.SetData(buffer);
|
||||
|
||||
@@ -84,12 +84,13 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
|
||||
/// <param name="length">The length of the buffer to allocate.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, int length)
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, length);
|
||||
return new(device, length, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,7 +118,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyBuffer<T> buffer = new(device, span.Length);
|
||||
ReadOnlyBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
|
||||
|
||||
buffer.SetData(span);
|
||||
|
||||
@@ -135,7 +136,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyBuffer<T> AllocateReadOnlyBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyBuffer<T> readWriteBuffer = new(device, buffer.Length);
|
||||
ReadOnlyBuffer<T> readWriteBuffer = new(device, buffer.Length, AllocationMode.Default);
|
||||
|
||||
readWriteBuffer.SetData(buffer);
|
||||
|
||||
@@ -149,12 +150,13 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, int width, int height)
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
return new(device, width, height, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,7 +181,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadOnlyTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
@@ -201,7 +203,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, T[,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
ReadOnlyTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -221,7 +223,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T> texture = new(device, width, height);
|
||||
ReadOnlyTexture2D<T> texture = new(device, width, height, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -236,13 +238,14 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyTexture2D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T, TPixel> AllocateReadOnlyTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height)
|
||||
public static ReadOnlyTexture2D<T, TPixel> AllocateReadOnlyTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
return new(device, width, height, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -270,7 +273,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadOnlyTexture2D{T,TPixel}"/> instance with the contents of the input array.</returns>
|
||||
@@ -295,7 +298,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
ReadOnlyTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -317,7 +320,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T, TPixel> texture = new(device, width, height);
|
||||
ReadOnlyTexture2D<T, TPixel> texture = new(device, width, height, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -332,12 +335,13 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, int width, int height, int depth)
|
||||
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height, depth);
|
||||
return new(device, width, height, depth, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -363,7 +367,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
@@ -390,7 +394,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, T[,,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
|
||||
ReadOnlyTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -411,7 +415,7 @@ namespace ComputeSharp
|
||||
public static ReadOnlyTexture3D<T> AllocateReadOnlyTexture3D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture3D<T> texture = new(device, width, height, depth);
|
||||
ReadOnlyTexture3D<T> texture = new(device, width, height, depth, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -427,13 +431,14 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>, <paramref name="depth"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture3D<T, TPixel> AllocateReadOnlyTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth)
|
||||
public static ReadOnlyTexture3D<T, TPixel> AllocateReadOnlyTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return new(device, width, height, depth);
|
||||
return new(device, width, height, depth, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -462,7 +467,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
@@ -492,7 +497,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadOnlyTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
|
||||
ReadOnlyTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -515,7 +520,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadOnlyTexture3D<T, TPixel> texture = new(device, width, height, depth);
|
||||
ReadOnlyTexture3D<T, TPixel> texture = new(device, width, height, depth, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -528,12 +533,13 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the buffer.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the buffer.</param>
|
||||
/// <param name="length">The length of the buffer to allocate.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteBuffer{T}"/> instance of size <paramref name="length"/>.</returns>
|
||||
[Pure]
|
||||
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int length)
|
||||
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, int length, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, length);
|
||||
return new(device, length, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -561,7 +567,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, ReadOnlySpan<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteBuffer<T> buffer = new(device, span.Length);
|
||||
ReadWriteBuffer<T> buffer = new(device, span.Length, AllocationMode.Default);
|
||||
|
||||
buffer.SetData(span);
|
||||
|
||||
@@ -579,7 +585,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteBuffer<T> AllocateReadWriteBuffer<T>(this GraphicsDevice device, Buffer<T> buffer)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteBuffer<T> readWriteBuffer = new(device, buffer.Length);
|
||||
ReadWriteBuffer<T> readWriteBuffer = new(device, buffer.Length, AllocationMode.Default);
|
||||
|
||||
readWriteBuffer.SetData(buffer);
|
||||
|
||||
@@ -593,12 +599,13 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, int width, int height)
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
return new(device, width, height, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -623,7 +630,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadWriteTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
@@ -645,7 +652,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, T[,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
ReadWriteTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -665,7 +672,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T> texture = new(device, width, height);
|
||||
ReadWriteTexture2D<T> texture = new(device, width, height, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -680,13 +687,14 @@ namespace ComputeSharp
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteTexture2D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T, TPixel> AllocateReadWriteTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height)
|
||||
public static ReadWriteTexture2D<T, TPixel> AllocateReadWriteTexture2D<T, TPixel>(this GraphicsDevice device, int width, int height, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
return new(device, width, height, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -714,7 +722,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadWriteTexture2D{T,TPixel}"/> instance with the contents of the input array.</returns>
|
||||
@@ -739,7 +747,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
ReadWriteTexture2D<T, TPixel> texture = new(device, array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -761,7 +769,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T, TPixel> texture = new(device, width, height);
|
||||
ReadWriteTexture2D<T, TPixel> texture = new(device, width, height, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -776,12 +784,13 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteTexture3D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, int width, int height, int depth)
|
||||
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height, depth);
|
||||
return new(device, width, height, depth, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -807,7 +816,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
@@ -834,7 +843,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, T[,,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
|
||||
ReadWriteTexture3D<T> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -855,7 +864,7 @@ namespace ComputeSharp
|
||||
public static ReadWriteTexture3D<T> AllocateReadWriteTexture3D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height, int depth)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture3D<T> texture = new(device, width, height, depth);
|
||||
ReadWriteTexture3D<T> texture = new(device, width, height, depth, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
@@ -871,13 +880,14 @@ namespace ComputeSharp
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="allocationMode">The allocation mode to use for the new resource.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteTexture3D{T,TPixel}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture3D<T, TPixel> AllocateReadWriteTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth)
|
||||
public static ReadWriteTexture3D<T, TPixel> AllocateReadWriteTexture3D<T, TPixel>(this GraphicsDevice device, int width, int height, int depth, AllocationMode allocationMode = AllocationMode.Default)
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
return new(device, width, height, depth);
|
||||
return new(device, width, height, depth, allocationMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -906,7 +916,7 @@ namespace ComputeSharp
|
||||
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="array"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
@@ -936,7 +946,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadWriteTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
|
||||
ReadWriteTexture3D<T, TPixel> texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0), AllocationMode.Default);
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
@@ -959,7 +969,7 @@ namespace ComputeSharp
|
||||
where T : unmanaged, IUnorm<TPixel>
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
ReadWriteTexture3D<T, TPixel> texture = new(device, width, height, depth);
|
||||
ReadWriteTexture3D<T, TPixel> texture = new(device, width, height, depth, AllocationMode.Default);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.Graphics;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
|
||||
namespace ComputeSharp
|
||||
|
||||
116ファイル中100ファイルを読み込みました。 変更されたファイルが多すぎるため、それ以降のファイルは表示していません。
さらに表示
新しいイシューから参照
ユーザーをブロックする