2 * Copyright (C) 2005 Henri Verbeet
3 * Copyright (C) 2006 Ivan Gyurdiev
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
22 #include "wine/test.h"
24 static HMODULE d3d9_handle = 0;
26 static HWND create_window(void)
29 wc.lpfnWndProc = &DefWindowProc;
30 wc.lpszClassName = "d3d9_test_wc";
33 return CreateWindow("d3d9_test_wc", "d3d9_test",
34 0, 0, 0, 0, 0, 0, 0, 0, 0);
37 static HRESULT init_d3d9(
38 IDirect3DDevice9** device,
39 D3DPRESENT_PARAMETERS* device_pparams)
41 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
42 IDirect3D9 *d3d9_ptr = 0;
46 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
47 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
48 if (!d3d9_create) return E_FAIL;
50 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
51 ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
52 if (!d3d9_ptr) return E_FAIL;
54 window = create_window();
56 ZeroMemory(device_pparams, sizeof(D3DPRESENT_PARAMETERS));
57 device_pparams->Windowed = TRUE;
58 device_pparams->hDeviceWindow = window;
59 device_pparams->SwapEffect = D3DSWAPEFFECT_DISCARD;
61 hres = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, window,
62 D3DCREATE_SOFTWARE_VERTEXPROCESSING, device_pparams, device);
63 ok(hres == D3D_OK, "IDirect3D_CreateDevice returned: 0x%lx\n", hres);
67 static void test_begin_end_state_block(IDirect3DDevice9 *device_ptr)
70 IDirect3DStateBlock9 *state_block_ptr = 0;
73 hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
74 ok(hret == D3D_OK, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3D_OK);
75 if (hret != D3D_OK) return;
77 /* Calling BeginStateBlock while recording should return D3DERR_INVALIDCALL */
78 hret = IDirect3DDevice9_BeginStateBlock(device_ptr);
79 ok(hret == D3DERR_INVALIDCALL, "BeginStateBlock returned: hret 0x%lx. Expected hret 0x%lx. Aborting.\n", hret, D3DERR_INVALIDCALL);
80 if (hret != D3DERR_INVALIDCALL) return;
83 state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
84 hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
85 ok(hret == D3D_OK && state_block_ptr != 0 && state_block_ptr != (IDirect3DStateBlock9 *)0xdeadbeef,
86 "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
87 "Expected hret 0x%lx, state_block_ptr != %p, state_block_ptr != 0xdeadbeef.\n", hret, state_block_ptr, D3D_OK, NULL);
89 /* Calling EndStateBlock while not recording should return D3DERR_INVALIDCALL. state_block_ptr should not be touched. */
90 state_block_ptr = (IDirect3DStateBlock9 *)0xdeadbeef;
91 hret = IDirect3DDevice9_EndStateBlock(device_ptr, &state_block_ptr);
92 ok(hret == D3DERR_INVALIDCALL && state_block_ptr == (IDirect3DStateBlock9 *)0xdeadbeef,
93 "EndStateBlock returned: hret 0x%lx, state_block_ptr %p. "
94 "Expected hret 0x%lx, state_block_ptr 0xdeadbeef.\n", hret, state_block_ptr, D3DERR_INVALIDCALL);
97 /* ============================ State Testing Framework ========================== */
99 typedef struct state_test {
100 const char* test_name;
102 /* The initial data is usually the same
103 * as the default data, but a write can have side effects.
104 * The initial data is tested first, before any writes take place
105 * The default data can be tested after a write */
106 const void* initial_data;
108 /* The default data is the standard state to compare
109 * against, and restore to */
110 const void* default_data;
112 /* The test data is the experiment data to try
113 * in - what we want to write
114 * out - what windows will actually write (not necessarily the same) */
115 const void* test_data_in;
116 const void* test_data_out;
118 /* The poison data is the data to preinitialize the return buffer to */
119 const void* poison_data;
124 unsigned int data_size;
126 void (*set_handler) (IDirect3DDevice9* device, const void* data, void* set_arg);
127 void (*get_handler) (IDirect3DDevice9* device, const void* data, void* get_arg);
128 void (*print_handler) (const void* data);
135 /* See below for explanation of the flags */
136 #define EVENT_OK 0x00
137 #define EVENT_CHECK_DEFAULT 0x01
138 #define EVENT_CHECK_INITIAL 0x02
139 #define EVENT_CHECK_TEST 0x04
140 #define EVENT_ERROR 0x08
141 #define EVENT_APPLY_DATA 0x10
143 typedef struct event {
144 int (*event_fn) (IDirect3DDevice9* device, void* arg);
148 /* This is an event-machine, which tests things.
149 * It tests get and set operations for a batch of states, based on
150 * results from the event function, which directs what's to be done */
152 static void execute_test_chain(
153 IDirect3DDevice9* device,
157 unsigned int nevents,
161 unsigned int i = 0, j;
163 /* For each queued event */
164 for (j=0; j < nevents; j++) {
166 /* Execute the next event handler (if available) or just set the supplied status */
167 outcome = event[j].status;
168 if (event[j].event_fn)
169 outcome |= event[j].event_fn(device, event_arg);
171 /* Now verify correct outcome depending on what was signaled by the handler.
172 * An EVENT_CHECK_TEST signal means check the returned data against the test_data (out).
173 * An EVENT_CHECK_DEFAULT signal means check the returned data against the default_data.
174 * An EVENT_CHECK_INITIAL signal means check the returned data against the initial_data.
175 * An EVENT_ERROR signal means the test isn't going to work, exit the event loop.
176 * An EVENT_APPLY_DATA signal means load the test data (after checks) */
178 if (outcome & EVENT_ERROR) {
179 trace("Test %s, Stage %u in error state, aborting\n", test[i].test_name, j);
182 } else if (outcome & EVENT_CHECK_TEST || outcome & EVENT_CHECK_DEFAULT || outcome & EVENT_CHECK_INITIAL) {
184 for (i=0; i < ntests; i++) {
186 memcpy(test[i].return_data, test[i].poison_data, test[i].data_size);
187 test[i].get_handler(device, test[i].return_data, test[i].get_arg);
188 if ((outcome & EVENT_CHECK_TEST) &&
189 memcmp(test[i].test_data_out, test[i].return_data, test[i].data_size)) {
191 ok(FALSE, "Test %s, Stage %u: change applied, but returned data does not "
192 "match test data [csize=%u]\n", test[i].test_name, j, test[i].data_size);
194 if (test[i].print_handler) {
195 trace("Returned data was:\n");
196 test[i].print_handler(test[i].return_data);
197 trace("Test data was:\n");
198 test[i].print_handler(test[i].test_data_out);
202 else if ((outcome & EVENT_CHECK_DEFAULT) &&
203 memcmp(test[i].default_data, test[i].return_data, test[i].data_size)) {
205 ok (FALSE, "Test %s, Stage %u: change aborted, but returned data does not "
206 "match default data [csize=%u]\n", test[i].test_name, j, test[i].data_size);
208 if (test[i].print_handler) {
209 trace("Returned data was:\n");
210 test[i].print_handler(test[i].return_data);
211 trace("Default data was:\n");
212 test[i].print_handler(test[i].default_data);
216 else if ((outcome & EVENT_CHECK_INITIAL) &&
217 memcmp(test[i].initial_data, test[i].return_data, test[i].data_size)) {
219 ok (FALSE, "Test %s, Stage %u: returned data does not "
220 "match initial data [csize=%u]\n", test[i].test_name, j, test[i].data_size);
222 if (test[i].print_handler) {
223 trace("Returned data was:\n");
224 test[i].print_handler(test[i].return_data);
225 trace("Initial data was:\n");
226 test[i].print_handler(test[i].initial_data);
232 if (outcome & EVENT_APPLY_DATA) {
233 for (i=0; i < ntests; i++)
234 test[i].set_handler(device, test[i].test_data_in, test[i].set_arg);
238 /* Attempt to reset any changes made */
239 for (i=0; i < ntests; i++)
240 test[i].set_handler(device, test[i].default_data, test[i].set_arg);
243 typedef struct event_data {
244 IDirect3DStateBlock9* stateblock;
245 IDirect3DSurface9* original_render_target;
248 static int switch_render_target(
249 IDirect3DDevice9* device,
253 D3DPRESENT_PARAMETERS present_parameters;
254 event_data* edata = (event_data*) data;
255 IDirect3DSwapChain9* swapchain = NULL;
256 IDirect3DSurface9* backbuffer = NULL;
258 /* Parameters for new swapchain */
259 ZeroMemory(&present_parameters, sizeof(present_parameters));
260 present_parameters.Windowed = TRUE;
261 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
263 /* Create new swapchain */
264 hret = IDirect3DDevice9_CreateAdditionalSwapChain(device, &present_parameters, &swapchain);
265 ok (hret == D3D_OK, "CreateAdditionalSwapChain returned %#lx.\n", hret);
266 if (hret != D3D_OK) goto error;
268 /* Get its backbuffer */
269 hret = IDirect3DSwapChain9_GetBackBuffer(swapchain, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
270 ok (hret == D3D_OK, "GetBackBuffer returned %#lx.\n", hret);
271 if (hret != D3D_OK) goto error;
273 /* Save the current render target */
274 hret = IDirect3DDevice9_GetRenderTarget(device, 0, &edata->original_render_target);
275 ok (hret == D3D_OK, "GetRenderTarget returned %#lx.\n", hret);
276 if (hret != D3D_OK) goto error;
278 /* Set the new swapchain's backbuffer as a render target */
279 hret = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer);
280 ok (hret == D3D_OK, "SetRenderTarget returned %#lx.\n", hret);
281 if (hret != D3D_OK) goto error;
283 IUnknown_Release(backbuffer);
284 IUnknown_Release(swapchain);
288 if (backbuffer) IUnknown_Release(backbuffer);
289 if (swapchain) IUnknown_Release(swapchain);
293 static int revert_render_target(
294 IDirect3DDevice9* device,
298 event_data* edata = (event_data*) data;
300 /* Reset the old render target */
301 hret = IDirect3DDevice9_SetRenderTarget(device, 0, edata->original_render_target);
302 ok (hret == D3D_OK, "SetRenderTarget returned %#lx.\n", hret);
303 if (hret != D3D_OK) {
304 IUnknown_Release(edata->original_render_target);
308 IUnknown_Release(edata->original_render_target);
312 static int begin_stateblock(
313 IDirect3DDevice9* device,
319 hret = IDirect3DDevice9_BeginStateBlock(device);
320 ok(hret == D3D_OK, "BeginStateBlock returned %#lx.\n", hret);
321 if (hret != D3D_OK) return EVENT_ERROR;
325 static int end_stateblock(
326 IDirect3DDevice9* device,
330 event_data* edata = (event_data*) data;
332 hret = IDirect3DDevice9_EndStateBlock(device, &edata->stateblock);
333 ok(hret == D3D_OK, "EndStateBlock returned %#lx.\n", hret);
334 if (hret != D3D_OK) return EVENT_ERROR;
338 static int abort_stateblock(
339 IDirect3DDevice9* device,
342 event_data* edata = (event_data*) data;
344 IUnknown_Release(edata->stateblock);
348 static int apply_stateblock(
349 IDirect3DDevice9* device,
352 event_data* edata = (event_data*) data;
355 hret = IDirect3DStateBlock9_Apply(edata->stateblock);
356 ok(hret == D3D_OK, "Apply returned %#lx.\n", hret);
357 if (hret != D3D_OK) {
358 IUnknown_Release(edata->stateblock);
362 IUnknown_Release(edata->stateblock);
366 static int capture_stateblock(
367 IDirect3DDevice9* device,
371 event_data* edata = (event_data*) data;
373 hret = IDirect3DStateBlock9_Capture(edata->stateblock);
374 ok(hret == D3D_OK, "Capture returned %#lx.\n", hret);
381 static void execute_test_chain_all(
382 IDirect3DDevice9* device,
384 unsigned int ntests) {
388 event read_events[] = {
389 { NULL, EVENT_CHECK_INITIAL }
392 event write_read_events[] = {
393 { NULL, EVENT_APPLY_DATA },
394 { NULL, EVENT_CHECK_TEST }
397 event abort_stateblock_events[] = {
398 { begin_stateblock, EVENT_APPLY_DATA },
399 { end_stateblock, EVENT_OK },
400 { abort_stateblock, EVENT_CHECK_DEFAULT }
403 event apply_stateblock_events[] = {
404 { begin_stateblock, EVENT_APPLY_DATA },
405 { end_stateblock, EVENT_OK },
406 { apply_stateblock, EVENT_CHECK_TEST }
409 event capture_reapply_stateblock_events[] = {
410 { begin_stateblock, EVENT_APPLY_DATA },
411 { end_stateblock, EVENT_OK },
412 { capture_stateblock, EVENT_CHECK_DEFAULT | EVENT_APPLY_DATA },
413 { apply_stateblock, EVENT_CHECK_DEFAULT }
416 event rendertarget_switch_events[] = {
417 { NULL, EVENT_APPLY_DATA },
418 { switch_render_target, EVENT_CHECK_TEST },
419 { revert_render_target, EVENT_OK }
422 event rendertarget_stateblock_events[] = {
423 { begin_stateblock, EVENT_APPLY_DATA },
424 { switch_render_target, EVENT_CHECK_DEFAULT },
425 { end_stateblock, EVENT_OK },
426 { revert_render_target, EVENT_OK },
427 { apply_stateblock, EVENT_CHECK_TEST }
430 trace("Running initial read state tests\n");
431 execute_test_chain(device, test, ntests, read_events, 1, NULL);
433 trace("Running write-read state tests\n");
434 execute_test_chain(device, test, ntests, write_read_events, 2, NULL);
436 trace("Running stateblock abort state tests\n");
437 execute_test_chain(device, test, ntests, abort_stateblock_events, 3, &arg);
439 trace("Running stateblock apply state tests\n");
440 execute_test_chain(device, test, ntests, apply_stateblock_events, 3, &arg);
442 trace("Running stateblock capture/reapply state tests\n");
443 execute_test_chain(device, test, ntests, capture_reapply_stateblock_events, 4, &arg);
445 trace("Running rendertarget switch state tests\n");
446 execute_test_chain(device, test, ntests, rendertarget_switch_events, 3, &arg);
448 trace("Running stateblock apply over rendertarget switch interrupt tests\n");
449 execute_test_chain(device, test, ntests, rendertarget_stateblock_events, 5, &arg);
452 /* =================== State test: Pixel and Vertex Shader constants ============ */
454 typedef struct shader_constant_data {
455 int int_constant[4]; /* 1x4 integer constant */
456 float float_constant[4]; /* 1x4 float constant */
457 BOOL bool_constant[4]; /* 4x1 boolean constants */
458 } shader_constant_data;
460 typedef struct shader_constant_arg {
463 } shader_constant_arg;
465 static void shader_constant_print_handler(
468 shader_constant_data* scdata = (shader_constant_data*) data;
470 trace("Integer constant = { %#x, %#x, %#x, %#x }\n",
471 scdata->int_constant[0], scdata->int_constant[1],
472 scdata->int_constant[2], scdata->int_constant[3]);
474 trace("Float constant = { %f, %f, %f, %f }\n",
475 scdata->float_constant[0], scdata->float_constant[1],
476 scdata->float_constant[2], scdata->float_constant[3]);
478 trace("Boolean constants = [ %#x, %#x, %#x, %#x ]\n",
479 scdata->bool_constant[0], scdata->bool_constant[1],
480 scdata->bool_constant[2], scdata->bool_constant[3]);
483 static void shader_constant_set_handler(
484 IDirect3DDevice9* device, const void* data, void* arg) {
487 shader_constant_data* scdata = (shader_constant_data*) data;
488 shader_constant_arg* scarg = (shader_constant_arg*) arg;
489 unsigned int index = scarg->idx;
491 if (!scarg->pshader) {
492 hret = IDirect3DDevice9_SetVertexShaderConstantI(device, index, scdata->int_constant, 1);
493 ok(hret == D3D_OK, "SetVertexShaderConstantI returned %#lx.\n", hret);
494 hret = IDirect3DDevice9_SetVertexShaderConstantF(device, index, scdata->float_constant, 1);
495 ok(hret == D3D_OK, "SetVertexShaderConstantF returned %#lx.\n", hret);
496 hret = IDirect3DDevice9_SetVertexShaderConstantB(device, index, scdata->bool_constant, 4);
497 ok(hret == D3D_OK, "SetVertexShaderConstantB returned %#lx.\n", hret);
500 hret = IDirect3DDevice9_SetPixelShaderConstantI(device, index, scdata->int_constant, 1);
501 ok(hret == D3D_OK, "SetPixelShaderConstantI returned %#lx.\n", hret);
502 hret = IDirect3DDevice9_SetPixelShaderConstantF(device, index, scdata->float_constant, 1);
503 ok(hret == D3D_OK, "SetPixelShaderConstantF returned %#lx.\n", hret);
504 hret = IDirect3DDevice9_SetPixelShaderConstantB(device, index, scdata->bool_constant, 4);
505 ok(hret == D3D_OK, "SetPixelShaderConstantB returned %#lx.\n", hret);
509 static void shader_constant_get_handler(
510 IDirect3DDevice9* device, const void* data, void* arg) {
513 shader_constant_data* scdata = (shader_constant_data*) data;
514 shader_constant_arg* scarg = (shader_constant_arg*) arg;
515 unsigned int index = scarg->idx;
517 if (!scarg->pshader) {
518 hret = IDirect3DDevice9_GetVertexShaderConstantI(device, index, scdata->int_constant, 1);
519 ok(hret == D3D_OK, "GetVertexShaderConstantI returned %#lx.\n", hret);
520 hret = IDirect3DDevice9_GetVertexShaderConstantF(device, index, scdata->float_constant, 1);
521 ok(hret == D3D_OK, "GetVertexShaderConstantF returned %#lx.\n", hret);
522 hret = IDirect3DDevice9_GetVertexShaderConstantB(device, index, scdata->bool_constant, 4);
523 ok(hret == D3D_OK, "GetVertexShaderConstantB returned %#lx.\n", hret);
526 hret = IDirect3DDevice9_GetPixelShaderConstantI(device, index, scdata->int_constant, 1);
527 ok(hret == D3D_OK, "GetPixelShaderConstantI returned %#lx.\n", hret);
528 hret = IDirect3DDevice9_GetPixelShaderConstantF(device, index, scdata->float_constant, 1);
529 ok(hret == D3D_OK, "GetPixelShaderConstantF returned %#lx.\n", hret);
530 hret = IDirect3DDevice9_GetPixelShaderConstantB(device, index, scdata->bool_constant, 4);
531 ok(hret == D3D_OK, "GetPixelShaderConstantB returned %#lx.\n", hret);
535 static const shader_constant_data shader_constant_poison_data = {
536 { 0x1337c0de, 0x1337c0de, 0x1337c0de, 0x1337c0de },
537 { 1.0f, 2.0f, 3.0f, 4.0f },
538 { FALSE, TRUE, FALSE, TRUE }
541 static const shader_constant_data shader_constant_default_data = {
542 { 0, 0, 0, 0 }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0, 0, 0, 0 }
545 static const shader_constant_data shader_constant_test_data = {
546 { 0xdead0000, 0xdead0001, 0xdead0002, 0xdead0003 },
547 { 0.0f, 0.0f, 0.0f, 0.0f },
548 { TRUE, FALSE, FALSE, TRUE }
551 #define SHADER_CONSTANTS_REQ_BUFFER \
552 (sizeof(shader_constant_data) + sizeof(shader_constant_arg))
554 static void shader_constants_queue_test(
555 IDirect3DDevice9 *device,
560 shader_constant_arg* arg = buffer;
561 shader_constant_data* return_data = (shader_constant_data*) (arg + 1);
563 test->test_data_in = &shader_constant_test_data;
564 test->test_data_out = &shader_constant_test_data;
565 test->default_data = &shader_constant_default_data;
566 test->initial_data = &shader_constant_default_data;
567 test->poison_data = &shader_constant_poison_data;
568 test->return_data = return_data;
569 test->data_size = sizeof(shader_constant_data);
570 test->set_handler = shader_constant_set_handler;
571 test->get_handler = shader_constant_get_handler;
572 test->print_handler = shader_constant_print_handler;
573 test->get_arg = test->set_arg = arg;
574 test->test_name = pshader? "set_get_pshader_constants": "set_get_vshader_constants";
576 arg->pshader = pshader;
579 /* =================== State test: Lights ===================================== */
581 typedef struct light_data {
584 HRESULT get_light_result;
585 HRESULT get_enabled_result;
588 typedef struct light_arg {
592 static void light_print_handler(
595 light_data* ldata = (light_data*) data;
597 trace("Get Light return value: %#lx\n", ldata->get_light_result);
598 trace("Get Light enable return value: %#lx\n", ldata->get_enabled_result);
600 trace("Light Enabled = %u\n", ldata->enabled);
601 trace("Light Type = %u\n", ldata->light.Type);
602 trace("Light Diffuse = { %f, %f, %f, %f }\n",
603 ldata->light.Diffuse.r, ldata->light.Diffuse.g,
604 ldata->light.Diffuse.b, ldata->light.Diffuse.a);
605 trace("Light Specular = { %f, %f, %f, %f}\n",
606 ldata->light.Specular.r, ldata->light.Specular.g,
607 ldata->light.Specular.b, ldata->light.Specular.a);
608 trace("Light Ambient = { %f, %f, %f, %f }\n",
609 ldata->light.Ambient.r, ldata->light.Ambient.g,
610 ldata->light.Ambient.b, ldata->light.Ambient.a);
611 trace("Light Position = { %f, %f, %f }\n",
612 ldata->light.Position.x, ldata->light.Position.y, ldata->light.Position.z);
613 trace("Light Direction = { %f, %f, %f }\n",
614 ldata->light.Direction.x, ldata->light.Direction.y, ldata->light.Direction.z);
615 trace("Light Range = %f\n", ldata->light.Range);
616 trace("Light Fallof = %f\n", ldata->light.Falloff);
617 trace("Light Attenuation0 = %f\n", ldata->light.Attenuation0);
618 trace("Light Attenuation1 = %f\n", ldata->light.Attenuation1);
619 trace("Light Attenuation2 = %f\n", ldata->light.Attenuation2);
620 trace("Light Theta = %f\n", ldata->light.Theta);
621 trace("Light Phi = %f\n", ldata->light.Phi);
624 static void light_set_handler(
625 IDirect3DDevice9* device, const void* data, void* arg) {
628 light_data* ldata = (light_data*) data;
629 light_arg* larg = (light_arg*) arg;
630 unsigned int index = larg->idx;
632 hret = IDirect3DDevice9_SetLight(device, index, &ldata->light);
633 ok(hret == D3D_OK, "SetLight returned %#lx.\n", hret);
635 hret = IDirect3DDevice9_LightEnable(device, index, ldata->enabled);
636 ok(hret == D3D_OK, "SetLightEnable returned %#lx.\n", hret);
639 static void light_get_handler(
640 IDirect3DDevice9* device, const void* data, void* arg) {
643 light_data* ldata = (light_data*) data;
644 light_arg* larg = (light_arg*) arg;
645 unsigned int index = larg->idx;
647 hret = IDirect3DDevice9_GetLightEnable(device, index, &ldata->enabled);
648 ldata->get_enabled_result = hret;
650 hret = IDirect3DDevice9_GetLight(device, index, &ldata->light);
651 ldata->get_light_result = hret;
654 static const light_data light_poison_data =
656 { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 },
657 { 3.3, 4.4, 5.5 }, { 6.6, 7.7, 8.8 },
658 12.12, 13.13, 14.14, 15.15, 16.16, 17.17, 18.18 }, 1, 0x1337c0de, 0x1337c0de };
660 static const light_data light_default_data =
661 { { D3DLIGHT_DIRECTIONAL,
662 { 1.0, 1.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 },
663 { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 },
664 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, 0, D3D_OK, D3D_OK };
666 /* This is used for the initial read state (before a write causes side effects)
667 * The proper return status is D3DERR_INVALIDCALL */
668 static const light_data light_initial_data =
670 { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 }, { 7.0, 4.0, 2.0, 1.0 },
671 { 3.3, 4.4, 5.5 }, { 6.6, 7.7, 8.8 },
672 12.12, 13.13, 14.14, 15.15, 16.16, 17.17, 18.18 }, 1, D3DERR_INVALIDCALL, D3DERR_INVALIDCALL };
674 static const light_data light_test_data_in =
676 { 2.0, 2.0, 2.0, 2.0 }, { 3.0, 3.0, 3.0, 3.0 }, { 4.0, 4.0, 4.0, 4.0 },
677 { 5.0, 5.0, 5.0 }, { 6.0, 6.0, 6.0 },
678 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }, 1, D3D_OK, D3D_OK};
680 /* SetLight will use 128 as the "enabled" value */
681 static const light_data light_test_data_out =
683 { 2.0, 2.0, 2.0, 2.0 }, { 3.0, 3.0, 3.0, 3.0 }, { 4.0, 4.0, 4.0, 4.0 },
684 { 5.0, 5.0, 5.0 }, { 6.0, 6.0, 6.0 },
685 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0 }, 128, D3D_OK, D3D_OK};
687 #define LIGHTS_REQ_BUFFER \
688 (sizeof(light_data) + sizeof(light_arg))
690 static void lights_queue_test(
691 IDirect3DDevice9 *device,
695 light_arg* arg = buffer;
696 light_data* return_data = (light_data*) (arg + 1);
698 test->test_data_in = &light_test_data_in;
699 test->test_data_out = &light_test_data_out;
700 test->default_data = &light_default_data;
701 test->initial_data = &light_initial_data;
702 test->poison_data = &light_poison_data;
703 test->return_data = return_data;
704 test->data_size = sizeof(light_data);
705 test->set_handler = light_set_handler;
706 test->get_handler = light_get_handler;
707 test->print_handler = light_print_handler;
708 test->get_arg = test->set_arg = arg;
709 test->test_name = "set_get_light";
713 /* =================== State test: Transforms ===================================== */
715 typedef struct transform_data {
718 D3DMATRIX projection;
726 static inline void print_matrix(
727 const char* name, D3DMATRIX* matrix) {
729 trace("%s Matrix = {\n", name);
730 trace(" %f %f %f %f\n", matrix->m[0][0], matrix->m[1][0], matrix->m[2][0], matrix->m[3][0]);
731 trace(" %f %f %f %f\n", matrix->m[0][1], matrix->m[1][1], matrix->m[2][1], matrix->m[3][1]);
732 trace(" %f %f %f %f\n", matrix->m[0][2], matrix->m[1][2], matrix->m[2][2], matrix->m[3][2]);
733 trace(" %f %f %f %f\n", matrix->m[0][3], matrix->m[1][3], matrix->m[2][3], matrix->m[3][3]);
737 static void transform_print_handler(
740 transform_data* tdata = (transform_data*) data;
741 print_matrix("View", &tdata->view);
742 print_matrix("Projection", &tdata->projection);
743 print_matrix("Texture0", &tdata->texture0);
744 print_matrix("Texture7", &tdata->texture7);
745 print_matrix("World0", &tdata->world0);
746 print_matrix("World255", &tdata->world255);
749 static void transform_set_handler(
750 IDirect3DDevice9* device, const void* data, void* arg) {
753 transform_data* tdata = (transform_data*) data;
755 hret = IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &tdata->view);
756 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
758 hret = IDirect3DDevice9_SetTransform(device, D3DTS_PROJECTION, &tdata->projection);
759 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
761 hret = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE0, &tdata->texture0);
762 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
764 hret = IDirect3DDevice9_SetTransform(device, D3DTS_TEXTURE7, &tdata->texture7);
765 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
767 hret = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &tdata->world0);
768 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
770 hret = IDirect3DDevice9_SetTransform(device, D3DTS_WORLDMATRIX(255), &tdata->world255);
771 ok(hret == D3D_OK, "SetTransform returned %#lx.\n", hret);
774 static void transform_get_handler(
775 IDirect3DDevice9* device, const void* data, void* arg) {
778 transform_data* tdata = (transform_data*) data;
780 hret = IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &tdata->view);
781 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
783 hret = IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &tdata->projection);
784 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
786 hret = IDirect3DDevice9_GetTransform(device, D3DTS_TEXTURE0, &tdata->texture0);
787 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
789 hret = IDirect3DDevice9_GetTransform(device, D3DTS_TEXTURE7, &tdata->texture7);
790 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
792 hret = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &tdata->world0);
793 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
795 hret = IDirect3DDevice9_GetTransform(device, D3DTS_WORLDMATRIX(255), &tdata->world255);
796 ok(hret == D3D_OK, "GetTransform returned %#lx.\n", hret);
799 static const transform_data transform_default_data = {
800 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
801 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
802 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
803 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
804 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } },
805 { { { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } } }
808 static const transform_data transform_poison_data = {
809 { { { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
810 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 } } },
812 { { { 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0,
813 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0 } } },
815 { { { 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0,
816 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0 } } },
818 { { { 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0,
819 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, 64.0 } } },
821 { { { 64.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0,
822 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, 80.0 } } },
824 { { { 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0,
825 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0} } },
828 static const transform_data transform_test_data = {
829 { { { 1.2, 3.4, -5.6, 7.2, 10.11, -12.13, 14.15, -1.5,
830 23.56, 12.89, 44.56, -1.0, 2.3, 0.0, 4.4, 5.5 } } },
832 { { { 9.2, 38.7, -6.6, 7.2, 10.11, -12.13, 77.15, -1.5,
833 23.56, 12.89, 14.56, -1.0, 12.3, 0.0, 4.4, 5.5 } } },
835 { { { 10.2, 3.4, 0.6, 7.2, 10.11, -12.13, 14.15, -1.5,
836 23.54, 12.9, 44.56, -1.0, 2.3, 0.0, 4.4, 5.5 } } },
838 { { { 1.2, 3.4, -5.6, 7.2, 10.11, -12.13, -14.5, -1.5,
839 2.56, 12.89, 23.56, -1.0, 112.3, 0.0, 4.4, 2.5 } } },
841 { { { 1.2, 31.41, 58.6, 7.2, 10.11, -12.13, -14.5, -1.5,
842 2.56, 12.89, 11.56, -1.0, 112.3, 0.0, 44.4, 2.5 } } },
844 { { { 1.20, 3.4, -5.6, 7.0, 10.11, -12.156, -14.5, -1.5,
845 2.56, 1.829, 23.6, -1.0, 112.3, 0.0, 41.4, 2.5 } } },
848 #define TRANSFORMS_REQ_BUFFER (sizeof(transform_data))
850 static void transform_queue_test(
851 IDirect3DDevice9 *device,
855 transform_data* return_data = buffer;
857 test->test_data_in = &transform_test_data;
858 test->test_data_out = &transform_test_data;
859 test->default_data = &transform_default_data;
860 test->initial_data = &transform_default_data;
861 test->poison_data = &transform_poison_data;
862 test->return_data = return_data;
863 test->data_size = sizeof(transform_data);
864 test->set_handler = transform_set_handler;
865 test->get_handler = transform_get_handler;
866 test->print_handler = transform_print_handler;
867 test->get_arg = test->set_arg = NULL;
868 test->test_name = "set_get_transforms";
871 /* =================== State test: Render States ===================================== */
873 #define D3D9_RENDER_STATES 102
874 const D3DRENDERSTATETYPE render_state_indices[] = {
880 D3DRS_ALPHATESTENABLE,
889 D3DRS_ALPHABLENDENABLE,
891 D3DRS_SPECULARENABLE,
897 D3DRS_RANGEFOGENABLE,
905 D3DRS_STENCILWRITEMASK,
921 D3DRS_NORMALIZENORMALS,
922 D3DRS_DIFFUSEMATERIALSOURCE,
923 D3DRS_SPECULARMATERIALSOURCE,
924 D3DRS_AMBIENTMATERIALSOURCE,
925 D3DRS_EMISSIVEMATERIALSOURCE,
927 D3DRS_CLIPPLANEENABLE,
928 #if 0 /* Driver dependent, increase array size to enable */
932 D3DRS_POINTSPRITEENABLE,
933 D3DRS_POINTSCALEENABLE,
937 D3DRS_MULTISAMPLEANTIALIAS,
938 D3DRS_MULTISAMPLEMASK,
939 D3DRS_PATCHEDGESTYLE,
940 D3DRS_DEBUGMONITORTOKEN,
942 D3DRS_INDEXEDVERTEXBLENDENABLE,
943 D3DRS_COLORWRITEENABLE,
946 D3DRS_POSITIONDEGREE,
948 D3DRS_SCISSORTESTENABLE,
949 D3DRS_SLOPESCALEDEPTHBIAS,
950 D3DRS_ANTIALIASEDLINEENABLE,
951 D3DRS_MINTESSELLATIONLEVEL,
952 D3DRS_MAXTESSELLATIONLEVEL,
953 D3DRS_ADAPTIVETESS_X,
954 D3DRS_ADAPTIVETESS_Y,
955 D3DRS_ADAPTIVETESS_Z,
956 D3DRS_ADAPTIVETESS_W,
957 D3DRS_ENABLEADAPTIVETESSELLATION,
958 D3DRS_TWOSIDEDSTENCILMODE,
959 D3DRS_CCW_STENCILFAIL,
960 D3DRS_CCW_STENCILZFAIL,
961 D3DRS_CCW_STENCILPASS,
962 D3DRS_CCW_STENCILFUNC,
963 D3DRS_COLORWRITEENABLE1,
964 D3DRS_COLORWRITEENABLE2,
965 D3DRS_COLORWRITEENABLE3,
967 D3DRS_SRGBWRITEENABLE,
977 D3DRS_SEPARATEALPHABLENDENABLE,
979 D3DRS_DESTBLENDALPHA,
983 typedef struct render_state_data {
984 DWORD states[D3D9_RENDER_STATES];
987 static void render_state_set_handler(
988 IDirect3DDevice9* device, const void* data, void* arg) {
991 render_state_data* rsdata = (render_state_data*) data;
994 for (i = 0; i < D3D9_RENDER_STATES; i++) {
995 hret = IDirect3DDevice9_SetRenderState(device, render_state_indices[i], rsdata->states[i]);
996 ok(hret == D3D_OK, "SetRenderState returned %#lx.\n", hret);
1000 static void render_state_get_handler(
1001 IDirect3DDevice9* device, const void* data, void* arg) {
1004 render_state_data* rsdata = (render_state_data*) data;
1007 for (i = 0; i < D3D9_RENDER_STATES; i++) {
1008 hret = IDirect3DDevice9_GetRenderState(device, render_state_indices[i], &rsdata->states[i]);
1009 ok(hret == D3D_OK, "GetRenderState returned %#lx.\n", hret);
1013 static void render_state_print_handler(
1016 render_state_data* rsdata = (render_state_data*) data;
1018 for (i = 0; i < D3D9_RENDER_STATES; i++)
1019 trace("Index = %u, Value = %#lx\n", i, rsdata->states[i]);
1022 static inline DWORD to_dword(float fl) {
1023 return *((DWORD*) &fl);
1026 static void render_state_default_data_init(
1027 D3DPRESENT_PARAMETERS* device_pparams,
1028 render_state_data* data) {
1030 unsigned int idx = 0;
1032 data->states[idx++] = device_pparams->EnableAutoDepthStencil?
1033 D3DZB_TRUE : D3DZB_FALSE; /* ZENABLE */
1034 data->states[idx++] = D3DFILL_SOLID; /* FILLMODE */
1035 data->states[idx++] = D3DSHADE_GOURAUD; /* SHADEMODE */
1036 data->states[idx++] = TRUE; /* ZWRITEENABLE */
1037 data->states[idx++] = FALSE; /* ALPHATESTENABLE */
1038 data->states[idx++] = TRUE; /* LASTPIXEL */
1039 data->states[idx++] = D3DBLEND_ONE; /* SRCBLEND */
1040 data->states[idx++] = D3DBLEND_ZERO; /* DESTBLEND */
1041 data->states[idx++] = D3DCULL_CCW; /* CULLMODE */
1042 data->states[idx++] = D3DCMP_LESSEQUAL; /* ZFUNC */
1043 data->states[idx++] = 0; /* ALPHAREF */
1044 data->states[idx++] = D3DCMP_ALWAYS; /* ALPHAFUNC */
1045 data->states[idx++] = FALSE; /* DITHERENABLE */
1046 data->states[idx++] = FALSE; /* ALPHABLENDENABLE */
1047 data->states[idx++] = FALSE; /* FOGENABLE */
1048 data->states[idx++] = FALSE; /* SPECULARENABLE */
1049 data->states[idx++] = 0; /* FOGCOLOR */
1050 data->states[idx++] = D3DFOG_NONE; /* FOGTABLEMODE */
1051 data->states[idx++] = to_dword(0.0f); /* FOGSTART */
1052 data->states[idx++] = to_dword(1.0f); /* FOGEND */
1053 data->states[idx++] = to_dword(1.0f); /* FOGDENSITY */
1054 data->states[idx++] = FALSE; /* RANGEFOGENABLE */
1055 data->states[idx++] = FALSE; /* STENCILENABLE */
1056 data->states[idx++] = D3DSTENCILOP_KEEP; /* STENCILFAIL */
1057 data->states[idx++] = D3DSTENCILOP_KEEP; /* STENCILZFAIL */
1058 data->states[idx++] = D3DSTENCILOP_KEEP; /* STENCILPASS */
1059 data->states[idx++] = D3DCMP_ALWAYS; /* STENCILFUNC */
1060 data->states[idx++] = 0; /* STENCILREF */
1061 data->states[idx++] = 0xFFFFFFFF; /* STENCILMASK */
1062 data->states[idx++] = 0xFFFFFFFF; /* STENCILWRITEMASK */
1063 data->states[idx++] = 0xFFFFFFFF; /* TEXTUREFACTOR */
1064 data->states[idx++] = 0; /* WRAP 0 */
1065 data->states[idx++] = 0; /* WRAP 1 */
1066 data->states[idx++] = 0; /* WRAP 2 */
1067 data->states[idx++] = 0; /* WRAP 3 */
1068 data->states[idx++] = 0; /* WRAP 4 */
1069 data->states[idx++] = 0; /* WRAP 5 */
1070 data->states[idx++] = 0; /* WRAP 6 */
1071 data->states[idx++] = 0; /* WRAP 7 */
1072 data->states[idx++] = TRUE; /* CLIPPING */
1073 data->states[idx++] = TRUE; /* LIGHTING */
1074 data->states[idx++] = 0; /* AMBIENT */
1075 data->states[idx++] = D3DFOG_NONE; /* FOGVERTEXMODE */
1076 data->states[idx++] = TRUE; /* COLORVERTEX */
1077 data->states[idx++] = TRUE; /* LOCALVIEWER */
1078 data->states[idx++] = FALSE; /* NORMALIZENORMALS */
1079 data->states[idx++] = D3DMCS_COLOR1; /* DIFFUSEMATERIALSOURCE */
1080 data->states[idx++] = D3DMCS_COLOR2; /* SPECULARMATERIALSOURCE */
1081 data->states[idx++] = D3DMCS_MATERIAL; /* AMBIENTMATERIALSOURCE */
1082 data->states[idx++] = D3DMCS_MATERIAL; /* EMISSIVEMATERIALSOURCE */
1083 data->states[idx++] = D3DVBF_DISABLE; /* VERTEXBLEND */
1084 data->states[idx++] = 0; /* CLIPPLANEENABLE */
1085 #if 0 /* Driver dependent, increase array size to enable */
1086 data->states[idx++] = to_dword(1.0f); /* POINTSIZE */
1088 data->states[idx++] = to_dword(1.0f); /* POINTSIZEMIN */
1089 data->states[idx++] = FALSE; /* POINTSPRITEENABLE */
1090 data->states[idx++] = FALSE; /* POINTSCALEENABLE */
1091 data->states[idx++] = to_dword(1.0f); /* POINTSCALE_A */
1092 data->states[idx++] = to_dword(0.0f); /* POINTSCALE_B */
1093 data->states[idx++] = to_dword(0.0f); /* POINTSCALE_C */
1094 data->states[idx++] = TRUE; /* MULTISAMPLEANTIALIAS */
1095 data->states[idx++] = 0xFFFFFFFF; /* MULTISAMPLEMASK */
1096 data->states[idx++] = D3DPATCHEDGE_DISCRETE; /* PATCHEDGESTYLE */
1097 data->states[idx++] = 0xbaadcafe; /* DEBUGMONITORTOKEN */
1098 data->states[idx++] = to_dword(64.0f); /* POINTSIZE_MAX */
1099 data->states[idx++] = FALSE; /* INDEXEDVERTEXBLENDENABLE */
1100 data->states[idx++] = 0x0000000F; /* COLORWRITEENABLE */
1101 data->states[idx++] = to_dword(0.0f); /* TWEENFACTOR */
1102 data->states[idx++] = D3DBLENDOP_ADD; /* BLENDOP */
1103 data->states[idx++] = D3DDEGREE_CUBIC; /* POSITIONDEGREE */
1104 data->states[idx++] = D3DDEGREE_LINEAR; /* NORMALDEGREE */
1105 data->states[idx++] = FALSE; /* SCISSORTESTENABLE */
1106 data->states[idx++] = to_dword(0.0f); /* SLOPESCALEDEPTHBIAS */
1107 data->states[idx++] = FALSE; /* ANTIALIASEDLINEENABLE */
1108 data->states[idx++] = to_dword(1.0f); /* MINTESSELATIONLEVEL */
1109 data->states[idx++] = to_dword(1.0f); /* MAXTESSELATIONLEVEL */
1110 data->states[idx++] = to_dword(0.0f); /* ADAPTIVETESS_X */
1111 data->states[idx++] = to_dword(0.0f); /* ADAPTIVETESS_Y */
1112 data->states[idx++] = to_dword(1.0f); /* ADAPTIVETESS_Z */
1113 data->states[idx++] = to_dword(0.0f); /* ADAPTIVETESS_W */
1114 data->states[idx++] = FALSE; /* ENABLEADAPTIVETESSELATION */
1115 data->states[idx++] = FALSE; /* TWOSIDEDSTENCILMODE */
1116 data->states[idx++] = D3DSTENCILOP_KEEP; /* CCW_STENCILFAIL */
1117 data->states[idx++] = D3DSTENCILOP_KEEP; /* CCW_STENCILZFAIL */
1118 data->states[idx++] = D3DSTENCILOP_KEEP; /* CCW_STENCILPASS */
1119 data->states[idx++] = D3DCMP_ALWAYS; /* CCW_STENCILFUNC */
1120 data->states[idx++] = 0x0000000F; /* COLORWRITEENABLE1 */
1121 data->states[idx++] = 0x0000000F; /* COLORWRITEENABLE2 */
1122 data->states[idx++] = 0x0000000F; /* COLORWRITEENABLE3 */
1123 data->states[idx++] = 0xFFFFFFFF; /* BLENDFACTOR */
1124 data->states[idx++] = 0; /* SRGBWRITEENABLE */
1125 data->states[idx++] = to_dword(0.0f); /* DEPTHBIAS */
1126 data->states[idx++] = 0; /* WRAP8 */
1127 data->states[idx++] = 0; /* WRAP9 */
1128 data->states[idx++] = 0; /* WRAP10 */
1129 data->states[idx++] = 0; /* WRAP11 */
1130 data->states[idx++] = 0; /* WRAP12 */
1131 data->states[idx++] = 0; /* WRAP13 */
1132 data->states[idx++] = 0; /* WRAP14 */
1133 data->states[idx++] = 0; /* WRAP15 */
1134 data->states[idx++] = FALSE; /* SEPARATEALPHABLENDENABLE */
1135 data->states[idx++] = D3DBLEND_ONE; /* SRCBLENDALPHA */
1136 data->states[idx++] = D3DBLEND_ZERO; /* DESTBLENDALPHA */
1137 data->states[idx++] = TRUE; /* BLENDOPALPHA */
1140 static void render_state_poison_data_init(
1141 render_state_data* data) {
1144 for (i = 0; i < D3D9_RENDER_STATES; i++)
1145 data->states[i] = 0x1337c0de;
1148 static void render_state_test_data_init(
1149 render_state_data* data) {
1151 unsigned int idx = 0;
1152 data->states[idx++] = D3DZB_USEW; /* ZENABLE */
1153 data->states[idx++] = D3DFILL_WIREFRAME; /* FILLMODE */
1154 data->states[idx++] = D3DSHADE_PHONG; /* SHADEMODE */
1155 data->states[idx++] = FALSE; /* ZWRITEENABLE */
1156 data->states[idx++] = TRUE; /* ALPHATESTENABLE */
1157 data->states[idx++] = FALSE; /* LASTPIXEL */
1158 data->states[idx++] = D3DBLEND_SRCALPHASAT; /* SRCBLEND */
1159 data->states[idx++] = D3DBLEND_INVDESTALPHA; /* DESTBLEND */
1160 data->states[idx++] = D3DCULL_CW; /* CULLMODE */
1161 data->states[idx++] = D3DCMP_NOTEQUAL; /* ZFUNC */
1162 data->states[idx++] = 10; /* ALPHAREF */
1163 data->states[idx++] = D3DCMP_GREATER; /* ALPHAFUNC */
1164 data->states[idx++] = TRUE; /* DITHERENABLE */
1165 data->states[idx++] = TRUE; /* ALPHABLENDENABLE */
1166 data->states[idx++] = TRUE; /* FOGENABLE */
1167 data->states[idx++] = TRUE; /* SPECULARENABLE */
1168 data->states[idx++] = 255 << 31; /* FOGCOLOR */
1169 data->states[idx++] = D3DFOG_EXP; /* FOGTABLEMODE */
1170 data->states[idx++] = to_dword(0.1f); /* FOGSTART */
1171 data->states[idx++] = to_dword(0.8f); /* FOGEND */
1172 data->states[idx++] = to_dword(0.5f); /* FOGDENSITY */
1173 data->states[idx++] = TRUE; /* RANGEFOGENABLE */
1174 data->states[idx++] = TRUE; /* STENCILENABLE */
1175 data->states[idx++] = D3DSTENCILOP_INCRSAT; /* STENCILFAIL */
1176 data->states[idx++] = D3DSTENCILOP_REPLACE; /* STENCILZFAIL */
1177 data->states[idx++] = D3DSTENCILOP_INVERT; /* STENCILPASS */
1178 data->states[idx++] = D3DCMP_LESS; /* STENCILFUNC */
1179 data->states[idx++] = 10; /* STENCILREF */
1180 data->states[idx++] = 0xFF00FF00; /* STENCILMASK */
1181 data->states[idx++] = 0x00FF00FF; /* STENCILWRITEMASK */
1182 data->states[idx++] = 0xF0F0F0F0; /* TEXTUREFACTOR */
1183 data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_2; /* WRAP 0 */
1184 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3; /* WRAP 1 */
1185 data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 2 */
1186 data->states[idx++] = D3DWRAPCOORD_3 | D3DWRAPCOORD_0; /* WRAP 4 */
1187 data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_1 | D3DWRAPCOORD_2; /* WRAP 5 */
1188 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3 | D3DWRAPCOORD_2; /* WRAP 6 */
1189 data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_1 | D3DWRAPCOORD_0; /* WRAP 7 */
1190 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_0 | D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 8 */
1191 data->states[idx++] = FALSE; /* CLIPPING */
1192 data->states[idx++] = FALSE; /* LIGHTING */
1193 data->states[idx++] = 255 << 16; /* AMBIENT */
1194 data->states[idx++] = D3DFOG_EXP2; /* FOGVERTEXMODE */
1195 data->states[idx++] = FALSE; /* COLORVERTEX */
1196 data->states[idx++] = FALSE; /* LOCALVIEWER */
1197 data->states[idx++] = TRUE; /* NORMALIZENORMALS */
1198 data->states[idx++] = D3DMCS_COLOR2; /* DIFFUSEMATERIALSOURCE */
1199 data->states[idx++] = D3DMCS_MATERIAL; /* SPECULARMATERIALSOURCE */
1200 data->states[idx++] = D3DMCS_COLOR1; /* AMBIENTMATERIALSOURCE */
1201 data->states[idx++] = D3DMCS_COLOR2; /* EMISSIVEMATERIALSOURCE */
1202 data->states[idx++] = D3DVBF_3WEIGHTS; /* VERTEXBLEND */
1203 data->states[idx++] = 0xf1f1f1f1; /* CLIPPLANEENABLE */
1204 #if 0 /* Driver dependent, increase array size to enable */
1205 data->states[idx++] = to_dword(32.0f); /* POINTSIZE */
1207 data->states[idx++] = to_dword(0.7f); /* POINTSIZEMIN */
1208 data->states[idx++] = TRUE; /* POINTSPRITEENABLE */
1209 data->states[idx++] = TRUE; /* POINTSCALEENABLE */
1210 data->states[idx++] = to_dword(0.7f); /* POINTSCALE_A */
1211 data->states[idx++] = to_dword(0.5f); /* POINTSCALE_B */
1212 data->states[idx++] = to_dword(0.4f); /* POINTSCALE_C */
1213 data->states[idx++] = FALSE; /* MULTISAMPLEANTIALIAS */
1214 data->states[idx++] = 0xABCDDBCA; /* MULTISAMPLEMASK */
1215 data->states[idx++] = D3DPATCHEDGE_CONTINUOUS; /* PATCHEDGESTYLE */
1216 data->states[idx++] = D3DDMT_DISABLE; /* DEBUGMONITORTOKEN */
1217 data->states[idx++] = to_dword(77.0f); /* POINTSIZE_MAX */
1218 data->states[idx++] = TRUE; /* INDEXEDVERTEXBLENDENABLE */
1219 data->states[idx++] = 0x00000009; /* COLORWRITEENABLE */
1220 data->states[idx++] = to_dword(0.2f); /* TWEENFACTOR */
1221 data->states[idx++] = D3DBLENDOP_REVSUBTRACT;/* BLENDOP */
1222 data->states[idx++] = D3DDEGREE_LINEAR; /* POSITIONDEGREE */
1223 data->states[idx++] = D3DDEGREE_CUBIC; /* NORMALDEGREE */
1224 data->states[idx++] = TRUE; /* SCISSORTESTENABLE */
1225 data->states[idx++] = to_dword(0.33f); /* SLOPESCALEDEPTHBIAS */
1226 data->states[idx++] = TRUE; /* ANTIALIASEDLINEENABLE */
1227 data->states[idx++] = to_dword(0.8f); /* MINTESSELATIONLEVEL */
1228 data->states[idx++] = to_dword(0.8f); /* MAXTESSELATIONLEVEL */
1229 data->states[idx++] = to_dword(0.2f); /* ADAPTIVETESS_X */
1230 data->states[idx++] = to_dword(0.3f); /* ADAPTIVETESS_Y */
1231 data->states[idx++] = to_dword(0.6f); /* ADAPTIVETESS_Z */
1232 data->states[idx++] = to_dword(0.4f); /* ADAPTIVETESS_W */
1233 data->states[idx++] = TRUE; /* ENABLEADAPTIVETESSELATION */
1234 data->states[idx++] = TRUE; /* TWOSIDEDSTENCILMODE */
1235 data->states[idx++] = D3DSTENCILOP_ZERO; /* CCW_STENCILFAIL */
1236 data->states[idx++] = D3DSTENCILOP_DECR; /* CCW_STENCILZFAIL */
1237 data->states[idx++] = D3DSTENCILOP_INCR; /* CCW_STENCILPASS */
1238 data->states[idx++] = D3DCMP_ALWAYS; /* CCW_STENCILFUNC */
1239 data->states[idx++] = 0x00000007; /* COLORWRITEENABLE1 */
1240 data->states[idx++] = 0x00000008; /* COLORWRITEENABLE2 */
1241 data->states[idx++] = 0x00000004; /* COLORWRITEENABLE3 */
1242 data->states[idx++] = 0xF0F1F2F3; /* BLENDFACTOR */
1243 data->states[idx++] = 1; /* SRGBWRITEENABLE */
1244 data->states[idx++] = to_dword(0.3f); /* DEPTHBIAS */
1245 data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_2; /* WRAP 8 */
1246 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3; /* WRAP 9 */
1247 data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 10 */
1248 data->states[idx++] = D3DWRAPCOORD_3 | D3DWRAPCOORD_0; /* WRAP 11 */
1249 data->states[idx++] = D3DWRAPCOORD_0 | D3DWRAPCOORD_1 | D3DWRAPCOORD_2; /* WRAP 12 */
1250 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_3 | D3DWRAPCOORD_2; /* WRAP 13 */
1251 data->states[idx++] = D3DWRAPCOORD_2 | D3DWRAPCOORD_1 | D3DWRAPCOORD_0; /* WRAP 14 */
1252 data->states[idx++] = D3DWRAPCOORD_1 | D3DWRAPCOORD_0 | D3DWRAPCOORD_2 | D3DWRAPCOORD_3; /* WRAP 15 */
1253 data->states[idx++] = TRUE; /* SEPARATEALPHABLENDENABLE */
1254 data->states[idx++] = D3DBLEND_ZERO; /* SRCBLENDALPHA */
1255 data->states[idx++] = D3DBLEND_ONE; /* DESTBLENDALPHA */
1256 data->states[idx++] = FALSE; /* BLENDOPALPHA */
1259 #define RENDER_STATES_REQ_BUFFER (sizeof(render_state_data) * 4)
1261 static void render_states_queue_test(
1262 IDirect3DDevice9 *device,
1263 D3DPRESENT_PARAMETERS *device_pparams,
1267 render_state_data* return_data = buffer;
1268 render_state_data* default_data = return_data + 1;
1269 render_state_data* test_data = default_data + 1;
1270 render_state_data* poison_data = test_data + 1;
1272 render_state_default_data_init(device_pparams, default_data);
1273 render_state_test_data_init(test_data);
1274 render_state_poison_data_init(poison_data);
1276 test->test_data_in = test_data;
1277 test->test_data_out = test_data;
1278 test->default_data = default_data;
1279 test->initial_data = default_data;
1280 test->poison_data = poison_data;
1281 test->return_data = return_data;
1282 test->data_size = sizeof(render_state_data);
1283 test->set_handler = render_state_set_handler;
1284 test->get_handler = render_state_get_handler;
1285 test->print_handler = render_state_print_handler;
1286 test->get_arg = test->set_arg = NULL;
1287 test->test_name = "set_get_render_states";
1290 /* =================== Main state tests function =============================== */
1292 static void test_state_management(
1293 IDirect3DDevice9 *device,
1294 D3DPRESENT_PARAMETERS *device_pparams) {
1299 /* Test count: 2 for shader constants
1304 const int max_tests = 2 + 1 + 1 + 1;
1305 const int max_buffer = SHADER_CONSTANTS_REQ_BUFFER * 2 +
1307 TRANSFORMS_REQ_BUFFER +
1308 RENDER_STATES_REQ_BUFFER;
1310 unsigned int tcount = 0;
1311 unsigned int bcount = 0;
1313 state_test tests[max_tests];
1314 BYTE buffer[max_buffer];
1316 hret = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1317 ok(hret == D3D_OK, "GetDeviceCaps returned %#lx.\n", hret);
1318 if (hret != D3D_OK) return;
1320 if (caps.VertexShaderVersion & 0xffff) {
1321 shader_constants_queue_test(device, &tests[tcount], &buffer[bcount], FALSE);
1322 bcount += SHADER_CONSTANTS_REQ_BUFFER;
1326 if (caps.PixelShaderVersion & 0xffff) {
1327 shader_constants_queue_test(device, &tests[tcount], &buffer[bcount], TRUE);
1328 bcount += SHADER_CONSTANTS_REQ_BUFFER;
1332 lights_queue_test(device, &tests[tcount], &buffer[bcount]);
1333 bcount += LIGHTS_REQ_BUFFER;
1336 transform_queue_test(device, &tests[tcount], &buffer[bcount]);
1337 bcount += TRANSFORMS_REQ_BUFFER;
1340 render_states_queue_test(device, device_pparams, &tests[tcount], &buffer[bcount]);
1341 bcount += RENDER_STATES_REQ_BUFFER;
1344 execute_test_chain_all(device, tests, tcount);
1347 START_TEST(stateblock)
1349 IDirect3DDevice9 *device_ptr = NULL;
1350 D3DPRESENT_PARAMETERS device_pparams;
1353 d3d9_handle = LoadLibraryA("d3d9.dll");
1356 trace("Could not load d3d9.dll, skipping tests\n");
1360 hret = init_d3d9(&device_ptr, &device_pparams);
1361 if (hret != D3D_OK) return;
1363 test_begin_end_state_block(device_ptr);
1364 test_state_management(device_ptr, &device_pparams);
1366 if (device_ptr) IUnknown_Release(device_ptr);