Add PIX set marker extension for ComputeContext

このコミットが含まれているのは:
Sergio Pedri committed 2022-06-19 02:57:58 +02:00
1 親 4222a7092a
コミット d5556daa36
5ファイル変更
+134 -4

検索条件に一致するファイルはありません

+43
ファイルの表示
@@ -0,0 +1,43 @@
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Text;
using TerraFX.Interop.DirectX;
namespace ComputeSharp.Interop;
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ID3D12GraphicsCommandList"/> type.
/// </summary>
internal static class ID3D12GraphicsCommandListExtensions
{
/// <summary>
/// Sets a PIX marker on a target <see cref="ID3D12GraphicsCommandList"/> object.
/// </summary>
/// <param name="d3D12GraphicsCommandList">The target <see cref="ID3D12GraphicsCommandList"/> object.</param>
/// <param name="message">The message to use for the marker.</param>
public static unsafe void SetPixMarker(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, string message)
{
// Rent a byte buffer with space for the null-terminator too
int maxByteLength = Encoding.ASCII.GetMaxByteCount(message.Length) + 1;
byte[] buffer = ArrayPool<byte>.Shared.Rent(maxByteLength);
int bytesWritten;
fixed (byte* bufferPtr = buffer)
{
// Transcode from unicode to ASCII
fixed (char* messagePtr = message)
{
bytesWritten = Encoding.ASCII.GetBytes(messagePtr, message.Length, bufferPtr, buffer.Length);
}
// Add the null terminator
buffer[bytesWritten] = 0;
// Write the marker with the null-terminated ANSI message
Pix.PIXSetMarkerOnCommandList((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref d3D12GraphicsCommandList), 0, (sbyte*)bufferPtr);
}
// Return the buffer (if an exception is thrown, it's fine to not do so)
ArrayPool<byte>.Shared.Return(buffer);
}
}
+44
ファイルの表示
@@ -0,0 +1,44 @@
using System.Runtime.InteropServices;
using TerraFX.Interop.DirectX;
namespace ComputeSharp.Interop;
/// <summary>
/// A collection of native bindings for PIX APIs (see <see href="https://devblogs.microsoft.com/pix/winpixeventruntime/"/>).
/// </summary>
internal static unsafe class Pix
{
/// <summary>
/// Starts a PIX event on a target <see cref="ID3D12GraphicsCommandList"/> object.
/// <para>
/// C export: <c>typedef void(WINAPI* BeginEventOnCommandList)(ID3D12GraphicsCommandList* commandList, UINT64 color, _In_ PCSTR formatString)</c>.
/// </para>
/// </summary>
/// <param name="commandList">The target <see cref="ID3D12GraphicsCommandList"/> object.</param>
/// <param name="color">The color to use for the event.</param>
/// <param name="formatString">The format string to use for the event (in ANSI format, <see langword="null"/>-terminated).</param>
[DllImport("WinPixEventRuntime", ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern void PIXBeginEventOnCommandList(ID3D12GraphicsCommandList* commandList, ulong color, sbyte* formatString);
/// <summary>
/// Ends a PIX event on a target <see cref="ID3D12GraphicsCommandList"/> object.
/// <para>
/// C export: <c>typedef void(WINAPI* EndEventOnCommandList)(ID3D12GraphicsCommandList* commandList)</c>.
/// </para>
/// </summary>
/// <param name="commandList">The target <see cref="ID3D12GraphicsCommandList"/> object.</param>
[DllImport("WinPixEventRuntime", ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern void PIXEndEventOnCommandList(ID3D12GraphicsCommandList* commandList);
/// <summary>
/// Sets a PIX marker on a target <see cref="ID3D12GraphicsCommandList"/> object.
/// <para>
/// C export: <c>typedef void(WINAPI* SetMarkerOnCommandList)(ID3D12GraphicsCommandList* commandList, UINT64 color, _In_ PCSTR formatString)</c>.
/// </para>
/// </summary>
/// <param name="commandList">The target <see cref="ID3D12GraphicsCommandList"/> object.</param>
/// <param name="color">The color to use for the marker.</param>
/// <param name="formatString">The format string to use for the marker (in ANSI format, <see langword="null"/>-terminated).</param>
[DllImport("WinPixEventRuntime", ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern void PIXSetMarkerOnCommandList(ID3D12GraphicsCommandList* commandList, ulong color, sbyte* formatString);
}