Files
TheRock/third-party/sysdeps/linux/amd-mesa/mesa-fork/docs/spirv/index.rst
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

74 lines
3.0 KiB
ReStructuredText

SPIR-V Debugging
================
SPIR-V is a binary shader intermediate representation used extensively by
Vulkan applications. Mesa translates SPIR-V shaders into its internal NIR
representation using the `spirv_to_nir` function.
.. _spirv_capture:
SPIR-V Shader Capture
~~~~~~~~~~~~~~~~~~~~~
Set the environment variable `MESA_SPIRV_DUMP_PATH` to a directory where
the SPIR-V shaders will be captured. This is useful for debugging purposes,
allowing developers to inspect the SPIR-V shaders provided by applications.
Shader capture filenames are a hexadecimal representation of the shader's
BLAKE3 hash. The file extension corresponds to the shader stage, e.g.
`.vert` for vertex shaders or `.frag` for fragment shaders.
It is usually necessary to disable the shader cache to activate the dump logic.
This can be done by setting the `MESA_SHADER_CACHE_DISABLE` environment variable to `1`.
.. code-block:: sh
MESA_SPIRV_DUMP_PATH=$(pwd) MESA_SHADER_CACHE_DISABLE=1 vkcube
.. _spirv_replacement:
SPIR-V Shader Replacement
~~~~~~~~~~~~~~~~~~~~~~~~~
SPIR-V shaders can be replaced with alternative SPIR-V shaders
during runtime. This is useful for debugging or testing purposes, allowing
developers to swap out shaders without modifying the application.
To enable shader replacement, set the environment variable
`MESA_SPIRV_READ_PATH` to the directory containing the replacement SPIR-V shaders.
The filenames of the replacement shaders must match the original shader's BLAKE3
hash and the extensions must match the original shader stages (e.g., `.vert`, `.frag`).
It is usually necessary to disable the shader cache to ensure that
the replacement shaders are used. This can be done by setting the
`MESA_SHADER_CACHE_DISABLE` environment variable to `1`.
When a shader is replaced, Mesa will log the replacement action, including
the original shader's BLAKE3 hash and the filename of the replacement shader.
Set `MESA_SPIRV_LOG_LEVEL=info` to see these log messages printed to `stderr`.
.. code-block:: sh
MESA_SPIRV_READ_PATH=$(pwd)/replace MESA_SPIRV_LOG_LEVEL=info MESA_SHADER_CACHE_DISABLE=1 vkcube
To replace a shader with a modified version of a captured shader, you can
convert the captured SPIR-V shader to GLSL, edit as needed, and then
recompile it back to SPIR-V.
.. code-block:: sh
# Capture a SPIR-V shader
MESA_SPIRV_DUMP_PATH=$(pwd) MESA_SHADER_CACHE_DISABLE=1 vkcube
# Convert a captured SPIR-V shader to Vulkan-flavored GLSL
# spriv-cross is bundled with the Vulkan SDK and also generally available via package managers
spirv-cross -V 0x36c56e0f736238.frag --output 0x36c56e0f736238.frag.glsl
# <Edit the GLSL file as needed>
# Recompile the GLSL shader to SPIR-V
# Some shaders may require additional flags, such as "--auto-map-locations"
glslang -V 0x36c56e0f736238.frag.glsl -o replace/0x36c56e0f736238.frag
# run the application with the replacement shader
MESA_SPIRV_READ_PATH=$(pwd)/replace MESA_SPIRV_LOG_LEVEL=info MESA_SHADER_CACHE_DISABLE=1 vkcube