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
|
//
// Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
/**
*************************************************************************************************************
* @File ags_shader_intrinsics_dx11.hlsl
*
* @brief
* AMD D3D Shader Intrinsics API hlsl file.
* This include file contains the shader intrinsics definitions (structures, enums, constant)
* and HLSL shader intrinsics functions.
*
*************************************************************************************************************
*/
#ifndef _AMDDXEXTSHADERINTRINSICS_HLSL_
#define _AMDDXEXTSHADERINTRINSICS_HLSL_
/**
*************************************************************************************************************
* Definitions to construct the intrinsic instruction composed of an opcode and optional immediate data.
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsics_MagicCodeShift 28
#define AmdDxExtShaderIntrinsics_MagicCodeMask 0xf
#define AmdDxExtShaderIntrinsics_OpcodePhaseShift 24
#define AmdDxExtShaderIntrinsics_OpcodePhaseMask 0x3
#define AmdDxExtShaderIntrinsics_DataShift 8
#define AmdDxExtShaderIntrinsics_DataMask 0xffff
#define AmdDxExtShaderIntrinsics_OpcodeShift 0
#define AmdDxExtShaderIntrinsics_OpcodeMask 0xff
#define AmdDxExtShaderIntrinsics_MagicCode 0x5
/**
*************************************************************************************************************
* Intrinsic opcodes.
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsicsOpcode_Readfirstlane 0x01
#define AmdDxExtShaderIntrinsicsOpcode_Readlane 0x02
#define AmdDxExtShaderIntrinsicsOpcode_LaneId 0x03
#define AmdDxExtShaderIntrinsicsOpcode_Swizzle 0x04
#define AmdDxExtShaderIntrinsicsOpcode_Ballot 0x05
#define AmdDxExtShaderIntrinsicsOpcode_MBCnt 0x06
#define AmdDxExtShaderIntrinsicsOpcode_Min3U 0x08
#define AmdDxExtShaderIntrinsicsOpcode_Min3F 0x09
#define AmdDxExtShaderIntrinsicsOpcode_Med3U 0x0a
#define AmdDxExtShaderIntrinsicsOpcode_Med3F 0x0b
#define AmdDxExtShaderIntrinsicsOpcode_Max3U 0x0c
#define AmdDxExtShaderIntrinsicsOpcode_Max3F 0x0d
#define AmdDxExtShaderIntrinsicsOpcode_BaryCoord 0x0e
#define AmdDxExtShaderIntrinsicsOpcode_VtxParam 0x0f
/**
*************************************************************************************************************
* Intrinsic opcode phases.
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsicsOpcodePhase_0 0x0
#define AmdDxExtShaderIntrinsicsOpcodePhase_1 0x1
#define AmdDxExtShaderIntrinsicsOpcodePhase_2 0x2
#define AmdDxExtShaderIntrinsicsOpcodePhase_3 0x3
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsicsSwizzle defines for common swizzles. Can be used as the operation parameter for
* the AmdDxExtShaderIntrinsics_Swizzle intrinsic.
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsicsSwizzle_SwapX1 0x041f
#define AmdDxExtShaderIntrinsicsSwizzle_SwapX2 0x081f
#define AmdDxExtShaderIntrinsicsSwizzle_SwapX4 0x101f
#define AmdDxExtShaderIntrinsicsSwizzle_SwapX8 0x201f
#define AmdDxExtShaderIntrinsicsSwizzle_SwapX16 0x401f
#define AmdDxExtShaderIntrinsicsSwizzle_ReverseX2 0x041f
#define AmdDxExtShaderIntrinsicsSwizzle_ReverseX4 0x0c1f
#define AmdDxExtShaderIntrinsicsSwizzle_ReverseX8 0x1c1f
#define AmdDxExtShaderIntrinsicsSwizzle_ReverseX16 0x3c1f
#define AmdDxExtShaderIntrinsicsSwizzle_ReverseX32 0x7c1f
#define AmdDxExtShaderIntrinsicsSwizzle_BCastX2 0x003e
#define AmdDxExtShaderIntrinsicsSwizzle_BCastX4 0x003c
#define AmdDxExtShaderIntrinsicsSwizzle_BCastX8 0x0038
#define AmdDxExtShaderIntrinsicsSwizzle_BCastX16 0x0030
#define AmdDxExtShaderIntrinsicsSwizzle_BCastX32 0x0020
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsicsBarycentric defines for barycentric interpolation mode. To be used with
* AmdDxExtShaderIntrinsicsOpcode_IjBarycentricCoords to specify the interpolation mode.
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsicsBarycentric_LinearCenter 0x1
#define AmdDxExtShaderIntrinsicsBarycentric_LinearCentroid 0x2
#define AmdDxExtShaderIntrinsicsBarycentric_LinearSample 0x3
#define AmdDxExtShaderIntrinsicsBarycentric_PerspCenter 0x4
#define AmdDxExtShaderIntrinsicsBarycentric_PerspCentroid 0x5
#define AmdDxExtShaderIntrinsicsBarycentric_PerspSample 0x6
#define AmdDxExtShaderIntrinsicsBarycentric_PerspPullModel 0x7
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsicsBarycentric defines for specifying vertex and parameter indices. To be used as
* the inputs to the AmdDxExtShaderIntrinsicsOpcode_VertexParameter function
*************************************************************************************************************
*/
#define AmdDxExtShaderIntrinsicsBarycentric_Vertex0 0x0
#define AmdDxExtShaderIntrinsicsBarycentric_Vertex1 0x1
#define AmdDxExtShaderIntrinsicsBarycentric_Vertex2 0x2
#define AmdDxExtShaderIntrinsicsBarycentric_Param0 0x00
#define AmdDxExtShaderIntrinsicsBarycentric_Param1 0x01
#define AmdDxExtShaderIntrinsicsBarycentric_Param2 0x02
#define AmdDxExtShaderIntrinsicsBarycentric_Param3 0x03
#define AmdDxExtShaderIntrinsicsBarycentric_Param4 0x04
#define AmdDxExtShaderIntrinsicsBarycentric_Param5 0x05
#define AmdDxExtShaderIntrinsicsBarycentric_Param6 0x06
#define AmdDxExtShaderIntrinsicsBarycentric_Param7 0x07
#define AmdDxExtShaderIntrinsicsBarycentric_Param8 0x08
#define AmdDxExtShaderIntrinsicsBarycentric_Param9 0x09
#define AmdDxExtShaderIntrinsicsBarycentric_Param10 0x0a
#define AmdDxExtShaderIntrinsicsBarycentric_Param11 0x0b
#define AmdDxExtShaderIntrinsicsBarycentric_Param12 0x0c
#define AmdDxExtShaderIntrinsicsBarycentric_Param13 0x0d
#define AmdDxExtShaderIntrinsicsBarycentric_Param14 0x0e
#define AmdDxExtShaderIntrinsicsBarycentric_Param15 0x0f
#define AmdDxExtShaderIntrinsicsBarycentric_Param16 0x10
#define AmdDxExtShaderIntrinsicsBarycentric_Param17 0x11
#define AmdDxExtShaderIntrinsicsBarycentric_Param18 0x12
#define AmdDxExtShaderIntrinsicsBarycentric_Param19 0x13
#define AmdDxExtShaderIntrinsicsBarycentric_Param20 0x14
#define AmdDxExtShaderIntrinsicsBarycentric_Param21 0x15
#define AmdDxExtShaderIntrinsicsBarycentric_Param22 0x16
#define AmdDxExtShaderIntrinsicsBarycentric_Param23 0x17
#define AmdDxExtShaderIntrinsicsBarycentric_Param24 0x18
#define AmdDxExtShaderIntrinsicsBarycentric_Param25 0x19
#define AmdDxExtShaderIntrinsicsBarycentric_Param26 0x1a
#define AmdDxExtShaderIntrinsicsBarycentric_Param27 0x1b
#define AmdDxExtShaderIntrinsicsBarycentric_Param28 0x1c
#define AmdDxExtShaderIntrinsicsBarycentric_Param29 0x1d
#define AmdDxExtShaderIntrinsicsBarycentric_Param30 0x1e
#define AmdDxExtShaderIntrinsicsBarycentric_Param31 0x1f
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentX 0x0
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentY 0x1
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentZ 0x2
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentW 0x3
#define AmdDxExtShaderIntrinsicsBarycentric_ParamShift 0
#define AmdDxExtShaderIntrinsicsBarycentric_ParamMask 0x1f
#define AmdDxExtShaderIntrinsicsBarycentric_VtxShift 0x5
#define AmdDxExtShaderIntrinsicsBarycentric_VtxMask 0x3
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentShift 0x7
#define AmdDxExtShaderIntrinsicsBarycentric_ComponentMask 0x3
/**
*************************************************************************************************************
* Resource slots
*************************************************************************************************************
*/
#ifndef AmdDxExtShaderIntrinsicsUAVSlot
#define AmdDxExtShaderIntrinsicsUAVSlot u7
#endif
RWByteAddressBuffer AmdDxExtShaderIntrinsicsUAV : register(AmdDxExtShaderIntrinsicsUAVSlot);
/**
*************************************************************************************************************
* MakeAmdShaderIntrinsicsInstruction
*
* Creates instruction from supplied opcode and immediate data.
* NOTE: This is an internal function and should not be called by the source HLSL shader directly.
*
*************************************************************************************************************
*/
uint MakeAmdShaderIntrinsicsInstruction(uint opcode, uint opcodePhase, uint immediateData)
{
return ((AmdDxExtShaderIntrinsics_MagicCode << AmdDxExtShaderIntrinsics_MagicCodeShift) |
(immediateData << AmdDxExtShaderIntrinsics_DataShift) |
(opcodePhase << AmdDxExtShaderIntrinsics_OpcodePhaseShift) |
(opcode << AmdDxExtShaderIntrinsics_OpcodeShift));
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_ReadfirstlaneF
*
* Returns the value of float src for the first active lane of the wavefront.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Readfirstlane) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_ReadfirstlaneF(float src)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Readfirstlane,
0, 0);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, asuint(src), 0, retVal);
return asfloat(retVal);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_ReadfirstlaneU
*
* Returns the value of unsigned integer src for the first active lane of the wavefront.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Readfirstlane) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_ReadfirstlaneU(uint src)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Readfirstlane,
0, 0);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, src, 0, retVal);
return retVal;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Readlane
*
* Returns the value of float src for the lane within the wavefront specified by laneId.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Readlane) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_ReadlaneF(float src, uint laneId)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Readlane, 0,
laneId);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, asuint(src), 0, retVal);
return asfloat(retVal);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_ReadlaneU
*
* Returns the value of unsigned integer src for the lane within the wavefront specified by laneId.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Readlane) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_ReadlaneU(uint src, uint laneId)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Readlane, 0,
laneId);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, src, 0, retVal);
return retVal;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_LaneId
*
* Returns the current lane id for the thread within the wavefront.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_LaneId) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_LaneId()
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_LaneId, 0, 0);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, 0, 0, retVal);
return retVal;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Swizzle
*
* Generic instruction to shuffle the float src value among different lanes as specified by the
* operation.
* Note that the operation parameter must be an immediately specified value not a value from a variable.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Swizzle) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_SwizzleF(float src, uint operation)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Swizzle, 0,
operation);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, asuint(src), 0, retVal);
return asfloat(retVal);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_SwizzleU
*
* Generic instruction to shuffle the unsigned integer src value among different lanes as specified by the
* operation.
* Note that the operation parameter must be an immediately specified value not a value from a variable.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Swizzle) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_SwizzleU(uint src, uint operation)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Swizzle, 0,
operation);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, src, 0, retVal);
return retVal;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Ballot
*
* Given an input predicate returns a bit mask indicating for which lanes the predicate is true.
* Inactive or non-existent lanes will always return 0. The number of existent lanes is the
* wavefront size.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Ballot) returned S_OK.
*
*************************************************************************************************************
*/
uint2 AmdDxExtShaderIntrinsics_Ballot(bool predicate)
{
uint instruction;
uint retVal1;
instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Ballot,
AmdDxExtShaderIntrinsicsOpcodePhase_0, 0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, predicate, 0, retVal1);
uint retVal2;
instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Ballot,
AmdDxExtShaderIntrinsicsOpcodePhase_1, 0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, predicate, 0, retVal2);
return uint2(retVal1, retVal2);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_BallotAny
*
* Convenience routine that uses Ballot and returns true if for any of the active lanes the predicate
* is true.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Ballot) returned S_OK.
*
*************************************************************************************************************
*/
bool AmdDxExtShaderIntrinsics_BallotAny(bool predicate)
{
uint2 retVal = AmdDxExtShaderIntrinsics_Ballot(predicate);
return ((retVal.x | retVal.y) != 0 ? true : false);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_BallotAll
*
* Convenience routine that uses Ballot and returns true if for all of the active lanes the predicate
* is true.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Ballot) returned S_OK.
*
*************************************************************************************************************
*/
bool AmdDxExtShaderIntrinsics_BallotAll(bool predicate)
{
uint2 ballot = AmdDxExtShaderIntrinsics_Ballot(predicate);
uint2 execMask = AmdDxExtShaderIntrinsics_Ballot(true);
return ((ballot.x == execMask.x) && (ballot.y == execMask.y));
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_MBCnt
*
* Returns the masked bit count of the source register for this thread within all the active threads
* within a wavefront.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_MBCnt) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_MBCnt(uint2 src)
{
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_MBCnt, 0, 0);
uint retVal;
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, src.x, src.y, retVal);
return retVal;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Min3F
*
* Returns the minimum value of the three floating point source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_Min3F(float src0, float src1, float src2)
{
uint minimum;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Min3F,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, asuint(src0), asuint(src1), minimum);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Min3F,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, asuint(src2), minimum, minimum);
return asfloat(minimum);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Min3U
*
* Returns the minimum value of the three unsigned integer source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_Min3U(uint src0, uint src1, uint src2)
{
uint minimum;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Min3U,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, src0, src1, minimum);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Min3U,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, src2, minimum, minimum);
return minimum;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Med3F
*
* Returns the median value of the three floating point source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_Med3F(float src0, float src1, float src2)
{
uint median;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Med3F,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, asuint(src0), asuint(src1), median);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Med3F,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, asuint(src2), median, median);
return asfloat(median);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Med3U
*
* Returns the median value of the three unsigned integer source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_Med3U(uint src0, uint src1, uint src2)
{
uint median;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Med3U,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, src0, src1, median);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Med3U,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, src2, median, median);
return median;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Max3F
*
* Returns the maximum value of the three floating point source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_Max3F(float src0, float src1, float src2)
{
uint maximum;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Max3F,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, asuint(src0), asuint(src1), maximum);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Max3F,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, asuint(src2), maximum, maximum);
return asfloat(maximum);
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_Max3U
*
* Returns the maximum value of the three unsigned integer source arguments.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_Compare3) returned S_OK.
*
*************************************************************************************************************
*/
uint AmdDxExtShaderIntrinsics_Max3U(uint src0, uint src1, uint src2)
{
uint maximum;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Max3U,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, src0, src1, maximum);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_Max3U,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
0);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, src2, maximum, maximum);
return maximum;
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_IjBarycentricCoords
*
* Returns the (i, j) barycentric coordinate pair for this shader invocation with the specified
* interpolation mode at the specified pixel location. Should not be used for "pull-model" interpolation,
* PullModelBarycentricCoords should be used instead
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_BaryCoord) returned S_OK.
*
* Can only be used in pixel shader stages.
*
*************************************************************************************************************
*/
float2 AmdDxExtShaderIntrinsics_IjBarycentricCoords(uint interpMode)
{
uint2 retVal;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_BaryCoord,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
interpMode);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, 0, 0, retVal.x);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_BaryCoord,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
interpMode);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, retVal.x, 0, retVal.y);
return float2(asfloat(retVal.x), asfloat(retVal.y));
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_PullModelBarycentricCoords
*
* Returns the (1/W,1/I,1/J) coordinates at the pixel center which can be used for custom interpolation at
* any location in the pixel.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_BaryCoord) returned S_OK.
*
* Can only be used in pixel shader stages.
*
*************************************************************************************************************
*/
float3 AmdDxExtShaderIntrinsics_PullModelBarycentricCoords()
{
uint3 retVal;
uint instruction1 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_BaryCoord,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
AmdDxExtShaderIntrinsicsBarycentric_PerspPullModel);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction1, 0, 0, retVal.x);
uint instruction2 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_BaryCoord,
AmdDxExtShaderIntrinsicsOpcodePhase_1,
AmdDxExtShaderIntrinsicsBarycentric_PerspPullModel);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction2, retVal.x, 0, retVal.y);
uint instruction3 = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_BaryCoord,
AmdDxExtShaderIntrinsicsOpcodePhase_2,
AmdDxExtShaderIntrinsicsBarycentric_PerspPullModel);
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction3, retVal.y, 0, retVal.z);
return float3(asfloat(retVal.x), asfloat(retVal.y), asfloat(retVal.z));
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_VertexParameter
*
* Returns the triangle's parameter information at the specified triangle vertex.
* The vertex and parameter indices must specified as immediate values.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_VtxParam) returned S_OK.
*
* Only available in pixel shader stages.
*
*************************************************************************************************************
*/
float4 AmdDxExtShaderIntrinsics_VertexParameter(uint vertexIdx, uint parameterIdx)
{
uint4 retVal;
uint4 instruction;
instruction.x = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_VtxParam,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
((vertexIdx << AmdDxExtShaderIntrinsicsBarycentric_VtxShift) |
(parameterIdx << AmdDxExtShaderIntrinsicsBarycentric_ParamShift) |
(AmdDxExtShaderIntrinsicsBarycentric_ComponentX << AmdDxExtShaderIntrinsicsBarycentric_ComponentShift)));
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction.x, 0, 0, retVal.x);
instruction.y = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_VtxParam,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
((vertexIdx << AmdDxExtShaderIntrinsicsBarycentric_VtxShift) |
(parameterIdx << AmdDxExtShaderIntrinsicsBarycentric_ParamShift) |
(AmdDxExtShaderIntrinsicsBarycentric_ComponentY << AmdDxExtShaderIntrinsicsBarycentric_ComponentShift)));
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction.y, 0, 0, retVal.y);
instruction.z = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_VtxParam,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
((vertexIdx << AmdDxExtShaderIntrinsicsBarycentric_VtxShift) |
(parameterIdx << AmdDxExtShaderIntrinsicsBarycentric_ParamShift) |
(AmdDxExtShaderIntrinsicsBarycentric_ComponentZ << AmdDxExtShaderIntrinsicsBarycentric_ComponentShift)));
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction.z, 0, 0, retVal.z);
instruction.w = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_VtxParam,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
((vertexIdx << AmdDxExtShaderIntrinsicsBarycentric_VtxShift) |
(parameterIdx << AmdDxExtShaderIntrinsicsBarycentric_ParamShift) |
(AmdDxExtShaderIntrinsicsBarycentric_ComponentW << AmdDxExtShaderIntrinsicsBarycentric_ComponentShift)));
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction.w, 0, 0, retVal.w);
return float4(asfloat(retVal.x), asfloat(retVal.y), asfloat(retVal.z), asfloat(retVal.w));
}
/**
*************************************************************************************************************
* AmdDxExtShaderIntrinsics_VertexParameterComponent
*
* Returns the triangle's parameter information at the specified triangle vertex and component.
* The vertex, parameter and component indices must be specified as immediate values.
*
* Available if CheckSupport(AmdDxExtShaderIntrinsicsSupport_VtxParam) returned S_OK.
*
* Only available in pixel shader stages.
*
*************************************************************************************************************
*/
float AmdDxExtShaderIntrinsics_VertexParameterComponent(uint vertexIdx, uint parameterIdx, uint componentIdx)
{
uint retVal;
uint instruction = MakeAmdShaderIntrinsicsInstruction(AmdDxExtShaderIntrinsicsOpcode_VtxParam,
AmdDxExtShaderIntrinsicsOpcodePhase_0,
((vertexIdx << AmdDxExtShaderIntrinsicsBarycentric_VtxShift) |
(parameterIdx << AmdDxExtShaderIntrinsicsBarycentric_ParamShift) |
(componentIdx << AmdDxExtShaderIntrinsicsBarycentric_ComponentShift)));
AmdDxExtShaderIntrinsicsUAV.InterlockedCompareExchange(instruction, 0, 0, retVal);
return asfloat(retVal);
}
#endif // AMD_HLSL_EXTENSION
|