diff --git a/.gitignore b/.gitignore index fd8f3e38..b266c367 100644 --- a/.gitignore +++ b/.gitignore @@ -330,4 +330,7 @@ ASALocalRun/ .mfractor/ # Sample images -**/city_*.jpg +samples/**/city_*.jpg + +# XML docs files +src/**/ComputeSharp*.xml \ No newline at end of file diff --git a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs index 687f86bb..d1e3df0a 100644 --- a/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs +++ b/samples/ComputeSharp.Benchmark/Blas/BlasHelpers.cs @@ -92,17 +92,17 @@ namespace ComputeSharp.Benchmark.Blas public readonly ReadWriteBuffer y; /// - 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]; } } } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 5ac36156..9ae94951 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -302,7 +302,7 @@ namespace ComputeSharp.BokehBlur.Processors public ReadOnlyBuffer kernel; /// - public void Execute(ThreadIds ids) + public void Execute() { Vector4 real = Vector4.Zero; Vector4 imaginary = Vector4.Zero; @@ -313,8 +313,8 @@ namespace ComputeSharp.BokehBlur.Processors for (int i = 0; i < kernelLength; i++) { - int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY); - int offsetX = Hlsl.Clamp(ids.X, 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]; @@ -322,8 +322,8 @@ namespace ComputeSharp.BokehBlur.Processors imaginary += factors.Imaginary * color; } - reals[ids.XY] = real; - imaginaries[ids.XY] = imaginary; + reals[ThreadIds.XY] = real; + imaginaries[ThreadIds.XY] = imaginary; } } @@ -342,7 +342,7 @@ namespace ComputeSharp.BokehBlur.Processors public ReadOnlyBuffer kernel; /// - public void Execute(ThreadIds ids) + public void Execute() { Vector4 real = Vector4.Zero; Vector4 imaginary = Vector4.Zero; @@ -350,11 +350,11 @@ namespace ComputeSharp.BokehBlur.Processors int maxX = target.Width; int kernelLength = kernel.Length; int radiusX = kernelLength >> 1; - 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(ids.X + 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]; @@ -363,7 +363,7 @@ 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; } } @@ -376,17 +376,17 @@ namespace ComputeSharp.BokehBlur.Processors public readonly IReadWriteTexture2D source; /// - 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; } } } @@ -401,18 +401,18 @@ namespace ComputeSharp.BokehBlur.Processors public readonly IReadWriteTexture2D target; /// - 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; } } } diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index 0aad185e..3126f2d4 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -115,7 +115,7 @@ namespace ComputeSharp.BokehBlur.Processors public readonly ReadOnlyBuffer kernel; /// - public void Execute(ThreadIds ids) + public void Execute() { Vector4 result = Vector4.Zero; int maxY = source.Height - 1; @@ -125,14 +125,14 @@ namespace ComputeSharp.BokehBlur.Processors for (int i = 0; i < kernelLength; i++) { - int offsetY = Hlsl.Clamp(ids.Y + i - radiusY, 0, maxY); - int offsetX = Hlsl.Clamp(ids.X, 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; } } @@ -147,24 +147,24 @@ namespace ComputeSharp.BokehBlur.Processors public readonly ReadOnlyBuffer kernel; /// - 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 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(ids.X + 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; } } } diff --git a/samples/ComputeSharp.Sample.Shared/Program.cs b/samples/ComputeSharp.Sample.Shared/Program.cs index b56d467d..e20ef49d 100644 --- a/samples/ComputeSharp.Sample.Shared/Program.cs +++ b/samples/ComputeSharp.Sample.Shared/Program.cs @@ -47,9 +47,9 @@ namespace ComputeSharp.Sample public readonly ReadWriteBuffer buffer; /// - public void Execute(ThreadIds ids) + public void Execute() { - buffer[ids.X] *= 2; + buffer[ThreadIds.X] *= 2; } } diff --git a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs index bd4dc3e7..c5db9978 100644 --- a/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/AutoConstructorAttribute.cs @@ -5,7 +5,7 @@ namespace ComputeSharp /// /// An attribute that indicates that a target shader type should get an automatic constructor for all fields. /// - [AttributeUsage(AttributeTargets.Struct)] + [AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] public sealed class AutoConstructorAttribute : Attribute { } diff --git a/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs b/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs new file mode 100644 index 00000000..06f561ba --- /dev/null +++ b/src/ComputeSharp.Core/Attributes/GroupSharedAttribute.cs @@ -0,0 +1,46 @@ +using System; + +namespace ComputeSharp +{ + /// + /// An attribute that indicates that an array static field in a shader type will be shared in a thread group. + /// + /// This attribute can be used to declare fields as follows: + /// + /// struct MyShader : IComputeShader + /// { + /// [GroupShared(32)] + /// static float[] MyBuffer; + /// } + /// + /// + /// 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. + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] + public sealed class GroupSharedAttribute : Attribute + { + /// + /// Creates a new instance with the specified parameters. + /// + public GroupSharedAttribute() + { + } + + /// + /// Creates a new instance with the specified parameters. + /// + /// The size of the shared buffer to declare. + public GroupSharedAttribute(int size) + { + Size = size; + } + + /// + /// Gets the size of the shared buffer being declared. + /// If , the thread group size will be used. + /// + public int? Size { get; } + } +} \ No newline at end of file diff --git a/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs b/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs index 9eae4f37..d644045c 100644 --- a/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/ShaderMethodAttribute.cs @@ -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. /// - [AttributeUsage(AttributeTargets.Method)] + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class ShaderMethodAttribute : Attribute { } diff --git a/src/ComputeSharp.Core/Attributes/__Internals/IComputeShaderSourceAttribute.cs b/src/ComputeSharp.Core/Attributes/__Internals/IComputeShaderSourceAttribute.cs index 91c92c52..7cd9407c 100644 --- a/src/ComputeSharp.Core/Attributes/__Internals/IComputeShaderSourceAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/__Internals/IComputeShaderSourceAttribute.cs @@ -25,13 +25,15 @@ namespace ComputeSharp.__Internals /// The source code for the method. /// The collection of processed methods. /// The collection of discovered constants. + /// The collection of group shared buffers public IComputeShaderSourceAttribute( string shaderTypeName, string[] types, object[] args, string executeMethod, string[] methods, - object[] constants) + object[] constants, + object[] sharedBuffers) { ShaderTypeName = shaderTypeName; Types = types; @@ -39,6 +41,7 @@ namespace ComputeSharp.__Internals ExecuteMethod = executeMethod; Methods = methods; Constants = constants.Cast().ToDictionary(static c => c[0], static c => c[1]); + SharedBuffers = sharedBuffers.Cast().ToDictionary(static t => (string)t[0], static t => ((string)t[1], (int?)t[2])); } /// @@ -71,6 +74,11 @@ namespace ComputeSharp.__Internals /// internal IReadOnlyDictionary Constants { get; } + /// + /// Gets the collection of discovered constants. + /// + internal IReadOnlyDictionary SharedBuffers { get; } + /// /// Gets the associated instance for a specified type. /// diff --git a/src/ComputeSharp.Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs b/src/ComputeSharp.Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs index 97104dfd..8d0bbce3 100644 --- a/src/ComputeSharp.Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs +++ b/src/ComputeSharp.Core/Attributes/__Internals/ShaderMethodSourceAttribute.cs @@ -79,10 +79,10 @@ namespace ComputeSharp.__Internals } /// - /// Gets the associated instance for a specified type. + /// Gets the associated instance for a specified delegate. /// - /// The shader type to get the attribute for. - /// The associated instance for type . + /// The input instance to get info for. + /// The associated instance for the given delegate. [Pure] internal static ShaderMethodSourceAttribute GetForDelegate(Delegate function) { diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index a76d03f4..4df5b272 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -2,6 +2,8 @@ netstandard2.0;net5.0 + bin\Release + ComputeSharp.Core.xml diff --git a/src/ComputeSharp.Core/Dispatch/GroupIds.cs b/src/ComputeSharp.Core/Dispatch/GroupIds.cs new file mode 100644 index 00000000..18473a80 --- /dev/null +++ b/src/ComputeSharp.Core/Dispatch/GroupIds.cs @@ -0,0 +1,210 @@ +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + /// A that indicates the ids of a given GPU thread running a compute shader within a dispatch group. + /// + public static class GroupIds + { + /// + /// Gets the flattened index of the current thread with respect to the dispatch group. + /// + public static int Index => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(Index)}"); + + /// + /// Gets the X id of the current thread with respect to the dispatch group. + /// + public static int X => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(X)}"); + + /// + /// Gets the Y id of the current thread with respect to the dispatch group. + /// + public static int Y => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(Y)}"); + + /// + /// Gets the Z id of the current thread with respect to the dispatch group. + /// + public static int Z => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(Z)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZ)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(XZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YYZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(YZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZXZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(GroupIds)}.{nameof(ZZZ)}"); + } +} diff --git a/src/ComputeSharp.Core/Dispatch/GroupSize.cs b/src/ComputeSharp.Core/Dispatch/GroupSize.cs new file mode 100644 index 00000000..0b4973c8 --- /dev/null +++ b/src/ComputeSharp.Core/Dispatch/GroupSize.cs @@ -0,0 +1,210 @@ +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + /// A that indicates the size info of a given GPU thread group running a compute shader within. + /// + public static class GroupSize + { + /// + /// Gets the total size of the current thread group. + /// + public static int Count => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Count)}"); + + /// + /// Gets the size of the X axis of the current thread group. + /// + public static int X => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(X)}"); + + /// + /// Gets the size of the Y axis of the current thread group. + /// + public static int Y => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Y)}"); + + /// + /// Gets the size of the Z axis of the current thread group. + /// + public static int Z => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(Z)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZ)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(XZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YYZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(YZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZXZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(GroupSize)}.{nameof(ZZZ)}"); + } +} diff --git a/src/ComputeSharp.Core/Primitives/ThreadIds.cs b/src/ComputeSharp.Core/Dispatch/ThreadIds.cs similarity index 56% rename from src/ComputeSharp.Core/Primitives/ThreadIds.cs rename to src/ComputeSharp.Core/Dispatch/ThreadIds.cs index 69f58032..175d5f5a 100644 --- a/src/ComputeSharp.Core/Primitives/ThreadIds.cs +++ b/src/ComputeSharp.Core/Dispatch/ThreadIds.cs @@ -3,203 +3,203 @@ namespace ComputeSharp { /// - /// A that indicates the ids of a given GPU thread running a compute shader. + /// A that indicates the ids of a given GPU thread running a compute shader. /// - public readonly ref struct ThreadIds + public static class ThreadIds { /// /// Gets the X id of the current thread. /// - public int X => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(X)}"); + public static int X => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(X)}"); /// /// Gets the Y id of the current thread. /// - public int Y => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Y)}"); + public static int Y => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Y)}"); /// /// Gets the Z id of the current thread. /// - public int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}"); + public static int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}"); /// /// Gets an value with the value for all components. /// - public Int2 XX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XX)}"); + public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XX)}"); /// /// Gets or sets an value with the and values. /// - public Int2 XY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XY)}"); + public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XY)}"); /// /// Gets or sets an value with the and values. /// - public Int2 XZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZ)}"); + public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZ)}"); /// /// Gets or sets an value with the and values. /// - public Int2 YX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YX)}"); + public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YX)}"); /// /// Gets an value with the value for all components. /// - public Int2 YY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YY)}"); + public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YY)}"); /// /// Gets or sets an value with the and values. /// - public Int2 YZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZ)}"); + public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZ)}"); /// /// Gets or sets an value with the and values. /// - public Int2 ZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZX)}"); + public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZX)}"); /// /// Gets or sets an value with the and values. /// - public Int2 ZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZY)}"); + public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZY)}"); /// /// Gets an value with the value for all components. /// - public Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZ)}"); + public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZ)}"); /// /// Gets an value with the value for all components. /// - public Int3 XXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXX)}"); + public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXX)}"); /// /// Gets an value with the , and values. /// - public Int3 XXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXY)}"); + public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXY)}"); /// /// Gets an value with the , and values. /// - public Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXZ)}"); + public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXZ)}"); /// /// Gets an value with the , and values. /// - public Int3 XYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYX)}"); + public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYX)}"); /// /// Gets an value with the , and values. /// - public Int3 XYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYY)}"); + public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYY)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYZ)}"); + public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYZ)}"); /// /// Gets an value with the , and values. /// - public Int3 XZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZX)}"); + public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZX)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 XZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZY)}"); + public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZY)}"); /// /// Gets an value with the , and values. /// - public Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZZ)}"); + public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZZ)}"); /// /// Gets an value with the , and values. /// - public Int3 YXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXX)}"); + public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXX)}"); /// /// Gets an value with the , and values. /// - public Int3 YXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXY)}"); + public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXY)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXZ)}"); + public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXZ)}"); /// /// Gets an value with the , and values. /// - public Int3 YYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYX)}"); + public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYX)}"); /// /// Gets an value with the value for all components. /// - public Int3 YYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYY)}"); + public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYY)}"); /// /// Gets an value with the , and values. /// - public Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYZ)}"); + public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYZ)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 YZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZX)}"); + public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZX)}"); /// /// Gets an value with the , and values. /// - public Int3 YZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZY)}"); + public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZY)}"); /// /// Gets an value with the , and values. /// - public Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZZ)}"); + public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZZ)}"); /// /// Gets an value with the , and values. /// - public Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXX)}"); + public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXX)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXY)}"); + public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXY)}"); /// /// Gets an value with the , and values. /// - public Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXZ)}"); + public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXZ)}"); /// /// Gets or sets an value with the , and values. /// - public Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYX)}"); + public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYX)}"); /// /// Gets an value with the , and values. /// - public Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYY)}"); + public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYY)}"); /// /// Gets an value with the , and values. /// - public Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYZ)}"); + public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYZ)}"); /// /// Gets an value with the , and values. /// - public Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZX)}"); + public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZX)}"); /// /// Gets an value with the , and values. /// - public Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZY)}"); + public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZY)}"); /// /// Gets an value with the value for all components. /// - public Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}"); + public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}"); } } diff --git a/src/ComputeSharp.Core/Dispatch/WarpIds.cs b/src/ComputeSharp.Core/Dispatch/WarpIds.cs new file mode 100644 index 00000000..2c02cdbb --- /dev/null +++ b/src/ComputeSharp.Core/Dispatch/WarpIds.cs @@ -0,0 +1,205 @@ +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + /// A that indicates the ids of a given dispatch warp (a group of threads). + /// + public static class WarpIds + { + /// + /// Gets the X id of the current thread with respect to the dispatch group. + /// + public static int X => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(X)}"); + + /// + /// Gets the Y id of the current thread with respect to the dispatch group. + /// + public static int Y => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(Y)}"); + + /// + /// Gets the Z id of the current thread with respect to the dispatch group. + /// + public static int Z => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(Z)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZ)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZZ)}"); + } +} diff --git a/src/ComputeSharp.Core/Interfaces/IComputeShader.cs b/src/ComputeSharp.Core/Interfaces/IComputeShader.cs index 66f145dd..37f5396d 100644 --- a/src/ComputeSharp.Core/Interfaces/IComputeShader.cs +++ b/src/ComputeSharp.Core/Interfaces/IComputeShader.cs @@ -8,7 +8,6 @@ /// /// Executes the current compute shader. /// - /// The value with the current execution indices. - void Execute(ThreadIds ids); + void Execute(); } } diff --git a/src/ComputeSharp.Core/Intrinsics/Hlsl.cs b/src/ComputeSharp.Core/Intrinsics/Hlsl.cs index c58a3301..3d757637 100644 --- a/src/ComputeSharp.Core/Intrinsics/Hlsl.cs +++ b/src/ComputeSharp.Core/Intrinsics/Hlsl.cs @@ -153,6 +153,28 @@ namespace ComputeSharp [Pure] public static bool All(Float4 x) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(All)}({nameof(Float4)})"); + /// + /// Blocks execution of all threads in a group until all memory accesses have been completed. + /// + /// + /// 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. + /// + [PreserveMemberName] + public static void AllMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(AllMemoryBarrier)}()"); + + /// + /// 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. + /// + /// + /// 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. + /// + [PreserveMemberName] + public static void AllMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(AllMemoryBarrierWithGroupSync)}()"); + /// /// Determines if any components of the specified value are non-zero. /// @@ -616,6 +638,18 @@ namespace ComputeSharp [Pure] public static Float3 Degrees(Float4 x) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(Degrees)}({nameof(Float4)})"); + /// + /// Blocks execution of all threads in a group until all device memory accesses have been completed. + /// + [PreserveMemberName] + public static void DeviceMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(DeviceMemoryBarrier)}()"); + + /// + /// 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. + /// + [PreserveMemberName] + public static void DeviceMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(DeviceMemoryBarrierWithGroupSync)}()"); + /// /// Returns a distance scalar between two values. /// @@ -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)})"); + /// + /// Blocks execution of all threads in a group until all group shared accesses have been completed. + /// + [PreserveMemberName] + public static void GroupMemoryBarrier() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(GroupMemoryBarrier)}()"); + + /// + /// 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. + /// + [PreserveMemberName] + public static void GroupMemoryBarrierWithGroupSync() => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(GroupMemoryBarrierWithGroupSync)}()"); + /// /// Performs a guaranteed atomic add of a value to a destination. /// diff --git a/src/ComputeSharp.Core/PixelTypes/Rg16.cs b/src/ComputeSharp.Core/PixelTypes/Rg16.cs index dd3b6ce9..5da5ce6d 100644 --- a/src/ComputeSharp.Core/PixelTypes/Rg16.cs +++ b/src/ComputeSharp.Core/PixelTypes/Rg16.cs @@ -30,8 +30,8 @@ namespace ComputeSharp /// /// Initializes a new instance of the struct. /// - /// The x-component - /// The y-component + /// The red component. + /// The green component. public Rg16(byte r, byte g) { R = r; diff --git a/src/ComputeSharp.Core/PixelTypes/Rg32.cs b/src/ComputeSharp.Core/PixelTypes/Rg32.cs index 10f5a7c1..8d0e39ba 100644 --- a/src/ComputeSharp.Core/PixelTypes/Rg32.cs +++ b/src/ComputeSharp.Core/PixelTypes/Rg32.cs @@ -30,8 +30,8 @@ namespace ComputeSharp /// /// Initializes a new instance of the struct. /// - /// The x-component - /// The y-component + /// The red component. + /// The green component. public Rg32(ushort r, ushort g) { R = r; diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.cs b/src/ComputeSharp.Core/Primitives/Float/Float3.cs index eeeea995..4c1893c6 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float3.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float3.cs @@ -567,13 +567,13 @@ namespace ComputeSharp /// /// Casts a value to a one. /// - /// The input value to cast. + /// The input value to cast. public static unsafe implicit operator Vector3(Float3 xyz) => *(Vector3*)&xyz; /// /// Casts a value to a one. /// - /// The input value to cast. + /// The input value to cast. public static unsafe implicit operator Float3(Vector3 xyz) => *(Float3*)&xyz; /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.cs b/src/ComputeSharp.Core/Primitives/Float/Float4.cs index 5b7904a6..f6192624 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float4.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float4.cs @@ -3972,13 +3972,13 @@ namespace ComputeSharp /// /// Casts a value to a one. /// - /// The input value to cast. + /// The input value to cast. public static unsafe implicit operator Vector4(Float4 xyzw) => *(Vector4*)&xyzw; /// /// Casts a value to a one. /// - /// The input value to cast. + /// The input value to cast. public static unsafe implicit operator Float4(Vector4 xyzw) => *(Float4*)&xyzw; /// diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs index f75edc4f..58bd809a 100644 --- a/src/ComputeSharp.Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs @@ -120,6 +120,7 @@ namespace ComputeSharp.Graphics.Commands /// The source (a texture) to read from. /// The horizontal offset in the destination texture. /// The vertical offset in the destination texture. + /// The depthwise offset in the destination texture. /// The width of the memory area to read from. /// The height of the memory area to read from. /// The depth of the memory area to read from. @@ -166,7 +167,7 @@ namespace ComputeSharp.Graphics.Commands /// /// Sets a given object ready to be executed. /// - /// The input to setup. + /// The input to setup. public readonly void SetPipelineData(PipelineData pipelineData) { this.d3D12GraphicsCommandList.Get()->SetComputeRootSignature(pipelineData.D3D12RootSignature); diff --git a/src/ComputeSharp.Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs b/src/ComputeSharp.Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs index f41b8007..5b869e48 100644 --- a/src/ComputeSharp.Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs +++ b/src/ComputeSharp.Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs @@ -79,7 +79,7 @@ namespace ComputeSharp.Graphics.Commands.Interop /// Rents a new CPU and GPU handle pair to use in a memory buffer. /// /// The resulting value. - /// The resulting value. + /// The resulting value. public void Rent( out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle) @@ -106,7 +106,7 @@ namespace ComputeSharp.Graphics.Commands.Interop /// Returns a CPU and GPU handle pair for later use. /// /// The returned value. - /// The returned value. + /// The returned value. public void Return( D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle) diff --git a/src/ComputeSharp.Graphics/Commands/PipelineData.cs b/src/ComputeSharp.Graphics/Commands/PipelineData.cs index d25c1fe0..be6ad0eb 100644 --- a/src/ComputeSharp.Graphics/Commands/PipelineData.cs +++ b/src/ComputeSharp.Graphics/Commands/PipelineData.cs @@ -19,11 +19,10 @@ namespace ComputeSharp.Graphics.Commands private ComPtr d3D12PipelineState; /// - /// Creates a new instance with the specified parameters. + /// Creates a new instance with the specified parameters. /// - /// The to use. - /// The value for the current shader. - /// The bytecode for the compute shader to run. + /// The value for the current shader. + /// The compiled pipeline state to reuse for the current shader. public PipelineData(ComPtr d3D12RootSignature, ComPtr d3D12PipelineState) { this.d3D12RootSignature = d3D12RootSignature; diff --git a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj index e52ebdb8..96c738d6 100644 --- a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj +++ b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj @@ -2,11 +2,13 @@ netstandard2.0;net5.0 + bin\Release + ComputeSharp.Graphics.xml - - + + diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs index 6d177f7c..971f3db3 100644 --- a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs @@ -423,6 +423,7 @@ namespace ComputeSharp.Graphics.Extensions /// /// The target to use to create the command list. /// The type of command list to create. + /// The command allocator to use to create the command list. /// A pointer to the newly allocated instance. /// Thrown when the creation of the command list fails. public static ComPtr CreateCommandList( diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs index 824becaf..600ded21 100644 --- a/src/ComputeSharp.Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs @@ -152,11 +152,11 @@ namespace ComputeSharp internal bool IsCacheCoherentUMA { get; } /// - /// Checks whether the current device supports the creation of + /// Checks whether the current device supports the creation of /// resources for a specified type . /// /// The type of values to check support for. - /// Whether instances can be created by the current device. + /// Whether instances can be created by the current device. [Pure] public bool IsTexture2DSupportedForType() where T : unmanaged @@ -167,11 +167,11 @@ namespace ComputeSharp } /// - /// Checks whether the current device supports the creation of + /// Checks whether the current device supports the creation of /// resources for a specified type . /// /// The type of values to check support for. - /// Whether instances can be created by the current device. + /// Whether instances can be created by the current device. [Pure] public bool IsTexture3DSupportedForType() where T : unmanaged @@ -181,7 +181,7 @@ namespace ComputeSharp return this.d3D12Device.Get()->IsDxgiFormatSupported(DXGIFormatHelper.GetForType(), D3D12_FORMAT_SUPPORT1_TEXTURE3D); } - /// + /// internal void RentShaderResourceViewDescriptorHandles( out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle) diff --git a/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs b/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs index 71a5c06a..5c4b7f48 100644 --- a/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs +++ b/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs @@ -11,7 +11,7 @@ namespace ComputeSharp /// /// Creates a new instance with the specified parameters. /// - /// The available info for the associate device. + /// The available info for the associated device. internal unsafe GraphicsDeviceInfo(DXGI_ADAPTER_DESC1* dxgiDescription1) { Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); diff --git a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs index 4842f413..4a30f2b8 100644 --- a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs +++ b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs @@ -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. /// - /// The type of values to read. /// The source memory area to read from. /// The pointer that indicates the 3D memory area to write to. /// The height of the 3D memory area to write to. @@ -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. /// - /// The type of values to read. /// The pointer that indicates the memory area to read from. /// The height of the 3D memory area to read. /// The depth of the 3D memory area to read. diff --git a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs index df101b43..74725b0a 100644 --- a/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs +++ b/src/ComputeSharp.Graphics/Resources/Interfaces/IReadOnlyTexture3D{TPixel}.cs @@ -28,7 +28,7 @@ /// /// The horizontal offset of the value to get. /// The vertical offset of the value to get. - /// The depthwise offset of the value to get. + /// The depthwise offset of the value to get. /// This API can only be used from a compute shader, and will always throw if used anywhere else. public TPixel this[int x, int y, int z] { get; } diff --git a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T}.cs index 044a069a..7dc1995e 100644 --- a/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/ReadOnlyTexture3D{T}.cs @@ -32,7 +32,7 @@ namespace ComputeSharp /// /// The horizontal offset of the value to get. /// The vertical offset of the value to get. - /// The depthwise offset of the value to get. + /// The depthwise offset of the value to get. /// This API can only be used from a compute shader, and will always throw if used anywhere else. public T this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[int,int,int]"); diff --git a/src/ComputeSharp.Shaders/ComputeSharp.Shaders.csproj b/src/ComputeSharp.Shaders/ComputeSharp.Shaders.csproj index f2204371..a0ee85cf 100644 --- a/src/ComputeSharp.Shaders/ComputeSharp.Shaders.csproj +++ b/src/ComputeSharp.Shaders/ComputeSharp.Shaders.csproj @@ -2,6 +2,8 @@ netstandard2.0;net5.0 + bin\Release + ComputeSharp.Shaders.xml diff --git a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs index b3066e31..882d5298 100644 --- a/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs +++ b/src/ComputeSharp.Shaders/Renderer/HlslShaderRenderer.cs @@ -33,7 +33,16 @@ namespace ComputeSharp.Shaders.Renderer builder.AppendLine("// This shader was created by ComputeSharp."); builder.AppendLine("// See: https://github.com/Sergio0694/ComputeSharp."); - // Constants + // 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 if (info.ConstantsInfo.Count > 0) { builder.AppendLine(); @@ -114,6 +123,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) { @@ -123,13 +148,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; @@ -235,7 +254,7 @@ namespace ComputeSharp.Shaders.Renderer /// /// Ensures that has enough free space to contain a given number of new items. /// - /// The minimum number of items to ensure space for in . + /// The minimum number of items to ensure space for in . [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureCapacity(int requestedSize) { @@ -281,7 +300,7 @@ namespace ComputeSharp.Shaders.Renderer internal sealed class DebugView { /// - /// Initializes a new instance of the class with the specified parameters. + /// Initializes a new instance of the class with the specified parameters. /// /// The input instance to display. public DebugView(ArrayPoolStringBuilder builder) diff --git a/src/ComputeSharp.Shaders/Renderer/Models/HlslResourceInfo.cs b/src/ComputeSharp.Shaders/Renderer/Models/HlslResourceInfo.cs index f89cb615..cbde91bb 100644 --- a/src/ComputeSharp.Shaders/Renderer/Models/HlslResourceInfo.cs +++ b/src/ComputeSharp.Shaders/Renderer/Models/HlslResourceInfo.cs @@ -5,6 +5,7 @@ /// /// The type of the current field in the HLSL shader. /// The name to use for the current field. + /// The register index to bind the resource to. internal abstract record HlslResourceInfo(string FieldType, string FieldName, int BufferIndex) : CapturedFieldInfo(FieldType, FieldName) { diff --git a/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs index bf21f77e..0ff336a8 100644 --- a/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/IShaderLoader.cs @@ -11,31 +11,36 @@ namespace ComputeSharp.Shaders.Translation /// /// Gets the generated source code for the method in the current shader. /// - public string EntryPoint { get; } + string EntryPoint { get; } /// /// Gets the collection of items for the shader fields. /// - public IReadOnlyList HlslResourceInfo { get; } + IReadOnlyList HlslResourceInfo { get; } /// /// Gets the collection of items for the shader fields. /// - public IReadOnlyList FieldsInfo { get; } + IReadOnlyList FieldsInfo { get; } /// /// Gets the collection of methods to be used in the shader. /// - public IReadOnlyCollection MethodsInfo { get; } + IReadOnlyCollection MethodsInfo { get; } /// /// Gets the collection of constants to be declared in the shader. /// - public IReadOnlyDictionary ConstantsInfo { get; } + IReadOnlyDictionary ConstantsInfo { get; } /// /// Gets the collection of declared types for the shader. /// - public IReadOnlyCollection DeclaredTypes { get; } + IReadOnlyCollection DeclaredTypes { get; } + + /// + /// Gets the collection of discovered constants. + /// + IReadOnlyDictionary SharedBuffers { get; } } } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs index 12606154..1d6f6257 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader{T}.cs @@ -104,11 +104,14 @@ namespace ComputeSharp.Shaders.Translation /// public IReadOnlyCollection DeclaredTypes => this.declaredTypes; + /// + public IReadOnlyDictionary SharedBuffers { get; private set; } + /// /// Loads and processes an input shadeer. /// /// The instance to use to build the shader. - /// A new instance representing the input shader. + /// A new instance representing the input shader. [Pure] public static ShaderLoader Load(in T shader) { @@ -131,6 +134,7 @@ namespace ComputeSharp.Shaders.Translation private void LoadMethodMetadata() { EntryPoint = Attribute.ExecuteMethod; + SharedBuffers = Attribute.SharedBuffers; this.declaredTypes.AddRange(Attribute.Types); this.methodsInfo.AddRange(Attribute.Methods); @@ -175,7 +179,7 @@ namespace ComputeSharp.Shaders.Translation } /// - /// Loads a specified and adds it to the shader model. + /// Loads a specified and adds it to the shader model. /// /// The boxed instance to use to build the shader. /// The target to load. diff --git a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs index 40ebf95d..7111ff4b 100644 --- a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs @@ -43,7 +43,7 @@ namespace ComputeSharp.SourceGenerators var structModifiers = structDeclaration.Modifiers; var fields = ( from fieldSymbol in structDeclarationSymbol.GetMembers().OfType() - where !fieldSymbol.IsConst + where !fieldSymbol.IsConst && !fieldSymbol.IsStatic let typeName = fieldSymbol.Type!.ToDisplayString() let fieldFullType = ParseTypeName(typeName) select (Type: fieldFullType, Identifier: Identifier(fieldSymbol.Name))).ToImmutableArray(); diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 14f36b67..c49ab22a 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -14,9 +14,14 @@ and to match members based on full name, so the types being in the generator assembly are not an issue.--> + + + + + @@ -37,7 +42,6 @@ - diff --git a/src/ComputeSharp.SourceGenerators/Helpers/SyntaxFactoryHelper.cs b/src/ComputeSharp.SourceGenerators/Helpers/SyntaxFactoryHelper.cs index 5fb2c00a..894f6630 100644 --- a/src/ComputeSharp.SourceGenerators/Helpers/SyntaxFactoryHelper.cs +++ b/src/ComputeSharp.SourceGenerators/Helpers/SyntaxFactoryHelper.cs @@ -57,5 +57,37 @@ namespace ComputeSharp.SourceGenerators.Helpers ImplicitArrayCreationExpression(InitializerExpression(SyntaxKind.ArrayInitializerExpression).AddExpressions( group.Select(static item => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(item))).ToArray()))).ToArray())); } + + /// + /// Creates an [] array expression with the nested groups in the input sequence. + /// + /// That it, it applies the following transformation: + /// + /// { ("K1", "V1", I1), ("K2", "V2", null) } => new object[] { new object[] { "K1", "V1", I1 }, new object[] { "K2", "V2", null } } + /// + /// + /// + /// The input sequence of groups. + /// An instance with the described contents. + [Pure] + public static ArrayCreationExpressionSyntax NestedArrayExpression(IEnumerable<(string A, string B, int? C)> groups) + { + return + ArrayCreationExpression( + ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword))) + .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression())))) + .WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression) + .AddExpressions(groups.Select(static group => + ArrayCreationExpression( + ArrayType(PredefinedType(Token(SyntaxKind.ObjectKeyword))) + .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(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())); + } } } diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs index 2922aa8a..834fb2d9 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs @@ -128,6 +128,8 @@ namespace ComputeSharp.SourceGenerators foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) { + if (fieldSymbol.IsStatic) continue; + INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type; string typeName = typeSymbol.GetFullMetadataName(); diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs index ae194820..127677c7 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderHashCodeGenerator.cs @@ -120,6 +120,8 @@ namespace ComputeSharp.SourceGenerators { foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) { + if (fieldSymbol.IsStatic) continue; + INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type; if (typeSymbol.TypeKind != TypeKind.Delegate) continue; diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs index c1b061a3..05ec04c3 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceGenerator.cs @@ -50,6 +50,7 @@ namespace ComputeSharp.SourceGenerators // Explore the syntax tree and extract the processed info var processedMembers = GetProcessedMembers(structDeclarationSymbol, discoveredTypes).ToArray(); + 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.NormalizeWhitespace().ToFullString()).ToArray(); @@ -66,7 +67,8 @@ namespace ComputeSharp.SourceGenerators AttributeArgument(NestedArrayExpression(processedMembers)), AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(entryPoint))), AttributeArgument(ArrayExpression(processedMethods)), - AttributeArgument(NestedArrayExpression(processedConstants))))) + AttributeArgument(NestedArrayExpression(processedConstants)), + AttributeArgument(NestedArrayExpression(sharedBuffers))))) .WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList())) .WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)))) .NormalizeWhitespace() @@ -88,6 +90,8 @@ namespace ComputeSharp.SourceGenerators { foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) { + if (fieldSymbol.IsStatic) continue; + INamedTypeSymbol typeSymbol = (INamedTypeSymbol)fieldSymbol.Type; string typeName = HlslKnownTypes.GetMappedName(typeSymbol); @@ -106,6 +110,33 @@ namespace ComputeSharp.SourceGenerators } } + /// + /// Gets a sequence of captured members and their mapped names. + /// + /// The input instance to process. + /// The collection of currently discovered types. + /// A sequence of captured members in . + [Pure] + private static IEnumerable<(string Name, string Type, int? Count)> GetGroupSharedMembers(INamedTypeSymbol structDeclarationSymbol, ICollection types) + { + foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType()) + { + 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); + } + } + /// /// Gets a sequence of processed methods declared within a given type. /// @@ -140,18 +171,15 @@ namespace ComputeSharp.SourceGenerators 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(); } diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs index c2c58e37..707abb64 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs @@ -190,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; } diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index 22aefe96..c6716afd 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -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" }; /// @@ -50,7 +49,6 @@ namespace ComputeSharp.SourceGenerators.Mappings /// public static IReadOnlyCollection 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) }; + /// + /// Gets the known HLSL dispatch types. + /// + public static IReadOnlyCollection HlslDispatchTypes { get; } = new[] + { + typeof(ThreadIds), + typeof(GroupIds), + typeof(WarpIds) + }; + /// /// Checks whether or not a given type name matches a typed resource type. /// @@ -94,9 +102,7 @@ namespace ComputeSharp.SourceGenerators.Mappings /// Whether or not represents a typed resource type. public static bool IsScalarOrVectorType(string typeName) { - return - KnownTypes.ContainsKey(typeName) && - typeName != typeof(ThreadIds).FullName; + return KnownTypes.ContainsKey(typeName); } /// @@ -149,6 +155,24 @@ namespace ComputeSharp.SourceGenerators.Mappings return KnownTypes[typeName]; } + /// + /// Gets the mapped HLSL-compatible type name for the input element type symbol. + /// + /// The input type to map. + /// The HLSL-compatible type name that can be used in an HLSL shader. + [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(".", "__"); + } + /// /// Gets the mapped HLSL-compatible type name for the input type name. /// diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs index 63245d3b..ad67c0b3 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs @@ -11,17 +11,17 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters internal sealed class ExecuteMethodRewriter : CSharpSyntaxRewriter { /// - /// The identifier name for the input parameter. + /// The instance used to process the input tree. /// - private readonly string threadIdsIdentifier; + private readonly ShaderSourceRewriter shaderSourceRewriter; /// /// Creates a new instance with the specified parameters. /// - /// The identifier name for the input parameter. - public ExecuteMethodRewriter(string threadIdsIdentifier) + /// The instance used to process the input tree. + public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter) { - this.threadIdsIdentifier = threadIdsIdentifier; + this.shaderSourceRewriter = shaderSourceRewriter; } /// @@ -32,11 +32,28 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters } /// - 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; } /// @@ -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) // { // // } @@ -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"))); diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 80112469..289f14ac 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using ComputeSharp.SourceGenerators.Extensions; using ComputeSharp.SourceGenerators.Mappings; @@ -107,6 +106,21 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters /// public IReadOnlyDictionary LocalFunctions => this.localFunctions; + /// + /// Gets whether or not the shader uses at least once (except ). + /// + public bool IsGroupIdsUsed { get; private set; } + + /// + /// Gets whether or not the shader uses at least once. + /// + public bool IsWarpIdsUsed { get; set; } + /// public MethodDeclarationSyntax? Visit(MethodDeclarationSyntax? node) { @@ -308,11 +322,22 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters // 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!), diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 31d48cef..8f1cc533 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -2,6 +2,8 @@ netstandard2.0;net5.0 + bin\Release + ComputeSharp.xml diff --git a/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs b/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs index a838cc5b..256c57a2 100644 --- a/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs +++ b/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs @@ -68,7 +68,7 @@ namespace ComputeSharp /// The type of items stored on the buffer. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. /// The offset to start reading data from. /// The number of items to read. public static void GetData(this Buffer buffer, T[] destination, int destinationOffset, int bufferOffset, int count) diff --git a/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs b/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs index 50ee8172..ae58b6b7 100644 --- a/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs +++ b/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs @@ -93,7 +93,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. public static void GetData(this Texture2D texture, T[] destination, int offset) where T : unmanaged { @@ -107,7 +107,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. /// The horizontal range of items to copy. /// The vertical range of items to copy. public static void GetData(this Texture2D texture, T[] destination, int offset, Range x, Range y) @@ -123,7 +123,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. /// The horizontal offset in the source texture. /// The vertical offset in the source texture. /// The width of the memory area to copy. diff --git a/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs b/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs index 3e0ccfe6..6c16d91a 100644 --- a/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs +++ b/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs @@ -41,7 +41,7 @@ namespace ComputeSharp /// The input array to write data to. /// /// 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 [, , ]. + /// layout of the input array has to be of shape [depth, height, width]. /// public static void GetData(this Texture3D texture, T[,,] destination) where T : unmanaged @@ -59,7 +59,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. public static void GetData(this Texture3D texture, T[] destination, int offset) where T : unmanaged { @@ -73,7 +73,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. /// The horizontal range of items to copy. /// The vertical range of items to copy. /// The depthwise range of items to copy. @@ -90,7 +90,7 @@ namespace ComputeSharp /// The type of items stored on the texture. /// The input instance to read data from. /// The input array to write data to. - /// The starting offset within to write data to. + /// The starting offset within to write data to. /// The horizontal offset in the source texture. /// The vertical offset in the source texture. /// The depthwise offset in the source texture. @@ -162,7 +162,7 @@ namespace ComputeSharp /// The input array to read data from. /// /// 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 [, , ]. + /// layout of the input array has to be of shape [depth, height, width]. /// public static void SetData(this Texture3D texture, T[,,] source) where T : unmanaged diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs index 60492b1b..078e2ca4 100644 --- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs +++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs @@ -178,7 +178,7 @@ namespace ComputeSharp /// The type of items to store in the texture. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// A instance with the contents of the input array. @@ -269,7 +269,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// A instance with the contents of the input array. @@ -362,7 +362,7 @@ namespace ComputeSharp /// The type of items to store in the texture. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// The depth of the texture. @@ -461,7 +461,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// The depth of the texture. @@ -622,7 +622,7 @@ namespace ComputeSharp /// The type of items to store in the texture. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// A instance with the contents of the input array. @@ -713,7 +713,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// A instance with the contents of the input array. @@ -806,7 +806,7 @@ namespace ComputeSharp /// The type of items to store in the texture. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// The depth of the texture. @@ -905,7 +905,7 @@ namespace ComputeSharp /// The type of pixels used on the GPU side. /// The instance to use to allocate the texture. /// The input array with the data to copy on the allocated texture. - /// The starting offset within to read data from. + /// The starting offset within to read data from. /// The width of the texture. /// The height of the texture. /// The depth of the texture. diff --git a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs index 498695ea..dfe219e2 100644 --- a/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs +++ b/tests/ComputeSharp.Tests.Internals/ShaderHashCodeTests.cs @@ -13,7 +13,7 @@ namespace ComputeSharp.Tests.Internals public float A; public ReadWriteBuffer B; - public void Execute(ThreadIds ids) + public void Execute() { B[0] = A; } @@ -46,7 +46,7 @@ namespace ComputeSharp.Tests.Internals public ReadWriteBuffer B; public Func F; - public void Execute(ThreadIds ids) + public void Execute() { B[0] = F(A); } diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index 55e49552..e8dcc321 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -223,9 +223,9 @@ namespace ComputeSharp.Tests public readonly ConstantBuffer source; public readonly ReadWriteBuffer destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.X] = source[ids.X]; + destination[ThreadIds.X] = source[ThreadIds.X]; } } @@ -250,9 +250,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyBuffer source; public readonly ReadWriteBuffer destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.X] = source[ids.X]; + destination[ThreadIds.X] = source[ThreadIds.X]; } } @@ -277,9 +277,9 @@ namespace ComputeSharp.Tests public readonly ReadWriteBuffer source; public readonly ReadWriteBuffer destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.X] = source[ids.X]; + destination[ThreadIds.X] = source[ThreadIds.X]; } } } diff --git a/tests/ComputeSharp.Tests/DispatchTests.cs b/tests/ComputeSharp.Tests/DispatchTests.cs new file mode 100644 index 00000000..39f74221 --- /dev/null +++ b/tests/ComputeSharp.Tests/DispatchTests.cs @@ -0,0 +1,112 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests +{ + [TestClass] + [TestCategory("Dispatch")] + public partial class DispatchTests + { + [TestMethod] + public void Verify_ThreadIds() + { + using ReadWriteTexture3D buffer = Gpu.Default.AllocateReadWriteTexture3D(50, 50, 50); + + Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, new ThreadIdsShader(buffer)); + + Int4[,,] data = buffer.GetData(); + + for (int z = 0; z < 50; z++) + { + for (int x = 0; x < 50; x++) + { + for (int y = 0; y < 50; y++) + { + Int4 value = data[z, y, x]; + + Assert.AreEqual(x, value.X); + Assert.AreEqual(y, value.Y); + Assert.AreEqual(z, value.Z); + } + } + } + } + + [AutoConstructor] + internal readonly partial struct ThreadIdsShader : IComputeShader + { + public readonly ReadWriteTexture3D buffer; + + public void Execute() + { + buffer[ThreadIds.XYZ].XYZ = ThreadIds.XYZ; + } + } + + [TestMethod] + public void Verify_GroupIds() + { + using ReadWriteTexture3D buffer = Gpu.Default.AllocateReadWriteTexture3D(50, 50, 50); + + Gpu.Default.For(buffer.Width, buffer.Height, buffer.Depth, 4, 4, 4, new GroupIdsShader(buffer)); + + Int4[,,] data = buffer.GetData(); + + for (int z = 0; z < 50; z++) + { + for (int x = 0; x < 50; x++) + { + for (int y = 0; y < 50; y++) + { + Int4 value = data[z, y, x]; + + Assert.AreEqual(x % 4, value.X); + Assert.AreEqual(y % 4, value.Y); + Assert.AreEqual(z % 4, value.Z); + Assert.AreEqual(value.Z * 4 * 4 + value.Y * 4 + value.X, value.W); + } + } + } + } + + [AutoConstructor] + internal readonly partial struct GroupIdsShader : IComputeShader + { + public readonly ReadWriteTexture3D buffer; + + public void Execute() + { + buffer[ThreadIds.XYZ].XYZ = GroupIds.XYZ; + buffer[ThreadIds.XYZ].W = GroupIds.Index; + } + } + + [TestMethod] + public void Verify_GroupSize() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(32); + + Gpu.Default.For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer)); + + int[] data = buffer.GetData(); + + Assert.AreEqual(4, data[0]); + Assert.AreEqual(15, data[1]); + Assert.AreEqual(7, data[2]); + Assert.AreEqual(4 * 15 * 7, data[3]); + } + + [AutoConstructor] + internal readonly partial struct GroupSizeShader : IComputeShader + { + public readonly ReadWriteBuffer buffer; + + public void Execute() + { + buffer[0] = GroupSize.X; + buffer[1] = GroupSize.Y; + buffer[2] = GroupSize.Z; + buffer[3] = GroupSize.Count; + } + } + } +} diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs index 661896e0..4e7e8589 100644 --- a/tests/ComputeSharp.Tests/InitializationTests.cs +++ b/tests/ComputeSharp.Tests/InitializationTests.cs @@ -86,9 +86,9 @@ namespace ComputeSharp.Tests { public readonly ReadWriteBuffer buffer; - public void Execute(ThreadIds ids) + public void Execute() { - buffer[ids.X] = ids.X; + buffer[ThreadIds.X] = ThreadIds.X; } } } diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs index 08039596..f914c901 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.g.cs @@ -113,9 +113,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -125,9 +125,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -137,9 +137,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -149,9 +149,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -161,9 +161,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -173,9 +173,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -185,9 +185,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -197,9 +197,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -209,9 +209,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -221,9 +221,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -233,9 +233,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } @@ -245,9 +245,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } } diff --git a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt index 33775291..991ce833 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt +++ b/tests/ComputeSharp.Tests/Texture2DTests.Pixels.tt @@ -69,9 +69,9 @@ foreach (var (t, tPixel) in EnumerateTypes()) public readonly ReadOnlyTexture2D<<#=t#>, <#=tPixel#>> source; public readonly ReadWriteTexture2D<<#=t#>, <#=tPixel#>> destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = (source[ids.XY] + destination[ids.XY]) / 2; + destination[ThreadIds.XY] = (source[ThreadIds.XY] + destination[ThreadIds.XY]) / 2; } } <# diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 4a6806e8..77991cfe 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -159,9 +159,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture2D source; public readonly ReadWriteBuffer destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.Y * 32 + ids.X] = source[ids.XY]; + destination[ThreadIds.Y * 32 + ThreadIds.X] = source[ThreadIds.XY]; } } @@ -188,9 +188,9 @@ namespace ComputeSharp.Tests public readonly ReadWriteTexture2D source; public readonly ReadWriteTexture2D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XY] = source[ids.XY]; + destination[ThreadIds.XY] = source[ThreadIds.XY]; } } } diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs index 3c1e4955..debd29cf 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.g.cs @@ -113,9 +113,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -125,9 +125,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -137,9 +137,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -149,9 +149,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -161,9 +161,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -173,9 +173,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -185,9 +185,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -197,9 +197,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -209,9 +209,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -221,9 +221,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -233,9 +233,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } @@ -245,9 +245,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } } diff --git a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt index d72edd3c..57be04b8 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt +++ b/tests/ComputeSharp.Tests/Texture3DTests.Pixels.tt @@ -69,9 +69,9 @@ foreach (var (t, tPixel) in EnumerateTypes()) public readonly ReadOnlyTexture3D<<#=t#>, <#=tPixel#>> source; public readonly ReadWriteTexture3D<<#=t#>, <#=tPixel#>> destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = (source[ids.XYZ] + destination[ids.XYZ]) / 2; + destination[ThreadIds.XYZ] = (source[ThreadIds.XYZ] + destination[ThreadIds.XYZ]) / 2; } } <# diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index d69d4335..b2adb7e0 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -193,9 +193,9 @@ namespace ComputeSharp.Tests public readonly ReadOnlyTexture3D source; public readonly ReadWriteBuffer destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.Z * 32 * 32 + ids.Y * 32 + ids.X] = source[ids.XYZ]; + destination[ThreadIds.Z * 32 * 32 + ThreadIds.Y * 32 + ThreadIds.X] = source[ThreadIds.XYZ]; } } @@ -222,9 +222,9 @@ namespace ComputeSharp.Tests public readonly ReadWriteTexture3D source; public readonly ReadWriteTexture3D destination; - public void Execute(ThreadIds ids) + public void Execute() { - destination[ids.XYZ] = source[ids.XYZ]; + destination[ThreadIds.XYZ] = source[ThreadIds.XYZ]; } } }