mesa: Add support for binding a buffer texture to a shader image unit.

Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Francisco Jerez 2014-11-14 20:31:13 +02:00
parent 8424cafbac
commit f74ba58f84

View file

@ -335,7 +335,7 @@ static GLboolean
validate_image_unit(struct gl_context *ctx, struct gl_image_unit *u)
{
struct gl_texture_object *t = u->TexObj;
struct gl_texture_image *img;
mesa_format tex_format;
if (!t || u->Level < t->BaseLevel ||
u->Level > t->_MaxLevel)
@ -351,25 +351,32 @@ validate_image_unit(struct gl_context *ctx, struct gl_image_unit *u)
u->Layer >= _mesa_get_texture_layers(t, u->Level))
return GL_FALSE;
if (t->Target == GL_TEXTURE_CUBE_MAP)
img = t->Image[u->Layer][u->Level];
else
img = t->Image[0][u->Level];
if (t->Target == GL_TEXTURE_BUFFER) {
tex_format = t->_BufferObjectFormat;
if (!img || img->Border ||
get_image_format_class(img->TexFormat) == IMAGE_FORMAT_CLASS_NONE ||
img->NumSamples > ctx->Const.MaxImageSamples)
} else {
struct gl_texture_image *img = (t->Target == GL_TEXTURE_CUBE_MAP ?
t->Image[u->Layer][u->Level] :
t->Image[0][u->Level]);
if (!img || img->Border || img->NumSamples > ctx->Const.MaxImageSamples)
return GL_FALSE;
tex_format = img->TexFormat;
}
if (get_image_format_class(tex_format) == IMAGE_FORMAT_CLASS_NONE)
return GL_FALSE;
switch (t->ImageFormatCompatibilityType) {
case GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE:
if (_mesa_get_format_bytes(img->TexFormat) !=
if (_mesa_get_format_bytes(tex_format) !=
_mesa_get_format_bytes(u->_ActualFormat))
return GL_FALSE;
break;
case GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS:
if (get_image_format_class(img->TexFormat) !=
if (get_image_format_class(tex_format) !=
get_image_format_class(u->_ActualFormat))
return GL_FALSE;
break;
@ -535,8 +542,7 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures)
if (texture != 0) {
struct gl_texture_object *texObj;
struct gl_texture_image *image;
mesa_format actualFormat;
GLenum tex_format;
if (!u->TexObj || u->TexObj->Name != texture) {
texObj = _mesa_lookup_texture_locked(ctx, texture);
@ -557,25 +563,30 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures)
texObj = u->TexObj;
}
image = texObj->Image[0][0];
if (texObj->Target == GL_TEXTURE_BUFFER) {
tex_format = texObj->BufferObjectFormat;
} else {
struct gl_texture_image *image = texObj->Image[0][0];
if (!image || image->Width == 0 || image->Height == 0 || image->Depth == 0) {
/* The ARB_multi_bind spec says:
*
* "An INVALID_OPERATION error is generated if the width,
* height, or depth of the level zero texture image of
* any texture in <textures> is zero (per binding)."
*/
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBindImageTextures(the width, height or depth "
"of the level zero texture image of "
"textures[%d]=%u is zero)", i, texture);
continue;
if (!image || image->Width == 0 || image->Height == 0 ||
image->Depth == 0) {
/* The ARB_multi_bind spec says:
*
* "An INVALID_OPERATION error is generated if the width,
* height, or depth of the level zero texture image of
* any texture in <textures> is zero (per binding)."
*/
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBindImageTextures(the width, height or depth "
"of the level zero texture image of "
"textures[%d]=%u is zero)", i, texture);
continue;
}
tex_format = image->InternalFormat;
}
actualFormat = _mesa_get_shader_image_format(image->InternalFormat);
if (actualFormat == MESA_FORMAT_NONE) {
if (_mesa_get_shader_image_format(tex_format) == MESA_FORMAT_NONE) {
/* The ARB_multi_bind spec says:
*
* "An INVALID_OPERATION error is generated if the internal
@ -586,7 +597,7 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures)
"glBindImageTextures(the internal format %s of "
"the level zero texture image of textures[%d]=%u "
"is not supported)",
_mesa_lookup_enum_by_nr(image->InternalFormat),
_mesa_lookup_enum_by_nr(tex_format),
i, texture);
continue;
}
@ -597,8 +608,8 @@ _mesa_BindImageTextures(GLuint first, GLsizei count, const GLuint *textures)
u->Layered = _mesa_tex_target_is_layered(texObj->Target);
u->Layer = 0;
u->Access = GL_READ_WRITE;
u->Format = image->InternalFormat;
u->_ActualFormat = actualFormat;
u->Format = tex_format;
u->_ActualFormat = _mesa_get_shader_image_format(tex_format);
u->_Valid = validate_image_unit(ctx, u);
} else {
/* Unbind the texture from the unit */