Implement dynamic D2D1 compilation generation

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:09 +02:00
1 親 f95079ea51
コミット c1e795129e
11ファイル変更
+126 -83

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

+2 -2
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.__Internals;
namespace ComputeSharp.D2D1Interop.__Internals;
/// <summary>
/// A base <see langword="interface"/> representing a bytecode loader for a D2D1 shader.
@@ -14,7 +14,7 @@ public interface ID2D1BytecodeLoader
/// Loads a dynamic shader bytecode.
/// </summary>
/// <param name="handle">An opaque handle to the shader bytecode.</param>
/// <exception cref="InvalidOperationException">Thrown if the shader has already been initialized or a precompiled bytecode was requested when not available..</exception>
/// <exception cref="InvalidOperationException">Thrown if the shader has already been initialized or a precompiled bytecode was requested when not available.</exception>
void LoadDynamicBytecode(IntPtr handle);
/// <summary>
+1 -1
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.__Internals;
namespace ComputeSharp.D2D1Interop.__Internals;
/// <summary>
/// A base <see langword="interface"/> representing a data loader for a D2D1 shader being dispatched.
-1
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using ComputeSharp.__Internals;
namespace ComputeSharp.D2D1Interop.__Internals;
+1 -1
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
using ComputeSharp.D2D1Interop.__Internals;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
+1 -1
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
using ComputeSharp.D2D1Interop.__Internals;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
+2 -2
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
using ComputeSharp.D2D1Interop.__Internals;
using ComputeSharp.D2D1Interop.Extensions;
using ComputeSharp.D2D1Interop.Helpers;
using TerraFX.Interop.DirectX;
@@ -9,7 +9,7 @@ using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.Shaders.Dispatching;
namespace ComputeSharp.D2D1Interop.Shaders.Dispatching;
/// <summary>
/// A bytecode loader for D2D1 shaders.
+6 -5
ファイルの表示
@@ -2,7 +2,6 @@
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1Interop.Shaders.Dispatching;
using ComputeSharp.D2D1Interop.Shaders.Interop.Buffers;
using ComputeSharp.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -20,10 +19,12 @@ public static unsafe class D2D1InteropServices
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to load the bytecode for.</typeparam>
/// <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>
/// <remarks>
/// This method will only run correctly if the input shader has been precompiled, or it will throw an exception.
/// The returned <see cref="ReadOnlyMemory{T}"/> instance will wrap a pinned memory buffer (from the PE section).
/// This method will only compile the shader using <see cref="D2D1ShaderProfile.PixelShader50"/> if no precompiled shader is available.
/// <para>
/// 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.
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadShaderBytecode<T>()
where T : unmanaged, ID2D1PixelShader
@@ -59,7 +60,7 @@ public static unsafe class D2D1InteropServices
{
D2D1ShaderBytecodeLoader bytecodeLoader = default;
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, shaderProfile, out _);
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, shaderProfile ?? D2D1ShaderProfile.PixelShader50);
using ComPtr<ID3DBlob> dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan<byte> precompiledBytecode);
+4 -2
ファイルの表示
@@ -2,7 +2,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1Interop.Extensions;
using ComputeSharp.Shaders.Dispatching;
using ComputeSharp.D2D1Interop.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -23,9 +23,11 @@ public static class D2D1ReflectionServices
public static unsafe D2D1ShaderInfo GetShaderInfo<T>()
where T : struct, ID2D1PixelShader
{
Unsafe.NullRef<T>().BuildHlslSource(out string hlslSource);
D2D1ShaderBytecodeLoader bytecodeLoader = default;
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, D2D1ShaderProfile.PixelShader50, out string hlslSource);
Unsafe.NullRef<T>().LoadBytecode(ref bytecodeLoader, D2D1ShaderProfile.PixelShader50);
using ComPtr<ID3DBlob> dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan<byte> precompiledBytecode);
+38
ファイルの表示
@@ -0,0 +1,38 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
namespace ComputeSharp.D2D1Interop.__Internals;
/// <summary>
/// A <see langword="class"/> that uses the DXC APIs to compile compute shaders.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This type is not intended to be used directly by user code")]
public static class D2D1ShaderCompiler
{
/// <summary>
/// Compiles a new HLSL shader from the input source code.
/// </summary>
/// <typeparam name="TLoader">The type of bytecode loader being used.</typeparam>
/// <typeparam name="T">The type of D2D1 shader being dispatched.</typeparam>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the bytecode.</param>
/// <param name="shader">The input <typeparamref name="T"/> instance representing the D2D1 shader to run.</param>
/// <param name="shaderProfile">The shader profile to use to compile the shader.</param>
/// <param name="enableLinkingSupport">Whether to enable linking support for the shader.</param>
public static unsafe void LoadDynamicBytecode<TLoader, T>(ref TLoader loader, in T shader, D2D1ShaderProfile? shaderProfile, bool enableLinkingSupport)
where TLoader : struct, ID2D1BytecodeLoader
where T : struct, ID2D1Shader
{
Unsafe.AsRef(in shader).BuildHlslSource(out string hlslSource);
using ComPtr<ID3DBlob> d3DBlobBytecode = Shaders.Translation.D2D1ShaderCompiler.Compile(
hlslSource.AsSpan(),
shaderProfile ?? D2D1ShaderProfile.PixelShader50,
enableLinkingSupport);
loader.LoadDynamicBytecode((IntPtr)d3DBlobBytecode.Get());
}
}