Merge pull request #618 from Sergio0694/dev/graphics-resources-loading
Rework IShader APIs to load constant buffer and resources
このコミットが含まれているのは:
32ファイル変更
+653
-1027
検索条件に一致するファイルはありません
+36
-23
@@ -11,53 +11,43 @@ partial class IShaderGenerator
|
||||
partial class LoadDispatchData
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the <c>LoadDispatchData</c> method.
|
||||
/// Writes the <c>LoadConstantBuffer</c> method.
|
||||
/// </summary>
|
||||
/// <param name="info">The input <see cref="ShaderInfo"/> instance with gathered shader info.</param>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
public static void WriteSyntax(ShaderInfo info, IndentedTextWriter writer)
|
||||
public static void WriteLoadConstantBufferSyntax(ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
|
||||
writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadDispatchData<TLoader>(ref TLoader loader, global::ComputeSharp.GraphicsDevice device, int x, int y, int z)");
|
||||
writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadConstantBuffer<TLoader>(ref TLoader loader, int x, int y, int z)");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
writer.WriteLine($"global::System.Span<uint> span0 = stackalloc uint[{info.ConstantBufferSizeInBytes}];");
|
||||
writer.WriteLineIf($"global::System.Span<ulong> span1 = stackalloc ulong[{info.ResourceCount}];", info.ResourceCount > 0);
|
||||
writer.WriteLine("ref uint r0 = ref span0[0];");
|
||||
writer.WriteLineIf("ref ulong r1 = ref span1[0];", info.ResourceCount > 0);
|
||||
writer.WriteLine($"global::System.Span<byte> span = stackalloc byte[{info.ConstantBufferSizeInBytes}];");
|
||||
|
||||
// Append the statements for the dispatch ranges
|
||||
writer.WriteLine("span0[0] = (uint)x;");
|
||||
writer.WriteLine("span0[1] = (uint)y;");
|
||||
writer.WriteLineIf("span0[2] = (uint)z;", !info.IsPixelShaderLike);
|
||||
writer.WriteLine("global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref span[0]) = (uint)x;");
|
||||
writer.WriteLine("global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref span[4]) = (uint)y;");
|
||||
writer.WriteLineIf("global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref span[8]) = (uint)z;", !info.IsPixelShaderLike);
|
||||
|
||||
// Generate loading statements for each captured field
|
||||
foreach (FieldInfo fieldInfo in info.Fields)
|
||||
{
|
||||
switch (fieldInfo)
|
||||
{
|
||||
case FieldInfo.Resource resource:
|
||||
|
||||
// Validate the resource and get a handle for it
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.Add(ref r1, {resource.Offset}) = " +
|
||||
$"global::ComputeSharp.__Internals.GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle({resource.FieldName}, device);");
|
||||
break;
|
||||
case FieldInfo.Primitive { TypeName: "System.Boolean" } primitive:
|
||||
|
||||
// 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<uint, global::ComputeSharp.Bool>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){primitive.Offset})) = " +
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.Bool>(ref span[{primitive.Offset}]) = " +
|
||||
$"(global::ComputeSharp.Bool){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<uint, global::{primitive.TypeName}>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){primitive.Offset})) = " +
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, global::{primitive.TypeName}>(ref span[{primitive.Offset}]) = " +
|
||||
$"{string.Join(".", primitive.FieldPath)};");
|
||||
break;
|
||||
|
||||
@@ -82,7 +72,7 @@ partial class IShaderGenerator
|
||||
for (int j = 0; j < matrix.Rows; j++)
|
||||
{
|
||||
writer.WriteLine(
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<uint, {rowTypeName}>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){matrix.Offsets[j]})) = " +
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.As<byte, {rowTypeName}>(ref span[{matrix.Offsets[j]}]) = " +
|
||||
$"global::System.Runtime.CompilerServices.Unsafe.Add(ref {rowLocalName}, {j});");
|
||||
}
|
||||
|
||||
@@ -90,9 +80,32 @@ partial class IShaderGenerator
|
||||
}
|
||||
}
|
||||
|
||||
// Load the prepared buffers
|
||||
writer.WriteLine("loader.LoadCapturedValues(span0);");
|
||||
writer.WriteLineIf("loader.LoadCapturedResources(span1);", info.ResourceCount > 0);
|
||||
// Load the prepared buffer
|
||||
writer.WriteLine("loader.LoadConstantBuffer(span);");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the <c>LoadGraphicsResources</c> method.
|
||||
/// </summary>
|
||||
/// <param name="info">The input <see cref="ShaderInfo"/> instance with gathered shader info.</param>
|
||||
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
|
||||
public static void WriteLoadGraphicsResourcesSyntax(ShaderInfo info, IndentedTextWriter writer)
|
||||
{
|
||||
writer.WriteLine("/// <inheritdoc/>");
|
||||
writer.WriteGeneratedAttributes(GeneratorName);
|
||||
writer.WriteLine("readonly void global::ComputeSharp.__Internals.IShader.LoadGraphicsResources<TLoader>(ref TLoader loader)");
|
||||
|
||||
using (writer.WriteBlock())
|
||||
{
|
||||
// Generate loading statements for each captured resource
|
||||
foreach (FieldInfo fieldInfo in info.Fields)
|
||||
{
|
||||
if (fieldInfo is FieldInfo.Resource resource)
|
||||
{
|
||||
writer.WriteLine($"loader.LoadGraphicsResource({resource.FieldName}, {resource.Offset});");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ partial class IShaderGenerator
|
||||
/// </summary>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="structDeclarationSymbol">The current shader type being explored.</param>
|
||||
/// <param name="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
/// <param name="isPixelShaderLike">Whether the compute shader is "pixel shader like", ie. outputting a pixel into a target texture.</param>
|
||||
/// <param name="constantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
/// <param name="resourceCount">The total number of captured resources in the shader.</param>
|
||||
/// <returns>The sequence of <see cref="FieldInfo"/> instances for all captured resources and values.</returns>
|
||||
public static ImmutableArray<FieldInfo> GetInfo(
|
||||
@@ -108,7 +108,7 @@ partial class IShaderGenerator
|
||||
// the local variables is padded to a multiple of a 32 bit value. This is necessary to
|
||||
// enable loading all the dispatch data after reinterpreting it to a sequence of values
|
||||
// of size 32 bits (via SetComputeRoot32BitConstants), without reading out of bounds.
|
||||
constantBufferSizeInBytes = AlignmentHelper.Pad(rawDataOffsetAsBox.Value, sizeof(int)) / sizeof(int);
|
||||
constantBufferSizeInBytes = AlignmentHelper.Pad(rawDataOffsetAsBox.Value, sizeof(int));
|
||||
|
||||
// A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
|
||||
// Loaded values in the root signature have the following costs:
|
||||
@@ -118,9 +118,9 @@ partial class IShaderGenerator
|
||||
// So here we check whether the current signature respects that constraint,
|
||||
// and emit a build error otherwise. For more info on this, see the docs here:
|
||||
// https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
|
||||
int rootSignatureDwordSize = constantBufferSizeInBytes + resourceCount;
|
||||
int root32BitConstantCount = (constantBufferSizeInBytes / sizeof(int)) + resourceCount;
|
||||
|
||||
if (rootSignatureDwordSize > 64)
|
||||
if (root32BitConstantCount > 64)
|
||||
{
|
||||
diagnostics.Add(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,11 @@ partial class IShaderGenerator
|
||||
/// <summary>
|
||||
/// Gets the data related to the shader metadata for a given shader type.
|
||||
/// </summary>
|
||||
/// <param name="root32BitConstantCount">The total number of needed 32 bit constants in the shader root signature.</param>
|
||||
/// <param name="isImplicitTextureUsed">Indicates whether the current shader uses an implicit texture.</param>
|
||||
/// <param name="isSamplerUsed">Whether the static sampler is used by the shader.</param>
|
||||
/// <param name="capturedFields">The sequence of captured fields for the shader.</param>
|
||||
/// <returns>The metadata info for the shader.</returns>
|
||||
public static ImmutableArray<ResourceDescriptor> GetInfo(
|
||||
int root32BitConstantCount,
|
||||
bool isImplicitTextureUsed,
|
||||
bool isSamplerUsed,
|
||||
ImmutableArray<FieldInfo> capturedFields)
|
||||
|
||||
@@ -59,7 +59,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
diagnostics,
|
||||
typeSymbol,
|
||||
isPixelShaderLike,
|
||||
out int root32BitConstantCount,
|
||||
out int constantBufferSizeInBytes,
|
||||
out int resourceCount);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
@@ -92,7 +92,6 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
|
||||
// GetDispatchMetadata() info
|
||||
ImmutableArray<ResourceDescriptor> resourceDescriptors = LoadDispatchMetadata.GetInfo(
|
||||
root32BitConstantCount,
|
||||
isImplicitTextureUsed,
|
||||
isSamplerUsed,
|
||||
fieldInfos);
|
||||
@@ -123,7 +122,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
ThreadsZ: threadsZ,
|
||||
IsPixelShaderLike: isPixelShaderLike,
|
||||
IsSamplerUsed: isSamplerUsed,
|
||||
ConstantBufferSizeInBytes: root32BitConstantCount,
|
||||
ConstantBufferSizeInBytes: constantBufferSizeInBytes,
|
||||
ResourceCount: resourceCount,
|
||||
Fields: fieldInfos,
|
||||
ResourceDescriptors: resourceDescriptors,
|
||||
@@ -153,7 +152,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
declaredMembers.Add(LoadDispatchMetadata.WriteSyntax);
|
||||
declaredMembers.Add(BuildHlslSource.WriteSyntax);
|
||||
declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax);
|
||||
declaredMembers.Add(LoadDispatchData.WriteSyntax);
|
||||
declaredMembers.Add(LoadDispatchData.WriteLoadConstantBufferSyntax);
|
||||
declaredMembers.Add(LoadDispatchData.WriteLoadGraphicsResourcesSyntax);
|
||||
|
||||
using ImmutableArrayBuilder<IndentedTextWriter.Callback<ShaderInfo>> additionalTypes = new();
|
||||
using ImmutableHashSetBuilder<string> usingDirectives = new();
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ComputeSharp.SourceGenerators.Models;
|
||||
/// <param name="ThreadsZ">The thread ids value for the Z axis.</param>
|
||||
/// <param name="IsPixelShaderLike">Whether the compute shader is "pixel shader like", ie. outputting a pixel into a target texture.</param>
|
||||
/// <param name="IsSamplerUsed">Whether or not the static sampler is used.</param>
|
||||
/// /// <param name="ConstantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
/// <param name="ConstantBufferSizeInBytes">The size of the shader constant buffer.</param>
|
||||
/// <param name="ResourceCount">The total number of captured resources in the shader.</param>
|
||||
/// <param name="Fields">The description on shader instance fields.</param>
|
||||
/// <param name="ResourceDescriptors">The sequence of resource descriptors for the shader.</param>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing a data loader for the constant buffer of a compute shader.
|
||||
/// </summary>
|
||||
public interface IConstantBufferLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the constant buffer of a compute shader.
|
||||
/// </summary>
|
||||
/// <param name="data">The constant buffer for the compute shader (the size must be a multiple of the size of a DWORD value).</param>
|
||||
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="data"/> is not a multiple of the size of a DWORD value).</exception>
|
||||
void LoadConstantBuffer(ReadOnlySpan<byte> data);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a data loader for a shader being dispatched.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the captured values used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized captured values.</param>
|
||||
void LoadCapturedValues(ReadOnlySpan<uint> data);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the captured resources used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized resources.</param>
|
||||
void LoadCapturedResources(ReadOnlySpan<ulong> data);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A type representing a loader object for <see cref="IGraphicsResource"/> values used in compute shaders.
|
||||
/// </summary>
|
||||
public interface IGraphicsResourceLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads a resource used by the shader to be dispatched.
|
||||
/// </summary>
|
||||
/// <param name="resource">The input resource to be loaded.</param>
|
||||
/// <param name="index">The index to use to bind the resource to the shader.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="resource"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="resource"/> is not a valid resource object.</exception>
|
||||
/// <exception cref="GraphicsDeviceMismatchException">Thrown if the resource isn't associated with the same device used to dispatch the shader.</exception>
|
||||
void LoadGraphicsResource(IGraphicsResource resource, uint index);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public interface IShader
|
||||
/// <remarks>
|
||||
/// Constant buffer data is bound to shaders via 32 bit root constants, and loaded before dispatching via
|
||||
/// <see href="https://learn.microsoft.com/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-setcomputeroot32bitconstants"><c>ID3D12GraphicsCommandList::SetComputeRoot32BitConstants</c></see>,
|
||||
/// so the size must be a multiple of 4.
|
||||
/// so the size must be a multiple of the size of a DWORD value (ie. 4 bytes).
|
||||
/// </remarks>
|
||||
int ConstantBufferSize { get; }
|
||||
|
||||
@@ -60,16 +60,21 @@ public interface IShader
|
||||
ReadOnlyMemory<byte> HlslBytecode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the dispatch data for the shader.
|
||||
/// Loads the constant buffer of a given input shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TLoader">The type of data loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the data.</param>
|
||||
/// <param name="device">The device the shader is being dispatched on.</param>
|
||||
/// <param name="x">The number of iterations to run on the X axis.</param>
|
||||
/// <param name="y">The number of iterations to run on the Y axis.</param>
|
||||
/// <param name="z">The number of iterations to run on the Z axis.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void LoadDispatchData<TLoader>(ref TLoader loader, GraphicsDevice device, int x, int y, int z)
|
||||
where TLoader : struct, IDispatchDataLoader;
|
||||
void LoadConstantBuffer<TLoader>(ref TLoader loader, int x, int y, int z)
|
||||
where TLoader : struct, IConstantBufferLoader;
|
||||
|
||||
/// <summary>
|
||||
/// Loads the graphics resources for the shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TLoader">The type of graphics resource loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the data.</param>
|
||||
void LoadGraphicsResources<TLoader>(ref TLoader loader)
|
||||
where TLoader : struct, IGraphicsResourceLoader;
|
||||
}
|
||||
@@ -288,11 +288,11 @@ internal static unsafe class ID3D12GraphicsCommandListExtensions
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> instance in use.</param>
|
||||
/// <param name="data">The input buffer with the constant data to bind.</param>
|
||||
public static void SetComputeRoot32BitConstants(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ReadOnlySpan<uint> data)
|
||||
public static void SetComputeRoot32BitConstants(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ReadOnlySpan<byte> data)
|
||||
{
|
||||
fixed (uint* p = data)
|
||||
fixed (byte* p = data)
|
||||
{
|
||||
d3D12GraphicsCommandList.SetComputeRoot32BitConstants(0, (uint)data.Length, p, 0);
|
||||
d3D12GraphicsCommandList.SetComputeRoot32BitConstants(0, (uint)data.Length / sizeof(uint), p, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,416 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A helper class with some proxy methods to expose to generated code in external projects.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This type is not intended to be used directly by user code")]
|
||||
public static class GraphicsResourceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface for non-generic graphics resource types.
|
||||
/// </summary>
|
||||
internal unsafe interface IGraphicsResource
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the resource.</returns>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves its GPU and CPU descriptor handles for a clear operation.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="isNormalized">Indicates whether the current resource uses a normalized format.</param>
|
||||
/// <returns>The GPU and CPU descriptor handles for the resource.</returns>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="lease">The <see cref="ReferenceTracker.Lease"/> value for the returned <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <returns>The the underlying <see cref="ID3D12Resource"/> object.</returns>
|
||||
ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object, along with the transition states.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="resourceState">The target state to transition the resource to.</param>
|
||||
/// <param name="d3D12Resource">The the underlying <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <param name="lease">The <see cref="ReferenceTracker.Lease"/> value for the returned <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <returns>The resource states for <paramref name="d3D12Resource"/>, before and after the transition.</returns>
|
||||
(D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given buffer for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input buffer.</typeparam>
|
||||
/// <param name="buffer">The input <see cref="Buffer{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the buffer.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(Buffer<T> buffer, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(buffer);
|
||||
|
||||
using ReferenceTracker.Lease _0 = buffer.GetReferenceTracker().GetLease();
|
||||
|
||||
buffer.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = buffer.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadOnlyTexture1D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture1D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture1D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture1D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyTexture1D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(IReadOnlyTexture1D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyNormalizedTexture1D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyNormalizedTexture1D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadWriteNormalizedTexture1D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteNormalizedTexture1D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadOnlyTexture2D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture2D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyTexture2D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(IReadOnlyTexture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyNormalizedTexture2D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyNormalizedTexture2D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadWriteNormalizedTexture2D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteNormalizedTexture2D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadOnlyTexture3D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadOnlyTexture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="ReadWriteTexture3D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(ReadWriteTexture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
using ReferenceTracker.Lease _0 = texture.GetReferenceTracker().GetLease();
|
||||
|
||||
texture.ThrowIfDeviceMismatch(device);
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = texture.D3D12GpuDescriptorHandle;
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyTexture3D{T}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<T>(IReadOnlyTexture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadOnlyNormalizedTexture3D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadOnlyNormalizedTexture3D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given texture for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="TPixel">The type of normalized values stored in the input texture.</typeparam>
|
||||
/// <param name="texture">The input <see cref="IReadWriteNormalizedTexture3D{TPixel}"/> instance to check.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the texture.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong ValidateAndGetGpuDescriptorHandle<TPixel>(IReadWriteNormalizedTexture3D<TPixel> texture, GraphicsDevice device)
|
||||
where TPixel : unmanaged
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
if (texture is IGraphicsResource resource)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle = resource.ValidateAndGetGpuDescriptorHandle(device);
|
||||
|
||||
return *(ulong*)&d3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
return default(ArgumentException).Throw<ulong>(nameof(texture));
|
||||
}
|
||||
}
|
||||
@@ -7,25 +7,28 @@ using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Interop.Allocation;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.DirectX.D3D12_FEATURE;
|
||||
using static TerraFX.Interop.DirectX.DXGI_FORMAT;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
using ComputeSharp.Interop.Allocation;
|
||||
#if NET6_0_OR_GREATER
|
||||
using MemoryMarshal = System.Runtime.InteropServices.MemoryMarshal;
|
||||
#else
|
||||
using MemoryMarshal = ComputeSharp.NetStandard.MemoryMarshal;
|
||||
#endif
|
||||
|
||||
#pragma warning disable CA1063
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> representing a typed buffer stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the buffer.</typeparam>
|
||||
public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraphicsResource
|
||||
public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraphicsResource, ID3D12ReadOnlyResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -232,7 +235,7 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
@@ -244,7 +247,7 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
|
||||
this.d3D12ResourceDescriptorHandlesForTypedUnorderedAccessView.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="__Internals.GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal unsafe ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
@@ -253,4 +256,20 @@ public abstract unsafe partial class Buffer<T> : IReferenceTrackedObject, IGraph
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12Resource(device, out lease);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
@@ -9,6 +8,7 @@ using ComputeSharp.Graphics.Resources.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Interop.Allocation;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
|
||||
@@ -17,7 +17,7 @@ using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
|
||||
#pragma warning disable CS0618, CA1063
|
||||
#pragma warning disable CA1063
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ComputeSharp.Resources;
|
||||
/// A <see langword="class"/> representing a typed 1D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
|
||||
public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGraphicsResource, ID3D12ReadWriteResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -511,7 +511,27 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
@@ -523,17 +543,7 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
internal (D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
@@ -551,29 +561,19 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12GpuDescriptorHandle;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12Resource(device, out lease);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12ResourceAndTransitionStates(device, resourceState, out d3D12Resource, out lease);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
@@ -9,6 +8,7 @@ using ComputeSharp.Graphics.Resources.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Interop.Allocation;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
|
||||
@@ -17,7 +17,7 @@ using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
|
||||
#pragma warning disable CS0618, CA1063
|
||||
#pragma warning disable CA1063
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ComputeSharp.Resources;
|
||||
/// A <see langword="class"/> representing a typed 2D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
|
||||
public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGraphicsResource, ID3D12ReadWriteResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -561,7 +561,17 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
@@ -573,17 +583,7 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
internal (D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
@@ -601,7 +601,7 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -611,19 +611,19 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12Resource(device, out lease);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12ResourceAndTransitionStates(device, resourceState, out d3D12Resource, out lease);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
@@ -9,6 +8,7 @@ using ComputeSharp.Graphics.Resources.Helpers;
|
||||
using ComputeSharp.Graphics.Resources.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Interop.Allocation;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.DirectX.D3D12_COMMAND_LIST_TYPE;
|
||||
@@ -17,7 +17,7 @@ using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
using static TerraFX.Interop.DirectX.D3D12_UAV_DIMENSION;
|
||||
using ResourceType = ComputeSharp.Graphics.Resources.Enums.ResourceType;
|
||||
|
||||
#pragma warning disable CS0618, CA1063
|
||||
#pragma warning disable CA1063
|
||||
|
||||
namespace ComputeSharp.Resources;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ComputeSharp.Resources;
|
||||
/// A <see langword="class"/> representing a typed 3D texture stored on GPU memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
|
||||
public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGraphicsResource, GraphicsResourceHelper.IGraphicsResource
|
||||
public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGraphicsResource, ID3D12ReadWriteResource
|
||||
where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
@@ -613,7 +613,17 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice, out bool)"/>
|
||||
internal (D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
@@ -625,17 +635,7 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
|
||||
return (this.d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle, this.d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice, out ReferenceTracker.Lease)"/>
|
||||
internal ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
ThrowIfDeviceMismatch(device);
|
||||
|
||||
return D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
/// <inheritdoc cref="ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice, ResourceState, out ID3D12Resource*, out ReferenceTracker.Lease)"/>
|
||||
internal (D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
@@ -653,7 +653,7 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -663,19 +663,19 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12Resource(device, out lease);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) ID3D12ReadWriteResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
return ValidateAndGetGpuAndCpuDescriptorHandlesForClear(device, out isNormalized);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) ID3D12ReadWriteResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
return ValidateAndGetID3D12ResourceAndTransitionStates(device, resourceState, out d3D12Resource, out lease);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.Resources.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a readonly, non-generic readonly graphics resource types.
|
||||
/// </summary>
|
||||
internal unsafe interface ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves its GPU descriptor handle.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <returns>The GPU descriptor handle for the resource.</returns>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ValidateAndGetGpuDescriptorHandle(GraphicsDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="lease">The <see cref="ReferenceTracker.Lease"/> value for the returned <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <returns>The the underlying <see cref="ID3D12Resource"/> object.</returns>
|
||||
ID3D12Resource* ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.Resources.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a writeable, non-generic graphics resource types.
|
||||
/// </summary>
|
||||
internal unsafe interface ID3D12ReadWriteResource : ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves its GPU and CPU descriptor handles for a clear operation.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="isNormalized">Indicates whether the current resource uses a normalized format.</param>
|
||||
/// <returns>The GPU and CPU descriptor handles for the resource.</returns>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized);
|
||||
|
||||
/// <summary>
|
||||
/// Validates the given resource for usage with a specified device, and retrieves the underlying <see cref="ID3D12Resource"/> object, along with the transition states.
|
||||
/// </summary>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance in use.</param>
|
||||
/// <param name="resourceState">The target state to transition the resource to.</param>
|
||||
/// <param name="d3D12Resource">The the underlying <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <param name="lease">The <see cref="ReferenceTracker.Lease"/> value for the returned <see cref="ID3D12Resource"/> object.</param>
|
||||
/// <returns>The resource states for <paramref name="d3D12Resource"/>, before and after the transition.</returns>
|
||||
(D3D12_RESOURCE_STATES Before, D3D12_RESOURCE_STATES After) ValidateAndGetID3D12ResourceAndTransitionStates(
|
||||
GraphicsDevice device,
|
||||
ResourceState resourceState,
|
||||
out ID3D12Resource* d3D12Resource,
|
||||
out ReferenceTracker.Lease lease);
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -57,7 +56,7 @@ partial class ReadWriteTexture1D<T, TPixel>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture1D{T, TPixel}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture1D<TPixel>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture1D<TPixel>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture1D{T, TPixel}"/> instance being wrapped.
|
||||
@@ -99,7 +98,7 @@ partial class ReadWriteTexture1D<T, TPixel>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -110,13 +109,7 @@ partial class ReadWriteTexture1D<T, TPixel>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -127,12 +120,6 @@ partial class ReadWriteTexture1D<T, TPixel>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -57,7 +56,7 @@ partial class ReadWriteTexture1D<T>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture1D{T}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture1D<T>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture1D<T>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture1D{T}"/> instance being wrapped.
|
||||
@@ -99,7 +98,7 @@ partial class ReadWriteTexture1D<T>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -110,13 +109,7 @@ partial class ReadWriteTexture1D<T>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -127,12 +120,6 @@ partial class ReadWriteTexture1D<T>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -57,7 +56,7 @@ partial class ReadWriteTexture2D<T, TPixel>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture2D{T, TPixel}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture2D<TPixel>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture2D<TPixel>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture2D{T, TPixel}"/> instance being wrapped.
|
||||
@@ -111,7 +110,7 @@ partial class ReadWriteTexture2D<T, TPixel>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -122,13 +121,7 @@ partial class ReadWriteTexture2D<T, TPixel>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -139,12 +132,6 @@ partial class ReadWriteTexture2D<T, TPixel>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -60,7 +59,7 @@ partial class ReadWriteTexture2D<T>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture2D{T}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture2D<T>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture2D<T>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture2D{T}"/> instance being wrapped.
|
||||
@@ -111,7 +110,7 @@ partial class ReadWriteTexture2D<T>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -122,13 +121,7 @@ partial class ReadWriteTexture2D<T>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -139,12 +132,6 @@ partial class ReadWriteTexture2D<T>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -57,7 +56,7 @@ partial class ReadWriteTexture3D<T, TPixel>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture3D{T, TPixel}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture3D<TPixel>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyNormalizedTexture3D<TPixel>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture3D{T, TPixel}"/> instance being wrapped.
|
||||
@@ -111,7 +110,7 @@ partial class ReadWriteTexture3D<T, TPixel>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -122,13 +121,7 @@ partial class ReadWriteTexture3D<T, TPixel>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -139,12 +132,6 @@ partial class ReadWriteTexture3D<T, TPixel>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using static TerraFX.Interop.DirectX.D3D12_SRV_DIMENSION;
|
||||
|
||||
#pragma warning disable CS0618, IDE0022
|
||||
#pragma warning disable IDE0022
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -57,7 +56,7 @@ partial class ReadWriteTexture3D<T>
|
||||
/// <summary>
|
||||
/// A wrapper for a <see cref="ReadWriteTexture3D{T}"/> resource that has been temporarily transitioned to readonly.
|
||||
/// </summary>
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture3D<T>, GraphicsResourceHelper.IGraphicsResource
|
||||
private sealed unsafe class ReadOnly : ReferenceTrackedObject, IReadOnlyTexture3D<T>, ID3D12ReadOnlyResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The owning <see cref="ReadWriteTexture3D{T}"/> instance being wrapped.
|
||||
@@ -111,7 +110,7 @@ partial class ReadWriteTexture3D<T>
|
||||
public GraphicsDevice GraphicsDevice => this.owner.GraphicsDevice;
|
||||
|
||||
/// <inheritdoc/>
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ID3D12ReadOnlyResource.ValidateAndGetGpuDescriptorHandle(GraphicsDevice device)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
using ReferenceTracker.Lease _1 = this.owner.GetReferenceTracker().GetLease();
|
||||
@@ -122,13 +121,7 @@ partial class ReadWriteTexture3D<T>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetGpuAndCpuDescriptorHandlesForClear(GraphicsDevice device, out bool isNormalized)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ID3D12Resource* GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
ID3D12Resource* ID3D12ReadOnlyResource.ValidateAndGetID3D12Resource(GraphicsDevice device, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
lease = GetReferenceTracker().GetLease();
|
||||
|
||||
@@ -139,12 +132,6 @@ partial class ReadWriteTexture3D<T>
|
||||
return this.owner.D3D12Resource;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
(D3D12_RESOURCE_STATES, D3D12_RESOURCE_STATES) GraphicsResourceHelper.IGraphicsResource.ValidateAndGetID3D12ResourceAndTransitionStates(GraphicsDevice device, ResourceState resourceState, out ID3D12Resource* d3D12Resource, out ReferenceTracker.Lease lease)
|
||||
{
|
||||
throw new NotSupportedException("This operation cannot be performaned on a readonly wrapper.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DangerousOnDispose()
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@ using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using ComputeSharp.Shaders.Dispatching;
|
||||
using ComputeSharp.Shaders.Loading;
|
||||
using TerraFX.Interop.DirectX;
|
||||
@@ -172,9 +172,13 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
|
||||
ComputeShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
D3D12GraphicsCommandListConstantBufferLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
|
||||
shader.LoadDispatchData(ref dataLoader, this.device, x, y, z);
|
||||
shader.LoadConstantBuffer(ref dataLoader, x, y, z);
|
||||
|
||||
D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 1);
|
||||
|
||||
shader.LoadGraphicsResources(ref graphicsResourceLoader);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ);
|
||||
}
|
||||
@@ -206,14 +210,18 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature);
|
||||
|
||||
PixelShaderDispatchDataLoader dataLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
D3D12GraphicsCommandListConstantBufferLoader constantBufferLoader = new(commandList.D3D12GraphicsCommandList);
|
||||
|
||||
shader.LoadDispatchData(ref dataLoader, this.device, x, y, 1);
|
||||
shader.LoadConstantBuffer(ref constantBufferLoader, x, y, 1);
|
||||
|
||||
D3D12GraphicsCommandListGraphicsResourceLoader graphicsResourceLoader = new(commandList.D3D12GraphicsCommandList, this.device, rootParameterOffset: 2);
|
||||
|
||||
shader.LoadGraphicsResources(ref graphicsResourceLoader);
|
||||
|
||||
// Load the implicit output texture
|
||||
commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable(
|
||||
1,
|
||||
((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuDescriptorHandle(this.device));
|
||||
((ID3D12ReadOnlyResource)texture).ValidateAndGetGpuDescriptorHandle(this.device));
|
||||
|
||||
commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, 1);
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.__Internals;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Shaders.Dispatching;
|
||||
|
||||
/// <summary>
|
||||
/// A data loader for compute shaders.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct ComputeShaderDispatchDataLoader : IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> object in use.
|
||||
/// </summary>
|
||||
private readonly ID3D12GraphicsCommandList* d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ComputeShaderDispatchDataLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> object to use.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal ComputeShaderDispatchDataLoader(ID3D12GraphicsCommandList* d3D12GraphicsCommandList)
|
||||
{
|
||||
this.d3D12GraphicsCommandList = d3D12GraphicsCommandList;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void LoadCapturedValues(ReadOnlySpan<uint> data)
|
||||
{
|
||||
this.d3D12GraphicsCommandList->SetComputeRoot32BitConstants(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedResources(ReadOnlySpan<ulong> data)
|
||||
{
|
||||
ID3D12GraphicsCommandList* d3D12GraphicsCommandList = this.d3D12GraphicsCommandList;
|
||||
ref ulong resourcesRef = ref MemoryMarshal.GetReference(data);
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE startRef = ref Unsafe.As<ulong, D3D12_GPU_DESCRIPTOR_HANDLE>(ref resourcesRef);
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE endRef = ref Unsafe.Add(ref startRef, data.Length);
|
||||
uint offset = 1;
|
||||
|
||||
while (Unsafe.IsAddressLessThan(ref startRef, ref endRef))
|
||||
{
|
||||
d3D12GraphicsCommandList->SetComputeRootDescriptorTable(offset, startRef);
|
||||
|
||||
startRef = ref Unsafe.Add(ref startRef, 1);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.__Internals;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.Shaders.Dispatching;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IConstantBufferLoader"/> implementation for compute shaders dispatched via <see cref="ID3D12GraphicsCommandList"/>.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct D3D12GraphicsCommandListConstantBufferLoader : IConstantBufferLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> object in use.
|
||||
/// </summary>
|
||||
private readonly ID3D12GraphicsCommandList* d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D3D12GraphicsCommandListConstantBufferLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> object to use.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal D3D12GraphicsCommandListConstantBufferLoader(ID3D12GraphicsCommandList* d3D12GraphicsCommandList)
|
||||
{
|
||||
this.d3D12GraphicsCommandList = d3D12GraphicsCommandList;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void LoadConstantBuffer(ReadOnlySpan<byte> data)
|
||||
{
|
||||
default(ArgumentException).ThrowIf((data.Length & 3) != 0, nameof(data));
|
||||
|
||||
this.d3D12GraphicsCommandList->SetComputeRoot32BitConstants(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
|
||||
namespace ComputeSharp.Shaders.Dispatching;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IGraphicsResource"/> loader for compute shaders dispatched via <see cref="ID3D12GraphicsCommandList"/>.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct D3D12GraphicsCommandListGraphicsResourceLoader : IGraphicsResourceLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> object in use.
|
||||
/// </summary>
|
||||
private readonly ID3D12GraphicsCommandList* d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="GraphicsDevice"/> object in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice graphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The offset into the compute root descriptor table for loaded resources.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This is used to correctly align the explicit resources captured by shaders, with the implicit ones
|
||||
/// that are injected by ComputeSharp. For instance, the constant buffer is always added automatically.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For compute shaders capturing an implicit texture, this is used to skip the first target resource,
|
||||
/// as that is loaded explicitly by the shader runner using the target texture passed in by the user,
|
||||
/// which is not actually captured by the shader itself. The target root descriptor table index is therefore
|
||||
/// 2 in this case, as it needs to skip not only the this implicit texture to draw on, but also the constant
|
||||
/// buffer with capture values.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
private readonly uint rootParameterOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D3D12GraphicsCommandListGraphicsResourceLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> object to use.</param>
|
||||
/// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> instance that <paramref name="d3D12GraphicsCommandList"/> is tied to.</param>
|
||||
/// <param name="rootParameterOffset">The offset into the compute root descriptor table for loaded resources.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal D3D12GraphicsCommandListGraphicsResourceLoader(
|
||||
ID3D12GraphicsCommandList* d3D12GraphicsCommandList,
|
||||
GraphicsDevice graphicsDevice,
|
||||
uint rootParameterOffset)
|
||||
{
|
||||
this.d3D12GraphicsCommandList = d3D12GraphicsCommandList;
|
||||
this.graphicsDevice = graphicsDevice;
|
||||
this.rootParameterOffset = rootParameterOffset;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IGraphicsResourceLoader.LoadGraphicsResource(IGraphicsResource resource, uint index)
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(resource);
|
||||
|
||||
if (resource is not ID3D12ReadOnlyResource readOnlyResource)
|
||||
{
|
||||
default(ArgumentException).Throw(nameof(resource));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.d3D12GraphicsCommandList->SetComputeRootDescriptorTable(
|
||||
RootParameterIndex: this.rootParameterOffset + index,
|
||||
BaseDescriptor: readOnlyResource.ValidateAndGetGpuDescriptorHandle(this.graphicsDevice));
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.__Internals;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Shaders.Dispatching;
|
||||
|
||||
/// <summary>
|
||||
/// A data loader for pixel shaders.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct PixelShaderDispatchDataLoader : IDispatchDataLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12GraphicsCommandList"/> object in use.
|
||||
/// </summary>
|
||||
private readonly ID3D12GraphicsCommandList* d3D12GraphicsCommandList;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PixelShaderDispatchDataLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d3D12GraphicsCommandList">The <see cref="ID3D12GraphicsCommandList"/> object to use.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal PixelShaderDispatchDataLoader(ID3D12GraphicsCommandList* d3D12GraphicsCommandList)
|
||||
{
|
||||
this.d3D12GraphicsCommandList = d3D12GraphicsCommandList;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void LoadCapturedValues(ReadOnlySpan<uint> data)
|
||||
{
|
||||
this.d3D12GraphicsCommandList->SetComputeRoot32BitConstants(data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedResources(ReadOnlySpan<ulong> data)
|
||||
{
|
||||
ID3D12GraphicsCommandList* d3D12GraphicsCommandList = this.d3D12GraphicsCommandList;
|
||||
ref ulong resourcesRef = ref MemoryMarshal.GetReference(data);
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE startRef = ref Unsafe.As<ulong, D3D12_GPU_DESCRIPTOR_HANDLE>(ref resourcesRef);
|
||||
ref D3D12_GPU_DESCRIPTOR_HANDLE endRef = ref Unsafe.Add(ref startRef, data.Length);
|
||||
uint offset = 2;
|
||||
|
||||
// Skip the first target resource, as that is loaded explicitly by the shader runner using the
|
||||
// target texture passed in by the user, which is not actually captured by the shader itself.
|
||||
// The target root descriptor table index is therefore 2 in this case, as it needs to skip not
|
||||
// only the this implicit texture to draw on, but also the constant buffer with capture values.
|
||||
while (Unsafe.IsAddressLessThan(ref startRef, ref endRef))
|
||||
{
|
||||
d3D12GraphicsCommandList->SetComputeRootDescriptorTable(offset, startRef);
|
||||
|
||||
startRef = ref Unsafe.Add(ref startRef, 1);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
@@ -145,7 +143,7 @@ public static class ComputeContextExtensions
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
context.Barrier(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,7 +159,7 @@ public static class ComputeContextExtensions
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
context.Barrier(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -177,7 +175,7 @@ public static class ComputeContextExtensions
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Barrier(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
context.Barrier(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -309,11 +307,11 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Clear(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
context.Clear(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -327,11 +325,11 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Clear(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
context.Clear(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -345,11 +343,11 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Clear(((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
context.Clear(((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)), handles.Gpu, handles.Cpu, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -421,12 +419,12 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Fill(
|
||||
((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
handles.Gpu,
|
||||
handles.Cpu,
|
||||
DXGIFormatHelper.ExtendToNormalizedValue(value));
|
||||
@@ -444,12 +442,12 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Fill(
|
||||
((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
handles.Gpu,
|
||||
handles.Cpu,
|
||||
DXGIFormatHelper.ExtendToNormalizedValue(value));
|
||||
@@ -467,12 +465,12 @@ public static class ComputeContextExtensions
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(texture);
|
||||
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
(D3D12_GPU_DESCRIPTOR_HANDLE Gpu, D3D12_CPU_DESCRIPTOR_HANDLE Cpu) handles = ((ID3D12ReadWriteResource)texture).ValidateAndGetGpuAndCpuDescriptorHandlesForClear(context.GraphicsDevice, out _);
|
||||
|
||||
using ReferenceTracker.Lease lease = default;
|
||||
|
||||
context.Fill(
|
||||
((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
((ID3D12ReadOnlyResource)texture).ValidateAndGetID3D12Resource(context.GraphicsDevice, out Unsafe.AsRef(in lease)),
|
||||
handles.Gpu,
|
||||
handles.Cpu,
|
||||
DXGIFormatHelper.ExtendToNormalizedValue(value));
|
||||
|
||||
@@ -96,9 +96,12 @@ internal static unsafe class PipelineDataLoader<T>
|
||||
d3D12DescriptorRange.OffsetInDescriptorsFromTableStart = D3D12.D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
|
||||
}
|
||||
|
||||
// Calculate the actual size of the constant buffer in DWORD values
|
||||
int root32BitConstantCount = shader.ConstantBufferSize / sizeof(int);
|
||||
|
||||
// Create the D3D12 root signature
|
||||
*d3D12RootSignature = d3D12Device->CreateRootSignature(
|
||||
shader.ConstantBufferSize,
|
||||
root32BitConstantCount,
|
||||
d3D12DescriptorRanges,
|
||||
shader.IsStaticSamplerRequired).Get();
|
||||
|
||||
|
||||
@@ -1,53 +1,50 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.__Internals;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Internals.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A debug data loader for generic shaders.
|
||||
/// </summary>
|
||||
internal readonly unsafe struct DebugDispatchDataLoader : IDispatchDataLoader
|
||||
internal struct DebugDispatchDataLoader : IConstantBufferLoader, IGraphicsResourceLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The backing, mutable data for <see cref="Values"/> and <see cref="Resources"/>.
|
||||
/// The constant buffer, if set.
|
||||
/// </summary>
|
||||
private readonly StrongBox<(uint[] Values, ulong[] Resources)> data;
|
||||
private byte[]? constantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the captured values.
|
||||
/// The list of loaded resources.
|
||||
/// </summary>
|
||||
public uint[] Values => this.data.Value.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the captured resources.
|
||||
/// </summary>
|
||||
public ulong[] Resources => this.data.Value.Resources;
|
||||
private readonly List<(IGraphicsResource Resource, uint Index)> graphicsResources = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DebugDispatchDataLoader"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="DebugDispatchDataLoader"/> instance to use.</returns>
|
||||
public static DebugDispatchDataLoader Create()
|
||||
public DebugDispatchDataLoader()
|
||||
{
|
||||
DebugDispatchDataLoader @this = default;
|
||||
}
|
||||
|
||||
Unsafe.AsRef(in @this.data) = new StrongBox<(uint[], ulong[])>((Array.Empty<uint>(), Array.Empty<ulong>()));
|
||||
/// <summary>
|
||||
/// Gets the constant buffer.
|
||||
/// </summary>
|
||||
public byte[]? ConstantBuffer => this.constantBuffer;
|
||||
|
||||
return @this;
|
||||
/// <summary>
|
||||
/// Gets the loaded resources.
|
||||
/// </summary>
|
||||
public IReadOnlyList<(IGraphicsResource Resource, uint Index)> GraphicsResources => this.graphicsResources;
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
|
||||
{
|
||||
this.constantBuffer = data.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedValues(ReadOnlySpan<uint> data)
|
||||
readonly void IGraphicsResourceLoader.LoadGraphicsResource(IGraphicsResource resource, uint index)
|
||||
{
|
||||
this.data.Value.Values = data.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void LoadCapturedResources(ReadOnlySpan<ulong> data)
|
||||
{
|
||||
this.data.Value.Resources = data.ToArray();
|
||||
this.graphicsResources.Add((resource, index));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Tests.Internals.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Tests.Internals;
|
||||
|
||||
[TestClass]
|
||||
@@ -22,21 +21,27 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void CapturedResource()
|
||||
public void CapturedResource()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
CapturedResourceShader shader = new(buffer);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)new CapturedResourceShader(buffer)).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(3, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(12, ((IShader)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]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -55,26 +60,33 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadMultipleResourcesAndPrimitives()
|
||||
public void LoadMultipleResourcesAndPrimitives()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer0 = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
using ReadWriteBuffer<float> buffer1 = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
MultipleResourcesAndPrimitivesShader shader = new(buffer0, buffer1, 1, 22, 77);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)new MultipleResourcesAndPrimitivesShader(buffer0, buffer1, 1, 22, 77)).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(6, dataLoader.Values.Length);
|
||||
Assert.AreEqual(2, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(24, 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]));
|
||||
Assert.AreEqual(1, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[12]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(77, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[20]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
Assert.AreEqual(1, (int)dataLoader.Values[3]);
|
||||
Assert.AreEqual(22, (int)dataLoader.Values[4]);
|
||||
Assert.AreEqual(77, (int)dataLoader.Values[5]);
|
||||
Assert.AreEqual(buffer0.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
Assert.AreEqual(buffer1.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[1]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(2, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer0, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
Assert.AreSame(buffer1, dataLoader.GraphicsResources[1].Resource);
|
||||
Assert.AreEqual(1u, dataLoader.GraphicsResources[1].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -95,38 +107,36 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadScalarAndVectorTypes()
|
||||
public void LoadScalarAndVectorTypes()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
ScalarAndVectorTypesShader shader = new(buffer, new(55, 44, 888), 22, 77, new(3.14, 6.28), 42, 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(18, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(72, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(72, 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]));
|
||||
Assert.AreEqual(55, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[20]));
|
||||
Assert.AreEqual(888, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[24]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[28]));
|
||||
Assert.AreEqual(77, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[32]));
|
||||
Assert.AreEqual(3.14, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[48]));
|
||||
Assert.AreEqual(6.28, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[56]));
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[64]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[68]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(22, *(int*)&p1[28]);
|
||||
Assert.AreEqual(77, *(int*)&p1[32]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[48]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[56]);
|
||||
Assert.AreEqual(42, *(int*)&p1[64]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[68]);
|
||||
}
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -149,11 +159,10 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadScalarVectorAndMatrixTypes()
|
||||
public void LoadScalarVectorAndMatrixTypes()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
ScalarVectorAndMatrixTypesShader shader = new(
|
||||
buffer,
|
||||
f2x3: new(55, 44, 888, 111, 222, 333),
|
||||
@@ -164,43 +173,42 @@ public partial class ShaderDataLoaderTests
|
||||
i1x2: new(111, 222),
|
||||
i2x2: new(11, 22, 33, 44),
|
||||
d: 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(31, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(124, 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]));
|
||||
Assert.AreEqual(55, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[20]));
|
||||
Assert.AreEqual(888, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[24]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[32]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[36]));
|
||||
Assert.AreEqual(333, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[40]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[44]));
|
||||
Assert.AreEqual(1, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[48]));
|
||||
Assert.AreEqual(2, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[52]));
|
||||
Assert.AreEqual(3, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[56]));
|
||||
Assert.AreEqual(3.14, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[64]));
|
||||
Assert.AreEqual(6.28, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[72]));
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[80]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[84]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[88]));
|
||||
Assert.AreEqual(11, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[96]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[100]));
|
||||
Assert.AreEqual(33, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[112]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[116]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[120]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
}
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -229,11 +237,10 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadFlatCustomTypeShader()
|
||||
public void LoadFlatCustomTypeShader()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
FlatCustomTypeShader shader = new(
|
||||
buffer,
|
||||
new SimpleTypes(
|
||||
@@ -245,43 +252,42 @@ public partial class ShaderDataLoaderTests
|
||||
i1x2: new(111, 222),
|
||||
i2x2: new(11, 22, 33, 44),
|
||||
d: 9999));
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(31, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(124, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(124, 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]));
|
||||
Assert.AreEqual(55, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[20]));
|
||||
Assert.AreEqual(888, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[24]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[32]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[36]));
|
||||
Assert.AreEqual(333, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[40]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[44]));
|
||||
Assert.AreEqual(1, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[48]));
|
||||
Assert.AreEqual(2, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[52]));
|
||||
Assert.AreEqual(3, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[56]));
|
||||
Assert.AreEqual(3.14, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[64]));
|
||||
Assert.AreEqual(6.28, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[72]));
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[80]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[84]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[88]));
|
||||
Assert.AreEqual(11, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[96]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[100]));
|
||||
Assert.AreEqual(33, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[112]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[116]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[120]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(55, *(float*)&p1[16]);
|
||||
Assert.AreEqual(44, *(float*)&p1[20]);
|
||||
Assert.AreEqual(888, *(float*)&p1[24]);
|
||||
Assert.AreEqual(111, *(float*)&p1[32]);
|
||||
Assert.AreEqual(222, *(float*)&p1[36]);
|
||||
Assert.AreEqual(333, *(float*)&p1[40]);
|
||||
Assert.AreEqual(22, *(int*)&p1[44]);
|
||||
Assert.AreEqual(1, *(int*)&p1[48]);
|
||||
Assert.AreEqual(2, *(int*)&p1[52]);
|
||||
Assert.AreEqual(3, *(int*)&p1[56]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[64]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[72]);
|
||||
Assert.AreEqual(42, *(int*)&p1[80]);
|
||||
Assert.AreEqual(111, *(int*)&p1[84]);
|
||||
Assert.AreEqual(222, *(int*)&p1[88]);
|
||||
Assert.AreEqual(11, *(int*)&p1[96]);
|
||||
Assert.AreEqual(22, *(int*)&p1[100]);
|
||||
Assert.AreEqual(33, *(int*)&p1[112]);
|
||||
Assert.AreEqual(44, *(int*)&p1[116]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[120]);
|
||||
}
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -322,11 +328,10 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadNestedCustomTypes()
|
||||
public void LoadNestedCustomTypes()
|
||||
{
|
||||
using ReadWriteBuffer<float> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
NestedCustomTypesShader shader = new(
|
||||
buffer,
|
||||
new CustomType1(
|
||||
@@ -350,56 +355,55 @@ public partial class ShaderDataLoaderTests
|
||||
e: new CustomType3(
|
||||
a: 888888,
|
||||
b: new(333.3f, 444.4f))));
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(47, dataLoader.Values.Length);
|
||||
Assert.AreEqual(1, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(188, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(188, 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]));
|
||||
Assert.AreEqual(3.14f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(6.28f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[20]));
|
||||
Assert.AreEqual(123.4f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[24]));
|
||||
Assert.AreEqual(55, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[32]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[36]));
|
||||
Assert.AreEqual(888, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[40]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[48]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[52]));
|
||||
Assert.AreEqual(333, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[56]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[60]));
|
||||
Assert.AreEqual(1, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[64]));
|
||||
Assert.AreEqual(2, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[68]));
|
||||
Assert.AreEqual(3, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[72]));
|
||||
Assert.AreEqual(3.14, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[80]));
|
||||
Assert.AreEqual(6.28, Unsafe.As<byte, double>(ref dataLoader.ConstantBuffer[88]));
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[96]));
|
||||
Assert.AreEqual(111, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[100]));
|
||||
Assert.AreEqual(222, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[104]));
|
||||
Assert.AreEqual(11, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[112]));
|
||||
Assert.AreEqual(22, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[116]));
|
||||
Assert.AreEqual(33, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[128]));
|
||||
Assert.AreEqual(44, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[132]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[136]));
|
||||
Assert.AreEqual(42, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[140]));
|
||||
Assert.AreEqual(1234567, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[144]));
|
||||
Assert.AreEqual(44.4f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[148]));
|
||||
Assert.AreEqual(55.5f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[152]));
|
||||
Assert.AreEqual(7654321, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[160]));
|
||||
Assert.AreEqual(111.1f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[164]));
|
||||
Assert.AreEqual(222.2f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[168]));
|
||||
Assert.AreEqual(888888, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[176]));
|
||||
Assert.AreEqual(333.3f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[180]));
|
||||
Assert.AreEqual(444.4f, Unsafe.As<byte, float>(ref dataLoader.ConstantBuffer[184]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
|
||||
fixed (void* p0 = &dataLoader.Values[0])
|
||||
{
|
||||
byte* p1 = (byte*)p0;
|
||||
|
||||
Assert.AreEqual(3.14f, *(float*)&p1[16]);
|
||||
Assert.AreEqual(6.28f, *(float*)&p1[20]);
|
||||
Assert.AreEqual(123.4f, *(float*)&p1[24]);
|
||||
Assert.AreEqual(55, *(float*)&p1[32]);
|
||||
Assert.AreEqual(44, *(float*)&p1[36]);
|
||||
Assert.AreEqual(888, *(float*)&p1[40]);
|
||||
Assert.AreEqual(111, *(float*)&p1[48]);
|
||||
Assert.AreEqual(222, *(float*)&p1[52]);
|
||||
Assert.AreEqual(333, *(float*)&p1[56]);
|
||||
Assert.AreEqual(22, *(int*)&p1[60]);
|
||||
Assert.AreEqual(1, *(int*)&p1[64]);
|
||||
Assert.AreEqual(2, *(int*)&p1[68]);
|
||||
Assert.AreEqual(3, *(int*)&p1[72]);
|
||||
Assert.AreEqual(3.14, *(double*)&p1[80]);
|
||||
Assert.AreEqual(6.28, *(double*)&p1[88]);
|
||||
Assert.AreEqual(42, *(int*)&p1[96]);
|
||||
Assert.AreEqual(111, *(int*)&p1[100]);
|
||||
Assert.AreEqual(222, *(int*)&p1[104]);
|
||||
Assert.AreEqual(11, *(int*)&p1[112]);
|
||||
Assert.AreEqual(22, *(int*)&p1[116]);
|
||||
Assert.AreEqual(33, *(int*)&p1[128]);
|
||||
Assert.AreEqual(44, *(int*)&p1[132]);
|
||||
Assert.AreEqual(9999, *(int*)&p1[136]);
|
||||
Assert.AreEqual(42, *(int*)&p1[140]);
|
||||
Assert.AreEqual(1234567, *(int*)&p1[144]);
|
||||
Assert.AreEqual(44.4f, *(float*)&p1[148]);
|
||||
Assert.AreEqual(55.5f, *(float*)&p1[152]);
|
||||
Assert.AreEqual(7654321, *(int*)&p1[160]);
|
||||
Assert.AreEqual(111.1f, *(float*)&p1[164]);
|
||||
Assert.AreEqual(222.2f, *(float*)&p1[168]);
|
||||
Assert.AreEqual(888888, *(int*)&p1[176]);
|
||||
Assert.AreEqual(333.3f, *(float*)&p1[180]);
|
||||
Assert.AreEqual(444.4f, *(float*)&p1[184]);
|
||||
}
|
||||
Assert.AreEqual(1, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(buffer, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
@@ -422,7 +426,7 @@ public partial class ShaderDataLoaderTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void AmbiguousNames()
|
||||
public void AmbiguousNames()
|
||||
{
|
||||
using ReadWriteBuffer<float> a = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
using ReadWriteBuffer<float> b = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
@@ -431,24 +435,35 @@ public partial class ShaderDataLoaderTests
|
||||
using ReadWriteBuffer<float> y = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
using ReadWriteBuffer<float> z = GraphicsDevice.GetDefault().AllocateReadWriteBuffer<float>(16);
|
||||
|
||||
DebugDispatchDataLoader dataLoader = DebugDispatchDataLoader.Create();
|
||||
AmbiguousNamesShader shader = new(a, b, c, x, y, z, 7777, 8888, 9999);
|
||||
DebugDispatchDataLoader dataLoader = new();
|
||||
|
||||
((IShader)new AmbiguousNamesShader(a, b, c, x, y, z, 7777, 8888, 9999)).LoadDispatchData(ref dataLoader, GraphicsDevice.GetDefault(), 111, 222, 333);
|
||||
((IShader)shader).LoadConstantBuffer(ref dataLoader, 111, 222, 333);
|
||||
|
||||
Assert.AreEqual(6, dataLoader.Values.Length);
|
||||
Assert.AreEqual(6, dataLoader.Resources.Length);
|
||||
Assert.AreEqual(24, ((IShader)shader).ConstantBufferSize);
|
||||
Assert.IsNotNull(dataLoader.ConstantBuffer);
|
||||
Assert.AreEqual(24, 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]));
|
||||
Assert.AreEqual(7777, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[12]));
|
||||
Assert.AreEqual(8888, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[16]));
|
||||
Assert.AreEqual(9999, Unsafe.As<byte, int>(ref dataLoader.ConstantBuffer[20]));
|
||||
|
||||
Assert.AreEqual(111, (int)dataLoader.Values[0]);
|
||||
Assert.AreEqual(222, (int)dataLoader.Values[1]);
|
||||
Assert.AreEqual(333, (int)dataLoader.Values[2]);
|
||||
Assert.AreEqual(7777, (int)dataLoader.Values[3]);
|
||||
Assert.AreEqual(8888, (int)dataLoader.Values[4]);
|
||||
Assert.AreEqual(9999, (int)dataLoader.Values[5]);
|
||||
Assert.AreEqual(a.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);
|
||||
Assert.AreEqual(b.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[1]);
|
||||
Assert.AreEqual(c.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[2]);
|
||||
Assert.AreEqual(x.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[3]);
|
||||
Assert.AreEqual(y.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[4]);
|
||||
Assert.AreEqual(z.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[5]);
|
||||
((IShader)shader).LoadGraphicsResources(ref dataLoader);
|
||||
|
||||
Assert.AreEqual(6, ((IShader)shader).ResourceDescriptorRanges.Length);
|
||||
Assert.AreSame(a, dataLoader.GraphicsResources[0].Resource);
|
||||
Assert.AreEqual(0u, dataLoader.GraphicsResources[0].Index);
|
||||
Assert.AreSame(b, dataLoader.GraphicsResources[1].Resource);
|
||||
Assert.AreEqual(1u, dataLoader.GraphicsResources[1].Index);
|
||||
Assert.AreSame(c, dataLoader.GraphicsResources[2].Resource);
|
||||
Assert.AreEqual(2u, dataLoader.GraphicsResources[2].Index);
|
||||
Assert.AreSame(x, dataLoader.GraphicsResources[3].Resource);
|
||||
Assert.AreEqual(3u, dataLoader.GraphicsResources[3].Index);
|
||||
Assert.AreSame(y, dataLoader.GraphicsResources[4].Resource);
|
||||
Assert.AreEqual(4u, dataLoader.GraphicsResources[4].Index);
|
||||
Assert.AreSame(z, dataLoader.GraphicsResources[5].Resource);
|
||||
Assert.AreEqual(5u, dataLoader.GraphicsResources[5].Index);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする