1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
|
======================
DXIL Resource Handling
======================
.. contents::
:local:
.. toctree::
:hidden:
Introduction
============
Resources in DXIL are represented via ``TargetExtType`` in LLVM IR and
eventually lowered by the DirectX backend into metadata in DXIL.
In DXC and DXIL, static resources are represented as lists of SRVs (Shader
Resource Views), UAVs (Uniform Access Views), CBVs (Constant Bffer Views), and
Samplers. This metadata consists of a "resource record ID" which uniquely
identifies a resource and type information. As of shader model 6.6, there are
also dynamic resources, which forgo the metadata and are described via
``annotateHandle`` operations in the instruction stream instead.
In LLVM we attempt to unify some of the alternative representations that are
present in DXC, with the aim of making handling of resources in the middle end
of the compiler simpler and more consistent.
Resource Type Information and Properties
========================================
There are a number of properties associated with a resource in DXIL.
`Resource ID`
An arbitrary ID that must be unique per resource type (SRV, UAV, etc).
In LLVM we don't bother representing this, instead opting to generate it at
DXIL lowering time.
`Binding information`
Information about where the resource comes from. This is either (a) a
register space, lower bound in that space, and size of the binding, or (b)
an index into a dynamic resource heap.
In LLVM we represent binding information in the arguments of the
:ref:`handle creation intrinsics <dxil-resources-handles>`. When generating
DXIL we transform these calls to metadata, ``dx.op.createHandle``,
``dx.op.createHandleFromBinding``, ``dx.op.createHandleFromHeap``, and
``dx.op.createHandleForLib`` as needed.
`Type information`
The type of data that's accessible via the resource. For buffers and
textures this can be a simple type like ``float`` or ``float4``, a struct,
or raw bytes. For constant buffers this is just a size. For samplers this is
the kind of sampler.
In LLVM we embed this information as a parameter on the ``target()`` type of
the resource. See :ref:`dxil-resources-types-of-resource`.
`Resource kind information`
The kind of resource. In HLSL we have things like ``ByteAddressBuffer``,
``RWTexture2D``, and ``RasterizerOrderedStructuredBuffer``. These map to a
set of DXIL kinds like ``RawBuffer`` and ``Texture2D`` with fields for
certain properties such as ``IsUAV`` and ``IsROV``.
In LLVM we represent this in the ``target()`` type. We omit information
that's deriveable from the type information, but we do have fields to encode
``IsWriteable``, ``IsROV``, and ``SampleCount`` when needed.
.. note:: TODO: There are two fields in the DXIL metadata that are not
represented as part of the target type: ``IsGloballyCoherent`` and
``HasCounter``.
Since these are derived from analysis, storing them on the type would mean
we need to change the type during the compiler pipeline. That just isn't
practical. It isn't entirely clear to me that we need to serialize this info
into the IR during the compiler pipeline anyway - we can probably get away
with an analysis pass that can calculate the information when we need it.
If analysis is insufficient we'll need something akin to ``annotateHandle``
(but limited to these two properties) or to encode these in the handle
creation.
.. _dxil-resources-types-of-resource:
Types of Resource
=================
We define a set of ``TargetExtTypes`` that is similar to the HLSL
representations for the various resources, albeit with a few things
parameterized. This is different than DXIL, as simplifying the types to
something like "dx.srv" and "dx.uav" types would mean the operations on these
types would have to be overly generic.
Buffers
-------
.. code-block:: llvm
target("dx.TypedBuffer", ElementType, IsWriteable, IsROV, IsSigned)
target("dx.RawBuffer", ElementType, IsWriteable, IsROV)
We need two separate buffer types to account for the differences between the
16-byte `bufferLoad`_ / `bufferStore`_ operations that work on DXIL's
TypedBuffers and the `rawBufferLoad`_ / `rawBufferStore`_ operations that are
used for DXIL's RawBuffers and StructuredBuffers. We call the latter
"RawBuffer" to match the naming of the operations, but it can represent both
the Raw and Structured variants.
HLSL's Buffer and RWBuffer are represented as a TypedBuffer with an element
type that is a scalar integer or floating point type, or a vector of at most 4
such types. HLSL's ByteAddressBuffer is a RawBuffer with an `i8` element type.
HLSL's StructuredBuffers are RawBuffer with a struct, vector, or scalar type.
One unfortunate necessity here is that TypedBuffer needs an extra parameter to
differentiate signed vs unsigned ints. The is because in LLVM IR int types
don't have a sign, so to keep this information we need a side channel.
These types are generally used by BufferLoad and BufferStore operations, as
well as atomics.
There are a few fields to describe variants of all of these types:
.. list-table:: Buffer Fields
:header-rows: 1
* - Field
- Description
* - ElementType
- Type for a single element, such as ``i8``, ``v4f32``, or a structure
type.
* - IsWriteable
- Whether or not the field is writeable. This distinguishes SRVs (not
writeable) and UAVs (writeable).
* - IsROV
- Whether the UAV is a rasterizer ordered view. Always ``0`` for SRVs.
* - IsSigned
- Whether an int element type is signed ("dx.TypedBuffer" only)
.. _bufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferload
.. _bufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferstore
.. _rawBufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#rawbufferload
.. _rawBufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#rawbufferstore
Resource Operations
===================
.. _dxil-resources-handles:
Resource Handles
----------------
We provide a few different ways to instantiate resources in the IR via the
``llvm.dx.handle.*`` intrinsics. These intrinsics are overloaded on return
type, returning an appropriate handle for the resource, and represent binding
information in the arguments to the intrinsic.
The three operations we need are ``llvm.dx.resource.handlefrombinding``,
``llvm.dx.handle.fromHeap``, and ``llvm.dx.handle.fromPointer``. These are
rougly equivalent to the DXIL operations ``dx.op.createHandleFromBinding``,
``dx.op.createHandleFromHeap``, and ``dx.op.createHandleForLib``, but they fold
the subsequent ``dx.op.annotateHandle`` operation in. Note that we don't have
an analogue for `dx.op.createHandle`_, since ``dx.op.createHandleFromBinding``
subsumes it.
We diverge from DXIL and index from the beginning of the binding rather than
indexing from the beginning of the binding space. This matches the semantics
more clearly and avoids a non-obvious invariant in what constitutes valid
arguments.
.. _dx.op.createHandle: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-handles
.. list-table:: ``@llvm.dx.resource.handlefrombinding``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A ``target()`` type
- A handle which can be operated on
* - ``%reg_space``
- 1
- ``i32``
- Register space ID in the root signature for this resource.
* - ``%lower_bound``
- 2
- ``i32``
- Lower bound of the binding in its register space.
* - ``%range_size``
- 3
- ``i32``
- Range size of the binding.
* - ``%index``
- 4
- ``i32``
- Index from the beginning of the binding.
* - ``%non-uniform``
- 5
- i1
- Must be ``true`` if the resource index may be non-uniform.
.. note:: TODO: Can we drop the uniformity bit? I suspect we can derive it from
uniformity analysis...
Examples:
.. code-block:: llvm
; RWBuffer<float4> Buf : register(u5, space3)
%buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0(
i32 3, i32 5, i32 1, i32 0, i1 false)
; RWBuffer<int> Buf : register(u7, space2)
%buf = call target("dx.TypedBuffer", i32, 1, 0, 1)
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_1_0t(
i32 2, i32 7, i32 1, i32 0, i1 false)
; Buffer<uint4> Buf[24] : register(t3, space5)
%buf = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_0_0t(
i32 2, i32 7, i32 24, i32 0, i1 false)
; struct S { float4 a; uint4 b; };
; StructuredBuffer<S> Buf : register(t2, space4)
%buf = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
@llvm.dx.resource.handlefrombinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
i32 4, i32 2, i32 1, i32 0, i1 false)
; ByteAddressBuffer Buf : register(t8, space1)
%buf = call target("dx.RawBuffer", i8, 0, 0)
@llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t(
i32 1, i32 8, i32 1, i32 0, i1 false)
; RWBuffer<float4> Global[3] : register(u6, space5)
; RWBuffer<float4> Buf = Global[2];
%buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0(
i32 5, i32 6, i32 3, i32 2, i1 false)
.. list-table:: ``@llvm.dx.handle.fromHeap``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A ``target()`` type
- A handle which can be operated on
* - ``%index``
- 0
- ``i32``
- Index of the resource to access.
* - ``%non-uniform``
- 1
- i1
- Must be ``true`` if the resource index may be non-uniform.
Examples:
.. code-block:: llvm
; RWStructuredBuffer<float4> Buf = ResourceDescriptorHeap[2];
declare
target("dx.RawBuffer", <4 x float>, 1, 0)
@llvm.dx.handle.fromHeap.tdx.RawBuffer_v4f32_1_0(
i32 %index, i1 %non_uniform)
; ...
%buf = call target("dx.RawBuffer", <4 x f32>, 1, 0)
@llvm.dx.handle.fromHeap.tdx.RawBuffer_v4f32_1_0(
i32 2, i1 false)
Accessing Resources as Memory
-----------------------------
*relevant types: Buffers and Textures*
Loading and storing from resources is generally represented in LLVM using
operations on memory that is only accessible via a handle object. Given a
handle, `llvm.dx.resource.getpointer` gives a pointer that can be used to read
and (depending on type) write to the resource.
Accesses using `llvm.dx.resource.getpointer` are replaced with direct load and
store operations in the `DXILResourceAccess` pass. These direct loads and
stores are described later in this document.
.. note:: Currently the pointers returned by `dx.resource.getpointer` are in
the default address space, but that will likely change in the future.
.. list-table:: ``@llvm.dx.resource.getpointer``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- Pointer
- A pointer to an object in the buffer
* - ``%buffer``
- 0
- ``target(dx.TypedBuffer, ...)``
- The buffer to access
* - ``%index``
- 1
- ``i32``
- Index into the buffer
Examples:
.. code-block:: llvm
%ptr = call ptr @llvm.dx.resource.getpointer.p0.tdx.TypedBuffer_v4f32_0_0_0t(
target("dx.TypedBuffer", <4 x float>, 0, 0, 0) %buffer, i32 %index)
Loads, Samples, and Gathers
---------------------------
*relevant types: Buffers and Textures*
All load, sample, and gather operations in DXIL return a `ResRet`_ type. These
types are structs containing 4 elements of some basic type, and a 5th element
that is used by the `CheckAccessFullyMapped`_ operation. Some of these
operations, like `RawBufferLoad`_ include a mask and/or alignment that tell us
some information about how to interpret those four values.
In the LLVM IR representations of these operations we instead return scalars or
vectors, but we keep the requirement that we only return up to 4 elements of a
basic type. This avoids some unnecessary casting and structure manipulation in
the intermediate format while also keeping lowering to DXIL straightforward.
LLVM intrinsics that map to operations returning `ResRet` return an anonymous
struct with element-0 being the scalar or vector type, and element-1 being the
``i1`` result of a ``CheckAccessFullyMapped`` call. We don't have a separate
call to ``CheckAccessFullyMapped`` at all, since that's the only operation that
can possibly be done on this value. In practice this may mean we insert a DXIL
operation for the check when this was missing in the HLSL source, but this
actually matches DXC's behaviour in practice.
For TypedBuffer and Texture, we map directly from the contained type of the
resource to the return value of the intrinsic. Since these resources are
constrained to contain only scalars and vectors of up to 4 elements, the
lowering to DXIL ops is generally straightforward. The one exception we have
here is that `double` types in the elements are special - these are allowed in
the LLVM intrinsics, but are lowered to pairs of `i32` followed by
``MakeDouble`` operations for DXIL.
.. _ResRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-operation-return-types
.. _CBufRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy
.. _CheckAccessFullyMapped: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/checkaccessfullymapped
.. _RawBufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#rawbufferload
.. list-table:: ``@llvm.dx.resource.load.typedbuffer``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A structure of the contained type and the check bit
- The data loaded from the buffer and the check bit
* - ``%buffer``
- 0
- ``target(dx.TypedBuffer, ...)``
- The buffer to load from
* - ``%index``
- 1
- ``i32``
- Index into the buffer
Examples:
.. code-block:: llvm
%ret = call {<4 x float>, i1}
@llvm.dx.resource.load.typedbuffer.v4f32.tdx.TypedBuffer_v4f32_0_0_0t(
target("dx.TypedBuffer", <4 x float>, 0, 0, 0) %buffer, i32 %index)
%ret = call {float, i1}
@llvm.dx.resource.load.typedbuffer.f32.tdx.TypedBuffer_f32_0_0_0t(
target("dx.TypedBuffer", float, 0, 0, 0) %buffer, i32 %index)
%ret = call {<4 x i32>, i1}
@llvm.dx.resource.load.typedbuffer.v4i32.tdx.TypedBuffer_v4i32_0_0_0t(
target("dx.TypedBuffer", <4 x i32>, 0, 0, 0) %buffer, i32 %index)
%ret = call {<4 x half>, i1}
@llvm.dx.resource.load.typedbuffer.v4f16.tdx.TypedBuffer_v4f16_0_0_0t(
target("dx.TypedBuffer", <4 x half>, 0, 0, 0) %buffer, i32 %index)
%ret = call {<2 x double>, i1}
@llvm.dx.resource.load.typedbuffer.v2f64.tdx.TypedBuffer_v2f64_0_0t(
target("dx.TypedBuffer", <2 x double>, 0, 0, 0) %buffer, i32 %index)
For RawBuffer, an HLSL load operation may return an arbitrarily sized result,
but we still constrain the LLVM intrinsic to return only up to 4 elements of a
basic type. This means that larger loads are represented as a series of loads,
which matches DXIL. Unlike in the `RawBufferLoad`_ operation, we do not need
arguments for the mask/type size and alignment, since we can calculate these
from the return type of the load during lowering.
.. _RawBufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#rawbufferload
.. list-table:: ``@llvm.dx.resource.load.rawbuffer``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A structure of a scalar or vector and the check bit
- The data loaded from the buffer and the check bit
* - ``%buffer``
- 0
- ``target(dx.RawBuffer, ...)``
- The buffer to load from
* - ``%index``
- 1
- ``i32``
- Index into the buffer
* - ``%offset``
- 2
- ``i32``
- Offset into the structure at the given index
Examples:
.. code-block:: llvm
; float
%ret = call {float, i1}
@llvm.dx.resource.load.rawbuffer.f32.tdx.RawBuffer_f32_0_0_0t(
target("dx.RawBuffer", float, 0, 0, 0) %buffer,
i32 %index,
i32 0)
%ret = call {float, i1}
@llvm.dx.resource.load.rawbuffer.f32.tdx.RawBuffer_i8_0_0_0t(
target("dx.RawBuffer", i8, 0, 0, 0) %buffer,
i32 %byte_offset,
i32 0)
; float4
%ret = call {<4 x float>, i1}
@llvm.dx.resource.load.rawbuffer.v4f32.tdx.RawBuffer_v4f32_0_0_0t(
target("dx.RawBuffer", float, 0, 0, 0) %buffer,
i32 %index,
i32 0)
%ret = call {float, i1}
@llvm.dx.resource.load.rawbuffer.v4f32.tdx.RawBuffer_i8_0_0_0t(
target("dx.RawBuffer", i8, 0, 0, 0) %buffer,
i32 %byte_offset,
i32 0)
; struct S0 { float4 f; int4 i; };
%ret = call {<4 x float>, i1}
@llvm.dx.resource.load.rawbuffer.v4f32.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0, 0) %buffer,
i32 %index,
i32 0)
%ret = call {<4 x i32>, i1}
@llvm.dx.resource.load.rawbuffer.v4i32.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0, 0) %buffer,
i32 %index,
i32 1)
; struct Q { float4 f; int3 i; }
; struct R { int z; S x; }
%ret = call {i32, i1}
@llvm.dx.resource.load.rawbuffer.i32(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x i32>}}, 0, 0, 0)
%buffer, i32 %index, i32 0)
%ret = call {<4 x float>, i1}
@llvm.dx.resource.load.rawbuffer.i32(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x i32>}}, 0, 0, 0)
%buffer, i32 %index, i32 4)
%ret = call {<3 x i32>, i1}
@llvm.dx.resource.load.rawbuffer.i32(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x i32>}}, 0, 0, 0)
%buffer, i32 %index, i32 20)
; byteaddressbuf.Load<int64_t4>
%ret = call {<4 x i64>, i1}
@llvm.dx.resource.load.rawbuffer.v4i64.tdx.RawBuffer_i8_0_0t(
target("dx.RawBuffer", i8, 0, 0, 0) %buffer,
i32 %byte_offset,
i32 0)
Stores
------
*relevant types: Textures and Buffer*
The `TextureStore`_, `BufferStore`_, and `RawBufferStore`_ DXIL operations
write four components to a texture or a buffer. These include a mask argument
that is used when fewer than 4 components are written, but notably this only
takes on the contiguous x, xy, xyz, and xyzw values.
We define the LLVM store intrinsics to accept vectors when storing multiple
components rather than using `undef` and a mask, but otherwise match the DXIL
ops fairly closely.
.. _TextureStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#texturestore
.. _BufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferstore
.. _RawBufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#rawbufferstore
For TypedBuffer, we only need one coordinate, and we must always write a vector
since partial writes aren't possible. Similarly to the load operations
described above, we handle 64-bit types specially and only handle 2-element
vectors rather than 4.
Examples:
.. list-table:: ``@llvm.dx.resource.store.typedbuffer``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- ``void``
-
* - ``%buffer``
- 0
- ``target(dx.TypedBuffer, ...)``
- The buffer to store into
* - ``%index``
- 1
- ``i32``
- Index into the buffer
* - ``%data``
- 2
- A 4- or 2-element vector of the type of the buffer
- The data to store
Examples:
.. code-block:: llvm
call void @llvm.dx.resource.store.typedbuffer.tdx.Buffer_v4f32_1_0_0t(
target("dx.TypedBuffer", f32, 1, 0) %buf, i32 %index, <4 x f32> %data)
call void @llvm.dx.resource.store.typedbuffer.tdx.Buffer_v4f16_1_0_0t(
target("dx.TypedBuffer", f16, 1, 0) %buf, i32 %index, <4 x f16> %data)
call void @llvm.dx.resource.store.typedbuffer.tdx.Buffer_v2f64_1_0_0t(
target("dx.TypedBuffer", f64, 1, 0) %buf, i32 %index, <2 x f64> %data)
For RawBuffer, we need two indices and we accept scalars and vectors of 4 or
fewer elements. Note that we do allow vectors of 4 64-bit elements here.
Examples:
.. list-table:: ``@llvm.dx.resource.store.rawbuffer``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- ``void``
-
* - ``%buffer``
- 0
- ``target(dx.RawBuffer, ...)``
- The buffer to store into
* - ``%index``
- 1
- ``i32``
- Index into the buffer
* - ``%offset``
- 2
- ``i32``
- Byte offset into structured buffer elements
* - ``%data``
- 3
- Scalar or vector
- The data to store
Examples:
.. code-block:: llvm
; float
call void @llvm.dx.resource.store.rawbuffer.tdx.RawBuffer_f32_1_0_0t.f32(
target("dx.RawBuffer", float, 1, 0, 0) %buffer,
i32 %index, i32 0, float %data)
call void @llvm.dx.resource.store.rawbuffer.tdx.RawBuffer_i8_1_0_0t.f32(
target("dx.RawBuffer", i8, 1, 0, 0) %buffer,
i32 %index, i32 0, float %data)
; float4
call void @llvm.dx.resource.store.rawbuffer.tdx.RawBuffer_v4f32_1_0_0t.v4f32(
target("dx.RawBuffer", <4 x float>, 1, 0, 0) %buffer,
i32 %index, i32 0, <4 x float> %data)
call void @llvm.dx.resource.store.rawbuffer.tdx.RawBuffer_i8_1_0_0t.v4f32(
target("dx.RawBuffer", i8, 1, 0, 0) %buffer,
i32 %index, i32 0, <4 x float> %data)
; struct S0 { float4 f; int4 i; }
call void @llvm.dx.resource.store.rawbuffer.v4f32(
target("dx.RawBuffer", { <4 x float>, <4 x i32> }, 1, 0, 0) %buffer,
i32 %index, i32 0, <4 x float> %data0)
call void @llvm.dx.resource.store.rawbuffer.v4i32(
target("dx.RawBuffer", { <4 x float>, <4 x i32> }, 1, 0, 0) %buffer,
i32 %index, i32 16, <4 x i32> %data1)
; struct Q { float4 f; int3 i; }
; struct R { int z; S x; }
call void @llvm.dx.resource.store.rawbuffer.i32(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x half>}}, 1, 0, 0)
%buffer,
i32 %index, i32 0, i32 %data0)
call void @llvm.dx.resource.store.rawbuffer.v4f32(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x half>}}, 1, 0, 0)
%buffer,
i32 %index, i32 4, <4 x float> %data1)
call void @llvm.dx.resource.store.rawbuffer.v3f16(
target("dx.RawBuffer", {i32, {<4 x float>, <3 x half>}}, 1, 0, 0)
%buffer,
i32 %index, i32 20, <3 x half> %data2)
; byteaddressbuf.Store<int64_t4>
call void @llvm.dx.resource.store.rawbuffer.tdx.RawBuffer_i8_1_0_0t.v4f64(
target("dx.RawBuffer", i8, 1, 0, 0) %buffer,
i32 %index, i32 0, <4 x double> %data)
Constant Buffer Loads
---------------------
*relevant types: CBuffers*
The `CBufferLoadLegacy`_ operation, which despite the name is the only
supported way to load from a cbuffer in any DXIL version, loads a single "row"
of a cbuffer, which is exactly 16 bytes. The return value of the operation is
represented by a `CBufRet`_ type, which has variants for 2 64-bit values, 4
32-bit values, and 8 16-bit values.
We represent these in LLVM IR with 3 separate operations, which return a
2-element, 4-element, or 8-element struct respectively.
.. _CBufferLoadLegacy: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferLoadLegacy
.. _CBufRet: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#cbufferloadlegacy
.. list-table:: ``@llvm.dx.resource.load.cbufferrow.4``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A struct of 4 32-bit values
- A single row of a cbuffer, interpreted as 4 32-bit values
* - ``%buffer``
- 0
- ``target(dx.CBuffer, ...)``
- The buffer to load from
* - ``%index``
- 1
- ``i32``
- Index into the buffer
Examples:
.. code-block:: llvm
%ret = call {float, float, float, float}
@llvm.dx.resource.load.cbufferrow.4(
target("dx.CBuffer", target("dx.Layout", {float}, 4, 0)) %buffer,
i32 %index)
%ret = call {i32, i32, i32, i32}
@llvm.dx.resource.load.cbufferrow.4(
target("dx.CBuffer", target("dx.Layout", {i32}, 4, 0)) %buffer,
i32 %index)
.. list-table:: ``@llvm.dx.resource.load.cbufferrow.2``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A struct of 2 64-bit values
- A single row of a cbuffer, interpreted as 2 64-bit values
* - ``%buffer``
- 0
- ``target(dx.CBuffer, ...)``
- The buffer to load from
* - ``%index``
- 1
- ``i32``
- Index into the buffer
Examples:
.. code-block:: llvm
%ret = call {double, double}
@llvm.dx.resource.load.cbufferrow.2(
target("dx.CBuffer", target("dx.Layout", {double}, 8, 0)) %buffer,
i32 %index)
%ret = call {i64, i64}
@llvm.dx.resource.load.cbufferrow.2(
target("dx.CBuffer", target("dx.Layout", {i64}, 4, 0)) %buffer,
i32 %index)
.. list-table:: ``@llvm.dx.resource.load.cbufferrow.8``
:header-rows: 1
* - Argument
-
- Type
- Description
* - Return value
-
- A struct of 8 16-bit values
- A single row of a cbuffer, interpreted as 8 16-bit values
* - ``%buffer``
- 0
- ``target(dx.CBuffer, ...)``
- The buffer to load from
* - ``%index``
- 1
- ``i32``
- Index into the buffer
Examples:
.. code-block:: llvm
%ret = call {half, half, half, half, half, half, half, half}
@llvm.dx.resource.load.cbufferrow.8(
target("dx.CBuffer", target("dx.Layout", {half}, 2, 0)) %buffer,
i32 %index)
%ret = call {i16, i16, i16, i16, i16, i16, i16, i16}
@llvm.dx.resource.load.cbufferrow.8(
target("dx.CBuffer", target("dx.Layout", {i16}, 2, 0)) %buffer,
i32 %index)
|