Merge pull request #624 from Sergio0694/dev/d2d1-generator-cswin32

Switch to CsWin32 for DXC APIs in D2D1 generator
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-10-17 20:55:08 +02:00
コミット 35ec7afa99
15ファイル変更
+179 -77

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

-2
ファイルの表示
@@ -489,10 +489,8 @@ Global
src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{c12d7ace-98ed-4813-8118-6667c34f484f}*SharedItemsImports = 5
src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5
src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5
src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5
src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5
src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5
+12 -27
ファイルの表示
@@ -1,21 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591;CS0649;CS1574</NoWarn>
<NoWarn>$(NoWarn);CS1591;CS0649;CS1574;CS0419;IDE0004</NoWarn>
</PropertyGroup>
<!-- Same setup as ComputeSharp.Core.SourceGenerators, just with also APIs from ComputeSharp -->
<ItemGroup>
<!-- ComputeSharp.Core APIs -->
<Compile Include="..\ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" Link="ComputeSharp.Core\Attributes\AutoConstructorAttribute.cs" />
<Compile Include="..\ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" Link="ComputeSharp.Core\Exceptions\InvalidExecutionContextException.cs" />
<Compile Include="..\ComputeSharp.Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" Link="ComputeSharp.Core\Intrinsics\Attributes\HlslIntrinsicNameAttribute.cs" />
<Compile Include="..\ComputeSharp.Core\Intrinsics\Hlsl.Casts.g.cs" Link="ComputeSharp.Core\Intrinsics\Hlsl.Casts.g.cs" />
<Compile Include="..\ComputeSharp.Core\Intrinsics\Hlsl.cs" Link="ComputeSharp.Core\Intrinsics\Hlsl.cs" />
<Compile Include="..\ComputeSharp.Core\Intrinsics\Hlsl.g.cs" Link="ComputeSharp.Core\Intrinsics\Hlsl.g.cs" />
<Compile Include="..\ComputeSharp.Core\Intrinsics\Hlsl.Void.g.cs" Link="ComputeSharp.Core\Intrinsics\Hlsl.Void.g.cs" />
<Compile Include="..\ComputeSharp.Core\Polyfills\Win32ExceptionExtensions.cs" Link="ComputeSharp.Core\Polyfills\Win32ExceptionExtensions.cs" />
<Compile Include="..\ComputeSharp.Core\Primitives\Bool\Bool.cs" Link="ComputeSharp.Core\Primitives\Bool\Bool.cs" />
<Compile Include="..\ComputeSharp.Core\Primitives\Bool\Bool2.cs" Link="ComputeSharp.Core\Primitives\Bool\Bool2.cs" />
<Compile Include="..\ComputeSharp.Core\Primitives\Bool\Bool3.cs" Link="ComputeSharp.Core\Primitives\Bool\Bool3.cs" />
@@ -65,31 +63,24 @@
<Compile Include="..\ComputeSharp.D2D1\Attributes\Enums\D2D1CompileOptions.cs" Link="ComputeSharp.D2D1\Attributes\Enums\D2D1CompileOptions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\Enums\D2D1Filter.cs" Link="ComputeSharp.D2D1\Attributes\Enums\D2D1Filter.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\Enums\D2D1PixelOptions.cs" Link="ComputeSharp.D2D1\Attributes\Enums\D2D1PixelOptions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DCompileOptionsAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DCompileOptionsAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DShaderProfileAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DShaderProfileAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DInputComplexAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DInputComplexAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DInputCountAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DInputCountAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DInputSimpleAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DInputSimpleAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DRequiresScenePositionAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DRequiresScenePositionAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Attributes\D2DPixelShaderSourceAttribute.cs" Link="ComputeSharp.D2D1\Attributes\D2DPixelShaderSourceAttribute.cs" />
<Compile Include="..\ComputeSharp.D2D1\Extensions\ComPtrExtensions.cs" Link="ComputeSharp.D2D1\Extensions\ComPtrExtensions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Extensions\HRESULTExtensions.cs" Link="ComputeSharp.D2D1\Extensions\HRESULTExtensions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" Link="ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1ConstantBufferLoader.cs" Link="ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1ConstantBufferLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1PixelShaderDescriptor{T}.cs" Link="ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1PixelShaderDescriptor{T}.cs" />
<Compile Include="..\ComputeSharp.D2D1\Intrinsics\D2D.cs" Link="ComputeSharp.D2D1\Intrinsics\D2D.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" Link="ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\Helpers\D2D1AssemblyAssociatedMemory.cs" Link="ComputeSharp.D2D1\Shaders\Interop\Helpers\D2D1AssemblyAssociatedMemory.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1ResourceTextureDescription.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1ResourceTextureDescription.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\Headers\d2d1effecthelpers.hlsli.cs" Link="ComputeSharp.D2D1\Shaders\Translation\Headers\d2d1effecthelpers.hlsli.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" Link="Fxc\D3DCompiler.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" Link="Fxc\D3DCompiler.ID3DInclude.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\Headers\d2d1effecthelpers.hlsli.cs" Link="Fxc\Headers\d2d1effecthelpers.hlsli.cs" />
<!-- ComPtr<T> and HRESULT extension from D3D12 generator -->
<Compile Include="..\ComputeSharp.SourceGenerators\Dxc\Windows.Win32\ComPtr{T}.cs" Link="Fxc\Windows.Win32\ComPtr{T}.cs" />
<Compile Include="..\ComputeSharp.SourceGenerators\Dxc\Windows.Win32\HRESULT.cs" Link="Fxc\Windows.Win32\HRESULT.cs" />
<!-- Shared JSON config for CsWin32 from D3D12 generator -->
<AdditionalFiles Include="..\ComputeSharp.SourceGenerators\NativeMethods.json" Link="NativeMethods.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
@@ -101,12 +92,6 @@
<Import Project="..\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems" Label="Shared" />
<!-- Shared ComputeSharp.Win32.D2D1 with D2D1 bindings -->
<Import Project="..\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems" Label="Shared" />
<!-- Shared project with .NET Standard 2.0 polyfills -->
<Import Project="..\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems" Label="Shared" />
<!-- Give access to the code fixers project for the exported diagnostic ids and properties -->
<ItemGroup>
<InternalsVisibleTo Include="ComputeSharp.D2D1.CodeFixers, PublicKey=$(AssemblySignPublicKey)" />
+13 -3
ファイルの表示
@@ -76,7 +76,7 @@ partial class D2DPixelShaderDescriptorGenerator
/// </summary>
/// <param name="typeSymbol">The input <see cref="INamedTypeSymbol"/> instance.</param>
/// <returns>The resulting effect id.</returns>
private static ImmutableArray<byte> CreateDefaultEffectId(INamedTypeSymbol typeSymbol)
private static unsafe ImmutableArray<byte> CreateDefaultEffectId(INamedTypeSymbol typeSymbol)
{
try
{
@@ -97,15 +97,25 @@ partial class D2DPixelShaderDescriptorGenerator
int maxEncodedByteCount = Math.Max(maxTypeNameByteCount, maxAssemblyNameByteCount);
byte[] bufferUtf8 = ArrayPool<byte>.Shared.Rent(maxEncodedByteCount);
int typeNameBytesWritten;
int assemblyNameBytesWritten;
// UTF8 encode the fully qualified name first
int typeNameBytesWritten = Encoding.UTF8.GetBytes(charBuffer.WrittenSpan, bufferUtf8.AsSpan());
fixed (char* pCharBuffer = charBuffer.WrittenSpan)
fixed (byte* pBufferUtf8 = bufferUtf8)
{
typeNameBytesWritten = Encoding.UTF8.GetBytes(pCharBuffer, charBuffer.Count, pBufferUtf8, bufferUtf8.Length);
}
// Append the UTF8 fully qualified name to the MD5 hash
incrementalHash.AppendData(bufferUtf8, 0, typeNameBytesWritten);
// UTF8 encode the assembly name as well
int assemblyNameBytesWritten = Encoding.UTF8.GetBytes(assemblyName.AsSpan(), bufferUtf8.AsSpan());
fixed (char* pAssemblyName = assemblyName)
fixed (byte* pBufferUtf8 = bufferUtf8)
{
assemblyNameBytesWritten = Encoding.UTF8.GetBytes(pAssemblyName, assemblyName.Length, pBufferUtf8, bufferUtf8.Length);
}
// Append the UTF8 assembly name to the MD5 hash
incrementalHash.AppendData(bufferUtf8, 0, assemblyNameBytesWritten);
@@ -10,8 +10,8 @@ using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using Windows.Win32;
using Windows.Win32.Graphics.Direct3D;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
namespace ComputeSharp.D2D1.SourceGenerators;
+1 -1
ファイルの表示
@@ -287,7 +287,7 @@ partial class D2DPixelShaderDescriptorGenerator
{
IMethodSymbol methodDeclarationSymbol = semanticModel.For(methodDeclaration).GetDeclaredSymbol(methodDeclaration)!;
bool isShaderEntryPoint =
methodDeclarationSymbol.Name == nameof(ID2D1PixelShader.Execute) &&
methodDeclarationSymbol.Name == "Execute" &&
methodDeclarationSymbol.ReturnType.HasFullyQualifiedMetadataName("ComputeSharp.Float4") &&
methodDeclarationSymbol.TypeParameters.Length == 0 &&
methodDeclarationSymbol.Parameters.Length == 0;
+24
ファイルの表示
@@ -0,0 +1,24 @@
D3DCompile
D3DSetBlobPart
D2D1_BUFFER_PRECISION
D2D1_CHANNEL_DEPTH
D2D1_FILTER
D2D1_PIXEL_OPTIONS
D3DCOMPILE_DEBUG
D3DCOMPILE_SKIP_VALIDATION
D3DCOMPILE_SKIP_OPTIMIZATION
D3DCOMPILE_PACK_MATRIX_ROW_MAJOR
D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR
D3DCOMPILE_PARTIAL_PRECISION
D3DCOMPILE_AVOID_FLOW_CONTROL
D3DCOMPILE_ENABLE_STRICTNESS
D3DCOMPILE_IEEE_STRICTNESS
D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY
D3DCOMPILE_OPTIMIZATION_LEVEL0
D3DCOMPILE_OPTIMIZATION_LEVEL1
D3DCOMPILE_OPTIMIZATION_LEVEL2
D3DCOMPILE_OPTIMIZATION_LEVEL3
D3DCOMPILE_WARNINGS_ARE_ERRORS
IUnknown
S_OK
S_FALSE
+4
ファイルの表示
@@ -1,4 +1,8 @@
#if SOURCE_GENERATOR
using static Windows.Win32.Graphics.Direct2D.D2D1_BUFFER_PRECISION;
#else
using static TerraFX.Interop.DirectX.D2D1_BUFFER_PRECISION;
#endif
namespace ComputeSharp.D2D1;
+4
ファイルの表示
@@ -1,4 +1,8 @@
#if SOURCE_GENERATOR
using static Windows.Win32.Graphics.Direct2D.D2D1_CHANNEL_DEPTH;
#else
using static TerraFX.Interop.DirectX.D2D1_CHANNEL_DEPTH;
#endif
namespace ComputeSharp.D2D1;
+21 -17
ファイルの表示
@@ -1,9 +1,13 @@
using System;
#if !SOURCE_GENERATOR
#if SOURCE_GENERATOR
using D3DCOMPILE = Windows.Win32.PInvoke;
#else
using ComputeSharp.D2D1.Interop;
#endif
using TerraFX.Interop.DirectX;
#pragma warning disable IDE0004
#endif
namespace ComputeSharp.D2D1;
/// <summary>
@@ -21,7 +25,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_DEBUG</c> and <c>/Zi</c>.
/// </remarks>
Debug = D3DCOMPILE.D3DCOMPILE_DEBUG,
Debug = (int)D3DCOMPILE.D3DCOMPILE_DEBUG,
/// <summary>
/// Directs the compiler not to validate the generated code against known capabilities and constraints.
@@ -31,7 +35,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_SKIP_VALIDATION</c> and <c>/Vd</c>.
/// </remarks>
SkipValidation = D3DCOMPILE.D3DCOMPILE_SKIP_VALIDATION,
SkipValidation = (int)D3DCOMPILE.D3DCOMPILE_SKIP_VALIDATION,
/// <summary>
/// Directs the compiler to skip optimization steps during code generation.
@@ -40,7 +44,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_SKIP_OPTIMIZATION</c> and <c>/Od</c>.
/// </remarks>
SkipOptimization = D3DCOMPILE.D3DCOMPILE_SKIP_OPTIMIZATION,
SkipOptimization = (int)D3DCOMPILE.D3DCOMPILE_SKIP_OPTIMIZATION,
/// <summary>
/// Directs the compiler to pack matrices in row-major order on input and output from the shader.
@@ -49,7 +53,7 @@ public enum D2D1CompileOptions
/// <para>This value is needed to have the constant buffer loading from generated shaders map to compiled shaders.</para>
/// <para>This flag maps to <c>D3DCOMPILE_PACK_MATRIX_ROW_MAJOR</c> and <c>/Zpr</c>.</para>
/// </remarks>
PackMatrixRowMajor = D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR,
PackMatrixRowMajor = (int)D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR,
/// <summary>
/// Directs the compiler to pack matrices in column-major order on input and output from the shader.
@@ -61,7 +65,7 @@ public enum D2D1CompileOptions
/// <para>That is, trying to load a constant buffer from a shader processed by the source generator is undefined behavior.</para>
/// <para>This flag maps to <c>D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR</c> and <c>/Zpc</c>.</para>
/// </remarks>
PackMatrixColumnMajor = D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR,
PackMatrixColumnMajor = (int)D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR,
/// <summary>
/// Directs the compiler to perform all computations with partial precision.
@@ -70,7 +74,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_PARTIAL_PRECISION</c> and <c>/Gpp</c>.
/// </remarks>
PartialPrecision = D3DCOMPILE.D3DCOMPILE_PARTIAL_PRECISION,
PartialPrecision = (int)D3DCOMPILE.D3DCOMPILE_PARTIAL_PRECISION,
/// <summary>
/// Directs the compiler to not use flow-control constructs where possible.
@@ -78,7 +82,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_AVOID_FLOW_CONTROL</c> and <c>/Gfa</c>.
/// </remarks>
AvoidFlowControl = D3DCOMPILE.D3DCOMPILE_AVOID_FLOW_CONTROL,
AvoidFlowControl = (int)D3DCOMPILE.D3DCOMPILE_AVOID_FLOW_CONTROL,
/// <summary>
/// Forces strict compile, which might not allow for legacy syntax.
@@ -87,7 +91,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_ENABLE_STRICTNESS</c> and <c>/Ges</c>.
/// </remarks>
EnableStrictness = D3DCOMPILE.D3DCOMPILE_ENABLE_STRICTNESS,
EnableStrictness = (int)D3DCOMPILE.D3DCOMPILE_ENABLE_STRICTNESS,
/// <summary>
/// Forces the IEEE strict compile which avoids optimizations that may break IEEE rules.
@@ -95,7 +99,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_IEEE_STRICTNESS</c> and <c>/Gis</c>.
/// </remarks>
IeeeStrictness = D3DCOMPILE.D3DCOMPILE_IEEE_STRICTNESS,
IeeeStrictness = (int)D3DCOMPILE.D3DCOMPILE_IEEE_STRICTNESS,
/// <summary>
/// Directs the compiler to enable older shaders to compile to 5_0 targets.
@@ -103,7 +107,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY</c> and <c>/Gec</c>.
/// </remarks>
EnableBackwardsCompatibility = D3DCOMPILE.D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY,
EnableBackwardsCompatibility = (int)D3DCOMPILE.D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY,
/// <summary>
/// Directs the compiler to use the lowest optimization level. If this option is set, the compiler
@@ -113,7 +117,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_OPTIMIZATION_LEVEL0</c> and <c>/O0</c>.
/// </remarks>
OptimizationLevel0 = D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL0,
OptimizationLevel0 = (int)D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL0,
/// <summary>
/// Directs the compiler to use the second lowest optimization level.
@@ -121,7 +125,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_OPTIMIZATION_LEVEL1</c> and <c>/O1</c>.
/// </remarks>
OptimizationLevel1 = D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL1,
OptimizationLevel1 = (int)D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL1,
/// <summary>
/// Directs the compiler to use the second highest optimization level.
@@ -129,7 +133,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_OPTIMIZATION_LEVEL2</c> and <c>/O2</c>.
/// </remarks>
OptimizationLevel2 = D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL2,
OptimizationLevel2 = (int)D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL2,
/// <summary>
/// Directs the compiler to use the highest optimization level. If this option is set, the compiler
@@ -139,7 +143,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_OPTIMIZATION_LEVEL3</c> and <c>/O3</c>.
/// </remarks>
OptimizationLevel3 = D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3,
OptimizationLevel3 = (int)D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3,
/// <summary>
/// Directs the compiler to treat all warnings as errors when it compiles the shader code. This
@@ -149,7 +153,7 @@ public enum D2D1CompileOptions
/// <remarks>
/// This flag maps to <c>D3DCOMPILE_WARNINGS_ARE_ERRORS</c> and <c>/WX</c>.
/// </remarks>
WarningsAreErrors = D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS,
WarningsAreErrors = (int)D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS,
/// <summary>
/// This flag enables the support for shader linking. Specifically, when set, this flag causes the APIs from
+4
ファイルの表示
@@ -1,4 +1,8 @@
#if SOURCE_GENERATOR
using static Windows.Win32.Graphics.Direct2D.D2D1_FILTER;
#else
using static TerraFX.Interop.DirectX.D2D1_FILTER;
#endif
namespace ComputeSharp.D2D1;
+4
ファイルの表示
@@ -1,5 +1,9 @@
using System;
#if SOURCE_GENERATOR
using static Windows.Win32.Graphics.Direct2D.D2D1_PIXEL_OPTIONS;
#else
using static TerraFX.Interop.DirectX.D2D1_PIXEL_OPTIONS;
#endif
namespace ComputeSharp.D2D1;
+7 -3
ファイルの表示
@@ -1,7 +1,7 @@
#if NET6_0_OR_GREATER
using System.Runtime.CompilerServices;
#if SOURCE_GENERATOR
using System.Runtime.InteropServices;
#else
using RuntimeHelpers = ComputeSharp.NetStandard.RuntimeHelpers;
using System.Runtime.CompilerServices;
#endif
namespace ComputeSharp.D2D1.Interop;
@@ -26,6 +26,10 @@ internal static unsafe class D2D1AssemblyAssociatedMemory
// only invoking this API on an empty type, which minimizes the codegen increase. This is still safe, as types are
// not unloaded one by one. Rather, the entire assembly they belong to is unloaded. So given all uses of this API
// are from within this same assembly, there is no functional difference than associating memory to the various types.
#if SOURCE_GENERATOR
return (void*)Marshal.AllocHGlobal(size);
#else
return (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D2D1AssemblyAssociatedMemory), size);
#endif
}
}
+28 -19
ファイルの表示
@@ -1,13 +1,15 @@
#if !SOURCE_GENERATOR
using System;
#endif
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Interop;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if NET6_0_OR_GREATER
using MemoryMarshal2 = System.Runtime.InteropServices.MemoryMarshal;
#if SOURCE_GENERATOR
using Windows.Win32.Graphics.Direct3D;
using static Windows.Win32.Foundation.HRESULT;
#else
using MemoryMarshal2 = ComputeSharp.NetStandard.MemoryMarshal;
using TerraFX.Interop.DirectX;
using static TerraFX.Interop.Windows.S;
#endif
namespace ComputeSharp.D2D1.Shaders.Translation;
@@ -20,7 +22,7 @@ partial class D3DCompiler
/// </summary>
private unsafe struct ID3DIncludeForD2DHelpers
{
#if !NET6_0_OR_GREATER
#if SOURCE_GENERATOR
/// <inheritdoc cref="Open"/>
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int OpenDelegate(ID3DIncludeForD2DHelpers* @this, D3D_INCLUDE_TYPE IncludeType, sbyte* pFileName, void* pParentData, void** ppData, uint* pBytes);
@@ -53,12 +55,12 @@ partial class D3DCompiler
{
void** lpVtbl = (void**)D2D1AssemblyAssociatedMemory.Allocate(sizeof(void*) * 2);
#if NET6_0_OR_GREATER
lpVtbl[0] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, D3D_INCLUDE_TYPE, sbyte*, void*, void**, uint*, int>)&Open;
lpVtbl[1] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, void*, int>)&Close;
#else
#if SOURCE_GENERATOR
lpVtbl[0] = (void*)Marshal.GetFunctionPointerForDelegate(OpenWrapper);
lpVtbl[1] = (void*)Marshal.GetFunctionPointerForDelegate(CloseWrapper);
#else
lpVtbl[0] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, D3D_INCLUDE_TYPE, sbyte*, void*, void**, uint*, int>)&Open;
lpVtbl[1] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, void*, int>)&Close;
#endif
return lpVtbl;
@@ -73,37 +75,44 @@ partial class D3DCompiler
/// Creates and initializes a new <see cref="ID3DIncludeForD2DHelpers"/> instance.
/// </summary>
/// <returns>A pointer to a new <see cref="ID3DIncludeForD2DHelpers"/> instance.</returns>
public static ID3DIncludeForD2DHelpers* Create()
public static ID3DInclude* Create()
{
ID3DIncludeForD2DHelpers* @this = (ID3DIncludeForD2DHelpers*)NativeMemory.Alloc((nuint)sizeof(ID3DIncludeForD2DHelpers));
ID3DIncludeForD2DHelpers* @this =
#if SOURCE_GENERATOR
(ID3DIncludeForD2DHelpers*)Marshal.AllocHGlobal(sizeof(ID3DIncludeForD2DHelpers));
#else
(ID3DIncludeForD2DHelpers*)NativeMemory.Alloc((nuint)sizeof(ID3DIncludeForD2DHelpers));
#endif
@this->lpVtbl = Vtbl;
return @this;
return (ID3DInclude*)@this;
}
/// <inheritdoc cref="ID3DInclude.Open"/>
[UnmanagedCallersOnly]
public static int Open(ID3DIncludeForD2DHelpers* @this, D3D_INCLUDE_TYPE IncludeType, sbyte* pFileName, void* pParentData, void** ppData, uint* pBytes)
{
ReadOnlySpan<byte> fileName = MemoryMarshal2.CreateReadOnlySpanFromNullTerminated((byte*)pFileName);
if (fileName.SequenceEqual("d2d1effecthelpers.hlsli"u8))
#if SOURCE_GENERATOR
if (new string(pFileName) == "d2d1effecthelpers.hlsli")
#else
if (MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)pFileName).SequenceEqual("d2d1effecthelpers.hlsli"u8))
#endif
{
*ppData = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(D2D1EffectHelpers.TextUtf8));
*pBytes = (uint)D2D1EffectHelpers.TextUtf8.Length;
return S.S_OK;
return S_OK;
}
return S.S_FALSE;
return S_FALSE;
}
/// <inheritdoc cref="ID3DInclude.Close"/>
[UnmanagedCallersOnly]
public static int Close(ID3DIncludeForD2DHelpers* @this, void* pData)
{
return S.S_OK;
return S_OK;
}
}
}
+39 -3
ファイルの表示
@@ -4,9 +4,17 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
#if SOURCE_GENERATOR
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Direct3D;
using Windows.Win32.Graphics.Direct3D.Fxc;
using DirectX = Windows.Win32.PInvoke;
#else
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#endif
namespace ComputeSharp.D2D1.Shaders.Translation;
@@ -18,7 +26,7 @@ internal static unsafe partial class D3DCompiler
/// <summary>
/// The <see cref="ID3DInclude"/> instance to load <c>d2d1effecthelpers.hlsli</c>.
/// </summary>
private static readonly ID3DIncludeForD2DHelpers* D3DIncludeForD2D1EffectHelpers = ID3DIncludeForD2DHelpers.Create();
private static readonly ID3DInclude* D3DIncludeForD2D1EffectHelpers = ID3DIncludeForD2DHelpers.Create();
/// <summary>
/// Compiles a new HLSL shader from the input source code.
@@ -31,7 +39,17 @@ internal static unsafe partial class D3DCompiler
{
int maxLength = Encoding.ASCII.GetMaxByteCount(source.Length);
byte[] buffer = ArrayPool<byte>.Shared.Rent(maxLength);
int writtenBytes = Encoding.ASCII.GetBytes(source, buffer);
int writtenBytes;
#if SOURCE_GENERATOR
fixed (char* pSource = source)
fixed (byte* pBuffer = buffer)
{
writtenBytes = Encoding.ASCII.GetBytes(pSource, source.Length, pBuffer, buffer.Length);
}
#else
writtenBytes = Encoding.ASCII.GetBytes(source, buffer);
#endif
try
{
@@ -91,7 +109,7 @@ internal static unsafe partial class D3DCompiler
using ComPtr<ID3DBlob> d3DBlobBytecode = default;
using ComPtr<ID3DBlob> d3DBlobErrors = default;
int hResult;
HRESULT hResult;
fixed (byte* sourcePtr = source)
fixed (byte* macroPtr = macro)
@@ -108,13 +126,23 @@ internal static unsafe partial class D3DCompiler
{
new()
{
#if SOURCE_GENERATOR
Name = new PCSTR(macroPtr),
Definition = new PCSTR((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.NullTerminator)))
#else
Name = (sbyte*)macroPtr,
Definition = (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.NullTerminator))
#endif
},
new()
{
#if SOURCE_GENERATOR
Name = new PCSTR((byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.D2D_ENTRY))),
Definition = new PCSTR(d2DEntryPtr)
#else
Name = (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.D2D_ENTRY)),
Definition = (sbyte*)d2DEntryPtr
#endif
},
new()
};
@@ -123,11 +151,19 @@ internal static unsafe partial class D3DCompiler
hResult = DirectX.D3DCompile(
pSrcData: sourcePtr,
SrcDataSize: (nuint)source.Length,
#if SOURCE_GENERATOR
pSourceName: (PCSTR)null,
pDefines: macros,
pInclude: D3DIncludeForD2D1EffectHelpers,
pEntrypoint: new PCSTR(entryPointPtr),
pTarget: new PCSTR(targetPtr),
#else
pSourceName: null,
pDefines: macros,
pInclude: D3DIncludeForD2D1EffectHelpers,
pEntrypoint: (sbyte*)entryPointPtr,
pTarget: (sbyte*)targetPtr,
#endif
Flags1: flags,
Flags2: 0,
ppCode: d3DBlobBytecode.GetAddressOf(),
+16
ファイルの表示
@@ -59,4 +59,20 @@ internal unsafe struct ComPtr<T> : IDisposable
{
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
}
/// <summary>
/// Moves the current <see cref="ComPtr{T}"/> instance and resets it without releasing the reference.
/// </summary>
/// <returns>The moved <see cref="ComPtr{T}"/> instance.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ComPtr<T> Move()
{
ComPtr<T> other = default;
other.ptr = this.ptr;
this.ptr = null;
return other;
}
}