2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 * Copyright 2013 Christoph Bumiller
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:
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
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. */
25 #include "basetexture9.h"
26 #include "indexbuffer9.h"
28 #include "vertexdeclaration9.h"
29 #include "vertexshader9.h"
30 #include "pixelshader9.h"
31 #include "nine_pipe.h"
33 #include "pipe/p_context.h"
34 #include "pipe/p_state.h"
35 #include "cso_cache/cso_context.h"
36 #include "util/u_upload_mgr.h"
37 #include "util/u_math.h"
39 #define DBG_CHANNEL DBG_DEVICE
41 /* State preparation only */
44 prepare_blend(struct NineDevice9
*device
)
46 nine_convert_blend_state(&device
->state
.pipe
.blend
, device
->state
.rs
);
47 device
->state
.commit
|= NINE_STATE_COMMIT_BLEND
;
51 prepare_dsa(struct NineDevice9
*device
)
53 nine_convert_dsa_state(&device
->state
.pipe
.dsa
, device
->state
.rs
);
54 device
->state
.commit
|= NINE_STATE_COMMIT_DSA
;
58 prepare_rasterizer(struct NineDevice9
*device
)
60 nine_convert_rasterizer_state(&device
->state
.pipe
.rast
, device
->state
.rs
);
61 device
->state
.commit
|= NINE_STATE_COMMIT_RASTERIZER
;
64 #define DO_UPLOAD_CONST_F(buf,p,c,d) \
66 DBG("upload ConstantF [%u .. %u]\n", x, (x) + (c) - 1); \
67 box.x = (p) * 4 * sizeof(float); \
68 box.width = (c) * 4 * sizeof(float); \
69 pipe->transfer_inline_write(pipe, buf, 0, usage, &box, &((d)[p * 4]), \
73 /* OK, this is a bit ugly ... */
75 upload_constants(struct NineDevice9
*device
, unsigned shader_type
)
77 struct pipe_context
*pipe
= device
->pipe
;
78 struct pipe_resource
*buf
;
84 uint32_t data_b
[NINE_MAX_CONST_B
];
87 const unsigned usage
= PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD_RANGE
;
88 unsigned x
= 0; /* silence warning */
90 struct nine_range
*r
, *p
, *lconstf_ranges
;
98 if (shader_type
== PIPE_SHADER_VERTEX
) {
100 buf
= device
->constbuf_vs
;
102 const_f
= device
->state
.vs_const_f
;
103 for (p
= r
= device
->state
.changed
.vs_const_f
; r
; p
= r
, r
= r
->next
)
104 DO_UPLOAD_CONST_F(buf
, r
->bgn
, r
->end
- r
->bgn
, const_f
);
106 nine_range_pool_put_chain(&device
->range_pool
,
107 device
->state
.changed
.vs_const_f
, p
);
108 device
->state
.changed
.vs_const_f
= NULL
;
111 dirty_i
= device
->state
.changed
.vs_const_i
;
112 device
->state
.changed
.vs_const_i
= 0;
113 const_i
= &device
->state
.vs_const_i
[0][0];
115 dirty_b
= device
->state
.changed
.vs_const_b
;
116 device
->state
.changed
.vs_const_b
= 0;
117 const_b
= device
->state
.vs_const_b
;
119 lconstf_ranges
= device
->state
.vs
->lconstf
.ranges
;
120 lconstf_data
= device
->state
.vs
->lconstf
.data
;
122 device
->state
.changed
.group
&= ~NINE_STATE_VS_CONST
;
125 buf
= device
->constbuf_ps
;
127 const_f
= device
->state
.ps_const_f
;
128 for (p
= r
= device
->state
.changed
.ps_const_f
; r
; p
= r
, r
= r
->next
)
129 DO_UPLOAD_CONST_F(buf
, r
->bgn
, r
->end
- r
->bgn
, const_f
);
131 nine_range_pool_put_chain(&device
->range_pool
,
132 device
->state
.changed
.ps_const_f
, p
);
133 device
->state
.changed
.ps_const_f
= NULL
;
136 dirty_i
= device
->state
.changed
.ps_const_i
;
137 device
->state
.changed
.ps_const_i
= 0;
138 const_i
= &device
->state
.ps_const_i
[0][0];
140 dirty_b
= device
->state
.changed
.ps_const_b
;
141 device
->state
.changed
.ps_const_b
= 0;
142 const_b
= device
->state
.ps_const_b
;
144 lconstf_ranges
= NULL
;
147 device
->state
.changed
.group
&= ~NINE_STATE_PS_CONST
;
150 /* write range from min to max changed, it's not much data */
153 c
= util_last_bit(dirty_b
);
154 i
= ffs(dirty_b
) - 1;
155 x
= buf
->width0
- (NINE_MAX_CONST_B
- i
) * 4;
157 memcpy(data_b
, &(const_b
[i
]), c
* sizeof(uint32_t));
160 DBG("upload ConstantB [%u .. %u]\n", x
, x
+ c
- 1);
161 pipe
->transfer_inline_write(pipe
, buf
, 0, usage
, &box
, data_b
, 0, 0);
165 for (c
= 0, i
= 0; dirty_i
; i
++, dirty_i
>>= 1) {
172 DBG("upload ConstantI [%u .. %u]\n", x
, x
+ c
- 1);
173 data
= &const_i
[x
* 4];
174 box
.x
= buf
->width0
- (NINE_MAX_CONST_I
* 4 + NINE_MAX_CONST_B
) * 4;
175 box
.x
+= x
* 4 * sizeof(int);
176 box
.width
= c
* 4 * sizeof(int);
178 pipe
->transfer_inline_write(pipe
, buf
, 0, usage
, &box
, data
, 0, 0);
182 DBG("upload ConstantI [%u .. %u]\n", x
, x
+ c
- 1);
183 data
= &const_i
[x
* 4];
184 box
.x
= buf
->width0
- (NINE_MAX_CONST_I
* 4 + NINE_MAX_CONST_B
) * 4;
185 box
.x
+= x
* 4 * sizeof(int);
186 box
.width
= c
* 4 * sizeof(int);
187 pipe
->transfer_inline_write(pipe
, buf
, 0, usage
, &box
, data
, 0, 0);
190 /* TODO: only upload these when shader itself changes */
191 if (lconstf_ranges
) {
193 struct nine_range
*r
= lconstf_ranges
;
195 box
.x
= r
->bgn
* 4 * sizeof(float);
196 n
+= r
->end
- r
->bgn
;
197 box
.width
= (r
->end
- r
->bgn
) * 4 * sizeof(float);
198 data
= &lconstf_data
[4 * n
];
199 pipe
->transfer_inline_write(pipe
, buf
, 0, usage
, &box
, data
, 0, 0);
206 prepare_vs_constants_userbuf(struct NineDevice9
*device
)
208 struct nine_state
*state
= &device
->state
;
209 struct pipe_constant_buffer cb
;
211 cb
.buffer_offset
= 0;
212 cb
.buffer_size
= device
->state
.vs
->const_used_size
;
213 cb
.user_buffer
= device
->state
.vs_const_f
;
218 if (state
->changed
.vs_const_i
) {
219 int *idst
= (int *)&state
->vs_const_f
[4 * device
->max_vs_const_f
];
220 memcpy(idst
, state
->vs_const_i
, sizeof(state
->vs_const_i
));
221 state
->changed
.vs_const_i
= 0;
223 if (state
->changed
.vs_const_b
) {
224 int *idst
= (int *)&state
->vs_const_f
[4 * device
->max_vs_const_f
];
225 uint32_t *bdst
= (uint32_t *)&idst
[4 * NINE_MAX_CONST_I
];
226 memcpy(bdst
, state
->vs_const_b
, sizeof(state
->vs_const_b
));
227 state
->changed
.vs_const_b
= 0;
230 if (device
->state
.vs
->lconstf
.ranges
) {
231 /* TODO: Can we make it so that we don't have to copy everything ? */
232 const struct nine_lconstf
*lconstf
= &device
->state
.vs
->lconstf
;
233 const struct nine_range
*r
= lconstf
->ranges
;
235 float *dst
= device
->state
.vs_lconstf_temp
;
236 float *src
= (float *)cb
.user_buffer
;
237 memcpy(dst
, src
, cb
.buffer_size
);
240 unsigned c
= r
->end
- r
->bgn
;
241 memcpy(&dst
[p
* 4], &lconstf
->data
[n
* 4], c
* 4 * sizeof(float));
245 cb
.user_buffer
= dst
;
248 if (!device
->driver_caps
.user_cbufs
) {
249 u_upload_data(device
->constbuf_uploader
,
255 u_upload_unmap(device
->constbuf_uploader
);
256 cb
.user_buffer
= NULL
;
259 state
->pipe
.cb_vs
= cb
;
261 if (device
->state
.changed
.vs_const_f
) {
262 struct nine_range
*r
= device
->state
.changed
.vs_const_f
;
263 struct nine_range
*p
= r
;
266 nine_range_pool_put_chain(&device
->range_pool
, r
, p
);
267 device
->state
.changed
.vs_const_f
= NULL
;
269 state
->changed
.group
&= ~NINE_STATE_VS_CONST
;
270 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
274 prepare_ps_constants_userbuf(struct NineDevice9
*device
)
276 struct nine_state
*state
= &device
->state
;
277 struct pipe_constant_buffer cb
;
279 cb
.buffer_offset
= 0;
280 cb
.buffer_size
= device
->state
.ps
->const_used_size
;
281 cb
.user_buffer
= device
->state
.ps_const_f
;
286 if (state
->changed
.ps_const_i
) {
287 int *idst
= (int *)&state
->ps_const_f
[4 * device
->max_ps_const_f
];
288 memcpy(idst
, state
->ps_const_i
, sizeof(state
->ps_const_i
));
289 state
->changed
.ps_const_i
= 0;
291 if (state
->changed
.ps_const_b
) {
292 int *idst
= (int *)&state
->ps_const_f
[4 * device
->max_ps_const_f
];
293 uint32_t *bdst
= (uint32_t *)&idst
[4 * NINE_MAX_CONST_I
];
294 memcpy(bdst
, state
->ps_const_b
, sizeof(state
->ps_const_b
));
295 state
->changed
.ps_const_b
= 0;
298 /* Upload special constants needed to implement PS1.x instructions like TEXBEM,TEXBEML and BEM */
299 if (device
->state
.ps
->bumpenvmat_needed
) {
300 memcpy(device
->state
.ps_lconstf_temp
, cb
.user_buffer
, cb
.buffer_size
);
301 memcpy(&device
->state
.ps_lconstf_temp
[4 * 8], &device
->state
.bumpmap_vars
, sizeof(device
->state
.bumpmap_vars
));
303 cb
.user_buffer
= device
->state
.ps_lconstf_temp
;
306 if (!device
->driver_caps
.user_cbufs
) {
307 u_upload_data(device
->constbuf_uploader
,
313 u_upload_unmap(device
->constbuf_uploader
);
314 cb
.user_buffer
= NULL
;
317 state
->pipe
.cb_ps
= cb
;
319 if (device
->state
.changed
.ps_const_f
) {
320 struct nine_range
*r
= device
->state
.changed
.ps_const_f
;
321 struct nine_range
*p
= r
;
324 nine_range_pool_put_chain(&device
->range_pool
, r
, p
);
325 device
->state
.changed
.ps_const_f
= NULL
;
327 state
->changed
.group
&= ~NINE_STATE_PS_CONST
;
328 state
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
331 static inline uint32_t
332 prepare_vs(struct NineDevice9
*device
, uint8_t shader_changed
)
334 struct nine_state
*state
= &device
->state
;
335 struct NineVertexShader9
*vs
= state
->vs
;
336 uint32_t changed_group
= 0;
337 int has_key_changed
= 0;
340 has_key_changed
= NineVertexShader9_UpdateKey(vs
, state
);
342 if (!shader_changed
&& !has_key_changed
)
345 /* likely because we dislike FF */
347 state
->cso
.vs
= NineVertexShader9_GetVariant(vs
);
350 state
->cso
.vs
= vs
->ff_cso
;
353 if (state
->rs
[NINED3DRS_VSPOINTSIZE
] != vs
->point_size
) {
354 state
->rs
[NINED3DRS_VSPOINTSIZE
] = vs
->point_size
;
355 changed_group
|= NINE_STATE_RASTERIZER
;
358 if ((state
->bound_samplers_mask_vs
& vs
->sampler_mask
) != vs
->sampler_mask
)
359 /* Bound dummy sampler. */
360 changed_group
|= NINE_STATE_SAMPLER
;
362 state
->commit
|= NINE_STATE_COMMIT_VS
;
363 return changed_group
;
366 static inline uint32_t
367 prepare_ps(struct NineDevice9
*device
, uint8_t shader_changed
)
369 struct nine_state
*state
= &device
->state
;
370 struct NinePixelShader9
*ps
= state
->ps
;
371 uint32_t changed_group
= 0;
372 int has_key_changed
= 0;
375 has_key_changed
= NinePixelShader9_UpdateKey(ps
, state
);
377 if (!shader_changed
&& !has_key_changed
)
381 state
->cso
.ps
= NinePixelShader9_GetVariant(ps
);
384 state
->cso
.ps
= ps
->ff_cso
;
387 if ((state
->bound_samplers_mask_ps
& ps
->sampler_mask
) != ps
->sampler_mask
)
388 /* Bound dummy sampler. */
389 changed_group
|= NINE_STATE_SAMPLER
;
391 state
->commit
|= NINE_STATE_COMMIT_PS
;
392 return changed_group
;
395 /* State preparation incremental */
397 /* State preparation + State commit */
400 update_framebuffer(struct NineDevice9
*device
)
402 struct pipe_context
*pipe
= device
->pipe
;
403 struct nine_state
*state
= &device
->state
;
404 struct pipe_framebuffer_state
*fb
= &device
->state
.fb
;
406 struct NineSurface9
*rt0
= state
->rt
[0];
407 unsigned w
= rt0
->desc
.Width
;
408 unsigned h
= rt0
->desc
.Height
;
409 D3DMULTISAMPLE_TYPE nr_samples
= rt0
->desc
.MultiSampleType
;
410 unsigned mask
= state
->ps
? state
->ps
->rt_mask
: 1;
411 const int sRGB
= state
->rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
415 state
->rt_mask
= 0x0;
418 /* all render targets must have the same size and the depth buffer must be
419 * bigger. Multisample has to match, according to spec. But some apps do
420 * things wrong there, and no error is returned. The behaviour they get
421 * apparently is that depth buffer is disabled if it doesn't match.
422 * Surely the same for render targets. */
424 /* Special case: D3DFMT_NULL is used to bound no real render target,
425 * but render to depth buffer. We have to not take into account the render
426 * target info. TODO: know what should happen when there are several render targers
427 * and the first one is D3DFMT_NULL */
428 if (rt0
->desc
.Format
== D3DFMT_NULL
&& state
->ds
) {
429 w
= state
->ds
->desc
.Width
;
430 h
= state
->ds
->desc
.Height
;
431 nr_samples
= state
->ds
->desc
.MultiSampleType
;
434 for (i
= 0; i
< device
->caps
.NumSimultaneousRTs
; ++i
) {
435 struct NineSurface9
*rt
= state
->rt
[i
];
437 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (mask
& (1 << i
)) &&
438 rt
->desc
.Width
== w
&& rt
->desc
.Height
== h
&&
439 rt
->desc
.MultiSampleType
== nr_samples
) {
440 fb
->cbufs
[i
] = NineSurface9_GetSurface(rt
, sRGB
);
441 state
->rt_mask
|= 1 << i
;
442 fb
->nr_cbufs
= i
+ 1;
444 if (unlikely(rt
->desc
.Usage
& D3DUSAGE_AUTOGENMIPMAP
)) {
445 assert(rt
->texture
== D3DRTYPE_TEXTURE
||
446 rt
->texture
== D3DRTYPE_CUBETEXTURE
);
447 NineBaseTexture9(rt
->base
.base
.container
)->dirty_mip
= TRUE
;
450 /* Color outputs must match RT slot,
451 * drivers will have to handle NULL entries for GL, too.
457 if (state
->ds
&& state
->ds
->desc
.Width
>= w
&&
458 state
->ds
->desc
.Height
>= h
&&
459 state
->ds
->desc
.MultiSampleType
== nr_samples
) {
460 fb
->zsbuf
= NineSurface9_GetSurface(state
->ds
, 0);
468 pipe
->set_framebuffer_state(pipe
, fb
); /* XXX: cso ? */
472 switch (fb
->zsbuf
->format
) {
473 case PIPE_FORMAT_Z32_FLOAT
:
474 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
477 case PIPE_FORMAT_Z16_UNORM
:
478 scale
= fui((float)(1 << 16));
481 scale
= fui((float)(1 << 24));
484 if (state
->rs
[NINED3DRS_ZBIASSCALE
] != scale
) {
485 state
->rs
[NINED3DRS_ZBIASSCALE
] = scale
;
486 state
->changed
.group
|= NINE_STATE_RASTERIZER
;
490 return state
->changed
.group
;
494 update_viewport(struct NineDevice9
*device
)
496 struct pipe_context
*pipe
= device
->pipe
;
497 const D3DVIEWPORT9
*vport
= &device
->state
.viewport
;
498 struct pipe_viewport_state pvport
;
500 /* D3D coordinates are:
501 * -1 .. +1 for X,Y and
502 * 0 .. +1 for Z (we use pipe_rasterizer_state.clip_halfz)
504 pvport
.scale
[0] = (float)vport
->Width
* 0.5f
;
505 pvport
.scale
[1] = (float)vport
->Height
* -0.5f
;
506 pvport
.scale
[2] = vport
->MaxZ
- vport
->MinZ
;
507 pvport
.translate
[0] = (float)vport
->Width
* 0.5f
+ (float)vport
->X
;
508 pvport
.translate
[1] = (float)vport
->Height
* 0.5f
+ (float)vport
->Y
;
509 pvport
.translate
[2] = vport
->MinZ
;
511 /* We found R600 and SI cards have some imprecision
512 * on the barycentric coordinates used for interpolation.
513 * Some shaders rely on having something precise.
514 * We found that the proprietary driver has the imprecision issue,
515 * except when the render target width and height are powers of two.
516 * It is using some sort of workaround for these cases
517 * which covers likely all the cases the applications rely
518 * on something precise.
519 * We haven't found the workaround, but it seems like it's better
520 * for applications if the imprecision is biased towards infinity
521 * instead of -infinity (which is what measured). So shift slightly
522 * the viewport: not enough to change rasterization result (in particular
523 * for multisampling), but enough to make the imprecision biased
524 * towards infinity. We do this shift only if render target width and
525 * height are powers of two.
526 * Solves 'red shadows' bug on UE3 games.
528 if (device
->driver_bugs
.buggy_barycentrics
&&
529 ((vport
->Width
& (vport
->Width
-1)) == 0) &&
530 ((vport
->Height
& (vport
->Height
-1)) == 0)) {
531 pvport
.translate
[0] -= 1.0f
/ 128.0f
;
532 pvport
.translate
[1] -= 1.0f
/ 128.0f
;
535 pipe
->set_viewport_states(pipe
, 0, 1, &pvport
);
538 /* Loop through VS inputs and pick the vertex elements with the declared
539 * usage from the vertex declaration, then insert the instance divisor from
540 * the stream source frequency setting.
543 update_vertex_elements(struct NineDevice9
*device
)
545 struct nine_state
*state
= &device
->state
;
546 const struct NineVertexDeclaration9
*vdecl
= device
->state
.vdecl
;
547 const struct NineVertexShader9
*vs
;
550 char vdecl_index_map
[16]; /* vs->num_inputs <= 16 */
551 char used_streams
[device
->caps
.MaxStreams
];
552 int dummy_vbo_stream
= -1;
553 BOOL need_dummy_vbo
= FALSE
;
554 struct pipe_vertex_element ve
[PIPE_MAX_ATTRIBS
];
556 state
->stream_usage_mask
= 0;
557 memset(vdecl_index_map
, -1, 16);
558 memset(used_streams
, 0, device
->caps
.MaxStreams
);
559 vs
= device
->state
.vs
? device
->state
.vs
: device
->ff
.vs
;
562 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
563 DBG("looking up input %u (usage %u) from vdecl(%p)\n",
564 n
, vs
->input_map
[n
].ndecl
, vdecl
);
566 for (i
= 0; i
< vdecl
->nelems
; i
++) {
567 if (vdecl
->usage_map
[i
] == vs
->input_map
[n
].ndecl
) {
568 vdecl_index_map
[n
] = i
;
569 used_streams
[vdecl
->elems
[i
].vertex_buffer_index
] = 1;
573 if (vdecl_index_map
[n
] < 0)
574 need_dummy_vbo
= TRUE
;
577 /* No vertex declaration. Likely will never happen in practice,
578 * but we need not crash on this */
579 need_dummy_vbo
= TRUE
;
582 if (need_dummy_vbo
) {
583 for (i
= 0; i
< device
->caps
.MaxStreams
; i
++ ) {
584 if (!used_streams
[i
]) {
585 dummy_vbo_stream
= i
;
590 /* there are less vertex shader inputs than stream slots,
591 * so if we need a slot for the dummy vbo, we should have found one */
592 assert (!need_dummy_vbo
|| dummy_vbo_stream
!= -1);
594 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
595 index
= vdecl_index_map
[n
];
597 ve
[n
] = vdecl
->elems
[index
];
598 b
= ve
[n
].vertex_buffer_index
;
599 state
->stream_usage_mask
|= 1 << b
;
600 /* XXX wine just uses 1 here: */
601 if (state
->stream_freq
[b
] & D3DSTREAMSOURCE_INSTANCEDATA
)
602 ve
[n
].instance_divisor
= state
->stream_freq
[b
] & 0x7FFFFF;
604 /* if the vertex declaration is incomplete compared to what the
605 * vertex shader needs, we bind a dummy vbo with 0 0 0 0.
606 * This is not precised by the spec, but is the behaviour
608 ve
[n
].vertex_buffer_index
= dummy_vbo_stream
;
609 ve
[n
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
610 ve
[n
].src_offset
= 0;
611 ve
[n
].instance_divisor
= 0;
615 if (state
->dummy_vbo_bound_at
!= dummy_vbo_stream
) {
616 if (state
->dummy_vbo_bound_at
>= 0)
617 state
->changed
.vtxbuf
|= 1 << state
->dummy_vbo_bound_at
;
618 if (dummy_vbo_stream
>= 0) {
619 state
->changed
.vtxbuf
|= 1 << dummy_vbo_stream
;
620 state
->vbo_bound_done
= FALSE
;
622 state
->dummy_vbo_bound_at
= dummy_vbo_stream
;
625 cso_set_vertex_elements(device
->cso
, vs
->num_inputs
, ve
);
627 state
->changed
.stream_freq
= 0;
631 update_vertex_buffers(struct NineDevice9
*device
)
633 struct pipe_context
*pipe
= device
->pipe
;
634 struct nine_state
*state
= &device
->state
;
635 struct pipe_vertex_buffer dummy_vtxbuf
;
636 uint32_t mask
= state
->changed
.vtxbuf
;
640 DBG("mask=%x\n", mask
);
642 if (state
->dummy_vbo_bound_at
>= 0) {
643 if (!state
->vbo_bound_done
) {
644 dummy_vtxbuf
.buffer
= device
->dummy_vbo
;
645 dummy_vtxbuf
.stride
= 0;
646 dummy_vtxbuf
.user_buffer
= NULL
;
647 dummy_vtxbuf
.buffer_offset
= 0;
648 pipe
->set_vertex_buffers(pipe
, state
->dummy_vbo_bound_at
,
650 state
->vbo_bound_done
= TRUE
;
652 mask
&= ~(1 << state
->dummy_vbo_bound_at
);
655 for (i
= 0; mask
; mask
>>= 1, ++i
) {
657 if (state
->vtxbuf
[i
].buffer
)
658 pipe
->set_vertex_buffers(pipe
, i
, 1, &state
->vtxbuf
[i
]);
660 pipe
->set_vertex_buffers(pipe
, i
, 1, NULL
);
664 state
->changed
.vtxbuf
= 0;
667 static inline boolean
668 update_sampler_derived(struct nine_state
*state
, unsigned s
)
670 boolean changed
= FALSE
;
672 if (state
->samp
[s
][NINED3DSAMP_SHADOW
] != state
->texture
[s
]->shadow
) {
674 state
->samp
[s
][NINED3DSAMP_SHADOW
] = state
->texture
[s
]->shadow
;
677 if (state
->samp
[s
][D3DSAMP_MIPFILTER
] != D3DTEXF_NONE
) {
678 int lod
= state
->samp
[s
][D3DSAMP_MAXMIPLEVEL
] - state
->texture
[s
]->managed
.lod
;
681 if (state
->samp
[s
][NINED3DSAMP_MINLOD
] != lod
) {
683 state
->samp
[s
][NINED3DSAMP_MINLOD
] = lod
;
686 state
->changed
.sampler
[s
] &= ~0x300; /* lod changes irrelevant */
692 /* TODO: add sRGB override to pipe_sampler_state ? */
694 update_textures_and_samplers(struct NineDevice9
*device
)
696 struct pipe_context
*pipe
= device
->pipe
;
697 struct nine_state
*state
= &device
->state
;
698 struct pipe_sampler_view
*view
[NINE_MAX_SAMPLERS
];
699 struct pipe_sampler_state samp
;
700 unsigned num_textures
;
702 boolean commit_views
;
703 boolean commit_samplers
;
704 uint16_t sampler_mask
= state
->ps
? state
->ps
->sampler_mask
:
705 device
->ff
.ps
->sampler_mask
;
707 /* TODO: Can we reduce iterations here ? */
709 commit_views
= FALSE
;
710 commit_samplers
= FALSE
;
711 state
->bound_samplers_mask_ps
= 0;
712 for (num_textures
= 0, i
= 0; i
< NINE_MAX_SAMPLERS_PS
; ++i
) {
713 const unsigned s
= NINE_SAMPLER_PS(i
);
716 if (!state
->texture
[s
] && !(sampler_mask
& (1 << i
))) {
721 if (state
->texture
[s
]) {
722 sRGB
= state
->samp
[s
][D3DSAMP_SRGBTEXTURE
] ? 1 : 0;
724 view
[i
] = NineBaseTexture9_GetSamplerView(state
->texture
[s
], sRGB
);
725 num_textures
= i
+ 1;
727 if (update_sampler_derived(state
, s
) || (state
->changed
.sampler
[s
] & 0x05fe)) {
728 state
->changed
.sampler
[s
] = 0;
729 commit_samplers
= TRUE
;
730 nine_convert_sampler_state(device
->cso
, s
, state
->samp
[s
]);
733 /* Bind dummy sampler. We do not bind dummy sampler when
734 * it is not needed because it could add overhead. The
735 * dummy sampler should have r=g=b=0 and a=1. We do not
736 * unbind dummy sampler directly when they are not needed
737 * anymore, but they're going to be removed as long as texture
738 * or sampler states are changed. */
739 view
[i
] = device
->dummy_sampler
;
740 num_textures
= i
+ 1;
742 memset(&samp
, 0, sizeof(samp
));
743 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
744 samp
.max_lod
= 15.0f
;
745 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
746 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
747 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
748 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
749 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
750 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
751 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
752 samp
.normalized_coords
= 1;
753 samp
.seamless_cube_map
= 1;
755 cso_single_sampler(device
->cso
, PIPE_SHADER_FRAGMENT
,
756 s
- NINE_SAMPLER_PS(0), &samp
);
759 commit_samplers
= TRUE
;
760 state
->changed
.sampler
[s
] = ~0;
763 state
->bound_samplers_mask_ps
|= (1 << s
);
766 commit_views
|= (state
->changed
.texture
& NINE_PS_SAMPLERS_MASK
) != 0;
767 commit_views
|= state
->changed
.srgb
;
769 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0,
773 cso_single_sampler_done(device
->cso
, PIPE_SHADER_FRAGMENT
);
775 commit_views
= FALSE
;
776 commit_samplers
= FALSE
;
777 sampler_mask
= state
->vs
? state
->vs
->sampler_mask
: 0;
778 state
->bound_samplers_mask_vs
= 0;
779 for (num_textures
= 0, i
= 0; i
< NINE_MAX_SAMPLERS_VS
; ++i
) {
780 const unsigned s
= NINE_SAMPLER_VS(i
);
783 if (!state
->texture
[s
] && !(sampler_mask
& (1 << i
))) {
788 if (state
->texture
[s
]) {
789 sRGB
= state
->samp
[s
][D3DSAMP_SRGBTEXTURE
] ? 1 : 0;
791 view
[i
] = NineBaseTexture9_GetSamplerView(state
->texture
[s
], sRGB
);
792 num_textures
= i
+ 1;
794 if (update_sampler_derived(state
, s
) || (state
->changed
.sampler
[s
] & 0x05fe)) {
795 state
->changed
.sampler
[s
] = 0;
796 commit_samplers
= TRUE
;
797 nine_convert_sampler_state(device
->cso
, s
, state
->samp
[s
]);
800 /* Bind dummy sampler. We do not bind dummy sampler when
801 * it is not needed because it could add overhead. The
802 * dummy sampler should have r=g=b=0 and a=1. We do not
803 * unbind dummy sampler directly when they are not needed
804 * anymore, but they're going to be removed as long as texture
805 * or sampler states are changed. */
806 view
[i
] = device
->dummy_sampler
;
807 num_textures
= i
+ 1;
809 memset(&samp
, 0, sizeof(samp
));
810 samp
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
811 samp
.max_lod
= 15.0f
;
812 samp
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
813 samp
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
814 samp
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
815 samp
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
816 samp
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
817 samp
.compare_mode
= PIPE_TEX_COMPARE_NONE
;
818 samp
.compare_func
= PIPE_FUNC_LEQUAL
;
819 samp
.normalized_coords
= 1;
820 samp
.seamless_cube_map
= 1;
822 cso_single_sampler(device
->cso
, PIPE_SHADER_VERTEX
,
823 s
- NINE_SAMPLER_VS(0), &samp
);
826 commit_samplers
= TRUE
;
827 state
->changed
.sampler
[s
] = ~0;
830 state
->bound_samplers_mask_vs
|= (1 << s
);
832 commit_views
|= (state
->changed
.texture
& NINE_VS_SAMPLERS_MASK
) != 0;
833 commit_views
|= state
->changed
.srgb
;
835 pipe
->set_sampler_views(pipe
, PIPE_SHADER_VERTEX
, 0,
839 cso_single_sampler_done(device
->cso
, PIPE_SHADER_VERTEX
);
841 state
->changed
.srgb
= FALSE
;
842 state
->changed
.texture
= 0;
845 /* State commit only */
848 commit_blend(struct NineDevice9
*device
)
850 cso_set_blend(device
->cso
, &device
->state
.pipe
.blend
);
854 commit_dsa(struct NineDevice9
*device
)
856 cso_set_depth_stencil_alpha(device
->cso
, &device
->state
.pipe
.dsa
);
860 commit_scissor(struct NineDevice9
*device
)
862 struct pipe_context
*pipe
= device
->pipe
;
864 pipe
->set_scissor_states(pipe
, 0, 1, &device
->state
.scissor
);
868 commit_rasterizer(struct NineDevice9
*device
)
870 cso_set_rasterizer(device
->cso
, &device
->state
.pipe
.rast
);
874 commit_index_buffer(struct NineDevice9
*device
)
876 struct pipe_context
*pipe
= device
->pipe
;
877 if (device
->state
.idxbuf
)
878 pipe
->set_index_buffer(pipe
, &device
->state
.idxbuf
->buffer
);
880 pipe
->set_index_buffer(pipe
, NULL
);
884 commit_vs_constants(struct NineDevice9
*device
)
886 struct pipe_context
*pipe
= device
->pipe
;
888 if (unlikely(!device
->state
.vs
))
889 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &device
->state
.pipe
.cb_vs_ff
);
891 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &device
->state
.pipe
.cb_vs
);
895 commit_ps_constants(struct NineDevice9
*device
)
897 struct pipe_context
*pipe
= device
->pipe
;
899 if (unlikely(!device
->state
.ps
))
900 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &device
->state
.pipe
.cb_ps_ff
);
902 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &device
->state
.pipe
.cb_ps
);
906 commit_vs(struct NineDevice9
*device
)
908 struct nine_state
*state
= &device
->state
;
910 device
->pipe
->bind_vs_state(device
->pipe
, state
->cso
.vs
);
915 commit_ps(struct NineDevice9
*device
)
917 struct nine_state
*state
= &device
->state
;
919 device
->pipe
->bind_fs_state(device
->pipe
, state
->cso
.ps
);
923 #define NINE_STATE_FREQ_GROUP_0 \
925 NINE_STATE_VIEWPORT | \
926 NINE_STATE_SCISSOR | \
929 NINE_STATE_RASTERIZER | \
932 NINE_STATE_BLEND_COLOR | \
933 NINE_STATE_STENCIL_REF | \
934 NINE_STATE_SAMPLE_MASK)
936 #define NINE_STATE_FREQ_GROUP_1 ~NINE_STATE_FREQ_GROUP_0
938 /* TODO: only go through dirty textures */
940 validate_textures(struct NineDevice9
*device
)
942 struct NineBaseTexture9
*tex
, *ptr
;
943 LIST_FOR_EACH_ENTRY_SAFE(tex
, ptr
, &device
->update_textures
, list
) {
944 list_delinit(&tex
->list
);
945 NineBaseTexture9_Validate(tex
);
950 nine_update_state_framebuffer(struct NineDevice9
*device
)
952 struct nine_state
*state
= &device
->state
;
954 validate_textures(device
);
956 if (state
->changed
.group
& NINE_STATE_FB
)
957 update_framebuffer(device
);
959 state
->changed
.group
&= ~NINE_STATE_FB
;
963 nine_update_state(struct NineDevice9
*device
)
965 struct pipe_context
*pipe
= device
->pipe
;
966 struct nine_state
*state
= &device
->state
;
969 DBG("changed state groups: %x | %x\n",
970 state
->changed
.group
& NINE_STATE_FREQ_GROUP_0
,
971 state
->changed
.group
& NINE_STATE_FREQ_GROUP_1
);
973 /* NOTE: We may want to use the cso cache for everything, or let
974 * NineDevice9.RestoreNonCSOState actually set the states, then we wouldn't
975 * have to care about state being clobbered here and could merge this back
976 * into update_textures. Except, we also need to re-validate textures that
977 * may be dirty anyway, even if no texture bindings changed.
979 validate_textures(device
); /* may clobber state */
981 /* ff_update may change VS/PS dirty bits */
982 if (unlikely(!state
->vs
|| !state
->ps
))
983 nine_ff_update(device
);
984 group
= state
->changed
.group
;
986 if (group
& (NINE_STATE_FREQ_GROUP_0
| NINE_STATE_TEXTURE
)) {
987 if (group
& NINE_STATE_FB
)
988 group
= update_framebuffer(device
);
989 if (group
& NINE_STATE_VIEWPORT
)
990 update_viewport(device
);
991 if (group
& NINE_STATE_SCISSOR
)
992 commit_scissor(device
);
994 if (group
& NINE_STATE_DSA
)
996 if (group
& NINE_STATE_BLEND
)
997 prepare_blend(device
);
999 if (group
& (NINE_STATE_VS
| NINE_STATE_TEXTURE
))
1000 group
|= prepare_vs(device
, (group
& NINE_STATE_VS
) != 0);
1002 if (group
& NINE_STATE_RASTERIZER
)
1003 prepare_rasterizer(device
);
1005 if (group
& (NINE_STATE_PS
| NINE_STATE_TEXTURE
))
1006 group
|= prepare_ps(device
, (group
& NINE_STATE_PS
) != 0);
1008 if (group
& NINE_STATE_BLEND_COLOR
) {
1009 struct pipe_blend_color color
;
1010 d3dcolor_to_rgba(&color
.color
[0], state
->rs
[D3DRS_BLENDFACTOR
]);
1011 pipe
->set_blend_color(pipe
, &color
);
1013 if (group
& NINE_STATE_SAMPLE_MASK
) {
1014 pipe
->set_sample_mask(pipe
, state
->rs
[D3DRS_MULTISAMPLEMASK
]);
1016 if (group
& NINE_STATE_STENCIL_REF
) {
1017 struct pipe_stencil_ref ref
;
1018 ref
.ref_value
[0] = state
->rs
[D3DRS_STENCILREF
];
1019 ref
.ref_value
[1] = ref
.ref_value
[0];
1020 pipe
->set_stencil_ref(pipe
, &ref
);
1024 if (state
->changed
.ucp
) {
1025 pipe
->set_clip_state(pipe
, &state
->clip
);
1026 state
->changed
.ucp
= 0;
1029 if (group
& (NINE_STATE_FREQ_GROUP_1
| NINE_STATE_VS
)) {
1030 if (group
& (NINE_STATE_TEXTURE
| NINE_STATE_SAMPLER
))
1031 update_textures_and_samplers(device
);
1033 if (group
& NINE_STATE_IDXBUF
)
1034 commit_index_buffer(device
);
1036 if ((group
& (NINE_STATE_VDECL
| NINE_STATE_VS
)) ||
1037 state
->changed
.stream_freq
& ~1)
1038 update_vertex_elements(device
);
1040 if (device
->prefer_user_constbuf
) {
1041 if ((group
& (NINE_STATE_VS_CONST
| NINE_STATE_VS
)) && state
->vs
)
1042 prepare_vs_constants_userbuf(device
);
1043 if ((group
& (NINE_STATE_PS_CONST
| NINE_STATE_PS
)) && state
->ps
)
1044 prepare_ps_constants_userbuf(device
);
1046 if ((group
& NINE_STATE_VS_CONST
) && state
->vs
)
1047 upload_constants(device
, PIPE_SHADER_VERTEX
);
1048 if ((group
& NINE_STATE_PS_CONST
) && state
->ps
)
1049 upload_constants(device
, PIPE_SHADER_FRAGMENT
);
1052 if (state
->changed
.vtxbuf
)
1053 update_vertex_buffers(device
);
1055 if (state
->commit
& NINE_STATE_COMMIT_BLEND
)
1056 commit_blend(device
);
1057 if (state
->commit
& NINE_STATE_COMMIT_DSA
)
1059 if (state
->commit
& NINE_STATE_COMMIT_RASTERIZER
)
1060 commit_rasterizer(device
);
1061 if (state
->commit
& NINE_STATE_COMMIT_CONST_VS
)
1062 commit_vs_constants(device
);
1063 if (state
->commit
& NINE_STATE_COMMIT_CONST_PS
)
1064 commit_ps_constants(device
);
1065 if (state
->commit
& NINE_STATE_COMMIT_VS
)
1067 if (state
->commit
& NINE_STATE_COMMIT_PS
)
1072 device
->state
.changed
.group
&=
1073 (NINE_STATE_FF
| NINE_STATE_VS_CONST
| NINE_STATE_PS_CONST
);
1080 /* State defaults */
1082 static const DWORD nine_render_state_defaults
[NINED3DRS_LAST
+ 1] =
1084 /* [D3DRS_ZENABLE] = D3DZB_TRUE; wine: auto_depth_stencil */
1085 [D3DRS_ZENABLE
] = D3DZB_FALSE
,
1086 [D3DRS_FILLMODE
] = D3DFILL_SOLID
,
1087 [D3DRS_SHADEMODE
] = D3DSHADE_GOURAUD
,
1088 /* [D3DRS_LINEPATTERN] = 0x00000000, */
1089 [D3DRS_ZWRITEENABLE
] = TRUE
,
1090 [D3DRS_ALPHATESTENABLE
] = FALSE
,
1091 [D3DRS_LASTPIXEL
] = TRUE
,
1092 [D3DRS_SRCBLEND
] = D3DBLEND_ONE
,
1093 [D3DRS_DESTBLEND
] = D3DBLEND_ZERO
,
1094 [D3DRS_CULLMODE
] = D3DCULL_CCW
,
1095 [D3DRS_ZFUNC
] = D3DCMP_LESSEQUAL
,
1096 [D3DRS_ALPHAFUNC
] = D3DCMP_ALWAYS
,
1097 [D3DRS_ALPHAREF
] = 0,
1098 [D3DRS_DITHERENABLE
] = FALSE
,
1099 [D3DRS_ALPHABLENDENABLE
] = FALSE
,
1100 [D3DRS_FOGENABLE
] = FALSE
,
1101 [D3DRS_SPECULARENABLE
] = FALSE
,
1102 /* [D3DRS_ZVISIBLE] = 0, */
1103 [D3DRS_FOGCOLOR
] = 0,
1104 [D3DRS_FOGTABLEMODE
] = D3DFOG_NONE
,
1105 [D3DRS_FOGSTART
] = 0x00000000,
1106 [D3DRS_FOGEND
] = 0x3F800000,
1107 [D3DRS_FOGDENSITY
] = 0x3F800000,
1108 /* [D3DRS_EDGEANTIALIAS] = FALSE, */
1109 [D3DRS_RANGEFOGENABLE
] = FALSE
,
1110 [D3DRS_STENCILENABLE
] = FALSE
,
1111 [D3DRS_STENCILFAIL
] = D3DSTENCILOP_KEEP
,
1112 [D3DRS_STENCILZFAIL
] = D3DSTENCILOP_KEEP
,
1113 [D3DRS_STENCILPASS
] = D3DSTENCILOP_KEEP
,
1114 [D3DRS_STENCILREF
] = 0,
1115 [D3DRS_STENCILMASK
] = 0xFFFFFFFF,
1116 [D3DRS_STENCILFUNC
] = D3DCMP_ALWAYS
,
1117 [D3DRS_STENCILWRITEMASK
] = 0xFFFFFFFF,
1118 [D3DRS_TEXTUREFACTOR
] = 0xFFFFFFFF,
1127 [D3DRS_CLIPPING
] = TRUE
,
1128 [D3DRS_LIGHTING
] = TRUE
,
1129 [D3DRS_AMBIENT
] = 0,
1130 [D3DRS_FOGVERTEXMODE
] = D3DFOG_NONE
,
1131 [D3DRS_COLORVERTEX
] = TRUE
,
1132 [D3DRS_LOCALVIEWER
] = TRUE
,
1133 [D3DRS_NORMALIZENORMALS
] = FALSE
,
1134 [D3DRS_DIFFUSEMATERIALSOURCE
] = D3DMCS_COLOR1
,
1135 [D3DRS_SPECULARMATERIALSOURCE
] = D3DMCS_COLOR2
,
1136 [D3DRS_AMBIENTMATERIALSOURCE
] = D3DMCS_MATERIAL
,
1137 [D3DRS_EMISSIVEMATERIALSOURCE
] = D3DMCS_MATERIAL
,
1138 [D3DRS_VERTEXBLEND
] = D3DVBF_DISABLE
,
1139 [D3DRS_CLIPPLANEENABLE
] = 0,
1140 /* [D3DRS_SOFTWAREVERTEXPROCESSING] = FALSE, */
1141 [D3DRS_POINTSIZE
] = 0x3F800000,
1142 [D3DRS_POINTSIZE_MIN
] = 0x3F800000,
1143 [D3DRS_POINTSPRITEENABLE
] = FALSE
,
1144 [D3DRS_POINTSCALEENABLE
] = FALSE
,
1145 [D3DRS_POINTSCALE_A
] = 0x3F800000,
1146 [D3DRS_POINTSCALE_B
] = 0x00000000,
1147 [D3DRS_POINTSCALE_C
] = 0x00000000,
1148 [D3DRS_MULTISAMPLEANTIALIAS
] = TRUE
,
1149 [D3DRS_MULTISAMPLEMASK
] = 0xFFFFFFFF,
1150 [D3DRS_PATCHEDGESTYLE
] = D3DPATCHEDGE_DISCRETE
,
1151 /* [D3DRS_PATCHSEGMENTS] = 0x3F800000, */
1152 [D3DRS_DEBUGMONITORTOKEN
] = 0xDEADCAFE,
1153 [D3DRS_POINTSIZE_MAX
] = 0x3F800000, /* depends on cap */
1154 [D3DRS_INDEXEDVERTEXBLENDENABLE
] = FALSE
,
1155 [D3DRS_COLORWRITEENABLE
] = 0x0000000f,
1156 [D3DRS_TWEENFACTOR
] = 0x00000000,
1157 [D3DRS_BLENDOP
] = D3DBLENDOP_ADD
,
1158 [D3DRS_POSITIONDEGREE
] = D3DDEGREE_CUBIC
,
1159 [D3DRS_NORMALDEGREE
] = D3DDEGREE_LINEAR
,
1160 [D3DRS_SCISSORTESTENABLE
] = FALSE
,
1161 [D3DRS_SLOPESCALEDEPTHBIAS
] = 0,
1162 [D3DRS_MINTESSELLATIONLEVEL
] = 0x3F800000,
1163 [D3DRS_MAXTESSELLATIONLEVEL
] = 0x3F800000,
1164 [D3DRS_ANTIALIASEDLINEENABLE
] = FALSE
,
1165 [D3DRS_ADAPTIVETESS_X
] = 0x00000000,
1166 [D3DRS_ADAPTIVETESS_Y
] = 0x00000000,
1167 [D3DRS_ADAPTIVETESS_Z
] = 0x3F800000,
1168 [D3DRS_ADAPTIVETESS_W
] = 0x00000000,
1169 [D3DRS_ENABLEADAPTIVETESSELLATION
] = FALSE
,
1170 [D3DRS_TWOSIDEDSTENCILMODE
] = FALSE
,
1171 [D3DRS_CCW_STENCILFAIL
] = D3DSTENCILOP_KEEP
,
1172 [D3DRS_CCW_STENCILZFAIL
] = D3DSTENCILOP_KEEP
,
1173 [D3DRS_CCW_STENCILPASS
] = D3DSTENCILOP_KEEP
,
1174 [D3DRS_CCW_STENCILFUNC
] = D3DCMP_ALWAYS
,
1175 [D3DRS_COLORWRITEENABLE1
] = 0x0000000F,
1176 [D3DRS_COLORWRITEENABLE2
] = 0x0000000F,
1177 [D3DRS_COLORWRITEENABLE3
] = 0x0000000F,
1178 [D3DRS_BLENDFACTOR
] = 0xFFFFFFFF,
1179 [D3DRS_SRGBWRITEENABLE
] = 0,
1180 [D3DRS_DEPTHBIAS
] = 0,
1189 [D3DRS_SEPARATEALPHABLENDENABLE
] = FALSE
,
1190 [D3DRS_SRCBLENDALPHA
] = D3DBLEND_ONE
,
1191 [D3DRS_DESTBLENDALPHA
] = D3DBLEND_ZERO
,
1192 [D3DRS_BLENDOPALPHA
] = D3DBLENDOP_ADD
,
1193 [NINED3DRS_VSPOINTSIZE
] = FALSE
,
1194 [NINED3DRS_RTMASK
] = 0xf,
1195 [NINED3DRS_ALPHACOVERAGE
] = FALSE
1197 static const DWORD nine_tex_stage_state_defaults
[NINED3DTSS_LAST
+ 1] =
1199 [D3DTSS_COLOROP
] = D3DTOP_DISABLE
,
1200 [D3DTSS_ALPHAOP
] = D3DTOP_DISABLE
,
1201 [D3DTSS_COLORARG1
] = D3DTA_TEXTURE
,
1202 [D3DTSS_COLORARG2
] = D3DTA_CURRENT
,
1203 [D3DTSS_COLORARG0
] = D3DTA_CURRENT
,
1204 [D3DTSS_ALPHAARG1
] = D3DTA_TEXTURE
,
1205 [D3DTSS_ALPHAARG2
] = D3DTA_CURRENT
,
1206 [D3DTSS_ALPHAARG0
] = D3DTA_CURRENT
,
1207 [D3DTSS_RESULTARG
] = D3DTA_CURRENT
,
1208 [D3DTSS_BUMPENVMAT00
] = 0,
1209 [D3DTSS_BUMPENVMAT01
] = 0,
1210 [D3DTSS_BUMPENVMAT10
] = 0,
1211 [D3DTSS_BUMPENVMAT11
] = 0,
1212 [D3DTSS_BUMPENVLSCALE
] = 0,
1213 [D3DTSS_BUMPENVLOFFSET
] = 0,
1214 [D3DTSS_TEXCOORDINDEX
] = 0,
1215 [D3DTSS_TEXTURETRANSFORMFLAGS
] = D3DTTFF_DISABLE
,
1217 static const DWORD nine_samp_state_defaults
[NINED3DSAMP_LAST
+ 1] =
1219 [D3DSAMP_ADDRESSU
] = D3DTADDRESS_WRAP
,
1220 [D3DSAMP_ADDRESSV
] = D3DTADDRESS_WRAP
,
1221 [D3DSAMP_ADDRESSW
] = D3DTADDRESS_WRAP
,
1222 [D3DSAMP_BORDERCOLOR
] = 0,
1223 [D3DSAMP_MAGFILTER
] = D3DTEXF_POINT
,
1224 [D3DSAMP_MINFILTER
] = D3DTEXF_POINT
,
1225 [D3DSAMP_MIPFILTER
] = D3DTEXF_NONE
,
1226 [D3DSAMP_MIPMAPLODBIAS
] = 0,
1227 [D3DSAMP_MAXMIPLEVEL
] = 0,
1228 [D3DSAMP_MAXANISOTROPY
] = 1,
1229 [D3DSAMP_SRGBTEXTURE
] = 0,
1230 [D3DSAMP_ELEMENTINDEX
] = 0,
1231 [D3DSAMP_DMAPOFFSET
] = 0,
1232 [NINED3DSAMP_MINLOD
] = 0,
1233 [NINED3DSAMP_SHADOW
] = 0
1236 void nine_state_restore_non_cso(struct NineDevice9
*device
)
1238 struct nine_state
*state
= &device
->state
;
1240 state
->changed
.group
= NINE_STATE_ALL
;
1241 state
->changed
.vtxbuf
= (1ULL << device
->caps
.MaxStreams
) - 1;
1242 state
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
1243 state
->changed
.texture
= NINE_PS_SAMPLERS_MASK
| NINE_VS_SAMPLERS_MASK
;
1244 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
| NINE_STATE_COMMIT_CONST_PS
;
1248 nine_state_set_defaults(struct NineDevice9
*device
, const D3DCAPS9
*caps
,
1251 struct nine_state
*state
= &device
->state
;
1254 /* Initialize defaults.
1256 memcpy(state
->rs
, nine_render_state_defaults
, sizeof(state
->rs
));
1258 for (s
= 0; s
< Elements(state
->ff
.tex_stage
); ++s
) {
1259 memcpy(&state
->ff
.tex_stage
[s
], nine_tex_stage_state_defaults
,
1260 sizeof(state
->ff
.tex_stage
[s
]));
1261 state
->ff
.tex_stage
[s
][D3DTSS_TEXCOORDINDEX
] = s
;
1263 state
->ff
.tex_stage
[0][D3DTSS_COLOROP
] = D3DTOP_MODULATE
;
1264 state
->ff
.tex_stage
[0][D3DTSS_ALPHAOP
] = D3DTOP_SELECTARG1
;
1265 memset(&state
->bumpmap_vars
, 0, sizeof(state
->bumpmap_vars
));
1267 for (s
= 0; s
< Elements(state
->samp
); ++s
) {
1268 memcpy(&state
->samp
[s
], nine_samp_state_defaults
,
1269 sizeof(state
->samp
[s
]));
1272 if (state
->vs_const_f
)
1273 memset(state
->vs_const_f
, 0, device
->vs_const_size
);
1274 if (state
->ps_const_f
)
1275 memset(state
->ps_const_f
, 0, device
->ps_const_size
);
1277 /* Cap dependent initial state:
1279 state
->rs
[D3DRS_POINTSIZE_MAX
] = fui(caps
->MaxPointSize
);
1281 /* Set changed flags to initialize driver.
1283 state
->changed
.group
= NINE_STATE_ALL
;
1284 state
->changed
.vtxbuf
= (1ULL << device
->caps
.MaxStreams
) - 1;
1285 state
->changed
.ucp
= (1 << PIPE_MAX_CLIP_PLANES
) - 1;
1286 state
->changed
.texture
= NINE_PS_SAMPLERS_MASK
| NINE_VS_SAMPLERS_MASK
;
1288 state
->ff
.changed
.transform
[0] = ~0;
1289 state
->ff
.changed
.transform
[D3DTS_WORLD
/ 32] |= 1 << (D3DTS_WORLD
% 32);
1292 state
->viewport
.MinZ
= 0.0f
;
1293 state
->viewport
.MaxZ
= 1.0f
;
1296 for (s
= 0; s
< Elements(state
->changed
.sampler
); ++s
)
1297 state
->changed
.sampler
[s
] = ~0;
1300 state
->dummy_vbo_bound_at
= -1;
1301 state
->vbo_bound_done
= FALSE
;
1304 if (!device
->prefer_user_constbuf
) {
1305 /* fill cb_vs and cb_ps for the non user constbuf path */
1306 struct pipe_constant_buffer cb
;
1308 cb
.buffer_offset
= 0;
1309 cb
.buffer_size
= device
->vs_const_size
;
1310 cb
.buffer
= device
->constbuf_vs
;
1311 cb
.user_buffer
= NULL
;
1312 state
->pipe
.cb_vs
= cb
;
1314 cb
.buffer_size
= device
->ps_const_size
;
1315 cb
.buffer
= device
->constbuf_ps
;
1316 state
->pipe
.cb_ps
= cb
;
1318 state
->commit
|= NINE_STATE_COMMIT_CONST_VS
| NINE_STATE_COMMIT_CONST_PS
;
1323 nine_state_clear(struct nine_state
*state
, const boolean device
)
1327 for (i
= 0; i
< Elements(state
->rt
); ++i
)
1328 nine_bind(&state
->rt
[i
], NULL
);
1329 nine_bind(&state
->ds
, NULL
);
1330 nine_bind(&state
->vs
, NULL
);
1331 nine_bind(&state
->ps
, NULL
);
1332 nine_bind(&state
->vdecl
, NULL
);
1333 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; ++i
)
1334 nine_bind(&state
->stream
[i
], NULL
);
1335 nine_bind(&state
->idxbuf
, NULL
);
1336 for (i
= 0; i
< NINE_MAX_SAMPLERS
; ++i
) {
1338 state
->texture
[i
] &&
1339 --state
->texture
[i
]->bind_count
== 0)
1340 list_delinit(&state
->texture
[i
]->list
);
1341 nine_bind(&state
->texture
[i
], NULL
);
1346 static const DWORD nine_render_states_pixel[] =
1348 D3DRS_ALPHABLENDENABLE,
1351 D3DRS_ALPHATESTENABLE,
1352 D3DRS_ANTIALIASEDLINEENABLE,
1356 D3DRS_CCW_STENCILFAIL,
1357 D3DRS_CCW_STENCILPASS,
1358 D3DRS_CCW_STENCILZFAIL,
1359 D3DRS_COLORWRITEENABLE,
1360 D3DRS_COLORWRITEENABLE1,
1361 D3DRS_COLORWRITEENABLE2,
1362 D3DRS_COLORWRITEENABLE3,
1365 D3DRS_DESTBLENDALPHA,
1372 D3DRS_SCISSORTESTENABLE,
1373 D3DRS_SEPARATEALPHABLENDENABLE,
1375 D3DRS_SLOPESCALEDEPTHBIAS,
1377 D3DRS_SRCBLENDALPHA,
1378 D3DRS_SRGBWRITEENABLE,
1379 D3DRS_STENCILENABLE,
1385 D3DRS_STENCILWRITEMASK,
1387 D3DRS_TEXTUREFACTOR,
1388 D3DRS_TWOSIDEDSTENCILMODE,
1410 const uint32_t nine_render_states_pixel
[(NINED3DRS_LAST
+ 31) / 32] =
1412 0x0f99c380, 0x1ff00070, 0x00000000, 0x00000000,
1413 0x000000ff, 0xde01c900, 0x0003ffcf
1417 static const DWORD nine_render_states_vertex[] =
1419 D3DRS_ADAPTIVETESS_W,
1420 D3DRS_ADAPTIVETESS_X,
1421 D3DRS_ADAPTIVETESS_Y,
1422 D3DRS_ADAPTIVETESS_Z,
1424 D3DRS_AMBIENTMATERIALSOURCE,
1426 D3DRS_CLIPPLANEENABLE,
1429 D3DRS_DIFFUSEMATERIALSOURCE,
1430 D3DRS_EMISSIVEMATERIALSOURCE,
1431 D3DRS_ENABLEADAPTIVETESSELLATION,
1438 D3DRS_FOGVERTEXMODE,
1439 D3DRS_INDEXEDVERTEXBLENDENABLE,
1442 D3DRS_MAXTESSELLATIONLEVEL,
1443 D3DRS_MINTESSELLATIONLEVEL,
1444 D3DRS_MULTISAMPLEANTIALIAS,
1445 D3DRS_MULTISAMPLEMASK,
1447 D3DRS_NORMALIZENORMALS,
1448 D3DRS_PATCHEDGESTYLE,
1452 D3DRS_POINTSCALEENABLE,
1454 D3DRS_POINTSIZE_MAX,
1455 D3DRS_POINTSIZE_MIN,
1456 D3DRS_POINTSPRITEENABLE,
1457 D3DRS_POSITIONDEGREE,
1458 D3DRS_RANGEFOGENABLE,
1460 D3DRS_SPECULARENABLE,
1461 D3DRS_SPECULARMATERIALSOURCE,
1466 const uint32_t nine_render_states_vertex
[(NINED3DRS_LAST
+ 31) / 32] =
1468 0x30400200, 0x0001007c, 0x00000000, 0x00000000,
1469 0xfd9efb00, 0x01fc34cf, 0x00000000
1472 /* TODO: put in the right values */
1473 const uint32_t nine_render_state_group
[NINED3DRS_LAST
+ 1] =
1475 [D3DRS_ZENABLE
] = NINE_STATE_DSA
,
1476 [D3DRS_FILLMODE
] = NINE_STATE_RASTERIZER
,
1477 [D3DRS_SHADEMODE
] = NINE_STATE_RASTERIZER
,
1478 [D3DRS_ZWRITEENABLE
] = NINE_STATE_DSA
,
1479 [D3DRS_ALPHATESTENABLE
] = NINE_STATE_DSA
,
1480 [D3DRS_LASTPIXEL
] = NINE_STATE_RASTERIZER
,
1481 [D3DRS_SRCBLEND
] = NINE_STATE_BLEND
,
1482 [D3DRS_DESTBLEND
] = NINE_STATE_BLEND
,
1483 [D3DRS_CULLMODE
] = NINE_STATE_RASTERIZER
,
1484 [D3DRS_ZFUNC
] = NINE_STATE_DSA
,
1485 [D3DRS_ALPHAREF
] = NINE_STATE_DSA
,
1486 [D3DRS_ALPHAFUNC
] = NINE_STATE_DSA
,
1487 [D3DRS_DITHERENABLE
] = NINE_STATE_BLEND
,
1488 [D3DRS_ALPHABLENDENABLE
] = NINE_STATE_BLEND
,
1489 [D3DRS_FOGENABLE
] = NINE_STATE_FF_OTHER
,
1490 [D3DRS_SPECULARENABLE
] = NINE_STATE_FF_LIGHTING
,
1491 [D3DRS_FOGCOLOR
] = NINE_STATE_FF_OTHER
,
1492 [D3DRS_FOGTABLEMODE
] = NINE_STATE_FF_OTHER
,
1493 [D3DRS_FOGSTART
] = NINE_STATE_FF_OTHER
,
1494 [D3DRS_FOGEND
] = NINE_STATE_FF_OTHER
,
1495 [D3DRS_FOGDENSITY
] = NINE_STATE_FF_OTHER
,
1496 [D3DRS_RANGEFOGENABLE
] = NINE_STATE_FF_OTHER
,
1497 [D3DRS_STENCILENABLE
] = NINE_STATE_DSA
,
1498 [D3DRS_STENCILFAIL
] = NINE_STATE_DSA
,
1499 [D3DRS_STENCILZFAIL
] = NINE_STATE_DSA
,
1500 [D3DRS_STENCILPASS
] = NINE_STATE_DSA
,
1501 [D3DRS_STENCILFUNC
] = NINE_STATE_DSA
,
1502 [D3DRS_STENCILREF
] = NINE_STATE_STENCIL_REF
,
1503 [D3DRS_STENCILMASK
] = NINE_STATE_DSA
,
1504 [D3DRS_STENCILWRITEMASK
] = NINE_STATE_DSA
,
1505 [D3DRS_TEXTUREFACTOR
] = NINE_STATE_FF_PSSTAGES
,
1506 [D3DRS_WRAP0
] = NINE_STATE_UNHANDLED
, /* cylindrical wrap is crazy */
1507 [D3DRS_WRAP1
] = NINE_STATE_UNHANDLED
,
1508 [D3DRS_WRAP2
] = NINE_STATE_UNHANDLED
,
1509 [D3DRS_WRAP3
] = NINE_STATE_UNHANDLED
,
1510 [D3DRS_WRAP4
] = NINE_STATE_UNHANDLED
,
1511 [D3DRS_WRAP5
] = NINE_STATE_UNHANDLED
,
1512 [D3DRS_WRAP6
] = NINE_STATE_UNHANDLED
,
1513 [D3DRS_WRAP7
] = NINE_STATE_UNHANDLED
,
1514 [D3DRS_CLIPPING
] = 0, /* software vertex processing only */
1515 [D3DRS_LIGHTING
] = NINE_STATE_FF_LIGHTING
,
1516 [D3DRS_AMBIENT
] = NINE_STATE_FF_LIGHTING
| NINE_STATE_FF_MATERIAL
,
1517 [D3DRS_FOGVERTEXMODE
] = NINE_STATE_FF_OTHER
,
1518 [D3DRS_COLORVERTEX
] = NINE_STATE_FF_LIGHTING
,
1519 [D3DRS_LOCALVIEWER
] = NINE_STATE_FF_LIGHTING
,
1520 [D3DRS_NORMALIZENORMALS
] = NINE_STATE_FF_OTHER
,
1521 [D3DRS_DIFFUSEMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
1522 [D3DRS_SPECULARMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
1523 [D3DRS_AMBIENTMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
1524 [D3DRS_EMISSIVEMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
1525 [D3DRS_VERTEXBLEND
] = NINE_STATE_FF_OTHER
,
1526 [D3DRS_CLIPPLANEENABLE
] = NINE_STATE_RASTERIZER
,
1527 [D3DRS_POINTSIZE
] = NINE_STATE_RASTERIZER
,
1528 [D3DRS_POINTSIZE_MIN
] = NINE_STATE_RASTERIZER
,
1529 [D3DRS_POINTSPRITEENABLE
] = NINE_STATE_RASTERIZER
,
1530 [D3DRS_POINTSCALEENABLE
] = NINE_STATE_FF_OTHER
,
1531 [D3DRS_POINTSCALE_A
] = NINE_STATE_FF_OTHER
,
1532 [D3DRS_POINTSCALE_B
] = NINE_STATE_FF_OTHER
,
1533 [D3DRS_POINTSCALE_C
] = NINE_STATE_FF_OTHER
,
1534 [D3DRS_MULTISAMPLEANTIALIAS
] = NINE_STATE_RASTERIZER
,
1535 [D3DRS_MULTISAMPLEMASK
] = NINE_STATE_SAMPLE_MASK
,
1536 [D3DRS_PATCHEDGESTYLE
] = NINE_STATE_UNHANDLED
,
1537 [D3DRS_DEBUGMONITORTOKEN
] = NINE_STATE_UNHANDLED
,
1538 [D3DRS_POINTSIZE_MAX
] = NINE_STATE_RASTERIZER
,
1539 [D3DRS_INDEXEDVERTEXBLENDENABLE
] = NINE_STATE_FF_OTHER
,
1540 [D3DRS_COLORWRITEENABLE
] = NINE_STATE_BLEND
,
1541 [D3DRS_TWEENFACTOR
] = NINE_STATE_FF_OTHER
,
1542 [D3DRS_BLENDOP
] = NINE_STATE_BLEND
,
1543 [D3DRS_POSITIONDEGREE
] = NINE_STATE_UNHANDLED
,
1544 [D3DRS_NORMALDEGREE
] = NINE_STATE_UNHANDLED
,
1545 [D3DRS_SCISSORTESTENABLE
] = NINE_STATE_RASTERIZER
,
1546 [D3DRS_SLOPESCALEDEPTHBIAS
] = NINE_STATE_RASTERIZER
,
1547 [D3DRS_ANTIALIASEDLINEENABLE
] = NINE_STATE_RASTERIZER
,
1548 [D3DRS_MINTESSELLATIONLEVEL
] = NINE_STATE_UNHANDLED
,
1549 [D3DRS_MAXTESSELLATIONLEVEL
] = NINE_STATE_UNHANDLED
,
1550 [D3DRS_ADAPTIVETESS_X
] = NINE_STATE_UNHANDLED
,
1551 [D3DRS_ADAPTIVETESS_Y
] = NINE_STATE_UNHANDLED
,
1552 [D3DRS_ADAPTIVETESS_Z
] = NINE_STATE_UNHANDLED
,
1553 [D3DRS_ADAPTIVETESS_W
] = NINE_STATE_UNHANDLED
,
1554 [D3DRS_ENABLEADAPTIVETESSELLATION
] = NINE_STATE_UNHANDLED
,
1555 [D3DRS_TWOSIDEDSTENCILMODE
] = NINE_STATE_DSA
,
1556 [D3DRS_CCW_STENCILFAIL
] = NINE_STATE_DSA
,
1557 [D3DRS_CCW_STENCILZFAIL
] = NINE_STATE_DSA
,
1558 [D3DRS_CCW_STENCILPASS
] = NINE_STATE_DSA
,
1559 [D3DRS_CCW_STENCILFUNC
] = NINE_STATE_DSA
,
1560 [D3DRS_COLORWRITEENABLE1
] = NINE_STATE_BLEND
,
1561 [D3DRS_COLORWRITEENABLE2
] = NINE_STATE_BLEND
,
1562 [D3DRS_COLORWRITEENABLE3
] = NINE_STATE_BLEND
,
1563 [D3DRS_BLENDFACTOR
] = NINE_STATE_BLEND_COLOR
,
1564 [D3DRS_SRGBWRITEENABLE
] = NINE_STATE_FB
,
1565 [D3DRS_DEPTHBIAS
] = NINE_STATE_RASTERIZER
,
1566 [D3DRS_WRAP8
] = NINE_STATE_UNHANDLED
, /* cylwrap has to be done via GP */
1567 [D3DRS_WRAP9
] = NINE_STATE_UNHANDLED
,
1568 [D3DRS_WRAP10
] = NINE_STATE_UNHANDLED
,
1569 [D3DRS_WRAP11
] = NINE_STATE_UNHANDLED
,
1570 [D3DRS_WRAP12
] = NINE_STATE_UNHANDLED
,
1571 [D3DRS_WRAP13
] = NINE_STATE_UNHANDLED
,
1572 [D3DRS_WRAP14
] = NINE_STATE_UNHANDLED
,
1573 [D3DRS_WRAP15
] = NINE_STATE_UNHANDLED
,
1574 [D3DRS_SEPARATEALPHABLENDENABLE
] = NINE_STATE_BLEND
,
1575 [D3DRS_SRCBLENDALPHA
] = NINE_STATE_BLEND
,
1576 [D3DRS_DESTBLENDALPHA
] = NINE_STATE_BLEND
,
1577 [D3DRS_BLENDOPALPHA
] = NINE_STATE_BLEND
1583 nine_state_access_transform(struct nine_state
*state
, D3DTRANSFORMSTATETYPE t
,
1586 static D3DMATRIX Identity
= { .m
[0] = { 1, 0, 0, 0 },
1587 .m
[1] = { 0, 1, 0, 0 },
1588 .m
[2] = { 0, 0, 1, 0 },
1589 .m
[3] = { 0, 0, 0, 1 } };
1593 case D3DTS_VIEW
: index
= 0; break;
1594 case D3DTS_PROJECTION
: index
= 1; break;
1595 case D3DTS_TEXTURE0
: index
= 2; break;
1596 case D3DTS_TEXTURE1
: index
= 3; break;
1597 case D3DTS_TEXTURE2
: index
= 4; break;
1598 case D3DTS_TEXTURE3
: index
= 5; break;
1599 case D3DTS_TEXTURE4
: index
= 6; break;
1600 case D3DTS_TEXTURE5
: index
= 7; break;
1601 case D3DTS_TEXTURE6
: index
= 8; break;
1602 case D3DTS_TEXTURE7
: index
= 9; break;
1604 if (!(t
>= D3DTS_WORLDMATRIX(0) && t
<= D3DTS_WORLDMATRIX(255)))
1606 index
= 10 + (t
- D3DTS_WORLDMATRIX(0));
1610 if (index
>= state
->ff
.num_transforms
) {
1611 unsigned N
= index
+ 1;
1612 unsigned n
= state
->ff
.num_transforms
;
1616 state
->ff
.transform
= REALLOC(state
->ff
.transform
,
1617 n
* sizeof(D3DMATRIX
),
1618 N
* sizeof(D3DMATRIX
));
1620 state
->ff
.transform
[n
] = Identity
;
1621 state
->ff
.num_transforms
= N
;
1623 return &state
->ff
.transform
[index
];
1626 #define D3DRS_TO_STRING_CASE(n) case D3DRS_##n: return "D3DRS_"#n
1627 const char *nine_d3drs_to_string(DWORD State
)
1630 D3DRS_TO_STRING_CASE(ZENABLE
);
1631 D3DRS_TO_STRING_CASE(FILLMODE
);
1632 D3DRS_TO_STRING_CASE(SHADEMODE
);
1633 D3DRS_TO_STRING_CASE(ZWRITEENABLE
);
1634 D3DRS_TO_STRING_CASE(ALPHATESTENABLE
);
1635 D3DRS_TO_STRING_CASE(LASTPIXEL
);
1636 D3DRS_TO_STRING_CASE(SRCBLEND
);
1637 D3DRS_TO_STRING_CASE(DESTBLEND
);
1638 D3DRS_TO_STRING_CASE(CULLMODE
);
1639 D3DRS_TO_STRING_CASE(ZFUNC
);
1640 D3DRS_TO_STRING_CASE(ALPHAREF
);
1641 D3DRS_TO_STRING_CASE(ALPHAFUNC
);
1642 D3DRS_TO_STRING_CASE(DITHERENABLE
);
1643 D3DRS_TO_STRING_CASE(ALPHABLENDENABLE
);
1644 D3DRS_TO_STRING_CASE(FOGENABLE
);
1645 D3DRS_TO_STRING_CASE(SPECULARENABLE
);
1646 D3DRS_TO_STRING_CASE(FOGCOLOR
);
1647 D3DRS_TO_STRING_CASE(FOGTABLEMODE
);
1648 D3DRS_TO_STRING_CASE(FOGSTART
);
1649 D3DRS_TO_STRING_CASE(FOGEND
);
1650 D3DRS_TO_STRING_CASE(FOGDENSITY
);
1651 D3DRS_TO_STRING_CASE(RANGEFOGENABLE
);
1652 D3DRS_TO_STRING_CASE(STENCILENABLE
);
1653 D3DRS_TO_STRING_CASE(STENCILFAIL
);
1654 D3DRS_TO_STRING_CASE(STENCILZFAIL
);
1655 D3DRS_TO_STRING_CASE(STENCILPASS
);
1656 D3DRS_TO_STRING_CASE(STENCILFUNC
);
1657 D3DRS_TO_STRING_CASE(STENCILREF
);
1658 D3DRS_TO_STRING_CASE(STENCILMASK
);
1659 D3DRS_TO_STRING_CASE(STENCILWRITEMASK
);
1660 D3DRS_TO_STRING_CASE(TEXTUREFACTOR
);
1661 D3DRS_TO_STRING_CASE(WRAP0
);
1662 D3DRS_TO_STRING_CASE(WRAP1
);
1663 D3DRS_TO_STRING_CASE(WRAP2
);
1664 D3DRS_TO_STRING_CASE(WRAP3
);
1665 D3DRS_TO_STRING_CASE(WRAP4
);
1666 D3DRS_TO_STRING_CASE(WRAP5
);
1667 D3DRS_TO_STRING_CASE(WRAP6
);
1668 D3DRS_TO_STRING_CASE(WRAP7
);
1669 D3DRS_TO_STRING_CASE(CLIPPING
);
1670 D3DRS_TO_STRING_CASE(LIGHTING
);
1671 D3DRS_TO_STRING_CASE(AMBIENT
);
1672 D3DRS_TO_STRING_CASE(FOGVERTEXMODE
);
1673 D3DRS_TO_STRING_CASE(COLORVERTEX
);
1674 D3DRS_TO_STRING_CASE(LOCALVIEWER
);
1675 D3DRS_TO_STRING_CASE(NORMALIZENORMALS
);
1676 D3DRS_TO_STRING_CASE(DIFFUSEMATERIALSOURCE
);
1677 D3DRS_TO_STRING_CASE(SPECULARMATERIALSOURCE
);
1678 D3DRS_TO_STRING_CASE(AMBIENTMATERIALSOURCE
);
1679 D3DRS_TO_STRING_CASE(EMISSIVEMATERIALSOURCE
);
1680 D3DRS_TO_STRING_CASE(VERTEXBLEND
);
1681 D3DRS_TO_STRING_CASE(CLIPPLANEENABLE
);
1682 D3DRS_TO_STRING_CASE(POINTSIZE
);
1683 D3DRS_TO_STRING_CASE(POINTSIZE_MIN
);
1684 D3DRS_TO_STRING_CASE(POINTSPRITEENABLE
);
1685 D3DRS_TO_STRING_CASE(POINTSCALEENABLE
);
1686 D3DRS_TO_STRING_CASE(POINTSCALE_A
);
1687 D3DRS_TO_STRING_CASE(POINTSCALE_B
);
1688 D3DRS_TO_STRING_CASE(POINTSCALE_C
);
1689 D3DRS_TO_STRING_CASE(MULTISAMPLEANTIALIAS
);
1690 D3DRS_TO_STRING_CASE(MULTISAMPLEMASK
);
1691 D3DRS_TO_STRING_CASE(PATCHEDGESTYLE
);
1692 D3DRS_TO_STRING_CASE(DEBUGMONITORTOKEN
);
1693 D3DRS_TO_STRING_CASE(POINTSIZE_MAX
);
1694 D3DRS_TO_STRING_CASE(INDEXEDVERTEXBLENDENABLE
);
1695 D3DRS_TO_STRING_CASE(COLORWRITEENABLE
);
1696 D3DRS_TO_STRING_CASE(TWEENFACTOR
);
1697 D3DRS_TO_STRING_CASE(BLENDOP
);
1698 D3DRS_TO_STRING_CASE(POSITIONDEGREE
);
1699 D3DRS_TO_STRING_CASE(NORMALDEGREE
);
1700 D3DRS_TO_STRING_CASE(SCISSORTESTENABLE
);
1701 D3DRS_TO_STRING_CASE(SLOPESCALEDEPTHBIAS
);
1702 D3DRS_TO_STRING_CASE(ANTIALIASEDLINEENABLE
);
1703 D3DRS_TO_STRING_CASE(MINTESSELLATIONLEVEL
);
1704 D3DRS_TO_STRING_CASE(MAXTESSELLATIONLEVEL
);
1705 D3DRS_TO_STRING_CASE(ADAPTIVETESS_X
);
1706 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Y
);
1707 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Z
);
1708 D3DRS_TO_STRING_CASE(ADAPTIVETESS_W
);
1709 D3DRS_TO_STRING_CASE(ENABLEADAPTIVETESSELLATION
);
1710 D3DRS_TO_STRING_CASE(TWOSIDEDSTENCILMODE
);
1711 D3DRS_TO_STRING_CASE(CCW_STENCILFAIL
);
1712 D3DRS_TO_STRING_CASE(CCW_STENCILZFAIL
);
1713 D3DRS_TO_STRING_CASE(CCW_STENCILPASS
);
1714 D3DRS_TO_STRING_CASE(CCW_STENCILFUNC
);
1715 D3DRS_TO_STRING_CASE(COLORWRITEENABLE1
);
1716 D3DRS_TO_STRING_CASE(COLORWRITEENABLE2
);
1717 D3DRS_TO_STRING_CASE(COLORWRITEENABLE3
);
1718 D3DRS_TO_STRING_CASE(BLENDFACTOR
);
1719 D3DRS_TO_STRING_CASE(SRGBWRITEENABLE
);
1720 D3DRS_TO_STRING_CASE(DEPTHBIAS
);
1721 D3DRS_TO_STRING_CASE(WRAP8
);
1722 D3DRS_TO_STRING_CASE(WRAP9
);
1723 D3DRS_TO_STRING_CASE(WRAP10
);
1724 D3DRS_TO_STRING_CASE(WRAP11
);
1725 D3DRS_TO_STRING_CASE(WRAP12
);
1726 D3DRS_TO_STRING_CASE(WRAP13
);
1727 D3DRS_TO_STRING_CASE(WRAP14
);
1728 D3DRS_TO_STRING_CASE(WRAP15
);
1729 D3DRS_TO_STRING_CASE(SEPARATEALPHABLENDENABLE
);
1730 D3DRS_TO_STRING_CASE(SRCBLENDALPHA
);
1731 D3DRS_TO_STRING_CASE(DESTBLENDALPHA
);
1732 D3DRS_TO_STRING_CASE(BLENDOPALPHA
);