/* Set Data pointer and additional data for mapped texture image */ static void teximage_set_map_data(radeon_texture_image *image) { radeon_mipmap_level *lvl; if (!image->mt) { radeon_warning("%s(%p) Trying to set map data without miptree.\n", __func__, image); return; } lvl = &image->mt->levels[image->base.Base.Level]; image->base.Map = image->mt->bo->ptr + lvl->faces[image->base.Base.Face].offset; image->base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat); }
/** * Try to allocate a mipmap tree for the given texture object. * @param[in] rmesa radeon context * @param[in] t radeon texture object */ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t) { struct gl_texture_object *texObj = &t->base; struct gl_texture_image *texImg = texObj->Image[0][texObj->BaseLevel]; GLuint numLevels; assert(!t->mt); if (!texImg) { radeon_warning("%s(%p) No image in given texture object(%p).\n", __func__, rmesa, t); return; } numLevels = MIN2(texObj->MaxLevel - texObj->BaseLevel + 1, texImg->MaxNumLevels); t->mt = radeon_miptree_create(rmesa, t->base.Target, texImg->TexFormat, texObj->BaseLevel, numLevels, texImg->Width, texImg->Height, texImg->Depth, t->tile_bits); }
/** * Map a validated texture for reading during software rendering. */ void radeonMapTexture(GLcontext *ctx, struct gl_texture_object *texObj) { radeonTexObj* t = radeon_tex_obj(texObj); int face, level; radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, "%s(%p, tex %p)\n", __func__, ctx, texObj); if (!radeon_validate_texture_miptree(ctx, texObj)) { radeon_error("%s(%p, tex %p) Failed to validate miptree for " "sw fallback.\n", __func__, ctx, texObj); return; } if (t->image_override && t->bo) { radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, "%s(%p, tex %p) Work around for missing miptree in r100.\n", __func__, ctx, texObj); map_override(ctx, t); } /* for r100 3D sw fallbacks don't have mt */ if (!t->mt) { radeon_warning("%s(%p, tex %p) No miptree in texture.\n", __func__, ctx, texObj); return; } radeon_bo_map(t->mt->bo, GL_FALSE); for(face = 0; face < t->mt->faces; ++face) { for(level = t->minLod; level <= t->maxLod; ++level) teximage_set_map_data(get_radeon_texture_image(texObj->Image[face][level])); } }
/** * Update a subregion of the given texture image. */ static void radeon_store_teximage(GLcontext* ctx, int dims, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, GLenum format, GLenum type, const GLvoid * pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage, int compressed) { radeonContextPtr rmesa = RADEON_CONTEXT(ctx); radeonTexObj *t = radeon_tex_obj(texObj); radeon_texture_image* image = get_radeon_texture_image(texImage); GLuint dstRowStride; GLuint *dstImageOffsets; radeon_print(RADEON_TEXTURE, RADEON_TRACE, "%s(%p, tex %p, image %p) compressed %d\n", __func__, ctx, texObj, texImage, compressed); if (image->mt) { dstRowStride = image->mt->levels[image->mtlevel].rowstride; } else if (t->bo) { /* TFP case */ dstRowStride = get_texture_image_row_stride(rmesa, texImage->TexFormat, width, 0); } else { dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); } assert(dstRowStride); if (dims == 3) { unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat); dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, texImage->Height, texImage->Depth); if (!dstImageOffsets) { radeon_warning("%s Failed to allocate dstImaeOffset.\n", __func__); return; } } else { dstImageOffsets = texImage->ImageOffsets; } radeon_teximage_map(image, GL_TRUE); if (compressed) { uint32_t srcRowStride, bytesPerRow, rows, block_width, block_height; GLubyte *img_start; _mesa_get_format_block_size(texImage->TexFormat, &block_width, &block_height); if (!image->mt) { dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); img_start = _mesa_compressed_image_address(xoffset, yoffset, 0, texImage->TexFormat, texImage->Width, texImage->Data); } else { uint32_t offset; offset = dstRowStride / _mesa_get_format_bytes(texImage->TexFormat) * yoffset / block_height + xoffset / block_width; offset *= _mesa_get_format_bytes(texImage->TexFormat); img_start = texImage->Data + offset; } srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width); bytesPerRow = srcRowStride; rows = (height + block_height - 1) / block_height; copy_rows(img_start, dstRowStride, pixels, srcRowStride, rows, bytesPerRow); } else { if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat, texImage->TexFormat, texImage->Data, xoffset, yoffset, zoffset, dstRowStride, dstImageOffsets, width, height, depth, format, type, pixels, packing)) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage"); } } if (dims == 3) { free(dstImageOffsets); } radeon_teximage_unmap(image); }