Skip to content

Commit 0bcfa6b

Browse files
authored
Addressing comments
1 parent b013080 commit 0bcfa6b

File tree

1 file changed

+51
-173
lines changed

1 file changed

+51
-173
lines changed

llvm/docs/DirectX/DXContainer.rst

Lines changed: 51 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -405,21 +405,22 @@ Root Signature (RTS0) Part
405405
--------------------------
406406
.. _RTS0:
407407

408-
The Root Signature defines the interface between the shader and the pipeline,
409-
specifying which resources are bound to the shader and how they are accessed.
410-
This structure serves as a contract between the application and the GPU,
411-
establishing a layout for resource binding that both the shader compiler and
412-
the runtime can understand.
413-
414-
The Root Signature consists of a header followed by an array of root parameters
415-
and an array of static samplers. The structure uses a versioned design with
416-
offset-based references to allow for flexible serialization and deserialization.
417-
One consequence of using an offset-based reference is that root parameters and
418-
static samplers don't need to follow any specific ordering logic.
408+
The Root Signature data defines the shader's resource interface with Direct3D 12,
409+
specifying what resources the shader needs to access and how they're organized
410+
and bound to the pipeline.
411+
412+
The RTS0 part comprises three data structures: ``RootSignatureHeader``,
413+
``RootParameters`` and ``StaticSamplers``. The details of each will be described
414+
in the following sections. All ``RootParameters`` will be serialized following the
415+
order they were defined in the metadata representation.
419416

420417
Root Signature Header
421418
~~~~~~~~~~~~~~~~~~~~~
422419

420+
The root signature header is 24 bytes long, consisting of six 32 bit values
421+
representing the version, number and offset of parameters, number and offset
422+
of static samplers, and a flags field for global behaviours:
423+
423424
.. code-block:: c
424425
425426
struct RootSignatureHeader {
@@ -432,215 +433,113 @@ Root Signature Header
432433
}
433434
434435
435-
The `RootSignatureHeader` structure contains the top-level information about a root signature:
436-
437-
#. **Version**: Specifies the version of the root signature format. This allows for backward
438-
compatibility as the format evolves.
439-
#. **NumParameters**: The number of root parameters contained in this root signature.
440-
#. **ParametersOffset**: Byte offset from the beginning of RST0 section to the array of root
441-
parameters header.
442-
#. **NumStaticSamplers**: The number of static samplers defined in the root signature.
443-
#. **StaticSamplerOffset**: Byte offset to the array of static samplers.
444-
#. **Flags**: Bit flags that define global behaviors for the root signature, such as whether
445-
to deny vertex shader access to certain resources.
446-
447-
This header allows readers to navigate the binary representation of the root signature by
448-
providing counts and offsets to locate each component within the serialized data.
449-
450436
Root Parameters
451437
~~~~~~~~~~~~~~~
438+
Root parameters define how resources are bound to the shader pipeline, each
439+
type having different size and fields.
452440

453-
Root signatures parameters are split into a header section containing the parameter type,
454-
shader visibility and its offset, and a data section. The parameters don't need to follow
455-
any specific order. Root parameters define the interface elements that shaders can access.
456-
Each parameter can be one of several types, including descriptor tables, constants, or
457-
descriptors for different resource types.
458-
459-
Root Parameter Header
460-
'''''''''''''''''''''
441+
Each slot of root parameters is preceded by 12 bytes, three 32 bit values,
442+
representing the parameter type, a flag encoding the pipeline stages where
443+
the data is visible, and an offset calculated from the start of RTS0 section.
461444

462445
.. code-block:: c
463446
464447
struct RootParameterHeader {
465-
dxbc::RootParameterType ParameterType;
466-
dxbc::ShaderVisibility ShaderVisibility;
448+
uint32_t ParameterType;
449+
uint32_t ShaderVisibility;
467450
uint32_t ParameterOffset;
468451
};
469452
470-
471-
Each root parameter in the signature is preceded by a `RootParameterHeader` that describes
472-
the parameter's basic attributes:
473-
474-
#. **ParameterType**: Enumeration indicating what type of parameter this is (e.g., descriptor
475-
table, constants, CBV, SRV, UAV).
476-
#. **ShaderVisibility**: Specifies which shader stages can access this parameter (e.g., all stages,
477-
vertex shader only, pixel shader only).
478-
#. **ParameterOffset**: Byte offset to the specific parameter data structure
479-
for this entry.
480-
481-
The header uses a parameter type field rather than encoding the version of the parameter through
482-
size, allowing for a more explicit representation of the parameter's nature.
483-
484-
Root Parameter Types
485-
''''''''''''''''''''
486-
This section describes the representation of each root parameter type.
453+
The following sections will describe each of the root parameters types and their encodings.
487454

488455
Root Constants
489-
^^^^^^^^^^^^^^
456+
''''''''''''''
457+
458+
Root constants are values passed directly to shaders without needing a constant
459+
buffer. It is a 12 bytes long structure, two 32 bit values encoding the register
460+
and space the constant is assigned to, and one 32 bit value encoding the constant value.
490461

491462
.. code-block:: c
492463
493464
struct RootConstants {
494-
uint32_t ShaderRegister;
495-
uint32_t RegisterSpace;
496-
uint32_t Num32BitValues;
465+
uint32_t Register;
466+
uint32_t Space;
467+
uint32_t Value;
497468
};
498469
499-
The ``RootConstants`` structure represents inline root constants that are directly embedded in the root
500-
signature and passed to the shader without requiring a constant buffer resource:
501-
502-
#. **ShaderRegister**: The shader register (b#) where these constants are bound.
503-
#. **RegisterSpace**: The register space used for the binding.
504-
#. **Num32BitValues**: The number of 32-bit values included in this constant buffer.
505-
506-
Root constants provide a fast way to pass small amounts of data directly to the shader without the
507-
overhead of creating and binding a constant buffer resource.
508-
509470
Root Descriptor
510-
^^^^^^^^^^^^^^^
471+
'''''''''''''''
511472

512-
Root descriptors provide a mechanism for binding individual resources to shader stages in the Direct3D 12
513-
rendering pipeline. They allow applications to specify how shader stages access specific GPU resources.
473+
Root descriptors provide direct GPU memory addresses to resources. Version 1.1 of
474+
root descriptor is a 12 byte long, the first two 32 bit values encode the register
475+
and space being assigned to the descriptor, and the last 32 bit value is an access flag flag.
514476

515-
.. code-block:: c
477+
Version 1.0 doesn't contain the flags available in version 1.1.
516478

517-
enum RootDescriptorFlags {
518-
None = 0,
519-
DataVolatile = 0x2,
520-
DataStaticWhileSetAtExecute = 0x4,
521-
DataStatic = 0x8,
522-
}
479+
.. code-block:: c
523480
524-
// Version 1.0 Root Descriptor
525481
struct RootDescriptor_V1_0 {
526482
uint32_t ShaderRegister;
527483
uint32_t RegisterSpace;
528484
};
529485
530-
// Version 1.1 Root Descriptor
531486
struct RootDescriptor_V1_1 {
532487
uint32_t ShaderRegister;
533488
uint32_t RegisterSpace;
534-
// Bitfield of flags from the Flags enum
535489
uint32_t Flags;
536490
};
537491
538-
Version 1.1 of Root Descriptors has introduced some flags that can hint the drivers into
539-
performing further code optimizations. For details, check
540-
`Direct X documentation <https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signature-version-1-1#static-and-volatile-flags>`_.
541-
542-
Version 1.0 Root Descriptor
543-
"""""""""""""""""""""""""""
544-
The Version 1.0 RootDescriptor_V1_0 provides basic resource binding:
545-
546-
#. **ShaderRegister**: The shader register where the descriptor is bound.
547-
#. **RegisterSpace**: The register space used for the binding.
548-
549-
Version 1.1 Root Descriptor
550-
"""""""""""""""""""""""""""
551-
The Version 1.1 RootDescriptor_V1_1 extends the base structure with the following additional fields:
552-
553-
#. **Flags**: Provides additional metadata about the descriptor's usage pattern.
554-
555492
Root Descriptor Table
556-
^^^^^^^^^^^^^^^^^^^^^
557-
Descriptor tables function as containers that hold references to descriptors in descriptor heaps.
558-
They allow multiple descriptors to be bound to the pipeline through a single root signature parameter.
559-
Tables are split in a Header and Data Section. The Header contains information that helps locate the data,
560-
which will contain a collection of descriptor ranges.
561-
562-
Root Descriptor Table Header
563-
"""""""""""""""""""""""""""""""
564-
565-
.. code-block:: c
566-
567-
struct RootDescriptorTable {
568-
uint32_t NumDescriptorRanges;
569-
uint32_t DescriptorRangesOffset;
570-
};
571-
572-
RootDescriptorTable provides basic table structure:
493+
'''''''''''''''''''''
494+
Descriptor tables let shaders access multiple resources through a single pointer to a descriptor heap.
573495

574-
#. **NumDescriptorRanges**: Number of descriptor ranges
575-
#. **DescriptorRangesOffset**: Offset to descriptor range array
496+
The tables are made of a collection of descriptor ranges. Version 1.1 ranges are 24 bytes long, containing
497+
five 32 bit values: The type of register, the number of registers in the range, the starting register number,
498+
the register space, an offset in number of descriptors from the start of the table and finally an access flag.
576499

577-
Descriptor Range Version 1.0
578-
""""""""""""""""""""""""""""
500+
Version 1.0 ranges are the 20 bytes long, following the same structure without the flags.
579501

580502
.. code-block:: c
581503
582504
struct DescriptorRange_V1_0 {
583-
dxbc::DescriptorRangeType RangeType;
505+
uint_32t RangeType;
584506
uint32_t NumDescriptors;
585507
uint32_t BaseShaderRegister;
586508
uint32_t RegisterSpace;
587509
uint32_t OffsetInDescriptorsFromTableStart;
588510
};
589511
590-
The Version 1.0 ``DescriptorRange_V1_0`` provides basic descriptor range definition:
591-
592-
#. **RangeType**: Type of descriptors (CBV, SRV, UAV, or Sampler)
593-
#. **NumDescriptors**: Number of descriptors in the range
594-
#. **BaseShaderRegister**: First shader register in the range
595-
#. **RegisterSpace**: Register space for the range
596-
#. **OffsetInDescriptorsFromTableStart**: Offset from the descriptor heap start
597-
598-
Descriptor Range Version 1.1
599-
""""""""""""""""""""""""""""
600-
601-
.. code-block:: c
602-
603512
struct DescriptorRange_V1_1 {
604513
dxbc::DescriptorRangeType RangeType;
605514
uint32_t NumDescriptors;
606515
uint32_t BaseShaderRegister;
607516
uint32_t RegisterSpace;
608-
uint32_t OffsetInDescriptorsFromTableStart;
609-
// New flags for Version 1.1
610-
enum Flags {
611-
None = 0x0,
612-
// Descriptors are static and known at root signature creation
613-
DESCRIPTORS_STATIC = 0x1,
614-
// Descriptors remain constant during command list execution
615-
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS = 0x2,
616-
// Descriptors may change frequently
617-
DESCRIPTORS_VOLATILE = 0x4
618-
};
619-
517+
uint32_t OffsetInDescriptorsFromTableStart;
620518
// Bitfield of flags from the Flags enum
621519
uint32_t Flags;
622520
};
623521
624-
The Version 1.1 DescriptorRange_V1_1 extends the base structure with performance optimization flags.
625-
626-
#. **Flags**: Provide additional information about the descriptors and enable further driver optimizations.
627-
For details, check `Direct X documentation <https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signature-version-1-1#static-and-volatile-flags>`_.
628-
629522
Static Samplers
630523
~~~~~~~~~~~~~~~
631524

632-
Static samplers provide a way to define fixed sampler states within the root signature itself.
525+
Static samplers are predefined filtering settings built into the root signature, avoiding descriptor heap lookups.
526+
527+
This section also has a variable size. The size is 68 bytes long, containing the following fields: 32 bits for a
528+
filter mode, three 32 bit fields for texture address mode, 64 bits for the bias value of minmap level calculation,
529+
32 bits for maximum anisotropy level, 32 bits for the comparison function type, 32 bits for the static border colour,
530+
two 64 bit fields for the min and max level of detail, two 32 bit fields for the register number and space and finally
531+
32 bits for the shader visibility flag.
633532

634533
.. code-block:: c
635534
636535
struct StaticSamplerDesc {
637-
FilterMode Filter;
536+
FilterMode Filter;
638537
TextureAddressMode AddressU;
639538
TextureAddressMode AddressV;
640539
TextureAddressMode AddressW;
641540
float MipLODBias;
642541
uint32_t MaxAnisotropy;
643-
ComparisonFunc ComparisonFunc;
542+
ComparisonFunc ComparisonFunc;
644543
StaticBorderColor BorderColor;
645544
float MinLOD;
646545
float MaxLOD;
@@ -649,24 +548,3 @@ Static samplers provide a way to define fixed sampler states within the root sig
649548
ShaderVisibility ShaderVisibility;
650549
};
651550
652-
653-
The StaticSamplerDesc structure defines all properties of a static sampler:
654-
655-
#. **Filter**: The filtering mode (e.g., point, linear, anisotropic) used for texture sampling.
656-
For details, check `Static Sampler Fileters definition. <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter#syntax>`_.
657-
#. **AddressU**: The addressing mode for the U texture coordinate.
658-
For details, check `Texture address mode definition. <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode>`_.
659-
#. **AddressV**: The addressing mode for the V texture coordinate.
660-
#. **AddressW**: The addressing mode for the W texture coordinate.
661-
#. **MipLODBias**: Bias value applied to mipmap level of detail calculations.
662-
#. **MaxAnisotropy**: Maximum anisotropy level when using anisotropic filtering.
663-
#. **ComparisonFunc**: Comparison function used for comparison samplers.
664-
For details, check `Comparison Function definition. <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_comparison_func>`_.
665-
#. **BorderColor**: Predefined border color used when address mode is set to border.
666-
For details, check `Static border color <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_static_border_color>`_.
667-
#. **MinLOD**: Minimum level of detail to use for sampling.
668-
#. **MaxLOD**: Maximum level of detail to use for sampling.
669-
#. **ShaderRegister**: The shader sampler register (s#) where this sampler is bound.
670-
#. **RegisterSpace**: The register space used for the binding.
671-
#. **ShaderVisibility**: Specifies which shader stages can access this sampler.
672-
For details, check `Shader Visibility definition. <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_shader_visibility>`_.

0 commit comments

Comments
 (0)