r600_pipe.h revision 084c29baedf2702200b310d6e63a5d0f95aaac37
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 "r600.h"
34#include "r600_public.h"
35#include "r600_shader.h"
36#include "r600_resource.h"
37
38enum r600_pipe_state_id {
39	R600_PIPE_STATE_BLEND = 0,
40	R600_PIPE_STATE_BLEND_COLOR,
41	R600_PIPE_STATE_CONFIG,
42	R600_PIPE_STATE_CLIP,
43	R600_PIPE_STATE_SCISSOR,
44	R600_PIPE_STATE_VIEWPORT,
45	R600_PIPE_STATE_RASTERIZER,
46	R600_PIPE_STATE_VGT,
47	R600_PIPE_STATE_FRAMEBUFFER,
48	R600_PIPE_STATE_DSA,
49	R600_PIPE_STATE_STENCIL_REF,
50	R600_PIPE_STATE_PS_SHADER,
51	R600_PIPE_STATE_VS_SHADER,
52	R600_PIPE_STATE_CONSTANT,
53	R600_PIPE_STATE_SAMPLER,
54	R600_PIPE_STATE_RESOURCE,
55	R600_PIPE_NSTATES
56};
57
58struct r600_screen {
59	struct pipe_screen		screen;
60	struct radeon			*radeon;
61};
62
63struct r600_pipe_sampler_view {
64	struct pipe_sampler_view	base;
65	struct r600_pipe_state		state;
66};
67
68struct r600_pipe_rasterizer {
69	struct r600_pipe_state		rstate;
70	bool				flatshade;
71	unsigned			sprite_coord_enable;
72	float				offset_units;
73	float				offset_scale;
74};
75
76struct r600_pipe_blend {
77	struct r600_pipe_state		rstate;
78	unsigned			cb_target_mask;
79};
80
81struct r600_vertex_element
82{
83	unsigned			count;
84	unsigned			refcount;
85	struct pipe_vertex_element	elements[32];
86};
87
88struct r600_pipe_shader {
89	struct r600_shader		shader;
90	struct r600_pipe_state		rstate;
91	struct radeon_ws_bo		*bo;
92	struct r600_vertex_element	vertex_elements;
93};
94
95struct r600_pipe_context {
96	struct pipe_context		context;
97	struct blitter_context		*blitter;
98	struct pipe_framebuffer_state	*pframebuffer;
99	unsigned			family;
100	void				*custom_dsa_flush;
101	struct r600_screen		*screen;
102	struct radeon			*radeon;
103	struct r600_pipe_state		*states[R600_PIPE_NSTATES];
104	struct r600_context		ctx;
105	struct r600_vertex_element	*vertex_elements;
106	struct pipe_framebuffer_state	framebuffer;
107	struct pipe_index_buffer	index_buffer;
108	struct pipe_vertex_buffer	vertex_buffer[PIPE_MAX_ATTRIBS];
109	unsigned			nvertex_buffer;
110	unsigned			cb_target_mask;
111	/* for saving when using blitter */
112	struct pipe_stencil_ref		stencil_ref;
113	struct pipe_viewport_state	viewport;
114	struct pipe_clip_state		clip;
115	unsigned			vs_nconst;
116	unsigned			ps_nconst;
117	struct r600_pipe_state		vs_const[256];
118	struct r600_pipe_state		ps_const[256];
119	struct r600_pipe_state		vs_resource[160];
120	struct r600_pipe_state		ps_resource[160];
121	struct r600_pipe_state		config;
122	struct r600_pipe_shader 	*ps_shader;
123	struct r600_pipe_shader 	*vs_shader;
124	struct r600_pipe_state		vs_const_buffer;
125	struct r600_pipe_state		ps_const_buffer;
126	struct r600_pipe_rasterizer	*rasterizer;
127	/* shader information */
128	unsigned			sprite_coord_enable;
129	bool				flatshade;
130	struct u_upload_mgr		*upload_vb;
131	struct u_upload_mgr		*upload_ib;
132	unsigned			any_user_vbs;
133};
134
135struct r600_drawl {
136	struct pipe_context	*ctx;
137	unsigned		mode;
138	unsigned		min_index;
139	unsigned		max_index;
140	unsigned		index_bias;
141	unsigned		start;
142	unsigned		count;
143	unsigned		index_size;
144	unsigned		index_buffer_offset;
145	struct pipe_resource	*index_buffer;
146};
147
148/* evergreen_state.c */
149void evergreen_init_state_functions(struct r600_pipe_context *rctx);
150void evergreen_init_config(struct r600_pipe_context *rctx);
151void evergreen_draw(struct pipe_context *ctx, const struct pipe_draw_info *info);
152void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
153void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
154void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx);
155
156/* r600_blit.c */
157void r600_init_blit_functions(struct r600_pipe_context *rctx);
158int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
159
160/* r600_buffer.c */
161struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
162					 const struct pipe_resource *templ);
163struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
164					      void *ptr, unsigned bytes,
165					      unsigned bind);
166unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context,
167					 struct pipe_resource *buf,
168					 unsigned face, unsigned level);
169struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen,
170					      struct winsys_handle *whandle);
171int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw);
172int r600_upload_user_buffers(struct r600_pipe_context *rctx);
173
174/* r600_query.c */
175void r600_init_query_functions(struct r600_pipe_context *rctx);
176
177/* r600_resource.c */
178void r600_init_context_resource_functions(struct r600_pipe_context *r600);
179
180/* r600_shader.c */
181int r600_pipe_shader_update(struct pipe_context *ctx, struct r600_pipe_shader *shader);
182int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens);
183int r600_find_vs_semantic_index(struct r600_shader *vs,
184				struct r600_shader *ps, int id);
185
186/* r600_state.c */
187void r600_init_state_functions(struct r600_pipe_context *rctx);
188void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
189void r600_init_config(struct r600_pipe_context *rctx);
190void r600_translate_index_buffer(struct r600_pipe_context *r600,
191					struct pipe_resource **index_buffer,
192					unsigned *index_size,
193					unsigned *start, unsigned count);
194void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx);
195/* r600_helper.h */
196int r600_conv_pipe_prim(unsigned pprim, unsigned *prim);
197
198/* r600_texture.c */
199void r600_init_screen_texture_functions(struct pipe_screen *screen);
200uint32_t r600_translate_texformat(enum pipe_format format,
201				  const unsigned char *swizzle_view,
202				  uint32_t *word4_p, uint32_t *yuv_format_p);
203
204/*
205 * common helpers
206 */
207static INLINE u32 S_FIXED(float value, u32 frac_bits)
208{
209	return value * (1 << frac_bits);
210}
211#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
212
213#endif
214