Commit f33cb272 authored by Eric Anholt's avatar Eric Anholt

mesa: Replace MaxTextureLevels with MaxTextureSize.

In most places (glGetInteger, max_legal_texture_dimensions), we wanted the
number of pixels, not the number of levels.  Number of levels is easily
recovered with util_next_power_of_two() and ffs().  More importantly, for
V3D we want to be able to expose a non-power-of-two maximum texture size
to cover 2x4k displays on HW that can't quite do 8192 wide.
Reviewed-by: default avatarMarek Olšák <marek.olsak@amd.com>
parent ce6dbc04
......@@ -1245,7 +1245,7 @@ init_temp_texture(struct gl_context *ctx, struct temp_texture *tex)
else {
/* use 2D texture, NPOT if possible */
tex->Target = GL_TEXTURE_2D;
tex->MaxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
tex->MaxSize = ctx->Const.MaxTextureSize;
tex->NPOT = ctx->Extensions.ARB_texture_non_power_of_two;
}
tex->MinSize = 16; /* 16 x 16 at least */
......
......@@ -104,7 +104,7 @@ i830CreateContext(int api,
/* Advertise the full hardware capabilities. The new memory
* manager should cope much better with overload situations:
*/
ctx->Const.MaxTextureLevels = 12;
ctx->Const.MaxTextureSize = 2048;
ctx->Const.Max3DTextureLevels = 9;
ctx->Const.MaxCubeTextureLevels = 11;
ctx->Const.MaxTextureRectSize = (1 << 11);
......
......@@ -214,7 +214,7 @@ i915CreateContext(int api,
/* Advertise the full hardware capabilities. The new memory
* manager should cope much better with overload situations:
*/
ctx->Const.MaxTextureLevels = 12;
ctx->Const.MaxTextureSize = 2048;
ctx->Const.Max3DTextureLevels = 9;
ctx->Const.MaxCubeTextureLevels = 12;
ctx->Const.MaxTextureRectSize = (1 << 11);
......
......@@ -477,11 +477,11 @@ brw_initialize_context_constants(struct brw_context *brw)
ctx->Const.MaxImageUnits = MAX_IMAGE_UNITS;
if (devinfo->gen >= 7) {
ctx->Const.MaxRenderbufferSize = 16384;
ctx->Const.MaxTextureLevels = MIN2(15 /* 16384 */, MAX_TEXTURE_LEVELS);
ctx->Const.MaxTextureSize = 16384;
ctx->Const.MaxCubeTextureLevels = 15; /* 16384 */
} else {
ctx->Const.MaxRenderbufferSize = 8192;
ctx->Const.MaxTextureLevels = MIN2(14 /* 8192 */, MAX_TEXTURE_LEVELS);
ctx->Const.MaxTextureSize = 8192;
ctx->Const.MaxCubeTextureLevels = 14; /* 8192 */
}
ctx->Const.Max3DTextureLevels = 12; /* 2048 */
......
......@@ -157,7 +157,7 @@ nv04_context_create(struct nouveau_screen *screen, gl_api api,
goto fail;
/* GL constants. */
ctx->Const.MaxTextureLevels = 11;
ctx->Const.MaxTextureSize = 1024;
ctx->Const.MaxTextureCoordUnits = NV04_TEXTURE_UNITS;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = NV04_TEXTURE_UNITS;
ctx->Const.MaxTextureUnits = NV04_TEXTURE_UNITS;
......
......@@ -455,7 +455,7 @@ nv10_context_create(struct nouveau_screen *screen, gl_api api,
ctx->Extensions.ANGLE_texture_compression_dxt = true;
/* GL constants. */
ctx->Const.MaxTextureLevels = 12;
ctx->Const.MaxTextureSize = 2048;
ctx->Const.MaxTextureCoordUnits = NV10_TEXTURE_UNITS;
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = NV10_TEXTURE_UNITS;
ctx->Const.MaxTextureUnits = NV10_TEXTURE_UNITS;
......
......@@ -268,7 +268,7 @@ GLboolean r200CreateContext( gl_api api,
/* FIXME: When no memory manager is available we should set this
* to some reasonable value based on texture memory pool size */
ctx->Const.MaxTextureLevels = 12;
ctx->Const.MaxTextureSize = 2048;
ctx->Const.Max3DTextureLevels = 9;
ctx->Const.MaxCubeTextureLevels = 12;
ctx->Const.MaxTextureRectSize = 2048;
......
......@@ -230,7 +230,7 @@ r100CreateContext( gl_api api,
/* FIXME: When no memory manager is available we should set this
* to some reasonable value based on texture memory pool size */
ctx->Const.MaxTextureLevels = 12;
ctx->Const.MaxTextureSize = 2048;
ctx->Const.Max3DTextureLevels = 9;
ctx->Const.MaxCubeTextureLevels = 12;
ctx->Const.MaxTextureRectSize = 2048;
......
......@@ -150,7 +150,7 @@ static void calculate_miptree_layout(radeonContextPtr rmesa, radeon_mipmap_tree
{
GLuint curOffset, i, face, level;
assert(mt->numLevels <= rmesa->glCtx.Const.MaxTextureLevels);
assert(1 << (mt->numLevels - 1) <= rmesa->glCtx.Const.MaxTextureSize);
curOffset = 0;
for(face = 0; face < mt->faces; face++) {
......
......@@ -555,7 +555,7 @@ _mesa_init_constants(struct gl_constants *consts, gl_api api)
/* Constants, may be overriden (usually only reduced) by device drivers */
consts->MaxTextureMbytes = MAX_TEXTURE_MBYTES;
consts->MaxTextureLevels = MAX_TEXTURE_LEVELS;
consts->MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
consts->Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
consts->MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
consts->MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
......@@ -782,7 +782,7 @@ check_context_limits(struct gl_context *ctx)
/* Texture size checks */
assert(ctx->Const.MaxTextureLevels <= MAX_TEXTURE_LEVELS);
assert(ctx->Const.MaxTextureSize <= (1 << (MAX_TEXTURE_LEVELS - 1)));
assert(ctx->Const.Max3DTextureLevels <= MAX_3D_TEXTURE_LEVELS);
assert(ctx->Const.MaxCubeTextureLevels <= MAX_CUBE_TEXTURE_LEVELS);
assert(ctx->Const.MaxTextureRectSize <= MAX_TEXTURE_RECT_SIZE);
......@@ -792,10 +792,8 @@ check_context_limits(struct gl_context *ctx)
assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
/* Max texture size should be <= max viewport size (render to texture) */
assert((1U << (ctx->Const.MaxTextureLevels - 1))
<= ctx->Const.MaxViewportWidth);
assert((1U << (ctx->Const.MaxTextureLevels - 1))
<= ctx->Const.MaxViewportHeight);
assert(ctx->Const.MaxTextureSize <= ctx->Const.MaxViewportWidth);
assert(ctx->Const.MaxTextureSize <= ctx->Const.MaxViewportHeight);
assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
......
......@@ -21,7 +21,7 @@ descriptor=[
[ "ALIASED_LINE_WIDTH_RANGE", "CONTEXT_FLOAT2(Const.MinLineWidth), NO_EXTRA" ],
[ "MAX_ELEMENTS_VERTICES", "CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA" ],
[ "MAX_ELEMENTS_INDICES", "CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA" ],
[ "MAX_TEXTURE_SIZE", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_context, Const.MaxTextureLevels), NO_EXTRA" ],
[ "MAX_TEXTURE_SIZE", "CONTEXT_INT(Const.MaxTextureSize), NO_EXTRA" ],
[ "MAX_VIEWPORT_DIMS", "CONTEXT_INT2(Const.MaxViewportWidth), NO_EXTRA" ],
[ "PACK_ALIGNMENT", "CONTEXT_INT(Pack.Alignment), NO_EXTRA" ],
[ "ALIASED_POINT_SIZE_RANGE", "CONTEXT_FLOAT2(Const.MinPointSize), NO_EXTRA" ],
......
......@@ -3654,7 +3654,7 @@ struct gl_program_constants
struct gl_constants
{
GLuint MaxTextureMbytes; /**< Max memory per image, in MB */
GLuint MaxTextureLevels; /**< Max mipmap levels. */
GLuint MaxTextureSize; /**< Max 1D/2D texture size, in pixels*/
GLuint Max3DTextureLevels; /**< Max mipmap levels for 3D textures */
GLuint MaxCubeTextureLevels; /**< Max mipmap levels for cube textures */
GLuint MaxArrayTextureLayers; /**< Max layers in array textures */
......
......@@ -492,7 +492,7 @@ _mesa_max_texture_levels(const struct gl_context *ctx, GLenum target)
case GL_PROXY_TEXTURE_1D:
case GL_TEXTURE_2D:
case GL_PROXY_TEXTURE_2D:
return ctx->Const.MaxTextureLevels;
return ffs(util_next_power_of_two(ctx->Const.MaxTextureSize));
case GL_TEXTURE_3D:
case GL_PROXY_TEXTURE_3D:
return ctx->Const.Max3DTextureLevels;
......@@ -514,7 +514,7 @@ _mesa_max_texture_levels(const struct gl_context *ctx, GLenum target)
case GL_TEXTURE_2D_ARRAY_EXT:
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
return ctx->Extensions.EXT_texture_array
? ctx->Const.MaxTextureLevels : 0;
? ffs(util_next_power_of_two(ctx->Const.MaxTextureSize)) : 0;
case GL_TEXTURE_CUBE_MAP_ARRAY:
case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
return _mesa_has_texture_cube_map_array(ctx)
......@@ -973,8 +973,7 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
switch (target) {
case GL_TEXTURE_1D:
case GL_PROXY_TEXTURE_1D:
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1); /* level zero size */
maxSize >>= level; /* level size */
maxSize = ctx->Const.MaxTextureSize >> level;
if (width < 2 * border || width > 2 * border + maxSize)
return GL_FALSE;
if (!ctx->Extensions.ARB_texture_non_power_of_two) {
......@@ -987,8 +986,7 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
case GL_PROXY_TEXTURE_2D:
case GL_TEXTURE_2D_MULTISAMPLE:
case GL_PROXY_TEXTURE_2D_MULTISAMPLE:
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
maxSize >>= level;
maxSize = ctx->Const.MaxTextureSize >> level;
if (width < 2 * border || width > 2 * border + maxSize)
return GL_FALSE;
if (height < 2 * border || height > 2 * border + maxSize)
......@@ -1058,8 +1056,7 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
case GL_TEXTURE_1D_ARRAY_EXT:
case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
maxSize >>= level;
maxSize = ctx->Const.MaxTextureSize >> level;
if (width < 2 * border || width > 2 * border + maxSize)
return GL_FALSE;
if (height < 0 || height > ctx->Const.MaxArrayTextureLayers)
......@@ -1074,8 +1071,7 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY:
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
maxSize >>= level;
maxSize = ctx->Const.MaxTextureSize >> level;
if (width < 2 * border || width > 2 * border + maxSize)
return GL_FALSE;
if (height < 2 * border || height > 2 * border + maxSize)
......
......@@ -84,9 +84,11 @@ void st_init_limits(struct pipe_screen *screen,
bool can_ubo = true;
int temp;
c->MaxTextureLevels
= _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
MAX_TEXTURE_LEVELS);
int max_texture_levels =
_min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
MAX_TEXTURE_LEVELS);
c->MaxTextureSize = 1 << (max_texture_levels - 1);
c->Max3DTextureLevels
= _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
......@@ -96,8 +98,7 @@ void st_init_limits(struct pipe_screen *screen,
= _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
MAX_CUBE_TEXTURE_LEVELS);
c->MaxTextureRectSize
= _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
c->MaxTextureRectSize = _min(c->MaxTextureSize, MAX_TEXTURE_RECT_SIZE);
c->MaxArrayTextureLayers
= screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
......
......@@ -728,7 +728,7 @@ _swrast_CreateContext( struct gl_context *ctx )
assert(ctx->Const.MaxRenderbufferSize <= SWRAST_MAX_WIDTH);
/* make sure largest texture image is <= SWRAST_MAX_WIDTH in size */
assert((1 << (ctx->Const.MaxTextureLevels - 1)) <= SWRAST_MAX_WIDTH);
assert(ctx->Const.MaxTextureSize <= SWRAST_MAX_WIDTH);
assert((1 << (ctx->Const.MaxCubeTextureLevels - 1)) <= SWRAST_MAX_WIDTH);
assert((1 << (ctx->Const.Max3DTextureLevels - 1)) <= SWRAST_MAX_WIDTH);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment