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