Merge remote branch 'origin/master' into lp-setup-llvm
[mesa.git] / src / mesa / drivers / dri / intel / intel_fbo.c
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/imports.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
32 #include "main/fbobject.h"
33 #include "main/framebuffer.h"
34 #include "main/renderbuffer.h"
35 #include "main/context.h"
36 #include "main/texrender.h"
37 #include "drivers/common/meta.h"
38
39 #include "intel_context.h"
40 #include "intel_batchbuffer.h"
41 #include "intel_buffers.h"
42 #include "intel_fbo.h"
43 #include "intel_mipmap_tree.h"
44 #include "intel_regions.h"
45
46 #define FILE_DEBUG_FLAG DEBUG_FBO
47
48
49 /**
50 * Create a new framebuffer object.
51 */
52 static struct gl_framebuffer *
53 intel_new_framebuffer(struct gl_context * ctx, GLuint name)
54 {
55 /* Only drawable state in intel_framebuffer at this time, just use Mesa's
56 * class
57 */
58 return _mesa_new_framebuffer(ctx, name);
59 }
60
61
62 /** Called by gl_renderbuffer::Delete() */
63 static void
64 intel_delete_renderbuffer(struct gl_renderbuffer *rb)
65 {
66 GET_CURRENT_CONTEXT(ctx);
67 struct intel_context *intel = intel_context(ctx);
68 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
69
70 ASSERT(irb);
71
72 if (intel && irb->region) {
73 intel_region_release(&irb->region);
74 }
75
76 free(irb);
77 }
78
79
80 /**
81 * Return a pointer to a specific pixel in a renderbuffer.
82 */
83 static void *
84 intel_get_pointer(struct gl_context * ctx, struct gl_renderbuffer *rb,
85 GLint x, GLint y)
86 {
87 /* By returning NULL we force all software rendering to go through
88 * the span routines.
89 */
90 return NULL;
91 }
92
93
94 /**
95 * Called via glRenderbufferStorageEXT() to set the format and allocate
96 * storage for a user-created renderbuffer.
97 */
98 static GLboolean
99 intel_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
100 GLenum internalFormat,
101 GLuint width, GLuint height)
102 {
103 struct intel_context *intel = intel_context(ctx);
104 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
105 int cpp, tiling;
106
107 ASSERT(rb->Name != 0);
108
109 switch (internalFormat) {
110 case GL_RED:
111 case GL_R8:
112 rb->Format = MESA_FORMAT_R8;
113 rb->DataType = GL_UNSIGNED_BYTE;
114 break;
115 case GL_R16:
116 rb->Format = MESA_FORMAT_R16;
117 rb->DataType = GL_UNSIGNED_SHORT;
118 break;
119 case GL_RG:
120 case GL_RG8:
121 rb->Format = MESA_FORMAT_RG88;
122 rb->DataType = GL_UNSIGNED_BYTE;
123 break;
124 case GL_RG16:
125 rb->Format = MESA_FORMAT_RG1616;
126 rb->DataType = GL_UNSIGNED_SHORT;
127 break;
128 case GL_R3_G3_B2:
129 case GL_RGB4:
130 case GL_RGB5:
131 rb->Format = MESA_FORMAT_RGB565;
132 rb->DataType = GL_UNSIGNED_BYTE;
133 break;
134 case GL_RGB:
135 case GL_RGB8:
136 case GL_RGB10:
137 case GL_RGB12:
138 case GL_RGB16:
139 rb->Format = MESA_FORMAT_XRGB8888;
140 rb->DataType = GL_UNSIGNED_BYTE;
141 break;
142 case GL_RGBA:
143 case GL_RGBA2:
144 case GL_RGBA4:
145 case GL_RGB5_A1:
146 case GL_RGBA8:
147 case GL_RGB10_A2:
148 case GL_RGBA12:
149 case GL_RGBA16:
150 rb->Format = MESA_FORMAT_ARGB8888;
151 rb->DataType = GL_UNSIGNED_BYTE;
152 break;
153 case GL_ALPHA:
154 case GL_ALPHA8:
155 rb->Format = MESA_FORMAT_A8;
156 rb->DataType = GL_UNSIGNED_BYTE;
157 break;
158 case GL_DEPTH_COMPONENT16:
159 rb->Format = MESA_FORMAT_Z16;
160 rb->DataType = GL_UNSIGNED_SHORT;
161 break;
162 case GL_STENCIL_INDEX:
163 case GL_STENCIL_INDEX1_EXT:
164 case GL_STENCIL_INDEX4_EXT:
165 case GL_STENCIL_INDEX8_EXT:
166 case GL_STENCIL_INDEX16_EXT:
167 case GL_DEPTH_COMPONENT:
168 case GL_DEPTH_COMPONENT24:
169 case GL_DEPTH_COMPONENT32:
170 case GL_DEPTH_STENCIL_EXT:
171 case GL_DEPTH24_STENCIL8_EXT:
172 /* alloc a depth+stencil buffer */
173 rb->Format = MESA_FORMAT_S8_Z24;
174 rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
175 break;
176 default:
177 _mesa_problem(ctx,
178 "Unexpected format in intel_alloc_renderbuffer_storage");
179 return GL_FALSE;
180 }
181
182 rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
183 cpp = _mesa_get_format_bytes(rb->Format);
184
185 intel_flush(ctx);
186
187 /* free old region */
188 if (irb->region) {
189 intel_region_release(&irb->region);
190 }
191
192 /* allocate new memory region/renderbuffer */
193
194 /* alloc hardware renderbuffer */
195 DBG("Allocating %d x %d Intel RBO\n", width, height);
196
197 tiling = I915_TILING_NONE;
198
199 /* Gen6 requires depth must be tiling */
200 if (intel->gen >= 6 && rb->Format == MESA_FORMAT_S8_Z24)
201 tiling = I915_TILING_Y;
202
203 irb->region = intel_region_alloc(intel->intelScreen, tiling, cpp,
204 width, height, GL_TRUE);
205 if (!irb->region)
206 return GL_FALSE; /* out of memory? */
207
208 ASSERT(irb->region->buffer);
209
210 rb->Width = width;
211 rb->Height = height;
212
213 return GL_TRUE;
214 }
215
216
217 #if FEATURE_OES_EGL_image
218 static void
219 intel_image_target_renderbuffer_storage(struct gl_context *ctx,
220 struct gl_renderbuffer *rb,
221 void *image_handle)
222 {
223 struct intel_context *intel = intel_context(ctx);
224 struct intel_renderbuffer *irb;
225 __DRIscreen *screen;
226 __DRIimage *image;
227
228 screen = intel->intelScreen->driScrnPriv;
229 image = screen->dri2.image->lookupEGLImage(screen, image_handle,
230 screen->loaderPrivate);
231 if (image == NULL)
232 return;
233
234 irb = intel_renderbuffer(rb);
235 if (irb->region)
236 intel_region_release(&irb->region);
237 intel_region_reference(&irb->region, image->region);
238
239 rb->InternalFormat = image->internal_format;
240 rb->Width = image->region->width;
241 rb->Height = image->region->height;
242 rb->Format = image->format;
243 rb->DataType = image->data_type;
244 rb->_BaseFormat = _mesa_base_fbo_format(&intel->ctx,
245 image->internal_format);
246 }
247 #endif
248
249 /**
250 * Called for each hardware renderbuffer when a _window_ is resized.
251 * Just update fields.
252 * Not used for user-created renderbuffers!
253 */
254 static GLboolean
255 intel_alloc_window_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
256 GLenum internalFormat, GLuint width, GLuint height)
257 {
258 ASSERT(rb->Name == 0);
259 rb->Width = width;
260 rb->Height = height;
261 rb->InternalFormat = internalFormat;
262
263 return GL_TRUE;
264 }
265
266
267 static void
268 intel_resize_buffers(struct gl_context *ctx, struct gl_framebuffer *fb,
269 GLuint width, GLuint height)
270 {
271 int i;
272
273 _mesa_resize_framebuffer(ctx, fb, width, height);
274
275 fb->Initialized = GL_TRUE; /* XXX remove someday */
276
277 if (fb->Name != 0) {
278 return;
279 }
280
281
282 /* Make sure all window system renderbuffers are up to date */
283 for (i = BUFFER_FRONT_LEFT; i <= BUFFER_BACK_RIGHT; i++) {
284 struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer;
285
286 /* only resize if size is changing */
287 if (rb && (rb->Width != width || rb->Height != height)) {
288 rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height);
289 }
290 }
291 }
292
293
294 /** Dummy function for gl_renderbuffer::AllocStorage() */
295 static GLboolean
296 intel_nop_alloc_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
297 GLenum internalFormat, GLuint width, GLuint height)
298 {
299 _mesa_problem(ctx, "intel_op_alloc_storage should never be called.");
300 return GL_FALSE;
301 }
302
303
304 void
305 intel_renderbuffer_set_region(struct intel_context *intel,
306 struct intel_renderbuffer *rb,
307 struct intel_region *region)
308 {
309 struct intel_region *old;
310
311 old = rb->region;
312 rb->region = NULL;
313 intel_region_reference(&rb->region, region);
314 intel_region_release(&old);
315 }
316
317
318 /**
319 * Create a new intel_renderbuffer which corresponds to an on-screen window,
320 * not a user-created renderbuffer.
321 */
322 struct intel_renderbuffer *
323 intel_create_renderbuffer(gl_format format)
324 {
325 GET_CURRENT_CONTEXT(ctx);
326
327 struct intel_renderbuffer *irb;
328
329 irb = CALLOC_STRUCT(intel_renderbuffer);
330 if (!irb) {
331 _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
332 return NULL;
333 }
334
335 _mesa_init_renderbuffer(&irb->Base, 0);
336 irb->Base.ClassID = INTEL_RB_CLASS;
337
338 switch (format) {
339 case MESA_FORMAT_RGB565:
340 irb->Base._BaseFormat = GL_RGB;
341 irb->Base.DataType = GL_UNSIGNED_BYTE;
342 break;
343 case MESA_FORMAT_XRGB8888:
344 irb->Base._BaseFormat = GL_RGB;
345 irb->Base.DataType = GL_UNSIGNED_BYTE;
346 break;
347 case MESA_FORMAT_ARGB8888:
348 irb->Base._BaseFormat = GL_RGBA;
349 irb->Base.DataType = GL_UNSIGNED_BYTE;
350 break;
351 case MESA_FORMAT_Z16:
352 irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
353 irb->Base.DataType = GL_UNSIGNED_SHORT;
354 break;
355 case MESA_FORMAT_X8_Z24:
356 irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
357 irb->Base.DataType = GL_UNSIGNED_INT;
358 break;
359 case MESA_FORMAT_S8_Z24:
360 irb->Base._BaseFormat = GL_DEPTH_STENCIL;
361 irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
362 break;
363 case MESA_FORMAT_A8:
364 irb->Base._BaseFormat = GL_ALPHA;
365 irb->Base.DataType = GL_UNSIGNED_BYTE;
366 break;
367 case MESA_FORMAT_R8:
368 irb->Base._BaseFormat = GL_RED;
369 irb->Base.DataType = GL_UNSIGNED_BYTE;
370 break;
371 case MESA_FORMAT_RG88:
372 irb->Base._BaseFormat = GL_RG;
373 irb->Base.DataType = GL_UNSIGNED_BYTE;
374 break;
375 default:
376 _mesa_problem(NULL,
377 "Unexpected intFormat in intel_create_renderbuffer");
378 free(irb);
379 return NULL;
380 }
381
382 irb->Base.Format = format;
383 irb->Base.InternalFormat = irb->Base._BaseFormat;
384
385 /* intel-specific methods */
386 irb->Base.Delete = intel_delete_renderbuffer;
387 irb->Base.AllocStorage = intel_alloc_window_storage;
388 irb->Base.GetPointer = intel_get_pointer;
389
390 return irb;
391 }
392
393
394 /**
395 * Create a new renderbuffer object.
396 * Typically called via glBindRenderbufferEXT().
397 */
398 static struct gl_renderbuffer *
399 intel_new_renderbuffer(struct gl_context * ctx, GLuint name)
400 {
401 /*struct intel_context *intel = intel_context(ctx); */
402 struct intel_renderbuffer *irb;
403
404 irb = CALLOC_STRUCT(intel_renderbuffer);
405 if (!irb) {
406 _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
407 return NULL;
408 }
409
410 _mesa_init_renderbuffer(&irb->Base, name);
411 irb->Base.ClassID = INTEL_RB_CLASS;
412
413 /* intel-specific methods */
414 irb->Base.Delete = intel_delete_renderbuffer;
415 irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
416 irb->Base.GetPointer = intel_get_pointer;
417 /* span routines set in alloc_storage function */
418
419 return &irb->Base;
420 }
421
422
423 /**
424 * Called via glBindFramebufferEXT().
425 */
426 static void
427 intel_bind_framebuffer(struct gl_context * ctx, GLenum target,
428 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
429 {
430 if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) {
431 intel_draw_buffer(ctx, fb);
432 }
433 else {
434 /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
435 }
436 }
437
438
439 /**
440 * Called via glFramebufferRenderbufferEXT().
441 */
442 static void
443 intel_framebuffer_renderbuffer(struct gl_context * ctx,
444 struct gl_framebuffer *fb,
445 GLenum attachment, struct gl_renderbuffer *rb)
446 {
447 DBG("Intel FramebufferRenderbuffer %u %u\n", fb->Name, rb ? rb->Name : 0);
448
449 intel_flush(ctx);
450
451 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
452 intel_draw_buffer(ctx, fb);
453 }
454
455
456 static GLboolean
457 intel_update_wrapper(struct gl_context *ctx, struct intel_renderbuffer *irb,
458 struct gl_texture_image *texImage)
459 {
460 if (texImage->TexFormat == MESA_FORMAT_ARGB8888) {
461 irb->Base.DataType = GL_UNSIGNED_BYTE;
462 DBG("Render to RGBA8 texture OK\n");
463 }
464 else if (texImage->TexFormat == MESA_FORMAT_XRGB8888) {
465 irb->Base.DataType = GL_UNSIGNED_BYTE;
466 DBG("Render to XGBA8 texture OK\n");
467 }
468 else if (texImage->TexFormat == MESA_FORMAT_SARGB8) {
469 irb->Base.DataType = GL_UNSIGNED_BYTE;
470 DBG("Render to SARGB8 texture OK\n");
471 }
472 else if (texImage->TexFormat == MESA_FORMAT_RGB565) {
473 irb->Base.DataType = GL_UNSIGNED_BYTE;
474 DBG("Render to RGB5 texture OK\n");
475 }
476 else if (texImage->TexFormat == MESA_FORMAT_ARGB1555) {
477 irb->Base.DataType = GL_UNSIGNED_BYTE;
478 DBG("Render to ARGB1555 texture OK\n");
479 }
480 else if (texImage->TexFormat == MESA_FORMAT_ARGB4444) {
481 irb->Base.DataType = GL_UNSIGNED_BYTE;
482 DBG("Render to ARGB4444 texture OK\n");
483 }
484 else if (texImage->TexFormat == MESA_FORMAT_A8) {
485 irb->Base.DataType = GL_UNSIGNED_BYTE;
486 DBG("Render to A8 texture OK\n");
487 }
488 else if (texImage->TexFormat == MESA_FORMAT_R8) {
489 irb->Base.DataType = GL_UNSIGNED_BYTE;
490 DBG("Render to R8 texture OK\n");
491 }
492 else if (texImage->TexFormat == MESA_FORMAT_RG88) {
493 irb->Base.DataType = GL_UNSIGNED_BYTE;
494 DBG("Render to RG88 texture OK\n");
495 }
496 else if (texImage->TexFormat == MESA_FORMAT_R16) {
497 irb->Base.DataType = GL_UNSIGNED_SHORT;
498 DBG("Render to R8 texture OK\n");
499 }
500 else if (texImage->TexFormat == MESA_FORMAT_RG1616) {
501 irb->Base.DataType = GL_UNSIGNED_SHORT;
502 DBG("Render to RG88 texture OK\n");
503 }
504 else if (texImage->TexFormat == MESA_FORMAT_Z16) {
505 irb->Base.DataType = GL_UNSIGNED_SHORT;
506 DBG("Render to DEPTH16 texture OK\n");
507 }
508 else if (texImage->TexFormat == MESA_FORMAT_S8_Z24) {
509 irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
510 DBG("Render to DEPTH_STENCIL texture OK\n");
511 }
512 else {
513 DBG("Render to texture BAD FORMAT %s\n",
514 _mesa_get_format_name(texImage->TexFormat));
515 return GL_FALSE;
516 }
517
518 irb->Base.Format = texImage->TexFormat;
519
520 irb->Base.InternalFormat = texImage->InternalFormat;
521 irb->Base._BaseFormat = _mesa_base_fbo_format(ctx, irb->Base.InternalFormat);
522 irb->Base.Width = texImage->Width;
523 irb->Base.Height = texImage->Height;
524
525 irb->Base.Delete = intel_delete_renderbuffer;
526 irb->Base.AllocStorage = intel_nop_alloc_storage;
527
528 return GL_TRUE;
529 }
530
531
532 /**
533 * When glFramebufferTexture[123]D is called this function sets up the
534 * gl_renderbuffer wrapper around the texture image.
535 * This will have the region info needed for hardware rendering.
536 */
537 static struct intel_renderbuffer *
538 intel_wrap_texture(struct gl_context * ctx, struct gl_texture_image *texImage)
539 {
540 const GLuint name = ~0; /* not significant, but distinct for debugging */
541 struct intel_renderbuffer *irb;
542
543 /* make an intel_renderbuffer to wrap the texture image */
544 irb = CALLOC_STRUCT(intel_renderbuffer);
545 if (!irb) {
546 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture");
547 return NULL;
548 }
549
550 _mesa_init_renderbuffer(&irb->Base, name);
551 irb->Base.ClassID = INTEL_RB_CLASS;
552
553 if (!intel_update_wrapper(ctx, irb, texImage)) {
554 free(irb);
555 return NULL;
556 }
557
558 return irb;
559 }
560
561
562 /**
563 * Called by glFramebufferTexture[123]DEXT() (and other places) to
564 * prepare for rendering into texture memory. This might be called
565 * many times to choose different texture levels, cube faces, etc
566 * before intel_finish_render_texture() is ever called.
567 */
568 static void
569 intel_render_texture(struct gl_context * ctx,
570 struct gl_framebuffer *fb,
571 struct gl_renderbuffer_attachment *att)
572 {
573 struct gl_texture_image *newImage
574 = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
575 struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
576 struct intel_texture_image *intel_image;
577 GLuint dst_x, dst_y;
578
579 (void) fb;
580
581 ASSERT(newImage);
582
583 intel_image = intel_texture_image(newImage);
584 if (!intel_image->mt) {
585 /* Fallback on drawing to a texture that doesn't have a miptree
586 * (has a border, width/height 0, etc.)
587 */
588 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
589 _mesa_render_texture(ctx, fb, att);
590 return;
591 }
592 else if (!irb) {
593 irb = intel_wrap_texture(ctx, newImage);
594 if (irb) {
595 /* bind the wrapper to the attachment point */
596 _mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base);
597 }
598 else {
599 /* fallback to software rendering */
600 _mesa_render_texture(ctx, fb, att);
601 return;
602 }
603 }
604
605 if (!intel_update_wrapper(ctx, irb, newImage)) {
606 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
607 _mesa_render_texture(ctx, fb, att);
608 return;
609 }
610
611 DBG("Begin render texture tid %lx tex=%u w=%d h=%d refcount=%d\n",
612 _glthread_GetID(),
613 att->Texture->Name, newImage->Width, newImage->Height,
614 irb->Base.RefCount);
615
616 /* point the renderbufer's region to the texture image region */
617 if (irb->region != intel_image->mt->region) {
618 if (irb->region)
619 intel_region_release(&irb->region);
620 intel_region_reference(&irb->region, intel_image->mt->region);
621 }
622
623 /* compute offset of the particular 2D image within the texture region */
624 intel_miptree_get_image_offset(intel_image->mt,
625 att->TextureLevel,
626 att->CubeMapFace,
627 att->Zoffset,
628 &dst_x, &dst_y);
629
630 intel_image->mt->region->draw_offset = (dst_y * intel_image->mt->region->pitch +
631 dst_x) * intel_image->mt->cpp;
632 intel_image->mt->region->draw_x = dst_x;
633 intel_image->mt->region->draw_y = dst_y;
634 intel_image->used_as_render_target = GL_TRUE;
635
636 /* update drawing region, etc */
637 intel_draw_buffer(ctx, fb);
638 }
639
640
641 /**
642 * Called by Mesa when rendering to a texture is done.
643 */
644 static void
645 intel_finish_render_texture(struct gl_context * ctx,
646 struct gl_renderbuffer_attachment *att)
647 {
648 struct intel_context *intel = intel_context(ctx);
649 struct gl_texture_object *tex_obj = att->Texture;
650 struct gl_texture_image *image =
651 tex_obj->Image[att->CubeMapFace][att->TextureLevel];
652 struct intel_texture_image *intel_image = intel_texture_image(image);
653
654 DBG("Finish render texture tid %lx tex=%u\n",
655 _glthread_GetID(), att->Texture->Name);
656
657 /* Flag that this image may now be validated into the object's miptree. */
658 intel_image->used_as_render_target = GL_FALSE;
659
660 /* Since we've (probably) rendered to the texture and will (likely) use
661 * it in the texture domain later on in this batchbuffer, flush the
662 * batch. Once again, we wish for a domain tracker in libdrm to cover
663 * usage inside of a batchbuffer like GEM does in the kernel.
664 */
665 intel_batchbuffer_emit_mi_flush(intel->batch);
666 }
667
668 /**
669 * Do additional "completeness" testing of a framebuffer object.
670 */
671 static void
672 intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
673 {
674 const struct intel_renderbuffer *depthRb =
675 intel_get_renderbuffer(fb, BUFFER_DEPTH);
676 const struct intel_renderbuffer *stencilRb =
677 intel_get_renderbuffer(fb, BUFFER_STENCIL);
678 int i;
679
680 if (depthRb && stencilRb && stencilRb != depthRb) {
681 if (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Type == GL_TEXTURE &&
682 ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Type == GL_TEXTURE &&
683 (ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Texture->Name ==
684 ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Texture->Name)) {
685 /* OK */
686 } else {
687 /* we only support combined depth/stencil buffers, not separate
688 * stencil buffers.
689 */
690 DBG("Only supports combined depth/stencil (found %s, %s)\n",
691 depthRb ? _mesa_get_format_name(depthRb->Base.Format): "NULL",
692 stencilRb ? _mesa_get_format_name(stencilRb->Base.Format): "NULL");
693 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
694 }
695 }
696
697 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
698 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[i];
699 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
700
701 if (rb == NULL)
702 continue;
703
704 if (irb == NULL) {
705 DBG("software rendering renderbuffer\n");
706 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
707 continue;
708 }
709
710 switch (irb->Base.Format) {
711 case MESA_FORMAT_ARGB8888:
712 case MESA_FORMAT_XRGB8888:
713 case MESA_FORMAT_SARGB8:
714 case MESA_FORMAT_RGB565:
715 case MESA_FORMAT_ARGB1555:
716 case MESA_FORMAT_ARGB4444:
717 case MESA_FORMAT_A8:
718 case MESA_FORMAT_R8:
719 case MESA_FORMAT_R16:
720 case MESA_FORMAT_RG88:
721 case MESA_FORMAT_RG1616:
722 break;
723 default:
724 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
725 }
726 }
727 }
728
729
730 /**
731 * Do one-time context initializations related to GL_EXT_framebuffer_object.
732 * Hook in device driver functions.
733 */
734 void
735 intel_fbo_init(struct intel_context *intel)
736 {
737 intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer;
738 intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer;
739 intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer;
740 intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer;
741 intel->ctx.Driver.RenderTexture = intel_render_texture;
742 intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture;
743 intel->ctx.Driver.ResizeBuffers = intel_resize_buffers;
744 intel->ctx.Driver.ValidateFramebuffer = intel_validate_framebuffer;
745 intel->ctx.Driver.BlitFramebuffer = _mesa_meta_BlitFramebuffer;
746
747 #if FEATURE_OES_EGL_image
748 intel->ctx.Driver.EGLImageTargetRenderbufferStorage =
749 intel_image_target_renderbuffer_storage;
750 #endif
751 }