From 7fcfa14c14396350aac984ec2dc42ba13c30c9b9 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 4 Jun 2011 12:48:54 +0100 Subject: [PATCH] i965: Limit the maximum texture size to fit inside a GTT mapping We have to presume the worst when advertising maximum textures size. And that is somebody will try to use the maximum size and cause us to try and mmap it into the GTT. If it is too big, then we fail the mapping and kill the application with a SIGBUS. Bugzilla: http://bugs.freedesktop.org/show_bug.cgi?id=37871 Signed-off-by: Chris Wilson --- configure.ac | 2 +- src/mesa/drivers/dri/i965/brw_context.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1e5f9ce..06e9359 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ AC_CANONICAL_HOST dnl Versions for external dependencies LIBDRM_REQUIRED=2.4.24 LIBDRM_RADEON_REQUIRED=2.4.24 -LIBDRM_INTEL_REQUIRED=2.4.24 +LIBDRM_INTEL_REQUIRED=2.4.26 LIBDRM_NOUVEAU_REQUIRED=0.6 DRI2PROTO_REQUIRED=2.1 GLPROTO_REQUIRED=1.4.11 diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 0256ab9..6172ca8 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -53,6 +53,34 @@ static void brwInitDriverFunctions( struct dd_function_table *functions ) brw_init_queryobj_functions(functions); } +static int brw_get_maximum_texture_level (struct brw_context *brw) +{ + size_t mappable, total; + int bpp_shift; + int level; + + /* We need to be able to mmap the texture through the GTT at all + * times, so we need to query the mappable aperture size and + * limit the texture size appropriately. + * + * An alternative approach would be to avoid GTT mmapping large + * surfaces, either through the use of a CPU map if unfenced or + * by blitting to a temporary and mmapping, then blitting back. + * That gets ugly really quick... + */ + drm_intel_get_aperture_sizes(brw->intel.driFd, &mappable, &total); + + /* Worst-case scenario is a 4x64bit floating point texture, however + * we don't support those yet, so presume for the time being that + * ARGB32 is the largest pixel size we need to handle. + */ + bpp_shift = 2; + for (level = 13; 1 << (2*level + bpp_shift) > mappable; level--) + ; + + return level; +} + GLboolean brwCreateContext( int api, const struct gl_config *mesaVis, __DRIcontext *driContextPriv, @@ -94,7 +122,7 @@ GLboolean brwCreateContext( int api, ctx->Const.MaxVertexTextureImageUnits + ctx->Const.MaxTextureImageUnits; - ctx->Const.MaxTextureLevels = 14; /* 8192 */ + ctx->Const.MaxTextureLevels = brw_get_maximum_texture_level(brw) + 1; if (ctx->Const.MaxTextureLevels > MAX_TEXTURE_LEVELS) ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; ctx->Const.Max3DTextureLevels = 9; -- 1.7.5.3