@@ -277,7 +277,7 @@ Examples:
277277 Accessing Resources as Memory
278278-----------------------------
279279
280- *relevant types: Buffers, CBuffer, and Textures *
280+ *relevant types: Buffers and Textures *
281281
282282Loading and storing from resources is generally represented in LLVM using
283283operations on memory that is only accessible via a handle object. Given a
@@ -321,12 +321,11 @@ Examples:
321321 Loads, Samples, and Gathers
322322---------------------------
323323
324- *relevant types: Buffers, CBuffers, and Textures *
324+ *relevant types: Buffers and Textures *
325325
326- All load, sample, and gather operations in DXIL return a `ResRet `_ type, and
327- CBuffer loads return a similar `CBufRet `_ type. These types are structs
328- containing 4 elements of some basic type, and in the case of `ResRet ` a 5th
329- element that is used by the `CheckAccessFullyMapped `_ operation. Some of these
326+ All load, sample, and gather operations in DXIL return a `ResRet `_ type. These
327+ types are structs containing 4 elements of some basic type, and a 5th element
328+ that is used by the `CheckAccessFullyMapped `_ operation. Some of these
330329operations, like `RawBufferLoad `_ include a mask and/or alignment that tell us
331330some information about how to interpret those four values.
332331
@@ -632,3 +631,118 @@ Examples:
632631 target("dx.RawBuffer", i8, 1, 0, 0) %buffer,
633632 i32 %index, i32 0, <4 x double> %data)
634633
634+ Constant Buffer Loads
635+ ---------------------
636+
637+ *relevant types: CBuffers *
638+
639+ The `CBufferLoadLegacy `_ operation, which despite the name is the only
640+ supported way to load from a cbuffer in any DXIL version, loads a single "row"
641+ of a cbuffer, which is exactly 16 bytes. The return value of the operation is
642+ represented by a `CBufRet `_ type, which has variants for 2 64-bit values, 4
643+ 32-bit values, and 8 16-bit values.
644+
645+ We represent these in LLVM IR with 3 separate operations, which return a
646+ 2-element, 4-element, or 8-element struct respectively.
647+
648+ .. _CBufferLoadLegacy : https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferLoadLegacy
649+ .. _CBufRet : https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy
650+
651+ .. list-table :: ``@llvm.dx.resource.load.cbufferrow.4``
652+ :header-rows: 1
653+
654+ * - Argument
655+ -
656+ - Type
657+ - Description
658+ * - Return value
659+ -
660+ - A struct of 4 32-bit values
661+ - A single row of a cbuffer, interpreted as 4 32-bit values
662+ * - ``%buffer ``
663+ - 0
664+ - ``target(dx.CBuffer, ...) ``
665+ - The buffer to load from
666+ * - ``%index ``
667+ - 1
668+ - ``i32 ``
669+ - Index into the buffer
670+
671+ Examples:
672+
673+ .. code-block :: llvm
674+
675+ %ret = call {float, float, float, float}
676+ @llvm.dx.resource.load.cbufferrow.4(
677+ target("dx.CBuffer", target("dx.Layout", {float}, 4, 0)) %buffer,
678+ i32 %index)
679+ %ret = call {i32, i32, i32, i32}
680+ @llvm.dx.resource.load.cbufferrow.4(
681+ target("dx.CBuffer", target("dx.Layout", {i32}, 4, 0)) %buffer,
682+ i32 %index)
683+
684+ .. list-table :: ``@llvm.dx.resource.load.cbufferrow.2``
685+ :header-rows: 1
686+
687+ * - Argument
688+ -
689+ - Type
690+ - Description
691+ * - Return value
692+ -
693+ - A struct of 2 64-bit values
694+ - A single row of a cbuffer, interpreted as 2 64-bit values
695+ * - ``%buffer ``
696+ - 0
697+ - ``target(dx.CBuffer, ...) ``
698+ - The buffer to load from
699+ * - ``%index ``
700+ - 1
701+ - ``i32 ``
702+ - Index into the buffer
703+
704+ Examples:
705+
706+ .. code-block :: llvm
707+
708+ %ret = call {double, double}
709+ @llvm.dx.resource.load.cbufferrow.2(
710+ target("dx.CBuffer", target("dx.Layout", {double}, 8, 0)) %buffer,
711+ i32 %index)
712+ %ret = call {i64, i64}
713+ @llvm.dx.resource.load.cbufferrow.2(
714+ target("dx.CBuffer", target("dx.Layout", {i64}, 4, 0)) %buffer,
715+ i32 %index)
716+
717+ .. list-table :: ``@llvm.dx.resource.load.cbufferrow.8``
718+ :header-rows: 1
719+
720+ * - Argument
721+ -
722+ - Type
723+ - Description
724+ * - Return value
725+ -
726+ - A struct of 8 16-bit values
727+ - A single row of a cbuffer, interpreted as 8 16-bit values
728+ * - ``%buffer ``
729+ - 0
730+ - ``target(dx.CBuffer, ...) ``
731+ - The buffer to load from
732+ * - ``%index ``
733+ - 1
734+ - ``i32 ``
735+ - Index into the buffer
736+
737+ Examples:
738+
739+ .. code-block :: llvm
740+
741+ %ret = call {half, half, half, half, half, half, half, half}
742+ @llvm.dx.resource.load.cbufferrow.8(
743+ target("dx.CBuffer", target("dx.Layout", {half}, 2, 0)) %buffer,
744+ i32 %index)
745+ %ret = call {i16, i16, i16, i16, i16, i16, i16, i16}
746+ @llvm.dx.resource.load.cbufferrow.8(
747+ target("dx.CBuffer", target("dx.Layout", {i16}, 2, 0)) %buffer,
748+ i32 %index)
0 commit comments