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. */
27 #include "swapchain9.h"
28 #include "basetexture9.h"
30 #include "indexbuffer9.h"
32 #include "vertexbuffer9.h"
33 #include "vertexdeclaration9.h"
34 #include "vertexshader9.h"
35 #include "pixelshader9.h"
36 #include "nine_pipe.h"
38 #include "nine_limits.h"
39 #include "pipe/p_context.h"
40 #include "pipe/p_state.h"
41 #include "cso_cache/cso_context.h"
42 #include "util/u_atomic.h"
43 #include "util/u_upload_mgr.h"
44 #include "util/u_math.h"
45 #include "util/u_box.h"
46 #include "util/u_simple_shaders.h"
47 #include "util/u_gen_mipmap.h"
50 #include "nine_queue.h"
51 #include "nine_csmt_helper.h"
52 #include "os/os_thread.h"
54 #define DBG_CHANNEL DBG_DEVICE
58 struct csmt_instruction
{
59 int (* func
)(struct NineDevice9
*This
, struct csmt_instruction
*instr
);
64 struct nine_queue_pool
* pool
;
66 cnd_t event_processed
;
67 mtx_t mutex_processed
;
68 struct NineDevice9
*device
;
76 /* Wait for instruction to be processed.
77 * Caller has to ensure that only one thread waits at time.
80 nine_csmt_wait_processed(struct csmt_context
*ctx
)
82 mtx_lock(&ctx
->mutex_processed
);
83 while (!p_atomic_read(&ctx
->processed
)) {
84 cnd_wait(&ctx
->event_processed
, &ctx
->mutex_processed
);
86 mtx_unlock(&ctx
->mutex_processed
);
89 /* CSMT worker thread */
92 nine_csmt_worker(void *arg
)
94 struct csmt_context
*ctx
= arg
;
95 struct csmt_instruction
*instr
;
96 DBG("CSMT worker spawned\n");
98 u_thread_setname("CSMT-Worker");
101 nine_queue_wait_flush(ctx
->pool
);
102 mtx_lock(&ctx
->thread_running
);
104 /* Get instruction. NULL on empty cmdbuf. */
105 while (!p_atomic_read(&ctx
->terminate
) &&
106 (instr
= (struct csmt_instruction
*)nine_queue_get(ctx
->pool
))) {
109 if (instr
->func(ctx
->device
, instr
)) {
110 mtx_lock(&ctx
->mutex_processed
);
111 p_atomic_set(&ctx
->processed
, TRUE
);
112 cnd_signal(&ctx
->event_processed
);
113 mtx_unlock(&ctx
->mutex_processed
);
115 if (p_atomic_read(&ctx
->toPause
)) {
116 mtx_unlock(&ctx
->thread_running
);
117 /* will wait here the thread can be resumed */
118 mtx_lock(&ctx
->thread_resume
);
119 mtx_lock(&ctx
->thread_running
);
120 mtx_unlock(&ctx
->thread_resume
);
124 mtx_unlock(&ctx
->thread_running
);
125 if (p_atomic_read(&ctx
->terminate
)) {
126 mtx_lock(&ctx
->mutex_processed
);
127 p_atomic_set(&ctx
->processed
, TRUE
);
128 cnd_signal(&ctx
->event_processed
);
129 mtx_unlock(&ctx
->mutex_processed
);
134 DBG("CSMT worker destroyed\n");
138 /* Create a CSMT context.
139 * Spawns a worker thread.
141 struct csmt_context
*
142 nine_csmt_create( struct NineDevice9
*This
)
144 struct csmt_context
*ctx
;
146 ctx
= CALLOC_STRUCT(csmt_context
);
150 ctx
->pool
= nine_queue_create();
155 cnd_init(&ctx
->event_processed
);
156 (void) mtx_init(&ctx
->mutex_processed
, mtx_plain
);
157 (void) mtx_init(&ctx
->thread_running
, mtx_plain
);
158 (void) mtx_init(&ctx
->thread_resume
, mtx_plain
);
161 u_thread_setname("Main thread");
166 ctx
->worker
= u_thread_create(nine_csmt_worker
, ctx
);
168 nine_queue_delete(ctx
->pool
);
173 DBG("Returning context %p\n", ctx
);
179 nop_func( struct NineDevice9
*This
, struct csmt_instruction
*instr
)
187 /* Push nop instruction and flush the queue.
188 * Waits for the worker to complete. */
190 nine_csmt_process( struct NineDevice9
*device
)
192 struct csmt_instruction
* instr
;
193 struct csmt_context
*ctx
= device
->csmt_ctx
;
195 if (!device
->csmt_active
)
198 if (nine_queue_isempty(ctx
->pool
))
201 DBG("device=%p\n", device
);
204 instr
= nine_queue_alloc(ctx
->pool
, sizeof(struct csmt_instruction
));
206 instr
->func
= nop_func
;
208 p_atomic_set(&ctx
->processed
, FALSE
);
209 nine_queue_flush(ctx
->pool
);
211 nine_csmt_wait_processed(ctx
);
214 /* Destroys a CSMT context.
215 * Waits for the worker thread to terminate.
218 nine_csmt_destroy( struct NineDevice9
*device
, struct csmt_context
*ctx
)
220 struct csmt_instruction
* instr
;
221 thrd_t render_thread
= ctx
->worker
;
223 DBG("device=%p ctx=%p\n", device
, ctx
);
225 /* Push nop and flush the queue. */
226 instr
= nine_queue_alloc(ctx
->pool
, sizeof(struct csmt_instruction
));
228 instr
->func
= nop_func
;
230 p_atomic_set(&ctx
->processed
, FALSE
);
231 /* Signal worker to terminate. */
232 p_atomic_set(&ctx
->terminate
, TRUE
);
233 nine_queue_flush(ctx
->pool
);
235 nine_csmt_wait_processed(ctx
);
236 nine_queue_delete(ctx
->pool
);
237 mtx_destroy(&ctx
->mutex_processed
);
241 thrd_join(render_thread
, NULL
);
245 nine_csmt_pause( struct NineDevice9
*device
)
247 struct csmt_context
*ctx
= device
->csmt_ctx
;
249 if (!device
->csmt_active
)
252 /* No need to pause the thread */
253 if (nine_queue_no_flushed_work(ctx
->pool
))
256 mtx_lock(&ctx
->thread_resume
);
257 p_atomic_set(&ctx
->toPause
, TRUE
);
259 /* Wait the thread is paused */
260 mtx_lock(&ctx
->thread_running
);
261 ctx
->hasPaused
= TRUE
;
262 p_atomic_set(&ctx
->toPause
, FALSE
);
266 nine_csmt_resume( struct NineDevice9
*device
)
268 struct csmt_context
*ctx
= device
->csmt_ctx
;
270 if (!device
->csmt_active
)
276 ctx
->hasPaused
= FALSE
;
277 mtx_unlock(&ctx
->thread_running
);
278 mtx_unlock(&ctx
->thread_resume
);
281 struct pipe_context
*
282 nine_context_get_pipe( struct NineDevice9
*device
)
284 nine_csmt_process(device
);
285 return device
->context
.pipe
;
288 struct pipe_context
*
289 nine_context_get_pipe_multithread( struct NineDevice9
*device
)
291 struct csmt_context
*ctx
= device
->csmt_ctx
;
293 if (!device
->csmt_active
)
294 return device
->context
.pipe
;
296 if (!u_thread_is_self(ctx
->worker
))
297 nine_csmt_process(device
);
299 return device
->context
.pipe
;
302 struct pipe_context
*
303 nine_context_get_pipe_acquire( struct NineDevice9
*device
)
305 nine_csmt_pause(device
);
306 return device
->context
.pipe
;
310 nine_context_get_pipe_release( struct NineDevice9
*device
)
312 nine_csmt_resume(device
);
315 /* Nine state functions */
317 /* Check if some states need to be set dirty */
320 check_multisample(struct NineDevice9
*device
)
322 DWORD
*rs
= device
->context
.rs
;
323 DWORD new_value
= (rs
[D3DRS_ZENABLE
] || rs
[D3DRS_STENCILENABLE
]) &&
324 device
->context
.rt
[0]->desc
.MultiSampleType
>= 1 &&
325 rs
[D3DRS_MULTISAMPLEANTIALIAS
];
326 if (rs
[NINED3DRS_MULTISAMPLE
] != new_value
) {
327 rs
[NINED3DRS_MULTISAMPLE
] = new_value
;
328 return NINE_STATE_RASTERIZER
;
333 /* State preparation only */
336 prepare_blend(struct NineDevice9
*device
)
338 nine_convert_blend_state(&device
->context
.pipe_data
.blend
, device
->context
.rs
);
339 device
->context
.commit
|= NINE_STATE_COMMIT_BLEND
;
343 prepare_dsa(struct NineDevice9
*device
)
345 nine_convert_dsa_state(&device
->context
.pipe_data
.dsa
, device
->context
.rs
);
346 device
->context
.commit
|= NINE_STATE_COMMIT_DSA
;
350 prepare_rasterizer(struct NineDevice9
*device
)
352 nine_convert_rasterizer_state(device
, &device
->context
.pipe_data
.rast
, device
->context
.rs
);
353 device
->context
.commit
|= NINE_STATE_COMMIT_RASTERIZER
;
357 prepare_vs_constants_userbuf_swvp(struct NineDevice9
*device
)
359 struct nine_context
*context
= &device
->context
;
361 if (context
->changed
.vs_const_f
|| context
->changed
.group
& NINE_STATE_SWVP
) {
362 struct pipe_constant_buffer cb
;
364 cb
.buffer_offset
= 0;
365 cb
.buffer_size
= 4096 * sizeof(float[4]);
366 cb
.user_buffer
= context
->vs_const_f_swvp
;
368 if (context
->vs
->lconstf
.ranges
) {
369 const struct nine_lconstf
*lconstf
= &(context
->vs
->lconstf
);
370 const struct nine_range
*r
= lconstf
->ranges
;
372 float *dst
= context
->vs_lconstf_temp
;
373 float *src
= (float *)cb
.user_buffer
;
374 memcpy(dst
, src
, cb
.buffer_size
);
377 unsigned c
= r
->end
- r
->bgn
;
378 memcpy(&dst
[p
* 4], &lconstf
->data
[n
* 4], c
* 4 * sizeof(float));
382 cb
.user_buffer
= dst
;
385 context
->pipe_data
.cb0_swvp
.buffer_offset
= cb
.buffer_offset
;
386 context
->pipe_data
.cb0_swvp
.buffer_size
= cb
.buffer_size
;
387 context
->pipe_data
.cb0_swvp
.user_buffer
= cb
.user_buffer
;
389 cb
.user_buffer
= (char *)cb
.user_buffer
+ 4096 * sizeof(float[4]);
390 context
->pipe_data
.cb1_swvp
.buffer_offset
= cb
.buffer_offset
;
391 context
->pipe_data
.cb1_swvp
.buffer_size
= cb
.buffer_size
;
392 context
->pipe_data
.cb1_swvp
.user_buffer
= cb
.user_buffer
;
394 context
->changed
.vs_const_f
= 0;
397 if (context
->changed
.vs_const_i
|| context
->changed
.group
& NINE_STATE_SWVP
) {
398 struct pipe_constant_buffer cb
;
400 cb
.buffer_offset
= 0;
401 cb
.buffer_size
= 2048 * sizeof(float[4]);
402 cb
.user_buffer
= context
->vs_const_i
;
404 context
->pipe_data
.cb2_swvp
.buffer_offset
= cb
.buffer_offset
;
405 context
->pipe_data
.cb2_swvp
.buffer_size
= cb
.buffer_size
;
406 context
->pipe_data
.cb2_swvp
.user_buffer
= cb
.user_buffer
;
407 context
->changed
.vs_const_i
= 0;
410 if (context
->changed
.vs_const_b
|| context
->changed
.group
& NINE_STATE_SWVP
) {
411 struct pipe_constant_buffer cb
;
413 cb
.buffer_offset
= 0;
414 cb
.buffer_size
= 512 * sizeof(float[4]);
415 cb
.user_buffer
= context
->vs_const_b
;
417 context
->pipe_data
.cb3_swvp
.buffer_offset
= cb
.buffer_offset
;
418 context
->pipe_data
.cb3_swvp
.buffer_size
= cb
.buffer_size
;
419 context
->pipe_data
.cb3_swvp
.user_buffer
= cb
.user_buffer
;
420 context
->changed
.vs_const_b
= 0;
423 context
->changed
.group
&= ~NINE_STATE_VS_CONST
;
424 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
428 prepare_vs_constants_userbuf(struct NineDevice9
*device
)
430 struct nine_context
*context
= &device
->context
;
431 struct pipe_constant_buffer cb
;
433 cb
.buffer_offset
= 0;
434 cb
.buffer_size
= context
->vs
->const_used_size
;
435 cb
.user_buffer
= context
->vs_const_f
;
438 prepare_vs_constants_userbuf_swvp(device
);
442 if (context
->changed
.vs_const_i
|| context
->changed
.group
& NINE_STATE_SWVP
) {
443 int *idst
= (int *)&context
->vs_const_f
[4 * device
->max_vs_const_f
];
444 memcpy(idst
, context
->vs_const_i
, NINE_MAX_CONST_I
* sizeof(int[4]));
445 context
->changed
.vs_const_i
= 0;
448 if (context
->changed
.vs_const_b
|| context
->changed
.group
& NINE_STATE_SWVP
) {
449 int *idst
= (int *)&context
->vs_const_f
[4 * device
->max_vs_const_f
];
450 uint32_t *bdst
= (uint32_t *)&idst
[4 * NINE_MAX_CONST_I
];
451 memcpy(bdst
, context
->vs_const_b
, NINE_MAX_CONST_B
* sizeof(BOOL
));
452 context
->changed
.vs_const_b
= 0;
458 if (context
->vs
->lconstf
.ranges
) {
459 /* TODO: Can we make it so that we don't have to copy everything ? */
460 const struct nine_lconstf
*lconstf
= &(context
->vs
->lconstf
);
461 const struct nine_range
*r
= lconstf
->ranges
;
463 float *dst
= context
->vs_lconstf_temp
;
464 float *src
= (float *)cb
.user_buffer
;
465 memcpy(dst
, src
, cb
.buffer_size
);
468 unsigned c
= r
->end
- r
->bgn
;
469 memcpy(&dst
[p
* 4], &lconstf
->data
[n
* 4], c
* 4 * sizeof(float));
473 cb
.user_buffer
= dst
;
476 context
->pipe_data
.cb_vs
= cb
;
477 context
->changed
.vs_const_f
= 0;
479 context
->changed
.group
&= ~NINE_STATE_VS_CONST
;
480 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
484 prepare_ps_constants_userbuf(struct NineDevice9
*device
)
486 struct nine_context
*context
= &device
->context
;
487 struct pipe_constant_buffer cb
;
489 cb
.buffer_offset
= 0;
490 cb
.buffer_size
= context
->ps
->const_used_size
;
491 cb
.user_buffer
= context
->ps_const_f
;
493 if (context
->changed
.ps_const_i
) {
494 int *idst
= (int *)&context
->ps_const_f
[4 * device
->max_ps_const_f
];
495 memcpy(idst
, context
->ps_const_i
, sizeof(context
->ps_const_i
));
496 context
->changed
.ps_const_i
= 0;
498 if (context
->changed
.ps_const_b
) {
499 int *idst
= (int *)&context
->ps_const_f
[4 * device
->max_ps_const_f
];
500 uint32_t *bdst
= (uint32_t *)&idst
[4 * NINE_MAX_CONST_I
];
501 memcpy(bdst
, context
->ps_const_b
, sizeof(context
->ps_const_b
));
502 context
->changed
.ps_const_b
= 0;
505 /* Upload special constants needed to implement PS1.x instructions like TEXBEM,TEXBEML and BEM */
506 if (context
->ps
->bumpenvmat_needed
) {
507 memcpy(context
->ps_lconstf_temp
, cb
.user_buffer
, cb
.buffer_size
);
508 memcpy(&context
->ps_lconstf_temp
[4 * 8], &device
->context
.bumpmap_vars
, sizeof(device
->context
.bumpmap_vars
));
510 cb
.user_buffer
= context
->ps_lconstf_temp
;
513 if (context
->ps
->byte_code
.version
< 0x30 &&
514 context
->rs
[D3DRS_FOGENABLE
]) {
515 float *dst
= &context
->ps_lconstf_temp
[4 * 32];
516 if (cb
.user_buffer
!= context
->ps_lconstf_temp
) {
517 memcpy(context
->ps_lconstf_temp
, cb
.user_buffer
, cb
.buffer_size
);
518 cb
.user_buffer
= context
->ps_lconstf_temp
;
521 d3dcolor_to_rgba(dst
, context
->rs
[D3DRS_FOGCOLOR
]);
522 if (context
->rs
[D3DRS_FOGTABLEMODE
] == D3DFOG_LINEAR
) {
523 dst
[4] = asfloat(context
->rs
[D3DRS_FOGEND
]);
524 dst
[5] = 1.0f
/ (asfloat(context
->rs
[D3DRS_FOGEND
]) - asfloat(context
->rs
[D3DRS_FOGSTART
]));
525 } else if (context
->rs
[D3DRS_FOGTABLEMODE
] != D3DFOG_NONE
) {
526 dst
[4] = asfloat(context
->rs
[D3DRS_FOGDENSITY
]);
528 cb
.buffer_size
= 4 * 4 * 34;
534 context
->pipe_data
.cb_ps
= cb
;
535 context
->changed
.ps_const_f
= 0;
537 context
->changed
.group
&= ~NINE_STATE_PS_CONST
;
538 context
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
541 static inline uint32_t
542 prepare_vs(struct NineDevice9
*device
, uint8_t shader_changed
)
544 struct nine_context
*context
= &device
->context
;
545 struct NineVertexShader9
*vs
= context
->vs
;
546 uint32_t changed_group
= 0;
547 int has_key_changed
= 0;
549 if (likely(context
->programmable_vs
))
550 has_key_changed
= NineVertexShader9_UpdateKey(vs
, device
);
552 if (!shader_changed
&& !has_key_changed
)
555 /* likely because we dislike FF */
556 if (likely(context
->programmable_vs
)) {
557 context
->cso_shader
.vs
= NineVertexShader9_GetVariant(vs
);
560 context
->cso_shader
.vs
= vs
->ff_cso
;
563 if (context
->rs
[NINED3DRS_VSPOINTSIZE
] != vs
->point_size
) {
564 context
->rs
[NINED3DRS_VSPOINTSIZE
] = vs
->point_size
;
565 changed_group
|= NINE_STATE_RASTERIZER
;
568 if ((context
->bound_samplers_mask_vs
& vs
->sampler_mask
) != vs
->sampler_mask
)
569 /* Bound dummy sampler. */
570 changed_group
|= NINE_STATE_SAMPLER
;
572 context
->commit
|= NINE_STATE_COMMIT_VS
;
573 return changed_group
;
576 static inline uint32_t
577 prepare_ps(struct NineDevice9
*device
, uint8_t shader_changed
)
579 struct nine_context
*context
= &device
->context
;
580 struct NinePixelShader9
*ps
= context
->ps
;
581 uint32_t changed_group
= 0;
582 int has_key_changed
= 0;
585 has_key_changed
= NinePixelShader9_UpdateKey(ps
, context
);
587 if (!shader_changed
&& !has_key_changed
)
591 context
->cso_shader
.ps
= NinePixelShader9_GetVariant(ps
);
594 context
->cso_shader
.ps
= ps
->ff_cso
;
597 if ((context
->bound_samplers_mask_ps
& ps
->sampler_mask
) != ps
->sampler_mask
)
598 /* Bound dummy sampler. */
599 changed_group
|= NINE_STATE_SAMPLER
;
601 context
->commit
|= NINE_STATE_COMMIT_PS
;
602 return changed_group
;
605 /* State preparation incremental */
607 /* State preparation + State commit */
610 update_framebuffer(struct NineDevice9
*device
, bool is_clear
)
612 struct nine_context
*context
= &device
->context
;
613 struct pipe_context
*pipe
= context
->pipe
;
614 struct pipe_framebuffer_state
*fb
= &context
->pipe_data
.fb
;
616 struct NineSurface9
*rt0
= context
->rt
[0];
617 unsigned w
= rt0
->desc
.Width
;
618 unsigned h
= rt0
->desc
.Height
;
619 unsigned nr_samples
= rt0
->base
.info
.nr_samples
;
620 unsigned ps_mask
= context
->ps
? context
->ps
->rt_mask
: 1;
621 unsigned mask
= is_clear
? 0xf : ps_mask
;
622 const int sRGB
= context
->rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
626 context
->rt_mask
= 0x0;
629 /* all render targets must have the same size and the depth buffer must be
630 * bigger. Multisample has to match, according to spec. But some apps do
631 * things wrong there, and no error is returned. The behaviour they get
632 * apparently is that depth buffer is disabled if it doesn't match.
633 * Surely the same for render targets. */
635 /* Special case: D3DFMT_NULL is used to bound no real render target,
636 * but render to depth buffer. We have to not take into account the render
637 * target info. TODO: know what should happen when there are several render targers
638 * and the first one is D3DFMT_NULL */
639 if (rt0
->desc
.Format
== D3DFMT_NULL
&& context
->ds
) {
640 w
= context
->ds
->desc
.Width
;
641 h
= context
->ds
->desc
.Height
;
642 nr_samples
= context
->ds
->base
.info
.nr_samples
;
645 for (i
= 0; i
< device
->caps
.NumSimultaneousRTs
; ++i
) {
646 struct NineSurface9
*rt
= context
->rt
[i
];
648 if (rt
&& rt
->desc
.Format
!= D3DFMT_NULL
&& (mask
& (1 << i
)) &&
649 rt
->desc
.Width
== w
&& rt
->desc
.Height
== h
&&
650 rt
->base
.info
.nr_samples
== nr_samples
) {
651 fb
->cbufs
[i
] = NineSurface9_GetSurface(rt
, sRGB
);
652 context
->rt_mask
|= 1 << i
;
653 fb
->nr_cbufs
= i
+ 1;
655 /* Color outputs must match RT slot,
656 * drivers will have to handle NULL entries for GL, too.
662 if (context
->ds
&& context
->ds
->desc
.Width
>= w
&&
663 context
->ds
->desc
.Height
>= h
&&
664 context
->ds
->base
.info
.nr_samples
== nr_samples
) {
665 fb
->zsbuf
= NineSurface9_GetSurface(context
->ds
, 0);
673 pipe
->set_framebuffer_state(pipe
, fb
); /* XXX: cso ? */
675 if (is_clear
&& context
->rt_mask
== ps_mask
)
676 context
->changed
.group
&= ~NINE_STATE_FB
;
680 update_viewport(struct NineDevice9
*device
)
682 struct nine_context
*context
= &device
->context
;
683 const D3DVIEWPORT9
*vport
= &context
->viewport
;
684 struct pipe_viewport_state pvport
;
686 /* D3D coordinates are:
687 * -1 .. +1 for X,Y and
688 * 0 .. +1 for Z (we use pipe_rasterizer_state.clip_halfz)
690 pvport
.scale
[0] = (float)vport
->Width
* 0.5f
;
691 pvport
.scale
[1] = (float)vport
->Height
* -0.5f
;
692 pvport
.scale
[2] = vport
->MaxZ
- vport
->MinZ
;
693 pvport
.translate
[0] = (float)vport
->Width
* 0.5f
+ (float)vport
->X
;
694 pvport
.translate
[1] = (float)vport
->Height
* 0.5f
+ (float)vport
->Y
;
695 pvport
.translate
[2] = vport
->MinZ
;
697 /* We found R600 and SI cards have some imprecision
698 * on the barycentric coordinates used for interpolation.
699 * Some shaders rely on having something precise.
700 * We found that the proprietary driver has the imprecision issue,
701 * except when the render target width and height are powers of two.
702 * It is using some sort of workaround for these cases
703 * which covers likely all the cases the applications rely
704 * on something precise.
705 * We haven't found the workaround, but it seems like it's better
706 * for applications if the imprecision is biased towards infinity
707 * instead of -infinity (which is what measured). So shift slightly
708 * the viewport: not enough to change rasterization result (in particular
709 * for multisampling), but enough to make the imprecision biased
710 * towards infinity. We do this shift only if render target width and
711 * height are powers of two.
712 * Solves 'red shadows' bug on UE3 games.
714 if (device
->driver_bugs
.buggy_barycentrics
&&
715 ((vport
->Width
& (vport
->Width
-1)) == 0) &&
716 ((vport
->Height
& (vport
->Height
-1)) == 0)) {
717 pvport
.translate
[0] -= 1.0f
/ 128.0f
;
718 pvport
.translate
[1] -= 1.0f
/ 128.0f
;
721 cso_set_viewport(context
->cso
, &pvport
);
724 /* Loop through VS inputs and pick the vertex elements with the declared
725 * usage from the vertex declaration, then insert the instance divisor from
726 * the stream source frequency setting.
729 update_vertex_elements(struct NineDevice9
*device
)
731 struct nine_context
*context
= &device
->context
;
732 const struct NineVertexDeclaration9
*vdecl
= device
->context
.vdecl
;
733 const struct NineVertexShader9
*vs
;
736 char vdecl_index_map
[16]; /* vs->num_inputs <= 16 */
737 char used_streams
[device
->caps
.MaxStreams
];
738 int dummy_vbo_stream
= -1;
739 BOOL need_dummy_vbo
= FALSE
;
740 struct pipe_vertex_element ve
[PIPE_MAX_ATTRIBS
];
742 context
->stream_usage_mask
= 0;
743 memset(vdecl_index_map
, -1, 16);
744 memset(used_streams
, 0, device
->caps
.MaxStreams
);
745 vs
= context
->programmable_vs
? context
->vs
: device
->ff
.vs
;
748 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
749 DBG("looking up input %u (usage %u) from vdecl(%p)\n",
750 n
, vs
->input_map
[n
].ndecl
, vdecl
);
752 for (i
= 0; i
< vdecl
->nelems
; i
++) {
753 if (vdecl
->usage_map
[i
] == vs
->input_map
[n
].ndecl
) {
754 vdecl_index_map
[n
] = i
;
755 used_streams
[vdecl
->elems
[i
].vertex_buffer_index
] = 1;
759 if (vdecl_index_map
[n
] < 0)
760 need_dummy_vbo
= TRUE
;
763 /* No vertex declaration. Likely will never happen in practice,
764 * but we need not crash on this */
765 need_dummy_vbo
= TRUE
;
768 if (need_dummy_vbo
) {
769 for (i
= 0; i
< device
->caps
.MaxStreams
; i
++ ) {
770 if (!used_streams
[i
]) {
771 dummy_vbo_stream
= i
;
776 /* there are less vertex shader inputs than stream slots,
777 * so if we need a slot for the dummy vbo, we should have found one */
778 assert (!need_dummy_vbo
|| dummy_vbo_stream
!= -1);
780 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
781 index
= vdecl_index_map
[n
];
783 ve
[n
] = vdecl
->elems
[index
];
784 b
= ve
[n
].vertex_buffer_index
;
785 context
->stream_usage_mask
|= 1 << b
;
786 /* XXX wine just uses 1 here: */
787 if (context
->stream_freq
[b
] & D3DSTREAMSOURCE_INSTANCEDATA
)
788 ve
[n
].instance_divisor
= context
->stream_freq
[b
] & 0x7FFFFF;
790 /* if the vertex declaration is incomplete compared to what the
791 * vertex shader needs, we bind a dummy vbo with 0 0 0 0.
792 * This is not precised by the spec, but is the behaviour
794 ve
[n
].vertex_buffer_index
= dummy_vbo_stream
;
795 ve
[n
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
796 ve
[n
].src_offset
= 0;
797 ve
[n
].instance_divisor
= 0;
801 if (context
->dummy_vbo_bound_at
!= dummy_vbo_stream
) {
802 if (context
->dummy_vbo_bound_at
>= 0)
803 context
->changed
.vtxbuf
|= 1 << context
->dummy_vbo_bound_at
;
804 if (dummy_vbo_stream
>= 0) {
805 context
->changed
.vtxbuf
|= 1 << dummy_vbo_stream
;
806 context
->vbo_bound_done
= FALSE
;
808 context
->dummy_vbo_bound_at
= dummy_vbo_stream
;
811 cso_set_vertex_elements(context
->cso
, vs
->num_inputs
, ve
);
815 update_vertex_buffers(struct NineDevice9
*device
)
817 struct nine_context
*context
= &device
->context
;
818 struct pipe_context
*pipe
= context
->pipe
;
819 struct pipe_vertex_buffer dummy_vtxbuf
;
820 uint32_t mask
= context
->changed
.vtxbuf
;
823 DBG("mask=%x\n", mask
);
825 if (context
->dummy_vbo_bound_at
>= 0) {
826 if (!context
->vbo_bound_done
) {
827 dummy_vtxbuf
.buffer
.resource
= device
->dummy_vbo
;
828 dummy_vtxbuf
.stride
= 0;
829 dummy_vtxbuf
.is_user_buffer
= false;
830 dummy_vtxbuf
.buffer_offset
= 0;
831 pipe
->set_vertex_buffers(pipe
, context
->dummy_vbo_bound_at
,
833 context
->vbo_bound_done
= TRUE
;
835 mask
&= ~(1 << context
->dummy_vbo_bound_at
);
838 for (i
= 0; mask
; mask
>>= 1, ++i
) {
840 if (context
->vtxbuf
[i
].buffer
.resource
)
841 pipe
->set_vertex_buffers(pipe
, i
, 1, &context
->vtxbuf
[i
]);
843 pipe
->set_vertex_buffers(pipe
, i
, 1, NULL
);
847 context
->changed
.vtxbuf
= 0;
850 static inline boolean
851 update_sampler_derived(struct nine_context
*context
, unsigned s
)
853 boolean changed
= FALSE
;
855 if (context
->samp
[s
][NINED3DSAMP_SHADOW
] != context
->texture
[s
].shadow
) {
857 context
->samp
[s
][NINED3DSAMP_SHADOW
] = context
->texture
[s
].shadow
;
860 if (context
->samp
[s
][NINED3DSAMP_CUBETEX
] !=
861 (context
->texture
[s
].type
== D3DRTYPE_CUBETEXTURE
)) {
863 context
->samp
[s
][NINED3DSAMP_CUBETEX
] =
864 context
->texture
[s
].type
== D3DRTYPE_CUBETEXTURE
;
867 if (context
->samp
[s
][D3DSAMP_MIPFILTER
] != D3DTEXF_NONE
) {
868 int lod
= context
->samp
[s
][D3DSAMP_MAXMIPLEVEL
] - context
->texture
[s
].lod
;
871 if (context
->samp
[s
][NINED3DSAMP_MINLOD
] != lod
) {
873 context
->samp
[s
][NINED3DSAMP_MINLOD
] = lod
;
876 context
->changed
.sampler
[s
] &= ~0x300; /* lod changes irrelevant */
882 /* TODO: add sRGB override to pipe_sampler_state ? */
884 update_textures_and_samplers(struct NineDevice9
*device
)
886 struct nine_context
*context
= &device
->context
;
887 struct pipe_sampler_view
*view
[NINE_MAX_SAMPLERS
];
888 unsigned num_textures
;
890 boolean commit_samplers
;
891 uint16_t sampler_mask
= context
->ps
? context
->ps
->sampler_mask
:
892 device
->ff
.ps
->sampler_mask
;
894 /* TODO: Can we reduce iterations here ? */
896 commit_samplers
= FALSE
;
897 context
->bound_samplers_mask_ps
= 0;
898 for (num_textures
= 0, i
= 0; i
< NINE_MAX_SAMPLERS_PS
; ++i
) {
899 const unsigned s
= NINE_SAMPLER_PS(i
);
902 if (!context
->texture
[s
].enabled
&& !(sampler_mask
& (1 << i
))) {
907 if (context
->texture
[s
].enabled
) {
908 sRGB
= context
->samp
[s
][D3DSAMP_SRGBTEXTURE
] ? 1 : 0;
910 view
[i
] = context
->texture
[s
].view
[sRGB
];
911 num_textures
= i
+ 1;
913 if (update_sampler_derived(context
, s
) || (context
->changed
.sampler
[s
] & 0x05fe)) {
914 context
->changed
.sampler
[s
] = 0;
915 commit_samplers
= TRUE
;
916 nine_convert_sampler_state(context
->cso
, s
, context
->samp
[s
]);
919 /* Bind dummy sampler. We do not bind dummy sampler when
920 * it is not needed because it could add overhead. The
921 * dummy sampler should have r=g=b=0 and a=1. We do not
922 * unbind dummy sampler directly when they are not needed
923 * anymore, but they're going to be removed as long as texture
924 * or sampler states are changed. */
925 view
[i
] = device
->dummy_sampler_view
;
926 num_textures
= i
+ 1;
928 cso_single_sampler(context
->cso
, PIPE_SHADER_FRAGMENT
,
929 s
- NINE_SAMPLER_PS(0), &device
->dummy_sampler_state
);
931 commit_samplers
= TRUE
;
932 context
->changed
.sampler
[s
] = ~0;
935 context
->bound_samplers_mask_ps
|= (1 << s
);
938 cso_set_sampler_views(context
->cso
, PIPE_SHADER_FRAGMENT
, num_textures
, view
);
941 cso_single_sampler_done(context
->cso
, PIPE_SHADER_FRAGMENT
);
943 commit_samplers
= FALSE
;
944 sampler_mask
= context
->programmable_vs
? context
->vs
->sampler_mask
: 0;
945 context
->bound_samplers_mask_vs
= 0;
946 for (num_textures
= 0, i
= 0; i
< NINE_MAX_SAMPLERS_VS
; ++i
) {
947 const unsigned s
= NINE_SAMPLER_VS(i
);
950 if (!context
->texture
[s
].enabled
&& !(sampler_mask
& (1 << i
))) {
955 if (context
->texture
[s
].enabled
) {
956 sRGB
= context
->samp
[s
][D3DSAMP_SRGBTEXTURE
] ? 1 : 0;
958 view
[i
] = context
->texture
[s
].view
[sRGB
];
959 num_textures
= i
+ 1;
961 if (update_sampler_derived(context
, s
) || (context
->changed
.sampler
[s
] & 0x05fe)) {
962 context
->changed
.sampler
[s
] = 0;
963 commit_samplers
= TRUE
;
964 nine_convert_sampler_state(context
->cso
, s
, context
->samp
[s
]);
967 /* Bind dummy sampler. We do not bind dummy sampler when
968 * it is not needed because it could add overhead. The
969 * dummy sampler should have r=g=b=0 and a=1. We do not
970 * unbind dummy sampler directly when they are not needed
971 * anymore, but they're going to be removed as long as texture
972 * or sampler states are changed. */
973 view
[i
] = device
->dummy_sampler_view
;
974 num_textures
= i
+ 1;
976 cso_single_sampler(context
->cso
, PIPE_SHADER_VERTEX
,
977 s
- NINE_SAMPLER_VS(0), &device
->dummy_sampler_state
);
979 commit_samplers
= TRUE
;
980 context
->changed
.sampler
[s
] = ~0;
983 context
->bound_samplers_mask_vs
|= (1 << i
);
986 cso_set_sampler_views(context
->cso
, PIPE_SHADER_VERTEX
, num_textures
, view
);
989 cso_single_sampler_done(context
->cso
, PIPE_SHADER_VERTEX
);
992 /* State commit only */
995 commit_blend(struct NineDevice9
*device
)
997 struct nine_context
*context
= &device
->context
;
999 cso_set_blend(context
->cso
, &context
->pipe_data
.blend
);
1003 commit_dsa(struct NineDevice9
*device
)
1005 struct nine_context
*context
= &device
->context
;
1007 cso_set_depth_stencil_alpha(context
->cso
, &context
->pipe_data
.dsa
);
1011 commit_scissor(struct NineDevice9
*device
)
1013 struct nine_context
*context
= &device
->context
;
1014 struct pipe_context
*pipe
= context
->pipe
;
1016 pipe
->set_scissor_states(pipe
, 0, 1, &context
->scissor
);
1020 commit_rasterizer(struct NineDevice9
*device
)
1022 struct nine_context
*context
= &device
->context
;
1024 cso_set_rasterizer(context
->cso
, &context
->pipe_data
.rast
);
1028 commit_vs_constants(struct NineDevice9
*device
)
1030 struct nine_context
*context
= &device
->context
;
1031 struct pipe_context
*pipe
= context
->pipe
;
1033 if (unlikely(!context
->programmable_vs
))
1034 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &context
->pipe_data
.cb_vs_ff
);
1036 if (context
->swvp
) {
1037 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &context
->pipe_data
.cb0_swvp
);
1038 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 1, &context
->pipe_data
.cb1_swvp
);
1039 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 2, &context
->pipe_data
.cb2_swvp
);
1040 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 3, &context
->pipe_data
.cb3_swvp
);
1042 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_VERTEX
, 0, &context
->pipe_data
.cb_vs
);
1048 commit_ps_constants(struct NineDevice9
*device
)
1050 struct nine_context
*context
= &device
->context
;
1051 struct pipe_context
*pipe
= context
->pipe
;
1053 if (unlikely(!context
->ps
))
1054 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &context
->pipe_data
.cb_ps_ff
);
1056 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, 0, &context
->pipe_data
.cb_ps
);
1060 commit_vs(struct NineDevice9
*device
)
1062 struct nine_context
*context
= &device
->context
;
1064 context
->pipe
->bind_vs_state(context
->pipe
, context
->cso_shader
.vs
);
1069 commit_ps(struct NineDevice9
*device
)
1071 struct nine_context
*context
= &device
->context
;
1073 context
->pipe
->bind_fs_state(context
->pipe
, context
->cso_shader
.ps
);
1077 #define NINE_STATE_SHADER_CHANGE_VS \
1079 NINE_STATE_TEXTURE | \
1080 NINE_STATE_VS_PARAMS_MISC | \
1083 #define NINE_STATE_SHADER_CHANGE_PS \
1085 NINE_STATE_TEXTURE | \
1086 NINE_STATE_PS_PARAMS_MISC)
1088 #define NINE_STATE_FREQUENT \
1089 (NINE_STATE_RASTERIZER | \
1090 NINE_STATE_TEXTURE | \
1091 NINE_STATE_SAMPLER | \
1092 NINE_STATE_VS_CONST | \
1093 NINE_STATE_PS_CONST | \
1094 NINE_STATE_MULTISAMPLE)
1096 #define NINE_STATE_COMMON \
1098 NINE_STATE_BLEND | \
1100 NINE_STATE_VIEWPORT | \
1101 NINE_STATE_VDECL | \
1102 NINE_STATE_IDXBUF | \
1103 NINE_STATE_STREAMFREQ)
1105 #define NINE_STATE_RARE \
1106 (NINE_STATE_SCISSOR | \
1107 NINE_STATE_BLEND_COLOR | \
1108 NINE_STATE_STENCIL_REF | \
1109 NINE_STATE_SAMPLE_MASK)
1112 nine_update_state(struct NineDevice9
*device
)
1114 struct nine_context
*context
= &device
->context
;
1115 struct pipe_context
*pipe
= context
->pipe
;
1118 DBG("changed state groups: %x\n", context
->changed
.group
);
1120 /* NOTE: We may want to use the cso cache for everything, or let
1121 * NineDevice9.RestoreNonCSOState actually set the states, then we wouldn't
1122 * have to care about state being clobbered here and could merge this back
1123 * into update_textures. Except, we also need to re-validate textures that
1124 * may be dirty anyway, even if no texture bindings changed.
1127 /* ff_update may change VS/PS dirty bits */
1128 if (unlikely(!context
->programmable_vs
|| !context
->ps
))
1129 nine_ff_update(device
);
1130 group
= context
->changed
.group
;
1132 if (group
& (NINE_STATE_SHADER_CHANGE_VS
| NINE_STATE_SHADER_CHANGE_PS
)) {
1133 if (group
& NINE_STATE_SHADER_CHANGE_VS
)
1134 group
|= prepare_vs(device
, (group
& NINE_STATE_VS
) != 0); /* may set NINE_STATE_RASTERIZER and NINE_STATE_SAMPLER*/
1135 if (group
& NINE_STATE_SHADER_CHANGE_PS
)
1136 group
|= prepare_ps(device
, (group
& NINE_STATE_PS
) != 0);
1139 if (group
& (NINE_STATE_COMMON
| NINE_STATE_VS
)) {
1140 if (group
& NINE_STATE_FB
)
1141 update_framebuffer(device
, FALSE
);
1142 if (group
& NINE_STATE_BLEND
)
1143 prepare_blend(device
);
1144 if (group
& NINE_STATE_DSA
)
1145 prepare_dsa(device
);
1146 if (group
& NINE_STATE_VIEWPORT
)
1147 update_viewport(device
);
1148 if (group
& (NINE_STATE_VDECL
| NINE_STATE_VS
| NINE_STATE_STREAMFREQ
))
1149 update_vertex_elements(device
);
1152 if (likely(group
& (NINE_STATE_FREQUENT
| NINE_STATE_VS
| NINE_STATE_PS
| NINE_STATE_SWVP
))) {
1153 if (group
& NINE_STATE_MULTISAMPLE
)
1154 group
|= check_multisample(device
);
1155 if (group
& NINE_STATE_RASTERIZER
)
1156 prepare_rasterizer(device
);
1157 if (group
& (NINE_STATE_TEXTURE
| NINE_STATE_SAMPLER
))
1158 update_textures_and_samplers(device
);
1159 if ((group
& (NINE_STATE_VS_CONST
| NINE_STATE_VS
| NINE_STATE_SWVP
)) && context
->programmable_vs
)
1160 prepare_vs_constants_userbuf(device
);
1161 if ((group
& (NINE_STATE_PS_CONST
| NINE_STATE_PS
)) && context
->ps
)
1162 prepare_ps_constants_userbuf(device
);
1165 if (context
->changed
.vtxbuf
)
1166 update_vertex_buffers(device
);
1168 if (context
->commit
& NINE_STATE_COMMIT_BLEND
)
1169 commit_blend(device
);
1170 if (context
->commit
& NINE_STATE_COMMIT_DSA
)
1172 if (context
->commit
& NINE_STATE_COMMIT_RASTERIZER
)
1173 commit_rasterizer(device
);
1174 if (context
->commit
& NINE_STATE_COMMIT_CONST_VS
)
1175 commit_vs_constants(device
);
1176 if (context
->commit
& NINE_STATE_COMMIT_CONST_PS
)
1177 commit_ps_constants(device
);
1178 if (context
->commit
& NINE_STATE_COMMIT_VS
)
1180 if (context
->commit
& NINE_STATE_COMMIT_PS
)
1183 context
->commit
= 0;
1185 if (unlikely(context
->changed
.ucp
)) {
1186 pipe
->set_clip_state(pipe
, &context
->clip
);
1187 context
->changed
.ucp
= FALSE
;
1190 if (unlikely(group
& NINE_STATE_RARE
)) {
1191 if (group
& NINE_STATE_SCISSOR
)
1192 commit_scissor(device
);
1193 if (group
& NINE_STATE_BLEND_COLOR
) {
1194 struct pipe_blend_color color
;
1195 d3dcolor_to_rgba(&color
.color
[0], context
->rs
[D3DRS_BLENDFACTOR
]);
1196 pipe
->set_blend_color(pipe
, &color
);
1198 if (group
& NINE_STATE_SAMPLE_MASK
) {
1199 if (context
->rt
[0]->desc
.MultiSampleType
<= D3DMULTISAMPLE_NONMASKABLE
) {
1200 pipe
->set_sample_mask(pipe
, ~0);
1202 pipe
->set_sample_mask(pipe
, context
->rs
[D3DRS_MULTISAMPLEMASK
]);
1205 if (group
& NINE_STATE_STENCIL_REF
) {
1206 struct pipe_stencil_ref ref
;
1207 ref
.ref_value
[0] = context
->rs
[D3DRS_STENCILREF
];
1208 ref
.ref_value
[1] = ref
.ref_value
[0];
1209 pipe
->set_stencil_ref(pipe
, &ref
);
1213 context
->changed
.group
&=
1214 (NINE_STATE_FF
| NINE_STATE_VS_CONST
| NINE_STATE_PS_CONST
);
1219 #define RESZ_CODE 0x7fa05000
1222 NineDevice9_ResolveZ( struct NineDevice9
*device
)
1224 struct nine_context
*context
= &device
->context
;
1225 const struct util_format_description
*desc
;
1226 struct NineSurface9
*source
= context
->ds
;
1227 struct pipe_resource
*src
, *dst
;
1228 struct pipe_blit_info blit
;
1230 DBG("RESZ resolve\n");
1232 if (!source
|| !context
->texture
[0].enabled
||
1233 context
->texture
[0].type
!= D3DRTYPE_TEXTURE
)
1236 src
= source
->base
.resource
;
1237 dst
= context
->texture
[0].resource
;
1242 /* check dst is depth format. we know already for src */
1243 desc
= util_format_description(dst
->format
);
1244 if (desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
)
1247 memset(&blit
, 0, sizeof(blit
));
1248 blit
.src
.resource
= src
;
1250 blit
.src
.format
= src
->format
;
1252 blit
.src
.box
.depth
= 1;
1255 blit
.src
.box
.width
= src
->width0
;
1256 blit
.src
.box
.height
= src
->height0
;
1258 blit
.dst
.resource
= dst
;
1260 blit
.dst
.format
= dst
->format
;
1262 blit
.dst
.box
.depth
= 1;
1265 blit
.dst
.box
.width
= dst
->width0
;
1266 blit
.dst
.box
.height
= dst
->height0
;
1268 blit
.mask
= PIPE_MASK_ZS
;
1269 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1270 blit
.scissor_enable
= FALSE
;
1272 context
->pipe
->blit(context
->pipe
, &blit
);
1275 #define ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A', '2', 'M', '1')
1276 #define ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A', '2', 'M', '0')
1278 /* Nine_context functions.
1279 * Serialized through CSMT macros.
1283 nine_context_set_texture_apply(struct NineDevice9
*device
,
1288 D3DRESOURCETYPE type
,
1290 struct pipe_resource
*res
,
1291 struct pipe_sampler_view
*view0
,
1292 struct pipe_sampler_view
*view1
);
1294 nine_context_set_stream_source_apply(struct NineDevice9
*device
,
1296 struct pipe_resource
*res
,
1301 nine_context_set_indices_apply(struct NineDevice9
*device
,
1302 struct pipe_resource
*res
,
1304 UINT OffsetInBytes
);
1307 nine_context_set_pixel_shader_constant_i_transformed(struct NineDevice9
*device
,
1309 const int *pConstantData
,
1310 unsigned pConstantData_size
,
1311 UINT Vector4iCount
);
1313 CSMT_ITEM_NO_WAIT(nine_context_set_render_state
,
1314 ARG_VAL(D3DRENDERSTATETYPE
, State
),
1315 ARG_VAL(DWORD
, Value
))
1317 struct nine_context
*context
= &device
->context
;
1319 /* Amd hacks (equivalent to GL extensions) */
1320 if (unlikely(State
== D3DRS_POINTSIZE
)) {
1321 if (Value
== RESZ_CODE
) {
1322 NineDevice9_ResolveZ(device
);
1326 if (Value
== ALPHA_TO_COVERAGE_ENABLE
||
1327 Value
== ALPHA_TO_COVERAGE_DISABLE
) {
1328 context
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== ALPHA_TO_COVERAGE_ENABLE
);
1329 context
->changed
.group
|= NINE_STATE_BLEND
;
1335 if (unlikely(State
== D3DRS_ADAPTIVETESS_Y
)) {
1336 if (Value
== D3DFMT_ATOC
|| (Value
== D3DFMT_UNKNOWN
&& context
->rs
[NINED3DRS_ALPHACOVERAGE
])) {
1337 context
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
== D3DFMT_ATOC
) ? 3 : 0;
1338 context
->rs
[NINED3DRS_ALPHACOVERAGE
] &= context
->rs
[D3DRS_ALPHATESTENABLE
] ? 3 : 2;
1339 context
->changed
.group
|= NINE_STATE_BLEND
;
1343 if (unlikely(State
== D3DRS_ALPHATESTENABLE
&& (context
->rs
[NINED3DRS_ALPHACOVERAGE
] & 2))) {
1344 DWORD alphacoverage_prev
= context
->rs
[NINED3DRS_ALPHACOVERAGE
];
1345 context
->rs
[NINED3DRS_ALPHACOVERAGE
] = (Value
? 3 : 2);
1346 if (context
->rs
[NINED3DRS_ALPHACOVERAGE
] != alphacoverage_prev
)
1347 context
->changed
.group
|= NINE_STATE_BLEND
;
1350 context
->rs
[State
] = nine_fix_render_state_value(State
, Value
);
1351 context
->changed
.group
|= nine_render_state_group
[State
];
1354 CSMT_ITEM_NO_WAIT(nine_context_set_texture_apply
,
1355 ARG_VAL(DWORD
, stage
),
1356 ARG_VAL(BOOL
, enabled
),
1357 ARG_VAL(BOOL
, shadow
),
1358 ARG_VAL(DWORD
, lod
),
1359 ARG_VAL(D3DRESOURCETYPE
, type
),
1360 ARG_VAL(uint8_t, pstype
),
1361 ARG_BIND_RES(struct pipe_resource
, res
),
1362 ARG_BIND_VIEW(struct pipe_sampler_view
, view0
),
1363 ARG_BIND_VIEW(struct pipe_sampler_view
, view1
))
1365 struct nine_context
*context
= &device
->context
;
1367 context
->texture
[stage
].enabled
= enabled
;
1368 context
->samplers_shadow
&= ~(1 << stage
);
1369 context
->samplers_shadow
|= shadow
<< stage
;
1370 context
->texture
[stage
].shadow
= shadow
;
1371 context
->texture
[stage
].lod
= lod
;
1372 context
->texture
[stage
].type
= type
;
1373 context
->texture
[stage
].pstype
= pstype
;
1374 pipe_resource_reference(&context
->texture
[stage
].resource
, res
);
1375 pipe_sampler_view_reference(&context
->texture
[stage
].view
[0], view0
);
1376 pipe_sampler_view_reference(&context
->texture
[stage
].view
[1], view1
);
1378 context
->changed
.group
|= NINE_STATE_TEXTURE
;
1382 nine_context_set_texture(struct NineDevice9
*device
,
1384 struct NineBaseTexture9
*tex
)
1386 BOOL enabled
= FALSE
;
1387 BOOL shadow
= FALSE
;
1389 D3DRESOURCETYPE type
= D3DRTYPE_TEXTURE
;
1391 struct pipe_resource
*res
= NULL
;
1392 struct pipe_sampler_view
*view0
= NULL
, *view1
= NULL
;
1394 /* For managed pool, the data can be initially incomplete.
1395 * In that case, the texture is rebound later
1396 * (in NineBaseTexture9_Validate/NineBaseTexture9_UploadSelf). */
1397 if (tex
&& tex
->base
.resource
) {
1399 shadow
= tex
->shadow
;
1400 lod
= tex
->managed
.lod
;
1401 type
= tex
->base
.type
;
1402 pstype
= tex
->pstype
;
1403 res
= tex
->base
.resource
;
1404 view0
= NineBaseTexture9_GetSamplerView(tex
, 0);
1405 view1
= NineBaseTexture9_GetSamplerView(tex
, 1);
1408 nine_context_set_texture_apply(device
, Stage
, enabled
,
1409 shadow
, lod
, type
, pstype
,
1413 CSMT_ITEM_NO_WAIT(nine_context_set_sampler_state
,
1414 ARG_VAL(DWORD
, Sampler
),
1415 ARG_VAL(D3DSAMPLERSTATETYPE
, Type
),
1416 ARG_VAL(DWORD
, Value
))
1418 struct nine_context
*context
= &device
->context
;
1420 if (unlikely(!nine_check_sampler_state_value(Type
, Value
)))
1423 context
->samp
[Sampler
][Type
] = Value
;
1424 context
->changed
.group
|= NINE_STATE_SAMPLER
;
1425 context
->changed
.sampler
[Sampler
] |= 1 << Type
;
1428 CSMT_ITEM_NO_WAIT(nine_context_set_stream_source_apply
,
1429 ARG_VAL(UINT
, StreamNumber
),
1430 ARG_BIND_RES(struct pipe_resource
, res
),
1431 ARG_VAL(UINT
, OffsetInBytes
),
1432 ARG_VAL(UINT
, Stride
))
1434 struct nine_context
*context
= &device
->context
;
1435 const unsigned i
= StreamNumber
;
1437 context
->vtxbuf
[i
].stride
= Stride
;
1438 context
->vtxbuf
[i
].buffer_offset
= OffsetInBytes
;
1439 pipe_resource_reference(&context
->vtxbuf
[i
].buffer
.resource
, res
);
1441 context
->changed
.vtxbuf
|= 1 << StreamNumber
;
1445 nine_context_set_stream_source(struct NineDevice9
*device
,
1447 struct NineVertexBuffer9
*pVBuf9
,
1451 struct pipe_resource
*res
= NULL
;
1452 unsigned offset
= 0;
1455 res
= NineVertexBuffer9_GetResource(pVBuf9
, &offset
);
1456 /* in the future when there is internal offset, add it
1457 * to OffsetInBytes */
1459 nine_context_set_stream_source_apply(device
, StreamNumber
,
1460 res
, offset
+ OffsetInBytes
,
1464 CSMT_ITEM_NO_WAIT(nine_context_set_stream_source_freq
,
1465 ARG_VAL(UINT
, StreamNumber
),
1466 ARG_VAL(UINT
, Setting
))
1468 struct nine_context
*context
= &device
->context
;
1470 context
->stream_freq
[StreamNumber
] = Setting
;
1472 if (Setting
& D3DSTREAMSOURCE_INSTANCEDATA
)
1473 context
->stream_instancedata_mask
|= 1 << StreamNumber
;
1475 context
->stream_instancedata_mask
&= ~(1 << StreamNumber
);
1477 if (StreamNumber
!= 0)
1478 context
->changed
.group
|= NINE_STATE_STREAMFREQ
;
1481 CSMT_ITEM_NO_WAIT(nine_context_set_indices_apply
,
1482 ARG_BIND_RES(struct pipe_resource
, res
),
1483 ARG_VAL(UINT
, IndexSize
),
1484 ARG_VAL(UINT
, OffsetInBytes
))
1486 struct nine_context
*context
= &device
->context
;
1488 context
->index_size
= IndexSize
;
1489 context
->index_offset
= OffsetInBytes
;
1490 pipe_resource_reference(&context
->idxbuf
, res
);
1492 context
->changed
.group
|= NINE_STATE_IDXBUF
;
1496 nine_context_set_indices(struct NineDevice9
*device
,
1497 struct NineIndexBuffer9
*idxbuf
)
1499 struct pipe_resource
*res
= NULL
;
1501 unsigned OffsetInBytes
= 0;
1504 res
= NineIndexBuffer9_GetBuffer(idxbuf
, &OffsetInBytes
);
1505 IndexSize
= idxbuf
->index_size
;
1508 nine_context_set_indices_apply(device
, res
, IndexSize
, OffsetInBytes
);
1511 CSMT_ITEM_NO_WAIT(nine_context_set_vertex_declaration
,
1512 ARG_BIND_REF(struct NineVertexDeclaration9
, vdecl
))
1514 struct nine_context
*context
= &device
->context
;
1515 BOOL was_programmable_vs
= context
->programmable_vs
;
1517 nine_bind(&context
->vdecl
, vdecl
);
1519 context
->programmable_vs
= context
->vs
&& !(context
->vdecl
&& context
->vdecl
->position_t
);
1520 if (was_programmable_vs
!= context
->programmable_vs
) {
1521 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
1522 context
->changed
.group
|= NINE_STATE_VS
;
1525 context
->changed
.group
|= NINE_STATE_VDECL
;
1528 CSMT_ITEM_NO_WAIT(nine_context_set_vertex_shader
,
1529 ARG_BIND_REF(struct NineVertexShader9
, pShader
))
1531 struct nine_context
*context
= &device
->context
;
1532 BOOL was_programmable_vs
= context
->programmable_vs
;
1534 nine_bind(&context
->vs
, pShader
);
1536 context
->programmable_vs
= context
->vs
&& !(context
->vdecl
&& context
->vdecl
->position_t
);
1538 /* ff -> non-ff: commit back non-ff constants */
1539 if (!was_programmable_vs
&& context
->programmable_vs
)
1540 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
;
1542 context
->changed
.group
|= NINE_STATE_VS
;
1545 CSMT_ITEM_NO_WAIT(nine_context_set_vertex_shader_constant_f
,
1546 ARG_VAL(UINT
, StartRegister
),
1547 ARG_MEM(float, pConstantData
),
1548 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1549 ARG_VAL(UINT
, Vector4fCount
))
1551 struct nine_context
*context
= &device
->context
;
1552 float *vs_const_f
= device
->may_swvp
? context
->vs_const_f_swvp
: context
->vs_const_f
;
1554 memcpy(&vs_const_f
[StartRegister
* 4],
1556 pConstantData_size
);
1558 if (device
->may_swvp
) {
1559 Vector4fCount
= MIN2(StartRegister
+ Vector4fCount
, NINE_MAX_CONST_F
) - StartRegister
;
1560 if (StartRegister
< NINE_MAX_CONST_F
)
1561 memcpy(&context
->vs_const_f
[StartRegister
* 4],
1563 Vector4fCount
* 4 * sizeof(context
->vs_const_f
[0]));
1566 context
->changed
.vs_const_f
= TRUE
;
1567 context
->changed
.group
|= NINE_STATE_VS_CONST
;
1570 CSMT_ITEM_NO_WAIT(nine_context_set_vertex_shader_constant_i
,
1571 ARG_VAL(UINT
, StartRegister
),
1572 ARG_MEM(int, pConstantData
),
1573 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1574 ARG_VAL(UINT
, Vector4iCount
))
1576 struct nine_context
*context
= &device
->context
;
1579 if (device
->driver_caps
.vs_integer
) {
1580 memcpy(&context
->vs_const_i
[4 * StartRegister
],
1582 pConstantData_size
);
1584 for (i
= 0; i
< Vector4iCount
; i
++) {
1585 context
->vs_const_i
[4 * (StartRegister
+ i
)] = fui((float)(pConstantData
[4 * i
]));
1586 context
->vs_const_i
[4 * (StartRegister
+ i
) + 1] = fui((float)(pConstantData
[4 * i
+ 1]));
1587 context
->vs_const_i
[4 * (StartRegister
+ i
) + 2] = fui((float)(pConstantData
[4 * i
+ 2]));
1588 context
->vs_const_i
[4 * (StartRegister
+ i
) + 3] = fui((float)(pConstantData
[4 * i
+ 3]));
1592 context
->changed
.vs_const_i
= TRUE
;
1593 context
->changed
.group
|= NINE_STATE_VS_CONST
;
1596 CSMT_ITEM_NO_WAIT(nine_context_set_vertex_shader_constant_b
,
1597 ARG_VAL(UINT
, StartRegister
),
1598 ARG_MEM(BOOL
, pConstantData
),
1599 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1600 ARG_VAL(UINT
, BoolCount
))
1602 struct nine_context
*context
= &device
->context
;
1604 uint32_t bool_true
= device
->driver_caps
.vs_integer
? 0xFFFFFFFF : fui(1.0f
);
1606 (void) pConstantData_size
;
1608 for (i
= 0; i
< BoolCount
; i
++)
1609 context
->vs_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
1611 context
->changed
.vs_const_b
= TRUE
;
1612 context
->changed
.group
|= NINE_STATE_VS_CONST
;
1615 CSMT_ITEM_NO_WAIT(nine_context_set_pixel_shader
,
1616 ARG_BIND_REF(struct NinePixelShader9
, ps
))
1618 struct nine_context
*context
= &device
->context
;
1619 unsigned old_mask
= context
->ps
? context
->ps
->rt_mask
: 1;
1622 /* ff -> non-ff: commit back non-ff constants */
1623 if (!context
->ps
&& ps
)
1624 context
->commit
|= NINE_STATE_COMMIT_CONST_PS
;
1626 nine_bind(&context
->ps
, ps
);
1628 context
->changed
.group
|= NINE_STATE_PS
;
1630 mask
= context
->ps
? context
->ps
->rt_mask
: 1;
1631 /* We need to update cbufs if the pixel shader would
1632 * write to different render targets */
1633 if (mask
!= old_mask
)
1634 context
->changed
.group
|= NINE_STATE_FB
;
1637 CSMT_ITEM_NO_WAIT(nine_context_set_pixel_shader_constant_f
,
1638 ARG_VAL(UINT
, StartRegister
),
1639 ARG_MEM(float, pConstantData
),
1640 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1641 ARG_VAL(UINT
, Vector4fCount
))
1643 struct nine_context
*context
= &device
->context
;
1645 memcpy(&context
->ps_const_f
[StartRegister
* 4],
1647 pConstantData_size
);
1649 context
->changed
.ps_const_f
= TRUE
;
1650 context
->changed
.group
|= NINE_STATE_PS_CONST
;
1653 /* For stateblocks */
1654 CSMT_ITEM_NO_WAIT(nine_context_set_pixel_shader_constant_i_transformed
,
1655 ARG_VAL(UINT
, StartRegister
),
1656 ARG_MEM(int, pConstantData
),
1657 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1658 ARG_VAL(UINT
, Vector4iCount
))
1660 struct nine_context
*context
= &device
->context
;
1662 memcpy(&context
->ps_const_i
[StartRegister
][0],
1664 Vector4iCount
* sizeof(context
->ps_const_i
[0]));
1666 context
->changed
.ps_const_i
= TRUE
;
1667 context
->changed
.group
|= NINE_STATE_PS_CONST
;
1670 CSMT_ITEM_NO_WAIT(nine_context_set_pixel_shader_constant_i
,
1671 ARG_VAL(UINT
, StartRegister
),
1672 ARG_MEM(int, pConstantData
),
1673 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1674 ARG_VAL(UINT
, Vector4iCount
))
1676 struct nine_context
*context
= &device
->context
;
1679 if (device
->driver_caps
.ps_integer
) {
1680 memcpy(&context
->ps_const_i
[StartRegister
][0],
1682 pConstantData_size
);
1684 for (i
= 0; i
< Vector4iCount
; i
++) {
1685 context
->ps_const_i
[StartRegister
+i
][0] = fui((float)(pConstantData
[4*i
]));
1686 context
->ps_const_i
[StartRegister
+i
][1] = fui((float)(pConstantData
[4*i
+1]));
1687 context
->ps_const_i
[StartRegister
+i
][2] = fui((float)(pConstantData
[4*i
+2]));
1688 context
->ps_const_i
[StartRegister
+i
][3] = fui((float)(pConstantData
[4*i
+3]));
1691 context
->changed
.ps_const_i
= TRUE
;
1692 context
->changed
.group
|= NINE_STATE_PS_CONST
;
1695 CSMT_ITEM_NO_WAIT(nine_context_set_pixel_shader_constant_b
,
1696 ARG_VAL(UINT
, StartRegister
),
1697 ARG_MEM(BOOL
, pConstantData
),
1698 ARG_MEM_SIZE(unsigned, pConstantData_size
),
1699 ARG_VAL(UINT
, BoolCount
))
1701 struct nine_context
*context
= &device
->context
;
1703 uint32_t bool_true
= device
->driver_caps
.ps_integer
? 0xFFFFFFFF : fui(1.0f
);
1705 (void) pConstantData_size
;
1707 for (i
= 0; i
< BoolCount
; i
++)
1708 context
->ps_const_b
[StartRegister
+ i
] = pConstantData
[i
] ? bool_true
: 0;
1710 context
->changed
.ps_const_b
= TRUE
;
1711 context
->changed
.group
|= NINE_STATE_PS_CONST
;
1714 /* XXX: use resource, as resource might change */
1715 CSMT_ITEM_NO_WAIT(nine_context_set_render_target
,
1716 ARG_VAL(DWORD
, RenderTargetIndex
),
1717 ARG_BIND_REF(struct NineSurface9
, rt
))
1719 struct nine_context
*context
= &device
->context
;
1720 const unsigned i
= RenderTargetIndex
;
1723 context
->viewport
.X
= 0;
1724 context
->viewport
.Y
= 0;
1725 context
->viewport
.Width
= rt
->desc
.Width
;
1726 context
->viewport
.Height
= rt
->desc
.Height
;
1727 context
->viewport
.MinZ
= 0.0f
;
1728 context
->viewport
.MaxZ
= 1.0f
;
1730 context
->scissor
.minx
= 0;
1731 context
->scissor
.miny
= 0;
1732 context
->scissor
.maxx
= rt
->desc
.Width
;
1733 context
->scissor
.maxy
= rt
->desc
.Height
;
1735 context
->changed
.group
|= NINE_STATE_VIEWPORT
| NINE_STATE_SCISSOR
| NINE_STATE_MULTISAMPLE
;
1737 if (context
->rt
[0] &&
1738 (context
->rt
[0]->desc
.MultiSampleType
<= D3DMULTISAMPLE_NONMASKABLE
) !=
1739 (rt
->desc
.MultiSampleType
<= D3DMULTISAMPLE_NONMASKABLE
))
1740 context
->changed
.group
|= NINE_STATE_SAMPLE_MASK
;
1743 if (context
->rt
[i
] != rt
) {
1744 nine_bind(&context
->rt
[i
], rt
);
1745 context
->changed
.group
|= NINE_STATE_FB
;
1749 /* XXX: use resource instead of ds, as resource might change */
1750 CSMT_ITEM_NO_WAIT(nine_context_set_depth_stencil
,
1751 ARG_BIND_REF(struct NineSurface9
, ds
))
1753 struct nine_context
*context
= &device
->context
;
1755 nine_bind(&context
->ds
, ds
);
1756 context
->changed
.group
|= NINE_STATE_FB
;
1759 CSMT_ITEM_NO_WAIT(nine_context_set_viewport
,
1760 ARG_COPY_REF(D3DVIEWPORT9
, viewport
))
1762 struct nine_context
*context
= &device
->context
;
1764 context
->viewport
= *viewport
;
1765 context
->changed
.group
|= NINE_STATE_VIEWPORT
;
1768 CSMT_ITEM_NO_WAIT(nine_context_set_scissor
,
1769 ARG_COPY_REF(struct pipe_scissor_state
, scissor
))
1771 struct nine_context
*context
= &device
->context
;
1773 context
->scissor
= *scissor
;
1774 context
->changed
.group
|= NINE_STATE_SCISSOR
;
1777 CSMT_ITEM_NO_WAIT(nine_context_set_transform
,
1778 ARG_VAL(D3DTRANSFORMSTATETYPE
, State
),
1779 ARG_COPY_REF(D3DMATRIX
, pMatrix
))
1781 struct nine_context
*context
= &device
->context
;
1782 D3DMATRIX
*M
= nine_state_access_transform(&context
->ff
, State
, TRUE
);
1785 context
->ff
.changed
.transform
[State
/ 32] |= 1 << (State
% 32);
1786 context
->changed
.group
|= NINE_STATE_FF
;
1789 CSMT_ITEM_NO_WAIT(nine_context_set_material
,
1790 ARG_COPY_REF(D3DMATERIAL9
, pMaterial
))
1792 struct nine_context
*context
= &device
->context
;
1794 context
->ff
.material
= *pMaterial
;
1795 context
->changed
.group
|= NINE_STATE_FF_MATERIAL
;
1798 CSMT_ITEM_NO_WAIT(nine_context_set_light
,
1799 ARG_VAL(DWORD
, Index
),
1800 ARG_COPY_REF(D3DLIGHT9
, pLight
))
1802 struct nine_context
*context
= &device
->context
;
1804 (void)nine_state_set_light(&context
->ff
, Index
, pLight
);
1805 context
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
1809 /* For stateblocks */
1811 nine_context_light_enable_stateblock(struct NineDevice9
*device
,
1812 const uint16_t active_light
[NINE_MAX_LIGHTS_ACTIVE
], /* TODO: use pointer that convey size for csmt */
1813 unsigned int num_lights_active
)
1815 struct nine_context
*context
= &device
->context
;
1817 /* TODO: Use CSMT_* to avoid calling nine_csmt_process */
1818 nine_csmt_process(device
);
1819 memcpy(context
->ff
.active_light
, active_light
, NINE_MAX_LIGHTS_ACTIVE
* sizeof(context
->ff
.active_light
[0]));
1820 context
->ff
.num_lights_active
= num_lights_active
;
1821 context
->changed
.group
|= NINE_STATE_FF_LIGHTING
;
1824 CSMT_ITEM_NO_WAIT(nine_context_light_enable
,
1825 ARG_VAL(DWORD
, Index
),
1826 ARG_VAL(BOOL
, Enable
))
1828 struct nine_context
*context
= &device
->context
;
1830 nine_state_light_enable(&context
->ff
, &context
->changed
.group
, Index
, Enable
);
1833 CSMT_ITEM_NO_WAIT(nine_context_set_texture_stage_state
,
1834 ARG_VAL(DWORD
, Stage
),
1835 ARG_VAL(D3DTEXTURESTAGESTATETYPE
, Type
),
1836 ARG_VAL(DWORD
, Value
))
1838 struct nine_context
*context
= &device
->context
;
1839 int bumpmap_index
= -1;
1841 context
->ff
.tex_stage
[Stage
][Type
] = Value
;
1843 case D3DTSS_BUMPENVMAT00
:
1844 bumpmap_index
= 4 * Stage
;
1846 case D3DTSS_BUMPENVMAT01
:
1847 bumpmap_index
= 4 * Stage
+ 1;
1849 case D3DTSS_BUMPENVMAT10
:
1850 bumpmap_index
= 4 * Stage
+ 2;
1852 case D3DTSS_BUMPENVMAT11
:
1853 bumpmap_index
= 4 * Stage
+ 3;
1855 case D3DTSS_BUMPENVLSCALE
:
1856 bumpmap_index
= 4 * 8 + 2 * Stage
;
1858 case D3DTSS_BUMPENVLOFFSET
:
1859 bumpmap_index
= 4 * 8 + 2 * Stage
+ 1;
1861 case D3DTSS_TEXTURETRANSFORMFLAGS
:
1862 context
->changed
.group
|= NINE_STATE_PS_PARAMS_MISC
;
1868 if (bumpmap_index
>= 0) {
1869 context
->bumpmap_vars
[bumpmap_index
] = Value
;
1870 context
->changed
.group
|= NINE_STATE_PS_CONST
;
1873 context
->changed
.group
|= NINE_STATE_FF_PS_CONSTS
;
1874 context
->ff
.changed
.tex_stage
[Stage
][Type
/ 32] |= 1 << (Type
% 32);
1877 CSMT_ITEM_NO_WAIT(nine_context_set_clip_plane
,
1878 ARG_VAL(DWORD
, Index
),
1879 ARG_COPY_REF(struct nine_clipplane
, pPlane
))
1881 struct nine_context
*context
= &device
->context
;
1883 memcpy(&context
->clip
.ucp
[Index
][0], pPlane
, sizeof(context
->clip
.ucp
[0]));
1884 context
->changed
.ucp
= TRUE
;
1887 CSMT_ITEM_NO_WAIT(nine_context_set_swvp
,
1888 ARG_VAL(boolean
, swvp
))
1890 struct nine_context
*context
= &device
->context
;
1892 context
->swvp
= swvp
;
1893 context
->changed
.group
|= NINE_STATE_SWVP
;
1896 /* Do not write to nine_context directly. Slower,
1897 * but works with csmt. TODO: write a special csmt version that
1898 * would record the list of commands as much as possible,
1899 * and use the version above else.
1902 nine_context_apply_stateblock(struct NineDevice9
*device
,
1903 const struct nine_state
*src
)
1907 /* No need to apply src->changed.group, since all calls do
1908 * set context->changed.group */
1910 for (i
= 0; i
< ARRAY_SIZE(src
->changed
.rs
); ++i
) {
1911 uint32_t m
= src
->changed
.rs
[i
];
1913 const int r
= ffs(m
) - 1;
1915 nine_context_set_render_state(device
, i
* 32 + r
, src
->rs_advertised
[i
* 32 + r
]);
1920 if (src
->changed
.texture
) {
1921 uint32_t m
= src
->changed
.texture
;
1924 for (s
= 0; m
; ++s
, m
>>= 1) {
1925 struct NineBaseTexture9
*tex
= src
->texture
[s
];
1928 nine_context_set_texture(device
, s
, tex
);
1933 if (src
->changed
.group
& NINE_STATE_SAMPLER
) {
1936 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
) {
1937 uint32_t m
= src
->changed
.sampler
[s
];
1939 const int i
= ffs(m
) - 1;
1941 nine_context_set_sampler_state(device
, s
, i
, src
->samp_advertised
[s
][i
]);
1946 /* Vertex buffers */
1947 if (src
->changed
.vtxbuf
| src
->changed
.stream_freq
) {
1948 uint32_t m
= src
->changed
.vtxbuf
| src
->changed
.stream_freq
;
1949 for (i
= 0; m
; ++i
, m
>>= 1) {
1950 if (src
->changed
.vtxbuf
& (1 << i
))
1951 nine_context_set_stream_source(device
, i
, src
->stream
[i
], src
->vtxbuf
[i
].buffer_offset
, src
->vtxbuf
[i
].stride
);
1952 if (src
->changed
.stream_freq
& (1 << i
))
1953 nine_context_set_stream_source_freq(device
, i
, src
->stream_freq
[i
]);
1958 if (src
->changed
.group
& NINE_STATE_IDXBUF
)
1959 nine_context_set_indices(device
, src
->idxbuf
);
1961 /* Vertex declaration */
1962 if ((src
->changed
.group
& NINE_STATE_VDECL
) && src
->vdecl
)
1963 nine_context_set_vertex_declaration(device
, src
->vdecl
);
1966 if (src
->changed
.group
& NINE_STATE_VS
)
1967 nine_context_set_vertex_shader(device
, src
->vs
);
1970 if (src
->changed
.group
& NINE_STATE_PS
)
1971 nine_context_set_pixel_shader(device
, src
->ps
);
1973 /* Vertex constants */
1974 if (src
->changed
.group
& NINE_STATE_VS_CONST
) {
1975 struct nine_range
*r
;
1976 for (r
= src
->changed
.vs_const_f
; r
; r
= r
->next
)
1977 nine_context_set_vertex_shader_constant_f(device
, r
->bgn
,
1978 &src
->vs_const_f
[r
->bgn
* 4],
1979 sizeof(float[4]) * (r
->end
- r
->bgn
),
1981 for (r
= src
->changed
.vs_const_i
; r
; r
= r
->next
)
1982 nine_context_set_vertex_shader_constant_i(device
, r
->bgn
,
1983 &src
->vs_const_i
[r
->bgn
* 4],
1984 sizeof(int[4]) * (r
->end
- r
->bgn
),
1986 for (r
= src
->changed
.vs_const_b
; r
; r
= r
->next
)
1987 nine_context_set_vertex_shader_constant_b(device
, r
->bgn
,
1988 &src
->vs_const_b
[r
->bgn
* 4],
1989 sizeof(BOOL
) * (r
->end
- r
->bgn
),
1993 /* Pixel constants */
1994 if (src
->changed
.group
& NINE_STATE_PS_CONST
) {
1995 struct nine_range
*r
;
1996 for (r
= src
->changed
.ps_const_f
; r
; r
= r
->next
)
1997 nine_context_set_pixel_shader_constant_f(device
, r
->bgn
,
1998 &src
->ps_const_f
[r
->bgn
* 4],
1999 sizeof(float[4]) * (r
->end
- r
->bgn
),
2001 if (src
->changed
.ps_const_i
) {
2002 uint16_t m
= src
->changed
.ps_const_i
;
2003 for (i
= ffs(m
) - 1, m
>>= i
; m
; ++i
, m
>>= 1)
2005 nine_context_set_pixel_shader_constant_i_transformed(device
, i
,
2006 src
->ps_const_i
[i
], sizeof(int[4]), 1);
2008 if (src
->changed
.ps_const_b
) {
2009 uint16_t m
= src
->changed
.ps_const_b
;
2010 for (i
= ffs(m
) - 1, m
>>= i
; m
; ++i
, m
>>= 1)
2012 nine_context_set_pixel_shader_constant_b(device
, i
,
2013 &src
->ps_const_b
[i
], sizeof(BOOL
), 1);
2018 if (src
->changed
.group
& NINE_STATE_VIEWPORT
)
2019 nine_context_set_viewport(device
, &src
->viewport
);
2022 if (src
->changed
.group
& NINE_STATE_SCISSOR
)
2023 nine_context_set_scissor(device
, &src
->scissor
);
2025 /* User Clip Planes */
2026 if (src
->changed
.ucp
)
2027 for (i
= 0; i
< PIPE_MAX_CLIP_PLANES
; ++i
)
2028 if (src
->changed
.ucp
& (1 << i
))
2029 nine_context_set_clip_plane(device
, i
, (struct nine_clipplane
*)&src
->clip
.ucp
[i
][0]);
2031 if (!(src
->changed
.group
& NINE_STATE_FF
))
2034 /* Fixed function state. */
2036 if (src
->changed
.group
& NINE_STATE_FF_MATERIAL
)
2037 nine_context_set_material(device
, &src
->ff
.material
);
2039 if (src
->changed
.group
& NINE_STATE_FF_PS_CONSTS
) {
2041 for (s
= 0; s
< NINE_MAX_TEXTURE_STAGES
; ++s
) {
2042 for (i
= 0; i
< NINED3DTSS_COUNT
; ++i
)
2043 if (src
->ff
.changed
.tex_stage
[s
][i
/ 32] & (1 << (i
% 32)))
2044 nine_context_set_texture_stage_state(device
, s
, i
, src
->ff
.tex_stage
[s
][i
]);
2047 if (src
->changed
.group
& NINE_STATE_FF_LIGHTING
) {
2048 for (i
= 0; i
< src
->ff
.num_lights
; ++i
)
2049 if (src
->ff
.light
[i
].Type
!= NINED3DLIGHT_INVALID
)
2050 nine_context_set_light(device
, i
, &src
->ff
.light
[i
]);
2052 nine_context_light_enable_stateblock(device
, src
->ff
.active_light
, src
->ff
.num_lights_active
);
2054 if (src
->changed
.group
& NINE_STATE_FF_VSTRANSF
) {
2055 for (i
= 0; i
< ARRAY_SIZE(src
->ff
.changed
.transform
); ++i
) {
2057 if (!src
->ff
.changed
.transform
[i
])
2059 for (s
= i
* 32; s
< (i
* 32 + 32); ++s
) {
2060 if (!(src
->ff
.changed
.transform
[i
] & (1 << (s
% 32))))
2062 nine_context_set_transform(device
, s
,
2063 nine_state_access_transform(
2064 (struct nine_ff_state
*)&src
->ff
,
2072 nine_update_state_framebuffer_clear(struct NineDevice9
*device
)
2074 struct nine_context
*context
= &device
->context
;
2076 if (context
->changed
.group
& NINE_STATE_FB
)
2077 update_framebuffer(device
, TRUE
);
2080 CSMT_ITEM_NO_WAIT(nine_context_clear_fb
,
2081 ARG_VAL(DWORD
, Count
),
2082 ARG_COPY_REF(D3DRECT
, pRects
),
2083 ARG_VAL(DWORD
, Flags
),
2084 ARG_VAL(D3DCOLOR
, Color
),
2086 ARG_VAL(DWORD
, Stencil
))
2088 struct nine_context
*context
= &device
->context
;
2089 const int sRGB
= context
->rs
[D3DRS_SRGBWRITEENABLE
] ? 1 : 0;
2090 struct pipe_surface
*cbuf
, *zsbuf
;
2091 struct pipe_context
*pipe
= context
->pipe
;
2092 struct NineSurface9
*zsbuf_surf
= context
->ds
;
2093 struct NineSurface9
*rt
;
2096 union pipe_color_union rgba
;
2097 unsigned rt_mask
= 0;
2100 nine_update_state_framebuffer_clear(device
);
2102 if (Flags
& D3DCLEAR_TARGET
) bufs
|= PIPE_CLEAR_COLOR
;
2103 /* Ignore Z buffer if not bound */
2104 if (context
->pipe_data
.fb
.zsbuf
!= NULL
) {
2105 if (Flags
& D3DCLEAR_ZBUFFER
) bufs
|= PIPE_CLEAR_DEPTH
;
2106 if (Flags
& D3DCLEAR_STENCIL
) bufs
|= PIPE_CLEAR_STENCIL
;
2110 d3dcolor_to_pipe_color_union(&rgba
, Color
);
2112 rect
.x1
= context
->viewport
.X
;
2113 rect
.y1
= context
->viewport
.Y
;
2114 rect
.x2
= context
->viewport
.Width
+ rect
.x1
;
2115 rect
.y2
= context
->viewport
.Height
+ rect
.y1
;
2117 /* Both rectangles apply, which is weird, but that's D3D9. */
2118 if (context
->rs
[D3DRS_SCISSORTESTENABLE
]) {
2119 rect
.x1
= MAX2(rect
.x1
, context
->scissor
.minx
);
2120 rect
.y1
= MAX2(rect
.y1
, context
->scissor
.miny
);
2121 rect
.x2
= MIN2(rect
.x2
, context
->scissor
.maxx
);
2122 rect
.y2
= MIN2(rect
.y2
, context
->scissor
.maxy
);
2126 /* Maybe apps like to specify a large rect ? */
2127 if (pRects
[0].x1
<= rect
.x1
&& pRects
[0].x2
>= rect
.x2
&&
2128 pRects
[0].y1
<= rect
.y1
&& pRects
[0].y2
>= rect
.y2
) {
2129 DBG("First rect covers viewport.\n");
2135 if (rect
.x1
>= context
->pipe_data
.fb
.width
|| rect
.y1
>= context
->pipe_data
.fb
.height
)
2138 for (i
= 0; i
< device
->caps
.NumSimultaneousRTs
; ++i
) {
2139 if (context
->rt
[i
] && context
->rt
[i
]->desc
.Format
!= D3DFMT_NULL
)
2143 /* fast path, clears everything at once */
2145 (!(bufs
& PIPE_CLEAR_COLOR
) || (rt_mask
== context
->rt_mask
)) &&
2146 rect
.x1
== 0 && rect
.y1
== 0 &&
2147 /* Case we clear only render target. Check clear region vs rt. */
2148 ((!(bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
2149 rect
.x2
>= context
->pipe_data
.fb
.width
&&
2150 rect
.y2
>= context
->pipe_data
.fb
.height
) ||
2151 /* Case we clear depth buffer (and eventually rt too).
2152 * depth buffer size is always >= rt size. Compare to clear region */
2153 ((bufs
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) &&
2154 rect
.x2
>= zsbuf_surf
->desc
.Width
&&
2155 rect
.y2
>= zsbuf_surf
->desc
.Height
))) {
2156 DBG("Clear fast path\n");
2157 pipe
->clear(pipe
, bufs
, &rgba
, Z
, Stencil
);
2166 for (i
= 0; i
< device
->caps
.NumSimultaneousRTs
; ++i
) {
2167 rt
= context
->rt
[i
];
2168 if (!rt
|| rt
->desc
.Format
== D3DFMT_NULL
||
2169 !(bufs
& PIPE_CLEAR_COLOR
))
2170 continue; /* save space, compiler should hoist this */
2171 cbuf
= NineSurface9_GetSurface(rt
, sRGB
);
2172 for (r
= 0; r
< Count
; ++r
) {
2173 /* Don't trust users to pass these in the right order. */
2174 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2175 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2176 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2177 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2179 /* Drop negative rectangles (like wine expects). */
2180 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2181 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2184 x1
= MAX2(x1
, rect
.x1
);
2185 y1
= MAX2(y1
, rect
.y1
);
2186 x2
= MIN3(x2
, rect
.x2
, rt
->desc
.Width
);
2187 y2
= MIN3(y2
, rect
.y2
, rt
->desc
.Height
);
2189 DBG("Clearing (%u..%u)x(%u..%u)\n", x1
, x2
, y1
, y2
);
2190 pipe
->clear_render_target(pipe
, cbuf
, &rgba
,
2191 x1
, y1
, x2
- x1
, y2
- y1
, false);
2194 if (!(bufs
& PIPE_CLEAR_DEPTHSTENCIL
))
2197 bufs
&= PIPE_CLEAR_DEPTHSTENCIL
;
2199 for (r
= 0; r
< Count
; ++r
) {
2200 unsigned x1
= MIN2(pRects
[r
].x1
, pRects
[r
].x2
);
2201 unsigned y1
= MIN2(pRects
[r
].y1
, pRects
[r
].y2
);
2202 unsigned x2
= MAX2(pRects
[r
].x1
, pRects
[r
].x2
);
2203 unsigned y2
= MAX2(pRects
[r
].y1
, pRects
[r
].y2
);
2205 /* Drop negative rectangles. */
2206 if (pRects
[r
].x1
> pRects
[r
].x2
) continue;
2207 if (pRects
[r
].y1
> pRects
[r
].y2
) continue;
2210 x1
= MIN2(x1
, rect
.x1
);
2211 y1
= MIN2(y1
, rect
.y1
);
2212 x2
= MIN3(x2
, rect
.x2
, zsbuf_surf
->desc
.Width
);
2213 y2
= MIN3(y2
, rect
.y2
, zsbuf_surf
->desc
.Height
);
2215 zsbuf
= NineSurface9_GetSurface(zsbuf_surf
, 0);
2217 pipe
->clear_depth_stencil(pipe
, zsbuf
, bufs
, Z
, Stencil
,
2218 x1
, y1
, x2
- x1
, y2
- y1
, false);
2225 init_draw_info(struct pipe_draw_info
*info
,
2226 struct NineDevice9
*dev
, D3DPRIMITIVETYPE type
, UINT count
)
2228 info
->mode
= d3dprimitivetype_to_pipe_prim(type
);
2229 info
->count
= prim_count_to_vertex_count(type
, count
);
2230 info
->start_instance
= 0;
2231 info
->instance_count
= 1;
2232 if (dev
->context
.stream_instancedata_mask
& dev
->context
.stream_usage_mask
)
2233 info
->instance_count
= MAX2(dev
->context
.stream_freq
[0] & 0x7FFFFF, 1);
2234 info
->primitive_restart
= FALSE
;
2235 info
->has_user_indices
= FALSE
;
2236 info
->restart_index
= 0;
2237 info
->count_from_stream_output
= NULL
;
2238 info
->indirect
= NULL
;
2241 CSMT_ITEM_NO_WAIT(nine_context_draw_primitive
,
2242 ARG_VAL(D3DPRIMITIVETYPE
, PrimitiveType
),
2243 ARG_VAL(UINT
, StartVertex
),
2244 ARG_VAL(UINT
, PrimitiveCount
))
2246 struct nine_context
*context
= &device
->context
;
2247 struct pipe_draw_info info
;
2249 nine_update_state(device
);
2251 init_draw_info(&info
, device
, PrimitiveType
, PrimitiveCount
);
2252 info
.index_size
= 0;
2253 info
.start
= StartVertex
;
2254 info
.index_bias
= 0;
2255 info
.min_index
= info
.start
;
2256 info
.max_index
= info
.count
- 1;
2257 info
.index
.resource
= NULL
;
2259 context
->pipe
->draw_vbo(context
->pipe
, &info
);
2262 CSMT_ITEM_NO_WAIT(nine_context_draw_indexed_primitive
,
2263 ARG_VAL(D3DPRIMITIVETYPE
, PrimitiveType
),
2264 ARG_VAL(INT
, BaseVertexIndex
),
2265 ARG_VAL(UINT
, MinVertexIndex
),
2266 ARG_VAL(UINT
, NumVertices
),
2267 ARG_VAL(UINT
, StartIndex
),
2268 ARG_VAL(UINT
, PrimitiveCount
))
2270 struct nine_context
*context
= &device
->context
;
2271 struct pipe_draw_info info
;
2273 nine_update_state(device
);
2275 init_draw_info(&info
, device
, PrimitiveType
, PrimitiveCount
);
2276 info
.index_size
= context
->index_size
;
2277 info
.start
= context
->index_offset
/ context
->index_size
+ StartIndex
;
2278 info
.index_bias
= BaseVertexIndex
;
2279 /* These don't include index bias: */
2280 info
.min_index
= MinVertexIndex
;
2281 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2282 info
.index
.resource
= context
->idxbuf
;
2284 context
->pipe
->draw_vbo(context
->pipe
, &info
);
2287 CSMT_ITEM_NO_WAIT(nine_context_draw_primitive_from_vtxbuf
,
2288 ARG_VAL(D3DPRIMITIVETYPE
, PrimitiveType
),
2289 ARG_VAL(UINT
, PrimitiveCount
),
2290 ARG_BIND_VBUF(struct pipe_vertex_buffer
, vtxbuf
))
2292 struct nine_context
*context
= &device
->context
;
2293 struct pipe_draw_info info
;
2295 nine_update_state(device
);
2297 init_draw_info(&info
, device
, PrimitiveType
, PrimitiveCount
);
2298 info
.index_size
= 0;
2300 info
.index_bias
= 0;
2302 info
.max_index
= info
.count
- 1;
2303 info
.index
.resource
= NULL
;
2305 context
->pipe
->set_vertex_buffers(context
->pipe
, 0, 1, vtxbuf
);
2307 context
->pipe
->draw_vbo(context
->pipe
, &info
);
2310 CSMT_ITEM_NO_WAIT(nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf
,
2311 ARG_VAL(D3DPRIMITIVETYPE
, PrimitiveType
),
2312 ARG_VAL(UINT
, MinVertexIndex
),
2313 ARG_VAL(UINT
, NumVertices
),
2314 ARG_VAL(UINT
, PrimitiveCount
),
2315 ARG_BIND_VBUF(struct pipe_vertex_buffer
, vbuf
),
2316 ARG_BIND_RES(struct pipe_resource
, ibuf
),
2317 ARG_VAL(void *, user_ibuf
),
2318 ARG_VAL(UINT
, index_offset
),
2319 ARG_VAL(UINT
, index_size
))
2321 struct nine_context
*context
= &device
->context
;
2322 struct pipe_draw_info info
;
2324 nine_update_state(device
);
2326 init_draw_info(&info
, device
, PrimitiveType
, PrimitiveCount
);
2327 info
.index_size
= index_size
;
2328 info
.start
= index_offset
/ info
.index_size
;
2329 info
.index_bias
= 0;
2330 info
.min_index
= MinVertexIndex
;
2331 info
.max_index
= MinVertexIndex
+ NumVertices
- 1;
2332 info
.has_user_indices
= ibuf
== NULL
;
2334 info
.index
.resource
= ibuf
;
2336 info
.index
.user
= user_ibuf
;
2338 context
->pipe
->set_vertex_buffers(context
->pipe
, 0, 1, vbuf
);
2340 context
->pipe
->draw_vbo(context
->pipe
, &info
);
2343 CSMT_ITEM_NO_WAIT(nine_context_resource_copy_region
,
2344 ARG_BIND_REF(struct NineUnknown
, dst
),
2345 ARG_BIND_REF(struct NineUnknown
, src
),
2346 ARG_BIND_RES(struct pipe_resource
, dst_res
),
2347 ARG_VAL(unsigned, dst_level
),
2348 ARG_COPY_REF(struct pipe_box
, dst_box
),
2349 ARG_BIND_RES(struct pipe_resource
, src_res
),
2350 ARG_VAL(unsigned, src_level
),
2351 ARG_COPY_REF(struct pipe_box
, src_box
))
2353 struct nine_context
*context
= &device
->context
;
2358 context
->pipe
->resource_copy_region(context
->pipe
,
2360 dst_box
->x
, dst_box
->y
, dst_box
->z
,
2365 CSMT_ITEM_NO_WAIT(nine_context_blit
,
2366 ARG_BIND_REF(struct NineUnknown
, dst
),
2367 ARG_BIND_REF(struct NineUnknown
, src
),
2368 ARG_BIND_BLIT(struct pipe_blit_info
, blit
))
2370 struct nine_context
*context
= &device
->context
;
2375 context
->pipe
->blit(context
->pipe
, blit
);
2378 CSMT_ITEM_NO_WAIT(nine_context_clear_render_target
,
2379 ARG_BIND_REF(struct NineSurface9
, surface
),
2380 ARG_VAL(D3DCOLOR
, color
),
2383 ARG_VAL(UINT
, width
),
2384 ARG_VAL(UINT
, height
))
2386 struct nine_context
*context
= &device
->context
;
2387 struct pipe_surface
*surf
;
2388 union pipe_color_union rgba
;
2390 d3dcolor_to_pipe_color_union(&rgba
, color
);
2391 surf
= NineSurface9_GetSurface(surface
, 0);
2392 context
->pipe
->clear_render_target(context
->pipe
, surf
, &rgba
, x
, y
, width
, height
, false);
2395 CSMT_ITEM_NO_WAIT(nine_context_gen_mipmap
,
2396 ARG_BIND_REF(struct NineUnknown
, dst
),
2397 ARG_BIND_RES(struct pipe_resource
, res
),
2398 ARG_VAL(UINT
, base_level
),
2399 ARG_VAL(UINT
, last_level
),
2400 ARG_VAL(UINT
, first_layer
),
2401 ARG_VAL(UINT
, last_layer
),
2402 ARG_VAL(UINT
, filter
))
2404 struct nine_context
*context
= &device
->context
;
2406 /* We just bind dst for the bind count */
2409 util_gen_mipmap(context
->pipe
, res
, res
->format
, base_level
,
2410 last_level
, first_layer
, last_layer
, filter
);
2413 CSMT_ITEM_NO_WAIT_WITH_COUNTER(nine_context_range_upload
,
2414 ARG_BIND_RES(struct pipe_resource
, res
),
2415 ARG_VAL(unsigned, offset
),
2416 ARG_VAL(unsigned, size
),
2417 ARG_VAL(const void *, data
))
2419 struct nine_context
*context
= &device
->context
;
2421 context
->pipe
->buffer_subdata(context
->pipe
, res
, 0, offset
, size
, data
);
2424 CSMT_ITEM_NO_WAIT_WITH_COUNTER(nine_context_box_upload
,
2425 ARG_BIND_REF(struct NineUnknown
, dst
),
2426 ARG_BIND_RES(struct pipe_resource
, res
),
2427 ARG_VAL(unsigned, level
),
2428 ARG_COPY_REF(struct pipe_box
, dst_box
),
2429 ARG_VAL(enum pipe_format
, src_format
),
2430 ARG_VAL(const void *, src
),
2431 ARG_VAL(unsigned, src_stride
),
2432 ARG_VAL(unsigned, src_layer_stride
),
2433 ARG_COPY_REF(struct pipe_box
, src_box
))
2435 struct nine_context
*context
= &device
->context
;
2436 struct pipe_context
*pipe
= context
->pipe
;
2437 struct pipe_transfer
*transfer
= NULL
;
2440 /* We just bind dst for the bind count */
2443 map
= pipe
->transfer_map(pipe
,
2446 PIPE_TRANSFER_WRITE
| PIPE_TRANSFER_DISCARD_RANGE
,
2447 dst_box
, &transfer
);
2451 /* Note: if formats are the sames, it will revert
2452 * to normal memcpy */
2453 (void) util_format_translate_3d(res
->format
,
2454 map
, transfer
->stride
,
2455 transfer
->layer_stride
,
2460 src_box
->x
, src_box
->y
, src_box
->z
,
2461 dst_box
->width
, dst_box
->height
,
2464 pipe_transfer_unmap(pipe
, transfer
);
2468 nine_context_create_query(struct NineDevice9
*device
, unsigned query_type
)
2470 struct pipe_context
*pipe
;
2471 struct pipe_query
*res
;
2473 pipe
= nine_context_get_pipe_acquire(device
);
2474 res
= pipe
->create_query(pipe
, query_type
, 0);
2475 nine_context_get_pipe_release(device
);
2479 CSMT_ITEM_DO_WAIT(nine_context_destroy_query
,
2480 ARG_REF(struct pipe_query
, query
))
2482 struct nine_context
*context
= &device
->context
;
2484 context
->pipe
->destroy_query(context
->pipe
, query
);
2487 CSMT_ITEM_NO_WAIT_WITH_COUNTER(nine_context_begin_query
,
2488 ARG_REF(struct pipe_query
, query
))
2490 struct nine_context
*context
= &device
->context
;
2492 (void) context
->pipe
->begin_query(context
->pipe
, query
);
2495 CSMT_ITEM_NO_WAIT_WITH_COUNTER(nine_context_end_query
,
2496 ARG_REF(struct pipe_query
, query
))
2498 struct nine_context
*context
= &device
->context
;
2500 (void) context
->pipe
->end_query(context
->pipe
, query
);
2504 nine_context_get_query_result(struct NineDevice9
*device
, struct pipe_query
*query
,
2505 unsigned *counter
, boolean flush
, boolean wait
,
2506 union pipe_query_result
*result
)
2508 struct pipe_context
*pipe
;
2512 nine_csmt_process(device
);
2513 else if (p_atomic_read(counter
) > 0) {
2514 if (flush
&& device
->csmt_active
)
2515 nine_queue_flush(device
->csmt_ctx
->pool
);
2516 DBG("Pending begin/end. Returning\n");
2520 pipe
= nine_context_get_pipe_acquire(device
);
2521 ret
= pipe
->get_query_result(pipe
, query
, wait
, result
);
2522 nine_context_get_pipe_release(device
);
2524 DBG("Query result %s\n", ret
? "found" : "not yet available");
2528 /* State defaults */
2530 static const DWORD nine_render_state_defaults
[NINED3DRS_LAST
+ 1] =
2532 /* [D3DRS_ZENABLE] = D3DZB_TRUE; wine: auto_depth_stencil */
2533 [D3DRS_ZENABLE
] = D3DZB_FALSE
,
2534 [D3DRS_FILLMODE
] = D3DFILL_SOLID
,
2535 [D3DRS_SHADEMODE
] = D3DSHADE_GOURAUD
,
2536 /* [D3DRS_LINEPATTERN] = 0x00000000, */
2537 [D3DRS_ZWRITEENABLE
] = TRUE
,
2538 [D3DRS_ALPHATESTENABLE
] = FALSE
,
2539 [D3DRS_LASTPIXEL
] = TRUE
,
2540 [D3DRS_SRCBLEND
] = D3DBLEND_ONE
,
2541 [D3DRS_DESTBLEND
] = D3DBLEND_ZERO
,
2542 [D3DRS_CULLMODE
] = D3DCULL_CCW
,
2543 [D3DRS_ZFUNC
] = D3DCMP_LESSEQUAL
,
2544 [D3DRS_ALPHAFUNC
] = D3DCMP_ALWAYS
,
2545 [D3DRS_ALPHAREF
] = 0,
2546 [D3DRS_DITHERENABLE
] = FALSE
,
2547 [D3DRS_ALPHABLENDENABLE
] = FALSE
,
2548 [D3DRS_FOGENABLE
] = FALSE
,
2549 [D3DRS_SPECULARENABLE
] = FALSE
,
2550 /* [D3DRS_ZVISIBLE] = 0, */
2551 [D3DRS_FOGCOLOR
] = 0,
2552 [D3DRS_FOGTABLEMODE
] = D3DFOG_NONE
,
2553 [D3DRS_FOGSTART
] = 0x00000000,
2554 [D3DRS_FOGEND
] = 0x3F800000,
2555 [D3DRS_FOGDENSITY
] = 0x3F800000,
2556 /* [D3DRS_EDGEANTIALIAS] = FALSE, */
2557 [D3DRS_RANGEFOGENABLE
] = FALSE
,
2558 [D3DRS_STENCILENABLE
] = FALSE
,
2559 [D3DRS_STENCILFAIL
] = D3DSTENCILOP_KEEP
,
2560 [D3DRS_STENCILZFAIL
] = D3DSTENCILOP_KEEP
,
2561 [D3DRS_STENCILPASS
] = D3DSTENCILOP_KEEP
,
2562 [D3DRS_STENCILREF
] = 0,
2563 [D3DRS_STENCILMASK
] = 0xFFFFFFFF,
2564 [D3DRS_STENCILFUNC
] = D3DCMP_ALWAYS
,
2565 [D3DRS_STENCILWRITEMASK
] = 0xFFFFFFFF,
2566 [D3DRS_TEXTUREFACTOR
] = 0xFFFFFFFF,
2575 [D3DRS_CLIPPING
] = TRUE
,
2576 [D3DRS_LIGHTING
] = TRUE
,
2577 [D3DRS_AMBIENT
] = 0,
2578 [D3DRS_FOGVERTEXMODE
] = D3DFOG_NONE
,
2579 [D3DRS_COLORVERTEX
] = TRUE
,
2580 [D3DRS_LOCALVIEWER
] = TRUE
,
2581 [D3DRS_NORMALIZENORMALS
] = FALSE
,
2582 [D3DRS_DIFFUSEMATERIALSOURCE
] = D3DMCS_COLOR1
,
2583 [D3DRS_SPECULARMATERIALSOURCE
] = D3DMCS_COLOR2
,
2584 [D3DRS_AMBIENTMATERIALSOURCE
] = D3DMCS_MATERIAL
,
2585 [D3DRS_EMISSIVEMATERIALSOURCE
] = D3DMCS_MATERIAL
,
2586 [D3DRS_VERTEXBLEND
] = D3DVBF_DISABLE
,
2587 [D3DRS_CLIPPLANEENABLE
] = 0,
2588 /* [D3DRS_SOFTWAREVERTEXPROCESSING] = FALSE, */
2589 [D3DRS_POINTSIZE
] = 0x3F800000,
2590 [D3DRS_POINTSIZE_MIN
] = 0x3F800000,
2591 [D3DRS_POINTSPRITEENABLE
] = FALSE
,
2592 [D3DRS_POINTSCALEENABLE
] = FALSE
,
2593 [D3DRS_POINTSCALE_A
] = 0x3F800000,
2594 [D3DRS_POINTSCALE_B
] = 0x00000000,
2595 [D3DRS_POINTSCALE_C
] = 0x00000000,
2596 [D3DRS_MULTISAMPLEANTIALIAS
] = TRUE
,
2597 [D3DRS_MULTISAMPLEMASK
] = 0xFFFFFFFF,
2598 [D3DRS_PATCHEDGESTYLE
] = D3DPATCHEDGE_DISCRETE
,
2599 /* [D3DRS_PATCHSEGMENTS] = 0x3F800000, */
2600 [D3DRS_DEBUGMONITORTOKEN
] = 0xDEADCAFE,
2601 [D3DRS_POINTSIZE_MAX
] = 0x3F800000, /* depends on cap */
2602 [D3DRS_INDEXEDVERTEXBLENDENABLE
] = FALSE
,
2603 [D3DRS_COLORWRITEENABLE
] = 0x0000000f,
2604 [D3DRS_TWEENFACTOR
] = 0x00000000,
2605 [D3DRS_BLENDOP
] = D3DBLENDOP_ADD
,
2606 [D3DRS_POSITIONDEGREE
] = D3DDEGREE_CUBIC
,
2607 [D3DRS_NORMALDEGREE
] = D3DDEGREE_LINEAR
,
2608 [D3DRS_SCISSORTESTENABLE
] = FALSE
,
2609 [D3DRS_SLOPESCALEDEPTHBIAS
] = 0,
2610 [D3DRS_MINTESSELLATIONLEVEL
] = 0x3F800000,
2611 [D3DRS_MAXTESSELLATIONLEVEL
] = 0x3F800000,
2612 [D3DRS_ANTIALIASEDLINEENABLE
] = FALSE
,
2613 [D3DRS_ADAPTIVETESS_X
] = 0x00000000,
2614 [D3DRS_ADAPTIVETESS_Y
] = 0x00000000,
2615 [D3DRS_ADAPTIVETESS_Z
] = 0x3F800000,
2616 [D3DRS_ADAPTIVETESS_W
] = 0x00000000,
2617 [D3DRS_ENABLEADAPTIVETESSELLATION
] = FALSE
,
2618 [D3DRS_TWOSIDEDSTENCILMODE
] = FALSE
,
2619 [D3DRS_CCW_STENCILFAIL
] = D3DSTENCILOP_KEEP
,
2620 [D3DRS_CCW_STENCILZFAIL
] = D3DSTENCILOP_KEEP
,
2621 [D3DRS_CCW_STENCILPASS
] = D3DSTENCILOP_KEEP
,
2622 [D3DRS_CCW_STENCILFUNC
] = D3DCMP_ALWAYS
,
2623 [D3DRS_COLORWRITEENABLE1
] = 0x0000000F,
2624 [D3DRS_COLORWRITEENABLE2
] = 0x0000000F,
2625 [D3DRS_COLORWRITEENABLE3
] = 0x0000000F,
2626 [D3DRS_BLENDFACTOR
] = 0xFFFFFFFF,
2627 [D3DRS_SRGBWRITEENABLE
] = 0,
2628 [D3DRS_DEPTHBIAS
] = 0,
2637 [D3DRS_SEPARATEALPHABLENDENABLE
] = FALSE
,
2638 [D3DRS_SRCBLENDALPHA
] = D3DBLEND_ONE
,
2639 [D3DRS_DESTBLENDALPHA
] = D3DBLEND_ZERO
,
2640 [D3DRS_BLENDOPALPHA
] = D3DBLENDOP_ADD
,
2641 [NINED3DRS_VSPOINTSIZE
] = FALSE
,
2642 [NINED3DRS_RTMASK
] = 0xf,
2643 [NINED3DRS_ALPHACOVERAGE
] = FALSE
,
2644 [NINED3DRS_MULTISAMPLE
] = FALSE
2646 static const DWORD nine_tex_stage_state_defaults
[NINED3DTSS_LAST
+ 1] =
2648 [D3DTSS_COLOROP
] = D3DTOP_DISABLE
,
2649 [D3DTSS_ALPHAOP
] = D3DTOP_DISABLE
,
2650 [D3DTSS_COLORARG1
] = D3DTA_TEXTURE
,
2651 [D3DTSS_COLORARG2
] = D3DTA_CURRENT
,
2652 [D3DTSS_COLORARG0
] = D3DTA_CURRENT
,
2653 [D3DTSS_ALPHAARG1
] = D3DTA_TEXTURE
,
2654 [D3DTSS_ALPHAARG2
] = D3DTA_CURRENT
,
2655 [D3DTSS_ALPHAARG0
] = D3DTA_CURRENT
,
2656 [D3DTSS_RESULTARG
] = D3DTA_CURRENT
,
2657 [D3DTSS_BUMPENVMAT00
] = 0,
2658 [D3DTSS_BUMPENVMAT01
] = 0,
2659 [D3DTSS_BUMPENVMAT10
] = 0,
2660 [D3DTSS_BUMPENVMAT11
] = 0,
2661 [D3DTSS_BUMPENVLSCALE
] = 0,
2662 [D3DTSS_BUMPENVLOFFSET
] = 0,
2663 [D3DTSS_TEXCOORDINDEX
] = 0,
2664 [D3DTSS_TEXTURETRANSFORMFLAGS
] = D3DTTFF_DISABLE
,
2666 static const DWORD nine_samp_state_defaults
[NINED3DSAMP_LAST
+ 1] =
2668 [D3DSAMP_ADDRESSU
] = D3DTADDRESS_WRAP
,
2669 [D3DSAMP_ADDRESSV
] = D3DTADDRESS_WRAP
,
2670 [D3DSAMP_ADDRESSW
] = D3DTADDRESS_WRAP
,
2671 [D3DSAMP_BORDERCOLOR
] = 0,
2672 [D3DSAMP_MAGFILTER
] = D3DTEXF_POINT
,
2673 [D3DSAMP_MINFILTER
] = D3DTEXF_POINT
,
2674 [D3DSAMP_MIPFILTER
] = D3DTEXF_NONE
,
2675 [D3DSAMP_MIPMAPLODBIAS
] = 0,
2676 [D3DSAMP_MAXMIPLEVEL
] = 0,
2677 [D3DSAMP_MAXANISOTROPY
] = 1,
2678 [D3DSAMP_SRGBTEXTURE
] = 0,
2679 [D3DSAMP_ELEMENTINDEX
] = 0,
2680 [D3DSAMP_DMAPOFFSET
] = 0,
2681 [NINED3DSAMP_MINLOD
] = 0,
2682 [NINED3DSAMP_SHADOW
] = 0,
2683 [NINED3DSAMP_CUBETEX
] = 0
2686 /* Note: The following 4 functions assume there is no
2687 * pending commands */
2689 void nine_state_restore_non_cso(struct NineDevice9
*device
)
2691 struct nine_context
*context
= &device
->context
;
2693 context
->changed
.group
= NINE_STATE_ALL
;
2694 context
->changed
.vtxbuf
= (1ULL << device
->caps
.MaxStreams
) - 1;
2695 context
->changed
.ucp
= TRUE
;
2696 context
->commit
|= NINE_STATE_COMMIT_CONST_VS
| NINE_STATE_COMMIT_CONST_PS
;
2700 nine_state_set_defaults(struct NineDevice9
*device
, const D3DCAPS9
*caps
,
2703 struct nine_state
*state
= &device
->state
;
2704 struct nine_context
*context
= &device
->context
;
2707 /* Initialize defaults.
2709 memcpy(context
->rs
, nine_render_state_defaults
, sizeof(context
->rs
));
2711 for (s
= 0; s
< ARRAY_SIZE(state
->ff
.tex_stage
); ++s
) {
2712 memcpy(&state
->ff
.tex_stage
[s
], nine_tex_stage_state_defaults
,
2713 sizeof(state
->ff
.tex_stage
[s
]));
2714 state
->ff
.tex_stage
[s
][D3DTSS_TEXCOORDINDEX
] = s
;
2716 state
->ff
.tex_stage
[0][D3DTSS_COLOROP
] = D3DTOP_MODULATE
;
2717 state
->ff
.tex_stage
[0][D3DTSS_ALPHAOP
] = D3DTOP_SELECTARG1
;
2719 for (s
= 0; s
< ARRAY_SIZE(state
->ff
.tex_stage
); ++s
)
2720 memcpy(&context
->ff
.tex_stage
[s
], state
->ff
.tex_stage
[s
],
2721 sizeof(state
->ff
.tex_stage
[s
]));
2723 memset(&context
->bumpmap_vars
, 0, sizeof(context
->bumpmap_vars
));
2725 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
) {
2726 memcpy(&context
->samp
[s
], nine_samp_state_defaults
,
2727 sizeof(context
->samp
[s
]));
2728 memcpy(&state
->samp_advertised
[s
], nine_samp_state_defaults
,
2729 sizeof(state
->samp_advertised
[s
]));
2732 memset(state
->vs_const_f
, 0, VS_CONST_F_SIZE(device
));
2733 memset(context
->vs_const_f
, 0, device
->vs_const_size
);
2734 if (context
->vs_const_f_swvp
)
2735 memset(context
->vs_const_f_swvp
, 0, NINE_MAX_CONST_F_SWVP
* sizeof(float[4]));
2736 memset(state
->vs_const_i
, 0, VS_CONST_I_SIZE(device
));
2737 memset(context
->vs_const_i
, 0, VS_CONST_I_SIZE(device
));
2738 memset(state
->vs_const_b
, 0, VS_CONST_B_SIZE(device
));
2739 memset(context
->vs_const_b
, 0, VS_CONST_B_SIZE(device
));
2740 memset(state
->ps_const_f
, 0, device
->ps_const_size
);
2741 memset(context
->ps_const_f
, 0, device
->ps_const_size
);
2742 memset(state
->ps_const_i
, 0, sizeof(state
->ps_const_i
));
2743 memset(context
->ps_const_i
, 0, sizeof(context
->ps_const_i
));
2744 memset(state
->ps_const_b
, 0, sizeof(state
->ps_const_b
));
2745 memset(context
->ps_const_b
, 0, sizeof(context
->ps_const_b
));
2747 /* Cap dependent initial state:
2749 context
->rs
[D3DRS_POINTSIZE_MAX
] = fui(caps
->MaxPointSize
);
2751 memcpy(state
->rs_advertised
, context
->rs
, sizeof(context
->rs
));
2753 /* Set changed flags to initialize driver.
2755 context
->changed
.group
= NINE_STATE_ALL
;
2756 context
->changed
.vtxbuf
= (1ULL << device
->caps
.MaxStreams
) - 1;
2757 context
->changed
.ucp
= TRUE
;
2759 context
->ff
.changed
.transform
[0] = ~0;
2760 context
->ff
.changed
.transform
[D3DTS_WORLD
/ 32] |= 1 << (D3DTS_WORLD
% 32);
2763 state
->viewport
.MinZ
= context
->viewport
.MinZ
= 0.0f
;
2764 state
->viewport
.MaxZ
= context
->viewport
.MaxZ
= 1.0f
;
2767 for (s
= 0; s
< NINE_MAX_SAMPLERS
; ++s
)
2768 context
->changed
.sampler
[s
] = ~0;
2771 context
->dummy_vbo_bound_at
= -1;
2772 context
->vbo_bound_done
= FALSE
;
2777 nine_state_clear(struct nine_state
*state
, const boolean device
)
2781 for (i
= 0; i
< ARRAY_SIZE(state
->rt
); ++i
)
2782 nine_bind(&state
->rt
[i
], NULL
);
2783 nine_bind(&state
->ds
, NULL
);
2784 nine_bind(&state
->vs
, NULL
);
2785 nine_bind(&state
->ps
, NULL
);
2786 nine_bind(&state
->vdecl
, NULL
);
2787 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; ++i
)
2788 nine_bind(&state
->stream
[i
], NULL
);
2790 nine_bind(&state
->idxbuf
, NULL
);
2791 for (i
= 0; i
< NINE_MAX_SAMPLERS
; ++i
) {
2793 state
->texture
[i
] &&
2794 --state
->texture
[i
]->bind_count
== 0)
2795 list_delinit(&state
->texture
[i
]->list
);
2796 nine_bind(&state
->texture
[i
], NULL
);
2801 nine_context_clear(struct NineDevice9
*device
)
2803 struct nine_context
*context
= &device
->context
;
2804 struct pipe_context
*pipe
= context
->pipe
;
2805 struct cso_context
*cso
= context
->cso
;
2808 /* Early device ctor failure. Nothing to do */
2812 pipe
->bind_vs_state(pipe
, NULL
);
2813 pipe
->bind_fs_state(pipe
, NULL
);
2815 /* Don't unbind constant buffers, they're device-private and
2816 * do not change on Reset.
2819 cso_set_samplers(cso
, PIPE_SHADER_VERTEX
, 0, NULL
);
2820 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, 0, NULL
);
2822 cso_set_sampler_views(cso
, PIPE_SHADER_VERTEX
, 0, NULL
);
2823 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, 0, NULL
);
2825 pipe
->set_vertex_buffers(pipe
, 0, device
->caps
.MaxStreams
, NULL
);
2827 for (i
= 0; i
< ARRAY_SIZE(context
->rt
); ++i
)
2828 nine_bind(&context
->rt
[i
], NULL
);
2829 nine_bind(&context
->ds
, NULL
);
2830 nine_bind(&context
->vs
, NULL
);
2831 nine_bind(&context
->ps
, NULL
);
2832 nine_bind(&context
->vdecl
, NULL
);
2833 for (i
= 0; i
< PIPE_MAX_ATTRIBS
; ++i
)
2834 pipe_vertex_buffer_unreference(&context
->vtxbuf
[i
]);
2835 pipe_resource_reference(&context
->idxbuf
, NULL
);
2837 for (i
= 0; i
< NINE_MAX_SAMPLERS
; ++i
) {
2838 context
->texture
[i
].enabled
= FALSE
;
2839 pipe_resource_reference(&context
->texture
[i
].resource
,
2841 pipe_sampler_view_reference(&context
->texture
[i
].view
[0],
2843 pipe_sampler_view_reference(&context
->texture
[i
].view
[1],
2849 nine_state_init_sw(struct NineDevice9
*device
)
2851 struct pipe_context
*pipe_sw
= device
->pipe_sw
;
2852 struct pipe_rasterizer_state rast
;
2853 struct pipe_blend_state blend
;
2854 struct pipe_depth_stencil_alpha_state dsa
;
2855 struct pipe_framebuffer_state fb
;
2857 /* Only used with Streamout */
2858 memset(&rast
, 0, sizeof(rast
));
2859 rast
.rasterizer_discard
= true;
2860 rast
.point_quad_rasterization
= 1; /* to make llvmpipe happy */
2861 cso_set_rasterizer(device
->cso_sw
, &rast
);
2863 /* dummy settings */
2864 memset(&blend
, 0, sizeof(blend
));
2865 memset(&dsa
, 0, sizeof(dsa
));
2866 memset(&fb
, 0, sizeof(fb
));
2867 cso_set_blend(device
->cso_sw
, &blend
);
2868 cso_set_depth_stencil_alpha(device
->cso_sw
, &dsa
);
2869 cso_set_framebuffer(device
->cso_sw
, &fb
);
2870 cso_set_viewport_dims(device
->cso_sw
, 1.0, 1.0, false);
2871 cso_set_fragment_shader_handle(device
->cso_sw
, util_make_empty_fragment_shader(pipe_sw
));
2874 /* There is duplication with update_vertex_elements.
2875 * TODO: Share the code */
2878 update_vertex_elements_sw(struct NineDevice9
*device
)
2880 struct nine_state
*state
= &device
->state
;
2881 const struct NineVertexDeclaration9
*vdecl
= device
->state
.vdecl
;
2882 const struct NineVertexShader9
*vs
;
2885 char vdecl_index_map
[16]; /* vs->num_inputs <= 16 */
2886 char used_streams
[device
->caps
.MaxStreams
];
2887 int dummy_vbo_stream
= -1;
2888 BOOL need_dummy_vbo
= FALSE
;
2889 struct pipe_vertex_element ve
[PIPE_MAX_ATTRIBS
];
2890 bool programmable_vs
= state
->vs
&& !(state
->vdecl
&& state
->vdecl
->position_t
);
2892 memset(vdecl_index_map
, -1, 16);
2893 memset(used_streams
, 0, device
->caps
.MaxStreams
);
2894 vs
= programmable_vs
? device
->state
.vs
: device
->ff
.vs
;
2897 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
2898 DBG("looking up input %u (usage %u) from vdecl(%p)\n",
2899 n
, vs
->input_map
[n
].ndecl
, vdecl
);
2901 for (i
= 0; i
< vdecl
->nelems
; i
++) {
2902 if (vdecl
->usage_map
[i
] == vs
->input_map
[n
].ndecl
) {
2903 vdecl_index_map
[n
] = i
;
2904 used_streams
[vdecl
->elems
[i
].vertex_buffer_index
] = 1;
2908 if (vdecl_index_map
[n
] < 0)
2909 need_dummy_vbo
= TRUE
;
2912 /* No vertex declaration. Likely will never happen in practice,
2913 * but we need not crash on this */
2914 need_dummy_vbo
= TRUE
;
2917 if (need_dummy_vbo
) {
2918 for (i
= 0; i
< device
->caps
.MaxStreams
; i
++ ) {
2919 if (!used_streams
[i
]) {
2920 dummy_vbo_stream
= i
;
2925 /* TODO handle dummy_vbo */
2926 assert (!need_dummy_vbo
);
2928 for (n
= 0; n
< vs
->num_inputs
; ++n
) {
2929 index
= vdecl_index_map
[n
];
2931 ve
[n
] = vdecl
->elems
[index
];
2932 b
= ve
[n
].vertex_buffer_index
;
2933 /* XXX wine just uses 1 here: */
2934 if (state
->stream_freq
[b
] & D3DSTREAMSOURCE_INSTANCEDATA
)
2935 ve
[n
].instance_divisor
= state
->stream_freq
[b
] & 0x7FFFFF;
2937 /* if the vertex declaration is incomplete compared to what the
2938 * vertex shader needs, we bind a dummy vbo with 0 0 0 0.
2939 * This is not precised by the spec, but is the behaviour
2941 ve
[n
].vertex_buffer_index
= dummy_vbo_stream
;
2942 ve
[n
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
2943 ve
[n
].src_offset
= 0;
2944 ve
[n
].instance_divisor
= 0;
2948 cso_set_vertex_elements(device
->cso_sw
, vs
->num_inputs
, ve
);
2952 update_vertex_buffers_sw(struct NineDevice9
*device
, int start_vertice
, int num_vertices
)
2954 struct pipe_context
*pipe
= nine_context_get_pipe_acquire(device
);
2955 struct pipe_context
*pipe_sw
= device
->pipe_sw
;
2956 struct nine_state
*state
= &device
->state
;
2957 struct nine_state_sw_internal
*sw_internal
= &device
->state_sw_internal
;
2958 struct pipe_vertex_buffer vtxbuf
;
2959 uint32_t mask
= 0xf;
2962 DBG("mask=%x\n", mask
);
2964 /* TODO: handle dummy_vbo_bound_at */
2966 for (i
= 0; mask
; mask
>>= 1, ++i
) {
2968 if (state
->stream
[i
]) {
2970 struct pipe_resource
*buf
;
2971 struct pipe_box box
;
2974 vtxbuf
= state
->vtxbuf
[i
];
2975 buf
= NineVertexBuffer9_GetResource(state
->stream
[i
], &offset
);
2977 DBG("Locking %p (offset %d, length %d)\n", buf
,
2978 vtxbuf
.buffer_offset
, num_vertices
* vtxbuf
.stride
);
2980 u_box_1d(vtxbuf
.buffer_offset
+ offset
+ start_vertice
* vtxbuf
.stride
,
2981 num_vertices
* vtxbuf
.stride
, &box
);
2983 userbuf
= pipe
->transfer_map(pipe
, buf
, 0, PIPE_TRANSFER_READ
, &box
,
2984 &(sw_internal
->transfers_so
[i
]));
2985 vtxbuf
.is_user_buffer
= true;
2986 vtxbuf
.buffer
.user
= userbuf
;
2988 if (!device
->driver_caps
.user_sw_vbufs
) {
2989 vtxbuf
.buffer
.resource
= NULL
;
2990 vtxbuf
.is_user_buffer
= false;
2991 u_upload_data(device
->pipe_sw
->stream_uploader
,
2996 &(vtxbuf
.buffer_offset
),
2997 &(vtxbuf
.buffer
.resource
));
2998 u_upload_unmap(device
->pipe_sw
->stream_uploader
);
3000 pipe_sw
->set_vertex_buffers(pipe_sw
, i
, 1, &vtxbuf
);
3001 pipe_vertex_buffer_unreference(&vtxbuf
);
3003 pipe_sw
->set_vertex_buffers(pipe_sw
, i
, 1, NULL
);
3006 nine_context_get_pipe_release(device
);
3010 update_vs_constants_sw(struct NineDevice9
*device
)
3012 struct nine_state
*state
= &device
->state
;
3013 struct pipe_context
*pipe_sw
= device
->pipe_sw
;
3018 struct pipe_constant_buffer cb
;
3022 cb
.buffer_offset
= 0;
3023 cb
.buffer_size
= 4096 * sizeof(float[4]);
3024 cb
.user_buffer
= state
->vs_const_f
;
3026 if (state
->vs
->lconstf
.ranges
) {
3027 const struct nine_lconstf
*lconstf
= &device
->state
.vs
->lconstf
;
3028 const struct nine_range
*r
= lconstf
->ranges
;
3030 float *dst
= device
->state
.vs_lconstf_temp
;
3031 float *src
= (float *)cb
.user_buffer
;
3032 memcpy(dst
, src
, 8192 * sizeof(float[4]));
3034 unsigned p
= r
->bgn
;
3035 unsigned c
= r
->end
- r
->bgn
;
3036 memcpy(&dst
[p
* 4], &lconstf
->data
[n
* 4], c
* 4 * sizeof(float));
3040 cb
.user_buffer
= dst
;
3043 buf
= cb
.user_buffer
;
3045 pipe_sw
->set_constant_buffer(pipe_sw
, PIPE_SHADER_VERTEX
, 0, &cb
);
3047 pipe_resource_reference(&cb
.buffer
, NULL
);
3049 cb
.user_buffer
= (char *)buf
+ 4096 * sizeof(float[4]);
3051 pipe_sw
->set_constant_buffer(pipe_sw
, PIPE_SHADER_VERTEX
, 1, &cb
);
3053 pipe_resource_reference(&cb
.buffer
, NULL
);
3057 struct pipe_constant_buffer cb
;
3060 cb
.buffer_offset
= 0;
3061 cb
.buffer_size
= 2048 * sizeof(float[4]);
3062 cb
.user_buffer
= state
->vs_const_i
;
3064 pipe_sw
->set_constant_buffer(pipe_sw
, PIPE_SHADER_VERTEX
, 2, &cb
);
3066 pipe_resource_reference(&cb
.buffer
, NULL
);
3070 struct pipe_constant_buffer cb
;
3073 cb
.buffer_offset
= 0;
3074 cb
.buffer_size
= 512 * sizeof(float[4]);
3075 cb
.user_buffer
= state
->vs_const_b
;
3077 pipe_sw
->set_constant_buffer(pipe_sw
, PIPE_SHADER_VERTEX
, 3, &cb
);
3079 pipe_resource_reference(&cb
.buffer
, NULL
);
3083 struct pipe_constant_buffer cb
;
3084 const D3DVIEWPORT9
*vport
= &device
->state
.viewport
;
3085 float viewport_data
[8] = {(float)vport
->Width
* 0.5f
,
3086 (float)vport
->Height
* -0.5f
, vport
->MaxZ
- vport
->MinZ
, 0.f
,
3087 (float)vport
->Width
* 0.5f
+ (float)vport
->X
,
3088 (float)vport
->Height
* 0.5f
+ (float)vport
->Y
,
3092 cb
.buffer_offset
= 0;
3093 cb
.buffer_size
= 2 * sizeof(float[4]);
3094 cb
.user_buffer
= viewport_data
;
3097 u_upload_data(device
->pipe_sw
->const_uploader
,
3102 &(cb
.buffer_offset
),
3104 u_upload_unmap(device
->pipe_sw
->const_uploader
);
3105 cb
.user_buffer
= NULL
;
3108 pipe_sw
->set_constant_buffer(pipe_sw
, PIPE_SHADER_VERTEX
, 4, &cb
);
3110 pipe_resource_reference(&cb
.buffer
, NULL
);
3116 nine_state_prepare_draw_sw(struct NineDevice9
*device
, struct NineVertexDeclaration9
*vdecl_out
,
3117 int start_vertice
, int num_vertices
, struct pipe_stream_output_info
*so
)
3119 struct nine_state
*state
= &device
->state
;
3120 bool programmable_vs
= state
->vs
&& !(state
->vdecl
&& state
->vdecl
->position_t
);
3121 struct NineVertexShader9
*vs
= programmable_vs
? device
->state
.vs
: device
->ff
.vs
;
3123 assert(programmable_vs
);
3125 DBG("Preparing draw\n");
3126 cso_set_vertex_shader_handle(device
->cso_sw
,
3127 NineVertexShader9_GetVariantProcessVertices(vs
, vdecl_out
, so
));
3128 update_vertex_elements_sw(device
);
3129 update_vertex_buffers_sw(device
, start_vertice
, num_vertices
);
3130 update_vs_constants_sw(device
);
3131 DBG("Preparation succeeded\n");
3135 nine_state_after_draw_sw(struct NineDevice9
*device
)
3137 struct nine_state_sw_internal
*sw_internal
= &device
->state_sw_internal
;
3138 struct pipe_context
*pipe
= nine_context_get_pipe_acquire(device
);
3139 struct pipe_context
*pipe_sw
= device
->pipe_sw
;
3142 for (i
= 0; i
< 4; i
++) {
3143 pipe_sw
->set_vertex_buffers(pipe_sw
, i
, 1, NULL
);
3144 if (sw_internal
->transfers_so
[i
])
3145 pipe
->transfer_unmap(pipe
, sw_internal
->transfers_so
[i
]);
3146 sw_internal
->transfers_so
[i
] = NULL
;
3148 nine_context_get_pipe_release(device
);
3152 nine_state_destroy_sw(struct NineDevice9
*device
)
3155 /* Everything destroyed with cso */
3159 static const DWORD nine_render_states_pixel[] =
3161 D3DRS_ALPHABLENDENABLE,
3164 D3DRS_ALPHATESTENABLE,
3165 D3DRS_ANTIALIASEDLINEENABLE,
3169 D3DRS_CCW_STENCILFAIL,
3170 D3DRS_CCW_STENCILPASS,
3171 D3DRS_CCW_STENCILZFAIL,
3172 D3DRS_COLORWRITEENABLE,
3173 D3DRS_COLORWRITEENABLE1,
3174 D3DRS_COLORWRITEENABLE2,
3175 D3DRS_COLORWRITEENABLE3,
3178 D3DRS_DESTBLENDALPHA,
3185 D3DRS_SCISSORTESTENABLE,
3186 D3DRS_SEPARATEALPHABLENDENABLE,
3188 D3DRS_SLOPESCALEDEPTHBIAS,
3190 D3DRS_SRCBLENDALPHA,
3191 D3DRS_SRGBWRITEENABLE,
3192 D3DRS_STENCILENABLE,
3198 D3DRS_STENCILWRITEMASK,
3200 D3DRS_TEXTUREFACTOR,
3201 D3DRS_TWOSIDEDSTENCILMODE,
3223 const uint32_t nine_render_states_pixel
[(NINED3DRS_LAST
+ 31) / 32] =
3225 0x0f99c380, 0x1ff00070, 0x00000000, 0x00000000,
3226 0x000000ff, 0xde01c900, 0x0003ffcf
3230 static const DWORD nine_render_states_vertex[] =
3232 D3DRS_ADAPTIVETESS_W,
3233 D3DRS_ADAPTIVETESS_X,
3234 D3DRS_ADAPTIVETESS_Y,
3235 D3DRS_ADAPTIVETESS_Z,
3237 D3DRS_AMBIENTMATERIALSOURCE,
3239 D3DRS_CLIPPLANEENABLE,
3242 D3DRS_DIFFUSEMATERIALSOURCE,
3243 D3DRS_EMISSIVEMATERIALSOURCE,
3244 D3DRS_ENABLEADAPTIVETESSELLATION,
3251 D3DRS_FOGVERTEXMODE,
3252 D3DRS_INDEXEDVERTEXBLENDENABLE,
3255 D3DRS_MAXTESSELLATIONLEVEL,
3256 D3DRS_MINTESSELLATIONLEVEL,
3257 D3DRS_MULTISAMPLEANTIALIAS,
3258 D3DRS_MULTISAMPLEMASK,
3260 D3DRS_NORMALIZENORMALS,
3261 D3DRS_PATCHEDGESTYLE,
3265 D3DRS_POINTSCALEENABLE,
3267 D3DRS_POINTSIZE_MAX,
3268 D3DRS_POINTSIZE_MIN,
3269 D3DRS_POINTSPRITEENABLE,
3270 D3DRS_POSITIONDEGREE,
3271 D3DRS_RANGEFOGENABLE,
3273 D3DRS_SPECULARENABLE,
3274 D3DRS_SPECULARMATERIALSOURCE,
3279 const uint32_t nine_render_states_vertex
[(NINED3DRS_LAST
+ 31) / 32] =
3281 0x30400200, 0x0001007c, 0x00000000, 0x00000000,
3282 0xfd9efb00, 0x01fc34cf, 0x00000000
3285 /* TODO: put in the right values */
3286 const uint32_t nine_render_state_group
[NINED3DRS_LAST
+ 1] =
3288 [D3DRS_ZENABLE
] = NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
,
3289 [D3DRS_FILLMODE
] = NINE_STATE_RASTERIZER
,
3290 [D3DRS_SHADEMODE
] = NINE_STATE_RASTERIZER
,
3291 [D3DRS_ZWRITEENABLE
] = NINE_STATE_DSA
,
3292 [D3DRS_ALPHATESTENABLE
] = NINE_STATE_DSA
,
3293 [D3DRS_LASTPIXEL
] = NINE_STATE_RASTERIZER
,
3294 [D3DRS_SRCBLEND
] = NINE_STATE_BLEND
,
3295 [D3DRS_DESTBLEND
] = NINE_STATE_BLEND
,
3296 [D3DRS_CULLMODE
] = NINE_STATE_RASTERIZER
,
3297 [D3DRS_ZFUNC
] = NINE_STATE_DSA
,
3298 [D3DRS_ALPHAREF
] = NINE_STATE_DSA
,
3299 [D3DRS_ALPHAFUNC
] = NINE_STATE_DSA
,
3300 [D3DRS_DITHERENABLE
] = NINE_STATE_BLEND
,
3301 [D3DRS_ALPHABLENDENABLE
] = NINE_STATE_BLEND
,
3302 [D3DRS_FOGENABLE
] = NINE_STATE_FF_SHADER
| NINE_STATE_VS_PARAMS_MISC
| NINE_STATE_PS_PARAMS_MISC
| NINE_STATE_PS_CONST
,
3303 [D3DRS_SPECULARENABLE
] = NINE_STATE_FF_LIGHTING
,
3304 [D3DRS_FOGCOLOR
] = NINE_STATE_FF_PS_CONSTS
| NINE_STATE_PS_CONST
,
3305 [D3DRS_FOGTABLEMODE
] = NINE_STATE_FF_SHADER
| NINE_STATE_PS_PARAMS_MISC
| NINE_STATE_PS_CONST
,
3306 [D3DRS_FOGSTART
] = NINE_STATE_FF_VS_OTHER
| NINE_STATE_FF_PS_CONSTS
| NINE_STATE_PS_CONST
,
3307 [D3DRS_FOGEND
] = NINE_STATE_FF_VS_OTHER
| NINE_STATE_FF_PS_CONSTS
| NINE_STATE_PS_CONST
,
3308 [D3DRS_FOGDENSITY
] = NINE_STATE_FF_VS_OTHER
| NINE_STATE_FF_PS_CONSTS
| NINE_STATE_PS_CONST
,
3309 [D3DRS_RANGEFOGENABLE
] = NINE_STATE_FF_SHADER
,
3310 [D3DRS_STENCILENABLE
] = NINE_STATE_DSA
| NINE_STATE_MULTISAMPLE
,
3311 [D3DRS_STENCILFAIL
] = NINE_STATE_DSA
,
3312 [D3DRS_STENCILZFAIL
] = NINE_STATE_DSA
,
3313 [D3DRS_STENCILPASS
] = NINE_STATE_DSA
,
3314 [D3DRS_STENCILFUNC
] = NINE_STATE_DSA
,
3315 [D3DRS_STENCILREF
] = NINE_STATE_STENCIL_REF
,
3316 [D3DRS_STENCILMASK
] = NINE_STATE_DSA
,
3317 [D3DRS_STENCILWRITEMASK
] = NINE_STATE_DSA
,
3318 [D3DRS_TEXTUREFACTOR
] = NINE_STATE_FF_PS_CONSTS
,
3319 [D3DRS_WRAP0
] = NINE_STATE_UNHANDLED
, /* cylindrical wrap is crazy */
3320 [D3DRS_WRAP1
] = NINE_STATE_UNHANDLED
,
3321 [D3DRS_WRAP2
] = NINE_STATE_UNHANDLED
,
3322 [D3DRS_WRAP3
] = NINE_STATE_UNHANDLED
,
3323 [D3DRS_WRAP4
] = NINE_STATE_UNHANDLED
,
3324 [D3DRS_WRAP5
] = NINE_STATE_UNHANDLED
,
3325 [D3DRS_WRAP6
] = NINE_STATE_UNHANDLED
,
3326 [D3DRS_WRAP7
] = NINE_STATE_UNHANDLED
,
3327 [D3DRS_CLIPPING
] = 0, /* software vertex processing only */
3328 [D3DRS_LIGHTING
] = NINE_STATE_FF_LIGHTING
,
3329 [D3DRS_AMBIENT
] = NINE_STATE_FF_LIGHTING
| NINE_STATE_FF_MATERIAL
,
3330 [D3DRS_FOGVERTEXMODE
] = NINE_STATE_FF_SHADER
,
3331 [D3DRS_COLORVERTEX
] = NINE_STATE_FF_LIGHTING
,
3332 [D3DRS_LOCALVIEWER
] = NINE_STATE_FF_LIGHTING
,
3333 [D3DRS_NORMALIZENORMALS
] = NINE_STATE_FF_SHADER
,
3334 [D3DRS_DIFFUSEMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
3335 [D3DRS_SPECULARMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
3336 [D3DRS_AMBIENTMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
3337 [D3DRS_EMISSIVEMATERIALSOURCE
] = NINE_STATE_FF_LIGHTING
,
3338 [D3DRS_VERTEXBLEND
] = NINE_STATE_FF_SHADER
,
3339 [D3DRS_CLIPPLANEENABLE
] = NINE_STATE_RASTERIZER
,
3340 [D3DRS_POINTSIZE
] = NINE_STATE_RASTERIZER
| NINE_STATE_FF_VS_OTHER
,
3341 [D3DRS_POINTSIZE_MIN
] = NINE_STATE_RASTERIZER
| NINE_STATE_FF_VS_OTHER
| NINE_STATE_VS_PARAMS_MISC
,
3342 [D3DRS_POINTSPRITEENABLE
] = NINE_STATE_RASTERIZER
,
3343 [D3DRS_POINTSCALEENABLE
] = NINE_STATE_FF_SHADER
,
3344 [D3DRS_POINTSCALE_A
] = NINE_STATE_FF_VS_OTHER
,
3345 [D3DRS_POINTSCALE_B
] = NINE_STATE_FF_VS_OTHER
,
3346 [D3DRS_POINTSCALE_C
] = NINE_STATE_FF_VS_OTHER
,
3347 [D3DRS_MULTISAMPLEANTIALIAS
] = NINE_STATE_MULTISAMPLE
,
3348 [D3DRS_MULTISAMPLEMASK
] = NINE_STATE_SAMPLE_MASK
,
3349 [D3DRS_PATCHEDGESTYLE
] = NINE_STATE_UNHANDLED
,
3350 [D3DRS_DEBUGMONITORTOKEN
] = NINE_STATE_UNHANDLED
,
3351 [D3DRS_POINTSIZE_MAX
] = NINE_STATE_RASTERIZER
| NINE_STATE_FF_VS_OTHER
| NINE_STATE_VS_PARAMS_MISC
,
3352 [D3DRS_INDEXEDVERTEXBLENDENABLE
] = NINE_STATE_FF_SHADER
,
3353 [D3DRS_COLORWRITEENABLE
] = NINE_STATE_BLEND
,
3354 [D3DRS_TWEENFACTOR
] = NINE_STATE_FF_VS_OTHER
,
3355 [D3DRS_BLENDOP
] = NINE_STATE_BLEND
,
3356 [D3DRS_POSITIONDEGREE
] = NINE_STATE_UNHANDLED
,
3357 [D3DRS_NORMALDEGREE
] = NINE_STATE_UNHANDLED
,
3358 [D3DRS_SCISSORTESTENABLE
] = NINE_STATE_RASTERIZER
,
3359 [D3DRS_SLOPESCALEDEPTHBIAS
] = NINE_STATE_RASTERIZER
,
3360 [D3DRS_ANTIALIASEDLINEENABLE
] = NINE_STATE_RASTERIZER
,
3361 [D3DRS_MINTESSELLATIONLEVEL
] = NINE_STATE_UNHANDLED
,
3362 [D3DRS_MAXTESSELLATIONLEVEL
] = NINE_STATE_UNHANDLED
,
3363 [D3DRS_ADAPTIVETESS_X
] = NINE_STATE_UNHANDLED
,
3364 [D3DRS_ADAPTIVETESS_Y
] = NINE_STATE_UNHANDLED
,
3365 [D3DRS_ADAPTIVETESS_Z
] = NINE_STATE_UNHANDLED
,
3366 [D3DRS_ADAPTIVETESS_W
] = NINE_STATE_UNHANDLED
,
3367 [D3DRS_ENABLEADAPTIVETESSELLATION
] = NINE_STATE_UNHANDLED
,
3368 [D3DRS_TWOSIDEDSTENCILMODE
] = NINE_STATE_DSA
,
3369 [D3DRS_CCW_STENCILFAIL
] = NINE_STATE_DSA
,
3370 [D3DRS_CCW_STENCILZFAIL
] = NINE_STATE_DSA
,
3371 [D3DRS_CCW_STENCILPASS
] = NINE_STATE_DSA
,
3372 [D3DRS_CCW_STENCILFUNC
] = NINE_STATE_DSA
,
3373 [D3DRS_COLORWRITEENABLE1
] = NINE_STATE_BLEND
,
3374 [D3DRS_COLORWRITEENABLE2
] = NINE_STATE_BLEND
,
3375 [D3DRS_COLORWRITEENABLE3
] = NINE_STATE_BLEND
,
3376 [D3DRS_BLENDFACTOR
] = NINE_STATE_BLEND_COLOR
,
3377 [D3DRS_SRGBWRITEENABLE
] = NINE_STATE_FB
,
3378 [D3DRS_DEPTHBIAS
] = NINE_STATE_RASTERIZER
,
3379 [D3DRS_WRAP8
] = NINE_STATE_UNHANDLED
, /* cylwrap has to be done via GP */
3380 [D3DRS_WRAP9
] = NINE_STATE_UNHANDLED
,
3381 [D3DRS_WRAP10
] = NINE_STATE_UNHANDLED
,
3382 [D3DRS_WRAP11
] = NINE_STATE_UNHANDLED
,
3383 [D3DRS_WRAP12
] = NINE_STATE_UNHANDLED
,
3384 [D3DRS_WRAP13
] = NINE_STATE_UNHANDLED
,
3385 [D3DRS_WRAP14
] = NINE_STATE_UNHANDLED
,
3386 [D3DRS_WRAP15
] = NINE_STATE_UNHANDLED
,
3387 [D3DRS_SEPARATEALPHABLENDENABLE
] = NINE_STATE_BLEND
,
3388 [D3DRS_SRCBLENDALPHA
] = NINE_STATE_BLEND
,
3389 [D3DRS_DESTBLENDALPHA
] = NINE_STATE_BLEND
,
3390 [D3DRS_BLENDOPALPHA
] = NINE_STATE_BLEND
3396 nine_state_access_transform(struct nine_ff_state
*ff_state
, D3DTRANSFORMSTATETYPE t
,
3399 static D3DMATRIX Identity
= { .m
[0] = { 1, 0, 0, 0 },
3400 .m
[1] = { 0, 1, 0, 0 },
3401 .m
[2] = { 0, 0, 1, 0 },
3402 .m
[3] = { 0, 0, 0, 1 } };
3406 case D3DTS_VIEW
: index
= 0; break;
3407 case D3DTS_PROJECTION
: index
= 1; break;
3408 case D3DTS_TEXTURE0
: index
= 2; break;
3409 case D3DTS_TEXTURE1
: index
= 3; break;
3410 case D3DTS_TEXTURE2
: index
= 4; break;
3411 case D3DTS_TEXTURE3
: index
= 5; break;
3412 case D3DTS_TEXTURE4
: index
= 6; break;
3413 case D3DTS_TEXTURE5
: index
= 7; break;
3414 case D3DTS_TEXTURE6
: index
= 8; break;
3415 case D3DTS_TEXTURE7
: index
= 9; break;
3417 if (!(t
>= D3DTS_WORLDMATRIX(0) && t
<= D3DTS_WORLDMATRIX(255)))
3419 index
= 10 + (t
- D3DTS_WORLDMATRIX(0));
3423 if (index
>= ff_state
->num_transforms
) {
3424 unsigned N
= index
+ 1;
3425 unsigned n
= ff_state
->num_transforms
;
3429 ff_state
->transform
= REALLOC(ff_state
->transform
,
3430 n
* sizeof(D3DMATRIX
),
3431 N
* sizeof(D3DMATRIX
));
3433 ff_state
->transform
[n
] = Identity
;
3434 ff_state
->num_transforms
= N
;
3436 return &ff_state
->transform
[index
];
3440 nine_state_set_light(struct nine_ff_state
*ff_state
, DWORD Index
,
3441 const D3DLIGHT9
*pLight
)
3443 if (Index
>= ff_state
->num_lights
) {
3444 unsigned n
= ff_state
->num_lights
;
3445 unsigned N
= Index
+ 1;
3447 ff_state
->light
= REALLOC(ff_state
->light
, n
* sizeof(D3DLIGHT9
),
3448 N
* sizeof(D3DLIGHT9
));
3449 if (!ff_state
->light
)
3450 return E_OUTOFMEMORY
;
3451 ff_state
->num_lights
= N
;
3453 for (; n
< Index
; ++n
) {
3454 memset(&ff_state
->light
[n
], 0, sizeof(D3DLIGHT9
));
3455 ff_state
->light
[n
].Type
= (D3DLIGHTTYPE
)NINED3DLIGHT_INVALID
;
3458 ff_state
->light
[Index
] = *pLight
;
3460 if (pLight
->Type
== D3DLIGHT_SPOT
&& pLight
->Theta
>= pLight
->Phi
) {
3461 DBG("Warning: clamping D3DLIGHT9.Theta\n");
3462 ff_state
->light
[Index
].Theta
= ff_state
->light
[Index
].Phi
;
3468 nine_state_light_enable(struct nine_ff_state
*ff_state
, uint32_t *change_group
,
3469 DWORD Index
, BOOL Enable
)
3473 user_assert(Index
< ff_state
->num_lights
, D3DERR_INVALIDCALL
);
3475 for (i
= 0; i
< ff_state
->num_lights_active
; ++i
) {
3476 if (ff_state
->active_light
[i
] == Index
)
3481 if (i
< ff_state
->num_lights_active
)
3483 /* XXX wine thinks this should still succeed:
3485 user_assert(i
< NINE_MAX_LIGHTS_ACTIVE
, D3DERR_INVALIDCALL
);
3487 ff_state
->active_light
[i
] = Index
;
3488 ff_state
->num_lights_active
++;
3490 if (i
== ff_state
->num_lights_active
)
3492 --ff_state
->num_lights_active
;
3493 for (; i
< ff_state
->num_lights_active
; ++i
)
3494 ff_state
->active_light
[i
] = ff_state
->active_light
[i
+ 1];
3497 *change_group
|= NINE_STATE_FF_LIGHTING
;
3502 #define D3DRS_TO_STRING_CASE(n) case D3DRS_##n: return "D3DRS_"#n
3503 const char *nine_d3drs_to_string(DWORD State
)
3506 D3DRS_TO_STRING_CASE(ZENABLE
);
3507 D3DRS_TO_STRING_CASE(FILLMODE
);
3508 D3DRS_TO_STRING_CASE(SHADEMODE
);
3509 D3DRS_TO_STRING_CASE(ZWRITEENABLE
);
3510 D3DRS_TO_STRING_CASE(ALPHATESTENABLE
);
3511 D3DRS_TO_STRING_CASE(LASTPIXEL
);
3512 D3DRS_TO_STRING_CASE(SRCBLEND
);
3513 D3DRS_TO_STRING_CASE(DESTBLEND
);
3514 D3DRS_TO_STRING_CASE(CULLMODE
);
3515 D3DRS_TO_STRING_CASE(ZFUNC
);
3516 D3DRS_TO_STRING_CASE(ALPHAREF
);
3517 D3DRS_TO_STRING_CASE(ALPHAFUNC
);
3518 D3DRS_TO_STRING_CASE(DITHERENABLE
);
3519 D3DRS_TO_STRING_CASE(ALPHABLENDENABLE
);
3520 D3DRS_TO_STRING_CASE(FOGENABLE
);
3521 D3DRS_TO_STRING_CASE(SPECULARENABLE
);
3522 D3DRS_TO_STRING_CASE(FOGCOLOR
);
3523 D3DRS_TO_STRING_CASE(FOGTABLEMODE
);
3524 D3DRS_TO_STRING_CASE(FOGSTART
);
3525 D3DRS_TO_STRING_CASE(FOGEND
);
3526 D3DRS_TO_STRING_CASE(FOGDENSITY
);
3527 D3DRS_TO_STRING_CASE(RANGEFOGENABLE
);
3528 D3DRS_TO_STRING_CASE(STENCILENABLE
);
3529 D3DRS_TO_STRING_CASE(STENCILFAIL
);
3530 D3DRS_TO_STRING_CASE(STENCILZFAIL
);
3531 D3DRS_TO_STRING_CASE(STENCILPASS
);
3532 D3DRS_TO_STRING_CASE(STENCILFUNC
);
3533 D3DRS_TO_STRING_CASE(STENCILREF
);
3534 D3DRS_TO_STRING_CASE(STENCILMASK
);
3535 D3DRS_TO_STRING_CASE(STENCILWRITEMASK
);
3536 D3DRS_TO_STRING_CASE(TEXTUREFACTOR
);
3537 D3DRS_TO_STRING_CASE(WRAP0
);
3538 D3DRS_TO_STRING_CASE(WRAP1
);
3539 D3DRS_TO_STRING_CASE(WRAP2
);
3540 D3DRS_TO_STRING_CASE(WRAP3
);
3541 D3DRS_TO_STRING_CASE(WRAP4
);
3542 D3DRS_TO_STRING_CASE(WRAP5
);
3543 D3DRS_TO_STRING_CASE(WRAP6
);
3544 D3DRS_TO_STRING_CASE(WRAP7
);
3545 D3DRS_TO_STRING_CASE(CLIPPING
);
3546 D3DRS_TO_STRING_CASE(LIGHTING
);
3547 D3DRS_TO_STRING_CASE(AMBIENT
);
3548 D3DRS_TO_STRING_CASE(FOGVERTEXMODE
);
3549 D3DRS_TO_STRING_CASE(COLORVERTEX
);
3550 D3DRS_TO_STRING_CASE(LOCALVIEWER
);
3551 D3DRS_TO_STRING_CASE(NORMALIZENORMALS
);
3552 D3DRS_TO_STRING_CASE(DIFFUSEMATERIALSOURCE
);
3553 D3DRS_TO_STRING_CASE(SPECULARMATERIALSOURCE
);
3554 D3DRS_TO_STRING_CASE(AMBIENTMATERIALSOURCE
);
3555 D3DRS_TO_STRING_CASE(EMISSIVEMATERIALSOURCE
);
3556 D3DRS_TO_STRING_CASE(VERTEXBLEND
);
3557 D3DRS_TO_STRING_CASE(CLIPPLANEENABLE
);
3558 D3DRS_TO_STRING_CASE(POINTSIZE
);
3559 D3DRS_TO_STRING_CASE(POINTSIZE_MIN
);
3560 D3DRS_TO_STRING_CASE(POINTSPRITEENABLE
);
3561 D3DRS_TO_STRING_CASE(POINTSCALEENABLE
);
3562 D3DRS_TO_STRING_CASE(POINTSCALE_A
);
3563 D3DRS_TO_STRING_CASE(POINTSCALE_B
);
3564 D3DRS_TO_STRING_CASE(POINTSCALE_C
);
3565 D3DRS_TO_STRING_CASE(MULTISAMPLEANTIALIAS
);
3566 D3DRS_TO_STRING_CASE(MULTISAMPLEMASK
);
3567 D3DRS_TO_STRING_CASE(PATCHEDGESTYLE
);
3568 D3DRS_TO_STRING_CASE(DEBUGMONITORTOKEN
);
3569 D3DRS_TO_STRING_CASE(POINTSIZE_MAX
);
3570 D3DRS_TO_STRING_CASE(INDEXEDVERTEXBLENDENABLE
);
3571 D3DRS_TO_STRING_CASE(COLORWRITEENABLE
);
3572 D3DRS_TO_STRING_CASE(TWEENFACTOR
);
3573 D3DRS_TO_STRING_CASE(BLENDOP
);
3574 D3DRS_TO_STRING_CASE(POSITIONDEGREE
);
3575 D3DRS_TO_STRING_CASE(NORMALDEGREE
);
3576 D3DRS_TO_STRING_CASE(SCISSORTESTENABLE
);
3577 D3DRS_TO_STRING_CASE(SLOPESCALEDEPTHBIAS
);
3578 D3DRS_TO_STRING_CASE(ANTIALIASEDLINEENABLE
);
3579 D3DRS_TO_STRING_CASE(MINTESSELLATIONLEVEL
);
3580 D3DRS_TO_STRING_CASE(MAXTESSELLATIONLEVEL
);
3581 D3DRS_TO_STRING_CASE(ADAPTIVETESS_X
);
3582 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Y
);
3583 D3DRS_TO_STRING_CASE(ADAPTIVETESS_Z
);
3584 D3DRS_TO_STRING_CASE(ADAPTIVETESS_W
);
3585 D3DRS_TO_STRING_CASE(ENABLEADAPTIVETESSELLATION
);
3586 D3DRS_TO_STRING_CASE(TWOSIDEDSTENCILMODE
);
3587 D3DRS_TO_STRING_CASE(CCW_STENCILFAIL
);
3588 D3DRS_TO_STRING_CASE(CCW_STENCILZFAIL
);
3589 D3DRS_TO_STRING_CASE(CCW_STENCILPASS
);
3590 D3DRS_TO_STRING_CASE(CCW_STENCILFUNC
);
3591 D3DRS_TO_STRING_CASE(COLORWRITEENABLE1
);
3592 D3DRS_TO_STRING_CASE(COLORWRITEENABLE2
);
3593 D3DRS_TO_STRING_CASE(COLORWRITEENABLE3
);
3594 D3DRS_TO_STRING_CASE(BLENDFACTOR
);
3595 D3DRS_TO_STRING_CASE(SRGBWRITEENABLE
);
3596 D3DRS_TO_STRING_CASE(DEPTHBIAS
);
3597 D3DRS_TO_STRING_CASE(WRAP8
);
3598 D3DRS_TO_STRING_CASE(WRAP9
);
3599 D3DRS_TO_STRING_CASE(WRAP10
);
3600 D3DRS_TO_STRING_CASE(WRAP11
);
3601 D3DRS_TO_STRING_CASE(WRAP12
);
3602 D3DRS_TO_STRING_CASE(WRAP13
);
3603 D3DRS_TO_STRING_CASE(WRAP14
);
3604 D3DRS_TO_STRING_CASE(WRAP15
);
3605 D3DRS_TO_STRING_CASE(SEPARATEALPHABLENDENABLE
);
3606 D3DRS_TO_STRING_CASE(SRCBLENDALPHA
);
3607 D3DRS_TO_STRING_CASE(DESTBLENDALPHA
);
3608 D3DRS_TO_STRING_CASE(BLENDOPALPHA
);