using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.Graphics.Buffers.Abstract;
using TerraFX.Interop;
namespace ComputeSharp.Shaders.Translation.Models
{
///
/// A that contains all the captured data to dispatch a shader.
///
internal readonly ref struct DispatchData2
{
///
/// The array with the captured buffers.
///
private readonly D3D12_GPU_DESCRIPTOR_HANDLE[] resourcesArray;
///
/// The number of instances in .
///
private readonly int resourcesCount;
///
/// The array with all the captured variables, with proper padding.
///
private readonly byte[] variablesArray;
///
/// The actual size in bytes to use from .
///
private readonly int variablesByteSize;
///
/// Creates a new instance with the specified parameters.
///
/// The array with the captured buffers.
/// The number of instances in .
/// The array with all the captured variables, with proper padding.
/// The actual size in bytes to use from .
public DispatchData2(D3D12_GPU_DESCRIPTOR_HANDLE[] resourcesArray, int resourcesCount, byte[] variablesArray, int variablesByteSize)
{
this.resourcesArray = resourcesArray;
this.variablesArray = variablesArray;
this.resourcesCount = resourcesCount;
this.variablesByteSize = variablesByteSize;
}
///
/// Gets a with all the captured buffers.
///
public ReadOnlySpan Resources
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ref D3D12_GPU_DESCRIPTOR_HANDLE r0 = ref MemoryMarshal.GetArrayDataReference(this.resourcesArray);
return MemoryMarshal.CreateReadOnlySpan(ref r0, this.resourcesCount);
}
}
///
/// Gets a with the padded data representing all the captured variables.
///
public ReadOnlySpan Variables
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ref byte r0 = ref MemoryMarshal.GetArrayDataReference(this.variablesArray);
ref Int4 r1 = ref Unsafe.As(ref r0);
bool mod = (this.variablesByteSize & 15) > 0;
int length = variablesByteSize / 4 + Unsafe.As(ref mod);
return MemoryMarshal.CreateReadOnlySpan(ref r1, length);
}
}
///
public void Dispose()
{
ArrayPool.Shared.Return(this.resourcesArray);
ArrayPool.Shared.Return(this.variablesArray);
}
}
}