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