r600_pipe.h revision 26dacce2c0b33a2a6aff77e6094c06e385e1a541
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 r600_bo			*bo;
92	struct r600_vertex_element	vertex_elements;
93};
94
95/* needed for blitter save */
96struct r600_textures_info {
97	struct r600_pipe_sampler_view   **views;
98	unsigned                        n_views;
99	void				**samplers;
100	unsigned                        n_samplers;
101};
102
103#define R600_CONSTANT_ARRAY_SIZE 256
104#define R600_RESOURCE_ARRAY_SIZE 160
105
106struct r600_pipe_context {
107	struct pipe_context		context;
108	struct blitter_context		*blitter;
109	struct pipe_framebuffer_state	*pframebuffer;
110	unsigned			family;
111	void				*custom_dsa_flush;
112	struct r600_screen		*screen;
113	struct radeon			*radeon;
114	struct r600_pipe_state		*states[R600_PIPE_NSTATES];
115	struct r600_context		ctx;
116	struct r600_vertex_element	*vertex_elements;
117	struct pipe_framebuffer_state	framebuffer;
118	struct pipe_index_buffer	index_buffer;
119	struct pipe_vertex_buffer	vertex_buffer[PIPE_MAX_ATTRIBS];
120	unsigned			nvertex_buffer;
121	unsigned			cb_target_mask;
122	/* for saving when using blitter */
123	struct pipe_stencil_ref		stencil_ref;
124	struct pipe_viewport_state	viewport;
125	struct pipe_clip_state		clip;
126	struct r600_pipe_state		*vs_resource;
127	struct r600_pipe_state		*ps_resource;
128	struct r600_pipe_state		config;
129	struct r600_pipe_shader 	*ps_shader;
130	struct r600_pipe_shader 	*vs_shader;
131	struct r600_pipe_state		vs_const_buffer;
132	struct r600_pipe_state		ps_const_buffer;
133	struct r600_pipe_rasterizer	*rasterizer;
134	/* shader information */
135	unsigned			sprite_coord_enable;
136	bool				flatshade;
137	struct u_upload_mgr		*upload_vb;
138	struct u_upload_mgr		*upload_ib;
139	unsigned			any_user_vbs;
140	struct r600_textures_info       ps_samplers;
141
142};
143
144struct r600_drawl {
145	struct pipe_context	*ctx;
146	unsigned		mode;
147	unsigned		min_index;
148	unsigned		max_index;
149	unsigned		index_bias;
150	unsigned		start;
151	unsigned		count;
152	unsigned		index_size;
153	unsigned		index_buffer_offset;
154	struct pipe_resource	*index_buffer;
155};
156
157/* evergreen_state.c */
158void evergreen_init_state_functions(struct r600_pipe_context *rctx);
159void evergreen_init_config(struct r600_pipe_context *rctx);
160void evergreen_draw(struct pipe_context *ctx, const struct pipe_draw_info *info);
161void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
162void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
163void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx);
164
165/* r600_blit.c */
166void r600_init_blit_functions(struct r600_pipe_context *rctx);
167int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
168
169/* r600_buffer.c */
170struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
171					 const struct pipe_resource *templ);
172struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
173					      void *ptr, unsigned bytes,
174					      unsigned bind);
175unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context,
176					 struct pipe_resource *buf,
177					 unsigned face, unsigned level);
178struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen,
179					      struct winsys_handle *whandle);
180int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw);
181int r600_upload_user_buffers(struct r600_pipe_context *rctx);
182
183/* r600_query.c */
184void r600_init_query_functions(struct r600_pipe_context *rctx);
185
186/* r600_resource.c */
187void r600_init_context_resource_functions(struct r600_pipe_context *r600);
188
189/* r600_shader.c */
190int r600_pipe_shader_update(struct pipe_context *ctx, struct r600_pipe_shader *shader);
191int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens);
192int r600_find_vs_semantic_index(struct r600_shader *vs,
193				struct r600_shader *ps, int id);
194
195/* r600_state.c */
196void r600_init_state_functions(struct r600_pipe_context *rctx);
197void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
198void r600_init_config(struct r600_pipe_context *rctx);
199void r600_translate_index_buffer(struct r600_pipe_context *r600,
200					struct pipe_resource **index_buffer,
201					unsigned *index_size,
202					unsigned *start, unsigned count);
203void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx);
204/* r600_helper.h */
205int r600_conv_pipe_prim(unsigned pprim, unsigned *prim);
206
207/* r600_texture.c */
208void r600_init_screen_texture_functions(struct pipe_screen *screen);
209uint32_t r600_translate_texformat(enum pipe_format format,
210				  const unsigned char *swizzle_view,
211				  uint32_t *word4_p, uint32_t *yuv_format_p);
212
213/*
214 * common helpers
215 */
216static INLINE u32 S_FIXED(float value, u32 frac_bits)
217{
218	return value * (1 << frac_bits);
219}
220#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
221
222#endif
223