17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */
227ec681f3Smrg
237ec681f3Smrg#ifndef _NINE_STATE_H_
247ec681f3Smrg#define _NINE_STATE_H_
257ec681f3Smrg
267ec681f3Smrg#include "d3d9.h"
277ec681f3Smrg#include "iunknown.h"
287ec681f3Smrg#include "nine_defines.h"
297ec681f3Smrg#include "pipe/p_state.h"
307ec681f3Smrg#include "util/list.h"
317ec681f3Smrg
327ec681f3Smrg#define NINED3DSAMP_MINLOD (D3DSAMP_DMAPOFFSET + 1)
337ec681f3Smrg#define NINED3DSAMP_SHADOW (D3DSAMP_DMAPOFFSET + 2)
347ec681f3Smrg#define NINED3DSAMP_CUBETEX (D3DSAMP_DMAPOFFSET + 3)
357ec681f3Smrg
367ec681f3Smrg#define NINED3DRS_VSPOINTSIZE (D3DRS_BLENDOPALPHA + 1)
377ec681f3Smrg#define NINED3DRS_RTMASK      (D3DRS_BLENDOPALPHA + 2)
387ec681f3Smrg/* ALPHACOVERAGE:
397ec681f3Smrg * bit 0: enable alpha coverage
407ec681f3Smrg * bit 1: ATOC is on
417ec681f3Smrg */
427ec681f3Smrg#define NINED3DRS_ALPHACOVERAGE  (D3DRS_BLENDOPALPHA + 3)
437ec681f3Smrg#define NINED3DRS_MULTISAMPLE  (D3DRS_BLENDOPALPHA + 4)
447ec681f3Smrg#define NINED3DRS_FETCH4  (D3DRS_BLENDOPALPHA + 5)
457ec681f3Smrg
467ec681f3Smrg#define D3DRS_LAST       D3DRS_BLENDOPALPHA
477ec681f3Smrg#define D3DSAMP_LAST     D3DSAMP_DMAPOFFSET
487ec681f3Smrg#define NINED3DRS_LAST   NINED3DRS_FETCH4 /* 215 */
497ec681f3Smrg#define NINED3DSAMP_LAST NINED3DSAMP_CUBETEX /* 16 */
507ec681f3Smrg#define NINED3DTSS_LAST  D3DTSS_CONSTANT
517ec681f3Smrg#define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)
527ec681f3Smrg
537ec681f3Smrg#define D3DRS_COUNT       (D3DRS_LAST + 1)
547ec681f3Smrg#define D3DSAMP_COUNT     (D3DSAMP_LAST + 1)
557ec681f3Smrg#define NINED3DRS_COUNT   (NINED3DRS_LAST + 1)
567ec681f3Smrg#define NINED3DSAMP_COUNT (NINED3DSAMP_LAST + 1)
577ec681f3Smrg#define NINED3DTSS_COUNT  (NINED3DTSS_LAST + 1)
587ec681f3Smrg#define NINED3DTS_COUNT   (NINED3DTS_LAST + 1)
597ec681f3Smrg
607ec681f3Smrg#define NINE_STATE_FB          (1 <<  0)
617ec681f3Smrg#define NINE_STATE_VIEWPORT    (1 <<  1)
627ec681f3Smrg#define NINE_STATE_SCISSOR     (1 <<  2)
637ec681f3Smrg#define NINE_STATE_RASTERIZER  (1 <<  3)
647ec681f3Smrg#define NINE_STATE_BLEND       (1 <<  4)
657ec681f3Smrg#define NINE_STATE_DSA         (1 <<  5)
667ec681f3Smrg#define NINE_STATE_VS          (1 <<  6)
677ec681f3Smrg#define NINE_STATE_VS_CONST    (1 <<  7)
687ec681f3Smrg#define NINE_STATE_PS          (1 <<  8)
697ec681f3Smrg#define NINE_STATE_PS_CONST    (1 <<  9)
707ec681f3Smrg#define NINE_STATE_TEXTURE     (1 << 10)
717ec681f3Smrg#define NINE_STATE_SAMPLER     (1 << 11)
727ec681f3Smrg#define NINE_STATE_VDECL       (1 << 12)
737ec681f3Smrg#define NINE_STATE_IDXBUF      (1 << 13)
747ec681f3Smrg#define NINE_STATE_STREAMFREQ  (1 << 14)
757ec681f3Smrg#define NINE_STATE_BLEND_COLOR (1 << 17)
767ec681f3Smrg#define NINE_STATE_STENCIL_REF (1 << 18)
777ec681f3Smrg#define NINE_STATE_SAMPLE_MASK (1 << 19)
787ec681f3Smrg#define NINE_STATE_FF          (0x1f << 20)
797ec681f3Smrg#define NINE_STATE_FF_VS       (0x17 << 20)
807ec681f3Smrg#define NINE_STATE_FF_PS       (0x08 << 20)
817ec681f3Smrg#define NINE_STATE_FF_LIGHTING (1 << 20)
827ec681f3Smrg#define NINE_STATE_FF_MATERIAL (1 << 21)
837ec681f3Smrg#define NINE_STATE_FF_VSTRANSF (1 << 22)
847ec681f3Smrg#define NINE_STATE_FF_PS_CONSTS (1 << 23)
857ec681f3Smrg#define NINE_STATE_FF_VS_OTHER  (1 << 24)
867ec681f3Smrg#define NINE_STATE_VS_PARAMS_MISC  (1 << 25)
877ec681f3Smrg#define NINE_STATE_PS_PARAMS_MISC (1 << 26)
887ec681f3Smrg#define NINE_STATE_MULTISAMPLE (1 << 27)
897ec681f3Smrg#define NINE_STATE_SWVP        (1 << 28)
907ec681f3Smrg#define NINE_STATE_ALL          0x1fffffff
917ec681f3Smrg#define NINE_STATE_UNHANDLED   (1 << 29)
927ec681f3Smrg
937ec681f3Smrg/* These states affect the ff shader key,
947ec681f3Smrg * which we recompute everytime. */
957ec681f3Smrg#define NINE_STATE_FF_SHADER    0
967ec681f3Smrg
977ec681f3Smrg#define NINE_STATE_COMMIT_DSA  (1 << 0)
987ec681f3Smrg#define NINE_STATE_COMMIT_RASTERIZER (1 << 1)
997ec681f3Smrg#define NINE_STATE_COMMIT_BLEND (1 << 2)
1007ec681f3Smrg#define NINE_STATE_COMMIT_CONST_VS (1 << 3)
1017ec681f3Smrg#define NINE_STATE_COMMIT_CONST_PS (1 << 4)
1027ec681f3Smrg#define NINE_STATE_COMMIT_VS (1 << 5)
1037ec681f3Smrg#define NINE_STATE_COMMIT_PS (1 << 6)
1047ec681f3Smrg
1057ec681f3Smrg
1067ec681f3Smrg#define NINE_MAX_SIMULTANEOUS_RENDERTARGETS 4
1077ec681f3Smrg#define NINE_MAX_CONST_F_PS3 224
1087ec681f3Smrg#define NINE_MAX_CONST_F   256
1097ec681f3Smrg#define NINE_MAX_CONST_I   16
1107ec681f3Smrg#define NINE_MAX_CONST_B   16
1117ec681f3Smrg#define NINE_MAX_CONST_F_SWVP   8192
1127ec681f3Smrg#define NINE_MAX_CONST_I_SWVP   2048
1137ec681f3Smrg#define NINE_MAX_CONST_B_SWVP   2048
1147ec681f3Smrg#define NINE_MAX_CONST_ALL 276 /* B consts count only 1/4 th */
1157ec681f3Smrg
1167ec681f3Smrg#define NINE_CONST_I_BASE(nconstf) \
1177ec681f3Smrg    ((nconstf)        * 4 * sizeof(float))
1187ec681f3Smrg#define NINE_CONST_B_BASE(nconstf) \
1197ec681f3Smrg    ((nconstf)        * 4 * sizeof(float) + \
1207ec681f3Smrg     NINE_MAX_CONST_I * 4 * sizeof(int))
1217ec681f3Smrg
1227ec681f3Smrg#define VS_CONST_F_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_F_SWVP * sizeof(float[4])) : (NINE_MAX_CONST_F * sizeof(float[4])))
1237ec681f3Smrg#define VS_CONST_I_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_I_SWVP * sizeof(int[4])) : (NINE_MAX_CONST_I * sizeof(int[4])))
1247ec681f3Smrg#define VS_CONST_B_SIZE(device) (device->may_swvp ? (NINE_MAX_CONST_B_SWVP * sizeof(BOOL)) : (NINE_MAX_CONST_B * sizeof(BOOL)))
1257ec681f3Smrg
1267ec681f3Smrg
1277ec681f3Smrg#define NINE_MAX_TEXTURE_STAGES 8
1287ec681f3Smrg
1297ec681f3Smrg#define NINE_MAX_LIGHTS        65536
1307ec681f3Smrg#define NINE_MAX_LIGHTS_ACTIVE 8
1317ec681f3Smrg
1327ec681f3Smrg#define NINED3DLIGHT_INVALID (D3DLIGHT_DIRECTIONAL + 1)
1337ec681f3Smrg
1347ec681f3Smrg#define NINE_MAX_SAMPLERS_PS 16
1357ec681f3Smrg#define NINE_MAX_SAMPLERS_VS  4
1367ec681f3Smrg#define NINE_MAX_SAMPLERS    21 /* PS + DMAP + VS */
1377ec681f3Smrg#define NINE_SAMPLER_PS(s)  ( 0 + (s))
1387ec681f3Smrg#define NINE_SAMPLER_DMAP    16
1397ec681f3Smrg#define NINE_SAMPLER_VS(s)  (17 + (s))
1407ec681f3Smrg#define NINE_PS_SAMPLERS_MASK 0x00ffff
1417ec681f3Smrg#define NINE_VS_SAMPLERS_MASK 0x1e0000
1427ec681f3Smrg
1437ec681f3Smrgstruct nine_ff_state {
1447ec681f3Smrg    struct {
1457ec681f3Smrg        uint32_t tex_stage[NINE_MAX_TEXTURE_STAGES][(NINED3DTSS_COUNT + 31) / 32]; /* stateblocks only */
1467ec681f3Smrg        uint32_t transform[(NINED3DTS_COUNT + 31) / 32];
1477ec681f3Smrg    } changed;
1487ec681f3Smrg
1497ec681f3Smrg    D3DMATRIX *transform; /* access only via nine_state_access_transform */
1507ec681f3Smrg    unsigned num_transforms;
1517ec681f3Smrg
1527ec681f3Smrg    /* XXX: Do state blocks just change the set of active lights or do we
1537ec681f3Smrg     * have to store which lights have been disabled, too ?
1547ec681f3Smrg     */
1557ec681f3Smrg    D3DLIGHT9 *light;
1567ec681f3Smrg    uint16_t active_light[NINE_MAX_LIGHTS_ACTIVE]; /* 8 */
1577ec681f3Smrg    unsigned num_lights;
1587ec681f3Smrg    unsigned num_lights_active;
1597ec681f3Smrg
1607ec681f3Smrg    D3DMATERIAL9 material;
1617ec681f3Smrg
1627ec681f3Smrg    DWORD tex_stage[NINE_MAX_TEXTURE_STAGES][NINED3DTSS_COUNT];
1637ec681f3Smrg};
1647ec681f3Smrg
1657ec681f3Smrgstruct nine_state
1667ec681f3Smrg{
1677ec681f3Smrg    struct {
1687ec681f3Smrg        uint32_t group;
1697ec681f3Smrg        uint32_t rs[(NINED3DRS_COUNT + 31) / 32];
1707ec681f3Smrg        uint32_t vtxbuf;
1717ec681f3Smrg        uint32_t stream_freq;
1727ec681f3Smrg        uint32_t texture;
1737ec681f3Smrg        uint16_t sampler[NINE_MAX_SAMPLERS];
1747ec681f3Smrg        struct nine_range *vs_const_f;
1757ec681f3Smrg        struct nine_range *ps_const_f;
1767ec681f3Smrg        struct nine_range *vs_const_i;
1777ec681f3Smrg        uint16_t ps_const_i; /* NINE_MAX_CONST_I == 16 */
1787ec681f3Smrg        struct nine_range *vs_const_b;
1797ec681f3Smrg        uint16_t ps_const_b; /* NINE_MAX_CONST_B == 16 */
1807ec681f3Smrg        uint8_t ucp;
1817ec681f3Smrg    } changed; /* stateblocks only */
1827ec681f3Smrg
1837ec681f3Smrg    struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
1847ec681f3Smrg    struct NineSurface9 *ds;
1857ec681f3Smrg
1867ec681f3Smrg    D3DVIEWPORT9 viewport;
1877ec681f3Smrg
1887ec681f3Smrg    struct pipe_scissor_state scissor;
1897ec681f3Smrg
1907ec681f3Smrg    /* NOTE: vs, ps will be NULL for FF and are set in device->ff.vs,ps instead
1917ec681f3Smrg     *  (XXX: or is it better to reference FF shaders here, too ?)
1927ec681f3Smrg     * NOTE: const_f contains extra space for const_i,b to use as user constbuf
1937ec681f3Smrg     */
1947ec681f3Smrg    struct NineVertexShader9 *vs;
1957ec681f3Smrg    float *vs_const_f;
1967ec681f3Smrg    int   *vs_const_i;
1977ec681f3Smrg    BOOL  *vs_const_b;
1987ec681f3Smrg    float *vs_lconstf_temp; /* ProcessVertices */
1997ec681f3Smrg
2007ec681f3Smrg    struct NinePixelShader9 *ps;
2017ec681f3Smrg    float *ps_const_f;
2027ec681f3Smrg    int    ps_const_i[NINE_MAX_CONST_I][4];
2037ec681f3Smrg    BOOL   ps_const_b[NINE_MAX_CONST_B];
2047ec681f3Smrg
2057ec681f3Smrg    struct NineVertexDeclaration9 *vdecl;
2067ec681f3Smrg
2077ec681f3Smrg    struct NineIndexBuffer9   *idxbuf;
2087ec681f3Smrg    struct NineVertexBuffer9  *stream[PIPE_MAX_ATTRIBS];
2097ec681f3Smrg    struct pipe_vertex_buffer  vtxbuf[PIPE_MAX_ATTRIBS]; /* vtxbuf.buffer unused */
2107ec681f3Smrg    UINT stream_freq[PIPE_MAX_ATTRIBS];
2117ec681f3Smrg
2127ec681f3Smrg    struct pipe_clip_state clip;
2137ec681f3Smrg
2147ec681f3Smrg    DWORD rs_advertised[NINED3DRS_COUNT]; /* the ones apps get with GetRenderState */
2157ec681f3Smrg
2167ec681f3Smrg    struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */
2177ec681f3Smrg
2187ec681f3Smrg    DWORD samp_advertised[NINE_MAX_SAMPLERS][D3DSAMP_COUNT];
2197ec681f3Smrg
2207ec681f3Smrg    struct nine_ff_state ff;
2217ec681f3Smrg};
2227ec681f3Smrg
2237ec681f3Smrgstruct nine_context {
2247ec681f3Smrg    struct {
2257ec681f3Smrg        uint32_t group;
2267ec681f3Smrg        uint16_t sampler[NINE_MAX_SAMPLERS];
2277ec681f3Smrg        uint32_t vtxbuf;
2287ec681f3Smrg        BOOL vs_const_f;
2297ec681f3Smrg        BOOL vs_const_i;
2307ec681f3Smrg        BOOL vs_const_b;
2317ec681f3Smrg        BOOL ps_const_f;
2327ec681f3Smrg        BOOL ps_const_i;
2337ec681f3Smrg        BOOL ps_const_b;
2347ec681f3Smrg        BOOL ucp;
2357ec681f3Smrg    } changed;
2367ec681f3Smrg
2377ec681f3Smrg    uint32_t bumpmap_vars[6 * NINE_MAX_TEXTURE_STAGES];
2387ec681f3Smrg
2397ec681f3Smrg    struct NineSurface9 *rt[NINE_MAX_SIMULTANEOUS_RENDERTARGETS];
2407ec681f3Smrg    struct NineSurface9 *ds;
2417ec681f3Smrg
2427ec681f3Smrg    struct {
2437ec681f3Smrg        void *vs;
2447ec681f3Smrg        unsigned *vs_const_ranges;
2457ec681f3Smrg        unsigned vs_const_used_size;
2467ec681f3Smrg        void *ps;
2477ec681f3Smrg        unsigned *ps_const_ranges;
2487ec681f3Smrg        unsigned ps_const_used_size;
2497ec681f3Smrg    } cso_shader;
2507ec681f3Smrg
2517ec681f3Smrg    struct pipe_context *pipe;
2527ec681f3Smrg    struct cso_context *cso;
2537ec681f3Smrg
2547ec681f3Smrg    uint8_t rt_mask;
2557ec681f3Smrg
2567ec681f3Smrg    D3DVIEWPORT9 viewport;
2577ec681f3Smrg
2587ec681f3Smrg    struct pipe_scissor_state scissor;
2597ec681f3Smrg
2607ec681f3Smrg    struct NineVertexShader9 *vs;
2617ec681f3Smrg    BOOL programmable_vs;
2627ec681f3Smrg    float *vs_const_f;
2637ec681f3Smrg    float *vs_const_f_swvp;
2647ec681f3Smrg    int   *vs_const_i;
2657ec681f3Smrg    BOOL  *vs_const_b;
2667ec681f3Smrg    float *vs_lconstf_temp;
2677ec681f3Smrg
2687ec681f3Smrg    struct NinePixelShader9 *ps;
2697ec681f3Smrg    float *ps_const_f;
2707ec681f3Smrg    int    ps_const_i[NINE_MAX_CONST_I][4];
2717ec681f3Smrg    BOOL   ps_const_b[NINE_MAX_CONST_B];
2727ec681f3Smrg    float *ps_lconstf_temp;
2737ec681f3Smrg
2747ec681f3Smrg    struct NineVertexDeclaration9 *vdecl;
2757ec681f3Smrg
2767ec681f3Smrg    struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
2777ec681f3Smrg    UINT stream_freq[PIPE_MAX_ATTRIBS];
2787ec681f3Smrg    uint32_t stream_instancedata_mask; /* derived from stream_freq */
2797ec681f3Smrg    uint32_t stream_usage_mask; /* derived from VS and vdecl */
2807ec681f3Smrg
2817ec681f3Smrg    struct pipe_resource *idxbuf;
2827ec681f3Smrg    unsigned index_offset;
2837ec681f3Smrg    unsigned index_size;
2847ec681f3Smrg
2857ec681f3Smrg    struct pipe_clip_state clip;
2867ec681f3Smrg
2877ec681f3Smrg    DWORD rs[NINED3DRS_COUNT];
2887ec681f3Smrg
2897ec681f3Smrg    struct {
2907ec681f3Smrg        BOOL enabled;
2917ec681f3Smrg        BOOL shadow;
2927ec681f3Smrg        DWORD lod;
2937ec681f3Smrg        D3DRESOURCETYPE type;
2947ec681f3Smrg        struct pipe_resource *resource;
2957ec681f3Smrg        struct pipe_sampler_view *view[2];
2967ec681f3Smrg        uint8_t pstype;
2977ec681f3Smrg    } texture[NINE_MAX_SAMPLERS];
2987ec681f3Smrg
2997ec681f3Smrg    DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT];
3007ec681f3Smrg
3017ec681f3Smrg    uint32_t samplers_shadow;
3027ec681f3Smrg    uint32_t samplers_fetch4;
3037ec681f3Smrg
3047ec681f3Smrg    uint8_t bound_samplers_mask_vs;
3057ec681f3Smrg    uint8_t enabled_samplers_mask_vs;
3067ec681f3Smrg    uint8_t enabled_sampler_count_vs;
3077ec681f3Smrg    uint8_t enabled_sampler_count_ps;
3087ec681f3Smrg    uint16_t bound_samplers_mask_ps;
3097ec681f3Smrg    uint16_t enabled_samplers_mask_ps;
3107ec681f3Smrg
3117ec681f3Smrg    int dummy_vbo_bound_at; /* -1 = not bound , >= 0 = bound index */
3127ec681f3Smrg    boolean vbo_bound_done;
3137ec681f3Smrg
3147ec681f3Smrg    boolean inline_constants;
3157ec681f3Smrg
3167ec681f3Smrg    struct nine_ff_state ff;
3177ec681f3Smrg
3187ec681f3Smrg    /* software vertex processing */
3197ec681f3Smrg    boolean swvp;
3207ec681f3Smrg
3217ec681f3Smrg    uint32_t commit;
3227ec681f3Smrg    struct {
3237ec681f3Smrg        struct pipe_framebuffer_state fb;
3247ec681f3Smrg        struct pipe_depth_stencil_alpha_state dsa;
3257ec681f3Smrg        struct pipe_rasterizer_state rast;
3267ec681f3Smrg        struct pipe_blend_state blend;
3277ec681f3Smrg        struct pipe_constant_buffer cb_vs;
3287ec681f3Smrg        struct pipe_constant_buffer cb0_swvp;
3297ec681f3Smrg        struct pipe_constant_buffer cb1_swvp;
3307ec681f3Smrg        struct pipe_constant_buffer cb2_swvp;
3317ec681f3Smrg        struct pipe_constant_buffer cb3_swvp;
3327ec681f3Smrg        struct pipe_constant_buffer cb_ps;
3337ec681f3Smrg        struct pipe_constant_buffer cb_vs_ff;
3347ec681f3Smrg        struct pipe_constant_buffer cb_ps_ff;
3357ec681f3Smrg    } pipe_data;
3367ec681f3Smrg};
3377ec681f3Smrg
3387ec681f3Smrgstruct nine_state_sw_internal {
3397ec681f3Smrg    struct pipe_transfer *transfers_so[4];
3407ec681f3Smrg};
3417ec681f3Smrg
3427ec681f3Smrgstruct nine_clipplane {
3437ec681f3Smrg    float plane[4];
3447ec681f3Smrg};
3457ec681f3Smrg/* map D3DRS -> NINE_STATE_x
3467ec681f3Smrg */
3477ec681f3Smrgextern const uint32_t nine_render_state_group[NINED3DRS_COUNT];
3487ec681f3Smrg
3497ec681f3Smrg/* for D3DSBT_PIXEL/VERTEX:
3507ec681f3Smrg */
3517ec681f3Smrgextern const uint32_t nine_render_states_pixel[(NINED3DRS_COUNT + 31) / 32];
3527ec681f3Smrgextern const uint32_t nine_render_states_vertex[(NINED3DRS_COUNT + 31) / 32];
3537ec681f3Smrg
3547ec681f3Smrgstruct NineDevice9;
3557ec681f3Smrg
3567ec681f3Smrg/* Internal multithreading: When enabled, the nine_context functions
3577ec681f3Smrg * will append work to a worker thread when possible. Only the worker
3587ec681f3Smrg * thread can access struct nine_context. */
3597ec681f3Smrg
3607ec681f3Smrgvoid
3617ec681f3Smrgnine_context_set_stream_source_apply(struct NineDevice9 *device,
3627ec681f3Smrg                                    UINT StreamNumber,
3637ec681f3Smrg                                    struct pipe_resource *res,
3647ec681f3Smrg                                    UINT OffsetInBytes,
3657ec681f3Smrg                                    UINT Stride);
3667ec681f3Smrg
3677ec681f3Smrgvoid
3687ec681f3Smrgnine_context_set_indices_apply(struct NineDevice9 *device,
3697ec681f3Smrg                               struct pipe_resource *res,
3707ec681f3Smrg                               UINT IndexSize,
3717ec681f3Smrg                               UINT OffsetInBytes);
3727ec681f3Smrg
3737ec681f3Smrgvoid
3747ec681f3Smrgnine_context_set_render_state(struct NineDevice9 *device,
3757ec681f3Smrg                              D3DRENDERSTATETYPE State,
3767ec681f3Smrg                              DWORD Value);
3777ec681f3Smrg
3787ec681f3Smrgvoid
3797ec681f3Smrgnine_context_set_texture(struct NineDevice9 *device,
3807ec681f3Smrg                         DWORD Stage,
3817ec681f3Smrg                         struct NineBaseTexture9 *tex);
3827ec681f3Smrg
3837ec681f3Smrgvoid
3847ec681f3Smrgnine_context_set_sampler_state(struct NineDevice9 *device,
3857ec681f3Smrg                               DWORD Sampler,
3867ec681f3Smrg                               D3DSAMPLERSTATETYPE Type,
3877ec681f3Smrg                               DWORD Value);
3887ec681f3Smrg
3897ec681f3Smrgvoid
3907ec681f3Smrgnine_context_set_stream_source(struct NineDevice9 *device,
3917ec681f3Smrg                               UINT StreamNumber,
3927ec681f3Smrg                               struct NineVertexBuffer9 *pVBuf9,
3937ec681f3Smrg                               UINT OffsetInBytes,
3947ec681f3Smrg                               UINT Stride);
3957ec681f3Smrg
3967ec681f3Smrgvoid
3977ec681f3Smrgnine_context_set_stream_source_freq(struct NineDevice9 *device,
3987ec681f3Smrg                                    UINT StreamNumber,
3997ec681f3Smrg                                    UINT Setting);
4007ec681f3Smrg
4017ec681f3Smrgvoid
4027ec681f3Smrgnine_context_set_indices(struct NineDevice9 *device,
4037ec681f3Smrg                         struct NineIndexBuffer9 *idxbuf);
4047ec681f3Smrg
4057ec681f3Smrgvoid
4067ec681f3Smrgnine_context_set_vertex_declaration(struct NineDevice9 *device,
4077ec681f3Smrg                                    struct NineVertexDeclaration9 *vdecl);
4087ec681f3Smrg
4097ec681f3Smrgvoid
4107ec681f3Smrgnine_context_set_vertex_shader(struct NineDevice9 *device,
4117ec681f3Smrg                               struct NineVertexShader9 *pShader);
4127ec681f3Smrg
4137ec681f3Smrgvoid
4147ec681f3Smrgnine_context_set_vertex_shader_constant_f(struct NineDevice9 *device,
4157ec681f3Smrg                                          UINT StartRegister,
4167ec681f3Smrg                                          const float *pConstantData,
4177ec681f3Smrg                                          const unsigned pConstantData_size,
4187ec681f3Smrg                                          UINT Vector4fCount);
4197ec681f3Smrg
4207ec681f3Smrgvoid
4217ec681f3Smrgnine_context_set_vertex_shader_constant_i(struct NineDevice9 *device,
4227ec681f3Smrg                                          UINT StartRegister,
4237ec681f3Smrg                                          const int *pConstantData,
4247ec681f3Smrg                                          const unsigned pConstantData_size,
4257ec681f3Smrg                                          UINT Vector4iCount);
4267ec681f3Smrg
4277ec681f3Smrgvoid
4287ec681f3Smrgnine_context_set_vertex_shader_constant_b(struct NineDevice9 *device,
4297ec681f3Smrg                                          UINT StartRegister,
4307ec681f3Smrg                                          const BOOL *pConstantData,
4317ec681f3Smrg                                          const unsigned pConstantData_size,
4327ec681f3Smrg                                          UINT BoolCount);
4337ec681f3Smrg
4347ec681f3Smrgvoid
4357ec681f3Smrgnine_context_set_pixel_shader(struct NineDevice9 *device,
4367ec681f3Smrg                              struct NinePixelShader9* ps);
4377ec681f3Smrg
4387ec681f3Smrgvoid
4397ec681f3Smrgnine_context_set_pixel_shader_constant_f(struct NineDevice9 *device,
4407ec681f3Smrg                                        UINT StartRegister,
4417ec681f3Smrg                                        const float *pConstantData,
4427ec681f3Smrg                                        const unsigned pConstantData_size,
4437ec681f3Smrg                                        UINT Vector4fCount);
4447ec681f3Smrg
4457ec681f3Smrgvoid
4467ec681f3Smrgnine_context_set_pixel_shader_constant_i(struct NineDevice9 *device,
4477ec681f3Smrg                                         UINT StartRegister,
4487ec681f3Smrg                                         const int *pConstantData,
4497ec681f3Smrg                                         const unsigned pConstantData_size,
4507ec681f3Smrg                                         UINT Vector4iCount);
4517ec681f3Smrg
4527ec681f3Smrgvoid
4537ec681f3Smrgnine_context_set_pixel_shader_constant_b(struct NineDevice9 *device,
4547ec681f3Smrg                                         UINT StartRegister,
4557ec681f3Smrg                                         const BOOL *pConstantData,
4567ec681f3Smrg                                         const unsigned pConstantData_size,
4577ec681f3Smrg                                         UINT BoolCount);
4587ec681f3Smrg
4597ec681f3Smrgvoid
4607ec681f3Smrgnine_context_set_viewport(struct NineDevice9 *device,
4617ec681f3Smrg                          const D3DVIEWPORT9 *viewport);
4627ec681f3Smrg
4637ec681f3Smrgvoid
4647ec681f3Smrgnine_context_set_scissor(struct NineDevice9 *device,
4657ec681f3Smrg                         const struct pipe_scissor_state *scissor);
4667ec681f3Smrg
4677ec681f3Smrgvoid
4687ec681f3Smrgnine_context_set_transform(struct NineDevice9 *device,
4697ec681f3Smrg                           D3DTRANSFORMSTATETYPE State,
4707ec681f3Smrg                           const D3DMATRIX *pMatrix);
4717ec681f3Smrg
4727ec681f3Smrgvoid
4737ec681f3Smrgnine_context_set_material(struct NineDevice9 *device,
4747ec681f3Smrg                          const D3DMATERIAL9 *pMaterial);
4757ec681f3Smrg
4767ec681f3Smrgvoid
4777ec681f3Smrgnine_context_set_light(struct NineDevice9 *device,
4787ec681f3Smrg                       DWORD Index,
4797ec681f3Smrg                       const D3DLIGHT9 *pLight);
4807ec681f3Smrg
4817ec681f3Smrgvoid
4827ec681f3Smrgnine_context_light_enable(struct NineDevice9 *device,
4837ec681f3Smrg                          DWORD Index,
4847ec681f3Smrg                          BOOL Enable);
4857ec681f3Smrg
4867ec681f3Smrgvoid
4877ec681f3Smrgnine_context_set_texture_stage_state(struct NineDevice9 *device,
4887ec681f3Smrg                                     DWORD Stage,
4897ec681f3Smrg                                     D3DTEXTURESTAGESTATETYPE Type,
4907ec681f3Smrg                                     DWORD Value);
4917ec681f3Smrg
4927ec681f3Smrgvoid
4937ec681f3Smrgnine_context_set_render_target(struct NineDevice9 *device,
4947ec681f3Smrg                               DWORD RenderTargetIndex,
4957ec681f3Smrg                               struct NineSurface9 *rt);
4967ec681f3Smrg
4977ec681f3Smrgvoid
4987ec681f3Smrgnine_context_set_depth_stencil(struct NineDevice9 *device,
4997ec681f3Smrg                               struct NineSurface9 *ds);
5007ec681f3Smrg
5017ec681f3Smrgvoid
5027ec681f3Smrgnine_context_set_clip_plane(struct NineDevice9 *device,
5037ec681f3Smrg                            DWORD Index,
5047ec681f3Smrg                            const struct nine_clipplane *pPlane);
5057ec681f3Smrg
5067ec681f3Smrgvoid
5077ec681f3Smrgnine_context_set_swvp(struct NineDevice9 *device,
5087ec681f3Smrg                      boolean swvp);
5097ec681f3Smrg
5107ec681f3Smrgvoid
5117ec681f3Smrgnine_context_apply_stateblock(struct NineDevice9 *device,
5127ec681f3Smrg                              const struct nine_state *src);
5137ec681f3Smrg
5147ec681f3Smrgvoid
5157ec681f3Smrgnine_context_clear_fb(struct NineDevice9 *device, DWORD Count,
5167ec681f3Smrg                      const D3DRECT *pRects, DWORD Flags,
5177ec681f3Smrg                      D3DCOLOR Color, float Z, DWORD Stencil);
5187ec681f3Smrg
5197ec681f3Smrgvoid
5207ec681f3Smrgnine_context_draw_primitive(struct NineDevice9 *device,
5217ec681f3Smrg                            D3DPRIMITIVETYPE PrimitiveType,
5227ec681f3Smrg                            UINT StartVertex,
5237ec681f3Smrg                            UINT PrimitiveCount);
5247ec681f3Smrg
5257ec681f3Smrgvoid
5267ec681f3Smrgnine_context_draw_indexed_primitive(struct NineDevice9 *device,
5277ec681f3Smrg                                    D3DPRIMITIVETYPE PrimitiveType,
5287ec681f3Smrg                                    INT BaseVertexIndex,
5297ec681f3Smrg                                    UINT MinVertexIndex,
5307ec681f3Smrg                                    UINT NumVertices,
5317ec681f3Smrg                                    UINT StartIndex,
5327ec681f3Smrg                                    UINT PrimitiveCount);
5337ec681f3Smrg
5347ec681f3Smrgvoid
5357ec681f3Smrgnine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(struct NineDevice9 *device,
5367ec681f3Smrg                                                       D3DPRIMITIVETYPE PrimitiveType,
5377ec681f3Smrg                                                       UINT MinVertexIndex,
5387ec681f3Smrg                                                       UINT NumVertices,
5397ec681f3Smrg                                                       UINT PrimitiveCount,
5407ec681f3Smrg                                                       struct pipe_vertex_buffer *vbuf,
5417ec681f3Smrg                                                       struct pipe_resource *ibuf,
5427ec681f3Smrg                                                       void *user_ibuf,
5437ec681f3Smrg                                                       unsigned index_offset,
5447ec681f3Smrg						       unsigned index_size);
5457ec681f3Smrg
5467ec681f3Smrgvoid
5477ec681f3Smrgnine_context_resource_copy_region(struct NineDevice9 *device,
5487ec681f3Smrg                                  struct NineUnknown *dst,
5497ec681f3Smrg                                  struct NineUnknown *src,
5507ec681f3Smrg                                  struct pipe_resource* dst_res,
5517ec681f3Smrg                                  unsigned dst_level,
5527ec681f3Smrg                                  const struct pipe_box *dst_box,
5537ec681f3Smrg                                  struct pipe_resource* src_res,
5547ec681f3Smrg                                  unsigned src_level,
5557ec681f3Smrg                                  const struct pipe_box *src_box);
5567ec681f3Smrg
5577ec681f3Smrgvoid
5587ec681f3Smrgnine_context_blit(struct NineDevice9 *device,
5597ec681f3Smrg                  struct NineUnknown *dst,
5607ec681f3Smrg                  struct NineUnknown *src,
5617ec681f3Smrg                  struct pipe_blit_info *blit);
5627ec681f3Smrg
5637ec681f3Smrgvoid
5647ec681f3Smrgnine_context_clear_render_target(struct NineDevice9 *device,
5657ec681f3Smrg                                 struct NineSurface9 *surface,
5667ec681f3Smrg                                 D3DCOLOR color,
5677ec681f3Smrg                                 UINT x,
5687ec681f3Smrg                                 UINT y,
5697ec681f3Smrg                                 UINT width,
5707ec681f3Smrg                                 UINT height);
5717ec681f3Smrg
5727ec681f3Smrgvoid
5737ec681f3Smrgnine_context_gen_mipmap(struct NineDevice9 *device,
5747ec681f3Smrg                        struct NineUnknown *dst,
5757ec681f3Smrg                        struct pipe_resource *res,
5767ec681f3Smrg                        UINT base_level, UINT last_level,
5777ec681f3Smrg                        UINT first_layer, UINT last_layer,
5787ec681f3Smrg                        UINT filter);
5797ec681f3Smrg
5807ec681f3Smrgvoid
5817ec681f3Smrgnine_context_range_upload(struct NineDevice9 *device,
5827ec681f3Smrg                          unsigned *counter,
5837ec681f3Smrg                          struct NineUnknown *src_ref,
5847ec681f3Smrg                          struct pipe_resource *res,
5857ec681f3Smrg                          unsigned offset,
5867ec681f3Smrg                          unsigned size,
5877ec681f3Smrg                          unsigned usage,
5887ec681f3Smrg                          const void *data);
5897ec681f3Smrg
5907ec681f3Smrgvoid
5917ec681f3Smrgnine_context_box_upload(struct NineDevice9 *device,
5927ec681f3Smrg                        unsigned *counter,
5937ec681f3Smrg                        struct NineUnknown *src_ref,
5947ec681f3Smrg                        struct pipe_resource *res,
5957ec681f3Smrg                        unsigned level,
5967ec681f3Smrg                        const struct pipe_box *dst_box,
5977ec681f3Smrg                        enum pipe_format src_format,
5987ec681f3Smrg                        const void *src, unsigned src_stride,
5997ec681f3Smrg                        unsigned src_layer_stride,
6007ec681f3Smrg                        const struct pipe_box *src_box);
6017ec681f3Smrg
6027ec681f3Smrgstruct pipe_query *
6037ec681f3Smrgnine_context_create_query(struct NineDevice9 *device, unsigned query_type);
6047ec681f3Smrg
6057ec681f3Smrgvoid
6067ec681f3Smrgnine_context_destroy_query(struct NineDevice9 *device, struct pipe_query *query);
6077ec681f3Smrg
6087ec681f3Smrgvoid
6097ec681f3Smrgnine_context_begin_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);
6107ec681f3Smrg
6117ec681f3Smrgvoid
6127ec681f3Smrgnine_context_end_query(struct NineDevice9 *device, unsigned *counter, struct pipe_query *query);
6137ec681f3Smrg
6147ec681f3Smrgboolean
6157ec681f3Smrgnine_context_get_query_result(struct NineDevice9 *device, struct pipe_query *query,
6167ec681f3Smrg                              unsigned *counter, boolean flush, boolean wait,
6177ec681f3Smrg                              union pipe_query_result *result);
6187ec681f3Smrg
6197ec681f3Smrgvoid
6207ec681f3Smrgnine_context_pipe_flush(struct NineDevice9 *device);
6217ec681f3Smrg
6227ec681f3Smrgvoid nine_state_restore_non_cso(struct NineDevice9 *device);
6237ec681f3Smrgvoid nine_state_set_defaults(struct NineDevice9 *, const D3DCAPS9 *,
6247ec681f3Smrg                             boolean is_reset);
6257ec681f3Smrgvoid nine_device_state_clear(struct NineDevice9 *);
6267ec681f3Smrgvoid nine_context_clear(struct NineDevice9 *);
6277ec681f3Smrgvoid nine_context_update_state(struct NineDevice9 *);
6287ec681f3Smrg
6297ec681f3Smrgvoid nine_state_init_sw(struct NineDevice9 *device);
6307ec681f3Smrgvoid nine_state_prepare_draw_sw(struct NineDevice9 *device,
6317ec681f3Smrg                                struct NineVertexDeclaration9 *vdecl_out,
6327ec681f3Smrg                                int start_vertice,
6337ec681f3Smrg                                int num_vertices,
6347ec681f3Smrg                                struct pipe_stream_output_info *so);
6357ec681f3Smrgvoid nine_state_after_draw_sw(struct NineDevice9 *device);
6367ec681f3Smrgvoid nine_state_destroy_sw(struct NineDevice9 *device);
6377ec681f3Smrg
6387ec681f3Smrgvoid
6397ec681f3Smrgnine_state_resize_transform(struct nine_ff_state *ff_state, unsigned N);
6407ec681f3Smrg
6417ec681f3Smrg/* If @alloc is FALSE, the return value may be a const identity matrix.
6427ec681f3Smrg * Therefore, do not modify if you set alloc to FALSE !
6437ec681f3Smrg */
6447ec681f3SmrgD3DMATRIX *
6457ec681f3Smrgnine_state_access_transform(struct nine_ff_state *, D3DTRANSFORMSTATETYPE,
6467ec681f3Smrg                            boolean alloc);
6477ec681f3Smrg
6487ec681f3SmrgHRESULT
6497ec681f3Smrgnine_state_set_light(struct nine_ff_state *, DWORD, const D3DLIGHT9 *);
6507ec681f3Smrg
6517ec681f3SmrgHRESULT
6527ec681f3Smrgnine_state_light_enable(struct nine_ff_state *,
6537ec681f3Smrg                        DWORD, BOOL);
6547ec681f3Smrg
6557ec681f3Smrgconst char *nine_d3drs_to_string(DWORD State);
6567ec681f3Smrg
6577ec681f3Smrg/* CSMT functions */
6587ec681f3Smrgstruct csmt_context;
6597ec681f3Smrg
6607ec681f3Smrgstruct csmt_context *
6617ec681f3Smrgnine_csmt_create( struct NineDevice9 *This );
6627ec681f3Smrg
6637ec681f3Smrgvoid
6647ec681f3Smrgnine_csmt_destroy( struct NineDevice9 *This, struct csmt_context *ctx );
6657ec681f3Smrg
6667ec681f3Smrg/* Flushes and waits everything is executed */
6677ec681f3Smrgvoid
6687ec681f3Smrgnine_csmt_process( struct NineDevice9 *This );
6697ec681f3Smrg
6707ec681f3Smrg/* Flushes and doesn't wait */
6717ec681f3Smrgvoid
6727ec681f3Smrgnine_csmt_flush( struct NineDevice9 *This );
6737ec681f3Smrg
6747ec681f3Smrg/* Get the pipe_context (should not be called from the worker thread).
6757ec681f3Smrg * All the work in the worker thread is finished before returning. */
6767ec681f3Smrgstruct pipe_context *
6777ec681f3Smrgnine_context_get_pipe( struct NineDevice9 *device );
6787ec681f3Smrg
6797ec681f3Smrg/* Can be called from all threads */
6807ec681f3Smrgstruct pipe_context *
6817ec681f3Smrgnine_context_get_pipe_multithread( struct NineDevice9 *device );
6827ec681f3Smrg
6837ec681f3Smrg
6847ec681f3Smrg/* Get the pipe_context (should not be called from the worker thread).
6857ec681f3Smrg * All the work in the worker thread is paused before returning.
6867ec681f3Smrg * It is neccessary to release in order to restart the thread.
6877ec681f3Smrg * This is intended for use of the nine_context pipe_context that don't
6887ec681f3Smrg * need the worker thread to finish all queued job. */
6897ec681f3Smrgstruct pipe_context *
6907ec681f3Smrgnine_context_get_pipe_acquire( struct NineDevice9 *device );
6917ec681f3Smrg
6927ec681f3Smrgvoid
6937ec681f3Smrgnine_context_get_pipe_release( struct NineDevice9 *device );
6947ec681f3Smrg
6957ec681f3Smrgbool
6967ec681f3Smrgnine_context_is_worker( struct NineDevice9 *device );
6977ec681f3Smrg
6987ec681f3Smrg#endif /* _NINE_STATE_H_ */
699