diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool.cs
index ff6bbb70..b1fe373a 100644
--- a/src/ComputeSharp.Core/Primitives/Bool/Bool.cs
+++ b/src/ComputeSharp.Core/Primitives/Bool/Bool.cs
@@ -20,16 +20,28 @@ namespace ComputeSharp
/// Creates a new instance for a given value.
///
/// .
- private Bool(bool value) => Value = value;
+ private Bool(bool value)
+ {
+ Value = value;
+ }
///
- public override bool Equals(object? obj) => obj is Bool x && Value == x.Value;
+ public override bool Equals(object? obj)
+ {
+ return obj is Bool x && Value == x.Value;
+ }
///
- public override int GetHashCode() => Value.GetHashCode();
+ public override int GetHashCode()
+ {
+ return Value.GetHashCode();
+ }
///
- public override string ToString() => Value.ToString();
+ public override string ToString()
+ {
+ return Value.ToString();
+ }
///
/// Checks whether or not two instances represent the same value.
@@ -49,7 +61,7 @@ namespace ComputeSharp
/// Inverts the value represented by a given instance.
///
/// The input instance.
- public static Bool operator !(Bool x) => new Bool(!x.Value);
+ public static Bool operator !(Bool x) => new(!x.Value);
///
/// Converts a given instance to its corresponding value.
@@ -61,6 +73,6 @@ namespace ComputeSharp
/// Converts a value to a corresponding instance.
///
/// The input value.
- public static implicit operator Bool(bool x) => new Bool(x);
+ public static implicit operator Bool(bool x) => new(x);
}
}
diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs
index 13d32e3c..581bdcf5 100644
--- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs
+++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs
@@ -24,12 +24,12 @@ namespace ComputeSharp
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool2 TrueX => new Bool2(true, false);
+ public static Bool2 TrueX => new(true, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool2 TrueY => new Bool2(false, true);
+ public static Bool2 TrueY => new(false, true);
///
/// Creates a new instance with the specified parameters.
@@ -154,6 +154,6 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Bool2(bool x) => new Bool2(x, x);
+ public static implicit operator Bool2(bool x) => new(x, x);
}
}
diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs
index 6450c6b1..67ad7199 100644
--- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs
+++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs
@@ -24,17 +24,17 @@ namespace ComputeSharp
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool3 TrueX => new Bool3(true, false, false);
+ public static Bool3 TrueX => new(true, false, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool3 TrueY => new Bool3(false, true, false);
+ public static Bool3 TrueY => new(false, true, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool3 TrueZ => new Bool3(false, false, true);
+ public static Bool3 TrueZ => new(false, false, true);
///
/// Creates a new instance with the specified parameters.
@@ -263,32 +263,32 @@ namespace ComputeSharp
///
/// Gets an value with the value for all components.
///
- public Bool2 XXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXX)}");
+ public Bool3 XXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXX)}");
///
/// Gets an value with the , and values.
///
- public Bool2 XXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXY)}");
+ public Bool3 XXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXY)}");
///
/// Gets an value with the , and values.
///
- public Bool2 XXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXZ)}");
+ public Bool3 XXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XXZ)}");
///
/// Gets an value with the , and values.
///
- public Bool2 XYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYX)}");
+ public Bool3 XYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYX)}");
///
/// Gets an value with the , and values.
///
- public Bool2 XYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYY)}");
+ public Bool3 XYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYY)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 XYZ
+ public Bool3 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XYZ)}");
@@ -297,12 +297,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 XZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZX)}");
+ public Bool3 XZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZX)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 XZY
+ public Bool3 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZY)}");
@@ -311,22 +311,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 XZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZZ)}");
+ public Bool3 XZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(XZZ)}");
///
/// Gets an value with the , and values.
///
- public Bool2 YXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXX)}");
+ public Bool3 YXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXX)}");
///
/// Gets an value with the , and values.
///
- public Bool2 YXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXY)}");
+ public Bool3 YXY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXY)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 YXZ
+ public Bool3 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YXZ)}");
@@ -335,22 +335,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 YYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYX)}");
+ public Bool3 YYX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYX)}");
///
/// Gets an value with the value for all components.
///
- public Bool2 YYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYY)}");
+ public Bool3 YYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYY)}");
///
/// Gets an value with the , and values.
///
- public Bool2 YYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYZ)}");
+ public Bool3 YYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YYZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 YZX
+ public Bool3 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZX)}");
@@ -359,22 +359,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 YZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZY)}");
+ public Bool3 YZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZY)}");
///
/// Gets an value with the , and values.
///
- public Bool2 YZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZZ)}");
+ public Bool3 YZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(YZZ)}");
///
/// Gets an value with the , and values.
///
- public Bool2 ZXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXX)}");
+ public Bool3 ZXX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXX)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 ZXY
+ public Bool3 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXY)}");
@@ -383,12 +383,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXZ)}");
+ public Bool3 ZXZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZXZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 ZYX
+ public Bool3 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYX)}");
@@ -397,57 +397,57 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 ZYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYY)}");
+ public Bool3 ZYY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYY)}");
///
/// Gets an value with the , and values.
///
- public Bool2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYZ)}");
+ public Bool3 ZYZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZYZ)}");
///
/// Gets an value with the , and values.
///
- public Bool2 ZZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZX)}");
+ public Bool3 ZZX => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZX)}");
///
/// Gets an value with the , and values.
///
- public Bool2 ZZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZY)}");
+ public Bool3 ZZY => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZY)}");
///
/// Gets an value with the value for all components.
///
- public Bool2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZZ)}");
+ public Bool3 ZZZ => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(ZZZ)}");
///
/// Gets an value with the value for all components.
///
- public Bool2 RRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRR)}");
+ public Bool3 RRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRR)}");
///
/// Gets an value with the , and values.
///
- public Bool2 RRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRG)}");
+ public Bool3 RRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRG)}");
///
/// Gets an value with the , and values.
///
- public Bool2 RRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRB)}");
+ public Bool3 RRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RRB)}");
///
/// Gets an value with the , and values.
///
- public Bool2 RGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGR)}");
+ public Bool3 RGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGR)}");
///
/// Gets an value with the , and values.
///
- public Bool2 RGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGG)}");
+ public Bool3 RGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGG)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 RGB
+ public Bool3 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RGB)}");
@@ -456,12 +456,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 RBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBR)}");
+ public Bool3 RBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBR)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 RBG
+ public Bool3 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBG)}");
@@ -470,22 +470,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 RBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBB)}");
+ public Bool3 RBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(RBB)}");
///
/// Gets an value with the , and values.
///
- public Bool2 GRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRR)}");
+ public Bool3 GRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRR)}");
///
/// Gets an value with the , and values.
///
- public Bool2 GRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRG)}");
+ public Bool3 GRG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRG)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 GRB
+ public Bool3 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GRB)}");
@@ -494,22 +494,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 GGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGR)}");
+ public Bool3 GGR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGR)}");
///
/// Gets an value with the value for all components.
///
- public Bool2 GGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGG)}");
+ public Bool3 GGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGG)}");
///
/// Gets an value with the , and values.
///
- public Bool2 GGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGB)}");
+ public Bool3 GGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GGB)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 GBR
+ public Bool3 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBR)}");
@@ -518,22 +518,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 GBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBG)}");
+ public Bool3 GBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBG)}");
///
/// Gets an value with the , and values.
///
- public Bool2 GBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBB)}");
+ public Bool3 GBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(GBB)}");
///
/// Gets an value with the , and values.
///
- public Bool2 BRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRR)}");
+ public Bool3 BRR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRR)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 BRG
+ public Bool3 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRG)}");
@@ -542,12 +542,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 BRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRB)}");
+ public Bool3 BRB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BRB)}");
///
/// Gets or sets an value with the , and values.
///
- public Bool2 BGR
+ public Bool3 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGR)}");
@@ -556,32 +556,32 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Bool2 BGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGG)}");
+ public Bool3 BGG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGG)}");
///
/// Gets an value with the , and values.
///
- public Bool2 BGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGB)}");
+ public Bool3 BGB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BGB)}");
///
/// Gets an value with the , and values.
///
- public Bool2 BBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBR)}");
+ public Bool3 BBR => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBR)}");
///
/// Gets an value with the , and values.
///
- public Bool2 BBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBG)}");
+ public Bool3 BBG => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBG)}");
///
/// Gets an value with the value for all components.
///
- public Bool2 BBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBB)}");
+ public Bool3 BBB => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(BBB)}");
///
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Bool3(bool x) => new Bool3(x, x, x);
+ public static implicit operator Bool3(bool x) => new(x, x, x);
}
}
diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs
index cfb92514..2ca262e2 100644
--- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs
+++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs
@@ -24,22 +24,22 @@ namespace ComputeSharp
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool4 TrueX => new Bool4(true, false, false, false);
+ public static Bool4 TrueX => new(true, false, false, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool4 TrueY => new Bool4(false, true, false, false);
+ public static Bool4 TrueY => new(false, true, false, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool4 TrueZ => new Bool4(false, false, true, false);
+ public static Bool4 TrueZ => new(false, false, true, false);
///
/// Gets an value with the component set to , and the others to .
///
- public static Bool4 TrueW => new Bool4(false, false, false, true);
+ public static Bool4 TrueW => new(false, false, false, true);
///
/// Creates a new instance with the specified parameters.
@@ -3994,6 +3994,6 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Bool4(bool x) => new Bool4(x, x, x, x);
+ public static implicit operator Bool4(bool x) => new(x, x, x, x);
}
}
diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.cs b/src/ComputeSharp.Core/Primitives/Double/Double2.cs
index 5809961b..7409862c 100644
--- a/src/ComputeSharp.Core/Primitives/Double/Double2.cs
+++ b/src/ComputeSharp.Core/Primitives/Double/Double2.cs
@@ -24,12 +24,12 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double2 UnitX => new Double2(1, 0);
+ public static Double2 UnitX => new(1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double2 UnitY => new Double2(0, 1);
+ public static Double2 UnitY => new(0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -140,7 +140,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Double2(double x) => new Double2(x, x);
+ public static implicit operator Double2(double x) => new(x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Double/Double3.cs b/src/ComputeSharp.Core/Primitives/Double/Double3.cs
index a9e01edc..27eb3b80 100644
--- a/src/ComputeSharp.Core/Primitives/Double/Double3.cs
+++ b/src/ComputeSharp.Core/Primitives/Double/Double3.cs
@@ -24,17 +24,17 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double3 UnitX => new Double3(1, 0, 0);
+ public static Double3 UnitX => new(1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double3 UnitY => new Double3(0, 1, 0);
+ public static Double3 UnitY => new(0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double3 UnitZ => new Double3(0, 0, 1);
+ public static Double3 UnitZ => new(0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -242,32 +242,32 @@ namespace ComputeSharp
///
/// Gets an value with the value for all components.
///
- public Double2 XXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXX)}");
+ public Double3 XXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXX)}");
///
/// Gets an value with the , and values.
///
- public Double2 XXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXY)}");
+ public Double3 XXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXY)}");
///
/// Gets an value with the , and values.
///
- public Double2 XXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXZ)}");
+ public Double3 XXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XXZ)}");
///
/// Gets an value with the , and values.
///
- public Double2 XYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYX)}");
+ public Double3 XYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYX)}");
///
/// Gets an value with the , and values.
///
- public Double2 XYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYY)}");
+ public Double3 XYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYY)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 XYZ
+ public Double3 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XYZ)}");
@@ -276,12 +276,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 XZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZX)}");
+ public Double3 XZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZX)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 XZY
+ public Double3 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZY)}");
@@ -290,22 +290,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 XZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZZ)}");
+ public Double3 XZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(XZZ)}");
///
/// Gets an value with the , and values.
///
- public Double2 YXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXX)}");
+ public Double3 YXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXX)}");
///
/// Gets an value with the , and values.
///
- public Double2 YXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXY)}");
+ public Double3 YXY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXY)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 YXZ
+ public Double3 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YXZ)}");
@@ -314,22 +314,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 YYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYX)}");
+ public Double3 YYX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYX)}");
///
/// Gets an value with the value for all components.
///
- public Double2 YYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYY)}");
+ public Double3 YYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYY)}");
///
/// Gets an value with the , and values.
///
- public Double2 YYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYZ)}");
+ public Double3 YYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YYZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 YZX
+ public Double3 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZX)}");
@@ -338,22 +338,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 YZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZY)}");
+ public Double3 YZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZY)}");
///
/// Gets an value with the , and values.
///
- public Double2 YZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZZ)}");
+ public Double3 YZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(YZZ)}");
///
/// Gets an value with the , and values.
///
- public Double2 ZXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXX)}");
+ public Double3 ZXX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXX)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 ZXY
+ public Double3 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXY)}");
@@ -362,12 +362,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXZ)}");
+ public Double3 ZXZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZXZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 ZYX
+ public Double3 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYX)}");
@@ -376,57 +376,57 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 ZYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYY)}");
+ public Double3 ZYY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYY)}");
///
/// Gets an value with the , and values.
///
- public Double2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYZ)}");
+ public Double3 ZYZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZYZ)}");
///
/// Gets an value with the , and values.
///
- public Double2 ZZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZX)}");
+ public Double3 ZZX => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZX)}");
///
/// Gets an value with the , and values.
///
- public Double2 ZZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZY)}");
+ public Double3 ZZY => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZY)}");
///
/// Gets an value with the value for all components.
///
- public Double2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZZ)}");
+ public Double3 ZZZ => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(ZZZ)}");
///
/// Gets an value with the value for all components.
///
- public Double2 RRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRR)}");
+ public Double3 RRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRR)}");
///
/// Gets an value with the , and values.
///
- public Double2 RRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRG)}");
+ public Double3 RRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRG)}");
///
/// Gets an value with the , and values.
///
- public Double2 RRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRB)}");
+ public Double3 RRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RRB)}");
///
/// Gets an value with the , and values.
///
- public Double2 RGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGR)}");
+ public Double3 RGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGR)}");
///
/// Gets an value with the , and values.
///
- public Double2 RGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGG)}");
+ public Double3 RGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGG)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 RGB
+ public Double3 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RGB)}");
@@ -435,12 +435,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 RBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBR)}");
+ public Double3 RBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBR)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 RBG
+ public Double3 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBG)}");
@@ -449,22 +449,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 RBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBB)}");
+ public Double3 RBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(RBB)}");
///
/// Gets an value with the , and values.
///
- public Double2 GRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRR)}");
+ public Double3 GRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRR)}");
///
/// Gets an value with the , and values.
///
- public Double2 GRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRG)}");
+ public Double3 GRG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRG)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 GRB
+ public Double3 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GRB)}");
@@ -473,22 +473,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 GGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGR)}");
+ public Double3 GGR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGR)}");
///
/// Gets an value with the value for all components.
///
- public Double2 GGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGG)}");
+ public Double3 GGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGG)}");
///
/// Gets an value with the , and values.
///
- public Double2 GGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGB)}");
+ public Double3 GGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GGB)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 GBR
+ public Double3 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBR)}");
@@ -497,22 +497,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 GBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBG)}");
+ public Double3 GBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBG)}");
///
/// Gets an value with the , and values.
///
- public Double2 GBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBB)}");
+ public Double3 GBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(GBB)}");
///
/// Gets an value with the , and values.
///
- public Double2 BRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRR)}");
+ public Double3 BRR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRR)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 BRG
+ public Double3 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRG)}");
@@ -521,12 +521,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 BRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRB)}");
+ public Double3 BRB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BRB)}");
///
/// Gets or sets an value with the , and values.
///
- public Double2 BGR
+ public Double3 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGR)}");
@@ -535,33 +535,33 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Double2 BGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGG)}");
+ public Double3 BGG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGG)}");
///
/// Gets an value with the , and values.
///
- public Double2 BGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGB)}");
+ public Double3 BGB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BGB)}");
///
/// Gets an value with the , and values.
///
- public Double2 BBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBR)}");
+ public Double3 BBR => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBR)}");
///
/// Gets an value with the , and values.
///
- public Double2 BBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBG)}");
+ public Double3 BBG => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBG)}");
///
/// Gets an value with the value for all components.
///
- public Double2 BBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBB)}");
+ public Double3 BBB => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(BBB)}");
///
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Double3(double x) => new Double3(x, x, x);
+ public static implicit operator Double3(double x) => new(x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Double/Double4.cs b/src/ComputeSharp.Core/Primitives/Double/Double4.cs
index a87dcfba..d59ddf09 100644
--- a/src/ComputeSharp.Core/Primitives/Double/Double4.cs
+++ b/src/ComputeSharp.Core/Primitives/Double/Double4.cs
@@ -24,22 +24,22 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double4 UnitX => new Double4(1, 0, 0, 0);
+ public static Double4 UnitX => new(1, 0, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double4 UnitY => new Double4(0, 1, 0, 0);
+ public static Double4 UnitY => new(0, 1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double4 UnitZ => new Double4(0, 0, 1, 0);
+ public static Double4 UnitZ => new(0, 0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Double4 UnitW => new Double4(0, 0, 0, 1);
+ public static Double4 UnitW => new(0, 0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -3966,7 +3966,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Double4(double x) => new Double4(x, x, x, x);
+ public static implicit operator Double4(double x) => new(x, x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.cs b/src/ComputeSharp.Core/Primitives/Float/Float2.cs
index 69ff3eec..266cbe77 100644
--- a/src/ComputeSharp.Core/Primitives/Float/Float2.cs
+++ b/src/ComputeSharp.Core/Primitives/Float/Float2.cs
@@ -24,12 +24,12 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float2 UnitX => new Float2(1, 0);
+ public static Float2 UnitX => new(1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float2 UnitY => new Float2(0, 1);
+ public static Float2 UnitY => new(0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -140,7 +140,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Float2(float x) => new Float2(x, x);
+ public static implicit operator Float2(float x) => new(x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.cs b/src/ComputeSharp.Core/Primitives/Float/Float3.cs
index 20b9c1f2..d8d9675b 100644
--- a/src/ComputeSharp.Core/Primitives/Float/Float3.cs
+++ b/src/ComputeSharp.Core/Primitives/Float/Float3.cs
@@ -24,17 +24,17 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float3 UnitX => new Float3(1, 0, 0);
+ public static Float3 UnitX => new(1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float3 UnitY => new Float3(0, 1, 0);
+ public static Float3 UnitY => new(0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float3 UnitZ => new Float3(0, 0, 1);
+ public static Float3 UnitZ => new(0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -242,32 +242,32 @@ namespace ComputeSharp
///
/// Gets an value with the value for all components.
///
- public Float2 XXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXX)}");
+ public Float3 XXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXX)}");
///
/// Gets an value with the , and values.
///
- public Float2 XXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXY)}");
+ public Float3 XXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXY)}");
///
/// Gets an value with the , and values.
///
- public Float2 XXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXZ)}");
+ public Float3 XXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XXZ)}");
///
/// Gets an value with the , and values.
///
- public Float2 XYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYX)}");
+ public Float3 XYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYX)}");
///
/// Gets an value with the , and values.
///
- public Float2 XYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYY)}");
+ public Float3 XYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYY)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 XYZ
+ public Float3 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XYZ)}");
@@ -276,12 +276,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 XZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZX)}");
+ public Float3 XZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZX)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 XZY
+ public Float3 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZY)}");
@@ -290,22 +290,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 XZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZZ)}");
+ public Float3 XZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(XZZ)}");
///
/// Gets an value with the , and values.
///
- public Float2 YXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXX)}");
+ public Float3 YXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXX)}");
///
/// Gets an value with the , and values.
///
- public Float2 YXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXY)}");
+ public Float3 YXY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXY)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 YXZ
+ public Float3 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YXZ)}");
@@ -314,22 +314,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 YYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYX)}");
+ public Float3 YYX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYX)}");
///
/// Gets an value with the value for all components.
///
- public Float2 YYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYY)}");
+ public Float3 YYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYY)}");
///
/// Gets an value with the , and values.
///
- public Float2 YYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYZ)}");
+ public Float3 YYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YYZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 YZX
+ public Float3 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZX)}");
@@ -338,22 +338,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 YZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZY)}");
+ public Float3 YZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZY)}");
///
/// Gets an value with the , and values.
///
- public Float2 YZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZZ)}");
+ public Float3 YZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(YZZ)}");
///
/// Gets an value with the , and values.
///
- public Float2 ZXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXX)}");
+ public Float3 ZXX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXX)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 ZXY
+ public Float3 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXY)}");
@@ -362,12 +362,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXZ)}");
+ public Float3 ZXZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZXZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 ZYX
+ public Float3 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYX)}");
@@ -376,57 +376,57 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 ZYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYY)}");
+ public Float3 ZYY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYY)}");
///
/// Gets an value with the , and values.
///
- public Float2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYZ)}");
+ public Float3 ZYZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZYZ)}");
///
/// Gets an value with the , and values.
///
- public Float2 ZZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZX)}");
+ public Float3 ZZX => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZX)}");
///
/// Gets an value with the , and values.
///
- public Float2 ZZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZY)}");
+ public Float3 ZZY => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZY)}");
///
/// Gets an value with the value for all components.
///
- public Float2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZZ)}");
+ public Float3 ZZZ => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(ZZZ)}");
///
/// Gets an value with the value for all components.
///
- public Float2 RRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRR)}");
+ public Float3 RRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRR)}");
///
/// Gets an value with the , and values.
///
- public Float2 RRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRG)}");
+ public Float3 RRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRG)}");
///
/// Gets an value with the , and values.
///
- public Float2 RRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRB)}");
+ public Float3 RRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RRB)}");
///
/// Gets an value with the , and values.
///
- public Float2 RGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGR)}");
+ public Float3 RGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGR)}");
///
/// Gets an value with the , and values.
///
- public Float2 RGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGG)}");
+ public Float3 RGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGG)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 RGB
+ public Float3 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RGB)}");
@@ -435,12 +435,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 RBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBR)}");
+ public Float3 RBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBR)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 RBG
+ public Float3 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBG)}");
@@ -449,22 +449,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 RBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBB)}");
+ public Float3 RBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(RBB)}");
///
/// Gets an value with the , and values.
///
- public Float2 GRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRR)}");
+ public Float3 GRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRR)}");
///
/// Gets an value with the , and values.
///
- public Float2 GRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRG)}");
+ public Float3 GRG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRG)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 GRB
+ public Float3 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GRB)}");
@@ -473,22 +473,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 GGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGR)}");
+ public Float3 GGR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGR)}");
///
/// Gets an value with the value for all components.
///
- public Float2 GGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGG)}");
+ public Float3 GGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGG)}");
///
/// Gets an value with the , and values.
///
- public Float2 GGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGB)}");
+ public Float3 GGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GGB)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 GBR
+ public Float3 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBR)}");
@@ -497,22 +497,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 GBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBG)}");
+ public Float3 GBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBG)}");
///
/// Gets an value with the , and values.
///
- public Float2 GBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBB)}");
+ public Float3 GBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(GBB)}");
///
/// Gets an value with the , and values.
///
- public Float2 BRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRR)}");
+ public Float3 BRR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRR)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 BRG
+ public Float3 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRG)}");
@@ -521,12 +521,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 BRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRB)}");
+ public Float3 BRB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BRB)}");
///
/// Gets or sets an value with the , and values.
///
- public Float2 BGR
+ public Float3 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGR)}");
@@ -535,33 +535,33 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Float2 BGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGG)}");
+ public Float3 BGG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGG)}");
///
/// Gets an value with the , and values.
///
- public Float2 BGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGB)}");
+ public Float3 BGB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BGB)}");
///
/// Gets an value with the , and values.
///
- public Float2 BBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBR)}");
+ public Float3 BBR => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBR)}");
///
/// Gets an value with the , and values.
///
- public Float2 BBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBG)}");
+ public Float3 BBG => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBG)}");
///
/// Gets an value with the value for all components.
///
- public Float2 BBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBB)}");
+ public Float3 BBB => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(BBB)}");
///
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Float3(float x) => new Float3(x, x, x);
+ public static implicit operator Float3(float x) => new(x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.cs b/src/ComputeSharp.Core/Primitives/Float/Float4.cs
index 3dbaa07e..e112ab95 100644
--- a/src/ComputeSharp.Core/Primitives/Float/Float4.cs
+++ b/src/ComputeSharp.Core/Primitives/Float/Float4.cs
@@ -24,22 +24,22 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float4 UnitX => new Float4(1, 0, 0, 0);
+ public static Float4 UnitX => new(1, 0, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float4 UnitY => new Float4(0, 1, 0, 0);
+ public static Float4 UnitY => new(0, 1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float4 UnitZ => new Float4(0, 0, 1, 0);
+ public static Float4 UnitZ => new(0, 0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Float4 UnitW => new Float4(0, 0, 0, 1);
+ public static Float4 UnitW => new(0, 0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -3966,7 +3966,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Float4(float x) => new Float4(x, x, x, x);
+ public static implicit operator Float4(float x) => new(x, x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.cs b/src/ComputeSharp.Core/Primitives/Int/Int2.cs
index dc41c1ca..76e238a5 100644
--- a/src/ComputeSharp.Core/Primitives/Int/Int2.cs
+++ b/src/ComputeSharp.Core/Primitives/Int/Int2.cs
@@ -24,12 +24,12 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int2 UnitX => new Int2(1, 0);
+ public static Int2 UnitX => new(1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int2 UnitY => new Int2(0, 1);
+ public static Int2 UnitY => new(0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -140,7 +140,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Int2(int x) => new Int2(x, x);
+ public static implicit operator Int2(int x) => new(x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Int/Int3.cs b/src/ComputeSharp.Core/Primitives/Int/Int3.cs
index 620ebb81..cb2f09f2 100644
--- a/src/ComputeSharp.Core/Primitives/Int/Int3.cs
+++ b/src/ComputeSharp.Core/Primitives/Int/Int3.cs
@@ -24,17 +24,17 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int3 UnitX => new Int3(1, 0, 0);
+ public static Int3 UnitX => new(1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int3 UnitY => new Int3(0, 1, 0);
+ public static Int3 UnitY => new(0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int3 UnitZ => new Int3(0, 0, 1);
+ public static Int3 UnitZ => new(0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -242,32 +242,32 @@ namespace ComputeSharp
///
/// Gets an value with the value for all components.
///
- public Int2 XXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXX)}");
+ public Int3 XXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXX)}");
///
/// Gets an value with the , and values.
///
- public Int2 XXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXY)}");
+ public Int3 XXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXY)}");
///
/// Gets an value with the , and values.
///
- public Int2 XXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXZ)}");
+ public Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XXZ)}");
///
/// Gets an value with the , and values.
///
- public Int2 XYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYX)}");
+ public Int3 XYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYX)}");
///
/// Gets an value with the , and values.
///
- public Int2 XYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYY)}");
+ public Int3 XYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYY)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 XYZ
+ public Int3 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XYZ)}");
@@ -276,12 +276,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 XZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZX)}");
+ public Int3 XZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZX)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 XZY
+ public Int3 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZY)}");
@@ -290,22 +290,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 XZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZZ)}");
+ public Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(XZZ)}");
///
/// Gets an value with the , and values.
///
- public Int2 YXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXX)}");
+ public Int3 YXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXX)}");
///
/// Gets an value with the , and values.
///
- public Int2 YXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXY)}");
+ public Int3 YXY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXY)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 YXZ
+ public Int3 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YXZ)}");
@@ -314,22 +314,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 YYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYX)}");
+ public Int3 YYX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYX)}");
///
/// Gets an value with the value for all components.
///
- public Int2 YYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYY)}");
+ public Int3 YYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYY)}");
///
/// Gets an value with the , and values.
///
- public Int2 YYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYZ)}");
+ public Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YYZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 YZX
+ public Int3 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZX)}");
@@ -338,22 +338,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 YZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZY)}");
+ public Int3 YZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZY)}");
///
/// Gets an value with the , and values.
///
- public Int2 YZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZZ)}");
+ public Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(YZZ)}");
///
/// Gets an value with the , and values.
///
- public Int2 ZXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXX)}");
+ public Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXX)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 ZXY
+ public Int3 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXY)}");
@@ -362,12 +362,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 ZXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXZ)}");
+ public Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZXZ)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 ZYX
+ public Int3 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYX)}");
@@ -376,57 +376,57 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 ZYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYY)}");
+ public Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYY)}");
///
/// Gets an value with the , and values.
///
- public Int2 ZYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYZ)}");
+ public Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZYZ)}");
///
/// Gets an value with the , and values.
///
- public Int2 ZZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZX)}");
+ public Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZX)}");
///
/// Gets an value with the , and values.
///
- public Int2 ZZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZY)}");
+ public Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZY)}");
///
/// Gets an value with the value for all components.
///
- public Int2 ZZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZZ)}");
+ public Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(ZZZ)}");
///
/// Gets an value with the value for all components.
///
- public Int2 RRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRR)}");
+ public Int3 RRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRR)}");
///
/// Gets an value with the , and values.
///
- public Int2 RRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRG)}");
+ public Int3 RRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRG)}");
///
/// Gets an value with the , and values.
///
- public Int2 RRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRB)}");
+ public Int3 RRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RRB)}");
///
/// Gets an value with the , and values.
///
- public Int2 RGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGR)}");
+ public Int3 RGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGR)}");
///
/// Gets an value with the , and values.
///
- public Int2 RGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGG)}");
+ public Int3 RGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGG)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 RGB
+ public Int3 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RGB)}");
@@ -435,12 +435,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 RBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBR)}");
+ public Int3 RBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBR)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 RBG
+ public Int3 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBG)}");
@@ -449,22 +449,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 RBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBB)}");
+ public Int3 RBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(RBB)}");
///
/// Gets an value with the , and values.
///
- public Int2 GRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRR)}");
+ public Int3 GRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRR)}");
///
/// Gets an value with the , and values.
///
- public Int2 GRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRG)}");
+ public Int3 GRG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRG)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 GRB
+ public Int3 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GRB)}");
@@ -473,22 +473,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 GGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGR)}");
+ public Int3 GGR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGR)}");
///
/// Gets an value with the value for all components.
///
- public Int2 GGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGG)}");
+ public Int3 GGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGG)}");
///
/// Gets an value with the , and values.
///
- public Int2 GGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGB)}");
+ public Int3 GGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GGB)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 GBR
+ public Int3 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBR)}");
@@ -497,22 +497,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 GBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBG)}");
+ public Int3 GBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBG)}");
///
/// Gets an value with the , and values.
///
- public Int2 GBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBB)}");
+ public Int3 GBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(GBB)}");
///
/// Gets an value with the , and values.
///
- public Int2 BRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRR)}");
+ public Int3 BRR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRR)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 BRG
+ public Int3 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRG)}");
@@ -521,12 +521,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 BRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRB)}");
+ public Int3 BRB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BRB)}");
///
/// Gets or sets an value with the , and values.
///
- public Int2 BGR
+ public Int3 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGR)}");
@@ -535,33 +535,33 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public Int2 BGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGG)}");
+ public Int3 BGG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGG)}");
///
/// Gets an value with the , and values.
///
- public Int2 BGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGB)}");
+ public Int3 BGB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BGB)}");
///
/// Gets an value with the , and values.
///
- public Int2 BBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBR)}");
+ public Int3 BBR => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBR)}");
///
/// Gets an value with the , and values.
///
- public Int2 BBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBG)}");
+ public Int3 BBG => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBG)}");
///
/// Gets an value with the value for all components.
///
- public Int2 BBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBB)}");
+ public Int3 BBB => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(BBB)}");
///
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Int3(int x) => new Int3(x, x, x);
+ public static implicit operator Int3(int x) => new(x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/Int/Int4.cs b/src/ComputeSharp.Core/Primitives/Int/Int4.cs
index ed11b46b..692f5e66 100644
--- a/src/ComputeSharp.Core/Primitives/Int/Int4.cs
+++ b/src/ComputeSharp.Core/Primitives/Int/Int4.cs
@@ -24,22 +24,22 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int4 UnitX => new Int4(1, 0, 0, 0);
+ public static Int4 UnitX => new(1, 0, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int4 UnitY => new Int4(0, 1, 0, 0);
+ public static Int4 UnitY => new(0, 1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int4 UnitZ => new Int4(0, 0, 1, 0);
+ public static Int4 UnitZ => new(0, 0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static Int4 UnitW => new Int4(0, 0, 0, 1);
+ public static Int4 UnitW => new(0, 0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -3966,7 +3966,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator Int4(int x) => new Int4(x, x, x, x);
+ public static implicit operator Int4(int x) => new(x, x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/ThreadIds.cs b/src/ComputeSharp.Core/Primitives/ThreadIds.cs
index f5370ec8..69f58032 100644
--- a/src/ComputeSharp.Core/Primitives/ThreadIds.cs
+++ b/src/ComputeSharp.Core/Primitives/ThreadIds.cs
@@ -5,7 +5,7 @@ namespace ComputeSharp
///
/// A that indicates the ids of a given GPU thread running a compute shader.
///
- public readonly struct ThreadIds
+ public readonly ref struct ThreadIds
{
///
/// Gets the X id of the current thread.
@@ -21,5 +21,185 @@ namespace ComputeSharp
/// Gets the Z id of the current thread.
///
public 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)}");
+
+ ///
+ /// Gets or sets an value with the and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets or sets an value with the and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets or sets an value with the and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets or sets an value with the and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the value for all components.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the , and values.
+ ///
+ public 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)}");
+
+ ///
+ /// Gets an value with the value for all components.
+ ///
+ public Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}");
}
}
diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs
index 5f40d45f..8865306e 100644
--- a/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs
+++ b/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs
@@ -24,12 +24,12 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt2 UnitX => new UInt2(1, 0);
+ public static UInt2 UnitX => new(1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt2 UnitY => new UInt2(0, 1);
+ public static UInt2 UnitY => new(0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -140,7 +140,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator UInt2(uint x) => new UInt2(x, x);
+ public static implicit operator UInt2(uint x) => new(x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs
index ccaa7d12..7f4bfc83 100644
--- a/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs
+++ b/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs
@@ -24,17 +24,17 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt3 UnitX => new UInt3(1, 0, 0);
+ public static UInt3 UnitX => new(1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt3 UnitY => new UInt3(0, 1, 0);
+ public static UInt3 UnitY => new(0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt3 UnitZ => new UInt3(0, 0, 1);
+ public static UInt3 UnitZ => new(0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -242,32 +242,32 @@ namespace ComputeSharp
///
/// Gets an value with the value for all components.
///
- public UInt2 XXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXX)}");
+ public UInt3 XXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXX)}");
///
/// Gets an value with the , and values.
///
- public UInt2 XXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXY)}");
+ public UInt3 XXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXY)}");
///
/// Gets an value with the , and values.
///
- public UInt2 XXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXZ)}");
+ public UInt3 XXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XXZ)}");
///
/// Gets an value with the , and values.
///
- public UInt2 XYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYX)}");
+ public UInt3 XYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYX)}");
///
/// Gets an value with the , and values.
///
- public UInt2 XYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYY)}");
+ public UInt3 XYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYY)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 XYZ
+ public UInt3 XYZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XYZ)}");
@@ -276,12 +276,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 XZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZX)}");
+ public UInt3 XZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZX)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 XZY
+ public UInt3 XZY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZY)}");
@@ -290,22 +290,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 XZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZZ)}");
+ public UInt3 XZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(XZZ)}");
///
/// Gets an value with the , and values.
///
- public UInt2 YXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXX)}");
+ public UInt3 YXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXX)}");
///
/// Gets an value with the , and values.
///
- public UInt2 YXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXY)}");
+ public UInt3 YXY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXY)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 YXZ
+ public UInt3 YXZ
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXZ)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YXZ)}");
@@ -314,22 +314,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 YYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYX)}");
+ public UInt3 YYX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYX)}");
///
/// Gets an value with the value for all components.
///
- public UInt2 YYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYY)}");
+ public UInt3 YYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYY)}");
///
/// Gets an value with the , and values.
///
- public UInt2 YYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYZ)}");
+ public UInt3 YYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YYZ)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 YZX
+ public UInt3 YZX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZX)}");
@@ -338,22 +338,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 YZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZY)}");
+ public UInt3 YZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZY)}");
///
/// Gets an value with the , and values.
///
- public UInt2 YZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZZ)}");
+ public UInt3 YZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(YZZ)}");
///
/// Gets an value with the , and values.
///
- public UInt2 ZXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXX)}");
+ public UInt3 ZXX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXX)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 ZXY
+ public UInt3 ZXY
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXY)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXY)}");
@@ -362,12 +362,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 ZXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXZ)}");
+ public UInt3 ZXZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZXZ)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 ZYX
+ public UInt3 ZYX
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYX)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYX)}");
@@ -376,57 +376,57 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 ZYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYY)}");
+ public UInt3 ZYY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYY)}");
///
/// Gets an value with the , and values.
///
- public UInt2 ZYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYZ)}");
+ public UInt3 ZYZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZYZ)}");
///
/// Gets an value with the , and values.
///
- public UInt2 ZZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZX)}");
+ public UInt3 ZZX => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZX)}");
///
/// Gets an value with the , and values.
///
- public UInt2 ZZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZY)}");
+ public UInt3 ZZY => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZY)}");
///
/// Gets an value with the value for all components.
///
- public UInt2 ZZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZZ)}");
+ public UInt3 ZZZ => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(ZZZ)}");
///
/// Gets an value with the value for all components.
///
- public UInt2 RRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRR)}");
+ public UInt3 RRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRR)}");
///
/// Gets an value with the , and values.
///
- public UInt2 RRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRG)}");
+ public UInt3 RRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRG)}");
///
/// Gets an value with the , and values.
///
- public UInt2 RRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRB)}");
+ public UInt3 RRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RRB)}");
///
/// Gets an value with the , and values.
///
- public UInt2 RGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGR)}");
+ public UInt3 RGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGR)}");
///
/// Gets an value with the , and values.
///
- public UInt2 RGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGG)}");
+ public UInt3 RGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGG)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 RGB
+ public UInt3 RGB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RGB)}");
@@ -435,12 +435,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 RBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBR)}");
+ public UInt3 RBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBR)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 RBG
+ public UInt3 RBG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBG)}");
@@ -449,22 +449,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 RBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBB)}");
+ public UInt3 RBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(RBB)}");
///
/// Gets an value with the , and values.
///
- public UInt2 GRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRR)}");
+ public UInt3 GRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRR)}");
///
/// Gets an value with the , and values.
///
- public UInt2 GRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRG)}");
+ public UInt3 GRG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRG)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 GRB
+ public UInt3 GRB
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRB)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GRB)}");
@@ -473,22 +473,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 GGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGR)}");
+ public UInt3 GGR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGR)}");
///
/// Gets an value with the value for all components.
///
- public UInt2 GGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGG)}");
+ public UInt3 GGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGG)}");
///
/// Gets an value with the , and values.
///
- public UInt2 GGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGB)}");
+ public UInt3 GGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GGB)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 GBR
+ public UInt3 GBR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBR)}");
@@ -497,22 +497,22 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 GBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBG)}");
+ public UInt3 GBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBG)}");
///
/// Gets an value with the , and values.
///
- public UInt2 GBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBB)}");
+ public UInt3 GBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(GBB)}");
///
/// Gets an value with the , and values.
///
- public UInt2 BRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRR)}");
+ public UInt3 BRR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRR)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 BRG
+ public UInt3 BRG
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRG)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRG)}");
@@ -521,12 +521,12 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 BRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRB)}");
+ public UInt3 BRB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BRB)}");
///
/// Gets or sets an value with the , and values.
///
- public UInt2 BGR
+ public UInt3 BGR
{
get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGR)}");
set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGR)}");
@@ -535,33 +535,33 @@ namespace ComputeSharp
///
/// Gets an value with the , and values.
///
- public UInt2 BGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGG)}");
+ public UInt3 BGG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGG)}");
///
/// Gets an value with the , and values.
///
- public UInt2 BGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGB)}");
+ public UInt3 BGB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BGB)}");
///
/// Gets an value with the , and values.
///
- public UInt2 BBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBR)}");
+ public UInt3 BBR => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBR)}");
///
/// Gets an value with the , and values.
///
- public UInt2 BBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBG)}");
+ public UInt3 BBG => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBG)}");
///
/// Gets an value with the value for all components.
///
- public UInt2 BBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBB)}");
+ public UInt3 BBB => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(BBB)}");
///
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator UInt3(uint x) => new UInt3(x, x, x);
+ public static implicit operator UInt3(uint x) => new(x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs
index 1d6f1ba9..6bfbf0fb 100644
--- a/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs
+++ b/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs
@@ -24,22 +24,22 @@ namespace ComputeSharp
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt4 UnitX => new UInt4(1, 0, 0, 0);
+ public static UInt4 UnitX => new(1, 0, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt4 UnitY => new UInt4(0, 1, 0, 0);
+ public static UInt4 UnitY => new(0, 1, 0, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt4 UnitZ => new UInt4(0, 0, 1, 0);
+ public static UInt4 UnitZ => new(0, 0, 1, 0);
///
/// Gets an value with the component set to 1, and the others to 0.
///
- public static UInt4 UnitW => new UInt4(0, 0, 0, 1);
+ public static UInt4 UnitW => new(0, 0, 0, 1);
///
/// Creates a new instance with the specified parameters.
@@ -3966,7 +3966,7 @@ namespace ComputeSharp
/// Creates a new value with the same value for all its components.
///
/// The value to use for the components of the new instance.
- public static implicit operator UInt4(uint x) => new UInt4(x, x, x, x);
+ public static implicit operator UInt4(uint x) => new(x, x, x, x);
///
/// Sums two values.
diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs
index b04c95b4..6d1cb6ba 100644
--- a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs
@@ -1,13 +1,13 @@
-using System;
-using System.Buffers;
-using System.Diagnostics.Contracts;
+using System.Buffers;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using ComputeSharp.Core.Interop;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Extensions;
using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
+using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.Graphics.Buffers.Abstract
{
@@ -45,7 +45,15 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
{
device.ThrowIfDisposed();
- Guard.IsGreaterThanOrEqualTo(length, 0, nameof(length));
+ if (resourceType == ResourceType.Constant)
+ {
+ Guard.IsBetweenOrEqualTo(length, 1, FX.D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT, nameof(length));
+ }
+ else
+ {
+ // The maximum length is set such that the aligned buffer size can't exceed uint.MaxValue
+ Guard.IsBetweenOrEqualTo(length, 1, (uint.MaxValue / elementSizeInBytes) & ~255, nameof(length));
+ }
SizeInBytes = checked((nint)(length * elementSizeInBytes));
GraphicsDevice = device;
@@ -79,22 +87,13 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
///
public int Length { get; }
- ///
- /// Gets the size in bytes of each value contained in the buffer.
- ///
- protected int ElementSizeInBytes
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => Unsafe.SizeOf();
- }
-
///
/// Gets whether or not there is some padding between elements in the current buffer.
///
internal bool IsPaddingPresent
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => SizeInBytes > Length * Unsafe.SizeOf();
+ get => SizeInBytes > (nint)Length * sizeof(T);
}
///
@@ -103,114 +102,20 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
///
- /// Reads the contents of the current instance and returns an array.
- ///
- /// A array with the contents of the current buffer.
- [Pure]
- public T[] GetData()
- {
- return GetData(0, Length);
- }
-
- ///
- /// Reads the contents of the current instance in a given range and returns an array.
+ /// Reads the contents of the specified range from the current instance and writes them into a target memory area.
///
+ /// The input memory area to write data to.
+ /// The size of the memory area to write data to.
/// The offset to start reading data from.
- /// The number of items to read.
- /// A array with the contents of the specified range from the current buffer.
- [Pure]
- public T[] GetData(int offset, int count)
- {
- Guard.IsGreaterThanOrEqualTo(count, 0, nameof(count));
-
- T[] data = GC.AllocateUninitializedArray(count);
-
- GetData(data.AsSpan(), offset);
-
- return data;
- }
+ internal abstract void GetData(ref T destination, nint size, int offset);
///
- /// Reads the contents of the current instance and writes them into a target array.
+ /// Writes the contents of a given memory area to a specified area of the current instance.
///
- /// The input array to write data to.
- public void GetData(T[] destination)
- {
- GetData(destination.AsSpan(), 0);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array 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 void GetData(T[] destination, int destinationOffset, int bufferOffset, int count)
- {
- Span span = destination.AsSpan(destinationOffset, count);
-
- GetData(span, bufferOffset);
- }
-
- ///
- /// Reads the contents of the current instance and writes them into a target .
- /// The input data will be read from the start of the buffer.
- ///
- /// The input to write data to.
- public void GetData(Span destination)
- {
- GetData(destination, 0);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target .
- ///
- /// The input to write data to.
- /// The offset to start reading data from.
- public abstract void GetData(Span destination, int offset);
-
- ///
- /// Writes the contents of a given array to the current instance.
- ///
- /// The input array to read data from.
- public void SetData(T[] source)
- {
- SetData(source.AsSpan());
- }
-
- ///
- /// Writes the contents of a given array to a specified area of the current instance.
- ///
- /// The input array to read data from.
- /// The starting offset within to read data from.
- /// The offset to start writing data to.
- /// The number of items to write.
- public void SetData(T[] source, int sourceOffset, int bufferOffset, int count)
- {
- ReadOnlySpan span = source.AsSpan(sourceOffset, count);
-
- SetData(span, bufferOffset);
- }
-
- ///
- /// Writes the contents of a given to the current instance.
- /// The input data will be written to the start of the buffer, and all input items will be copied.
- ///
- /// The input to read data from.
- public void SetData(ReadOnlySpan source)
- {
- SetData(source, 0);
- }
-
- ///
- /// Writes the contents of a given to a specified area of the current instance.
- /// The input data will be written into the buffer starting at the specified offset, and all input items will be copied.
- ///
- /// The input to read data from.
+ /// The input memory area to read data from.
+ /// The size of the input memory area to read data from.
/// The offset to start writing data to.
- /// The number of items to write.
- public abstract void SetData(ReadOnlySpan source, int offset);
+ internal abstract void SetData(ref T source, nint size, int offset);
///
/// Writes the contents of a given to the current instance.
@@ -228,11 +133,9 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
try
{
- Span span = array.AsSpan(0, source.Length);
+ source.GetData(ref MemoryMarshal.GetArrayDataReference(array), source.Length, 0);
- source.GetData(span);
-
- SetData(span);
+ SetData(ref MemoryMarshal.GetArrayDataReference(array), source.Length, 0);
}
finally
{
diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs
index 41926a7a..86528ee7 100644
--- a/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Abstract/StructuredBuffer{T}.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Runtime.CompilerServices;
-using ComputeSharp.Graphics.Buffers.Enums;
+using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Buffers.Interop;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Graphics.Extensions;
@@ -24,24 +22,24 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
/// The associated with the current instance.
/// The number of items to store in the current buffer.
/// The buffer type for the current buffer.
- private protected StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType)
- : base(device, length, (uint)Unsafe.SizeOf(), resourceType)
+ private protected unsafe StructuredBuffer(GraphicsDevice device, int length, ResourceType resourceType)
+ : base(device, length, (uint)sizeof(T), resourceType)
{
}
///
- public override unsafe void GetData(Span destination, int offset)
+ internal override unsafe void GetData(ref T destination, nint size, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
- Guard.IsLessThanOrEqualTo((uint)offset + destination.Length, (uint)Length, nameof(destination));
+ Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
nint
- byteOffset = (nint)offset * ElementSizeInBytes,
- byteSize = (nint)destination.Length * ElementSizeInBytes;
+ byteOffset = (nint)offset * sizeof(T),
+ byteSize = size * sizeof(T);
using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, (ulong)byteSize);
@@ -52,29 +50,42 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
-
- MemoryHelper.Copy(resource.Pointer, 0, destination);
+ fixed (void* destinationPointer = &destination)
+ {
+ MemoryHelper.Copy(
+ resource.Pointer,
+ 0u,
+ (uint)size,
+ (uint)sizeof(T),
+ destinationPointer);
+ }
}
///
- public override unsafe void SetData(ReadOnlySpan source, int offset)
+ internal override unsafe void SetData(ref T source, nint size, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
- Guard.IsLessThanOrEqualTo((uint)offset + source.Length, (uint)Length, nameof(source));
+ Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
nint
- byteOffset = (nint)offset * ElementSizeInBytes,
- byteSize = (nint)source.Length * ElementSizeInBytes;
+ byteOffset = (nint)offset * sizeof(T),
+ byteSize = size * sizeof(T);
using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, (ulong)byteSize);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
+ fixed (void* sourcePointer = &source)
{
- MemoryHelper.Copy(source, resource.Pointer, 0);
+ MemoryHelper.Copy(
+ sourcePointer,
+ 0u,
+ (uint)size,
+ (uint)sizeof(T),
+ resource.Pointer);
}
using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs
index c909e598..2f00b7dd 100644
--- a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture2D{T}.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Diagnostics.Contracts;
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
using ComputeSharp.Core.Interop;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Buffers.Enums;
@@ -12,6 +10,8 @@ using Microsoft.Toolkit.Diagnostics;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
+using static TerraFX.Interop.D3D12_SRV_DIMENSION;
+using static TerraFX.Interop.D3D12_UAV_DIMENSION;
using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.Graphics.Buffers.Abstract
@@ -37,7 +37,12 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
///
/// The default value for the current resource.
///
- private readonly D3D12_RESOURCE_STATES D3D12ResourceState;
+ private readonly D3D12_RESOURCE_STATES d3D12ResourceState;
+
+ ///
+ /// The value to use for copy operations.
+ ///
+ private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType;
///
/// Creates a new instance with the specified parameters.
@@ -50,8 +55,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
{
device.ThrowIfDisposed();
- Guard.IsGreaterThanOrEqualTo(width, 0, nameof(width));
- Guard.IsGreaterThanOrEqualTo(height, 0, nameof(height));
+ Guard.IsBetweenOrEqualTo(width, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height));
GraphicsDevice = device;
Width = width;
@@ -62,17 +67,21 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
DXGIFormatHelper.GetForType(),
(uint)width,
(uint)height,
- out D3D12ResourceState);
+ out this.d3D12ResourceState);
+
+ this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
+ ? D3D12_COMMAND_LIST_TYPE_COPY
+ : D3D12_COMMAND_LIST_TYPE_COMPUTE;
device.AllocateShaderResourceViewDescriptorHandles(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
switch (resourceType)
{
case ResourceType.ReadOnly:
- device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType(), d3D12CpuDescriptorHandle);
+ device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE2D, d3D12CpuDescriptorHandle);
break;
case ResourceType.ReadWrite:
- device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType(), d3D12CpuDescriptorHandle);
+ device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE2D, d3D12CpuDescriptorHandle);
break;
}
}
@@ -98,133 +107,15 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
///
- /// Reads the contents of the current instance and returns an array.
+ /// Reads the contents of the specified range from the current instance and writes them into a target memory area.
///
- /// A array with the contents of the current buffer.
- [Pure]
- public T[,] GetData()
- {
- T[,] data = new T[Height, Width];
-
- GetData(data);
-
- return data;
- }
-
- ///
- /// Reads the contents of the current instance and writes them into a target array.
- ///
- /// The input array to write data to.
- public void GetData(T[,] destination)
- {
- fixed (T* p = destination)
- {
- GetData(new Span(p, destination.Length));
- }
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array to write data to.
- public void GetData(T[] destination)
- {
- GetData(destination.AsSpan(), 0, 0, Width, Height);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array to write data to.
- /// The horizontal range of items to copy.
- /// The vertical range of items to copy.
- public void GetData(T[] destination, Range x, Range y)
- {
- GetData(destination.AsSpan(), x, y);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array to write data to.
+ /// The target memory area to write data to.
+ /// The size of the target memory area 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.
/// The height of the memory area to copy.
- public void GetData(T[] destination, int x, int y, int width, int height)
- {
- GetData(destination.AsSpan(), x, y, width, height);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array to write data to.
- /// The starting offset within to write data to.
- public void GetData(T[] destination, int offset)
- {
- GetData(destination.AsSpan(offset), 0, 0, Width, Height);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array 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 void GetData(T[] destination, int offset, Range x, Range y)
- {
- GetData(destination.AsSpan(offset), x, y);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target array.
- ///
- /// The input array 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.
- /// The height of the memory area to copy.
- public void GetData(T[] destination, int offset, int x, int y, int width, int height)
- {
- GetData(destination.AsSpan(offset), x, y, width, height);
- }
-
- ///
- /// Reads the contents of the current instance and writes them into a target .
- /// The input data will be read from the start of the texture.
- ///
- /// The input to write data to.
- public void GetData(Span destination)
- {
- GetData(destination, 0, 0, Width, Height);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target .
- ///
- /// The input to write data to.
- /// The horizontal range of items to copy.
- /// The vertical range of items to copy.
- public void GetData(Span destination, Range x, Range y)
- {
- var (offsetX, width) = x.GetOffsetAndLength(Width);
- var (offsetY, height) = y.GetOffsetAndLength(Height);
-
- GetData(destination, offsetX, offsetY, width, height);
- }
-
- ///
- /// Reads the contents of the specified range from the current instance and writes them into a target .
- ///
- /// The input 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.
- /// The height of the memory area to copy.
- public void GetData(Span destination, int x, int y, int width, int height)
+ internal void GetData(ref T destination, nint size, int x, int y, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
@@ -232,136 +123,72 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
Guard.IsInRange(x, 0, Width, nameof(x));
Guard.IsInRange(y, 0, Height, nameof(y));
- Guard.IsBetweenOrEqualTo(width, 0, Width, nameof(width));
- Guard.IsBetweenOrEqualTo(height, 0, Height, nameof(height));
+ Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
- Guard.HasSizeGreaterThanOrEqualTo(destination, width * height, nameof(destination));
+ Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
- ulong
- rowByteSize = (ulong)((nint)width * Unsafe.SizeOf()),
- rowPitchSize = (rowByteSize + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((ulong)(FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)),
- resourceByteSize = rowPitchSize * (uint)height;
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, resourceByteSize);
+ GraphicsDevice.D3D12Device->GetCopyableFootprint(
+ &d3D12ResourceDescription,
+ out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
+ out _,
+ out ulong rowSizeInBytes,
+ out ulong totalSizeInBytes);
- using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COMPUTE))
+ using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes);
+
+ using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
{
- copyCommandList.ResourceBarrier(D3D12Resource, D3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
- copyCommandList.CopyTextureRegion(d3D12Resource.Get(), (uint)Unsafe.SizeOf(), D3D12Resource, DXGIFormatHelper.GetForType(), (uint)x, (uint)y, (uint)width, (uint)height);
- copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12ResourceState);
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
+ }
+
+ copyCommandList.CopyTextureRegion(
+ d3D12Resource.Get(),
+ &d3D12PlacedSubresourceFootprint,
+ D3D12Resource,
+ (uint)x,
+ (uint)y,
+ 0,
+ (uint)width,
+ (uint)height,
+ 1);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
+ }
+
copyCommandList.ExecuteAndWaitForCompletion();
}
using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
- MemoryHelper.Copy(resource.Pointer, width, height, rowByteSize, rowPitchSize, destination);
- }
-
- ///
- /// Writes the contents of a given array to the current instance.
- ///
- /// The input array to read data from.
- public void SetData(T[,] source)
- {
- fixed (T* p = source)
+ fixed (void* destinationPointer = &destination)
{
- SetData(new Span(p, source.Length));
+ MemoryHelper.Copy(
+ resource.Pointer,
+ (uint)height,
+ rowSizeInBytes,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
+ destinationPointer);
}
}
///
- /// Writes the contents of a given array to the current instance.
+ /// Writes the contents of a given memory area to a specified area of the current instance.
///
- /// The input array to read data from.
- public void SetData(T[] source)
- {
- SetData(source.AsSpan(), 0, 0, Width, Height);
- }
-
- ///
- /// Writes the contents of a given array to a specified area of the current instance.
- ///
- /// The input array to read data from.
- /// The horizontal range of items to write.
- /// The vertical range of items to write.
- public void SetData(T[] source, Range x, Range y)
- {
- SetData(source.AsSpan(), x, y);
- }
-
- ///
- /// Writes the contents of a given array to a specified area of the current instance.
- ///
- /// The input array to read data from.
+ /// The input memory area to read data from.
+ /// The size of the memory area to read data from.
/// The horizontal offset in the destination texture.
/// The vertical offset in the destination texture.
/// The width of the memory area to write to.
/// The height of the memory area to write to.
- public void SetData(T[] source, int x, int y, int width, int height)
- {
- SetData(source.AsSpan(), x, y, width, height);
- }
-
- ///
- /// Writes the contents of a given array to a specified area of the current instance.
- ///
- /// The input array to read data from.
- /// The starting offset within to read data from.
- /// The horizontal range of items to write.
- /// The vertical range of items to write.
- public void SetData(T[] source, int offset, Range x, Range y)
- {
- SetData(source.AsSpan(offset), x, y);
- }
-
- ///
- /// Writes the contents of a given array to a specified area of the current instance.
- ///
- /// The input array to read data from.
- /// The starting offset within to read data from.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
- public void SetData(T[] source, int offset, int x, int y, int width, int height)
- {
- SetData(source.AsSpan(offset), x, y, width, height);
- }
-
- ///
- /// Writes the contents of a given to the current instance.
- /// The input data will be written to the start of the texture, and all input items will be copied.
- ///
- /// The input to read data from.
- public void SetData(ReadOnlySpan source)
- {
- SetData(source, 0, 0, Width, Height);
- }
-
- ///
- /// Writes the contents of a given to a specified area of the current instance.
- ///
- /// The input to read data from.
- /// The horizontal range of items to write.
- /// The vertical range of items to write.
- public void SetData(ReadOnlySpan source, Range x, Range y)
- {
- var (offsetX, width) = x.GetOffsetAndLength(Width);
- var (offsetY, height) = y.GetOffsetAndLength(Height);
-
- SetData(source, offsetX, offsetY, width, height);
- }
-
- ///
- /// Writes the contents of a given to a specified area of the current instance.
- ///
- /// The input to read data from.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
- public void SetData(ReadOnlySpan source, int x, int y, int width, int height)
+ internal void SetData(ref T source, nint size, int x, int y, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
@@ -369,29 +196,54 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
Guard.IsInRange(x, 0, Width, nameof(x));
Guard.IsInRange(y, 0, Height, nameof(y));
- Guard.IsBetweenOrEqualTo(width, 0, Width, nameof(width));
- Guard.IsBetweenOrEqualTo(height, 0, Height, nameof(height));
+ Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
- Guard.HasSizeGreaterThanOrEqualTo(source, width * height, nameof(source));
+ Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
- ulong
- rowByteSize = (ulong)((nint)width * Unsafe.SizeOf()),
- rowPitchSize = (rowByteSize + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((ulong)(FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)),
- resourceByteSize = rowPitchSize * (uint)height;
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height);
- using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, resourceByteSize);
+ GraphicsDevice.D3D12Device->GetCopyableFootprint(
+ &d3D12ResourceDescription,
+ out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
+ out _,
+ out ulong rowSizeInBytes,
+ out ulong totalSizeInBytes);
+
+ using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
+ fixed (void* sourcePointer = &source)
{
- MemoryHelper.Copy(source, resource.Pointer, width, height, rowByteSize, rowPitchSize);
+ MemoryHelper.Copy(
+ sourcePointer,
+ resource.Pointer,
+ (uint)height,
+ rowSizeInBytes,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch);
}
- using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COMPUTE);
+ using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
+ }
+
+ copyCommandList.CopyTextureRegion(
+ D3D12Resource,
+ (uint)x,
+ (uint)y,
+ 0,
+ d3D12Resource.Get(),
+ &d3D12PlacedSubresourceFootprint);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
+ }
- copyCommandList.ResourceBarrier(D3D12Resource, D3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
- copyCommandList.CopyTextureRegion(D3D12Resource, DXGIFormatHelper.GetForType(), (uint)x, (uint)y, d3D12Resource.Get(), (uint)width, (uint)height, (uint)Unsafe.SizeOf());
- copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12ResourceState);
copyCommandList.ExecuteAndWaitForCompletion();
}
diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture3D{T}.cs
new file mode 100644
index 00000000..12599cdc
--- /dev/null
+++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Texture3D{T}.cs
@@ -0,0 +1,291 @@
+using System.Runtime.CompilerServices;
+using ComputeSharp.Core.Interop;
+using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics.Buffers.Enums;
+using ComputeSharp.Graphics.Buffers.Interop;
+using ComputeSharp.Graphics.Commands;
+using ComputeSharp.Graphics.Extensions;
+using ComputeSharp.Graphics.Helpers;
+using Microsoft.Toolkit.Diagnostics;
+using TerraFX.Interop;
+using static TerraFX.Interop.D3D12_COMMAND_LIST_TYPE;
+using static TerraFX.Interop.D3D12_RESOURCE_STATES;
+using static TerraFX.Interop.D3D12_SRV_DIMENSION;
+using static TerraFX.Interop.D3D12_UAV_DIMENSION;
+using FX = TerraFX.Interop.Windows;
+
+namespace ComputeSharp.Graphics.Buffers.Abstract
+{
+ ///
+ /// A representing a typed 3D texture stored on GPU memory.
+ ///
+ /// The type of items stored on the texture.
+ public unsafe abstract class Texture3D : NativeObject
+ where T : unmanaged
+ {
+ ///
+ /// The instance currently mapped.
+ ///
+ private ComPtr d3D12Resource;
+
+ ///
+ /// The instance for the current resource.
+ ///
+ /// This field is dynamically accessed when loading shader dispatch data.
+ internal readonly D3D12_GPU_DESCRIPTOR_HANDLE D3D12GpuDescriptorHandle;
+
+ ///
+ /// The default value for the current resource.
+ ///
+ private readonly D3D12_RESOURCE_STATES d3D12ResourceState;
+
+ ///
+ /// The value to use for copy operations.
+ ///
+ private readonly D3D12_COMMAND_LIST_TYPE d3D12CommandListType;
+
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The associated with the current instance.
+ /// The height of the texture.
+ /// The width of the texture.
+ /// The depth of the texture.
+ /// The resource type for the current texture.
+ private protected Texture3D(GraphicsDevice device, int width, int height, int depth, ResourceType resourceType)
+ {
+ device.ThrowIfDisposed();
+
+ Guard.IsBetweenOrEqualTo(width, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(height));
+ Guard.IsBetweenOrEqualTo(depth, 1, FX.D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, nameof(depth));
+
+ GraphicsDevice = device;
+ Width = width;
+ Height = height;
+ Depth = depth;
+
+ this.d3D12Resource = device.D3D12Device->CreateCommittedResource(
+ resourceType,
+ DXGIFormatHelper.GetForType(),
+ (uint)width,
+ (uint)height,
+ (ushort)depth,
+ out this.d3D12ResourceState);
+
+ this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON
+ ? D3D12_COMMAND_LIST_TYPE_COPY
+ : D3D12_COMMAND_LIST_TYPE_COMPUTE;
+
+ device.AllocateShaderResourceViewDescriptorHandles(out D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
+
+ switch (resourceType)
+ {
+ case ResourceType.ReadOnly:
+ device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE3D, d3D12CpuDescriptorHandle);
+ break;
+ case ResourceType.ReadWrite:
+ device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE3D, d3D12CpuDescriptorHandle);
+ break;
+ }
+ }
+
+ ///
+ /// Gets the associated with the current instance.
+ ///
+ public GraphicsDevice GraphicsDevice { get; }
+
+ ///
+ /// Gets the width of the current texture.
+ ///
+ public int Width { get; }
+
+ ///
+ /// Gets the height of the current texture.
+ ///
+ public int Height { get; }
+
+ ///
+ /// Gets the depth of the current texture.
+ ///
+ public int Depth { get; }
+
+ ///
+ /// Gets the instance currently mapped.
+ ///
+ internal ID3D12Resource* D3D12Resource => this.d3D12Resource;
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target memory area.
+ ///
+ /// The target memory area to write data to.
+ /// The size of the memory area 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.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ internal void GetData(ref T destination, nint size, int x, int y, int z, int width, int height, int depth)
+ {
+ GraphicsDevice.ThrowIfDisposed();
+
+ ThrowIfDisposed();
+
+ Guard.IsInRange(x, 0, Width, nameof(x));
+ Guard.IsInRange(y, 0, Height, nameof(y));
+ Guard.IsInRange(z, 0, Depth, nameof(z));
+ Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
+ Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
+ Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
+ Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
+ Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
+ Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size));
+
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth);
+
+ GraphicsDevice.D3D12Device->GetCopyableFootprint(
+ &d3D12ResourceDescription,
+ out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
+ out _,
+ out ulong rowSizeInBytes,
+ out ulong totalSizeInBytes);
+
+ using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.ReadBack, totalSizeInBytes);
+
+ using (CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType))
+ {
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE);
+ }
+
+ copyCommandList.CopyTextureRegion(
+ d3D12Resource.Get(),
+ &d3D12PlacedSubresourceFootprint,
+ D3D12Resource,
+ (uint)x,
+ (uint)y,
+ (ushort)z,
+ (uint)width,
+ (uint)height,
+ (ushort)depth);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState);
+ }
+
+ copyCommandList.ExecuteAndWaitForCompletion();
+ }
+
+ using ID3D12ResourceMap resource = d3D12Resource.Get()->Map();
+
+ fixed (void* destinationPointer = &destination)
+ {
+ MemoryHelper.Copy(
+ resource.Pointer,
+ (uint)height,
+ (uint)depth,
+ rowSizeInBytes,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height,
+ destinationPointer);
+ }
+ }
+
+ ///
+ /// Writes the contents of a given memory area to a specified area of the current instance.
+ ///
+ /// The input memory area to read data from.
+ /// The size of the memory area to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The depthwise offseet in the destination texture.
+ /// The width of the memory area to write to.
+ /// The height of the memory area to write to.
+ /// The depth of the memory area to write to.
+ internal void SetData(ref T source, nint size, int x, int y, int z, int width, int height, int depth)
+ {
+ GraphicsDevice.ThrowIfDisposed();
+
+ ThrowIfDisposed();
+
+ Guard.IsInRange(x, 0, Width, nameof(x));
+ Guard.IsInRange(y, 0, Height, nameof(y));
+ Guard.IsInRange(z, 0, Depth, nameof(z));
+ Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
+ Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
+ Guard.IsBetweenOrEqualTo(depth, 1, Depth, nameof(depth));
+ Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
+ Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
+ Guard.IsLessThanOrEqualTo(z + depth, Depth, nameof(z));
+ Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth, nameof(size));
+
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(DXGIFormatHelper.GetForType(), (ulong)width, (uint)height, (ushort)depth);
+
+ GraphicsDevice.D3D12Device->GetCopyableFootprint(
+ &d3D12ResourceDescription,
+ out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
+ out _,
+ out ulong rowSizeInBytes,
+ out ulong totalSizeInBytes);
+
+ using ComPtr d3D12Resource = GraphicsDevice.D3D12Device->CreateCommittedResource(ResourceType.Upload, totalSizeInBytes);
+
+ using (ID3D12ResourceMap resource = d3D12Resource.Get()->Map())
+ fixed (void* sourcePointer = &source)
+ {
+ MemoryHelper.Copy(
+ sourcePointer,
+ resource.Pointer,
+ (uint)height,
+ (uint)depth,
+ rowSizeInBytes,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch,
+ d3D12PlacedSubresourceFootprint.Footprint.RowPitch * (uint)height);
+ }
+
+ using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST);
+ }
+
+ copyCommandList.CopyTextureRegion(
+ D3D12Resource,
+ (uint)x,
+ (uint)y,
+ (ushort)z,
+ d3D12Resource.Get(),
+ &d3D12PlacedSubresourceFootprint);
+
+ if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE)
+ {
+ copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState);
+ }
+
+ copyCommandList.ExecuteAndWaitForCompletion();
+ }
+
+ ///
+ protected override void OnDispose()
+ {
+ this.d3D12Resource.Dispose();
+ }
+
+ ///
+ /// Throws a if the target device doesn't match the current one.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal void ThrowIfDeviceMismatch(GraphicsDevice device)
+ {
+ if (GraphicsDevice != device)
+ {
+ GraphicsDeviceMismatchException.Throw(this, device);
+ }
+ }
+ }
+}
diff --git a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
index 2789b764..732c78f2 100644
--- a/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/ConstantBuffer{T}.cs
@@ -1,8 +1,6 @@
-using System;
-using System.Diagnostics;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
@@ -48,71 +46,77 @@ namespace ComputeSharp
///
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int GetPaddedSize()
+ private static unsafe int GetPaddedSize()
{
- return (Unsafe.SizeOf() + 15) & ~15;
+ return (sizeof(T) + 15) & ~15;
}
///
- public override unsafe void GetData(Span destination, int offset)
+ internal override unsafe void GetData(ref T destination, nint size, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
- Guard.IsLessThanOrEqualTo((uint)offset + destination.Length, (uint)Length, nameof(destination));
+ Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
using ID3D12ResourceMap resource = D3D12Resource->Map();
-
- if (IsPaddingPresent)
+ fixed (void* destinationPointer = &destination)
{
- int count = destination.Length;
- ref T spanRef = ref MemoryMarshal.GetReference(destination);
- ref byte resourceRef = ref Unsafe.AsRef(resource.Pointer);
-
- // Move to the initial ref
- resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
-
- for (var i = 0; i < count; i++)
+ if (IsPaddingPresent)
{
- ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
-
- Unsafe.Add(ref spanRef, i) = Unsafe.As(ref targetRef);
+ MemoryHelper.Copy(
+ resource.Pointer,
+ (uint)offset,
+ (uint)size,
+ (uint)GetPaddedSize(),
+ destinationPointer);
+ }
+ else
+ {
+ MemoryHelper.Copy(
+ resource.Pointer,
+ (uint)offset,
+ (uint)size,
+ (uint)sizeof(T),
+ destinationPointer);
}
}
- else MemoryHelper.Copy(resource.Pointer, offset, destination);
}
///
- public override unsafe void SetData(ReadOnlySpan source, int offset)
+ internal override unsafe void SetData(ref T source, nint size, int offset)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(offset, 0, Length, nameof(offset));
- Guard.IsLessThanOrEqualTo((uint)offset + source.Length, (uint)Length, nameof(source));
+ Guard.IsLessThanOrEqualTo(offset + size, Length, nameof(size));
using ID3D12ResourceMap resource = D3D12Resource->Map();
-
- if (IsPaddingPresent)
+ fixed (void* sourcePointer = &source)
{
- int count = source.Length;
- ref T spanRef = ref MemoryMarshal.GetReference(source);
- ref byte resourceRef = ref Unsafe.AsRef(resource.Pointer);
-
- // Move to the initial offset
- resourceRef = ref Unsafe.Add(ref resourceRef, offset * GetPaddedSize());
-
- for (var i = 0; i < count; i++)
+ if (IsPaddingPresent)
{
- ref byte targetRef = ref Unsafe.Add(ref resourceRef, i * GetPaddedSize());
-
- Unsafe.As(ref targetRef) = Unsafe.Add(ref spanRef, i);
+ MemoryHelper.Copy(
+ sourcePointer,
+ resource.Pointer,
+ (uint)offset,
+ (uint)size,
+ (uint)GetPaddedSize());
+ }
+ else
+ {
+ MemoryHelper.Copy(
+ sourcePointer,
+ (uint)offset,
+ (uint)size,
+ (uint)sizeof(T),
+ resource.Pointer);
}
}
- else MemoryHelper.Copy(source, resource.Pointer, offset);
}
///
@@ -128,7 +132,7 @@ namespace ComputeSharp
source.GraphicsDevice == GraphicsDevice)
{
// Directly copy the input buffer, if possible
- using CommandList copyCommandList = new CommandList(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
+ using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY);
copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes);
copyCommandList.ExecuteAndWaitForCompletion();
diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs
index 2c7c9130..36b930ef 100644
--- a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture2D{T}.cs
@@ -11,7 +11,7 @@ namespace ComputeSharp
/// A representing a typed readonly 2D texture stored on GPU memory.
///
/// The type of items stored on the texture.
- [DebuggerTypeProxy(typeof(BufferDebugView2D<>))]
+ [DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadOnlyTexture2D : Texture2D
where T : unmanaged
@@ -27,12 +27,20 @@ namespace ComputeSharp
{
}
+ ///
+ /// Gets a single value from the current readonly texture.
+ ///
+ /// The horizontal offset of the value to get.
+ /// The vertical 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] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[int,int]");
+
///
/// Gets a single value from the current readonly texture.
///
/// The coordinates 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[UInt2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[UInt2]");
+ public T this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[Int2]");
///
public override string ToString()
diff --git a/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs
new file mode 100644
index 00000000..306b0d19
--- /dev/null
+++ b/src/ComputeSharp.Graphics/Buffers/ReadOnlyTexture3D{T}.cs
@@ -0,0 +1,53 @@
+using System.Diagnostics;
+using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using ComputeSharp.Graphics.Buffers.Enums;
+using ComputeSharp.Graphics.Buffers.Views;
+
+namespace ComputeSharp
+{
+ ///
+ /// A representing a typed readonly 3D texture stored on GPU memory.
+ ///
+ /// The type of items stored on the texture.
+ [DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
+ [DebuggerDisplay("{ToString(),raw}")]
+ public sealed class ReadOnlyTexture3D : Texture3D
+ where T : unmanaged
+ {
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The associated with the current instance.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ internal ReadOnlyTexture3D(GraphicsDevice device, int width, int height, int depth)
+ : base(device, width, height, depth, ResourceType.ReadOnly)
+ {
+ }
+
+ ///
+ /// Gets a single value from the current readonly texture.
+ ///
+ /// The horizontal offset of the value to get.
+ /// The vertical 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]");
+
+ ///
+ /// Gets a single value from the current readonly texture.
+ ///
+ /// The coordinates 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[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture3D)}[Int3]");
+
+ ///
+ public override string ToString()
+ {
+ return $"ComputeSharp.ReadOnlyTexture3D<{typeof(T)}>[{Width}, {Height}, {Depth}]";
+ }
+ }
+}
diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs
index a2f2c0c2..28c65443 100644
--- a/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteBuffer{T}.cs
@@ -27,7 +27,7 @@ namespace ComputeSharp
}
///
- /// Gets or sets a single value from the current read write buffer.
+ /// Gets or sets a single value from the current writeable buffer.
///
/// The index of the value to get or set.
/// This API can only be used from a compute shader, and will always throw if used anywhere else.
diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs
index 779bba67..1b75ce5b 100644
--- a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture2D{T}.cs
@@ -11,7 +11,7 @@ namespace ComputeSharp
/// A representing a typed read write 2D texture stored on GPU memory.
///
/// The type of items stored on the texture.
- [DebuggerTypeProxy(typeof(BufferDebugView2D<>))]
+ [DebuggerTypeProxy(typeof(Texture2DDebugView<>))]
[DebuggerDisplay("{ToString(),raw}")]
public sealed class ReadWriteTexture2D : Texture2D
where T : unmanaged
@@ -28,11 +28,19 @@ namespace ComputeSharp
}
///
- /// Gets or sets a single value from the current readonly texture.
+ /// Gets a single value from the current writeable texture.
+ ///
+ /// The horizontal offset of the value to get.
+ /// The vertical 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 ref T this[int x, int y] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D)}[int,int]");
+
+ ///
+ /// Gets or sets a single value from the current writeable texture.
///
/// The coordinates of the value to get.
/// This API can only be used from a compute shader, and will always throw if used anywhere else.
- public ref T this[UInt2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadOnlyTexture2D)}[UInt2]");
+ public ref T this[Int2 xy] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture2D)}[Int2]");
///
public override string ToString()
diff --git a/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs
new file mode 100644
index 00000000..8ee45602
--- /dev/null
+++ b/src/ComputeSharp.Graphics/Buffers/ReadWriteTexture3D{T}.cs
@@ -0,0 +1,53 @@
+using System.Diagnostics;
+using ComputeSharp.Exceptions;
+using ComputeSharp.Graphics;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using ComputeSharp.Graphics.Buffers.Enums;
+using ComputeSharp.Graphics.Buffers.Views;
+
+namespace ComputeSharp
+{
+ ///
+ /// A representing a typed readonly 3D texture stored on GPU memory.
+ ///
+ /// The type of items stored on the texture.
+ [DebuggerTypeProxy(typeof(Texture3DDebugView<>))]
+ [DebuggerDisplay("{ToString(),raw}")]
+ public sealed class ReadWriteTexture3D : Texture3D
+ where T : unmanaged
+ {
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The associated with the current instance.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ internal ReadWriteTexture3D(GraphicsDevice device, int width, int height, int depth)
+ : base(device, width, height, depth, ResourceType.ReadWrite)
+ {
+ }
+
+ ///
+ /// Gets a single value from the current writeable texture.
+ ///
+ /// The horizontal offset of the value to get.
+ /// The vertical 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 ref T this[int x, int y, int z] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D)}[int,int,int]");
+
+ ///
+ /// Gets a single value from the current writeable texture.
+ ///
+ /// The coordinates of the value to get.
+ /// This API can only be used from a compute shader, and will always throw if used anywhere else.
+ public ref T this[Int3 xyz] => throw new InvalidExecutionContextException($"{nameof(ReadWriteTexture3D)}[Int3]");
+
+ ///
+ public override string ToString()
+ {
+ return $"ComputeSharp.ReadWriteTexture3D<{typeof(T)}>[{Width}, {Height}, {Depth}]";
+ }
+ }
+}
diff --git a/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView{T}.cs b/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView{T}.cs
index ad14b604..59950292 100644
--- a/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView{T}.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System;
+using System.Diagnostics;
using ComputeSharp.Graphics.Buffers.Abstract;
namespace ComputeSharp.Graphics.Buffers.Views
@@ -16,7 +17,14 @@ namespace ComputeSharp.Graphics.Buffers.Views
/// The input instance with the items to display.
public BufferDebugView(Buffer? buffer)
{
- Items = buffer?.GetData();
+ if (buffer is not null)
+ {
+ var items = GC.AllocateUninitializedArray(buffer.Length);
+
+ buffer.GetData(ref items[0], buffer.Length, 0);
+
+ Items = items;
+ }
}
///
diff --git a/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView2D{T}.cs b/src/ComputeSharp.Graphics/Buffers/Views/Texture2DDebugView{T}.cs
similarity index 60%
rename from src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView2D{T}.cs
rename to src/ComputeSharp.Graphics/Buffers/Views/Texture2DDebugView{T}.cs
index c3061ea1..def44462 100644
--- a/src/ComputeSharp.Graphics/Buffers/Views/BufferDebugView2D{T}.cs
+++ b/src/ComputeSharp.Graphics/Buffers/Views/Texture2DDebugView{T}.cs
@@ -7,16 +7,23 @@ namespace ComputeSharp.Graphics.Buffers.Views
/// A debug proxy used to display items in a instance.
///
/// The type of items to display.
- internal sealed class BufferDebugView2D
+ internal sealed class Texture2DDebugView
where T : unmanaged
{
///
- /// 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 with the items to display.
- public BufferDebugView2D(Texture2D? texture)
+ public Texture2DDebugView(Texture2D? texture)
{
- Items = texture?.GetData();
+ if (texture is not null)
+ {
+ var items = new T[texture.Height, texture.Width];
+
+ texture.GetData(ref items[0, 0], items.Length, 0, 0, texture.Width, texture.Height);
+
+ Items = items;
+ }
}
///
diff --git a/src/ComputeSharp.Graphics/Buffers/Views/Texture3DDebugView{T}.cs b/src/ComputeSharp.Graphics/Buffers/Views/Texture3DDebugView{T}.cs
new file mode 100644
index 00000000..d4e43269
--- /dev/null
+++ b/src/ComputeSharp.Graphics/Buffers/Views/Texture3DDebugView{T}.cs
@@ -0,0 +1,35 @@
+using System.Diagnostics;
+using ComputeSharp.Graphics.Buffers.Abstract;
+
+namespace ComputeSharp.Graphics.Buffers.Views
+{
+ ///
+ /// A debug proxy used to display items in a instance.
+ ///
+ /// The type of items to display.
+ internal sealed class Texture3DDebugView
+ where T : unmanaged
+ {
+ ///
+ /// Initializes a new instance of the class with the specified parameters.
+ ///
+ /// The input instance with the items to display.
+ public Texture3DDebugView(Texture3D? texture)
+ {
+ if (texture is not null)
+ {
+ var items = new T[texture.Depth, texture.Height, texture.Width];
+
+ texture.GetData(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+
+ Items = items;
+ }
+ }
+
+ ///
+ /// Gets the items to display for the current instance.
+ ///
+ [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
+ public T[,,]? Items { get; }
+ }
+}
diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs
index 2eb12aaa..13bc89bc 100644
--- a/src/ComputeSharp.Graphics/Commands/CommandList.cs
+++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs
@@ -55,7 +55,7 @@ namespace ComputeSharp.Graphics.Commands
///
/// Gets the command list type being used by the current instance.
///
- public readonly D3D12_COMMAND_LIST_TYPE D3d12CommandListType => this.d3D12CommandListType;
+ public readonly D3D12_COMMAND_LIST_TYPE D3D12CommandListType => this.d3D12CommandListType;
///
/// Detaches the object in use by the current instance.
@@ -95,49 +95,46 @@ namespace ComputeSharp.Graphics.Commands
/// Copies a texture memory region from one resource (a buffer) to another (a texture).
///
/// The destination (a texture) to write to.
- /// The parameter curreently in use by the texture.
/// The horizontal offset in the destination texture.
/// The vertical offset in the destination texture.
+ /// The depthwise offset in the destination texture.
/// The source (a buffer) to read from.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
- /// The size of each element to copy.
+ /// The value describing .
public readonly void CopyTextureRegion(
ID3D12Resource* d3D12ResourceDestination,
- DXGI_FORMAT dxgiFormat,
uint x,
uint y,
+ ushort z,
ID3D12Resource* d3D12ResourceSource,
- uint width,
- uint height,
- uint elementSizeInBytes)
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource)
{
- this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, dxgiFormat, x, y, d3D12ResourceSource, width, height, elementSizeInBytes);
+ this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, x, y, z, d3D12ResourceSource, d3D12PlacedSubresourceFootprintSource);
}
///
/// Copies a texture memory region from one resource (a texture) to another (a buffer).
///
/// The destination (a buffer) to write to.
- /// The size of each element to copy.
+ /// The value describing .
/// The source (a texture) to read from.
- /// The parameter curreently in use by the texture.
/// The horizontal offset in the destination texture.
/// The vertical offset in the destination texture.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
+ /// 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.
public readonly void CopyTextureRegion(
ID3D12Resource* d3D12ResourceDestination,
- uint elementSizeInBytes,
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination,
ID3D12Resource* d3D12ResourceSource,
- DXGI_FORMAT dxgiFormat,
uint x,
uint y,
+ ushort z,
uint width,
- uint height)
+ uint height,
+ ushort depth)
{
- this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, elementSizeInBytes, d3D12ResourceSource, dxgiFormat, x, y, width, height);
+ this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, d3D12PlacedSubresourceFootprintDestination, d3D12ResourceSource, x, y, z, width, height, depth);
}
///
diff --git a/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs b/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs
index 8c7eb70c..4abb6981 100644
--- a/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs
+++ b/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs
@@ -71,5 +71,18 @@ namespace ComputeSharp.Exceptions
{
throw Create(texture, texture.GraphicsDevice, device);
}
+
+ ///
+ /// Throws a new instance from the specified parameters.
+ ///
+ /// The type of values in the input buffer.
+ /// The input that was used.
+ /// The target instance that was used.
+ [Pure]
+ internal static void Throw(Texture3D texture, GraphicsDevice device)
+ where T : unmanaged
+ {
+ throw Create(texture, texture.GraphicsDevice, device);
+ }
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs
index abe70867..3576f368 100644
--- a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs
+++ b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs
@@ -163,7 +163,7 @@ namespace ComputeSharp.Graphics.Extensions
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
{
- ResourceType.ReadOnly => (D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
+ ResourceType.ReadOnly => (D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
ResourceType.ReadWrite => (D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
_ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
};
@@ -190,6 +190,57 @@ namespace ComputeSharp.Graphics.Extensions
return d3D12Resource.Move();
}
+ ///
+ /// Creates a committed resource for a given 3D texture type.
+ ///
+ /// The instance in use.
+ /// The resource type currently in use.
+ /// The value to use.
+ /// The width of the texture resource.
+ /// The height of the texture resource.
+ /// The depth of the texture resource.
+ /// The default value for the resource.
+ /// An reference for the current texture.
+ public static ComPtr CreateCommittedResource(
+ this ref ID3D12Device d3D12Device,
+ ResourceType resourceType,
+ DXGI_FORMAT dxgiFormat,
+ uint width,
+ uint height,
+ ushort depth,
+ out D3D12_RESOURCE_STATES d3D12ResourceStates)
+ {
+ D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
+
+ (d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
+ {
+ ResourceType.ReadOnly => (D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COMMON),
+ ResourceType.ReadWrite => (D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
+ _ => ThrowHelper.ThrowArgumentException<(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_STATES)>()
+ };
+
+ using ComPtr d3D12Resource = default;
+
+ D3D12_HEAP_PROPERTIES d3D12HeapProperties;
+ d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
+ d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
+ d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
+ d3D12HeapProperties.CreationNodeMask = 1;
+ d3D12HeapProperties.VisibleNodeMask = 1;
+ D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex3D(dxgiFormat, width, height, depth, flags: d3D12ResourceFlags);
+
+ d3D12Device.CreateCommittedResource(
+ &d3D12HeapProperties,
+ D3D12_HEAP_FLAG_NONE,
+ &d3D12ResourceDescription,
+ d3D12ResourceStates,
+ null,
+ FX.__uuidof(),
+ d3D12Resource.GetVoidAddressOf()).Assert();
+
+ return d3D12Resource.Move();
+ }
+
///
/// Creates a view for a constant buffer.
///
@@ -242,15 +293,17 @@ namespace ComputeSharp.Graphics.Extensions
/// The target instance in use.
/// The to create a view for.
/// The value to use.
+ /// The value for the view to create.
/// The instance for the current resource.
public static void CreateShaderResourceView(
this ref ID3D12Device d3D12Device,
ID3D12Resource* d3D12Resource,
DXGI_FORMAT dxgiFormat,
+ D3D12_SRV_DIMENSION d3D12SrvDimension,
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
{
D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default;
- d3D12ShaderResourceViewDescription.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ d3D12ShaderResourceViewDescription.ViewDimension = d3D12SrvDimension;
d3D12ShaderResourceViewDescription.Format = dxgiFormat;
d3D12ShaderResourceViewDescription.Shader4ComponentMapping = FX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
d3D12ShaderResourceViewDescription.Texture2D.MipLevels = uint.MaxValue;
@@ -287,16 +340,19 @@ namespace ComputeSharp.Graphics.Extensions
/// The target instance in use.
/// The to create a view for.
/// The value to use.
+ /// The value for the view to create.
/// The instance for the current resource.
public static void CreateUnorderedAccessView(
this ref ID3D12Device d3D12Device,
ID3D12Resource* d3D12Resource,
DXGI_FORMAT dxgiFormat,
+ D3D12_UAV_DIMENSION d3D12UavDimension,
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
{
D3D12_UNORDERED_ACCESS_VIEW_DESC d3D12UnorderedAccessViewDescription = default;
- d3D12UnorderedAccessViewDescription.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
+ d3D12UnorderedAccessViewDescription.ViewDimension = d3D12UavDimension;
d3D12UnorderedAccessViewDescription.Format = dxgiFormat;
+ d3D12UnorderedAccessViewDescription.Texture3D.WSize = uint.MaxValue;
d3D12Device.CreateUnorderedAccessView(d3D12Resource, null, &d3D12UnorderedAccessViewDescription, d3D12CpuDescriptorHandle);
}
@@ -347,6 +403,36 @@ namespace ComputeSharp.Graphics.Extensions
return d3D12GraphicsCommandList.Move();
}
+ ///
+ /// Gets the layout data for a target resource.
+ ///
+ /// The target to use to get the layout info.
+ /// The value for the target resource.
+ /// The resulting layout info for the resource.
+ /// The number of rows in the resource.
+ /// The size in bytes of each row in the resource.
+ /// The total number of bytes for the resource.
+ public static void GetCopyableFootprint(
+ this ref ID3D12Device d3D12Device,
+ D3D12_RESOURCE_DESC* d3D12ResourceDesc,
+ out D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint,
+ out uint numRows,
+ out ulong rowSizeInBytes,
+ out ulong totalSizeInBytes)
+ {
+ uint a;
+ ulong b, c;
+
+ fixed (D3D12_PLACED_SUBRESOURCE_FOOTPRINT* p = &d3D12PlacedSubresourceFootprint)
+ {
+ d3D12Device.GetCopyableFootprints(d3D12ResourceDesc, 0, 1, 0, p, &a, &b, &c);
+ }
+
+ numRows = a;
+ rowSizeInBytes = b;
+ totalSizeInBytes = c;
+ }
+
///
/// Checks the feature support of a given type for a given device.
///
diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs
index 4f7effdd..a228f3ed 100644
--- a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs
+++ b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs
@@ -1,5 +1,4 @@
using TerraFX.Interop;
-using FX = TerraFX.Interop.Windows;
namespace ComputeSharp.Graphics.Extensions
{
@@ -13,39 +12,26 @@ namespace ComputeSharp.Graphics.Extensions
///
/// The instance in use.
/// The destination (a texture) to write to.
- /// The parameter curreently in use by the texture.
/// The horizontal offset in the destination texture.
/// The vertical offset in the destination texture.
+ /// The depthwise offset in the destination texture.
/// The source (a buffer) to read from.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
- /// The size of each element to copy.
+ /// The value describing .
public static void CopyTextureRegion(
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
ID3D12Resource* d3D12ResourceDestination,
- DXGI_FORMAT dxgiFormat,
uint x,
uint y,
+ ushort z,
ID3D12Resource* d3D12ResourceSource,
- uint width,
- uint height,
- uint elementSizeInBytes)
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource)
{
- D3D12_SUBRESOURCE_FOOTPRINT d3D12SubresourceFootprint = new(
- dxgiFormat,
- width,
- height,
- 1,
- (elementSizeInBytes * width + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1));
- D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
- d3D12PlacedSubresourceFootprint.Offset = 0;
- d3D12PlacedSubresourceFootprint.Footprint = d3D12SubresourceFootprint;
D3D12_TEXTURE_COPY_LOCATION
d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, 0),
- d3D12TextureCopyLocationSource = new(d3D12ResourceSource, d3D12PlacedSubresourceFootprint);
+ d3D12TextureCopyLocationSource = new(d3D12ResourceSource, in *d3D12PlacedSubresourceFootprintSource);
- d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, 0, &d3D12TextureCopyLocationSource, null);
+ d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, x, y, z, &d3D12TextureCopyLocationSource, null);
}
///
@@ -53,37 +39,30 @@ namespace ComputeSharp.Graphics.Extensions
///
/// The instance in use.
/// The destination (a buffer) to write to.
- /// The size of each element to copy.
+ /// The value describing .
/// The source (a texture) to read from.
- /// The parameter curreently in use by the texture.
- /// The horizontal offset in the destination texture.
- /// The vertical offset in the destination texture.
- /// The width of the memory area to write to.
- /// The height of the memory area to write to.
+ /// The horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source 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.
public static void CopyTextureRegion(
this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList,
ID3D12Resource* d3D12ResourceDestination,
- uint elementSizeInBytes,
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination,
ID3D12Resource* d3D12ResourceSource,
- DXGI_FORMAT dxgiFormat,
uint x,
uint y,
+ ushort z,
uint width,
- uint height)
+ uint height,
+ ushort depth)
{
- D3D12_SUBRESOURCE_FOOTPRINT d3D12SubresourceFootprint = new(
- dxgiFormat,
- width,
- height,
- 1,
- (elementSizeInBytes * width + FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1) & ~((uint)FX.D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1));
- D3D12_PLACED_SUBRESOURCE_FOOTPRINT d3D12PlacedSubresourceFootprint;
- d3D12PlacedSubresourceFootprint.Offset = 0;
- d3D12PlacedSubresourceFootprint.Footprint = d3D12SubresourceFootprint;
D3D12_TEXTURE_COPY_LOCATION
- d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, d3D12PlacedSubresourceFootprint),
+ d3D12TextureCopyLocationDestination = new(d3D12ResourceDestination, in *d3D12PlacedSubresourceFootprintDestination),
d3D12TextureCopyLocationSource = new(d3D12ResourceSource, 0);
- D3D12_BOX d3D12Box = new((int)x, (int)y, (int)(x + width), (int)(y + height));
+ D3D12_BOX d3D12Box = new((int)x, (int)y, z, (int)(x + width), (int)(y + height), z + depth);
d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, 0, 0, 0, &d3D12TextureCopyLocationSource, &d3D12Box);
}
diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs
index e49cee8f..cdfad124 100644
--- a/src/ComputeSharp.Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs
@@ -168,7 +168,7 @@ namespace ComputeSharp.Graphics
ulong d3D12FenceValue;
// Get the target command queue, fence and pool for the list type
- switch (commandList.D3d12CommandListType)
+ switch (commandList.D3D12CommandListType)
{
case D3D12_COMMAND_LIST_TYPE_COMPUTE:
commandAllocatorPool = ref this.computeCommandAllocatorPool;
diff --git a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
index 9115977c..4842f413 100644
--- a/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
+++ b/src/ComputeSharp.Graphics/Helpers/MemoryHelper.cs
@@ -9,101 +9,253 @@ namespace ComputeSharp.Graphics.Helpers
internal static class MemoryHelper
{
///
- /// Copies the content of a to the area pointed by an input pointer.
+ /// Copies the content of a source memory area to a target one.
///
- /// The type of values in the input .
- /// The source to read.
+ /// The source memory area to read from.
/// The pointer for the destination memory area.
- /// The destination offset to start writing data to.
+ /// The destination offset to start writing data to.
+ /// The number of items to copy.
+ /// The size in bytes of each item to copy.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(ReadOnlySpan source, void* destination, int destinationOffset)
- where T : unmanaged
+ public static unsafe void Copy(
+ void* source,
+ void* destination,
+ uint offset,
+ uint length,
+ uint elementSizeInBytes)
{
- source.CopyTo(new Span((T*)destination + destinationOffset, source.Length));
+ Buffer.MemoryCopy(
+ source,
+ (byte*)destination + offset * elementSizeInBytes,
+ ulong.MaxValue,
+ elementSizeInBytes * length);
}
///
- /// Copies a memory area pointed by a pointer to a target .
+ /// Copies the content of a source memory area to a target one, accounting for padding.
+ /// The destination memory area has padding for each element, while the source does not.
///
- /// The type of values to read.
- /// The pointer that indicates the memory area to read from.
- /// The source offset to start reading data from.
- /// The destination to write.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(void* source, int sourceOffset, Span destination)
+ /// The source memory area to read from.
+ /// The pointer for the destination memory area.
+ /// The destination offset to start writing data to.
+ /// The number of items to copy.
+ /// The padded size of each element.
+ public static unsafe void Copy(
+ void* source,
+ void* destination,
+ uint offset,
+ uint length,
+ uint elementPitchInBytes)
where T : unmanaged
{
- new Span((T*)source + sourceOffset, destination.Length).CopyTo(destination);
+ destination = (byte*)destination + offset * elementPitchInBytes;
+
+ for (int i = 0; i < length; i++)
+ {
+ *(T*)&((byte*)destination)[i * elementPitchInBytes] = ((T*)source)[i];
+ }
}
///
- /// Copies the content of a to the 2D area pointed by an input pointer.
+ /// Copies the content of a source memory area to a target one.
///
- /// The type of values to read.
- /// The destination to read from.
+ /// The source memory area to read from.
+ /// The source offset to start reading data from.
+ /// The number of items to copy.
+ /// The size in bytes of each item to copy.
+ /// The pointer for the destination memory area.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe void Copy(
+ void* source,
+ uint offset,
+ uint length,
+ uint elementSizeInBytes,
+ void* destination)
+ {
+ Buffer.MemoryCopy(
+ (byte*)source + offset * elementSizeInBytes,
+ destination,
+ ulong.MaxValue,
+ elementSizeInBytes * length);
+ }
+
+ ///
+ /// Copies the content of a source memory area to a target one, accounting for padding.
+ /// The source memory area has padding for each element, while the destination does not.
+ ///
+ /// The source memory area to read from.
+ /// The source offset to start reading data from.
+ /// The number of items to copy.
+ /// The padded size of each element.
+ /// The pointer for the destination memory area.
+ public static unsafe void Copy(
+ void* source,
+ uint offset,
+ uint length,
+ uint elementPitchInBytes,
+ void* destination)
+ where T : unmanaged
+ {
+ source = (byte*)source + offset * elementPitchInBytes;
+
+ for (int i = 0; i < length; i++)
+ {
+ ((T*)destination)[i] = *(T*)&((byte*)source)[i * elementPitchInBytes];
+ }
+ }
+
+ ///
+ /// Copies the content of a source memory area to the 2D area pointed by an input pointer.
+ /// The destination memory area has padding in each row, while the source does not.
+ ///
+ /// The source pointer to read from.
/// The pointer that indicates the 2D memory area to write to.
- /// The width of the 2D memory area to read.
- /// The height of the 2D memory area to read.
+ /// The height of the 2D memory area to write to.
/// The width of the memory area in bytes.
/// The pitch (padded width) of the memory area in bytes.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(
- ReadOnlySpan source,
+ public static unsafe void Copy(
+ void* source,
void* destination,
- int width,
- int height,
+ uint height,
ulong widthInBytes,
ulong pitchInBytes)
- where T : unmanaged
{
if (widthInBytes == pitchInBytes)
{
- source.CopyTo(new Span(destination, width * height));
+ Buffer.MemoryCopy(source, destination, ulong.MaxValue, widthInBytes * height);
}
else
{
for (int i = 0; i < height; i++)
{
- ReadOnlySpan sourceRow = source.Slice(i * width, width);
- Span destinationRow = new((byte*)destination + (uint)i * pitchInBytes, width);
-
- sourceRow.CopyTo(destinationRow);
+ Buffer.MemoryCopy(
+ (byte*)source + (uint)i * widthInBytes,
+ (byte*)destination + (uint)i * pitchInBytes,
+ ulong.MaxValue,
+ widthInBytes);
}
}
}
///
- /// Copies a 2D memory area pointed by a pointer value to a target .
+ /// Copies a 2D 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 width of the 2D memory area to read.
/// The height of the 2D memory area to read.
/// The width of the memory area in bytes.
/// The pitch (padded width) of the memory area in bytes.
- /// The destination to write.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static unsafe void Copy(
+ /// The destination pointer to write to.
+ public static unsafe void Copy(
void* source,
- int width,
- int height,
+ uint height,
ulong widthInBytes,
ulong pitchInBytes,
- Span destination)
- where T : unmanaged
+ void* destination)
{
if (widthInBytes == pitchInBytes)
{
- new Span(source, width * height).CopyTo(destination);
+ Buffer.MemoryCopy(source, destination, ulong.MaxValue, widthInBytes * height);
}
else
{
for (int i = 0; i < height; i++)
{
- ReadOnlySpan sourceRow = new((byte*)source + (uint)i * pitchInBytes, width);
- Span destinationRow = destination.Slice(i * width, width);
+ Buffer.MemoryCopy(
+ (byte*)source + (uint)i * pitchInBytes,
+ (byte*)destination + (uint)i * widthInBytes,
+ ulong.MaxValue,
+ widthInBytes);
+ }
+ }
+ }
- sourceRow.CopyTo(destinationRow);
+ ///
+ /// 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.
+ /// The depth of the 3D memory area to write to.
+ /// The width of the memory area in bytes.
+ /// The pitch (padded width) of the memory area in bytes.
+ /// The size in bytes of each 2D slice within the target 3D memory area.
+ public static unsafe void Copy(
+ void* source,
+ void* destination,
+ uint height,
+ uint depth,
+ ulong widthInBytes,
+ ulong pitchInBytes,
+ ulong sliceInBytes)
+ {
+ if (widthInBytes == pitchInBytes)
+ {
+ Buffer.MemoryCopy(source, destination, ulong.MaxValue, widthInBytes * height * depth);
+ }
+ else
+ {
+ for (int z = 0; z < depth; z++)
+ {
+ ulong
+ sourceZOffset = (uint)z * widthInBytes * height,
+ destinationZOffset = (uint)z * sliceInBytes;
+
+ for (int i = 0; i < height; i++)
+ {
+ Buffer.MemoryCopy(
+ (byte*)source + sourceZOffset + (uint)i * widthInBytes,
+ (byte*)destination + destinationZOffset + (uint)i * pitchInBytes,
+ ulong.MaxValue,
+ widthInBytes);
+ }
+ }
+ }
+ }
+
+ ///
+ /// 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.
+ /// The width of the memory area in bytes.
+ /// The pitch (padded width) of the memory area in bytes.
+ /// The size in bytes of each 2D slice within the source 3D memory area.
+ /// The destination pointer to write.
+ public static unsafe void Copy(
+ void* source,
+ uint height,
+ uint depth,
+ ulong widthInBytes,
+ ulong pitchInBytes,
+ ulong sliceInBytes,
+ void* destination)
+ {
+ if (widthInBytes == pitchInBytes)
+ {
+ Buffer.MemoryCopy(source, destination, ulong.MaxValue, widthInBytes * height * depth);
+ }
+ else
+ {
+ for (int z = 0; z < depth; z++)
+ {
+ ulong
+ sourceZOffset = (uint)z * sliceInBytes,
+ destinationZOffset = (uint)z * widthInBytes * height;
+
+ for (int i = 0; i < height; i++)
+ {
+ Buffer.MemoryCopy(
+ (byte*)source + sourceZOffset + (uint)i * pitchInBytes,
+ (byte*)destination + destinationZOffset + (uint)i * widthInBytes,
+ ulong.MaxValue,
+ widthInBytes);
+ }
}
}
}
diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
index 7f9248a2..5bec10c2 100644
--- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
+++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Commands;
@@ -136,8 +137,9 @@ namespace ComputeSharp.Shaders
// Initialize the loop targets and the captured values
ConstantBuffer variablesBuffer = ShaderRunner.GetVariablesBuffer(device);
+ ReadOnlySpan variables = dispatchData.Variables;
- variablesBuffer.SetData(dispatchData.Variables);
+ variablesBuffer.SetData(ref MemoryMarshal.GetReference(variables), variables.Length, 0);
commandList.SetComputeRootDescriptorTable(0, variablesBuffer.D3D12GpuDescriptorHandle);
diff --git a/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs
similarity index 91%
rename from src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs
rename to src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs
index 7ade5bc9..b3fe7b73 100644
--- a/src/ComputeSharp.Shaders/Mappings/HlslKnownTypes.cs
+++ b/src/ComputeSharp.Shaders/Translation/Mappings/HlslKnownTypes.cs
@@ -63,7 +63,7 @@ namespace ComputeSharp.Shaders.Mappings
type.GetGenericTypeDefinition() == typeof(ConstantBuffer<>);
///
- /// Checks whether or not the input type is a or value.
+ /// Checks whether or not the input type is a known readonly resource type (buffer or texture).
///
/// The input instance to check.
/// A indicating whether the input is a readonly resource type.
@@ -76,11 +76,12 @@ namespace ComputeSharp.Shaders.Mappings
return
genericType == typeof(ReadOnlyBuffer<>) ||
- genericType == typeof(ReadOnlyTexture2D<>);
+ genericType == typeof(ReadOnlyTexture2D<>) ||
+ genericType == typeof(ReadOnlyTexture3D<>);
}
///
- /// Checks whether or not the input type is a or value.
+ /// Checks whether or not the input type is a known writeable resource type (buffer or texture).
///
/// The input instance to check.
/// A indicating whether the input is a writeable resource type.
@@ -93,7 +94,8 @@ namespace ComputeSharp.Shaders.Mappings
return
genericType == typeof(ReadWriteBuffer<>) ||
- genericType == typeof(ReadWriteTexture2D<>);
+ genericType == typeof(ReadWriteTexture2D<>) ||
+ genericType == typeof(ReadWriteTexture3D<>);
}
}
}
diff --git a/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs b/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
index d1581c61..e08f19e8 100644
--- a/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGenerators/Extensions/ISymbolExtensions.cs
@@ -74,6 +74,26 @@ namespace ComputeSharp.SourceGenerators.Extensions
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat);
}
+ ///
+ /// Gets the full metadata name for a given instance.
+ ///
+ /// The input instance.
+ /// The full metadata name for .
+ [Pure]
+ public static string GetFullMetadataName(this IPropertySymbol symbol)
+ {
+ string declaringTypeName = symbol.ContainingType.GetFullMetadataName();
+
+ if (symbol.IsIndexer)
+ {
+ var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
+
+ return $"{declaringTypeName}.this[{parameters}]";
+ }
+
+ return $"{declaringTypeName}.{symbol.Name}";
+ }
+
///
/// Gets a valid filename for a target symbol and generator type.
///
diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs
index 874b4cfe..7a7df32b 100644
--- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs
+++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs
@@ -12,6 +12,17 @@ namespace ComputeSharp.SourceGenerators.Mappings
///
internal static class HlslKnownMembers
{
+ ///
+ /// The mapping of supported known indexers to HLSL vector type names.
+ ///
+ private static readonly IReadOnlyDictionary KnownIndexers = new Dictionary
+ {
+ [$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
+ [$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
+ [$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
+ };
+
///
/// The mapping of supported known members to HLSL names.
///
@@ -25,10 +36,6 @@ namespace ComputeSharp.SourceGenerators.Mappings
{
Dictionary knownMembers = new()
{
- [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.X)}"] = "x",
- [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.Y)}"] = "y",
- [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.Z)}"] = "z",
-
[$"{typeof(Vector2).FullName}.{nameof(Vector2.X)}"] = "x",
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Y)}"] = "y",
[$"{typeof(Vector2).FullName}.{nameof(Vector2.Zero)}"] = "(float2)0",
@@ -166,5 +173,17 @@ namespace ComputeSharp.SourceGenerators.Mappings
{
return KnownMembers.TryGetValue(name, out mapped);
}
+
+ ///
+ /// Tries to get the mapped HLSL-compatible indexer vector type name for the input indexer name.
+ ///
+ /// The input fully qualified indexer name.
+ /// The mapped type name, if one is found.
+ /// The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.
+ [Pure]
+ public static bool TryGetMappedIndexerTypeName(string name, out string? mapped)
+ {
+ return KnownIndexers.TryGetValue(name, out mapped);
+ }
}
}
diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs
index 5b3b9299..b4332b8e 100644
--- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs
+++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs
@@ -41,20 +41,21 @@ namespace ComputeSharp.SourceGenerators.Mappings
[typeof(Double2).FullName] = "double2",
[typeof(Double3).FullName] = "double3",
[typeof(Double4).FullName] = "double4",
- [typeof(ThreadIds).FullName] = "uint3"
+ [typeof(ThreadIds).FullName] = "int3"
};
///
/// Gets the known HLSL vector types available as mapped types.
///
- public static IReadOnlyCollection HlslMappedVectorTypes { get; } = new HashSet(new[]
+ 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),
typeof(Float2), typeof(Float3), typeof(Float4),
typeof(Double2), typeof(Double3), typeof(Double4)
- });
+ };
///
/// Checks whether or not a given type name matches a typed resource type.
@@ -63,11 +64,18 @@ namespace ComputeSharp.SourceGenerators.Mappings
/// Whether or not represents a typed resource type.
public static bool IsTypedResourceType(string typeName)
{
- return
- typeName == "ComputeSharp.ReadOnlyBuffer`1" ||
- typeName == "ComputeSharp.ReadWriteBuffer`1" ||
- typeName == "ComputeSharp.ReadOnlyTexture2D`1" ||
- typeName == "ComputeSharp.ReadWriteTexture2D`1";
+ switch (typeName)
+ {
+ case "ComputeSharp.ConstantBuffer`1":
+ case "ComputeSharp.ReadOnlyBuffer`1":
+ case "ComputeSharp.ReadWriteBuffer`1":
+ case "ComputeSharp.ReadOnlyTexture2D`1":
+ case "ComputeSharp.ReadWriteTexture2D`1":
+ case "ComputeSharp.ReadOnlyTexture3D`1":
+ case "ComputeSharp.ReadWriteTexture3D`1":
+ return true;
+ default: return false;
+ };
}
///
@@ -98,10 +106,13 @@ namespace ComputeSharp.SourceGenerators.Mappings
// Construct the HLSL type name
return typeName switch
{
+ "ComputeSharp.ConstantBuffer`1" => mapped,
"ComputeSharp.ReadOnlyBuffer`1" => $"StructuredBuffer<{mapped}>",
"ComputeSharp.ReadWriteBuffer`1" => $"RWStructuredBuffer<{mapped}>",
"ComputeSharp.ReadOnlyTexture2D`1" => $"Texture2D<{mapped}>",
"ComputeSharp.ReadWriteTexture2D`1" => $"RWTexture2D<{mapped}>",
+ "ComputeSharp.ReadOnlyTexture3D`1" => $"Texture3D<{mapped}>",
+ "ComputeSharp.ReadWriteTexture3D`1" => $"RWTexture3D<{mapped}>",
_ => throw new ArgumentException()
};
}
diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
index d6f2a027..0c274f7a 100644
--- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
+++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
@@ -158,7 +158,7 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
{
var updatedNode = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!;
- updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, this.semanticModel, this.discoveredTypes);
+ updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node, this.semanticModel, this.discoveredTypes);
// New objects use the default HLSL cast syntax, eg. (float4)0
if (updatedNode.ArgumentList!.Arguments.Count == 0)
@@ -342,6 +342,22 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
return updatedNode;
}
+ ///
+ public override SyntaxNode? VisitElementAccessExpression(ElementAccessExpressionSyntax node)
+ {
+ var updatedNode = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!;
+
+ if (this.semanticModel.GetOperation(node) is IPropertyReferenceOperation operation &&
+ HlslKnownMembers.TryGetMappedIndexerTypeName(operation.Property.GetFullMetadataName(), out string? mapping))
+ {
+ var index = InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments));
+
+ return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
+ }
+
+ return updatedNode;
+ }
+
///
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
{
diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj
index e2f82a06..a4aa8e9e 100644
--- a/src/ComputeSharp/ComputeSharp.csproj
+++ b/src/ComputeSharp/ComputeSharp.csproj
@@ -4,6 +4,7 @@
net5.0-windows10.0.19041.0
preview
enable
+ true
diff --git a/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs b/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs
new file mode 100644
index 00000000..95ddd2f5
--- /dev/null
+++ b/src/ComputeSharp/Extensions/Buffers/BufferExtensions.cs
@@ -0,0 +1,156 @@
+using System;
+using System.Diagnostics.Contracts;
+using System.Runtime.InteropServices;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using Microsoft.Toolkit.Diagnostics;
+
+namespace ComputeSharp
+{
+ ///
+ /// A that contains extension methods for the type.
+ ///
+ public static class BufferExtensions
+ {
+ ///
+ /// Reads the contents of a instance and returns an array.
+ ///
+ /// The type of items stored on the buffer.
+ /// The input instance to read data from.
+ /// A array with the contents of the input buffer.
+ [Pure]
+ public static T[] GetData(this Buffer buffer)
+ where T : unmanaged
+ {
+ return buffer.GetData(0, buffer.Length);
+ }
+
+ ///
+ /// Reads the contents of a instance in a given range and returns an array.
+ ///
+ /// The type of items stored on the buffer.
+ /// The input instance to read data from.
+ /// The offset to start reading data from.
+ /// The number of items to read.
+ /// A array with the contents of the specified range from the current buffer.
+ [Pure]
+ public static T[] GetData(this Buffer buffer, int offset, int count)
+ where T : unmanaged
+ {
+ Guard.IsGreaterThanOrEqualTo(count, 0, nameof(count));
+
+ T[] data = GC.AllocateUninitializedArray(count);
+
+ buffer.GetData(data.AsSpan(), offset);
+
+ return data;
+ }
+
+ ///
+ /// Reads the contents of s instance and writes them into a target array.
+ ///
+ /// The type of items stored on the buffer.
+ /// The input instance to read data from.
+ /// The input array to write data to.
+ public static void GetData(this Buffer buffer, T[] destination)
+ where T : unmanaged
+ {
+ buffer.GetData(destination.AsSpan(), 0);
+ }
+
+ ///
+ /// Reads the contents of the specified range from s instance and writes them into a target array.
+ ///
+ /// 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 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)
+ where T : unmanaged
+ {
+ Span span = destination.AsSpan(destinationOffset, count);
+
+ buffer.GetData(span, bufferOffset);
+ }
+
+ ///
+ /// Reads the contents of a instance and writes them into a target .
+ ///
+ /// The type of items stored on the buffer.
+ /// The input instance to read data from.
+ /// The input to write data to.
+ public static void GetData(this Buffer buffer, Span destination)
+ where T : unmanaged
+ {
+ buffer.GetData(destination, 0);
+ }
+
+ ///
+ /// Reads the contents of the specified range from a instance and writes them into a target .
+ ///
+ /// The type of items stored on the buffer.
+ /// The input instance to read data from.
+ /// The input to write data to.
+ /// The offset to start reading data from.
+ public static void GetData(this Buffer buffer, Span destination, int offset)
+ where T : unmanaged
+ {
+ buffer.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, offset);
+ }
+
+ ///
+ /// Writes the contents of a given array to a instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ public static void SetData(this Buffer buffer, T[] source)
+ where T : unmanaged
+ {
+ buffer.SetData(source.AsSpan(), 0);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of a instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The starting offset within to read data from.
+ /// The offset to start writing data to.
+ /// The number of items to write.
+ public static void SetData(this Buffer buffer, T[] source, int sourceOffset, int bufferOffset, int count)
+ where T : unmanaged
+ {
+ ReadOnlySpan span = source.AsSpan(sourceOffset, count);
+
+ buffer.SetData(span, bufferOffset);
+ }
+
+ ///
+ /// Writes the contents of a given to a instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ public static void SetData(this Buffer buffer, ReadOnlySpan source)
+ where T : unmanaged
+ {
+ buffer.SetData(source, 0);
+ }
+
+ ///
+ /// Writes the contents of a given to a specified area of a instance.
+ ///
+ /// The type of items stored on the buffer.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ /// The offset to start writing data to.
+ public static void SetData(this Buffer buffer, ReadOnlySpan source, int offset)
+ where T : unmanaged
+ {
+ buffer.SetData(ref MemoryMarshal.GetReference(source), source.Length, offset);
+ }
+ }
+}
diff --git a/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs b/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs
new file mode 100644
index 00000000..4c1b03e2
--- /dev/null
+++ b/src/ComputeSharp/Extensions/Buffers/Texture2DExtensions.cs
@@ -0,0 +1,314 @@
+using System;
+using System.Diagnostics.Contracts;
+using System.Runtime.InteropServices;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using Microsoft.Toolkit.Diagnostics;
+
+namespace ComputeSharp
+{
+ ///
+ /// A that contains extension methods for the type.
+ ///
+ public static class Texture2DExtensions
+ {
+ ///
+ /// Reads the contents of the current instance and returns an array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// A array with the contents of the current texture.
+ [Pure]
+ public static T[,] GetData(this Texture2D texture)
+ where T : unmanaged
+ {
+ T[,] data = new T[texture.Height, texture.Width];
+
+ texture.GetData(data);
+
+ return data;
+ }
+
+ ///
+ /// Reads the contents of the current instance and writes them into a target array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input array to write data to.
+ public static void GetData(this Texture2D texture, T[,] destination)
+ where T : unmanaged
+ {
+ Guard.IsEqualTo(destination.GetLength(0), texture.Height, nameof(destination));
+ Guard.IsEqualTo(destination.GetLength(1), texture.Width, nameof(destination));
+
+ texture.GetData(ref destination[0, 0], destination.Length, 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input array to write data to.
+ public static void GetData(this Texture2D texture, T[] destination)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(), 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input array 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, Range x, Range y)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(), x, y);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input array 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.
+ /// The height of the memory area to copy.
+ public static void GetData(this Texture2D texture, T[] destination, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(), x, y, width, height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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.
+ public static void GetData(this Texture2D texture, T[] destination, int offset)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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 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)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), x, y);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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 horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ public static void GetData(this Texture2D texture, T[] destination, int offset, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), x, y, width, height);
+ }
+
+ ///
+ /// Reads the contents of the current instance and writes them into a target .
+ /// The input data will be read from the start of the texture.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input to write data to.
+ public static void GetData(this Texture2D texture, Span destination)
+ where T : unmanaged
+ {
+ texture.GetData(destination, 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target .
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input 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, Span destination, Range x, Range y)
+ where T : unmanaged
+ {
+ var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
+ var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
+
+ texture.GetData(destination, offsetX, offsetY, width, height);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target .
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input 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.
+ /// The height of the memory area to copy.
+ public static void GetData(this Texture2D texture, Span destination, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height);
+ }
+
+ ///
+ /// Writes the contents of a given array to the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ public static unsafe void SetData(this Texture2D texture, T[,] source)
+ where T : unmanaged
+ {
+ Guard.IsEqualTo(source.GetLength(0), texture.Height, nameof(source));
+ Guard.IsEqualTo(source.GetLength(1), texture.Width, nameof(source));
+
+ texture.SetData(ref source[0, 0], source.Length, 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Writes the contents of a given array to the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ public static void SetData(this Texture2D texture, T[] source)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ public static void SetData(this Texture2D texture, T[] source, Range x, Range y)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), x, y);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to write to.
+ /// The height of the memory area to write to.
+ public static void SetData(this Texture2D texture, T[] source, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), x, y, width, height);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The starting offset within to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ public static void SetData(this Texture2D texture, T[] source, int offset, Range x, Range y)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(offset), x, y);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The starting offset within to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to write to.
+ /// The height of the memory area to write to.
+ public static void SetData(this Texture2D texture, T[] source, int offset, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(offset), x, y, width, height);
+ }
+
+ ///
+ /// Writes the contents of a given to the current instance.
+ /// The input data will be written to the start of the texture, and all input items will be copied.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ public static void SetData(this Texture2D texture, ReadOnlySpan source)
+ where T : unmanaged
+ {
+ texture.SetData(source, 0, 0, texture.Width, texture.Height);
+ }
+
+ ///
+ /// Writes the contents of a given to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ public static void SetData(this Texture2D texture, ReadOnlySpan source, Range x, Range y)
+ where T : unmanaged
+ {
+ var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
+ var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
+
+ texture.SetData(source, offsetX, offsetY, width, height);
+ }
+
+ ///
+ /// Writes the contents of a given to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The width of the memory area to write to.
+ /// The height of the memory area to write to.
+ public static void SetData(this Texture2D texture, ReadOnlySpan source, int x, int y, int width, int height)
+ where T : unmanaged
+ {
+ texture.SetData(ref MemoryMarshal.GetReference(source), source.Length, x, y, width, height);
+ }
+ }
+}
diff --git a/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs b/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs
new file mode 100644
index 00000000..850378a5
--- /dev/null
+++ b/src/ComputeSharp/Extensions/Buffers/Texture3DExtensions.cs
@@ -0,0 +1,303 @@
+using System;
+using System.Diagnostics.Contracts;
+using System.Runtime.InteropServices;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using Microsoft.Toolkit.Diagnostics;
+
+namespace ComputeSharp
+{
+ ///
+ /// A that contains extension methods for the type.
+ ///
+ public static class Texture3DExtensions
+ {
+ ///
+ /// Reads the contents of the current instance and returns an array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// A array with the contents of the current buffer.
+ ///
+ /// The returned array will be using the same memory layout as the texture, that is, each 2D plane
+ /// in the 3D volume represented by the texture is contiguous in memory, and planes are stacked in
+ /// the depth dimension. This means that the resulting 3D array will have a size of [D, H, W].
+ ///
+ [Pure]
+ public static T[,,] GetData(this Texture3D texture)
+ where T : unmanaged
+ {
+ T[,,] data = new T[texture.Depth, texture.Height, texture.Width];
+
+ texture.GetData(data);
+
+ return data;
+ }
+
+ ///
+ /// Reads the contents of the current instance and writes them into a target array.
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// 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 [, , ].
+ ///
+ public static void GetData(this Texture3D texture, T[,,] destination)
+ where T : unmanaged
+ {
+ Guard.IsEqualTo(destination.GetLength(0), texture.Depth, nameof(destination));
+ Guard.IsEqualTo(destination.GetLength(1), texture.Height, nameof(destination));
+ Guard.IsEqualTo(destination.GetLength(2), texture.Width, nameof(destination));
+
+ texture.GetData(ref destination[0, 0, 0], destination.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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.
+ public static void GetData(this Texture3D texture, T[] destination, int offset)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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 horizontal range of items to copy.
+ /// The vertical range of items to copy.
+ /// The depthwise range of items to copy.
+ public static void GetData(this Texture3D texture, T[] destination, int offset, Range x, Range y, Range z)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), x, y, z);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target array.
+ ///
+ /// 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 horizontal offset in the source texture.
+ /// The vertical offset in the source texture.
+ /// The depthwise offset in the source texture.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ public static void GetData(this Texture3D texture, T[] destination, int offset, int x, int y, int z, int width, int height, int depth)
+ where T : unmanaged
+ {
+ texture.GetData(destination.AsSpan(offset), x, y, z, width, height, depth);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target .
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input to write data to.
+ public static void GetData(this Texture3D texture, Span destination)
+ where T : unmanaged
+ {
+ texture.GetData(destination, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target .
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input to write data to.
+ /// The horizontal range in the source texture.
+ /// The vertical range in the source texture.
+ /// The depthwise range in the source texture.
+ public static void GetData(this Texture3D texture, Span destination, Range x, Range y, Range z)
+ where T : unmanaged
+ {
+ var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
+ var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
+ var (offsetZ, depth) = z.GetOffsetAndLength(texture.Depth);
+
+ texture.GetData(destination, offsetX, offsetY, offsetZ, width, height, depth);
+ }
+
+ ///
+ /// Reads the contents of the specified range from the current instance and writes them into a target .
+ ///
+ /// The type of items stored on the texture.
+ /// The input instance to read data from.
+ /// The input 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.
+ /// The width of the memory area to copy.
+ /// The height of the memory area to copy.
+ /// The depth of the memory area to copy.
+ public static void GetData(this Texture3D texture, Span destination, int x, int y, int z, int width, int height, int depth)
+ where T : unmanaged
+ {
+ texture.GetData(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth);
+ }
+
+ ///
+ /// Writes the contents of a given array to the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// 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 [, , ].
+ ///
+ public static void SetData(this Texture3D texture, T[,,] source)
+ where T : unmanaged
+ {
+ Guard.IsEqualTo(source.GetLength(0), texture.Depth, nameof(source));
+ Guard.IsEqualTo(source.GetLength(1), texture.Height, nameof(source));
+ Guard.IsEqualTo(source.GetLength(2), texture.Width, nameof(source));
+
+ texture.SetData(ref source[0, 0, 0], source.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Writes the contents of a given array to the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ public static void SetData(this Texture3D texture, T[] source)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ /// The depthwise range of items to write.
+ public static void SetData(this Texture3D texture, T[] source, Range x, Range y, Range z)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), x, y, z);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data 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 write to.
+ /// The height of the memory area to write to.
+ /// The depth of the memory area to write to.
+ public static void SetData(this Texture3D texture, T[] source, int x, int y, int z, int width, int height, int depth)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(), x, y, z, width, height, depth);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The starting offset within to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ /// The depthwise range of items to write.
+ public static void SetData(this Texture3D texture, T[] source, int offset, Range x, Range y, Range z)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(offset), x, y, z);
+ }
+
+ ///
+ /// Writes the contents of a given array to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input array to read data from.
+ /// The starting offset within to read data 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 write to.
+ /// The height of the memory area to write to.
+ /// The depth of the memory area to write to.
+ public static void SetData(this Texture3D texture, T[] source, int offset, int x, int y, int z, int width, int height, int depth)
+ where T : unmanaged
+ {
+ texture.SetData(source.AsSpan(offset), x, y, z, width, height, depth);
+ }
+
+ ///
+ /// Writes the contents of a given to the current instance.
+ /// The input data will be written to the start of the texture, and all input items will be copied.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ public static void SetData(this Texture3D texture, ReadOnlySpan source)
+ where T : unmanaged
+ {
+ texture.SetData(source, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
+ }
+
+ ///
+ /// Writes the contents of a given to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ /// The horizontal range of items to write.
+ /// The vertical range of items to write.
+ /// The depthwise range of items to write.
+ public static void SetData(this Texture3D texture, ReadOnlySpan source, Range x, Range y, Range z)
+ where T : unmanaged
+ {
+ var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
+ var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
+ var (offsetZ, depth) = z.GetOffsetAndLength(texture.Depth);
+
+ texture.SetData(source, offsetX, offsetY, offsetZ, width, height, depth);
+ }
+
+ ///
+ /// Writes the contents of a given to a specified area of the current instance.
+ ///
+ /// The type of items stored on the texture.
+ /// The target instance to write data to.
+ /// The input to read data from.
+ /// The horizontal offset in the destination texture.
+ /// The vertical offset in the destination texture.
+ /// The depthwise offseet in the destination texture.
+ /// The width of the memory area to write to.
+ /// The height of the memory area to write to.
+ /// The depth of the memory area to write to.
+ public static void SetData(this Texture3D texture, ReadOnlySpan source, int x, int y, int z, int width, int height, int depth)
+ where T : unmanaged
+ {
+ texture.SetData(ref MemoryMarshal.GetReference(source), source.Length, x, y, z, width, height, depth);
+ }
+ }
+}
diff --git a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
index 303397c2..e22ed529 100644
--- a/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
+++ b/src/ComputeSharp/Extensions/GraphicsDeviceExtensions.cs
@@ -139,70 +139,6 @@ namespace ComputeSharp
return readWriteBuffer;
}
- ///
- /// Allocates a new read write buffer with the specified parameters.
- ///
- /// The type of items to store in the buffer.
- /// The instance to use to allocate the buffer.
- /// The length of the buffer to allocate.
- /// A zeroed instance of size .
- [Pure]
- public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, int length)
- where T : unmanaged
- {
- return new(device, length);
- }
-
- ///
- /// Allocates a new read write buffer with the specified parameters.
- ///
- /// The type of items to store in the buffer.
- /// The instance to use to allocate the buffer.
- /// The input array with the data to copy on the allocated buffer.
- /// A read write instance with the contents of the input array.
- [Pure]
- public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[] array)
- where T : unmanaged
- {
- return device.AllocateReadWriteBuffer(array.AsSpan());
- }
-
- ///
- /// Allocates a new read write buffer with the specified parameters.
- ///
- /// The type of items to store in the buffer.
- /// The instance to use to allocate the buffer.
- /// The input with the data to copy on the allocated buffer.
- /// A read write instance with the contents of the input .
- [Pure]
- public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, ReadOnlySpan span)
- where T : unmanaged
- {
- ReadWriteBuffer buffer = new(device, span.Length);
-
- buffer.SetData(span);
-
- return buffer;
- }
-
- ///
- /// Allocates a new read write buffer with the specified parameters.
- ///
- /// The type of items to store in the buffer.
- /// The instance to use to allocate the buffer.
- /// The input with the data to copy on the allocated buffer.
- /// A read write instance with the contents of the input .
- [Pure]
- public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, Buffer buffer)
- where T : unmanaged
- {
- ReadWriteBuffer readWriteBuffer = new(device, buffer.Length);
-
- readWriteBuffer.SetData(buffer);
-
- return readWriteBuffer;
- }
-
///
/// Allocates a new readonly 2D texture with the specified parameters.
///
@@ -289,6 +225,164 @@ namespace ComputeSharp
return texture;
}
+ ///
+ /// Allocates a new readonly 3D texture with the specified parameters.
+ ///
+ /// The type of items to store in the texture.
+ /// The instance to use to allocate the texture.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A zeroed instance of size [, , ].
+ [Pure]
+ public static ReadOnlyTexture3D AllocateReadOnlyTexture3D(this GraphicsDevice device, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return new(device, width, height, depth);
+ }
+
+ ///
+ /// Allocates a new readonly 3D texture with the specified parameters.
+ ///
+ /// 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 width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input array.
+ [Pure]
+ public static ReadOnlyTexture3D AllocateReadOnlyTexture3D(this GraphicsDevice device, T[] array, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return device.AllocateReadOnlyTexture3D(array.AsSpan(), width, height, depth);
+ }
+
+ ///
+ /// Allocates a new readonly 3D texture with the specified parameters.
+ ///
+ /// 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 width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input array.
+ [Pure]
+ public static ReadOnlyTexture3D AllocateReadOnlyTexture3D(this GraphicsDevice device, T[] array, int offset, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return device.AllocateReadOnlyTexture3D(array.AsSpan(offset), width, height, depth);
+ }
+
+ ///
+ /// Allocates a new readonly 3D texture with the specified parameters.
+ ///
+ /// 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.
+ /// A read write instance with the contents of the input array.
+ ///
+ /// 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 [depth, height, width].
+ ///
+ [Pure]
+ public static ReadOnlyTexture3D AllocateReadOnlyTexture3D(this GraphicsDevice device, T[,,] array)
+ where T : unmanaged
+ {
+ ReadOnlyTexture3D texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
+
+ texture.SetData(array);
+
+ return texture;
+ }
+
+ ///
+ /// Allocates a new readonly 3D texture with the specified parameters.
+ ///
+ /// The type of items to store in the texture.
+ /// The instance to use to allocate the texture.
+ /// The input with the data to copy on the allocated texture.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input .
+ [Pure]
+ public static ReadOnlyTexture3D AllocateReadOnlyTexture3D(this GraphicsDevice device, ReadOnlySpan span, int width, int height, int depth)
+ where T : unmanaged
+ {
+ ReadOnlyTexture3D texture = new(device, width, height, depth);
+
+ texture.SetData(span);
+
+ return texture;
+ }
+
+ ///
+ /// Allocates a new read write buffer with the specified parameters.
+ ///
+ /// The type of items to store in the buffer.
+ /// The instance to use to allocate the buffer.
+ /// The length of the buffer to allocate.
+ /// A zeroed instance of size .
+ [Pure]
+ public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, int length)
+ where T : unmanaged
+ {
+ return new(device, length);
+ }
+
+ ///
+ /// Allocates a new read write buffer with the specified parameters.
+ ///
+ /// The type of items to store in the buffer.
+ /// The instance to use to allocate the buffer.
+ /// The input array with the data to copy on the allocated buffer.
+ /// A read write instance with the contents of the input array.
+ [Pure]
+ public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, T[] array)
+ where T : unmanaged
+ {
+ return device.AllocateReadWriteBuffer(array.AsSpan());
+ }
+
+ ///
+ /// Allocates a new read write buffer with the specified parameters.
+ ///
+ /// The type of items to store in the buffer.
+ /// The instance to use to allocate the buffer.
+ /// The input with the data to copy on the allocated buffer.
+ /// A read write instance with the contents of the input .
+ [Pure]
+ public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, ReadOnlySpan span)
+ where T : unmanaged
+ {
+ ReadWriteBuffer buffer = new(device, span.Length);
+
+ buffer.SetData(span);
+
+ return buffer;
+ }
+
+ ///
+ /// Allocates a new read write buffer with the specified parameters.
+ ///
+ /// The type of items to store in the buffer.
+ /// The instance to use to allocate the buffer.
+ /// The input with the data to copy on the allocated buffer.
+ /// A read write instance with the contents of the input .
+ [Pure]
+ public static ReadWriteBuffer AllocateReadWriteBuffer(this GraphicsDevice device, Buffer buffer)
+ where T : unmanaged
+ {
+ ReadWriteBuffer readWriteBuffer = new(device, buffer.Length);
+
+ readWriteBuffer.SetData(buffer);
+
+ return readWriteBuffer;
+ }
+
///
/// Allocates a new writeable 2D texture with the specified parameters.
///
@@ -375,6 +469,100 @@ namespace ComputeSharp
return texture;
}
+ ///
+ /// Allocates a new writeable 3D texture with the specified parameters.
+ ///
+ /// The type of items to store in the texture.
+ /// The instance to use to allocate the texture.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A zeroed instance of size [, ].
+ [Pure]
+ public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return new(device, width, height, depth);
+ }
+
+ ///
+ /// Allocates a new writeable 3D texture with the specified parameters.
+ ///
+ /// 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 width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input array.
+ [Pure]
+ public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, T[] array, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return device.AllocateReadWriteTexture3D(array.AsSpan(), width, height, depth);
+ }
+
+ ///
+ /// Allocates a new writeable 3D texture with the specified parameters.
+ ///
+ /// 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 width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input array.
+ [Pure]
+ public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, T[] array, int offset, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return device.AllocateReadWriteTexture3D(array.AsSpan(offset), width, height, depth);
+ }
+
+ ///
+ /// Allocates a new writeable 3D texture with the specified parameters.
+ ///
+ /// 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.
+ /// A read write instance with the contents of the input array.
+ ///
+ /// 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 [depth, height, width].
+ ///
+ [Pure]
+ public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, T[,,] array)
+ where T : unmanaged
+ {
+ ReadWriteTexture3D texture = new(device, array.GetLength(2), array.GetLength(1), array.GetLength(0));
+
+ texture.SetData(array);
+
+ return texture;
+ }
+
+ ///
+ /// Allocates a new writeable 3D texture with the specified parameters.
+ ///
+ /// The type of items to store in the texture.
+ /// The instance to use to allocate the texture.
+ /// The input with the data to copy on the allocated texture.
+ /// The width of the texture.
+ /// The height of the texture.
+ /// The depth of the texture.
+ /// A instance with the contents of the input .
+ [Pure]
+ public static ReadWriteTexture3D AllocateReadWriteTexture3D(this GraphicsDevice device, ReadOnlySpan span, int width, int height, int depth)
+ where T : unmanaged
+ {
+ ReadWriteTexture3D texture = new(device, width, height, depth);
+
+ texture.SetData(span);
+
+ return texture;
+ }
+
///
/// Compiles and runs the input shader on a target instance, with the specified parameters.
///
diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs
index 7810777e..6731b5fa 100644
--- a/tests/ComputeSharp.Tests/BufferTests.cs
+++ b/tests/ComputeSharp.Tests/BufferTests.cs
@@ -7,14 +7,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests
{
[TestClass]
- [TestCategory("Buffers")]
- public class BufferTests
+ [TestCategory("Buffer")]
+ public partial class BufferTests
{
[TestMethod]
[DataRow(typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>))]
- public void AllocateBuffer_Uninitialized(Type bufferType)
+ public void Allocate_Uninitialized_Ok(Type bufferType)
{
using Buffer buffer = Gpu.Default.AllocateBuffer(bufferType, 128);
@@ -23,11 +23,24 @@ namespace ComputeSharp.Tests
Assert.AreSame(buffer.GraphicsDevice, Gpu.Default);
}
+ [TestMethod]
+ [DataRow(typeof(ConstantBuffer<>), -247824)]
+ [DataRow(typeof(ConstantBuffer<>), -1)]
+ [DataRow(typeof(ConstantBuffer<>), -247824)]
+ [DataRow(typeof(ConstantBuffer<>), -1)]
+ [DataRow(typeof(ConstantBuffer<>), -247824)]
+ [DataRow(typeof(ConstantBuffer<>), -1)]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void Allocate_Uninitialized_Fail(Type bufferType, int length)
+ {
+ using Buffer buffer = Gpu.Default.AllocateBuffer(bufferType, length);
+ }
+
[TestMethod]
[DataRow(typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>))]
- public void AllocateBuffer_FromArray(Type bufferType)
+ public void Allocate_FromArray(Type bufferType)
{
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
@@ -54,7 +67,7 @@ namespace ComputeSharp.Tests
[DataRow(typeof(ReadWriteBuffer<>), typeof(ConstantBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadOnlyBuffer<>))]
[DataRow(typeof(ReadWriteBuffer<>), typeof(ReadWriteBuffer<>))]
- public void AllocateBuffer_FromBuffer(Type sourceType, Type destinationType)
+ public void Allocate_FromBuffer(Type sourceType, Type destinationType)
{
float[] data = Enumerable.Range(0, 128).Select(static i => (float)i).ToArray();
@@ -188,5 +201,86 @@ namespace ComputeSharp.Tests
buffer.GetData(result, destinationOffset, bufferOffset, count);
}
+
+ [TestMethod]
+ public void Dispatch_ConstantBuffer()
+ {
+ int[] data = Enumerable.Range(0, 1024).ToArray();
+
+ using ConstantBuffer source = Gpu.Default.AllocateConstantBuffer(data);
+ using ReadWriteBuffer destination = Gpu.Default.AllocateReadWriteBuffer(data.Length);
+
+ Gpu.Default.For(source.Length, new ConstantBufferKernel(source, destination));
+
+ int[] result = destination.GetData();
+
+ CollectionAssert.AreEqual(data, result);
+ }
+
+ [AutoConstructor]
+ private readonly partial struct ConstantBufferKernel : IComputeShader
+ {
+ public readonly ConstantBuffer source;
+ public readonly ReadWriteBuffer destination;
+
+ public void Execute(ThreadIds ids)
+ {
+ destination[ids.X] = source[ids.X];
+ }
+ }
+
+ [TestMethod]
+ public void Dispatch_ReadOnlyBuffer()
+ {
+ int[] data = Enumerable.Range(0, 1024).ToArray();
+
+ using ReadOnlyBuffer source = Gpu.Default.AllocateReadOnlyBuffer(data);
+ using ReadWriteBuffer destination = Gpu.Default.AllocateReadWriteBuffer(data.Length);
+
+ Gpu.Default.For(source.Length, new ReadOnlyBufferKernel(source, destination));
+
+ int[] result = destination.GetData();
+
+ CollectionAssert.AreEqual(data, result);
+ }
+
+ [AutoConstructor]
+ private readonly partial struct ReadOnlyBufferKernel : IComputeShader
+ {
+ public readonly ReadOnlyBuffer source;
+ public readonly ReadWriteBuffer destination;
+
+ public void Execute(ThreadIds ids)
+ {
+ destination[ids.X] = source[ids.X];
+ }
+ }
+
+ [TestMethod]
+ public void Dispatch_ReadWriteBuffer()
+ {
+ int[] data = Enumerable.Range(0, 1024).ToArray();
+
+ using ReadWriteBuffer source = Gpu.Default.AllocateReadWriteBuffer(data);
+ using ReadWriteBuffer destination = Gpu.Default.AllocateReadWriteBuffer(data.Length);
+
+ Gpu.Default.For(source.Length, new ReadWriteBufferKernel(source, destination));
+
+ int[] result = destination.GetData();
+
+ CollectionAssert.AreEqual(data, result);
+ }
+
+ [AutoConstructor]
+ private readonly partial struct ReadWriteBufferKernel : IComputeShader
+ {
+ public readonly ReadWriteBuffer source;
+ public readonly ReadWriteBuffer destination;
+
+ public void Execute(ThreadIds ids)
+ {
+ destination[ids.X] = source[ids.X];
+ }
+ }
}
}
diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
index 385ffb57..9e45c3d9 100644
--- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
+++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
@@ -7,6 +7,7 @@
+
diff --git a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs
index 48aa0554..ff9ba47e 100644
--- a/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs
+++ b/tests/ComputeSharp.Tests/Extensions/GraphicsDeviceExtensions.cs
@@ -31,6 +31,49 @@ namespace ComputeSharp.Tests.Extensions
};
}
+ ///
+ /// Allocates a new instance of the specified type.
+ ///
+ /// The type of items in the texture.
+ /// The target instance to allocate the texture for.
+ /// The type of texture to allocate.
+ /// The width of the texture to create.
+ /// The height of the texture to create.
+ /// A instance of the requested size.
+ [Pure]
+ public static Texture2D AllocateTexture2D(this GraphicsDevice device, Type type, int width, int height)
+ where T : unmanaged
+ {
+ return type switch
+ {
+ _ when type == typeof(ReadOnlyTexture2D<>) => device.AllocateReadOnlyTexture2D(width, height),
+ _ when type == typeof(ReadWriteTexture2D<>) => device.AllocateReadWriteTexture2D(width, height),
+ _ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
+ };
+ }
+
+ ///
+ /// Allocates a new instance of the specified type.
+ ///
+ /// The type of items in the texture.
+ /// The target instance to allocate the texture for.
+ /// The type of texture to allocate.
+ /// The width of the texture to create.
+ /// The height of the texture to create.
+ /// The depth of the texture to create.
+ /// A instance of the requested size.
+ [Pure]
+ public static Texture3D AllocateTexture3D(this GraphicsDevice device, Type type, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return type switch
+ {
+ _ when type == typeof(ReadOnlyTexture3D<>) => device.AllocateReadOnlyTexture3D(width, height, depth),
+ _ when type == typeof(ReadWriteTexture3D<>) => device.AllocateReadWriteTexture3D(width, height, depth),
+ _ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
+ };
+ }
+
///
/// Allocates a new instance of the specified type.
///
@@ -52,6 +95,70 @@ namespace ComputeSharp.Tests.Extensions
};
}
+ ///
+ /// Allocates a new instance of the specified type.
+ ///
+ /// The type of items in the texture.
+ /// The target instance to allocate the texture for.
+ /// The type of buffer to allocate.
+ /// The data to load on the texture.
+ /// The width of the texture to create.
+ /// The height of the texture to create.
+ /// A instance of the requested type.
+ [Pure]
+ public static Texture2D AllocateTexture2D(this GraphicsDevice device, Type type, T[] data, int width, int height)
+ where T : unmanaged
+ {
+ return type switch
+ {
+ _ when type == typeof(ReadOnlyTexture2D<>) => device.AllocateReadOnlyTexture2D(data, width, height),
+ _ when type == typeof(ReadWriteTexture2D<>) => device.AllocateReadWriteTexture2D(data, width, height),
+ _ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
+ };
+ }
+
+ ///
+ /// Allocates a new instance of the specified type.
+ ///
+ /// The type of items in the texture.
+ /// The target instance to allocate the texture for.
+ /// The type of buffer to allocate.
+ /// The data to load on the texture.
+ /// The width of the texture to create.
+ /// The height of the texture to create.
+ /// The depth of the texture to create.
+ /// A instance of the requested type.
+ [Pure]
+ public static Texture3D AllocateTexture3D(this GraphicsDevice device, Type type, T[] data, int width, int height, int depth)
+ where T : unmanaged
+ {
+ return type switch
+ {
+ _ when type == typeof(ReadOnlyTexture3D<>) => device.AllocateReadOnlyTexture3D(data, width, height, depth),
+ _ when type == typeof(ReadWriteTexture3D<>) => device.AllocateReadWriteTexture3D(data, width, height, depth),
+ _ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
+ };
+ }
+
+ ///
+ /// Allocates a new instance of the specified type.
+ ///
+ /// The type of items in the texture.
+ /// The target instance to allocate the texture for.
+ /// The type of texture to allocate.
+ /// A instance of the requested size.
+ [Pure]
+ public static Texture3D AllocateTexture3D(this GraphicsDevice device, Type type, T[,,] data)
+ where T : unmanaged
+ {
+ return type switch
+ {
+ _ when type == typeof(ReadOnlyTexture3D<>) => device.AllocateReadOnlyTexture3D(data),
+ _ when type == typeof(ReadWriteTexture3D<>) => device.AllocateReadWriteTexture3D(data),
+ _ => throw new ArgumentException($"Invalid type: {type}", nameof(type))
+ };
+ }
+
///
/// Allocates a new instance of the specified type.
///
diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs
new file mode 100644
index 00000000..cf23220f
--- /dev/null
+++ b/tests/ComputeSharp.Tests/Texture2DTests.cs
@@ -0,0 +1,197 @@
+using System;
+using System.Linq;
+using ComputeSharp.Graphics.Buffers.Abstract;
+using ComputeSharp.Tests.Extensions;
+using Microsoft.Toolkit.HighPerformance.Memory;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace ComputeSharp.Tests
+{
+ [TestClass]
+ [TestCategory("Texture2D")]
+ public partial class Texture2DTests
+ {
+ [TestMethod]
+ [DataRow(typeof(ReadOnlyTexture2D<>))]
+ [DataRow(typeof(ReadWriteTexture2D<>))]
+ public void Allocate_Uninitialized_Ok(Type textureType)
+ {
+ using Texture2D texture = Gpu.Default.AllocateTexture2D(textureType, 128, 128);
+
+ Assert.IsNotNull(texture);
+ Assert.AreEqual(texture.Width, 128);
+ Assert.AreEqual(texture.Height, 128);
+ Assert.AreSame(texture.GraphicsDevice, Gpu.Default);
+ }
+
+ [TestMethod]
+ [DataRow(typeof(ReadOnlyTexture2D<>), 128, -14253)]
+ [DataRow(typeof(ReadOnlyTexture2D<>), 128, -1)]
+ [DataRow(typeof(ReadOnlyTexture2D<>), 0, -4314)]
+ [DataRow(typeof(ReadOnlyTexture2D<>), -14, -53)]
+ [DataRow(typeof(ReadWriteTexture2D<>), 128, -14253)]
+ [DataRow(typeof(ReadWriteTexture2D<>), 128, -1)]
+ [DataRow(typeof(ReadWriteTexture2D<>), 0, -4314)]
+ [DataRow(typeof(ReadWriteTexture2D<>), -14, -53)]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void Allocate_Uninitialized_Fail(Type textureType, int width, int height)
+ {
+ using Texture2D texture = Gpu.Default.AllocateTexture2D