Update D3D12 generator to implement descriptor interface
このコミットが含まれているのは:
1 親
cecafb8d88
コミット
f5b38e1af8
11ファイル変更
+67
-75
検索条件に一致するファイルはありません
+1
-1
@@ -19,7 +19,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly string global::ComputeSharp.__Internals.IShader.HlslSource =>");
|
||||
writer.WriteLine($"readonly string global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslSource =>");
|
||||
writer.IncreaseIndent();
|
||||
writer.WriteLine("\"\"\"");
|
||||
writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true);
|
||||
|
||||
@@ -20,7 +20,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<byte> global::ComputeSharp.__Internals.IShader.HlslBytecode => ");
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<byte> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslBytecode => ");
|
||||
|
||||
// Just like with the D2D1 generator, only return the MemoryManager<T> if we do have HLSL bytecode
|
||||
if (info.HlslInfo is not HlslBytecodeInfo.Success)
|
||||
@@ -129,7 +129,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsX => {info.ThreadsX};");
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsX => {info.ThreadsX};");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -141,7 +141,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsY => {info.ThreadsY};");
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsY => {info.ThreadsY};");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,7 +153,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ThreadsZ => {info.ThreadsZ};");
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ThreadsZ => {info.ThreadsZ};");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-6
@@ -17,10 +17,12 @@ partial class IShaderGenerator
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
public static void WriteLoadConstantBufferSyntax(ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
|
||||
writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadConstantBuffer<TLoader>(ref TLoader loader, int x, int y, int z)");
|
||||
writer.WriteLine($"readonly void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{typeName}>.LoadConstantBuffer<TLoader>(in {typeName} shader, ref TLoader loader, int x, int y, int z)");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
@@ -41,14 +43,14 @@ partial class IShaderGenerator
|
||||
// Read a boolean value and cast it to Bool first, which will apply the correct size expansion
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.Bool>(ref span[{primitive.Offset}]) = " +
|
||||
$"(global::ComputeSharp.Bool){string.Join(".", primitive.FieldPath)};");
|
||||
$"(global::ComputeSharp.Bool)shader.{string.Join(".", primitive.FieldPath)};");
|
||||
break;
|
||||
case FieldInfo.Primitive primitive:
|
||||
|
||||
// Read a primitive value and serialize it into the target buffer
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::{primitive.TypeName}>(ref span[{primitive.Offset}]) = " +
|
||||
$"{string.Join(".", primitive.FieldPath)};");
|
||||
$"shader.{string.Join(".", primitive.FieldPath)};");
|
||||
break;
|
||||
|
||||
case FieldInfo.NonLinearMatrix matrix:
|
||||
@@ -61,7 +63,7 @@ partial class IShaderGenerator
|
||||
// ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in <FIELD_PATH>));
|
||||
writer.WriteLine(
|
||||
$"ref {rowTypeName} {rowLocalName} = ref global::System.Runtime.CompilerServices.Unsafe.As<global::{matrix.TypeName}, {rowTypeName}>(" +
|
||||
$"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in {string.Join(".", matrix.FieldPath)}));");
|
||||
$"ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in shader.{string.Join(".", matrix.FieldPath)}));");
|
||||
|
||||
// Generate the loading code for each individual row, with proper alignment.
|
||||
// This will result in the following (assuming Float2x3 m):
|
||||
@@ -92,9 +94,11 @@ partial class IShaderGenerator
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
public static void WriteLoadGraphicsResourcesSyntax(ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
|
||||
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadGraphicsResources<TLoader>(ref TLoader loader)");
|
||||
writer.WriteLine($"readonly void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{typeName}>.LoadGraphicsResources<TLoader>(in {typeName} shader, ref TLoader loader)");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
@@ -103,7 +107,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
if (fieldInfo is FieldInfo.Resource resource)
|
||||
{
|
||||
writer.WriteLine($"loader.LoadGraphicsResource({resource.FieldName}, {resource.Offset});");
|
||||
writer.WriteLine($"loader.LoadGraphicsResource(shader.{resource.FieldName}, {resource.Offset});");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,6 @@ partial class IShaderGenerator
|
||||
string fieldName = fieldSymbol.Name;
|
||||
string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
|
||||
|
||||
// Disambiguates the name of target fields against the current input parameters
|
||||
if (fieldName is "loader" or "device" or "x" or "y" or "z")
|
||||
{
|
||||
fieldName = $"this.{fieldName}";
|
||||
}
|
||||
|
||||
// The first item in each nested struct needs to be aligned to 16 bytes
|
||||
if (isFirstField && fieldPath.Length > 0)
|
||||
{
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.__Internals.IShader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
|
||||
writer.WriteLine($"readonly int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +31,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine($"readonly bool global::ComputeSharp.__Internals.IShader.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};");
|
||||
writer.WriteLine($"readonly bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.IsStaticSamplerRequired => {info.IsSamplerUsed.ToString().ToLowerInvariant()};");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +43,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.Interop.ResourceDescriptorRange> global::ComputeSharp.__Internals.IShader.ResourceDescriptorRanges => ");
|
||||
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.Interop.ResourceDescriptorRange> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceDescriptorRanges => ");
|
||||
|
||||
// If there are no declared resources, just return an empty collection
|
||||
if (info.ResourceDescriptors.IsEmpty)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
@@ -166,7 +165,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
item.Hierarchy.WriteSyntax(
|
||||
state: item,
|
||||
writer: writer,
|
||||
baseTypes: ReadOnlySpan<string>.Empty,
|
||||
baseTypes: new[] { $"global::ComputeSharp.Descriptors.IComputeShaderDescriptor<{item.Hierarchy.Hierarchy[0].QualifiedName}>" },
|
||||
memberCallbacks: declaredMembers.WrittenSpan);
|
||||
|
||||
// Append any additional types as well
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする