Added TerraFX GraphicsResource type
このコミットが含まれているのは:
1 親
10dfef9a5c
コミット
d4752ef1b0
2ファイル変更
+128
検索条件に一致するファイルはありません
@@ -0,0 +1,86 @@
|
||||
using ComputeSharp.Core.Interop;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract <see langword="class"/> that represents a graphics resource object.
|
||||
/// </summary>
|
||||
public abstract unsafe class GraphicsResource2 : NativeObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID3D12Resource"/> instance currently mapped.
|
||||
/// </summary>
|
||||
protected internal readonly ID3D12Resource* D3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsResource"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
protected GraphicsResource2(GraphicsDevice device, ID3D12Resource* d3d12resource)
|
||||
{
|
||||
D3D12Resource = d3d12resource;
|
||||
|
||||
GraphicsDevice = device;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Maps the current resource to a specified subresource.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="MappedResource"/> instance representing the mapped resource.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal MappedResource MapResource()
|
||||
{
|
||||
return new MappedResource(D3D12Resource);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
D3D12Resource->Release();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type representing a mapped memory resource.
|
||||
/// </summary>
|
||||
internal readonly ref struct MappedResource
|
||||
{
|
||||
/// <summary>
|
||||
/// The target <see cref="ID3D12Resource"/> to map.
|
||||
/// </summary>
|
||||
private readonly ID3D12Resource* d3D12Resource;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the mapped resource.
|
||||
/// </summary>
|
||||
public readonly IntPtr Pointer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MappedResource"/> instance for a given <see cref="ID3D12Resource"/> value.
|
||||
/// </summary>
|
||||
/// <param name="resource">The input <see cref="ID3D12Resource"/> instance to map.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public MappedResource(ID3D12Resource* d3d12resource)
|
||||
{
|
||||
d3D12Resource = d3d12resource;
|
||||
|
||||
Pointer = d3d12resource->Map();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
d3D12Resource->Unmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with extensions for the <see cref="ID3D12Resource"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class ID3D12ResourceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps a given <see cref="ID3D12Resource"/> memory area.
|
||||
/// </summary>
|
||||
/// <param name="d3d12resource">The target <see cref="ID3D12Resource"/> to map.</param>
|
||||
/// <returns>A pointer to the mapped area for <paramref name="d3d12resource"/>.</returns>
|
||||
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
|
||||
public static IntPtr Map(this ref ID3D12Resource d3d12resource)
|
||||
{
|
||||
IntPtr ptr;
|
||||
|
||||
int result = d3d12resource.Map(0, null, (void**)&ptr);
|
||||
|
||||
if (FX.FAILED(result)) Marshal.ThrowExceptionForHR(result);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a given <see cref="ID3D12Resource"/> memory area.
|
||||
/// </summary>
|
||||
/// <param name="d3d12resource">The target <see cref="ID3D12Resource"/> to map.</param>
|
||||
/// <returns>A pointer to the mapped area for <paramref name="d3d12resource"/>.</returns>
|
||||
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
|
||||
/// <remarks>Only use this method to unmap resources that were mapped with <see cref="Map(ref ID3D12Resource)"/>.</remarks>
|
||||
public static void Unmap(this ref ID3D12Resource d3d12resource)
|
||||
{
|
||||
d3d12resource.Unmap(0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする