summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_debug.c75
-rw-r--r--src/gallium/auxiliary/util/u_debug.h4
-rw-r--r--src/gallium/auxiliary/util/u_dl.c9
-rw-r--r--src/gallium/auxiliary/util/u_ringbuffer.c21
-rw-r--r--src/gallium/auxiliary/util/u_surface.c71
-rw-r--r--src/gallium/auxiliary/util/u_surface.h19
-rw-r--r--src/gallium/auxiliary/util/u_time.h9
7 files changed, 198 insertions, 10 deletions
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,
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 <dlfcn.h>
@@ -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
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;
}
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index f828908f0be..70de140ec9d 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"
@@ -110,3 +111,73 @@ 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)
+{
+ 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]) {
+ return FALSE;
+ }
+ }
+
+ if (dst->nr_cbufs != src->nr_cbufs) {
+ return FALSE;
+ }
+
+ if (dst->zsbuf != src->zsbuf) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * 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;
+
+ 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]);
+ }
+
+ dst->nr_cbufs = src->nr_cbufs;
+
+ 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;
+}
diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h
index ce84ed7ad06..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"
/**
@@ -66,4 +62,17 @@ 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);
+
+
+extern void
+util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb);
+
+
#endif /* U_SURFACE_H */
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);