Remove metaprogramming support from D2D1Interop

This also allows ID2D1Shader to be much simpler, with just 2 APIs
このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:13 +02:00
1 親 5d1f3927d3
コミット 41be84bfe4
3ファイル変更
+25 -62

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

+2 -17
ファイルの表示
@@ -11,14 +11,6 @@ namespace ComputeSharp.D2D1Interop.__Internals;
[Obsolete("This interface is not intended to be used directly by user code")]
public interface ID2D1Shader
{
/// <summary>
/// Gets a unique dispatch identifier for the shader.
/// </summary>
/// <returns>The unique dispatch identifier for the shader.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
int GetDispatchId();
/// <summary>
/// Loads the dispatch data for the shader.
/// </summary>
@@ -29,21 +21,14 @@ public interface ID2D1Shader
void LoadDispatchData<TLoader>(ref TLoader loader)
where TLoader : struct, ID2D1DispatchDataLoader;
/// <summary>
/// Builds the HLSL source code for the current shader instance.
/// </summary>
/// <param name="builder">The resulting <see cref="ArrayPoolStringBuilder"/> instance containing the HLSL source.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void BuildHlslString(out ArrayPoolStringBuilder builder);
/// <summary>
/// Loads the bytecode for the current shader.
/// </summary>
/// <typeparam name="TLoader">The type of bytecode loader being used.</typeparam>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the bytecode.</param>
/// <param name="hlslSource">The HLSL source that was compiled.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
void LoadBytecode<TLoader>(ref TLoader loader)
void LoadBytecode<TLoader>(ref TLoader loader, out string hlslSource)
where TLoader : struct, ID2D1BytecodeLoader;
}
+1 -21
ファイルの表示
@@ -17,10 +17,6 @@ public static unsafe class D2D1InteropServices
{
/// <summary>
/// Loads the bytecode from an input D2D1 pixel shader.
/// <para>
/// This overload can be used for simplicity when the D2D1 shader does not rely on captured objects to
/// be processed correctly. This is the case when it does not contain any <see cref="Delegate"/>-s.
/// </para>
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to load the bytecode for.</typeparam>
/// <param name="bytecode">A <see cref="ReadOnlyMemory{T}"/> instance with the resulting shader bytecode.</param>
@@ -30,26 +26,10 @@ public static unsafe class D2D1InteropServices
/// </remarks>
public static void LoadShaderBytecode<T>(out ReadOnlyMemory<byte> bytecode)
where T : unmanaged, ID2D1PixelShader
{
LoadShaderBytecode(default(T), out bytecode);
}
/// <summary>
/// Loads the bytecode from an input D2D1 pixel shader.
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to load the bytecode for.</typeparam>
/// <param name="shader">The input D2D1 pixel shader to load the bytecode for.</param>
/// <param name="bytecode">A <see cref="ReadOnlyMemory{T}"/> instance with the resulting shader bytecode.</param>
/// <remarks>
/// If the input shader was precompiled, <paramref name="bytecode"/> will wrap a pinned memory buffer (from the PE section).
/// If the shader was compiled at runtime, <paramref name="bytecode"/> will wrap a <see cref="byte"/> array with the bytecode.
/// </remarks>
public static void LoadShaderBytecode<T>(in T shader, out ReadOnlyMemory<byte> bytecode)
where T : unmanaged, ID2D1PixelShader
{
D2D1ShaderBytecodeLoader bytecodeLoader = default;
Unsafe.AsRef(in shader).LoadBytecode(ref bytecodeLoader);
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, out _);
using ComPtr<ID3DBlob> dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan<byte> precompiledBytecode);
+22 -24
ファイルの表示
@@ -1,9 +1,9 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.__Internals;
using System.Runtime.InteropServices;
using ComputeSharp.Core.Extensions;
using ComputeSharp.D2D1Interop;
using ComputeSharp.D2D1Interop.Shaders.Translation;
using ComputeSharp.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -18,39 +18,37 @@ public static class D2D1ReflectionServices
{
/// <summary>
/// Gets the shader info associated with a given D2D1 shader.
/// <para>
/// This overload can be used for simplicity when the D2D1 shader being inspected does not rely on captured
/// objects to be processed correctly. This is the case when it does not contain any <see cref="Delegate"/>-s.
/// </para>
/// </summary>
/// <typeparam name="T">The type of D2D1 shader to retrieve info for.</typeparam>
/// <returns>The resulting <see cref="D2D1ShaderInfo"/> instance.</returns>
public static D2D1ShaderInfo GetShaderInfo<T>()
public static unsafe D2D1ShaderInfo GetShaderInfo<T>()
where T : struct, ID2D1PixelShader
{
return GetShaderInfo(default(T));
}
D2D1ShaderBytecodeLoader bytecodeLoader = default;
/// <summary>
/// Gets the shader info associated with a given D2D1 shader.
/// </summary>
/// <typeparam name="T">The type of D2D1 shader to retrieve info for.</typeparam>
/// <param name="shader">The input D2D1 shader to retrieve info for.</param>
/// <returns>The resulting <see cref="D2D1ShaderInfo"/> instance.</returns>
public static unsafe D2D1ShaderInfo GetShaderInfo<T>(in T shader)
where T : struct, ID2D1PixelShader
{
Unsafe.AsRef(in shader).BuildHlslString(out ArrayPoolStringBuilder shaderSource);
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, out string hlslSource);
using ComPtr<ID3DBlob> d3DBlobBytecode = D2D1ShaderCompiler.Compile(shaderSource.WrittenSpan, enableLinkingSupport: false);
using ComPtr<ID3DBlob> dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan<byte> precompiledBytecode);
shaderSource.Dispose();
byte* bytecodePtr;
int bytecodeSize;
if (!precompiledBytecode.IsEmpty)
{
bytecodePtr = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(precompiledBytecode));
bytecodeSize = precompiledBytecode.Length;
}
else
{
bytecodePtr = (byte*)dynamicBytecode.Get()->GetBufferPointer();
bytecodeSize = (int)dynamicBytecode.Get()->GetBufferSize();
}
using ComPtr<ID3D11ShaderReflection> d3D11ShaderReflection = default;
DirectX.D3DReflect(
pSrcData: d3DBlobBytecode.Get()->GetBufferPointer(),
SrcDataSize: d3DBlobBytecode.Get()->GetBufferSize(),
pSrcData: bytecodePtr,
SrcDataSize: (nuint)bytecodeSize,
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
ppReflector: d3D11ShaderReflection.GetVoidAddressOf()).Assert();
@@ -60,7 +58,7 @@ public static class D2D1ReflectionServices
return new(
CompilerVersion: new string(d3D11ShaderDescription.Creator),
HlslSource: shaderSource.WrittenSpan.ToString(),
HlslSource: hlslSource,
ConstantBufferCount: d3D11ShaderDescription.ConstantBuffers,
BoundResourceCount: d3D11ShaderDescription.BoundResources,
InstructionCount: d3D11ShaderDescription.InstructionCount,