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