Skip to content
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

[Doc][HLSL] Add documentation for root signature #88781

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

python3kgae
Copy link
Contributor

This patch adds documentation for the root signature in HLSL.

For issue #55116

This patch adds documentation for the root signature in HLSL.

For issue llvm#55116
@llvmbot llvmbot added clang Clang issues not falling into any other category HLSL HLSL Language Support labels Apr 15, 2024
@python3kgae python3kgae removed the clang Clang issues not falling into any other category label Apr 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 15, 2024

@llvm/pr-subscribers-clang

Author: Xiang Li (python3kgae)

Changes

This patch adds documentation for the root signature in HLSL.

For issue #55116


Full diff: https://github.com/llvm/llvm-project/pull/88781.diff

1 Files Affected:

  • (added) clang/docs/HLSL/RootSignature.rst (+291)
diff --git a/clang/docs/HLSL/RootSignature.rst b/clang/docs/HLSL/RootSignature.rst
new file mode 100644
index 00000000000000..259e93463f59bf
--- /dev/null
+++ b/clang/docs/HLSL/RootSignature.rst
@@ -0,0 +1,291 @@
+====================
+HLSL Root Signatures
+====================
+
+.. contents::
+   :local:
+
+Usage
+=====
+
+In HLSL, the `root signature
+<https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures>`_
+defines what types of resources are bound to the graphics pipeline.
+
+A root signature can be specified in HLSL as a `string
+<https://learn.microsoft.com/en-us/windows/win32/direct3d12/specifying-root-signatures-in-hlsl#an-example-hlsl-root-signature>`_.
+The string contains a collection of comma-separated clauses that describe root
+signature constituent components.
+
+There are two mechanisms to compile an HLSL root signature. First, it is
+possible to attach a root signature string to a particular shader via the
+RootSignature attribute (in the following example, using the main entry
+point):
+
+.. code-block::
+
+    #define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \
+              "DENY_VERTEX_SHADER_ROOT_ACCESS), " \
+              "CBV(b0, space = 1, flags = DATA_STATIC), " \
+              "SRV(t0), " \
+              "UAV(u0), " \
+              "DescriptorTable( CBV(b1), " \
+              "                 SRV(t1, numDescriptors = 8, " \
+              "                     flags = DESCRIPTORS_VOLATILE), " \
+              "                 UAV(u1, numDescriptors = unbounded, " \
+              "                     flags = DESCRIPTORS_VOLATILE)), " \
+              "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \
+              "RootConstants(num32BitConstants=3, b10), " \
+              "StaticSampler(s1)," \
+              "StaticSampler(s2, " \
+              "              addressU = TEXTURE_ADDRESS_CLAMP, " \
+              "              filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+    [RootSignature(MyRS)]
+    float4 main(float4 coord : COORD) : SV_Target
+    {
+
+    }
+
+The compiler will create and verify the root signature blob for the shader and
+embed it alongside the shader byte code into the shader blob.
+
+The other mechanism is to create a standalone root signature blob, perhaps to
+reuse it with a large set of shaders, saving space. The name of the define
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command
+line, e.g, -D MyRS1=”…”.
+
+Root signature could also used in form of StateObject like this:
+
+.. code-block::
+
+  GlobalRootSignature MyGlobalRootSignature =
+  {
+      "DescriptorTable(UAV(u0)),"                     // Output texture
+      "SRV(t0),"                                      // Acceleration structure
+      "CBV(b0),"                                      // Scene constants
+      "DescriptorTable(SRV(t1, numDescriptors = 2))"  // Static index and vertex buffers.
+  };
+
+  LocalRootSignature MyLocalRootSignature =
+  {
+      "RootConstants(num32BitConstants = 4, b1)"  // Cube constants
+  };
+
+
+Root Signature Grammar
+======================
+
+.. code-block:: peg
+
+    RootSignature : (RootElement(,RootElement)?)?
+
+    RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+                  DescriptorTable | StaticSampler
+
+    RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+    RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' |
+               'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+    RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ','
+           bReg (',' 'space' '=' NUMBER)?
+           (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    DTClause : CBV | SRV | UAV | Sampler
+
+    CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)?
+    (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' NUMBER)? ')'
+
+
+    SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' |
+                        'SHADER_VISIBILITY_HULL' |
+                        'SHADER_VISIBILITY_DOMAIN' |
+                        'SHADER_VISIBILITY_GEOMETRY' |
+                        'SHADER_VISIBILITY_PIXEL' |
+                        'SHADER_VISIBILITY_AMPLIFICATION' |
+                        'SHADER_VISIBILITY_MESH'
+
+    DATA_FLAGS : 'DATA_STATIC_WHILE_SET_AT_EXECUTE' | 'DATA_VOLATILE'
+
+    DESCRIPTOR_RANGE_OFFSET : 'DESCRIPTOR_RANGE_OFFSET_APPEND' | NUMBER
+
+    StaticSampler : 'StaticSampler' '(' sReg (',' 'filter' '=' FILTER)?
+             (',' 'addressU' '=' TEXTURE_ADDRESS)?
+             (',' 'addressV' '=' TEXTURE_ADDRESS)?
+             (',' 'addressW' '=' TEXTURE_ADDRESS)?
+             (',' 'mipLODBias' '=' NUMBER)?
+             (',' 'maxAnisotropy' '=' NUMBER)?
+             (',' 'comparisonFunc' '=' COMPARISON_FUNC)?
+             (',' 'borderColor' '=' STATIC_BORDER_COLOR)?
+             (',' 'minLOD' '=' NUMBER)?
+             (',' 'maxLOD' '=' NUMBER)? (',' 'space' '=' NUMBER)?
+             (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    bReg : 'b' NUMBER
+
+    tReg : 't' NUMBER
+
+    uReg : 'u' NUMBER
+
+    sReg : 's' NUMBER
+
+    FILTER : 'FILTER_MIN_MAG_MIP_POINT' |
+             'FILTER_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MIN_MAG_MIP_LINEAR' |
+             'FILTER_ANISOTROPIC' |
+             'FILTER_COMPARISON_MIN_MAG_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_MAG_MIP_LINEAR' |
+             'FILTER_COMPARISON_ANISOTROPIC' |
+             'FILTER_MINIMUM_MIN_MAG_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_MAG_MIP_LINEAR' |
+             'FILTER_MINIMUM_ANISOTROPIC' |
+             'FILTER_MAXIMUM_MIN_MAG_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR' |
+             'FILTER_MAXIMUM_ANISOTROPIC'
+
+    TEXTURE_ADDRESS : 'TEXTURE_ADDRESS_WRAP' |
+                      'TEXTURE_ADDRESS_MIRROR' | 'TEXTURE_ADDRESS_CLAMP' |
+                      'TEXTURE_ADDRESS_BORDER' | 'TEXTURE_ADDRESS_MIRROR_ONCE'
+
+    COMPARISON_FUNC : 'COMPARISON_NEVER' | 'COMPARISON_LESS' |
+                      'COMPARISON_EQUAL' | 'COMPARISON_LESS_EQUAL' |
+                      'COMPARISON_GREATER' | 'COMPARISON_NOT_EQUAL' |
+                      'COMPARISON_GREATER_EQUAL' | 'COMPARISON_ALWAYS'
+
+    STATIC_BORDER_COLOR : 'STATIC_BORDER_COLOR_TRANSPARENT_BLACK' |
+                          'STATIC_BORDER_COLOR_OPAQUE_BLACK' |
+                          'STATIC_BORDER_COLOR_OPAQUE_WHITE'
+
+GlobalRootSignature
+===================
+
+A GlobalRootSignature corresponds to a D3D12_GLOBAL_ROOT_SIGNATURE structure.
+
+The fields consist of some number of strings describing the parts of the root signature.
+The string should follow Root Signature Grammar.
+
+.. code-block::
+
+  GlobalRootSignature MyGlobalRootSignature =
+  {
+      "DescriptorTable(UAV(u0)),"                     // Output texture
+      "SRV(t0),"                                      // Acceleration structure
+      "CBV(b0),"                                      // Scene constants
+      "DescriptorTable(SRV(t1, numDescriptors = 2))"  // Static index and vertex buffers
+  };
+
+
+LocalRootSignature
+==================
+
+A LocalRootSignature corresponds to a D3D12_LOCAL_ROOT_SIGNATURE structure.
+
+Just like the global root signature subobject, the fields consist of some
+number of strings describing the parts of the root signature.
+The string should follow Root Signature Grammar.
+
+.. code-block::
+
+  LocalRootSignature MyLocalRootSignature =
+  {
+      "RootConstants(num32BitConstants = 4, b1)"  // Cube constants
+  };
+
+
+SubobjectToExportsAssociation
+=============================
+
+By default, a subobject merely declared in the same library as an export is
+able to apply to that export.
+However, applications have the ability to override that and get specific about
+what subobject goes with which export. In HLSL, this "explicit association" is
+done using SubobjectToExportsAssociation.
+
+A SubobjectToExportsAssociation corresponds to a
+D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION structure.
+
+This subobject is declared with the syntax
+.. code-block::
+
+  SubobjectToExportsAssociation Name =
+  {
+      SubobjectName,
+      Exports
+  };
+
+The local/global root siganture in above example could be used like this:
+
+.. code-block::
+
+  SubobjectToExportsAssociation MyLocalRootSignatureAssociation =
+  {
+      "MyLocalRootSignature",    // Subobject name
+      "MyHitGroup;MyMissShader"  // Exports association
+  };
+  SubobjectToExportsAssociation MyGlobalRootSignatureAssociation =
+  {
+      "MyGlobalRootSignature",    // Subobject name
+      "MyHitGroup;MyMissShader"  // Exports association
+  };
+

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 15, 2024

@llvm/pr-subscribers-hlsl

Author: Xiang Li (python3kgae)

Changes

This patch adds documentation for the root signature in HLSL.

For issue #55116


Full diff: https://github.com/llvm/llvm-project/pull/88781.diff

1 Files Affected:

  • (added) clang/docs/HLSL/RootSignature.rst (+291)
diff --git a/clang/docs/HLSL/RootSignature.rst b/clang/docs/HLSL/RootSignature.rst
new file mode 100644
index 00000000000000..259e93463f59bf
--- /dev/null
+++ b/clang/docs/HLSL/RootSignature.rst
@@ -0,0 +1,291 @@
+====================
+HLSL Root Signatures
+====================
+
+.. contents::
+   :local:
+
+Usage
+=====
+
+In HLSL, the `root signature
+<https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures>`_
+defines what types of resources are bound to the graphics pipeline.
+
+A root signature can be specified in HLSL as a `string
+<https://learn.microsoft.com/en-us/windows/win32/direct3d12/specifying-root-signatures-in-hlsl#an-example-hlsl-root-signature>`_.
+The string contains a collection of comma-separated clauses that describe root
+signature constituent components.
+
+There are two mechanisms to compile an HLSL root signature. First, it is
+possible to attach a root signature string to a particular shader via the
+RootSignature attribute (in the following example, using the main entry
+point):
+
+.. code-block::
+
+    #define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \
+              "DENY_VERTEX_SHADER_ROOT_ACCESS), " \
+              "CBV(b0, space = 1, flags = DATA_STATIC), " \
+              "SRV(t0), " \
+              "UAV(u0), " \
+              "DescriptorTable( CBV(b1), " \
+              "                 SRV(t1, numDescriptors = 8, " \
+              "                     flags = DESCRIPTORS_VOLATILE), " \
+              "                 UAV(u1, numDescriptors = unbounded, " \
+              "                     flags = DESCRIPTORS_VOLATILE)), " \
+              "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \
+              "RootConstants(num32BitConstants=3, b10), " \
+              "StaticSampler(s1)," \
+              "StaticSampler(s2, " \
+              "              addressU = TEXTURE_ADDRESS_CLAMP, " \
+              "              filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+    [RootSignature(MyRS)]
+    float4 main(float4 coord : COORD) : SV_Target
+    {
+
+    }
+
+The compiler will create and verify the root signature blob for the shader and
+embed it alongside the shader byte code into the shader blob.
+
+The other mechanism is to create a standalone root signature blob, perhaps to
+reuse it with a large set of shaders, saving space. The name of the define
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command
+line, e.g, -D MyRS1=”…”.
+
+Root signature could also used in form of StateObject like this:
+
+.. code-block::
+
+  GlobalRootSignature MyGlobalRootSignature =
+  {
+      "DescriptorTable(UAV(u0)),"                     // Output texture
+      "SRV(t0),"                                      // Acceleration structure
+      "CBV(b0),"                                      // Scene constants
+      "DescriptorTable(SRV(t1, numDescriptors = 2))"  // Static index and vertex buffers.
+  };
+
+  LocalRootSignature MyLocalRootSignature =
+  {
+      "RootConstants(num32BitConstants = 4, b1)"  // Cube constants
+  };
+
+
+Root Signature Grammar
+======================
+
+.. code-block:: peg
+
+    RootSignature : (RootElement(,RootElement)?)?
+
+    RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+                  DescriptorTable | StaticSampler
+
+    RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+    RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' |
+               'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+    RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ','
+           bReg (',' 'space' '=' NUMBER)?
+           (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)?
+          (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    DTClause : CBV | SRV | UAV | Sampler
+
+    CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)?
+    (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)?
+          (',' 'flags' '=' DATA_FLAGS)? ')'
+
+    Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)?
+          (',' 'space' '=' NUMBER)?
+          (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' NUMBER)? ')'
+
+
+    SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' |
+                        'SHADER_VISIBILITY_HULL' |
+                        'SHADER_VISIBILITY_DOMAIN' |
+                        'SHADER_VISIBILITY_GEOMETRY' |
+                        'SHADER_VISIBILITY_PIXEL' |
+                        'SHADER_VISIBILITY_AMPLIFICATION' |
+                        'SHADER_VISIBILITY_MESH'
+
+    DATA_FLAGS : 'DATA_STATIC_WHILE_SET_AT_EXECUTE' | 'DATA_VOLATILE'
+
+    DESCRIPTOR_RANGE_OFFSET : 'DESCRIPTOR_RANGE_OFFSET_APPEND' | NUMBER
+
+    StaticSampler : 'StaticSampler' '(' sReg (',' 'filter' '=' FILTER)?
+             (',' 'addressU' '=' TEXTURE_ADDRESS)?
+             (',' 'addressV' '=' TEXTURE_ADDRESS)?
+             (',' 'addressW' '=' TEXTURE_ADDRESS)?
+             (',' 'mipLODBias' '=' NUMBER)?
+             (',' 'maxAnisotropy' '=' NUMBER)?
+             (',' 'comparisonFunc' '=' COMPARISON_FUNC)?
+             (',' 'borderColor' '=' STATIC_BORDER_COLOR)?
+             (',' 'minLOD' '=' NUMBER)?
+             (',' 'maxLOD' '=' NUMBER)? (',' 'space' '=' NUMBER)?
+             (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+    bReg : 'b' NUMBER
+
+    tReg : 't' NUMBER
+
+    uReg : 'u' NUMBER
+
+    sReg : 's' NUMBER
+
+    FILTER : 'FILTER_MIN_MAG_MIP_POINT' |
+             'FILTER_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MIN_MAG_MIP_LINEAR' |
+             'FILTER_ANISOTROPIC' |
+             'FILTER_COMPARISON_MIN_MAG_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_COMPARISON_MIN_MAG_MIP_LINEAR' |
+             'FILTER_COMPARISON_ANISOTROPIC' |
+             'FILTER_MINIMUM_MIN_MAG_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MINIMUM_MIN_MAG_MIP_LINEAR' |
+             'FILTER_MINIMUM_ANISOTROPIC' |
+             'FILTER_MAXIMUM_MIN_MAG_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR' |
+             'FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT' |
+             'FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR' |
+             'FILTER_MAXIMUM_ANISOTROPIC'
+
+    TEXTURE_ADDRESS : 'TEXTURE_ADDRESS_WRAP' |
+                      'TEXTURE_ADDRESS_MIRROR' | 'TEXTURE_ADDRESS_CLAMP' |
+                      'TEXTURE_ADDRESS_BORDER' | 'TEXTURE_ADDRESS_MIRROR_ONCE'
+
+    COMPARISON_FUNC : 'COMPARISON_NEVER' | 'COMPARISON_LESS' |
+                      'COMPARISON_EQUAL' | 'COMPARISON_LESS_EQUAL' |
+                      'COMPARISON_GREATER' | 'COMPARISON_NOT_EQUAL' |
+                      'COMPARISON_GREATER_EQUAL' | 'COMPARISON_ALWAYS'
+
+    STATIC_BORDER_COLOR : 'STATIC_BORDER_COLOR_TRANSPARENT_BLACK' |
+                          'STATIC_BORDER_COLOR_OPAQUE_BLACK' |
+                          'STATIC_BORDER_COLOR_OPAQUE_WHITE'
+
+GlobalRootSignature
+===================
+
+A GlobalRootSignature corresponds to a D3D12_GLOBAL_ROOT_SIGNATURE structure.
+
+The fields consist of some number of strings describing the parts of the root signature.
+The string should follow Root Signature Grammar.
+
+.. code-block::
+
+  GlobalRootSignature MyGlobalRootSignature =
+  {
+      "DescriptorTable(UAV(u0)),"                     // Output texture
+      "SRV(t0),"                                      // Acceleration structure
+      "CBV(b0),"                                      // Scene constants
+      "DescriptorTable(SRV(t1, numDescriptors = 2))"  // Static index and vertex buffers
+  };
+
+
+LocalRootSignature
+==================
+
+A LocalRootSignature corresponds to a D3D12_LOCAL_ROOT_SIGNATURE structure.
+
+Just like the global root signature subobject, the fields consist of some
+number of strings describing the parts of the root signature.
+The string should follow Root Signature Grammar.
+
+.. code-block::
+
+  LocalRootSignature MyLocalRootSignature =
+  {
+      "RootConstants(num32BitConstants = 4, b1)"  // Cube constants
+  };
+
+
+SubobjectToExportsAssociation
+=============================
+
+By default, a subobject merely declared in the same library as an export is
+able to apply to that export.
+However, applications have the ability to override that and get specific about
+what subobject goes with which export. In HLSL, this "explicit association" is
+done using SubobjectToExportsAssociation.
+
+A SubobjectToExportsAssociation corresponds to a
+D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION structure.
+
+This subobject is declared with the syntax
+.. code-block::
+
+  SubobjectToExportsAssociation Name =
+  {
+      SubobjectName,
+      Exports
+  };
+
+The local/global root siganture in above example could be used like this:
+
+.. code-block::
+
+  SubobjectToExportsAssociation MyLocalRootSignatureAssociation =
+  {
+      "MyLocalRootSignature",    // Subobject name
+      "MyHitGroup;MyMissShader"  // Exports association
+  };
+  SubobjectToExportsAssociation MyGlobalRootSignatureAssociation =
+  {
+      "MyGlobalRootSignature",    // Subobject name
+      "MyHitGroup;MyMissShader"  // Exports association
+  };
+

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 15, 2024
'STATIC_BORDER_COLOR_OPAQUE_BLACK' |
'STATIC_BORDER_COLOR_OPAQUE_WHITE'

GlobalRootSignature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organizationally I'm not sure that having it go:

  • "normal" root signature
  • grammar
  • global root signature
  • local root signature
  • subobject etc..

Is the best we could do here. I wonder if the grammar could come at the end to explain what goes into the various places where a root signature string goes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved grammar to the end.

}

The compiler will create and verify the root signature blob for the shader and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it'd be helpful to show the runtime side of this? Just by reading this, I think it's hard to understand what a root signature is, why I'd need to specify one, and what I'd do with one once I'd specified it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we link the D3D runtime doc https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures ?
That should have all the things about root signature.

}

The compiler will create and verify the root signature blob for the shader and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and verify ...

What sort of verifications does it do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register ranges do not overlap.
Used resource in the shader has bindings in root signature.
No mix of sampler and other resources (CBV,SRV,UAV) in one descriptor table
...


A GlobalRootSignature corresponds to a D3D12_GLOBAL_ROOT_SIGNATURE structure.

The fields consist of some number of strings describing the parts of the root signature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really multiple strings? It looks like it is just one long string to me, using the concatenation rule for adjacent string literals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not.
It will be one long string in AST.

done using SubobjectToExportsAssociation.

A SubobjectToExportsAssociation corresponds to a
D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION structure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a developer specify one of these? Say, below, there's MyLocalRootSIgnatureAssociation. What is done with that? Does the compiler look at it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 259 to 260
By default, a subobject merely declared in the same library as an export is
able to apply to that export.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what "subobject merely declared in the same library as an export is able to apply to that export" means.

Are subobjects always root signatures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Subobjects could be things other than root signature.
Like


RaytracingPipelineConfig1 rpc = { 32, RAYTRACING_PIPELINE_FLAG_SKIP_TRIANGLES };
SubobjectToExportsAssociation sea4 = {"rpc", ";"};

Copy link
Contributor

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comments.

python3kgae and others added 2 commits April 15, 2024 22:43
Co-authored-by: Damyan Pepper <damyanp@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

3 participants