intel: Restructure TexSubImage as just the 2D implementation and blit func.

Fixes a segfault in piglit copyteximage where I accidentally removed
the dst_bo setup in the previous cleanup.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40474
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Tested-by: Sean McNamara <gm.potato.ul@gmail.com>
Tested-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Eric Anholt
2011-08-30 10:31:41 -07:00
parent b26a08402f
commit 0b96b3ffa9
+106 -92
View File
@@ -40,112 +40,121 @@
#define FILE_DEBUG_FLAG DEBUG_TEXTURE
static void
intelTexSubimage(struct gl_context * ctx,
GLint dims,
GLenum target, GLint level,
GLint xoffset, GLint yoffset, GLint zoffset,
GLint width, GLint height, GLint depth,
GLsizei imageSize,
GLenum format, GLenum type, const void *pixels,
const struct gl_pixelstore_attrib *packing,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
static bool
intel_blit_texsubimage(struct gl_context * ctx,
GLenum target, GLint level,
GLint xoffset, GLint yoffset,
GLint width, GLint height,
GLenum format, GLenum type, const void *pixels,
const struct gl_pixelstore_attrib *packing,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
struct intel_context *intel = intel_context(ctx);
struct intel_texture_image *intelImage = intel_texture_image(texImage);
GLuint dstRowStride = 0;
drm_intel_bo *temp_bo = NULL, *dst_bo = NULL;
unsigned int blit_x = 0, blit_y = 0;
unsigned long pitch;
uint32_t tiling_mode = I915_TILING_NONE;
/* Try to do a blit upload of the subimage if the texture is
* currently busy.
*/
if (intelImage->mt &&
intelImage->mt->region->tiling != I915_TILING_Y &&
intel->gen < 6 && target == GL_TEXTURE_2D &&
drm_intel_bo_busy(dst_bo)) {
unsigned long pitch;
uint32_t tiling_mode = I915_TILING_NONE;
if (!intelImage->mt)
return false;
DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
__FUNCTION__,
_mesa_lookup_enum_by_nr(target),
level, xoffset, yoffset, width, height);
/* The blitter can't handle Y tiling */
if (intelImage->mt->region->tiling == I915_TILING_Y)
return false;
pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
format, type, pixels, packing,
"glTexSubImage");
if (!pixels)
return;
if (target != GL_TEXTURE_2D)
return false;
temp_bo = drm_intel_bo_alloc_tiled(intel->bufmgr,
"subimage blit bo",
width, height,
intelImage->mt->cpp,
&tiling_mode,
&pitch,
0);
if (temp_bo == NULL) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
return;
}
/* On gen6, it's probably not worth swapping to the blit ring to do
* this because of all the overhead involved.
*/
if (intel->gen >= 6)
return false;
if (drm_intel_gem_bo_map_gtt(temp_bo)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
return;
}
dst_bo = intel_region_buffer(intel, intelImage->mt->region,
INTEL_WRITE_PART);
texImage->Data = temp_bo->virtual;
texImage->ImageOffsets[0] = 0;
dstRowStride = pitch;
if (!drm_intel_bo_busy(dst_bo))
return false;
intel_miptree_get_image_offset(intelImage->mt, level,
intelImage->base.Face, 0,
&blit_x, &blit_y);
blit_x += xoffset;
blit_y += yoffset;
xoffset = 0;
yoffset = 0;
DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
__FUNCTION__,
_mesa_lookup_enum_by_nr(target),
level, xoffset, yoffset, width, height);
if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
texImage->TexFormat,
texImage->Data,
xoffset, yoffset, zoffset,
dstRowStride,
texImage->ImageOffsets,
width, height, depth,
format, type, pixels, packing)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
}
pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1,
format, type, pixels, packing,
"glTexSubImage");
if (!pixels)
return false;
GLboolean ret;
unsigned int dst_pitch = intelImage->mt->region->pitch *
intelImage->mt->cpp;
drm_intel_gem_bo_unmap_gtt(temp_bo);
texImage->Data = NULL;
ret = intelEmitCopyBlit(intel,
intelImage->mt->cpp,
dstRowStride / intelImage->mt->cpp,
temp_bo, 0, GL_FALSE,
dst_pitch / intelImage->mt->cpp, dst_bo, 0,
intelImage->mt->region->tiling,
0, 0, blit_x, blit_y, width, height,
GL_COPY);
assert(ret);
drm_intel_bo_unreference(temp_bo);
_mesa_unmap_teximage_pbo(ctx, packing);
return;
temp_bo = drm_intel_bo_alloc_tiled(intel->bufmgr,
"subimage blit bo",
width, height,
intelImage->mt->cpp,
&tiling_mode,
&pitch,
0);
if (temp_bo == NULL) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
return false;
}
_mesa_store_texsubimage3d(ctx, target, level,
xoffset, yoffset, zoffset,
width, height, depth,
format, type, pixels,
packing, texObj, texImage);
if (drm_intel_gem_bo_map_gtt(temp_bo)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
return false;
}
texImage->Data = temp_bo->virtual;
texImage->ImageOffsets[0] = 0;
dstRowStride = pitch;
intel_miptree_get_image_offset(intelImage->mt, level,
intelImage->base.Face, 0,
&blit_x, &blit_y);
blit_x += xoffset;
blit_y += yoffset;
xoffset = 0;
yoffset = 0;
if (!_mesa_texstore(ctx, 2, texImage->_BaseFormat,
texImage->TexFormat,
texImage->Data,
xoffset, yoffset, 0,
dstRowStride,
texImage->ImageOffsets,
width, height, 1,
format, type, pixels, packing)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
}
GLboolean ret;
unsigned int dst_pitch = intelImage->mt->region->pitch *
intelImage->mt->cpp;
drm_intel_gem_bo_unmap_gtt(temp_bo);
texImage->Data = NULL;
ret = intelEmitCopyBlit(intel,
intelImage->mt->cpp,
dstRowStride / intelImage->mt->cpp,
temp_bo, 0, GL_FALSE,
dst_pitch / intelImage->mt->cpp, dst_bo, 0,
intelImage->mt->region->tiling,
0, 0, blit_x, blit_y, width, height,
GL_COPY);
assert(ret);
drm_intel_bo_unreference(temp_bo);
_mesa_unmap_teximage_pbo(ctx, packing);
return true;
}
static void
@@ -160,14 +169,19 @@ intelTexSubImage2D(struct gl_context * ctx,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
intelTexSubimage(ctx, 2,
target, level,
xoffset, yoffset, 0,
width, height, 1, 0,
format, type, pixels, packing, texObj, texImage);
if (!intel_blit_texsubimage(ctx, target, level,
xoffset, yoffset,
width, height,
format, type, pixels, packing,
texObj, texImage)) {
_mesa_store_texsubimage2d(ctx, target, level,
xoffset, yoffset,
width, height,
format, type, pixels,
packing, texObj, texImage);
}
}
void
intelInitTextureSubImageFuncs(struct dd_function_table *functions)
{