From 00ffef383c62ca6cd0d5687539dc45fecfbefeec Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 9 Oct 2009 13:22:42 +0100 Subject: util: Force ESI register for cpuid's ebx result. Fixes a segfault and better code. Unfortunately using an arbitrary register ("=r") causes the gcc to abort when the code is optimized saying it can't satisfy the constraint. Setting seems to do the trick. --- src/gallium/auxiliary/util/u_cpu_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c index 70ce25cfcf4..ded361ce704 100644 --- a/src/gallium/auxiliary/util/u_cpu_detect.c +++ b/src/gallium/auxiliary/util/u_cpu_detect.c @@ -346,7 +346,7 @@ cpuid(uint32_t ax, uint32_t *p) "cpuid\n\t" "xchgl %%ebx, %1" : "=a" (p[0]), - "=m" (p[1]), + "=S" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax) -- cgit v1.2.3 From a67f39810b5c88367ae2a9ee564b1a740b27601b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 10 Dec 2009 14:54:57 -0700 Subject: gallium/util: added framebuffer compare, copy util funcs --- src/gallium/auxiliary/util/u_surface.c | 49 ++++++++++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_surface.h | 9 +++++++ 2 files changed, 58 insertions(+) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 85e443204e3..a95b887e847 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -36,6 +36,7 @@ #include "pipe/p_state.h" #include "pipe/p_defines.h" +#include "util/u_memory.h" #include "util/u_surface.h" @@ -111,3 +112,51 @@ util_destroy_rgba_surface(struct pipe_texture *texture, pipe_texture_reference(&texture, NULL); } + + +/** + * Compare pipe_framebuffer_state objects. + * \return TRUE if same, FALSE if different + */ +boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + boolean changed = FALSE; + unsigned i; + + for (i = 0; i < Elements(src->cbufs); i++) { + if (dst->cbufs[i] != src->cbufs[i]) { + changed = TRUE; + } + } + + if (dst->nr_cbufs != src->nr_cbufs) { + changed = TRUE; + } + + if (dst->zsbuf != src->zsbuf) { + changed = TRUE; + } + + return changed; +} + + +/** + * Copy framebuffer state from src to dst, updating refcounts. + */ +void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + for (i = 0; i < Elements(src->cbufs); i++) { + pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]); + } + + dst->nr_cbufs = src->nr_cbufs; + + pipe_surface_reference(&dst->zsbuf, src->zsbuf); +} diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index ce84ed7ad06..a9da9aadcbb 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -66,4 +66,13 @@ util_destroy_rgba_surface(struct pipe_texture *texture, struct pipe_surface *surface); +extern boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + +extern void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + + #endif /* U_SURFACE_H */ -- cgit v1.2.3 From 8f2a1736635368951c3f30e484ee6137066964d6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 11 Dec 2009 11:39:53 -0700 Subject: gallium/util: simplify util_framebuffer_state_equal() And copy width, height in util_copy_framebuffer_state(). --- src/gallium/auxiliary/util/u_surface.c | 16 +++++++++++----- src/gallium/auxiliary/util/u_surface.h | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index a95b887e847..daaa275ef25 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -122,24 +122,27 @@ boolean util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, const struct pipe_framebuffer_state *src) { - boolean changed = FALSE; unsigned i; + if (dst->width != src->width || + dst->height != src->height) + return FALSE; + for (i = 0; i < Elements(src->cbufs); i++) { if (dst->cbufs[i] != src->cbufs[i]) { - changed = TRUE; + return FALSE; } } if (dst->nr_cbufs != src->nr_cbufs) { - changed = TRUE; + return FALSE; } if (dst->zsbuf != src->zsbuf) { - changed = TRUE; + return FALSE; } - return changed; + return TRUE; } @@ -152,6 +155,9 @@ util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, { unsigned i; + dst->width = src->width; + dst->height = src->height; + for (i = 0; i < Elements(src->cbufs); i++) { pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]); } diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index a9da9aadcbb..3c60df2c3e5 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -30,11 +30,7 @@ #include "pipe/p_compiler.h" - - -struct pipe_screen; -struct pipe_texture; -struct pipe_surface; +#include "pipe/p_state.h" /** @@ -75,4 +71,8 @@ util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, const struct pipe_framebuffer_state *src); +extern void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb); + + #endif /* U_SURFACE_H */ -- cgit v1.2.3 From d1fa748cdba0b1145066186b3d634b79b5d69473 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 11 Dec 2009 11:40:52 -0700 Subject: gallium/util: added util_unreference_framebuffer_state() --- src/gallium/auxiliary/util/u_surface.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index daaa275ef25..cfdf7ab8f8a 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -166,3 +166,19 @@ util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, pipe_surface_reference(&dst->zsbuf, src->zsbuf); } + + +void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb) +{ + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + pipe_surface_reference(&fb->cbufs[i], NULL); + } + + pipe_surface_reference(&fb->zsbuf, NULL); + + fb->width = fb->height = 0; + fb->nr_cbufs = 0; +} -- cgit v1.2.3 From 4f5675e94b936d012b89937aac8a16c28143d5ec Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 14 Jan 2010 19:04:40 -0700 Subject: gallium/util: added debug_dump_texture() and ppm output Now we can get dump debug images on Linux too. --- src/gallium/auxiliary/util/u_debug.c | 75 ++++++++++++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_debug.h | 4 ++ 2 files changed, 79 insertions(+) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 9b4e6ca2a73..7ee0864d292 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -631,6 +631,14 @@ const char *u_prim_name( unsigned prim ) #ifdef DEBUG +/** + * Dump an image to a .raw or .ppm file (depends on OS). + * \param format PIPE_FORMAT_x + * \param cpp bytes per pixel + * \param width width in pixels + * \param height height in pixels + * \param stride row stride in bytes + */ void debug_dump_image(const char *prefix, unsigned format, unsigned cpp, unsigned width, unsigned height, @@ -672,6 +680,52 @@ void debug_dump_image(const char *prefix, } EngUnmapFile(iFile); +#elif defined(PIPE_OS_UNIX) + /* write a ppm file */ + char filename[256]; + FILE *f; + + util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); + + f = fopen(filename, "w"); + if (f) { + int i, x, y; + int r, g, b; + const uint8_t *ptr = (uint8_t *) data; + + /* XXX this is a hack */ + switch (format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: + r = 2; + g = 1; + b = 0; + break; + default: + r = 0; + g = 1; + b = 1; + } + + fprintf(f, "P6\n"); + fprintf(f, "# ppm-file created by osdemo.c\n"); + fprintf(f, "%i %i\n", width, height); + fprintf(f, "255\n"); + fclose(f); + + f = fopen(filename, "ab"); /* reopen in binary append mode */ + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + i = y * stride + x * cpp; + fputc(ptr[i + r], f); /* write red */ + fputc(ptr[i + g], f); /* write green */ + fputc(ptr[i + b], f); /* write blue */ + } + } + fclose(f); + } + else { + fprintf(stderr, "Can't open %s for writing\n", filename); + } #endif } @@ -712,6 +766,27 @@ error: } +void debug_dump_texture(const char *prefix, + struct pipe_texture *texture) +{ + struct pipe_surface *surface; + struct pipe_screen *screen; + + if (!texture) + return; + + screen = texture->screen; + + /* XXX for now, just dump image for face=0, level=0 */ + surface = screen->get_tex_surface(screen, texture, 0, 0, 0, + PIPE_TEXTURE_USAGE_SAMPLER); + if (surface) { + debug_dump_surface(prefix, surface); + screen->tex_surface_destroy(surface); + } +} + + #pragma pack(push,2) struct bmp_file_header { uint16_t bfType; diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h index facc30a5534..131c9915391 100644 --- a/src/gallium/auxiliary/util/u_debug.h +++ b/src/gallium/auxiliary/util/u_debug.h @@ -354,6 +354,8 @@ debug_memory_end(unsigned long beginning); #ifdef DEBUG struct pipe_surface; struct pipe_transfer; +struct pipe_texture; + void debug_dump_image(const char *prefix, unsigned format, unsigned cpp, unsigned width, unsigned height, @@ -361,6 +363,8 @@ void debug_dump_image(const char *prefix, const void *data); void debug_dump_surface(const char *prefix, struct pipe_surface *surface); +void debug_dump_texture(const char *prefix, + struct pipe_texture *texture); void debug_dump_surface_bmp(const char *filename, struct pipe_surface *surface); void debug_dump_transfer_bmp(const char *filename, -- cgit v1.2.3 From 89bb07730b1c0f292d1d70a99466e8a885fb87bf Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 18 Jan 2010 14:35:43 -0700 Subject: util: fix broken util_ringbuffer_dequeue() The tests for an empty ring buffer were incorrect. Fixes glxinfo segfaults. Plus, add a new assertion. --- src/gallium/auxiliary/util/u_ringbuffer.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c index 3f43a19e018..e73ba0b3481 100644 --- a/src/gallium/auxiliary/util/u_ringbuffer.c +++ b/src/gallium/auxiliary/util/u_ringbuffer.c @@ -53,11 +53,22 @@ void util_ringbuffer_destroy( struct util_ringbuffer *ring ) FREE(ring); } +/** + * Return number of free entries in the ring + */ static INLINE unsigned util_ringbuffer_space( const struct util_ringbuffer *ring ) { return (ring->tail - (ring->head + 1)) & ring->mask; } +/** + * Is the ring buffer empty? + */ +static INLINE boolean util_ringbuffer_empty( const struct util_ringbuffer *ring ) +{ + return util_ringbuffer_space(ring) == ring->mask; +} + void util_ringbuffer_enqueue( struct util_ringbuffer *ring, const struct util_packet *packet ) { @@ -67,6 +78,10 @@ void util_ringbuffer_enqueue( struct util_ringbuffer *ring, */ pipe_mutex_lock(ring->mutex); + /* make sure we don't request an impossible amount of space + */ + assert(packet->dwords <= ring->mask); + /* Wait for free space: */ while (util_ringbuffer_space(ring) < packet->dwords) @@ -104,14 +119,14 @@ enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, */ pipe_mutex_lock(ring->mutex); - /* Wait for free space: + /* Get next ring entry: */ if (wait) { - while (util_ringbuffer_space(ring) == 0) + while (util_ringbuffer_empty(ring)) pipe_condvar_wait(ring->change, ring->mutex); } else { - if (util_ringbuffer_space(ring) == 0) { + if (util_ringbuffer_empty(ring)) { ret = PIPE_ERROR_OUT_OF_MEMORY; goto out; } -- cgit v1.2.3 From 99f1e32fadbf16c167350af3304b2d68c464452a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 27 Jan 2010 13:46:23 -0700 Subject: gallium/util: print dlerror() info upon dlopen() failure --- src/gallium/auxiliary/util/u_dl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_dl.c b/src/gallium/auxiliary/util/u_dl.c index b42b429d4d7..d8803f77fa0 100644 --- a/src/gallium/auxiliary/util/u_dl.c +++ b/src/gallium/auxiliary/util/u_dl.c @@ -26,8 +26,8 @@ * **************************************************************************/ - #include "pipe/p_config.h" +#include "util/u_debug.h" #if defined(PIPE_OS_UNIX) #include @@ -43,7 +43,12 @@ struct util_dl_library * util_dl_open(const char *filename) { #if defined(PIPE_OS_UNIX) - return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); + struct util_dl_library *lib; + lib = (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); + if (!lib) { + debug_printf("gallium: dlopen() failed: %s\n", dlerror()); + } + return lib; #elif defined(PIPE_OS_WINDOWS) return (struct util_dl_library *)LoadLibraryA(filename); #else -- cgit v1.2.3 From 5460da543608805a3debbb401ccc19442e1cb476 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 27 Jan 2010 13:46:43 -0700 Subject: gallium/util: comments for time-related functions --- src/gallium/auxiliary/util/u_time.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/gallium/auxiliary') diff --git a/src/gallium/auxiliary/util/u_time.h b/src/gallium/auxiliary/util/u_time.h index a6189a247bb..29fd1cbc67d 100644 --- a/src/gallium/auxiliary/util/u_time.h +++ b/src/gallium/auxiliary/util/u_time.h @@ -74,14 +74,23 @@ struct util_time void util_time_get(struct util_time *t); +/** + * Return t2 = t1 + usecs + */ void util_time_add(const struct util_time *t1, int64_t usecs, struct util_time *t2); +/** + * Return current time in microseconds + */ uint64_t util_time_micros( void ); +/** + * Return difference between times, in microseconds + */ int64_t util_time_diff(const struct util_time *t1, const struct util_time *t2); -- cgit v1.2.3