mesa: move around current texture object fetching

We have to validate the target before fetching the current texture
object. Move this so that it happens later.

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 22:07:17 -05:00
parent d814539c2b
commit df005c2a65

View File

@@ -2287,13 +2287,6 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
struct gl_renderbuffer *rb; struct gl_renderbuffer *rb;
GLenum rb_internal_format; GLenum rb_internal_format;
/* check target */
if (!legal_texsubimage_target(ctx, dimensions, target, false)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)",
dimensions, _mesa_enum_to_string(target));
return GL_TRUE;
}
/* level check */ /* level check */
if (level < 0 || level >= _mesa_max_texture_levels(ctx, target)) { if (level < 0 || level >= _mesa_max_texture_levels(ctx, target)) {
_mesa_error(ctx, GL_INVALID_VALUE, _mesa_error(ctx, GL_INVALID_VALUE,
@@ -3418,8 +3411,7 @@ egl_image_target_texture(struct gl_context *ctx,
(tex_storage && _mesa_has_EXT_EGL_image_storage(ctx)); (tex_storage && _mesa_has_EXT_EGL_image_storage(ctx));
break; break;
case GL_TEXTURE_EXTERNAL_OES: case GL_TEXTURE_EXTERNAL_OES:
valid_target = valid_target = _mesa_has_OES_EGL_image_external(ctx);
_mesa_is_gles(ctx) ? _mesa_has_OES_EGL_image_external(ctx) : false;
break; break;
default: default:
valid_target = false; valid_target = false;
@@ -3427,10 +3419,15 @@ egl_image_target_texture(struct gl_context *ctx,
} }
if (!valid_target) { if (!valid_target) {
_mesa_error(ctx, GL_INVALID_ENUM, "%s(target=%d)", caller, target); _mesa_error(ctx, tex_storage ? GL_INVALID_OPERATION : GL_INVALID_ENUM, "%s(target=%d)", caller, target);
return; return;
} }
if (!texObj)
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
if (!image || (ctx->Driver.ValidateEGLImage && if (!image || (ctx->Driver.ValidateEGLImage &&
!ctx->Driver.ValidateEGLImage(ctx, image))) { !ctx->Driver.ValidateEGLImage(ctx, image))) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(image=%p)", caller, image); _mesa_error(ctx, GL_INVALID_VALUE, "%s(image=%p)", caller, image);
@@ -3475,17 +3472,10 @@ egl_image_target_texture(struct gl_context *ctx,
void GLAPIENTRY void GLAPIENTRY
_mesa_EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) _mesa_EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
{ {
struct gl_texture_object *texObj;
const char *func = "glEGLImageTargetTexture2D"; const char *func = "glEGLImageTargetTexture2D";
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target); egl_image_target_texture(ctx, NULL, target, image, false, func);
if (!texObj) {
_mesa_error(ctx, GL_INVALID_ENUM, "%s(target=%d)", func, target);
return;
}
egl_image_target_texture(ctx, texObj, target, image, false, func);
} }
static void static void
@@ -3504,21 +3494,6 @@ egl_image_target_texture_storage(struct gl_context *ctx,
return; return;
} }
switch (target) {
case GL_TEXTURE_2D:
case GL_TEXTURE_EXTERNAL_OES:
break;
default:
/*
* The EXT_EGL_image_storage spec allows for many other targets besides
* GL_TEXTURE_2D and GL_TEXTURE_EXTERNAL_OES, however these are complicated
* to implement.
*/
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported target=%d)",
caller, target);
return;
}
egl_image_target_texture(ctx, texObj, target, image, true, caller); egl_image_target_texture(ctx, texObj, target, image, true, caller);
} }
@@ -3527,17 +3502,10 @@ void GLAPIENTRY
_mesa_EGLImageTargetTexStorageEXT(GLenum target, GLeglImageOES image, _mesa_EGLImageTargetTexStorageEXT(GLenum target, GLeglImageOES image,
const GLint *attrib_list) const GLint *attrib_list)
{ {
struct gl_texture_object *texObj;
const char *func = "glEGLImageTargetTexStorageEXT"; const char *func = "glEGLImageTargetTexStorageEXT";
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target); egl_image_target_texture_storage(ctx, NULL, target, image, attrib_list,
if (!texObj) {
_mesa_error(ctx, GL_INVALID_ENUM, "%s(target=%d)", func, target);
return;
}
egl_image_target_texture_storage(ctx, texObj, target, image, attrib_list,
func); func);
} }
@@ -4323,6 +4291,16 @@ copyteximage(struct gl_context *ctx, GLuint dims, struct gl_texture_object *texO
if (ctx->NewState & _NEW_BUFFERS) if (ctx->NewState & _NEW_BUFFERS)
_mesa_update_state(ctx); _mesa_update_state(ctx);
/* check target */
if (!no_error && !legal_texsubimage_target(ctx, dims, target, false)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%uD(target=%s)",
dims, _mesa_enum_to_string(target));
return;
}
if (!texObj)
texObj = _mesa_get_current_tex_object(ctx, target);
if (!no_error) { if (!no_error) {
if (copytexture_error_check(ctx, dims, target, texObj, level, if (copytexture_error_check(ctx, dims, target, texObj, level,
internalFormat, border)) internalFormat, border))
@@ -4470,8 +4448,7 @@ copyteximage_err(struct gl_context *ctx, GLuint dims,
GLint level, GLenum internalFormat, GLint x, GLint y, GLint level, GLenum internalFormat, GLint x, GLint y,
GLsizei width, GLsizei height, GLint border) GLsizei width, GLsizei height, GLint border)
{ {
struct gl_texture_object* texObj = _mesa_get_current_tex_object(ctx, target); copyteximage(ctx, dims, NULL, target, level, internalFormat, x, y, width, height,
copyteximage(ctx, dims, texObj, target, level, internalFormat, x, y, width, height,
border, false); border, false);
} }
@@ -4481,8 +4458,7 @@ copyteximage_no_error(struct gl_context *ctx, GLuint dims, GLenum target,
GLint level, GLenum internalFormat, GLint x, GLint y, GLint level, GLenum internalFormat, GLint x, GLint y,
GLsizei width, GLsizei height, GLint border) GLsizei width, GLsizei height, GLint border)
{ {
struct gl_texture_object* texObj = _mesa_get_current_tex_object(ctx, target); copyteximage(ctx, dims, NULL, target, level, internalFormat, x, y, width, height,
copyteximage(ctx, dims, texObj, target, level, internalFormat, x, y, width, height,
border, true); border, true);
} }
@@ -6843,7 +6819,13 @@ texture_image_multisample(struct gl_context *ctx, GLuint dims,
return; return;
} }
if (immutable && (!texObj || (texObj->Name == 0))) { if (!texObj) {
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
}
if (immutable && texObj->Name == 0) {
_mesa_error(ctx, GL_INVALID_OPERATION, _mesa_error(ctx, GL_INVALID_OPERATION,
"%s(texture object 0)", "%s(texture object 0)",
func); func);
@@ -6942,14 +6924,9 @@ _mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
GLenum internalformat, GLsizei width, GLenum internalformat, GLsizei width,
GLsizei height, GLboolean fixedsamplelocations) GLsizei height, GLboolean fixedsamplelocations)
{ {
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target); texture_image_multisample(ctx, 2, NULL, NULL, target, samples,
if (!texObj)
return;
texture_image_multisample(ctx, 2, texObj, NULL, target, samples,
internalformat, width, height, 1, internalformat, width, height, 1,
fixedsamplelocations, GL_FALSE, 0, fixedsamplelocations, GL_FALSE, 0,
"glTexImage2DMultisample"); "glTexImage2DMultisample");
@@ -6962,14 +6939,9 @@ _mesa_TexImage3DMultisample(GLenum target, GLsizei samples,
GLsizei height, GLsizei depth, GLsizei height, GLsizei depth,
GLboolean fixedsamplelocations) GLboolean fixedsamplelocations)
{ {
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target); texture_image_multisample(ctx, 3, NULL, NULL, target, samples,
if (!texObj)
return;
texture_image_multisample(ctx, 3, texObj, NULL, target, samples,
internalformat, width, height, depth, internalformat, width, height, depth,
fixedsamplelocations, GL_FALSE, 0, fixedsamplelocations, GL_FALSE, 0,
"glTexImage3DMultisample"); "glTexImage3DMultisample");
@@ -6995,17 +6967,12 @@ _mesa_TexStorage2DMultisample(GLenum target, GLsizei samples,
GLenum internalformat, GLsizei width, GLenum internalformat, GLsizei width,
GLsizei height, GLboolean fixedsamplelocations) GLsizei height, GLboolean fixedsamplelocations)
{ {
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
if (!valid_texstorage_ms_parameters(width, height, 1, 2)) if (!valid_texstorage_ms_parameters(width, height, 1, 2))
return; return;
texture_image_multisample(ctx, 2, texObj, NULL, target, samples, texture_image_multisample(ctx, 2, NULL, NULL, target, samples,
internalformat, width, height, 1, internalformat, width, height, 1,
fixedsamplelocations, GL_TRUE, 0, fixedsamplelocations, GL_TRUE, 0,
"glTexStorage2DMultisample"); "glTexStorage2DMultisample");
@@ -7017,17 +6984,12 @@ _mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
GLsizei height, GLsizei depth, GLsizei height, GLsizei depth,
GLboolean fixedsamplelocations) GLboolean fixedsamplelocations)
{ {
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
if (!valid_texstorage_ms_parameters(width, height, depth, 3)) if (!valid_texstorage_ms_parameters(width, height, depth, 3))
return; return;
texture_image_multisample(ctx, 3, texObj, NULL, target, samples, texture_image_multisample(ctx, 3, NULL, NULL, target, samples,
internalformat, width, height, depth, internalformat, width, height, depth,
fixedsamplelocations, GL_TRUE, 0, fixedsamplelocations, GL_TRUE, 0,
"glTexStorage3DMultisample"); "glTexStorage3DMultisample");