-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[Docs][DirectX] Add relevant documentation of Root Signature #149608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c51346
[Docs][DirectX] Add documentation of root signature metadata represen…
inbelic 42e6657
add to doc tree
inbelic 0c419be
correct doc tree
inbelic f20706c
review: fix typo
inbelic e82b737
review: update demo root signature
inbelic 71d84ca
review: use simply tables and out of line links
inbelic 8fa5896
fix code formatting
inbelic c3e5b5b
whoops missed one
inbelic 70df567
remove lingering csv-table
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
=============== | ||
Root Signatures | ||
=============== | ||
|
||
.. contents:: | ||
:local: | ||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
Overview | ||
======== | ||
|
||
A root signature is used to describe what resources a shader needs to access to | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and how they're organized and bound in the pipeline. The DirectX Container | ||
(DXContainer) contains a root signature part (RTS0), which stores this | ||
information in a binary format. To assist with the construction of, and | ||
interaction with, a root signature is represented as metadata | ||
(``dx.rootsignatures`` ) in the LLVM IR. The metadata can then be converted to | ||
its binary form, as defined in | ||
`llvm/include/llvm/llvm/Frontend/HLSL/RootSignatureMetadata.h | ||
<https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h>`_. | ||
This document serves as a reference for the metadata representation of a root | ||
signature for users to interface with. | ||
|
||
Metadata Representation | ||
======================= | ||
|
||
Consider the reference root signature, then the following sections describe the | ||
metadata representation of this root signature and the corresponding operands. | ||
|
||
.. code-block:: C | ||
|
||
#define DemoRootSignature \ | ||
"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT)," \ | ||
"RootConstants(b0, space = 1, num32Constants = 3)," \ | ||
"CBV(b1, flags = 0)," \ | ||
"StaticSampler(" \ | ||
" filter = FILTER_MIN_MAG_POINT_MIP_LINEAR," \ | ||
" addressU = TEXTURE_ADDRESS_BORDER," \ | ||
")," \ | ||
"DescriptorTable(" \ | ||
" visibility = VISIBILITY_ALL," \ | ||
" SRV(t0, flags = DATA_STATIC_WHILE_SET_AT_EXECUTE)," \ | ||
" UAV(" \ | ||
" numDescriptors = 5, u1, space = 10, offset = 5," \ | ||
" flags = DATA_VOLATILE" \ | ||
" )" \ | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
")" | ||
|
||
.. note:: | ||
|
||
A root signature does not necessarily have a unique metadata representation. | ||
Futher, a malformed root signature can be represented in the metadata format, | ||
(eg. mixing Sampler and non-Sampler descriptor ranges), and so it is the | ||
user's responsibility to verify that it is a well-formed root signature. | ||
|
||
Named Root Signature Table | ||
========================== | ||
|
||
.. code-block:: LLVM | ||
|
||
!dx.rootsignatures = !{!0} | ||
|
||
A named metadata node, ``dx.rootsignatures``` is used to identify the root | ||
signature table. The table itself is a list of references to function/root | ||
signature pairs. | ||
|
||
Function/Root Signature Pair | ||
============================ | ||
|
||
.. code-block:: LLVM | ||
|
||
!1 = !{ptr @main, !2, i32 2 } | ||
|
||
The function/root signature associates a function (the first operand) with a | ||
reference to a root signature (the second operand). The root signature version | ||
(the third operand) used for validation logic and binary format follows. | ||
|
||
Root Signature | ||
============== | ||
|
||
.. code-block:: LLVM | ||
|
||
!2 = !{ !3, !4, !5, !6, !7 } | ||
|
||
The root signature itself simply consists of a list of references to its root | ||
signature elements. | ||
|
||
Root Signature Element | ||
====================== | ||
|
||
A root signature element is identified by the first operand, which is a string. | ||
The following root signature elements are defined: | ||
|
||
.. csv-table:: | ||
|
||
Identifier String, Root Signature Element | ||
|
||
\"RootFlags\", Root Flags | ||
\"RootConstants\", Root Constants | ||
\"RootCBV\", Root Descriptor | ||
\"RootSRV\", Root Descriptor | ||
\"RootUAV\", Root Descriptor | ||
\"StaticSampler\", Static Sampler | ||
\"DescriptorTable\", Descriptor Table | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Below is listed the representation for each type of root signature element. | ||
|
||
Root Flags | ||
========== | ||
|
||
.. code-block:: LLVM | ||
|
||
!3 = { !"RootFlags", i32 1 } | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
`Root Signature Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_root_signature_flags>`_, i32 | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
Root Constants | ||
============== | ||
|
||
.. code-block:: LLVM | ||
|
||
!4 = { !"RootConstants", i32 0, i32 1, i32 2, i32 3 } | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
`Shader Visibility <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_shader_visibility>`_, i32 | ||
Shader Register, i32 | ||
Register Space, i32 | ||
Number 32-bit Values, i32 | ||
|
||
Root Descriptor | ||
=============== | ||
|
||
As noted in the table above, the first operand will denote the type of | ||
root descriptor. | ||
|
||
.. code-block:: LLVM | ||
|
||
!5 = { !"RootCBV", i32 0, i32 1, i32 0, i32 0 } | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
`Shader Visibility`_, i32 | ||
Shader Register, i32 | ||
Register Space, i32 | ||
`Root Descriptor Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_root_descriptor_flags>`_, i32 | ||
|
||
Static Sampler | ||
============== | ||
|
||
.. code-block:: LLVM | ||
|
||
!6 = !{ !"StaticSampler", i32 1, i32 4, ... }; remaining operands omitted for space | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
`Filter <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter>`_, i32 | ||
`AddressU <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 | ||
`AddressV <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 | ||
`AddressW <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 | ||
MipLODBias, float | ||
MaxAnisotropy, i32 | ||
`ComparisonFunc <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_comparison_func>`_, i32 | ||
`BorderColor <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_static_border_color>`_, i32 | ||
MinLOD, float | ||
MaxLOD, float | ||
ShaderRegister, i32 | ||
RegisterSpace, i32 | ||
`Shader Visibility`_, i32 | ||
|
||
Descriptor Table | ||
================ | ||
|
||
A descriptor table consists of a visibility and the remaining operands are a | ||
list of references to its descriptor ranges. | ||
|
||
.. note:: | ||
|
||
The term Descriptor Table Clause is synonymous with Descriptor Range when | ||
referencing the implementation details. | ||
|
||
.. code-block:: LLVM | ||
|
||
!7 = { !"DescriptorTable", i32 0, !8, !9 } | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
`Shader Visibility`_, i32 | ||
Descriptor Range Elements, Descriptor Range | ||
|
||
|
||
Descriptor Range | ||
================ | ||
|
||
Similar to a root descriptor, the first operand will denote the type of | ||
descriptor range. It is one of the following types: | ||
|
||
- "CBV" | ||
- "SRV" | ||
- "UAV" | ||
- "Sampler" | ||
|
||
.. code-block:: LLVM | ||
|
||
!8 = !{ !"SRV", i32 1, i32 0, i32 0, i32 -1, i32 4 } | ||
!9 = !{ !"UAV", i32 5, i32 1, i32 10, i32 5, i32 2 } | ||
|
||
.. csv-table:: | ||
|
||
Description, Type | ||
|
||
Number of Descriptors in Range, i32 | ||
Shader Register, i32 | ||
Register Space, i32 | ||
`Offset <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_descriptor_range>`_, i32 | ||
`Descriptor Range Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_descriptor_range_flags>`_, i32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.