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/p_debug.c60
-rw-r--r--src/gallium/auxiliary/util/u_blit.c20
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c47
-rw-r--r--src/gallium/auxiliary/util/u_pack_color.h39
-rw-r--r--src/gallium/auxiliary/util/u_time.c8
-rw-r--r--src/gallium/auxiliary/util/u_time.h6
6 files changed, 85 insertions, 95 deletions
diff --git a/src/gallium/auxiliary/util/p_debug.c b/src/gallium/auxiliary/util/p_debug.c
index f9366467cd..25b132b40c 100644
--- a/src/gallium/auxiliary/util/p_debug.c
+++ b/src/gallium/auxiliary/util/p_debug.c
@@ -59,10 +59,15 @@ void _debug_vprintf(const char *format, va_list ap)
#ifdef WIN32
#ifndef WINCE
/* EngDebugPrint does not handle float point arguments, so we need to use
- * our own vsnprintf implementation */
- char buf[512 + 1];
- util_vsnprintf(buf, sizeof(buf), format, ap);
- _EngDebugPrint("%s", buf);
+ * our own vsnprintf implementation. It is also very slow, so buffer until
+ * we find a newline. */
+ static char buf[512 + 1] = {'\0'};
+ size_t len = strlen(buf);
+ int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
+ if(ret > (int)(sizeof(buf) - len - 1) || strchr(buf + len, '\n')) {
+ _EngDebugPrint("%s", buf);
+ buf[0] = '\0';
+ }
#else
/* TODO: Implement debug print for WINCE */
#endif
@@ -195,6 +200,8 @@ debug_get_bool_option(const char *name, boolean dfault)
if(str == NULL)
result = dfault;
+ else if(!strcmp(str, "n"))
+ result = FALSE;
else if(!strcmp(str, "no"))
result = FALSE;
else if(!strcmp(str, "0"))
@@ -246,57 +253,16 @@ debug_get_flags_option(const char *name,
}
-#if defined(WIN32)
-ULONG_PTR debug_config_file = 0;
-void *mapped_config_file = 0;
-
-enum {
- eAssertAbortEn = 0x1,
-};
-
-/* Check for aborts enabled. */
-static unsigned abort_en(void)
-{
- if (!mapped_config_file)
- {
- /* Open an 8 byte file for configuration data. */
- mapped_config_file = EngMapFile(L"\\??\\c:\\gaDebug.cfg", 8, &debug_config_file);
- }
-
- /* A value of "0" (ascii) in the configuration file will clear the
- * first 8 bits in the test byte.
- *
- * A value of "1" (ascii) in the configuration file will set the
- * first bit in the test byte.
- *
- * A value of "2" (ascii) in the configuration file will set the
- * second bit in the test byte.
- *
- * Currently the only interesting values are 0 and 1, which clear
- * and set abort-on-assert behaviour respectively.
- */
- return ((((char *)mapped_config_file)[0]) - 0x30) & eAssertAbortEn;
-}
-#else /* WIN32 */
-static unsigned abort_en(void)
-{
- return !GETENV("GALLIUM_ABORT_ON_ASSERT");
-}
-#endif
-
void _debug_assert_fail(const char *expr,
const char *file,
unsigned line,
const char *function)
{
_debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
- if (abort_en())
- {
+ if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
debug_break();
- } else
- {
+ else
_debug_printf("continuing...\n");
- }
}
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index eec5e600c9..1105066cb8 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -57,6 +57,7 @@ struct blit_state
struct pipe_depth_stencil_alpha_state depthstencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
+ struct pipe_viewport_state viewport;
struct pipe_shader_state vert_shader;
struct pipe_shader_state frag_shader;
@@ -100,7 +101,7 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
ctx->rasterizer.front_winding = PIPE_WINDING_CW;
ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
- ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */
+ ctx->rasterizer.bypass_clipping = 1;
/*ctx->rasterizer.bypass_vs = 1;*/
/* samplers */
@@ -113,8 +114,7 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
ctx->sampler.mag_img_filter = 0; /* set later */
ctx->sampler.normalized_coords = 1;
-#if 0
- /* viewport */
+ /* viewport (identity, we setup vertices in wincoords) */
ctx->viewport.scale[0] = 1.0;
ctx->viewport.scale[1] = 1.0;
ctx->viewport.scale[2] = 1.0;
@@ -123,7 +123,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
ctx->viewport.translate[1] = 0.0;
ctx->viewport.translate[2] = 0.0;
ctx->viewport.translate[3] = 0.0;
-#endif
/* vertex shader */
{
@@ -300,11 +299,15 @@ util_blit_pixels(struct blit_state *ctx,
cso_save_samplers(ctx->cso);
cso_save_sampler_textures(ctx->cso);
cso_save_framebuffer(ctx->cso);
+ cso_save_fragment_shader(ctx->cso);
+ cso_save_vertex_shader(ctx->cso);
+ cso_save_viewport(ctx->cso);
/* set misc state we care about */
cso_set_blend(ctx->cso, &ctx->blend);
cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
+ cso_set_viewport(ctx->cso, &ctx->viewport);
/* sampler */
ctx->sampler.min_img_filter = filter;
@@ -313,11 +316,11 @@ util_blit_pixels(struct blit_state *ctx,
cso_single_sampler_done(ctx->cso);
/* texture */
- pipe->set_sampler_textures(pipe, 1, &tex);
+ cso_set_sampler_textures(ctx->cso, 1, &tex);
/* shaders */
- pipe->bind_fs_state(pipe, ctx->fs);
- pipe->bind_vs_state(pipe, ctx->vs);
+ cso_set_fragment_shader_handle(ctx->cso, ctx->fs);
+ cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
/* drawing dest */
memset(&fb, 0, sizeof(fb));
@@ -344,6 +347,9 @@ util_blit_pixels(struct blit_state *ctx,
cso_restore_samplers(ctx->cso);
cso_restore_sampler_textures(ctx->cso);
cso_restore_framebuffer(ctx->cso);
+ cso_restore_fragment_shader(ctx->cso);
+ cso_restore_vertex_shader(ctx->cso);
+ cso_restore_viewport(ctx->cso);
/* free the texture */
pipe_surface_reference(&texSurf, NULL);
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 2fd214d22e..dfdb5f16fe 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -61,6 +61,7 @@ struct gen_mipmap_state
struct pipe_depth_stencil_alpha_state depthstencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
+ struct pipe_viewport_state viewport;
struct pipe_shader_state vert_shader;
struct pipe_shader_state frag_shader;
@@ -712,7 +713,7 @@ util_create_gen_mipmap(struct pipe_context *pipe,
memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
ctx->rasterizer.front_winding = PIPE_WINDING_CW;
ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
- ctx->rasterizer.bypass_clipping = 1; /* bypasses viewport too */
+ ctx->rasterizer.bypass_clipping = 1;
/*ctx->rasterizer.bypass_vs = 1;*/
/* sampler state */
@@ -723,9 +724,7 @@ util_create_gen_mipmap(struct pipe_context *pipe,
ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
ctx->sampler.normalized_coords = 1;
-
-#if 0
- /* viewport */
+ /* viewport state (identity, verts are in wincoords) */
ctx->viewport.scale[0] = 1.0;
ctx->viewport.scale[1] = 1.0;
ctx->viewport.scale[2] = 1.0;
@@ -734,7 +733,6 @@ util_create_gen_mipmap(struct pipe_context *pipe,
ctx->viewport.translate[1] = 0.0;
ctx->viewport.translate[2] = 0.0;
ctx->viewport.translate[3] = 0.0;
-#endif
/* vertex shader */
{
@@ -825,26 +823,6 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
}
-#if 0
-static void
-simple_viewport(struct pipe_context *pipe, uint width, uint height)
-{
- struct pipe_viewport_state vp;
-
- vp.scale[0] = 0.5 * width;
- vp.scale[1] = -0.5 * height;
- vp.scale[2] = 1.0;
- vp.scale[3] = 1.0;
- vp.translate[0] = 0.5 * width;
- vp.translate[1] = 0.5 * height;
- vp.translate[2] = 0.0;
- vp.translate[3] = 0.0;
-
- pipe->set_viewport_state(pipe, &vp);
-}
-#endif
-
-
/**
* Generate mipmap images. It's assumed all needed texture memory is
* already allocated.
@@ -880,17 +858,18 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
cso_save_samplers(ctx->cso);
cso_save_sampler_textures(ctx->cso);
cso_save_framebuffer(ctx->cso);
+ cso_save_fragment_shader(ctx->cso);
+ cso_save_vertex_shader(ctx->cso);
+ cso_save_viewport(ctx->cso);
/* bind our state */
cso_set_blend(ctx->cso, &ctx->blend);
cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
+ cso_set_viewport(ctx->cso, &ctx->viewport);
- pipe->bind_vs_state(pipe, ctx->vs);
- pipe->bind_fs_state(pipe, ctx->fs);
-#if 0
- pipe->set_viewport_state(pipe, &ctx->viewport);
-#endif
+ cso_set_fragment_shader_handle(ctx->cso, ctx->fs);
+ cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
/* init framebuffer state */
memset(&fb, 0, sizeof(fb));
@@ -926,11 +905,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
ctx->sampler.lod_bias = (float) srcLevel;
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
-#if 0
- simple_viewport(pipe, pt->width[dstLevel], pt->height[dstLevel]);
-#endif
- pipe->set_sampler_textures(pipe, 1, &pt);
+ cso_set_sampler_textures(ctx->cso, 1, &pt);
/* quad coords in window coords (bypassing clipping, viewport mapping) */
set_vertex_data(ctx,
@@ -954,4 +930,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
cso_restore_samplers(ctx->cso);
cso_restore_sampler_textures(ctx->cso);
cso_restore_framebuffer(ctx->cso);
+ cso_restore_fragment_shader(ctx->cso);
+ cso_restore_vertex_shader(ctx->cso);
+ cso_restore_viewport(ctx->cso);
}
diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h
index cd13823985..1f6604c554 100644
--- a/src/gallium/auxiliary/util/u_pack_color.h
+++ b/src/gallium/auxiliary/util/u_pack_color.h
@@ -40,6 +40,45 @@
/**
+ * Pack ubyte R,G,B,A into dest pixel.
+ */
+static INLINE void
+util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a,
+ enum pipe_format format, void *dest)
+{
+ switch (format) {
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
+ {
+ uint *d = (uint *) dest;
+ *d = (r << 24) | (g << 16) | (b << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ {
+ uint *d = (uint *) dest;
+ *d = (a << 24) | (r << 16) | (g << 8) | b;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ {
+ uint *d = (uint *) dest;
+ *d = (b << 24) | (g << 16) | (r << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_R5G6B5_UNORM:
+ {
+ ushort *d = (ushort *) dest;
+ *d = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
+ }
+ return;
+ /* XXX lots more cases to add */
+ default:
+ debug_printf("gallium: unhandled format in util_pack_color_ub()");
+ }
+}
+
+
+/**
* Note rgba outside [0,1] will be clamped for int pixel formats.
*/
static INLINE void
diff --git a/src/gallium/auxiliary/util/u_time.c b/src/gallium/auxiliary/util/u_time.c
index e6c0b19ff6..01112ebe5a 100644
--- a/src/gallium/auxiliary/util/u_time.c
+++ b/src/gallium/auxiliary/util/u_time.c
@@ -120,20 +120,20 @@ util_time_compare(const struct util_time *t1,
}
-int
+boolean
util_time_timeout(const struct util_time *start,
const struct util_time *end,
const struct util_time *curr)
{
if(util_time_compare(start, end) <= 0)
- return util_time_compare(start, curr) <= 0 && util_time_compare(curr, end) < 0;
+ return !(util_time_compare(start, curr) <= 0 && util_time_compare(curr, end) < 0);
else
- return util_time_compare(start, curr) <= 0 || util_time_compare(curr, end) < 0;
+ return !(util_time_compare(start, curr) <= 0 || util_time_compare(curr, end) < 0);
}
#ifdef WIN32
-void util_time_usleep(unsigned usecs)
+void util_time_sleep(unsigned usecs)
{
LONGLONG start, curr, end;
diff --git a/src/gallium/auxiliary/util/u_time.h b/src/gallium/auxiliary/util/u_time.h
index 32035cceb5..c8836c137f 100644
--- a/src/gallium/auxiliary/util/u_time.h
+++ b/src/gallium/auxiliary/util/u_time.h
@@ -77,9 +77,9 @@ util_time_diff(const struct util_time *t1,
const struct util_time *t2);
/**
- * Returns zero when the timeout expires, non zero otherwise.
+ * Returns non-zero when the timeout expires.
*/
-int
+boolean
util_time_timeout(const struct util_time *start,
const struct util_time *end,
const struct util_time *curr);
@@ -87,7 +87,7 @@ util_time_timeout(const struct util_time *start,
#ifndef WIN32
#define util_time_sleep usleep
#else
-int
+void
util_time_sleep(unsigned usecs);
#endif