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.
23 #ifndef R600_CONTEXT_H
24 #define R600_CONTEXT_H
27 #include <pipe/p_state.h>
28 #include <pipe/p_context.h>
29 #include <tgsi/tgsi_scan.h>
30 #include <tgsi/tgsi_parse.h>
31 #include <tgsi/tgsi_util.h>
32 #include <util/u_blitter.h>
34 #include "r600_shader.h"
36 /* XXX move this to a more appropriate place */
38 struct pipe_rasterizer_state rasterizer
;
39 struct pipe_poly_stipple poly_stipple
;
40 struct pipe_scissor_state scissor
;
41 struct pipe_clip_state clip
;
42 struct pipe_shader_state shader
;
43 struct pipe_depth_state depth
;
44 struct pipe_stencil_state stencil
;
45 struct pipe_alpha_state alpha
;
46 struct pipe_depth_stencil_alpha_state dsa
;
47 struct pipe_blend_state blend
;
48 struct pipe_blend_color blend_color
;
49 struct pipe_stencil_ref stencil_ref
;
50 struct pipe_framebuffer_state framebuffer
;
51 struct pipe_sampler_state sampler
;
52 struct pipe_sampler_view sampler_view
;
53 struct pipe_viewport_state viewport
;
56 enum pipe_state_type
{
57 pipe_rasterizer_type
= 1,
58 pipe_poly_stipple_type
,
67 pipe_stencil_ref_type
,
68 pipe_framebuffer_type
,
70 pipe_sampler_view_type
,
75 struct r600_context_state
{
76 union pipe_states state
;
79 struct radeon_state
*rstate
;
80 struct r600_shader shader
;
84 struct r600_vertex_element
88 struct pipe_vertex_element elements
[32];
91 struct r600_context_hw_states
{
92 struct radeon_state
*rasterizer
;
93 struct radeon_state
*scissor
;
94 struct radeon_state
*dsa
;
95 struct radeon_state
*blend
;
96 struct radeon_state
*viewport
;
97 struct radeon_state
*cb0
;
98 struct radeon_state
*config
;
99 struct radeon_state
*cb_cntl
;
100 struct radeon_state
*db
;
101 unsigned ps_nresource
;
102 unsigned ps_nsampler
;
103 struct radeon_state
*ps_resource
[160];
104 struct radeon_state
*ps_sampler
[16];
107 struct r600_context
{
108 struct pipe_context context
;
109 struct r600_screen
*screen
;
111 struct radeon_ctx
*ctx
;
112 struct blitter_context
*blitter
;
113 struct radeon_draw
*draw
;
115 struct r600_context_hw_states hw_states
;
117 struct r600_pipe_shader
*ps_shader
;
118 struct r600_pipe_shader
*vs_shader
;
119 unsigned nps_sampler
;
120 struct radeon_state
*ps_sampler
[PIPE_MAX_ATTRIBS
];
123 struct r600_texture_resource
*ps_view
[PIPE_MAX_ATTRIBS
];
124 struct r600_texture_resource
*vs_view
[PIPE_MAX_ATTRIBS
];
126 unsigned nvertex_buffer
;
127 struct r600_vertex_elements_state
*vertex_elements
;
128 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
129 struct pipe_stencil_ref stencil_ref
;
130 struct pipe_framebuffer_state fb_state
;
131 struct pipe_viewport_state viewport
;
135 unsigned ps_nsampler
;
136 unsigned vs_nsampler
;
137 unsigned ps_nsampler_view
;
138 unsigned vs_nsampler_view
;
139 unsigned nvertex_buffer
;
140 struct r600_context_state
*rasterizer
;
141 struct r600_context_state
*poly_stipple
;
142 struct r600_context_state
*scissor
;
143 struct r600_context_state
*clip
;
144 struct r600_context_state
*ps_shader
;
145 struct r600_context_state
*vs_shader
;
146 struct r600_context_state
*depth
;
147 struct r600_context_state
*stencil
;
148 struct r600_context_state
*alpha
;
149 struct r600_context_state
*dsa
;
150 struct r600_context_state
*blend
;
151 struct r600_context_state
*stencil_ref
;
152 struct r600_context_state
*viewport
;
153 struct r600_context_state
*framebuffer
;
154 struct r600_context_state
*ps_sampler
[PIPE_MAX_ATTRIBS
];
155 struct r600_context_state
*vs_sampler
[PIPE_MAX_ATTRIBS
];
156 struct r600_context_state
*ps_sampler_view
[PIPE_MAX_ATTRIBS
];
157 struct r600_context_state
*vs_sampler_view
[PIPE_MAX_ATTRIBS
];
158 struct r600_vertex_element
*vertex_elements
;
159 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
160 struct pipe_index_buffer index_buffer
;
161 struct pipe_blend_color blend_color
;
165 struct r600_vertex_elements_state
168 struct pipe_vertex_element elements
[32];
171 struct r600_pipe_shader
{
172 struct r600_shader shader
;
173 struct radeon_bo
*bo
;
174 struct radeon_state
*state
;
177 struct r600_texture_resource
{
178 struct pipe_sampler_view view
;
179 struct radeon_state
*state
;
183 /* Convenience cast wrapper. */
184 static INLINE
struct r600_context
*r600_context(struct pipe_context
*pipe
)
186 return (struct r600_context
*)pipe
;
189 struct r600_context_state
*r600_context_state(struct r600_context
*rctx
, unsigned type
, const void *state
);
190 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
);
191 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
);
193 int r600_context_hw_states(struct r600_context
*rctx
);
195 void r600_draw_vbo(struct pipe_context
*ctx
,
196 const struct pipe_draw_info
*info
);
198 void r600_init_blit_functions(struct r600_context
*rctx
);
199 void r600_init_state_functions(struct r600_context
*rctx
);
200 void r600_init_query_functions(struct r600_context
* rctx
);
201 struct pipe_context
*r600_create_context(struct pipe_screen
*screen
, void *priv
);
203 int r600_pipe_shader_create(struct pipe_context
*ctx
,
204 struct r600_context_state
*rstate
,
205 const struct tgsi_token
*tokens
);
206 int r600_pipe_shader_update(struct pipe_context
*ctx
,
207 struct r600_context_state
*rstate
);
209 #define R600_ERR(fmt, args...) \
210 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)