|
| 1 | +=============== |
| 2 | +Root Signatures |
| 3 | +=============== |
| 4 | + |
| 5 | +.. contents:: |
| 6 | + :local: |
| 7 | + |
| 8 | +.. toctree:: |
| 9 | + :hidden: |
| 10 | + |
| 11 | +Overview |
| 12 | +======== |
| 13 | + |
| 14 | +A root signature is used to describe what resources a shader needs to access to |
| 15 | +and how they're organized and bound in the pipeline. The DirectX Container |
| 16 | +(DXContainer) contains a root signature part (RTS0), which stores this |
| 17 | +information in a binary format. To assist with the construction of, and |
| 18 | +interaction with, a root signature is represented as metadata |
| 19 | +(``dx.rootsignatures`` ) in the LLVM IR. The metadata can then be converted to |
| 20 | +its binary form, as defined in |
| 21 | +`llvm/include/llvm/llvm/Frontend/HLSL/RootSignatureMetadata.h |
| 22 | +<https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h>`_. |
| 23 | +This document serves as a reference for the metadata representation of a root |
| 24 | +signature for users to interface with. |
| 25 | + |
| 26 | +Metadata Representation |
| 27 | +======================= |
| 28 | + |
| 29 | +Consider the reference root signature, then the following sections describe the |
| 30 | +metadata representation of this root signature and the corresponding operands. |
| 31 | + |
| 32 | +.. code-block:: C |
| 33 | +
|
| 34 | + #define DemoRootSignature \ |
| 35 | + "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT)," \ |
| 36 | + "RootConstants(b0, space = 1, num32Constants = 3)," \ |
| 37 | + "CBV(b1, flags = 0)," \ |
| 38 | + "StaticSampler(" \ |
| 39 | + " filter = FILTER_MIN_MAG_POINT_MIP_LINEAR," \ |
| 40 | + " addressU = TEXTURE_ADDRESS_BORDER," \ |
| 41 | + ")," \ |
| 42 | + "DescriptorTable(" \ |
| 43 | + " visibility = VISIBILITY_ALL," \ |
| 44 | + " SRV(t0, flags = DATA_STATIC_WHILE_SET_AT_EXECUTE)," \ |
| 45 | + " UAV(" \ |
| 46 | + " numDescriptors = 5, u1, space = 10, offset = 5," \ |
| 47 | + " flags = DATA_VOLATILE" \ |
| 48 | + " )" \ |
| 49 | + ")" |
| 50 | +
|
| 51 | +.. note:: |
| 52 | + |
| 53 | + A root signature does not necessarily have a unique metadata representation. |
| 54 | + Futher, a malformed root signature can be represented in the metadata format, |
| 55 | + (eg. mixing Sampler and non-Sampler descriptor ranges), and so it is the |
| 56 | + user's responsibility to verify that it is a well-formed root signature. |
| 57 | + |
| 58 | +Named Root Signature Table |
| 59 | +========================== |
| 60 | + |
| 61 | +.. code-block:: LLVM |
| 62 | +
|
| 63 | + !dx.rootsignatures = !{!0} |
| 64 | +
|
| 65 | +A named metadata node, ``dx.rootsignatures``` is used to identify the root |
| 66 | +signature table. The table itself is a list of references to function/root |
| 67 | +signature pairs. |
| 68 | + |
| 69 | +Function/Root Signature Pair |
| 70 | +============================ |
| 71 | + |
| 72 | +.. code-block:: LLVM |
| 73 | +
|
| 74 | + !1 = !{ptr @main, !2, i32 2 } |
| 75 | +
|
| 76 | +The function/root signature associates a function (the first operand) with a |
| 77 | +reference to a root signature (the second operand). The root signature version |
| 78 | +(the third operand) used for validation logic and binary format follows. |
| 79 | + |
| 80 | +Root Signature |
| 81 | +============== |
| 82 | + |
| 83 | +.. code-block:: LLVM |
| 84 | +
|
| 85 | + !2 = !{ !3, !4, !5, !6, !7 } |
| 86 | +
|
| 87 | +The root signature itself simply consists of a list of references to its root |
| 88 | +signature elements. |
| 89 | + |
| 90 | +Root Signature Element |
| 91 | +====================== |
| 92 | + |
| 93 | +A root signature element is identified by the first operand, which is a string. |
| 94 | +The following root signature elements are defined: |
| 95 | + |
| 96 | +.. csv-table:: |
| 97 | + |
| 98 | + Identifier String, Root Signature Element |
| 99 | + |
| 100 | + \"RootFlags\", Root Flags |
| 101 | + \"RootConstants\", Root Constants |
| 102 | + \"RootCBV\", Root Descriptor |
| 103 | + \"RootSRV\", Root Descriptor |
| 104 | + \"RootUAV\", Root Descriptor |
| 105 | + \"StaticSampler\", Static Sampler |
| 106 | + \"DescriptorTable\", Descriptor Table |
| 107 | + |
| 108 | +Below is listed the representation for each type of root signature element. |
| 109 | + |
| 110 | +Root Flags |
| 111 | +========== |
| 112 | + |
| 113 | +.. code-block:: LLVM |
| 114 | +
|
| 115 | + !3 = { !"RootFlags", i32 1 } |
| 116 | +
|
| 117 | +.. csv-table:: |
| 118 | + |
| 119 | + Description, Type |
| 120 | + |
| 121 | + `Root Signature Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_root_signature_flags>`_, i32 |
| 122 | + |
| 123 | + |
| 124 | +Root Constants |
| 125 | +============== |
| 126 | + |
| 127 | +.. code-block:: LLVM |
| 128 | +
|
| 129 | + !4 = { !"RootConstants", i32 0, i32 1, i32 2, i32 3 } |
| 130 | +
|
| 131 | +.. csv-table:: |
| 132 | + |
| 133 | + Description, Type |
| 134 | + |
| 135 | + `Shader Visibility <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_shader_visibility>`_, i32 |
| 136 | + Shader Register, i32 |
| 137 | + Register Space, i32 |
| 138 | + Number 32-bit Values, i32 |
| 139 | + |
| 140 | +Root Descriptor |
| 141 | +=============== |
| 142 | + |
| 143 | +As noted in the table above, the first operand will denote the type of |
| 144 | +root descriptor. |
| 145 | + |
| 146 | +.. code-block:: LLVM |
| 147 | +
|
| 148 | + !5 = { !"RootCBV", i32 0, i32 1, i32 0, i32 0 } |
| 149 | +
|
| 150 | +.. csv-table:: |
| 151 | + |
| 152 | + Description, Type |
| 153 | + |
| 154 | + `Shader Visibility`_, i32 |
| 155 | + Shader Register, i32 |
| 156 | + Register Space, i32 |
| 157 | + `Root Descriptor Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_root_descriptor_flags>`_, i32 |
| 158 | + |
| 159 | +Static Sampler |
| 160 | +============== |
| 161 | + |
| 162 | +.. code-block:: LLVM |
| 163 | +
|
| 164 | + !6 = !{ !"StaticSampler", i32 1, i32 4, ... }; remaining operands omitted for space |
| 165 | +
|
| 166 | +.. csv-table:: |
| 167 | + |
| 168 | + Description, Type |
| 169 | + |
| 170 | + `Filter <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter>`_, i32 |
| 171 | + `AddressU <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 |
| 172 | + `AddressV <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 |
| 173 | + `AddressW <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_, i32 |
| 174 | + MipLODBias, float |
| 175 | + MaxAnisotropy, i32 |
| 176 | + `ComparisonFunc <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_comparison_func>`_, i32 |
| 177 | + `BorderColor <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_static_border_color>`_, i32 |
| 178 | + MinLOD, float |
| 179 | + MaxLOD, float |
| 180 | + ShaderRegister, i32 |
| 181 | + RegisterSpace, i32 |
| 182 | + `Shader Visibility`_, i32 |
| 183 | + |
| 184 | +Descriptor Table |
| 185 | +================ |
| 186 | + |
| 187 | +A descriptor table consists of a visibility and the remaining operands are a |
| 188 | +list of references to its descriptor ranges. |
| 189 | + |
| 190 | +.. note:: |
| 191 | + |
| 192 | + The term Descriptor Table Clause is synonymous with Descriptor Range when |
| 193 | + referencing the implementation details. |
| 194 | + |
| 195 | +.. code-block:: LLVM |
| 196 | +
|
| 197 | + !7 = { !"DescriptorTable", i32 0, !8, !9 } |
| 198 | +
|
| 199 | +.. csv-table:: |
| 200 | + |
| 201 | + Description, Type |
| 202 | + |
| 203 | + `Shader Visibility`_, i32 |
| 204 | + Descriptor Range Elements, Descriptor Range |
| 205 | + |
| 206 | + |
| 207 | +Descriptor Range |
| 208 | +================ |
| 209 | + |
| 210 | +Similar to a root descriptor, the first operand will denote the type of |
| 211 | +descriptor range. It is one of the following types: |
| 212 | + |
| 213 | +- "CBV" |
| 214 | +- "SRV" |
| 215 | +- "UAV" |
| 216 | +- "Sampler" |
| 217 | + |
| 218 | +.. code-block:: LLVM |
| 219 | +
|
| 220 | + !8 = !{ !"SRV", i32 1, i32 0, i32 0, i32 -1, i32 4 } |
| 221 | + !9 = !{ !"UAV", i32 5, i32 1, i32 10, i32 5, i32 2 } |
| 222 | +
|
| 223 | +.. csv-table:: |
| 224 | + |
| 225 | + Description, Type |
| 226 | + |
| 227 | + Number of Descriptors in Range, i32 |
| 228 | + Shader Register, i32 |
| 229 | + Register Space, i32 |
| 230 | + `Offset <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_descriptor_range>`_, i32 |
| 231 | + `Descriptor Range Flags <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_descriptor_range_flags>`_, i32 |
0 commit comments