Complete set of PIX extensions for ComputeContext

このコミットが含まれているのは:
Sergio Pedri committed 2022-06-19 02:57:59 +02:00
1 親 279c464dc2
コミット a4763426fe
2ファイル変更
+107 -8

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

+70 -4
ファイルの表示
@@ -1,4 +1,4 @@
using System;
using System.Drawing;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Interop;
@@ -9,6 +9,37 @@ namespace ComputeSharp;
/// </summary>
public static class ComputeContextExtensions
{
/// <summary>
/// Starts a PIX event on a target <see cref="ComputeContext"/> object.
/// </summary>
/// <param name="context">The <see cref="ComputeContext"/> to use to start the PIX event.</param>
/// <param name="color">The color to use for the event (the alpha channel will be ignored).</param>
/// <param name="message">The message to use for the event.</param>
public static unsafe void BeginEvent(this in ComputeContext context, Color color, string message)
{
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
int argb = color.ToArgb();
uint pixColor = Pix.PIX_COLOR((byte)((argb & 0x00FF0000) >> 16), (byte)((argb & 0x0000FF00) >> 8), (byte)(argb & 0x000000FF));
commandList.D3D12GraphicsCommandList->BeginEvent(pixColor, message);
}
/// <summary>
/// Starts a PIX event on a target <see cref="ComputeContext"/> object.
/// </summary>
/// <param name="context">The <see cref="ComputeContext"/> to use to start the PIX event.</param>
/// <param name="index">The index to identify the group this event belongs to (PIX will choose a color to represent all entries in the group).</param>
/// <param name="message">The message to use for the event.</param>
public static unsafe void BeginEvent(this in ComputeContext context, byte index, string message)
{
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->BeginEvent(pixColor, message);
}
/// <summary>
/// Starts a PIX event on a target <see cref="ComputeContext"/> object.
/// </summary>
@@ -16,7 +47,9 @@ public static class ComputeContextExtensions
/// <param name="message">The message to use for the event.</param>
public static unsafe void BeginEvent(this in ComputeContext context, string message)
{
throw new NotImplementedException();
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
commandList.D3D12GraphicsCommandList->BeginEvent(0, message);
}
/// <summary>
@@ -25,7 +58,40 @@ public static class ComputeContextExtensions
/// <param name="context">The <see cref="ComputeContext"/> to use to end the PIX event.</param>
public static unsafe void EndEvent(this in ComputeContext context)
{
throw new NotImplementedException();
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
Pix.PIXEndEventOnCommandList(commandList.D3D12GraphicsCommandList);
}
/// <summary>
/// Sets a PIX marker on a target <see cref="ComputeContext"/> object.
/// </summary>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the PIX marker.</param>
/// <param name="color">The color to use for the log (the alpha channel will be ignored).</param>
/// <param name="message">The message to use for the marker.</param>
public static unsafe void Log(this in ComputeContext context, Color color, string message)
{
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
int argb = color.ToArgb();
uint pixColor = Pix.PIX_COLOR((byte)((argb & 0x00FF0000) >> 16), (byte)((argb & 0x0000FF00) >> 8), (byte)(argb & 0x000000FF));
commandList.D3D12GraphicsCommandList->SetPixMarker(pixColor, message);
}
/// <summary>
/// Sets a PIX marker on a target <see cref="ComputeContext"/> object.
/// </summary>
/// <param name="context">The <see cref="ComputeContext"/> to use to insert the PIX marker.</param>
/// <param name="index">The index to identify the group this log belongs to (PIX will choose a color to represent all entries in the group).</param>
/// <param name="message">The message to use for the marker.</param>
public static unsafe void Log(this in ComputeContext context, byte index, string message)
{
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->SetPixMarker(pixColor, message);
}
/// <summary>
@@ -37,6 +103,6 @@ public static class ComputeContextExtensions
{
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
commandList.D3D12GraphicsCommandList->SetPixMarker(message);
commandList.D3D12GraphicsCommandList->SetPixMarker(0, message);
}
}
+37 -4
ファイルの表示
@@ -11,11 +11,12 @@ namespace ComputeSharp.Interop;
internal static class ID3D12GraphicsCommandListExtensions
{
/// <summary>
/// Sets a PIX marker on a target <see cref="ID3D12GraphicsCommandList"/> object.
/// Begins a PIX event 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)
/// <param name="color">The color to use for the event.</param>
/// <param name="message">The message to use for the event.</param>
public static unsafe void BeginEvent(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, uint color, string message)
{
// Rent a byte buffer with space for the null-terminator too
int maxByteLength = Encoding.ASCII.GetMaxByteCount(message.Length) + 1;
@@ -34,7 +35,39 @@ internal static class ID3D12GraphicsCommandListExtensions
buffer[bytesWritten] = 0;
// Write the marker with the null-terminated ANSI message
Pix.PIXSetMarkerOnCommandList((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref d3D12GraphicsCommandList), 0, (sbyte*)bufferPtr);
Pix.PIXBeginEventOnCommandList((ID3D12GraphicsCommandList*)Unsafe.AsPointer(ref d3D12GraphicsCommandList), color, (sbyte*)bufferPtr);
}
// Return the buffer (if an exception is thrown, it's fine to not do so)
ArrayPool<byte>.Shared.Return(buffer);
}
/// <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="color">The color to use for the marker.</param>
/// <param name="message">The message to use for the marker.</param>
public static unsafe void SetPixMarker(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, uint color, 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), color, (sbyte*)bufferPtr);
}
// Return the buffer (if an exception is thrown, it's fine to not do so)