From 4c2920e659cd4c1e64e2b4dcb07caa94dd22ce1a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Aug 2022 16:03:26 +0200 Subject: [PATCH] Add D2D1TextureResource intrinsic type --- .../Resources/D2D1TextureResource.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Resources/D2D1TextureResource.cs diff --git a/src/ComputeSharp.D2D1/Resources/D2D1TextureResource.cs b/src/ComputeSharp.D2D1/Resources/D2D1TextureResource.cs new file mode 100644 index 00000000..3cb5264e --- /dev/null +++ b/src/ComputeSharp.D2D1/Resources/D2D1TextureResource.cs @@ -0,0 +1,53 @@ +using ComputeSharp.Exceptions; + +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. +/// +[AutoConstructorBehavior(AutoConstructorBehavior.IgnoreAndSetToDefault)] +public readonly struct D2D1TextureResource +{ + /// + /// 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(D2D1TextureResource)}.{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(D2D1TextureResource)}.{nameof(Height)}"); + + /// + /// 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 ref readonly Float4 this[int x, int y] => throw new InvalidExecutionContextException($"{typeof(D2D1TextureResource)}[{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(D2D1TextureResource)}[{typeof(Int2)}]"); + + /// + /// Gets a single value from the current readonly texture with linear sampling. + /// + /// 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 this[float u, float v] => throw new InvalidExecutionContextException($"{typeof(D2D1TextureResource)}[{typeof(float)}, {typeof(float)}]"); + + /// + /// Gets 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 this[Float2 uv] => throw new InvalidExecutionContextException($"{typeof(D2D1TextureResource)}[{typeof(Float2)}]"); +}