summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/i915simple/i915_texture.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/i915simple/i915_texture.c')
-rw-r--r--src/gallium/drivers/i915simple/i915_texture.c154
1 files changed, 85 insertions, 69 deletions
diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c
index 3e23e540f9..4c0c7ce3f3 100644
--- a/src/gallium/drivers/i915simple/i915_texture.c
+++ b/src/gallium/drivers/i915simple/i915_texture.c
@@ -104,52 +104,50 @@ i915_miptree_set_image_offset(struct i915_texture *tex,
*/
}
+static unsigned
+power_of_two(unsigned x)
+{
+ int value = 1;
+ while (value <= x)
+ value = value << 1;
+ return value;
+}
+
+static unsigned
+round_up(unsigned n, unsigned multiple)
+{
+ return (n + multiple - 1) & ~(multiple - 1);
+}
-/* Hack it up to use the old winsys->surface_alloc_storage()
- * method for now:
+/**
+ * Special case to deal with display targets.
*/
static boolean
i915_displaytarget_layout(struct pipe_screen *screen,
struct i915_texture *tex)
{
- struct pipe_winsys *ws = screen->winsys;
- struct pipe_surface surf;
- unsigned flags = (PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
-
-
- memset(&surf, 0, sizeof(surf));
-
- ws->surface_alloc_storage( ws,
- &surf,
- tex->base.width[0],
- tex->base.height[0],
- tex->base.format,
- flags,
- tex->base.tex_usage);
-
- /* Now extract the goodies:
- */
- i915_miptree_set_image_offset( tex, 0, 0, 0, 0 );
- i915_miptree_set_level_info( tex, 0, 0, 0, 0,
+ struct pipe_texture *pt = &tex->base;
+
+ if (pt->last_level > 0 || pt->cpp != 4)
+ return 0;
+
+ i915_miptree_set_level_info( tex, 0, 1, 0, 0,
tex->base.width[0],
tex->base.height[0],
1 );
+ i915_miptree_set_image_offset( tex, 0, 0, 0, 0 );
- tex->buffer = surf.buffer;
- tex->pitch = surf.pitch;
- tex->total_height = 0;
-
+#if 0
+ tex->pitch = MAX2(512, power_of_two(tex->base.width[0] * pt->cpp)) / pt->cpp;
+ tex->total_height = round_up(tex->base.height[0], 8);
+#else
+ tex->pitch = round_up(tex->base.width[0], 64 / pt->cpp);
+ tex->total_height = tex->base.height[0];
+#endif
- return tex->buffer != NULL;
+ return 1;
}
-
-
-
-
static void
i945_miptree_layout_2d( struct i915_texture *tex )
{
@@ -179,7 +177,7 @@ i945_miptree_layout_2d( struct i915_texture *tex )
/* Pitch must be a whole number of dwords, even though we
* express it in texels.
*/
- tex->pitch = align_int(tex->pitch * pt->cpp, 4) / pt->cpp;
+ tex->pitch = align_int(tex->pitch * pt->cpp, 64) / pt->cpp;
tex->total_height = 0;
for (level = 0; level <= pt->last_level; level++) {
@@ -525,54 +523,47 @@ i945_miptree_layout(struct i915_texture * tex)
static struct pipe_texture *
-i915_texture_create_screen(struct pipe_screen *screen,
- const struct pipe_texture *templat)
+i915_texture_create(struct pipe_screen *screen,
+ const struct pipe_texture *templat)
{
struct i915_screen *i915screen = i915_screen(screen);
struct pipe_winsys *ws = screen->winsys;
struct i915_texture *tex = CALLOC_STRUCT(i915_texture);
- if (!tex)
+ if (!tex)
return NULL;
tex->base = *templat;
tex->base.refcount = 1;
tex->base.screen = screen;
- if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) {
- if (!i915_displaytarget_layout(screen, tex))
- goto fail;
- }
- else {
- if (i915screen->is_i945) {
- if (!i945_miptree_layout(tex))
- goto fail;
- }
- else {
- if (!i915_miptree_layout(tex))
- goto fail;
- }
-
- tex->buffer = ws->buffer_create(ws, 64,
- PIPE_BUFFER_USAGE_PIXEL,
- tex->pitch * tex->base.cpp *
- tex->total_height);
-
- if (!tex->buffer)
- goto fail;
+ if (i915screen->is_i945) {
+ if (!i945_miptree_layout(tex))
+ goto fail;
+ } else {
+ if (!i915_miptree_layout(tex))
+ goto fail;
}
+ tex->buffer = ws->buffer_create(ws, 64,
+ PIPE_BUFFER_USAGE_PIXEL,
+ tex->pitch * tex->base.cpp *
+ tex->total_height);
+
+ if (!tex->buffer)
+ goto fail;
+
return &tex->base;
- fail:
+fail:
FREE(tex);
return NULL;
}
static void
-i915_texture_release_screen(struct pipe_screen *screen,
- struct pipe_texture **pt)
+i915_texture_release(struct pipe_screen *screen,
+ struct pipe_texture **pt)
{
if (!*pt)
return;
@@ -606,10 +597,10 @@ i915_texture_release_screen(struct pipe_screen *screen,
* XXX note: same as code in sp_surface.c
*/
static struct pipe_surface *
-i915_get_tex_surface_screen(struct pipe_screen *screen,
- struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
+i915_get_tex_surface(struct pipe_screen *screen,
+ struct pipe_texture *pt,
+ unsigned face, unsigned level, unsigned zslice,
+ unsigned flags)
{
struct i915_texture *tex = (struct i915_texture *)pt;
struct pipe_winsys *ws = screen->winsys;
@@ -629,10 +620,11 @@ i915_get_tex_surface_screen(struct pipe_screen *screen,
assert(zslice == 0);
}
- ps = ws->surface_alloc(ws);
+ ps = CALLOC_STRUCT(pipe_surface);//ws->surface_alloc(ws);
if (ps) {
assert(ps->refcount);
assert(ps->winsys);
+ pipe_texture_reference(&ps->texture, pt);
pipe_buffer_reference(ws, &ps->buffer, tex->buffer);
ps->format = pt->format;
ps->cpp = pt->cpp;
@@ -652,11 +644,35 @@ i915_init_texture_functions(struct i915_context *i915)
// i915->pipe.texture_update = i915_texture_update;
}
+static void
+i915_tex_surface_release(struct pipe_screen *screen,
+ struct pipe_surface **surface)
+{
+ struct pipe_surface *surf = *surface;
+
+ if (--surf->refcount == 0) {
+
+ /* This really should not be possible, but it's actually
+ * happening quite a bit... Will fix.
+ */
+ if (surf->status == PIPE_SURFACE_STATUS_CLEAR) {
+ debug_printf("XXX destroying a surface with pending clears...\n");
+ assert(0);
+ }
+
+ pipe_texture_reference(&surf->texture, NULL);
+ pipe_buffer_reference(screen->winsys, &surf->buffer, NULL);
+ FREE(surf);
+ }
+
+ *surface = NULL;
+}
void
i915_init_screen_texture_functions(struct pipe_screen *screen)
{
- screen->texture_create = i915_texture_create_screen;
- screen->texture_release = i915_texture_release_screen;
- screen->get_tex_surface = i915_get_tex_surface_screen;
+ screen->texture_create = i915_texture_create;
+ screen->texture_release = i915_texture_release;
+ screen->get_tex_surface = i915_get_tex_surface;
+ screen->tex_surface_release = i915_tex_surface_release;
}