Add PIX set marker extension for ComputeContext
このコミットが含まれているのは:
1 親
4222a7092a
コミット
d5556daa36
5ファイル変更
+134
-4
検索条件に一致するファイルはありません
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Interop;
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that contains extension methods using PIX APIs for the <see cref="ComputeContext"/> type.
|
||||
/// </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="message">The message to use for the event.</param>
|
||||
public static unsafe void BeginEvent(this in ComputeContext context, string message)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends a PIX event on a target <see cref="ComputeContext"/> object.
|
||||
/// </summary>
|
||||
/// <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();
|
||||
}
|
||||
|
||||
/// <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="message">The message to use for the marker.</param>
|
||||
public static unsafe void Log(this in ComputeContext context, string message)
|
||||
{
|
||||
ref CommandList commandList = ref ComputeContext.GetCommandList(in context, pipelineState: null);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->SetPixMarker(message);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
[module: SkipLocalsInit]
|
||||
|
||||
[assembly: InternalsVisibleTo("ComputeSharp.Dynamic")]
|
||||
[assembly: InternalsVisibleTo("ComputeSharp.Pix")]
|
||||
[assembly: InternalsVisibleTo("ComputeSharp.Uwp")]
|
||||
[assembly: InternalsVisibleTo("ComputeSharp.WinUI")]
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
{
|
||||
ThrowInvalidOperationExceptionIfDeviceIsNull();
|
||||
|
||||
ref CommandList commandList = ref GetCommandList(in this, null);
|
||||
ref CommandList commandList = ref GetCommandList(in this, pipelineState: null);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->ClearUnorderedAccessView(d3D12Resource, d3D12GpuDescriptorHandle, d3D12CpuDescriptorHandle, isNormalized);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
{
|
||||
ThrowInvalidOperationExceptionIfDeviceIsNull();
|
||||
|
||||
ref CommandList commandList = ref GetCommandList(in this, null);
|
||||
ref CommandList commandList = ref GetCommandList(in this, pipelineState: null);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->FillUnorderedAccessView(d3D12Resource, d3D12GpuDescriptorHandle, d3D12CpuDescriptorHandle, value);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
{
|
||||
ThrowInvalidOperationExceptionIfDeviceIsNull();
|
||||
|
||||
ref CommandList commandList = ref GetCommandList(in this, null);
|
||||
ref CommandList commandList = ref GetCommandList(in this, pipelineState: null);
|
||||
|
||||
commandList.D3D12GraphicsCommandList->TransitionBarrier(d3D12Resource, d3D12ResourceStatesBefore, d3D12ResourceStatesAfter);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
/// <param name="pipelineState">The input <see cref="ID3D12PipelineState"/> to load.</param>
|
||||
/// <returns>A reference to the <see cref="CommandList"/> instance to use.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static unsafe ref CommandList GetCommandList(in ComputeContext @this, ID3D12PipelineState* pipelineState)
|
||||
internal static unsafe ref CommandList GetCommandList(in ComputeContext @this, ID3D12PipelineState* pipelineState)
|
||||
{
|
||||
ref ComputeContext context = ref Unsafe.AsRef(in @this);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする