Update D3D12 generator to implement descriptor interface
このコミットが含まれているのは:
1 親
cecafb8d88
コミット
f5b38e1af8
11ファイル変更
+67
-75
検索条件に一致するファイルはありません
-6
@@ -51,12 +51,6 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
string fieldName = fieldSymbol.Name;
|
||||
string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
|
||||
|
||||
// Disambiguates the name of target fields against the current input parameters
|
||||
if (fieldName is "loader")
|
||||
{
|
||||
fieldName = $"this.{fieldName}";
|
||||
}
|
||||
|
||||
// The first item in each nested struct needs to be aligned to 16 bytes
|
||||
if (isFirstField && fieldPath.Length > 0)
|
||||
{
|
||||
|
||||
+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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Descriptors;
|
||||
|
||||
namespace ComputeSharp.Tests.Internals.Helpers;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Descriptors;
|
||||
using ComputeSharp.Tests.Internals.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -28,18 +28,18 @@ public partial class ShaderDataLoaderTests
|
||||
CapturedResourceShader shader = new(buffer);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<CapturedResourceShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(12, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(12, ((IComputeShaderDescriptor<CapturedResourceShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(12, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[4]));
|
||||
Assert.AreEqual(333, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[8]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<CapturedResourceShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<CapturedResourceShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
@@ -68,9 +68,9 @@ public partial class ShaderDataLoaderTests
|
||||
MultipleResourcesAndPrimitivesShader shader = new(buffer0, buffer1, 1, 22, 77);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<MultipleResourcesAndPrimitivesShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(24, ((IComputeShaderDescriptor<MultipleResourcesAndPrimitivesShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(24, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -80,9 +80,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(77, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[20]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<MultipleResourcesAndPrimitivesShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(2, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(2, ((IComputeShaderDescriptor<MultipleResourcesAndPrimitivesShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer0, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
Assert.AreSame(buffer1, dataLoader.GraphicsResources[1].Resource);
|
||||
@@ -114,9 +114,9 @@ public partial class ShaderDataLoaderTests
|
||||
ScalarAndVectorTypesShader shader = new(buffer, new(55, 44, 888), 22, 77, new(3.14, 6.28), 42, 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<ScalarAndVectorTypesShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(72, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(72, ((IComputeShaderDescriptor<ScalarAndVectorTypesShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(72, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -132,9 +132,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[64]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[68]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<ScalarAndVectorTypesShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<ScalarAndVectorTypesShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
@@ -175,9 +175,9 @@ public partial class ShaderDataLoaderTests
|
||||
d: 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<ScalarVectorAndMatrixTypesShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(124, ((IComputeShaderDescriptor<ScalarVectorAndMatrixTypesShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(124, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -204,9 +204,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(44, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[116]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[120]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<ScalarVectorAndMatrixTypesShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<ScalarVectorAndMatrixTypesShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
@@ -254,9 +254,9 @@ public partial class ShaderDataLoaderTests
|
||||
d: 9999));
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<FlatCustomTypeShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(124, ((IComputeShaderDescriptor<FlatCustomTypeShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(124, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -283,9 +283,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(44, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[116]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[120]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<FlatCustomTypeShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<FlatCustomTypeShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
@@ -357,9 +357,9 @@ public partial class ShaderDataLoaderTests
|
||||
b: new(333.3f, 444.4f))));
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<NestedCustomTypesShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(188, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(188, ((IComputeShaderDescriptor<NestedCustomTypesShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(188, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -399,9 +399,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(333.3f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[180]));
|
||||
Assert.AreEqual(444.4f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[184]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<NestedCustomTypesShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<NestedCustomTypesShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
@@ -438,9 +438,9 @@ public partial class ShaderDataLoaderTests
|
||||
AmbiguousNamesShader shader = new(a, b, c, x, y, z, 7777, 8888, 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
((IComputeShaderDescriptor<AmbiguousNamesShader>)shader).LoadConstantBuffer(in shader, ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.AreEqual(24, ((IComputeShaderDescriptor<AmbiguousNamesShader>)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(24, dataLoader.ConstantBuffer.Length);
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[0]));
|
||||
@@ -450,9 +450,9 @@ public partial class ShaderDataLoaderTests
|
||||
Assert.AreEqual(8888, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[20]));
|
||||
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
((IComputeShaderDescriptor<AmbiguousNamesShader>)shader).LoadGraphicsResources(in shader, ref dataLoader);
|
||||
|
||||
Assert.AreEqual(6, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreEqual(6, ((IComputeShaderDescriptor<AmbiguousNamesShader>)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(a, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
Assert.AreSame(b, dataLoader.GraphicsResources[1].Resource);
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Descriptors;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
@@ -169,7 +170,7 @@ public class ShadersTests
|
||||
if (typeof(IComputeShader).IsAssignableFrom(shaderType))
|
||||
{
|
||||
static void RunComputeShader<T>(ReadWriteTexture2D<Rgba32, float4> texture)
|
||||
where T : struct, IComputeShader
|
||||
where T : struct, IComputeShader, IComputeShaderDescriptor<T>
|
||||
{
|
||||
ShaderInfo info = ReflectionServices.GetShaderInfo<T>();
|
||||
|
||||
@@ -185,7 +186,7 @@ public class ShadersTests
|
||||
else
|
||||
{
|
||||
static void RunPixelShader<T>(ReadWriteTexture2D<Rgba32, float4> texture)
|
||||
where T : struct, IComputeShader<float4>
|
||||
where T : struct, IComputeShader<float4>, IComputeShaderDescriptor<T>
|
||||
{
|
||||
ShaderInfo info = ReflectionServices.GetShaderInfo<T, float4>();
|
||||
|
||||
@@ -229,8 +230,8 @@ public class ShadersTests
|
||||
Func<ReadWriteTexture2D<Rgba32, float4>, TCompute> computeFactory,
|
||||
Func<ReadWriteTexture2D<Rgba32, float4>, TPixel> pixelFactory,
|
||||
float delta)
|
||||
where TCompute : struct, IComputeShader
|
||||
where TPixel : struct, IComputeShader<float4>
|
||||
where TCompute : struct, IComputeShader, IComputeShaderDescriptor<TCompute>
|
||||
where TPixel : struct, IComputeShader<float4>, IComputeShaderDescriptor<TPixel>
|
||||
{
|
||||
_ = device.Get();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Descriptors;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests;
|
||||
@@ -10,21 +10,21 @@ public partial class ThreadGroupSizeTests
|
||||
[TestMethod]
|
||||
public unsafe void Verify_ThreadGroupSize()
|
||||
{
|
||||
Assert.AreEqual(64, ((IShader)default(DispatchXShader)).ThreadsX);
|
||||
Assert.AreEqual(1, ((IShader)default(DispatchXShader)).ThreadsY);
|
||||
Assert.AreEqual(1, ((IShader)default(DispatchXShader)).ThreadsZ);
|
||||
Assert.AreEqual(64, ((IComputeShaderDescriptor<DispatchXShader>)default(DispatchXShader)).ThreadsX);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<DispatchXShader>)default(DispatchXShader)).ThreadsY);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<DispatchXShader>)default(DispatchXShader)).ThreadsZ);
|
||||
|
||||
Assert.AreEqual(8, ((IShader)default(DispatchXYShader)).ThreadsX);
|
||||
Assert.AreEqual(8, ((IShader)default(DispatchXYShader)).ThreadsY);
|
||||
Assert.AreEqual(1, ((IShader)default(DispatchXYShader)).ThreadsZ);
|
||||
Assert.AreEqual(8, ((IComputeShaderDescriptor<DispatchXYShader>)default(DispatchXYShader)).ThreadsX);
|
||||
Assert.AreEqual(8, ((IComputeShaderDescriptor<DispatchXYShader>)default(DispatchXYShader)).ThreadsY);
|
||||
Assert.AreEqual(1, ((IComputeShaderDescriptor<DispatchXYShader>)default(DispatchXYShader)).ThreadsZ);
|
||||
|
||||
Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsX);
|
||||
Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsY);
|
||||
Assert.AreEqual(4, ((IShader)default(DispatchXYZShader)).ThreadsZ);
|
||||
Assert.AreEqual(4, ((IComputeShaderDescriptor<DispatchXYZShader>)default(DispatchXYZShader)).ThreadsX);
|
||||
Assert.AreEqual(4, ((IComputeShaderDescriptor<DispatchXYZShader>)default(DispatchXYZShader)).ThreadsY);
|
||||
Assert.AreEqual(4, ((IComputeShaderDescriptor<DispatchXYZShader>)default(DispatchXYZShader)).ThreadsZ);
|
||||
|
||||
Assert.AreEqual(11, ((IShader)default(DispatchCustomShader)).ThreadsX);
|
||||
Assert.AreEqual(14, ((IShader)default(DispatchCustomShader)).ThreadsY);
|
||||
Assert.AreEqual(6, ((IShader)default(DispatchCustomShader)).ThreadsZ);
|
||||
Assert.AreEqual(11, ((IComputeShaderDescriptor<DispatchCustomShader>)default(DispatchCustomShader)).ThreadsX);
|
||||
Assert.AreEqual(14, ((IComputeShaderDescriptor<DispatchCustomShader>)default(DispatchCustomShader)).ThreadsY);
|
||||
Assert.AreEqual(6, ((IComputeShaderDescriptor<DispatchCustomShader>)default(DispatchCustomShader)).ThreadsZ);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする