r600_pipe.h revision d59498b78041b8a7a046ac2c892e7a1896f59ca2
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	unsigned			vs_nconst;
127	unsigned			ps_nconst;
128	struct r600_pipe_state		*vs_const;
129	struct r600_pipe_state		*ps_const;
130	struct r600_pipe_state		*vs_resource;
131	struct r600_pipe_state		*ps_resource;
132	struct r600_pipe_state		config;
133	struct r600_pipe_shader 	*ps_shader;
134	struct r600_pipe_shader 	*vs_shader;
135	struct r600_pipe_state		vs_const_buffer;
136	struct r600_pipe_state		ps_const_buffer;
137	struct r600_pipe_rasterizer	*rasterizer;
138	/* shader information */
139	unsigned			sprite_coord_enable;
140	bool				flatshade;
141	struct u_upload_mgr		*upload_vb;
142	struct u_upload_mgr		*upload_ib;
143	unsigned			any_user_vbs;
144	struct r600_textures_info       ps_samplers;
145
146};
147
148struct r600_drawl {
149	struct pipe_context	*ctx;
150	unsigned		mode;
151	unsigned		min_index;
152	unsigned		max_index;
153	unsigned		index_bias;
154	unsigned		start;
155	unsigned		count;
156	unsigned		index_size;
157	unsigned		index_buffer_offset;
158	struct pipe_resource	*index_buffer;
159};
160
161/* evergreen_state.c */
162void evergreen_init_state_functions(struct r600_pipe_context *rctx);
163void evergreen_init_config(struct r600_pipe_context *rctx);
164void evergreen_draw(struct pipe_context *ctx, const struct pipe_draw_info *info);
165void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
166void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
167void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx);
168
169/* r600_blit.c */
170void r600_init_blit_functions(struct r600_pipe_context *rctx);
171int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
172
173/* r600_buffer.c */
174struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
175					 const struct pipe_resource *templ);
176struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
177					      void *ptr, unsigned bytes,
178					      unsigned bind);
179unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context,
180					 struct pipe_resource *buf,
181					 unsigned face, unsigned level);
182struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen,
183					      struct winsys_handle *whandle);
184int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw);
185int r600_upload_user_buffers(struct r600_pipe_context *rctx);
186
187/* r600_query.c */
188void r600_init_query_functions(struct r600_pipe_context *rctx);
189
190/* r600_resource.c */
191void r600_init_context_resource_functions(struct r600_pipe_context *r600);
192
193/* r600_shader.c */
194int r600_pipe_shader_update(struct pipe_context *ctx, struct r600_pipe_shader *shader);
195int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens);
196int r600_find_vs_semantic_index(struct r600_shader *vs,
197				struct r600_shader *ps, int id);
198
199/* r600_state.c */
200void r600_init_state_functions(struct r600_pipe_context *rctx);
201void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
202void r600_init_config(struct r600_pipe_context *rctx);
203void r600_translate_index_buffer(struct r600_pipe_context *r600,
204					struct pipe_resource **index_buffer,
205					unsigned *index_size,
206					unsigned *start, unsigned count);
207void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx);
208/* r600_helper.h */
209int r600_conv_pipe_prim(unsigned pprim, unsigned *prim);
210
211/* r600_texture.c */
212void r600_init_screen_texture_functions(struct pipe_screen *screen);
213uint32_t r600_translate_texformat(enum pipe_format format,
214				  const unsigned char *swizzle_view,
215				  uint32_t *word4_p, uint32_t *yuv_format_p);
216
217/*
218 * common helpers
219 */
220static INLINE u32 S_FIXED(float value, u32 frac_bits)
221{
222	return value * (1 << frac_bits);
223}
224#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
225
226#endif
227