diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 37fac13b..ec2e545f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -82,7 +82,7 @@ - + diff --git a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D.cs b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D{T}.cs similarity index 69% rename from src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D.cs rename to src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D{T}.cs index 4796f6f4..725c4b6c 100644 --- a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D.cs +++ b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture1D{T}.cs @@ -6,26 +6,28 @@ namespace ComputeSharp.D2D1; /// A representing a readonly 1D texture stored on GPU memory. /// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them. /// +/// The type of items stored on the texture (only and are supported). [AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)] -public readonly struct D2D1ResourceTexture1D +public readonly struct D2D1ResourceTexture1D + where T : unmanaged { /// /// Gets the width of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D)}.{nameof(Width)}"); + public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D)}.{nameof(Width)}"); /// /// Gets a single value from the current readonly texture. /// /// The horizontal 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 readonly Float4 this[int x] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(int)}]"); + public ref readonly T this[int x] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D)}[{typeof(int)}]"); /// /// Retrieves a single value from the current readonly texture with linear sampling. /// /// The horizontal normalized 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 readonly Float4 Sample(float u) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(float)})"); + public ref readonly T Sample(float u) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D)}.{nameof(Sample)}({typeof(float)})"); } diff --git a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D.cs b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D{T}.cs similarity index 70% rename from src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D.cs rename to src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D{T}.cs index dabb4e5f..902579f3 100644 --- a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D.cs +++ b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture2D{T}.cs @@ -6,20 +6,22 @@ namespace ComputeSharp.D2D1; /// A representing a readonly 2D texture stored on GPU memory. /// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them. /// +/// The type of items stored on the texture (only and are supported). [AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)] -public readonly struct D2D1ResourceTexture2D +public readonly struct D2D1ResourceTexture2D + where T : unmanaged { /// /// Gets the width of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Width)}"); + public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Width)}"); /// /// Gets the height of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Height)}"); + public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Height)}"); /// /// Gets a single value from the current readonly texture. @@ -27,14 +29,14 @@ public readonly struct D2D1ResourceTexture2D /// 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 readonly Float4 this[int x, int y] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(int)}, {typeof(int)}]"); + public ref readonly T this[int x, int y] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(int)}, {typeof(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 ref readonly Float4 this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(Int2)}]"); + public ref readonly T this[Int2 xy] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(Int2)}]"); /// /// Retrieves a single value from the current readonly texture with linear sampling. @@ -42,12 +44,12 @@ public readonly struct D2D1ResourceTexture2D /// The horizontal normalized offset of the value to get. /// The vertical normalized 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 readonly Float4 Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})"); + public ref readonly T Sample(float u, float v) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})"); /// /// Retrieves a single value from the current readonly texture with linear sampling. /// /// The normalized 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 readonly Float4 Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(Float2)})"); + public ref readonly T Sample(Float2 uv) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Sample)}({typeof(Float2)})"); } diff --git a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D.cs b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D{T}.cs similarity index 71% rename from src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D.cs rename to src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D{T}.cs index 9d50238e..dfe6936a 100644 --- a/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D.cs +++ b/src/ComputeSharp.D2D1/Resources/D2D1ResourceTexture3D{T}.cs @@ -6,26 +6,28 @@ namespace ComputeSharp.D2D1; /// A representing a readonly 3D texture stored on GPU memory. /// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them. /// +/// The type of items stored on the texture (only and are supported). [AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)] -public readonly struct D2D1ResourceTexture3D +public readonly struct D2D1ResourceTexture3D + where T : unmanaged { /// /// Gets the width of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Width)}"); + public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Width)}"); /// /// Gets the height of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Height)}"); + public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Height)}"); /// /// Gets the depth of the current texture. /// /// This API can only be used from a compute shader, and will always throw if used anywhere else. - public int Depth => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Depth)}"); + public int Depth => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Depth)}"); /// /// Gets a single value from the current readonly texture. @@ -34,14 +36,14 @@ public readonly struct D2D1ResourceTexture3D /// 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 readonly Float4 this[int x, int y, int z] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(int)}, {typeof(int)}, {typeof(int)}]"); + public ref readonly T this[int x, int y, int z] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(int)}, {typeof(int)}, {typeof(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 ref readonly Float4 this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(Int3)}]"); + public ref readonly T this[Int3 xyz] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}[{typeof(Int3)}]"); /// /// Retrieves a single value from the current readonly texture with linear sampling. @@ -50,12 +52,12 @@ public readonly struct D2D1ResourceTexture3D /// The vertical normalized 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 readonly Float4 Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})"); + public ref readonly T Sample(float u, float v, float w) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})"); /// /// Retrieves a single value from the current readonly texture with linear sampling. /// /// The normalized 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 readonly Float4 Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(Float3)})"); + public ref readonly T Sample(Float3 uvw) => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Sample)}({typeof(Float3)})"); } diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index d89d18e4..c0c06e06 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -215,13 +215,13 @@ public partial class D2D1PixelShaderTests float number; [D2DResourceTextureIndex(5)] - D2D1ResourceTexture1D myTexture1; + D2D1ResourceTexture1D myTexture1; [D2DResourceTextureIndex(6)] - D2D1ResourceTexture2D myTexture2; + D2D1ResourceTexture2D myTexture2; [D2DResourceTextureIndex(7)] - D2D1ResourceTexture3D myTexture3; + D2D1ResourceTexture3D myTexture3; public Float4 Execute() {