From c7431552c0ff203cd4b3ae37751b10e6111e4167 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 18 Feb 2009 10:25:04 +0000 Subject: pipebuffer: Don't retry to alloc memory block on mm. It will give the same result 2nd time too, as fencing is done at a higher level. --- src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c index fe80ca30eea..37984e7b7be 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c @@ -181,13 +181,9 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr, #if 0 mmDumpMemInfo(mm->heap); #endif - - mm_buf->block = mmAllocMem(mm->heap, size, mm->align2, 0); - if(!mm_buf->block) { - FREE(mm_buf); - pipe_mutex_unlock(mm->mutex); - return NULL; - } + FREE(mm_buf); + pipe_mutex_unlock(mm->mutex); + return NULL; } /* Some sanity checks */ -- cgit v1.2.3 From 46728037a0ef3b78d6d1c9843f3bc0eeaa6df11a Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 18 Feb 2009 15:05:23 +0000 Subject: scons: Produce map files for debug builds too. --- scons/gallium.py | 2 +- scons/generic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scons/gallium.py b/scons/gallium.py index 33bd65dd543..2e490dde6e9 100644 --- a/scons/gallium.py +++ b/scons/gallium.py @@ -444,7 +444,7 @@ def generate(env): '/entry:DrvEnableDriver', ] - if env['profile']: + if env['debug'] or env['profile']: linkflags += [ '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx ] diff --git a/scons/generic.py b/scons/generic.py index 0ed21a4e6ce..db77ca238ac 100644 --- a/scons/generic.py +++ b/scons/generic.py @@ -512,7 +512,7 @@ def generate(env): '/entry:DrvEnableDriver', ] - if env['profile']: + if env['debug'] or env['profile']: linkflags += [ '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx ] -- cgit v1.2.3 From 7c12e1aa53ba457d29edf4c07d834c70d51f0bbd Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 18 Feb 2009 15:12:16 +0000 Subject: pipebuffer: Dump debugging info for fenced buffer list. --- .../auxiliary/pipebuffer/pb_buffer_fenced.c | 98 ++++++++++++++++++++-- .../auxiliary/pipebuffer/pb_buffer_fenced.h | 7 ++ .../auxiliary/pipebuffer/pb_bufmgr_fenced.c | 4 + 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index 17b27810520..c3d747898a9 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -74,8 +74,12 @@ struct fenced_buffer_list struct pipe_winsys *winsys; size_t numDelayed; - struct list_head delayed; + +#ifdef DEBUG + size_t numUnfenced; + struct list_head unfenced; +#endif }; @@ -122,8 +126,11 @@ _fenced_buffer_add(struct fenced_buffer *fenced_buf) assert(fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); assert(fenced_buf->fence); - assert(!fenced_buf->head.prev); - assert(!fenced_buf->head.next); +#ifdef DEBUG + LIST_DEL(&fenced_buf->head); + assert(fenced_list->numUnfenced); + --fenced_list->numUnfenced; +#endif LIST_ADDTAIL(&fenced_buf->head, &fenced_list->delayed); ++fenced_list->numDelayed; } @@ -135,8 +142,19 @@ _fenced_buffer_add(struct fenced_buffer *fenced_buf) static INLINE void _fenced_buffer_destroy(struct fenced_buffer *fenced_buf) { + struct fenced_buffer_list *fenced_list = fenced_buf->list; + assert(!fenced_buf->base.base.refcount); assert(!fenced_buf->fence); +#ifdef DEBUG + assert(fenced_buf->head.prev); + assert(fenced_buf->head.next); + LIST_DEL(&fenced_buf->head); + assert(fenced_list->numUnfenced); + --fenced_list->numUnfenced; +#else + (void)fenced_list; +#endif pb_reference(&fenced_buf->buffer, NULL); FREE(fenced_buf); } @@ -156,15 +174,16 @@ _fenced_buffer_remove(struct fenced_buffer_list *fenced_list, assert(fenced_buf->head.prev); assert(fenced_buf->head.next); - LIST_DEL(&fenced_buf->head); -#ifdef DEBUG - fenced_buf->head.prev = NULL; - fenced_buf->head.next = NULL; -#endif + LIST_DEL(&fenced_buf->head); assert(fenced_list->numDelayed); --fenced_list->numDelayed; +#ifdef DEBUG + LIST_ADDTAIL(&fenced_buf->head, &fenced_list->unfenced); + ++fenced_list->numUnfenced; +#endif + if(!fenced_buf->base.base.refcount) _fenced_buffer_destroy(fenced_buf); } @@ -358,6 +377,13 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, buf->buffer = buffer; buf->list = fenced_list; +#ifdef DEBUG + pipe_mutex_lock(fenced_list->mutex); + LIST_ADDTAIL(&buf->head, &fenced_list->unfenced); + ++fenced_list->numUnfenced; + pipe_mutex_unlock(fenced_list->mutex); +#endif + return &buf->base; } @@ -420,9 +446,13 @@ fenced_buffer_list_create(struct pipe_winsys *winsys) fenced_list->winsys = winsys; LIST_INITHEAD(&fenced_list->delayed); - fenced_list->numDelayed = 0; +#ifdef DEBUG + LIST_INITHEAD(&fenced_list->unfenced); + fenced_list->numUnfenced = 0; +#endif + pipe_mutex_init(fenced_list->mutex); return fenced_list; @@ -439,6 +469,52 @@ fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list, } +#ifdef DEBUG +void +fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list) +{ + struct pipe_winsys *winsys = fenced_list->winsys; + struct list_head *curr, *next; + struct fenced_buffer *fenced_buf; + struct pipe_fence_handle *prev_fence = NULL; + + pipe_mutex_lock(fenced_list->mutex); + + debug_printf("%10s %7s %10s %s\n", + "buffer", "refcount", "fence", "signalled"); + + curr = fenced_list->unfenced.next; + next = curr->next; + while(curr != &fenced_list->unfenced) { + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + assert(!fenced_buf->fence); + debug_printf("%10p %7u\n", + fenced_buf, + fenced_buf->base.base.refcount); + curr = next; + next = curr->next; + } + + curr = fenced_list->delayed.next; + next = curr->next; + while(curr != &fenced_list->delayed) { + int signaled; + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + signaled = winsys->fence_signalled(winsys, fenced_buf->fence, 0); + debug_printf("%10p %7u %10p %s\n", + fenced_buf, + fenced_buf->base.base.refcount, + fenced_buf->fence, + signaled == 0 ? "y" : "n"); + curr = next; + next = curr->next; + } + + pipe_mutex_unlock(fenced_list->mutex); +} +#endif + + void fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list) { @@ -454,6 +530,10 @@ fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list) pipe_mutex_lock(fenced_list->mutex); } +#ifdef DEBUG + //assert(!fenced_list->numUnfenced); +#endif + pipe_mutex_unlock(fenced_list->mutex); FREE(fenced_list); diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h index 50d5891bdb3..510f4565081 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h @@ -94,6 +94,13 @@ void fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list, int wait); + +#ifdef DEBUG +void +fenced_buffer_list_dump(struct fenced_buffer_list *fenced_list); +#endif + + void fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list); diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c index 633ee70a75b..8d67efab6ca 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c @@ -79,6 +79,10 @@ fenced_bufmgr_create_buffer(struct pb_manager *mgr, buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc); if(!buf) { +#if 0 + fenced_buffer_list_dump(fenced_mgr->fenced_list); +#endif + /* give up */ return NULL; } -- cgit v1.2.3 From 43b31fc6fcee6deb52a8bd033dada62e9ce67ecb Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 19 Feb 2009 12:56:56 +0000 Subject: util: Support PIPE_FORMAT_Z32_FLOAT in pipe_tile_raw_to_rgba --- src/gallium/auxiliary/util/u_tile.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 853c503f4ff..788cc560e4e 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -769,6 +769,32 @@ z24s8_get_tile_rgba(const unsigned *src, } +/*** PIPE_FORMAT_Z32_FLOAT ***/ + +/** + * Return each Z value as four floats. + */ +static void +z32f_get_tile_rgba(const float *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = *src++; + } + p += dst_stride; + } +} + + /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/ /** @@ -913,6 +939,9 @@ pipe_tile_raw_to_rgba(enum pipe_format format, case PIPE_FORMAT_Z24S8_UNORM: z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; + case PIPE_FORMAT_Z32_FLOAT: + z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride); + break; case PIPE_FORMAT_YCBCR: ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, FALSE); break; -- cgit v1.2.3 From 7887a3e42b8cd9f3376dbf090e11c56198275c44 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 31 Dec 2008 15:03:35 +0000 Subject: python: Pass a zero offset to util_draw_vertex_buffer. --- src/gallium/state_trackers/python/p_context.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 1fdcec639f7..7b8b64b5923 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -245,7 +245,7 @@ struct st_context { memcpy(map, vertices, size); pipe_buffer_unmap(screen, vbuf); - util_draw_vertex_buffer(pipe, vbuf, prim, num_verts, num_attribs); + util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs); error2: pipe_buffer_reference(screen, &vbuf, NULL); -- cgit v1.2.3 From 204526a6d277265b9872d4681e70c58d57038926 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 20 Feb 2009 15:02:19 +0000 Subject: python/retrace: Cope with python 2.4.x --- src/gallium/state_trackers/python/retrace/interpreter.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index f418f80d7b4..181113cae62 100755 --- a/src/gallium/state_trackers/python/retrace/interpreter.py +++ b/src/gallium/state_trackers/python/retrace/interpreter.py @@ -35,6 +35,14 @@ import model import parser +try: + from struct import unpack_from +except ImportError: + def unpack_from(fmt, buf, offset=0): + size = struct.calcsize(fmt) + return struct.unpack(fmt, buf[offset:offset + size]) + + def make_image(surface): pixels = gallium.FloatArray(surface.height*surface.width*4) surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) @@ -383,7 +391,7 @@ class Context(Object): format = '4f' index = 0 for offset in range(0, len(data), struct.calcsize(format)): - x, y, z, w = struct.unpack_from(format, data, offset) + x, y, z, w = unpack_from(format, data, offset) sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) index += 1 @@ -454,7 +462,7 @@ class Context(Object): }[velem.src_format] data = vbuf.buffer.read() - values = struct.unpack_from(format, data, offset) + values = unpack_from(format, data, offset) sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n') assert len(values) == velem.nr_components sys.stdout.write('\t},\n') @@ -477,7 +485,7 @@ class Context(Object): sys.stdout.write('\t...\n') break offset = i*isize - index, = struct.unpack_from(format, data, offset) + index, = unpack_from(format, data, offset) sys.stdout.write('\t\t%u,\n' % index) minindex = min(minindex, index) maxindex = max(maxindex, index) -- cgit v1.2.3 From e92f3310fa552b06a17d4f52177fc71e9ad54257 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 20 Feb 2009 15:14:15 +0000 Subject: python/retrace: Verbosity level. --- .../state_trackers/python/retrace/interpreter.py | 45 ++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 181113cae62..72dafab9929 100755 --- a/src/gallium/state_trackers/python/retrace/interpreter.py +++ b/src/gallium/state_trackers/python/retrace/interpreter.py @@ -85,6 +85,7 @@ def show_image(surface): root.mainloop() +verbose = 1 class Struct: @@ -382,18 +383,23 @@ class Context(Object): _state.ucp = ucp self.real.set_clip(_state) + def dump_constant_buffer(self, buffer): + if verbose < 2: + return + + data = buffer.read() + format = '4f' + index = 0 + for offset in range(0, len(data), struct.calcsize(format)): + x, y, z, w = unpack_from(format, data, offset) + sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) + index += 1 + def set_constant_buffer(self, shader, index, state): if state is not None: self.real.set_constant_buffer(shader, index, state.buffer) - if 1: - data = state.buffer.read() - format = '4f' - index = 0 - for offset in range(0, len(data), struct.calcsize(format)): - x, y, z, w = unpack_from(format, data, offset) - sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) - index += 1 + self.dump_constant_buffer(state.buffer) def set_framebuffer_state(self, state): _state = gallium.Framebuffer() @@ -444,6 +450,9 @@ class Context(Object): pass def dump_vertices(self, start, count): + if verbose < 2: + return + for index in range(start, start + count): if index >= start + 16: sys.stdout.write('\t...\n') @@ -468,6 +477,9 @@ class Context(Object): sys.stdout.write('\t},\n') def dump_indices(self, ibuf, isize, start, count): + if verbose < 2: + return + format = { 1: 'B', 2: 'H', @@ -499,16 +511,18 @@ class Context(Object): self.real.draw_arrays(mode, start, count) def draw_elements(self, indexBuffer, indexSize, mode, start, count): - minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) - self.dump_vertices(minindex, maxindex - minindex) + if verbose >= 2: + minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) + self.dump_vertices(minindex, maxindex - minindex) self.real.draw_elements(indexBuffer, indexSize, mode, start, count) def draw_range_elements(self, indexBuffer, indexSize, minIndex, maxIndex, mode, start, count): - minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) - minindex = min(minindex, minIndex) - maxindex = min(maxindex, maxIndex) - self.dump_vertices(minindex, maxindex - minindex) + if verbose >= 2: + minindex, maxindex = self.dump_indices(indexBuffer, indexSize, start, count) + minindex = min(minindex, minIndex) + maxindex = min(maxindex, maxIndex) + self.dump_vertices(minindex, maxindex - minindex) self.real.draw_range_elements(indexBuffer, indexSize, minIndex, maxIndex, mode, start, count) @@ -561,7 +575,8 @@ class Interpreter(parser.TraceDumper): if (call.klass, call.method) in self.ignore_calls: return - parser.TraceDumper.handle_call(self, call) + if verbose >= 1: + parser.TraceDumper.handle_call(self, call) args = [self.interpret_arg(arg) for name, arg in call.args] -- cgit v1.2.3 From 059d7f3103395917217d376365def36641a51602 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 20 Feb 2009 15:23:33 +0000 Subject: python/interpreter: Don't do unnecessary updates. --- src/gallium/state_trackers/python/retrace/interpreter.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 72dafab9929..2a75ee82d5d 100755 --- a/src/gallium/state_trackers/python/retrace/interpreter.py +++ b/src/gallium/state_trackers/python/retrace/interpreter.py @@ -306,6 +306,7 @@ class Context(Object): self.zsbuf = None self.vbufs = [] self.velems = [] + self.dirty = False def destroy(self): pass @@ -509,6 +510,8 @@ class Context(Object): self.dump_vertices(start, count) self.real.draw_arrays(mode, start, count) + + self.dirty = True def draw_elements(self, indexBuffer, indexSize, mode, start, count): if verbose >= 2: @@ -516,6 +519,8 @@ class Context(Object): self.dump_vertices(minindex, maxindex - minindex) self.real.draw_elements(indexBuffer, indexSize, mode, start, count) + + self.dirty = True def draw_range_elements(self, indexBuffer, indexSize, minIndex, maxIndex, mode, start, count): if verbose >= 2: @@ -525,11 +530,15 @@ class Context(Object): self.dump_vertices(minindex, maxindex - minindex) self.real.draw_range_elements(indexBuffer, indexSize, minIndex, maxIndex, mode, start, count) + + self.dirty = True def flush(self, flags): self.real.flush(flags) - if flags & gallium.PIPE_FLUSH_FRAME: - self._update() + if self.dirty: + if flags & gallium.PIPE_FLUSH_FRAME: + self._update() + self.dirty = False return None def clear(self, surface, value): -- cgit v1.2.3 From 77388559886dd84c69aaffc9a385ad87c410afa9 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 20 Feb 2009 16:48:45 +0000 Subject: util: Use a checkboard pattern instead of asserting for unknown formats. Useful to replay traces which use DXTC textures... --- src/gallium/auxiliary/util/u_tile.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 788cc560e4e..336c7714d4d 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -883,6 +883,27 @@ ycbcr_get_tile_rgba(const ushort *src, } +static void +fake_get_tile_rgba(const ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (i ^ j) & 1 ? 1.0f : 0.0f; + } + p += dst_stride; + } +} + + void pipe_tile_raw_to_rgba(enum pipe_format format, void *src, @@ -949,7 +970,8 @@ pipe_tile_raw_to_rgba(enum pipe_format format, ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, TRUE); break; default: - assert(0); + debug_printf("%s: unsupported format %s\n", __FUNCTION__, pf_name(format)); + fake_get_tile_rgba(src, w, h, dst, dst_stride); } } @@ -1051,7 +1073,7 @@ pipe_put_tile_rgba(struct pipe_surface *ps, /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; default: - assert(0); + debug_printf("%s: unsupported format %s\n", __FUNCTION__, pf_name(ps->format)); } pipe_put_tile_raw(ps, x, y, w, h, packed, 0); -- cgit v1.2.3 From 60e35ebf1476c31eb5d7c207ab8e9db77fcad896 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 20 Feb 2009 16:50:02 +0000 Subject: python: More efficient blits from surfaces. C code instead of interpreted python code. --- src/gallium/state_trackers/python/gallium.i | 1 + src/gallium/state_trackers/python/p_texture.i | 44 ++++++++++++++++++++++ .../state_trackers/python/retrace/interpreter.py | 14 +------ src/gallium/state_trackers/python/samples/tri.py | 14 +------ 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index f4c4b36ea7d..bd30d9068f3 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -47,6 +47,7 @@ #include "cso_cache/cso_context.h" #include "util/u_draw_quad.h" #include "util/u_tile.h" +#include "util/u_math.h" #include "tgsi/tgsi_text.h" #include "tgsi/tgsi_dump.h" diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 08ba0ebe4d0..9396522961e 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -121,6 +121,50 @@ pipe_put_tile_rgba($self, x, y, w, h, rgba); } + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + get_tile_rgba8(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) + { + unsigned surface_usage; + float *rgba; + unsigned char *rgba8; + unsigned i, j, k; + + *LENGTH = 0; + *STRING = NULL; + + if (!$self) + return; + + *LENGTH = h*w*4; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + rgba = malloc(w*4*sizeof(float)); + if(!rgba) + return; + + rgba8 = (unsigned char *) *STRING; + + /* XXX: force mappable surface */ + surface_usage = $self->usage; + $self->usage |= PIPE_BUFFER_USAGE_CPU_READ; + + for(j = 0; j < h; ++j) { + pipe_get_tile_rgba($self, + x, y + j, w, 1, + rgba); + for(i = 0; i < w; ++i) + for(k = 0; k <4; ++k) + rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[i*4 + k]); + } + + $self->usage = surface_usage; + + free(rgba); + } + void get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) { pipe_get_tile_z($self, x, y, w, h, z); diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 2a75ee82d5d..e6999a2211e 100755 --- a/src/gallium/state_trackers/python/retrace/interpreter.py +++ b/src/gallium/state_trackers/python/retrace/interpreter.py @@ -44,20 +44,10 @@ except ImportError: def make_image(surface): - pixels = gallium.FloatArray(surface.height*surface.width*4) - surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) + data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) import Image - outimage = Image.new( - mode='RGB', - size=(surface.width, surface.height), - color=(0,0,0)) - outpixels = outimage.load() - for y in range(0, surface.height): - for x in range(0, surface.width): - offset = (y*surface.width + x)*4 - r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)] - outpixels[x, y] = r, g, b + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) return outimage def save_image(filename, surface): diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index 193479f7d6c..d3ccb6c2f46 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -31,20 +31,10 @@ from gallium import * def make_image(surface): - pixels = FloatArray(surface.height*surface.width*4) - surface.get_tile_rgba(0, 0, surface.width, surface.height, pixels) + data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) import Image - outimage = Image.new( - mode='RGB', - size=(surface.width, surface.height), - color=(0,0,0)) - outpixels = outimage.load() - for y in range(0, surface.height): - for x in range(0, surface.width): - offset = (y*surface.width + x)*4 - r, g, b, a = [int(pixels[offset + ch]*255) for ch in range(4)] - outpixels[x, y] = r, g, b + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) return outimage def save_image(filename, surface): -- cgit v1.2.3