*/
unsigned stride_override;
- /* Total size of this texture, in bytes. */
+ /* Total size of this texture, in bytes,
+ * derived from the texture properties. */
unsigned size;
+ /* Total size of the buffer backing this texture, in bytes.
+ * It must be >= size. */
+ unsigned buffer_size;
+
/* Whether this texture has non-power-of-two dimensions
* or a user-specified pitch.
* It can be either a regular texture or a rectangle one.
tex->buffer = rws->buffer_create(rws, tex->size, 2048, base->bind,
base->usage, tex->domain);
+ tex->buffer_size = tex->size;
if (!tex->buffer) {
FREE(tex);
struct r300_screen* rscreen = r300_screen(screen);
struct r300_winsys_buffer *buffer;
struct r300_texture* tex;
- unsigned stride;
+ unsigned stride, size;
boolean override_zb_flags;
/* Support only 2D textures without mipmaps */
return NULL;
}
- buffer = rws->buffer_from_handle(rws, whandle, &stride);
+ buffer = rws->buffer_from_handle(rws, whandle, &stride, &size);
if (!buffer) {
return NULL;
}
/* one ref already taken */
tex->buffer = buffer;
+ tex->buffer_size = size;
rws->buffer_get_tiling(rws, buffer, &tex->microtile, &tex->macrotile);
r300_setup_flags(tex);
tex->pitch[0] * util_format_get_blocksize(tex->b.b.format));
}
- if (SCREEN_DBG_ON(rscreen, DBG_TEX))
+ /* Make sure the buffer we got is large enough. */
+ if (tex->size > tex->buffer_size) {
+ fprintf(stderr, "r300: texture_from_handle: The buffer is not "
+ "large enough. Got: %i, Need: %i, Info:\n",
+ tex->buffer_size, tex->size);
r300_tex_print_info(rscreen, tex, "texture_from_handle");
+ pipe_resource_reference((struct pipe_resource**)&tex, NULL);
+ return NULL;
+ } else {
+ if (SCREEN_DBG_ON(rscreen, DBG_TEX))
+ r300_tex_print_info(rscreen, tex, "texture_from_handle");
+ }
return (struct pipe_resource*)tex;
}
* \param ws The winsys this function is called from.
* \param whandle A winsys handle pointer as was received from a state
* tracker.
- * \param stride A pointer to the stride return variable.
- * The stride is in bytes.
+ * \param stride The returned buffer stride in bytes.
+ * \param size The returned buffer size.
*/
struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *ws,
struct winsys_handle *whandle,
- unsigned *stride);
+ unsigned *stride,
+ unsigned *size);
/**
* Get a winsys handle from a winsys buffer. The internal structure
static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws,
struct winsys_handle *whandle,
- unsigned *stride)
+ unsigned *stride,
+ unsigned *size)
{
struct radeon_libdrm_winsys *ws = radeon_libdrm_winsys(rws);
struct pb_buffer *_buf;
- *stride = whandle->stride;
-
_buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle);
+
+ if (stride)
+ *stride = whandle->stride;
+ if (size)
+ *size = _buf->base.size;
+
return radeon_libdrm_winsys_buffer(_buf);
}