Using Radeon™ GPU Analyzer v2.4.1 with DirectX® Raytracing

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on email

Introduction

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 ( -s dxr ).

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.

Requirements

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.

A good example for how the DXR state subobjects can be defined in HLSL can found in Raytracing.hlsl  in the D3D12RaytracingLibrarySubobjects sample:

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 MyClosestHitShader which is defined in Raytracing.hlsl  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:

  • --hlsl points to the source file where the shader and subobjects are defined. Note that your code may include any number of header files (use the -I option to add additional include directories to the search path).
  • --export  specifies the name of the target shader.
  • --isa points 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 --export  option.

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:

  • Added --mode pipeline  to force a pipeline compilation (instead of shader compilation which is assumed by default).
  • Removed the --export  option, since in pipeline mode the tool compiles all pipelines.

When running a command with --mode pipeline , 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.

Unified compilation

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 _unified suffix:

This will allow us to identify the specific pipeline that we are looking for in case that multiple pipelines are generated.

Indirect compilation

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.  

Conclusion

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 ( -a ), performing live VGPR analysis ( --livereg ) and generating a control-flow graph ( --cfg ).

For more information about RGA’s DXR mode, run rga -s dxr -h .

Acknowledgements

Code samples used herein are from Microsoft®’s DirectX Graphics Samples and are © Microsoft 2015 and subject to the MIT License.

 

Related content

RGA

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.

Amit Ben-Moshe
Amit Ben-Moshe is a Technical Lead and a Principal Member of Technical Staff at AMD. His postings are his own opinions and may not represent AMD’s positions, strategies or opinions. Links to third party sites are provided for convenience and unless explicitly stated, AMD is not responsible for the contents of such linked sites and no endorsement is implied.

You may also like...

Some light reading to take away with you. Our ISAs, manuals, whitepapers, and many more.

Explore our huge collection of detailed tutorials, sample code, presentations, and documentation to find your answers to your graphics development questions.

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

Browse all our fantastic tutorials, including programming techniques, performance improvements, guest blogs, and how to use our tools.