Make D2D1 resource texture types generic

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-10 22:15:18 +02:00
1 親 00cbf9352d
コミット 3471d6233b
5ファイル変更
+29 -23

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -82,7 +82,7 @@
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1BytecodeLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1BytecodeLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1InputDescriptionsLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1InputDescriptionsLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Intrinsics\D2D.cs" Link="ComputeSharp.D2D1\Intrinsics\D2D.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" Link="ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" />
@@ -6,26 +6,28 @@ namespace ComputeSharp.D2D1;
/// A <see langword="struct"/> representing a <see cref="Float4"/> readonly 1D texture stored on GPU memory.
/// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture (only <see langword="float"/> and <see cref="Float4"/> are supported).</typeparam>
[AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)]
public readonly struct D2D1ResourceTexture1D
public readonly struct D2D1ResourceTexture1D<T>
where T : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D)}.{nameof(Width)}");
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D<T>)}.{nameof(Width)}");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture.
/// </summary>
/// <param name="x">The horizontal offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref readonly Float4 this[int x] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}[{typeof(int)}]");
public ref readonly T this[int x] => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture1D<T>)}[{typeof(int)}]");
/// <summary>
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="u">The horizontal normalized offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}.{nameof(Sample)}({typeof(float)})");
}
@@ -6,20 +6,22 @@ namespace ComputeSharp.D2D1;
/// A <see langword="struct"/> representing a <see cref="Float4"/> readonly 2D texture stored on GPU memory.
/// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture (only <see langword="float"/> and <see cref="Float4"/> are supported).</typeparam>
[AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)]
public readonly struct D2D1ResourceTexture2D
public readonly struct D2D1ResourceTexture2D<T>
where T : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Width)}");
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D<T>)}.{nameof(Width)}");
/// <summary>
/// Gets the height of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D)}.{nameof(Height)}");
public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture2D<T>)}.{nameof(Height)}");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture.
@@ -27,14 +29,14 @@ public readonly struct D2D1ResourceTexture2D
/// <param name="x">The horizontal offset of the value to get.</param>
/// <param name="y">The vertical offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}[{typeof(int)}, {typeof(int)}]");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture.
/// </summary>
/// <param name="xy">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public 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<T>)}[{typeof(Int2)}]");
/// <summary>
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
@@ -42,12 +44,12 @@ public readonly struct D2D1ResourceTexture2D
/// <param name="u">The horizontal normalized offset of the value to get.</param>
/// <param name="v">The vertical normalized offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}.{nameof(Sample)}({typeof(float)}, {typeof(float)})");
/// <summary>
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uv">The normalized coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}.{nameof(Sample)}({typeof(Float2)})");
}
@@ -6,26 +6,28 @@ namespace ComputeSharp.D2D1;
/// A <see langword="struct"/> representing a <see cref="Float4"/> readonly 3D texture stored on GPU memory.
/// This can be used from D2D1 pixel shaders to be able to pass arbitrary inputs to them.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture (only <see langword="float"/> and <see cref="Float4"/> are supported).</typeparam>
[AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)]
public readonly struct D2D1ResourceTexture3D
public readonly struct D2D1ResourceTexture3D<T>
where T : unmanaged
{
/// <summary>
/// Gets the width of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Width)}");
public int Width => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D<T>)}.{nameof(Width)}");
/// <summary>
/// Gets the height of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Height)}");
public int Height => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D<T>)}.{nameof(Height)}");
/// <summary>
/// Gets the depth of the current texture.
/// </summary>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public int Depth => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D)}.{nameof(Depth)}");
public int Depth => throw new InvalidExecutionContextException($"{typeof(D2D1ResourceTexture3D<T>)}.{nameof(Depth)}");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture.
@@ -34,14 +36,14 @@ public readonly struct D2D1ResourceTexture3D
/// <param name="y">The vertical offset of the value to get.</param>
/// <param name="z">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}[{typeof(int)}, {typeof(int)}, {typeof(int)}]");
/// <summary>
/// Gets a single <see cref="Float4"/> value from the current readonly texture.
/// </summary>
/// <param name="xyz">The coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public 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<T>)}[{typeof(Int3)}]");
/// <summary>
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
@@ -50,12 +52,12 @@ public readonly struct D2D1ResourceTexture3D
/// <param name="v">The vertical normalized offset of the value to get.</param>
/// <param name="w">The depthwise offset of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}.{nameof(Sample)}({typeof(float)}, {typeof(float)}, {typeof(float)})");
/// <summary>
/// Retrieves a single <see cref="Float4"/> value from the current readonly texture with linear sampling.
/// </summary>
/// <param name="uvw">The normalized coordinates of the value to get.</param>
/// <remarks>This API can only be used from a compute shader, and will always throw if used anywhere else.</remarks>
public ref 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<T>)}.{nameof(Sample)}({typeof(Float3)})");
}
+3 -3
ファイルの表示
@@ -215,13 +215,13 @@ public partial class D2D1PixelShaderTests
float number;
[D2DResourceTextureIndex(5)]
D2D1ResourceTexture1D myTexture1;
D2D1ResourceTexture1D<float4> myTexture1;
[D2DResourceTextureIndex(6)]
D2D1ResourceTexture2D myTexture2;
D2D1ResourceTexture2D<float4> myTexture2;
[D2DResourceTextureIndex(7)]
D2D1ResourceTexture3D myTexture3;
D2D1ResourceTexture3D<float4> myTexture3;
public Float4 Execute()
{