From 4609fa710b19104bfcdd2c8cf58dd1d8d507a0b7 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 23 Aug 2015 15:12:05 +0200 Subject: [PATCH] Update RenderDoc application-facing API to a stable/mature version. * This API is now intended to be forward and backward compatible as much as possible. Meaning applications should be able to run without changing on many RenderDoc versions after the one they are built against without breaking. * All function pointers are fetched at once in one versioned GetAPI() function, to save on constant GetProcAddress/dlsym'ing. * Otherwise, it's largely similar to the previous API. --- renderdoc/Makefile | 2 + renderdoc/api/app/renderdoc_app.h | 605 +++++++++++++------ renderdoc/api/replay/capture_options.h | 50 ++ renderdoc/api/replay/renderdoc_replay.h | 26 +- renderdoc/core/core.cpp | 78 +-- renderdoc/core/core.h | 18 +- renderdoc/driver/d3d11/d3d11_device.cpp | 40 +- renderdoc/driver/gl/gl_driver.cpp | 37 +- renderdoc/os/linux/linux_stringio.cpp | 56 +- renderdoc/os/win32/win32_process.cpp | 8 +- renderdoc/os/win32/win32_stringio.cpp | 56 +- renderdoc/renderdoc.vcxproj | 3 + renderdoc/renderdoc.vcxproj.filters | 9 + renderdoc/replay/app_api.cpp | 228 +++++++ renderdoc/replay/capture_options.cpp | 216 +++++++ renderdoc/replay/entry_points.cpp | 154 +---- renderdocui/Interop/CaptureOptions.cs | 21 +- renderdocui/Interop/StaticExports.cs | 16 + renderdocui/Windows/Dialogs/CaptureDialog.cs | 2 +- 19 files changed, 1116 insertions(+), 509 deletions(-) create mode 100644 renderdoc/api/replay/capture_options.h create mode 100644 renderdoc/replay/app_api.cpp create mode 100644 renderdoc/replay/capture_options.cpp diff --git a/renderdoc/Makefile b/renderdoc/Makefile index 2fba557ec..c6ed78ab4 100644 --- a/renderdoc/Makefile +++ b/renderdoc/Makefile @@ -14,6 +14,8 @@ OBJECTS=replay/replay_output.o \ replay/replay_renderer.o \ replay/entry_points.o \ replay/type_helpers.o \ +replay/app_api.o \ +replay/capture_options.o \ hooks/hooks.o \ serialise/serialiser.o \ serialise/grisu2.o \ diff --git a/renderdoc/api/app/renderdoc_app.h b/renderdoc/api/app/renderdoc_app.h index 77c17848e..f6eedbf92 100644 --- a/renderdoc/api/app/renderdoc_app.h +++ b/renderdoc/api/app/renderdoc_app.h @@ -1,7 +1,7 @@ /****************************************************************************** * The MIT License (MIT) * - * Copyright (c) 2014 Crytek + * Copyright (c) 2015 Baldur Karlsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,18 +22,20 @@ * THE SOFTWARE. ******************************************************************************/ - #pragma once +#if !defined(RENDERDOC_NO_STDINT) #include +#endif -#ifdef WIN32 +#if defined(WIN32) -#ifdef RENDERDOC_EXPORTS +#if defined(RENDERDOC_EXPORTS) #define RENDERDOC_API __declspec(dllexport) #else #define RENDERDOC_API __declspec(dllimport) #endif + #define RENDERDOC_CC __cdecl #elif defined(__linux__) @@ -52,245 +54,478 @@ #endif -struct CaptureOptions -{ - CaptureOptions() - : AllowVSync(true), - AllowFullscreen(true), - DebugDeviceMode(false), - CaptureCallstacks(false), - CaptureCallstacksOnlyDraws(false), - DelayForDebugger(0), - VerifyMapWrites(false), - HookIntoChildren(false), - RefAllResources(false), - SaveAllInitials(false), - CaptureAllCmdLists(false) - {} - - // Whether or not to allow the application to enable vsync - // - // 1 - allows the application to enable or disable vsync at will - // 0 - vsync is force disabled - uint32_t AllowVSync; +#ifdef __cplusplus +extern "C" { +#endif - // Whether or not to allow the application to enable fullscreen +////////////////////////////////////////////////////////////////////////////////////////////////// +// RenderDoc capture options +// + +typedef enum +{ + // Allow the application to enable vsync // - // 1 - allows the application to enable or disable fullscreen at will + // Default - enabled + // + // 1 - The application can enable or disable vsync at will + // 0 - vsync is force disabled + eRENDERDOC_Option_AllowVSync = 0, + + // Allow the application to enable fullscreen + // + // Default - enabled + // + // 1 - The application can enable or disable fullscreen at will // 0 - fullscreen is force disabled - uint32_t AllowFullscreen; + eRENDERDOC_Option_AllowFullscreen = 1, - // 1 - in-built API debugging features and records the results into the - // capture logfile, which is matched up with events on replay - // 0 - no API debugging is enabled - uint32_t DebugDeviceMode; - - // 1 - Captures callstacks for every API event during capture + // Record API debugging events and messages + // + // Default - disabled + // + // 1 - Enable built-in API debugging features and records the results into + // the capture logfile, which is matched up with events on replay + // 0 - no API debugging is forcibly enabled + eRENDERDOC_Option_DebugDeviceMode = 2, + + // Capture CPU callstacks for API events + // + // Default - disabled + // + // 1 - Enables capturing of callstacks // 0 - no callstacks are captured - uint32_t CaptureCallstacks; - + eRENDERDOC_Option_CaptureCallstacks = 3, + + // When capturing CPU callstacks, only capture them from drawcalls. + // This option does nothing without the above option being enabled + // + // Default - disabled + // // 1 - Only captures callstacks for drawcall type API events. // Ignored if CaptureCallstacks is disabled // 0 - Callstacks, if enabled, are captured for every event. - uint32_t CaptureCallstacksOnlyDraws; + eRENDERDOC_Option_CaptureCallstacksOnlyDraws = 4, - // Specify a delay in seconds to wait for a debugger to attach after + // Specify a delay in seconds to wait for a debugger to attach, after // creating or injecting into a process, before continuing to allow it to run. + // // 0 indicates no delay, and the process will run immediately after injection - uint32_t DelayForDebugger; - - // 1 - Verify any writes to mapped buffers, to check that they don't overwrite the - // bounds of the pointer returned. - // 0 - No verification is performed, and overwriting bounds may cause crashes or - // corruption in RenderDoc - uint32_t VerifyMapWrites; - - // 1 - Hooks any system API events that create child processes, and injects - // renderdoc into them recursively with the same options. + // + // Default - 0 seconds + // + eRENDERDOC_Option_DelayForDebugger = 5, + + // Verify any writes to mapped buffers, by checking the memory after the + // bounds of the returned pointer to detect any modification. + // + // Default - disabled + // + // 1 - Verify any writes to mapped buffers + // 0 - No verification is performed, and overwriting bounds may cause + // crashes or corruption in RenderDoc + eRENDERDOC_Option_VerifyMapWrites = 6, + + // Hooks any system API calls that create child processes, and injects + // RenderDoc into them recursively with the same options. + // + // Default - disabled + // + // 1 - Hooks into spawned child processes // 0 - Child processes are not hooked by RenderDoc - uint32_t HookIntoChildren; + eRENDERDOC_Option_HookIntoChildren = 7, - // By default renderdoc only includes resources in the final logfile necessary - // for that frame, this allows you to override that behaviour + // By default RenderDoc only includes resources in the final logfile necessary + // for that frame, this allows you to override that behaviour. + // + // Default - disabled // // 1 - all live resources at the time of capture are included in the log // and available for inspection // 0 - only the resources referenced by the captured frame are included - uint32_t RefAllResources; + eRENDERDOC_Option_RefAllResources = 8, - // By default renderdoc skips saving initial states for resources where the + // By default RenderDoc skips saving initial states for resources where the // previous contents don't appear to be used, assuming that writes before // reads indicate previous contents aren't used. // + // Default - disabled + // // 1 - initial contents at the start of each captured frame are saved, even if // they are later overwritten or cleared before being used. // 0 - unless a read is detected, initial contents will not be saved and will // appear as black or empty data. - uint32_t SaveAllInitials; + eRENDERDOC_Option_SaveAllInitials = 9, // In APIs that allow for the recording of command lists to be replayed later, - // renderdoc may choose to not capture command lists before a frame capture is + // RenderDoc may choose to not capture command lists before a frame capture is // triggered, to reduce overheads. This means any command lists recorded once // and replayed many times will not be available and may cause a failure to // capture. // - // Note this is typically only true for APIs where multithreading is difficult - // or discouraged. Newer APIs like Vulkan and D3D12 will ignore this option and - // always capture all command lists since the API is heavily oriented around it, - // and the overheads have been reduced by API design. + // Note this is only true for APIs where multithreading is difficult or + // discouraged. Newer APIs like Vulkan and D3D12 will ignore this option + // and always capture all command lists since the API is heavily oriented + // around it and the overheads have been reduced by API design. // // 1 - All command lists are captured from the start of the application // 0 - Command lists are only captured if their recording begins during // the period when a frame capture is in progress. - uint32_t CaptureAllCmdLists; -}; + eRENDERDOC_Option_CaptureAllCmdLists = 10, -enum KeyButton + // Mute API debugging output when the debug device mode option is enabled + // + // Default - enabled + // + // 1 - Mute any API debug messages from being displayed or passed through + // 0 - API debugging is displayed as normal + eRENDERDOC_Option_DebugOutputMute = 11, + +} RENDERDOC_CaptureOption; + +// Sets an option that controls how RenderDoc behaves on capture. +// +// Returns 1 if the option and value are valid +// Returns 0 if either is invalid and the option is unchanged +typedef int (RENDERDOC_CC *pRENDERDOC_SetCaptureOptionU32)(RENDERDOC_CaptureOption opt, uint32_t val); +typedef int (RENDERDOC_CC *pRENDERDOC_SetCaptureOptionF32)(RENDERDOC_CaptureOption opt, float val); + +// Gets the current value of an option as a uint32_t +// +// If the option is invalid, 0xffffffff is returned +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetCaptureOptionU32)(RENDERDOC_CaptureOption opt); + +// Gets the current value of an option as a float +// +// If the option is invalid, -FLT_MAX is returned +typedef float (RENDERDOC_CC *pRENDERDOC_GetCaptureOptionF32)(RENDERDOC_CaptureOption opt); + +typedef enum { - eKey_0 = 0x30, // '0' - // ... - eKey_9 = 0x39, // '9' - eKey_A = 0x41, // 'A' - // ... - eKey_Z = 0x5A, // 'Z' + // '0' - '9' matches ASCII values + eRENDERDOC_Key_0 = 0x30, + eRENDERDOC_Key_1 = 0x31, + eRENDERDOC_Key_2 = 0x32, + eRENDERDOC_Key_3 = 0x33, + eRENDERDOC_Key_4 = 0x34, + eRENDERDOC_Key_5 = 0x35, + eRENDERDOC_Key_6 = 0x36, + eRENDERDOC_Key_7 = 0x37, + eRENDERDOC_Key_8 = 0x38, + eRENDERDOC_Key_9 = 0x39, - eKey_Divide, - eKey_Multiply, - eKey_Subtract, - eKey_Plus, + // 'A' - 'Z' matches ASCII values + eRENDERDOC_Key_A = 0x41, + eRENDERDOC_Key_B = 0x42, + eRENDERDOC_Key_C = 0x43, + eRENDERDOC_Key_D = 0x44, + eRENDERDOC_Key_E = 0x45, + eRENDERDOC_Key_F = 0x46, + eRENDERDOC_Key_G = 0x47, + eRENDERDOC_Key_H = 0x48, + eRENDERDOC_Key_I = 0x49, + eRENDERDOC_Key_J = 0x4A, + eRENDERDOC_Key_K = 0x4B, + eRENDERDOC_Key_L = 0x4C, + eRENDERDOC_Key_M = 0x4D, + eRENDERDOC_Key_N = 0x4E, + eRENDERDOC_Key_O = 0x4F, + eRENDERDOC_Key_P = 0x50, + eRENDERDOC_Key_Q = 0x51, + eRENDERDOC_Key_R = 0x52, + eRENDERDOC_Key_S = 0x53, + eRENDERDOC_Key_T = 0x54, + eRENDERDOC_Key_U = 0x55, + eRENDERDOC_Key_V = 0x56, + eRENDERDOC_Key_W = 0x57, + eRENDERDOC_Key_X = 0x58, + eRENDERDOC_Key_Y = 0x59, + eRENDERDOC_Key_Z = 0x5A, - eKey_F1, - eKey_F2, - eKey_F3, - eKey_F4, - eKey_F5, - eKey_F6, - eKey_F7, - eKey_F8, - eKey_F9, - eKey_F10, - eKey_F11, - eKey_F12, + // leave the rest of the ASCII range free + // in case we want to use it later + eRENDERDOC_Key_NonPrintable = 0x100, - eKey_Home, - eKey_End, - eKey_Insert, - eKey_Delete, - eKey_PageUp, - eKey_PageDn, + eRENDERDOC_Key_Divide, + eRENDERDOC_Key_Multiply, + eRENDERDOC_Key_Subtract, + eRENDERDOC_Key_Plus, - eKey_Backspace, - eKey_Tab, - eKey_PrtScrn, - eKey_Pause, + eRENDERDOC_Key_F1, + eRENDERDOC_Key_F2, + eRENDERDOC_Key_F3, + eRENDERDOC_Key_F4, + eRENDERDOC_Key_F5, + eRENDERDOC_Key_F6, + eRENDERDOC_Key_F7, + eRENDERDOC_Key_F8, + eRENDERDOC_Key_F9, + eRENDERDOC_Key_F10, + eRENDERDOC_Key_F11, + eRENDERDOC_Key_F12, - eKey_Max, -}; + eRENDERDOC_Key_Home, + eRENDERDOC_Key_End, + eRENDERDOC_Key_Insert, + eRENDERDOC_Key_Delete, + eRENDERDOC_Key_PageUp, + eRENDERDOC_Key_PageDn, -enum InAppOverlay + eRENDERDOC_Key_Backspace, + eRENDERDOC_Key_Tab, + eRENDERDOC_Key_PrtScrn, + eRENDERDOC_Key_Pause, + + eRENDERDOC_Key_Max, +} RENDERDOC_InputButton; + +// Sets which key or keys can be used to toggle focus between multiple windows +// +// If keys is NULL or num is 0, toggle keys will be disabled +typedef void (RENDERDOC_CC *pRENDERDOC_SetFocusToggleKeys)(RENDERDOC_InputButton *keys, int num); + +// Sets which key or keys can be used to capture the next frame +// +// If keys is NULL or num is 0, captures keys will be disabled +typedef void (RENDERDOC_CC *pRENDERDOC_SetCaptureKeys)(RENDERDOC_InputButton *keys, int num); + +typedef enum { - eOverlay_Enabled = 0x1, - eOverlay_FrameRate = 0x2, - eOverlay_FrameNumber = 0x4, - eOverlay_CaptureList = 0x8, + // This single bit controls whether the overlay is enabled or disabled globally + eRENDERDOC_Overlay_Enabled = 0x1, - eOverlay_Default = (eOverlay_Enabled|eOverlay_FrameRate|eOverlay_FrameNumber|eOverlay_CaptureList), - eOverlay_All = ~0U, - eOverlay_None = 0, -}; + // Show the average framerate over several seconds as well as min/max + eRENDERDOC_Overlay_FrameRate = 0x2, -//////////////////////////////////////////////// -// !!!! IMPORTANT NOTE !!!! // -// // -// This API is pretty much experimental and // -// still in flux. The only thing guaranteed // -// to remain compatible is a call to // -// RENDERDOC_GetAPIVersion which must exactly // -// match the version you expect. // -// It will be bumped on breaking changes. // -//////////////////////////////////////////////// + // Show the current frame number + eRENDERDOC_Overlay_FrameNumber = 0x4, -// API breaking change history: -// Version 1 -> 2 - strings changed from wchar_t* to char* (UTF-8) -// Version 2 -> 3 - StartFrameCapture, EndFrameCapture and SetActiveWindow take -// 'device' pointer as well as window handles. -// This is either ID3D11Device* or the GL context (HGLRC/GLXContext) -// You can still pass NULL to both to capture the default, as long as -// there's only one device/window pair alive. -#define RENDERDOC_API_VERSION 3 + // Show a list of recent captures, and how many captures have been made + eRENDERDOC_Overlay_CaptureList = 0x8, -////////////////////////////////////////////////////////////////////////// -// In-program functions -////////////////////////////////////////////////////////////////////////// + // Default values for the overlay mask + eRENDERDOC_Overlay_Default = + (eRENDERDOC_Overlay_Enabled| + eRENDERDOC_Overlay_FrameRate| + eRENDERDOC_Overlay_FrameNumber| + eRENDERDOC_Overlay_CaptureList), -extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_GetAPIVersion(); -typedef int (RENDERDOC_CC *pRENDERDOC_GetAPIVersion)(); + // Enable all bits + eRENDERDOC_Overlay_All = ~0U, -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_Shutdown(); -typedef void (RENDERDOC_CC *pRENDERDOC_Shutdown)(); + // Disable all bits + eRENDERDOC_Overlay_None = 0, +} RENDERDOC_OverlayBits; -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetLogFile(const char *logfile); -typedef void (RENDERDOC_CC *pRENDERDOC_SetLogFile)(const char *logfile); - -extern "C" RENDERDOC_API const char* RENDERDOC_CC RENDERDOC_GetLogFile(); -typedef const char* (RENDERDOC_CC *pRENDERDOC_GetLogFile)(); - -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_GetNumCaptures(); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetNumCaptures)(); - -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_GetCapture(uint32_t idx, char *logfile, uint32_t *pathlength, uint64_t *timestamp); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetCapture)(uint32_t idx, char *logfile, uint32_t *pathlength, uint64_t *timestamp); - -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetCaptureOptions(const CaptureOptions *opts); -typedef void (RENDERDOC_CC *pRENDERDOC_SetCaptureOptions)(const CaptureOptions *opts); - -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_TriggerCapture(); -typedef void (RENDERDOC_CC *pRENDERDOC_TriggerCapture)(); - -// In the below functions 'device pointer' corresponds to the API specific handle, e.g. -// ID3D11Device, or the GL context pointer. -// The 'window handle' is the OS's native window handle (HWND or GLXDrawable). - -// This must match precisely to a pair, and it sets the RenderDoc in-app overlay to select that -// window as 'active' and respond to keypresses. -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetActiveWindow(void *device, void *wndHandle); -typedef void (RENDERDOC_CC *pRENDERDOC_SetActiveWindow)(void *device, void *wndHandle); - -// Either parameter can be NULL to wild-card match, such that you can capture from any -// device to a particular window, or a particular device to any window. -// In either case, if there are two or more possible matching (device,window) pairs it -// is undefined which one will be captured. -// You can pass (NULL, NULL) if you know you only have one device and one window, and -// it will match. Likewise if you have not created a window at all (only off-screen -// rendering), then NULL window pointer will capture, whether you pass a NULL device -// or specify a device among multiple. - -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartFrameCapture(void *device, void *wndHandle); -typedef void (RENDERDOC_CC *pRENDERDOC_StartFrameCapture)(void *device, void *wndHandle); - -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EndFrameCapture(void *device, void *wndHandle); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_EndFrameCapture)(void *device, void *wndHandle); - -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_GetOverlayBits(); +// returns the overlay bits that have been set typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetOverlayBits)(); - -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_MaskOverlayBits(uint32_t And, uint32_t Or); +// sets the overlay bits with an and & or mask typedef void (RENDERDOC_CC *pRENDERDOC_MaskOverlayBits)(uint32_t And, uint32_t Or); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetFocusToggleKeys(KeyButton *keys, int num); -typedef void (RENDERDOC_CC *pRENDERDOC_SetFocusToggleKeys)(KeyButton *keys, int num); +// this function will attempt to shut down RenderDoc. +// +// Note: that this will only work correctly if done immediately after +// the dll is loaded, before any API work happens. RenderDoc will remove its +// injected hooks and shut down. Behaviour is undefined if this is called +// after any API functions have been called. +typedef void (RENDERDOC_CC *pRENDERDOC_Shutdown)(); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetCaptureKeys(KeyButton *keys, int num); -typedef void (RENDERDOC_CC *pRENDERDOC_SetCaptureKeys)(KeyButton *keys, int num); +// This function will unload RenderDoc's crash handler. +// +// If you use your own crash handler and don't want RenderDoc's handler to +// intercede, you can call this function to unload it and any unhandled +// exceptions will pass to the next handler. +typedef void (RENDERDOC_CC *pRENDERDOC_UnloadCrashHandler)(); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_InitRemoteAccess(uint32_t *ident); -typedef void (RENDERDOC_CC *pRENDERDOC_InitRemoteAccess)(uint32_t *ident); +// Sets the logfile path template +// +// logfile is a UTF-8 string that gives a template for how captures will be named +// and where they will be saved. +// +// Any extension is stripped off the path, and captures are saved in the directory +// specified, and named with the filename and the frame number appended. If the +// directory does not exist it will be created, including any parent directories. +// +// If pathtemplate is NULL, the template will remain unchanged +// +// Example: +// +// SetLogFilePathTemplate("my_captures/example"); +// +// Capture #1 -> my_captures/example_frame123.rdc +// Capture #2 -> my_captures/example_frame456.rdc +typedef void (RENDERDOC_CC *pRENDERDOC_SetLogFilePathTemplate)(const char *pathtemplate); -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_IsRemoteAccessConnected(); +// returns the current logfile template, see SetLogFileTemplate above, as a UTF-8 string +typedef const char* (RENDERDOC_CC *pRENDERDOC_GetLogFilePathTemplate)(); + +// returns the number of captures that have been made +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetNumCaptures)(); + +// This function returns the details of a capture, by index. New captures are added +// to the end of the list. +// +// logfile will be filled with the absolute path to the capture file, as a UTF-8 string +// pathlength will be written with the length in bytes of the logfile string +// timestamp will be written with the time of the capture, in seconds since the Unix epoch +// +// Any of the parameters can be NULL and they'll be skipped. +// +// The function will return 1 if the capture index is valid, or 0 if the index is invalid +// If the index is invalid, the values will be unchanged +// +// Note: when captures are deleted in the UI they will remain in this list, so the +// logfile path may not exist anymore. +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetCapture)(uint32_t idx, char *logfile, uint32_t *pathlength, uint64_t *timestamp); + +// capture the next frame on whichever window and API is currently considered active +typedef void (RENDERDOC_CC *pRENDERDOC_TriggerCapture)(); + +// returns 1 if the RenderDoc UI is connected to this application, 0 otherwise typedef uint32_t (RENDERDOC_CC *pRENDERDOC_IsRemoteAccessConnected)(); -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_LaunchReplayUI(uint32_t connectRemoteAccess, const char *cmdline); +// This function will launch the Replay UI associated with the RenderDoc library injected +// into the running application. +// +// if connectRemoteAccess is 1, the Replay UI will be launched with a command line parameter +// to connect to this application +// cmdline is the rest of the command line, as a UTF-8 string. E.g. a captures to open +// if cmdline is NULL, the command line will be empty. +// +// returns the PID of the replay UI if successful, 0 if not successful. typedef uint32_t (RENDERDOC_CC *pRENDERDOC_LaunchReplayUI)(uint32_t connectRemoteAccess, const char *cmdline); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_UnloadCrashHandler(); -typedef void (RENDERDOC_CC *pRENDERDOC_UnloadCrashHandler)(); +// RenderDoc can return a higher version than requested if it's backwards compatible, +// this function returns the actual version returned. If a parameter is NULL, it will be +// ignored and the others will be filled out. +typedef void (RENDERDOC_CC *pRENDERDOC_GetAPIVersion)(int *major, int *minor, int *patch); + +////////////////////////////////////////////////////////////////////////// +// Capturing functions +// + +// A device pointer is a pointer to the API's root handle. +// +// This would be an ID3D11Device, HGLRC/GLXContext, ID3D12Device, etc +typedef void* RENDERDOC_DevicePointer; + +// A window handle is the OS's native window handle +// +// This would be an HWND, GLXDrawable, etc +typedef void* RENDERDOC_WindowHandle; + +// This sets the RenderDoc in-app overlay in the API/window pair as 'active' and it will +// respond to keypresses. Neither parameter can be NULL +typedef void (RENDERDOC_CC *pRENDERDOC_SetActiveWindow)(RENDERDOC_DevicePointer device, RENDERDOC_WindowHandle wndHandle); + +// When choosing either a device pointer or a window handle to capture, you can pass NULL. +// Passing NULL specifies a 'wildcard' match against anything. This allows you to specify +// any API rendering to a specific window, or a specific API instance rendering to any window, +// or in the simplest case of one window and one API, you can just pass NULL for both. +// +// In either case, if there are two or more possible matching (device,window) pairs it +// is undefined which one will be captured. +// +// Note: for headless rendering you can pass NULL for the window handle and either specify +// a device pointer or leave it NULL as above. + +// Immediately starts capturing API calls on the specified device pointer and window handle. +// +// If there is no matching thing to capture (e.g. no supported API has been initialised), +// this will do nothing. +// +// The results are undefined (including crashes) if two captures are started overlapping, +// even on separate devices and/oror windows. +typedef void (RENDERDOC_CC *pRENDERDOC_StartFrameCapture)(RENDERDOC_DevicePointer device, RENDERDOC_WindowHandle wndHandle); + +// Returns whether or not a frame capture is currently ongoing anywhere. +// +// This will return 1 if a capture is ongoing, and 0 if there is no capture running +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_IsFrameCapturing)(); + +// Ends capturing immediately. +// +// This will return 1 if the capture succeeded, and 0 if there was an error capturing. +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_EndFrameCapture)(RENDERDOC_DevicePointer device, RENDERDOC_WindowHandle wndHandle); + +////////////////////////////////////////////////////////////////////////////////////////////////// +// RenderDoc API versions +// + +// 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 +typedef enum +{ + eRENDERDOC_API_Version_1_0_0 = 10000, // RENDERDOC_API_1_0_0 = 1 000 000 +} RENDERDOC_Version; + +// eRENDERDOC_API_Version_1_0_0 +typedef struct +{ + pRENDERDOC_GetAPIVersion GetAPIVersion; + + pRENDERDOC_SetCaptureOptionU32 SetCaptureOptionU32; + pRENDERDOC_SetCaptureOptionF32 SetCaptureOptionF32; + + pRENDERDOC_GetCaptureOptionU32 GetCaptureOptionU32; + pRENDERDOC_GetCaptureOptionF32 GetCaptureOptionF32; + + pRENDERDOC_SetFocusToggleKeys SetFocusToggleKeys; + pRENDERDOC_SetCaptureKeys SetCaptureKeys; + + pRENDERDOC_GetOverlayBits GetOverlayBits; + pRENDERDOC_MaskOverlayBits MaskOverlayBits; + + pRENDERDOC_Shutdown Shutdown; + pRENDERDOC_UnloadCrashHandler UnloadCrashHandler; + + pRENDERDOC_SetLogFilePathTemplate SetLogFilePathTemplate; + pRENDERDOC_GetLogFilePathTemplate GetLogFilePathTemplate; + + pRENDERDOC_GetNumCaptures GetNumCaptures; + pRENDERDOC_GetCapture GetCapture; + + pRENDERDOC_TriggerCapture TriggerCapture; + + pRENDERDOC_IsRemoteAccessConnected IsRemoteAccessConnected; + pRENDERDOC_LaunchReplayUI LaunchReplayUI; + + pRENDERDOC_SetActiveWindow SetActiveWindow; + + pRENDERDOC_StartFrameCapture StartFrameCapture; + pRENDERDOC_IsFrameCapturing IsFrameCapturing; + pRENDERDOC_EndFrameCapture EndFrameCapture; +} RENDERDOC_API_1_0_0; + +////////////////////////////////////////////////////////////////////////////////////////////////// +// RenderDoc API entry point +// +// This entry point can be obtained via GetProcAddress/dlsym if RenderDoc is available. +// +// This function is not thread safe, and should not be called on multiple threads at once. +// Ideally, call this once as early as possible in your application's startup, before doing +// any API work, since some configuration functionality etc has to be done also before +// initialising any APIs. +// +// Parameters: +// version is a single value from the RENDERDOC_Version above. +// +// outAPIPointers will be filled out with a pointer to the corresponding struct of function +// pointers. +// +// Returns: +// 1 - if the outAPIPointers has been filled with a pointer to the API struct requested +// 0 - if the requested version is not supported or the arguments are invalid. +// +RENDERDOC_API int RENDERDOC_CC RENDERDOC_GetAPI(RENDERDOC_Version version, void **outAPIPointers); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/renderdoc/api/replay/capture_options.h b/renderdoc/api/replay/capture_options.h new file mode 100644 index 000000000..322b283e7 --- /dev/null +++ b/renderdoc/api/replay/capture_options.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015 Baldur Karlsson + * + * 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. + ******************************************************************************/ + +#pragma once + +typedef uint32_t bool32; + +// see renderdoc_app.h RENDERDOC_CaptureOption +struct CaptureOptions +{ + // for convenience, don't export the constructor but allow it within the module + // for constructing defaults +#ifdef RENDERDOC_EXPORTS + CaptureOptions(); +#endif + + bool32 AllowVSync; + bool32 AllowFullscreen; + bool32 DebugDeviceMode; + bool32 CaptureCallstacks; + bool32 CaptureCallstacksOnlyDraws; + uint32_t DelayForDebugger; + bool32 VerifyMapWrites; + bool32 HookIntoChildren; + bool32 RefAllResources; + bool32 SaveAllInitials; + bool32 CaptureAllCmdLists; + bool32 DebugOutputMute; +}; \ No newline at end of file diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 2090a7bd1..88ad1d0e0 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -100,6 +100,8 @@ struct ResourceId #include "data_types.h" #include "control_types.h" +#include "capture_options.h" + #include "d3d11_pipestate.h" #include "gl_pipestate.h" @@ -397,53 +399,31 @@ extern "C" RENDERDOC_API uint32_t RENDERDOC_CC Topology_VertexOffset(PrimitiveTo ////////////////////////////////////////////////////////////////////////// extern "C" RENDERDOC_API bool32 RENDERDOC_CC RENDERDOC_SupportLocalReplay(const char *logfile, rdctype::str *driverName); -typedef bool32 (RENDERDOC_CC *pRENDERDOC_SupportLocalReplay)(const char *logfile, rdctype::str *driverName); - extern "C" RENDERDOC_API ReplayCreateStatus RENDERDOC_CC RENDERDOC_CreateReplayRenderer(const char *logfile, float *progress, ReplayRenderer **rend); -typedef ReplayCreateStatus (RENDERDOC_CC *pRENDERDOC_CreateReplayRenderer)(const char *logfile, float *progress, ReplayRenderer **rend); ////////////////////////////////////////////////////////////////////////// // Remote access and control ////////////////////////////////////////////////////////////////////////// extern "C" RENDERDOC_API RemoteAccess* RENDERDOC_CC RENDERDOC_CreateRemoteAccessConnection(const char *host, uint32_t ident, const char *clientName, bool32 forceConnection); -typedef RemoteAccess* (RENDERDOC_CC *pRENDERDOC_CreateRemoteAccessConnection)(const char *host, uint32_t ident, const char *clientName, bool32 forceConnection); - extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteConnections(const char *host, uint32_t *idents); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_EnumerateRemoteConnections)(const char *host, uint32_t *idents); - extern "C" RENDERDOC_API ReplayCreateStatus RENDERDOC_CC RENDERDOC_CreateRemoteReplayConnection(const char *host, RemoteRenderer **rend); -typedef ReplayCreateStatus (RENDERDOC_CC *pRENDERDOC_CreateRemoteReplayConnection)(const char *host, RemoteRenderer **rend); - extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SpawnReplayHost(volatile bool32 *killReplay); -typedef void (RENDERDOC_CC *pRENDERDOC_SpawnReplayHost)(volatile bool32 *killReplay); ////////////////////////////////////////////////////////////////////////// // Injection/execution capture functions. ////////////////////////////////////////////////////////////////////////// -struct CaptureOptions; - +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_GetDefaultCaptureOptions(CaptureOptions *opts); extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartGlobalHook(const char *pathmatch, const char *logfile, const CaptureOptions *opts); -typedef void (RENDERDOC_CC *pRENDERDOC_StartGlobalHook)(const char *pathmatch, const char *logfile, const CaptureOptions *opts); - extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, const char *logfile, const CaptureOptions *opts, bool32 waitForExit); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_ExecuteAndInject)(const char *app, const char *workingDir, const char *cmdLine, - const char *logfile, const CaptureOptions *opts, bool32 waitForExit); - extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_InjectIntoProcess(uint32_t pid, const char *logfile, const CaptureOptions *opts, bool32 waitForExit); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_InjectIntoProcess)(uint32_t pid, const char *logfile, const CaptureOptions *opts, bool32 waitForExit); ////////////////////////////////////////////////////////////////////////// // Miscellaneous! ////////////////////////////////////////////////////////////////////////// extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_TriggerExceptionHandler(void *exceptionPtrs, bool32 crashed); -typedef void (RENDERDOC_CC *pRENDERDOC_TriggerExceptionHandler)(void *exceptionPtrs, bool32 crashed); - extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogText(const char *text); -typedef void (RENDERDOC_CC *pRENDERDOC_LogText)(const char *text); - extern "C" RENDERDOC_API bool32 RENDERDOC_CC RENDERDOC_GetThumbnail(const char *filename, byte *buf, uint32_t &len); -typedef bool32 (RENDERDOC_CC *pRENDERDOC_GetThumbnail)(const char *filename, byte *buf, uint32_t &len); diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 83793971c..99e4033c4 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -74,12 +74,12 @@ string ToStrHelper::Get(const RDCDriver &el) } template<> -string ToStrHelper::Get(const KeyButton &el) +string ToStrHelper::Get(const RENDERDOC_InputButton &el) { char alphanumericbuf[2] = { 'A', 0 }; // enums map straight to ascii - if( (el >= eKey_A && el <= eKey_Z) || (el >= eKey_0 && el <= eKey_9) ) + if( (el >= eRENDERDOC_Key_A && el <= eRENDERDOC_Key_Z) || (el >= eRENDERDOC_Key_0 && el <= eRENDERDOC_Key_9) ) { alphanumericbuf[0] = (char)el; return alphanumericbuf; @@ -87,40 +87,40 @@ string ToStrHelper::Get(const KeyButton &el) switch(el) { - case eKey_Divide: return "/"; - case eKey_Multiply: return "*"; - case eKey_Subtract: return "-"; - case eKey_Plus: return "+"; + case eRENDERDOC_Key_Divide: return "/"; + case eRENDERDOC_Key_Multiply: return "*"; + case eRENDERDOC_Key_Subtract: return "-"; + case eRENDERDOC_Key_Plus: return "+"; - case eKey_F1: return "F1"; - case eKey_F2: return "F2"; - case eKey_F3: return "F3"; - case eKey_F4: return "F4"; - case eKey_F5: return "F5"; - case eKey_F6: return "F6"; - case eKey_F7: return "F7"; - case eKey_F8: return "F8"; - case eKey_F9: return "F9"; - case eKey_F10: return "F10"; - case eKey_F11: return "F11"; - case eKey_F12: return "F12"; + case eRENDERDOC_Key_F1: return "F1"; + case eRENDERDOC_Key_F2: return "F2"; + case eRENDERDOC_Key_F3: return "F3"; + case eRENDERDOC_Key_F4: return "F4"; + case eRENDERDOC_Key_F5: return "F5"; + case eRENDERDOC_Key_F6: return "F6"; + case eRENDERDOC_Key_F7: return "F7"; + case eRENDERDOC_Key_F8: return "F8"; + case eRENDERDOC_Key_F9: return "F9"; + case eRENDERDOC_Key_F10: return "F10"; + case eRENDERDOC_Key_F11: return "F11"; + case eRENDERDOC_Key_F12: return "F12"; - case eKey_Home: return "Home"; - case eKey_End: return "End"; - case eKey_Insert: return "Insert"; - case eKey_Delete: return "Delete"; - case eKey_PageUp: return "PageUp"; - case eKey_PageDn: return "PageDn"; + case eRENDERDOC_Key_Home: return "Home"; + case eRENDERDOC_Key_End: return "End"; + case eRENDERDOC_Key_Insert: return "Insert"; + case eRENDERDOC_Key_Delete: return "Delete"; + case eRENDERDOC_Key_PageUp: return "PageUp"; + case eRENDERDOC_Key_PageDn: return "PageDn"; - case eKey_Backspace: return "Backspace"; - case eKey_Tab: return "Tab"; - case eKey_PrtScrn: return "PrtScrn"; - case eKey_Pause: return "Pause"; + case eRENDERDOC_Key_Backspace: return "Backspace"; + case eRENDERDOC_Key_Tab: return "Tab"; + case eRENDERDOC_Key_PrtScrn: return "PrtScrn"; + case eRENDERDOC_Key_Pause: return "Pause"; default: break; } char tostrBuf[256] = {0}; - StringFormat::snprintf(tostrBuf, 255, "KeyButton<%d>", el); + StringFormat::snprintf(tostrBuf, 255, "RENDERDOC_InputButton<%d>", el); return tostrBuf; } @@ -160,22 +160,24 @@ RenderDoc::RenderDoc() m_MarkerIndentLevel = 0; m_CurrentDriver = RDC_Unknown; + m_CapturesActive = 0; + m_Replay = false; m_Cap = false; m_FocusKeys.clear(); - m_FocusKeys.push_back(eKey_F11); + m_FocusKeys.push_back(eRENDERDOC_Key_F11); m_CaptureKeys.clear(); - m_CaptureKeys.push_back(eKey_F12); - m_CaptureKeys.push_back(eKey_PrtScrn); + m_CaptureKeys.push_back(eRENDERDOC_Key_F12); + m_CaptureKeys.push_back(eRENDERDOC_Key_PrtScrn); m_ProgressPtr = NULL; m_ExHandler = NULL; - m_Overlay = eOverlay_Default; + m_Overlay = eRENDERDOC_Overlay_Default; m_RemoteServerThreadShutdown = false; m_RemoteClientThreadShutdown = false; @@ -361,7 +363,10 @@ void RenderDoc::StartFrameCapture(void *dev, void *wnd) { IFrameCapturer *frameCap = MatchFrameCapturer(dev, wnd); if(frameCap) + { frameCap->StartFrameCapture(dev, wnd); + m_CapturesActive++; + } } void RenderDoc::SetActiveWindow(void *dev, void *wnd) @@ -382,7 +387,10 @@ bool RenderDoc::EndFrameCapture(void *dev, void *wnd) { IFrameCapturer *frameCap = MatchFrameCapturer(dev, wnd); if(frameCap) + { + m_CapturesActive--; return frameCap->EndFrameCapture(dev, wnd); + } return false; } @@ -725,9 +733,9 @@ map RenderDoc::GetRemoteDrivers() return ret; } -void RenderDoc::SetCaptureOptions(const CaptureOptions *opts) +void RenderDoc::SetCaptureOptions(const CaptureOptions &opts) { - m_Options = *opts; + m_Options = opts; } void RenderDoc::SetLogFile(const char *logFile) diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 17a9eb1f7..2a64ee1d1 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -42,6 +42,7 @@ class Serialiser; class Chunk; #include "api/app/renderdoc_app.h" +#include "api/replay/capture_options.h" #include "api/replay/replay_enums.h" #include "os/os_specific.h" #include "common/threading.h" @@ -186,7 +187,7 @@ class RenderDoc void BecomeReplayHost(volatile uint32_t &killReplay); - void SetCaptureOptions(const CaptureOptions *opts); + void SetCaptureOptions(const CaptureOptions &opts); const CaptureOptions &GetCaptureOptions() const { return m_Options; } void RecreateCrashHandler(); @@ -253,6 +254,7 @@ class RenderDoc void RemoveDeviceFrameCapturer(void *dev); void StartFrameCapture(void *dev, void *wnd); + bool IsFrameCapturing() { return m_CapturesActive > 0; } void SetActiveWindow(void *dev, void *wnd); bool EndFrameCapture(void *dev, void *wnd); @@ -265,21 +267,21 @@ class RenderDoc void QueueCapture(uint32_t frameNumber) { m_QueuedFrameCaptures.insert(frameNumber); } - void SetFocusKeys(KeyButton *keys, int num) + void SetFocusKeys(RENDERDOC_InputButton *keys, int num) { m_FocusKeys.resize(num); for(int i=0; i < num && keys; i++) m_FocusKeys[i] = keys[i]; } - void SetCaptureKeys(KeyButton *keys, int num) + void SetCaptureKeys(RENDERDOC_InputButton *keys, int num) { m_CaptureKeys.resize(num); for(int i=0; i < num && keys; i++) m_CaptureKeys[i] = keys[i]; } - const vector &GetFocusKeys() { return m_FocusKeys; } - const vector &GetCaptureKeys() { return m_CaptureKeys; } + const vector &GetFocusKeys() { return m_FocusKeys; } + const vector &GetCaptureKeys() { return m_CaptureKeys; } bool ShouldTriggerCapture(uint32_t frameNumber); private: @@ -292,8 +294,8 @@ class RenderDoc bool m_Cap; - vector m_FocusKeys; - vector m_CaptureKeys; + vector m_FocusKeys; + vector m_CaptureKeys; string m_LoggingFilename; @@ -363,6 +365,8 @@ class RenderDoc } }; + int m_CapturesActive; + map m_WindowFrameCapturers; DeviceWnd m_ActiveWindow; map m_DeviceFrameCapturers; diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index 1f6a40c38..a322fb95a 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -358,7 +358,8 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device* realDevice, D3D11InitPara if(m_pInfoQueue) { - m_pInfoQueue->SetMuteDebugOutput(true); + if(RenderDoc::Inst().GetCaptureOptions().DebugOutputMute) + m_pInfoQueue->SetMuteDebugOutput(true); UINT size = m_pInfoQueue->GetStorageFilterStackSize(); @@ -2863,11 +2864,19 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) } else { - RDCLOG("Failed to capture, frame %u", m_FrameCounter); + const char *reasonString = "Unknown reason"; + switch(reason) + { + case CaptureFailed_UncappedCmdlist: reasonString = "Uncapped command list"; break; + case CaptureFailed_UncappedUnmap: reasonString = "Uncapped Map()/Unmap()"; break; + default: break; + } + + RDCLOG("Failed to capture, frame %u: %s", m_FrameCounter, reasonString); m_Failures++; - if((RenderDoc::Inst().GetOverlayBits() & eOverlay_Enabled) && swap != NULL) + if((RenderDoc::Inst().GetOverlayBits() & eRENDERDOC_Overlay_Enabled) && swap != NULL) { D3D11RenderState old = *m_pImmediateContext->GetCurrentPipelineState(); @@ -2885,14 +2894,6 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) GetDebugManager()->SetOutputDimensions(swapDesc.BufferDesc.Width, swapDesc.BufferDesc.Height); GetDebugManager()->SetOutputWindow(swapDesc.OutputWindow); - const char *reasonString = "Unknown reason"; - switch(reason) - { - case CaptureFailed_UncappedCmdlist: reasonString = "Uncapped command list"; break; - case CaptureFailed_UncappedUnmap: reasonString = "Uncapped Map()/Unmap()"; break; - default: break; - } - GetDebugManager()->RenderText(0.0f, 0.0f, "Failed to capture frame %u: %s", m_FrameCounter, reasonString); } @@ -2915,7 +2916,10 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) GetResourceManager()->ClearReferencedResources(); - if(m_Failures > 5) // failed too many times + // if it's a capture triggered from application code, immediately + // give up as it's not reasonable to expect applications to detect and retry. + // otherwise we can retry in case the next frame works. + if(m_Failures > 5 || m_AppControlledCapture) { m_pImmediateContext->FinishCapture(); @@ -3037,7 +3041,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI uint32_t overlay = RenderDoc::Inst().GetOverlayBits(); - if(overlay & eOverlay_Enabled) + if(overlay & eRENDERDOC_Overlay_Enabled) { ID3D11RenderTargetView *rtv = m_SwapChains[swap]; @@ -3053,7 +3057,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI if(activeWindow) { - vector keys = RenderDoc::Inst().GetCaptureKeys(); + vector keys = RenderDoc::Inst().GetCaptureKeys(); string overlayText = "D3D11. "; @@ -3068,11 +3072,11 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI if(!keys.empty()) overlayText += " to capture."; - if(overlay & eOverlay_FrameNumber) + if(overlay & eRENDERDOC_Overlay_FrameNumber) { overlayText += StringFormat::Fmt(" Frame: %d.", m_FrameCounter); } - if(overlay & eOverlay_FrameRate) + if(overlay & eRENDERDOC_Overlay_FrameRate) { overlayText += StringFormat::Fmt(" %.2lf ms (%.2lf .. %.2lf) (%.0lf FPS)", m_AvgFrametime, m_MinFrametime, m_MaxFrametime, 1000.0f/m_AvgFrametime); @@ -3086,7 +3090,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI y += 1.0f; } - if(overlay & eOverlay_CaptureList) + if(overlay & eRENDERDOC_Overlay_CaptureList) { GetDebugManager()->RenderText(0.0f, y, "%d Captures saved.\n", (uint32_t)m_FrameRecord.size()); y += 1.0f; @@ -3125,7 +3129,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI } else { - vector keys = RenderDoc::Inst().GetFocusKeys(); + vector keys = RenderDoc::Inst().GetFocusKeys(); string str = "D3D11. Inactive swapchain."; diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index 98d5d0414..9719d994a 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -2059,7 +2059,7 @@ void WrappedOpenGL::SwapBuffers(void *windowHandle) uint32_t overlay = RenderDoc::Inst().GetOverlayBits(); - if(overlay & eOverlay_Enabled) + if(overlay & eRENDERDOC_Overlay_Enabled) { RenderTextState textState; @@ -2067,7 +2067,7 @@ void WrappedOpenGL::SwapBuffers(void *windowHandle) if(activeWindow) { - vector keys = RenderDoc::Inst().GetCaptureKeys(); + vector keys = RenderDoc::Inst().GetCaptureKeys(); string overlayText = "OpenGL."; @@ -2087,11 +2087,11 @@ void WrappedOpenGL::SwapBuffers(void *windowHandle) overlayText += " to capture."; } - if(overlay & eOverlay_FrameNumber) + if(overlay & eRENDERDOC_Overlay_FrameNumber) { overlayText += StringFormat::Fmt(" Frame: %d.", m_FrameCounter); } - if(overlay & eOverlay_FrameRate) + if(overlay & eRENDERDOC_Overlay_FrameRate) { overlayText += StringFormat::Fmt(" %.2lf ms (%.2lf .. %.2lf) (%.0lf FPS)", m_AvgFrametime, m_MinFrametime, m_MaxFrametime, @@ -2122,7 +2122,7 @@ void WrappedOpenGL::SwapBuffers(void *windowHandle) y += 1.0f; } - if(ctxdata.Modern() && (overlay & eOverlay_CaptureList)) + if(ctxdata.Modern() && (overlay & eRENDERDOC_Overlay_CaptureList)) { RenderOverlayText(0.0f, y, "%d Captures saved.\n", (uint32_t)m_FrameRecord.size()); y += 1.0f; @@ -2160,7 +2160,7 @@ void WrappedOpenGL::SwapBuffers(void *windowHandle) } else { - vector keys = RenderDoc::Inst().GetFocusKeys(); + vector keys = RenderDoc::Inst().GetFocusKeys(); string str = "OpenGL. Inactive window."; @@ -2433,11 +2433,18 @@ bool WrappedOpenGL::EndFrameCapture(void *dev, void *wnd) } else { - RDCLOG("Failed to capture, frame %u", m_FrameCounter); + const char *reasonString = "Unknown reason"; + switch(reason) + { + case CaptureFailed_UncappedUnmap: reasonString = "Uncapped Map()/Unmap()"; break; + default: break; + } + + RDCLOG("Failed to capture, frame %u: %s", m_FrameCounter, reasonString); m_Failures++; - if((RenderDoc::Inst().GetOverlayBits() & eOverlay_Enabled)) + if((RenderDoc::Inst().GetOverlayBits() & eRENDERDOC_Overlay_Enabled)) { ContextData &ctxdata = GetCtxData(); @@ -2445,13 +2452,6 @@ bool WrappedOpenGL::EndFrameCapture(void *dev, void *wnd) textState.Push(m_Real, ctxdata.Modern()); - const char *reasonString = "Unknown reason"; - switch(reason) - { - case CaptureFailed_UncappedUnmap: reasonString = "Uncapped Map()/Unmap()"; break; - default: break; - } - RenderOverlayText(0.0f, 0.0f, "Failed to capture frame %u: %s", m_FrameCounter, reasonString); textState.Pop(m_Real, ctxdata.Modern()); @@ -2469,8 +2469,11 @@ bool WrappedOpenGL::EndFrameCapture(void *dev, void *wnd) CleanupCapture(); GetResourceManager()->ClearReferencedResources(); - - if(m_Failures > 5) // failed too many times + + // if it's a capture triggered from application code, immediately + // give up as it's not reasonable to expect applications to detect and retry. + // otherwise we can retry in case the next frame works. + if(m_Failures > 5 || m_AppControlledCapture) { FinishCapture(); diff --git a/renderdoc/os/linux/linux_stringio.cpp b/renderdoc/os/linux/linux_stringio.cpp index 107a60a21..006ed3d50 100644 --- a/renderdoc/os/linux/linux_stringio.cpp +++ b/renderdoc/os/linux/linux_stringio.cpp @@ -79,37 +79,37 @@ namespace Keyboard if(CurrentXDisplay == NULL) return false; - if(key >= eKey_A && key <= eKey_Z) ks = key; - if(key >= eKey_0 && key <= eKey_9) ks = key; + if(key >= eRENDERDOC_Key_A && key <= eRENDERDOC_Key_Z) ks = key; + if(key >= eRENDERDOC_Key_0 && key <= eRENDERDOC_Key_9) ks = key; switch(key) { - case eKey_Divide: ks = XK_KP_Divide; break; - case eKey_Multiply: ks = XK_KP_Multiply; break; - case eKey_Subtract: ks = XK_KP_Subtract; break; - case eKey_Plus: ks = XK_KP_Add; break; - case eKey_F1: ks = XK_F1; break; - case eKey_F2: ks = XK_F2; break; - case eKey_F3: ks = XK_F3; break; - case eKey_F4: ks = XK_F4; break; - case eKey_F5: ks = XK_F5; break; - case eKey_F6: ks = XK_F6; break; - case eKey_F7: ks = XK_F7; break; - case eKey_F8: ks = XK_F8; break; - case eKey_F9: ks = XK_F9; break; - case eKey_F10: ks = XK_F10; break; - case eKey_F11: ks = XK_F11; break; - case eKey_F12: ks = XK_F12; break; - case eKey_Home: ks = XK_Home; break; - case eKey_End: ks = XK_End; break; - case eKey_Insert: ks = XK_Insert; break; - case eKey_Delete: ks = XK_Delete; break; - case eKey_PageUp: ks = XK_Prior; break; - case eKey_PageDn: ks = XK_Next; break; - case eKey_Backspace: ks = XK_BackSpace; break; - case eKey_Tab: ks = XK_Tab; break; - case eKey_PrtScrn: ks = XK_Print; break; - case eKey_Pause: ks = XK_Pause; break; + case eRENDERDOC_Key_Divide: ks = XK_KP_Divide; break; + case eRENDERDOC_Key_Multiply: ks = XK_KP_Multiply; break; + case eRENDERDOC_Key_Subtract: ks = XK_KP_Subtract; break; + case eRENDERDOC_Key_Plus: ks = XK_KP_Add; break; + case eRENDERDOC_Key_F1: ks = XK_F1; break; + case eRENDERDOC_Key_F2: ks = XK_F2; break; + case eRENDERDOC_Key_F3: ks = XK_F3; break; + case eRENDERDOC_Key_F4: ks = XK_F4; break; + case eRENDERDOC_Key_F5: ks = XK_F5; break; + case eRENDERDOC_Key_F6: ks = XK_F6; break; + case eRENDERDOC_Key_F7: ks = XK_F7; break; + case eRENDERDOC_Key_F8: ks = XK_F8; break; + case eRENDERDOC_Key_F9: ks = XK_F9; break; + case eRENDERDOC_Key_F10: ks = XK_F10; break; + case eRENDERDOC_Key_F11: ks = XK_F11; break; + case eRENDERDOC_Key_F12: ks = XK_F12; break; + case eRENDERDOC_Key_Home: ks = XK_Home; break; + case eRENDERDOC_Key_End: ks = XK_End; break; + case eRENDERDOC_Key_Insert: ks = XK_Insert; break; + case eRENDERDOC_Key_Delete: ks = XK_Delete; break; + case eRENDERDOC_Key_PageUp: ks = XK_Prior; break; + case eRENDERDOC_Key_PageDn: ks = XK_Next; break; + case eRENDERDOC_Key_Backspace: ks = XK_BackSpace; break; + case eRENDERDOC_Key_Tab: ks = XK_Tab; break; + case eRENDERDOC_Key_PrtScrn: ks = XK_Print; break; + case eRENDERDOC_Key_Pause: ks = XK_Pause; break; default: break; } diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index b62dce96b..bf3cf1dd8 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -249,6 +249,12 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c return pi; } +extern "C" __declspec(dllexport) +void __cdecl RENDERDOC_GetRemoteAccessIdent(uint32_t *ident) +{ + if(ident) *ident = RenderDoc::Inst().GetRemoteAccessIdent(); +} + uint32_t Process::InjectIntoProcess(uint32_t pid, const char *logfile, const CaptureOptions *opts, bool waitForExit) { CaptureOptions options; @@ -410,7 +416,7 @@ uint32_t Process::InjectIntoProcess(uint32_t pid, const char *logfile, const Cap if(opts != NULL) InjectFunctionCall(hProcess, loc, "RENDERDOC_SetCaptureOptions", (CaptureOptions *)opts, sizeof(CaptureOptions)); - InjectFunctionCall(hProcess, loc, "RENDERDOC_InitRemoteAccess", &remoteident, sizeof(remoteident)); + InjectFunctionCall(hProcess, loc, "RENDERDOC_GetRemoteAccessIdent", &remoteident, sizeof(remoteident)); } if(waitForExit) diff --git a/renderdoc/os/win32/win32_stringio.cpp b/renderdoc/os/win32/win32_stringio.cpp index d01539bf5..ad6e03f68 100644 --- a/renderdoc/os/win32/win32_stringio.cpp +++ b/renderdoc/os/win32/win32_stringio.cpp @@ -89,37 +89,37 @@ namespace Keyboard { int vk = 0; - if(key >= eKey_A && key <= eKey_Z) vk = key; - if(key >= eKey_0 && key <= eKey_9) vk = key; + if(key >= eRENDERDOC_Key_A && key <= eRENDERDOC_Key_Z) vk = key; + if(key >= eRENDERDOC_Key_0 && key <= eRENDERDOC_Key_9) vk = key; switch(key) { - case eKey_Divide: vk = VK_DIVIDE; break; - case eKey_Multiply: vk = VK_MULTIPLY; break; - case eKey_Subtract: vk = VK_SUBTRACT; break; - case eKey_Plus: vk = VK_ADD; break; - case eKey_F1: vk = VK_F1; break; - case eKey_F2: vk = VK_F2; break; - case eKey_F3: vk = VK_F3; break; - case eKey_F4: vk = VK_F4; break; - case eKey_F5: vk = VK_F5; break; - case eKey_F6: vk = VK_F6; break; - case eKey_F7: vk = VK_F7; break; - case eKey_F8: vk = VK_F8; break; - case eKey_F9: vk = VK_F9; break; - case eKey_F10: vk = VK_F10; break; - case eKey_F11: vk = VK_F11; break; - case eKey_F12: vk = VK_F12; break; - case eKey_Home: vk = VK_HOME; break; - case eKey_End: vk = VK_END; break; - case eKey_Insert: vk = VK_INSERT; break; - case eKey_Delete: vk = VK_DELETE; break; - case eKey_PageUp: vk = VK_PRIOR; break; - case eKey_PageDn: vk = VK_NEXT; break; - case eKey_Backspace: vk = VK_BACK; break; - case eKey_Tab: vk = VK_TAB; break; - case eKey_PrtScrn: vk = VK_SNAPSHOT; break; - case eKey_Pause: vk = VK_PAUSE; break; + case eRENDERDOC_Key_Divide: vk = VK_DIVIDE; break; + case eRENDERDOC_Key_Multiply: vk = VK_MULTIPLY; break; + case eRENDERDOC_Key_Subtract: vk = VK_SUBTRACT; break; + case eRENDERDOC_Key_Plus: vk = VK_ADD; break; + case eRENDERDOC_Key_F1: vk = VK_F1; break; + case eRENDERDOC_Key_F2: vk = VK_F2; break; + case eRENDERDOC_Key_F3: vk = VK_F3; break; + case eRENDERDOC_Key_F4: vk = VK_F4; break; + case eRENDERDOC_Key_F5: vk = VK_F5; break; + case eRENDERDOC_Key_F6: vk = VK_F6; break; + case eRENDERDOC_Key_F7: vk = VK_F7; break; + case eRENDERDOC_Key_F8: vk = VK_F8; break; + case eRENDERDOC_Key_F9: vk = VK_F9; break; + case eRENDERDOC_Key_F10: vk = VK_F10; break; + case eRENDERDOC_Key_F11: vk = VK_F11; break; + case eRENDERDOC_Key_F12: vk = VK_F12; break; + case eRENDERDOC_Key_Home: vk = VK_HOME; break; + case eRENDERDOC_Key_End: vk = VK_END; break; + case eRENDERDOC_Key_Insert: vk = VK_INSERT; break; + case eRENDERDOC_Key_Delete: vk = VK_DELETE; break; + case eRENDERDOC_Key_PageUp: vk = VK_PRIOR; break; + case eRENDERDOC_Key_PageDn: vk = VK_NEXT; break; + case eRENDERDOC_Key_Backspace: vk = VK_BACK; break; + case eRENDERDOC_Key_Tab: vk = VK_TAB; break; + case eRENDERDOC_Key_PrtScrn: vk = VK_SNAPSHOT; break; + case eRENDERDOC_Key_Pause: vk = VK_PAUSE; break; default: break; } diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index 8e4b4cbf1..b63f1ef6b 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -229,6 +229,7 @@ + @@ -315,6 +316,8 @@ + + diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index 90b83a128..1b9f8a073 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -219,6 +219,9 @@ Resources + + API\Replay + @@ -341,6 +344,12 @@ OS\Win32 + + API\In-App + + + Replay + diff --git a/renderdoc/replay/app_api.cpp b/renderdoc/replay/app_api.cpp new file mode 100644 index 000000000..5b6408e54 --- /dev/null +++ b/renderdoc/replay/app_api.cpp @@ -0,0 +1,228 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015 Baldur Karlsson + * + * 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. + ******************************************************************************/ + +#include "common/common.h" +#include "core/core.h" +#include "hooks/hooks.h" +#include "api/app/renderdoc_app.h" + +static void SetFocusToggleKeys(RENDERDOC_InputButton *keys, int num) +{ + RenderDoc::Inst().SetFocusKeys(keys, num); +} + +static void SetCaptureKeys(RENDERDOC_InputButton *keys, int num) +{ + RenderDoc::Inst().SetCaptureKeys(keys, num); +} + +static uint32_t GetOverlayBits() +{ + return RenderDoc::Inst().GetOverlayBits(); +} + +static void MaskOverlayBits(uint32_t And, uint32_t Or) +{ + RenderDoc::Inst().MaskOverlayBits(And, Or); +} + +static void Shutdown() +{ + RenderDoc::Inst().Shutdown(); + LibraryHooks::GetInstance().RemoveHooks(); +} + +static void UnloadCrashHandler() +{ + RenderDoc::Inst().UnloadCrashHandler(); +} + +static void SetLogFilePathTemplate(const char *logfile) +{ + RDCLOG("Using logfile %s", logfile); + RenderDoc::Inst().SetLogFile(logfile); +} + +static const char *GetLogFilePathTemplate() +{ + return RenderDoc::Inst().GetLogFile(); +} + +static uint32_t GetNumCaptures() +{ + return (uint32_t)RenderDoc::Inst().GetCaptures().size(); +} + +static uint32_t GetCapture(uint32_t idx, char *logfile, uint32_t *pathlength, uint64_t *timestamp) +{ + vector caps = RenderDoc::Inst().GetCaptures(); + + if(idx >= (uint32_t)caps.size()) + { + if(logfile) logfile[0] = 0; + if(pathlength) *pathlength = 0; + if(timestamp) *timestamp = 0; + return 0; + } + + CaptureData &c = caps[idx]; + + if(logfile) + memcpy(logfile, c.path.c_str(), sizeof(char)*(c.path.size()+1)); + if(pathlength) + *pathlength = uint32_t(c.path.size()+1); + if(timestamp) + *timestamp = c.timestamp; + + return 1; +} + +static void TriggerCapture() +{ + RenderDoc::Inst().TriggerCapture(); +} + +static uint32_t IsRemoteAccessConnected() +{ + return RenderDoc::Inst().IsRemoteAccessConnected(); +} + +static uint32_t LaunchReplayUI(uint32_t connectRemoteAccess, const char *cmdline) +{ + string replayapp = FileIO::GetReplayAppFilename(); + + if(replayapp.empty()) + return 0; + + string cmd = cmdline ? cmdline : ""; + if(connectRemoteAccess) + cmd += StringFormat::Fmt(" --remoteaccess localhost:%u", RenderDoc::Inst().GetRemoteAccessIdent()); + + return Process::LaunchProcess(replayapp.c_str(), "", cmd.c_str()); +} + +static void SetActiveWindow(void *device, void *wndHandle) +{ + RenderDoc::Inst().SetActiveWindow(device, wndHandle); +} + +static void StartFrameCapture(void *device, void *wndHandle) +{ + RenderDoc::Inst().StartFrameCapture(device, wndHandle); +} + +static uint32_t IsFrameCapturing() +{ + return RenderDoc::Inst().IsFrameCapturing() ? 1 : 0; +} + +static uint32_t EndFrameCapture(void *device, void *wndHandle) +{ + return RenderDoc::Inst().EndFrameCapture(device, wndHandle) ? 1 : 0; +} + +// defined in capture_options.cpp +int RENDERDOC_CC SetCaptureOptionU32(RENDERDOC_CaptureOption opt, uint32_t val); +int RENDERDOC_CC SetCaptureOptionF32(RENDERDOC_CaptureOption opt, float val); +uint32_t RENDERDOC_CC GetCaptureOptionU32(RENDERDOC_CaptureOption opt); +float RENDERDOC_CC GetCaptureOptionF32(RENDERDOC_CaptureOption opt); + +void RENDERDOC_CC GetAPIVersion_1_0_0(int *major, int *minor, int *patch) +{ + if(major) *major = 1; + if(minor) *minor = 0; + if(patch) *patch = 0; +} + +RENDERDOC_API_1_0_0 api_1_0_0; +void Init_1_0_0() +{ + api_1_0_0.GetAPIVersion = &GetAPIVersion_1_0_0; + + api_1_0_0.SetCaptureOptionU32 = &SetCaptureOptionU32; + api_1_0_0.SetCaptureOptionF32 = &SetCaptureOptionF32; + + api_1_0_0.GetCaptureOptionU32 = &GetCaptureOptionU32; + api_1_0_0.GetCaptureOptionF32 = &GetCaptureOptionF32; + + api_1_0_0.SetFocusToggleKeys = &SetFocusToggleKeys; + api_1_0_0.SetCaptureKeys = &SetCaptureKeys; + + api_1_0_0.GetOverlayBits = &GetOverlayBits; + api_1_0_0.MaskOverlayBits = &MaskOverlayBits; + + api_1_0_0.Shutdown = &Shutdown; + api_1_0_0.UnloadCrashHandler = &UnloadCrashHandler; + + api_1_0_0.SetLogFilePathTemplate = &SetLogFilePathTemplate; + api_1_0_0.GetLogFilePathTemplate = &GetLogFilePathTemplate; + + api_1_0_0.GetNumCaptures = &GetNumCaptures; + api_1_0_0.GetCapture = &GetCapture; + + api_1_0_0.TriggerCapture = &TriggerCapture; + + api_1_0_0.IsRemoteAccessConnected = &IsRemoteAccessConnected; + api_1_0_0.LaunchReplayUI = &LaunchReplayUI; + + api_1_0_0.SetActiveWindow = &SetActiveWindow; + + api_1_0_0.StartFrameCapture = &StartFrameCapture; + api_1_0_0.IsFrameCapturing = &IsFrameCapturing; + api_1_0_0.EndFrameCapture = &EndFrameCapture; +} + +extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_GetAPI(RENDERDOC_Version version, void **outAPIPointers) +{ + if(outAPIPointers == NULL) + { + RDCERR("Invalid call to RENDERDOC_GetAPI with NULL outAPIPointers"); + return 0; + } + + int ret = 0; + int major = 0, minor = 0, patch = 0; + +#define API_VERSION_HANDLE(enumver, actualver) \ + if(version == CONCAT(eRENDERDOC_API_Version_, enumver)) \ + { \ + CONCAT(Init_, actualver)(); \ + *outAPIPointers = &CONCAT(api_, actualver); \ + CONCAT(api_, actualver).GetAPIVersion(&major, &minor, &patch); \ + ret = 1; \ + } + + API_VERSION_HANDLE(1_0_0, 1_0_0); + +#undef API_VERSION_HANDLE + + if(ret) + { + RDCLOG("Initialising RenderDoc API version %d.%d.%d for requested version %d", major, minor, patch, version); + return 1; + } + + RDCERR("Unrecognised API version '%d'", version); + return 0; +} \ No newline at end of file diff --git a/renderdoc/replay/capture_options.cpp b/renderdoc/replay/capture_options.cpp new file mode 100644 index 000000000..68c58368f --- /dev/null +++ b/renderdoc/replay/capture_options.cpp @@ -0,0 +1,216 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015 Baldur Karlsson + * + * 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. + ******************************************************************************/ + +#include "common/common.h" +#include "core/core.h" +#include "api/replay/capture_options.h" +#include "api/app/renderdoc_app.h" + +int RENDERDOC_CC SetCaptureOptionU32(RENDERDOC_CaptureOption opt, uint32_t val) +{ + CaptureOptions opts = RenderDoc::Inst().GetCaptureOptions(); + + switch(opt) + { + case eRENDERDOC_Option_AllowVSync: + opts.AllowVSync = (val != 0); + break; + case eRENDERDOC_Option_AllowFullscreen: + opts.AllowFullscreen = (val != 0); + break; + case eRENDERDOC_Option_DebugDeviceMode: + opts.DebugDeviceMode = (val != 0); + break; + case eRENDERDOC_Option_CaptureCallstacks: + opts.CaptureCallstacks = (val != 0); + break; + case eRENDERDOC_Option_CaptureCallstacksOnlyDraws: + opts.CaptureCallstacksOnlyDraws = (val != 0); + break; + case eRENDERDOC_Option_DelayForDebugger: + opts.DelayForDebugger = val; + break; + case eRENDERDOC_Option_VerifyMapWrites: + opts.VerifyMapWrites = (val != 0); + break; + case eRENDERDOC_Option_HookIntoChildren: + opts.HookIntoChildren = (val != 0); + break; + case eRENDERDOC_Option_RefAllResources: + opts.RefAllResources = (val != 0); + break; + case eRENDERDOC_Option_SaveAllInitials: + opts.SaveAllInitials = (val != 0); + break; + case eRENDERDOC_Option_CaptureAllCmdLists: + opts.CaptureAllCmdLists = (val != 0); + break; + case eRENDERDOC_Option_DebugOutputMute: + opts.DebugOutputMute = (val != 0); + break; + default: + RDCLOG("Unrecognised capture option '%d'", opt); + return 0; + } + + RenderDoc::Inst().SetCaptureOptions(opts); + return 1; +} + +int RENDERDOC_CC SetCaptureOptionF32(RENDERDOC_CaptureOption opt, float val) +{ + CaptureOptions opts = RenderDoc::Inst().GetCaptureOptions(); + + switch(opt) + { + case eRENDERDOC_Option_AllowVSync: + opts.AllowVSync = (val != 0.0f); + break; + case eRENDERDOC_Option_AllowFullscreen: + opts.AllowFullscreen = (val != 0.0f); + break; + case eRENDERDOC_Option_DebugDeviceMode: + opts.DebugDeviceMode = (val != 0.0f); + break; + case eRENDERDOC_Option_CaptureCallstacks: + opts.CaptureCallstacks = (val != 0.0f); + break; + case eRENDERDOC_Option_CaptureCallstacksOnlyDraws: + opts.CaptureCallstacksOnlyDraws = (val != 0.0f); + break; + case eRENDERDOC_Option_DelayForDebugger: + opts.DelayForDebugger = (uint32_t)val; + break; + case eRENDERDOC_Option_VerifyMapWrites: + opts.VerifyMapWrites = (val != 0.0f); + break; + case eRENDERDOC_Option_HookIntoChildren: + opts.HookIntoChildren = (val != 0.0f); + break; + case eRENDERDOC_Option_RefAllResources: + opts.RefAllResources = (val != 0.0f); + break; + case eRENDERDOC_Option_SaveAllInitials: + opts.SaveAllInitials = (val != 0.0f); + break; + case eRENDERDOC_Option_CaptureAllCmdLists: + opts.CaptureAllCmdLists = (val != 0.0f); + break; + case eRENDERDOC_Option_DebugOutputMute: + opts.DebugOutputMute = (val != 0.0f); + break; + default: + RDCLOG("Unrecognised capture option '%d'", opt); + return 0; + } + + RenderDoc::Inst().SetCaptureOptions(opts); + return 1; +} + +uint32_t RENDERDOC_CC GetCaptureOptionU32(RENDERDOC_CaptureOption opt) +{ + switch(opt) + { + case eRENDERDOC_Option_AllowVSync: + return (RenderDoc::Inst().GetCaptureOptions().AllowVSync ? 1 : 0); + case eRENDERDOC_Option_AllowFullscreen: + return (RenderDoc::Inst().GetCaptureOptions().AllowFullscreen ? 1 : 0); + case eRENDERDOC_Option_DebugDeviceMode: + return (RenderDoc::Inst().GetCaptureOptions().DebugDeviceMode ? 1 : 0); + case eRENDERDOC_Option_CaptureCallstacks: + return (RenderDoc::Inst().GetCaptureOptions().CaptureCallstacks ? 1 : 0); + case eRENDERDOC_Option_CaptureCallstacksOnlyDraws: + return (RenderDoc::Inst().GetCaptureOptions().CaptureCallstacksOnlyDraws ? 1 : 0); + case eRENDERDOC_Option_DelayForDebugger: + return (RenderDoc::Inst().GetCaptureOptions().DelayForDebugger); + case eRENDERDOC_Option_VerifyMapWrites: + return (RenderDoc::Inst().GetCaptureOptions().VerifyMapWrites ? 1 : 0); + case eRENDERDOC_Option_HookIntoChildren: + return (RenderDoc::Inst().GetCaptureOptions().HookIntoChildren ? 1 : 0); + case eRENDERDOC_Option_RefAllResources: + return (RenderDoc::Inst().GetCaptureOptions().RefAllResources ? 1 : 0); + case eRENDERDOC_Option_SaveAllInitials: + return (RenderDoc::Inst().GetCaptureOptions().SaveAllInitials ? 1 : 0); + case eRENDERDOC_Option_CaptureAllCmdLists: + return (RenderDoc::Inst().GetCaptureOptions().CaptureAllCmdLists ? 1 : 0); + case eRENDERDOC_Option_DebugOutputMute: + return (RenderDoc::Inst().GetCaptureOptions().DebugOutputMute ? 1 : 0); + default: break; + } + + RDCLOG("Unrecognised capture option '%d'", opt); + return 0xffffffff; +} + +float RENDERDOC_CC GetCaptureOptionF32(RENDERDOC_CaptureOption opt) +{ + switch(opt) + { + case eRENDERDOC_Option_AllowVSync: + return (RenderDoc::Inst().GetCaptureOptions().AllowVSync ? 1.0f : 0.0f); + case eRENDERDOC_Option_AllowFullscreen: + return (RenderDoc::Inst().GetCaptureOptions().AllowFullscreen ? 1.0f : 0.0f); + case eRENDERDOC_Option_DebugDeviceMode: + return (RenderDoc::Inst().GetCaptureOptions().DebugDeviceMode ? 1.0f : 0.0f); + case eRENDERDOC_Option_CaptureCallstacks: + return (RenderDoc::Inst().GetCaptureOptions().CaptureCallstacks ? 1.0f : 0.0f); + case eRENDERDOC_Option_CaptureCallstacksOnlyDraws: + return (RenderDoc::Inst().GetCaptureOptions().CaptureCallstacksOnlyDraws ? 1.0f : 0.0f); + case eRENDERDOC_Option_DelayForDebugger: + return (RenderDoc::Inst().GetCaptureOptions().DelayForDebugger * 1.0f); + case eRENDERDOC_Option_VerifyMapWrites: + return (RenderDoc::Inst().GetCaptureOptions().VerifyMapWrites ? 1.0f : 0.0f); + case eRENDERDOC_Option_HookIntoChildren: + return (RenderDoc::Inst().GetCaptureOptions().HookIntoChildren ? 1.0f : 0.0f); + case eRENDERDOC_Option_RefAllResources: + return (RenderDoc::Inst().GetCaptureOptions().RefAllResources ? 1.0f : 0.0f); + case eRENDERDOC_Option_SaveAllInitials: + return (RenderDoc::Inst().GetCaptureOptions().SaveAllInitials ? 1.0f : 0.0f); + case eRENDERDOC_Option_CaptureAllCmdLists: + return (RenderDoc::Inst().GetCaptureOptions().CaptureAllCmdLists ? 1.0f : 0.0f); + case eRENDERDOC_Option_DebugOutputMute: + return (RenderDoc::Inst().GetCaptureOptions().DebugOutputMute ? 1.0f : 0.0f); + default: break; + } + + RDCLOG("Unrecognised capture option '%d'", opt); + return -FLT_MAX; +} + +CaptureOptions::CaptureOptions() +{ + AllowVSync = true; + AllowFullscreen = true; + DebugDeviceMode = false; + CaptureCallstacks = false; + CaptureCallstacksOnlyDraws = false; + DelayForDebugger = 0; + VerifyMapWrites = false; + HookIntoChildren = false; + RefAllResources = false; + SaveAllInitials = false; + CaptureAllCmdLists = false; + DebugOutputMute = true; +} diff --git a/renderdoc/replay/entry_points.cpp b/renderdoc/replay/entry_points.cpp index bc236b6da..1700dfb9e 100644 --- a/renderdoc/replay/entry_points.cpp +++ b/renderdoc/replay/entry_points.cpp @@ -27,10 +27,11 @@ #include "maths/formatpacking.h" #include "serialise/serialiser.h" #include "core/core.h" -#include "hooks/hooks.h" #include "replay/replay_renderer.h" #include "api/replay/renderdoc_replay.h" +// these entry points are for the replay/analysis side - not for the application. + extern "C" RENDERDOC_API uint32_t RENDERDOC_CC Topology_NumVerticesPerPrimitive(PrimitiveTopology topology) { // strips/loops/fans have the same number of indices for a single primitive @@ -233,19 +234,6 @@ extern "C" RENDERDOC_API void RENDERDOC_CC Camera_GetBasis(Camera *c, FloatVecto up->z = u.z; } -extern "C" RENDERDOC_API -int RENDERDOC_CC RENDERDOC_GetAPIVersion() -{ - return RENDERDOC_API_VERSION; -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_Shutdown() -{ - RenderDoc::Inst().Shutdown(); - LibraryHooks::GetInstance().RemoveHooks(); -} - extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogText(const char *text) { @@ -258,37 +246,6 @@ const char* RENDERDOC_CC RENDERDOC_GetLogFile() return RDCGETLOGFILE(); } -extern "C" RENDERDOC_API -uint32_t RENDERDOC_CC RENDERDOC_GetNumCaptures() -{ - return (uint32_t)RenderDoc::Inst().GetCaptures().size(); -} - -extern "C" RENDERDOC_API -bool32 RENDERDOC_CC RENDERDOC_GetCapture(uint32_t idx, char *logfile, uint32_t *pathlength, uint64_t *timestamp) -{ - vector caps = RenderDoc::Inst().GetCaptures(); - - if(idx >= (uint32_t)caps.size()) - { - if(logfile) logfile[0] = 0; - if(pathlength) *pathlength = 0; - if(timestamp) *timestamp = 0; - return false; - } - - CaptureData &c = caps[idx]; - - if(logfile) - memcpy(logfile, c.path.c_str(), sizeof(char)*(c.path.size()+1)); - if(pathlength) - *pathlength = uint32_t(c.path.size()+1); - if(timestamp) - *timestamp = c.timestamp; - - return true; -} - extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_TriggerExceptionHandler(void *exceptionPtrs, bool32 crashed) { @@ -315,12 +272,6 @@ void RENDERDOC_CC RENDERDOC_TriggerExceptionHandler(void *exceptionPtrs, bool32 } } -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_UnloadCrashHandler() -{ - RenderDoc::Inst().UnloadCrashHandler(); -} - extern "C" RENDERDOC_API bool32 RENDERDOC_CC RENDERDOC_SupportLocalReplay(const char *logfile, rdctype::str *driver) { @@ -366,20 +317,6 @@ ReplayCreateStatus RENDERDOC_CC RENDERDOC_CreateReplayRenderer(const char *logfi return eReplayCreate_Success; } -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_SetLogFile(const char *logfile) -{ - RDCLOG("Using logfile %s", logfile); - RenderDoc::Inst().SetLogFile(logfile); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_SetCaptureOptions(const CaptureOptions *opts) -{ - RDCLOG("Setting capture options"); - RenderDoc::Inst().SetCaptureOptions(opts); -} - extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, const char *logfile, const CaptureOptions *opts, bool32 waitForExit) @@ -387,6 +324,12 @@ uint32_t RENDERDOC_CC RENDERDOC_ExecuteAndInject(const char *app, const char *wo return Process::LaunchAndInjectIntoProcess(app, workingDir, cmdLine, logfile, opts, waitForExit != 0); } +extern "C" RENDERDOC_API +void RENDERDOC_CC RENDERDOC_GetDefaultCaptureOptions(CaptureOptions *opts) +{ + *opts = CaptureOptions(); +} + extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartGlobalHook(const char *pathmatch, const char *logfile, const CaptureOptions *opts) { @@ -399,60 +342,6 @@ uint32_t RENDERDOC_CC RENDERDOC_InjectIntoProcess(uint32_t pid, const char *logf return Process::InjectIntoProcess(pid, logfile, opts, waitForExit != 0); } -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_SetActiveWindow(void *device, void *wndHandle) -{ - RenderDoc::Inst().SetActiveWindow(device, wndHandle); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_TriggerCapture() -{ - RenderDoc::Inst().TriggerCapture(); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_StartFrameCapture(void *device, void *wndHandle) -{ - RenderDoc::Inst().StartFrameCapture(device, wndHandle); -} - -extern "C" RENDERDOC_API -bool32 RENDERDOC_CC RENDERDOC_EndFrameCapture(void *device, void *wndHandle) -{ - return RenderDoc::Inst().EndFrameCapture(device, wndHandle); -} - -extern "C" RENDERDOC_API -uint32_t RENDERDOC_CC RENDERDOC_GetOverlayBits() -{ - return RenderDoc::Inst().GetOverlayBits(); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_MaskOverlayBits(uint32_t And, uint32_t Or) -{ - RenderDoc::Inst().MaskOverlayBits(And, Or); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_SetFocusToggleKeys(KeyButton *keys, int num) -{ - RenderDoc::Inst().SetFocusKeys(keys, num); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_SetCaptureKeys(KeyButton *keys, int num) -{ - RenderDoc::Inst().SetCaptureKeys(keys, num); -} - -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_QueueCapture(uint32_t frameNumber) -{ - RenderDoc::Inst().QueueCapture(frameNumber); -} - extern "C" RENDERDOC_API bool32 RENDERDOC_CC RENDERDOC_GetThumbnail(const char *filename, byte *buf, uint32_t &len) { @@ -517,33 +406,6 @@ void *RENDERDOC_CC RENDERDOC_AllocArrayMem(uint64_t sz) return rdctype::array::allocate((size_t)sz); } -extern "C" RENDERDOC_API -void RENDERDOC_CC RENDERDOC_InitRemoteAccess(uint32_t *ident) -{ - if(ident) *ident = RenderDoc::Inst().GetRemoteAccessIdent(); -} - -extern "C" RENDERDOC_API -uint32_t RENDERDOC_CC RENDERDOC_IsRemoteAccessConnected() -{ - return RenderDoc::Inst().IsRemoteAccessConnected(); -} - -extern "C" RENDERDOC_API -uint32_t RENDERDOC_CC RENDERDOC_LaunchReplayUI(uint32_t connectRemoteAccess, const char *cmdline) -{ - string replayapp = FileIO::GetReplayAppFilename(); - - if(replayapp.empty()) - return 0; - - string cmd = cmdline ? cmdline : ""; - if(connectRemoteAccess) - cmd += StringFormat::Fmt(" --remoteaccess localhost:%u", RenderDoc::Inst().GetRemoteAccessIdent()); - - return Process::LaunchProcess(replayapp.c_str(), "", cmd.c_str()); -} - extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteConnections(const char *host, uint32_t *idents) { diff --git a/renderdocui/Interop/CaptureOptions.cs b/renderdocui/Interop/CaptureOptions.cs index 692e6be98..75e3927ea 100644 --- a/renderdocui/Interop/CaptureOptions.cs +++ b/renderdocui/Interop/CaptureOptions.cs @@ -78,25 +78,6 @@ namespace renderdoc public bool RefAllResources; public bool SaveAllInitials; public bool CaptureAllCmdLists; - - public static CaptureOptions Defaults - { - get - { - CaptureOptions defs = new CaptureOptions(); - defs.AllowVSync = true; - defs.AllowFullscreen = true; - defs.DebugDeviceMode = false; - defs.CaptureCallstacks = false; - defs.CaptureCallstacksOnlyDraws = false; - defs.DelayForDebugger = 0; - defs.VerifyMapWrites = false; - defs.HookIntoChildren = false; - defs.RefAllResources = false; - defs.SaveAllInitials = false; - defs.CaptureAllCmdLists = false; - return defs; - } - } + public bool DebugOutputMute; }; }; diff --git a/renderdocui/Interop/StaticExports.cs b/renderdocui/Interop/StaticExports.cs index 4bcb0a445..50e6cc265 100644 --- a/renderdocui/Interop/StaticExports.cs +++ b/renderdocui/Interop/StaticExports.cs @@ -55,6 +55,9 @@ namespace renderdoc [DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern ReplayCreateStatus RENDERDOC_CreateRemoteReplayConnection(IntPtr host, ref IntPtr outrend); + [DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + private static extern void RENDERDOC_GetDefaultCaptureOptions(IntPtr outopts); + [DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] private static extern void RENDERDOC_SpawnReplayHost(ref bool killReplay); @@ -255,5 +258,18 @@ namespace renderdoc return ret; } + + public static CaptureOptions GetDefaultCaptureOptions() + { + IntPtr mem = CustomMarshal.Alloc(typeof(CaptureOptions)); + + RENDERDOC_GetDefaultCaptureOptions(mem); + + CaptureOptions ret = (CaptureOptions)CustomMarshal.PtrToStructure(mem, typeof(CaptureOptions), true); + + CustomMarshal.Free(mem); + + return ret; + } } } diff --git a/renderdocui/Windows/Dialogs/CaptureDialog.cs b/renderdocui/Windows/Dialogs/CaptureDialog.cs index 7a811c7e5..5c61f8b70 100644 --- a/renderdocui/Windows/Dialogs/CaptureDialog.cs +++ b/renderdocui/Windows/Dialogs/CaptureDialog.cs @@ -46,7 +46,7 @@ namespace renderdocui.Windows.Dialogs { public class CaptureSettings { - public CaptureOptions Options = CaptureOptions.Defaults; + public CaptureOptions Options = StaticExports.GetDefaultCaptureOptions(); public bool Inject = false; public bool AutoStart = false; public string Executable = "";