summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancisco Jerez <currojerez@riseup.net>2018-03-16 13:06:26 -0700
committerFrancisco Jerez <currojerez@riseup.net>2018-05-23 16:21:09 -0700
commit156d2c6e621d836c4d45c636b87669e1de3d4464 (patch)
treebbf27610aa13485c881897312c5f21a32bbe05ae
parent5a6814780322988a7adee525899bca8a83907ab7 (diff)
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>
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_surface_state.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index 67438b0f7e3..af629a17bfa 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -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);