Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. |
||
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 | |||
29 | #include "main/enums.h" |
||
30 | #include "main/imports.h" |
||
31 | #include "main/macros.h" |
||
32 | #include "main/mtypes.h" |
||
33 | #include "main/fbobject.h" |
||
34 | #include "main/framebuffer.h" |
||
35 | #include "main/renderbuffer.h" |
||
36 | #include "main/context.h" |
||
37 | #include "main/teximage.h" |
||
38 | #include "main/image.h" |
||
39 | |||
40 | #include "swrast/swrast.h" |
||
41 | #include "drivers/common/meta.h" |
||
42 | |||
43 | #include "intel_context.h" |
||
44 | #include "intel_batchbuffer.h" |
||
45 | #include "intel_buffers.h" |
||
46 | #include "intel_blit.h" |
||
47 | #include "intel_fbo.h" |
||
48 | #include "intel_mipmap_tree.h" |
||
49 | #include "intel_regions.h" |
||
50 | #include "intel_tex.h" |
||
51 | |||
52 | #define FILE_DEBUG_FLAG DEBUG_FBO |
||
53 | |||
54 | static struct gl_renderbuffer * |
||
55 | intel_new_renderbuffer(struct gl_context * ctx, GLuint name); |
||
56 | |||
57 | struct intel_region* |
||
58 | intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex) |
||
59 | { |
||
60 | struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, attIndex); |
||
61 | if (irb && irb->mt) |
||
62 | return irb->mt->region; |
||
63 | else |
||
64 | return NULL; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Create a new framebuffer object. |
||
69 | */ |
||
70 | static struct gl_framebuffer * |
||
71 | intel_new_framebuffer(struct gl_context * ctx, GLuint name) |
||
72 | { |
||
73 | /* Only drawable state in intel_framebuffer at this time, just use Mesa's |
||
74 | * class |
||
75 | */ |
||
76 | return _mesa_new_framebuffer(ctx, name); |
||
77 | } |
||
78 | |||
79 | |||
80 | /** Called by gl_renderbuffer::Delete() */ |
||
81 | static void |
||
82 | intel_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) |
||
83 | { |
||
84 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
85 | |||
86 | ASSERT(irb); |
||
87 | |||
88 | intel_miptree_release(&irb->mt); |
||
89 | |||
90 | _mesa_delete_renderbuffer(ctx, rb); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * \see dd_function_table::MapRenderbuffer |
||
95 | */ |
||
96 | static void |
||
97 | intel_map_renderbuffer(struct gl_context *ctx, |
||
98 | struct gl_renderbuffer *rb, |
||
99 | GLuint x, GLuint y, GLuint w, GLuint h, |
||
100 | GLbitfield mode, |
||
101 | GLubyte **out_map, |
||
102 | GLint *out_stride) |
||
103 | { |
||
104 | struct intel_context *intel = intel_context(ctx); |
||
105 | struct swrast_renderbuffer *srb = (struct swrast_renderbuffer *)rb; |
||
106 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
107 | void *map; |
||
108 | int stride; |
||
109 | |||
110 | if (srb->Buffer) { |
||
111 | /* this is a malloc'd renderbuffer (accum buffer), not an irb */ |
||
112 | GLint bpp = _mesa_get_format_bytes(rb->Format); |
||
113 | GLint rowStride = srb->RowStride; |
||
114 | *out_map = (GLubyte *) srb->Buffer + y * rowStride + x * bpp; |
||
115 | *out_stride = rowStride; |
||
116 | return; |
||
117 | } |
||
118 | |||
119 | intel_prepare_render(intel); |
||
120 | |||
121 | /* For a window-system renderbuffer, we need to flip the mapping we receive |
||
122 | * upside-down. So we need to ask for a rectangle on flipped vertically, and |
||
123 | * we then return a pointer to the bottom of it with a negative stride. |
||
124 | */ |
||
125 | if (rb->Name == 0) { |
||
126 | y = rb->Height - y - h; |
||
127 | } |
||
128 | |||
129 | intel_miptree_map(intel, irb->mt, irb->mt_level, irb->mt_layer, |
||
130 | x, y, w, h, mode, &map, &stride); |
||
131 | |||
132 | if (rb->Name == 0) { |
||
133 | map += (h - 1) * stride; |
||
134 | stride = -stride; |
||
135 | } |
||
136 | |||
137 | DBG("%s: rb %d (%s) mt mapped: (%d, %d) (%dx%d) -> %p/%d\n", |
||
138 | __FUNCTION__, rb->Name, _mesa_get_format_name(rb->Format), |
||
139 | x, y, w, h, map, stride); |
||
140 | |||
141 | *out_map = map; |
||
142 | *out_stride = stride; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * \see dd_function_table::UnmapRenderbuffer |
||
147 | */ |
||
148 | static void |
||
149 | intel_unmap_renderbuffer(struct gl_context *ctx, |
||
150 | struct gl_renderbuffer *rb) |
||
151 | { |
||
152 | struct intel_context *intel = intel_context(ctx); |
||
153 | struct swrast_renderbuffer *srb = (struct swrast_renderbuffer *)rb; |
||
154 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
155 | |||
156 | DBG("%s: rb %d (%s)\n", __FUNCTION__, |
||
157 | rb->Name, _mesa_get_format_name(rb->Format)); |
||
158 | |||
159 | if (srb->Buffer) { |
||
160 | /* this is a malloc'd renderbuffer (accum buffer) */ |
||
161 | /* nothing to do */ |
||
162 | return; |
||
163 | } |
||
164 | |||
165 | intel_miptree_unmap(intel, irb->mt, irb->mt_level, irb->mt_layer); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Called via glRenderbufferStorageEXT() to set the format and allocate |
||
170 | * storage for a user-created renderbuffer. |
||
171 | */ |
||
172 | static GLboolean |
||
173 | intel_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffer *rb, |
||
174 | GLenum internalFormat, |
||
175 | GLuint width, GLuint height) |
||
176 | { |
||
177 | struct intel_context *intel = intel_context(ctx); |
||
178 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
179 | |||
180 | switch (internalFormat) { |
||
181 | default: |
||
182 | /* Use the same format-choice logic as for textures. |
||
183 | * Renderbuffers aren't any different from textures for us, |
||
184 | * except they're less useful because you can't texture with |
||
185 | * them. |
||
186 | */ |
||
187 | rb->Format = intel->ctx.Driver.ChooseTextureFormat(ctx, GL_TEXTURE_2D, |
||
188 | internalFormat, |
||
189 | GL_NONE, GL_NONE); |
||
190 | break; |
||
191 | case GL_STENCIL_INDEX: |
||
192 | case GL_STENCIL_INDEX1_EXT: |
||
193 | case GL_STENCIL_INDEX4_EXT: |
||
194 | case GL_STENCIL_INDEX8_EXT: |
||
195 | case GL_STENCIL_INDEX16_EXT: |
||
196 | /* These aren't actual texture formats, so force them here. */ |
||
197 | rb->Format = MESA_FORMAT_S8_Z24; |
||
198 | break; |
||
199 | } |
||
200 | |||
201 | rb->Width = width; |
||
202 | rb->Height = height; |
||
203 | rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat); |
||
204 | |||
205 | intel_miptree_release(&irb->mt); |
||
206 | |||
207 | DBG("%s: %s: %s (%dx%d)\n", __FUNCTION__, |
||
208 | _mesa_lookup_enum_by_nr(internalFormat), |
||
209 | _mesa_get_format_name(rb->Format), width, height); |
||
210 | |||
211 | if (width == 0 || height == 0) |
||
212 | return true; |
||
213 | |||
214 | irb->mt = intel_miptree_create_for_renderbuffer(intel, rb->Format, |
||
215 | width, height); |
||
216 | if (!irb->mt) |
||
217 | return false; |
||
218 | |||
219 | return true; |
||
220 | } |
||
221 | |||
222 | |||
223 | static void |
||
224 | intel_image_target_renderbuffer_storage(struct gl_context *ctx, |
||
225 | struct gl_renderbuffer *rb, |
||
226 | void *image_handle) |
||
227 | { |
||
228 | struct intel_context *intel = intel_context(ctx); |
||
229 | struct intel_renderbuffer *irb; |
||
230 | __DRIscreen *screen; |
||
231 | __DRIimage *image; |
||
232 | |||
233 | screen = intel->intelScreen->driScrnPriv; |
||
234 | image = screen->dri2.image->lookupEGLImage(screen, image_handle, |
||
235 | screen->loaderPrivate); |
||
236 | if (image == NULL) |
||
237 | return; |
||
238 | |||
239 | /* __DRIimage is opaque to the core so it has to be checked here */ |
||
240 | switch (image->format) { |
||
241 | case MESA_FORMAT_RGBA8888_REV: |
||
242 | _mesa_error(&intel->ctx, GL_INVALID_OPERATION, |
||
243 | "glEGLImageTargetRenderbufferStorage(unsupported image format"); |
||
244 | return; |
||
245 | break; |
||
246 | default: |
||
247 | break; |
||
248 | } |
||
249 | |||
250 | irb = intel_renderbuffer(rb); |
||
251 | intel_miptree_release(&irb->mt); |
||
252 | irb->mt = intel_miptree_create_for_bo(intel, |
||
253 | image->region->bo, |
||
254 | image->format, |
||
255 | image->offset, |
||
256 | image->region->width, |
||
257 | image->region->height, |
||
258 | image->region->pitch, |
||
259 | image->region->tiling); |
||
260 | if (!irb->mt) |
||
261 | return; |
||
262 | |||
263 | rb->InternalFormat = image->internal_format; |
||
264 | rb->Width = image->region->width; |
||
265 | rb->Height = image->region->height; |
||
266 | rb->Format = image->format; |
||
267 | rb->_BaseFormat = _mesa_base_fbo_format(&intel->ctx, |
||
268 | image->internal_format); |
||
269 | rb->NeedsFinishRenderTexture = true; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Called by _mesa_resize_framebuffer() for each hardware renderbuffer when a |
||
274 | * window system framebuffer is resized. |
||
275 | * |
||
276 | * Any actual buffer reallocations for hardware renderbuffers (which would |
||
277 | * have triggered _mesa_resize_framebuffer()) were done by |
||
278 | * intel_process_dri2_buffer(). |
||
279 | */ |
||
280 | static GLboolean |
||
281 | intel_alloc_window_storage(struct gl_context * ctx, struct gl_renderbuffer *rb, |
||
282 | GLenum internalFormat, GLuint width, GLuint height) |
||
283 | { |
||
284 | ASSERT(rb->Name == 0); |
||
285 | rb->Width = width; |
||
286 | rb->Height = height; |
||
287 | rb->InternalFormat = internalFormat; |
||
288 | |||
289 | return true; |
||
290 | } |
||
291 | |||
292 | /** Dummy function for gl_renderbuffer::AllocStorage() */ |
||
293 | static GLboolean |
||
294 | intel_nop_alloc_storage(struct gl_context * ctx, struct gl_renderbuffer *rb, |
||
295 | GLenum internalFormat, GLuint width, GLuint height) |
||
296 | { |
||
297 | _mesa_problem(ctx, "intel_op_alloc_storage should never be called."); |
||
298 | return false; |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * Create a new intel_renderbuffer which corresponds to an on-screen window, |
||
303 | * not a user-created renderbuffer. |
||
304 | */ |
||
305 | struct intel_renderbuffer * |
||
306 | intel_create_renderbuffer(gl_format format) |
||
307 | { |
||
308 | struct intel_renderbuffer *irb; |
||
309 | struct gl_renderbuffer *rb; |
||
310 | |||
311 | GET_CURRENT_CONTEXT(ctx); |
||
312 | |||
313 | irb = CALLOC_STRUCT(intel_renderbuffer); |
||
314 | if (!irb) { |
||
315 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer"); |
||
316 | return NULL; |
||
317 | } |
||
318 | |||
319 | rb = &irb->Base.Base; |
||
320 | |||
321 | _mesa_init_renderbuffer(rb, 0); |
||
322 | rb->ClassID = INTEL_RB_CLASS; |
||
323 | rb->_BaseFormat = _mesa_get_format_base_format(format); |
||
324 | rb->Format = format; |
||
325 | rb->InternalFormat = rb->_BaseFormat; |
||
326 | |||
327 | /* intel-specific methods */ |
||
328 | rb->Delete = intel_delete_renderbuffer; |
||
329 | rb->AllocStorage = intel_alloc_window_storage; |
||
330 | |||
331 | return irb; |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Private window-system buffers (as opposed to ones shared with the display |
||
336 | * server created with intel_create_renderbuffer()) are most similar in their |
||
337 | * handling to user-created renderbuffers, but they have a resize handler that |
||
338 | * may be called at intel_update_renderbuffers() time. |
||
339 | */ |
||
340 | struct intel_renderbuffer * |
||
341 | intel_create_private_renderbuffer(gl_format format) |
||
342 | { |
||
343 | struct intel_renderbuffer *irb; |
||
344 | |||
345 | irb = intel_create_renderbuffer(format); |
||
346 | irb->Base.Base.AllocStorage = intel_alloc_renderbuffer_storage; |
||
347 | |||
348 | return irb; |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * Create a new renderbuffer object. |
||
353 | * Typically called via glBindRenderbufferEXT(). |
||
354 | */ |
||
355 | static struct gl_renderbuffer * |
||
356 | intel_new_renderbuffer(struct gl_context * ctx, GLuint name) |
||
357 | { |
||
358 | /*struct intel_context *intel = intel_context(ctx); */ |
||
359 | struct intel_renderbuffer *irb; |
||
360 | struct gl_renderbuffer *rb; |
||
361 | |||
362 | irb = CALLOC_STRUCT(intel_renderbuffer); |
||
363 | if (!irb) { |
||
364 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer"); |
||
365 | return NULL; |
||
366 | } |
||
367 | |||
368 | rb = &irb->Base.Base; |
||
369 | |||
370 | _mesa_init_renderbuffer(rb, name); |
||
371 | rb->ClassID = INTEL_RB_CLASS; |
||
372 | |||
373 | /* intel-specific methods */ |
||
374 | rb->Delete = intel_delete_renderbuffer; |
||
375 | rb->AllocStorage = intel_alloc_renderbuffer_storage; |
||
376 | /* span routines set in alloc_storage function */ |
||
377 | |||
378 | return rb; |
||
379 | } |
||
380 | |||
381 | |||
382 | /** |
||
383 | * Called via glBindFramebufferEXT(). |
||
384 | */ |
||
385 | static void |
||
386 | intel_bind_framebuffer(struct gl_context * ctx, GLenum target, |
||
387 | struct gl_framebuffer *fb, struct gl_framebuffer *fbread) |
||
388 | { |
||
389 | if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) { |
||
390 | intel_draw_buffer(ctx); |
||
391 | } |
||
392 | else { |
||
393 | /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */ |
||
394 | } |
||
395 | } |
||
396 | |||
397 | |||
398 | /** |
||
399 | * Called via glFramebufferRenderbufferEXT(). |
||
400 | */ |
||
401 | static void |
||
402 | intel_framebuffer_renderbuffer(struct gl_context * ctx, |
||
403 | struct gl_framebuffer *fb, |
||
404 | GLenum attachment, struct gl_renderbuffer *rb) |
||
405 | { |
||
406 | DBG("Intel FramebufferRenderbuffer %u %u\n", fb->Name, rb ? rb->Name : 0); |
||
407 | |||
408 | _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); |
||
409 | intel_draw_buffer(ctx); |
||
410 | } |
||
411 | |||
412 | static bool |
||
413 | intel_renderbuffer_update_wrapper(struct intel_context *intel, |
||
414 | struct intel_renderbuffer *irb, |
||
415 | struct gl_texture_image *image, |
||
416 | uint32_t layer) |
||
417 | { |
||
418 | struct gl_renderbuffer *rb = &irb->Base.Base; |
||
419 | struct intel_texture_image *intel_image = intel_texture_image(image); |
||
420 | struct intel_mipmap_tree *mt = intel_image->mt; |
||
421 | int level = image->Level; |
||
422 | |||
423 | rb->Depth = image->Depth; |
||
424 | |||
425 | rb->AllocStorage = intel_nop_alloc_storage; |
||
426 | |||
427 | intel_miptree_check_level_layer(mt, level, layer); |
||
428 | irb->mt_level = level; |
||
429 | irb->mt_layer = layer; |
||
430 | |||
431 | intel_miptree_reference(&irb->mt, mt); |
||
432 | |||
433 | intel_renderbuffer_set_draw_offset(irb); |
||
434 | |||
435 | return true; |
||
436 | } |
||
437 | |||
438 | void |
||
439 | intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb) |
||
440 | { |
||
441 | unsigned int dst_x, dst_y; |
||
442 | |||
443 | /* compute offset of the particular 2D image within the texture region */ |
||
444 | intel_miptree_get_image_offset(irb->mt, |
||
445 | irb->mt_level, |
||
446 | irb->mt_layer, |
||
447 | &dst_x, &dst_y); |
||
448 | |||
449 | irb->draw_x = dst_x; |
||
450 | irb->draw_y = dst_y; |
||
451 | } |
||
452 | |||
453 | /** |
||
454 | * Called by glFramebufferTexture[123]DEXT() (and other places) to |
||
455 | * prepare for rendering into texture memory. This might be called |
||
456 | * many times to choose different texture levels, cube faces, etc |
||
457 | * before intel_finish_render_texture() is ever called. |
||
458 | */ |
||
459 | static void |
||
460 | intel_render_texture(struct gl_context * ctx, |
||
461 | struct gl_framebuffer *fb, |
||
462 | struct gl_renderbuffer_attachment *att) |
||
463 | { |
||
464 | struct intel_context *intel = intel_context(ctx); |
||
465 | struct gl_renderbuffer *rb = att->Renderbuffer; |
||
466 | struct intel_renderbuffer *irb = intel_renderbuffer(rb); |
||
467 | struct gl_texture_image *image = rb->TexImage; |
||
468 | struct intel_texture_image *intel_image = intel_texture_image(image); |
||
469 | struct intel_mipmap_tree *mt = intel_image->mt; |
||
470 | int layer; |
||
471 | |||
472 | (void) fb; |
||
473 | |||
474 | if (att->CubeMapFace > 0) { |
||
475 | assert(att->Zoffset == 0); |
||
476 | layer = att->CubeMapFace; |
||
477 | } else { |
||
478 | layer = att->Zoffset; |
||
479 | } |
||
480 | |||
481 | if (!intel_image->mt) { |
||
482 | /* Fallback on drawing to a texture that doesn't have a miptree |
||
483 | * (has a border, width/height 0, etc.) |
||
484 | */ |
||
485 | _swrast_render_texture(ctx, fb, att); |
||
486 | return; |
||
487 | } |
||
488 | |||
489 | intel_miptree_check_level_layer(mt, att->TextureLevel, layer); |
||
490 | |||
491 | if (!intel_renderbuffer_update_wrapper(intel, irb, image, layer)) { |
||
492 | _swrast_render_texture(ctx, fb, att); |
||
493 | return; |
||
494 | } |
||
495 | |||
496 | DBG("Begin render %s texture tex=%u w=%d h=%d d=%d refcount=%d\n", |
||
497 | _mesa_get_format_name(image->TexFormat), |
||
498 | att->Texture->Name, image->Width, image->Height, image->Depth, |
||
499 | rb->RefCount); |
||
500 | |||
501 | /* update drawing region, etc */ |
||
502 | intel_draw_buffer(ctx); |
||
503 | } |
||
504 | |||
505 | |||
506 | /** |
||
507 | * Called by Mesa when rendering to a texture is done. |
||
508 | */ |
||
509 | static void |
||
510 | intel_finish_render_texture(struct gl_context * ctx, struct gl_renderbuffer *rb) |
||
511 | { |
||
512 | struct intel_context *intel = intel_context(ctx); |
||
513 | |||
514 | DBG("Finish render %s texture\n", _mesa_get_format_name(rb->Format)); |
||
515 | |||
516 | /* Since we've (probably) rendered to the texture and will (likely) use |
||
517 | * it in the texture domain later on in this batchbuffer, flush the |
||
518 | * batch. Once again, we wish for a domain tracker in libdrm to cover |
||
519 | * usage inside of a batchbuffer like GEM does in the kernel. |
||
520 | */ |
||
521 | intel_batchbuffer_emit_mi_flush(intel); |
||
522 | } |
||
523 | |||
524 | #define fbo_incomplete(fb, ...) do { \ |
||
525 | static GLuint msg_id = 0; \ |
||
526 | if (unlikely(ctx->Const.ContextFlags & GL_CONTEXT_FLAG_DEBUG_BIT)) { \ |
||
527 | _mesa_gl_debug(ctx, &msg_id, \ |
||
528 | MESA_DEBUG_TYPE_OTHER, \ |
||
529 | MESA_DEBUG_SEVERITY_MEDIUM, \ |
||
530 | __VA_ARGS__); \ |
||
531 | } \ |
||
532 | DBG(__VA_ARGS__); \ |
||
533 | fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED; \ |
||
534 | } while (0) |
||
535 | |||
536 | /** |
||
537 | * Do additional "completeness" testing of a framebuffer object. |
||
538 | */ |
||
539 | static void |
||
540 | intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) |
||
541 | { |
||
542 | struct intel_context *intel = intel_context(ctx); |
||
543 | struct intel_renderbuffer *depthRb = |
||
544 | intel_get_renderbuffer(fb, BUFFER_DEPTH); |
||
545 | struct intel_renderbuffer *stencilRb = |
||
546 | intel_get_renderbuffer(fb, BUFFER_STENCIL); |
||
547 | struct intel_mipmap_tree *depth_mt = NULL, *stencil_mt = NULL; |
||
548 | int i; |
||
549 | |||
550 | DBG("%s() on fb %p (%s)\n", __FUNCTION__, |
||
551 | fb, (fb == ctx->DrawBuffer ? "drawbuffer" : |
||
552 | (fb == ctx->ReadBuffer ? "readbuffer" : "other buffer"))); |
||
553 | |||
554 | if (depthRb) |
||
555 | depth_mt = depthRb->mt; |
||
556 | if (stencilRb) |
||
557 | stencil_mt = stencilRb->mt; |
||
558 | |||
559 | if (depth_mt && stencil_mt) { |
||
560 | /* Make sure that the depth and stencil buffers are actually the same |
||
561 | * slice of the same miptree, since we only support packed |
||
562 | * depth/stencil. |
||
563 | */ |
||
564 | if (depth_mt == stencil_mt) { |
||
565 | if (depthRb->mt_level != stencilRb->mt_level || |
||
566 | depthRb->mt_layer != stencilRb->mt_layer) { |
||
567 | fbo_incomplete(fb, |
||
568 | "FBO incomplete: depth image level/layer %d/%d != " |
||
569 | "stencil image %d/%d\n", |
||
570 | depthRb->mt_level, |
||
571 | depthRb->mt_layer, |
||
572 | stencilRb->mt_level, |
||
573 | stencilRb->mt_layer); |
||
574 | } |
||
575 | } else { |
||
576 | fbo_incomplete(fb, "FBO incomplete: separate stencil unsupported\n"); |
||
577 | } |
||
578 | } |
||
579 | |||
580 | for (i = 0; i < Elements(fb->Attachment); i++) { |
||
581 | struct gl_renderbuffer *rb; |
||
582 | struct intel_renderbuffer *irb; |
||
583 | |||
584 | if (fb->Attachment[i].Type == GL_NONE) |
||
585 | continue; |
||
586 | |||
587 | /* A supported attachment will have a Renderbuffer set either |
||
588 | * from being a Renderbuffer or being a texture that got the |
||
589 | * intel_wrap_texture() treatment. |
||
590 | */ |
||
591 | rb = fb->Attachment[i].Renderbuffer; |
||
592 | if (rb == NULL) { |
||
593 | fbo_incomplete(fb, "FBO incomplete: attachment without " |
||
594 | "renderbuffer\n"); |
||
595 | continue; |
||
596 | } |
||
597 | |||
598 | if (fb->Attachment[i].Type == GL_TEXTURE) { |
||
599 | if (rb->TexImage->Border) { |
||
600 | fbo_incomplete(fb, "FBO incomplete: texture with border\n"); |
||
601 | continue; |
||
602 | } |
||
603 | } |
||
604 | |||
605 | irb = intel_renderbuffer(rb); |
||
606 | if (irb == NULL) { |
||
607 | fbo_incomplete(fb, "FBO incomplete: software rendering " |
||
608 | "renderbuffer\n"); |
||
609 | continue; |
||
610 | } |
||
611 | |||
612 | if (!intel->vtbl.render_target_supported(intel, rb)) { |
||
613 | fbo_incomplete(fb, "FBO incomplete: Unsupported HW " |
||
614 | "texture/renderbuffer format attached: %s\n", |
||
615 | _mesa_get_format_name(intel_rb_format(irb))); |
||
616 | } |
||
617 | } |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * Try to do a glBlitFramebuffer using glCopyTexSubImage2D |
||
622 | * We can do this when the dst renderbuffer is actually a texture and |
||
623 | * there is no scaling, mirroring or scissoring. |
||
624 | * |
||
625 | * \return new buffer mask indicating the buffers left to blit using the |
||
626 | * normal path. |
||
627 | */ |
||
628 | static GLbitfield |
||
629 | intel_blit_framebuffer_with_blitter(struct gl_context *ctx, |
||
630 | GLint srcX0, GLint srcY0, |
||
631 | GLint srcX1, GLint srcY1, |
||
632 | GLint dstX0, GLint dstY0, |
||
633 | GLint dstX1, GLint dstY1, |
||
634 | GLbitfield mask, GLenum filter) |
||
635 | { |
||
636 | struct intel_context *intel = intel_context(ctx); |
||
637 | |||
638 | if (mask & GL_COLOR_BUFFER_BIT) { |
||
639 | GLint i; |
||
640 | const struct gl_framebuffer *drawFb = ctx->DrawBuffer; |
||
641 | const struct gl_framebuffer *readFb = ctx->ReadBuffer; |
||
642 | struct gl_renderbuffer *src_rb = readFb->_ColorReadBuffer; |
||
643 | struct intel_renderbuffer *src_irb = intel_renderbuffer(src_rb); |
||
644 | |||
645 | if (!src_irb) { |
||
646 | perf_debug("glBlitFramebuffer(): missing src renderbuffer. " |
||
647 | "Falling back to software rendering.\n"); |
||
648 | return mask; |
||
649 | } |
||
650 | |||
651 | /* If the source and destination are the same size with no mirroring, |
||
652 | * the rectangles are within the size of the texture and there is no |
||
653 | * scissor, then we can probably use the blit engine. |
||
654 | */ |
||
655 | if (!(srcX0 - srcX1 == dstX0 - dstX1 && |
||
656 | srcY0 - srcY1 == dstY0 - dstY1 && |
||
657 | srcX1 >= srcX0 && |
||
658 | srcY1 >= srcY0 && |
||
659 | srcX0 >= 0 && srcX1 <= readFb->Width && |
||
660 | srcY0 >= 0 && srcY1 <= readFb->Height && |
||
661 | dstX0 >= 0 && dstX1 <= drawFb->Width && |
||
662 | dstY0 >= 0 && dstY1 <= drawFb->Height && |
||
663 | !ctx->Scissor.Enabled)) { |
||
664 | perf_debug("glBlitFramebuffer(): non-1:1 blit. " |
||
665 | "Falling back to software rendering.\n"); |
||
666 | return mask; |
||
667 | } |
||
668 | |||
669 | /* Blit to all active draw buffers. We don't do any pre-checking, |
||
670 | * because we assume that copying to MRTs is rare, and failure midway |
||
671 | * through copying is even more rare. Even if it was to occur, it's |
||
672 | * safe to let meta start the copy over from scratch, because |
||
673 | * glBlitFramebuffer completely overwrites the destination pixels, and |
||
674 | * results are undefined if any destination pixels have a dependency on |
||
675 | * source pixels. |
||
676 | */ |
||
677 | for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) { |
||
678 | struct gl_renderbuffer *dst_rb = ctx->DrawBuffer->_ColorDrawBuffers[i]; |
||
679 | struct intel_renderbuffer *dst_irb = intel_renderbuffer(dst_rb); |
||
680 | |||
681 | if (!dst_irb) { |
||
682 | perf_debug("glBlitFramebuffer(): missing dst renderbuffer. " |
||
683 | "Falling back to software rendering.\n"); |
||
684 | return mask; |
||
685 | } |
||
686 | |||
687 | gl_format src_format = _mesa_get_srgb_format_linear(src_rb->Format); |
||
688 | gl_format dst_format = _mesa_get_srgb_format_linear(dst_rb->Format); |
||
689 | if (src_format != dst_format) { |
||
690 | perf_debug("glBlitFramebuffer(): unsupported blit from %s to %s. " |
||
691 | "Falling back to software rendering.\n", |
||
692 | _mesa_get_format_name(src_format), |
||
693 | _mesa_get_format_name(dst_format)); |
||
694 | return mask; |
||
695 | } |
||
696 | |||
697 | if (!intel_miptree_blit(intel, |
||
698 | src_irb->mt, |
||
699 | src_irb->mt_level, src_irb->mt_layer, |
||
700 | srcX0, srcY0, src_rb->Name == 0, |
||
701 | dst_irb->mt, |
||
702 | dst_irb->mt_level, dst_irb->mt_layer, |
||
703 | dstX0, dstY0, dst_rb->Name == 0, |
||
704 | dstX1 - dstX0, dstY1 - dstY0, GL_COPY)) { |
||
705 | perf_debug("glBlitFramebuffer(): unknown blit failure. " |
||
706 | "Falling back to software rendering.\n"); |
||
707 | return mask; |
||
708 | } |
||
709 | } |
||
710 | |||
711 | mask &= ~GL_COLOR_BUFFER_BIT; |
||
712 | } |
||
713 | |||
714 | return mask; |
||
715 | } |
||
716 | |||
717 | static void |
||
718 | intel_blit_framebuffer(struct gl_context *ctx, |
||
719 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
||
720 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
||
721 | GLbitfield mask, GLenum filter) |
||
722 | { |
||
723 | /* Try using the BLT engine. */ |
||
724 | mask = intel_blit_framebuffer_with_blitter(ctx, |
||
725 | srcX0, srcY0, srcX1, srcY1, |
||
726 | dstX0, dstY0, dstX1, dstY1, |
||
727 | mask, filter); |
||
728 | if (mask == 0x0) |
||
729 | return; |
||
730 | |||
731 | |||
732 | _mesa_meta_BlitFramebuffer(ctx, |
||
733 | srcX0, srcY0, srcX1, srcY1, |
||
734 | dstX0, dstY0, dstX1, dstY1, |
||
735 | mask, filter); |
||
736 | } |
||
737 | |||
738 | /** |
||
739 | * Do one-time context initializations related to GL_EXT_framebuffer_object. |
||
740 | * Hook in device driver functions. |
||
741 | */ |
||
742 | void |
||
743 | intel_fbo_init(struct intel_context *intel) |
||
744 | { |
||
745 | intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer; |
||
746 | intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer; |
||
747 | intel->ctx.Driver.MapRenderbuffer = intel_map_renderbuffer; |
||
748 | intel->ctx.Driver.UnmapRenderbuffer = intel_unmap_renderbuffer; |
||
749 | intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer; |
||
750 | intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer; |
||
751 | intel->ctx.Driver.RenderTexture = intel_render_texture; |
||
752 | intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture; |
||
753 | intel->ctx.Driver.ValidateFramebuffer = intel_validate_framebuffer; |
||
754 | intel->ctx.Driver.BlitFramebuffer = intel_blit_framebuffer; |
||
755 | intel->ctx.Driver.EGLImageTargetRenderbufferStorage = |
||
756 | intel_image_target_renderbuffer_storage; |
||
757 | }>=>=>=>=>> |