2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
23 #ifndef R600_CONTEXT_H
24 #define R600_CONTEXT_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>
35 #include "r600_shader.h"
37 #define R600_QUERY_STATE_STARTED (1 << 0)
38 #define R600_QUERY_STATE_ENDED (1 << 1)
39 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
43 /* The kind of query. Currently only OQ is supported. */
45 /* How many results have been written, in dwords. It's incremented
46 * after end_query and flush. */
48 /* if we've flushed the query */
51 /* The buffer where query results are stored. */
52 struct radeon_bo
*buffer
;
54 /* linked list of queries */
55 struct list_head list
;
56 struct radeon_state rstate
;
59 /* XXX move this to a more appropriate place */
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
;
79 enum pipe_state_type
{
80 pipe_rasterizer_type
= 1,
81 pipe_poly_stipple_type
,
90 pipe_stencil_ref_type
,
91 pipe_framebuffer_type
,
93 pipe_sampler_view_type
,
98 #define R600_MAX_RSTATE 16
100 struct r600_context_state
{
101 union pipe_states state
;
104 struct radeon_state rstate
[R600_MAX_RSTATE
];
105 struct r600_shader shader
;
106 struct radeon_bo
*bo
;
110 struct r600_vertex_element
114 struct pipe_vertex_element elements
[32];
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
;
123 struct radeon_state db_flush
;
124 struct radeon_state cb_flush
;
127 #define R600_MAX_CONSTANT 256 /* magic */
128 #define R600_MAX_RESOURCE 160 /* magic */
130 struct r600_shader_sampler_states
{
134 struct radeon_state
*sampler
[PIPE_MAX_ATTRIBS
];
135 struct radeon_state
*view
[PIPE_MAX_ATTRIBS
];
136 struct radeon_state
*border
[PIPE_MAX_ATTRIBS
];
140 struct r600_resource
;
142 struct r600_context_hw_state_vtbl
{
143 void (*blend
)(struct r600_context
*rctx
,
144 struct radeon_state
*rstate
,
145 const struct pipe_blend_state
*state
);
146 void (*ucp
)(struct r600_context
*rctx
, struct radeon_state
*rstate
,
147 const struct pipe_clip_state
*state
);
148 void (*cb
)(struct r600_context
*rctx
, struct radeon_state
*rstate
,
149 const struct pipe_framebuffer_state
*state
, int cb
);
150 void (*db
)(struct r600_context
*rctx
, struct radeon_state
*rstate
,
151 const struct pipe_framebuffer_state
*state
);
152 void (*rasterizer
)(struct r600_context
*rctx
, struct radeon_state
*rstate
);
153 void (*scissor
)(struct r600_context
*rctx
, struct radeon_state
*rstate
);
154 void (*viewport
)(struct r600_context
*rctx
, struct radeon_state
*rstate
, const struct pipe_viewport_state
*state
);
155 void (*dsa
)(struct r600_context
*rctx
, struct radeon_state
*rstate
);
156 void (*sampler_border
)(struct r600_context
*rctx
, struct radeon_state
*rstate
,
157 const struct pipe_sampler_state
*state
, unsigned id
);
158 void (*sampler
)(struct r600_context
*rctx
, struct radeon_state
*rstate
,
159 const struct pipe_sampler_state
*state
, unsigned id
);
160 void (*resource
)(struct pipe_context
*ctx
, struct radeon_state
*rstate
,
161 const struct pipe_sampler_view
*view
, unsigned id
);
162 void (*cb_cntl
)(struct r600_context
*rctx
, struct radeon_state
*rstate
);
163 int (*vs_resource
)(struct r600_context
*rctx
, int id
, struct r600_resource
*rbuffer
, uint32_t offset
,
164 uint32_t stride
, uint32_t format
);
165 int (*vgt_init
)(struct r600_context
*rctx
, struct radeon_state
*draw
,
166 struct r600_resource
*rbuffer
,
167 uint32_t count
, int vgt_draw_initiator
);
168 int (*vgt_prim
)(struct r600_context
*rctx
, struct radeon_state
*vgt
,
169 uint32_t prim
, uint32_t start
, uint32_t vgt_dma_index_type
);
171 int (*ps_shader
)(struct r600_context
*rctx
, struct r600_context_state
*rshader
,
172 struct radeon_state
*state
);
173 int (*vs_shader
)(struct r600_context
*rctx
, struct r600_context_state
*rpshader
,
174 struct radeon_state
*state
);
175 void (*init_config
)(struct r600_context
*rctx
);
177 extern struct r600_context_hw_state_vtbl r600_hw_state_vtbl
;
178 extern struct r600_context_hw_state_vtbl eg_hw_state_vtbl
;
180 struct r600_context
{
181 struct pipe_context context
;
182 struct r600_screen
*screen
;
184 struct radeon_ctx ctx
;
185 struct blitter_context
*blitter
;
186 struct radeon_draw draw
;
187 struct r600_context_hw_state_vtbl
*vtbl
;
188 struct radeon_state config
;
189 boolean use_mem_constant
;
190 /* FIXME get rid of those vs_resource,vs/ps_constant */
191 struct radeon_state
*vs_resource
;
192 unsigned vs_nresource
;
193 struct radeon_state
*vs_constant
;
194 struct radeon_state
*ps_constant
;
196 struct r600_context_hw_states hw_states
;
200 unsigned nvertex_buffer
;
201 struct r600_context_state
*rasterizer
;
202 struct r600_context_state
*poly_stipple
;
203 struct r600_context_state
*scissor
;
204 struct r600_context_state
*clip
;
205 struct r600_context_state
*ps_shader
;
206 struct r600_context_state
*vs_shader
;
207 struct r600_context_state
*depth
;
208 struct r600_context_state
*stencil
;
209 struct r600_context_state
*alpha
;
210 struct r600_context_state
*dsa
;
211 struct r600_context_state
*blend
;
212 struct r600_context_state
*stencil_ref
;
213 struct r600_context_state
*viewport
;
214 struct r600_context_state
*framebuffer
;
215 struct r600_shader_sampler_states vs_sampler
;
216 struct r600_shader_sampler_states ps_sampler
;
217 /* can add gs later */
218 struct r600_vertex_element
*vertex_elements
;
219 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
220 struct pipe_index_buffer index_buffer
;
221 struct pipe_blend_color blend_color
;
222 struct list_head query_list
;
225 /* Convenience cast wrapper. */
226 static INLINE
struct r600_context
*r600_context(struct pipe_context
*pipe
)
228 return (struct r600_context
*)pipe
;
231 static INLINE
struct r600_query
* r600_query(struct pipe_query
* q
)
233 return (struct r600_query
*)q
;
236 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
);
237 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
);
238 void r600_flush(struct pipe_context
*ctx
, unsigned flags
,
239 struct pipe_fence_handle
**fence
);
241 int r600_context_hw_states(struct pipe_context
*ctx
);
243 void r600_draw_vbo(struct pipe_context
*ctx
,
244 const struct pipe_draw_info
*info
);
246 void r600_init_blit_functions(struct r600_context
*rctx
);
247 void r600_init_state_functions(struct r600_context
*rctx
);
248 void r600_init_query_functions(struct r600_context
* rctx
);
249 struct pipe_context
*r600_create_context(struct pipe_screen
*screen
, void *priv
);
251 extern int r600_pipe_shader_create(struct pipe_context
*ctx
,
252 struct r600_context_state
*rstate
,
253 const struct tgsi_token
*tokens
);
254 extern int r600_pipe_shader_update(struct pipe_context
*ctx
,
255 struct r600_context_state
*rstate
);
257 #define R600_ERR(fmt, args...) \
258 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
260 uint32_t r600_translate_texformat(enum pipe_format format
,
261 const unsigned char *swizzle_view
,
262 uint32_t *word4_p
, uint32_t *yuv_format_p
);
265 extern void r600_queries_resume(struct pipe_context
*ctx
);
266 extern void r600_queries_suspend(struct pipe_context
*ctx
);
268 int eg_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
);
270 void r600_set_constant_buffer_file(struct pipe_context
*ctx
,
271 uint shader
, uint index
,
272 struct pipe_resource
*buffer
);
273 void r600_set_constant_buffer_mem(struct pipe_context
*ctx
,
274 uint shader
, uint index
,
275 struct pipe_resource
*buffer
);
276 void eg_set_constant_buffer(struct pipe_context
*ctx
,
277 uint shader
, uint index
,
278 struct pipe_resource
*buffer
);