Add HlslBytecodeSyntaxProcessor shared helper type

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-17 13:31:17 +01:00
1 親 ef821be2b2
コミット 2a519c3f51
11ファイル変更
+284 -22

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

+1 -1
ファイルの表示
@@ -131,7 +131,7 @@ partial class ComputeShaderDescriptorGenerator
else if (info is HlslBytecodeInfo.CompilerError dxcError)
{
diagnostic = DiagnosticInfo.Create(
HlslBytecodeFailedWithDxcCompilationException,
HlslBytecodeFailedWithCompilationException,
structDeclarationSymbol,
structDeclarationSymbol,
dxcError.Message);
+1
ファイルの表示
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>$(DefineConstants);D3D12_SOURCE_GENERATOR</DefineConstants>
</PropertyGroup>
<PropertyGroup>
+1 -1
ファイルの表示
@@ -627,7 +627,7 @@ partial class DiagnosticDescriptors
/// Format: <c>"The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor HlslBytecodeFailedWithDxcCompilationException = new(
public static readonly DiagnosticDescriptor HlslBytecodeFailedWithCompilationException = new(
id: "CMPS0046",
title: "HLSL bytecode compilation failed due to an HLSL compiler error",
messageFormat: """The shader of type {0} failed to compile due to an HLSL compiler error (Message: "{1}")""",
+6 -14
ファイルの表示
@@ -42,13 +42,13 @@ internal sealed unsafe class DxcShaderCompiler
using ComPtr<IDxcCompiler3> dxcCompiler = default;
using ComPtr<IDxcUtils> dxcUtils = default;
PInvoke.DxcCreateInstance(
PInvoke.CLSID_DxcCompiler,
DirectX.DxcCreateInstance(
DirectX.CLSID_DxcCompiler,
IDxcCompiler3.IID_Guid,
out *(void**)dxcCompiler.GetAddressOf()).Assert();
PInvoke.DxcCreateInstance(
PInvoke.CLSID_DxcLibrary,
DirectX.DxcCreateInstance(
DirectX.CLSID_DxcLibrary,
IDxcUtils.IID_Guid,
out *(void**)dxcUtils.GetAddressOf()).Assert();
@@ -250,11 +250,7 @@ internal sealed unsafe class DxcShaderCompiler
return dxcBlobBytecode.Move();
}
/// <summary>
/// Checks whether double precision support is required.
/// </summary>
/// <param name="dxcBlob">The input HLSL bytecode to inspect.</param>
/// <returns>Whether double precision support is required for <paramref name="dxcBlob"/>.</returns>
/// <inheritdoc cref="SourceGeneration.SyntaxProcessors.HlslBytecodeSyntaxProcessor.IsDoublePrecisionSupportRequired"/>
public bool IsDoublePrecisionSupportRequired(IDxcBlob* dxcBlob)
{
using ComPtr<ID3D12ShaderReflection> d3D12ShaderReflection = default;
@@ -275,11 +271,7 @@ internal sealed unsafe class DxcShaderCompiler
return (d3D12ShaderReflection.Get()->GetRequiresFlags() & doublePrecisionFlags) != 0;
}
/// <summary>
/// Fixes up an exception message to improve the way it's displayed in VS.
/// </summary>
/// <param name="message">The input exception message.</param>
/// <returns>The updated exception message.</returns>
/// <inheritdoc cref="SourceGeneration.SyntaxProcessors.HlslBytecodeSyntaxProcessor.FixupErrorMessage"/>
public static string FixupExceptionMessage(string message)
{
// Add square brackets around error headers
@@ -0,0 +1,38 @@
using System;
using System.Threading;
using ComputeSharp.SourceGenerators.Dxc;
using ComputeSharp.SourceGenerators.Models;
using Windows.Win32;
using Windows.Win32.Graphics.Direct3D.Dxc;
namespace ComputeSharp.SourceGeneration.SyntaxProcessors;
/// <inheritdoc/>
partial class HlslBytecodeSyntaxProcessor
{
/// <summary>
/// The name of the attribute to enable double precision support.
/// </summary>
private const string RequiresDoublePrecisionSupportAttributeName = "ComputeSharp.RequiresDoublePrecisionSupportAttribute";
/// <inheritdoc/>
private static partial ComPtr<IDxcBlob> Compile(HlslBytecodeInfoKey key, CancellationToken token)
{
return DxcShaderCompiler.Instance.Compile(
key.HlslSource.AsSpan(),
key.CompileOptions,
token);
}
/// <inheritdoc/>
private static unsafe partial bool IsDoublePrecisionSupportRequired(IDxcBlob* d3DBlob)
{
return DxcShaderCompiler.Instance.IsDoublePrecisionSupportRequired(d3DBlob);
}
/// <inheritdoc/>
private static partial string FixupErrorMessage(string message)
{
return DxcShaderCompiler.FixupExceptionMessage(message);
}
}