summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/nine/nine_state.h
blob: 6578be363c1af737d992b4c5fca0aeea801acbc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/*
 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE. */

#ifndef _NINE_STATE_H_
#define _NINE_STATE_H_

#include "d3d9.h"
#include "nine_defines.h"
#include "pipe/p_state.h"
#include "util/list.h"

#define NINED3DSAMP_MINLOD (D3DSAMP_DMAPOFFSET + 1)
#define NINED3DSAMP_SHADOW (D3DSAMP_DMAPOFFSET + 2)
#define NINED3DSAMP_CUBETEX (D3DSAMP_DMAPOFFSET + 3)

#define NINED3DRS_VSPOINTSIZE (D3DRS_BLENDOPALPHA + 1)
#define NINED3DRS_RTMASK      (D3DRS_BLENDOPALPHA + 2)
/* ALPHACOVERAGE:
 * bit 0: enable alpha coverage
 * bit 1: ATOC is on
 */
#define NINED3DRS_ALPHACOVERAGE  (D3DRS_BLENDOPALPHA + 3)
#define NINED3DRS_MULTISAMPLE  (D3DRS_BLENDOPALPHA + 4)

#define D3DRS_LAST       D3DRS_BLENDOPALPHA
#define D3DSAMP_LAST     D3DSAMP_DMAPOFFSET
#define NINED3DRS_LAST   NINED3DRS_MULTISAMPLE /* 214 */
#define NINED3DSAMP_LAST NINED3DSAMP_CUBETEX /* 16 */
#define NINED3DTSS_LAST  D3DTSS_CONSTANT
#define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)

#define D3DRS_COUNT       (D3DRS_LAST + 1)
#define D3DSAMP_COUNT     (D3DSAMP_LAST + 1)
#define NINED3DRS_COUNT   (NINED3DRS_LAST + 1)
#define NINED3DSAMP_COUNT (NINED3DSAMP_LAST + 1)
#define NINED3DTSS_COUNT  (NINED3DTSS_LAST + 1)
#define NINED3DTS_COUNT   (NINED3DTS_LAST + 1)

#define NINE_STATE_FB          (1 <<  0)
#define NINE_STATE_VIEWPORT    (1 <<  1)
#define NINE_STATE_SCISSOR     (1 <<  2)
#define NINE_STATE_RASTERIZER  (1 <<  3)
#define NINE_STATE_BLEND       (1 <<  4)
#define NINE_STATE_DSA         (1 <<  5)
#define NINE_STATE_VS          (1 <<  6)
#define NINE_STATE_VS_CONST    (1 <<  7)
#define NINE_STATE_PS          (1 <<  8)
#define NINE_STATE_PS_CONST    (1 <<  9)
#define NINE_STATE_TEXTURE     (1 << 10)
#define NINE_STATE_SAMPLER     (1 << 11)
#define NINE_STATE_VDECL       (1 << 12)
#define NINE_STATE_IDXBUF      (1 << 13)
#define NINE_STATE_STREAMFREQ  (1 << 14)
#define NINE_STATE_PRIM        (1 << 15)
#define NINE_STATE_MATERIAL    (1 << 16)
#define NINE_STATE_BLEND_COLOR (1 << 17)
#define NINE_STATE_STENCIL_REF (1 << 18)
#define NINE_STATE_SAMPLE_MASK (1 << 19)
#define NINE_STATE_FF          (0x1f << 20)
#define NINE_STATE_FF_VS       (0x17 << 20)
#define NINE_STATE_FF_PS       (0x18 << 20)
#define NINE_STATE_FF_LIGHTING (1 << 20)
#define NINE_STATE_FF_MATERIAL (1 << 21)
#define NINE_STATE_FF_VSTRANSF (1 << 22)
#define NINE_STATE_FF_PSSTAGES (1 << 23)
#define NINE_STATE_FF_OTHER    (1 << 24)
#define NINE_STATE_FOG_SHADER  (1 << 25)
#define NINE_STATE_PS1X_SHADER (1 << 26)
#define NINE_STATE_POINTSIZE_SHADER (1 << 27)
#define NINE_STATE_MULTISAMPLE (1 << 28)
#define NINE_STATE_SWVP        (1 << 29)
#define NINE_STATE_ALL          0x3fffffff
#define NINE_STATE_UNHANDLED   (1 << 30)

#define NINE_STATE_COMMIT_DSA  (1 << 0)
#define NINE_STATE_COMMIT_RASTERIZER (1 << 1)
#define NINE_STATE_COMMIT_BLEND (1 << 2)
#define NINE_STATE_COMMIT_CONST_VS (1 << 3)
#define NINE_STATE_COMMIT_CONST_PS (1 << 4)
#define NINE_STATE_COMMIT_VS (1 << 5)
#define NINE_STATE_COMMIT_PS (1 << 6)


#define NINE_MAX_SIMULTANEOUS_RENDERTARGETS 4
#define NINE_MAX_CONST_F_PS3 224
#define NINE_MAX_CONST_F   256
#define NINE_MAX_CONST_I   16
#define NINE_MAX_CONST_B   16
#define NINE_MAX_CONST_F_SWVP   8192
#define NINE_MAX_CONST_I_SWVP   2048
#define NINE_MAX_CONST_B_SWVP   2048
#define NINE_MAX_CONST_ALL 276 /* B consts count only 1/4 th */

#define NINE_CONST_I_BASE(nconstf) \
    ((nconstf)        * 4 * sizeof(float))
#define NINE_CONST_B_BASE(nconstf) \
    ((nconstf)        * 4 * sizeof(float) + \
     NINE_MAX_CONST_I * 4 * sizeof(int))

#define VS_CONST_F_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_F_SWVP * sizeof(float[4])) : (NINE_MAX_CONST_F * sizeof(float[4])))
#define VS_CONST_I_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_I_SWVP * sizeof(int[4])) : (NINE_MAX_CONST_I * sizeof(int[4])))
#define VS_CONST_B_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_B_SWVP * sizeof(BOOL)) : (NINE_MAX_CONST_B * sizeof(BOOL)))


#define NINE_MAX_TEXTURE_STAGES 8

#define NINE_MAX_LIGHTS        65536
#define NINE_MAX_LIGHTS_ACTIVE 8

#define NINED3DLIGHT_INVALID (D3DLIGHT_DIRECTIONAL + 1)

#define NINE_MAX_SAMPLERS_PS 16
#define NINE_MAX_SAMPLERS_VS  4
#define NINE_MAX_SAMPLERS    21 /* PS + DMAP + VS */
#define NINE_SAMPLER_PS(s)  ( 0 + (s))
#define NINE_SAMPLER_DMAP    16
#define NINE_SAMPLER_VS(s)  (17 + (s))
#define NINE_PS_SAMPLERS_MASK 0x00ffff
#define NINE_VS_SAMPLERS_MASK 0x1e0000

struct nine_ff_state {
    struct {
        uint32_t tex_stage[NINE_MAX_TEXTURE_STAGES][(NINED3DTSS_COUNT + 31) / 32]; /* stateblocks only */
        uint32_t transform[(NINED3DTS_COUNT + 31) / 32];
    } changed;

    D3DMATRIX *transform; /* access only via nine_state_access_transform */
    unsigned num_transforms;

    /* XXX: Do state blocks just change the set of active lights or do we
     * have to store which lights have been disabled, too ?
     */
    D3DLIGHT9 *light;
    uint16_t active_light[NINE_MAX_LIGHTS_ACTIVE]; /* 8 */
    unsigned num_lights;
    unsigned num_lights_active;

    D3DMATERIAL9 material;

    DWORD tex_stage[NINE_MAX_TEXTURE_STAGES][NINED3DTSS_COUNT];
};

struct nine_state
{
    struct {
        uint32_t group;
        uint32_t rs[(NINED3DRS_COUNT + 31) / 32];
        uint32_t vtxbuf;
        uint32_t stream_freq;
        uint32_t texture;
        uint16_t sampler[NINE_MAX_SAMPLERS];
        struct nine_range *vs_const_f;
        struct nine_range *ps_const_f;
        struct nine_range *vs_const_i;
        uint16_t ps_const_i; /* NINE_MAX_CONST_I == 16 */
        struct nine_range *vs_const_b;
        uint16_t ps_const_b; /* NINE_MAX_CONST_B == 16 */
        uint8_t ucp;
    } changed; /* stateblocks only */

    struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
    struct NineSurface9 *ds;

    D3DVIEWPORT9 viewport;

    struct pipe_scissor_state scissor;

    /* NOTE: vs, ps will be NULL for FF and are set in device->ff.vs,ps instead
     *  (XXX: or is it better to reference FF shaders here, too ?)
     * NOTE: const_f contains extra space for const_i,b to use as user constbuf
     */
    struct NineVertexShader9 *vs;
    float *vs_const_f;
    int   *vs_const_i;
    BOOL  *vs_const_b;
    float *vs_lconstf_temp; /* ProcessVertices */

    struct NinePixelShader9 *ps;
    float *ps_const_f;
    int    ps_const_i[NINE_MAX_CONST_I][4];
    BOOL   ps_const_b[NINE_MAX_CONST_B];

    struct NineVertexDeclaration9 *vdecl;

    struct NineIndexBuffer9   *idxbuf;
    struct NineVertexBuffer9  *stream[PIPE_MAX_ATTRIBS];
    struct pipe_vertex_buffer  vtxbuf[PIPE_MAX_ATTRIBS]; /* vtxbuf.buffer unused */
    UINT stream_freq[PIPE_MAX_ATTRIBS];

    struct pipe_clip_state clip;

    DWORD rs_advertised[NINED3DRS_COUNT]; /* the ones apps get with GetRenderState */

    struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */

    DWORD samp_advertised[NINE_MAX_SAMPLERS][D3DSAMP_COUNT];

    struct nine_ff_state ff;
};

struct nine_context {
    struct {
        uint32_t group;
        uint16_t sampler[NINE_MAX_SAMPLERS];
        uint32_t vtxbuf;
        BOOL vs_const_f;
        BOOL vs_const_i;
        BOOL vs_const_b;
        BOOL ps_const_f;
        BOOL ps_const_i;
        BOOL ps_const_b;
        BOOL ucp;
    } changed;

    uint32_t bumpmap_vars[6 * NINE_MAX_TEXTURE_STAGES];

    struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
    struct NineSurface9 *ds;

    struct {
        void *vs;
        void *ps;
    } cso_shader;

    struct pipe_context *pipe;
    struct cso_context *cso;

    uint8_t rt_mask;

    D3DVIEWPORT9 viewport;

    struct pipe_scissor_state scissor;

    struct NineVertexShader9 *vs;
    BOOL programmable_vs;
    float *vs_const_f;
    float *vs_const_f_swvp;
    int   *vs_const_i;
    BOOL  *vs_const_b;
    float *vs_lconstf_temp;

    struct NinePixelShader9 *ps;
    float *ps_const_f;
    int    ps_const_i[NINE_MAX_CONST_I][4];
    BOOL   ps_const_b[NINE_MAX_CONST_B];
    float *ps_lconstf_temp;

    struct NineVertexDeclaration9 *vdecl;

    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
    UINT stream_freq[PIPE_MAX_ATTRIBS];
    uint32_t stream_instancedata_mask; /* derived from stream_freq */
    uint32_t stream_usage_mask; /* derived from VS and vdecl */

    struct pipe_index_buffer idxbuf;

    struct pipe_clip_state clip;

    DWORD rs[NINED3DRS_COUNT];

    struct {
        BOOL enabled;
        BOOL shadow;
        DWORD lod;
        D3DRESOURCETYPE type;
        struct pipe_resource *resource;
        struct pipe_sampler_view *view[2];
        uint8_t pstype;
    } texture[NINE_MAX_SAMPLERS];

    DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];

    uint32_t samplers_shadow;

    uint8_t bound_samplers_mask_vs;
    uint16_t bound_samplers_mask_ps;

    int dummy_vbo_bound_at; /* -1 = not bound , >= 0 = bound index */
    boolean vbo_bound_done;

    struct nine_ff_state ff;

    /* software vertex processing */
    boolean swvp;

    uint32_t commit;
    struct {
        struct pipe_framebuffer_state fb;
        struct pipe_depth_stencil_alpha_state dsa;
        struct pipe_rasterizer_state rast;
        struct pipe_blend_state blend;
        struct pipe_constant_buffer cb_vs;
        struct pipe_constant_buffer cb0_swvp;
        struct pipe_constant_buffer cb1_swvp;
        struct pipe_constant_buffer cb2_swvp;
        struct pipe_constant_buffer cb3_swvp;
        struct pipe_constant_buffer cb_ps;
        struct pipe_constant_buffer cb_vs_ff;
        struct pipe_constant_buffer cb_ps_ff;
    } pipe_data;
};

struct nine_state_sw_internal {
    struct pipe_transfer *transfers_so[4];
};

struct nine_clipplane {
    float plane[4];
};
/* map D3DRS -> NINE_STATE_x
 */
extern const uint32_t nine_render_state_group[NINED3DRS_COUNT];

/* for D3DSBT_PIXEL/VERTEX:
 */
extern const uint32_t nine_render_states_pixel[(NINED3DRS_COUNT + 31) / 32];
extern const uint32_t nine_render_states_vertex[(NINED3DRS_COUNT + 31) / 32];

struct NineDevice9;

/* Internal multithreading: When enabled, the nine_context functions
 * will append work to a worker thread when possible. Only the worker
 * thread can access struct nine_context. */

void
nine_context_set_render_state(struct NineDevice9 *device,
                              D3DRENDERSTATETYPE State,
                              DWORD Value);

void
nine_context_set_texture(struct NineDevice9 *device,
                         DWORD Stage,
                         struct NineBaseTexture9 *tex);

void
nine_context_set_sampler_state(struct NineDevice9 *device,
                               DWORD Sampler,
                               D3DSAMPLERSTATETYPE Type,
                               DWORD Value);

void
nine_context_set_stream_source(struct NineDevice9 *device,
                               UINT StreamNumber,
                               struct NineVertexBuffer9 *pVBuf9,
                               UINT OffsetInBytes,
                               UINT Stride);

void
nine_context_set_stream_source_freq(struct NineDevice9 *device,
                                    UINT StreamNumber,
                                    UINT Setting);

void
nine_context_set_indices(struct NineDevice9 *device,
                         struct NineIndexBuffer9 *idxbuf);

void
nine_context_set_vertex_declaration(struct NineDevice9 *device,
                                    struct NineVertexDeclaration9 *vdecl);

void
nine_context_set_vertex_shader(struct NineDevice9 *device,
                               struct NineVertexShader9 *pShader);

void
nine_context_set_vertex_shader_constant_f(struct NineDevice9 *device,
                                          UINT StartRegister,
                                          const float *pConstantData,
                                          const unsigned pConstantData_size,
                                          UINT Vector4fCount);

void
nine_context_set_vertex_shader_constant_i(struct NineDevice9 *device,
                                          UINT StartRegister,
                                          const int *pConstantData,
                                          const unsigned pConstantData_size,
                                          UINT Vector4iCount);

void
nine_context_set_vertex_shader_constant_b(struct NineDevice9 *device,
                                          UINT StartRegister,
                                          const BOOL *pConstantData,
                                          const unsigned pConstantData_size,
                                          UINT BoolCount);

void
nine_context_set_pixel_shader(struct NineDevice9 *device,
                              struct NinePixelShader9* ps);

void
nine_context_set_pixel_shader_constant_f(struct NineDevice9 *device,
                                        UINT StartRegister,
                                        const float *pConstantData,
                                        const unsigned pConstantData_size,
                                        UINT Vector4fCount);

void
nine_context_set_pixel_shader_constant_i(struct NineDevice9 *device,
                                         UINT StartRegister,
                                         const int *pConstantData,
                                         const unsigned pConstantData_size,
                                         UINT Vector4iCount);

void
nine_context_set_pixel_shader_constant_b(struct NineDevice9 *device,
                                         UINT StartRegister,
                                         const BOOL *pConstantData,
                                         const unsigned pConstantData_size,
                                         UINT BoolCount);

void
nine_context_set_viewport(struct NineDevice9 *device,
                          const D3DVIEWPORT9 *viewport);

void
nine_context_set_scissor(struct NineDevice9 *device,
                         const struct pipe_scissor_state *scissor);

void
nine_context_set_transform(struct NineDevice9 *device,
                           D3DTRANSFORMSTATETYPE State,
                           const D3DMATRIX *pMatrix);

void
nine_context_set_material(struct NineDevice9 *device,
                          const D3DMATERIAL9 *pMaterial);

void
nine_context_set_light(struct NineDevice9 *device,
                       DWORD Index,
                       const D3DLIGHT9 *pLight);

void
nine_context_light_enable(struct NineDevice9 *device,
                          DWORD Index,
                          BOOL Enable);

void
nine_context_set_texture_stage_state(struct NineDevice9 *device,
                                     DWORD Stage,
                                     D3DTEXTURESTAGESTATETYPE Type,
                                     DWORD Value);

void
nine_context_set_render_target(struct NineDevice9 *device,
                               DWORD RenderTargetIndex,
                               struct NineSurface9 *rt);

void
nine_context_set_depth_stencil(struct NineDevice9 *device,
                               struct NineSurface9 *ds);

void
nine_context_set_clip_plane(struct NineDevice9 *device,
                            DWORD Index,
                            const struct nine_clipplane *pPlane);

void
nine_context_set_swvp(struct NineDevice9 *device,
                      boolean swvp);

void
nine_context_apply_stateblock(struct NineDevice9 *device,
                              const struct nine_state *src);

void
nine_context_clear_fb(struct NineDevice9 *device, DWORD Count,
                      const D3DRECT *pRects, DWORD Flags,
                      D3DCOLOR Color, float Z, DWORD Stencil);

void
nine_context_draw_primitive(struct NineDevice9 *device,
                            D3DPRIMITIVETYPE PrimitiveType,
                            UINT StartVertex,
                            UINT PrimitiveCount);

void
nine_context_draw_indexed_primitive(struct NineDevice9 *device,
                                    D3DPRIMITIVETYPE PrimitiveType,
                                    INT BaseVertexIndex,
                                    UINT MinVertexIndex,
                                    UINT NumVertices,
                                    UINT StartIndex,
                                    UINT PrimitiveCount);

void
nine_context_draw_primitive_from_vtxbuf(struct NineDevice9 *device,
                                        D3DPRIMITIVETYPE PrimitiveType,
                                        UINT PrimitiveCount,
                                        struct pipe_vertex_buffer *vtxbuf);

void
nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(struct NineDevice9 *device,
                                                       D3DPRIMITIVETYPE PrimitiveType,
                                                       UINT MinVertexIndex,
                                                       UINT NumVertices,
                                                       UINT PrimitiveCount,
                                                       struct pipe_vertex_buffer *vbuf,
                                                       struct pipe_index_buffer *ibuf);

void
nine_context_resource_copy_region(struct NineDevice9 *device,
                                  struct pipe_resource* dst_res,
                                  unsigned dst_level,
                                  const struct pipe_box *dst_box,
                                  struct pipe_resource* src_res,
                                  unsigned src_level,
                                  const struct pipe_box *src_box);

void
nine_context_blit(struct NineDevice9 *device,
                  struct pipe_blit_info *blit);

void
nine_context_clear_render_target(struct NineDevice9 *device,
                                 struct NineSurface9 *surface,
                                 D3DCOLOR color,
                                 UINT x,
                                 UINT y,
                                 UINT width,
                                 UINT height);

struct pipe_query *
nine_context_create_query(struct NineDevice9 *device, unsigned query_type);

void
nine_context_destroy_query(struct NineDevice9 *device, struct pipe_query *query);

void
nine_context_begin_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);

void
nine_context_end_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);

boolean
nine_context_get_query_result(struct NineDevice9 *device, struct pipe_query *query,
                              unsigned *counter, boolean flush, boolean wait,
                              union pipe_query_result *result);

void nine_state_restore_non_cso(struct NineDevice9 *device);
void nine_state_set_defaults(struct NineDevice9 *, const D3DCAPS9 *,
                             boolean is_reset);
void nine_state_clear(struct nine_state *, const boolean device);
void nine_context_clear(struct NineDevice9 *);

void nine_state_init_sw(struct NineDevice9 *device);
void nine_state_prepare_draw_sw(struct NineDevice9 *device,
                                struct NineVertexDeclaration9 *vdecl_out,
                                int start_vertice,
                                int num_vertices,
                                struct pipe_stream_output_info *so);
void nine_state_after_draw_sw(struct NineDevice9 *device);
void nine_state_destroy_sw(struct NineDevice9 *device);

/* If @alloc is FALSE, the return value may be a const identity matrix.
 * Therefore, do not modify if you set alloc to FALSE !
 */
D3DMATRIX *
nine_state_access_transform(struct nine_ff_state *, D3DTRANSFORMSTATETYPE,
                            boolean alloc);

HRESULT
nine_state_set_light(struct nine_ff_state *, DWORD, const D3DLIGHT9 *);

HRESULT
nine_state_light_enable(struct nine_ff_state *, uint32_t *,
                        DWORD, BOOL);

const char *nine_d3drs_to_string(DWORD State);

/* CSMT functions */
struct csmt_context;

struct csmt_context *
nine_csmt_create( struct NineDevice9 *This );

void
nine_csmt_destroy( struct NineDevice9 *This, struct csmt_context *ctx );

void
nine_csmt_process( struct NineDevice9 *This );


/* Get the pipe_context (should not be called from the worker thread).
 * All the work in the worker thread is finished before returning. */
struct pipe_context *
nine_context_get_pipe( struct NineDevice9 *device );

/* Can be called from all threads */
struct pipe_context *
nine_context_get_pipe_multithread( struct NineDevice9 *device );


/* Get the pipe_context (should not be called from the worker thread).
 * All the work in the worker thread is paused before returning.
 * It is neccessary to release in order to restart the thread.
 * This is intended for use of the nine_context pipe_context that don't
 * need the worker thread to finish all queued job. */
struct pipe_context *
nine_context_get_pipe_acquire( struct NineDevice9 *device );

void
nine_context_get_pipe_release( struct NineDevice9 *device );

#endif /* _NINE_STATE_H_ */