using System;
using System.Diagnostics;
using System.Drawing;
using ComputeSharp.Graphics.Commands;
using ComputeSharp.Interop;
namespace ComputeSharp;
///
/// A that contains extension methods using PIX APIs for the type.
///
public static class ComputeContextExtensions
{
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The color to use for the event (the alpha channel will be ignored).
/// The message to use for the event.
[Conditional("USE_PIX")]
public static unsafe void BeginEvent(this ref readonly ComputeContext context, Color color, string message)
{
ref CommandList commandList = ref context.GetCommandList(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);
}
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The index to identify the group this event belongs to (PIX will choose a color to represent all entries in the group).
/// The message to use for the event.
[Conditional("USE_PIX")]
public static unsafe void BeginEvent(this ref readonly ComputeContext context, byte index, string message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->BeginEvent(pixColor, message);
}
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The message to use for the event.
[Conditional("USE_PIX")]
public static unsafe void BeginEvent(this ref readonly ComputeContext context, string message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
commandList.D3D12GraphicsCommandList->BeginEvent(0, message);
}
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The color to use for the event (the alpha channel will be ignored).
/// The message to use for the event (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void BeginEventUnsafe(this ref readonly ComputeContext context, Color color, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
int argb = color.ToArgb();
uint pixColor = Pix.PIX_COLOR((byte)((argb & 0x00FF0000) >> 16), (byte)((argb & 0x0000FF00) >> 8), (byte)(argb & 0x000000FF));
commandList.D3D12GraphicsCommandList->BeginEventUnsafe(pixColor, message);
}
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The index to identify the group this event belongs to (PIX will choose a color to represent all entries in the group).
/// The message to use for the event (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void BeginEventUnsafe(this ref readonly ComputeContext context, byte index, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->BeginEventUnsafe(pixColor, message);
}
///
/// Starts a PIX event on a target object.
///
/// The to use to start the PIX event.
/// The message to use for the event (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void BeginEventUnsafe(this ref readonly ComputeContext context, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
commandList.D3D12GraphicsCommandList->BeginEventUnsafe(0, message);
}
///
/// Ends a PIX event on a target object.
///
/// The to use to end the PIX event.
[Conditional("USE_PIX")]
public static unsafe void EndEvent(this ref readonly ComputeContext context)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
Pix.PIXEndEventOnCommandList(commandList.D3D12GraphicsCommandList);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The color to use for the log (the alpha channel will be ignored).
/// The message to use for the marker.
[Conditional("USE_PIX")]
public static unsafe void Log(this ref readonly ComputeContext context, Color color, string message)
{
ref CommandList commandList = ref context.GetCommandList(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);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The index to identify the group this log belongs to (PIX will choose a color to represent all entries in the group).
/// The message to use for the marker.
[Conditional("USE_PIX")]
public static unsafe void Log(this ref readonly ComputeContext context, byte index, string message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->SetPixMarker(pixColor, message);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The message to use for the marker.
[Conditional("USE_PIX")]
public static unsafe void Log(this ref readonly ComputeContext context, string message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
commandList.D3D12GraphicsCommandList->SetPixMarker(0, message);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The color to use for the log (the alpha channel will be ignored).
/// The message to use for the marker (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void LogUnsafe(this ref readonly ComputeContext context, Color color, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
int argb = color.ToArgb();
uint pixColor = Pix.PIX_COLOR((byte)((argb & 0x00FF0000) >> 16), (byte)((argb & 0x0000FF00) >> 8), (byte)(argb & 0x000000FF));
commandList.D3D12GraphicsCommandList->SetPixMarkerUnsafe(pixColor, message);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The index to identify the group this log belongs to (PIX will choose a color to represent all entries in the group).
/// The message to use for the marker (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void LogUnsafe(this ref readonly ComputeContext context, byte index, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
uint pixColor = Pix.PIX_COLOR_INDEX(index);
commandList.D3D12GraphicsCommandList->SetPixMarkerUnsafe(pixColor, message);
}
///
/// Sets a PIX marker on a target object.
///
/// The to use to insert the PIX marker.
/// The message to use for the marker (it's assumed to be a -terminated ANSI characters sequence).
///
///
/// The parameter is not checked to ensure it has a -terminator. This allows callers
/// to pass an UTF8 string literal containing only ASCII characters (as the byte contents would be a valid ANSI sequence in that case).
/// The compiler will automatically insert a terminator right past the end of the returned when doing so.
///
///
/// This method offers greatly reduced overhead compared to the overlods taking a , as there is no need to create the
/// instance nor to execute the transcoding at runtime. The behavior when the input is invalid though is undefined.
/// Callers must take extra care to ensure the input message is in fact -terminated when invoking this API.
///
///
[Conditional("USE_PIX")]
public static unsafe void LogUnsafe(this ref readonly ComputeContext context, ReadOnlySpan message)
{
ref CommandList commandList = ref context.GetCommandList(pipelineState: null);
commandList.D3D12GraphicsCommandList->SetPixMarkerUnsafe(0, message);
}
}