|
1 | 1 | Capturing a Graphics Frame with RenderDoc |
2 | 2 | ========================================= |
3 | 3 |
|
4 | | -TODO |
| 4 | +.. image:: ../_static/image/renderdoc.webp |
| 5 | + :alt: A screenshot of RenderDoc inspecting a capture from Mupen64Plus-Next running in libretro.py. |
| 6 | + :align: center |
| 7 | + |
| 8 | +RenderDoc_ is a frame debugger that provides detailed information about |
| 9 | +the API calls and pipeline state that produced a frame. |
| 10 | +It supports all major graphics APIs, |
| 11 | +and can be used in any application that creates a window. |
| 12 | +This guide walks you through using RenderDoc to capture a frame from a libretro core |
| 13 | +running in libretro.py. |
| 14 | + |
| 15 | +.. important:: |
| 16 | + |
| 17 | + This is *not* a tutorial for using RenderDoc; |
| 18 | + this guide assumes that you're proficient enough |
| 19 | + to analyze a capture after you've taken it. |
| 20 | + See the `official docs <https://renderdoc.org/docs>`_ for more guidance. |
| 21 | + |
| 22 | +In this guide we'll use `Mupen64Plus-Next <https://docs.libretro.com/library/mupen64plus>`_ to demonstrate, |
| 23 | +though any core will work. |
| 24 | + |
| 25 | +Getting Started |
| 26 | +--------------- |
| 27 | + |
| 28 | +We'll use the provided ``libretro.py.test.runs`` script to run the core. |
| 29 | +Make sure that you've installed the ``cli`` extra when you installed libretro.py. |
| 30 | +This script is a simple way to run a core for fixed length of time. |
| 31 | + |
| 32 | +.. admonition:: Prefer to use a custom script? |
| 33 | + |
| 34 | + You can use RenderDoc to capture a frame |
| 35 | + even if you're using a custom test script. |
| 36 | + However, the process of configuring |
| 37 | + your core's content, system files, and options |
| 38 | + may be different. |
| 39 | + |
| 40 | +Once you install RenderDoc, |
| 41 | +open up the `Launch Application tab <https://renderdoc.org/docs/window/capture_attach.html>`_ |
| 42 | +and configure it like so: |
| 43 | + |
| 44 | +:guilabel:`Executable Path` |
| 45 | + Select the Python executable you're using to run libretro.py. |
| 46 | + If you're using a virtual environment, |
| 47 | + see `Using a Virtual Environment`_ for more information. |
| 48 | + |
| 49 | +:guilabel:`Working Directory` |
| 50 | + You can leave this as-is |
| 51 | + unless your core or custom test script |
| 52 | + expects a specific working directory. |
| 53 | + |
| 54 | +:guilabel:`Command-line Arguments` |
| 55 | + Enter the following: :samp:`-m libretro.py.test.runs {path-to-core} {path-to-content} -Omupen64plus-rdp-plugin=gliden64 -n600 --window` |
| 56 | + |
| 57 | + Let's break this down: |
| 58 | + |
| 59 | + :samp:`-m libretro.py.test.runs` |
| 60 | + Using Python's ``-m`` flag will run the given module as a script, |
| 61 | + in this case the ``libretro.py.test.runs`` module |
| 62 | + included with libretro.py. |
| 63 | + |
| 64 | + :samp:`{path-to-core}` |
| 65 | + Replace this with the path to the core you're using. |
| 66 | + For the purpose of this guide, we're using Mupen64Plus-Next; |
| 67 | + on my machine, that's :file:`D:/SteamLibrary/steamapps/common/RetroArch/cores/mupen64plus_next_libretro.dll`. |
| 68 | + |
| 69 | + .. important:: |
| 70 | + |
| 71 | + This needs to be a full path, *not* a short name like RetroArch uses |
| 72 | + (i.e. passing an argument of :file:`mupen64plus_next` will not work |
| 73 | + unless that's literally the name of a core in the current working directory). |
| 74 | + |
| 75 | + :samp:`{path-to-content}` |
| 76 | + Replace this with the path to the content you're running. |
| 77 | + For this guide, I'm using a ROM located at :file:`D:/ROMs/N64/Super Mario 64 (U) [!].z64`. |
| 78 | + |
| 79 | + .. tip:: |
| 80 | + |
| 81 | + If you're using a core that supports running without content, |
| 82 | + you can leave this out. |
| 83 | + If you're using a subsystem, |
| 84 | + you'll need to include the subsystem name |
| 85 | + with the ``-s`` flag, |
| 86 | + plus additional content files after the main one if necessary. |
| 87 | + |
| 88 | + :samp:`-Omupen64plus-rdp-plugin=gliden64` |
| 89 | + The ``-O`` flag defines an option that will be passed to the core. |
| 90 | + It can be given as many times as you like, |
| 91 | + with each value given as :samp:`-O{name}={value}`. |
| 92 | + In this case we're telling Mupen64Plus-Next to use the GlideN64 renderer; |
| 93 | + we want to use this particular renderer because it uses OpenGL, |
| 94 | + which is the only graphics API that libretro.py supports at the moment. |
| 95 | + |
| 96 | + :samp:`-n600` |
| 97 | + The ``-n`` flag tells ``libretro.py`` to run the core for a fixed number of frames. |
| 98 | + In this case, we're running for 600 frames (about 10 seconds). |
| 99 | + |
| 100 | + :samp:`--window` |
| 101 | + This flag tells ``libretro.py`` to create a window for the core to render to. |
| 102 | + This is necessary for RenderDoc to capture the frame. |
| 103 | + |
| 104 | + Run ``python -m libretro.py.test.runs --help`` for more details about available flags. |
| 105 | + |
| 106 | +**Environment Variables** |
| 107 | + You can leave this blank |
| 108 | + unless your core or custom script |
| 109 | + expects specific environment variables. |
| 110 | + |
| 111 | + If you're using a virtual environment, |
| 112 | + see `Using a Virtual Environment`_ for more information. |
| 113 | + |
| 114 | +Taking a Capture |
| 115 | +---------------- |
| 116 | + |
| 117 | +Now that we've got our capture settings for RenderDoc in place, |
| 118 | +we can run the core and take a capture. |
| 119 | +You'll want to save your capture settings to avoid having to retype them later, |
| 120 | +but make sure not to commit them to your Git repo. |
| 121 | + |
| 122 | +You can either take a capture with the :kbd:`F12` key |
| 123 | +or queue up one or more captures to be taken automatically. |
| 124 | + |
| 125 | +.. hint:: Why not use RetroArch for capturing frames instead? |
| 126 | + |
| 127 | + You absolutely can! |
| 128 | + However, frontends intended for gameplay tend to allocate their own graphics resources |
| 129 | + for features like UI overlays or shader effects. |
| 130 | + You may find these to be a distraction when trying to debug your core. |
| 131 | + libretro.py only allocates the resources needed to support GPU-rendered cores. |
| 132 | + |
| 133 | +Using a Virtual Environment |
| 134 | +--------------------------- |
| 135 | + |
| 136 | +Using libretro.py through a virtual environment to capture frames is supported, |
| 137 | +but may require a few extra steps depending on your platform. |
| 138 | +The following recommendations come from my own experience |
| 139 | +using RenderDoc and libretro.py on Windows. |
| 140 | + |
| 141 | +First, you may need to set the :guilabel:`Executable Path` to the Python executable |
| 142 | +from which your virtual environment is derived, |
| 143 | +**not** the executable in the virtual environment itself. |
| 144 | +On Windows, this is actually a thin launcher for the system Python installation |
| 145 | +with some environment variables set to point to the virtual environment. |
| 146 | + |
| 147 | +Second, you may need to adjust the :guilabel:`Environment Variables` |
| 148 | +to set :samp:`PYTHONPATH` to include the path to the virtual environment's site-packages directory. |
| 149 | +If you're using a local copy of libretro.py (e.g. when contributing or fixing a bug), |
| 150 | +you may also need to include the path to the directory containing libretro.py itself. |
| 151 | + |
| 152 | +.. image:: ../_static/image/renderdoc-settings.webp |
| 153 | + :alt: A screenshot of RenderDoc's Launch Applications tab with the settings described in this guide. |
| 154 | + :align: center |
| 155 | + |
| 156 | + |
| 157 | +.. _RenderDoc: https://renderdoc.org |
| 158 | + |
| 159 | + |
0 commit comments