gallium: Remove bypass_vs_clip_and_viewport from rasteriser state.
[mesa.git] / src / gallium / drivers / softpipe / sp_video_context.c
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "sp_video_context.h"
29 #include <util/u_inlines.h>
30 #include <util/u_memory.h>
31 #include "softpipe/sp_texture.h"
32
33 static void
34 sp_mpeg12_destroy(struct pipe_video_context *vpipe)
35 {
36 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
37
38 assert(vpipe);
39
40 /* Asserted in softpipe_delete_fs_state() for some reason */
41 ctx->pipe->bind_vs_state(ctx->pipe, NULL);
42 ctx->pipe->bind_fs_state(ctx->pipe, NULL);
43
44 ctx->pipe->delete_blend_state(ctx->pipe, ctx->blend);
45 ctx->pipe->delete_rasterizer_state(ctx->pipe, ctx->rast);
46 ctx->pipe->delete_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
47
48 pipe_video_surface_reference(&ctx->decode_target, NULL);
49 vl_compositor_cleanup(&ctx->compositor);
50 vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
51 ctx->pipe->destroy(ctx->pipe);
52
53 FREE(ctx);
54 }
55
56 static void
57 sp_mpeg12_decode_macroblocks(struct pipe_video_context *vpipe,
58 struct pipe_video_surface *past,
59 struct pipe_video_surface *future,
60 unsigned num_macroblocks,
61 struct pipe_macroblock *macroblocks,
62 struct pipe_fence_handle **fence)
63 {
64 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
65 struct pipe_mpeg12_macroblock *mpeg12_macroblocks = (struct pipe_mpeg12_macroblock*)macroblocks;
66
67 assert(vpipe);
68 assert(num_macroblocks);
69 assert(macroblocks);
70 assert(macroblocks->codec == PIPE_VIDEO_CODEC_MPEG12);
71 assert(ctx->decode_target);
72
73 vl_mpeg12_mc_renderer_render_macroblocks(&ctx->mc_renderer,
74 softpipe_video_surface(ctx->decode_target)->tex,
75 past ? softpipe_video_surface(past)->tex : NULL,
76 future ? softpipe_video_surface(future)->tex : NULL,
77 num_macroblocks, mpeg12_macroblocks, fence);
78 }
79
80 static void
81 sp_mpeg12_clear_surface(struct pipe_video_context *vpipe,
82 unsigned x, unsigned y,
83 unsigned width, unsigned height,
84 unsigned value,
85 struct pipe_surface *surface)
86 {
87 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
88
89 assert(vpipe);
90 assert(surface);
91
92 ctx->pipe->surface_fill(ctx->pipe, surface, x, y, width, height, value);
93 }
94
95 static void
96 sp_mpeg12_render_picture(struct pipe_video_context *vpipe,
97 /*struct pipe_surface *backround,
98 struct pipe_video_rect *backround_area,*/
99 struct pipe_video_surface *src_surface,
100 enum pipe_mpeg12_picture_type picture_type,
101 /*unsigned num_past_surfaces,
102 struct pipe_video_surface *past_surfaces,
103 unsigned num_future_surfaces,
104 struct pipe_video_surface *future_surfaces,*/
105 struct pipe_video_rect *src_area,
106 struct pipe_surface *dst_surface,
107 struct pipe_video_rect *dst_area,
108 /*unsigned num_layers,
109 struct pipe_surface *layers,
110 struct pipe_video_rect *layer_src_areas,
111 struct pipe_video_rect *layer_dst_areas*/
112 struct pipe_fence_handle **fence)
113 {
114 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
115
116 assert(vpipe);
117 assert(src_surface);
118 assert(src_area);
119 assert(dst_surface);
120 assert(dst_area);
121
122 vl_compositor_render(&ctx->compositor, softpipe_video_surface(src_surface)->tex,
123 picture_type, src_area, dst_surface->texture, dst_area, fence);
124 }
125
126 static void
127 sp_mpeg12_set_decode_target(struct pipe_video_context *vpipe,
128 struct pipe_video_surface *dt)
129 {
130 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
131
132 assert(vpipe);
133 assert(dt);
134
135 pipe_video_surface_reference(&ctx->decode_target, dt);
136 }
137
138 static void sp_mpeg12_set_csc_matrix(struct pipe_video_context *vpipe, const float *mat)
139 {
140 struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
141
142 assert(vpipe);
143
144 vl_compositor_set_csc_matrix(&ctx->compositor, mat);
145 }
146
147 static bool
148 init_pipe_state(struct sp_mpeg12_context *ctx)
149 {
150 struct pipe_rasterizer_state rast;
151 struct pipe_blend_state blend;
152 struct pipe_depth_stencil_alpha_state dsa;
153 unsigned i;
154
155 assert(ctx);
156
157 rast.flatshade = 1;
158 rast.flatshade_first = 0;
159 rast.light_twoside = 0;
160 rast.front_winding = PIPE_WINDING_CCW;
161 rast.cull_mode = PIPE_WINDING_CW;
162 rast.fill_cw = PIPE_POLYGON_MODE_FILL;
163 rast.fill_ccw = PIPE_POLYGON_MODE_FILL;
164 rast.offset_cw = 0;
165 rast.offset_ccw = 0;
166 rast.scissor = 0;
167 rast.poly_smooth = 0;
168 rast.poly_stipple_enable = 0;
169 rast.sprite_coord_enable = 0;
170 rast.point_size_per_vertex = 0;
171 rast.multisample = 0;
172 rast.line_smooth = 0;
173 rast.line_stipple_enable = 0;
174 rast.line_stipple_factor = 0;
175 rast.line_stipple_pattern = 0;
176 rast.line_last_pixel = 0;
177 rast.line_width = 1;
178 rast.point_smooth = 0;
179 rast.point_quad_rasterization = 0;
180 rast.point_size = 1;
181 rast.offset_units = 1;
182 rast.offset_scale = 1;
183 ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
184 ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
185
186 blend.independent_blend_enable = 0;
187 blend.rt[0].blend_enable = 0;
188 blend.rt[0].rgb_func = PIPE_BLEND_ADD;
189 blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
190 blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
191 blend.rt[0].alpha_func = PIPE_BLEND_ADD;
192 blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
193 blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
194 blend.logicop_enable = 0;
195 blend.logicop_func = PIPE_LOGICOP_CLEAR;
196 /* Needed to allow color writes to FB, even if blending disabled */
197 blend.rt[0].colormask = PIPE_MASK_RGBA;
198 blend.dither = 0;
199 ctx->blend = ctx->pipe->create_blend_state(ctx->pipe, &blend);
200 ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend);
201
202 dsa.depth.enabled = 0;
203 dsa.depth.writemask = 0;
204 dsa.depth.func = PIPE_FUNC_ALWAYS;
205 for (i = 0; i < 2; ++i) {
206 dsa.stencil[i].enabled = 0;
207 dsa.stencil[i].func = PIPE_FUNC_ALWAYS;
208 dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP;
209 dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP;
210 dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP;
211 dsa.stencil[i].valuemask = 0;
212 dsa.stencil[i].writemask = 0;
213 }
214 dsa.alpha.enabled = 0;
215 dsa.alpha.func = PIPE_FUNC_ALWAYS;
216 dsa.alpha.ref_value = 0;
217 ctx->dsa = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &dsa);
218 ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
219
220 return true;
221 }
222
223 static struct pipe_video_context *
224 sp_mpeg12_create(struct pipe_screen *screen, enum pipe_video_profile profile,
225 enum pipe_video_chroma_format chroma_format,
226 unsigned width, unsigned height)
227 {
228 struct sp_mpeg12_context *ctx;
229
230 assert(u_reduce_video_profile(profile) == PIPE_VIDEO_CODEC_MPEG12);
231
232 ctx = CALLOC_STRUCT(sp_mpeg12_context);
233
234 if (!ctx)
235 return NULL;
236
237 ctx->base.profile = profile;
238 ctx->base.chroma_format = chroma_format;
239 ctx->base.width = width;
240 ctx->base.height = height;
241
242 ctx->base.screen = screen;
243 ctx->base.destroy = sp_mpeg12_destroy;
244 ctx->base.decode_macroblocks = sp_mpeg12_decode_macroblocks;
245 ctx->base.clear_surface = sp_mpeg12_clear_surface;
246 ctx->base.render_picture = sp_mpeg12_render_picture;
247 ctx->base.set_decode_target = sp_mpeg12_set_decode_target;
248 ctx->base.set_csc_matrix = sp_mpeg12_set_csc_matrix;
249
250 ctx->pipe = screen->context_create(screen, NULL);
251 if (!ctx->pipe) {
252 FREE(ctx);
253 return NULL;
254 }
255
256 /* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture */
257 if (!vl_mpeg12_mc_renderer_init(&ctx->mc_renderer, ctx->pipe,
258 width, height, chroma_format,
259 VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
260 /* TODO: Use XFER_NONE when implemented */
261 VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE,
262 true)) {
263 ctx->pipe->destroy(ctx->pipe);
264 FREE(ctx);
265 return NULL;
266 }
267
268 if (!vl_compositor_init(&ctx->compositor, ctx->pipe)) {
269 vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
270 ctx->pipe->destroy(ctx->pipe);
271 FREE(ctx);
272 return NULL;
273 }
274
275 if (!init_pipe_state(ctx)) {
276 vl_compositor_cleanup(&ctx->compositor);
277 vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
278 ctx->pipe->destroy(ctx->pipe);
279 FREE(ctx);
280 return NULL;
281 }
282
283 return &ctx->base;
284 }
285
286 struct pipe_video_context *
287 sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
288 enum pipe_video_chroma_format chroma_format,
289 unsigned width, unsigned height)
290 {
291 assert(screen);
292 assert(width && height);
293
294 switch (u_reduce_video_profile(profile)) {
295 case PIPE_VIDEO_CODEC_MPEG12:
296 return sp_mpeg12_create(screen, profile,
297 chroma_format,
298 width, height);
299 default:
300 return NULL;
301 }
302 }