mesa: check target/format for Tex(ture)StorageMem*

Noticed while doing an audit around _mesa_get_current_tex usage.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Acked-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13767>
This commit is contained in:
Ilia Mirkin 2021-11-11 21:47:15 -05:00
parent f659d00000
commit d814539c2b
3 changed files with 41 additions and 5 deletions

View file

@ -25,6 +25,7 @@
#include "mtypes.h"
#include "bufferobj.h"
#include "context.h"
#include "enums.h"
#include "externalobjects.h"
#include "teximage.h"
#include "texobj.h"
@ -302,6 +303,21 @@ texstorage_memory(GLuint dims, GLenum target, GLsizei levels,
return;
}
if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"%s(illegal target=%s)",
func, _mesa_enum_to_string(target));
return;
}
/* Check the format to make sure it is sized. */
if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"%s(internalformat = %s)", func,
_mesa_enum_to_string(internalFormat));
return;
}
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@ -363,10 +379,25 @@ texturestorage_memory(GLuint dims, GLuint texture, GLsizei levels,
return;
}
/* Check the format to make sure it is sized. */
if (!_mesa_is_legal_tex_storage_format(ctx, internalFormat)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"%s(internalformat = %s)", func,
_mesa_enum_to_string(internalFormat));
return;
}
texObj = _mesa_lookup_texture(ctx, texture);
if (!texObj)
return;
if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(illegal target=%s)", func,
_mesa_enum_to_string(texObj->Target));
return;
}
memObj = lookup_memory_object_err(ctx, memory, func);
if (!memObj)
return;

View file

@ -48,11 +48,12 @@
* This is a bit different than legal_teximage_target() when it comes
* to cube maps.
*/
static bool
legal_texobj_target(const struct gl_context *ctx, GLuint dims, GLenum target)
bool
_mesa_is_legal_tex_storage_target(const struct gl_context *ctx,
GLuint dims, GLenum target)
{
if (dims < 1 || dims > 3) {
_mesa_problem(ctx, "invalid dims=%u in legal_texobj_target()", dims);
_mesa_problem(ctx, "invalid dims=%u in _mesa_is_legal_tex_storage_target()", dims);
return false;
}
@ -530,7 +531,7 @@ texstorage_error(GLuint dims, GLenum target, GLsizei levels,
/* Check target. This is done here so that texture_storage
* can receive unsized formats.
*/
if (!legal_texobj_target(ctx, dims, target)) {
if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"%s(illegal target=%s)",
caller, _mesa_enum_to_string(target));
@ -605,7 +606,7 @@ texturestorage_error(GLuint dims, GLuint texture, GLsizei levels,
/* Check target. This is done here so that texture_storage
* can receive unsized formats.
*/
if (!legal_texobj_target(ctx, dims, texObj->Target)) {
if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(illegal target=%s)", caller,
_mesa_enum_to_string(texObj->Target));

View file

@ -131,6 +131,10 @@ extern GLboolean
_mesa_is_legal_tex_storage_format(const struct gl_context *ctx,
GLenum internalformat);
extern bool
_mesa_is_legal_tex_storage_target(const struct gl_context *ctx,
GLuint dims, GLenum target);
extern GLboolean
_mesa_AllocTextureStorage_sw(struct gl_context *ctx,
struct gl_texture_object *texObj,