Add output tests for DX12 source generator
このコミットが含まれているのは:
1 親
997f4917a9
コミット
cf00f747bc
2ファイル変更
+945
-6
検索条件に一致するファイルはありません
@@ -35,7 +35,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
private readonly float time;
|
||||
private readonly int2 dispatchSize;
|
||||
@@ -337,7 +337,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
private readonly float time;
|
||||
private readonly int2 dispatchSize;
|
||||
@@ -689,7 +689,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
private readonly float time;
|
||||
private readonly int2 dispatchSize;
|
||||
@@ -990,7 +990,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader(float time, int2 dispatchSize) : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader(float time, int2 dispatchSize) : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
@@ -1288,7 +1288,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DInputDescription(0, D2D1Filter.MinMagMipPoint)]
|
||||
[D2DInputDescription(1, D2D1Filter.Anisotropic)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public float4 Execute()
|
||||
{
|
||||
@@ -1571,7 +1571,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
public partial struct MyShader : ID2D1PixelShader
|
||||
internal readonly partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private readonly D2D1ResourceTexture2D<float> texture;
|
||||
|
||||
@@ -0,0 +1,939 @@
|
||||
extern alias Core;
|
||||
extern alias D3D12;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Basic.Reference.Assemblies;
|
||||
using ComputeSharp.SourceGenerators;
|
||||
using ComputeSharp.Tests.SourceGenerators.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ComputeSharp.Tests.SourceGenerators;
|
||||
|
||||
[TestClass]
|
||||
public class Test_D2DPixelShaderSourceGenerator
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task SimpleShader_ComputeShader()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using float2 = global::ComputeSharp.Float2;
|
||||
using float3 = global::ComputeSharp.Float3;
|
||||
using float4 = global::ComputeSharp.Float4;
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
||||
[GeneratedComputeShaderDescriptor]
|
||||
internal readonly partial struct MyShader : IComputeShader
|
||||
{
|
||||
private readonly IReadWriteNormalizedTexture2D<float4> texture;
|
||||
private readonly float time;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float2 uv = ThreadIds.Normalized.XY;
|
||||
float3 col = 0.5f + 0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4));
|
||||
texture[ThreadIds.XY] = new float4(col, 1f);
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
const string result = """"
|
||||
// <auto-generated/>
|
||||
#pragma warning disable
|
||||
|
||||
namespace MyNamespace
|
||||
{
|
||||
/// <inheritdoc cref="MyShader"/>
|
||||
partial struct MyShader : global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsX => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsY => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsZ => 1;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ConstantBufferSize => 16;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.IsStaticSamplerRequired => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<global::ComputeSharp.Interop.ResourceDescriptorRange> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ResourceDescriptorRanges => global::ComputeSharp.Generated.Data.ResourceDescriptorRanges;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static string global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslSource =>
|
||||
"""
|
||||
// ================================================
|
||||
// AUTO GENERATED
|
||||
// ================================================
|
||||
// This shader was created by ComputeSharp.
|
||||
// See: https://github.com/Sergio0694/ComputeSharp.
|
||||
|
||||
#define __GroupSize__get_X 8
|
||||
#define __GroupSize__get_Y 8
|
||||
#define __GroupSize__get_Z 1
|
||||
|
||||
cbuffer _ : register(b0)
|
||||
{
|
||||
uint __x;
|
||||
uint __y;
|
||||
uint __z;
|
||||
float time;
|
||||
}
|
||||
|
||||
RWTexture2D<unorm float4> __reserved__texture : register(u0);
|
||||
|
||||
[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]
|
||||
void Execute(uint3 ThreadIds : SV_DispatchThreadID)
|
||||
{
|
||||
if (ThreadIds.x < __x && ThreadIds.y < __y && ThreadIds.z < __z)
|
||||
{
|
||||
float2 uv = float2(ThreadIds.x, ThreadIds.y) / float2(max(1, int2(__x, __y) - 1));
|
||||
float3 col = 0.5 + 0.5 * cos(time + float3(uv, uv.x) + float3(0, 2, 4));
|
||||
__reserved__texture[ThreadIds.xy] = float4(col, 1.0);
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<byte> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslBytecode => global::ComputeSharp.Generated.HlslBytecodeMemoryManager.Instance.Memory;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
[global::System.Runtime.CompilerServices.SkipLocalsInit]
|
||||
static unsafe void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadConstantBuffer<TLoader>(in MyShader shader, ref TLoader loader, int x, int y, int z)
|
||||
{
|
||||
global::ComputeSharp.Generated.ConstantBufferMarshaller.FromManaged(in shader, out global::ComputeSharp.Generated.ConstantBuffer buffer);
|
||||
|
||||
buffer.__x = x;
|
||||
buffer.__y = y;
|
||||
buffer.__z = z;
|
||||
|
||||
loader.LoadConstantBuffer(new global::System.ReadOnlySpan<byte>(&buffer, sizeof(global::ComputeSharp.Generated.ConstantBuffer)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadGraphicsResources<TLoader>(in MyShader shader, ref TLoader loader)
|
||||
{
|
||||
global::ComputeSharp.Generated.GraphicsResourcesLoader.LoadGraphicsResources(in shader, ref loader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace ComputeSharp.Generated
|
||||
{
|
||||
using global::System;
|
||||
using global::System.Buffers;
|
||||
using global::System.CodeDom.Compiler;
|
||||
using global::System.Diagnostics;
|
||||
using global::System.Diagnostics.CodeAnalysis;
|
||||
using global::System.Runtime.CompilerServices;
|
||||
using global::System.Runtime.InteropServices;
|
||||
using global::ComputeSharp.Descriptors;
|
||||
using global::ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing the constant buffer native layout for <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
file struct ConstantBuffer
|
||||
{
|
||||
/// <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;
|
||||
|
||||
/// <summary>The artificial field backing <see cref="DispatchSize.Z"/>.</summary>
|
||||
[FieldOffset(8)]
|
||||
public int __z;
|
||||
|
||||
/// <inheritdoc cref="global::MyNamespace.MyShader.time"/>
|
||||
[FieldOffset(12)]
|
||||
public float time;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type containing marshalling logic for the constant buffer in shaders of type <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class ConstantBufferMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Marshals managed <see cref="global::MyNamespace.MyShader"/> instances to native constant buffer data.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input native constant buffer.</param>
|
||||
/// <returns>The marshalled <see cref="global::MyNamespace.MyShader"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[SkipLocalsInit]
|
||||
public static void FromManaged(in global::MyNamespace.MyShader shader, out ConstantBuffer buffer)
|
||||
{
|
||||
Unsafe.SkipInit(out buffer.__x);
|
||||
Unsafe.SkipInit(out buffer.__y);
|
||||
Unsafe.SkipInit(out buffer.__z);
|
||||
|
||||
buffer.time = shader.time();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="global::MyNamespace.MyShader.time"/>
|
||||
/// <param name="value">The input <see cref="global::MyNamespace.MyShader"/> value.</param>
|
||||
/// <returns>A mutable reference to <see cref="global::MyNamespace.MyShader.time"/>.</returns>
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field)]
|
||||
private static extern ref float time(this ref readonly global::MyNamespace.MyShader value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type containing loading logic for graphics resources in shaders of type <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class GraphicsResourcesLoader
|
||||
{
|
||||
/// <inheritdoc cref="IComputeShaderDescriptor{T}.LoadGraphicsResources"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LoadGraphicsResources<TLoader>(in global::MyNamespace.MyShader shader, ref TLoader loader)
|
||||
where TLoader : struct, IGraphicsResourceLoader
|
||||
{
|
||||
loader.LoadGraphicsResource(shader.texture(), 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="global::MyNamespace.MyShader.texture"/>
|
||||
/// <param name="value">The input <see cref="global::MyNamespace.MyShader"/> value.</param>
|
||||
/// <returns>A reference to <see cref="global::MyNamespace.MyShader.texture"/>.</returns>
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field)]
|
||||
private static extern ref readonly IReadWriteNormalizedTexture2D<float4> texture(this ref readonly global::MyNamespace.MyShader value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A container type for additional data needed by the shader.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class Data
|
||||
{
|
||||
/// <summary>The singleton <see cref="ResourceDescriptorRange"/> array instance.</summary>
|
||||
public static readonly ResourceDescriptorRange[] ResourceDescriptorRanges =
|
||||
[
|
||||
new ResourceDescriptorRange(ResourceDescriptorRangeType.UnorderedAccessView, 0)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MemoryManager{T}"/> implementation to get the HLSL bytecode.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file sealed class HlslBytecodeMemoryManager : MemoryManager<byte>
|
||||
{
|
||||
/// <summary>The singleton <see cref="HlslBytecodeMemoryManager"/> instance to use.</summary>
|
||||
public static readonly HlslBytecodeMemoryManager Instance = new();
|
||||
|
||||
/// <summary>The RVA data with the HLSL bytecode.</summary>
|
||||
private static ReadOnlySpan<byte> Data => [0x44, 0x58, 0x42, 0x43, 0x85, 0xAB, 0x89, 0xA8, 0x68, 0x86, 0x6C, 0x2B, 0x90, 0xB8, 0x38, 0x75, 0x15, 0x08, 0xEE, 0x86, 0x01, 0x00, 0x00, 0x00, 0xA0, 0x0E, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, 0x88, 0x07, 0x00, 0x00, 0xA4, 0x07, 0x00, 0x00, 0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4F, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x53, 0x56, 0x30, 0x78, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x94, 0x06, 0x00, 0x00, 0x60, 0x00, 0x05, 0x00, 0xA5, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4C, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x7C, 0x06, 0x00, 0x00, 0x42, 0x43, 0xC0, 0xDE, 0x21, 0x0C, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x0B, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xC8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0C, 0x25, 0x05, 0x08, 0x19, 0x1E, 0x04, 0x8B, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0B, 0x42, 0xA4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4B, 0x0A, 0x32, 0x52, 0x88, 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5, 0x00, 0x19, 0x32, 0x42, 0xE4, 0x48, 0x0E, 0x90, 0x91, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C, 0xE1, 0x83, 0xE5, 0x8A, 0x04, 0x29, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1B, 0x8C, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x40, 0x02, 0xA8, 0x0D, 0x84, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x20, 0x6D, 0x30, 0x86, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x09, 0xA8, 0x00, 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4C, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xA4, 0x84, 0x04, 0x93, 0x22, 0xE3, 0x84, 0xA1, 0x90, 0x14, 0x12, 0x4C, 0x8A, 0x8C, 0x0B, 0x84, 0xA4, 0x4C, 0x10, 0x7C, 0x23, 0x00, 0x25, 0x00, 0x14, 0xE6, 0x08, 0xC0, 0xA0, 0x0C, 0x63, 0x0C, 0x22, 0x85, 0x18, 0x63, 0x0C, 0x32, 0x33, 0x00, 0x65, 0x40, 0x03, 0x51, 0x9A, 0x23, 0x40, 0x68, 0xDD, 0x33, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x87, 0x40, 0x33, 0x2C, 0x04, 0x0A, 0x58, 0x59, 0xC0, 0x68, 0x63, 0x0C, 0x84, 0x10, 0x5A, 0xE4, 0x8E, 0x1A, 0x2E, 0x7F, 0xC2, 0x1E, 0x42, 0xF2, 0xB9, 0x8D, 0x2A, 0x56, 0x62, 0xF2, 0x8B, 0xDB, 0x46, 0x04, 0x42, 0x08, 0x15, 0x02, 0x8E, 0x36, 0x28, 0x1E, 0x35, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x73, 0x1B, 0x55, 0xAC, 0xC4, 0xE4, 0x23, 0xB7, 0x8D, 0x88, 0x31, 0xC6, 0x28, 0xC4, 0x1C, 0x6D, 0x10, 0x9D, 0x23, 0x08, 0x8A, 0xD1, 0xC6, 0x1A, 0xC3, 0xD2, 0x1D, 0x08, 0x18, 0x46, 0x20, 0x90, 0x99, 0xC8, 0x60, 0x1C, 0xD8, 0x21, 0x1C, 0xE6, 0x61, 0x1E, 0xDC, 0x40, 0x16, 0x6E, 0x81, 0x16, 0xCA, 0x01, 0x1F, 0xE8, 0xA1, 0x1E, 0xE4, 0xA1, 0x1C, 0xE4, 0x80, 0x14, 0xF8, 0xC0, 0x1E, 0xCA, 0x61, 0x1C, 0xE8, 0xE1, 0x1D, 0xE4, 0x81, 0x0F, 0xCC, 0x81, 0x1D, 0xDE, 0x21, 0x1C, 0xE8, 0x81, 0x0D, 0xC0, 0x80, 0x0E, 0xFC, 0x00, 0x0C, 0xFC, 0x00, 0x05, 0x9A, 0xF6, 0x05, 0x3F, 0x22, 0xC6, 0x18, 0x88, 0x3A, 0x00, 0x00, 0x13, 0x14, 0x72, 0xC0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xC0, 0x87, 0x0D, 0xAF, 0x50, 0x0E, 0x6D, 0xD0, 0x0E, 0x7A, 0x50, 0x0E, 0x6D, 0x00, 0x0F, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x78, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE9, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x76, 0x40, 0x07, 0x7A, 0x60, 0x07, 0x74, 0xD0, 0x06, 0xE6, 0x10, 0x07, 0x76, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x60, 0x0E, 0x73, 0x20, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE6, 0x60, 0x07, 0x74, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x6D, 0xE0, 0x0E, 0x78, 0xA0, 0x07, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9E, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3C, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x79, 0x0C, 0x20, 0x00, 0x02, 0x00行の続きは省略
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe Span<byte> GetSpan()
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Memory<byte> Memory
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CreateMemory(Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe MemoryHandle Pin(int elementIndex)
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Unpin()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyShader.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SimpleShader_PixelShader()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using float2 = global::ComputeSharp.Float2;
|
||||
using float3 = global::ComputeSharp.Float3;
|
||||
using float4 = global::ComputeSharp.Float4;
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
||||
[GeneratedComputeShaderDescriptor]
|
||||
internal readonly partial struct MyShader : IComputeShader<float4>
|
||||
{
|
||||
private readonly float time;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
float2 uv = ThreadIds.Normalized.XY;
|
||||
float3 col = 0.5f + 0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4));
|
||||
return new(col, 1f);
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
const string result = """"
|
||||
// <auto-generated/>
|
||||
#pragma warning disable
|
||||
|
||||
namespace MyNamespace
|
||||
{
|
||||
/// <inheritdoc cref="MyShader"/>
|
||||
partial struct MyShader : global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsX => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsY => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsZ => 1;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ConstantBufferSize => 12;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.IsStaticSamplerRequired => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<global::ComputeSharp.Interop.ResourceDescriptorRange> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ResourceDescriptorRanges => global::ComputeSharp.Generated.Data.ResourceDescriptorRanges;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static string global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslSource =>
|
||||
"""
|
||||
// ================================================
|
||||
// AUTO GENERATED
|
||||
// ================================================
|
||||
// This shader was created by ComputeSharp.
|
||||
// See: https://github.com/Sergio0694/ComputeSharp.
|
||||
|
||||
#define __GroupSize__get_X 8
|
||||
#define __GroupSize__get_Y 8
|
||||
#define __GroupSize__get_Z 1
|
||||
|
||||
cbuffer _ : register(b0)
|
||||
{
|
||||
uint __x;
|
||||
uint __y;
|
||||
float time;
|
||||
}
|
||||
|
||||
RWTexture2D<unorm float4> __outputTexture : register(u0);
|
||||
|
||||
[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]
|
||||
void Execute(uint3 ThreadIds : SV_DispatchThreadID)
|
||||
{
|
||||
if (ThreadIds.x < __x && ThreadIds.y < __y)
|
||||
{
|
||||
float2 uv = float2(ThreadIds.x, ThreadIds.y) / float2(max(1, int2(__x, __y) - 1));
|
||||
float3 col = 0.5 + 0.5 * cos(time + float3(uv, uv.x) + float3(0, 2, 4));
|
||||
{
|
||||
__outputTexture[ThreadIds.xy] = float4(col, 1.0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<byte> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslBytecode => global::ComputeSharp.Generated.HlslBytecodeMemoryManager.Instance.Memory;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
[global::System.Runtime.CompilerServices.SkipLocalsInit]
|
||||
static unsafe void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadConstantBuffer<TLoader>(in MyShader shader, ref TLoader loader, int x, int y, int z)
|
||||
{
|
||||
global::ComputeSharp.Generated.ConstantBufferMarshaller.FromManaged(in shader, out global::ComputeSharp.Generated.ConstantBuffer buffer);
|
||||
|
||||
buffer.__x = x;
|
||||
buffer.__y = y;
|
||||
loader.LoadConstantBuffer(new global::System.ReadOnlySpan<byte>(&buffer, sizeof(global::ComputeSharp.Generated.ConstantBuffer)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadGraphicsResources<TLoader>(in MyShader shader, ref TLoader loader)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace ComputeSharp.Generated
|
||||
{
|
||||
using global::System;
|
||||
using global::System.Buffers;
|
||||
using global::System.CodeDom.Compiler;
|
||||
using global::System.Diagnostics;
|
||||
using global::System.Diagnostics.CodeAnalysis;
|
||||
using global::System.Runtime.CompilerServices;
|
||||
using global::System.Runtime.InteropServices;
|
||||
using global::ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing the constant buffer native layout for <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12)]
|
||||
file struct ConstantBuffer
|
||||
{
|
||||
/// <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;
|
||||
|
||||
/// <inheritdoc cref="global::MyNamespace.MyShader.time"/>
|
||||
[FieldOffset(8)]
|
||||
public float time;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type containing marshalling logic for the constant buffer in shaders of type <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class ConstantBufferMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Marshals managed <see cref="global::MyNamespace.MyShader"/> instances to native constant buffer data.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input native constant buffer.</param>
|
||||
/// <returns>The marshalled <see cref="global::MyNamespace.MyShader"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[SkipLocalsInit]
|
||||
public static void FromManaged(in global::MyNamespace.MyShader shader, out ConstantBuffer buffer)
|
||||
{
|
||||
Unsafe.SkipInit(out buffer.__x);
|
||||
Unsafe.SkipInit(out buffer.__y);
|
||||
|
||||
buffer.time = shader.time();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="global::MyNamespace.MyShader.time"/>
|
||||
/// <param name="value">The input <see cref="global::MyNamespace.MyShader"/> value.</param>
|
||||
/// <returns>A mutable reference to <see cref="global::MyNamespace.MyShader.time"/>.</returns>
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field)]
|
||||
private static extern ref float time(this ref readonly global::MyNamespace.MyShader value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A container type for additional data needed by the shader.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class Data
|
||||
{
|
||||
/// <summary>The singleton <see cref="ResourceDescriptorRange"/> array instance.</summary>
|
||||
public static readonly ResourceDescriptorRange[] ResourceDescriptorRanges =
|
||||
[
|
||||
new ResourceDescriptorRange(ResourceDescriptorRangeType.UnorderedAccessView, 0)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MemoryManager{T}"/> implementation to get the HLSL bytecode.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file sealed class HlslBytecodeMemoryManager : MemoryManager<byte>
|
||||
{
|
||||
/// <summary>The singleton <see cref="HlslBytecodeMemoryManager"/> instance to use.</summary>
|
||||
public static readonly HlslBytecodeMemoryManager Instance = new();
|
||||
|
||||
/// <summary>The RVA data with the HLSL bytecode.</summary>
|
||||
private static ReadOnlySpan<byte> Data => [0x44, 0x58, 0x42, 0x43, 0xE2, 0xA1, 0x14, 0x53, 0xC8, 0x8F, 0xCF, 0x58, 0x57, 0x3E, 0x4A, 0xC2, 0x7F, 0xDD, 0xFE, 0x93, 0x01, 0x00, 0x00, 0x00, 0x60, 0x0E, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, 0x64, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4F, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x53, 0x56, 0x30, 0x78, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x70, 0x06, 0x00, 0x00, 0x60, 0x00, 0x05, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4C, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x58, 0x06, 0x00, 0x00, 0x42, 0x43, 0xC0, 0xDE, 0x21, 0x0C, 0x00, 0x00, 0x93, 0x01, 0x00, 0x00, 0x0B, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xC8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0C, 0x25, 0x05, 0x08, 0x19, 0x1E, 0x04, 0x8B, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0B, 0x42, 0xA4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4B, 0x0A, 0x32, 0x52, 0x88, 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5, 0x00, 0x19, 0x32, 0x42, 0xE4, 0x48, 0x0E, 0x90, 0x91, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C, 0xE1, 0x83, 0xE5, 0x8A, 0x04, 0x29, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1B, 0x8C, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x40, 0x02, 0xA8, 0x0D, 0x84, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x20, 0x6D, 0x30, 0x86, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x09, 0xA8, 0x00, 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4C, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xA4, 0x84, 0x04, 0x93, 0x22, 0xE3, 0x84, 0xA1, 0x90, 0x14, 0x12, 0x4C, 0x8A, 0x8C, 0x0B, 0x84, 0xA4, 0x4C, 0x10, 0x7C, 0x23, 0x00, 0x25, 0x00, 0x14, 0xE6, 0x08, 0xC0, 0xA0, 0x0C, 0x63, 0x0C, 0x22, 0x85, 0x18, 0x63, 0x0C, 0x32, 0x33, 0x00, 0x65, 0x40, 0x03, 0x51, 0x9A, 0x23, 0x40, 0x68, 0xDD, 0x33, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x87, 0x40, 0x33, 0x2C, 0x04, 0x0A, 0x58, 0x59, 0xC0, 0x68, 0x63, 0x0C, 0x84, 0x10, 0x5A, 0xE4, 0x8E, 0x1A, 0x2E, 0x7F, 0xC2, 0x1E, 0x42, 0xF2, 0xB9, 0x8D, 0x2A, 0x56, 0x62, 0xF2, 0x8B, 0xDB, 0x46, 0x04, 0x42, 0x08, 0x15, 0x02, 0x8E, 0x36, 0x28, 0x1E, 0x35, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x73, 0x1B, 0x55, 0xAC, 0xC4, 0xE4, 0x23, 0xB7, 0x8D, 0x88, 0x31, 0xC6, 0x28, 0xC4, 0x1C, 0x6D, 0x10, 0x9D, 0x23, 0x08, 0x8A, 0xD1, 0xC6, 0x1A, 0xC3, 0xD2, 0x1D, 0x08, 0x18, 0x46, 0x20, 0x90, 0x99, 0xC8, 0x60, 0x1C, 0xD8, 0x21, 0x1C, 0xE6, 0x61, 0x1E, 0xDC, 0x40, 0x16, 0x6E, 0x81, 0x16, 0xCA, 0x01, 0x1F, 0xE8, 0xA1, 0x1E, 0xE4, 0xA1, 0x1C, 0xE4, 0x80, 0x14, 0xF8, 0xC0, 0x1E, 0xCA, 0x61, 0x1C, 0xE8, 0xE1, 0x1D, 0xE4, 0x81, 0x0F, 0xCC, 0x81, 0x1D, 0xDE, 0x21, 0x1C, 0xE8, 0x81, 0x0D, 0xC0, 0x80, 0x0E, 0xFC, 0x00, 0x0C, 0xFC, 0x00, 0x05, 0x9A, 0xF6, 0x05, 0x3F, 0x1A, 0xC6, 0x40, 0xD4, 0x01, 0x00, 0x00, 0x13, 0x14, 0x72, 0xC0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xC0, 0x87, 0x0D, 0xAF, 0x50, 0x0E, 0x6D, 0xD0, 0x0E, 0x7A, 0x50, 0x0E, 0x6D, 0x00, 0x0F, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x78, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE9, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x76, 0x40, 0x07, 0x7A, 0x60, 0x07, 0x74, 0xD0, 0x06, 0xE6, 0x10, 0x07, 0x76, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x60, 0x0E, 0x73, 0x20, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE6, 0x60, 0x07, 0x74, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x6D, 0xE0, 0x0E, 0x78, 0xA0, 0x07, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9E, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3C, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x79, 0x0C, 0x20, 0x00, 0x02, 0x00行の続きは省略
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe Span<byte> GetSpan()
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Memory<byte> Memory
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CreateMemory(Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe MemoryHandle Pin(int elementIndex)
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Unpin()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyShader.g.cs", result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SimpleShader_WithPrimaryConstructorParameters()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using float2 = global::ComputeSharp.Float2;
|
||||
using float3 = global::ComputeSharp.Float3;
|
||||
using float4 = global::ComputeSharp.Float4;
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
||||
[GeneratedComputeShaderDescriptor]
|
||||
internal readonly partial struct MyShader(
|
||||
IReadWriteNormalizedTexture2D<float4> texture,
|
||||
float time) : IComputeShader
|
||||
{
|
||||
public void Execute()
|
||||
{
|
||||
float2 uv = ThreadIds.Normalized.XY;
|
||||
float3 col = 0.5f + 0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4));
|
||||
texture[ThreadIds.XY] = new float4(col, 1f);
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
const string result = """"
|
||||
// <auto-generated/>
|
||||
#pragma warning disable
|
||||
|
||||
namespace MyNamespace
|
||||
{
|
||||
/// <inheritdoc cref="MyShader"/>
|
||||
partial struct MyShader : global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsX => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsY => 8;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ThreadsZ => 1;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static int global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ConstantBufferSize => 16;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static bool global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.IsStaticSamplerRequired => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<global::ComputeSharp.Interop.ResourceDescriptorRange> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.ResourceDescriptorRanges => global::ComputeSharp.Generated.Data.ResourceDescriptorRanges;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static string global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslSource =>
|
||||
"""
|
||||
// ================================================
|
||||
// AUTO GENERATED
|
||||
// ================================================
|
||||
// This shader was created by ComputeSharp.
|
||||
// See: https://github.com/Sergio0694/ComputeSharp.
|
||||
|
||||
#define __GroupSize__get_X 8
|
||||
#define __GroupSize__get_Y 8
|
||||
#define __GroupSize__get_Z 1
|
||||
|
||||
cbuffer _ : register(b0)
|
||||
{
|
||||
uint __x;
|
||||
uint __y;
|
||||
uint __z;
|
||||
float time;
|
||||
}
|
||||
|
||||
RWTexture2D<unorm float4> __reserved__texture : register(u0);
|
||||
|
||||
[NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)]
|
||||
void Execute(uint3 ThreadIds : SV_DispatchThreadID)
|
||||
{
|
||||
if (ThreadIds.x < __x && ThreadIds.y < __y && ThreadIds.z < __z)
|
||||
{
|
||||
float2 uv = float2(ThreadIds.x, ThreadIds.y) / float2(max(1, int2(__x, __y) - 1));
|
||||
float3 col = 0.5 + 0.5 * cos(time + float3(uv, uv.x) + float3(0, 2, 4));
|
||||
__reserved__texture[ThreadIds.xy] = float4(col, 1.0);
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static global::System.ReadOnlyMemory<byte> global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.HlslBytecode => global::ComputeSharp.Generated.HlslBytecodeMemoryManager.Instance.Memory;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
[global::System.Runtime.CompilerServices.SkipLocalsInit]
|
||||
static unsafe void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadConstantBuffer<TLoader>(in MyShader shader, ref TLoader loader, int x, int y, int z)
|
||||
{
|
||||
global::ComputeSharp.Generated.ConstantBufferMarshaller.FromManaged(in shader, out global::ComputeSharp.Generated.ConstantBuffer buffer);
|
||||
|
||||
buffer.__x = x;
|
||||
buffer.__y = y;
|
||||
buffer.__z = z;
|
||||
|
||||
loader.LoadConstantBuffer(new global::System.ReadOnlySpan<byte>(&buffer, sizeof(global::ComputeSharp.Generated.ConstantBuffer)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[global::System.Diagnostics.DebuggerNonUserCode]
|
||||
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
static void global::ComputeSharp.Descriptors.IComputeShaderDescriptor<MyShader>.LoadGraphicsResources<TLoader>(in MyShader shader, ref TLoader loader)
|
||||
{
|
||||
global::ComputeSharp.Generated.GraphicsResourcesLoader.LoadGraphicsResources(in shader, ref loader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace ComputeSharp.Generated
|
||||
{
|
||||
using global::System;
|
||||
using global::System.Buffers;
|
||||
using global::System.CodeDom.Compiler;
|
||||
using global::System.Diagnostics;
|
||||
using global::System.Diagnostics.CodeAnalysis;
|
||||
using global::System.Runtime.CompilerServices;
|
||||
using global::System.Runtime.InteropServices;
|
||||
using global::ComputeSharp.Descriptors;
|
||||
using global::ComputeSharp.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing the constant buffer native layout for <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
file struct ConstantBuffer
|
||||
{
|
||||
/// <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;
|
||||
|
||||
/// <summary>The artificial field backing <see cref="DispatchSize.Z"/>.</summary>
|
||||
[FieldOffset(8)]
|
||||
public int __z;
|
||||
|
||||
/// <summary>The unspeakable field "time" of <see cref="global::MyNamespace.MyShader"/>.</summary>
|
||||
[FieldOffset(12)]
|
||||
public float time;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type containing marshalling logic for the constant buffer in shaders of type <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class ConstantBufferMarshaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Marshals managed <see cref="global::MyNamespace.MyShader"/> instances to native constant buffer data.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The input native constant buffer.</param>
|
||||
/// <returns>The marshalled <see cref="global::MyNamespace.MyShader"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[SkipLocalsInit]
|
||||
public static void FromManaged(in global::MyNamespace.MyShader shader, out ConstantBuffer buffer)
|
||||
{
|
||||
Unsafe.SkipInit(out buffer.__x);
|
||||
Unsafe.SkipInit(out buffer.__y);
|
||||
Unsafe.SkipInit(out buffer.__z);
|
||||
|
||||
buffer.time = shader.time();
|
||||
}
|
||||
|
||||
/// <summary>Gets a reference to the unspeakable field "time" of type <see cref="global::MyNamespace.MyShader"/>.</summary>
|
||||
/// <param name="value">The input <see cref="global::MyNamespace.MyShader"/> value.</param>
|
||||
/// <returns>A mutable reference to the unspeakable field "time".</returns>
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<time>P")]
|
||||
private static extern ref float time(this ref readonly global::MyNamespace.MyShader value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type containing loading logic for graphics resources in shaders of type <see cref="global::MyNamespace.MyShader"/>.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class GraphicsResourcesLoader
|
||||
{
|
||||
/// <inheritdoc cref="IComputeShaderDescriptor{T}.LoadGraphicsResources"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LoadGraphicsResources<TLoader>(in global::MyNamespace.MyShader shader, ref TLoader loader)
|
||||
where TLoader : struct, IGraphicsResourceLoader
|
||||
{
|
||||
loader.LoadGraphicsResource(shader.texture(), 0);
|
||||
}
|
||||
|
||||
/// <summary>Gets a reference to the unspeakable field "texture" of type <see cref="global::MyNamespace.MyShader"/>.</summary>
|
||||
/// <param name="value">The input <see cref="global::MyNamespace.MyShader"/> value.</param>
|
||||
/// <returns>A reference to the unspeakable field "texture".</returns>
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<texture>P")]
|
||||
private static extern ref readonly IReadWriteNormalizedTexture2D<float4> texture(this ref readonly global::MyNamespace.MyShader value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A container type for additional data needed by the shader.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file static class Data
|
||||
{
|
||||
/// <summary>The singleton <see cref="ResourceDescriptorRange"/> array instance.</summary>
|
||||
public static readonly ResourceDescriptorRange[] ResourceDescriptorRanges =
|
||||
[
|
||||
new ResourceDescriptorRange(ResourceDescriptorRangeType.UnorderedAccessView, 0)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MemoryManager{T}"/> implementation to get the HLSL bytecode.
|
||||
/// </summary>
|
||||
[GeneratedCode("ComputeSharp.ComputeShaderDescriptorGenerator", <ASSEMBLY_VERSION>)]
|
||||
[DebuggerNonUserCode]
|
||||
[ExcludeFromCodeCoverage]
|
||||
file sealed class HlslBytecodeMemoryManager : MemoryManager<byte>
|
||||
{
|
||||
/// <summary>The singleton <see cref="HlslBytecodeMemoryManager"/> instance to use.</summary>
|
||||
public static readonly HlslBytecodeMemoryManager Instance = new();
|
||||
|
||||
/// <summary>The RVA data with the HLSL bytecode.</summary>
|
||||
private static ReadOnlySpan<byte> Data => [0x44, 0x58, 0x42, 0x43, 0x85, 0xAB, 0x89, 0xA8, 0x68, 0x86, 0x6C, 0x2B, 0x90, 0xB8, 0x38, 0x75, 0x15, 0x08, 0xEE, 0x86, 0x01, 0x00, 0x00, 0x00, 0xA0, 0x0E, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00, 0x88, 0x07, 0x00, 0x00, 0xA4, 0x07, 0x00, 0x00, 0x53, 0x46, 0x49, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4F, 0x53, 0x47, 0x31, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x53, 0x56, 0x30, 0x78, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x54, 0x41, 0x54, 0x94, 0x06, 0x00, 0x00, 0x60, 0x00, 0x05, 0x00, 0xA5, 0x01, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4C, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x7C, 0x06, 0x00, 0x00, 0x42, 0x43, 0xC0, 0xDE, 0x21, 0x0C, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x00, 0x0B, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xC8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0C, 0x25, 0x05, 0x08, 0x19, 0x1E, 0x04, 0x8B, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0B, 0x42, 0xA4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4B, 0x0A, 0x32, 0x52, 0x88, 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5, 0x00, 0x19, 0x32, 0x42, 0xE4, 0x48, 0x0E, 0x90, 0x91, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C, 0xE1, 0x83, 0xE5, 0x8A, 0x04, 0x29, 0x46, 0x06, 0x51, 0x18, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1B, 0x8C, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x40, 0x02, 0xA8, 0x0D, 0x84, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x20, 0x6D, 0x30, 0x86, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x09, 0xA8, 0x00, 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x82, 0x60, 0x42, 0x20, 0x4C, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xA4, 0x84, 0x04, 0x93, 0x22, 0xE3, 0x84, 0xA1, 0x90, 0x14, 0x12, 0x4C, 0x8A, 0x8C, 0x0B, 0x84, 0xA4, 0x4C, 0x10, 0x7C, 0x23, 0x00, 0x25, 0x00, 0x14, 0xE6, 0x08, 0xC0, 0xA0, 0x0C, 0x63, 0x0C, 0x22, 0x85, 0x18, 0x63, 0x0C, 0x32, 0x33, 0x00, 0x65, 0x40, 0x03, 0x51, 0x9A, 0x23, 0x40, 0x68, 0xDD, 0x33, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x87, 0x40, 0x33, 0x2C, 0x04, 0x0A, 0x58, 0x59, 0xC0, 0x68, 0x63, 0x0C, 0x84, 0x10, 0x5A, 0xE4, 0x8E, 0x1A, 0x2E, 0x7F, 0xC2, 0x1E, 0x42, 0xF2, 0xB9, 0x8D, 0x2A, 0x56, 0x62, 0xF2, 0x8B, 0xDB, 0x46, 0x04, 0x42, 0x08, 0x15, 0x02, 0x8E, 0x36, 0x28, 0x1E, 0x35, 0x5C, 0xFE, 0x84, 0x3D, 0x84, 0xE4, 0x73, 0x1B, 0x55, 0xAC, 0xC4, 0xE4, 0x23, 0xB7, 0x8D, 0x88, 0x31, 0xC6, 0x28, 0xC4, 0x1C, 0x6D, 0x10, 0x9D, 0x23, 0x08, 0x8A, 0xD1, 0xC6, 0x1A, 0xC3, 0xD2, 0x1D, 0x08, 0x18, 0x46, 0x20, 0x90, 0x99, 0xC8, 0x60, 0x1C, 0xD8, 0x21, 0x1C, 0xE6, 0x61, 0x1E, 0xDC, 0x40, 0x16, 0x6E, 0x81, 0x16, 0xCA, 0x01, 0x1F, 0xE8, 0xA1, 0x1E, 0xE4, 0xA1, 0x1C, 0xE4, 0x80, 0x14, 0xF8, 0xC0, 0x1E, 0xCA, 0x61, 0x1C, 0xE8, 0xE1, 0x1D, 0xE4, 0x81, 0x0F, 0xCC, 0x81, 0x1D, 0xDE, 0x21, 0x1C, 0xE8, 0x81, 0x0D, 0xC0, 0x80, 0x0E, 0xFC, 0x00, 0x0C, 0xFC, 0x00, 0x05, 0x9A, 0xF6, 0x05, 0x3F, 0x22, 0xC6, 0x18, 0x88, 0x3A, 0x00, 0x00, 0x13, 0x14, 0x72, 0xC0, 0x87, 0x74, 0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x03, 0x72, 0xC0, 0x87, 0x0D, 0xAF, 0x50, 0x0E, 0x6D, 0xD0, 0x0E, 0x7A, 0x50, 0x0E, 0x6D, 0x00, 0x0F, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x78, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE9, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x90, 0x0E, 0x76, 0x40, 0x07, 0x7A, 0x60, 0x07, 0x74, 0xD0, 0x06, 0xE6, 0x10, 0x07, 0x76, 0xA0, 0x07, 0x73, 0x20, 0x07, 0x6D, 0x60, 0x0E, 0x73, 0x20, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xD0, 0x06, 0xE6, 0x60, 0x07, 0x74, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x6D, 0xE0, 0x0E, 0x78, 0xA0, 0x07, 0x71, 0x60, 0x07, 0x7A, 0x30, 0x07, 0x72, 0xA0, 0x07, 0x76, 0x40, 0x07, 0x43, 0x9E, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x3C, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x79, 0x0C, 0x20, 0x00, 0x02, 0x00行の続きは省略
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe Span<byte> GetSpan()
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref MemoryMarshal.GetReference(Data)), Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Memory<byte> Memory
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CreateMemory(Data.Length);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override unsafe MemoryHandle Pin(int elementIndex)
|
||||
{
|
||||
return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Unpin()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
"""";
|
||||
|
||||
await VerifyGeneratedDiagnosticsAsync(source, ("MyNamespace.MyShader.g.cs", result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the output of a source generator.
|
||||
/// </summary>
|
||||
/// <param name="source">The input source to process.</param>
|
||||
/// <param name="result">The expected source to be generated.</param>
|
||||
/// <returns>The task for the operation.</returns>
|
||||
private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result)
|
||||
{
|
||||
// Also validate all analyzers
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidComputeContextCopyAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<MissingAllowUnsafeBlocksCompilationOptionAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<MissingComputeShaderDescriptorOnComputeShaderAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleGeneratedComputeShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
|
||||
// Get all assembly references for the .NET TFM and ComputeSharp
|
||||
IEnumerable<MetadataReference> metadataReferences =
|
||||
[
|
||||
.. Net80.References.All,
|
||||
MetadataReference.CreateFromFile(typeof(Core::ComputeSharp.Hlsl).Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(D3D12::ComputeSharp.IComputeShader).Assembly.Location)
|
||||
];
|
||||
|
||||
// Parse the source text (C# 12)
|
||||
SyntaxTree sourceTree = CSharpSyntaxTree.ParseText(
|
||||
source,
|
||||
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12));
|
||||
|
||||
// Create the original compilation
|
||||
CSharpCompilation compilation = CSharpCompilation.Create(
|
||||
"original",
|
||||
new SyntaxTree[] { sourceTree },
|
||||
metadataReferences,
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true));
|
||||
|
||||
// Create the generator driver with the shader generator
|
||||
GeneratorDriver driver = CSharpGeneratorDriver.Create(new ComputeShaderDescriptorGenerator()).WithUpdatedParseOptions((CSharpParseOptions)sourceTree.Options);
|
||||
|
||||
// Run all source generators on the input source code
|
||||
_ = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation outputCompilation, out ImmutableArray<Diagnostic> diagnostics);
|
||||
|
||||
// Ensure that no diagnostics were generated
|
||||
CollectionAssert.AreEquivalent(Array.Empty<Diagnostic>(), diagnostics);
|
||||
|
||||
// Update the assembly version using the version from the assembly of the input generators.
|
||||
// This allows the tests to not need updates whenever the version of the MVVM Toolkit changes.
|
||||
string expectedText = result.Source.Replace("<ASSEMBLY_VERSION>", $"\"{typeof(ComputeShaderDescriptorGenerator).Assembly.GetName().Version}\"");
|
||||
string actualText = outputCompilation.SyntaxTrees.Single(tree => Path.GetFileName(tree.FilePath) == result.Filename).ToString();
|
||||
|
||||
Assert.AreEqual(expectedText, actualText);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする