Rename D2D1InteropServices to D2D1PixelShader

このコミットが含まれているのは:
Sergio Pedri committed 2022-05-07 03:19:46 +02:00
1 親 9687a74b90
コミット 295cdb1c8d
3ファイル変更
+23 -23

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

@@ -13,7 +13,7 @@ namespace ComputeSharp.D2D1.Interop;
/// <summary>
/// Provides methods to interop with D2D1 APIs and compile shaders or extract their constant buffer data.
/// </summary>
public static unsafe class D2D1InteropServices
public static class D2D1PixelShader
{
/// <summary>
/// Loads the bytecode from an input D2D1 pixel shader.
@@ -27,10 +27,10 @@ public static unsafe class D2D1InteropServices
/// If the shader was compiled at runtime, the returned <see cref="ReadOnlyMemory{T}"/> instance will wrap a <see cref="byte"/> array with the bytecode.
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadPixelShaderBytecode<T>()
public static ReadOnlyMemory<byte> LoadBytecode<T>()
where T : unmanaged, ID2D1PixelShader
{
return LoadOrCompilePixelShaderBytecode<T>(null);
return LoadOrCompileBytecode<T>(null);
}
/// <summary>
@@ -43,10 +43,10 @@ public static unsafe class D2D1InteropServices
/// If the input shader was precompiled, the returned <see cref="ReadOnlyMemory{T}"/> instance will wrap a pinned memory buffer (from the PE section).
/// If the shader was compiled at runtime, the returned <see cref="ReadOnlyMemory{T}"/> instance will wrap a <see cref="byte"/> array with the bytecode.
/// </remarks>
public static ReadOnlyMemory<byte> LoadPixelShaderBytecode<T>(D2D1ShaderProfile shaderProfile)
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1ShaderProfile shaderProfile)
where T : unmanaged, ID2D1PixelShader
{
return LoadOrCompilePixelShaderBytecode<T>(shaderProfile);
return LoadOrCompileBytecode<T>(shaderProfile);
}
/// <summary>
@@ -56,7 +56,7 @@ public static unsafe class D2D1InteropServices
/// <param name="shaderProfile">The shader profile to use to get the shader bytecode.</param>
/// <returns>A <see cref="ReadOnlyMemory{T}"/> instance with the resulting shader bytecode.</returns>
/// <exception cref="InvalidOperationException">Thrown if the input shader has not been precompiled.</exception>
private static ReadOnlyMemory<byte> LoadOrCompilePixelShaderBytecode<T>(D2D1ShaderProfile? shaderProfile)
private static unsafe ReadOnlyMemory<byte> LoadOrCompileBytecode<T>(D2D1ShaderProfile? shaderProfile)
where T : unmanaged, ID2D1PixelShader
{
D2D1ShaderBytecodeLoader bytecodeLoader = default;
@@ -85,7 +85,7 @@ public static unsafe class D2D1InteropServices
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to get the input count for.</typeparam>
/// <returns>The number of inputs for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static uint GetPixelShaderInputCount<T>()
public static uint GetInputCount<T>()
where T : unmanaged, ID2D1PixelShader
{
Unsafe.SkipInit(out T shader);
@@ -100,7 +100,7 @@ public static unsafe class D2D1InteropServices
/// <param name="index">The index of the input to get the type for.</param>
/// <returns>The type of the input of the target D2D1 pixel shader at the specified index.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not in range for the available inputs for the shader type.</exception>
public static D2D1PixelShaderInputType GetPixelShaderInputType<T>(uint index)
public static D2D1PixelShaderInputType GetInputType<T>(uint index)
where T : unmanaged, ID2D1PixelShader
{
Unsafe.SkipInit(out T shader);
@@ -121,8 +121,8 @@ public static unsafe class D2D1InteropServices
/// <returns>A <see cref="ReadOnlyMemory{T}"/> instance with the pixel shader constant buffer.</returns>
/// <remarks>
/// This method will allocate a buffer every time it is invoked.
/// For a zero-allocation alternative, use <see cref="SetPixelShaderConstantBufferForD2D1DrawInfo"/>.</remarks>
public static ReadOnlyMemory<byte> GetPixelShaderConstantBuffer<T>(in T shader)
/// For a zero-allocation alternative, use <see cref="SetConstantBufferForD2D1DrawInfo"/>.</remarks>
public static ReadOnlyMemory<byte> GetConstantBuffer<T>(in T shader)
where T : unmanaged, ID2D1PixelShader
{
D2D1ByteArrayDispatchDataLoader dataLoader = default;
@@ -139,7 +139,7 @@ public static unsafe class D2D1InteropServices
/// <param name="shader">The input D2D1 pixel shader to set the contant buffer for.</param>
/// <param name="d2D1DrawInfo">A pointer to the <c>ID2D1DrawInfo</c> instance to use.</param>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1drawinfo-setpixelshaderconstantbuffer"/>.</remarks>
public static void SetPixelShaderConstantBufferForD2D1DrawInfo<T>(in T shader, void* d2D1DrawInfo)
public static unsafe void SetConstantBufferForD2D1DrawInfo<T>(in T shader, void* d2D1DrawInfo)
where T : unmanaged, ID2D1PixelShader
{
D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);
+2 -2
ファイルの表示
@@ -89,8 +89,8 @@ internal unsafe partial struct PixelShaderEffect
{
// Load all shader properties
Guid guid = typeof(T).GUID;
int inputCount = (int)D2D1InteropServices.GetPixelShaderInputCount<T>();
ReadOnlyMemory<byte> buffer = D2D1InteropServices.LoadPixelShaderBytecode<T>();
int inputCount = (int)D2D1PixelShader.GetInputCount<T>();
ReadOnlyMemory<byte> buffer = D2D1PixelShader.LoadBytecode<T>();
byte* typeAssociatedMemory = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), buffer.Length);
// Copy the bytecode to the target buffer
+10 -10
ファイルの表示
@@ -11,21 +11,21 @@ public partial class D2D1InteropServicesTests
[TestMethod]
public unsafe void GetInputCount()
{
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount<InvertEffect>(), 1u);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount<PixelateEffect.Shader>(), 1u);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount<ZonePlateEffect>(), 0u);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount<ShaderWithMultipleInputs>(), 7u);
Assert.AreEqual(D2D1PixelShader.GetInputCount<InvertEffect>(), 1u);
Assert.AreEqual(D2D1PixelShader.GetInputCount<PixelateEffect.Shader>(), 1u);
Assert.AreEqual(D2D1PixelShader.GetInputCount<ZonePlateEffect>(), 0u);
Assert.AreEqual(D2D1PixelShader.GetInputCount<ShaderWithMultipleInputs>(), 7u);
}
[TestMethod]
public unsafe void GetInputType()
{
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(0), D2D1PixelShaderInputType.Simple);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(1), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(2), D2D1PixelShaderInputType.Simple);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(3), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(4), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType<ShaderWithMultipleInputs>(5), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(0), D2D1PixelShaderInputType.Simple);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(1), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(2), D2D1PixelShaderInputType.Simple);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(3), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(4), D2D1PixelShaderInputType.Complex);
Assert.AreEqual(D2D1PixelShader.GetInputType<ShaderWithMultipleInputs>(5), D2D1PixelShaderInputType.Complex);
}
[D2DInputCount(7)]