1//
2// Copyright 2017 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Clear11.hlsl: Shaders for clearing RTVs and DSVs using draw calls and
8// specifying float depth values and either float, uint or sint clear colors.
9// Notes:
10//  - UINT & SINT clears can only be compiled with FL10+
11//  - VS_Clear_FL9 requires a VB to be bound with vertices to create
12//    a primitive covering the entire surface (in clip co-ordinates)
13
14// Constants
15static const float2 g_Corners[6] =
16{
17    float2(-1.0f,  1.0f),
18    float2( 1.0f, -1.0f),
19    float2(-1.0f, -1.0f),
20    float2(-1.0f,  1.0f),
21    float2( 1.0f,  1.0f),
22    float2( 1.0f, -1.0f),
23};
24
25// Vertex Shaders
26void VS_Clear(in uint id : SV_VertexID,
27              out float4 outPosition : SV_POSITION)
28{
29    float2 corner = g_Corners[id];
30    outPosition = float4(corner.x, corner.y, 0.0f, 1.0f);
31}
32
33void VS_Multiview_Clear(in uint id : SV_VertexID,
34                        in uint instanceID : SV_InstanceID,
35                        out float4 outPosition : SV_POSITION,
36                        out uint outLayerID : TEXCOORD0)
37{
38    float2 corner = g_Corners[id];
39    outPosition = float4(corner.x, corner.y, 0.0f, 1.0f);
40    outLayerID = instanceID;
41}
42
43void VS_Clear_FL9( in float4 inPosition : POSITION,
44                   out float4 outPosition : SV_POSITION)
45{
46    outPosition = inPosition;
47}
48
49// Geometry shader for clearing multiview layered textures
50struct GS_INPUT
51{
52    float4 inPosition : SV_Position;
53    uint inLayerID : TEXCOORD0;
54};
55
56struct GS_OUTPUT
57{
58    float4 outPosition : SV_Position;
59    uint outLayerID : SV_RenderTargetArrayIndex;
60};
61
62[maxvertexcount(3)]
63void GS_Multiview_Clear(triangle GS_INPUT input[3], inout TriangleStream<GS_OUTPUT> outStream)
64{
65    GS_OUTPUT output = (GS_OUTPUT)0;
66    for (int i = 0; i < 3; i++)
67    {
68        output.outPosition = input[i].inPosition;
69        output.outLayerID = input[i].inLayerID;
70        outStream.Append(output);
71    }
72    outStream.RestartStrip();
73}
74
75// Pixel Shader Constant Buffers
76cbuffer ColorAndDepthDataFloat : register(b0)
77{
78    float4 color_Float   : packoffset(c0);
79    float  zValueF_Float : packoffset(c1);
80}
81
82cbuffer ColorAndDepthDataSint : register(b0)
83{
84    int4  color_Sint   : packoffset(c0);
85    float zValueF_Sint : packoffset(c1);
86}
87
88cbuffer ColorAndDepthDataUint : register(b0)
89{
90    uint4 color_Uint   : packoffset(c0);
91    float zValueF_Uint : packoffset(c1);
92}
93
94cbuffer DepthOnlyData : register(b0)
95{
96    float zValue_Depth : packoffset(c1);
97}
98
99// Pixel Shader Output Structs
100struct PS_OutputFloat_FL9
101{
102    float4 color0 : SV_TARGET0;
103    float4 color1 : SV_TARGET1;
104    float4 color2 : SV_TARGET2;
105    float4 color3 : SV_TARGET3;
106    float  depth  : SV_DEPTH;
107};
108
109struct PS_OutputFloat1
110{
111    float4 color0 : SV_TARGET0;
112    float  depth  : SV_DEPTH;
113};
114
115struct PS_OutputFloat2
116{
117    float4 color0 : SV_TARGET0;
118    float4 color1 : SV_TARGET1;
119    float  depth  : SV_DEPTH;
120};
121
122struct PS_OutputFloat3
123{
124    float4 color0 : SV_TARGET0;
125    float4 color1 : SV_TARGET1;
126    float4 color2 : SV_TARGET2;
127    float  depth  : SV_DEPTH;
128};
129
130struct PS_OutputFloat4
131{
132    float4 color0 : SV_TARGET0;
133    float4 color1 : SV_TARGET1;
134    float4 color2 : SV_TARGET2;
135    float4 color3 : SV_TARGET3;
136    float  depth  : SV_DEPTH;
137};
138
139struct PS_OutputFloat5
140{
141    float4 color0 : SV_TARGET0;
142    float4 color1 : SV_TARGET1;
143    float4 color2 : SV_TARGET2;
144    float4 color3 : SV_TARGET3;
145    float4 color4 : SV_TARGET4;
146    float  depth  : SV_DEPTH;
147};
148
149struct PS_OutputFloat6
150{
151    float4 color0 : SV_TARGET0;
152    float4 color1 : SV_TARGET1;
153    float4 color2 : SV_TARGET2;
154    float4 color3 : SV_TARGET3;
155    float4 color4 : SV_TARGET4;
156    float4 color5 : SV_TARGET5;
157    float  depth  : SV_DEPTH;
158};
159
160struct PS_OutputFloat7
161{
162    float4 color0 : SV_TARGET0;
163    float4 color1 : SV_TARGET1;
164    float4 color2 : SV_TARGET2;
165    float4 color3 : SV_TARGET3;
166    float4 color4 : SV_TARGET4;
167    float4 color5 : SV_TARGET5;
168    float4 color6 : SV_TARGET6;
169    float  depth  : SV_DEPTH;
170};
171
172struct PS_OutputFloat8
173{
174    float4 color0 : SV_TARGET0;
175    float4 color1 : SV_TARGET1;
176    float4 color2 : SV_TARGET2;
177    float4 color3 : SV_TARGET3;
178    float4 color4 : SV_TARGET4;
179    float4 color5 : SV_TARGET5;
180    float4 color6 : SV_TARGET6;
181    float4 color7 : SV_TARGET7;
182    float  depth  : SV_DEPTH;
183};
184
185struct PS_OutputUint1
186{
187    uint4 color0 : SV_TARGET0;
188    float depth  : SV_DEPTH;
189};
190
191struct PS_OutputUint2
192{
193    uint4 color0 : SV_TARGET0;
194    uint4 color1 : SV_TARGET1;
195    float depth  : SV_DEPTH;
196};
197
198struct PS_OutputUint3
199{
200    uint4 color0 : SV_TARGET0;
201    uint4 color1 : SV_TARGET1;
202    uint4 color2 : SV_TARGET2;
203    float depth  : SV_DEPTH;
204};
205
206struct PS_OutputUint4
207{
208    uint4 color0 : SV_TARGET0;
209    uint4 color1 : SV_TARGET1;
210    uint4 color2 : SV_TARGET2;
211    uint4 color3 : SV_TARGET3;
212    float depth  : SV_DEPTH;
213};
214
215struct PS_OutputUint5
216{
217    uint4 color0 : SV_TARGET0;
218    uint4 color1 : SV_TARGET1;
219    uint4 color2 : SV_TARGET2;
220    uint4 color3 : SV_TARGET3;
221    uint4 color4 : SV_TARGET4;
222    float depth  : SV_DEPTH;
223};
224
225struct PS_OutputUint6
226{
227    uint4 color0 : SV_TARGET0;
228    uint4 color1 : SV_TARGET1;
229    uint4 color2 : SV_TARGET2;
230    uint4 color3 : SV_TARGET3;
231    uint4 color4 : SV_TARGET4;
232    uint4 color5 : SV_TARGET5;
233    float depth  : SV_DEPTH;
234};
235
236struct PS_OutputUint7
237{
238    uint4 color0 : SV_TARGET0;
239    uint4 color1 : SV_TARGET1;
240    uint4 color2 : SV_TARGET2;
241    uint4 color3 : SV_TARGET3;
242    uint4 color4 : SV_TARGET4;
243    uint4 color5 : SV_TARGET5;
244    uint4 color6 : SV_TARGET6;
245    float depth  : SV_DEPTH;
246};
247
248struct PS_OutputUint8
249{
250    uint4 color0 : SV_TARGET0;
251    uint4 color1 : SV_TARGET1;
252    uint4 color2 : SV_TARGET2;
253    uint4 color3 : SV_TARGET3;
254    uint4 color4 : SV_TARGET4;
255    uint4 color5 : SV_TARGET5;
256    uint4 color6 : SV_TARGET6;
257    uint4 color7 : SV_TARGET7;
258    float depth  : SV_DEPTH;
259};
260
261struct PS_OutputSint1
262{
263    int4 color0 : SV_TARGET0;
264    float depth : SV_DEPTH;
265};
266
267struct PS_OutputSint2
268{
269    int4 color0 : SV_TARGET0;
270    int4 color1 : SV_TARGET1;
271    float depth : SV_DEPTH;
272};
273
274struct PS_OutputSint3
275{
276    int4 color0 : SV_TARGET0;
277    int4 color1 : SV_TARGET1;
278    int4 color2 : SV_TARGET2;
279    float depth : SV_DEPTH;
280};
281
282struct PS_OutputSint4
283{
284    int4 color0 : SV_TARGET0;
285    int4 color1 : SV_TARGET1;
286    int4 color2 : SV_TARGET2;
287    int4 color3 : SV_TARGET3;
288    float depth : SV_DEPTH;
289};
290
291struct PS_OutputSint5
292{
293    int4 color0 : SV_TARGET0;
294    int4 color1 : SV_TARGET1;
295    int4 color2 : SV_TARGET2;
296    int4 color3 : SV_TARGET3;
297    int4 color4 : SV_TARGET4;
298    float depth : SV_DEPTH;
299};
300
301struct PS_OutputSint6
302{
303    int4 color0 : SV_TARGET0;
304    int4 color1 : SV_TARGET1;
305    int4 color2 : SV_TARGET2;
306    int4 color3 : SV_TARGET3;
307    int4 color4 : SV_TARGET4;
308    int4 color5 : SV_TARGET5;
309    float depth : SV_DEPTH;
310};
311
312struct PS_OutputSint7
313{
314    int4 color0 : SV_TARGET0;
315    int4 color1 : SV_TARGET1;
316    int4 color2 : SV_TARGET2;
317    int4 color3 : SV_TARGET3;
318    int4 color4 : SV_TARGET4;
319    int4 color5 : SV_TARGET5;
320    int4 color6 : SV_TARGET6;
321    float depth : SV_DEPTH;
322};
323
324struct PS_OutputSint8
325{
326    int4 color0 : SV_TARGET0;
327    int4 color1 : SV_TARGET1;
328    int4 color2 : SV_TARGET2;
329    int4 color3 : SV_TARGET3;
330    int4 color4 : SV_TARGET4;
331    int4 color5 : SV_TARGET5;
332    int4 color6 : SV_TARGET6;
333    int4 color7 : SV_TARGET7;
334    float depth : SV_DEPTH;
335};
336
337struct PS_OutputDepth
338{
339    float depth : SV_DEPTH;
340};
341
342// Pixel Shaders
343PS_OutputFloat_FL9 PS_ClearFloat_FL9(in float4 inPosition : SV_POSITION)
344{
345    PS_OutputFloat_FL9 outData;
346    outData.color0 = color_Float;
347    outData.color1 = color_Float;
348    outData.color2 = color_Float;
349    outData.color3 = color_Float;
350    outData.depth  = zValueF_Float;
351    return outData;
352}
353
354PS_OutputFloat1 PS_ClearFloat1(in float4 inPosition : SV_POSITION)
355{
356    PS_OutputFloat1 outData;
357    outData.color0 = color_Float;
358    outData.depth  = zValueF_Float;
359    return outData;
360}
361
362PS_OutputFloat2 PS_ClearFloat2(in float4 inPosition : SV_POSITION)
363{
364    PS_OutputFloat2 outData;
365    outData.color0 = color_Float;
366    outData.color1 = color_Float;
367    outData.depth  = zValueF_Float;
368    return outData;
369}
370
371PS_OutputFloat3 PS_ClearFloat3(in float4 inPosition : SV_POSITION)
372{
373    PS_OutputFloat3 outData;
374    outData.color0 = color_Float;
375    outData.color1 = color_Float;
376    outData.color2 = color_Float;
377    outData.depth  = zValueF_Float;
378    return outData;
379}
380
381PS_OutputFloat4 PS_ClearFloat4(in float4 inPosition : SV_POSITION)
382{
383    PS_OutputFloat4 outData;
384    outData.color0 = color_Float;
385    outData.color1 = color_Float;
386    outData.color2 = color_Float;
387    outData.color3 = color_Float;
388    outData.depth  = zValueF_Float;
389    return outData;
390}
391
392PS_OutputFloat5 PS_ClearFloat5(in float4 inPosition : SV_POSITION)
393{
394    PS_OutputFloat5 outData;
395    outData.color0 = color_Float;
396    outData.color1 = color_Float;
397    outData.color2 = color_Float;
398    outData.color3 = color_Float;
399    outData.color4 = color_Float;
400    outData.depth  = zValueF_Float;
401    return outData;
402}
403
404PS_OutputFloat6 PS_ClearFloat6(in float4 inPosition : SV_POSITION)
405{
406    PS_OutputFloat6 outData;
407    outData.color0 = color_Float;
408    outData.color1 = color_Float;
409    outData.color2 = color_Float;
410    outData.color3 = color_Float;
411    outData.color4 = color_Float;
412    outData.color5 = color_Float;
413    outData.depth  = zValueF_Float;
414    return outData;
415}
416
417PS_OutputFloat7 PS_ClearFloat7(in float4 inPosition : SV_POSITION)
418{
419    PS_OutputFloat7 outData;
420    outData.color0 = color_Float;
421    outData.color1 = color_Float;
422    outData.color2 = color_Float;
423    outData.color3 = color_Float;
424    outData.color4 = color_Float;
425    outData.color5 = color_Float;
426    outData.color6 = color_Float;
427    outData.depth  = zValueF_Float;
428    return outData;
429}
430
431PS_OutputFloat8 PS_ClearFloat8(in float4 inPosition : SV_POSITION)
432{
433    PS_OutputFloat8 outData;
434    outData.color0 = color_Float;
435    outData.color1 = color_Float;
436    outData.color2 = color_Float;
437    outData.color3 = color_Float;
438    outData.color4 = color_Float;
439    outData.color5 = color_Float;
440    outData.color6 = color_Float;
441    outData.color7 = color_Float;
442    outData.depth  = zValueF_Float;
443    return outData;
444}
445
446PS_OutputUint1 PS_ClearUint1(in float4 inPosition : SV_POSITION)
447{
448    PS_OutputUint1 outData;
449    outData.color0 = color_Uint;
450    outData.depth = zValueF_Uint;
451    return outData;
452}
453
454PS_OutputUint2 PS_ClearUint2(in float4 inPosition : SV_POSITION)
455{
456    PS_OutputUint2 outData;
457    outData.color0 = color_Uint;
458    outData.color1 = color_Uint;
459    outData.depth = zValueF_Uint;
460    return outData;
461}
462
463PS_OutputUint3 PS_ClearUint3(in float4 inPosition : SV_POSITION)
464{
465    PS_OutputUint3 outData;
466    outData.color0 = color_Uint;
467    outData.color1 = color_Uint;
468    outData.color2 = color_Uint;
469    outData.depth = zValueF_Uint;
470    return outData;
471}
472
473PS_OutputUint4 PS_ClearUint4(in float4 inPosition : SV_POSITION)
474{
475    PS_OutputUint4 outData;
476    outData.color0 = color_Uint;
477    outData.color1 = color_Uint;
478    outData.color2 = color_Uint;
479    outData.color3 = color_Uint;
480    outData.depth = zValueF_Uint;
481    return outData;
482}
483
484PS_OutputUint5 PS_ClearUint5(in float4 inPosition : SV_POSITION)
485{
486    PS_OutputUint5 outData;
487    outData.color0 = color_Uint;
488    outData.color1 = color_Uint;
489    outData.color2 = color_Uint;
490    outData.color3 = color_Uint;
491    outData.color4 = color_Uint;
492    outData.depth = zValueF_Uint;
493    return outData;
494}
495
496PS_OutputUint6 PS_ClearUint6(in float4 inPosition : SV_POSITION)
497{
498    PS_OutputUint6 outData;
499    outData.color0 = color_Uint;
500    outData.color1 = color_Uint;
501    outData.color2 = color_Uint;
502    outData.color3 = color_Uint;
503    outData.color4 = color_Uint;
504    outData.color5 = color_Uint;
505    outData.depth = zValueF_Uint;
506    return outData;
507}
508
509PS_OutputUint7 PS_ClearUint7(in float4 inPosition : SV_POSITION)
510{
511    PS_OutputUint7 outData;
512    outData.color0 = color_Uint;
513    outData.color1 = color_Uint;
514    outData.color2 = color_Uint;
515    outData.color3 = color_Uint;
516    outData.color4 = color_Uint;
517    outData.color5 = color_Uint;
518    outData.color6 = color_Uint;
519    outData.depth = zValueF_Uint;
520    return outData;
521}
522
523PS_OutputUint8 PS_ClearUint8(in float4 inPosition : SV_POSITION)
524{
525    PS_OutputUint8 outData;
526    outData.color0 = color_Uint;
527    outData.color1 = color_Uint;
528    outData.color2 = color_Uint;
529    outData.color3 = color_Uint;
530    outData.color4 = color_Uint;
531    outData.color5 = color_Uint;
532    outData.color6 = color_Uint;
533    outData.color7 = color_Uint;
534    outData.depth = zValueF_Uint;
535    return outData;
536}
537
538PS_OutputSint1 PS_ClearSint1(in float4 inPosition : SV_POSITION)
539{
540    PS_OutputSint1 outData;
541    outData.color0 = color_Sint;
542    outData.depth = zValueF_Sint;
543    return outData;
544}
545
546PS_OutputSint2 PS_ClearSint2(in float4 inPosition : SV_POSITION)
547{
548    PS_OutputSint2 outData;
549    outData.color0 = color_Sint;
550    outData.color1 = color_Sint;
551    outData.depth = zValueF_Sint;
552    return outData;
553}
554
555PS_OutputSint3 PS_ClearSint3(in float4 inPosition : SV_POSITION)
556{
557    PS_OutputSint3 outData;
558    outData.color0 = color_Sint;
559    outData.color1 = color_Sint;
560    outData.color2 = color_Sint;
561    outData.depth = zValueF_Sint;
562    return outData;
563}
564
565PS_OutputSint4 PS_ClearSint4(in float4 inPosition : SV_POSITION)
566{
567    PS_OutputSint4 outData;
568    outData.color0 = color_Sint;
569    outData.color1 = color_Sint;
570    outData.color2 = color_Sint;
571    outData.color3 = color_Sint;
572    outData.depth = zValueF_Sint;
573    return outData;
574}
575
576PS_OutputSint5 PS_ClearSint5(in float4 inPosition : SV_POSITION)
577{
578    PS_OutputSint5 outData;
579    outData.color0 = color_Sint;
580    outData.color1 = color_Sint;
581    outData.color2 = color_Sint;
582    outData.color3 = color_Sint;
583    outData.color4 = color_Sint;
584    outData.depth = zValueF_Sint;
585    return outData;
586}
587
588PS_OutputSint6 PS_ClearSint6(in float4 inPosition : SV_POSITION)
589{
590    PS_OutputSint6 outData;
591    outData.color0 = color_Sint;
592    outData.color1 = color_Sint;
593    outData.color2 = color_Sint;
594    outData.color3 = color_Sint;
595    outData.color4 = color_Sint;
596    outData.color5 = color_Sint;
597    outData.depth = zValueF_Sint;
598    return outData;
599}
600
601PS_OutputSint7 PS_ClearSint7(in float4 inPosition : SV_POSITION)
602{
603    PS_OutputSint7 outData;
604    outData.color0 = color_Sint;
605    outData.color1 = color_Sint;
606    outData.color2 = color_Sint;
607    outData.color3 = color_Sint;
608    outData.color4 = color_Sint;
609    outData.color5 = color_Sint;
610    outData.color6 = color_Sint;
611    outData.depth = zValueF_Sint;
612    return outData;
613}
614
615PS_OutputSint8 PS_ClearSint8(in float4 inPosition : SV_POSITION)
616{
617    PS_OutputSint8 outData;
618    outData.color0 = color_Sint;
619    outData.color1 = color_Sint;
620    outData.color2 = color_Sint;
621    outData.color3 = color_Sint;
622    outData.color4 = color_Sint;
623    outData.color5 = color_Sint;
624    outData.color6 = color_Sint;
625    outData.color7 = color_Sint;
626    outData.depth = zValueF_Sint;
627    return outData;
628}
629
630PS_OutputDepth PS_ClearDepth(in float4 inPosition : SV_POSITION)
631{
632    PS_OutputDepth outData;
633    outData.depth = zValue_Depth;
634    return outData;
635}
636