summaryrefslogtreecommitdiff
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.c56
-rw-r--r--src/gallium/auxiliary/util/u_debug.h21
-rw-r--r--src/gallium/auxiliary/util/u_debug_stack.c11
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c96
-rw-r--r--src/gallium/auxiliary/util/u_linear.c31
-rw-r--r--src/gallium/auxiliary/util/u_linear.h31
-rw-r--r--src/gallium/auxiliary/util/u_time.c5
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.c30
8 files changed, 239 insertions, 42 deletions
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index ae47a274a6..18597ef839 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -721,6 +721,7 @@ void
debug_dump_surface_bmp(const char *filename,
struct pipe_surface *surface)
{
+#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
struct pipe_transfer *transfer;
struct pipe_texture *texture = surface->texture;
struct pipe_screen *screen = texture->screen;
@@ -733,6 +734,7 @@ debug_dump_surface_bmp(const char *filename,
debug_dump_transfer_bmp(filename, transfer);
screen->tex_transfer_destroy(transfer);
+#endif
}
void
@@ -740,11 +742,7 @@ debug_dump_transfer_bmp(const char *filename,
struct pipe_transfer *transfer)
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
- struct util_stream *stream;
- struct bmp_file_header bmfh;
- struct bmp_info_header bmih;
float *rgba;
- unsigned x, y;
if (!transfer)
goto error1;
@@ -753,19 +751,47 @@ debug_dump_transfer_bmp(const char *filename,
if(!rgba)
goto error1;
+ pipe_get_tile_rgba(transfer, 0, 0,
+ transfer->width, transfer->height,
+ rgba);
+
+ debug_dump_float_rgba_bmp(filename,
+ transfer->width, transfer->height,
+ rgba, transfer->width);
+
+ FREE(rgba);
+error1:
+ ;
+#endif
+}
+
+void
+debug_dump_float_rgba_bmp(const char *filename,
+ unsigned width, unsigned height,
+ float *rgba, unsigned stride)
+{
+#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
+ struct util_stream *stream;
+ struct bmp_file_header bmfh;
+ struct bmp_info_header bmih;
+ unsigned x, y;
+
+ if(!rgba)
+ goto error1;
+
bmfh.bfType = 0x4d42;
- bmfh.bfSize = 14 + 40 + transfer->height*transfer->width*4;
+ bmfh.bfSize = 14 + 40 + height*width*4;
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
bmfh.bfOffBits = 14 + 40;
bmih.biSize = 40;
- bmih.biWidth = transfer->width;
- bmih.biHeight = transfer->height;
+ bmih.biWidth = width;
+ bmih.biHeight = height;
bmih.biPlanes = 1;
bmih.biBitCount = 32;
bmih.biCompression = 0;
- bmih.biSizeImage = transfer->height*transfer->width*4;
+ bmih.biSizeImage = height*width*4;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
@@ -773,19 +799,15 @@ debug_dump_transfer_bmp(const char *filename,
stream = util_stream_create(filename, bmfh.bfSize);
if(!stream)
- goto error2;
+ goto error1;
util_stream_write(stream, &bmfh, 14);
util_stream_write(stream, &bmih, 40);
- pipe_get_tile_rgba(transfer, 0, 0,
- transfer->width, transfer->height,
- rgba);
-
- y = transfer->height;
+ y = height;
while(y--) {
- float *ptr = rgba + (transfer->width * y * 4);
- for(x = 0; x < transfer->width; ++x)
+ float *ptr = rgba + (stride * y * 4);
+ for(x = 0; x < width; ++x)
{
struct bmp_rgb_quad pixel;
pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]);
@@ -797,8 +819,6 @@ debug_dump_transfer_bmp(const char *filename,
}
util_stream_close(stream);
-error2:
- FREE(rgba);
error1:
;
#endif
diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index 8d703e47fc..d42b65ce28 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -102,6 +102,22 @@ debug_printf(const char *format, ...)
}
+/*
+ * ... isn't portable so we need to pass arguments in parentheses.
+ *
+ * usage:
+ * debug_printf_once(("awnser: %i\n", 42));
+ */
+#define debug_printf_once(args) \
+ do { \
+ static boolean once = TRUE; \
+ if (once) { \
+ once = FALSE; \
+ debug_printf args; \
+ } \
+ } while (0)
+
+
#ifdef DEBUG
#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
#else
@@ -347,10 +363,15 @@ void debug_dump_surface_bmp(const char *filename,
struct pipe_surface *surface);
void debug_dump_transfer_bmp(const char *filename,
struct pipe_transfer *transfer);
+void debug_dump_float_rgba_bmp(const char *filename,
+ unsigned width, unsigned height,
+ float *rgba, unsigned stride);
#else
#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
#define debug_dump_surface(prefix, surface) ((void)0)
#define debug_dump_surface_bmp(filename, surface) ((void)0)
+#define debug_dump_transfer_bmp(filename, transfer) ((void)0)
+#define debug_dump_rgba_float_bmp(filename, width, height, rgba, stride) ((void)0)
#endif
diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
index e9891fde8a..528a1c394b 100644
--- a/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/src/gallium/auxiliary/util/u_debug_stack.c
@@ -62,6 +62,8 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
#ifdef PIPE_ARCH_X86
while(nr_frames) {
+ const void **next_frame_pointer;
+
if(!frame_pointer)
break;
@@ -72,7 +74,14 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
--nr_frames;
}
- frame_pointer = (const void **)frame_pointer[0];
+ next_frame_pointer = (const void **)frame_pointer[0];
+
+ /* Limit the stack walk to avoid referencing undefined memory */
+ if((uintptr_t)next_frame_pointer <= (uintptr_t)frame_pointer ||
+ (uintptr_t)next_frame_pointer > (uintptr_t)frame_pointer + 64*1024)
+ break;
+
+ frame_pointer = next_frame_pointer;
}
#endif
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 690412ae7d..6fa13a8ce1 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -1316,7 +1316,6 @@ util_create_gen_mipmap(struct pipe_context *pipe,
for (i = 0; i < 4; i++) {
ctx->vertices[i][0][2] = 0.0f; /* z */
ctx->vertices[i][0][3] = 1.0f; /* w */
- ctx->vertices[i][1][2] = 0.0f; /* r */
ctx->vertices[i][1][3] = 1.0f; /* q */
}
@@ -1350,29 +1349,104 @@ get_next_slot(struct gen_mipmap_state *ctx)
static unsigned
-set_vertex_data(struct gen_mipmap_state *ctx, float width, float height)
+set_vertex_data(struct gen_mipmap_state *ctx,
+ enum pipe_texture_target tex_target,
+ uint face, float width, float height)
{
unsigned offset;
+ /* vert[0].position */
ctx->vertices[0][0][0] = 0.0f; /*x*/
ctx->vertices[0][0][1] = 0.0f; /*y*/
- ctx->vertices[0][1][0] = 0.0f; /*s*/
- ctx->vertices[0][1][1] = 0.0f; /*t*/
+ /* vert[1].position */
ctx->vertices[1][0][0] = width;
ctx->vertices[1][0][1] = 0.0f;
- ctx->vertices[1][1][0] = 1.0f;
- ctx->vertices[1][1][1] = 0.0f;
+ /* vert[2].position */
ctx->vertices[2][0][0] = width;
ctx->vertices[2][0][1] = height;
- ctx->vertices[2][1][0] = 1.0f;
- ctx->vertices[2][1][1] = 1.0f;
+ /* vert[3].position */
ctx->vertices[3][0][0] = 0.0f;
ctx->vertices[3][0][1] = height;
- ctx->vertices[3][1][0] = 0.0f;
- ctx->vertices[3][1][1] = 1.0f;
+
+ /* Setup vertex texcoords. This is a little tricky for cube maps. */
+ if (tex_target == PIPE_TEXTURE_CUBE) {
+ static const float st[4][2] = {
+ {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
+ };
+ float rx, ry, rz;
+ uint i;
+
+ /* loop over quad verts */
+ for (i = 0; i < 4; i++) {
+ /* Compute sc = +/-scale and tc = +/-scale.
+ * Not +/-1 to avoid cube face selection ambiguity near the edges,
+ * though that can still sometimes happen with this scale factor...
+ */
+ const float scale = 0.9999;
+ const float sc = (2.0f * st[i][0] - 1.0f) * scale;
+ const float tc = (2.0f * st[i][1] - 1.0f) * scale;
+
+ switch (face) {
+ case PIPE_TEX_FACE_POS_X:
+ rx = 1.0f;
+ ry = -tc;
+ rz = -sc;
+ break;
+ case PIPE_TEX_FACE_NEG_X:
+ rx = -1.0f;
+ ry = -tc;
+ rz = sc;
+ break;
+ case PIPE_TEX_FACE_POS_Y:
+ rx = sc;
+ ry = 1.0f;
+ rz = tc;
+ break;
+ case PIPE_TEX_FACE_NEG_Y:
+ rx = sc;
+ ry = -1.0f;
+ rz = -tc;
+ break;
+ case PIPE_TEX_FACE_POS_Z:
+ rx = sc;
+ ry = -tc;
+ rz = 1.0f;
+ break;
+ case PIPE_TEX_FACE_NEG_Z:
+ rx = -sc;
+ ry = -tc;
+ rz = -1.0f;
+ break;
+ default:
+ assert(0);
+ }
+
+ ctx->vertices[i][1][0] = rx; /*s*/
+ ctx->vertices[i][1][1] = ry; /*t*/
+ ctx->vertices[i][1][2] = rz; /*r*/
+ }
+ }
+ else {
+ /* 1D/2D */
+ ctx->vertices[0][1][0] = 0.0f; /*s*/
+ ctx->vertices[0][1][1] = 0.0f; /*t*/
+ ctx->vertices[0][1][2] = 0.0f; /*r*/
+
+ ctx->vertices[1][1][0] = 1.0f;
+ ctx->vertices[1][1][1] = 0.0f;
+ ctx->vertices[1][1][2] = 0.0f;
+
+ ctx->vertices[2][1][0] = 1.0f;
+ ctx->vertices[2][1][1] = 1.0f;
+ ctx->vertices[2][1][2] = 0.0f;
+
+ ctx->vertices[3][1][0] = 0.0f;
+ ctx->vertices[3][1][1] = 1.0f;
+ ctx->vertices[3][1][2] = 0.0f;
+ }
offset = get_next_slot( ctx );
@@ -1503,6 +1577,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
/* quad coords in window coords (bypassing vs, clip and viewport) */
offset = set_vertex_data(ctx,
+ pt->target,
+ face,
(float) pt->width[dstLevel],
(float) pt->height[dstLevel]);
diff --git a/src/gallium/auxiliary/util/u_linear.c b/src/gallium/auxiliary/util/u_linear.c
index 6be365e53b..a1dce3f5cf 100644
--- a/src/gallium/auxiliary/util/u_linear.c
+++ b/src/gallium/auxiliary/util/u_linear.c
@@ -1,3 +1,34 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * Functions for converting tiled data to linear and vice versa.
+ */
+
#include "util/u_debug.h"
#include "u_linear.h"
diff --git a/src/gallium/auxiliary/util/u_linear.h b/src/gallium/auxiliary/util/u_linear.h
index 1589f029bc..b74308ffa3 100644
--- a/src/gallium/auxiliary/util/u_linear.h
+++ b/src/gallium/auxiliary/util/u_linear.h
@@ -1,3 +1,34 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * Functions for converting tiled data to linear and vice versa.
+ */
+
#ifndef U_LINEAR_H
#define U_LINEAR_H
diff --git a/src/gallium/auxiliary/util/u_time.c b/src/gallium/auxiliary/util/u_time.c
index 8afe4fccf7..5268cbf79c 100644
--- a/src/gallium/auxiliary/util/u_time.c
+++ b/src/gallium/auxiliary/util/u_time.c
@@ -217,4 +217,9 @@ void util_time_sleep(unsigned usecs)
} while(start <= curr && curr < end ||
end < start && (curr < end || start <= curr));
}
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+void util_time_sleep(unsigned usecs)
+{
+ Sleep((usecs + 999)/ 1000);
+}
#endif
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index d9c0d7afa8..2eb98068c8 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -70,7 +70,7 @@ struct u_upload_mgr *u_upload_create( struct pipe_screen *screen,
}
-static INLINE void
+static INLINE enum pipe_error
my_buffer_write(struct pipe_screen *screen,
struct pipe_buffer *buf,
unsigned offset, unsigned size, unsigned dirty_size,
@@ -84,12 +84,14 @@ my_buffer_write(struct pipe_screen *screen,
assert(size);
map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE);
- assert(map);
- if(map) {
- memcpy(map + offset, data, size);
- pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
- pipe_buffer_unmap(screen, buf);
- }
+ if (map == NULL)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
+ memcpy(map + offset, data, size);
+ pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
+ pipe_buffer_unmap(screen, buf);
+
+ return PIPE_OK;
}
/* Release old buffer.
@@ -162,12 +164,14 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload,
/* Copy the data, using map_range if available:
*/
- my_buffer_write( upload->screen,
- upload->buffer,
- upload->offset,
- size,
- alloc_size,
- data );
+ ret = my_buffer_write( upload->screen,
+ upload->buffer,
+ upload->offset,
+ size,
+ alloc_size,
+ data );
+ if (ret)
+ return ret;
/* Emit the return values:
*/