From c7431552c0ff203cd4b3ae37751b10e6111e4167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c index fe80ca30ee..37984e7b7b 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 7c12e1aa53ba457d29edf4c07d834c70d51f0bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index 17b2781052..c3d747898a 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 50d5891bdb..510f456508 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 633ee70a75..8d67efab6c 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 853c503f4f..788cc560e4 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 1fdcec639f..7b8b64b592 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index f418f80d7b..181113cae6 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 181113cae6..72dafab992 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 72dafab992..2a75ee82d5 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 788cc560e4..336c7714d4 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: =?UTF-8?q?Jos=C3=A9=20Fonseca?= 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(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index f4c4b36ea7..bd30d9068f 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 08ba0ebe4d..9396522961 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 2a75ee82d5..e6999a2211 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 193479f7d6..d3ccb6c2f4 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