Merge pull request #2908 from Biswa96/cmake-spirv-remap
[platform/upstream/glslang.git] / Test / hlsl.promotions.frag
1
2 struct PS_OUTPUT
3 {
4     float4 Color : SV_Target0;
5 };
6
7 uniform int3    i3;
8 uniform bool3   b3;
9 uniform float3  f3;
10 uniform uint3   u3;
11 uniform double3 d3;
12
13 uniform int    is;
14 uniform bool   bs;
15 uniform float  fs;
16 uniform uint   us;
17 uniform double ds;
18
19 void Fn_F3(float3 x) { }
20 void Fn_I3(int3 x) { }
21 void Fn_U3(uint3 x) { }
22 void Fn_B3(bool3 x) { }
23 void Fn_D3(double3 x) { }
24
25 // ----------- Test implicit conversions on function returns -----------
26 float3  Fn_R_F3I(out float3 p) { p = i3; return i3; }
27 float3  Fn_R_F3U(out float3 p) { p = u3; return u3; }
28 float3  Fn_R_F3B(out float3 p) { p = b3; return b3; }
29 float3  Fn_R_F3D(out float3 p) { p = d3; return d3; }  // valid, but loss of precision on downconversion.
30
31 int3    Fn_R_I3U(out int3 p) { p = u3; return u3; }
32 int3    Fn_R_I3B(out int3 p) { p = b3; return b3; }
33 int3    Fn_R_I3F(out int3 p) { p = f3; return f3; }
34 int3    Fn_R_I3D(out int3 p) { p = d3; return d3; }  // valid, but loss of precision on downconversion.
35
36 uint3   Fn_R_U3I(out uint3 p) { p = i3; return i3; }
37 uint3   Fn_R_U3F(out uint3 p) { p = f3; return f3; }
38 uint3   Fn_R_U3B(out uint3 p) { p = b3; return b3; }
39 uint3   Fn_R_U3D(out uint3 p) { p = d3; return d3; }  // valid, but loss of precision on downconversion.
40
41 bool3   Fn_R_B3I(out bool3 p) { p = i3; return i3; }
42 bool3   Fn_R_B3U(out bool3 p) { p = u3; return u3; }
43 bool3   Fn_R_B3F(out bool3 p) { p = f3; return f3; }
44 bool3   Fn_R_B3D(out bool3 p) { p = d3; return d3; }
45
46 double3 Fn_R_D3I(out double3 p) { p = i3; return i3; }
47 double3 Fn_R_D3U(out double3 p) { p = u3; return u3; }
48 double3 Fn_R_D3B(out double3 p) { p = b3; return b3; }
49 double3 Fn_R_D3F(out double3 p) { p = f3; return f3; }
50
51 PS_OUTPUT main()
52 {
53     // ----------- assignment conversions -----------
54     float3 r00 = i3;
55     float3 r01 = b3;
56     float3 r02 = u3;
57     float3 r03 = d3;  // valid, but loss of precision on downconversion.
58
59     int3   r10 = b3;
60     int3   r11 = u3;
61     int3   r12 = f3;
62     int3   r13 = d3;  // valid, but loss of precision on downconversion.
63
64     uint3  r20 = b3;
65     uint3  r21 = i3;
66     uint3  r22 = f3;
67     uint3  r23 = d3;  // valid, but loss of precision on downconversion.
68
69     bool3  r30 = i3;
70     bool3  r31 = u3;
71     bool3  r32 = f3;
72     bool3  r33 = d3;
73
74     double3 r40 = i3;
75     double3 r41 = u3;
76     double3 r42 = f3;
77     double3 r43 = b3;
78
79     // ----------- assign ops: vector times vector ----------- 
80     r00 *= i3;
81     r01 *= b3;
82     r02 *= u3;
83     r03 *= d3;  // valid, but loss of precision on downconversion.
84     
85     r10 *= b3;
86     r11 *= u3;
87     r12 *= f3;
88     r13 *= d3;  // valid, but loss of precision on downconversion.
89     
90     r20 *= b3;
91     r21 *= i3;
92     r22 *= f3;
93     r23 *= d3;  // valid, but loss of precision on downconversion.
94
95     // No mul operator for bools
96     
97     r40 *= i3;
98     r41 *= u3;
99     r42 *= f3;
100     r43 *= b3;
101
102     // ----------- assign ops: vector times scalar ----------- 
103     r00 *= is;
104     r01 *= bs;
105     r02 *= us;
106     r03 *= ds;  // valid, but loss of precision on downconversion.
107     
108     r10 *= bs;
109     r11 *= us;
110     r12 *= fs;
111     r13 *= ds;  // valid, but loss of precision on downconversion.
112     
113     r20 *= bs;
114     r21 *= is;
115     r22 *= fs;
116     r23 *= ds;  // valid, but loss of precision on downconversion.
117
118     // No mul operator for bools
119     
120     r40 *= is;
121     r41 *= us;
122     r42 *= fs;
123     r43 *= bs;
124
125
126 #define FN_OVERLOADS 0 // change to 1 when overloads under promotions are in place
127
128 #if FN_OVERLOADS
129     Fn_F3(i3);
130     Fn_F3(u3);
131     Fn_F3(f3);
132     Fn_F3(b3);
133     Fn_F3(d3);  // valid, but loss of precision on downconversion.
134
135     Fn_I3(i3);
136     Fn_I3(u3);
137     Fn_I3(f3);
138     Fn_I3(b3);
139     Fn_I3(d3);  // valid, but loss of precision on downconversion.
140
141     Fn_U3(i3);
142     Fn_U3(u3);
143     Fn_U3(f3);
144     Fn_U3(b3);
145     Fn_U3(d3);  // valid, but loss of precision on downconversion.
146
147     Fn_B3(i3);
148     Fn_B3(u3);
149     Fn_B3(f3);
150     Fn_B3(b3);
151     Fn_B3(d3);
152
153     Fn_D3(i3);
154     Fn_D3(u3);
155     Fn_D3(f3);
156     Fn_D3(b3);
157     Fn_D3(d3);
158
159     Fn_F3(i3.x);
160     Fn_F3(u3.x);
161     Fn_F3(f3.x);
162     Fn_F3(b3.x);
163     Fn_F3(d3.x);  // valid, but loss of precision on downconversion.
164
165     Fn_I3(i3.x);
166     Fn_I3(u3.x);
167     Fn_I3(f3.x);
168     Fn_I3(b3.x);
169     Fn_I3(d3.x);  // valid, but loss of precision on downconversion.
170
171     Fn_U3(i3.x);
172     Fn_U3(u3.x);
173     Fn_U3(f3.x);
174     Fn_U3(b3.x);
175     Fn_U3(d3.x);  // valid, but loss of precision on downconversion.
176
177     Fn_B3(i3.x);
178     Fn_B3(u3.x);
179     Fn_B3(f3.x);
180     Fn_B3(b3.x);
181     Fn_B3(d3.x);
182
183     Fn_D3(i3.x);
184     Fn_D3(u3.x);
185     Fn_D3(f3.x);
186     Fn_D3(b3.x);
187     Fn_D3(d3.x);
188 #endif
189
190     const int   si = 3;
191     const float sf = 1.2;
192
193     int   c1 = si * sf;  // 3.6 (not 3!)
194     int   c2 = sf * si;  // 3.6 (not 3!)
195
196     float4 outval = float4(si * sf, sf*si, c1, c2);
197
198     PS_OUTPUT psout;
199     psout.Color = outval;
200     return psout;
201 }