summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers
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/gallium/state_trackers
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/gallium/state_trackers')
-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
4 files changed, 100 insertions, 43 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 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):