i965: Move buffer texture size calculation into a common helper function.

The buffer texture size calculations (should be easy enough, right?)
are repeated in three different places, each of them subtly broken in
a different way.  E.g. the image load/store path was never fixed to
clamp to MaxTextureBufferSize, and none of them are taking into
account the buffer offset correctly.  It's easier to fix it all in one
place.

Cc: mesa-stable@lists.freedesktop.org
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106481
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
This commit is contained in:
Francisco Jerez 2018-03-16 13:06:26 -07:00
parent 5a68147803
commit 156d2c6e62
1 changed files with 32 additions and 23 deletions

View File

@ -639,26 +639,14 @@ brw_emit_buffer_surface_state(struct brw_context *brw,
.mocs = brw_get_bo_mocs(devinfo, bo));
}
void
brw_update_buffer_texture_surface(struct gl_context *ctx,
unsigned unit,
uint32_t *surf_offset)
static unsigned
buffer_texture_range_size(struct brw_context *brw,
struct gl_texture_object *obj)
{
struct brw_context *brw = brw_context(ctx);
struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;
struct intel_buffer_object *intel_obj =
intel_buffer_object(tObj->BufferObject);
uint32_t size = tObj->BufferSize;
struct brw_bo *bo = NULL;
mesa_format format = tObj->_BufferObjectFormat;
const enum isl_format isl_format = brw_isl_format_for_mesa_format(format);
int texel_size = _mesa_get_format_bytes(format);
if (intel_obj) {
size = MIN2(size, intel_obj->Base.Size);
bo = intel_bufferobj_buffer(brw, intel_obj, tObj->BufferOffset, size,
false);
}
assert(obj->Target == GL_TEXTURE_BUFFER);
const unsigned texel_size = _mesa_get_format_bytes(obj->_BufferObjectFormat);
const unsigned buffer_size = (!obj->BufferObject ? 0 :
obj->BufferObject->Size);
/* The ARB_texture_buffer_specification says:
*
@ -676,7 +664,28 @@ brw_update_buffer_texture_surface(struct gl_context *ctx,
* so that when ISL divides by stride to obtain the number of texels, that
* texel count is clamped to MAX_TEXTURE_BUFFER_SIZE.
*/
size = MIN2(size, ctx->Const.MaxTextureBufferSize * (unsigned) texel_size);
return MIN3((unsigned)obj->BufferSize, buffer_size,
brw->ctx.Const.MaxTextureBufferSize * texel_size);
}
void
brw_update_buffer_texture_surface(struct gl_context *ctx,
unsigned unit,
uint32_t *surf_offset)
{
struct brw_context *brw = brw_context(ctx);
struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;
struct intel_buffer_object *intel_obj =
intel_buffer_object(tObj->BufferObject);
const unsigned size = buffer_texture_range_size(brw, tObj);
struct brw_bo *bo = NULL;
mesa_format format = tObj->_BufferObjectFormat;
const enum isl_format isl_format = brw_isl_format_for_mesa_format(format);
int texel_size = _mesa_get_format_bytes(format);
if (intel_obj)
bo = intel_bufferobj_buffer(brw, intel_obj, tObj->BufferOffset, size,
false);
if (isl_format == ISL_FORMAT_UNSUPPORTED) {
_mesa_problem(NULL, "bad format %s for texture buffer\n",
@ -1477,8 +1486,7 @@ update_buffer_image_param(struct brw_context *brw,
unsigned surface_idx,
struct brw_image_param *param)
{
struct gl_buffer_object *obj = u->TexObj->BufferObject;
const uint32_t size = MIN2((uint32_t)u->TexObj->BufferSize, obj->Size);
const unsigned size = buffer_texture_range_size(brw, u->TexObj);
update_default_image_param(brw, u, surface_idx, param);
param->size[0] = size / _mesa_get_format_bytes(u->_ActualFormat);
@ -1514,10 +1522,11 @@ update_image_surface(struct brw_context *brw,
intel_buffer_object(obj->BufferObject);
const unsigned texel_size = (format == ISL_FORMAT_RAW ? 1 :
_mesa_get_format_bytes(u->_ActualFormat));
const unsigned buffer_size = buffer_texture_range_size(brw, obj);
brw_emit_buffer_surface_state(
brw, surf_offset, intel_obj->buffer, obj->BufferOffset,
format, intel_obj->Base.Size, texel_size,
format, buffer_size, texel_size,
access != GL_READ_ONLY ? RELOC_WRITE : 0);
update_buffer_image_param(brw, u, surface_idx, param);