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 struct r600_context_state
{
99 union pipe_states state
;
102 struct radeon_state
*rstate
;
103 struct r600_shader shader
;
104 struct radeon_bo
*bo
;
107 struct r600_vertex_element
111 struct pipe_vertex_element elements
[32];
114 struct r600_context_hw_states
{
115 struct radeon_state
*rasterizer
;
116 struct radeon_state
*scissor
;
117 struct radeon_state
*dsa
;
118 struct radeon_state
*blend
;
119 struct radeon_state
*viewport
;
120 struct radeon_state
*cb
[8];
121 struct radeon_state
*config
;
122 struct radeon_state
*cb_cntl
;
123 struct radeon_state
*db
;
124 struct radeon_state
*ucp
[6];
125 unsigned ps_nresource
;
126 unsigned ps_nsampler
;
127 struct radeon_state
*ps_resource
[160];
128 struct radeon_state
*ps_sampler
[16];
131 struct r600_context
{
132 struct pipe_context context
;
133 struct r600_screen
*screen
;
135 struct radeon_ctx
*ctx
;
136 struct blitter_context
*blitter
;
137 struct radeon_draw
*draw
;
139 struct r600_context_hw_states hw_states
;
142 unsigned ps_nsampler
;
143 unsigned vs_nsampler
;
144 unsigned ps_nsampler_view
;
145 unsigned vs_nsampler_view
;
146 unsigned nvertex_buffer
;
147 struct r600_context_state
*rasterizer
;
148 struct r600_context_state
*poly_stipple
;
149 struct r600_context_state
*scissor
;
150 struct r600_context_state
*clip
;
151 struct r600_context_state
*ps_shader
;
152 struct r600_context_state
*vs_shader
;
153 struct r600_context_state
*depth
;
154 struct r600_context_state
*stencil
;
155 struct r600_context_state
*alpha
;
156 struct r600_context_state
*dsa
;
157 struct r600_context_state
*blend
;
158 struct r600_context_state
*stencil_ref
;
159 struct r600_context_state
*viewport
;
160 struct r600_context_state
*framebuffer
;
161 struct r600_context_state
*ps_sampler
[PIPE_MAX_ATTRIBS
];
162 struct r600_context_state
*vs_sampler
[PIPE_MAX_ATTRIBS
];
163 struct r600_context_state
*ps_sampler_view
[PIPE_MAX_ATTRIBS
];
164 struct r600_context_state
*vs_sampler_view
[PIPE_MAX_ATTRIBS
];
165 struct r600_vertex_element
*vertex_elements
;
166 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
167 struct pipe_index_buffer index_buffer
;
168 struct pipe_blend_color blend_color
;
169 struct list_head query_list
;
172 /* Convenience cast wrapper. */
173 static INLINE
struct r600_context
*r600_context(struct pipe_context
*pipe
)
175 return (struct r600_context
*)pipe
;
178 static INLINE
struct r600_query
* r600_query(struct pipe_query
* q
)
180 return (struct r600_query
*)q
;
183 struct r600_context_state
*r600_context_state(struct r600_context
*rctx
, unsigned type
, const void *state
);
184 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
);
185 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
);
186 void r600_flush(struct pipe_context
*ctx
, unsigned flags
,
187 struct pipe_fence_handle
**fence
);
189 int r600_context_hw_states(struct pipe_context
*ctx
);
191 void r600_draw_vbo(struct pipe_context
*ctx
,
192 const struct pipe_draw_info
*info
);
194 void r600_init_blit_functions(struct r600_context
*rctx
);
195 void r600_init_state_functions(struct r600_context
*rctx
);
196 void r600_init_query_functions(struct r600_context
* rctx
);
197 struct pipe_context
*r600_create_context(struct pipe_screen
*screen
, void *priv
);
199 extern int r600_pipe_shader_create(struct pipe_context
*ctx
,
200 struct r600_context_state
*rstate
,
201 const struct tgsi_token
*tokens
);
202 extern int r600_pipe_shader_update(struct pipe_context
*ctx
,
203 struct r600_context_state
*rstate
);
205 #define R600_ERR(fmt, args...) \
206 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
208 uint32_t r600_translate_texformat(enum pipe_format format
,
209 const unsigned char *swizzle_view
,
210 uint32_t *word4_p
, uint32_t *yuv_format_p
);
213 extern void r600_queries_resume(struct pipe_context
*ctx
);
214 extern void r600_queries_suspend(struct pipe_context
*ctx
);