void intel_renderbuffer_move_to_temp(struct brw_context *brw, struct intel_renderbuffer *irb, bool invalidate) { struct gl_renderbuffer *rb =&irb->Base.Base; struct intel_texture_image *intel_image = intel_texture_image(rb->TexImage); struct intel_mipmap_tree *new_mt; int width, height, depth; intel_miptree_get_dimensions_for_image(rb->TexImage, &width, &height, &depth); new_mt = intel_miptree_create(brw, rb->TexImage->TexObject->Target, intel_image->base.Base.TexFormat, intel_image->base.Base.Level, intel_image->base.Base.Level, width, height, depth, true, irb->mt->num_samples, INTEL_MIPTREE_TILING_ANY); if (brw_is_hiz_depth_format(brw, new_mt->format)) { intel_miptree_alloc_hiz(brw, new_mt); } intel_miptree_copy_teximage(brw, intel_image, new_mt, invalidate); intel_miptree_reference(&irb->mt, intel_image->mt); intel_renderbuffer_set_draw_offset(irb); intel_miptree_release(&new_mt); }
void intel_renderbuffer_move_to_temp(struct intel_context *intel, struct intel_renderbuffer *irb) { struct intel_texture_image *intel_image = intel_texture_image(irb->tex_image); struct intel_mipmap_tree *new_mt; int width, height, depth; intel_miptree_get_dimensions_for_image(irb->tex_image, &width, &height, &depth); new_mt = intel_miptree_create(intel, irb->tex_image->TexObject->Target, intel_image->base.Base.TexFormat, intel_image->base.Base.Level, intel_image->base.Base.Level, width, height, depth, true, irb->mt->num_samples, false /* force_y_tiling */); intel_miptree_copy_teximage(intel, intel_image, new_mt); intel_miptree_reference(&irb->mt, intel_image->mt); intel_renderbuffer_set_draw_offset(irb); intel_miptree_release(&new_mt); }
GLuint intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit) { struct gl_context *ctx = &intel->ctx; struct gl_texture_object *tObj = intel->ctx.Texture.Unit[unit]._Current; struct intel_texture_object *intelObj = intel_texture_object(tObj); struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); GLuint face, i; GLuint nr_faces = 0; struct intel_texture_image *firstImage; int width, height, depth; /* TBOs require no validation -- they always just point to their BO. */ if (tObj->Target == GL_TEXTURE_BUFFER) return true; /* We know/require this is true by now: */ assert(intelObj->base._BaseComplete); /* What levels must the tree include at a minimum? */ intel_update_max_level(intelObj, sampler); firstImage = intel_texture_image(tObj->Image[0][tObj->BaseLevel]); /* Check tree can hold all active levels. Check tree matches * target, imageFormat, etc. * * For pre-gen4, we have to match first_level == tObj->BaseLevel, * because we don't have the control that gen4 does to make min/mag * determination happen at a nonzero (hardware) baselevel. Because * of that, we just always relayout on baselevel change. */ if (intelObj->mt && (!intel_miptree_match_image(intelObj->mt, &firstImage->base.Base) || intelObj->mt->first_level != tObj->BaseLevel || intelObj->mt->last_level < intelObj->_MaxLevel)) { intel_miptree_release(&intelObj->mt); } /* May need to create a new tree: */ if (!intelObj->mt) { intel_miptree_get_dimensions_for_image(&firstImage->base.Base, &width, &height, &depth); intelObj->mt = intel_miptree_create(intel, intelObj->base.Target, firstImage->base.Base.TexFormat, tObj->BaseLevel, intelObj->_MaxLevel, width, height, depth, true, 0 /* num_samples */, false /* msaa_is_interleaved */); if (!intelObj->mt) return false; } /* Pull in any images not in the object's tree: */ nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; for (face = 0; face < nr_faces; face++) { for (i = tObj->BaseLevel; i <= intelObj->_MaxLevel; i++) { struct intel_texture_image *intelImage = intel_texture_image(intelObj->base.Image[face][i]); /* skip too small size mipmap */ if (intelImage == NULL) break; if (intelObj->mt != intelImage->mt) { intel_miptree_copy_teximage(intel, intelImage, intelObj->mt); } } } return true; }
/** * At rendering-from-a-texture time, make sure that the texture object has a * miptree that can hold the entire texture based on * BaseLevel/MaxLevel/filtering, and copy in any texture images that are * stored in other miptrees. */ GLuint intel_finalize_mipmap_tree(struct brw_context *brw, GLuint unit) { struct gl_context *ctx = &brw->ctx; struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; struct intel_texture_object *intelObj = intel_texture_object(tObj); struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); GLuint face, i; GLuint nr_faces = 0; struct intel_texture_image *firstImage; int width, height, depth; /* TBOs require no validation -- they always just point to their BO. */ if (tObj->Target == GL_TEXTURE_BUFFER) return true; /* We know that this is true by now, and if it wasn't, we might have * mismatched level sizes and the copies would fail. */ assert(intelObj->base._BaseComplete); intel_update_max_level(intelObj, sampler); /* What levels does this validated texture image require? */ int validate_first_level = tObj->BaseLevel; int validate_last_level = intelObj->_MaxLevel; /* Skip the loop over images in the common case of no images having * changed. But if the GL_BASE_LEVEL or GL_MAX_LEVEL change to something we * haven't looked at, then we do need to look at those new images. */ if (!intelObj->needs_validate && validate_first_level >= intelObj->validated_first_level && validate_last_level <= intelObj->validated_last_level) { return true; } /* Immutable textures should not get this far -- they should have been * created in a validated state, and nothing can invalidate them. */ assert(!tObj->Immutable); firstImage = intel_texture_image(tObj->Image[0][tObj->BaseLevel]); /* Check tree can hold all active levels. Check tree matches * target, imageFormat, etc. * * For pre-gen4, we have to match first_level == tObj->BaseLevel, * because we don't have the control that gen4 does to make min/mag * determination happen at a nonzero (hardware) baselevel. Because * of that, we just always relayout on baselevel change. */ if (intelObj->mt && (!intel_miptree_match_image(intelObj->mt, &firstImage->base.Base) || validate_first_level < intelObj->mt->first_level || validate_last_level > intelObj->mt->last_level)) { intel_miptree_release(&intelObj->mt); } /* May need to create a new tree: */ if (!intelObj->mt) { intel_miptree_get_dimensions_for_image(&firstImage->base.Base, &width, &height, &depth); perf_debug("Creating new %s %dx%dx%d %d-level miptree to handle " "finalized texture miptree.\n", _mesa_get_format_name(firstImage->base.Base.TexFormat), width, height, depth, validate_last_level + 1); intelObj->mt = intel_miptree_create(brw, intelObj->base.Target, firstImage->base.Base.TexFormat, 0, /* first_level */ validate_last_level, width, height, depth, true, 0 /* num_samples */, INTEL_MIPTREE_TILING_ANY); if (!intelObj->mt) return false; } /* Pull in any images not in the object's tree: */ nr_faces = _mesa_num_tex_faces(intelObj->base.Target); for (face = 0; face < nr_faces; face++) { for (i = validate_first_level; i <= validate_last_level; i++) { struct intel_texture_image *intelImage = intel_texture_image(intelObj->base.Image[face][i]); /* skip too small size mipmap */ if (intelImage == NULL) break; if (intelObj->mt != intelImage->mt) { intel_miptree_copy_teximage(brw, intelImage, intelObj->mt, false /* invalidate */); } /* After we're done, we'd better agree that our layout is * appropriate, or we'll end up hitting this function again on the * next draw */ assert(intel_miptree_match_image(intelObj->mt, &intelImage->base.Base)); } } intelObj->validated_first_level = validate_first_level; intelObj->validated_last_level = validate_last_level; intelObj->_Format = intelObj->mt->format; intelObj->needs_validate = false; return true; }
GLuint intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit) { struct gl_context *ctx = &intel->ctx; struct gl_texture_object *tObj = intel->ctx.Texture.Unit[unit]._Current; struct intel_texture_object *intelObj = intel_texture_object(tObj); struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); GLuint face, i; GLuint nr_faces = 0; struct intel_texture_image *firstImage; int width, height, depth; /* We know/require this is true by now: */ assert(intelObj->base._Complete); /* What levels must the tree include at a minimum? */ intel_update_max_level(intelObj, sampler); firstImage = intel_texture_image(tObj->Image[0][tObj->BaseLevel]); /* Check tree can hold all active levels. Check tree matches * target, imageFormat, etc. * * For pre-gen4, we have to match first_level == tObj->BaseLevel, * because we don't have the control that gen4 does to make min/mag * determination happen at a nonzero (hardware) baselevel. Because * of that, we just always relayout on baselevel change. */ if (intelObj->mt && (!intel_miptree_match_image(intelObj->mt, &firstImage->base.Base) || intelObj->mt->target != intelObj->base.Target || intelObj->mt->first_level != tObj->BaseLevel || intelObj->mt->last_level < intelObj->_MaxLevel)) { intel_miptree_release(&intelObj->mt); } /* May need to create a new tree: */ if (!intelObj->mt) { intel_miptree_get_dimensions_for_image(&firstImage->base.Base, &width, &height, &depth); intelObj->mt = intel_miptree_create(intel, intelObj->base.Target, firstImage->base.Base.TexFormat, tObj->BaseLevel, intelObj->_MaxLevel, width, height, depth, true); if (!intelObj->mt) return false; } /* Pull in any images not in the object's tree: */ nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; for (face = 0; face < nr_faces; face++) { for (i = tObj->BaseLevel; i <= intelObj->_MaxLevel; i++) { struct intel_texture_image *intelImage = intel_texture_image(intelObj->base.Image[face][i]); /* skip too small size mipmap */ if (intelImage == NULL) break; /* Need to import images in main memory or held in other trees. * If it's a render target, then its data isn't needed to be in * the object tree (otherwise we'd be FBO incomplete), and we need * to keep track of the image's MT as needing to be pulled in still, * or we'll lose the rendering that's done to it. */ if (intelObj->mt != intelImage->mt && !intelImage->used_as_render_target) { intel_miptree_copy_teximage(intel, intelImage, intelObj->mt); } } } return true; }
GLuint intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit) { struct gl_context *ctx = &intel->ctx; struct gl_texture_object *tObj = intel->ctx.Texture.Unit[unit]._Current; struct intel_texture_object *intelObj = intel_texture_object(tObj); struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); GLuint face, i; GLuint nr_faces = 0; struct intel_texture_image *firstImage; int width, height, depth; /* TBOs require no validation -- they always just point to their BO. */ if (tObj->Target == GL_TEXTURE_BUFFER) return true; /* We know/require this is true by now: */ assert(intelObj->base._BaseComplete); /* What levels must the tree include at a minimum? */ intel_update_max_level(intelObj, sampler); if (intelObj->mt && intelObj->mt->first_level != tObj->BaseLevel) intelObj->needs_validate = true; if (!intelObj->needs_validate) return true; firstImage = intel_texture_image(tObj->Image[0][tObj->BaseLevel]); /* Check tree can hold all active levels. Check tree matches * target, imageFormat, etc. * * For pre-gen4, we have to match first_level == tObj->BaseLevel, * because we don't have the control that gen4 does to make min/mag * determination happen at a nonzero (hardware) baselevel. Because * of that, we just always relayout on baselevel change. */ if (intelObj->mt && (!intel_miptree_match_image(intelObj->mt, &firstImage->base.Base) || intelObj->mt->first_level != tObj->BaseLevel || intelObj->mt->last_level < intelObj->_MaxLevel)) { intel_miptree_release(&intelObj->mt); } /* May need to create a new tree: */ if (!intelObj->mt) { intel_miptree_get_dimensions_for_image(&firstImage->base.Base, &width, &height, &depth); perf_debug("Creating new %s %dx%dx%d %d..%d miptree to handle finalized " "texture miptree.\n", _mesa_get_format_name(firstImage->base.Base.TexFormat), width, height, depth, tObj->BaseLevel, intelObj->_MaxLevel); intelObj->mt = intel_miptree_create(intel, intelObj->base.Target, firstImage->base.Base.TexFormat, tObj->BaseLevel, intelObj->_MaxLevel, width, height, depth, true, 0 /* num_samples */, false /* force_y_tiling */); if (!intelObj->mt) return false; } /* Pull in any images not in the object's tree: */ nr_faces = _mesa_num_tex_faces(intelObj->base.Target); for (face = 0; face < nr_faces; face++) { for (i = tObj->BaseLevel; i <= intelObj->_MaxLevel; i++) { struct intel_texture_image *intelImage = intel_texture_image(intelObj->base.Image[face][i]); /* skip too small size mipmap */ if (intelImage == NULL) break; if (intelObj->mt != intelImage->mt) { intel_miptree_copy_teximage(intel, intelImage, intelObj->mt, false /* invalidate */); } /* After we're done, we'd better agree that our layout is * appropriate, or we'll end up hitting this function again on the * next draw */ assert(intel_miptree_match_image(intelObj->mt, &intelImage->base.Base)); } } intelObj->needs_validate = false; return true; }
/** * Called by glFramebufferTexture[123]DEXT() (and other places) to * prepare for rendering into texture memory. This might be called * many times to choose different texture levels, cube faces, etc * before intel_finish_render_texture() is ever called. */ static void intel_render_texture(struct gl_context * ctx, struct gl_framebuffer *fb, struct gl_renderbuffer_attachment *att) { struct intel_context *intel = intel_context(ctx); struct gl_texture_image *image = _mesa_get_attachment_teximage(att); struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer); struct intel_texture_image *intel_image = intel_texture_image(image); struct intel_mipmap_tree *mt = intel_image->mt; int layer; (void) fb; if (att->CubeMapFace > 0) { assert(att->Zoffset == 0); layer = att->CubeMapFace; } else { layer = att->Zoffset; } if (!intel_image->mt) { /* Fallback on drawing to a texture that doesn't have a miptree * (has a border, width/height 0, etc.) */ _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); _swrast_render_texture(ctx, fb, att); return; } else if (!irb) { intel_miptree_check_level_layer(mt, att->TextureLevel, layer); irb = (struct intel_renderbuffer *)intel_new_renderbuffer(ctx, ~0); if (irb) { /* bind the wrapper to the attachment point */ _mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base.Base); } else { /* fallback to software rendering */ _swrast_render_texture(ctx, fb, att); return; } } if (!intel_renderbuffer_update_wrapper(intel, irb, image, layer)) { _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); _swrast_render_texture(ctx, fb, att); return; } DBG("Begin render %s texture tex=%u w=%d h=%d refcount=%d\n", _mesa_get_format_name(image->TexFormat), att->Texture->Name, image->Width, image->Height, irb->Base.Base.RefCount); intel_image->used_as_render_target = true; #ifndef I915 if (need_tile_offset_workaround(brw_context(ctx), irb)) { /* Original gen4 hardware couldn't draw to a non-tile-aligned * destination in a miptree unless you actually setup your * renderbuffer as a miptree and used the fragile * lod/array_index/etc. controls to select the image. So, * instead, we just make a new single-level miptree and render * into that. */ struct intel_context *intel = intel_context(ctx); struct intel_mipmap_tree *new_mt; int width, height, depth; intel_miptree_get_dimensions_for_image(image, &width, &height, &depth); new_mt = intel_miptree_create(intel, image->TexObject->Target, intel_image->base.Base.TexFormat, intel_image->base.Base.Level, intel_image->base.Base.Level, width, height, depth, true); intel_miptree_copy_teximage(intel, intel_image, new_mt); intel_renderbuffer_set_draw_offset(irb); intel_miptree_reference(&irb->mt, intel_image->mt); intel_miptree_release(&new_mt); } #endif /* update drawing region, etc */ intel_draw_buffer(ctx); }