Changed DispatchDataLoader to load D3D12_GPU_DESCRIPTOR_HANDLEs
このコミットが含まれているのは:
1 親
3c050dbad4
コミット
c491d8c57c
2ファイル変更
+31
-17
検索条件に一致するファイルはありません
@@ -3,6 +3,7 @@ using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation.Models
|
||||
{
|
||||
@@ -12,9 +13,9 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
internal readonly ref struct DispatchData2
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="GraphicsResource2"/> array with the captured buffers.
|
||||
/// The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> array with the captured buffers.
|
||||
/// </summary>
|
||||
private readonly GraphicsResource2[] resourcesArray;
|
||||
private readonly D3D12_GPU_DESCRIPTOR_HANDLE[] resourcesArray;
|
||||
|
||||
/// <summary>
|
||||
/// The number of <see cref="GraphicsResource"/> instances in <see cref="resourcesArray"/>.
|
||||
@@ -34,11 +35,11 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DispatchData"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourcesArray">The <see cref="GraphicsResource2"/> array with the captured buffers.</param>
|
||||
/// <param name="resourcesCount">The number of <see cref="GraphicsResource2"/> instances in <see cref="resourcesArray"/>.</param>
|
||||
/// <param name="resourcesArray">The <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> array with the captured buffers.</param>
|
||||
/// <param name="resourcesCount">The number of <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instances in <see cref="resourcesArray"/>.</param>
|
||||
/// <param name="variablesArray">The <see cref="byte"/> array with all the captured variables, with proper padding.</param>
|
||||
/// <param name="variablesByteSize">The actual size in bytes to use from <see cref="variablesArray"/>.</param>
|
||||
public DispatchData2(GraphicsResource2[] resourcesArray, int resourcesCount, byte[] variablesArray, int variablesByteSize)
|
||||
public DispatchData2(D3D12_GPU_DESCRIPTOR_HANDLE[] resourcesArray, int resourcesCount, byte[] variablesArray, int variablesByteSize)
|
||||
{
|
||||
this.resourcesArray = resourcesArray;
|
||||
this.variablesArray = variablesArray;
|
||||
@@ -47,21 +48,21 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Span{T}"/> with all the captured buffers.
|
||||
/// Gets a <see cref="ReadOnlySpan{T}"/> with all the captured buffers.
|
||||
/// </summary>
|
||||
public ReadOnlySpan<GraphicsResource2> Resources
|
||||
public ReadOnlySpan<D3D12_GPU_DESCRIPTOR_HANDLE> Resources
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ref GraphicsResource2 r0 = ref MemoryMarshal.GetArrayDataReference(this.resourcesArray);
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE r0 = ref MemoryMarshal.GetArrayDataReference(this.resourcesArray);
|
||||
|
||||
return MemoryMarshal.CreateReadOnlySpan(ref r0, this.resourcesCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Span{T}"/> with the padded data representing all the captured variables.
|
||||
/// Gets a <see cref="ReadOnlySpan{T}"/> with the padded data representing all the captured variables.
|
||||
/// </summary>
|
||||
public ReadOnlySpan<Int4> Variables
|
||||
{
|
||||
@@ -80,7 +81,7 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
public void Dispose()
|
||||
{
|
||||
ArrayPool<GraphicsResource2>.Shared.Return(this.resourcesArray, true);
|
||||
ArrayPool<D3D12_GPU_DESCRIPTOR_HANDLE>.Shared.Return(this.resourcesArray);
|
||||
ArrayPool<byte>.Shared.Return(this.variablesArray);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Buffers;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
@@ -18,9 +20,9 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// A <see langword="delegate"/> that loads all the captured members from a shader instance.
|
||||
/// </summary>
|
||||
/// <param name="shader">The shader instance to load the data from.</param>
|
||||
/// <param name="r0">A reference to the buffer with all the captured <see cref="GraphicsResource2"/> instances.</param>
|
||||
/// <param name="r0">A reference to the buffer with all the captured <see cref="D3D12_GPU_DESCRIPTOR_HANDLE"/> instances.</param>
|
||||
/// <param name="r1">A reference to the buffer to use to store all the captured value types.</param>
|
||||
private delegate void DispatchDataLoader(in T shader, ref GraphicsResource2 r0, ref byte r1);
|
||||
private delegate void DispatchDataLoader(in T shader, ref D3D12_GPU_DESCRIPTOR_HANDLE r0, ref byte r1);
|
||||
|
||||
/// <summary>
|
||||
/// The number of captured graphics resources (buffers).
|
||||
@@ -54,11 +56,11 @@ namespace ComputeSharp.Shaders.Translation
|
||||
public DispatchData2 GetDispatchData(in T shader, int x, int y, int z)
|
||||
{
|
||||
// Resources and variables buffers
|
||||
GraphicsResource2[] resources = ArrayPool<GraphicsResource2>.Shared.Rent(this.totalResourceCount);
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE[] resources = ArrayPool<D3D12_GPU_DESCRIPTOR_HANDLE>.Shared.Rent(this.totalResourceCount);
|
||||
byte[] variables = ArrayPool<byte>.Shared.Rent(this.totalVariablesByteSize);
|
||||
|
||||
ref GraphicsResource2 r0 = ref MemoryMarshal.GetArrayDataReference(resources);
|
||||
ref byte r1 = ref variables[0];
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE r0 = ref MemoryMarshal.GetArrayDataReference(resources);
|
||||
ref byte r1 = ref MemoryMarshal.GetArrayDataReference(variables);
|
||||
|
||||
// Set the x, y and z counters
|
||||
Unsafe.As<byte, int>(ref r1) = x;
|
||||
@@ -87,9 +89,20 @@ namespace ComputeSharp.Shaders.Translation
|
||||
|
||||
if (totalResourceCount > 0)
|
||||
{
|
||||
il.EmitAddOffset<GraphicsResource>(this.totalResourceCount);
|
||||
il.EmitAddOffset<D3D12_GPU_DESCRIPTOR_HANDLE>(this.totalResourceCount);
|
||||
}
|
||||
|
||||
il.Emit(OpCodes.Ldarg_0);
|
||||
il.EmitReadMember(member);
|
||||
|
||||
// Access Buffer<T>.D3D12GpuDescriptorHandle
|
||||
FieldInfo gpuDescriptorInfo = member.MemberType.GetField(
|
||||
nameof(Buffer2<byte>.D3D12GpuDescriptorHandle),
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)!;
|
||||
|
||||
il.EmitReadMember(gpuDescriptorInfo);
|
||||
il.EmitStoreToAddress(member.MemberType);
|
||||
|
||||
this.totalResourceCount++;
|
||||
}
|
||||
else if (HlslKnownTypes.IsKnownScalarType(member.MemberType) ||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする