kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / d3dx9_36 / tests / asm.c
blob276a6e2a41a39ed73a81a4c02d4dea8e13eef5c9
1 /*
2 * Copyright (C) 2008 Stefan Dösinger
3 * Copyright (C) 2009 Matteo Bruni
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #include "wine/test.h"
22 #include <d3dx9.h>
24 #include "resources.h"
26 struct shader_test {
27 const char *text;
28 const DWORD bytes[128];
31 static HRESULT create_file(const char *filename, const char *data, const unsigned int size)
33 DWORD received;
34 HANDLE hfile;
36 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
37 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
39 if(WriteFile(hfile, data, size, &received, NULL))
41 CloseHandle(hfile);
42 return D3D_OK;
45 CloseHandle(hfile);
46 return D3DERR_INVALIDCALL;
49 static void dump_shader(DWORD *shader) {
50 unsigned int i = 0, j = 0;
51 do {
52 trace("0x%08x ", shader[i]);
53 j++;
54 i++;
55 if(j == 6) trace("\n");
56 } while(shader[i - 1] != D3DSIO_END);
57 if(j != 6) trace("\n");
60 static void exec_tests(const char *name, struct shader_test tests[], unsigned int count) {
61 HRESULT hr;
62 DWORD *res;
63 unsigned int i, j;
64 BOOL diff;
65 LPD3DXBUFFER shader, messages;
67 for(i = 0; i < count; i++) {
68 /* D3DXAssembleShader sets messages to 0 if there aren't error messages */
69 messages = NULL;
70 hr = D3DXAssembleShader(tests[i].text, strlen(tests[i].text),
71 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
72 &shader, &messages);
73 ok(hr == D3D_OK, "Test %s, shader %d: D3DXAssembleShader failed with error 0x%x - %d\n", name, i, hr, hr & 0x0000FFFF);
74 if(messages) {
75 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
76 ID3DXBuffer_Release(messages);
78 if(FAILED(hr)) continue;
80 j = 0;
81 diff = FALSE;
82 res = ID3DXBuffer_GetBufferPointer(shader);
83 while(res[j] != D3DSIO_END && tests[i].bytes[j] != D3DSIO_END) {
84 if(res[j] != tests[i].bytes[j]) diff = TRUE;
85 j++;
87 /* Both must have an end token */
88 if(res[j] != tests[i].bytes[j]) diff = TRUE;
90 if(diff) {
91 ok(FALSE, "Test %s, shader %d: Generated code differs\n", name, i);
92 dump_shader(res);
94 ID3DXBuffer_Release(shader);
98 static void preproc_test(void) {
99 struct shader_test tests[] = {
100 { /* shader 0 */
101 "vs.1.1\r\n"
102 "//some comments\r\n"
103 "//other comments\n"
104 "; yet another comment\r\n"
105 "add r0, r0, r1\n",
106 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
108 { /* shader 1 */
109 "#line 1 \"vertex.vsh\"\n"
110 "vs.1.1\n",
111 {0xfffe0101, 0x0000ffff}
113 { /* shader 2 */
114 "#define REG 1 + 2 +\\\n"
115 "3 + 4\n"
116 "vs.1.1\n"
117 "mov r0, c0[ REG ]\n",
118 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4000a, 0x0000ffff}
122 exec_tests("preproc", tests, sizeof(tests) / sizeof(tests[0]));
125 static void ps_1_1_test(void) {
126 struct shader_test tests[] = {
127 { /* shader 0 */
128 "ps.1.1\r\n"
129 "tex t0\r\n"
130 "add r0.rgb, r0, r1\r\n"
131 "+mov r0.a, t0\r\n",
132 {0xffff0101, 0x00000042, 0xb00f0000, 0x00000002, 0x80070000, 0x80e40000,
133 0x80e40001, 0x40000001, 0x80080000, 0xb0e40000, 0x0000ffff}
137 exec_tests("ps_1_1", tests, sizeof(tests) / sizeof(tests[0]));
140 static void vs_1_1_test(void) {
141 struct shader_test tests[] = {
142 /* Basic instruction tests */
143 { /* shader 0 */
144 "vs_1_1\n"
145 "add r0, r1, r2\n",
146 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
148 { /* shader 1 */
149 "vs_1_1\n"
150 "nop\n",
151 {0xfffe0101, 0x00000000, 0x0000ffff}
153 /* Output register tests */
154 { /* shader 2 */
155 "vs_1_1\n"
156 "mov oPos, c0\n",
157 {0xfffe0101, 0x00000001, 0xc00f0000, 0xa0e40000, 0x0000ffff}
159 { /* shader 3 */
160 "vs_1_1\n"
161 "mov oT0, c0\n",
162 {0xfffe0101, 0x00000001, 0xe00f0000, 0xa0e40000, 0x0000ffff}
164 { /* shader 4 */
165 "vs_1_1\n"
166 "mov oT5, c0\n",
167 {0xfffe0101, 0x00000001, 0xe00f0005, 0xa0e40000, 0x0000ffff}
169 { /* shader 5 */
170 "vs_1_1\n"
171 "mov oD0, c0\n",
172 {0xfffe0101, 0x00000001, 0xd00f0000, 0xa0e40000, 0x0000ffff}
174 { /* shader 6 */
175 "vs_1_1\n"
176 "mov oD1, c0\n",
177 {0xfffe0101, 0x00000001, 0xd00f0001, 0xa0e40000, 0x0000ffff}
179 { /* shader 7 */
180 "vs_1_1\n"
181 "mov oFog, c0.x\n",
182 {0xfffe0101, 0x00000001, 0xc00f0001, 0xa0000000, 0x0000ffff}
184 { /* shader 8 */
185 "vs_1_1\n"
186 "mov oPts, c0.x\n",
187 {0xfffe0101, 0x00000001, 0xc00f0002, 0xa0000000, 0x0000ffff}
189 /* A bunch of tests for declarations */
190 { /* shader 9 */
191 "vs_1_1\n"
192 "dcl_position0 v0",
193 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000ffff}
195 { /* shader 10 */
196 "vs_1_1\n"
197 "dcl_position v1",
198 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0001, 0x0000ffff}
200 { /* shader 11 */
201 "vs_1_1\n"
202 "dcl_normal12 v15",
203 {0xfffe0101, 0x0000001f, 0x800c0003, 0x900f000f, 0x0000ffff}
205 { /* shader 12 */
206 "vs_1_1\n"
207 "add r0, v0, v1\n",
208 {0xfffe0101, 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, 0x0000ffff}
210 { /* shader 13 */
211 "vs_1_1\n"
212 "def c12, 0, -1, -0.5, 1024\n",
213 {0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
214 0x44800000, 0x0000ffff}
216 { /* shader 14: writemasks, swizzles */
217 "vs_1_1\n"
218 "dp4 r0.xw, r1.wzyx, r2.xxww\n",
219 {0xfffe0101, 0x00000009, 0x80090000, 0x801b0001, 0x80f00002, 0x0000ffff}
221 { /* shader 15: negation input modifier. Other modifiers not supprted in vs_1_1 */
222 "vs_1_1\n"
223 "add r0, -r0.x, -r1\n",
224 {0xfffe0101, 0x00000002, 0x800f0000, 0x81000000, 0x81e40001, 0x0000ffff}
226 { /* shader 16: relative addressing */
227 "vs_1_1\n"
228 "mov r0, c0[a0.x]\n",
229 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42000, 0x0000ffff}
231 { /* shader 17: relative addressing */
232 "vs_1_1\n"
233 "mov r0, c1[a0.x + 2]\n",
234 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42003, 0x0000ffff}
236 { /* shader 18 */
237 "vs_1_1\n"
238 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
239 {0xfffe0101, 0x00000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
240 0x3f000000, 0x0000ffff}
242 /* Other relative addressing tests */
243 { /* shader 19 */
244 "vs_1_1\n"
245 "mov r0, c[ a0.x + 12 ]\n",
246 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200c, 0x0000ffff}
248 { /* shader 20 */
249 "vs_1_1\n"
250 "mov r0, c[ 2 + a0.x ]\n",
251 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42002, 0x0000ffff}
253 { /* shader 21 */
254 "vs_1_1\n"
255 "mov r0, c[ 2 + a0.x + 12 ]\n",
256 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200e, 0x0000ffff}
258 { /* shader 22 */
259 "vs_1_1\n"
260 "mov r0, c[ 2 + 10 + 12 ]\n",
261 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40018, 0x0000ffff}
263 { /* shader 23 */
264 "vs_1_1\n"
265 "mov r0, c4[ 2 ]\n",
266 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40006, 0x0000ffff}
268 { /* shader 24 */
269 "vs_1_1\n"
270 "rcp r0, v0.x\n",
271 {0xfffe0101, 0x00000006, 0x800f0000, 0x90000000, 0x0000ffff}
273 { /* shader 25 */
274 "vs_1_1\n"
275 "rsq r0, v0.x\n",
276 {0xfffe0101, 0x00000007, 0x800f0000, 0x90000000, 0x0000ffff}
280 exec_tests("vs_1_1", tests, sizeof(tests) / sizeof(tests[0]));
283 static void ps_1_3_test(void) {
284 struct shader_test tests[] = {
285 /* Basic instruction tests */
286 { /* shader 0 */
287 "ps_1_3\n"
288 "mov r0, r1\n",
289 {0xffff0103, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
291 { /* shader 1 */
292 "ps_1_3\n"
293 "add r0, r1, r0\n",
294 {0xffff0103, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40000, 0x0000ffff}
296 /* Color interpolator tests */
297 { /* shader 2 */
298 "ps_1_3\n"
299 "mov r0, v0\n",
300 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40000, 0x0000ffff}
302 { /* shader 3 */
303 "ps_1_3\n"
304 "mov r0, v1\n",
305 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
307 /* Texture sampling instructions */
308 { /* shader 4 */
309 "ps_1_3\n"
310 "tex t0\n",
311 {0xffff0103, 0x00000042, 0xb00f0000, 0x0000ffff}
313 { /* shader 5 */
314 "ps_1_3\n"
315 "tex t0\n"
316 "texreg2ar t1, t0\n",
317 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000045, 0xb00f0001, 0xb0e40000,
318 0x0000ffff}
320 { /* shader 6 */
321 "ps_1_3\n"
322 "tex t0\n"
323 "texreg2gb t1, t0\n",
324 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000046, 0xb00f0001, 0xb0e40000,
325 0x0000ffff}
327 { /* shader 7 */
328 "ps_1_3\n"
329 "tex t0\n"
330 "texreg2rgb t1, t0\n",
331 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000052, 0xb00f0001, 0xb0e40000,
332 0x0000ffff}
334 { /* shader 8 */
335 "ps_1_3\n"
336 "cnd r0, r1, r0, v0\n",
337 {0xffff0103, 0x00000050, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
338 0x0000ffff}
340 { /* shader 9 */
341 "ps_1_3\n"
342 "cmp r0, r1, r0, v0\n",
343 {0xffff0103, 0x00000058, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
344 0x0000ffff}
346 { /* shader 10 */
347 "ps_1_3\n"
348 "texkill t0\n",
349 {0xffff0103, 0x00000041, 0xb00f0000, 0x0000ffff}
351 { /* shader 11 */
352 "ps_1_3\n"
353 "tex t0\n"
354 "texm3x2pad t1, t0\n"
355 "texm3x2tex t2, t0\n",
356 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
357 0x00000048, 0xb00f0002, 0xb0e40000, 0x0000ffff}
359 { /* shader 12 */
360 "ps_1_3\n"
361 "tex t0\n"
362 "texm3x2pad t1, t0\n"
363 "texm3x2depth t2, t0\n",
364 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
365 0x00000054, 0xb00f0002, 0xb0e40000, 0x0000ffff}
367 { /* shader 13 */
368 "ps_1_3\n"
369 "tex t0\n"
370 "texbem t1, t0\n",
371 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000043, 0xb00f0001, 0xb0e40000,
372 0x0000ffff}
374 { /* shader 14 */
375 "ps_1_3\n"
376 "tex t0\n"
377 "texbeml t1, t0\n",
378 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000044, 0xb00f0001, 0xb0e40000,
379 0x0000ffff}
381 { /* shader 15 */
382 "ps_1_3\n"
383 "tex t0\n"
384 "texdp3tex t1, t0\n",
385 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb00f0001, 0xb0e40000,
386 0x0000ffff}
388 { /* shader 16 */
389 "ps_1_3\n"
390 "tex t0\n"
391 "texdp3 t1, t0\n",
392 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000055, 0xb00f0001, 0xb0e40000,
393 0x0000ffff}
395 { /* shader 17 */
396 "ps_1_3\n"
397 "tex t0\n"
398 "texm3x3pad t1, t0\n"
399 "texm3x3pad t2, t0\n"
400 "texm3x3tex t3, t0\n",
401 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
402 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004a, 0xb00f0003, 0xb0e40000,
403 0x0000ffff}
405 { /* shader 18 */
406 "ps_1_3\n"
407 "tex t0\n"
408 "texm3x3pad t1, t0\n"
409 "texm3x3pad t2, t0\n"
410 "texm3x3 t3, t0\n",
411 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
412 0x00000049, 0xb00f0002, 0xb0e40000, 0x00000056, 0xb00f0003, 0xb0e40000,
413 0x0000ffff}
415 { /* shader 19 */
416 "ps_1_3\n"
417 "tex t0\n"
418 "texm3x3pad t1, t0\n"
419 "texm3x3pad t2, t0\n"
420 "texm3x3spec t3, t0, c0\n",
421 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
422 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004c, 0xb00f0003, 0xb0e40000,
423 0xa0e40000, 0x0000ffff}
425 { /* shader 20 */
426 "ps_1_3\n"
427 "tex t0\n"
428 "texm3x3pad t1, t0\n"
429 "texm3x3pad t2, t0\n"
430 "texm3x3vspec t3, t0\n",
431 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
432 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004d, 0xb00f0003, 0xb0e40000,
433 0x0000ffff}
435 { /* shader 21 */
436 "ps_1_3\n"
437 "texcoord t0\n",
438 {0xffff0103, 0x00000040, 0xb00f0000, 0x0000ffff}
440 /* Modifiers, shifts */
441 { /* shader 22 */
442 "ps_1_3\n"
443 "mov_x2_sat r0, 1 - r1\n",
444 {0xffff0103, 0x00000001, 0x811f0000, 0x86e40001, 0x0000ffff}
446 { /* shader 23 */
447 "ps_1_3\n"
448 "mov_d8 r0, -r1\n",
449 {0xffff0103, 0x00000001, 0x8d0f0000, 0x81e40001, 0x0000ffff}
451 { /* shader 24 */
452 "ps_1_3\n"
453 "mov_sat r0, r1_bx2\n",
454 {0xffff0103, 0x00000001, 0x801f0000, 0x84e40001, 0x0000ffff}
456 { /* shader 25 */
457 "ps_1_3\n"
458 "mov_sat r0, r1_bias\n",
459 {0xffff0103, 0x00000001, 0x801f0000, 0x82e40001, 0x0000ffff}
461 { /* shader 26 */
462 "ps_1_3\n"
463 "mov_sat r0, -r1_bias\n",
464 {0xffff0103, 0x00000001, 0x801f0000, 0x83e40001, 0x0000ffff}
466 { /* shader 27 */
467 "ps_1_3\n"
468 "mov_sat r0, -r1_bx2\n",
469 {0xffff0103, 0x00000001, 0x801f0000, 0x85e40001, 0x0000ffff}
471 { /* shader 28 */
472 "ps_1_3\n"
473 "mov_sat r0, -r1_x2\n",
474 {0xffff0103, 0x00000001, 0x801f0000, 0x88e40001, 0x0000ffff}
476 { /* shader 29 */
477 "ps_1_3\n"
478 "mov_x4_sat r0.a, -r1_bx2.a\n",
479 {0xffff0103, 0x00000001, 0x82180000, 0x85ff0001, 0x0000ffff}
483 exec_tests("ps_1_3", tests, sizeof(tests) / sizeof(tests[0]));
486 static void ps_1_4_test(void) {
487 struct shader_test tests[] = {
488 /* Basic instruction tests */
489 { /* shader 0 */
490 "ps_1_4\n"
491 "mov r0, r1\n",
492 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
494 { /* shader 1 */
495 "ps_1_4\n"
496 "mov r0, r5\n",
497 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40005, 0x0000ffff}
499 { /* shader 2 */
500 "ps_1_4\n"
501 "mov r0, c7\n",
502 {0xffff0104, 0x00000001, 0x800f0000, 0xa0e40007, 0x0000ffff}
504 { /* shader 3 */
505 "ps_1_4\n"
506 "mov r0, v1\n",
507 {0xffff0104, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
509 { /* shader 4 */
510 "ps_1_4\n"
511 "phase\n",
512 {0xffff0104, 0x0000fffd, 0x0000ffff}
514 { /* shader 5 */
515 "ps_1_4\n"
516 "texcrd r0, t0\n",
517 {0xffff0104, 0x00000040, 0x800f0000, 0xb0e40000, 0x0000ffff}
519 { /* shader 6 */
520 "ps_1_4\n"
521 "texcrd r4, t3\n",
522 {0xffff0104, 0x00000040, 0x800f0004, 0xb0e40003, 0x0000ffff}
524 { /* shader 7 */
525 "ps_1_4\n"
526 "texcrd_sat r4, t3\n",
527 {0xffff0104, 0x00000040, 0x801f0004, 0xb0e40003, 0x0000ffff}
529 { /* shader 8 */
530 "ps_1_4\n"
531 "texld r0, t0\n",
532 {0xffff0104, 0x00000042, 0x800f0000, 0xb0e40000, 0x0000ffff}
534 { /* shader 9 */
535 "ps_1_4\n"
536 "texld r1, t4\n",
537 {0xffff0104, 0x00000042, 0x800f0001, 0xb0e40004, 0x0000ffff}
539 { /* shader 10 */
540 "ps_1_4\n"
541 "texld r5, r0\n",
542 {0xffff0104, 0x00000042, 0x800f0005, 0x80e40000, 0x0000ffff}
544 { /* shader 11 */
545 "ps_1_4\n"
546 "texld r5, c0\n", /* Assembly succeeds, validation fails */
547 {0xffff0104, 0x00000042, 0x800f0005, 0xa0e40000, 0x0000ffff}
549 { /* shader 12 */
550 "ps_1_4\n"
551 "texld r5, r2_dz\n",
552 {0xffff0104, 0x00000042, 0x800f0005, 0x89e40002, 0x0000ffff}
554 { /* shader 13 */
555 "ps_1_4\n"
556 "bem r1.rg, c0, r0\n",
557 {0xffff0104, 0x00000059, 0x80030001, 0xa0e40000, 0x80e40000, 0x0000ffff}
559 { /* shader 14 */
560 "ps_1_4\n"
561 "texdepth r5\n",
562 {0xffff0104, 0x00000057, 0x800f0005, 0x0000ffff}
566 exec_tests("ps_1_4", tests, sizeof(tests) / sizeof(tests[0]));
569 static void vs_2_0_test(void) {
570 struct shader_test tests[] = {
571 /* Basic instruction tests */
572 { /* shader 0 */
573 "vs_2_0\n"
574 "mov r0, r1\n",
575 {0xfffe0200, 0x02000001, 0x800f0000, 0x80e40001, 0x0000ffff}
577 { /* shader 1 */
578 "vs_2_0\n"
579 "lrp r0, v0, c0, r1\n",
580 {0xfffe0200, 0x04000012, 0x800f0000, 0x90e40000, 0xa0e40000, 0x80e40001,
581 0x0000ffff}
583 { /* shader 2 */
584 "vs_2_0\n"
585 "dp4 oPos, v0, c0\n",
586 {0xfffe0200, 0x03000009, 0xc00f0000, 0x90e40000, 0xa0e40000, 0x0000ffff}
588 { /* shader 3 */
589 "vs_2_0\n"
590 "mov r0, c0[a0.x]\n",
591 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0000000, 0x0000ffff}
593 { /* shader 4 */
594 "vs_2_0\n"
595 "mov r0, c0[a0.y]\n",
596 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0550000, 0x0000ffff}
598 { /* shader 5 */
599 "vs_2_0\n"
600 "mov r0, c0[a0.z]\n",
601 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0aa0000, 0x0000ffff}
603 { /* shader 6 */
604 "vs_2_0\n"
605 "mov r0, c0[a0.w]\n",
606 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0ff0000, 0x0000ffff}
608 { /* shader 7 */
609 "vs_2_0\n"
610 "mov r0, c0[a0.w].x\n",
611 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0002000, 0xb0ff0000, 0x0000ffff}
613 { /* shader 8 */
614 "vs_2_0\n"
615 "mov r0, -c0[a0.w+5].x\n",
616 {0xfffe0200, 0x03000001, 0x800f0000, 0xa1002005, 0xb0ff0000, 0x0000ffff}
618 { /* shader 9 */
619 "vs_2_0\n"
620 "mov r0, c0[a0]\n",
621 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0e40000, 0x0000ffff}
623 { /* shader 10 */
624 "vs_2_0\n"
625 "mov r0, c0[a0.xyww]\n",
626 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0f40000, 0x0000ffff}
628 { /* shader 11 */
629 "vs_2_0\n"
630 "add r0, c0[a0.x], c1[a0.y]\n", /* validation would fail on this line */
631 {0xfffe0200, 0x05000002, 0x800f0000, 0xa0e42000, 0xb0000000, 0xa0e42001,
632 0xb0550000, 0x0000ffff}
634 { /* shader 12 */
635 "vs_2_0\n"
636 "rep i0\n"
637 "endrep\n",
638 {0xfffe0200, 0x01000026, 0xf0e40000, 0x00000027, 0x0000ffff}
640 { /* shader 13 */
641 "vs_2_0\n"
642 "if b0\n"
643 "else\n"
644 "endif\n",
645 {0xfffe0200, 0x01000028, 0xe0e40800, 0x0000002a, 0x0000002b, 0x0000ffff}
647 { /* shader 14 */
648 "vs_2_0\n"
649 "loop aL, i0\n"
650 "endloop\n",
651 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x0000001d, 0x0000ffff}
653 { /* shader 15 */
654 "vs_2_0\n"
655 "nrm r0, c0\n",
656 {0xfffe0200, 0x02000024, 0x800f0000, 0xa0e40000, 0x0000ffff}
658 { /* shader 16 */
659 "vs_2_0\n"
660 "crs r0, r1, r2\n",
661 {0xfffe0200, 0x03000021, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
663 { /* shader 17 */
664 "vs_2_0\n"
665 "sgn r0, r1, r2, r3\n",
666 {0xfffe0200, 0x04000022, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
667 0x0000ffff}
669 { /* shader 18 */
670 "vs_2_0\n"
671 "sincos r0, r1, r2, r3\n",
672 {0xfffe0200, 0x04000025, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
673 0x0000ffff}
675 { /* shader 19 */
676 "vs_2_0\n"
677 "pow r0, r1, r2\n",
678 {0xfffe0200, 0x03000020, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
680 { /* shader 20 */
681 "vs_2_0\n"
682 "mova a0.y, c0.z\n",
683 {0xfffe0200, 0x0200002e, 0xb0020000, 0xa0aa0000, 0x0000ffff}
685 { /* shader 21 */
686 "vs_2_0\n"
687 "defb b0, true\n"
688 "defb b1, false\n",
689 {0xfffe0200, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
690 0x00000000, 0x0000ffff}
692 { /* shader 22 */
693 "vs_2_0\n"
694 "defi i0, -1, 1, 10, 0\n"
695 "defi i1, 0, 40, 30, 10\n",
696 {0xfffe0200, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
697 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
698 0x0000000a, 0x0000ffff}
700 { /* shader 23 */
701 "vs_2_0\n"
702 "loop aL, i0\n"
703 "mov r0, c0[aL]\n"
704 "endloop\n",
705 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
706 0xa0e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
708 { /* shader 24 */
709 "vs_2_0\n"
710 "call l0\n"
711 "ret\n"
712 "label l0\n"
713 "ret\n",
714 {0xfffe0200, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
715 0x0000001c, 0x0000ffff}
717 { /* shader 25 */
718 "vs_2_0\n"
719 "callnz l0, b0\n"
720 "ret\n"
721 "label l0\n"
722 "ret\n",
723 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
724 0xa0e41000, 0x0000001c, 0x0000ffff}
726 { /* shader 26 */
727 "vs_2_0\n"
728 "callnz l0, !b0\n"
729 "ret\n"
730 "label l0\n"
731 "ret\n",
732 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
733 0xa0e41000, 0x0000001c, 0x0000ffff}
735 { /* shader 27 */
736 "vs_2_0\n"
737 "if !b0\n"
738 "else\n"
739 "endif\n",
740 {0xfffe0200, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
742 { /* shader 28 */
743 "vs_2_0\n"
744 "call l3\n"
745 "ret\n"
746 "label l3\n"
747 "ret\n",
748 {0xfffe0200, 0x01000019, 0xa0e41003, 0x0000001c, 0x0100001e, 0xa0e41003, 0x0000001c, 0x0000ffff}
750 { /* shader 29: labels up to 2047 are accepted even in vs_2_0 */
751 "vs_2_0\n"
752 "call l2047\n",
753 {0xfffe0200, 0x01000019, 0xa0e417ff, 0x0000ffff}
757 exec_tests("vs_2_0", tests, sizeof(tests) / sizeof(tests[0]));
760 static void vs_2_x_test(void) {
761 struct shader_test tests[] = {
762 { /* shader 0 */
763 "vs_2_x\n"
764 "rep i0\n"
765 "break\n"
766 "endrep\n",
767 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
769 { /* shader 1 */
770 "vs_2_x\n"
771 "if_ge r0, r1\n"
772 "endif\n",
773 {0xfffe0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
775 { /* shader 2 */
776 "vs_2_x\n"
777 "rep i0\n"
778 "break_ne r0, r1\n"
779 "endrep",
780 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
781 0x00000027, 0x0000ffff}
784 /* predicates */
785 { /* shader 3 */
786 "vs_2_x\n"
787 "setp_gt p0, r0, r1\n"
788 "(!p0) add r2, r2, r3\n",
789 {0xfffe0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
790 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
792 { /* shader 4 */
793 "vs_2_x\n"
794 "if p0.x\n"
795 "else\n"
796 "endif\n",
797 {0xfffe0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
799 { /* shader 5 */
800 "vs_2_x\n"
801 "callnz l0, !p0.z\n"
802 "ret\n"
803 "label l0\n"
804 "ret\n",
805 {0xfffe0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
806 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
808 { /* shader 6 */
809 "vs_2_x\n"
810 "rep i0\n"
811 "breakp p0.w\n"
812 "endrep\n",
813 {0xfffe0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
814 0x00000027, 0x0000ffff}
818 exec_tests("vs_2_x", tests, sizeof(tests) / sizeof(tests[0]));
821 static void ps_2_0_test(void) {
822 struct shader_test tests[] = {
823 { /* shader 0 */
824 "ps_2_0\n"
825 "dcl_2d s0\n",
826 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
828 { /* shader 1 */
829 "ps_2_0\n"
830 "dcl_cube s0\n",
831 {0xffff0200, 0x0200001f, 0x98000000, 0xa00f0800, 0x0000ffff}
833 { /* shader 2 */
834 "ps_2_0\n"
835 "dcl_volume s0\n",
836 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0000ffff}
838 { /* shader 3 */
839 "ps_2_0\n"
840 "dcl_volume s0\n"
841 "dcl_cube s1\n"
842 "dcl_2d s2\n",
843 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0200001f, 0x98000000,
844 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x0000ffff}
846 { /* shader 4 */
847 "ps_2_0\n"
848 "mov r0, t0\n",
849 {0xffff0200, 0x02000001, 0x800f0000, 0xb0e40000, 0x0000ffff}
851 { /* shader 5 */
852 "ps_2_0\n"
853 "dcl_2d s2\n"
854 "texld r0, t1, s2\n",
855 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
856 0xb0e40001, 0xa0e40802, 0x0000ffff}
858 { /* shader 6 */
859 "ps_2_0\n"
860 "texkill t0\n",
861 {0xffff0200, 0x01000041, 0xb00f0000, 0x0000ffff}
863 { /* shader 7 */
864 "ps_2_0\n"
865 "mov oC0, c0\n"
866 "mov oC1, c1\n",
867 {0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x02000001, 0x800f0801,
868 0xa0e40001, 0x0000ffff}
870 { /* shader 8 */
871 "ps_2_0\n"
872 "mov oDepth, c0.x\n",
873 {0xffff0200, 0x02000001, 0x900f0800, 0xa0000000, 0x0000ffff}
875 { /* shader 9 */
876 "ps_2_0\n"
877 "dcl_2d s2\n"
878 "texldp r0, t1, s2\n",
879 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03010042, 0x800f0000,
880 0xb0e40001, 0xa0e40802, 0x0000ffff}
882 { /* shader 10 */
883 "ps_2_0\n"
884 "dcl_2d s2\n"
885 "texldb r0, t1, s2\n",
886 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03020042, 0x800f0000,
887 0xb0e40001, 0xa0e40802, 0x0000ffff}
889 { /* shader 11 */
890 "ps_2_0\n"
891 "dcl v0\n",
892 {0xffff0200, 0x0200001f, 0x80000000, 0x900f0000, 0x0000ffff}
894 { /* shader 12 */
895 "ps_2_0\n"
896 "dcl t0.xyz\n"
897 "dcl t1\n",
898 {0xffff0200, 0x0200001f, 0x80000000, 0xb0070000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0000ffff}
900 { /* shader 13 */
901 "ps_2_0\n"
902 "dcl_pp t0\n",
903 {0xffff0200, 0x0200001f, 0x80000000, 0xb02f0000, 0x0000ffff}
907 exec_tests("ps_2_0", tests, sizeof(tests) / sizeof(tests[0]));
910 static void ps_2_x_test(void) {
911 struct shader_test tests[] = {
912 /* defb and defi are not supposed to work in ps_2_0 (even if defb actually works in ps_2_0 with native) */
913 { /* shader 0 */
914 "ps_2_x\n"
915 "defb b0, true\n"
916 "defb b1, false\n",
917 {0xffff0201, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
918 0x00000000, 0x0000ffff}
920 { /* shader 1 */
921 "ps_2_x\n"
922 "defi i0, -1, 1, 10, 0\n"
923 "defi i1, 0, 40, 30, 10\n",
924 {0xffff0201, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
925 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
926 0x0000000a, 0x0000ffff}
928 { /* shader 2 */
929 "ps_2_x\n"
930 "dsx r0, r0\n",
931 {0xffff0201, 0x0200005b, 0x800f0000, 0x80e40000, 0x0000ffff}
933 { /* shader 3 */
934 "ps_2_x\n"
935 "dsy r0, r0\n",
936 {0xffff0201, 0x0200005c, 0x800f0000, 0x80e40000, 0x0000ffff}
938 { /* shader 4 */
939 "ps_2_x\n"
940 "dcl_2d s2\n"
941 "texldd r0, v1, s2, r3, r4\n",
942 {0xffff0201, 0x0200001f, 0x90000000, 0xa00f0802, 0x0500005d, 0x800f0000,
943 0x90e40001, 0xa0e40802, 0x80e40003, 0x80e40004, 0x0000ffff}
945 /* Static flow control tests */
946 { /* shader 5 */
947 "ps_2_x\n"
948 "call l0\n"
949 "ret\n"
950 "label l0\n"
951 "ret\n",
952 {0xffff0201, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
953 0x0000001c, 0x0000ffff}
955 { /* shader 6 */
956 "ps_2_x\n"
957 "callnz l0, b0\n"
958 "ret\n"
959 "label l0\n"
960 "ret\n",
961 {0xffff0201, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
962 0xa0e41000, 0x0000001c, 0x0000ffff}
964 { /* shader 7 */
965 "ps_2_x\n"
966 "callnz l0, !b0\n"
967 "ret\n"
968 "label l0\n"
969 "ret\n",
970 {0xffff0201, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
971 0xa0e41000, 0x0000001c, 0x0000ffff}
973 { /* shader 8 */
974 "ps_2_x\n"
975 "if !b0\n"
976 "else\n"
977 "endif\n",
978 {0xffff0201, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
980 /* Dynamic flow control tests */
981 { /* shader 9 */
982 "ps_2_x\n"
983 "rep i0\n"
984 "break\n"
985 "endrep\n",
986 {0xffff0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
988 { /* shader 10 */
989 "ps_2_x\n"
990 "if_ge r0, r1\n"
991 "endif\n",
992 {0xffff0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
994 { /* shader 11 */
995 "ps_2_x\n"
996 "rep i0\n"
997 "break_ne r0, r1\n"
998 "endrep",
999 {0xffff0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
1000 0x00000027, 0x0000ffff}
1002 /* Predicates */
1003 { /* shader 12 */
1004 "ps_2_x\n"
1005 "setp_gt p0, r0, r1\n"
1006 "(!p0) add r2, r2, r3\n",
1007 {0xffff0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
1008 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
1010 { /* shader 13 */
1011 "ps_2_x\n"
1012 "if p0.x\n"
1013 "else\n"
1014 "endif\n",
1015 {0xffff0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
1017 { /* shader 14 */
1018 "ps_2_x\n"
1019 "callnz l0, !p0.z\n"
1020 "ret\n"
1021 "label l0\n"
1022 "ret\n",
1023 {0xffff0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
1024 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
1026 { /* shader 15 */
1027 "ps_2_x\n"
1028 "rep i0\n"
1029 "breakp p0.w\n"
1030 "endrep\n",
1031 {0xffff0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
1032 0x00000027, 0x0000ffff}
1034 { /* shader 16 */
1035 "ps_2_x\n"
1036 "call l2047\n"
1037 "ret\n"
1038 "label l2047\n"
1039 "ret\n",
1040 {0xffff0201, 0x01000019, 0xa0e417ff, 0x0000001c, 0x0100001e, 0xa0e417ff,
1041 0x0000001c, 0x0000ffff}
1045 exec_tests("ps_2_x", tests, sizeof(tests) / sizeof(tests[0]));
1048 static void vs_3_0_test(void) {
1049 struct shader_test tests[] = {
1050 { /* shader 0 */
1051 "vs_3_0\n"
1052 "mov r0, c0\n",
1053 {0xfffe0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1055 { /* shader 1 */
1056 "vs_3_0\n"
1057 "dcl_2d s0\n",
1058 {0xfffe0300, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
1060 { /* shader 2 */
1061 "vs_3_0\n"
1062 "dcl_position o0\n",
1063 {0xfffe0300, 0x0200001f, 0x80000000, 0xe00f0000, 0x0000ffff}
1065 { /* shader 3 */
1066 "vs_3_0\n"
1067 "dcl_texcoord12 o11\n",
1068 {0xfffe0300, 0x0200001f, 0x800c0005, 0xe00f000b, 0x0000ffff}
1070 { /* shader 4 */
1071 "vs_3_0\n"
1072 "texldl r0, v0, s0\n",
1073 {0xfffe0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1075 { /* shader 5 */
1076 "vs_3_0\n"
1077 "mov r0, c0[aL]\n",
1078 {0xfffe0300, 0x03000001, 0x800f0000, 0xa0e42000, 0xf0e40800, 0x0000ffff}
1080 { /* shader 6 */
1081 "vs_3_0\n"
1082 "mov o[ a0.x + 12 ], r0\n",
1083 {0xfffe0300, 0x03000001, 0xe00f200c, 0xb0000000, 0x80e40000, 0x0000ffff}
1085 { /* shader 7 */
1086 "vs_3_0\n"
1087 "add_sat r0, r0, r1\n",
1088 {0xfffe0300, 0x03000002, 0x801f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1090 { /* shader 8 */
1091 "vs_3_0\n"
1092 "mov r2, r1_abs\n",
1093 {0xfffe0300, 0x02000001, 0x800f0002, 0x8be40001, 0x0000ffff}
1095 { /* shader 9 */
1096 "vs_3_0\n"
1097 "mov r2, r1.xygb\n",
1098 {0xfffe0300, 0x02000001, 0x800f0002, 0x80940001, 0x0000ffff}
1100 { /* shader 10 */
1101 "vs_3_0\n"
1102 "mov r2.xyb, r1\n",
1103 {0xfffe0300, 0x02000001, 0x80070002, 0x80e40001, 0x0000ffff}
1105 { /* shader 11 */
1106 "vs_3_0\n"
1107 "mova_sat a0.x, r1\n",
1108 {0xfffe0300, 0x0200002e, 0xb0110000, 0x80e40001, 0x0000ffff}
1110 { /* shader 12 */
1111 "vs_3_0\n"
1112 "sincos r0, r1\n",
1113 {0xfffe0300, 0x02000025, 0x800f0000, 0x80e40001, 0x0000ffff}
1115 { /* shader 13 */
1116 "vs_3_0\n"
1117 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
1118 {0xfffe0300, 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
1119 0x3f000000, 0x0000ffff}
1121 { /* shader 14: no register number checks with relative addressing */
1122 "vs_3_0\n"
1123 "add r0, v20[aL], r2\n",
1124 {0xfffe0300, 0x04000002, 0x800f0000, 0x90e42014, 0xf0e40800, 0x80e40002,
1125 0x0000ffff}
1130 exec_tests("vs_3_0", tests, sizeof(tests) / sizeof(tests[0]));
1133 static void ps_3_0_test(void) {
1134 struct shader_test tests[] = {
1135 { /* shader 0 */
1136 "ps_3_0\n"
1137 "mov r0, c0\n",
1138 {0xffff0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1140 { /* shader 1 */
1141 "ps_3_0\n"
1142 "dcl_normal5 v0\n",
1143 {0xffff0300, 0x0200001f, 0x80050003, 0x900f0000, 0x0000ffff}
1145 { /* shader 2 */
1146 "ps_3_0\n"
1147 "mov r0, vPos\n",
1148 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41000, 0x0000ffff}
1150 { /* shader 3 */
1151 "ps_3_0\n"
1152 "mov r0, vFace\n",
1153 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41001, 0x0000ffff}
1155 { /* shader 4 */
1156 "ps_3_0\n"
1157 "mov r0, v[ aL + 12 ]\n",
1158 {0xffff0300, 0x03000001, 0x800f0000, 0x90e4200c, 0xf0e40800, 0x0000ffff}
1160 { /* shader 5 */
1161 "ps_3_0\n"
1162 "loop aL, i0\n"
1163 "mov r0, v0[aL]\n"
1164 "endloop\n",
1165 {0xffff0300, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
1166 0x90e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
1168 { /* shader 6 */
1169 "ps_3_0\n"
1170 "texldl r0, v0, s0\n",
1171 {0xffff0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1173 { /* shader 7 */
1174 "ps_3_0\n"
1175 "add_pp r0, r0, r1\n",
1176 {0xffff0300, 0x03000002, 0x802f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1178 { /* shader 8 */
1179 "ps_3_0\n"
1180 "dsx_sat r0, r1\n",
1181 {0xffff0300, 0x0200005b, 0x801f0000, 0x80e40001, 0x0000ffff}
1183 { /* shader 9 */
1184 "ps_3_0\n"
1185 "texldd_pp r0, r1, r2, r3, r4\n",
1186 {0xffff0300, 0x0500005d, 0x802f0000, 0x80e40001, 0x80e40002, 0x80e40003,
1187 0x80e40004, 0x0000ffff}
1189 { /* shader 10 */
1190 "ps_3_0\n"
1191 "texkill v0\n",
1192 {0xffff0300, 0x01000041, 0x900f0000, 0x0000ffff}
1194 { /* shader 11 */
1195 "ps_3_0\n"
1196 "add oC3, r0, r1\n",
1197 {0xffff0300, 0x03000002, 0x800f0803, 0x80e40000, 0x80e40001, 0x0000ffff}
1199 { /* shader 12 */
1200 "ps_3_0\n"
1201 "dcl_texcoord0_centroid v0\n",
1202 {0xffff0300, 0x0200001f, 0x80000005, 0x904f0000, 0x0000ffff}
1204 { /* shader 13 */
1205 "ps_3_0\n"
1206 "dcl_2d_centroid s0\n",
1207 {0xffff0300, 0x0200001f, 0x90000000, 0xa04f0800, 0x0000ffff}
1209 { /* shader 14 */
1210 "ps_3_0\n"
1211 "dcl_2d_pp s0\n",
1212 {0xffff0300, 0x0200001f, 0x90000000, 0xa02f0800, 0x0000ffff}
1214 { /* shader 15 */
1215 "ps_3_0\n"
1216 "dcl v0\n",
1217 {0xffff0300, 0x0200001f, 0x80000000, 0x900f0000, 0x0000ffff}
1219 { /* shader 16 */
1220 "ps_3_0\n"
1221 "dcl s2\n",
1222 {0xffff0300, 0x0200001f, 0x80000000, 0xa00f0802, 0x0000ffff}
1226 exec_tests("ps_3_0", tests, sizeof(tests) / sizeof(tests[0]));
1229 static void failure_test(void) {
1230 const char * tests[] = {
1231 /* shader 0: instruction modifier not allowed */
1232 "ps_3_0\n"
1233 "dcl_2d s2\n"
1234 "texldd_x2 r0, v1, s2, v3, v4\n",
1235 /* shader 1: coissue not supported in vertex shaders */
1236 "vs.1.1\r\n"
1237 "add r0.rgb, r0, r1\n"
1238 "+add r0.a, r0, r2\n",
1239 /* shader 2: coissue not supported in pixel shader version >= 2.0 */
1240 "ps_2_0\n"
1241 "texld r0, t0, s0\n"
1242 "add r0.rgb, r0, r1\n"
1243 "+add r0.a, r0, v1\n",
1244 /* shader 3: predicates not supported in vertex shader < 2.0 */
1245 "vs_1_1\n"
1246 "(p0) add r0, r0, v0\n",
1247 /* shader 4: register a0 doesn't exist in pixel shaders */
1248 "ps_3_0\n"
1249 "mov r0, v[ a0 + 12 ]\n",
1250 /* shader 5: s0 doesn't exist in vs_1_1 */
1251 "vs_1_1\n"
1252 "mov r0, s0\n",
1253 /* shader 6: aL is a scalar register, no swizzles allowed */
1254 "ps_3_0\n"
1255 "mov r0, v[ aL.x + 12 ]\n",
1256 /* shader 7: tn doesn't exist in ps_3_0 */
1257 "ps_3_0\n"
1258 "dcl_2d s2\n"
1259 "texldd r0, t1, s2, v3, v4\n",
1260 /* shader 8: two shift modifiers */
1261 "ps_1_3\n"
1262 "mov_x2_x2 r0, r1\n",
1263 /* shader 9: too many source registers for mov instruction */
1264 "vs_1_1\n"
1265 "mov r0, r1, r2\n",
1266 /* shader 10: invalid combination of negate and divide modifiers */
1267 "ps_1_4\n"
1268 "texld r5, -r2_dz\n",
1269 /* shader 11: complement modifier not allowed in >= PS 2 */
1270 "ps_2_0\n"
1271 "mov r2, 1 - r0\n",
1272 /* shader 12: invalid modifier */
1273 "vs_3_0\n"
1274 "mov r2, 2 - r0\n",
1275 /* shader 13: float value in relative addressing */
1276 "vs_3_0\n"
1277 "mov r2, c[ aL + 3.4 ]\n",
1278 /* shader 14: complement modifier not available in VS */
1279 "vs_3_0\n"
1280 "mov r2, 1 - r1\n",
1281 /* shader 15: _x2 modifier not available in VS */
1282 "vs_1_1\n"
1283 "mov r2, r1_x2\n",
1284 /* shader 16: _abs modifier not available in < VS 3.0 */
1285 "vs_1_1\n"
1286 "mov r2, r1_abs\n",
1287 /* shader 17: _x2 modifier not available in >= PS 2.0 */
1288 "ps_2_0\n"
1289 "mov r0, r1_x2\n",
1290 /* shader 18: wrong swizzle */
1291 "vs_2_0\n"
1292 "mov r0, r1.abcd\n",
1293 /* shader 19: wrong swizzle */
1294 "vs_2_0\n"
1295 "mov r0, r1.xyzwx\n",
1296 /* shader 20: wrong swizzle */
1297 "vs_2_0\n"
1298 "mov r0, r1.\n",
1299 /* shader 21: invalid writemask */
1300 "vs_2_0\n"
1301 "mov r0.xxyz, r1\n",
1302 /* shader 22: register r5 doesn't exist in PS < 1.4 */
1303 "ps_1_3\n"
1304 "mov r5, r0\n",
1305 /* shader 23: can't declare output registers in a pixel shader */
1306 "ps_3_0\n"
1307 "dcl_positiont o0\n",
1308 /* shader 24: _pp instruction modifier not allowed in vertex shaders */
1309 "vs_3_0\n"
1310 "add_pp r0, r0, r1\n",
1311 /* shader 25: _x4 instruction modified not allowed in > ps_1_x */
1312 "ps_3_0\n"
1313 "add_x4 r0, r0, r1\n",
1314 /* shader 26: there aren't oCx registers in ps_1_x */
1315 "ps_1_3\n"
1316 "add oC0, r0, r1\n",
1317 /* shader 27: oC3 is the max in >= ps_2_0 */
1318 "ps_3_0\n"
1319 "add oC4, r0, r1\n",
1320 /* shader 28: register v17 doesn't exist */
1321 "vs_3_0\n"
1322 "add r0, r0, v17\n",
1323 /* shader 29: register o13 doesn't exist */
1324 "vs_3_0\n"
1325 "add o13, r0, r1\n",
1326 /* shader 30: label > 2047 not allowed */
1327 "vs_3_0\n"
1328 "call l2048\n",
1329 /* shader 31: s20 register does not exist */
1330 "ps_3_0\n"
1331 "texld r0, r1, s20\n",
1332 /* shader 32: t5 not allowed in ps_1_3 */
1333 "ps_1_3\n"
1334 "tex t5\n",
1335 /* shader 33: no temporary registers relative addressing */
1336 "vs_3_0\n"
1337 "add r0, r0[ a0.x ], r1\n",
1338 /* shader 34: no input registers relative addressing in vs_2_0 */
1339 "vs_2_0\n"
1340 "add r0, v[ a0.x ], r1\n",
1341 /* shader 35: no aL register in ps_2_0 */
1342 "ps_2_0\n"
1343 "add r0, v[ aL ], r1\n",
1344 /* shader 36: no relative addressing in ps_2_0 */
1345 "ps_2_0\n"
1346 "add r0, v[ r0 ], r1\n",
1347 /* shader 37: no a0 register in ps_3_0 */
1348 "ps_3_0\n"
1349 "add r0, v[ a0.x ], r1\n",
1350 /* shader 38: only a0.x accepted in vs_1_1 */
1351 "vs_1_1\n"
1352 "mov r0, c0[ a0 ]\n",
1353 /* shader 39: invalid modifier for dcl instruction */
1354 "ps_3_0\n"
1355 "dcl_texcoord0_sat v0\n",
1356 /* shader 40: shift not allowed */
1357 "ps_3_0\n"
1358 "dcl_texcoord0_x2 v0\n",
1359 /* shader 41: no modifier allowed with dcl instruction in vs */
1360 "vs_3_0\n"
1361 "dcl_texcoord0_centroid v0\n",
1362 /* shader 42: no modifiers with vs dcl sampler instruction */
1363 "vs_3_0\n"
1364 "dcl_2d_pp s0\n",
1365 /* shader 43: can't explicitely declare input registers in ps_2_0 */
1366 "ps_2_0\n"
1367 "dcl_texcoord0 t0\n",
1368 /* shader 44: can't implicitely declare registers in vs */
1369 "vs_2_0\n"
1370 "dcl o0\n",
1371 /* shader 45: can't implicitely declare samplers in vs */
1372 "vs_3_0\n"
1373 "dcl s2\n",
1374 /* shader 46: no tx registers in ps_3_0 */
1375 "ps_3_0\n"
1376 "dcl t2\n",
1377 /* shader 47: no samplers in vs_2_0 */
1378 "vs_2_0\n"
1379 "dcl_2d s2\n",
1381 HRESULT hr;
1382 unsigned int i;
1383 LPD3DXBUFFER shader,messages;
1385 for(i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) {
1386 shader = NULL;
1387 messages = NULL;
1388 hr = D3DXAssembleShader(tests[i], strlen(tests[i]),
1389 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1390 &shader, &messages);
1391 ok(hr == D3DXERR_INVALIDDATA, "Failure test, shader %d: "
1392 "expected D3DXAssembleShader failure with D3DXERR_INVALIDDATA, "
1393 "got 0x%x - %d\n", i, hr, hr & 0x0000FFFF);
1394 if(messages) {
1395 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1396 ID3DXBuffer_Release(messages);
1398 if(shader) {
1399 DWORD *res = ID3DXBuffer_GetBufferPointer(shader);
1400 dump_shader(res);
1401 ID3DXBuffer_Release(shader);
1407 static HRESULT WINAPI testD3DXInclude_open(ID3DXInclude *iface,
1408 D3DXINCLUDE_TYPE include_type,
1409 LPCSTR filename, LPCVOID parent_data,
1410 LPCVOID *data, UINT *bytes) {
1411 char *buffer;
1412 char include[] = "#define REGISTER r0\nvs.1.1\n";
1414 trace("filename = %s\n",filename);
1416 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
1417 CopyMemory(buffer, include, sizeof(include));
1418 *data = buffer;
1419 *bytes = sizeof(include);
1420 return S_OK;
1423 static HRESULT WINAPI testD3DXInclude_close(ID3DXInclude *iface, LPCVOID data) {
1424 HeapFree(GetProcessHeap(), 0, (LPVOID)data);
1425 return S_OK;
1428 static const struct ID3DXIncludeVtbl D3DXInclude_Vtbl = {
1429 testD3DXInclude_open,
1430 testD3DXInclude_close
1433 struct D3DXIncludeImpl {
1434 const ID3DXIncludeVtbl *lpVtbl;
1437 static void assembleshader_test(void) {
1438 const char test1[] = {
1439 "vs.1.1\n"
1440 "mov DEF2, v0\n"
1442 const char testincl[] = {
1443 "#define REGISTER r0\n"
1444 "vs.1.1\n"
1446 const char testshader[] = {
1447 "#include \"incl.vsh\"\n"
1448 "mov REGISTER, v0\n"
1450 HRESULT hr;
1451 LPD3DXBUFFER shader, messages;
1452 D3DXMACRO defines[] = {
1454 "DEF1", "10 + 15"
1457 "DEF2", "r0"
1460 NULL, NULL
1463 struct D3DXIncludeImpl include;
1464 HRESULT shader_vsh_res, incl_vsh_res;
1466 /* pDefines test */
1467 shader = NULL;
1468 messages = NULL;
1469 hr = D3DXAssembleShader(test1, strlen(test1),
1470 defines, NULL, D3DXSHADER_SKIPVALIDATION,
1471 &shader, &messages);
1472 ok(hr == D3D_OK, "pDefines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1473 if(messages) {
1474 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1475 ID3DXBuffer_Release(messages);
1477 if(shader) ID3DXBuffer_Release(shader);
1479 /* NULL messages test */
1480 shader = NULL;
1481 hr = D3DXAssembleShader(test1, strlen(test1),
1482 defines, NULL, D3DXSHADER_SKIPVALIDATION,
1483 &shader, NULL);
1484 ok(hr == D3D_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1485 if(shader) ID3DXBuffer_Release(shader);
1487 /* NULL shader test */
1488 messages = NULL;
1489 hr = D3DXAssembleShader(test1, strlen(test1),
1490 defines, NULL, D3DXSHADER_SKIPVALIDATION,
1491 NULL, &messages);
1492 ok(hr == D3D_OK, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1493 if(messages) {
1494 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1495 ID3DXBuffer_Release(messages);
1498 /* pInclude test */
1499 shader = NULL;
1500 messages = NULL;
1501 include.lpVtbl = &D3DXInclude_Vtbl;
1502 hr = D3DXAssembleShader(testshader, strlen(testshader),
1503 NULL, (LPD3DXINCLUDE)&include, D3DXSHADER_SKIPVALIDATION,
1504 &shader, &messages);
1505 ok(hr == D3D_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1506 if(messages) {
1507 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1508 ID3DXBuffer_Release(messages);
1510 if(shader) ID3DXBuffer_Release(shader);
1512 todo_wine {
1514 shader_vsh_res = create_file("shader.vsh", testshader, sizeof(testshader));
1515 if(SUCCEEDED(shader_vsh_res)) {
1516 incl_vsh_res = create_file("incl.vsh", testincl, sizeof(testincl));
1517 if(SUCCEEDED(incl_vsh_res)) {
1518 /* D3DXAssembleShaderFromFile + #include test */
1519 shader = NULL;
1520 messages = NULL;
1521 hr = D3DXAssembleShaderFromFileA("shader.vsh",
1522 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1523 &shader, &messages);
1524 ok(hr == D3D_OK, "D3DXAssembleShaderFromFile test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1525 if(messages) {
1526 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1527 ID3DXBuffer_Release(messages);
1529 if(shader) ID3DXBuffer_Release(shader);
1530 } else skip("Couldn't create \"incl.vsh\"\n");
1532 /* D3DXAssembleShaderFromFile + pInclude test */
1533 shader = NULL;
1534 messages = NULL;
1535 hr = D3DXAssembleShaderFromFileA("shader.vsh",
1536 NULL, (LPD3DXINCLUDE)&include, D3DXSHADER_SKIPVALIDATION,
1537 &shader, &messages);
1538 ok(hr == D3D_OK, "D3DXAssembleShaderFromFile + pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1539 if(messages) {
1540 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1541 ID3DXBuffer_Release(messages);
1543 if(shader) ID3DXBuffer_Release(shader);
1544 } else skip("Couldn't create \"shader.vsh\"\n");
1546 } /* todo_wine */
1548 /* NULL shader tests */
1549 shader = NULL;
1550 messages = NULL;
1551 hr = D3DXAssembleShader(NULL, 0,
1552 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1553 &shader, &messages);
1554 ok(hr == D3DXERR_INVALIDDATA, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1555 if(messages) {
1556 trace("D3DXAssembleShader messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1557 ID3DXBuffer_Release(messages);
1559 if(shader) ID3DXBuffer_Release(shader);
1561 todo_wine {
1563 shader = NULL;
1564 messages = NULL;
1565 hr = D3DXAssembleShaderFromFileA("nonexistent.vsh",
1566 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1567 &shader, &messages);
1568 ok(hr == D3DXERR_INVALIDDATA || hr == E_FAIL, /* I get this on WinXP */
1569 "D3DXAssembleShaderFromFile nonexistent file test failed with error 0x%x - %d\n",
1570 hr, hr & 0x0000FFFF);
1571 if(messages) {
1572 trace("D3DXAssembleShaderFromFile messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1573 ID3DXBuffer_Release(messages);
1575 if(shader) ID3DXBuffer_Release(shader);
1577 } /* end of todo_wine */
1579 /* D3DXAssembleShaderFromResource test */
1580 shader = NULL;
1581 messages = NULL;
1582 hr = D3DXAssembleShaderFromResourceA(NULL, MAKEINTRESOURCEA(IDB_ASMSHADER),
1583 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1584 &shader, &messages);
1585 ok(hr == D3D_OK, "D3DXAssembleShaderFromResource test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1586 if(messages) {
1587 trace("D3DXAssembleShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1588 ID3DXBuffer_Release(messages);
1590 if(shader) ID3DXBuffer_Release(shader);
1592 /* D3DXAssembleShaderFromResource with missing shader resource test */
1593 shader = NULL;
1594 messages = NULL;
1595 hr = D3DXAssembleShaderFromResourceA(NULL, "notexisting",
1596 NULL, NULL, D3DXSHADER_SKIPVALIDATION,
1597 &shader, &messages);
1598 ok(hr == D3DXERR_INVALIDDATA, "D3DXAssembleShaderFromResource NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1599 if(messages) {
1600 trace("D3DXAssembleShaderFromResource messages:\n%s", (char *)ID3DXBuffer_GetBufferPointer(messages));
1601 ID3DXBuffer_Release(messages);
1603 if(shader) ID3DXBuffer_Release(shader);
1605 /* cleanup */
1606 if(SUCCEEDED(shader_vsh_res)) {
1607 DeleteFileA("shader.vsh");
1608 if(SUCCEEDED(incl_vsh_res)) DeleteFileA("incl.vsh");
1612 START_TEST(asm)
1614 preproc_test();
1615 todo_wine ps_1_1_test();
1616 vs_1_1_test();
1617 todo_wine ps_1_3_test();
1618 todo_wine ps_1_4_test();
1619 vs_2_0_test();
1620 vs_2_x_test();
1621 ps_2_0_test();
1622 ps_2_x_test();
1623 vs_3_0_test();
1624 ps_3_0_test();
1626 failure_test();
1628 assembleshader_test();