2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
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"
36 #include "r600_public.h"
37 #include "r600_shader.h"
38 #include "r600_resource.h"
40 #define R600_MAX_CONST_BUFFERS 1
42 enum r600_pipe_state_id
{
43 R600_PIPE_STATE_BLEND
= 0,
44 R600_PIPE_STATE_BLEND_COLOR
,
45 R600_PIPE_STATE_CONFIG
,
47 R600_PIPE_STATE_SCISSOR
,
48 R600_PIPE_STATE_VIEWPORT
,
49 R600_PIPE_STATE_RASTERIZER
,
51 R600_PIPE_STATE_FRAMEBUFFER
,
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
,
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
;
71 /* for thread-safe write accessing to num_contexts */
72 pipe_mutex mutex_num_contexts
;
75 struct r600_pipe_sampler_view
{
76 struct pipe_sampler_view base
;
77 struct r600_pipe_state state
;
80 struct r600_pipe_rasterizer
{
81 struct r600_pipe_state rstate
;
83 unsigned sprite_coord_enable
;
88 struct r600_pipe_blend
{
89 struct r600_pipe_state rstate
;
90 unsigned cb_target_mask
;
93 struct r600_vertex_element
96 struct pipe_vertex_element elements
[PIPE_MAX_ATTRIBS
];
97 struct u_vbuf_mgr_elements
*vmgr_elements
;
98 struct r600_bo
*fetch_shader
;
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
104 unsigned vbuffer_need_offset
;
105 unsigned vbuffer_offset
[PIPE_MAX_ATTRIBS
];
108 struct r600_pipe_shader
{
109 struct r600_shader shader
;
110 struct r600_pipe_state rstate
;
112 struct r600_bo
*bo_fetch
;
113 struct r600_vertex_element vertex_elements
;
116 /* needed for blitter save */
117 #define NUM_TEX_UNITS 16
119 struct r600_textures_info
{
120 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
122 void *samplers
[NUM_TEX_UNITS
];
126 #define R600_CONSTANT_ARRAY_SIZE 256
127 #define R600_RESOURCE_ARRAY_SIZE 160
129 struct r600_pipe_context
{
130 struct pipe_context context
;
131 struct blitter_context
*blitter
;
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
;
158 struct r600_textures_info ps_samplers
;
160 struct u_vbuf_mgr
*vbuf_mgr
;
161 struct util_slab_mempool pool_transfers
;
166 struct pipe_draw_info info
;
167 struct pipe_context
*ctx
;
169 unsigned index_buffer_offset
;
170 struct pipe_resource
*index_buffer
;
173 /* evergreen_state.c */
174 void evergreen_init_state_functions(struct r600_pipe_context
*rctx
);
175 void evergreen_init_config(struct r600_pipe_context
*rctx
);
176 void evergreen_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
177 void evergreen_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
178 void *evergreen_create_db_flush_dsa(struct r600_pipe_context
*rctx
);
179 void evergreen_polygon_offset_update(struct r600_pipe_context
*rctx
);
180 void 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
);
186 void r600_init_blit_functions(struct r600_pipe_context
*rctx
);
187 void r600_blit_uncompress_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
188 void r600_blit_push_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
189 void r600_flush_depth_textures(struct r600_pipe_context
*rctx
);
192 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
193 const struct pipe_resource
*templ
);
194 struct pipe_resource
*r600_user_buffer_create(struct pipe_screen
*screen
,
195 void *ptr
, unsigned bytes
,
197 struct pipe_resource
*r600_buffer_from_handle(struct pipe_screen
*screen
,
198 struct winsys_handle
*whandle
);
199 void r600_upload_index_buffer(struct r600_pipe_context
*rctx
, struct r600_drawl
*draw
);
202 void r600_init_query_functions(struct r600_pipe_context
*rctx
);
204 /* r600_resource.c */
205 void r600_init_context_resource_functions(struct r600_pipe_context
*r600
);
208 int r600_pipe_shader_create(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
, const struct tgsi_token
*tokens
);
209 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
210 int r600_find_vs_semantic_index(struct r600_shader
*vs
,
211 struct r600_shader
*ps
, int id
);
214 void r600_init_state_functions(struct r600_pipe_context
*rctx
);
215 void r600_spi_update(struct r600_pipe_context
*rctx
);
216 void r600_init_config(struct r600_pipe_context
*rctx
);
217 void *r600_create_db_flush_dsa(struct r600_pipe_context
*rctx
);
218 void r600_polygon_offset_update(struct r600_pipe_context
*rctx
);
219 void 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
);
225 int r600_conv_pipe_prim(unsigned pprim
, unsigned *prim
);
228 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
229 void r600_init_surface_functions(struct r600_pipe_context
*r600
);
230 uint32_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
);
233 unsigned r600_texture_get_offset(struct r600_resource_texture
*rtex
,
234 unsigned level
, unsigned layer
);
236 /* r600_translate.c */
237 void r600_translate_index_buffer(struct r600_pipe_context
*r600
,
238 struct pipe_resource
**index_buffer
,
239 unsigned *index_size
,
240 unsigned *start
, unsigned count
);
242 /* r600_state_common.c */
243 void r600_set_index_buffer(struct pipe_context
*ctx
,
244 const struct pipe_index_buffer
*ib
);
245 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
246 const struct pipe_vertex_buffer
*buffers
);
247 void *r600_create_vertex_elements(struct pipe_context
*ctx
,
249 const struct pipe_vertex_element
*elements
);
250 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
);
251 void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
);
252 void r600_bind_rs_state(struct pipe_context
*ctx
, void *state
);
253 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
);
254 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
255 struct pipe_sampler_view
*state
);
256 void r600_bind_state(struct pipe_context
*ctx
, void *state
);
257 void r600_delete_state(struct pipe_context
*ctx
, void *state
);
258 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
);
259 void *r600_create_shader_state(struct pipe_context
*ctx
,
260 const struct pipe_shader_state
*state
);
261 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
);
262 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
);
263 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
);
264 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
);
265 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
266 struct pipe_resource
*buffer
);
267 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
);
272 static INLINE u32
S_FIXED(float value
, u32 frac_bits
)
274 return value
* (1 << frac_bits
);
276 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))