Add HLSL bytecode to D2D1ShaderInfo

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-17 01:55:16 +02:00
1 親 5cbc583a19
コミット 7f00437a48
3ファイル変更
+16 -24

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

+6 -24
ファイルの表示
@@ -2,7 +2,6 @@ using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Translation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -31,33 +30,15 @@ public static class D2D1ReflectionServices
{
Unsafe.SkipInit(out T shader);
string hlslSource = shader.HlslSource;
ReadOnlyMemory<byte> hlslBytecode = D2D1PixelShader.LoadBytecode<T>();
using ComPtr<ID3D11ShaderReflection> d3D11ShaderReflection = default;
// If the shader already has embedded bytecode, use that directly
if (shader.HlslBytecode is ReadOnlyMemory<byte> { Length: > 0 } hlslBytecode)
fixed (byte* hlslBytecodePtr = hlslBytecode.Span)
{
fixed (byte* hlslBytecodePtr = hlslBytecode.Span)
{
DirectX.D3DReflect(
pSrcData: hlslBytecodePtr,
SrcDataSize: (nuint)hlslBytecode.Length,
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
ppReflector: (void**)d3D11ShaderReflection.GetAddressOf()).Assert();
}
}
else
{
// Otherwise, compile it with default shader profile and compile options and use that.
// Note that we're intentionally retrieving an ID3DBlob instance here to avoid having
// to allocate a ReadOnlyMemory<byte> object to throw away immediately, as we don't
// actually need to keep the bytecode for later.
using ComPtr<ID3DBlob> dynamicBytecode = D3DCompiler.Compile(hlslSource.AsSpan(), shader.ShaderProfile, shader.CompileOptions);
DirectX.D3DReflect(
pSrcData: (byte*)dynamicBytecode.Get()->GetBufferPointer(),
SrcDataSize: dynamicBytecode.Get()->GetBufferSize(),
pSrcData: hlslBytecodePtr,
SrcDataSize: (nuint)hlslBytecode.Length,
pInterface: Windows.__uuidof<ID3D11ShaderReflection>(),
ppReflector: (void**)d3D11ShaderReflection.GetAddressOf()).Assert();
}
@@ -72,7 +53,8 @@ public static class D2D1ReflectionServices
return new(
CompilerVersion: new string(d3D11ShaderDescription.Creator),
HlslSource: hlslSource,
HlslSource: shader.HlslSource,
HlslBytecode: hlslBytecode,
ConstantBufferCount: d3D11ShaderDescription.ConstantBuffers,
BoundResourceCount: d3D11ShaderDescription.BoundResources,
InstructionCount: d3D11ShaderDescription.InstructionCount,
+4
ファイルの表示
@@ -1,3 +1,5 @@
using System;
namespace ComputeSharp.D2D1.Interop;
/// <summary>
@@ -5,6 +7,7 @@ namespace ComputeSharp.D2D1.Interop;
/// </summary>
/// <param name="CompilerVersion">The compiler version used to build the shader.</param>
/// <param name="HlslSource">The HLSL source code the shader was built from.</param>
/// <param name="HlslBytecode">The HLSL bytecode for the shader.</param>
/// <param name="ConstantBufferCount">The number of shader constant buffers.</param>
/// <param name="BoundResourceCount">The number of resource (textures and buffers) bound to a shader.</param>
/// <param name="InstructionCount">The number of intermediate-language instructions in the compiled shader.</param>
@@ -32,6 +35,7 @@ namespace ComputeSharp.D2D1.Interop;
public sealed record D2D1ShaderInfo(
string CompilerVersion,
string HlslSource,
ReadOnlyMemory<byte> HlslBytecode,
uint ConstantBufferCount,
uint BoundResourceCount,
uint InstructionCount,
+6
ファイルの表示
@@ -18,6 +18,7 @@ public partial class D2D1ReflectionServicesTests
Assert.IsFalse(shaderInfo.RequiresDoublePrecisionSupport);
Assert.AreEqual(D3DFeatureLevel.FeatureLevel10_1, shaderInfo.MinimumFeatureLevel);
Assert.IsNotNull(shaderInfo.CompilerVersion);
Assert.AreEqual("""
// ================================================
// AUTO GENERATED
@@ -52,6 +53,8 @@ public partial class D2D1ReflectionServicesTests
return input0 + input1 + input2 + value3 + value4;
}
""".Replace("\r\n", "\n"), shaderInfo.HlslSource);
CollectionAssert.AreEqual(D2D1PixelShader.LoadBytecode<ReflectedShader>().ToArray(), shaderInfo.HlslBytecode.ToArray());
}
[D2DInputCount(3)]
@@ -98,6 +101,7 @@ public partial class D2D1ReflectionServicesTests
Assert.IsTrue(shaderInfo.RequiresDoublePrecisionSupport);
Assert.AreEqual(D3DFeatureLevel.FeatureLevel11_0, shaderInfo.MinimumFeatureLevel);
Assert.IsNotNull(shaderInfo.CompilerVersion);
Assert.AreEqual("""
// ================================================
// AUTO GENERATED
@@ -116,6 +120,8 @@ public partial class D2D1ReflectionServicesTests
return (float4)(D2DGetInput(0) + (double4)amount);
}
""".Replace("\r\n", "\n"), shaderInfo.HlslSource);
CollectionAssert.AreEqual(D2D1PixelShader.LoadBytecode<ReflectedShaderWithDoubleOperations>().ToArray(), shaderInfo.HlslBytecode.ToArray());
}
[D2DInputCount(1)]