Radeon™ GPU Analyzer (RGA) is our offline compiler and code analysis tool for DirectX®, Vulkan®, SPIR-V™, OpenGL®, and OpenCL™. RGA 2.4.1 introduces support for DXR shaders in a new mode of the command line tool (
You can use the new mode to compile HLSL DXR source code and generate RDNA™ 2 ISA disassembly, HW resource usage statistics, and perform static analysis on the generated disassembly. As always, RGA allows you to do that even without having the physical target GPU installed on your system. Therefore, you can analyze your DXR shaders for DXR-enabled GPUs, like the Radeon RX 6900 XT, even without having the card physically installed.
How to use RGA for DXR
RGA 2.4.1 for DXR requires all state subobjects to be defined in the HLSL code. To demonstrate how to use RGA for DXR, we will use the D3D12Raytracing sample from Microsoft®’s DirectX Graphics Samples. Specifically, we will use the D3D12RaytracingLibrarySubobjects sample, which defines the state subobjects in HLSL code.
For more information about HLSL for DXR, visit the HLSL section of the DXR Functional Spec by Microsoft®.
Compiling a DXR shader
Once you have the HLSL code correctly defining the state subobjects, compiling a DXR shader with RGA 2.4.1 is straightforward. The following command would compile and generate RDNA ISA disassembly for
which is defined in
in the D3D12RaytracingLibrarySubobjects sample:
rga -s dxr --hlsl C:\Shaders\Raytracing.hlsl --export MyClosestHitShader --isa C:\Output\isa.txt
Let’s break down the command:
--hlslpoints to the source file where the shader and subobjects are defined. Note that your code may include any number of header files (use the
-Ioption to add additional include directories to the search path).
--exportspecifies the name of the target shader.
--isapoints to the full path of the output text file where the disassembly would be stored.
After running this command, the disassembly file will be generated in the output path:
You can compile any other shader in the file by adjusting the argument to the
Note that we did not have to specify gfx1030 as the target GPU, RGA automatically selects an RDNA GPU in DXR mode if no target device is specified. Also, gfx1030 is the minimum target GPU for RGA’S DXR mode, since it is the first AMD GPU that comes with ray tracing hardware support.
Compiling DXR pipelines
Before demonstrating how to compile DXR pipelines, let’s get ourselves familiarized with the two modes of pipeline compilation that can be used by the AMD driver.
When a DXR app creates a DXR pipeline State Object (by calling CreateStateObject() with D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE as the type), AMD’s driver creates what we will refer to as “Raytracing Pipelines”.
AMD’s driver may compile each raytracing pipeline in two different modes:
- Unified: shaders are inlined into a single uber shader.
- Indirect: shaders are compiled into separate functions and are being invoked.
The compilation mode is decided by the driver at runtime, and is not controlled by RGA. The decision on how to compile the pipeline is being made based on certain conditions such as the existence of recursion in the code and the number of functions in the State Object.
It is important to note that the driver keeps track of the different raytracing pipelines through their raytracing shader’s export name. You can think of it as a map of pipelines, where the raygeneration shader is the key in the map:
Let’s go back to the the D3D12RaytracingLibrarySubobjects sample. The following command would compile the pipeline that is associated with raygeneration shader MyRaygenShader which is defined in Raytracing.hlsl, and generate RDNA disassembly for all of the pipeline’s shaders:
rga -s dxr --mode pipeline --hlsl C:\Shaders\Raytracing.hlsl --isa C:\Output\isa.txt
As you can see, the command is identical to the one we use to compile a specific shader, with two changes:
--mode pipelineto force a pipeline compilation (instead of shader compilation which is assumed by default).
- Removed the
--exportoption, since in pipeline mode the tool compiles all pipelines.
When running a command with
, the output will tell you whether the driver compiled the pipeline in Unified or Indirect mode and how many shaders you should expect in the output.
Remember that the tool has no control on the compilation mode – it is decided in runtime by the driver.
This is how the output would look like if the driver compiled the pipeline in Unified mode, which means that all pipeline shaders were inlined into a single uber shader:
As you can see, the output informs us that:
- A single pipeline was generated (the tool gives you the export name of the raygeneration shader which is associated with that pipeline).
- The pipeline was compiled in Unified mode, and we should therefore expect a single uber shader in the output.
In the output folder, we will then find a single disassembly output file named with a
This will allow us to identify the specific pipeline that we are looking for in case that multiple pipelines are generated.
Now, let’s have a look at the tool’s output in case that the driver chooses to compile the same State Object in Indirect mode:
As you can see in the above output, the tool notifies you that the single pipeline that was generated was compiled in Indirect mode, and that 4 shaders are included in the pipeline. Then, the tool extracts the output for each shader.
In the output folder, we will find 3 disassembly output files this time, one for each of the pipeline’s shaders:
Note that the output file names contain the number ‘1’ as a prefix, and then the shader name. The number designates the pipeline number for that output file (running number from 1 to N where N is the number of generated pipelines). This helps you find the relevant output file in cases where multiple pipelines are generated, since the same shader may be a part of multiple pipelines.
When a pipeline is compiled in Indirect mode, you would find an additional shader that is generated by the AMD driver, named “TraceRaysAmdInternal“. This shader is AMD driver’s implementation for the acceleration structure traversal.
In this article we learned how to use RGA 2.4.1 to compile DXR shaders and pipelines from HLSL code and generate RDNA ISA disassembly for DXR shaders. In our examples we focused on generating only RDNA disassembly, but RGA’s DXR mode supports all the output options that you are familiar with from other modes of the tool, such as extracting hardware resource usage statistics (
), performing live VGPR analysis (
) and generating a control-flow graph (
For more information about RGA’s DXR mode, run
rga -s dxr -h
Radeon GPU Analyzer is an offline compiler and performance analysis tool for DirectX®, Vulkan®, SPIR-V™, OpenGL® and OpenCL™.
Microsoft® DirectX®12 Ultimate provides APIs for creating games and other graphics applications.
Graphics feature architect Rys Sommefeldt provides a short presentation on the major advantages of the new API, and how to best utilize it on AMD RDNA™ 2-based hardware.