mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
15 changed files with 768360 additions and 0 deletions
6
brutal.renderdoc/Brutal.RenderDoc.ImGui/GlobalUsings.cs
Normal file
6
brutal.renderdoc/Brutal.RenderDoc.ImGui/GlobalUsings.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
global using System.Runtime.CompilerServices;
|
||||
global using Brutal.ImGuiApi;
|
||||
global using Brutal.Numerics;
|
||||
global using static Brutal.RenderDocApi.Logger;
|
||||
global using Brutal.Strings;
|
||||
global using Brutal.Strings.Extensions;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
Brutal.RenderDoc.ImGui builds on the Brutal.RenderDoc bindings to the
|
||||
third-party component listed below, reproduced with the licence that
|
||||
governs it.
|
||||
|
||||
============================================================
|
||||
RenderDoc 1.42 -- MIT -- https://github.com/baldurk/renderdoc
|
||||
============================================================
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2025 Baldur Karlsson
|
||||
|
||||
Copyright (c) 2014 Crytek
|
||||
|
||||
Copyright (c) 1998-2018 Third party code and tools
|
||||
(https://github.com/baldurk/renderdoc/blob/v1.42/docs/credits_acknowledgements.rst)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
314
brutal.renderdoc/Brutal.RenderDoc.ImGui/RenderDocWindow.cs
Normal file
314
brutal.renderdoc/Brutal.RenderDoc.ImGui/RenderDocWindow.cs
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
/// Helper to control RenderDoc, view captures etc., through an ImGui window.
|
||||
public class RenderDocWindow
|
||||
{
|
||||
public static readonly RenderDocWindow Instance = new();
|
||||
|
||||
bool LoadApi()
|
||||
{
|
||||
var success = RenderDoc.LoadApi();
|
||||
Log.Info($"RenderDoc API {(success ? "loaded successfully" : "loading failed")}");
|
||||
return success;
|
||||
}
|
||||
|
||||
void UnloadApi()
|
||||
{
|
||||
RenderDoc.RemoveHooks();
|
||||
Log.Info("RenderDoc API unloaded");
|
||||
}
|
||||
|
||||
void OpenUI()
|
||||
{
|
||||
var connected = RenderDoc.IsTargetControlConnected;
|
||||
var res = connected ? RenderDoc.ShowReplayUI() : RenderDoc.LaunchReplayUI(true, null);
|
||||
Log.Info(connected ? $"ShowReplayUI {res}" : $"LaunchReplayUI {res}");
|
||||
}
|
||||
|
||||
int frameCount;
|
||||
uint? triggerCaptureIndex;
|
||||
public bool Visible;
|
||||
|
||||
public void OnImGui()
|
||||
{
|
||||
OnUpdate();
|
||||
DrawMenuBar();
|
||||
DrawWindow();
|
||||
}
|
||||
|
||||
void OnUpdate()
|
||||
{
|
||||
frameCount++;
|
||||
|
||||
if (!RenderDoc.IsAvailable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (triggerCaptureIndex.HasValue && RenderDoc.NumCaptures > triggerCaptureIndex)
|
||||
{
|
||||
triggerCaptureIndex = null;
|
||||
Log.Info($"TriggerCapture finished (frame {frameCount}, {RenderDoc.NumCaptures} captures)");
|
||||
}
|
||||
}
|
||||
|
||||
void DrawMenuBar()
|
||||
{
|
||||
if (ImGui.BeginMainMenuBar())
|
||||
{
|
||||
if (ImGui.BeginMenu("View"u8))
|
||||
{
|
||||
if (ImGui.MenuItem("RenderDoc"u8, selected: Visible))
|
||||
Visible = !Visible;
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
||||
ImGui.EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawWindow()
|
||||
{
|
||||
if (!Visible)
|
||||
return;
|
||||
|
||||
var status = RenderDoc.State switch
|
||||
{
|
||||
RenderDoc.ControllerState.NotLoaded => "(not loaded)",
|
||||
RenderDoc.ControllerState.LoadFail => "(loading failed)",
|
||||
RenderDoc.ControllerState.LoadSuccess =>
|
||||
$"{RenderDoc.Version}{(RenderDoc.IsTargetControlConnected ? " (connected)" : "")}",
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
};
|
||||
|
||||
if (ImGui.Begin($"RenderDoc {status}###RenderDoc", ref Visible))
|
||||
{
|
||||
DrawWindowContent();
|
||||
}
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
void DrawWindowContent()
|
||||
{
|
||||
// insert a help URL in the top-right corner
|
||||
ImGui.SameLine(ImGui.GetContentRegionAvail().X - 25); // right-align
|
||||
ImGui.TextLinkOpenURL("Help"u8, "https://renderdoc.org/docs/in_application_api.html"u8);
|
||||
ImGui.SetCursorPos(ImGui.GetCursorStartPos()); // reset
|
||||
|
||||
if (RenderDoc.IsAvailable)
|
||||
{
|
||||
DrawWindowContentWhenAvailable();
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
||||
// the load/unload button is somewhat misleading -> draw it last:
|
||||
// - loading late appears to work but capturing might fail
|
||||
// - unloading/detaching is not guaranteed to work: https://renderdoc.org/docs/in_application_api.html#_CPPv411RemoveHooksv)
|
||||
if (ImGui.Button(RenderDoc.ApiLoaded ? "Unload RenderDoc"u8 : "Load RenderDoc"u8))
|
||||
{
|
||||
if (RenderDoc.ApiLoaded)
|
||||
UnloadApi();
|
||||
else
|
||||
LoadApi();
|
||||
}
|
||||
}
|
||||
|
||||
static readonly ImInputString CaptureFilePathTemplate = new(256);
|
||||
|
||||
void DrawWindowContentWhenAvailable()
|
||||
{
|
||||
var overlayBits = RenderDoc.OverlayBits;
|
||||
if (
|
||||
ImGui.CheckboxFlags(
|
||||
"##enabled"u8,
|
||||
ref Unsafe.As<OverlayBits, int>(ref overlayBits),
|
||||
(int)OverlayBits.Enabled
|
||||
)
|
||||
)
|
||||
{
|
||||
RenderDoc.OverlayBits = overlayBits;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
if (EnumFlagField("Overlay"u8, ref overlayBits))
|
||||
{
|
||||
RenderDoc.OverlayBits = overlayBits;
|
||||
}
|
||||
|
||||
if (ImGui.Button(RenderDoc.IsTargetControlConnected ? "Focus RenderDoc app"u8 : "Open RenderDoc app"u8))
|
||||
{
|
||||
OpenUI();
|
||||
}
|
||||
|
||||
if (ImGui.TreeNode("More"u8))
|
||||
{
|
||||
Field("IsTargetControlConnected"u8, RenderDoc.IsTargetControlConnected);
|
||||
|
||||
if (ImGui.Button("LaunchReplayUI"u8))
|
||||
{
|
||||
var res = RenderDoc.LaunchReplayUI(true, null);
|
||||
Log.Info($"LaunchReplayUI {res}");
|
||||
}
|
||||
|
||||
if (ImGui.Button("ShowReplayUI"u8))
|
||||
{
|
||||
var res = RenderDoc.ShowReplayUI();
|
||||
Log.Info($"ShowReplayUI {res}");
|
||||
}
|
||||
|
||||
if (ImGui.Button("SetActiveWindow"u8))
|
||||
{
|
||||
RenderDoc.SetActiveWindow(0, 0);
|
||||
}
|
||||
|
||||
if (ImGui.Button("UnloadCrashHandler"u8))
|
||||
{
|
||||
RenderDoc.UnloadCrashHandler();
|
||||
}
|
||||
|
||||
if (ImGui.Button("RemoveHooks"u8))
|
||||
{
|
||||
RenderDoc.RemoveHooks();
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
|
||||
if (ImGui.TreeNode("Capture options"u8))
|
||||
{
|
||||
foreach (var option in typeof(RenderDoc.CaptureOptions).GetProperties())
|
||||
{
|
||||
if (option.PropertyType == typeof(bool))
|
||||
{
|
||||
var value = (bool)option.GetValue(null)!;
|
||||
if (ImGui.Checkbox(option.Name, ref value))
|
||||
option.SetValue(null, value);
|
||||
}
|
||||
else if (option.PropertyType == typeof(float))
|
||||
{
|
||||
var value = (float)option.GetValue(null)!;
|
||||
if (ImGui.InputFloat(option.Name, ref value))
|
||||
option.SetValue(null, value);
|
||||
}
|
||||
else if (option.PropertyType == typeof(uint))
|
||||
{
|
||||
var value = (int)(uint)option.GetValue(null)!; // TODO actually uint...
|
||||
if (ImGui.InputInt(option.Name, ref value))
|
||||
option.SetValue(null, value);
|
||||
}
|
||||
}
|
||||
|
||||
CaptureFilePathTemplate.SetValue(RenderDoc.CaptureFilePathTemplate);
|
||||
ImGui.Text("CaptureFilePathTemplate"u8);
|
||||
ImGui.SameLine();
|
||||
if (ImGui.InputText("##CaptureFilePathTemplate"u8, CaptureFilePathTemplate))
|
||||
RenderDoc.CaptureFilePathTemplate = CaptureFilePathTemplate.ValueSpan;
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
|
||||
var foldoutCaptures = FoldoutField("Captures"u8, RenderDoc.NumCaptures, RenderDoc.NumCaptures > 0);
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("TriggerCapture"u8))
|
||||
{
|
||||
RenderDoc.TriggerCapture();
|
||||
triggerCaptureIndex = RenderDoc.NumCaptures;
|
||||
Log.Info($"TriggerCapture requested (frame {frameCount}, {RenderDoc.NumCaptures} captures)");
|
||||
}
|
||||
if (foldoutCaptures)
|
||||
{
|
||||
if (ImGui.BeginTable("captures"u8, 4, ImGuiTableFlags.Borders))
|
||||
{
|
||||
ImGui.TableSetupColumn("#"u8, ImGuiTableColumnFlags.WidthFixed);
|
||||
ImGui.TableSetupColumn("time"u8, ImGuiTableColumnFlags.WidthFixed);
|
||||
ImGui.TableSetupColumn("file"u8);
|
||||
ImGui.TableSetupColumn(""u8, ImGuiTableColumnFlags.WidthFixed);
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
for (var i = 0; i < RenderDoc.NumCaptures; i++)
|
||||
{
|
||||
ImGui.PushID(i);
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
ImGui.Text($"#{i}");
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
if (RenderDoc.TryGetCapture(i, out var path, out var time))
|
||||
{
|
||||
ImGui.Text($"{time:g}");
|
||||
ImGui.TableNextColumn();
|
||||
var name = Utf8.Path.GetFileName(path);
|
||||
ImGui.Text($"<{name}>");
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.Button("open"u8))
|
||||
{
|
||||
OpenUI();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.Text("N/A"u8);
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text("N/A"u8);
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
static bool EnumFlagField(ImString label, ref OverlayBits value)
|
||||
{
|
||||
var changed = false;
|
||||
|
||||
if (FoldoutField(label, value.ToString()))
|
||||
{
|
||||
foreach (var flag in Enum.GetValues<OverlayBits>())
|
||||
{
|
||||
if (flag == 0 || flag == OverlayBits.All)
|
||||
continue;
|
||||
changed |= EnumFlagFieldRow(flag.ToString(), ref value, flag);
|
||||
}
|
||||
ImGui.TreePop();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
static bool EnumFlagFieldRow(ImString label, ref OverlayBits mask, OverlayBits flag)
|
||||
{
|
||||
var flagSet = mask.HasFlag(flag);
|
||||
var changed = ImGui.Checkbox(label, ref flagSet);
|
||||
if (changed)
|
||||
{
|
||||
if (flagSet)
|
||||
mask |= flag;
|
||||
else
|
||||
mask &= ~flag;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
static void Field(ImString label, object? value)
|
||||
{
|
||||
ImGui.Text($"{label}: {value}");
|
||||
}
|
||||
|
||||
static void Field(ImString label, ImString value)
|
||||
{
|
||||
ImGui.Text($"{label}: {value}");
|
||||
}
|
||||
|
||||
static bool FoldoutField(ImString label, object? value, bool foldable = true)
|
||||
{
|
||||
if (foldable)
|
||||
return ImGui.TreeNode(label, $"{label}: {value}");
|
||||
Field(label, value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
public static partial class RenderDoc
|
||||
{
|
||||
public static partial class CaptureOptions
|
||||
{
|
||||
public static bool AllowVSync
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.AllowVSync);
|
||||
set => SetCaptureOption(CaptureOption.AllowVSync, value);
|
||||
}
|
||||
public static bool AllowFullscreen
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.AllowFullscreen);
|
||||
set => SetCaptureOption(CaptureOption.AllowFullscreen, value);
|
||||
}
|
||||
public static bool APIValidation
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.APIValidation);
|
||||
set => SetCaptureOption(CaptureOption.APIValidation, value);
|
||||
}
|
||||
public static bool CaptureCallstacks
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.CaptureCallstacks);
|
||||
set => SetCaptureOption(CaptureOption.CaptureCallstacks, value);
|
||||
}
|
||||
public static bool CaptureCallstacksOnlyActions
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.CaptureCallstacksOnlyActions);
|
||||
set => SetCaptureOption(CaptureOption.CaptureCallstacksOnlyActions, value);
|
||||
}
|
||||
public static float DelayForDebugger
|
||||
{
|
||||
get => GetCaptureOptionF32(CaptureOption.DelayForDebugger);
|
||||
set => SetCaptureOption(CaptureOption.DelayForDebugger, value);
|
||||
}
|
||||
public static bool VerifyBufferAccess
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.VerifyBufferAccess);
|
||||
set => SetCaptureOption(CaptureOption.VerifyBufferAccess, value);
|
||||
}
|
||||
public static bool HookIntoChildren
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.HookIntoChildren);
|
||||
set => SetCaptureOption(CaptureOption.HookIntoChildren, value);
|
||||
}
|
||||
public static bool RefAllResources
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.RefAllResources);
|
||||
set => SetCaptureOption(CaptureOption.RefAllResources, value);
|
||||
}
|
||||
public static bool SaveAllInitials
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.SaveAllInitials);
|
||||
set => SetCaptureOption(CaptureOption.SaveAllInitials, value);
|
||||
}
|
||||
public static bool CaptureAllCmdLists
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.CaptureAllCmdLists);
|
||||
set => SetCaptureOption(CaptureOption.CaptureAllCmdLists, value);
|
||||
}
|
||||
public static bool DebugOutputMute
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.DebugOutputMute);
|
||||
set => SetCaptureOption(CaptureOption.DebugOutputMute, value);
|
||||
}
|
||||
public static bool AllowUnsupportedVendorExtensions
|
||||
{
|
||||
get => GetCaptureOptionBool(CaptureOption.AllowUnsupportedVendorExtensions);
|
||||
set => SetCaptureOption(CaptureOption.AllowUnsupportedVendorExtensions, value);
|
||||
}
|
||||
public static uint SoftMemoryLimit
|
||||
{
|
||||
get => GetCaptureOptionU32(CaptureOption.SoftMemoryLimit);
|
||||
set => SetCaptureOption(CaptureOption.SoftMemoryLimit, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
/// RenderDoc uses semantic versioning (http://semver.org/).
|
||||
/// MAJOR version is incremented when incompatible API changes happen.
|
||||
/// MINOR version is incremented when functionality is added in a backwards-compatible manner.
|
||||
/// PATCH version is incremented when backwards-compatible bug fixes happen.
|
||||
/// Note that this means the API returned can be higher than the one you might have requested.
|
||||
/// e.g. if you are running against a newer RenderDoc that supports 1.0.1, it will be returned
|
||||
/// instead of 1.0.0. You can check this with the GetAPIVersion entry point
|
||||
public enum ApiVersions : int
|
||||
{
|
||||
/// eRENDERDOC_API_Version_1_0_0
|
||||
V1_0_0 = 10000,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_0_1
|
||||
V1_0_1 = 10001,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_0_2
|
||||
V1_0_2 = 10002,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_1_0
|
||||
V1_1_0 = 10100,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_1_1
|
||||
V1_1_1 = 10101,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_1_2
|
||||
V1_1_2 = 10102,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_2_0
|
||||
V1_2_0 = 10200,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_3_0
|
||||
V1_3_0 = 10300,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_4_0
|
||||
V1_4_0 = 10400,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_4_1
|
||||
V1_4_1 = 10401,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_4_2
|
||||
V1_4_2 = 10402,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_5_0
|
||||
V1_5_0 = 10500,
|
||||
|
||||
/// eRENDERDOC_API_Version_1_6_0
|
||||
V1_6_0 = 10600,
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// RenderDoc capture options
|
||||
public enum CaptureOption : int
|
||||
{
|
||||
/// eRENDERDOC_Option_AllowVSync
|
||||
AllowVSync = 0,
|
||||
|
||||
/// eRENDERDOC_Option_AllowFullscreen
|
||||
AllowFullscreen = 1,
|
||||
|
||||
/// eRENDERDOC_Option_APIValidation
|
||||
APIValidation = 2,
|
||||
|
||||
/// eRENDERDOC_Option_CaptureCallstacks
|
||||
CaptureCallstacks = 3,
|
||||
|
||||
/// eRENDERDOC_Option_CaptureCallstacksOnlyActions
|
||||
CaptureCallstacksOnlyActions = 4,
|
||||
|
||||
/// eRENDERDOC_Option_DelayForDebugger
|
||||
DelayForDebugger = 5,
|
||||
|
||||
/// eRENDERDOC_Option_VerifyBufferAccess
|
||||
VerifyBufferAccess = 6,
|
||||
|
||||
/// eRENDERDOC_Option_HookIntoChildren
|
||||
HookIntoChildren = 7,
|
||||
|
||||
/// eRENDERDOC_Option_RefAllResources
|
||||
RefAllResources = 8,
|
||||
|
||||
/// eRENDERDOC_Option_SaveAllInitials
|
||||
SaveAllInitials = 9,
|
||||
|
||||
/// eRENDERDOC_Option_CaptureAllCmdLists
|
||||
CaptureAllCmdLists = 10,
|
||||
|
||||
/// eRENDERDOC_Option_DebugOutputMute
|
||||
DebugOutputMute = 11,
|
||||
|
||||
/// eRENDERDOC_Option_AllowUnsupportedVendorExtensions
|
||||
AllowUnsupportedVendorExtensions = 12,
|
||||
|
||||
/// eRENDERDOC_Option_SoftMemoryLimit
|
||||
SoftMemoryLimit = 13,
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
///
|
||||
public enum InputButton : int
|
||||
{
|
||||
/// eRENDERDOC_Key_0
|
||||
Num0 = 0x30,
|
||||
|
||||
/// eRENDERDOC_Key_1
|
||||
Num1 = 0x31,
|
||||
|
||||
/// eRENDERDOC_Key_2
|
||||
Num2 = 0x32,
|
||||
|
||||
/// eRENDERDOC_Key_3
|
||||
Num3 = 0x33,
|
||||
|
||||
/// eRENDERDOC_Key_4
|
||||
Num4 = 0x34,
|
||||
|
||||
/// eRENDERDOC_Key_5
|
||||
Num5 = 0x35,
|
||||
|
||||
/// eRENDERDOC_Key_6
|
||||
Num6 = 0x36,
|
||||
|
||||
/// eRENDERDOC_Key_7
|
||||
Num7 = 0x37,
|
||||
|
||||
/// eRENDERDOC_Key_8
|
||||
Num8 = 0x38,
|
||||
|
||||
/// eRENDERDOC_Key_9
|
||||
Num9 = 0x39,
|
||||
|
||||
/// eRENDERDOC_Key_A
|
||||
A = 0x41,
|
||||
|
||||
/// eRENDERDOC_Key_B
|
||||
B = 0x42,
|
||||
|
||||
/// eRENDERDOC_Key_C
|
||||
C = 0x43,
|
||||
|
||||
/// eRENDERDOC_Key_D
|
||||
D = 0x44,
|
||||
|
||||
/// eRENDERDOC_Key_E
|
||||
E = 0x45,
|
||||
|
||||
/// eRENDERDOC_Key_F
|
||||
F = 0x46,
|
||||
|
||||
/// eRENDERDOC_Key_G
|
||||
G = 0x47,
|
||||
|
||||
/// eRENDERDOC_Key_H
|
||||
H = 0x48,
|
||||
|
||||
/// eRENDERDOC_Key_I
|
||||
I = 0x49,
|
||||
|
||||
/// eRENDERDOC_Key_J
|
||||
J = 0x4A,
|
||||
|
||||
/// eRENDERDOC_Key_K
|
||||
K = 0x4B,
|
||||
|
||||
/// eRENDERDOC_Key_L
|
||||
L = 0x4C,
|
||||
|
||||
/// eRENDERDOC_Key_M
|
||||
M = 0x4D,
|
||||
|
||||
/// eRENDERDOC_Key_N
|
||||
N = 0x4E,
|
||||
|
||||
/// eRENDERDOC_Key_O
|
||||
O = 0x4F,
|
||||
|
||||
/// eRENDERDOC_Key_P
|
||||
P = 0x50,
|
||||
|
||||
/// eRENDERDOC_Key_Q
|
||||
Q = 0x51,
|
||||
|
||||
/// eRENDERDOC_Key_R
|
||||
R = 0x52,
|
||||
|
||||
/// eRENDERDOC_Key_S
|
||||
S = 0x53,
|
||||
|
||||
/// eRENDERDOC_Key_T
|
||||
T = 0x54,
|
||||
|
||||
/// eRENDERDOC_Key_U
|
||||
U = 0x55,
|
||||
|
||||
/// eRENDERDOC_Key_V
|
||||
V = 0x56,
|
||||
|
||||
/// eRENDERDOC_Key_W
|
||||
W = 0x57,
|
||||
|
||||
/// eRENDERDOC_Key_X
|
||||
X = 0x58,
|
||||
|
||||
/// eRENDERDOC_Key_Y
|
||||
Y = 0x59,
|
||||
|
||||
/// eRENDERDOC_Key_Z
|
||||
Z = 0x5A,
|
||||
|
||||
/// eRENDERDOC_Key_NonPrintable
|
||||
NonPrintable = 0x100,
|
||||
|
||||
/// eRENDERDOC_Key_Divide
|
||||
Divide,
|
||||
|
||||
/// eRENDERDOC_Key_Multiply
|
||||
Multiply,
|
||||
|
||||
/// eRENDERDOC_Key_Subtract
|
||||
Subtract,
|
||||
|
||||
/// eRENDERDOC_Key_Plus
|
||||
Plus,
|
||||
|
||||
/// eRENDERDOC_Key_F1
|
||||
F1,
|
||||
|
||||
/// eRENDERDOC_Key_F2
|
||||
F2,
|
||||
|
||||
/// eRENDERDOC_Key_F3
|
||||
F3,
|
||||
|
||||
/// eRENDERDOC_Key_F4
|
||||
F4,
|
||||
|
||||
/// eRENDERDOC_Key_F5
|
||||
F5,
|
||||
|
||||
/// eRENDERDOC_Key_F6
|
||||
F6,
|
||||
|
||||
/// eRENDERDOC_Key_F7
|
||||
F7,
|
||||
|
||||
/// eRENDERDOC_Key_F8
|
||||
F8,
|
||||
|
||||
/// eRENDERDOC_Key_F9
|
||||
F9,
|
||||
|
||||
/// eRENDERDOC_Key_F10
|
||||
F10,
|
||||
|
||||
/// eRENDERDOC_Key_F11
|
||||
F11,
|
||||
|
||||
/// eRENDERDOC_Key_F12
|
||||
F12,
|
||||
|
||||
/// eRENDERDOC_Key_Home
|
||||
Home,
|
||||
|
||||
/// eRENDERDOC_Key_End
|
||||
End,
|
||||
|
||||
/// eRENDERDOC_Key_Insert
|
||||
Insert,
|
||||
|
||||
/// eRENDERDOC_Key_Delete
|
||||
Delete,
|
||||
|
||||
/// eRENDERDOC_Key_PageUp
|
||||
PageUp,
|
||||
|
||||
/// eRENDERDOC_Key_PageDn
|
||||
PageDn,
|
||||
|
||||
/// eRENDERDOC_Key_Backspace
|
||||
Backspace,
|
||||
|
||||
/// eRENDERDOC_Key_Tab
|
||||
Tab,
|
||||
|
||||
/// eRENDERDOC_Key_PrtScrn
|
||||
PrtScrn,
|
||||
|
||||
/// eRENDERDOC_Key_Pause
|
||||
Pause,
|
||||
|
||||
/// eRENDERDOC_Key_Max
|
||||
Max,
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
///
|
||||
[Flags]
|
||||
public enum OverlayBits : int
|
||||
{
|
||||
/// eRENDERDOC_Overlay_Enabled
|
||||
Enabled = 0x1,
|
||||
|
||||
/// eRENDERDOC_Overlay_FrameRate
|
||||
FrameRate = 0x2,
|
||||
|
||||
/// eRENDERDOC_Overlay_FrameNumber
|
||||
FrameNumber = 0x4,
|
||||
|
||||
/// eRENDERDOC_Overlay_CaptureList
|
||||
CaptureList = 0x8,
|
||||
|
||||
/// eRENDERDOC_Overlay_Default
|
||||
Default = (Enabled | FrameRate | FrameNumber | CaptureList),
|
||||
|
||||
/// eRENDERDOC_Overlay_All
|
||||
All = 0x7ffffff,
|
||||
|
||||
/// eRENDERDOC_Overlay_None
|
||||
None = 0,
|
||||
}
|
||||
147
brutal.renderdoc/Brutal.RenderDoc/Generated/RenderDoc.gen.cs
Normal file
147
brutal.renderdoc/Brutal.RenderDoc/Generated/RenderDoc.gen.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
public static unsafe partial class RenderDoc
|
||||
{
|
||||
[ApiVersion(1, 0)]
|
||||
public static void GetApiVersion(out int major, out int minor, out int patch)
|
||||
{
|
||||
fixed (int* major_fixed = &major)
|
||||
fixed (int* minor_fixed = &minor)
|
||||
fixed (int* patch_fixed = &patch)
|
||||
Api->GetAPIVersion(major_fixed, minor_fixed, patch_fixed);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static int SetCaptureOption(CaptureOption opt, uint val) => Api->SetCaptureOptionU32(opt, val);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static int SetCaptureOption(CaptureOption opt, float val) => Api->SetCaptureOptionF32(opt, val);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static uint GetCaptureOptionU32(CaptureOption opt) => Api->GetCaptureOptionU32(opt);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static float GetCaptureOptionF32(CaptureOption opt) => Api->GetCaptureOptionF32(opt);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void SetFocusToggleKeys(ReadOnlySpan<InputButton> keys)
|
||||
{
|
||||
fixed (InputButton* keys_fixed = keys)
|
||||
Api->SetFocusToggleKeys(keys_fixed, keys.Length);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void SetCaptureKeys(ReadOnlySpan<InputButton> keys)
|
||||
{
|
||||
fixed (InputButton* keys_fixed = keys)
|
||||
Api->SetCaptureKeys(keys_fixed, keys.Length);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static OverlayBits OverlayBits
|
||||
{
|
||||
get => Api->GetOverlayBits();
|
||||
set => Api->MaskOverlayBits(0, value);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void MaskOverlayBits(OverlayBits And, OverlayBits Or) => Api->MaskOverlayBits(And, Or);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static partial void RemoveHooks();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void UnloadCrashHandler() => Api->UnloadCrashHandler();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void SetCaptureFilePathTemplate(String8In pathtemplate)
|
||||
{
|
||||
fixed (byte* pathtemplate_fixed = pathtemplate)
|
||||
Api->SetCaptureFilePathTemplate(pathtemplate_fixed);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static String8Return CaptureFilePathTemplate
|
||||
{
|
||||
get => Utf8.GetNullTerminatedSpan(Api->GetCaptureFilePathTemplate());
|
||||
set => SetCaptureFilePathTemplate(value);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static uint NumCaptures => Api->GetNumCaptures();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static bool GetCapture(uint idx, String8Out filename, out uint pathlength, out ulong timestamp)
|
||||
{
|
||||
fixed (byte* filename_fixed = filename)
|
||||
fixed (uint* pathlength_fixed = &pathlength)
|
||||
fixed (ulong* timestamp_fixed = ×tamp)
|
||||
return Api->GetCapture(idx, filename_fixed, pathlength_fixed, timestamp_fixed);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void TriggerCapture() => Api->TriggerCapture();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static bool IsTargetControlConnected => Api->IsTargetControlConnected();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static bool LaunchReplayUI(bool connectTargetControl, String8In cmdline)
|
||||
{
|
||||
fixed (byte* cmdline_fixed = cmdline)
|
||||
return Api->LaunchReplayUI(connectTargetControl, cmdline_fixed);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void SetActiveWindow(DevicePointer device, WindowHandle wndHandle) =>
|
||||
Api->SetActiveWindow(device, wndHandle);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static void StartFrameCapture(DevicePointer device, WindowHandle wndHandle) =>
|
||||
Api->StartFrameCapture(device, wndHandle);
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static bool IsFrameCapturing => Api->IsFrameCapturing();
|
||||
|
||||
[ApiVersion(1, 0)]
|
||||
public static uint EndFrameCapture(DevicePointer device, WindowHandle wndHandle) =>
|
||||
Api->EndFrameCapture(device, wndHandle);
|
||||
|
||||
[ApiVersion(1, 1)]
|
||||
public static void TriggerMultiFrameCapture(uint numFrames)
|
||||
{
|
||||
EnsureApiVersion(1, 1);
|
||||
Api->TriggerMultiFrameCapture(numFrames);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 2)]
|
||||
public static void SetCaptureFileComments(String8In filePath, String8In comments)
|
||||
{
|
||||
EnsureApiVersion(1, 2);
|
||||
fixed (byte* filePath_fixed = filePath)
|
||||
fixed (byte* comments_fixed = comments)
|
||||
Api->SetCaptureFileComments(filePath_fixed, comments_fixed);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 4)]
|
||||
public static uint DiscardFrameCapture(DevicePointer device, WindowHandle wndHandle)
|
||||
{
|
||||
EnsureApiVersion(1, 4);
|
||||
return Api->DiscardFrameCapture(device, wndHandle);
|
||||
}
|
||||
|
||||
[ApiVersion(1, 5)]
|
||||
public static bool ShowReplayUI()
|
||||
{
|
||||
EnsureApiVersion(1, 5);
|
||||
return Api->ShowReplayUI();
|
||||
}
|
||||
|
||||
[ApiVersion(1, 6)]
|
||||
public static void SetCaptureTitle(String8In title)
|
||||
{
|
||||
EnsureApiVersion(1, 6);
|
||||
fixed (byte* title_fixed = title)
|
||||
Api->SetCaptureTitle(title_fixed);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
namespace Brutal.RenderDocApi;
|
||||
|
||||
/// API version changelog:
|
||||
/// 1.0.0 - initial release
|
||||
/// 1.0.1 - Bugfix: IsFrameCapturing() was returning false for captures that were triggered
|
||||
/// by keypress or TriggerCapture, instead of Start/EndFrameCapture.
|
||||
/// 1.0.2 - Refactor: Renamed eRENDERDOC_Option_DebugDeviceMode to eRENDERDOC_Option_APIValidation
|
||||
/// 1.1.0 - Add feature: TriggerMultiFrameCapture(). Backwards compatible with 1.0.x since the new
|
||||
/// function pointer is added to the end of the struct, the original layout is identical
|
||||
/// 1.1.1 - Refactor: Renamed remote access to target control (to better disambiguate from remote
|
||||
/// replay/remote server concept in replay UI)
|
||||
/// 1.1.2 - Refactor: Renamed "log file" in function names to just capture, to clarify that these
|
||||
/// are captures and not debug logging files. This is the first API version in the v1.0
|
||||
/// branch.
|
||||
/// 1.2.0 - Added feature: SetCaptureFileComments() to add comments to a capture file that will be
|
||||
/// displayed in the UI program on load.
|
||||
/// 1.3.0 - Added feature: New capture option eRENDERDOC_Option_AllowUnsupportedVendorExtensions
|
||||
/// which allows users to opt-in to allowing unsupported vendor extensions to function.
|
||||
/// Should be used at the user's own risk.
|
||||
/// Refactor: Renamed eRENDERDOC_Option_VerifyMapWrites to
|
||||
/// eRENDERDOC_Option_VerifyBufferAccess, which now also controls initialisation to
|
||||
/// 0xdddddddd of uninitialised buffer contents.
|
||||
/// 1.4.0 - Added feature: DiscardFrameCapture() to discard a frame capture in progress and stop
|
||||
/// capturing without saving anything to disk.
|
||||
/// 1.4.1 - Refactor: Renamed Shutdown to RemoveHooks to better clarify what is happening
|
||||
/// 1.4.2 - Refactor: Renamed 'draws' to 'actions' in callstack capture option.
|
||||
/// 1.5.0 - Added feature: ShowReplayUI() to request that the replay UI show itself if connected
|
||||
/// 1.6.0 - Added feature: SetCaptureTitle() which can be used to set a title for a
|
||||
/// capture made with StartFrameCapture() or EndFrameCapture()
|
||||
[StructLayout(LayoutKind.Explicit, Size = 216)]
|
||||
public unsafe partial struct RenderDocApi()
|
||||
{
|
||||
///
|
||||
[FieldOffset(0)]
|
||||
public delegate* unmanaged[Cdecl]<int*, int*, int*, void> GetAPIVersion;
|
||||
|
||||
///
|
||||
[FieldOffset(8)]
|
||||
public delegate* unmanaged[Cdecl]<CaptureOption, uint, int> SetCaptureOptionU32;
|
||||
|
||||
///
|
||||
[FieldOffset(16)]
|
||||
public delegate* unmanaged[Cdecl]<CaptureOption, float, int> SetCaptureOptionF32;
|
||||
|
||||
///
|
||||
[FieldOffset(24)]
|
||||
public delegate* unmanaged[Cdecl]<CaptureOption, uint> GetCaptureOptionU32;
|
||||
|
||||
///
|
||||
[FieldOffset(32)]
|
||||
public delegate* unmanaged[Cdecl]<CaptureOption, float> GetCaptureOptionF32;
|
||||
|
||||
///
|
||||
[FieldOffset(40)]
|
||||
public delegate* unmanaged[Cdecl]<InputButton*, int, void> SetFocusToggleKeys;
|
||||
|
||||
///
|
||||
[FieldOffset(48)]
|
||||
public delegate* unmanaged[Cdecl]<InputButton*, int, void> SetCaptureKeys;
|
||||
|
||||
///
|
||||
[FieldOffset(56)]
|
||||
public delegate* unmanaged[Cdecl]<OverlayBits> GetOverlayBits;
|
||||
|
||||
///
|
||||
[FieldOffset(64)]
|
||||
public delegate* unmanaged[Cdecl]<OverlayBits, OverlayBits, void> MaskOverlayBits;
|
||||
|
||||
///
|
||||
[FieldOffset(72)]
|
||||
public delegate* unmanaged[Cdecl]<void> RemoveHooks;
|
||||
|
||||
///
|
||||
[FieldOffset(80)]
|
||||
public delegate* unmanaged[Cdecl]<void> UnloadCrashHandler;
|
||||
|
||||
/// current name
|
||||
[FieldOffset(88)]
|
||||
public delegate* unmanaged[Cdecl]<byte*, void> SetCaptureFilePathTemplate;
|
||||
|
||||
/// current name
|
||||
[FieldOffset(96)]
|
||||
public delegate* unmanaged[Cdecl]<byte*> GetCaptureFilePathTemplate;
|
||||
|
||||
///
|
||||
[FieldOffset(104)]
|
||||
public delegate* unmanaged[Cdecl]<uint> GetNumCaptures;
|
||||
|
||||
///
|
||||
[FieldOffset(112)]
|
||||
public delegate* unmanaged[Cdecl]<uint, byte*, uint*, ulong*, Bool32> GetCapture;
|
||||
|
||||
///
|
||||
[FieldOffset(120)]
|
||||
public delegate* unmanaged[Cdecl]<void> TriggerCapture;
|
||||
|
||||
/// current name
|
||||
[FieldOffset(128)]
|
||||
public delegate* unmanaged[Cdecl]<Bool32> IsTargetControlConnected;
|
||||
|
||||
///
|
||||
[FieldOffset(136)]
|
||||
public delegate* unmanaged[Cdecl]<Bool32, byte*, Bool32> LaunchReplayUI;
|
||||
|
||||
///
|
||||
[FieldOffset(144)]
|
||||
public delegate* unmanaged[Cdecl]<DevicePointer, WindowHandle, void> SetActiveWindow;
|
||||
|
||||
///
|
||||
[FieldOffset(152)]
|
||||
public delegate* unmanaged[Cdecl]<DevicePointer, WindowHandle, void> StartFrameCapture;
|
||||
|
||||
///
|
||||
[FieldOffset(160)]
|
||||
public delegate* unmanaged[Cdecl]<Bool32> IsFrameCapturing;
|
||||
|
||||
///
|
||||
[FieldOffset(168)]
|
||||
public delegate* unmanaged[Cdecl]<DevicePointer, WindowHandle, uint> EndFrameCapture;
|
||||
|
||||
/// new function in 1.1.0
|
||||
[FieldOffset(176)]
|
||||
public delegate* unmanaged[Cdecl]<uint, void> TriggerMultiFrameCapture;
|
||||
|
||||
/// new function in 1.2.0
|
||||
[FieldOffset(184)]
|
||||
public delegate* unmanaged[Cdecl]<byte*, byte*, void> SetCaptureFileComments;
|
||||
|
||||
/// new function in 1.4.0
|
||||
[FieldOffset(192)]
|
||||
public delegate* unmanaged[Cdecl]<DevicePointer, WindowHandle, uint> DiscardFrameCapture;
|
||||
|
||||
/// new function in 1.5.0
|
||||
[FieldOffset(200)]
|
||||
public delegate* unmanaged[Cdecl]<Bool32> ShowReplayUI;
|
||||
|
||||
/// new function in 1.6.0
|
||||
[FieldOffset(208)]
|
||||
public delegate* unmanaged[Cdecl]<byte*, void> SetCaptureTitle;
|
||||
}
|
||||
3
brutal.renderdoc/Brutal.RenderDoc/GlobalUsings.cs
Normal file
3
brutal.renderdoc/Brutal.RenderDoc/GlobalUsings.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
global using System.Runtime.InteropServices;
|
||||
global using Brutal.Numerics;
|
||||
global using Brutal.Strings;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
Brutal.RenderDoc provides bindings to the third-party component listed below,
|
||||
reproduced with the licence that governs it.
|
||||
|
||||
============================================================
|
||||
RenderDoc 1.42 -- MIT -- https://github.com/baldurk/renderdoc
|
||||
============================================================
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2025 Baldur Karlsson
|
||||
|
||||
Copyright (c) 2014 Crytek
|
||||
|
||||
Copyright (c) 1998-2018 Third party code and tools
|
||||
(https://github.com/baldurk/renderdoc/blob/v1.42/docs/credits_acknowledgements.rst)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
9
brutal.renderdoc/Brutal.RenderDoc/Manual/Logger.cs
Normal file
9
brutal.renderdoc/Brutal.RenderDoc/Manual/Logger.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
global using static Brutal.RenderDocApi.Logger;
|
||||
using Brutal.Logging;
|
||||
|
||||
namespace Brutal.RenderDocApi;
|
||||
|
||||
public static class Logger
|
||||
{
|
||||
public static LogCategory Log = LogCategory.Make("RenderDoc");
|
||||
}
|
||||
317
brutal.renderdoc/Brutal.RenderDoc/Manual/RenderDoc.manual.cs
Normal file
317
brutal.renderdoc/Brutal.RenderDoc/Manual/RenderDoc.manual.cs
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Brutal.RenderDocApi;
|
||||
|
||||
/// RenderDoc's <a href="https://renderdoc.org/docs/in_application_api.html">in-app API</a>.
|
||||
public static unsafe partial class RenderDoc
|
||||
{
|
||||
#region controller (helpers around the actual native API)
|
||||
|
||||
public enum ControllerState
|
||||
{
|
||||
NotLoaded,
|
||||
LoadFail,
|
||||
LoadSuccess,
|
||||
}
|
||||
|
||||
public static ControllerState State =>
|
||||
ApiLoaded
|
||||
? Api != null
|
||||
? ControllerState.LoadSuccess
|
||||
: ControllerState.LoadFail
|
||||
: ControllerState.NotLoaded;
|
||||
|
||||
public struct InitOptions
|
||||
{
|
||||
internal bool LoadApi = true;
|
||||
public ApiVersions MinimumRequired = ApiVersions.V1_0_0;
|
||||
public string[] SearchPaths = DefaultSearchPaths;
|
||||
|
||||
/// The RenderDoc overlay ("F12 to capture" etc) is visible by default. Disable it here.
|
||||
public bool ShowOverlay = true;
|
||||
|
||||
public InitOptions() { }
|
||||
|
||||
/// This will install the RenderDoc hooks only if `--RenderDoc` is found in command-line arguments.
|
||||
public InitOptions(string[] commandLineArgs)
|
||||
{
|
||||
LoadApi = commandLineArgs.Contains("--RenderDoc", StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="LoadApi"/>
|
||||
public static bool Initialize() => Initialize(new InitOptions());
|
||||
|
||||
/// <inheritdoc cref="LoadApi"/>
|
||||
public static bool Initialize(InitOptions options)
|
||||
{
|
||||
if (!options.LoadApi)
|
||||
return false;
|
||||
|
||||
if (!LoadApi(options.MinimumRequired, options.SearchPaths))
|
||||
return false;
|
||||
|
||||
if (!options.ShowOverlay)
|
||||
OverlayBits &= ~OverlayBits.Enabled;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region loading
|
||||
|
||||
/// True if we tried to load the API, even if loading was unsuccessful.
|
||||
public static bool ApiLoaded { get; private set; }
|
||||
|
||||
private static RenderDocApi* Api;
|
||||
|
||||
/// True if the API was loaded successfully through <see cref="LoadApi"/>.
|
||||
public static bool IsAvailable => Api != null;
|
||||
|
||||
static readonly string[] DefaultSearchPaths =
|
||||
[
|
||||
//"renderdoc.dll", // TODO: copying the dll to the app's working directory does load it, but the connection to the actual replay UI doesn't work...
|
||||
@"C:\Program Files\RenderDoc\renderdoc.dll",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Try to load the API (= load the in-app API from a native DLL), if it hasn't been loaded already,
|
||||
/// and install the RenderDoc hooks.
|
||||
/// Note that RenderDoc hooks might incur a performance hit, and interfere with the rendering stack
|
||||
/// (Vulkan validation layers etc.), so be sure to only do it in Debug mode.
|
||||
///
|
||||
/// Do this as early as possible in the app lifecycle so that RenderDoc can capture resource initialization etc.
|
||||
/// Otherwise, loading on-demand later in the app lifecycle may appear to work (RenderDoc will attach),
|
||||
/// but capturing may fail, at least not without recreating the Vulkan instance/device etc.
|
||||
///
|
||||
/// Once loaded, there may be no going back, ie no detaching without restarting the app
|
||||
/// (<a href="https://renderdoc.org/docs/in_application_api.html#_CPPv411RemoveHooksv">RemoveHooks is not guaranteed to work</a>).
|
||||
///
|
||||
/// Loading may fail if the DLL isn't found / RenderDoc not installed.
|
||||
/// - If the process was started from RenderDoc already, it will be found in the loaded process modules.
|
||||
/// - Otherwise, we will look in C:\Program Files\RenderDoc\renderdoc.dll.
|
||||
/// - Alternatively, you can provide your own search paths.
|
||||
/// </summary>
|
||||
/// <param name="minimumRequired">Minimum required RenderDoc API version.</param>
|
||||
/// <param name="customSearchPaths">Optional: override the file paths to load the library from.</param>
|
||||
/// <returns></returns>
|
||||
public static bool LoadApi(
|
||||
ApiVersions minimumRequired = ApiVersions.V1_0_0,
|
||||
params ReadOnlySpan<string> customSearchPaths
|
||||
)
|
||||
{
|
||||
if (ApiLoaded)
|
||||
return IsAvailable;
|
||||
|
||||
lock (typeof(RenderDoc))
|
||||
{
|
||||
// Prevent double loads.
|
||||
if (ApiLoaded)
|
||||
return IsAvailable;
|
||||
|
||||
ApiLoaded = true;
|
||||
var searchPaths = !customSearchPaths.IsEmpty ? customSearchPaths : DefaultSearchPaths;
|
||||
if (!TryLoadApi(searchPaths, minimumRequired, out Api))
|
||||
{
|
||||
Version = UnknownVersion;
|
||||
Log.Debug("RenderDoc: couldn't load API");
|
||||
return false;
|
||||
}
|
||||
|
||||
GetApiVersion(out var major, out var minor, out var patch);
|
||||
Version = new(major, minor, patch);
|
||||
Log.Debug($"RenderDoc: API loaded successfully, version: {Version}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Pure]
|
||||
static bool TryLoadApi(
|
||||
ReadOnlySpan<string> searchPaths,
|
||||
ApiVersions minimumRequired,
|
||||
[NotNullWhen(true)] out RenderDocApi* api
|
||||
)
|
||||
{
|
||||
var re = new Regex(
|
||||
@"(lib)?renderdoc(\.dll|\.so|\.dylib)(\.\d+)?",
|
||||
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase
|
||||
);
|
||||
|
||||
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
|
||||
{
|
||||
var path = module.FileName;
|
||||
if (path.Contains("Brutal"))
|
||||
continue;
|
||||
if (!re.IsMatch(path))
|
||||
continue;
|
||||
if (TryLoadApi(path, minimumRequired, out api))
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var path in searchPaths)
|
||||
{
|
||||
if (TryLoadApi(path, minimumRequired, out api))
|
||||
return true;
|
||||
}
|
||||
|
||||
api = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
static bool TryLoadApi(string libPath, ApiVersions minimumRequired, [NotNullWhen(true)] out RenderDocApi* api)
|
||||
{
|
||||
api = null;
|
||||
|
||||
if (!NativeLibrary.TryLoad(libPath, out var libHandle))
|
||||
return false;
|
||||
|
||||
if (!NativeLibrary.TryGetExport(libHandle, "RENDERDOC_GetAPI", out var getApiPtr))
|
||||
return false;
|
||||
|
||||
Log.Trace($"RenderDoc: API found in {libPath}");
|
||||
|
||||
var getApi = (delegate* unmanaged[Cdecl]<ApiVersions, RenderDocApi**, int>)getApiPtr;
|
||||
fixed (RenderDocApi** api_fixed = &api)
|
||||
{
|
||||
if (getApi(minimumRequired, api_fixed) == 0)
|
||||
{
|
||||
Log.Error($"RenderDoc: failed to load API from {libPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Assert(api != null);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region API version stuff
|
||||
|
||||
static readonly ApiVersion UnknownVersion = new(-1, -1, -1);
|
||||
|
||||
/// Get the RenderDoc version, if loaded successfully, -1 otherwise.
|
||||
public static ApiVersion Version { get; private set; } = UnknownVersion;
|
||||
|
||||
/// Whether to check API version on each call.
|
||||
public static bool VersionCheckEnabled = true;
|
||||
|
||||
/// Ensure the given API is available in the loaded version.
|
||||
static void EnsureApiVersion(int major, int minor, int patch = 0, [CallerMemberName] string apiName = "")
|
||||
{
|
||||
if (!VersionCheckEnabled)
|
||||
return;
|
||||
|
||||
var apiVersion = new ApiVersion(major, minor, patch);
|
||||
if (Version < apiVersion)
|
||||
throw new NotSupportedException(
|
||||
$"API <{apiName}> requires RenderDoc version {apiVersion}, current version is {Version}."
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static partial void RemoveHooks()
|
||||
{
|
||||
if (ApiLoaded && Api != null)
|
||||
Api->RemoveHooks();
|
||||
ApiLoaded = false;
|
||||
Api = null;
|
||||
Version = UnknownVersion;
|
||||
}
|
||||
|
||||
public static bool TryGetCapture(int index, [NotNullWhen(true)] out String8? path, out DateTime time)
|
||||
{
|
||||
ulong timestamp;
|
||||
if (!GetCapture((uint)index, null, out var pathlength, out timestamp))
|
||||
{
|
||||
path = null;
|
||||
time = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
Span<byte> pathSpan = stackalloc byte[(int)pathlength - 1]; // -1 because pathlength includes the null-terminator
|
||||
if (!GetCapture((uint)index, pathSpan, out _, out _))
|
||||
{
|
||||
path = null;
|
||||
time = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
path = new String8(pathSpan);
|
||||
time = DateTimeOffset.FromUnixTimeSeconds((long)timestamp).DateTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool GetCaptureOptionBool(CaptureOption opt) => Api->GetCaptureOptionU32(opt) != 0;
|
||||
|
||||
public static void SetCaptureOption(CaptureOption opt, bool value) =>
|
||||
Api->SetCaptureOptionU32(opt, value ? 1u : 0u);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ApiVersions" />
|
||||
public readonly record struct ApiVersion(int Major, int Minor, int Patch)
|
||||
: IComparable<ApiVersion>,
|
||||
IUtf8SpanFormattable,
|
||||
ISpanFormattable
|
||||
{
|
||||
/// Version number, packed in the same format as RenderDoc.
|
||||
readonly int _packed = Major * 10000 + Minor * 100 + Patch;
|
||||
|
||||
#region IComparable + operators
|
||||
|
||||
public int CompareTo(ApiVersion other) => _packed.CompareTo(other._packed);
|
||||
|
||||
public static bool operator <(ApiVersion left, ApiVersion right) => left._packed < right._packed;
|
||||
|
||||
public static bool operator >(ApiVersion left, ApiVersion right) => left._packed > right._packed;
|
||||
|
||||
public static bool operator <=(ApiVersion left, ApiVersion right) => left._packed <= right._packed;
|
||||
|
||||
public static bool operator >=(ApiVersion left, ApiVersion right) => left._packed >= right._packed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IUtf8SpanFormattable, ISpanFormattable, IFormattable
|
||||
|
||||
/// IUtf8SpanFormattable implementation
|
||||
public bool TryFormat(
|
||||
Span<byte> utf8Destination,
|
||||
out int bytesWritten,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? provider
|
||||
)
|
||||
{
|
||||
return Utf8.TryWrite(utf8Destination, $"{Major}.{Minor}.{Patch}", out bytesWritten);
|
||||
}
|
||||
|
||||
/// ISpanFormattable implementation
|
||||
public bool TryFormat(
|
||||
Span<char> utf16Destination,
|
||||
out int charsWritten,
|
||||
ReadOnlySpan<char> format,
|
||||
IFormatProvider? provider
|
||||
)
|
||||
{
|
||||
return utf16Destination.TryWrite($"{Major}.{Minor}.{Patch}", out charsWritten);
|
||||
}
|
||||
|
||||
/// IFormattable implementation - useless but required for ISpanFormattable
|
||||
string IFormattable.ToString(string? format, IFormatProvider? formatProvider) => ToString();
|
||||
|
||||
public override string ToString() => $"{Major}.{Minor}.{Patch}";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// Specify which RenderDoc version this API is available from, for documentation / tooling.
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
|
||||
public sealed class ApiVersionAttribute(int major, int minor, int patch = 0) : Attribute
|
||||
{
|
||||
public readonly ApiVersion MinVersion = new(major, minor, patch);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
global using DevicePointer = nint;
|
||||
global using String8In = System.ReadOnlySpan<byte>;
|
||||
global using String8Out = System.Span<byte>;
|
||||
global using String8Return = System.ReadOnlySpan<byte>;
|
||||
global using WindowHandle = nint;
|
||||
Loading…
Reference in a new issue