• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22 
23 #ifndef _NINE_STATE_H_
24 #define _NINE_STATE_H_
25 
26 #include "d3d9.h"
27 #include "iunknown.h"
28 #include "nine_defines.h"
29 #include "pipe/p_state.h"
30 #include "util/list.h"
31 
32 #define NINED3DSAMP_MINLOD (D3DSAMP_DMAPOFFSET + 1)
33 #define NINED3DSAMP_SHADOW (D3DSAMP_DMAPOFFSET + 2)
34 #define NINED3DSAMP_CUBETEX (D3DSAMP_DMAPOFFSET + 3)
35 
36 #define NINED3DRS_VSPOINTSIZE (D3DRS_BLENDOPALPHA + 1)
37 #define NINED3DRS_RTMASK      (D3DRS_BLENDOPALPHA + 2)
38 /* ALPHACOVERAGE:
39  * bit 0: enable alpha coverage
40  * bit 1: ATOC is on
41  */
42 #define NINED3DRS_ALPHACOVERAGE  (D3DRS_BLENDOPALPHA + 3)
43 #define NINED3DRS_MULTISAMPLE  (D3DRS_BLENDOPALPHA + 4)
44 #define NINED3DRS_FETCH4  (D3DRS_BLENDOPALPHA + 5)
45 #define NINED3DRS_EMULATED_ALPHATEST  (D3DRS_BLENDOPALPHA + 6)
46 #define NINED3DRS_POSITIONT (D3DRS_BLENDOPALPHA + 7)
47 
48 #define D3DRS_LAST       D3DRS_BLENDOPALPHA
49 #define D3DSAMP_LAST     D3DSAMP_DMAPOFFSET
50 #define NINED3DRS_LAST   NINED3DRS_POSITIONT /* 217 */
51 #define NINED3DSAMP_LAST NINED3DSAMP_CUBETEX /* 16 */
52 #define NINED3DTSS_LAST  D3DTSS_CONSTANT
53 #define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)
54 
55 #define D3DRS_COUNT       (D3DRS_LAST + 1)
56 #define D3DSAMP_COUNT     (D3DSAMP_LAST + 1)
57 #define NINED3DRS_COUNT   (NINED3DRS_LAST + 1)
58 #define NINED3DSAMP_COUNT (NINED3DSAMP_LAST + 1)
59 #define NINED3DTSS_COUNT  (NINED3DTSS_LAST + 1)
60 #define NINED3DTS_COUNT   (NINED3DTS_LAST + 1)
61 
62 #define NINE_STATE_FB          (1 <<  0)
63 #define NINE_STATE_VIEWPORT    (1 <<  1)
64 #define NINE_STATE_SCISSOR     (1 <<  2)
65 #define NINE_STATE_RASTERIZER  (1 <<  3)
66 #define NINE_STATE_BLEND       (1 <<  4)
67 #define NINE_STATE_DSA         (1 <<  5)
68 #define NINE_STATE_VS          (1 <<  6)
69 #define NINE_STATE_VS_CONST    (1 <<  7)
70 #define NINE_STATE_PS          (1 <<  8)
71 #define NINE_STATE_PS_CONST    (1 <<  9)
72 #define NINE_STATE_TEXTURE     (1 << 10)
73 #define NINE_STATE_SAMPLER     (1 << 11)
74 #define NINE_STATE_VDECL       (1 << 12)
75 #define NINE_STATE_IDXBUF      (1 << 13)
76 #define NINE_STATE_STREAMFREQ  (1 << 14)
77 #define NINE_STATE_BLEND_COLOR (1 << 17)
78 #define NINE_STATE_STENCIL_REF (1 << 18)
79 #define NINE_STATE_SAMPLE_MASK (1 << 19)
80 #define NINE_STATE_FF          (0x1f << 20)
81 #define NINE_STATE_FF_VS       (0x17 << 20)
82 #define NINE_STATE_FF_PS       (0x08 << 20)
83 #define NINE_STATE_FF_LIGHTING (1 << 20)
84 #define NINE_STATE_FF_MATERIAL (1 << 21)
85 #define NINE_STATE_FF_VSTRANSF (1 << 22)
86 #define NINE_STATE_FF_PS_CONSTS (1 << 23)
87 #define NINE_STATE_FF_VS_OTHER  (1 << 24)
88 #define NINE_STATE_VS_PARAMS_MISC  (1 << 25)
89 #define NINE_STATE_PS_PARAMS_MISC (1 << 26)
90 #define NINE_STATE_MULTISAMPLE (1 << 27)
91 #define NINE_STATE_SWVP        (1 << 28)
92 #define NINE_STATE_ALL          0x1fffffff
93 #define NINE_STATE_UNHANDLED   (1 << 29)
94 
95 /* These states affect the ff shader key,
96  * which we recompute everytime. */
97 #define NINE_STATE_FF_SHADER    0
98 
99 #define NINE_STATE_COMMIT_DSA  (1 << 0)
100 #define NINE_STATE_COMMIT_RASTERIZER (1 << 1)
101 #define NINE_STATE_COMMIT_BLEND (1 << 2)
102 #define NINE_STATE_COMMIT_CONST_VS (1 << 3)
103 #define NINE_STATE_COMMIT_CONST_PS (1 << 4)
104 #define NINE_STATE_COMMIT_VS (1 << 5)
105 #define NINE_STATE_COMMIT_PS (1 << 6)
106 
107 
108 #define NINE_MAX_SIMULTANEOUS_RENDERTARGETS 4
109 #define NINE_MAX_CONST_F_PS3 224
110 #define NINE_MAX_CONST_F   256
111 #define NINE_MAX_CONST_I   16
112 #define NINE_MAX_CONST_B   16
113 #define NINE_MAX_CONST_F_SWVP   8192
114 #define NINE_MAX_CONST_I_SWVP   2048
115 #define NINE_MAX_CONST_B_SWVP   2048
116 #define NINE_MAX_CONST_VS_SPE_OFFSET (NINE_MAX_CONST_F + (NINE_MAX_CONST_I + NINE_MAX_CONST_B / 4)) /* B consts count only 1/4 th */
117 #define NINE_MAX_CONST_SWVP_SPE_OFFSET 3564 /* No app will read that far */
118 #define NINE_MAX_CONST_VS_SPE 9
119 #define NINE_MAX_CONST_ALL_VS (NINE_MAX_CONST_VS_SPE_OFFSET + NINE_MAX_CONST_VS_SPE)
120 #define NINE_MAX_CONST_PS_SPE_OFFSET (NINE_MAX_CONST_F_PS3 + (NINE_MAX_CONST_I + NINE_MAX_CONST_B / 4))
121 /* bumpmap_vars (12), fog (2), D3DRS_ALPHAREF (1) */
122 #define NINE_MAX_CONST_PS_SPE 15
123 #define NINE_MAX_CONST_ALL_PS (NINE_MAX_CONST_PS_SPE_OFFSET + NINE_MAX_CONST_PS_SPE)
124 
125 #define NINE_CONST_I_BASE(nconstf) \
126     ((nconstf)        * 4 * sizeof(float))
127 #define NINE_CONST_B_BASE(nconstf) \
128     ((nconstf)        * 4 * sizeof(float) + \
129      NINE_MAX_CONST_I * 4 * sizeof(int))
130 
131 #define VS_CONST_F_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_F_SWVP * sizeof(float[4])) : (NINE_MAX_CONST_F * sizeof(float[4])))
132 #define VS_CONST_I_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_I_SWVP * sizeof(int[4])) : (NINE_MAX_CONST_I * sizeof(int[4])))
133 #define VS_CONST_B_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_B_SWVP * sizeof(BOOL)) : (NINE_MAX_CONST_B * sizeof(BOOL)))
134 
135 
136 #define NINE_MAX_TEXTURE_STAGES 8
137 
138 #define NINE_MAX_LIGHTS        65536
139 #define NINE_MAX_LIGHTS_ACTIVE 8
140 
141 #define NINED3DLIGHT_INVALID (D3DLIGHT_DIRECTIONAL + 1)
142 
143 #define NINE_MAX_SAMPLERS_PS 16
144 #define NINE_MAX_SAMPLERS_VS  4
145 #define NINE_MAX_SAMPLERS    21 /* PS + DMAP + VS */
146 #define NINE_SAMPLER_PS(s)  ( 0 + (s))
147 #define NINE_SAMPLER_DMAP    16
148 #define NINE_SAMPLER_VS(s)  (17 + (s))
149 #define NINE_PS_SAMPLERS_MASK 0x00ffff
150 #define NINE_VS_SAMPLERS_MASK 0x1e0000
151 
152 struct nine_ff_state {
153     struct {
154         uint32_t tex_stage[NINE_MAX_TEXTURE_STAGES][(NINED3DTSS_COUNT + 31) / 32]; /* stateblocks only */
155         uint32_t transform[(NINED3DTS_COUNT + 31) / 32];
156     } changed;
157 
158     D3DMATRIX *transform; /* access only via nine_state_access_transform */
159     unsigned num_transforms;
160 
161     /* XXX: Do state blocks just change the set of active lights or do we
162      * have to store which lights have been disabled, too ?
163      */
164     D3DLIGHT9 *light;
165     uint16_t active_light[NINE_MAX_LIGHTS_ACTIVE]; /* 8 */
166     unsigned num_lights;
167     unsigned num_lights_active;
168 
169     D3DMATERIAL9 material;
170 
171     DWORD tex_stage[NINE_MAX_TEXTURE_STAGES][NINED3DTSS_COUNT];
172 };
173 
174 struct nine_state
175 {
176     struct {
177         uint32_t group;
178         uint32_t rs[(NINED3DRS_COUNT + 31) / 32];
179         uint32_t vtxbuf;
180         uint32_t stream_freq;
181         uint32_t texture;
182         uint16_t sampler[NINE_MAX_SAMPLERS];
183         struct nine_range *vs_const_f;
184         struct nine_range *ps_const_f;
185         struct nine_range *vs_const_i;
186         uint16_t ps_const_i; /* NINE_MAX_CONST_I == 16 */
187         struct nine_range *vs_const_b;
188         uint16_t ps_const_b; /* NINE_MAX_CONST_B == 16 */
189         uint8_t ucp;
190     } changed; /* stateblocks only */
191 
192     struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
193     struct NineSurface9 *ds;
194 
195     D3DVIEWPORT9 viewport;
196 
197     struct pipe_scissor_state scissor;
198 
199     /* NOTE: vs, ps will be NULL for FF and are set in device->ff.vs,ps instead
200      *  (XXX: or is it better to reference FF shaders here, too ?)
201      * NOTE: const_f contains extra space for const_i,b to use as user constbuf
202      */
203     struct NineVertexShader9 *vs;
204     float *vs_const_f;
205     int   *vs_const_i;
206     BOOL  *vs_const_b;
207     float *vs_lconstf_temp; /* ProcessVertices */
208 
209     struct NinePixelShader9 *ps;
210     float *ps_const_f;
211     int    ps_const_i[NINE_MAX_CONST_I][4];
212     BOOL   ps_const_b[NINE_MAX_CONST_B];
213 
214     struct NineVertexDeclaration9 *vdecl;
215 
216     struct NineIndexBuffer9   *idxbuf;
217     struct NineVertexBuffer9  *stream[PIPE_MAX_ATTRIBS];
218     uint32_t stream_mask; /* i bit set for *stream[i] not NULL */
219     struct pipe_vertex_buffer  vtxbuf[PIPE_MAX_ATTRIBS]; /* vtxbuf.buffer unused */
220     unsigned last_vtxbuf_count;
221     uint16_t                   vtxstride[PIPE_MAX_ATTRIBS];
222     UINT stream_freq[PIPE_MAX_ATTRIBS];
223 
224     struct pipe_clip_state clip;
225 
226     DWORD rs_advertised[NINED3DRS_COUNT]; /* the ones apps get with GetRenderState */
227 
228     struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */
229 
230     DWORD samp_advertised[NINE_MAX_SAMPLERS][D3DSAMP_COUNT];
231 
232     struct nine_ff_state ff;
233 };
234 
235 struct nine_context {
236     struct {
237         uint32_t group;
238         uint16_t sampler[NINE_MAX_SAMPLERS];
239         uint32_t vtxbuf;
240         BOOL vs_const_f;
241         BOOL vs_const_i;
242         BOOL vs_const_b;
243         BOOL ps_const_f;
244         BOOL ps_const_i;
245         BOOL ps_const_b;
246         BOOL ucp;
247     } changed;
248 
249     uint32_t bumpmap_vars[6 * NINE_MAX_TEXTURE_STAGES];
250 
251     struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
252     struct NineSurface9 *ds;
253 
254     struct {
255         void *vs;
256         unsigned *vs_const_ranges;
257         unsigned vs_const_used_size;
258         void *ps;
259         unsigned *ps_const_ranges;
260         unsigned ps_const_used_size;
261     } cso_shader;
262 
263     struct pipe_context *pipe;
264     struct cso_context *cso;
265 
266     uint8_t rt_mask;
267 
268     D3DVIEWPORT9 viewport;
269 
270     struct pipe_scissor_state scissor;
271 
272     struct NineVertexShader9 *vs;
273     BOOL programmable_vs;
274     float *vs_const_f;
275     float *vs_const_f_swvp;
276     int   *vs_const_i;
277     BOOL  *vs_const_b;
278     float *vs_lconstf_temp;
279 
280     struct NinePixelShader9 *ps;
281     float *ps_const_f;
282     int    ps_const_i[NINE_MAX_CONST_I][4];
283     BOOL   ps_const_b[NINE_MAX_CONST_B];
284     BOOL   zfog;
285 
286     struct NineVertexDeclaration9 *vdecl;
287 
288     struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
289     uint32_t vtxbuf_mask; /* i bit set for context->vtxbuf[i].buffer.resource not NULL */
290     uint32_t last_vtxbuf_count;
291     uint16_t vtxstride[PIPE_MAX_ATTRIBS];
292     UINT stream_freq[PIPE_MAX_ATTRIBS];
293     uint32_t stream_instancedata_mask; /* derived from stream_freq */
294     uint32_t stream_usage_mask; /* derived from VS and vdecl */
295 
296     struct pipe_resource *idxbuf;
297     unsigned index_offset;
298     unsigned index_size;
299 
300     struct pipe_clip_state clip;
301 
302     DWORD rs[NINED3DRS_COUNT];
303 
304     struct {
305         BOOL enabled;
306         BOOL shadow;
307         DWORD lod;
308         D3DRESOURCETYPE type;
309         struct pipe_resource *resource;
310         struct pipe_sampler_view *view[2];
311         uint8_t pstype;
312     } texture[NINE_MAX_SAMPLERS];
313 
314     DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
315 
316     uint32_t samplers_shadow;
317     uint32_t samplers_fetch4;
318 
319     uint8_t bound_samplers_mask_vs;
320     uint8_t enabled_samplers_mask_vs;
321     uint8_t enabled_sampler_count_vs;
322     uint8_t enabled_sampler_count_ps;
323     uint16_t bound_samplers_mask_ps;
324     uint16_t enabled_samplers_mask_ps;
325 
326     int dummy_vbo_bound_at; /* -1 = not bound , >= 0 = bound index */
327 
328     bool inline_constants;
329 
330     struct nine_ff_state ff;
331 
332     /* software vertex processing */
333     bool swvp;
334 
335     uint32_t commit;
336     struct {
337         struct pipe_framebuffer_state fb;
338         struct pipe_depth_stencil_alpha_state dsa;
339         struct pipe_rasterizer_state rast;
340         struct pipe_blend_state blend;
341         struct pipe_constant_buffer cb_vs;
342         struct pipe_constant_buffer cb0_swvp;
343         struct pipe_constant_buffer cb1_swvp;
344         struct pipe_constant_buffer cb2_swvp;
345         struct pipe_constant_buffer cb3_swvp;
346         struct pipe_constant_buffer cb_ps;
347         struct pipe_constant_buffer cb_vs_ff;
348         struct pipe_constant_buffer cb_ps_ff;
349     } pipe_data;
350 };
351 
352 struct nine_state_sw_internal {
353     struct pipe_transfer *transfers_so[4];
354 };
355 
356 struct nine_clipplane {
357     float plane[4];
358 };
359 /* map D3DRS -> NINE_STATE_x
360  */
361 extern const uint32_t nine_render_state_group[NINED3DRS_COUNT];
362 
363 /* for D3DSBT_PIXEL/VERTEX:
364  */
365 extern const uint32_t nine_render_states_pixel[(NINED3DRS_COUNT + 31) / 32];
366 extern const uint32_t nine_render_states_vertex[(NINED3DRS_COUNT + 31) / 32];
367 
368 struct NineDevice9;
369 
370 /* Internal multithreading: When enabled, the nine_context functions
371  * will append work to a worker thread when possible. Only the worker
372  * thread can access struct nine_context. */
373 
374 void
375 nine_context_set_stream_source_apply(struct NineDevice9 *device,
376                                     UINT StreamNumber,
377                                     struct pipe_resource *res,
378                                     UINT OffsetInBytes,
379                                     UINT Stride);
380 
381 void
382 nine_context_set_indices_apply(struct NineDevice9 *device,
383                                struct pipe_resource *res,
384                                UINT IndexSize,
385                                UINT OffsetInBytes);
386 
387 void
388 nine_context_set_render_state(struct NineDevice9 *device,
389                               D3DRENDERSTATETYPE State,
390                               DWORD Value);
391 
392 void
393 nine_context_set_texture(struct NineDevice9 *device,
394                          DWORD Stage,
395                          struct NineBaseTexture9 *tex);
396 
397 void
398 nine_context_set_sampler_state(struct NineDevice9 *device,
399                                DWORD Sampler,
400                                D3DSAMPLERSTATETYPE Type,
401                                DWORD Value);
402 
403 void
404 nine_context_set_stream_source(struct NineDevice9 *device,
405                                UINT StreamNumber,
406                                struct NineVertexBuffer9 *pVBuf9,
407                                UINT OffsetInBytes,
408                                UINT Stride);
409 
410 void
411 nine_context_set_stream_source_freq(struct NineDevice9 *device,
412                                     UINT StreamNumber,
413                                     UINT Setting);
414 
415 void
416 nine_context_set_indices(struct NineDevice9 *device,
417                          struct NineIndexBuffer9 *idxbuf);
418 
419 void
420 nine_context_set_vertex_declaration(struct NineDevice9 *device,
421                                     struct NineVertexDeclaration9 *vdecl);
422 
423 void
424 nine_context_set_vertex_shader(struct NineDevice9 *device,
425                                struct NineVertexShader9 *pShader);
426 
427 void
428 nine_context_set_vertex_shader_constant_f(struct NineDevice9 *device,
429                                           UINT StartRegister,
430                                           const float *pConstantData,
431                                           const unsigned pConstantData_size,
432                                           UINT Vector4fCount);
433 
434 void
435 nine_context_set_vertex_shader_constant_i(struct NineDevice9 *device,
436                                           UINT StartRegister,
437                                           const int *pConstantData,
438                                           const unsigned pConstantData_size,
439                                           UINT Vector4iCount);
440 
441 void
442 nine_context_set_vertex_shader_constant_b(struct NineDevice9 *device,
443                                           UINT StartRegister,
444                                           const BOOL *pConstantData,
445                                           const unsigned pConstantData_size,
446                                           UINT BoolCount);
447 
448 void
449 nine_context_set_pixel_shader(struct NineDevice9 *device,
450                               struct NinePixelShader9* ps);
451 
452 void
453 nine_context_set_pixel_shader_constant_f(struct NineDevice9 *device,
454                                         UINT StartRegister,
455                                         const float *pConstantData,
456                                         const unsigned pConstantData_size,
457                                         UINT Vector4fCount);
458 
459 void
460 nine_context_set_pixel_shader_constant_i(struct NineDevice9 *device,
461                                          UINT StartRegister,
462                                          const int *pConstantData,
463                                          const unsigned pConstantData_size,
464                                          UINT Vector4iCount);
465 
466 void
467 nine_context_set_pixel_shader_constant_b(struct NineDevice9 *device,
468                                          UINT StartRegister,
469                                          const BOOL *pConstantData,
470                                          const unsigned pConstantData_size,
471                                          UINT BoolCount);
472 
473 void
474 nine_context_set_viewport(struct NineDevice9 *device,
475                           const D3DVIEWPORT9 *viewport);
476 
477 void
478 nine_context_set_scissor(struct NineDevice9 *device,
479                          const struct pipe_scissor_state *scissor);
480 
481 void
482 nine_context_set_transform(struct NineDevice9 *device,
483                            D3DTRANSFORMSTATETYPE State,
484                            const D3DMATRIX *pMatrix);
485 
486 void
487 nine_context_set_material(struct NineDevice9 *device,
488                           const D3DMATERIAL9 *pMaterial);
489 
490 void
491 nine_context_set_light(struct NineDevice9 *device,
492                        DWORD Index,
493                        const D3DLIGHT9 *pLight);
494 
495 void
496 nine_context_light_enable(struct NineDevice9 *device,
497                           DWORD Index,
498                           BOOL Enable);
499 
500 void
501 nine_context_set_texture_stage_state(struct NineDevice9 *device,
502                                      DWORD Stage,
503                                      D3DTEXTURESTAGESTATETYPE Type,
504                                      DWORD Value);
505 
506 void
507 nine_context_set_render_target(struct NineDevice9 *device,
508                                DWORD RenderTargetIndex,
509                                struct NineSurface9 *rt);
510 
511 void
512 nine_context_set_depth_stencil(struct NineDevice9 *device,
513                                struct NineSurface9 *ds);
514 
515 void
516 nine_context_set_clip_plane(struct NineDevice9 *device,
517                             DWORD Index,
518                             const struct nine_clipplane *pPlane);
519 
520 void
521 nine_context_set_swvp(struct NineDevice9 *device,
522                       bool swvp);
523 
524 void
525 nine_context_apply_stateblock(struct NineDevice9 *device,
526                               const struct nine_state *src);
527 
528 void
529 nine_context_clear_fb(struct NineDevice9 *device, DWORD Count,
530                       const D3DRECT *pRects, DWORD Flags,
531                       D3DCOLOR Color, float Z, DWORD Stencil);
532 
533 void
534 nine_context_draw_primitive(struct NineDevice9 *device,
535                             D3DPRIMITIVETYPE PrimitiveType,
536                             UINT StartVertex,
537                             UINT PrimitiveCount);
538 
539 void
540 nine_context_draw_indexed_primitive(struct NineDevice9 *device,
541                                     D3DPRIMITIVETYPE PrimitiveType,
542                                     INT BaseVertexIndex,
543                                     UINT MinVertexIndex,
544                                     UINT NumVertices,
545                                     UINT StartIndex,
546                                     UINT PrimitiveCount);
547 
548 void
549 nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(struct NineDevice9 *device,
550                                                        D3DPRIMITIVETYPE PrimitiveType,
551                                                        UINT MinVertexIndex,
552                                                        UINT NumVertices,
553                                                        UINT PrimitiveCount,
554                                                        unsigned vbuf_stride,
555                                                        struct pipe_vertex_buffer *vbuf,
556                                                        struct pipe_resource *ibuf,
557                                                        void *user_ibuf,
558                                                        unsigned index_offset,
559                                                        unsigned index_size);
560 
561 void
562 nine_context_resource_copy_region(struct NineDevice9 *device,
563                                   struct NineUnknown *dst,
564                                   struct NineUnknown *src,
565                                   struct pipe_resource* dst_res,
566                                   unsigned dst_level,
567                                   const struct pipe_box *dst_box,
568                                   struct pipe_resource* src_res,
569                                   unsigned src_level,
570                                   const struct pipe_box *src_box);
571 
572 void
573 nine_context_blit(struct NineDevice9 *device,
574                   struct NineUnknown *dst,
575                   struct NineUnknown *src,
576                   struct pipe_blit_info *blit);
577 
578 void
579 nine_context_clear_render_target(struct NineDevice9 *device,
580                                  struct NineSurface9 *surface,
581                                  D3DCOLOR color,
582                                  UINT x,
583                                  UINT y,
584                                  UINT width,
585                                  UINT height);
586 
587 void
588 nine_context_gen_mipmap(struct NineDevice9 *device,
589                         struct NineUnknown *dst,
590                         struct pipe_resource *res,
591                         UINT base_level, UINT last_level,
592                         UINT first_layer, UINT last_layer,
593                         UINT filter);
594 
595 void
596 nine_context_range_upload(struct NineDevice9 *device,
597                           unsigned *counter,
598                           struct NineUnknown *src_ref,
599                           struct pipe_resource *res,
600                           unsigned offset,
601                           unsigned size,
602                           unsigned usage,
603                           const void *data);
604 
605 void
606 nine_context_box_upload(struct NineDevice9 *device,
607                         unsigned *counter,
608                         struct NineUnknown *src_ref,
609                         struct pipe_resource *res,
610                         unsigned level,
611                         const struct pipe_box *dst_box,
612                         enum pipe_format src_format,
613                         const void *src, unsigned src_stride,
614                         unsigned src_layer_stride,
615                         const struct pipe_box *src_box);
616 
617 struct pipe_query *
618 nine_context_create_query(struct NineDevice9 *device, unsigned query_type);
619 
620 void
621 nine_context_destroy_query(struct NineDevice9 *device, struct pipe_query *query);
622 
623 void
624 nine_context_begin_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);
625 
626 void
627 nine_context_end_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);
628 
629 bool
630 nine_context_get_query_result(struct NineDevice9 *device, struct pipe_query *query,
631                               unsigned *counter, bool flush, bool wait,
632                               union pipe_query_result *result);
633 
634 void
635 nine_context_pipe_flush(struct NineDevice9 *device);
636 
637 void nine_state_restore_non_cso(struct NineDevice9 *device);
638 void nine_state_set_defaults(struct NineDevice9 *, const D3DCAPS9 *,
639                              bool is_reset);
640 void nine_device_state_clear(struct NineDevice9 *);
641 void nine_context_clear(struct NineDevice9 *);
642 void nine_context_update_state(struct NineDevice9 *);
643 
644 void nine_state_init_sw(struct NineDevice9 *device);
645 void nine_state_prepare_draw_sw(struct NineDevice9 *device,
646                                 struct NineVertexDeclaration9 *vdecl_out,
647                                 int start_vertice,
648                                 int num_vertices,
649                                 struct pipe_stream_output_info *so);
650 void nine_state_after_draw_sw(struct NineDevice9 *device);
651 void nine_state_destroy_sw(struct NineDevice9 *device);
652 
653 void
654 nine_state_resize_transform(struct nine_ff_state *ff_state, unsigned N);
655 
656 /* If @alloc is FALSE, the return value may be a const identity matrix.
657  * Therefore, do not modify if you set alloc to FALSE !
658  */
659 D3DMATRIX *
660 nine_state_access_transform(struct nine_ff_state *, D3DTRANSFORMSTATETYPE,
661                             bool alloc);
662 
663 HRESULT
664 nine_state_set_light(struct nine_ff_state *, DWORD, const D3DLIGHT9 *);
665 
666 HRESULT
667 nine_state_light_enable(struct nine_ff_state *,
668                         DWORD, BOOL);
669 
670 const char *nine_d3drs_to_string(DWORD State);
671 
672 /* CSMT functions */
673 struct csmt_context;
674 
675 struct csmt_context *
676 nine_csmt_create( struct NineDevice9 *This );
677 
678 void
679 nine_csmt_destroy( struct NineDevice9 *This, struct csmt_context *ctx );
680 
681 /* Flushes and waits everything is executed */
682 void
683 nine_csmt_process( struct NineDevice9 *This );
684 
685 /* Flushes and doesn't wait */
686 void
687 nine_csmt_flush( struct NineDevice9 *This );
688 
689 /* Get the pipe_context (should not be called from the worker thread).
690  * All the work in the worker thread is finished before returning. */
691 struct pipe_context *
692 nine_context_get_pipe( struct NineDevice9 *device );
693 
694 /* Can be called from all threads */
695 struct pipe_context *
696 nine_context_get_pipe_multithread( struct NineDevice9 *device );
697 
698 
699 /* Get the pipe_context (should not be called from the worker thread).
700  * All the work in the worker thread is paused before returning.
701  * It is neccessary to release in order to restart the thread.
702  * This is intended for use of the nine_context pipe_context that don't
703  * need the worker thread to finish all queued job. */
704 struct pipe_context *
705 nine_context_get_pipe_acquire( struct NineDevice9 *device );
706 
707 void
708 nine_context_get_pipe_release( struct NineDevice9 *device );
709 
710 bool
711 nine_context_is_worker( struct NineDevice9 *device );
712 
713 #endif /* _NINE_STATE_H_ */
714