r600_pipe.h revision 929be6eb95c33d5885a89b36dbc82db64c1344fe
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 * Authors:
24 *      Jerome Glisse
25 */
26#ifndef R600_PIPE_H
27#define R600_PIPE_H
28
29#include <pipe/p_state.h>
30#include <pipe/p_screen.h>
31#include <pipe/p_context.h>
32#include <util/u_math.h>
33#include "util/u_slab.h"
34#include "util/u_vbuf_mgr.h"
35#include "r600.h"
36#include "r600_public.h"
37#include "r600_shader.h"
38#include "r600_resource.h"
39
40#define R600_MAX_CONST_BUFFERS 1
41
42enum r600_pipe_state_id {
43	R600_PIPE_STATE_BLEND = 0,
44	R600_PIPE_STATE_BLEND_COLOR,
45	R600_PIPE_STATE_CONFIG,
46	R600_PIPE_STATE_CLIP,
47	R600_PIPE_STATE_SCISSOR,
48	R600_PIPE_STATE_VIEWPORT,
49	R600_PIPE_STATE_RASTERIZER,
50	R600_PIPE_STATE_VGT,
51	R600_PIPE_STATE_FRAMEBUFFER,
52	R600_PIPE_STATE_DSA,
53	R600_PIPE_STATE_STENCIL_REF,
54	R600_PIPE_STATE_PS_SHADER,
55	R600_PIPE_STATE_VS_SHADER,
56	R600_PIPE_STATE_CONSTANT,
57	R600_PIPE_STATE_SAMPLER,
58	R600_PIPE_STATE_RESOURCE,
59	R600_PIPE_STATE_POLYGON_OFFSET,
60	R600_PIPE_STATE_FETCH_SHADER,
61	R600_PIPE_NSTATES
62};
63
64struct r600_screen {
65	struct pipe_screen		screen;
66	struct radeon			*radeon;
67	struct r600_tiling_info		*tiling_info;
68	struct util_slab_mempool	pool_buffers;
69	unsigned			num_contexts;
70
71	/* for thread-safe write accessing to num_contexts */
72	pipe_mutex			mutex_num_contexts;
73};
74
75struct r600_pipe_sampler_view {
76	struct pipe_sampler_view	base;
77	struct r600_pipe_state		state;
78};
79
80struct r600_pipe_rasterizer {
81	struct r600_pipe_state		rstate;
82	bool				flatshade;
83	unsigned			sprite_coord_enable;
84	float				offset_units;
85	float				offset_scale;
86};
87
88struct r600_pipe_blend {
89	struct r600_pipe_state		rstate;
90	unsigned			cb_target_mask;
91};
92
93struct r600_vertex_element
94{
95	unsigned			count;
96	struct pipe_vertex_element	elements[PIPE_MAX_ATTRIBS];
97	struct u_vbuf_mgr_elements	*vmgr_elements;
98	struct r600_bo			*fetch_shader;
99	unsigned			fs_size;
100	struct r600_pipe_state		rstate;
101	/* if offset is to big for fetch instructio we need to alterate
102	 * offset of vertex buffer, record here the offset need to add
103	 */
104	unsigned			vbuffer_need_offset;
105	unsigned			vbuffer_offset[PIPE_MAX_ATTRIBS];
106};
107
108struct r600_pipe_shader {
109	struct r600_shader		shader;
110	struct r600_pipe_state		rstate;
111	struct r600_bo			*bo;
112	struct r600_bo			*bo_fetch;
113	struct r600_vertex_element	vertex_elements;
114};
115
116/* needed for blitter save */
117#define NUM_TEX_UNITS 16
118
119struct r600_textures_info {
120	struct r600_pipe_sampler_view	*views[NUM_TEX_UNITS];
121	unsigned			n_views;
122	void				*samplers[NUM_TEX_UNITS];
123	unsigned			n_samplers;
124};
125
126#define R600_CONSTANT_ARRAY_SIZE 256
127#define R600_RESOURCE_ARRAY_SIZE 160
128
129struct r600_pipe_context {
130	struct pipe_context		context;
131	struct blitter_context		*blitter;
132	unsigned			family;
133	void				*custom_dsa_flush;
134	struct r600_screen		*screen;
135	struct radeon			*radeon;
136	struct r600_pipe_state		*states[R600_PIPE_NSTATES];
137	struct r600_context		ctx;
138	struct r600_vertex_element	*vertex_elements;
139	struct r600_pipe_state		fs_resource[PIPE_MAX_ATTRIBS];
140	struct pipe_framebuffer_state	framebuffer;
141	struct pipe_index_buffer	index_buffer;
142	unsigned			cb_target_mask;
143	/* for saving when using blitter */
144	struct pipe_stencil_ref		stencil_ref;
145	struct pipe_viewport_state	viewport;
146	struct pipe_clip_state		clip;
147	struct r600_pipe_state		config;
148	struct r600_pipe_shader 	*ps_shader;
149	struct r600_pipe_shader 	*vs_shader;
150	struct r600_pipe_state		vs_const_buffer;
151	struct r600_pipe_state		vs_const_buffer_resource[R600_MAX_CONST_BUFFERS];
152	struct r600_pipe_state		ps_const_buffer;
153	struct r600_pipe_state		ps_const_buffer_resource[R600_MAX_CONST_BUFFERS];
154	struct r600_pipe_rasterizer	*rasterizer;
155	/* shader information */
156	unsigned			sprite_coord_enable;
157	bool				flatshade;
158	struct r600_textures_info	ps_samplers;
159
160	struct u_vbuf_mgr		*vbuf_mgr;
161	struct util_slab_mempool	pool_transfers;
162	bool				blit;
163};
164
165struct r600_drawl {
166	struct pipe_draw_info	info;
167	struct pipe_context	*ctx;
168	unsigned		index_size;
169	unsigned		index_buffer_offset;
170	struct pipe_resource	*index_buffer;
171};
172
173/* evergreen_state.c */
174void evergreen_init_state_functions(struct r600_pipe_context *rctx);
175void evergreen_init_config(struct r600_pipe_context *rctx);
176void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
177void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
178void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx);
179void evergreen_polygon_offset_update(struct r600_pipe_context *rctx);
180void evergreen_pipe_set_buffer_resource(struct r600_pipe_context *rctx,
181					struct r600_pipe_state *rstate,
182					struct r600_resource *rbuffer,
183					unsigned offset, unsigned stride);
184
185/* r600_blit.c */
186void r600_init_blit_functions(struct r600_pipe_context *rctx);
187void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
188void r600_blit_push_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
189void r600_flush_depth_textures(struct r600_pipe_context *rctx);
190
191/* r600_buffer.c */
192struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
193					 const struct pipe_resource *templ);
194struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
195					      void *ptr, unsigned bytes,
196					      unsigned bind);
197struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen,
198					      struct winsys_handle *whandle);
199void r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw);
200
201/* r600_query.c */
202void r600_init_query_functions(struct r600_pipe_context *rctx);
203
204/* r600_resource.c */
205void r600_init_context_resource_functions(struct r600_pipe_context *r600);
206
207/* r600_shader.c */
208int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens);
209void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
210int r600_find_vs_semantic_index(struct r600_shader *vs,
211				struct r600_shader *ps, int id);
212
213/* r600_state.c */
214void r600_init_state_functions(struct r600_pipe_context *rctx);
215void r600_spi_update(struct r600_pipe_context *rctx);
216void r600_init_config(struct r600_pipe_context *rctx);
217void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx);
218void r600_polygon_offset_update(struct r600_pipe_context *rctx);
219void r600_pipe_set_buffer_resource(struct r600_pipe_context *rctx,
220				   struct r600_pipe_state *rstate,
221				   struct r600_resource *rbuffer,
222				   unsigned offset, unsigned stride);
223
224/* r600_helper.h */
225int r600_conv_pipe_prim(unsigned pprim, unsigned *prim);
226
227/* r600_texture.c */
228void r600_init_screen_texture_functions(struct pipe_screen *screen);
229void r600_init_surface_functions(struct r600_pipe_context *r600);
230uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
231				  const unsigned char *swizzle_view,
232				  uint32_t *word4_p, uint32_t *yuv_format_p);
233unsigned r600_texture_get_offset(struct r600_resource_texture *rtex,
234					unsigned level, unsigned layer);
235
236/* r600_translate.c */
237void r600_translate_index_buffer(struct r600_pipe_context *r600,
238				 struct pipe_resource **index_buffer,
239				 unsigned *index_size,
240				 unsigned *start, unsigned count);
241
242/* r600_state_common.c */
243void r600_set_index_buffer(struct pipe_context *ctx,
244			   const struct pipe_index_buffer *ib);
245void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count,
246			     const struct pipe_vertex_buffer *buffers);
247void *r600_create_vertex_elements(struct pipe_context *ctx,
248				  unsigned count,
249				  const struct pipe_vertex_element *elements);
250void r600_delete_vertex_element(struct pipe_context *ctx, void *state);
251void r600_bind_blend_state(struct pipe_context *ctx, void *state);
252void r600_bind_rs_state(struct pipe_context *ctx, void *state);
253void r600_delete_rs_state(struct pipe_context *ctx, void *state);
254void r600_sampler_view_destroy(struct pipe_context *ctx,
255			       struct pipe_sampler_view *state);
256void r600_bind_state(struct pipe_context *ctx, void *state);
257void r600_delete_state(struct pipe_context *ctx, void *state);
258void r600_bind_vertex_elements(struct pipe_context *ctx, void *state);
259void *r600_create_shader_state(struct pipe_context *ctx,
260			       const struct pipe_shader_state *state);
261void r600_bind_ps_shader(struct pipe_context *ctx, void *state);
262void r600_bind_vs_shader(struct pipe_context *ctx, void *state);
263void r600_delete_ps_shader(struct pipe_context *ctx, void *state);
264void r600_delete_vs_shader(struct pipe_context *ctx, void *state);
265void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
266			      struct pipe_resource *buffer);
267void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
268
269/*
270 * common helpers
271 */
272static INLINE u32 S_FIXED(float value, u32 frac_bits)
273{
274	return value * (1 << frac_bits);
275}
276#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
277
278#endif
279