r600g: refactor sample states into a reusable struct.
[mesa.git] / src / gallium / drivers / r600 / r600_context.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 R600_CONTEXT_H
24 #define R600_CONTEXT_H
25
26 #include <stdio.h>
27 #include <pipe/p_state.h>
28 #include <pipe/p_context.h>
29 #include <tgsi/tgsi_scan.h>
30 #include <tgsi/tgsi_parse.h>
31 #include <tgsi/tgsi_util.h>
32 #include <util/u_blitter.h>
33 #include <util/u_double_list.h>
34 #include "radeon.h"
35 #include "r600_shader.h"
36
37 #define R600_QUERY_STATE_STARTED (1 << 0)
38 #define R600_QUERY_STATE_ENDED (1 << 1)
39 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
40
41 struct r600_query {
42 u64 result;
43 /* The kind of query. Currently only OQ is supported. */
44 unsigned type;
45 /* How many results have been written, in dwords. It's incremented
46 * after end_query and flush. */
47 unsigned num_results;
48 /* if we've flushed the query */
49 boolean flushed;
50 unsigned state;
51 /* The buffer where query results are stored. */
52 struct radeon_bo *buffer;
53 unsigned buffer_size;
54 /* linked list of queries */
55 struct list_head list;
56 struct radeon_state rstate;
57 };
58
59 /* XXX move this to a more appropriate place */
60 union pipe_states {
61 struct pipe_rasterizer_state rasterizer;
62 struct pipe_poly_stipple poly_stipple;
63 struct pipe_scissor_state scissor;
64 struct pipe_clip_state clip;
65 struct pipe_shader_state shader;
66 struct pipe_depth_state depth;
67 struct pipe_stencil_state stencil;
68 struct pipe_alpha_state alpha;
69 struct pipe_depth_stencil_alpha_state dsa;
70 struct pipe_blend_state blend;
71 struct pipe_blend_color blend_color;
72 struct pipe_stencil_ref stencil_ref;
73 struct pipe_framebuffer_state framebuffer;
74 struct pipe_sampler_state sampler;
75 struct pipe_sampler_view sampler_view;
76 struct pipe_viewport_state viewport;
77 };
78
79 enum pipe_state_type {
80 pipe_rasterizer_type = 1,
81 pipe_poly_stipple_type,
82 pipe_scissor_type,
83 pipe_clip_type,
84 pipe_shader_type,
85 pipe_depth_type,
86 pipe_stencil_type,
87 pipe_alpha_type,
88 pipe_dsa_type,
89 pipe_blend_type,
90 pipe_stencil_ref_type,
91 pipe_framebuffer_type,
92 pipe_sampler_type,
93 pipe_sampler_view_type,
94 pipe_viewport_type,
95 pipe_type_count
96 };
97
98 #define R600_MAX_RSTATE 16
99
100 struct r600_context_state {
101 union pipe_states state;
102 unsigned refcount;
103 unsigned type;
104 struct radeon_state rstate[R600_MAX_RSTATE];
105 struct r600_shader shader;
106 struct radeon_bo *bo;
107 unsigned nrstate;
108 };
109
110 struct r600_vertex_element
111 {
112 unsigned refcount;
113 unsigned count;
114 struct pipe_vertex_element elements[32];
115 };
116
117 struct r600_context_hw_states {
118 struct radeon_state rasterizer;
119 struct radeon_state scissor;
120 struct radeon_state dsa;
121 struct radeon_state cb_cntl;
122 };
123
124 #define R600_MAX_CONSTANT 256 /* magic */
125 #define R600_MAX_RESOURCE 160 /* magic */
126
127 struct r600_shader_sampler_states {
128 unsigned nsampler;
129 unsigned nview;
130 unsigned nborder;
131 struct radeon_state *sampler[PIPE_MAX_ATTRIBS];
132 struct radeon_state *view[PIPE_MAX_ATTRIBS];
133 struct radeon_state *border[PIPE_MAX_ATTRIBS];
134 };
135
136 struct r600_context {
137 struct pipe_context context;
138 struct r600_screen *screen;
139 struct radeon *rw;
140 struct radeon_ctx ctx;
141 struct blitter_context *blitter;
142 struct radeon_draw draw;
143 struct radeon_state config;
144 /* FIXME get rid of those vs_resource,vs/ps_constant */
145 struct radeon_state *vs_resource;
146 unsigned vs_nresource;
147 struct radeon_state *vs_constant;
148 struct radeon_state *ps_constant;
149 /* hw states */
150 struct r600_context_hw_states hw_states;
151 /* pipe states */
152 unsigned flat_shade;
153
154 unsigned nvertex_buffer;
155 struct r600_context_state *rasterizer;
156 struct r600_context_state *poly_stipple;
157 struct r600_context_state *scissor;
158 struct r600_context_state *clip;
159 struct r600_context_state *ps_shader;
160 struct r600_context_state *vs_shader;
161 struct r600_context_state *depth;
162 struct r600_context_state *stencil;
163 struct r600_context_state *alpha;
164 struct r600_context_state *dsa;
165 struct r600_context_state *blend;
166 struct r600_context_state *stencil_ref;
167 struct r600_context_state *viewport;
168 struct r600_context_state *framebuffer;
169 struct r600_shader_sampler_states vs_sampler;
170 struct r600_shader_sampler_states ps_sampler;
171 /* can add gs later */
172 struct r600_vertex_element *vertex_elements;
173 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
174 struct pipe_index_buffer index_buffer;
175 struct pipe_blend_color blend_color;
176 struct list_head query_list;
177 };
178
179 /* Convenience cast wrapper. */
180 static INLINE struct r600_context *r600_context(struct pipe_context *pipe)
181 {
182 return (struct r600_context*)pipe;
183 }
184
185 static INLINE struct r600_query* r600_query(struct pipe_query* q)
186 {
187 return (struct r600_query*)q;
188 }
189
190 struct r600_context_state *r600_context_state_incref(struct r600_context_state *rstate);
191 struct r600_context_state *r600_context_state_decref(struct r600_context_state *rstate);
192 void r600_flush(struct pipe_context *ctx, unsigned flags,
193 struct pipe_fence_handle **fence);
194
195 int r600_context_hw_states(struct pipe_context *ctx);
196
197 void r600_draw_vbo(struct pipe_context *ctx,
198 const struct pipe_draw_info *info);
199
200 void r600_init_blit_functions(struct r600_context *rctx);
201 void r600_init_state_functions(struct r600_context *rctx);
202 void r600_init_query_functions(struct r600_context* rctx);
203 struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv);
204
205 extern int r600_pipe_shader_create(struct pipe_context *ctx,
206 struct r600_context_state *rstate,
207 const struct tgsi_token *tokens);
208 extern int r600_pipe_shader_update(struct pipe_context *ctx,
209 struct r600_context_state *rstate);
210
211 #define R600_ERR(fmt, args...) \
212 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
213
214 uint32_t r600_translate_texformat(enum pipe_format format,
215 const unsigned char *swizzle_view,
216 uint32_t *word4_p, uint32_t *yuv_format_p);
217
218 /* query */
219 extern void r600_queries_resume(struct pipe_context *ctx);
220 extern void r600_queries_suspend(struct pipe_context *ctx);
221
222
223 #endif