Skip to content

Debugging XWA

Marcos Orallo edited this page Jul 10, 2023 · 7 revisions

Built-in logs

Command Arguments: skipintro deusdbg 2 ffffffff

The deusdbg command line parameter enables the native logging from X-Wing Alliance.

Meaning of the first parameter:

  • 1 means OutputDebugString and file (deusdbg.txt)
  • 2 means OutputDebugString
  • 3 means file (deusdbg.txt)
Meaning of the second parameter (click to expand)
It's a mask. You can combine one or more of the Following values:
- 0 means None
- 1 means Sfx
- 2 means FFeedback
- 4 means Music
- 8 means MusicMem
- 10 means MusicIMuse
- 20 means HudText
- 80 means SfxFlush
- 100 means MusicStates
- 200 means EscapePods
- 400 means Backdrops
- 800 means LargeDebris
- 1000 means DamagePhysics
- 4000 means Voices
- 8000 means Stars
- 10000 means D3dText
- 20000 means Network
- 40000 means GlobalLight
- 80000 means Parser
- ffffffff means All

Reference:

https://www.xwaupgrade.com/phpBB3/viewtopic.php?t=10516

In-flight statistics

The game executable includes functions to display framerate, number of vertices, triangles, texture changes, state changes, video memory usage in the HUD. However these functions can only be enabled by patching the .EXE.

XwaExePatcher includes patches to enable that.

image

ddraw.dll and hooks OutputDebugString() messages

By default ddraw will output messages with OutputDebugString() with the prefix [DBG].

Some of the hooks may also output debug information through this channel.

You can also enable native XWA debug messages as indicated in the Built-in logs section above.

They can be viewed in the debugging Output window of Visual Studio or with DebugView

Hook_diag

JeremyaFr created a hook to display relevant information in-game, both in the Concourse and InFlight: https://github.com/JeremyAnsel/xwa_hooks/blob/master/xwa_hook_diag/zip/readme.txt

It includes CPU and RAM usage, mission loading time measurements.

image

It needs to be enabled in Hooks.ini

[hook_diag]
; ShowDiagMessages = 0 (no) or 1 (yes)`
ShowDiagMessages = 1

Here is the reference for the different loading steps:

  • step 0 is start.
  • step 1 is mission file loading, global buffers initializing, and hangar sounds loading.
  • step 2 is tactical officers and wingmen sounds loading.
  • step 3 is 3d initializing, and OPTs loading.
  • step 4 is dat images loading
  • step 5 is ResData_LightingEffects initializing
  • step 6 is nothing
  • step 7 is backdrops initializing, and HUD initializing
  • step 8 is starships debris initializing

Frame analysis with Intel Graphics Performance Analyzer

There are several tools that allow to capture the process of rendering a frame, by hooking the graphics API:

In my tests, neither RenderDoc nor NVIDIA Nsight Graphics are able to run X-Wing Alliance properly. With Intel GPA it's possible to capture a frame and re-play the rendering process in individual draw call steps.

  1. Download and Install Intel GPA
  2. Run Graphics Monitor and configure XwingAlliance.exe in the Desktop Applications tab. Select Frame in the capture drop-down. image
  3. Start the game by clicking on the Start light blue icon.
  4. Capture a frame with Ctrl+Shift+C
  5. In Graphics Monitor, you will have a new thumbnail of the frame capture appear on the right hand side. Double-click it. This will open Intel Graphics Frame Analyzer.

In Graphics Frame Analyzer, you will have a timeline of the frame, with each draw call represented by a bar/rectangle. with height and width proportional to the time spent by the GPU on it. This can give you a quick idea of the most expensive GPU operations.

Also, it's possible to display the results of each step of the rendering process by selecting the draw call on the left column. This can be very useful to debug graphical errors as it displays the inputs (constant buffers, shader resource views, geometry...), the render state and decompiled shaders, and the outputs (render target views, depth stencil view).

image

DirectX Debug Layer

To troubleshoot DirectX errors that don't generate a crash dump, it can be useful to enable the Direct3D Debug Layer. This will provide debug messages with details on why a certain D3D API call is failing.

Installation

Graphical interface

Follow this tutorial: https://www.tenforums.com/tutorials/7565-manage-optional-features-windows-10-a.html

  1. Windows Menu > Settings > Apps & Features > Optional Features > Add a Feature
  2. You need to enable the Graphics Tools feature (it may have a different name in your language, like "Herramientas de gráficos" in Spanish).

Command line

From this blog

  1. Open an elevated command-line prompt (right click over the Command Line menu entry, choose Run as Administrator)
  2. Enter the following command: DISM /online /add-capability /capabilityname:Tools.Graphics.DirectX~~~~0.0.1.0

Enable the debug layer for XWA

Graphical interface (DXCpl)

  1. Run DirectX Control Panel a. From Visual Studio (Debug > Graphics > DirectX Control Panel) b. Run the DXCpl.exe command
  2. Add xwingalliance.exe application in the Scope section
  3. Enable the Direct3D/DXGI Debug Layer
  4. Mute the Warning messages, as we are mostly interested in errors
  5. Apply

NOTE: Direct3D debug layer will have some impact on the performance. Make sure you disable it after your troubleshooting!!!

image

If the game exits to desktop without generating the error that you expect, you may need to disable the Break on functionality in the Break Settingstab:

image

d3dconfig command-line tool

https://devblogs.microsoft.com/directx/d3dconfig-a-new-tool-to-manage-directx-control-panel-settings/

How to check the output

Now, every time you run the game, Direct3D will generate debug messages as configured with DXCpl or d3dconfig. The most powerful way to use the debug layer messages is by debugging the game with Visual Studio. This way, whenever there is an error message the game execution will pause and you will have access to the call stack, the values of the parameters etc.

However, you don't need a development environment to monitor the output of the debug layer. You can see the messages with DebugView.

Run DebugView and filter for the process ID of X-Wing Alliance (17412 in the example below). Alternatively, look for lines starting with D3D11

[17412] D3D11: DeviceChild reference counter underflow.  Release should not be called on objects with zero reference count.
[17412] Exception 0x0000087D at 76A8D8A2 in KERNELBASE
[17412] A crash dump has been generated at G:\juegos\XWA\XwingAlliance_20230702_183019448_KERNELBASE.dmp
[17412] D3D11: DeviceChild reference counter underflow.  Release should not be called on objects with zero reference count.

References

Crash dumps

In case of crash, hook_main will create a minidump in the XWA folder, that you can open with your tool of choice (for example Visual Studio) to understand the state of execution that led to the crash.

The files will be named something similar to this XwingAlliance_20230509_234528324_DDRAW.dmp

OpenXR

Command Arguments: skipintro 1>openxr_log.txt 2>&1

Environment = XR_LOADER_DEBUG=all; XR_RUNTIME_JSON=F:\Oculus\Support\oculus-runtime\oculus_openxr_32.json $(LocalDebuggerEnvironment)