Add logic to optionally generate artificial fields
このコミットが含まれているのは:
1 親
5df310f87b
コミット
0a7dbb3cfb
2ファイル変更
+47
検索条件に一致するファイルはありません
+11
@@ -68,6 +68,9 @@ partial class ConstantBufferSyntaxProcessor
|
||||
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
// Append any artificial fields, if needed
|
||||
AppendArtificialFields(info, writer);
|
||||
|
||||
// Declare fields for every mapped item from the shader layout
|
||||
writer.WriteLineSeparatedMembers(info.Fields.AsSpan(), (field, writer) =>
|
||||
{
|
||||
@@ -302,6 +305,14 @@ partial class ConstantBufferSyntaxProcessor
|
||||
callbacks.Add(ConstantBufferCallback);
|
||||
callbacks.Add(ConstantBufferMarshallerCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends any artificial fields to the generated constant buffer type.
|
||||
/// </summary>
|
||||
/// <param name="info">The <see cref="IConstantBufferInfo"/> instance to use to extract info.</param>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
/// <remarks>This method is responsible for leaving trailing blanklines, if it adds any fields.</remarks>
|
||||
static partial void AppendArtificialFields(IConstantBufferInfo info, IndentedTextWriter writer);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Extensions.IndentedTextWriterExtensions"/>
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using ComputeSharp.SourceGeneration.Models;
|
||||
using ComputeSharp.SourceGenerators.Models;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.SyntaxProcessors;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ConstantBufferSyntaxProcessor
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
static partial void AppendArtificialFields(IConstantBufferInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
// The X and Y axes are always present
|
||||
writer.WriteLine("""
|
||||
/// <summary>The artificial field backing <see cref="DispatchSize.X"/>.</summary>
|
||||
[FieldOffset(0)]
|
||||
public int __x;
|
||||
|
||||
/// <summary>The artificial field backing <see cref="DispatchSize.Y"/>.</summary>
|
||||
[FieldOffset(4)]
|
||||
public int __y;
|
||||
""", isMultiline: true);
|
||||
|
||||
// The Z axis is only present for non pixel-shader-like compute shaders
|
||||
writer.WriteLineIf(
|
||||
condition: !((ShaderInfo)info).IsPixelShaderLike,
|
||||
"""
|
||||
/// <summary>The artificial field backing <see cref="DispatchSize.Z"/>.</summary>
|
||||
[FieldOffset(8)]
|
||||
public int __z;
|
||||
""", isMultiline: true);
|
||||
|
||||
// Leave a trailing blank line if the shader has any fields
|
||||
writer.WriteLineIf(!info.Fields.IsEmpty);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする