summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2009-02-23 17:21:36 +0000
committerJosé Fonseca <[email protected]>2009-02-23 17:21:36 +0000
commit37f21fce3bd323c361291215edeb7d8cf5f4335b (patch)
tree2909c90da7bff47ba359d50bde242b79a632210b /src
parent7399d56ec6019e00297eef57f802a53698baa8ad (diff)
parent60e35ebf1476c31eb5d7c207ab8e9db77fcad896 (diff)
Merge commit 'origin/gallium-0.1'
Conflicts: src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c src/gallium/auxiliary/util/u_tile.c
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c98
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h7
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c4
-rw-r--r--src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c10
-rw-r--r--src/gallium/auxiliary/util/u_tile.c26
-rw-r--r--src/gallium/state_trackers/python/gallium.i1
-rw-r--r--src/gallium/state_trackers/python/p_texture.i44
-rwxr-xr-xsrc/gallium/state_trackers/python/retrace/interpreter.py84
-rw-r--r--src/gallium/state_trackers/python/samples/tri.py14
9 files changed, 227 insertions, 61 deletions
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
index 0cddc95aa67..272e2205e34 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
@@ -66,8 +66,12 @@ struct fenced_buffer_list
struct pb_fence_ops *ops;
size_t numDelayed;
-
struct list_head delayed;
+
+#ifdef DEBUG
+ size_t numUnfenced;
+ struct list_head unfenced;
+#endif
};
@@ -115,8 +119,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;
}
@@ -128,8 +135,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);
}
@@ -149,15 +167,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);
}
@@ -441,6 +460,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;
}
@@ -457,9 +483,13 @@ fenced_buffer_list_create(struct pb_fence_ops *ops)
fenced_list->ops = ops;
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;
@@ -476,6 +506,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 pb_fence_ops *ops = fenced_list->ops;
+ 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 = ops->fence_signalled(ops, 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)
{
@@ -491,6 +567,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);
fenced_list->ops->destroy(fenced_list->ops);
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h
index c2b29e974b1..034ca1e024a 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h
+++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h
@@ -114,6 +114,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 e352f5357b5..144db5669b6 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;
}
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
index f3b1ca73b0c..85ff3a09de4 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
@@ -204,13 +204,9 @@ mm_bufmgr_create_buffer(struct pb_manager *mgr,
#if 0
mmDumpMemInfo(mm->heap);
#endif
-
- mm_buf->block = u_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 */
diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c
index 56f2f577ccf..d31ca9c029e 100644
--- a/src/gallium/auxiliary/util/u_tile.c
+++ b/src/gallium/auxiliary/util/u_tile.c
@@ -882,6 +882,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,
@@ -948,7 +969,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);
}
}
@@ -1050,7 +1072,7 @@ pipe_put_tile_rgba(struct pipe_transfer *pt,
/*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(pt->format));
}
pipe_put_tile_raw(pt, x, y, w, h, packed, 0);
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 f418f80d7b4..e6999a2211e 100755
--- a/src/gallium/state_trackers/python/retrace/interpreter.py
+++ b/src/gallium/state_trackers/python/retrace/interpreter.py
@@ -35,21 +35,19 @@ 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)
+ 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):
@@ -77,6 +75,7 @@ def show_image(surface):
root.mainloop()
+verbose = 1
class Struct:
@@ -297,6 +296,7 @@ class Context(Object):
self.zsbuf = None
self.vbufs = []
self.velems = []
+ self.dirty = False
def destroy(self):
pass
@@ -374,18 +374,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 = struct.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()
@@ -436,6 +441,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')
@@ -454,12 +462,15 @@ 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')
def dump_indices(self, ibuf, isize, start, count):
+ if verbose < 2:
+ return
+
format = {
1: 'B',
2: 'H',
@@ -477,7 +488,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)
@@ -489,25 +500,35 @@ 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):
- 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)
+
+ self.dirty = True
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)
+
+ 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):
@@ -553,7 +574,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]
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):