Add new models for shader methods, update generators
このコミットが含まれているのは:
1 親
4e6f4f55d4
コミット
87768dc2b4
6ファイル変更
+132
-22
検索条件に一致するファイルはありません
@@ -7,7 +7,7 @@ using ComputeSharp.SourceGeneration.Helpers;
|
||||
namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A model representing a shared and its compiled bytecode, if available.
|
||||
/// A model representing info on a shader that has requested to be precompiled at build time.
|
||||
/// </summary>
|
||||
/// <param name="HlslSource">The HLSL source for the shader.</param>
|
||||
/// <param name="ShaderProfile">The shader profile to use to compile the shader, if requested.</param>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A model representing info on a shader method that has requested to be precompiled at build time.
|
||||
/// </summary>
|
||||
///<param name="Modifiers">The modifiers for the annotated method.</param>
|
||||
/// <param name="MethodName">The name of the annotated method.</param>
|
||||
/// <param name="HlslSource">The HLSL source.</param>
|
||||
/// <param name="Bytecode">The compiled shader bytecode, if available.</param>
|
||||
internal sealed record EmbeddedBytecodeMethodInfo(
|
||||
ImmutableArray<SyntaxKind> Modifiers,
|
||||
string MethodName,
|
||||
string HlslSource,
|
||||
ImmutableArray<byte> Bytecode)
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="EmbeddedBytecodeMethodInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<EmbeddedBytecodeMethodInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeMethodInfo obj)
|
||||
{
|
||||
hashCode.AddRange(obj.Modifiers);
|
||||
hashCode.Add(obj.MethodName);
|
||||
hashCode.Add(obj.HlslSource);
|
||||
hashCode.AddBytes(obj.Bytecode.AsSpan());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(EmbeddedBytecodeMethodInfo x, EmbeddedBytecodeMethodInfo y)
|
||||
{
|
||||
return
|
||||
MemoryMarshal.Cast<SyntaxKind, ushort>(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast<SyntaxKind, ushort>(y.Modifiers.AsSpan())) &&
|
||||
x.MethodName == y.MethodName &&
|
||||
x.HlslSource == y.HlslSource &&
|
||||
x.Bytecode.SequenceEqual(y.Bytecode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A model for extracted info on a processed HLSL shader method.
|
||||
/// </summary>
|
||||
/// <param name="Modifiers">The modifiers for the annotated method.</param>
|
||||
/// <param name="MethodName">The name of the annotated method.</param>
|
||||
/// <param name="HlslSource">The HLSL source.</param>
|
||||
/// <param name="ShaderProfile">The shader profile to use to compile the shader, if requested.</param>
|
||||
/// <param name="CompileOptions">The compile options to use to compile the shader.</param>
|
||||
/// <param name="HasErrors">Whether any errors have been detected, and therefore the shader compilation should be skipped.</param>
|
||||
internal sealed record HlslShaderMethodSourceInfo(
|
||||
ImmutableArray<SyntaxKind> Modifiers,
|
||||
string MethodName,
|
||||
string HlslSource,
|
||||
D2D1ShaderProfile? ShaderProfile,
|
||||
D2D1CompileOptions? CompileOptions,
|
||||
bool HasErrors)
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="HlslShaderMethodSourceInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : Comparer<HlslShaderMethodSourceInfo, Comparer>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, HlslShaderMethodSourceInfo obj)
|
||||
{
|
||||
hashCode.AddRange(obj.Modifiers);
|
||||
hashCode.Add(obj.MethodName);
|
||||
hashCode.Add(obj.HlslSource);
|
||||
hashCode.Add(obj.ShaderProfile);
|
||||
hashCode.Add(obj.CompileOptions);
|
||||
hashCode.Add(obj.HasErrors);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(HlslShaderMethodSourceInfo x, HlslShaderMethodSourceInfo y)
|
||||
{
|
||||
return
|
||||
MemoryMarshal.Cast<SyntaxKind, ushort>(x.Modifiers.AsSpan()).SequenceEqual(MemoryMarshal.Cast<SyntaxKind, ushort>(y.Modifiers.AsSpan())) &&
|
||||
x.MethodName == y.MethodName &&
|
||||
x.HlslSource == y.HlslSource &&
|
||||
x.ShaderProfile == y.ShaderProfile &&
|
||||
x.CompileOptions == y.CompileOptions &&
|
||||
x.HasErrors == y.HasErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする