ba758176f494f6155af76b02e7876fff27addb9f
[mesa.git] / src / gallium / state_trackers / nine / nine_state.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 * Copyright 2013 Christoph Bumiller
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #include "device9.h"
25 #include "basetexture9.h"
26 #include "indexbuffer9.h"
27 #include "surface9.h"
28 #include "vertexdeclaration9.h"
29 #include "vertexshader9.h"
30 #include "pixelshader9.h"
31 #include "nine_pipe.h"
32 #include "nine_ff.h"
33 #include "pipe/p_context.h"
34 #include "pipe/p_state.h"
35 #include "cso_cache/cso_context.h"
36 #include "util/u_math.h"
37
38 #define DBG_CHANNEL DBG_DEVICE
39
40 static uint32_t
41 update_framebuffer(struct NineDevice9 *device)
42 {
43 struct pipe_context *pipe = device->pipe;
44 struct nine_state *state = &device->state;
45 struct pipe_framebuffer_state *fb = &device->state.fb;
46 unsigned i;
47 struct NineSurface9 *rt0 = state->rt[0];
48 unsigned w = rt0->desc.Width;
49 unsigned h = rt0->desc.Height;
50 D3DMULTISAMPLE_TYPE nr_samples = rt0->desc.MultiSampleType;
51 unsigned mask = state->ps ? state->ps->rt_mask : 1;
52 const int sRGB = state->rs[D3DRS_SRGBWRITEENABLE] ? 1 : 0;
53
54 DBG("\n");
55
56 state->rt_mask = 0x0;
57 fb->nr_cbufs = 0;
58
59 /* all render targets must have the same size and the depth buffer must be
60 * bigger. Multisample has to match, according to spec. But some apps do
61 * things wrong there, and no error is returned. The behaviour they get
62 * apparently is that depth buffer is disabled if it doesn't match.
63 * Surely the same for render targets. */
64
65 /* Special case: D3DFMT_NULL is used to bound no real render target,
66 * but render to depth buffer. We have to not take into account the render
67 * target info. TODO: know what should happen when there are several render targers
68 * and the first one is D3DFMT_NULL */
69 if (rt0->desc.Format == D3DFMT_NULL && state->ds) {
70 w = state->ds->desc.Width;
71 h = state->ds->desc.Height;
72 nr_samples = state->ds->desc.MultiSampleType;
73 }
74
75 for (i = 0; i < device->caps.NumSimultaneousRTs; ++i) {
76 struct NineSurface9 *rt = state->rt[i];
77
78 if (rt && rt->desc.Format != D3DFMT_NULL && (mask & (1 << i)) &&
79 rt->desc.Width == w && rt->desc.Height == h &&
80 rt->desc.MultiSampleType == nr_samples) {
81 fb->cbufs[i] = NineSurface9_GetSurface(rt, sRGB);
82 state->rt_mask |= 1 << i;
83 fb->nr_cbufs = i + 1;
84
85 if (unlikely(rt->desc.Usage & D3DUSAGE_AUTOGENMIPMAP)) {
86 assert(rt->texture == D3DRTYPE_TEXTURE ||
87 rt->texture == D3DRTYPE_CUBETEXTURE);
88 NineBaseTexture9(rt->base.base.container)->dirty_mip = TRUE;
89 }
90 } else {
91 /* Color outputs must match RT slot,
92 * drivers will have to handle NULL entries for GL, too.
93 */
94 fb->cbufs[i] = NULL;
95 }
96 }
97
98 if (state->ds && state->ds->desc.Width >= w &&
99 state->ds->desc.Height >= h &&
100 state->ds->desc.MultiSampleType == nr_samples) {
101 fb->zsbuf = NineSurface9_GetSurface(state->ds, 0);
102 } else {
103 fb->zsbuf = NULL;
104 }
105
106 fb->width = w;
107 fb->height = h;
108
109 pipe->set_framebuffer_state(pipe, fb); /* XXX: cso ? */
110
111 if (fb->zsbuf) {
112 DWORD scale;
113 switch (fb->zsbuf->format) {
114 case PIPE_FORMAT_Z32_FLOAT:
115 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
116 scale = fui(1.0f);
117 break;
118 case PIPE_FORMAT_Z16_UNORM:
119 scale = fui((float)(1 << 16));
120 break;
121 default:
122 scale = fui((float)(1 << 24));
123 break;
124 }
125 if (state->rs[NINED3DRS_ZBIASSCALE] != scale) {
126 state->rs[NINED3DRS_ZBIASSCALE] = scale;
127 state->changed.group |= NINE_STATE_RASTERIZER;
128 }
129 }
130
131 return state->changed.group;
132 }
133
134 static void
135 update_viewport(struct NineDevice9 *device)
136 {
137 struct pipe_context *pipe = device->pipe;
138 const D3DVIEWPORT9 *vport = &device->state.viewport;
139 struct pipe_viewport_state pvport;
140
141 /* XXX:
142 * I hope D3D clip coordinates are still
143 * -1 .. +1 for X,Y and
144 * 0 .. +1 for Z (use pipe_rasterizer_state.clip_halfz)
145 */
146 pvport.scale[0] = (float)vport->Width * 0.5f;
147 pvport.scale[1] = (float)vport->Height * -0.5f;
148 pvport.scale[2] = vport->MaxZ - vport->MinZ;
149 pvport.translate[0] = (float)vport->Width * 0.5f + (float)vport->X;
150 pvport.translate[1] = (float)vport->Height * 0.5f + (float)vport->Y;
151 pvport.translate[2] = vport->MinZ;
152
153 pipe->set_viewport_states(pipe, 0, 1, &pvport);
154 }
155
156 static INLINE void
157 update_scissor(struct NineDevice9 *device)
158 {
159 struct pipe_context *pipe = device->pipe;
160
161 pipe->set_scissor_states(pipe, 0, 1, &device->state.scissor);
162 }
163
164 static INLINE void
165 update_blend(struct NineDevice9 *device)
166 {
167 nine_convert_blend_state(device->cso, device->state.rs);
168 }
169
170 static INLINE void
171 update_dsa(struct NineDevice9 *device)
172 {
173 nine_convert_dsa_state(device->cso, device->state.rs);
174 }
175
176 static INLINE void
177 update_rasterizer(struct NineDevice9 *device)
178 {
179 nine_convert_rasterizer_state(device->cso, device->state.rs);
180 }
181
182 /* Loop through VS inputs and pick the vertex elements with the declared
183 * usage from the vertex declaration, then insert the instance divisor from
184 * the stream source frequency setting.
185 */
186 static void
187 update_vertex_elements(struct NineDevice9 *device)
188 {
189 struct nine_state *state = &device->state;
190 const struct NineVertexDeclaration9 *vdecl = device->state.vdecl;
191 const struct NineVertexShader9 *vs;
192 unsigned n, b, i;
193 int index;
194 struct pipe_vertex_element ve[PIPE_MAX_ATTRIBS];
195
196 state->stream_usage_mask = 0;
197
198 vs = device->state.vs ? device->state.vs : device->ff.vs;
199
200 if (!vdecl) /* no inputs */
201 return;
202 for (n = 0; n < vs->num_inputs; ++n) {
203 DBG("looking up input %u (usage %u) from vdecl(%p)\n",
204 n, vs->input_map[n].ndecl, vdecl);
205
206 index = -1;
207 for (i = 0; i < vdecl->nelems; i++) {
208 if (vdecl->usage_map[i] == vs->input_map[n].ndecl) {
209 index = i;
210 break;
211 }
212 }
213
214 if (index >= 0) {
215 ve[n] = vdecl->elems[index];
216 b = ve[n].vertex_buffer_index;
217 state->stream_usage_mask |= 1 << b;
218 /* XXX wine just uses 1 here: */
219 if (state->stream_freq[b] & D3DSTREAMSOURCE_INSTANCEDATA)
220 ve[n].instance_divisor = state->stream_freq[b] & 0x7FFFFF;
221 } else {
222 /* TODO: msdn doesn't specify what should happen when the vertex
223 * declaration doesn't match the vertex shader inputs.
224 * Some websites say the code will pass but nothing will get rendered.
225 * We should check and implement the correct behaviour. */
226 /* Put PIPE_FORMAT_NONE.
227 * Some drivers (r300) are very unhappy with that */
228 ve[n].src_format = PIPE_FORMAT_NONE;
229 ve[n].src_offset = 0;
230 ve[n].instance_divisor = 0;
231 ve[n].vertex_buffer_index = 0;
232 }
233 }
234 cso_set_vertex_elements(device->cso, vs->num_inputs, ve);
235
236 state->changed.stream_freq = 0;
237 }
238
239 static INLINE uint32_t
240 update_shader_variant_keys(struct NineDevice9 *device)
241 {
242 struct nine_state *state = &device->state;
243 uint32_t mask = 0;
244 uint32_t vs_key = state->samplers_shadow;
245 uint32_t ps_key = state->samplers_shadow;
246
247 vs_key = (vs_key & NINE_VS_SAMPLERS_MASK) >> NINE_SAMPLER_VS(0);
248 ps_key = (ps_key & NINE_PS_SAMPLERS_MASK) >> NINE_SAMPLER_PS(0);
249
250 if (state->vs) vs_key &= state->vs->sampler_mask;
251 if (state->ps) {
252 if (unlikely(state->ps->byte_code.version < 0x20)) {
253 /* no depth textures, but variable targets */
254 uint32_t m = state->ps->sampler_mask;
255 ps_key = 0;
256 while (m) {
257 int s = ffs(m) - 1;
258 m &= ~(1 << s);
259 ps_key |= (state->texture[s] ? state->texture[s]->pstype : 1) << (s * 2);
260 }
261 } else {
262 ps_key &= state->ps->sampler_mask;
263 }
264 }
265
266 if (state->vs && state->vs_key != vs_key) {
267 state->vs_key = vs_key;
268 mask |= NINE_STATE_VS;
269 }
270 if (state->ps && state->ps_key != ps_key) {
271 state->ps_key = ps_key;
272 mask |= NINE_STATE_PS;
273 }
274 return mask;
275 }
276
277 static INLINE uint32_t
278 update_vs(struct NineDevice9 *device)
279 {
280 struct nine_state *state = &device->state;
281 struct NineVertexShader9 *vs = state->vs;
282 uint32_t changed_group = 0;
283
284 /* likely because we dislike FF */
285 if (likely(vs)) {
286 state->cso.vs = NineVertexShader9_GetVariant(vs, state->vs_key);
287 } else {
288 vs = device->ff.vs;
289 state->cso.vs = vs->variant.cso;
290 }
291 device->pipe->bind_vs_state(device->pipe, state->cso.vs);
292
293 if (state->rs[NINED3DRS_VSPOINTSIZE] != vs->point_size) {
294 state->rs[NINED3DRS_VSPOINTSIZE] = vs->point_size;
295 changed_group |= NINE_STATE_RASTERIZER;
296 }
297
298 if ((state->bound_samplers_mask_vs & vs->sampler_mask) != vs->sampler_mask)
299 /* Bound dummy sampler. */
300 changed_group |= NINE_STATE_SAMPLER;
301 return changed_group;
302 }
303
304 static INLINE uint32_t
305 update_ps(struct NineDevice9 *device)
306 {
307 struct nine_state *state = &device->state;
308 struct NinePixelShader9 *ps = state->ps;
309 uint32_t changed_group = 0;
310
311 if (likely(ps)) {
312 state->cso.ps = NinePixelShader9_GetVariant(ps, state->ps_key);
313 } else {
314 ps = device->ff.ps;
315 state->cso.ps = ps->variant.cso;
316 }
317 device->pipe->bind_fs_state(device->pipe, state->cso.ps);
318
319 if ((state->bound_samplers_mask_ps & ps->sampler_mask) != ps->sampler_mask)
320 /* Bound dummy sampler. */
321 changed_group |= NINE_STATE_SAMPLER;
322 return changed_group;
323 }
324
325 #define DO_UPLOAD_CONST_F(buf,p,c,d) \
326 do { \
327 DBG("upload ConstantF [%u .. %u]\n", x, (x) + (c) - 1); \
328 box.x = (p) * 4 * sizeof(float); \
329 box.width = (c) * 4 * sizeof(float); \
330 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, &((d)[p * 4]), \
331 0, 0); \
332 } while(0)
333
334 /* OK, this is a bit ugly ... */
335 static void
336 update_constants(struct NineDevice9 *device, unsigned shader_type)
337 {
338 struct pipe_context *pipe = device->pipe;
339 struct pipe_resource *buf;
340 struct pipe_box box;
341 const void *data;
342 const float *const_f;
343 const int *const_i;
344 const BOOL *const_b;
345 uint32_t data_b[NINE_MAX_CONST_B];
346 uint16_t dirty_i;
347 uint16_t dirty_b;
348 const unsigned usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE;
349 unsigned x = 0; /* silence warning */
350 unsigned i, c;
351 struct nine_range *r, *p, *lconstf_ranges;
352 float *lconstf_data;
353
354 box.y = 0;
355 box.z = 0;
356 box.height = 1;
357 box.depth = 1;
358
359 if (shader_type == PIPE_SHADER_VERTEX) {
360 DBG("VS\n");
361 buf = device->constbuf_vs;
362
363 const_f = device->state.vs_const_f;
364 for (p = r = device->state.changed.vs_const_f; r; p = r, r = r->next)
365 DO_UPLOAD_CONST_F(buf, r->bgn, r->end - r->bgn, const_f);
366 if (p) {
367 nine_range_pool_put_chain(&device->range_pool,
368 device->state.changed.vs_const_f, p);
369 device->state.changed.vs_const_f = NULL;
370 }
371
372 dirty_i = device->state.changed.vs_const_i;
373 device->state.changed.vs_const_i = 0;
374 const_i = &device->state.vs_const_i[0][0];
375
376 dirty_b = device->state.changed.vs_const_b;
377 device->state.changed.vs_const_b = 0;
378 const_b = device->state.vs_const_b;
379
380 lconstf_ranges = device->state.vs->lconstf.ranges;
381 lconstf_data = device->state.vs->lconstf.data;
382
383 device->state.ff.clobber.vs_const = TRUE;
384 device->state.changed.group &= ~NINE_STATE_VS_CONST;
385 } else {
386 DBG("PS\n");
387 buf = device->constbuf_ps;
388
389 const_f = device->state.ps_const_f;
390 for (p = r = device->state.changed.ps_const_f; r; p = r, r = r->next)
391 DO_UPLOAD_CONST_F(buf, r->bgn, r->end - r->bgn, const_f);
392 if (p) {
393 nine_range_pool_put_chain(&device->range_pool,
394 device->state.changed.ps_const_f, p);
395 device->state.changed.ps_const_f = NULL;
396 }
397
398 dirty_i = device->state.changed.ps_const_i;
399 device->state.changed.ps_const_i = 0;
400 const_i = &device->state.ps_const_i[0][0];
401
402 dirty_b = device->state.changed.ps_const_b;
403 device->state.changed.ps_const_b = 0;
404 const_b = device->state.ps_const_b;
405
406 lconstf_ranges = NULL;
407 lconstf_data = NULL;
408
409 device->state.ff.clobber.ps_const = TRUE;
410 device->state.changed.group &= ~NINE_STATE_PS_CONST;
411 }
412
413 /* write range from min to max changed, it's not much data */
414 /* bool1 */
415 if (dirty_b) {
416 c = util_last_bit(dirty_b);
417 i = ffs(dirty_b) - 1;
418 x = buf->width0 - (NINE_MAX_CONST_B - i) * 4;
419 c -= i;
420 memcpy(data_b, &(const_b[i]), c * sizeof(uint32_t));
421 box.x = x;
422 box.width = c * 4;
423 DBG("upload ConstantB [%u .. %u]\n", x, x + c - 1);
424 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, data_b, 0, 0);
425 }
426
427 /* int4 */
428 for (c = 0, i = 0; dirty_i; i++, dirty_i >>= 1) {
429 if (dirty_i & 1) {
430 if (!c)
431 x = i;
432 ++c;
433 } else
434 if (c) {
435 DBG("upload ConstantI [%u .. %u]\n", x, x + c - 1);
436 data = &const_i[x * 4];
437 box.x = buf->width0 - (NINE_MAX_CONST_I * 4 + NINE_MAX_CONST_B) * 4;
438 box.x += x * 4 * sizeof(int);
439 box.width = c * 4 * sizeof(int);
440 c = 0;
441 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, data, 0, 0);
442 }
443 }
444 if (c) {
445 DBG("upload ConstantI [%u .. %u]\n", x, x + c - 1);
446 data = &const_i[x * 4];
447 box.x = buf->width0 - (NINE_MAX_CONST_I * 4 + NINE_MAX_CONST_B) * 4;
448 box.x += x * 4 * sizeof(int);
449 box.width = c * 4 * sizeof(int);
450 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, data, 0, 0);
451 }
452
453 /* TODO: only upload these when shader itself changes */
454 if (lconstf_ranges) {
455 unsigned n = 0;
456 struct nine_range *r = lconstf_ranges;
457 while (r) {
458 box.x = r->bgn * 4 * sizeof(float);
459 n += r->end - r->bgn;
460 box.width = (r->end - r->bgn) * 4 * sizeof(float);
461 data = &lconstf_data[4 * n];
462 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, data, 0, 0);
463 r = r->next;
464 }
465 }
466 }
467
468 static void
469 update_vs_constants_userbuf(struct NineDevice9 *device)
470 {
471 struct nine_state *state = &device->state;
472 struct pipe_context *pipe = device->pipe;
473 struct pipe_constant_buffer cb;
474 cb.buffer = NULL;
475 cb.buffer_offset = 0;
476 cb.buffer_size = device->state.vs->const_used_size;
477 cb.user_buffer = device->state.vs_const_f;
478
479 if (!cb.buffer_size)
480 return;
481
482 if (state->changed.vs_const_i) {
483 int *idst = (int *)&state->vs_const_f[4 * device->max_vs_const_f];
484 memcpy(idst, state->vs_const_i, sizeof(state->vs_const_i));
485 state->changed.vs_const_i = 0;
486 }
487 if (state->changed.vs_const_b) {
488 int *idst = (int *)&state->vs_const_f[4 * device->max_vs_const_f];
489 uint32_t *bdst = (uint32_t *)&idst[4 * NINE_MAX_CONST_I];
490 memcpy(bdst, state->vs_const_b, sizeof(state->vs_const_b));
491 state->changed.vs_const_b = 0;
492 }
493
494 if (device->state.vs->lconstf.ranges) {
495 /* TODO: Can we make it so that we don't have to copy everything ? */
496 const struct nine_lconstf *lconstf = &device->state.vs->lconstf;
497 const struct nine_range *r = lconstf->ranges;
498 unsigned n = 0;
499 float *dst = device->state.vs_lconstf_temp;
500 float *src = (float *)cb.user_buffer;
501 memcpy(dst, src, cb.buffer_size);
502 while (r) {
503 unsigned p = r->bgn;
504 unsigned c = r->end - r->bgn;
505 memcpy(&dst[p * 4], &lconstf->data[n * 4], c * 4 * sizeof(float));
506 n += c;
507 r = r->next;
508 }
509 cb.user_buffer = dst;
510 }
511
512 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &cb);
513
514 if (device->state.changed.vs_const_f) {
515 struct nine_range *r = device->state.changed.vs_const_f;
516 struct nine_range *p = r;
517 while (p->next)
518 p = p->next;
519 nine_range_pool_put_chain(&device->range_pool, r, p);
520 device->state.changed.vs_const_f = NULL;
521 }
522 state->changed.group &= ~NINE_STATE_VS_CONST;
523 }
524
525 static void
526 update_ps_constants_userbuf(struct NineDevice9 *device)
527 {
528 struct nine_state *state = &device->state;
529 struct pipe_context *pipe = device->pipe;
530 struct pipe_constant_buffer cb;
531 cb.buffer = NULL;
532 cb.buffer_offset = 0;
533 cb.buffer_size = device->state.ps->const_used_size;
534 cb.user_buffer = device->state.ps_const_f;
535
536 if (!cb.buffer_size)
537 return;
538
539 if (state->changed.ps_const_i) {
540 int *idst = (int *)&state->ps_const_f[4 * device->max_ps_const_f];
541 memcpy(idst, state->ps_const_i, sizeof(state->ps_const_i));
542 state->changed.ps_const_i = 0;
543 }
544 if (state->changed.ps_const_b) {
545 int *idst = (int *)&state->ps_const_f[4 * device->max_ps_const_f];
546 uint32_t *bdst = (uint32_t *)&idst[4 * NINE_MAX_CONST_I];
547 memcpy(bdst, state->ps_const_b, sizeof(state->ps_const_b));
548 state->changed.ps_const_b = 0;
549 }
550
551 pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, &cb);
552
553 if (device->state.changed.ps_const_f) {
554 struct nine_range *r = device->state.changed.ps_const_f;
555 struct nine_range *p = r;
556 while (p->next)
557 p = p->next;
558 nine_range_pool_put_chain(&device->range_pool, r, p);
559 device->state.changed.ps_const_f = NULL;
560 }
561 state->changed.group &= ~NINE_STATE_PS_CONST;
562 }
563
564 static void
565 update_vertex_buffers(struct NineDevice9 *device)
566 {
567 struct pipe_context *pipe = device->pipe;
568 struct nine_state *state = &device->state;
569 uint32_t mask = state->changed.vtxbuf;
570 unsigned i;
571 unsigned start;
572 unsigned count = 0;
573
574 DBG("mask=%x\n", mask);
575
576 for (i = 0; mask; mask >>= 1, ++i) {
577 if (mask & 1) {
578 if (!count)
579 start = i;
580 ++count;
581 } else {
582 if (count)
583 pipe->set_vertex_buffers(pipe,
584 start, count, &state->vtxbuf[start]);
585 count = 0;
586 }
587 }
588 if (count)
589 pipe->set_vertex_buffers(pipe, start, count, &state->vtxbuf[start]);
590
591 state->changed.vtxbuf = 0;
592 }
593
594 static INLINE void
595 update_index_buffer(struct NineDevice9 *device)
596 {
597 struct pipe_context *pipe = device->pipe;
598 if (device->state.idxbuf)
599 pipe->set_index_buffer(pipe, &device->state.idxbuf->buffer);
600 else
601 pipe->set_index_buffer(pipe, NULL);
602 }
603
604 /* TODO: only go through dirty textures */
605 static void
606 validate_textures(struct NineDevice9 *device)
607 {
608 struct NineBaseTexture9 *tex, *ptr;
609 LIST_FOR_EACH_ENTRY_SAFE(tex, ptr, &device->update_textures, list) {
610 list_delinit(&tex->list);
611 NineBaseTexture9_Validate(tex);
612 }
613 }
614
615 static INLINE boolean
616 update_sampler_derived(struct nine_state *state, unsigned s)
617 {
618 boolean changed = FALSE;
619
620 if (state->samp[s][NINED3DSAMP_SHADOW] != state->texture[s]->shadow) {
621 changed = TRUE;
622 state->samp[s][NINED3DSAMP_SHADOW] = state->texture[s]->shadow;
623 }
624
625 if (state->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
626 int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - state->texture[s]->lod;
627 if (lod < 0)
628 lod = 0;
629 if (state->samp[s][NINED3DSAMP_MINLOD] != lod) {
630 changed = TRUE;
631 state->samp[s][NINED3DSAMP_MINLOD] = lod;
632 }
633 } else {
634 state->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */
635 }
636
637 return changed;
638 }
639
640 /* TODO: add sRGB override to pipe_sampler_state ? */
641 static void
642 update_textures_and_samplers(struct NineDevice9 *device)
643 {
644 struct pipe_context *pipe = device->pipe;
645 struct nine_state *state = &device->state;
646 struct pipe_sampler_view *view[NINE_MAX_SAMPLERS];
647 struct pipe_sampler_state samp;
648 unsigned num_textures;
649 unsigned i;
650 boolean commit_views;
651 boolean commit_samplers;
652 uint16_t sampler_mask = state->ps ? state->ps->sampler_mask :
653 device->ff.ps->sampler_mask;
654
655 /* TODO: Can we reduce iterations here ? */
656
657 commit_views = FALSE;
658 commit_samplers = FALSE;
659 state->bound_samplers_mask_ps = 0;
660 for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_PS; ++i) {
661 const unsigned s = NINE_SAMPLER_PS(i);
662 int sRGB;
663
664 if (!state->texture[s] && !(sampler_mask & (1 << i))) {
665 view[i] = NULL;
666 continue;
667 }
668
669 if (state->texture[s]) {
670 sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
671
672 view[i] = NineBaseTexture9_GetSamplerView(state->texture[s], sRGB);
673 num_textures = i + 1;
674
675 if (update_sampler_derived(state, s) || (state->changed.sampler[s] & 0x05fe)) {
676 state->changed.sampler[s] = 0;
677 commit_samplers = TRUE;
678 nine_convert_sampler_state(device->cso, s, state->samp[s]);
679 }
680 } else {
681 /* Bind dummy sampler. We do not bind dummy sampler when
682 * it is not needed because it could add overhead. The
683 * dummy sampler should have r=g=b=0 and a=1. We do not
684 * unbind dummy sampler directly when they are not needed
685 * anymore, but they're going to be removed as long as texture
686 * or sampler states are changed. */
687 view[i] = device->dummy_sampler;
688 num_textures = i + 1;
689
690 memset(&samp, 0, sizeof(samp));
691 samp.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
692 samp.max_lod = 15.0f;
693 samp.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
694 samp.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
695 samp.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
696 samp.min_img_filter = PIPE_TEX_FILTER_NEAREST;
697 samp.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
698 samp.compare_mode = PIPE_TEX_COMPARE_NONE;
699 samp.compare_func = PIPE_FUNC_LEQUAL;
700 samp.normalized_coords = 1;
701 samp.seamless_cube_map = 1;
702
703 cso_single_sampler(device->cso, PIPE_SHADER_FRAGMENT,
704 s - NINE_SAMPLER_PS(0), &samp);
705
706 commit_views = TRUE;
707 commit_samplers = TRUE;
708 state->changed.sampler[s] = ~0;
709 }
710
711 state->bound_samplers_mask_ps |= (1 << s);
712 }
713
714 commit_views |= (state->changed.texture & NINE_PS_SAMPLERS_MASK) != 0;
715 commit_views |= state->changed.srgb;
716 if (commit_views)
717 pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0,
718 num_textures, view);
719
720 if (commit_samplers)
721 cso_single_sampler_done(device->cso, PIPE_SHADER_FRAGMENT);
722
723 commit_views = FALSE;
724 commit_samplers = FALSE;
725 sampler_mask = state->vs ? state->vs->sampler_mask : 0;
726 state->bound_samplers_mask_vs = 0;
727 for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_VS; ++i) {
728 const unsigned s = NINE_SAMPLER_VS(i);
729 int sRGB;
730
731 if (!state->texture[s] && !(sampler_mask & (1 << i))) {
732 view[i] = NULL;
733 continue;
734 }
735
736 if (state->texture[s]) {
737 sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
738
739 view[i] = NineBaseTexture9_GetSamplerView(state->texture[s], sRGB);
740 num_textures = i + 1;
741
742 if (update_sampler_derived(state, s) || (state->changed.sampler[s] & 0x05fe)) {
743 state->changed.sampler[s] = 0;
744 commit_samplers = TRUE;
745 nine_convert_sampler_state(device->cso, s, state->samp[s]);
746 }
747 } else {
748 /* Bind dummy sampler. We do not bind dummy sampler when
749 * it is not needed because it could add overhead. The
750 * dummy sampler should have r=g=b=0 and a=1. We do not
751 * unbind dummy sampler directly when they are not needed
752 * anymore, but they're going to be removed as long as texture
753 * or sampler states are changed. */
754 view[i] = device->dummy_sampler;
755 num_textures = i + 1;
756
757 memset(&samp, 0, sizeof(samp));
758 samp.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
759 samp.max_lod = 15.0f;
760 samp.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
761 samp.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
762 samp.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
763 samp.min_img_filter = PIPE_TEX_FILTER_NEAREST;
764 samp.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
765 samp.compare_mode = PIPE_TEX_COMPARE_NONE;
766 samp.compare_func = PIPE_FUNC_LEQUAL;
767 samp.normalized_coords = 1;
768 samp.seamless_cube_map = 1;
769
770 cso_single_sampler(device->cso, PIPE_SHADER_VERTEX,
771 s - NINE_SAMPLER_VS(0), &samp);
772
773 commit_views = TRUE;
774 commit_samplers = TRUE;
775 state->changed.sampler[s] = ~0;
776 }
777
778 state->bound_samplers_mask_vs |= (1 << s);
779 }
780 commit_views |= (state->changed.texture & NINE_VS_SAMPLERS_MASK) != 0;
781 commit_views |= state->changed.srgb;
782 if (commit_views)
783 pipe->set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0,
784 num_textures, view);
785
786 if (commit_samplers)
787 cso_single_sampler_done(device->cso, PIPE_SHADER_VERTEX);
788
789 state->changed.srgb = FALSE;
790 state->changed.texture = 0;
791 }
792
793
794 #define NINE_STATE_FREQ_GROUP_0 \
795 (NINE_STATE_FB | \
796 NINE_STATE_VIEWPORT | \
797 NINE_STATE_SCISSOR | \
798 NINE_STATE_BLEND | \
799 NINE_STATE_DSA | \
800 NINE_STATE_RASTERIZER | \
801 NINE_STATE_VS | \
802 NINE_STATE_PS | \
803 NINE_STATE_BLEND_COLOR | \
804 NINE_STATE_STENCIL_REF | \
805 NINE_STATE_SAMPLE_MASK)
806
807 #define NINE_STATE_FREQ_GROUP_1 ~NINE_STATE_FREQ_GROUP_0
808
809 #define NINE_STATE_SHADER_VARIANT_GROUP \
810 (NINE_STATE_TEXTURE | \
811 NINE_STATE_VS | \
812 NINE_STATE_PS)
813
814 boolean
815 nine_update_state(struct NineDevice9 *device, uint32_t mask)
816 {
817 struct pipe_context *pipe = device->pipe;
818 struct nine_state *state = &device->state;
819 uint32_t group;
820
821 DBG("changed state groups: %x | %x\n",
822 state->changed.group & NINE_STATE_FREQ_GROUP_0,
823 state->changed.group & NINE_STATE_FREQ_GROUP_1);
824
825 /* NOTE: We may want to use the cso cache for everything, or let
826 * NineDevice9.RestoreNonCSOState actually set the states, then we wouldn't
827 * have to care about state being clobbered here and could merge this back
828 * into update_textures. Except, we also need to re-validate textures that
829 * may be dirty anyway, even if no texture bindings changed.
830 */
831 validate_textures(device); /* may clobber state */
832
833 /* ff_update may change VS/PS dirty bits */
834 if ((mask & NINE_STATE_FF) && unlikely(!state->vs || !state->ps))
835 nine_ff_update(device);
836 group = state->changed.group & mask;
837
838 if (group & NINE_STATE_SHADER_VARIANT_GROUP)
839 group |= update_shader_variant_keys(device);
840
841 if (group & NINE_STATE_FREQ_GROUP_0) {
842 if (group & NINE_STATE_FB)
843 group = update_framebuffer(device) & mask;
844 if (group & NINE_STATE_VIEWPORT)
845 update_viewport(device);
846 if (group & NINE_STATE_SCISSOR)
847 update_scissor(device);
848
849 if (group & NINE_STATE_DSA)
850 update_dsa(device);
851 if (group & NINE_STATE_BLEND)
852 update_blend(device);
853
854 if (group & NINE_STATE_VS)
855 group |= update_vs(device);
856
857 if (group & NINE_STATE_RASTERIZER)
858 update_rasterizer(device);
859
860 if (group & NINE_STATE_PS)
861 group |= update_ps(device);
862
863 if (group & NINE_STATE_BLEND_COLOR) {
864 struct pipe_blend_color color;
865 d3dcolor_to_rgba(&color.color[0], state->rs[D3DRS_BLENDFACTOR]);
866 pipe->set_blend_color(pipe, &color);
867 }
868 if (group & NINE_STATE_SAMPLE_MASK) {
869 pipe->set_sample_mask(pipe, state->rs[D3DRS_MULTISAMPLEMASK]);
870 }
871 if (group & NINE_STATE_STENCIL_REF) {
872 struct pipe_stencil_ref ref;
873 ref.ref_value[0] = state->rs[D3DRS_STENCILREF];
874 ref.ref_value[1] = ref.ref_value[0];
875 pipe->set_stencil_ref(pipe, &ref);
876 }
877 }
878
879 if (state->changed.ucp) {
880 pipe->set_clip_state(pipe, &state->clip);
881 state->changed.ucp = 0;
882 }
883
884 if (group & (NINE_STATE_FREQ_GROUP_1 | NINE_STATE_VS)) {
885 if (group & (NINE_STATE_TEXTURE | NINE_STATE_SAMPLER))
886 update_textures_and_samplers(device);
887
888 if (group & NINE_STATE_IDXBUF)
889 update_index_buffer(device);
890
891 if ((group & (NINE_STATE_VDECL | NINE_STATE_VS)) ||
892 state->changed.stream_freq & ~1)
893 update_vertex_elements(device);
894
895 if (device->prefer_user_constbuf) {
896 if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS)) && state->vs)
897 update_vs_constants_userbuf(device);
898 if ((group & (NINE_STATE_PS_CONST | NINE_STATE_PS)) && state->ps)
899 update_ps_constants_userbuf(device);
900 } else {
901 if ((group & NINE_STATE_VS_CONST) && state->vs)
902 update_constants(device, PIPE_SHADER_VERTEX);
903 if ((group & NINE_STATE_PS_CONST) && state->ps)
904 update_constants(device, PIPE_SHADER_FRAGMENT);
905 }
906 }
907 if (state->changed.vtxbuf)
908 update_vertex_buffers(device);
909
910 device->state.changed.group &= ~mask |
911 (NINE_STATE_FF | NINE_STATE_VS_CONST | NINE_STATE_PS_CONST);
912
913 DBG("finished\n");
914
915 return TRUE;
916 }
917
918
919 static const DWORD nine_render_state_defaults[NINED3DRS_LAST + 1] =
920 {
921 /* [D3DRS_ZENABLE] = D3DZB_TRUE; wine: auto_depth_stencil */
922 [D3DRS_ZENABLE] = D3DZB_FALSE,
923 [D3DRS_FILLMODE] = D3DFILL_SOLID,
924 [D3DRS_SHADEMODE] = D3DSHADE_GOURAUD,
925 /* [D3DRS_LINEPATTERN] = 0x00000000, */
926 [D3DRS_ZWRITEENABLE] = TRUE,
927 [D3DRS_ALPHATESTENABLE] = FALSE,
928 [D3DRS_LASTPIXEL] = TRUE,
929 [D3DRS_SRCBLEND] = D3DBLEND_ONE,
930 [D3DRS_DESTBLEND] = D3DBLEND_ZERO,
931 [D3DRS_CULLMODE] = D3DCULL_CCW,
932 [D3DRS_ZFUNC] = D3DCMP_LESSEQUAL,
933 [D3DRS_ALPHAFUNC] = D3DCMP_ALWAYS,
934 [D3DRS_ALPHAREF] = 0,
935 [D3DRS_DITHERENABLE] = FALSE,
936 [D3DRS_ALPHABLENDENABLE] = FALSE,
937 [D3DRS_FOGENABLE] = FALSE,
938 [D3DRS_SPECULARENABLE] = FALSE,
939 /* [D3DRS_ZVISIBLE] = 0, */
940 [D3DRS_FOGCOLOR] = 0,
941 [D3DRS_FOGTABLEMODE] = D3DFOG_NONE,
942 [D3DRS_FOGSTART] = 0x00000000,
943 [D3DRS_FOGEND] = 0x3F800000,
944 [D3DRS_FOGDENSITY] = 0x3F800000,
945 /* [D3DRS_EDGEANTIALIAS] = FALSE, */
946 [D3DRS_RANGEFOGENABLE] = FALSE,
947 [D3DRS_STENCILENABLE] = FALSE,
948 [D3DRS_STENCILFAIL] = D3DSTENCILOP_KEEP,
949 [D3DRS_STENCILZFAIL] = D3DSTENCILOP_KEEP,
950 [D3DRS_STENCILPASS] = D3DSTENCILOP_KEEP,
951 [D3DRS_STENCILREF] = 0,
952 [D3DRS_STENCILMASK] = 0xFFFFFFFF,
953 [D3DRS_STENCILFUNC] = D3DCMP_ALWAYS,
954 [D3DRS_STENCILWRITEMASK] = 0xFFFFFFFF,
955 [D3DRS_TEXTUREFACTOR] = 0xFFFFFFFF,
956 [D3DRS_WRAP0] = 0,
957 [D3DRS_WRAP1] = 0,
958 [D3DRS_WRAP2] = 0,
959 [D3DRS_WRAP3] = 0,
960 [D3DRS_WRAP4] = 0,
961 [D3DRS_WRAP5] = 0,
962 [D3DRS_WRAP6] = 0,
963 [D3DRS_WRAP7] = 0,
964 [D3DRS_CLIPPING] = TRUE,
965 [D3DRS_LIGHTING] = TRUE,
966 [D3DRS_AMBIENT] = 0,
967 [D3DRS_FOGVERTEXMODE] = D3DFOG_NONE,
968 [D3DRS_COLORVERTEX] = TRUE,
969 [D3DRS_LOCALVIEWER] = TRUE,
970 [D3DRS_NORMALIZENORMALS] = FALSE,
971 [D3DRS_DIFFUSEMATERIALSOURCE] = D3DMCS_COLOR1,
972 [D3DRS_SPECULARMATERIALSOURCE] = D3DMCS_COLOR2,
973 [D3DRS_AMBIENTMATERIALSOURCE] = D3DMCS_MATERIAL,
974 [D3DRS_EMISSIVEMATERIALSOURCE] = D3DMCS_MATERIAL,
975 [D3DRS_VERTEXBLEND] = D3DVBF_DISABLE,
976 [D3DRS_CLIPPLANEENABLE] = 0,
977 /* [D3DRS_SOFTWAREVERTEXPROCESSING] = FALSE, */
978 [D3DRS_POINTSIZE] = 0x3F800000,
979 [D3DRS_POINTSIZE_MIN] = 0x3F800000,
980 [D3DRS_POINTSPRITEENABLE] = FALSE,
981 [D3DRS_POINTSCALEENABLE] = FALSE,
982 [D3DRS_POINTSCALE_A] = 0x3F800000,
983 [D3DRS_POINTSCALE_B] = 0x00000000,
984 [D3DRS_POINTSCALE_C] = 0x00000000,
985 [D3DRS_MULTISAMPLEANTIALIAS] = TRUE,
986 [D3DRS_MULTISAMPLEMASK] = 0xFFFFFFFF,
987 [D3DRS_PATCHEDGESTYLE] = D3DPATCHEDGE_DISCRETE,
988 /* [D3DRS_PATCHSEGMENTS] = 0x3F800000, */
989 [D3DRS_DEBUGMONITORTOKEN] = 0xDEADCAFE,
990 [D3DRS_POINTSIZE_MAX] = 0x3F800000, /* depends on cap */
991 [D3DRS_INDEXEDVERTEXBLENDENABLE] = FALSE,
992 [D3DRS_COLORWRITEENABLE] = 0x0000000f,
993 [D3DRS_TWEENFACTOR] = 0x00000000,
994 [D3DRS_BLENDOP] = D3DBLENDOP_ADD,
995 [D3DRS_POSITIONDEGREE] = D3DDEGREE_CUBIC,
996 [D3DRS_NORMALDEGREE] = D3DDEGREE_LINEAR,
997 [D3DRS_SCISSORTESTENABLE] = FALSE,
998 [D3DRS_SLOPESCALEDEPTHBIAS] = 0,
999 [D3DRS_MINTESSELLATIONLEVEL] = 0x3F800000,
1000 [D3DRS_MAXTESSELLATIONLEVEL] = 0x3F800000,
1001 [D3DRS_ANTIALIASEDLINEENABLE] = FALSE,
1002 [D3DRS_ADAPTIVETESS_X] = 0x00000000,
1003 [D3DRS_ADAPTIVETESS_Y] = 0x00000000,
1004 [D3DRS_ADAPTIVETESS_Z] = 0x3F800000,
1005 [D3DRS_ADAPTIVETESS_W] = 0x00000000,
1006 [D3DRS_ENABLEADAPTIVETESSELLATION] = FALSE,
1007 [D3DRS_TWOSIDEDSTENCILMODE] = FALSE,
1008 [D3DRS_CCW_STENCILFAIL] = D3DSTENCILOP_KEEP,
1009 [D3DRS_CCW_STENCILZFAIL] = D3DSTENCILOP_KEEP,
1010 [D3DRS_CCW_STENCILPASS] = D3DSTENCILOP_KEEP,
1011 [D3DRS_CCW_STENCILFUNC] = D3DCMP_ALWAYS,
1012 [D3DRS_COLORWRITEENABLE1] = 0x0000000F,
1013 [D3DRS_COLORWRITEENABLE2] = 0x0000000F,
1014 [D3DRS_COLORWRITEENABLE3] = 0x0000000F,
1015 [D3DRS_BLENDFACTOR] = 0xFFFFFFFF,
1016 [D3DRS_SRGBWRITEENABLE] = 0,
1017 [D3DRS_DEPTHBIAS] = 0,
1018 [D3DRS_WRAP8] = 0,
1019 [D3DRS_WRAP9] = 0,
1020 [D3DRS_WRAP10] = 0,
1021 [D3DRS_WRAP11] = 0,
1022 [D3DRS_WRAP12] = 0,
1023 [D3DRS_WRAP13] = 0,
1024 [D3DRS_WRAP14] = 0,
1025 [D3DRS_WRAP15] = 0,
1026 [D3DRS_SEPARATEALPHABLENDENABLE] = FALSE,
1027 [D3DRS_SRCBLENDALPHA] = D3DBLEND_ONE,
1028 [D3DRS_DESTBLENDALPHA] = D3DBLEND_ZERO,
1029 [D3DRS_BLENDOPALPHA] = D3DBLENDOP_ADD,
1030 [NINED3DRS_VSPOINTSIZE] = FALSE,
1031 [NINED3DRS_RTMASK] = 0xf,
1032 [NINED3DRS_ALPHACOVERAGE] = FALSE
1033 };
1034 static const DWORD nine_tex_stage_state_defaults[NINED3DTSS_LAST + 1] =
1035 {
1036 [D3DTSS_COLOROP] = D3DTOP_DISABLE,
1037 [D3DTSS_ALPHAOP] = D3DTOP_DISABLE,
1038 [D3DTSS_COLORARG1] = D3DTA_TEXTURE,
1039 [D3DTSS_COLORARG2] = D3DTA_CURRENT,
1040 [D3DTSS_COLORARG0] = D3DTA_CURRENT,
1041 [D3DTSS_ALPHAARG1] = D3DTA_TEXTURE,
1042 [D3DTSS_ALPHAARG2] = D3DTA_CURRENT,
1043 [D3DTSS_ALPHAARG0] = D3DTA_CURRENT,
1044 [D3DTSS_RESULTARG] = D3DTA_CURRENT,
1045 [D3DTSS_BUMPENVMAT00] = 0,
1046 [D3DTSS_BUMPENVMAT01] = 0,
1047 [D3DTSS_BUMPENVMAT10] = 0,
1048 [D3DTSS_BUMPENVMAT11] = 0,
1049 [D3DTSS_BUMPENVLSCALE] = 0,
1050 [D3DTSS_BUMPENVLOFFSET] = 0,
1051 [D3DTSS_TEXCOORDINDEX] = 0,
1052 [D3DTSS_TEXTURETRANSFORMFLAGS] = D3DTTFF_DISABLE,
1053 };
1054 static const DWORD nine_samp_state_defaults[NINED3DSAMP_LAST + 1] =
1055 {
1056 [D3DSAMP_ADDRESSU] = D3DTADDRESS_WRAP,
1057 [D3DSAMP_ADDRESSV] = D3DTADDRESS_WRAP,
1058 [D3DSAMP_ADDRESSW] = D3DTADDRESS_WRAP,
1059 [D3DSAMP_BORDERCOLOR] = 0,
1060 [D3DSAMP_MAGFILTER] = D3DTEXF_POINT,
1061 [D3DSAMP_MINFILTER] = D3DTEXF_POINT,
1062 [D3DSAMP_MIPFILTER] = D3DTEXF_NONE,
1063 [D3DSAMP_MIPMAPLODBIAS] = 0,
1064 [D3DSAMP_MAXMIPLEVEL] = 0,
1065 [D3DSAMP_MAXANISOTROPY] = 1,
1066 [D3DSAMP_SRGBTEXTURE] = 0,
1067 [D3DSAMP_ELEMENTINDEX] = 0,
1068 [D3DSAMP_DMAPOFFSET] = 0,
1069 [NINED3DSAMP_MINLOD] = 0,
1070 [NINED3DSAMP_SHADOW] = 0
1071 };
1072 void
1073 nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps,
1074 boolean is_reset)
1075 {
1076 struct nine_state *state = &device->state;
1077 unsigned s;
1078
1079 /* Initialize defaults.
1080 */
1081 memcpy(state->rs, nine_render_state_defaults, sizeof(state->rs));
1082
1083 for (s = 0; s < Elements(state->ff.tex_stage); ++s) {
1084 memcpy(&state->ff.tex_stage[s], nine_tex_stage_state_defaults,
1085 sizeof(state->ff.tex_stage[s]));
1086 state->ff.tex_stage[s][D3DTSS_TEXCOORDINDEX] = s;
1087 }
1088 state->ff.tex_stage[0][D3DTSS_COLOROP] = D3DTOP_MODULATE;
1089 state->ff.tex_stage[0][D3DTSS_ALPHAOP] = D3DTOP_SELECTARG1;
1090
1091 for (s = 0; s < Elements(state->samp); ++s) {
1092 memcpy(&state->samp[s], nine_samp_state_defaults,
1093 sizeof(state->samp[s]));
1094 }
1095
1096 if (state->vs_const_f)
1097 memset(state->vs_const_f, 0, device->vs_const_size);
1098 if (state->ps_const_f)
1099 memset(state->ps_const_f, 0, device->ps_const_size);
1100
1101 /* Cap dependent initial state:
1102 */
1103 state->rs[D3DRS_POINTSIZE_MAX] = fui(caps->MaxPointSize);
1104
1105 /* Set changed flags to initialize driver.
1106 */
1107 state->changed.group = NINE_STATE_ALL;
1108
1109 state->ff.changed.transform[0] = ~0;
1110 state->ff.changed.transform[D3DTS_WORLD / 32] |= 1 << (D3DTS_WORLD % 32);
1111
1112 if (!is_reset) {
1113 state->viewport.MinZ = 0.0f;
1114 state->viewport.MaxZ = 1.0f;
1115 }
1116
1117 for (s = 0; s < Elements(state->changed.sampler); ++s)
1118 state->changed.sampler[s] = ~0;
1119 }
1120
1121 void
1122 nine_state_clear(struct nine_state *state, const boolean device)
1123 {
1124 unsigned i;
1125
1126 for (i = 0; i < Elements(state->rt); ++i)
1127 nine_bind(&state->rt[i], NULL);
1128 nine_bind(&state->ds, NULL);
1129 nine_bind(&state->vs, NULL);
1130 nine_bind(&state->ps, NULL);
1131 nine_bind(&state->vdecl, NULL);
1132 for (i = 0; i < PIPE_MAX_ATTRIBS; ++i)
1133 nine_bind(&state->stream[i], NULL);
1134 nine_bind(&state->idxbuf, NULL);
1135 for (i = 0; i < NINE_MAX_SAMPLERS; ++i) {
1136 if (device &&
1137 state->texture[i] &&
1138 --state->texture[i]->bind_count == 0)
1139 list_delinit(&state->texture[i]->list);
1140 nine_bind(&state->texture[i], NULL);
1141 }
1142 }
1143
1144 /*
1145 static const DWORD nine_render_states_pixel[] =
1146 {
1147 D3DRS_ALPHABLENDENABLE,
1148 D3DRS_ALPHAFUNC,
1149 D3DRS_ALPHAREF,
1150 D3DRS_ALPHATESTENABLE,
1151 D3DRS_ANTIALIASEDLINEENABLE,
1152 D3DRS_BLENDFACTOR,
1153 D3DRS_BLENDOP,
1154 D3DRS_BLENDOPALPHA,
1155 D3DRS_CCW_STENCILFAIL,
1156 D3DRS_CCW_STENCILPASS,
1157 D3DRS_CCW_STENCILZFAIL,
1158 D3DRS_COLORWRITEENABLE,
1159 D3DRS_COLORWRITEENABLE1,
1160 D3DRS_COLORWRITEENABLE2,
1161 D3DRS_COLORWRITEENABLE3,
1162 D3DRS_DEPTHBIAS,
1163 D3DRS_DESTBLEND,
1164 D3DRS_DESTBLENDALPHA,
1165 D3DRS_DITHERENABLE,
1166 D3DRS_FILLMODE,
1167 D3DRS_FOGDENSITY,
1168 D3DRS_FOGEND,
1169 D3DRS_FOGSTART,
1170 D3DRS_LASTPIXEL,
1171 D3DRS_SCISSORTESTENABLE,
1172 D3DRS_SEPARATEALPHABLENDENABLE,
1173 D3DRS_SHADEMODE,
1174 D3DRS_SLOPESCALEDEPTHBIAS,
1175 D3DRS_SRCBLEND,
1176 D3DRS_SRCBLENDALPHA,
1177 D3DRS_SRGBWRITEENABLE,
1178 D3DRS_STENCILENABLE,
1179 D3DRS_STENCILFAIL,
1180 D3DRS_STENCILFUNC,
1181 D3DRS_STENCILMASK,
1182 D3DRS_STENCILPASS,
1183 D3DRS_STENCILREF,
1184 D3DRS_STENCILWRITEMASK,
1185 D3DRS_STENCILZFAIL,
1186 D3DRS_TEXTUREFACTOR,
1187 D3DRS_TWOSIDEDSTENCILMODE,
1188 D3DRS_WRAP0,
1189 D3DRS_WRAP1,
1190 D3DRS_WRAP10,
1191 D3DRS_WRAP11,
1192 D3DRS_WRAP12,
1193 D3DRS_WRAP13,
1194 D3DRS_WRAP14,
1195 D3DRS_WRAP15,
1196 D3DRS_WRAP2,
1197 D3DRS_WRAP3,
1198 D3DRS_WRAP4,
1199 D3DRS_WRAP5,
1200 D3DRS_WRAP6,
1201 D3DRS_WRAP7,
1202 D3DRS_WRAP8,
1203 D3DRS_WRAP9,
1204 D3DRS_ZENABLE,
1205 D3DRS_ZFUNC,
1206 D3DRS_ZWRITEENABLE
1207 };
1208 */
1209 const uint32_t nine_render_states_pixel[(NINED3DRS_LAST + 31) / 32] =
1210 {
1211 0x0f99c380, 0x1ff00070, 0x00000000, 0x00000000,
1212 0x000000ff, 0xde01c900, 0x0003ffcf
1213 };
1214
1215 /*
1216 static const DWORD nine_render_states_vertex[] =
1217 {
1218 D3DRS_ADAPTIVETESS_W,
1219 D3DRS_ADAPTIVETESS_X,
1220 D3DRS_ADAPTIVETESS_Y,
1221 D3DRS_ADAPTIVETESS_Z,
1222 D3DRS_AMBIENT,
1223 D3DRS_AMBIENTMATERIALSOURCE,
1224 D3DRS_CLIPPING,
1225 D3DRS_CLIPPLANEENABLE,
1226 D3DRS_COLORVERTEX,
1227 D3DRS_CULLMODE,
1228 D3DRS_DIFFUSEMATERIALSOURCE,
1229 D3DRS_EMISSIVEMATERIALSOURCE,
1230 D3DRS_ENABLEADAPTIVETESSELLATION,
1231 D3DRS_FOGCOLOR,
1232 D3DRS_FOGDENSITY,
1233 D3DRS_FOGENABLE,
1234 D3DRS_FOGEND,
1235 D3DRS_FOGSTART,
1236 D3DRS_FOGTABLEMODE,
1237 D3DRS_FOGVERTEXMODE,
1238 D3DRS_INDEXEDVERTEXBLENDENABLE,
1239 D3DRS_LIGHTING,
1240 D3DRS_LOCALVIEWER,
1241 D3DRS_MAXTESSELLATIONLEVEL,
1242 D3DRS_MINTESSELLATIONLEVEL,
1243 D3DRS_MULTISAMPLEANTIALIAS,
1244 D3DRS_MULTISAMPLEMASK,
1245 D3DRS_NORMALDEGREE,
1246 D3DRS_NORMALIZENORMALS,
1247 D3DRS_PATCHEDGESTYLE,
1248 D3DRS_POINTSCALE_A,
1249 D3DRS_POINTSCALE_B,
1250 D3DRS_POINTSCALE_C,
1251 D3DRS_POINTSCALEENABLE,
1252 D3DRS_POINTSIZE,
1253 D3DRS_POINTSIZE_MAX,
1254 D3DRS_POINTSIZE_MIN,
1255 D3DRS_POINTSPRITEENABLE,
1256 D3DRS_POSITIONDEGREE,
1257 D3DRS_RANGEFOGENABLE,
1258 D3DRS_SHADEMODE,
1259 D3DRS_SPECULARENABLE,
1260 D3DRS_SPECULARMATERIALSOURCE,
1261 D3DRS_TWEENFACTOR,
1262 D3DRS_VERTEXBLEND
1263 };
1264 */
1265 const uint32_t nine_render_states_vertex[(NINED3DRS_LAST + 31) / 32] =
1266 {
1267 0x30400200, 0x0001007c, 0x00000000, 0x00000000,
1268 0xfd9efb00, 0x01fc34cf, 0x00000000
1269 };
1270
1271 /* TODO: put in the right values */
1272 const uint32_t nine_render_state_group[NINED3DRS_LAST + 1] =
1273 {
1274 [D3DRS_ZENABLE] = NINE_STATE_DSA,
1275 [D3DRS_FILLMODE] = NINE_STATE_RASTERIZER,
1276 [D3DRS_SHADEMODE] = NINE_STATE_RASTERIZER,
1277 [D3DRS_ZWRITEENABLE] = NINE_STATE_DSA,
1278 [D3DRS_ALPHATESTENABLE] = NINE_STATE_DSA,
1279 [D3DRS_LASTPIXEL] = NINE_STATE_RASTERIZER,
1280 [D3DRS_SRCBLEND] = NINE_STATE_BLEND,
1281 [D3DRS_DESTBLEND] = NINE_STATE_BLEND,
1282 [D3DRS_CULLMODE] = NINE_STATE_RASTERIZER,
1283 [D3DRS_ZFUNC] = NINE_STATE_DSA,
1284 [D3DRS_ALPHAREF] = NINE_STATE_DSA,
1285 [D3DRS_ALPHAFUNC] = NINE_STATE_DSA,
1286 [D3DRS_DITHERENABLE] = NINE_STATE_RASTERIZER,
1287 [D3DRS_ALPHABLENDENABLE] = NINE_STATE_BLEND,
1288 [D3DRS_FOGENABLE] = NINE_STATE_FF_OTHER,
1289 [D3DRS_SPECULARENABLE] = NINE_STATE_FF_LIGHTING,
1290 [D3DRS_FOGCOLOR] = NINE_STATE_FF_OTHER,
1291 [D3DRS_FOGTABLEMODE] = NINE_STATE_FF_OTHER,
1292 [D3DRS_FOGSTART] = NINE_STATE_FF_OTHER,
1293 [D3DRS_FOGEND] = NINE_STATE_FF_OTHER,
1294 [D3DRS_FOGDENSITY] = NINE_STATE_FF_OTHER,
1295 [D3DRS_RANGEFOGENABLE] = NINE_STATE_FF_OTHER,
1296 [D3DRS_STENCILENABLE] = NINE_STATE_DSA,
1297 [D3DRS_STENCILFAIL] = NINE_STATE_DSA,
1298 [D3DRS_STENCILZFAIL] = NINE_STATE_DSA,
1299 [D3DRS_STENCILPASS] = NINE_STATE_DSA,
1300 [D3DRS_STENCILFUNC] = NINE_STATE_DSA,
1301 [D3DRS_STENCILREF] = NINE_STATE_STENCIL_REF,
1302 [D3DRS_STENCILMASK] = NINE_STATE_DSA,
1303 [D3DRS_STENCILWRITEMASK] = NINE_STATE_DSA,
1304 [D3DRS_TEXTUREFACTOR] = NINE_STATE_FF_PSSTAGES,
1305 [D3DRS_WRAP0] = NINE_STATE_UNHANDLED, /* cylindrical wrap is crazy */
1306 [D3DRS_WRAP1] = NINE_STATE_UNHANDLED,
1307 [D3DRS_WRAP2] = NINE_STATE_UNHANDLED,
1308 [D3DRS_WRAP3] = NINE_STATE_UNHANDLED,
1309 [D3DRS_WRAP4] = NINE_STATE_UNHANDLED,
1310 [D3DRS_WRAP5] = NINE_STATE_UNHANDLED,
1311 [D3DRS_WRAP6] = NINE_STATE_UNHANDLED,
1312 [D3DRS_WRAP7] = NINE_STATE_UNHANDLED,
1313 [D3DRS_CLIPPING] = 0, /* software vertex processing only */
1314 [D3DRS_LIGHTING] = NINE_STATE_FF_LIGHTING,
1315 [D3DRS_AMBIENT] = NINE_STATE_FF_LIGHTING | NINE_STATE_FF_MATERIAL,
1316 [D3DRS_FOGVERTEXMODE] = NINE_STATE_FF_OTHER,
1317 [D3DRS_COLORVERTEX] = NINE_STATE_FF_LIGHTING,
1318 [D3DRS_LOCALVIEWER] = NINE_STATE_FF_LIGHTING,
1319 [D3DRS_NORMALIZENORMALS] = NINE_STATE_FF_OTHER,
1320 [D3DRS_DIFFUSEMATERIALSOURCE] = NINE_STATE_FF_LIGHTING,
1321 [D3DRS_SPECULARMATERIALSOURCE] = NINE_STATE_FF_LIGHTING,
1322 [D3DRS_AMBIENTMATERIALSOURCE] = NINE_STATE_FF_LIGHTING,
1323 [D3DRS_EMISSIVEMATERIALSOURCE] = NINE_STATE_FF_LIGHTING,
1324 [D3DRS_VERTEXBLEND] = NINE_STATE_FF_OTHER,
1325 [D3DRS_CLIPPLANEENABLE] = NINE_STATE_RASTERIZER,
1326 [D3DRS_POINTSIZE] = NINE_STATE_RASTERIZER,
1327 [D3DRS_POINTSIZE_MIN] = NINE_STATE_MISC_CONST,
1328 [D3DRS_POINTSPRITEENABLE] = NINE_STATE_RASTERIZER,
1329 [D3DRS_POINTSCALEENABLE] = NINE_STATE_FF_OTHER,
1330 [D3DRS_POINTSCALE_A] = NINE_STATE_FF_OTHER,
1331 [D3DRS_POINTSCALE_B] = NINE_STATE_FF_OTHER,
1332 [D3DRS_POINTSCALE_C] = NINE_STATE_FF_OTHER,
1333 [D3DRS_MULTISAMPLEANTIALIAS] = NINE_STATE_RASTERIZER,
1334 [D3DRS_MULTISAMPLEMASK] = NINE_STATE_SAMPLE_MASK,
1335 [D3DRS_PATCHEDGESTYLE] = NINE_STATE_UNHANDLED,
1336 [D3DRS_DEBUGMONITORTOKEN] = NINE_STATE_UNHANDLED,
1337 [D3DRS_POINTSIZE_MAX] = NINE_STATE_MISC_CONST,
1338 [D3DRS_INDEXEDVERTEXBLENDENABLE] = NINE_STATE_FF_OTHER,
1339 [D3DRS_COLORWRITEENABLE] = NINE_STATE_BLEND,
1340 [D3DRS_TWEENFACTOR] = NINE_STATE_FF_OTHER,
1341 [D3DRS_BLENDOP] = NINE_STATE_BLEND,
1342 [D3DRS_POSITIONDEGREE] = NINE_STATE_UNHANDLED,
1343 [D3DRS_NORMALDEGREE] = NINE_STATE_UNHANDLED,
1344 [D3DRS_SCISSORTESTENABLE] = NINE_STATE_RASTERIZER,
1345 [D3DRS_SLOPESCALEDEPTHBIAS] = NINE_STATE_RASTERIZER,
1346 [D3DRS_ANTIALIASEDLINEENABLE] = NINE_STATE_RASTERIZER,
1347 [D3DRS_MINTESSELLATIONLEVEL] = NINE_STATE_UNHANDLED,
1348 [D3DRS_MAXTESSELLATIONLEVEL] = NINE_STATE_UNHANDLED,
1349 [D3DRS_ADAPTIVETESS_X] = NINE_STATE_UNHANDLED,
1350 [D3DRS_ADAPTIVETESS_Y] = NINE_STATE_UNHANDLED,
1351 [D3DRS_ADAPTIVETESS_Z] = NINE_STATE_UNHANDLED,
1352 [D3DRS_ADAPTIVETESS_W] = NINE_STATE_UNHANDLED,
1353 [D3DRS_ENABLEADAPTIVETESSELLATION] = NINE_STATE_UNHANDLED,
1354 [D3DRS_TWOSIDEDSTENCILMODE] = NINE_STATE_DSA,
1355 [D3DRS_CCW_STENCILFAIL] = NINE_STATE_DSA,
1356 [D3DRS_CCW_STENCILZFAIL] = NINE_STATE_DSA,
1357 [D3DRS_CCW_STENCILPASS] = NINE_STATE_DSA,
1358 [D3DRS_CCW_STENCILFUNC] = NINE_STATE_DSA,
1359 [D3DRS_COLORWRITEENABLE1] = NINE_STATE_BLEND,
1360 [D3DRS_COLORWRITEENABLE2] = NINE_STATE_BLEND,
1361 [D3DRS_COLORWRITEENABLE3] = NINE_STATE_BLEND,
1362 [D3DRS_BLENDFACTOR] = NINE_STATE_BLEND_COLOR,
1363 [D3DRS_SRGBWRITEENABLE] = NINE_STATE_FB,
1364 [D3DRS_DEPTHBIAS] = NINE_STATE_RASTERIZER,
1365 [D3DRS_WRAP8] = NINE_STATE_UNHANDLED, /* cylwrap has to be done via GP */
1366 [D3DRS_WRAP9] = NINE_STATE_UNHANDLED,
1367 [D3DRS_WRAP10] = NINE_STATE_UNHANDLED,
1368 [D3DRS_WRAP11] = NINE_STATE_UNHANDLED,
1369 [D3DRS_WRAP12] = NINE_STATE_UNHANDLED,
1370 [D3DRS_WRAP13] = NINE_STATE_UNHANDLED,
1371 [D3DRS_WRAP14] = NINE_STATE_UNHANDLED,
1372 [D3DRS_WRAP15] = NINE_STATE_UNHANDLED,
1373 [D3DRS_SEPARATEALPHABLENDENABLE] = NINE_STATE_BLEND,
1374 [D3DRS_SRCBLENDALPHA] = NINE_STATE_BLEND,
1375 [D3DRS_DESTBLENDALPHA] = NINE_STATE_BLEND,
1376 [D3DRS_BLENDOPALPHA] = NINE_STATE_BLEND
1377 };
1378
1379 D3DMATRIX *
1380 nine_state_access_transform(struct nine_state *state, D3DTRANSFORMSTATETYPE t,
1381 boolean alloc)
1382 {
1383 static D3DMATRIX Identity = { .m[0] = { 1, 0, 0, 0 },
1384 .m[1] = { 0, 1, 0, 0 },
1385 .m[2] = { 0, 0, 1, 0 },
1386 .m[3] = { 0, 0, 0, 1 } };
1387 unsigned index;
1388
1389 switch (t) {
1390 case D3DTS_VIEW: index = 0; break;
1391 case D3DTS_PROJECTION: index = 1; break;
1392 case D3DTS_TEXTURE0: index = 2; break;
1393 case D3DTS_TEXTURE1: index = 3; break;
1394 case D3DTS_TEXTURE2: index = 4; break;
1395 case D3DTS_TEXTURE3: index = 5; break;
1396 case D3DTS_TEXTURE4: index = 6; break;
1397 case D3DTS_TEXTURE5: index = 7; break;
1398 case D3DTS_TEXTURE6: index = 8; break;
1399 case D3DTS_TEXTURE7: index = 9; break;
1400 default:
1401 if (!(t >= D3DTS_WORLDMATRIX(0) && t <= D3DTS_WORLDMATRIX(255)))
1402 return NULL;
1403 index = 10 + (t - D3DTS_WORLDMATRIX(0));
1404 break;
1405 }
1406
1407 if (index >= state->ff.num_transforms) {
1408 unsigned N = index + 1;
1409 unsigned n = state->ff.num_transforms;
1410
1411 if (!alloc)
1412 return &Identity;
1413 state->ff.transform = REALLOC(state->ff.transform,
1414 n * sizeof(D3DMATRIX),
1415 N * sizeof(D3DMATRIX));
1416 for (; n < N; ++n)
1417 state->ff.transform[n] = Identity;
1418 state->ff.num_transforms = N;
1419 }
1420 return &state->ff.transform[index];
1421 }
1422
1423 #define D3DRS_TO_STRING_CASE(n) case D3DRS_##n: return "D3DRS_"#n
1424 const char *nine_d3drs_to_string(DWORD State)
1425 {
1426 switch (State) {
1427 D3DRS_TO_STRING_CASE(ZENABLE);
1428 D3DRS_TO_STRING_CASE(FILLMODE);
1429 D3DRS_TO_STRING_CASE(SHADEMODE);
1430 D3DRS_TO_STRING_CASE(ZWRITEENABLE);
1431 D3DRS_TO_STRING_CASE(ALPHATESTENABLE);
1432 D3DRS_TO_STRING_CASE(LASTPIXEL);
1433 D3DRS_TO_STRING_CASE(SRCBLEND);
1434 D3DRS_TO_STRING_CASE(DESTBLEND);
1435 D3DRS_TO_STRING_CASE(CULLMODE);
1436 D3DRS_TO_STRING_CASE(ZFUNC);
1437 D3DRS_TO_STRING_CASE(ALPHAREF);
1438 D3DRS_TO_STRING_CASE(ALPHAFUNC);
1439 D3DRS_TO_STRING_CASE(DITHERENABLE);
1440 D3DRS_TO_STRING_CASE(ALPHABLENDENABLE);
1441 D3DRS_TO_STRING_CASE(FOGENABLE);
1442 D3DRS_TO_STRING_CASE(SPECULARENABLE);
1443 D3DRS_TO_STRING_CASE(FOGCOLOR);
1444 D3DRS_TO_STRING_CASE(FOGTABLEMODE);
1445 D3DRS_TO_STRING_CASE(FOGSTART);
1446 D3DRS_TO_STRING_CASE(FOGEND);
1447 D3DRS_TO_STRING_CASE(FOGDENSITY);
1448 D3DRS_TO_STRING_CASE(RANGEFOGENABLE);
1449 D3DRS_TO_STRING_CASE(STENCILENABLE);
1450 D3DRS_TO_STRING_CASE(STENCILFAIL);
1451 D3DRS_TO_STRING_CASE(STENCILZFAIL);
1452 D3DRS_TO_STRING_CASE(STENCILPASS);
1453 D3DRS_TO_STRING_CASE(STENCILFUNC);
1454 D3DRS_TO_STRING_CASE(STENCILREF);
1455 D3DRS_TO_STRING_CASE(STENCILMASK);
1456 D3DRS_TO_STRING_CASE(STENCILWRITEMASK);
1457 D3DRS_TO_STRING_CASE(TEXTUREFACTOR);
1458 D3DRS_TO_STRING_CASE(WRAP0);
1459 D3DRS_TO_STRING_CASE(WRAP1);
1460 D3DRS_TO_STRING_CASE(WRAP2);
1461 D3DRS_TO_STRING_CASE(WRAP3);
1462 D3DRS_TO_STRING_CASE(WRAP4);
1463 D3DRS_TO_STRING_CASE(WRAP5);
1464 D3DRS_TO_STRING_CASE(WRAP6);
1465 D3DRS_TO_STRING_CASE(WRAP7);
1466 D3DRS_TO_STRING_CASE(CLIPPING);
1467 D3DRS_TO_STRING_CASE(LIGHTING);
1468 D3DRS_TO_STRING_CASE(AMBIENT);
1469 D3DRS_TO_STRING_CASE(FOGVERTEXMODE);
1470 D3DRS_TO_STRING_CASE(COLORVERTEX);
1471 D3DRS_TO_STRING_CASE(LOCALVIEWER);
1472 D3DRS_TO_STRING_CASE(NORMALIZENORMALS);
1473 D3DRS_TO_STRING_CASE(DIFFUSEMATERIALSOURCE);
1474 D3DRS_TO_STRING_CASE(SPECULARMATERIALSOURCE);
1475 D3DRS_TO_STRING_CASE(AMBIENTMATERIALSOURCE);
1476 D3DRS_TO_STRING_CASE(EMISSIVEMATERIALSOURCE);
1477 D3DRS_TO_STRING_CASE(VERTEXBLEND);
1478 D3DRS_TO_STRING_CASE(CLIPPLANEENABLE);
1479 D3DRS_TO_STRING_CASE(POINTSIZE);
1480 D3DRS_TO_STRING_CASE(POINTSIZE_MIN);
1481 D3DRS_TO_STRING_CASE(POINTSPRITEENABLE);
1482 D3DRS_TO_STRING_CASE(POINTSCALEENABLE);
1483 D3DRS_TO_STRING_CASE(POINTSCALE_A);
1484 D3DRS_TO_STRING_CASE(POINTSCALE_B);
1485 D3DRS_TO_STRING_CASE(POINTSCALE_C);
1486 D3DRS_TO_STRING_CASE(MULTISAMPLEANTIALIAS);
1487 D3DRS_TO_STRING_CASE(MULTISAMPLEMASK);
1488 D3DRS_TO_STRING_CASE(PATCHEDGESTYLE);
1489 D3DRS_TO_STRING_CASE(DEBUGMONITORTOKEN);
1490 D3DRS_TO_STRING_CASE(POINTSIZE_MAX);
1491 D3DRS_TO_STRING_CASE(INDEXEDVERTEXBLENDENABLE);
1492 D3DRS_TO_STRING_CASE(COLORWRITEENABLE);
1493 D3DRS_TO_STRING_CASE(TWEENFACTOR);
1494 D3DRS_TO_STRING_CASE(BLENDOP);
1495 D3DRS_TO_STRING_CASE(POSITIONDEGREE);
1496 D3DRS_TO_STRING_CASE(NORMALDEGREE);
1497 D3DRS_TO_STRING_CASE(SCISSORTESTENABLE);
1498 D3DRS_TO_STRING_CASE(SLOPESCALEDEPTHBIAS);
1499 D3DRS_TO_STRING_CASE(ANTIALIASEDLINEENABLE);
1500 D3DRS_TO_STRING_CASE(MINTESSELLATIONLEVEL);
1501 D3DRS_TO_STRING_CASE(MAXTESSELLATIONLEVEL);
1502 D3DRS_TO_STRING_CASE(ADAPTIVETESS_X);
1503 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Y);
1504 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Z);
1505 D3DRS_TO_STRING_CASE(ADAPTIVETESS_W);
1506 D3DRS_TO_STRING_CASE(ENABLEADAPTIVETESSELLATION);
1507 D3DRS_TO_STRING_CASE(TWOSIDEDSTENCILMODE);
1508 D3DRS_TO_STRING_CASE(CCW_STENCILFAIL);
1509 D3DRS_TO_STRING_CASE(CCW_STENCILZFAIL);
1510 D3DRS_TO_STRING_CASE(CCW_STENCILPASS);
1511 D3DRS_TO_STRING_CASE(CCW_STENCILFUNC);
1512 D3DRS_TO_STRING_CASE(COLORWRITEENABLE1);
1513 D3DRS_TO_STRING_CASE(COLORWRITEENABLE2);
1514 D3DRS_TO_STRING_CASE(COLORWRITEENABLE3);
1515 D3DRS_TO_STRING_CASE(BLENDFACTOR);
1516 D3DRS_TO_STRING_CASE(SRGBWRITEENABLE);
1517 D3DRS_TO_STRING_CASE(DEPTHBIAS);
1518 D3DRS_TO_STRING_CASE(WRAP8);
1519 D3DRS_TO_STRING_CASE(WRAP9);
1520 D3DRS_TO_STRING_CASE(WRAP10);
1521 D3DRS_TO_STRING_CASE(WRAP11);
1522 D3DRS_TO_STRING_CASE(WRAP12);
1523 D3DRS_TO_STRING_CASE(WRAP13);
1524 D3DRS_TO_STRING_CASE(WRAP14);
1525 D3DRS_TO_STRING_CASE(WRAP15);
1526 D3DRS_TO_STRING_CASE(SEPARATEALPHABLENDENABLE);
1527 D3DRS_TO_STRING_CASE(SRCBLENDALPHA);
1528 D3DRS_TO_STRING_CASE(DESTBLENDALPHA);
1529 D3DRS_TO_STRING_CASE(BLENDOPALPHA);
1530 default:
1531 return "(invalid)";
1532 }
1533 }
1534