nv30, nv40: unify all structures and headers, except shaders
[mesa.git] / src / gallium / drivers / nvfx / nvfx_context.h
1 #ifndef __NVFX_CONTEXT_H__
2 #define __NVFX_CONTEXT_H__
3
4 #include <stdio.h>
5
6 #include "pipe/p_context.h"
7 #include "pipe/p_defines.h"
8 #include "pipe/p_state.h"
9 #include "pipe/p_compiler.h"
10
11 #include "util/u_memory.h"
12 #include "util/u_math.h"
13 #include "util/u_inlines.h"
14
15 #include "draw/draw_vertex.h"
16
17 #include "nouveau/nouveau_winsys.h"
18 #include "nouveau/nouveau_gldefs.h"
19 #include "nouveau/nouveau_context.h"
20 #include "nouveau/nouveau_stateobj.h"
21
22 #include "nvfx_state.h"
23
24 #define NOUVEAU_ERR(fmt, args...) \
25 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
26 #define NOUVEAU_MSG(fmt, args...) \
27 fprintf(stderr, "nouveau: "fmt, ##args);
28
29 enum nvfx_state_index {
30 NVFX_STATE_FB = 0,
31 NVFX_STATE_VIEWPORT = 1,
32 NVFX_STATE_BLEND = 2,
33 NVFX_STATE_RAST = 3,
34 NVFX_STATE_ZSA = 4,
35 NVFX_STATE_BCOL = 5,
36 NVFX_STATE_CLIP = 6,
37 NVFX_STATE_SCISSOR = 7,
38 NVFX_STATE_STIPPLE = 8,
39 NVFX_STATE_FRAGPROG = 9,
40 NVFX_STATE_VERTPROG = 10,
41 NVFX_STATE_FRAGTEX0 = 11,
42 NVFX_STATE_FRAGTEX1 = 12,
43 NVFX_STATE_FRAGTEX2 = 13,
44 NVFX_STATE_FRAGTEX3 = 14,
45 NVFX_STATE_FRAGTEX4 = 15,
46 NVFX_STATE_FRAGTEX5 = 16,
47 NVFX_STATE_FRAGTEX6 = 17,
48 NVFX_STATE_FRAGTEX7 = 18,
49 NVFX_STATE_FRAGTEX8 = 19,
50 NVFX_STATE_FRAGTEX9 = 20,
51 NVFX_STATE_FRAGTEX10 = 21,
52 NVFX_STATE_FRAGTEX11 = 22,
53 NVFX_STATE_FRAGTEX12 = 23,
54 NVFX_STATE_FRAGTEX13 = 24,
55 NVFX_STATE_FRAGTEX14 = 25,
56 NVFX_STATE_FRAGTEX15 = 26,
57 NVFX_STATE_VERTTEX0 = 27,
58 NVFX_STATE_VERTTEX1 = 28,
59 NVFX_STATE_VERTTEX2 = 29,
60 NVFX_STATE_VERTTEX3 = 30,
61 NVFX_STATE_VTXBUF = 31,
62 NVFX_STATE_VTXFMT = 32,
63 NVFX_STATE_VTXATTR = 33,
64 NVFX_STATE_SR = 34,
65 NVFX_STATE_MAX = 35
66 };
67
68 #include "nvfx_screen.h"
69
70 #define NVFX_NEW_BLEND (1 << 0)
71 #define NVFX_NEW_RAST (1 << 1)
72 #define NVFX_NEW_ZSA (1 << 2)
73 #define NVFX_NEW_SAMPLER (1 << 3)
74 #define NVFX_NEW_FB (1 << 4)
75 #define NVFX_NEW_STIPPLE (1 << 5)
76 #define NVFX_NEW_SCISSOR (1 << 6)
77 #define NVFX_NEW_VIEWPORT (1 << 7)
78 #define NVFX_NEW_BCOL (1 << 8)
79 #define NVFX_NEW_VERTPROG (1 << 9)
80 #define NVFX_NEW_FRAGPROG (1 << 10)
81 #define NVFX_NEW_ARRAYS (1 << 11)
82 #define NVFX_NEW_UCP (1 << 12)
83 #define NVFX_NEW_SR (1 << 13)
84
85 struct nvfx_rasterizer_state {
86 struct pipe_rasterizer_state pipe;
87 struct nouveau_stateobj *so;
88 };
89
90 struct nvfx_zsa_state {
91 struct pipe_depth_stencil_alpha_state pipe;
92 struct nouveau_stateobj *so;
93 };
94
95 struct nvfx_blend_state {
96 struct pipe_blend_state pipe;
97 struct nouveau_stateobj *so;
98 };
99
100
101 struct nvfx_state {
102 unsigned scissor_enabled;
103 unsigned stipple_enabled;
104 unsigned fp_samplers;
105
106 uint64_t dirty;
107 struct nouveau_stateobj *hw[NVFX_STATE_MAX];
108 };
109
110 struct nvfx_vtxelt_state {
111 struct pipe_vertex_element pipe[16];
112 unsigned num_elements;
113 };
114
115 struct nvfx_context {
116 struct pipe_context pipe;
117
118 struct nouveau_winsys *nvws;
119 struct nvfx_screen *screen;
120
121 struct draw_context *draw;
122
123 /* HW state derived from pipe states */
124 struct nvfx_state state;
125 struct {
126 struct nvfx_vertex_program *vertprog;
127
128 unsigned nr_attribs;
129 unsigned hw[PIPE_MAX_SHADER_INPUTS];
130 unsigned draw[PIPE_MAX_SHADER_INPUTS];
131 unsigned emit[PIPE_MAX_SHADER_INPUTS];
132 } swtnl;
133
134 enum {
135 HW, SWTNL, SWRAST
136 } render_mode;
137 unsigned fallback_swtnl;
138 unsigned fallback_swrast;
139
140 /* Context state */
141 unsigned dirty, draw_dirty;
142 struct pipe_scissor_state scissor;
143 unsigned stipple[32];
144 struct pipe_clip_state clip;
145 struct nvfx_vertex_program *vertprog;
146 struct nvfx_fragment_program *fragprog;
147 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
148 unsigned constbuf_nr[PIPE_SHADER_TYPES];
149 struct nvfx_rasterizer_state *rasterizer;
150 struct nvfx_zsa_state *zsa;
151 struct nvfx_blend_state *blend;
152 struct pipe_blend_color blend_colour;
153 struct pipe_stencil_ref stencil_ref;
154 struct pipe_viewport_state viewport;
155 struct pipe_framebuffer_state framebuffer;
156 struct pipe_buffer *idxbuf;
157 unsigned idxbuf_format;
158 struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
159 struct nvfx_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
160 unsigned nr_samplers;
161 unsigned nr_textures;
162 unsigned dirty_samplers;
163 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
164 unsigned vtxbuf_nr;
165 struct nvfx_vtxelt_state *vtxelt;
166 };
167
168 static INLINE struct nvfx_context *
169 nvfx_context(struct pipe_context *pipe)
170 {
171 return (struct nvfx_context *)pipe;
172 }
173
174 struct nvfx_state_entry {
175 boolean (*validate)(struct nvfx_context *nvfx);
176 struct {
177 unsigned pipe;
178 unsigned hw;
179 } dirty;
180 };
181
182 #endif