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