comctl32: Add implementation of LVS_EX_ONECLICKACTIVATE.
[wine] / dlls / d3d9 / tests / stateblock.c
1 /*
2  * Copyright (C) 2005 Henri Verbeet
3  * Copyright (C) 2006 Ivan Gyurdiev
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #define COBJMACROS
21 #include <d3d9.h>
22 #include "wine/test.h"
23
24 static HMODULE d3d9_handle = 0;
25
26 static DWORD texture_stages;
27
28 static HWND create_window(void)
29 {
30     WNDCLASS wc = {0};
31     wc.lpfnWndProc = DefWindowProc;
32     wc.lpszClassName = "d3d9_test_wc";
33     RegisterClass(&wc);
34
35     return CreateWindow("d3d9_test_wc", "d3d9_test",
36             0, 0, 0, 0, 0, 0, 0, 0, 0);
37 }
38
39 static HRESULT init_d3d9(
40     IDirect3DDevice9** device,
41     D3DPRESENT_PARAMETERS* device_pparams)
42 {
43     IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
44     IDirect3D9 *d3d9_ptr = 0;
45     HRESULT hres;
46     HWND window;
47
48     d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
49     ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
50     if (!d3d9_create) return E_FAIL;
51     
52     d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
53     ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
54     if (!d3d9_ptr) return E_FAIL;
55
56     window = create_window();
57
58     ZeroMemory(device_pparams, sizeof(D3DPRESENT_PARAMETERS));
59     device_pparams->Windowed = TRUE;
60     device_pparams->hDeviceWindow = window;
61     device_pparams->SwapEffect = D3DSWAPEFFECT_DISCARD;
62
63     hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, window,
64         D3DCREATE_SOFTWARE_VERTEXPROCESSING, device_pparams, device);
65     ok(hres == D3D_OK || hres == D3DERR_NOTAVAILABLE,
66         "IDirect3D_CreateDevice returned: 0x%x\n", hres);
67     return hres;
68 }
69
70 static void test_begin_end_state_block(IDirect3DDevice9 *device_ptr)
71 {
72     HRESULT hret = 0;
73     IDirect3DStateBlock9 *state_block_ptr = 0;
74
75     /* Should succeed */
76     hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
77     ok(hret == D3D_OK, "BeginStateBlock returned: hret 0x%x. Expected hret 0x%x. Aborting.\n", hret, D3D_OK);
78     if (hret != D3D_OK) return;
79
80     /* Calling BeginStateBlock while recording should return D3DERR_INVALIDCALL */
81     hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
82     ok(hret == D3DERR_INVALIDCALL, "BeginStateBlock returned: hret 0x%x. Expected hret 0x%x. Aborting.\n", hret, D3DERR_INVALIDCALL);
83     if (hret != D3DERR_INVALIDCALL) return;
84
85     /* Should succeed */
86     state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
87     hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
88     ok(hret == D3D_OK && state_block_ptr != 0 && state_block_ptr != (IDirect3DStateBlock9 *)0xdeadbeef, 
89         "EndStateBlock returned: hret 0x%x, state_block_ptr %p. "
90         "Expected hret 0x%x, state_block_ptr != %p, state_block_ptr != 0xdeadbeef.\n", hret, state_block_ptr, D3D_OK, NULL);
91
92     /* Calling EndStateBlock while not recording should return D3DERR_INVALIDCALL. state_block_ptr should not be touched. */
93     state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
94     hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
95     ok(hret == D3DERR_INVALIDCALL && state_block_ptr == (IDirect3DStateBlock9 *)0xdeadbeef, 
96         "EndStateBlock returned: hret 0x%x, state_block_ptr %p. "
97         "Expected hret 0x%x, state_block_ptr 0xdeadbeef.\n", hret, state_block_ptr, D3DERR_INVALIDCALL);
98 }
99
100 /* ============================ State Testing Framework ========================== */
101
102 typedef struct state_test {
103     const char* test_name;
104
105     /* The initial data is usually the same
106      * as the default data, but a write can have side effects.
107      * The initial data is tested first, before any writes take place
108      * The default data can be tested after a write */
109     const void* initial_data;
110
111     /* The default data is the standard state to compare
112      * against, and restore to */
113     const void* default_data;
114
115     /* The test data is the experiment data to try
116      * in - what we want to write
117      * out - what windows will actually write (not necessarily the same)  */
118     const void* test_data_in;
119     const void* test_data_out;
120
121     /* The poison data is the data to preinitialize the return buffer to */
122     const void* poison_data;
123     
124     /* Return buffer */
125     void* return_data;
126
127     /* Size of the data samples above */
128     unsigned int data_size;
129
130     /* Test resource management handlers */
131     HRESULT (*setup_handler) (struct state_test* test);
132     void (*teardown_handler) (struct state_test* test);
133
134     /* Test data handlers */
135     void (*set_handler) (IDirect3DDevice9* device, const struct state_test* test, const void* data_in);
136     void (*get_handler) (IDirect3DDevice9* device, const struct state_test* test, void* data_out);
137     void (*print_handler) (const struct state_test* test, const void* data);
138
139     /* Test arguments */
140     const void* test_arg;
141
142     /* Test-specific context data */
143     void* test_context;
144
145 } state_test;
146
147 /* See below for explanation of the flags */
148 #define EVENT_OK             0x00
149 #define EVENT_CHECK_DEFAULT  0x01 
150 #define EVENT_CHECK_INITIAL  0x02
151 #define EVENT_CHECK_TEST     0x04
152 #define EVENT_ERROR          0x08
153 #define EVENT_APPLY_DATA     0x10
154
155 typedef struct event {
156    int (*event_fn) (IDirect3DDevice9* device, void* arg);
157    int status;
158 } event;
159
160 /* This is an event-machine, which tests things.
161  * It tests get and set operations for a batch of states, based on
162  * results from the event function, which directs what's to be done */
163
164 static void execute_test_chain(
165     IDirect3DDevice9* device,
166     state_test* test,
167     unsigned int ntests,
168     event *event,
169     unsigned int nevents,
170     void* event_arg) {
171
172     int outcome;
173     unsigned int i = 0, j;
174
175     /* For each queued event */
176     for (j=0; j < nevents; j++) {
177
178         /* Execute the next event handler (if available) or just set the supplied status */
179         outcome = event[j].status;
180         if (event[j].event_fn)
181             outcome |= event[j].event_fn(device, event_arg);
182
183         /* Now verify correct outcome depending on what was signaled by the handler.
184          * An EVENT_CHECK_TEST signal means check the returned data against the test_data (out).
185          * An EVENT_CHECK_DEFAULT signal means check the returned data against the default_data.
186          * An EVENT_CHECK_INITIAL signal means check the returned data against the initial_data.
187          * An EVENT_ERROR signal means the test isn't going to work, exit the event loop.
188          * An EVENT_APPLY_DATA signal means load the test data (after checks) */
189
190         if (outcome & EVENT_ERROR) {
191             trace("Test %s, Stage %u in error state, aborting\n", test[i].test_name, j);
192             break;
193
194         } else if (outcome & EVENT_CHECK_TEST || outcome & EVENT_CHECK_DEFAULT || outcome & EVENT_CHECK_INITIAL) {
195
196             for (i=0; i < ntests; i++) {
197
198                 memcpy(test[i].return_data, test[i].poison_data, test[i].data_size);
199                 test[i].get_handler(device, &test[i], test[i].return_data);
200
201                 if (outcome & EVENT_CHECK_TEST) {
202
203                     BOOL test_failed = memcmp(test[i].test_data_out, test[i].return_data, test[i].data_size);
204                     ok(!test_failed, "Test %s, Stage %u: returned data does not match test data [csize=%u]\n",
205                         test[i].test_name, j, test[i].data_size);
206
207                     if (test_failed && test[i].print_handler) {
208                         trace("Returned data was:\n");
209                         test[i].print_handler(&test[i], test[i].return_data);
210                         trace("Test data was:\n");
211                         test[i].print_handler(&test[i], test[i].test_data_out);
212                     }
213                 }
214
215                 else if (outcome & EVENT_CHECK_DEFAULT) {
216                   
217                     BOOL test_failed = memcmp(test[i].default_data, test[i].return_data, test[i].data_size);
218                     ok (!test_failed, "Test %s, Stage %u: returned data does not match default data [csize=%u]\n",
219                         test[i].test_name, j, test[i].data_size);
220
221                     if (test_failed && test[i].print_handler) {
222                         trace("Returned data was:\n");
223                         test[i].print_handler(&test[i], test[i].return_data);
224                         trace("Default data was:\n");
225                         test[i].print_handler(&test[i], test[i].default_data);
226                     }
227                 }
228
229                 else if (outcome & EVENT_CHECK_INITIAL) {
230                     
231                     BOOL test_failed = memcmp(test[i].initial_data, test[i].return_data, test[i].data_size);
232                     ok (!test_failed, "Test %s, Stage %u: returned data does not match initial data [csize=%u]\n",
233                         test[i].test_name, j, test[i].data_size);
234
235                     if (test_failed && test[i].print_handler) {
236                         trace("Returned data was:\n");
237                         test[i].print_handler(&test[i], test[i].return_data);
238                         trace("Initial data was:\n");
239                         test[i].print_handler(&test[i], test[i].initial_data);
240                     }
241                 }
242             }
243         }
244
245         if (outcome & EVENT_APPLY_DATA) {
246             for (i=0; i < ntests; i++)
247                 test[i].set_handler(device, &test[i], test[i].test_data_in);
248         }
249      }
250
251      /* Attempt to reset any changes made */
252      for (i=0; i < ntests; i++)
253          test[i].set_handler(device, &test[i], test[i].default_data);
254 }
255
256 typedef struct event_data {
257     IDirect3DStateBlock9* stateblock;
258     IDirect3DSurface9* original_render_target;
259     IDirect3DSwapChain9* new_swap_chain;
260 } event_data;
261
262 static int switch_render_target(
263     IDirect3DDevice9* device,
264     void* data) {
265   
266     HRESULT hret;
267     D3DPRESENT_PARAMETERS present_parameters;
268     event_data* edata = (event_data*) data;
269     IDirect3DSwapChain9* swapchain = NULL;
270     IDirect3DSurface9* backbuffer = NULL;
271
272     /* Parameters for new swapchain */
273     ZeroMemory(&present_parameters, sizeof(present_parameters));
274     present_parameters.Windowed = TRUE;
275     present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
276
277     /* Create new swapchain */
278     hret = IDirect3DDevice9_CreateAdditionalSwapChain(device, &present_parameters, &swapchain);
279     ok (hret == D3D_OK, "CreateAdditionalSwapChain returned %#x.\n", hret);
280     if (hret != D3D_OK) goto error;
281
282     /* Get its backbuffer */
283     hret = IDirect3DSwapChain9_GetBackBuffer(swapchain, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
284     ok (hret == D3D_OK, "GetBackBuffer returned %#x.\n", hret);
285     if (hret != D3D_OK) goto error;
286
287     /* Save the current render target */
288     hret = IDirect3DDevice9_GetRenderTarget(device, 0, &edata->original_render_target); 
289     ok (hret == D3D_OK, "GetRenderTarget returned %#x.\n", hret);
290     if (hret != D3D_OK) goto error;
291
292     /* Set the new swapchain's backbuffer as a render target */
293     hret = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
294     ok (hret == D3D_OK, "SetRenderTarget returned %#x.\n", hret);
295     if (hret != D3D_OK) goto error;
296
297     IUnknown_Release(backbuffer);
298     edata->new_swap_chain = swapchain;
299     return EVENT_OK;
300
301     error:
302     if (backbuffer) IUnknown_Release(backbuffer);
303     if (swapchain) IUnknown_Release(swapchain);
304     return EVENT_ERROR;
305 }
306
307 static int revert_render_target( 
308     IDirect3DDevice9* device,
309     void* data) {
310
311     HRESULT hret;
312     event_data* edata = (event_data*) data;
313    
314     /* Reset the old render target */
315     hret = IDirect3DDevice9_SetRenderTarget(device, 0, edata->original_render_target);
316     ok (hret == D3D_OK, "SetRenderTarget returned %#x.\n", hret);
317     if (hret != D3D_OK) {
318         IUnknown_Release(edata->original_render_target);
319         return EVENT_ERROR;
320     }
321
322     IUnknown_Release(edata->original_render_target);
323
324     IUnknown_Release(edata->new_swap_chain);
325     return EVENT_OK;
326 }
327
328 static int begin_stateblock(
329     IDirect3DDevice9* device,
330     void* data) {
331
332     HRESULT hret;
333
334     data = NULL;
335     hret = IDirect3DDevice9_BeginStateBlock(device);
336     ok(hret == D3D_OK, "BeginStateBlock returned %#x.\n", hret);
337     if (hret != D3D_OK) return EVENT_ERROR;
338     return EVENT_OK;
339 }
340
341 static int end_stateblock(
342     IDirect3DDevice9* device,
343     void* data) {
344
345     HRESULT hret;
346     event_data* edata = (event_data*) data;
347
348     hret = IDirect3DDevice9_EndStateBlock(device, &edata->stateblock);
349     ok(hret == D3D_OK, "EndStateBlock returned %#x.\n", hret);
350     if (hret != D3D_OK) return EVENT_ERROR;
351     return EVENT_OK;
352 }
353
354 static int abort_stateblock(
355     IDirect3DDevice9* device,
356     void* data) {
357
358     event_data* edata = (event_data*) data;
359
360     IUnknown_Release(edata->stateblock);
361     return EVENT_OK;
362 }
363
364 static int apply_stateblock(
365     IDirect3DDevice9* device,
366     void* data) {
367
368     event_data* edata = (event_data*) data;
369     HRESULT hret;
370
371     hret = IDirect3DStateBlock9_Apply(edata->stateblock);
372     ok(hret == D3D_OK, "Apply returned %#x.\n", hret);
373     if (hret != D3D_OK) {
374         IUnknown_Release(edata->stateblock);
375         return EVENT_ERROR;
376     }
377
378     IUnknown_Release(edata->stateblock);
379     return EVENT_OK;
380 }
381
382 static int capture_stateblock(
383     IDirect3DDevice9* device,
384     void* data) {
385
386     HRESULT hret;
387     event_data* edata = (event_data*) data;
388
389     hret = IDirect3DStateBlock9_Capture(edata->stateblock);
390     ok(hret == D3D_OK, "Capture returned %#x.\n", hret);
391     if (hret != D3D_OK)
392         return EVENT_ERROR;
393
394     return EVENT_OK;
395 }
396
397 static void execute_test_chain_all(
398     IDirect3DDevice9* device,
399     state_test* test,
400     unsigned int ntests) {
401
402     unsigned int i;
403     event_data arg;
404
405     event read_events[] = {
406         { NULL, EVENT_CHECK_INITIAL }
407     };
408
409     event write_read_events[] = {
410         { NULL, EVENT_APPLY_DATA },
411         { NULL, EVENT_CHECK_TEST }
412     };
413
414     event abort_stateblock_events[] = {
415         { begin_stateblock, EVENT_APPLY_DATA },
416         { end_stateblock, EVENT_OK },
417         { abort_stateblock, EVENT_CHECK_DEFAULT }
418     };
419
420     event apply_stateblock_events[] = {
421         { begin_stateblock, EVENT_APPLY_DATA },
422         { end_stateblock, EVENT_OK },
423         { apply_stateblock, EVENT_CHECK_TEST }
424     };
425
426     event capture_reapply_stateblock_events[] = {
427           { begin_stateblock, EVENT_APPLY_DATA },
428           { end_stateblock, EVENT_OK },
429           { capture_stateblock, EVENT_CHECK_DEFAULT | EVENT_APPLY_DATA },
430           { apply_stateblock, EVENT_CHECK_DEFAULT }
431     };
432
433     event rendertarget_switch_events[] = {
434           { NULL, EVENT_APPLY_DATA },
435           { switch_render_target, EVENT_CHECK_TEST },
436           { revert_render_target, EVENT_OK } 
437     };
438
439     event rendertarget_stateblock_events[] = {
440           { begin_stateblock, EVENT_APPLY_DATA },
441           { switch_render_target, EVENT_CHECK_DEFAULT },
442           { end_stateblock, EVENT_OK },
443           { revert_render_target, EVENT_OK },
444           { apply_stateblock, EVENT_CHECK_TEST }
445     };
446
447     /* Setup each test for execution */
448     for (i=0; i < ntests; i++) {
449         if (test[i].setup_handler(&test[i]) != D3D_OK) {
450             ok(FALSE, "Test \"%s\" failed setup, aborting\n", test[i].test_name);
451             return;
452         }
453     }
454
455     trace("Running initial read state tests\n");
456     execute_test_chain(device, test, ntests, read_events, 1, NULL);
457
458     trace("Running write-read state tests\n");
459     execute_test_chain(device, test, ntests, write_read_events, 2, NULL);
460
461     trace("Running stateblock abort state tests\n");
462     execute_test_chain(device, test, ntests, abort_stateblock_events, 3, &arg);
463
464     trace("Running stateblock apply state tests\n");
465     execute_test_chain(device, test, ntests, apply_stateblock_events, 3, &arg);
466
467     trace("Running stateblock capture/reapply state tests\n");
468     execute_test_chain(device, test, ntests, capture_reapply_stateblock_events, 4, &arg);
469   
470     trace("Running rendertarget switch state tests\n");
471     execute_test_chain(device, test, ntests, rendertarget_switch_events, 3, &arg);
472
473     trace("Running stateblock apply over rendertarget switch interrupt tests\n");
474     execute_test_chain(device, test, ntests, rendertarget_stateblock_events, 5, &arg);
475
476     /* Cleanup resources */
477     for (i=0; i < ntests; i++)
478         test[i].teardown_handler(&test[i]);
479 }
480
481 /* =================== State test: Pixel and Vertex Shader constants ============ */
482
483 typedef struct shader_constant_data {
484     int int_constant[4];     /* 1x4 integer constant */
485     float float_constant[4]; /* 1x4 float constant */
486     BOOL bool_constant[4];   /* 4x1 boolean constants */
487 } shader_constant_data;
488
489 typedef struct shader_constant_arg {
490     unsigned int idx;
491     BOOL pshader;
492 } shader_constant_arg;
493
494 typedef struct shader_constant_context {
495     shader_constant_data return_data_buffer;
496 } shader_constant_context;
497
498 static void shader_constant_print_handler(
499     const state_test* test,
500     const void* data) {
501
502     const shader_constant_data* scdata = data;
503
504     trace("Integer constant = { %#x, %#x, %#x, %#x }\n",
505         scdata->int_constant[0], scdata->int_constant[1],
506         scdata->int_constant[2], scdata->int_constant[3]);
507
508     trace("Float constant = { %f, %f, %f, %f }\n",
509         scdata->float_constant[0], scdata->float_constant[1],
510         scdata->float_constant[2], scdata->float_constant[3]);
511
512     trace("Boolean constants = [ %#x, %#x, %#x, %#x ]\n",
513         scdata->bool_constant[0], scdata->bool_constant[1],
514         scdata->bool_constant[2], scdata->bool_constant[3]);
515 }
516
517 static void shader_constant_set_handler(
518     IDirect3DDevice9* device, const state_test* test, const void* data) {
519
520     HRESULT hret;
521     const shader_constant_data* scdata = data;
522     const shader_constant_arg* scarg = test->test_arg;
523     unsigned int index = scarg->idx;
524
525     if (!scarg->pshader) {
526         hret = IDirect3DDevice9_SetVertexShaderConstantI(device, index, scdata->int_constant, 1);
527         ok(hret == D3D_OK, "SetVertexShaderConstantI returned %#x.\n", hret);
528         hret = IDirect3DDevice9_SetVertexShaderConstantF(device, index, scdata->float_constant, 1);
529         ok(hret == D3D_OK, "SetVertexShaderConstantF returned %#x.\n", hret);
530         hret = IDirect3DDevice9_SetVertexShaderConstantB(device, index, scdata->bool_constant, 4);
531         ok(hret == D3D_OK, "SetVertexShaderConstantB returned %#x.\n", hret);
532
533     } else {
534         hret = IDirect3DDevice9_SetPixelShaderConstantI(device, index, scdata->int_constant, 1);
535         ok(hret == D3D_OK, "SetPixelShaderConstantI returned %#x.\n", hret);
536         hret = IDirect3DDevice9_SetPixelShaderConstantF(device, index, scdata->float_constant, 1);
537         ok(hret == D3D_OK, "SetPixelShaderConstantF returned %#x.\n", hret);
538         hret = IDirect3DDevice9_SetPixelShaderConstantB(device, index, scdata->bool_constant, 4);
539         ok(hret == D3D_OK, "SetPixelShaderConstantB returned %#x.\n", hret);
540     }
541 }
542
543 static void shader_constant_get_handler(
544     IDirect3DDevice9* device, const state_test* test, void* data) {
545
546     HRESULT hret;
547     shader_constant_data* scdata = (shader_constant_data*) data;
548     const shader_constant_arg* scarg = test->test_arg;
549     unsigned int index = scarg->idx;
550
551     if (!scarg->pshader) {
552         hret = IDirect3DDevice9_GetVertexShaderConstantI(device, index, scdata->int_constant, 1);
553         ok(hret == D3D_OK, "GetVertexShaderConstantI returned %#x.\n", hret);
554         hret = IDirect3DDevice9_GetVertexShaderConstantF(device, index, scdata->float_constant, 1);
555         ok(hret == D3D_OK, "GetVertexShaderConstantF returned %#x.\n", hret);
556         hret = IDirect3DDevice9_GetVertexShaderConstantB(device, index, scdata->bool_constant, 4);
557         ok(hret == D3D_OK, "GetVertexShaderConstantB returned %#x.\n", hret);
558
559     } else {
560         hret = IDirect3DDevice9_GetPixelShaderConstantI(device, index, scdata->int_constant, 1);
561         ok(hret == D3D_OK, "GetPixelShaderConstantI returned %#x.\n", hret);
562         hret = IDirect3DDevice9_GetPixelShaderConstantF(device, index, scdata->float_constant, 1);
563         ok(hret == D3D_OK, "GetPixelShaderConstantF returned %#x.\n", hret);
564         hret = IDirect3DDevice9_GetPixelShaderConstantB(device, index, scdata->bool_constant, 4);
565         ok(hret == D3D_OK, "GetPixelShaderConstantB returned %#x.\n", hret);
566     }
567 }
568
569 static const shader_constant_data shader_constant_poison_data = {
570     { 0x1337c0de, 0x1337c0de, 0x1337c0de, 0x1337c0de },
571     { 1.0f, 2.0f, 3.0f, 4.0f },
572     { FALSE, TRUE, FALSE, TRUE }
573 };
574
575 static const shader_constant_data shader_constant_default_data = {
576         { 0, 0, 0, 0 }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0, 0, 0, 0 }
577 };
578
579 static const shader_constant_data shader_constant_test_data = {
580     { 0xdead0000, 0xdead0001, 0xdead0002, 0xdead0003 },
581     { 0.0f, 0.0f, 0.0f, 0.0f },
582     { TRUE, FALSE, FALSE, TRUE }
583 };
584
585 static HRESULT shader_constant_setup_handler(
586     state_test* test) {
587
588     shader_constant_context *ctx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(shader_constant_context));
589     if (ctx == NULL) return E_FAIL;
590     test->test_context = ctx;
591      
592     test->return_data = &ctx->return_data_buffer;
593     test->test_data_in = &shader_constant_test_data;
594     test->test_data_out = &shader_constant_test_data;
595     test->default_data = &shader_constant_default_data;
596     test->initial_data = &shader_constant_default_data;
597     test->poison_data = &shader_constant_poison_data;
598
599     test->data_size = sizeof(shader_constant_data);
600     
601     return D3D_OK;
602 }
603
604 static void shader_constant_teardown_handler(
605     state_test* test) {
606     
607     HeapFree(GetProcessHeap(), 0, test->test_context);
608 }
609
610 static void shader_constants_queue_test(
611     state_test* test,
612     const shader_constant_arg* test_arg) {
613
614     test->setup_handler = shader_constant_setup_handler;
615     test->teardown_handler = shader_constant_teardown_handler;
616     test->set_handler = shader_constant_set_handler;
617     test->get_handler = shader_constant_get_handler;
618     test->print_handler = shader_constant_print_handler;
619     test->test_name = test_arg->pshader? "set_get_pshader_constants": "set_get_vshader_constants";
620     test->test_arg = test_arg;
621 }
622
623 /* =================== State test: Lights ===================================== */
624
625 typedef struct light_data {
626     D3DLIGHT9 light;
627     BOOL enabled;
628     HRESULT get_light_result;
629     HRESULT get_enabled_result;
630 } light_data;
631
632 typedef struct light_arg {
633     unsigned int idx;
634 } light_arg;
635
636 typedef struct light_context {
637     light_data return_data_buffer;
638 } light_context;
639
640 static void light_print_handler(
641     const state_test* test,
642     const void* data) {
643
644     const light_data* ldata = data;
645
646     trace("Get Light return value: %#x\n", ldata->get_light_result);
647     trace("Get Light enable return value: %#x\n", ldata->get_enabled_result);
648
649     trace("Light Enabled = %u\n", ldata->enabled);
650     trace("Light Type = %u\n", ldata->light.Type);
651     trace("Light Diffuse = { %f, %f, %f, %f }\n",
652         ldata->light.Diffuse.r, ldata->light.Diffuse.g,
653         ldata->light.Diffuse.b, ldata->light.Diffuse.a);
654     trace("Light Specular = { %f, %f, %f, %f}\n",
655         ldata->light.Specular.r, ldata->light.Specular.g,
656         ldata->light.Specular.b, ldata->light.Specular.a);
657     trace("Light Ambient = { %f, %f, %f, %f }\n",
658         ldata->light.Ambient.r, ldata->light.Ambient.g,
659         ldata->light.Ambient.b, ldata->light.Ambient.a);
660     trace("Light Position = { %f, %f, %f }\n",
661         ldata->light.Position.x, ldata->light.Position.y, ldata->light.Position.z);
662     trace("Light Direction = { %f, %f, %f }\n",
663         ldata->light.Direction.x, ldata->light.Direction.y, ldata->light.Direction.z);
664     trace("Light Range = %f\n", ldata->light.Range);
665     trace("Light Fallof = %f\n", ldata->light.Falloff);
666     trace("Light Attenuation0 = %f\n", ldata->light.Attenuation0);
667     trace("Light Attenuation1 = %f\n", ldata->light.Attenuation1);
668     trace("Light Attenuation2 = %f\n", ldata->light.Attenuation2);
669     trace("Light Theta = %f\n", ldata->light.Theta);
670     trace("Light Phi = %f\n", ldata->light.Phi);
671 }
672
673 static void light_set_handler(
674     IDirect3DDevice9* device, const state_test* test, const void* data) {
675
676     HRESULT hret;
677     const light_data* ldata = data;
678     const light_arg* larg = test->test_arg;
679     unsigned int index = larg->idx;
680
681     hret = IDirect3DDevice9_SetLight(device, index, &ldata->light);
682     ok(hret == D3D_OK, "SetLight returned %#x.\n", hret);
683
684     hret = IDirect3DDevice9_LightEnable(device, index, ldata->enabled);
685     ok(hret == D3D_OK, "SetLightEnable returned %#x.\n", hret);
686 }
687
688 static void light_get_handler(
689     IDirect3DDevice9* device, const state_test* test, void* data) {
690
691     HRESULT hret;
692     light_data* ldata = data;
693     const light_arg* larg = test->test_arg;
694     unsigned int index = larg->idx;
695
696     hret = IDirect3DDevice9_GetLightEnable(device, index, &ldata->enabled);
697     ldata->get_enabled_result = hret;
698
699     hret = IDirect3DDevice9_GetLight(device, index, &ldata->light);
700     ldata->get_light_result = hret;
701 }
702
703 static const light_data light_poison_data = 
704     { { 0x1337c0de,
705         { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 },
706         { 3.3f, 4.4f, 5.5f },{ 6.6f, 7.7f, 8.8f },
707         12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f },
708         1, 0x1337c0de, 0x1337c0de };
709
710 static const light_data light_default_data =
711     { { D3DLIGHT_DIRECTIONAL,
712         { 1.0, 1.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 },
713         { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 },
714         0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 0, D3D_OK, D3D_OK };
715
716 /* This is used for the initial read state (before a write causes side effects)
717  * The proper return status is D3DERR_INVALIDCALL */
718 static const light_data light_initial_data =
719     { { 0x1337c0de,
720         { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 },
721         { 3.3f, 4.4f, 5.5f }, { 6.6f, 7.7f, 8.8f },
722         12.12f, 13.13f, 14.14f, 15.15f, 16.16f, 17.17f, 18.18f },
723         1, D3DERR_INVALIDCALL, D3DERR_INVALIDCALL };
724
725 static const light_data light_test_data_in =
726     { { 1,
727         { 2.0, 2.0, 2.0, 2.0 }, { 3.0, 3.0, 3.0, 3.0 }, { 4.0, 4.0, 4.0, 4.0 },
728         { 5.0, 5.0, 5.0 }, { 6.0, 6.0, 6.0 },
729         7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }, 1, D3D_OK, D3D_OK};
730
731 /* SetLight will use 128 as the "enabled" value */
732 static const light_data light_test_data_out = 
733     { { 1,
734         { 2.0, 2.0, 2.0, 2.0 }, { 3.0, 3.0, 3.0, 3.0 }, { 4.0, 4.0, 4.0, 4.0 },
735         { 5.0, 5.0, 5.0 }, { 6.0, 6.0, 6.0 },
736         7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }, 128, D3D_OK, D3D_OK};
737
738 static HRESULT light_setup_handler(
739     state_test* test) {
740      
741     light_context *ctx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(light_context));
742     if (ctx == NULL) return E_FAIL;
743     test->test_context = ctx;
744  
745     test->return_data = &ctx->return_data_buffer;
746     test->test_data_in = &light_test_data_in;
747     test->test_data_out = &light_test_data_out;
748     test->default_data = &light_default_data;
749     test->initial_data = &light_initial_data;
750     test->poison_data = &light_poison_data;
751
752     test->data_size = sizeof(light_data);
753     
754     return D3D_OK;
755 }
756
757 static void light_teardown_handler(
758     state_test* test) {
759     
760     HeapFree(GetProcessHeap(), 0, test->test_context);
761 }
762
763 static void lights_queue_test(
764     state_test* test,
765     const light_arg* test_arg) {
766
767     test->setup_handler = light_setup_handler;
768     test->teardown_handler = light_teardown_handler;
769     test->set_handler = light_set_handler;
770     test->get_handler = light_get_handler;
771     test->print_handler = light_print_handler;
772     test->test_name = "set_get_light";
773     test->test_arg = test_arg;
774 }
775
776 /* =================== State test: Transforms ===================================== */
777
778 typedef struct transform_data {
779
780     D3DMATRIX view;
781     D3DMATRIX projection;
782     D3DMATRIX texture0;
783     D3DMATRIX texture7;
784     D3DMATRIX world0;
785     D3DMATRIX world255;
786
787 } transform_data;
788
789 typedef struct transform_context {
790     transform_data return_data_buffer;
791 } transform_context;
792
793 static inline void print_matrix(
794     const char* name, const D3DMATRIX* matrix) {
795
796     trace("%s Matrix = {\n", name);
797     trace("    %f %f %f %f\n", U(*matrix).m[0][0], U(*matrix).m[1][0], U(*matrix).m[2][0], U(*matrix).m[3][0]);
798     trace("    %f %f %f %f\n", U(*matrix).m[0][1], U(*matrix).m[1][1], U(*matrix).m[2][1], U(*matrix).m[3][1]);
799     trace("    %f %f %f %f\n", U(*matrix).m[0][2], U(*matrix).m[1][2], U(*matrix).m[2][2], U(*matrix).m[3][2]);
800     trace("    %f %f %f %f\n", U(*matrix).m[0][3], U(*matrix).m[1][3], U(*matrix).m[2][3], U(*matrix).m[3][3]);
801     trace("}\n");
802 }
803
804 static void transform_print_handler(
805     const state_test* test,
806     const void* data) {
807
808     const transform_data* tdata = data;
809
810     print_matrix("View", &tdata->view);
811     print_matrix("Projection", &tdata->projection);
812     print_matrix("Texture0", &tdata->texture0);
813     print_matrix("Texture7", &tdata->texture7);
814     print_matrix("World0", &tdata->world0);
815     print_matrix("World255", &tdata->world255);
816 }
817
818 static void transform_set_handler(
819     IDirect3DDevice9* device, const state_test* test, const void* data) {
820
821     HRESULT hret;
822     const transform_data* tdata = data;
823
824     hret = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &tdata->view);
825     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
826
827     hret = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &tdata->projection);
828     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
829
830     hret = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &tdata->texture0);
831     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
832
833     hret = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0 + texture_stages - 1, &tdata->texture7);
834     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
835
836     hret = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &tdata->world0);
837     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
838
839     hret = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(255), &tdata->world255);
840     ok(hret == D3D_OK, "SetTransform returned %#x.\n", hret);
841 }
842
843 static void transform_get_handler(
844     IDirect3DDevice9* device, const state_test* test, void* data) {
845
846     HRESULT hret;
847     transform_data* tdata = (transform_data*) data;
848
849     hret = IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &tdata->view);
850     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
851
852     hret = IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &tdata->projection);
853     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
854
855     hret = IDirect3DDevice9_GetTransform(device, D3DTS_TEXTURE0, &tdata->texture0);
856     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
857
858     hret = IDirect3DDevice9_GetTransform(device, D3DTS_TEXTURE0 + texture_stages - 1, &tdata->texture7);
859     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
860
861     hret = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &tdata->world0);
862     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
863
864     hret = IDirect3DDevice9_GetTransform(device, D3DTS_WORLDMATRIX(255), &tdata->world255);
865     ok(hret == D3D_OK, "GetTransform returned %#x.\n", hret);
866 }
867
868 static const transform_data transform_default_data = {
869       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
870       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
871       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
872       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
873       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
874       { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } }
875 };
876
877 static const transform_data transform_poison_data = {
878       { { { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
879         9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f } } },
880
881       { { { 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
882         25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
883
884       { { { 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f, 40.0f,
885         41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f } } },
886
887       { { { 49.0f, 50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f,
888         57.0f, 58.0f, 59.0f, 60.0f, 61.0f, 62.0f, 63.0f, 64.0f } } },
889
890       { { { 64.0f, 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, 71.0f, 72.0f,
891         73.0f, 74.0f, 75.0f, 76.0f, 77.0f, 78.0f, 79.0f, 80.0f } } },
892
893       { { { 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, 86.0f, 87.0f, 88.0f,
894         89.0f, 90.0f, 91.0f, 92.0f, 93.0f, 94.0f, 95.0f, 96.0f} } },
895 };
896
897 static const transform_data transform_test_data = {
898       { { { 1.2f, 3.4f, -5.6f, 7.2f, 10.11f, -12.13f, 14.15f, -1.5f,
899         23.56f, 12.89f, 44.56f, -1.0f, 2.3f, 0.0f, 4.4f, 5.5f } } },
900
901       { { { 9.2f, 38.7f, -6.6f, 7.2f, 10.11f, -12.13f, 77.15f, -1.5f,
902         23.56f, 12.89f, 14.56f, -1.0f, 12.3f, 0.0f, 4.4f, 5.5f } } },
903
904       { { { 10.2f, 3.4f, 0.6f, 7.2f, 10.11f, -12.13f, 14.15f, -1.5f,
905         23.54f, 12.9f, 44.56f, -1.0f, 2.3f, 0.0f, 4.4f, 5.5f } } },
906
907       { { { 1.2f, 3.4f, -5.6f, 7.2f, 10.11f, -12.13f, -14.5f, -1.5f,
908         2.56f, 12.89f, 23.56f, -1.0f, 112.3f, 0.0f, 4.4f, 2.5f } } },
909
910       { { { 1.2f, 31.41f, 58.6f, 7.2f, 10.11f, -12.13f, -14.5f, -1.5f,
911         2.56f, 12.89f, 11.56f, -1.0f, 112.3f, 0.0f, 44.4f, 2.5f } } },
912
913       { { { 1.20f, 3.4f, -5.6f, 7.0f, 10.11f, -12.156f, -14.5f, -1.5f,
914         2.56f, 1.829f, 23.6f, -1.0f, 112.3f, 0.0f, 41.4f, 2.5f } } },
915 };
916
917 static HRESULT transform_setup_handler(
918     state_test* test) {
919
920     transform_context *ctx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(transform_context));
921     if (ctx == NULL) return E_FAIL;
922     test->test_context = ctx;
923
924     test->return_data = &ctx->return_data_buffer;
925     test->test_data_in = &transform_test_data;
926     test->test_data_out = &transform_test_data;
927     test->default_data = &transform_default_data;
928     test->initial_data = &transform_default_data;
929     test->poison_data = &transform_poison_data;
930
931     test->data_size = sizeof(transform_data);
932
933     return D3D_OK;
934 }
935
936 static void transform_teardown_handler(
937     state_test* test) {
938     
939     HeapFree(GetProcessHeap(), 0, test->test_context);
940 }
941
942 static void transform_queue_test(
943     state_test* test) {
944
945     test->setup_handler = transform_setup_handler;
946     test->teardown_handler = transform_teardown_handler;
947     test->set_handler = transform_set_handler;
948     test->get_handler = transform_get_handler;
949     test->print_handler = transform_print_handler;
950     test->test_name = "set_get_transforms";
951     test->test_arg = NULL;
952 }
953
954 /* =================== State test: Render States ===================================== */
955
956 #define D3D9_RENDER_STATES 102
957 const D3DRENDERSTATETYPE render_state_indices[] = {
958
959     D3DRS_ZENABLE,
960     D3DRS_FILLMODE,
961     D3DRS_SHADEMODE,
962     D3DRS_ZWRITEENABLE,
963     D3DRS_ALPHATESTENABLE,
964     D3DRS_LASTPIXEL,
965     D3DRS_SRCBLEND,
966     D3DRS_DESTBLEND,
967     D3DRS_CULLMODE,
968     D3DRS_ZFUNC,
969     D3DRS_ALPHAREF,
970     D3DRS_ALPHAFUNC,
971     D3DRS_DITHERENABLE,
972     D3DRS_ALPHABLENDENABLE,
973     D3DRS_FOGENABLE,
974     D3DRS_SPECULARENABLE,
975     D3DRS_FOGCOLOR,
976     D3DRS_FOGTABLEMODE,
977     D3DRS_FOGSTART,
978     D3DRS_FOGEND,
979     D3DRS_FOGDENSITY,
980     D3DRS_RANGEFOGENABLE,
981     D3DRS_STENCILENABLE,
982     D3DRS_STENCILFAIL,
983     D3DRS_STENCILZFAIL,
984     D3DRS_STENCILPASS,
985     D3DRS_STENCILFUNC,
986     D3DRS_STENCILREF,
987     D3DRS_STENCILMASK,
988     D3DRS_STENCILWRITEMASK,
989     D3DRS_TEXTUREFACTOR,
990     D3DRS_WRAP0,
991     D3DRS_WRAP1,
992     D3DRS_WRAP2,
993     D3DRS_WRAP3,
994     D3DRS_WRAP4,
995     D3DRS_WRAP5,
996     D3DRS_WRAP6,
997     D3DRS_WRAP7,
998     D3DRS_CLIPPING,
999     D3DRS_LIGHTING,
1000     D3DRS_AMBIENT,
1001     D3DRS_FOGVERTEXMODE,
1002     D3DRS_COLORVERTEX,
1003     D3DRS_LOCALVIEWER,
1004     D3DRS_NORMALIZENORMALS,
1005     D3DRS_DIFFUSEMATERIALSOURCE,
1006     D3DRS_SPECULARMATERIALSOURCE,
1007     D3DRS_AMBIENTMATERIALSOURCE,
1008     D3DRS_EMISSIVEMATERIALSOURCE,
1009     D3DRS_VERTEXBLEND,
1010     D3DRS_CLIPPLANEENABLE,
1011 #if 0 /* Driver dependent, increase array size to enable */
1012     D3DRS_POINTSIZE,
1013 #endif
1014     D3DRS_POINTSIZE_MIN,
1015     D3DRS_POINTSPRITEENABLE,
1016     D3DRS_POINTSCALEENABLE,
1017     D3DRS_POINTSCALE_A,
1018     D3DRS_POINTSCALE_B,
1019     D3DRS_POINTSCALE_C,
1020     D3DRS_MULTISAMPLEANTIALIAS,
1021     D3DRS_MULTISAMPLEMASK,
1022     D3DRS_PATCHEDGESTYLE,
1023     D3DRS_DEBUGMONITORTOKEN,
1024     D3DRS_POINTSIZE_MAX,
1025     D3DRS_INDEXEDVERTEXBLENDENABLE,
1026     D3DRS_COLORWRITEENABLE,
1027     D3DRS_TWEENFACTOR,
1028     D3DRS_BLENDOP,
1029     D3DRS_POSITIONDEGREE,
1030     D3DRS_NORMALDEGREE,
1031     D3DRS_SCISSORTESTENABLE,
1032     D3DRS_SLOPESCALEDEPTHBIAS,
1033     D3DRS_ANTIALIASEDLINEENABLE,
1034     D3DRS_MINTESSELLATIONLEVEL,
1035     D3DRS_MAXTESSELLATIONLEVEL,
1036     D3DRS_ADAPTIVETESS_X,
1037     D3DRS_ADAPTIVETESS_Y,
1038     D3DRS_ADAPTIVETESS_Z,
1039     D3DRS_ADAPTIVETESS_W,
1040     D3DRS_ENABLEADAPTIVETESSELLATION,
1041     D3DRS_TWOSIDEDSTENCILMODE,
1042     D3DRS_CCW_STENCILFAIL,
1043     D3DRS_CCW_STENCILZFAIL,
1044     D3DRS_CCW_STENCILPASS,
1045     D3DRS_CCW_STENCILFUNC,
1046     D3DRS_COLORWRITEENABLE1,
1047     D3DRS_COLORWRITEENABLE2,
1048     D3DRS_COLORWRITEENABLE3,
1049     D3DRS_BLENDFACTOR,
1050     D3DRS_SRGBWRITEENABLE,
1051     D3DRS_DEPTHBIAS,
1052     D3DRS_WRAP8,
1053     D3DRS_WRAP9,
1054     D3DRS_WRAP10,
1055     D3DRS_WRAP11,
1056     D3DRS_WRAP12,
1057     D3DRS_WRAP13,
1058     D3DRS_WRAP14,
1059     D3DRS_WRAP15,
1060     D3DRS_SEPARATEALPHABLENDENABLE,
1061     D3DRS_SRCBLENDALPHA,
1062     D3DRS_DESTBLENDALPHA,
1063     D3DRS_BLENDOPALPHA,
1064 };
1065
1066 typedef struct render_state_data {
1067     DWORD states[D3D9_RENDER_STATES];
1068 } render_state_data;
1069
1070 typedef struct render_state_arg {
1071     D3DPRESENT_PARAMETERS* device_pparams;
1072 } render_state_arg;
1073
1074 typedef struct render_state_context {
1075    render_state_data return_data_buffer;
1076    render_state_data default_data_buffer;
1077    render_state_data test_data_buffer;
1078    render_state_data poison_data_buffer;
1079 } render_state_context;
1080
1081 static void render_state_set_handler(
1082     IDirect3DDevice9* device, const state_test* test, const void* data) {
1083
1084     HRESULT hret;
1085     const render_state_data* rsdata = data;
1086     unsigned int i;
1087
1088     for (i = 0; i < D3D9_RENDER_STATES; i++) {
1089         hret = IDirect3DDevice9_SetRenderState(device, render_state_indices[i], rsdata->states[i]);
1090         ok(hret == D3D_OK, "SetRenderState returned %#x.\n", hret);
1091     }
1092 }
1093
1094 static void render_state_get_handler(
1095     IDirect3DDevice9* device, const state_test* test, void* data) {
1096
1097     HRESULT hret;
1098     render_state_data* rsdata = (render_state_data*) data;
1099     unsigned int i = 0;
1100
1101     for (i = 0; i < D3D9_RENDER_STATES; i++) {
1102         hret = IDirect3DDevice9_GetRenderState(device, render_state_indices[i], &rsdata->states[i]);
1103         ok(hret == D3D_OK, "GetRenderState returned %#x.\n", hret);
1104     }
1105 }
1106
1107 static void render_state_print_handler(
1108     const state_test* test,
1109     const void* data) {
1110
1111     const render_state_data* rsdata = data;
1112
1113     unsigned int i;
1114     for (i = 0; i < D3D9_RENDER_STATES; i++)
1115         trace("Index = %u, Value = %#x\n", i, rsdata->states[i]);
1116 }
1117
1118 static inline DWORD to_dword(float fl) {
1119     return *((DWORD*) &fl);
1120 }
1121
1122 static void render_state_default_data_init(
1123     D3DPRESENT_PARAMETERS* device_pparams,
1124     render_state_data* data) {
1125
1126    unsigned int idx = 0;
1127
1128    data->states[idx++] = device_pparams->EnableAutoDepthStencil?
1129                          D3DZB_TRUE : D3DZB_FALSE;  /* ZENABLE */
1130    data->states[idx++] = D3DFILL_SOLID;         /* FILLMODE */
1131    data->states[idx++] = D3DSHADE_GOURAUD;      /* SHADEMODE */
1132    data->states[idx++] = TRUE;                  /* ZWRITEENABLE */
1133    data->states[idx++] = FALSE;                 /* ALPHATESTENABLE */
1134    data->states[idx++] = TRUE;                  /* LASTPIXEL */
1135    data->states[idx++] = D3DBLEND_ONE;          /* SRCBLEND */
1136    data->states[idx++] = D3DBLEND_ZERO;         /* DESTBLEND */
1137    data->states[idx++] = D3DCULL_CCW;           /* CULLMODE */
1138    data->states[idx++] = D3DCMP_LESSEQUAL;      /* ZFUNC */
1139    data->states[idx++] = 0;                     /* ALPHAREF */
1140    data->states[idx++] = D3DCMP_ALWAYS;         /* ALPHAFUNC */
1141    data->states[idx++] = FALSE;                 /* DITHERENABLE */
1142    data->states[idx++] = FALSE;                 /* ALPHABLENDENABLE */
1143    data->states[idx++] = FALSE;                 /* FOGENABLE */
1144    data->states[idx++] = FALSE;                 /* SPECULARENABLE */
1145    data->states[idx++] = 0;                     /* FOGCOLOR */
1146    data->states[idx++] = D3DFOG_NONE;           /* FOGTABLEMODE */
1147    data->states[idx++] = to_dword(0.0f);        /* FOGSTART */
1148    data->states[idx++] = to_dword(1.0f);        /* FOGEND */
1149    data->states[idx++] = to_dword(1.0f);        /* FOGDENSITY */
1150    data->states[idx++] = FALSE;                 /* RANGEFOGENABLE */
1151    data->states[idx++] = FALSE;                 /* STENCILENABLE */
1152    data->states[idx++] = D3DSTENCILOP_KEEP;     /* STENCILFAIL */
1153    data->states[idx++] = D3DSTENCILOP_KEEP;     /* STENCILZFAIL */
1154    data->states[idx++] = D3DSTENCILOP_KEEP;     /* STENCILPASS */
1155    data->states[idx++] = D3DCMP_ALWAYS;         /* STENCILFUNC */
1156    data->states[idx++] = 0;                     /* STENCILREF */
1157    data->states[idx++] = 0xFFFFFFFF;            /* STENCILMASK */
1158    data->states[idx++] = 0xFFFFFFFF;            /* STENCILWRITEMASK */
1159    data->states[idx++] = 0xFFFFFFFF;            /* TEXTUREFACTOR */
1160    data->states[idx++] = 0;                     /* WRAP 0 */
1161    data->states[idx++] = 0;                     /* WRAP 1 */
1162    data->states[idx++] = 0;                     /* WRAP 2 */
1163    data->states[idx++] = 0;                     /* WRAP 3 */
1164    data->states[idx++] = 0;                     /* WRAP 4 */
1165    data->states[idx++] = 0;                     /* WRAP 5 */
1166    data->states[idx++] = 0;                     /* WRAP 6 */
1167    data->states[idx++] = 0;                     /* WRAP 7 */
1168    data->states[idx++] = TRUE;                  /* CLIPPING */
1169    data->states[idx++] = TRUE;                  /* LIGHTING */
1170    data->states[idx++] = 0;                     /* AMBIENT */
1171    data->states[idx++] = D3DFOG_NONE;           /* FOGVERTEXMODE */
1172    data->states[idx++] = TRUE;                  /* COLORVERTEX */
1173    data->states[idx++] = TRUE;                  /* LOCALVIEWER */
1174    data->states[idx++] = FALSE;                 /* NORMALIZENORMALS */
1175    data->states[idx++] = D3DMCS_COLOR1;         /* DIFFUSEMATERIALSOURCE */
1176    data->states[idx++] = D3DMCS_COLOR2;         /* SPECULARMATERIALSOURCE */
1177    data->states[idx++] = D3DMCS_MATERIAL;       /* AMBIENTMATERIALSOURCE */
1178    data->states[idx++] = D3DMCS_MATERIAL;       /* EMISSIVEMATERIALSOURCE */
1179    data->states[idx++] = D3DVBF_DISABLE;        /* VERTEXBLEND */
1180    data->states[idx++] = 0;                     /* CLIPPLANEENABLE */
1181 #if 0 /* Driver dependent, increase array size to enable */
1182    data->states[idx++] = to_dword(1.0f);       /* POINTSIZE */
1183 #endif
1184    data->states[idx++] = to_dword(1.0f);        /* POINTSIZEMIN */
1185    data->states[idx++] = FALSE;                 /* POINTSPRITEENABLE */
1186    data->states[idx++] = FALSE;                 /* POINTSCALEENABLE */
1187    data->states[idx++] = to_dword(1.0f);        /* POINTSCALE_A */
1188    data->states[idx++] = to_dword(0.0f);        /* POINTSCALE_B */
1189    data->states[idx++] = to_dword(0.0f);        /* POINTSCALE_C */
1190    data->states[idx++] = TRUE;                  /* MULTISAMPLEANTIALIAS */
1191    data->states[idx++] = 0xFFFFFFFF;            /* MULTISAMPLEMASK */
1192    data->states[idx++] = D3DPATCHEDGE_DISCRETE; /* PATCHEDGESTYLE */ 
1193    data->states[idx++] = 0xbaadcafe;            /* DEBUGMONITORTOKEN */
1194    data->states[idx++] = to_dword(64.0f);       /* POINTSIZE_MAX */
1195    data->states[idx++] = FALSE;                 /* INDEXEDVERTEXBLENDENABLE */
1196    data->states[idx++] = 0x0000000F;            /* COLORWRITEENABLE */
1197    data->states[idx++] = to_dword(0.0f);        /* TWEENFACTOR */
1198    data->states[idx++] = D3DBLENDOP_ADD;        /* BLENDOP */
1199    data->states[idx++] = D3DDEGREE_CUBIC;       /* POSITIONDEGREE */
1200    data->states[idx++] = D3DDEGREE_LINEAR;      /* NORMALDEGREE */
1201    data->states[idx++] = FALSE;                 /* SCISSORTESTENABLE */
1202    data->states[idx++] = to_dword(0.0f);        /* SLOPESCALEDEPTHBIAS */
1203    data->states[idx++] = FALSE;                 /* ANTIALIASEDLINEENABLE */
1204    data->states[idx++] = to_dword(1.0f);        /* MINTESSELATIONLEVEL */
1205    data->states[idx++] = to_dword(1.0f);        /* MAXTESSELATIONLEVEL */
1206    data->states[idx++] = to_dword(0.0f);        /* ADAPTIVETESS_X */
1207    data->states[idx++] = to_dword(0.0f);        /* ADAPTIVETESS_Y */
1208    data->states[idx++] = to_dword(1.0f);        /* ADAPTIVETESS_Z */
1209    data->states[idx++] = to_dword(0.0f);        /* ADAPTIVETESS_W */
1210    data->states[idx++] = FALSE;                 /* ENABLEADAPTIVETESSELATION */
1211    data->states[idx++] = FALSE;                 /* TWOSIDEDSTENCILMODE */
1212    data->states[idx++] = D3DSTENCILOP_KEEP;     /* CCW_STENCILFAIL */
1213    data->states[idx++] = D3DSTENCILOP_KEEP;     /* CCW_STENCILZFAIL */
1214    data->states[idx++] = D3DSTENCILOP_KEEP;     /* CCW_STENCILPASS */
1215    data->states[idx++] = D3DCMP_ALWAYS;         /* CCW_STENCILFUNC */
1216    data->states[idx++] = 0x0000000F;            /* COLORWRITEENABLE1 */
1217    data->states[idx++] = 0x0000000F;            /* COLORWRITEENABLE2 */
1218    data->states[idx++] = 0x0000000F;            /* COLORWRITEENABLE3 */
1219    data->states[idx++] = 0xFFFFFFFF;            /* BLENDFACTOR */
1220    data->states[idx++] = 0;                     /* SRGBWRITEENABLE */
1221    data->states[idx++] = to_dword(0.0f);        /* DEPTHBIAS */
1222    data->states[idx++] = 0;                     /* WRAP8 */
1223    data->states[idx++] = 0;                     /* WRAP9 */
1224    data->states[idx++] = 0;                     /* WRAP10 */
1225    data->states[idx++] = 0;                     /* WRAP11 */
1226    data->states[idx++] = 0;                     /* WRAP12 */
1227    data->states[idx++] = 0;                     /* WRAP13 */
1228    data->states[idx++] = 0;                     /* WRAP14 */
1229    data->states[idx++] = 0;                     /* WRAP15 */
1230    data->states[idx++] = FALSE;                 /* SEPARATEALPHABLENDENABLE */
1231    data->states[idx++] = D3DBLEND_ONE;          /* SRCBLENDALPHA */
1232    data->states[idx++] = D3DBLEND_ZERO;         /* DESTBLENDALPHA */
1233    data->states[idx++] = TRUE;                  /* BLENDOPALPHA */
1234 }
1235
1236 static void render_state_poison_data_init(
1237     render_state_data* data) {
1238
1239    unsigned int i;
1240    for (i = 0; i < D3D9_RENDER_STATES; i++)
1241        data->states[i] = 0x1337c0de;
1242 }
1243  
1244 static void render_state_test_data_init(
1245     render_state_data* data) {
1246
1247    unsigned int idx = 0;
1248    data->states[idx++] = D3DZB_USEW;            /* ZENABLE */
1249    data->states[idx++] = D3DFILL_WIREFRAME;     /* FILLMODE */
1250    data->states[idx++] = D3DSHADE_PHONG;        /* SHADEMODE */
1251    data->states[idx++] = FALSE;                 /* ZWRITEENABLE */
1252    data->states[idx++] = TRUE;                  /* ALPHATESTENABLE */
1253    data->states[idx++] = FALSE;                 /* LASTPIXEL */
1254    data->states[idx++] = D3DBLEND_SRCALPHASAT;  /* SRCBLEND */
1255    data->states[idx++] = D3DBLEND_INVDESTALPHA; /* DESTBLEND */
1256    data->states[idx++] = D3DCULL_CW;            /* CULLMODE */
1257    data->states[idx++] = D3DCMP_NOTEQUAL;       /* ZFUNC */
1258    data->states[idx++] = 10;                    /* ALPHAREF */
1259    data->states[idx++] = D3DCMP_GREATER;        /* ALPHAFUNC */
1260    data->states[idx++] = TRUE;                  /* DITHERENABLE */
1261    data->states[idx++] = TRUE;                  /* ALPHABLENDENABLE */
1262    data->states[idx++] = TRUE;                  /* FOGENABLE */
1263    data->states[idx++] = TRUE;                  /* SPECULARENABLE */
1264    data->states[idx++] = 255 << 31;             /* FOGCOLOR */
1265    data->states[idx++] = D3DFOG_EXP;            /* FOGTABLEMODE */
1266    data->states[idx++] = to_dword(0.1f);        /* FOGSTART */
1267    data->states[idx++] = to_dword(0.8f);        /* FOGEND */
1268    data->states[idx++] = to_dword(0.5f);        /* FOGDENSITY */
1269    data->states[idx++] = TRUE;                  /* RANGEFOGENABLE */
1270    data->states[idx++] = TRUE;                  /* STENCILENABLE */
1271    data->states[idx++] = D3DSTENCILOP_INCRSAT;  /* STENCILFAIL */
1272    data->states[idx++] = D3DSTENCILOP_REPLACE;  /* STENCILZFAIL */
1273    data->states[idx++] = D3DSTENCILOP_INVERT;   /* STENCILPASS */
1274    data->states[idx++] = D3DCMP_LESS;           /* STENCILFUNC */
1275    data->states[idx++] = 10;                    /* STENCILREF */
1276    data->states[idx++] = 0xFF00FF00;            /* STENCILMASK */
1277    data->states[idx++] = 0x00FF00FF;            /* STENCILWRITEMASK */
1278    data->states[idx++] = 0xF0F0F0F0;            /* TEXTUREFACTOR */
1279    data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_2;                                   /* WRAP 0 */
1280    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3;                                   /* WRAP 1 */
1281    data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_3;                                   /* WRAP 2 */
1282    data->states[idx++] = D3DWRAPCOORD_3 | D3DWRAPCOORD_0;                                   /* WRAP 4 */
1283    data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_1 | D3DWRAPCOORD_2;                  /* WRAP 5 */
1284    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3 | D3DWRAPCOORD_2;                  /* WRAP 6 */
1285    data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_1 | D3DWRAPCOORD_0;                  /* WRAP 7 */
1286    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_0 | D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 8 */
1287    data->states[idx++] = FALSE;                 /* CLIPPING */
1288    data->states[idx++] = FALSE;                 /* LIGHTING */
1289    data->states[idx++] = 255 << 16;             /* AMBIENT */
1290    data->states[idx++] = D3DFOG_EXP2;           /* FOGVERTEXMODE */
1291    data->states[idx++] = FALSE;                 /* COLORVERTEX */
1292    data->states[idx++] = FALSE;                 /* LOCALVIEWER */
1293    data->states[idx++] = TRUE;                  /* NORMALIZENORMALS */
1294    data->states[idx++] = D3DMCS_COLOR2;         /* DIFFUSEMATERIALSOURCE */
1295    data->states[idx++] = D3DMCS_MATERIAL;       /* SPECULARMATERIALSOURCE */
1296    data->states[idx++] = D3DMCS_COLOR1;         /* AMBIENTMATERIALSOURCE */
1297    data->states[idx++] = D3DMCS_COLOR2;         /* EMISSIVEMATERIALSOURCE */
1298    data->states[idx++] = D3DVBF_3WEIGHTS;       /* VERTEXBLEND */
1299    data->states[idx++] = 0xf1f1f1f1;            /* CLIPPLANEENABLE */
1300 #if 0 /* Driver dependent, increase array size to enable */
1301    data->states[idx++] = to_dword(32.0f);       /* POINTSIZE */
1302 #endif
1303    data->states[idx++] = to_dword(0.7f);        /* POINTSIZEMIN */
1304    data->states[idx++] = TRUE;                  /* POINTSPRITEENABLE */
1305    data->states[idx++] = TRUE;                  /* POINTSCALEENABLE */
1306    data->states[idx++] = to_dword(0.7f);        /* POINTSCALE_A */
1307    data->states[idx++] = to_dword(0.5f);        /* POINTSCALE_B */
1308    data->states[idx++] = to_dword(0.4f);        /* POINTSCALE_C */
1309    data->states[idx++] = FALSE;                 /* MULTISAMPLEANTIALIAS */
1310    data->states[idx++] = 0xABCDDBCA;            /* MULTISAMPLEMASK */
1311    data->states[idx++] = D3DPATCHEDGE_CONTINUOUS; /* PATCHEDGESTYLE */
1312    data->states[idx++] = D3DDMT_DISABLE;        /* DEBUGMONITORTOKEN */
1313    data->states[idx++] = to_dword(77.0f);       /* POINTSIZE_MAX */
1314    data->states[idx++] = TRUE;                  /* INDEXEDVERTEXBLENDENABLE */
1315    data->states[idx++] = 0x00000009;            /* COLORWRITEENABLE */
1316    data->states[idx++] = to_dword(0.2f);        /* TWEENFACTOR */
1317    data->states[idx++] = D3DBLENDOP_REVSUBTRACT;/* BLENDOP */
1318    data->states[idx++] = D3DDEGREE_LINEAR;      /* POSITIONDEGREE */
1319    data->states[idx++] = D3DDEGREE_CUBIC;       /* NORMALDEGREE */
1320    data->states[idx++] = TRUE;                  /* SCISSORTESTENABLE */
1321    data->states[idx++] = to_dword(0.33f);       /* SLOPESCALEDEPTHBIAS */
1322    data->states[idx++] = TRUE;                  /* ANTIALIASEDLINEENABLE */
1323    data->states[idx++] = to_dword(0.8f);        /* MINTESSELATIONLEVEL */
1324    data->states[idx++] = to_dword(0.8f);        /* MAXTESSELATIONLEVEL */
1325    data->states[idx++] = to_dword(0.2f);        /* ADAPTIVETESS_X */
1326    data->states[idx++] = to_dword(0.3f);        /* ADAPTIVETESS_Y */
1327    data->states[idx++] = to_dword(0.6f);        /* ADAPTIVETESS_Z */
1328    data->states[idx++] = to_dword(0.4f);        /* ADAPTIVETESS_W */
1329    data->states[idx++] = TRUE;                  /* ENABLEADAPTIVETESSELATION */
1330    data->states[idx++] = TRUE;                  /* TWOSIDEDSTENCILMODE */
1331    data->states[idx++] = D3DSTENCILOP_ZERO;     /* CCW_STENCILFAIL */
1332    data->states[idx++] = D3DSTENCILOP_DECR;     /* CCW_STENCILZFAIL */
1333    data->states[idx++] = D3DSTENCILOP_INCR;     /* CCW_STENCILPASS */
1334    data->states[idx++] = D3DCMP_ALWAYS;         /* CCW_STENCILFUNC */
1335    data->states[idx++] = 0x00000007;            /* COLORWRITEENABLE1 */
1336    data->states[idx++] = 0x00000008;            /* COLORWRITEENABLE2 */
1337    data->states[idx++] = 0x00000004;            /* COLORWRITEENABLE3 */
1338    data->states[idx++] = 0xF0F1F2F3;            /* BLENDFACTOR */
1339    data->states[idx++] = 1;                     /* SRGBWRITEENABLE */
1340    data->states[idx++] = to_dword(0.3f);        /* DEPTHBIAS */
1341    data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_2;                                   /* WRAP 8 */
1342    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3;                                   /* WRAP 9 */
1343    data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_3;                                   /* WRAP 10 */
1344    data->states[idx++] = D3DWRAPCOORD_3 | D3DWRAPCOORD_0;                                   /* WRAP 11 */
1345    data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_1 | D3DWRAPCOORD_2;                  /* WRAP 12 */
1346    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3 | D3DWRAPCOORD_2;                  /* WRAP 13 */
1347    data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_1 | D3DWRAPCOORD_0;                  /* WRAP 14 */
1348    data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_0 | D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 15 */
1349    data->states[idx++] = TRUE;                  /* SEPARATEALPHABLENDENABLE */
1350    data->states[idx++] = D3DBLEND_ZERO;         /* SRCBLENDALPHA */
1351    data->states[idx++] = D3DBLEND_ONE;          /* DESTBLENDALPHA */
1352    data->states[idx++] = FALSE;                 /* BLENDOPALPHA */
1353 }
1354
1355 static HRESULT render_state_setup_handler(
1356     state_test* test) {
1357
1358     const render_state_arg* rsarg = test->test_arg;
1359
1360     render_state_context *ctx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(render_state_context));
1361     if (ctx == NULL) return E_FAIL;
1362     test->test_context = ctx;
1363
1364     test->return_data = &ctx->return_data_buffer;
1365     test->default_data = &ctx->default_data_buffer;
1366     test->initial_data = &ctx->default_data_buffer;
1367     test->test_data_in = &ctx->test_data_buffer;
1368     test->test_data_out = &ctx->test_data_buffer;
1369     test->poison_data = &ctx->poison_data_buffer;
1370
1371     render_state_default_data_init(rsarg->device_pparams, &ctx->default_data_buffer);
1372     render_state_test_data_init(&ctx->test_data_buffer);
1373     render_state_poison_data_init(&ctx->poison_data_buffer);
1374
1375     test->data_size = sizeof(render_state_data);
1376
1377     return D3D_OK;
1378 }
1379
1380 static void render_state_teardown_handler(
1381     state_test* test) {
1382
1383     HeapFree(GetProcessHeap(), 0, test->test_context);
1384 }
1385
1386 static void render_states_queue_test(
1387     state_test* test,
1388     const render_state_arg* test_arg) {
1389
1390     test->setup_handler = render_state_setup_handler;
1391     test->teardown_handler = render_state_teardown_handler;
1392     test->set_handler = render_state_set_handler;
1393     test->get_handler = render_state_get_handler;
1394     test->print_handler = render_state_print_handler;
1395     test->test_name = "set_get_render_states";
1396     test->test_arg = test_arg;
1397 }
1398
1399 /* =================== Main state tests function =============================== */
1400
1401 static void test_state_management(
1402     IDirect3DDevice9 *device,
1403     D3DPRESENT_PARAMETERS *device_pparams) {
1404
1405     HRESULT hret;
1406     D3DCAPS9 caps;
1407
1408     /* Test count: 2 for shader constants 
1409                    1 for lights
1410                    1 for transforms
1411                    1 for render states
1412      */
1413     const int max_tests = 5;
1414     state_test tests[5];
1415     unsigned int tcount = 0;
1416
1417     shader_constant_arg pshader_constant_arg;
1418     shader_constant_arg vshader_constant_arg;
1419     render_state_arg render_state_arg;
1420     light_arg light_arg;
1421
1422     hret = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1423     ok(hret == D3D_OK, "GetDeviceCaps returned %#x.\n", hret);
1424     if (hret != D3D_OK) return;
1425
1426     texture_stages = caps.MaxTextureBlendStages;
1427
1428     /* Zero test memory */
1429     memset(tests, 0, sizeof(state_test) * max_tests);
1430
1431     if (caps.VertexShaderVersion & 0xffff) {
1432         vshader_constant_arg.idx = 0;
1433         vshader_constant_arg.pshader = FALSE;
1434         shader_constants_queue_test(&tests[tcount], &vshader_constant_arg);
1435         tcount++;
1436     }
1437
1438     if (caps.PixelShaderVersion & 0xffff) {
1439         pshader_constant_arg.idx = 0;
1440         pshader_constant_arg.pshader = TRUE;
1441         shader_constants_queue_test(&tests[tcount], &pshader_constant_arg);
1442         tcount++;
1443     }
1444
1445     light_arg.idx = 0;
1446     lights_queue_test(&tests[tcount], &light_arg);
1447     tcount++;
1448
1449     transform_queue_test(&tests[tcount]);
1450     tcount++;
1451
1452     render_state_arg.device_pparams = device_pparams;
1453     render_states_queue_test(&tests[tcount], &render_state_arg);
1454     tcount++;
1455
1456     execute_test_chain_all(device, tests, tcount);
1457 }
1458
1459 START_TEST(stateblock)
1460 {
1461     IDirect3DDevice9 *device_ptr = NULL;
1462     D3DPRESENT_PARAMETERS device_pparams;
1463     HRESULT hret;
1464
1465     d3d9_handle = LoadLibraryA("d3d9.dll");
1466     if (!d3d9_handle)
1467     {
1468         skip("Could not load d3d9.dll\n");
1469         return;
1470     }
1471
1472     hret = init_d3d9(&device_ptr, &device_pparams);
1473     if (hret != D3D_OK) return;
1474
1475     test_begin_end_state_block(device_ptr);
1476     test_state_management(device_ptr, &device_pparams);
1477
1478     if (device_ptr) IUnknown_Release(device_ptr);
1479 }