diff options
Diffstat (limited to 'src/gallium')
82 files changed, 2329 insertions, 1485 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch.c b/src/gallium/auxiliary/draw/draw_pt_fetch.c index 058caf7dcc3..505d32f2c32 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch.c @@ -114,7 +114,7 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch, fetch->translate = translate_cache_find(fetch->cache, &key); { - static struct vertex_header vh = { 0, 1, 0, 0xffff }; + static struct vertex_header vh = { 0, 1, 0, UNDEFINED_VERTEX_ID, { .0f, .0f, .0f, .0f } }; fetch->translate->set_buffer(fetch->translate, draw->pt.nr_vertex_buffers, &vh, diff --git a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h index 55a8e6521dc..010c7a18a7c 100644 --- a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h +++ b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h @@ -9,7 +9,7 @@ static void FUNC(struct draw_pt_front_end *frontend, unsigned count) { struct varray_frontend *varray = (struct varray_frontend *)frontend; - unsigned start = (unsigned)elts; + unsigned start = (unsigned) ((char *) elts - (char *) NULL); unsigned j; unsigned first, incr; diff --git a/src/gallium/auxiliary/draw/draw_vs_aos_machine.c b/src/gallium/auxiliary/draw/draw_vs_aos_machine.c index b358bd2df47..3240e3745dd 100644 --- a/src/gallium/auxiliary/draw/draw_vs_aos_machine.c +++ b/src/gallium/auxiliary/draw/draw_vs_aos_machine.c @@ -74,7 +74,7 @@ void PIPE_CDECL aos_do_lit( struct aos_machine *machine, { result[0] = 1.0F; result[1] = in[0]; - result[2] = 1.0; + result[2] = 0.0F; result[3] = 1.0F; } else @@ -108,7 +108,7 @@ static void PIPE_CDECL do_lit_lut( struct aos_machine *machine, { result[0] = 1.0F; result[1] = in[0]; - result[2] = 1.0; + result[2] = 0.0F; result[3] = 1.0F; return; } diff --git a/src/gallium/auxiliary/rtasm/rtasm_cpu.c b/src/gallium/auxiliary/rtasm/rtasm_cpu.c index 03bdd472386..2e15751e508 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_cpu.c +++ b/src/gallium/auxiliary/rtasm/rtasm_cpu.c @@ -30,6 +30,7 @@ #include "rtasm_cpu.h" +#if defined(PIPE_ARCH_X86) static boolean rtasm_sse_enabled(void) { static boolean firsttime = 1; @@ -43,6 +44,7 @@ static boolean rtasm_sse_enabled(void) } return enabled; } +#endif int rtasm_cpu_has_sse(void) { diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.c b/src/gallium/auxiliary/tgsi/tgsi_sse2.c index d70bcd03c5c..4b4e34b29eb 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_sse2.c +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.c @@ -1477,6 +1477,7 @@ emit_instruction( case TGSI_OPCODE_ARL: FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { FETCH( func, *inst, 0, 0, chan_index ); + emit_flr(func, 0, 0); emit_f2it( func, 0 ); STORE( func, *inst, 0, 0, chan_index ); } @@ -1553,7 +1554,7 @@ emit_instruction( func, make_xmm( 2 ), make_xmm( 0 ), - cc_LessThanEqual ); + cc_LessThan ); sse_andps( func, make_xmm( 2 ), @@ -2177,32 +2178,83 @@ emit_instruction( /* 3 or 4-component normalization */ { uint dims = (inst->Instruction.Opcode == TGSI_OPCODE_NRM) ? 3 : 4; - /* note: cannot use xmm regs 2/3 here (see emit_rsqrt() above) */ - FETCH( func, *inst, 4, 0, CHAN_X ); /* xmm4 = src[0].x */ - FETCH( func, *inst, 5, 0, CHAN_Y ); /* xmm5 = src[0].y */ - FETCH( func, *inst, 6, 0, CHAN_Z ); /* xmm6 = src[0].z */ - if (dims == 4) { - FETCH( func, *inst, 7, 0, CHAN_W ); /* xmm7 = src[0].w */ - } - emit_MOV( func, 0, 4 ); /* xmm0 = xmm3 */ - emit_mul( func, 0, 4 ); /* xmm0 *= xmm3 */ - emit_MOV( func, 1, 5 ); /* xmm1 = xmm4 */ - emit_mul( func, 1, 5 ); /* xmm1 *= xmm4 */ - emit_add( func, 0, 1 ); /* xmm0 += xmm1 */ - emit_MOV( func, 1, 6 ); /* xmm1 = xmm5 */ - emit_mul( func, 1, 6 ); /* xmm1 *= xmm5 */ - emit_add( func, 0, 1 ); /* xmm0 += xmm1 */ - if (dims == 4) { - emit_MOV( func, 1, 7 ); /* xmm1 = xmm7 */ - emit_mul( func, 1, 7 ); /* xmm1 *= xmm7 */ - emit_add( func, 0, 0 ); /* xmm0 += xmm1 */ - } - emit_rsqrt( func, 1, 0 ); /* xmm1 = 1/sqrt(xmm0) */ - FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { - if (chan_index < dims) { - emit_mul( func, 4+chan_index, 1); /* xmm[4+ch] *= xmm1 */ - STORE( func, *inst, 4+chan_index, 0, chan_index ); + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z) || + (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W) && dims == 4)) { + + /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */ + + /* xmm4 = src.x */ + /* xmm0 = src.x * src.x */ + FETCH(func, *inst, 0, 0, CHAN_X); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_MOV(func, 4, 0); } + emit_mul(func, 0, 0); + + /* xmm5 = src.y */ + /* xmm0 = xmm0 + src.y * src.y */ + FETCH(func, *inst, 1, 0, CHAN_Y); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + emit_MOV(func, 5, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + + /* xmm6 = src.z */ + /* xmm0 = xmm0 + src.z * src.z */ + FETCH(func, *inst, 1, 0, CHAN_Z); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + emit_MOV(func, 6, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + + if (dims == 4) { + /* xmm7 = src.w */ + /* xmm0 = xmm0 + src.w * src.w */ + FETCH(func, *inst, 1, 0, CHAN_W); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W)) { + emit_MOV(func, 7, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + } + + /* xmm1 = 1 / sqrt(xmm0) */ + emit_rsqrt(func, 1, 0); + + /* dst.x = xmm1 * src.x */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_mul(func, 4, 1); + STORE(func, *inst, 4, 0, CHAN_X); + } + + /* dst.y = xmm1 * src.y */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + emit_mul(func, 5, 1); + STORE(func, *inst, 5, 0, CHAN_Y); + } + + /* dst.z = xmm1 * src.z */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + emit_mul(func, 6, 1); + STORE(func, *inst, 6, 0, CHAN_Z); + } + + /* dst.w = xmm1 * src.w */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) && dims == 4) { + emit_mul(func, 7, 1); + STORE(func, *inst, 7, 0, CHAN_W); + } + } + + /* dst0.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W) && dims == 3) { + emit_tempf(func, 0, TEMP_ONE_I, TEMP_ONE_C); + STORE(func, *inst, 0, 0, CHAN_W); } } break; diff --git a/src/gallium/auxiliary/util/Makefile b/src/gallium/auxiliary/util/Makefile index 5035e9cc133..2995aba1b91 100644 --- a/src/gallium/auxiliary/util/Makefile +++ b/src/gallium/auxiliary/util/Makefile @@ -23,6 +23,7 @@ C_SOURCES = \ u_snprintf.c \ u_stream_stdc.c \ u_stream_wd.c \ + u_surface.c \ u_tile.c \ u_time.c \ u_timed_winsys.c \ diff --git a/src/gallium/auxiliary/util/SConscript b/src/gallium/auxiliary/util/SConscript index 8317263bb8b..d3ac7f747fd 100644 --- a/src/gallium/auxiliary/util/SConscript +++ b/src/gallium/auxiliary/util/SConscript @@ -24,6 +24,7 @@ util = env.ConvenienceLibrary( 'u_snprintf.c', 'u_stream_stdc.c', 'u_stream_wd.c', + 'u_surface.c', 'u_tile.c', 'u_time.c', 'u_timed_winsys.c', diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index deb68c43a6c..414cf910254 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -89,10 +89,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) /* disabled blending/masking */ memset(&ctx->blend, 0, sizeof(ctx->blend)); - ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; - ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; ctx->blend.colormask = PIPE_MASK_RGBA; /* no-op depth/stencil/alpha */ @@ -337,7 +333,6 @@ util_blit_pixels(struct blit_state *ctx, texTemp.width[0] = srcW; texTemp.height[0] = srcH; texTemp.depth[0] = 1; - texTemp.compressed = 0; pf_get_block(src->format, &texTemp.block); tex = screen->texture_create(screen, &texTemp); diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 96a2222f9b6..ae47a274a69 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -109,6 +109,7 @@ void _debug_vprintf(const char *format, va_list ap) } if(GetConsoleWindow() && !IsDebuggerPresent()) { + fflush(stdout); vfprintf(stderr, format, ap); fflush(stderr); } @@ -145,6 +146,7 @@ void _debug_vprintf(const char *format, va_list ap) /* TODO */ #else /* !PIPE_SUBSYSTEM_WINDOWS */ #ifdef DEBUG + fflush(stdout); vfprintf(stderr, format, ap); #endif #endif diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index b32ad1cbe98..690412ae7d3 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -1278,10 +1278,6 @@ util_create_gen_mipmap(struct pipe_context *pipe, /* disabled blending/masking */ memset(&ctx->blend, 0, sizeof(ctx->blend)); - ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; - ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; ctx->blend.colormask = PIPE_MASK_RGBA; /* no-op depth/stencil/alpha */ diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c new file mode 100644 index 00000000000..85e443204e3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_surface.c @@ -0,0 +1,113 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Surface utility functions. + * + * @author Brian Paul + */ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_surface.h" + + +/** + * Helper to quickly create an RGBA rendering surface of a certain size. + * \param textureOut returns the new texture + * \param surfaceOut returns the new surface + * \return TRUE for success, FALSE if failure + */ +boolean +util_create_rgba_surface(struct pipe_screen *screen, + uint width, uint height, + struct pipe_texture **textureOut, + struct pipe_surface **surfaceOut) +{ + static const enum pipe_format rgbaFormats[] = { + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_NONE + }; + const uint target = PIPE_TEXTURE_2D; + const uint usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + enum pipe_format format = PIPE_FORMAT_NONE; + struct pipe_texture templ; + uint i; + + /* Choose surface format */ + for (i = 0; rgbaFormats[i]; i++) { + if (screen->is_format_supported(screen, rgbaFormats[i], + target, usage, 0)) { + format = rgbaFormats[i]; + break; + } + } + if (format == PIPE_FORMAT_NONE) + return FALSE; /* unable to get an rgba format!?! */ + + /* create texture */ + memset(&templ, 0, sizeof(templ)); + templ.target = target; + templ.format = format; + templ.last_level = 0; + templ.width[0] = width; + templ.height[0] = height; + templ.depth[0] = 1; + pf_get_block(format, &templ.block); + templ.tex_usage = usage; + + *textureOut = screen->texture_create(screen, &templ); + if (!*textureOut) + return FALSE; + + /* create surface / view into texture */ + *surfaceOut = screen->get_tex_surface(screen, *textureOut, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + if (!*surfaceOut) { + pipe_texture_reference(textureOut, NULL); + return FALSE; + } + + return TRUE; +} + + +/** + * Release the surface and texture from util_create_rgba_surface(). + */ +void +util_destroy_rgba_surface(struct pipe_texture *texture, + struct pipe_surface *surface) +{ + pipe_surface_reference(&surface, NULL); + pipe_texture_reference(&texture, NULL); +} + diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.h b/src/gallium/auxiliary/util/u_surface.h index a0e4c5d98e8..a5b73cfc20a 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -1,8 +1,7 @@ /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * + * + * 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 @@ -10,26 +9,44 @@ * 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * 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. - * + * **************************************************************************/ -#ifndef WGL_ARBEXTENSIONSSTRING_H -#define WGL_ARBEXTENSIONSSTRING_H -WINGDIAPI const char * APIENTRY -wglGetExtensionsStringARB( - HDC hdc ); +#ifndef U_SURFACE_H +#define U_SURFACE_H -#endif /* WGL_ARBEXTENSIONSSTRING_H */ + +#include "pipe/p_compiler.h" + + +struct pipe_screen; +struct pipe_texture; +struct pipe_surface; + + +extern boolean +util_create_rgba_surface(struct pipe_screen *screen, + uint width, uint height, + struct pipe_texture **textureOut, + struct pipe_surface **surfaceOut); + + +extern void +util_destroy_rgba_surface(struct pipe_texture *texture, + struct pipe_surface *surface); + + +#endif /* U_SURFACE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_context.c b/src/gallium/drivers/cell/ppu/cell_context.c index 808be589bd9..ebb7a7acc44 100644 --- a/src/gallium/drivers/cell/ppu/cell_context.c +++ b/src/gallium/drivers/cell/ppu/cell_context.c @@ -99,6 +99,28 @@ static const struct debug_named_value cell_debug_flags[] = { {NULL, 0} }; +static unsigned int +cell_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +cell_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} struct pipe_context * cell_create_context(struct pipe_screen *screen, @@ -122,6 +144,9 @@ cell_create_context(struct pipe_screen *screen, cell->pipe.clear = cell_clear; cell->pipe.flush = cell_flush; + cell->pipe.is_texture_referenced = cell_is_texture_referenced; + cell->pipe.is_buffer_referenced = cell_is_buffer_referenced; + #if 0 cell->pipe.begin_query = cell_begin_query; cell->pipe.end_query = cell_end_query; diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index fcad717cf83..37184eac7b1 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -105,7 +105,28 @@ static boolean failover_draw_arrays( struct pipe_context *pipe, return failover_draw_elements(pipe, NULL, 0, prim, start, count); } +static unsigned int +failover_is_texture_referenced( struct pipe_context *_pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + struct failover_context *failover = failover_context( _pipe ); + struct pipe_context *pipe = (failover->mode == FO_HW) ? + failover->hw : failover->sw; + + return pipe->is_texture_referenced(pipe, texture, face, level); +} +static unsigned int +failover_is_buffer_referenced( struct pipe_context *_pipe, + struct pipe_buffer *buf) +{ + struct failover_context *failover = failover_context( _pipe ); + struct pipe_context *pipe = (failover->mode == FO_HW) ? + failover->hw : failover->sw; + + return pipe->is_buffer_referenced(pipe, buf); +} struct pipe_context *failover_create( struct pipe_context *hw, struct pipe_context *sw ) @@ -151,6 +172,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.flush = hw->flush; + failover->pipe.is_texture_referenced = failover_is_texture_referenced; + failover->pipe.is_buffer_referenced = failover_is_buffer_referenced; failover->dirty = 0; diff --git a/src/gallium/drivers/i915simple/i915_context.c b/src/gallium/drivers/i915simple/i915_context.c index 3e3a5968849..ccf9bb31fb0 100644 --- a/src/gallium/drivers/i915simple/i915_context.c +++ b/src/gallium/drivers/i915simple/i915_context.c @@ -136,6 +136,29 @@ static boolean i915_draw_arrays( struct pipe_context *pipe, } +static unsigned int +i915_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +i915_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context *i915_create_context( struct pipe_screen *screen, struct pipe_winsys *pipe_winsys, @@ -160,6 +183,9 @@ struct pipe_context *i915_create_context( struct pipe_screen *screen, i915->pipe.draw_elements = i915_draw_elements; i915->pipe.draw_range_elements = i915_draw_range_elements; + i915->pipe.is_texture_referenced = i915_is_texture_referenced; + i915->pipe.is_buffer_referenced = i915_is_buffer_referenced; + /* * Create drawing context and plug our rendering stage into it. */ diff --git a/src/gallium/drivers/i965simple/brw_context.c b/src/gallium/drivers/i965simple/brw_context.c index c74cbf8d73e..9b33285bc73 100644 --- a/src/gallium/drivers/i965simple/brw_context.c +++ b/src/gallium/drivers/i965simple/brw_context.c @@ -73,6 +73,28 @@ static void brw_clear(struct pipe_context *pipe, struct pipe_surface *ps, pipe->surface_fill(pipe, ps, x, y, w, h, clearValue); } +static unsigned int +brw_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +brw_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} struct pipe_context *brw_create(struct pipe_screen *screen, struct brw_winsys *brw_winsys, @@ -94,6 +116,9 @@ struct pipe_context *brw_create(struct pipe_screen *screen, brw->pipe.destroy = brw_destroy; brw->pipe.clear = brw_clear; + brw->pipe.is_texture_referenced = brw_is_texture_referenced; + brw->pipe.is_buffer_referenced = brw_is_buffer_referenced; + brw_init_surface_functions(brw); brw_init_texture_functions(brw); brw_init_state_functions(brw); diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index f44bd17451b..8aea8c05581 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -240,7 +240,7 @@ static boolean brw_miptree_layout(struct brw_texture *tex) nblocksx = pf_get_nblocksx(&pt->block, width); nblocksy = pf_get_nblocksy(&pt->block, height); - if (pt->compressed) { + if (pf_is_compressed(pt->format)) { pack_y_pitch = (height + 3) / 4; if (pack_x_pitch > align(width, align_w)) { diff --git a/src/gallium/drivers/nv04/nv04_context.c b/src/gallium/drivers/nv04/nv04_context.c index d6710cd8924..17166c9f51d 100644 --- a/src/gallium/drivers/nv04/nv04_context.c +++ b/src/gallium/drivers/nv04/nv04_context.c @@ -64,6 +64,30 @@ nv04_init_hwctx(struct nv04_context *nv04) return TRUE; } +static unsigned int +nv04_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv04_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + struct pipe_context * nv04_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -89,6 +113,9 @@ nv04_create(struct pipe_screen *pscreen, unsigned pctx_id) nv04->pipe.clear = nv04_clear; nv04->pipe.flush = nv04_flush; + nv04->pipe.is_texture_referenced = nv04_is_texture_referenced; + nv04->pipe.is_buffer_referenced = nv04_is_buffer_referenced; + nv04_init_surface_functions(nv04); nv04_init_state_functions(nv04); diff --git a/src/gallium/drivers/nv04/nv04_transfer.c b/src/gallium/drivers/nv04/nv04_transfer.c index e925a44e298..854b855d64a 100644 --- a/src/gallium/drivers/nv04/nv04_transfer.c +++ b/src/gallium/drivers/nv04/nv04_transfer.c @@ -43,7 +43,6 @@ nv04_compatible_transfer_tex(struct pipe_texture *pt, unsigned level, template->nblocksx[0] = pt->nblocksx[level]; template->nblocksy[0] = pt->nblocksx[level]; template->last_level = 0; - template->compressed = pt->compressed; template->nr_samples = pt->nr_samples; template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | diff --git a/src/gallium/drivers/nv10/nv10_context.c b/src/gallium/drivers/nv10/nv10_context.c index ef2c0c5d9fd..3da8d2f568f 100644 --- a/src/gallium/drivers/nv10/nv10_context.c +++ b/src/gallium/drivers/nv10/nv10_context.c @@ -257,6 +257,29 @@ nv10_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } +static unsigned int +nv10_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv10_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv10_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -282,6 +305,9 @@ nv10_create(struct pipe_screen *pscreen, unsigned pctx_id) nv10->pipe.clear = nv10_clear; nv10->pipe.flush = nv10_flush; + nv10->pipe.is_texture_referenced = nv10_is_texture_referenced; + nv10->pipe.is_buffer_referenced = nv10_is_buffer_referenced; + nv10_init_surface_functions(nv10); nv10_init_state_functions(nv10); diff --git a/src/gallium/drivers/nv10/nv10_transfer.c b/src/gallium/drivers/nv10/nv10_transfer.c index 5a99225409c..c06b8d34c72 100644 --- a/src/gallium/drivers/nv10/nv10_transfer.c +++ b/src/gallium/drivers/nv10/nv10_transfer.c @@ -43,7 +43,6 @@ nv10_compatible_transfer_tex(struct pipe_texture *pt, unsigned level, template->nblocksx[0] = pt->nblocksx[level]; template->nblocksy[0] = pt->nblocksx[level]; template->last_level = 0; - template->compressed = pt->compressed; template->nr_samples = pt->nr_samples; template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | diff --git a/src/gallium/drivers/nv20/nv20_context.c b/src/gallium/drivers/nv20/nv20_context.c index 1659aec8fab..cbc41707d54 100644 --- a/src/gallium/drivers/nv20/nv20_context.c +++ b/src/gallium/drivers/nv20/nv20_context.c @@ -380,6 +380,30 @@ nv20_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } + +static unsigned int +nv20_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv20_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv20_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -405,6 +429,9 @@ nv20_create(struct pipe_screen *pscreen, unsigned pctx_id) nv20->pipe.clear = nv20_clear; nv20->pipe.flush = nv20_flush; + nv20->pipe.is_texture_referenced = nv20_is_texture_referenced; + nv20->pipe.is_buffer_referenced = nv20_is_buffer_referenced; + nv20_init_surface_functions(nv20); nv20_init_state_functions(nv20); diff --git a/src/gallium/drivers/nv20/nv20_transfer.c b/src/gallium/drivers/nv20/nv20_transfer.c index e5255296aae..5018995596c 100644 --- a/src/gallium/drivers/nv20/nv20_transfer.c +++ b/src/gallium/drivers/nv20/nv20_transfer.c @@ -43,7 +43,6 @@ nv20_compatible_transfer_tex(struct pipe_texture *pt, unsigned level, template->nblocksx[0] = pt->nblocksx[level]; template->nblocksy[0] = pt->nblocksx[level]; template->last_level = 0; - template->compressed = pt->compressed; template->nr_samples = pt->nr_samples; template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | diff --git a/src/gallium/drivers/nv30/nv30_context.c b/src/gallium/drivers/nv30/nv30_context.c index 61654f8756a..f827bdc78b1 100644 --- a/src/gallium/drivers/nv30/nv30_context.c +++ b/src/gallium/drivers/nv30/nv30_context.c @@ -31,6 +31,29 @@ nv30_destroy(struct pipe_context *pipe) FREE(nv30); } +static unsigned int +nv30_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv30_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv30_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -55,6 +78,9 @@ nv30_create(struct pipe_screen *pscreen, unsigned pctx_id) nv30->pipe.clear = nv30_clear; nv30->pipe.flush = nv30_flush; + nv30->pipe.is_texture_referenced = nv30_is_texture_referenced; + nv30->pipe.is_buffer_referenced = nv30_is_buffer_referenced; + nv30_init_query_functions(nv30); nv30_init_surface_functions(nv30); nv30_init_state_functions(nv30); diff --git a/src/gallium/drivers/nv30/nv30_transfer.c b/src/gallium/drivers/nv30/nv30_transfer.c index 8b915b35bd4..23675718781 100644 --- a/src/gallium/drivers/nv30/nv30_transfer.c +++ b/src/gallium/drivers/nv30/nv30_transfer.c @@ -43,7 +43,6 @@ nv30_compatible_transfer_tex(struct pipe_texture *pt, unsigned level, template->nblocksx[0] = pt->nblocksx[level]; template->nblocksy[0] = pt->nblocksx[level]; template->last_level = 0; - template->compressed = pt->compressed; template->nr_samples = pt->nr_samples; template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | diff --git a/src/gallium/drivers/nv40/nv40_context.c b/src/gallium/drivers/nv40/nv40_context.c index 5d325f5067f..8eba6a43ef9 100644 --- a/src/gallium/drivers/nv40/nv40_context.c +++ b/src/gallium/drivers/nv40/nv40_context.c @@ -31,6 +31,29 @@ nv40_destroy(struct pipe_context *pipe) FREE(nv40); } +static unsigned int +nv40_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv40_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv40_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -55,6 +78,9 @@ nv40_create(struct pipe_screen *pscreen, unsigned pctx_id) nv40->pipe.clear = nv40_clear; nv40->pipe.flush = nv40_flush; + nv40->pipe.is_texture_referenced = nv40_is_texture_referenced; + nv40->pipe.is_buffer_referenced = nv40_is_buffer_referenced; + nv40_init_query_functions(nv40); nv40_init_surface_functions(nv40); nv40_init_state_functions(nv40); diff --git a/src/gallium/drivers/nv40/nv40_transfer.c b/src/gallium/drivers/nv40/nv40_transfer.c index 728e8b56745..ce45055fe82 100644 --- a/src/gallium/drivers/nv40/nv40_transfer.c +++ b/src/gallium/drivers/nv40/nv40_transfer.c @@ -43,7 +43,6 @@ nv40_compatible_transfer_tex(struct pipe_texture *pt, unsigned level, template->nblocksx[0] = pt->nblocksx[level]; template->nblocksy[0] = pt->nblocksx[level]; template->last_level = 0; - template->compressed = pt->compressed; template->nr_samples = pt->nr_samples; template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | diff --git a/src/gallium/drivers/nv50/nv50_clear.c b/src/gallium/drivers/nv50/nv50_clear.c index db44a9da0e3..33427a15a56 100644 --- a/src/gallium/drivers/nv50/nv50_clear.c +++ b/src/gallium/drivers/nv50/nv50_clear.c @@ -27,64 +27,42 @@ #include "nv50_context.h" void -nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps, - unsigned clearValue) +nv50_clear(struct pipe_context *pipe, unsigned buffers, + const float *rgba, double depth, unsigned stencil) { struct nv50_context *nv50 = nv50_context(pipe); struct nouveau_channel *chan = nv50->screen->nvws->channel; struct nouveau_grobj *tesla = nv50->screen->tesla; - struct pipe_framebuffer_state fb, s_fb = nv50->framebuffer; - struct pipe_scissor_state sc, s_sc = nv50->scissor; - unsigned dirty = nv50->dirty; + struct pipe_framebuffer_state *fb = &nv50->framebuffer; + unsigned mode = 0, i; - nv50->dirty = 0; + if (!nv50_state_validate(nv50)) + return; - if (ps->format == PIPE_FORMAT_Z24S8_UNORM || - ps->format == PIPE_FORMAT_Z16_UNORM) { - fb.nr_cbufs = 0; - fb.zsbuf = ps; - } else { - fb.nr_cbufs = 1; - fb.cbufs[0] = ps; - fb.zsbuf = NULL; + if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_COLOR(0), 4); + OUT_RING (chan, fui(rgba[0])); + OUT_RING (chan, fui(rgba[1])); + OUT_RING (chan, fui(rgba[2])); + OUT_RING (chan, fui(rgba[3])); + mode |= 0x3c; } - fb.width = ps->width; - fb.height = ps->height; - pipe->set_framebuffer_state(pipe, &fb); - sc.minx = sc.miny = 0; - sc.maxx = fb.width; - sc.maxy = fb.height; - pipe->set_scissor_state(pipe, &sc); + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_DEPTH, 1); + OUT_RING (chan, fui(depth)); + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_STENCIL, 1); + OUT_RING (chan, stencil & 0xff); - nv50_state_validate(nv50); - - switch (ps->format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - BEGIN_RING(chan, tesla, 0x0d80, 4); - OUT_RINGf (chan, ubyte_to_float((clearValue >> 16) & 0xff)); - OUT_RINGf (chan, ubyte_to_float((clearValue >> 8) & 0xff)); - OUT_RINGf (chan, ubyte_to_float((clearValue >> 0) & 0xff)); - OUT_RINGf (chan, ubyte_to_float((clearValue >> 24) & 0xff)); - BEGIN_RING(chan, tesla, 0x19d0, 1); - OUT_RING (chan, 0x3c); - break; - case PIPE_FORMAT_Z24S8_UNORM: - BEGIN_RING(chan, tesla, 0x0d90, 1); - OUT_RINGf (chan, (float)(clearValue >> 8) * (1.0 / 16777215.0)); - BEGIN_RING(chan, tesla, 0x0da0, 1); - OUT_RING (chan, clearValue & 0xff); - BEGIN_RING(chan, tesla, 0x19d0, 1); - OUT_RING (chan, 0x03); - break; - default: - pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, - clearValue); - break; + mode |= 0x03; } - pipe->set_framebuffer_state(pipe, &s_fb); - pipe->set_scissor_state(pipe, &s_sc); - nv50->dirty |= dirty; + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, mode); + + for (i = 1; i < fb->nr_cbufs; i++) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, (i << 6) | 0x3c); + } } diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c index 565a5da668c..a511f655c19 100644 --- a/src/gallium/drivers/nv50/nv50_context.c +++ b/src/gallium/drivers/nv50/nv50_context.c @@ -51,6 +51,29 @@ nv50_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } +static unsigned int +nv50_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv50_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv50_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -76,6 +99,9 @@ nv50_create(struct pipe_screen *pscreen, unsigned pctx_id) nv50->pipe.flush = nv50_flush; + nv50->pipe.is_texture_referenced = nv50_is_texture_referenced; + nv50->pipe.is_buffer_referenced = nv50_is_buffer_referenced; + nv50_init_surface_functions(nv50); nv50_init_state_functions(nv50); nv50_init_query_functions(nv50); diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 31efe914171..6bdf544a05c 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -102,6 +102,29 @@ static void r300_destroy_context(struct pipe_context* context) { FREE(r300); } +static unsigned int +r300_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +r300_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context* r300_create_context(struct pipe_screen* screen, struct r300_winsys* r300_winsys) { @@ -124,6 +147,9 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300->context.draw_elements = r300_draw_elements; r300->context.draw_range_elements = r300_draw_range_elements; + r300->context.is_texture_referenced = r300_is_texture_referenced; + r300->context.is_buffer_referenced = r300_is_buffer_referenced; + r300->draw = draw_create(); draw_set_rasterize_stage(r300->draw, r300_draw_stage(r300)); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index fec2bad5461..4c695c1195a 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -60,7 +60,7 @@ struct r300_dsa_state { }; struct r300_rs_state { - /* XXX icky as fucking hell */ + /* Draw-specific rasterizer state */ struct pipe_rasterizer_state rs; uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */ @@ -225,10 +225,11 @@ struct r300_vertex_format { uint32_t vap_prog_stream_cntl[8]; /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ uint32_t vap_prog_stream_cntl_ext[8]; - /* This is a map of VAP/SW TCL outputs into the GA/RS. - * tab[i] is the location of input i in GA/RS input memory. - * Named tab for historical reasons. */ - int tab[16]; + /* Map of vertex attributes into PVS memory for HW TCL, + * or GA memory for SW TCL. */ + int vs_tab[16]; + /* Map of rasterizer attributes from GB through RS to US. */ + int fs_tab[16]; }; struct r300_vertex_shader { diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index a3d83376b66..417d5f6307d 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -340,7 +340,11 @@ void r300_emit_vertex_shader(struct r300_context* r300, return; } - BEGIN_CS(13 + (vs->instruction_count * 4) + (constants->count * 4)); + if (constants->count) { + BEGIN_CS(16 + (vs->instruction_count * 4) + (constants->count * 4)); + } else { + BEGIN_CS(13 + (vs->instruction_count * 4) + (constants->count * 4)); + } OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_0, R300_PVS_FIRST_INST(0) | R300_PVS_LAST_INST(vs->instruction_count - 1)); diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index b7ee8fb8a94..cbd84d7c569 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -234,6 +234,8 @@ static void r300_render_draw(struct vbuf_render* render, struct pipe_screen* screen = r300->context.screen; struct pipe_buffer* index_buffer; void* index_map; + int i; + uint32_t index; CS_LOCALS(r300); @@ -252,14 +254,24 @@ static void r300_render_draw(struct vbuf_render* render, pipe_buffer_unmap(screen, index_buffer); debug_printf("r300: Doing indexbuf render, count %d\n", count); - - BEGIN_CS(6); +/* + BEGIN_CS(8); OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | r300render->hwprim); OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2)); OUT_CS_INDEX_RELOC(index_buffer, 0, count, RADEON_GEM_DOMAIN_GTT, 0, 0); + END_CS; */ + + BEGIN_CS(2 + count); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, count); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + r300render->hwprim | R300_VAP_VF_CNTL__INDEX_SIZE_32bit); + for (i = 0; i < count; i++) { + index = indices[i]; + OUT_CS(index); + } END_CS; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 2a77fd17390..c9507ae1937 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -555,25 +555,41 @@ static void r300_set_viewport_state(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - r300->viewport_state->xscale = state->scale[0]; - r300->viewport_state->yscale = state->scale[1]; - r300->viewport_state->zscale = state->scale[2]; - - r300->viewport_state->xoffset = state->translate[0]; - r300->viewport_state->yoffset = state->translate[1]; - r300->viewport_state->zoffset = state->translate[2]; - - r300->viewport_state->vte_control = 0; if (r300_screen(r300->context.screen)->caps->has_tcl) { /* Do the transform in HW. */ - r300->viewport_state->vte_control |= - R300_VPORT_X_SCALE_ENA | R300_VPORT_X_OFFSET_ENA | - R300_VPORT_Y_SCALE_ENA | R300_VPORT_Y_OFFSET_ENA | - R300_VPORT_Z_SCALE_ENA | R300_VPORT_Z_OFFSET_ENA; + r300->viewport_state->vte_control = R300_VTX_W0_FMT; + + if (state->scale[0] != 1.0f) { + r300->viewport_state->xscale = state->scale[0]; + r300->viewport_state->vte_control |= R300_VPORT_X_SCALE_ENA; + } + if (state->scale[1] != 1.0f) { + r300->viewport_state->yscale = state->scale[1]; + r300->viewport_state->vte_control |= R300_VPORT_Y_SCALE_ENA; + } + if (state->scale[2] != 1.0f) { + r300->viewport_state->zscale = state->scale[2]; + r300->viewport_state->vte_control |= R300_VPORT_Z_SCALE_ENA; + } + if (state->translate[0] != 0.0f) { + r300->viewport_state->xoffset = state->translate[0]; + r300->viewport_state->vte_control |= R300_VPORT_X_OFFSET_ENA; + } + if (state->translate[1] != 0.0f) { + r300->viewport_state->yoffset = state->translate[1]; + r300->viewport_state->vte_control |= R300_VPORT_Y_OFFSET_ENA; + } + if (state->translate[2] != 0.0f) { + r300->viewport_state->zoffset = state->translate[2]; + r300->viewport_state->vte_control |= R300_VPORT_Z_OFFSET_ENA; + } } else { + r300->viewport_state->vte_control = 0; /* Have Draw do the actual transform. */ draw_set_viewport_state(r300->draw, state); } + + r300->dirty_state |= R300_NEW_VIEWPORT; } static void r300_set_vertex_buffers(struct pipe_context* pipe, diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index f1feafbcf91..c4c9784a00c 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -25,60 +25,82 @@ /* r300_state_derived: Various bits of state which are dependent upon * currently bound CSO data. */ -/* Update the vertex_info struct in our r300_context. - * - * The vertex_info struct describes the post-TCL format of vertices. It is - * required for Draw when doing SW TCL, and also for describing the - * dreaded RS block on R300 chipsets. */ -static void r300_update_vertex_layout(struct r300_context* r300) +/* Set up the vs_tab and routes. */ +static void r300_vs_tab_routes(struct r300_context* r300, + struct r300_vertex_format* vformat) { struct r300_screen* r300screen = r300_screen(r300->context.screen); - struct r300_vertex_format vformat; - struct vertex_info vinfo; + struct vertex_info* vinfo = &vformat->vinfo; + int* tab = vformat->vs_tab; boolean pos = FALSE, psize = FALSE, fog = FALSE; int i, texs = 0, cols = 0; - int tab[16]; - - struct tgsi_shader_info* info = &r300->fs->info; + struct tgsi_shader_info* info; - memset(&vinfo, 0, sizeof(vinfo)); - for (i = 0; i < 16; i++) { - tab[i] = -1; + if (r300screen->caps->has_tcl) { + /* Use vertex shader to determine required routes. */ + info = &r300->vs->info; + } else { + /* Use fragment shader to determine required routes. */ + info = &r300->fs->info; } assert(info->num_inputs <= 16); - for (i = 0; i < info->num_inputs; i++) { - switch (info->input_semantic_name[i]) { - case TGSI_SEMANTIC_POSITION: - pos = TRUE; - tab[i] = 0; - break; - case TGSI_SEMANTIC_COLOR: - tab[i] = 2 + cols++; - break; - case TGSI_SEMANTIC_PSIZE: - psize = TRUE; - tab[i] = 1; - break; - case TGSI_SEMANTIC_FOG: - fog = TRUE; - /* Fall through... */ - case TGSI_SEMANTIC_GENERIC: - tab[i] = 6 + texs++; - break; - default: - debug_printf("r300: Unknown vertex input %d\n", - info->input_semantic_name[i]); - break; - } - } - if (r300screen->caps->has_tcl) { + /* Just copy vert attribs over as-is. */ for (i = 0; i < info->num_inputs; i++) { - /* XXX should probably do real lookup with vert shader */ tab[i] = i; } + for (i = 0; i < info->num_outputs; i++) { + switch (info->output_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + pos = TRUE; + break; + case TGSI_SEMANTIC_COLOR: + cols++; + break; + case TGSI_SEMANTIC_PSIZE: + psize = TRUE; + break; + case TGSI_SEMANTIC_FOG: + fog = TRUE; + case TGSI_SEMANTIC_GENERIC: + texs++; + break; + default: + debug_printf("r300: Unknown vertex output %d\n", + info->output_semantic_name[i]); + break; + } + } + } else { + for (i = 0; i < info->num_inputs; i++) { + switch (info->input_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + pos = TRUE; + tab[i] = 0; + break; + case TGSI_SEMANTIC_COLOR: + tab[i] = 2 + cols; + cols++; + break; + case TGSI_SEMANTIC_PSIZE: + psize = TRUE; + tab[i] = 15; + break; + case TGSI_SEMANTIC_FOG: + fog = TRUE; + /* Fall through */ + case TGSI_SEMANTIC_GENERIC: + tab[i] = 6 + texs; + texs++; + break; + default: + debug_printf("r300: Unknown vertex input %d\n", + info->input_semantic_name[i]); + break; + } + } } /* Do the actual vertex_info setup. @@ -89,7 +111,7 @@ static void r300_update_vertex_layout(struct r300_context* r300) * vinfo.hwfmt[2] is R300_VAP_OUTPUT_VTX_FMT_0 * vinfo.hwfmt[3] is R300_VAP_OUTPUT_VTX_FMT_1 */ - vinfo.hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */ + vinfo->hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */ if (!pos) { debug_printf("r300: Forcing vertex position attribute emit...\n"); @@ -99,109 +121,199 @@ static void r300_update_vertex_layout(struct r300_context* r300) tab[i] = tab[i-1]; } tab[0] = 0; - - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_POS, - draw_find_vs_output(r300->draw, TGSI_SEMANTIC_POSITION, 0)); - } else { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, - draw_find_vs_output(r300->draw, TGSI_SEMANTIC_POSITION, 0)); } - vinfo.hwfmt[1] |= R300_INPUT_CNTL_POS; - vinfo.hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_find_vs_output(r300->draw, TGSI_SEMANTIC_POSITION, 0)); + vinfo->hwfmt[1] |= R300_INPUT_CNTL_POS; + vinfo->hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; if (psize) { - draw_emit_vertex_attr(&vinfo, EMIT_1F_PSIZE, INTERP_POS, + draw_emit_vertex_attr(vinfo, EMIT_1F_PSIZE, INTERP_POS, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_PSIZE, 0)); - vinfo.hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; + vinfo->hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; } for (i = 0; i < cols; i++) { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_COLOR, i)); - vinfo.hwfmt[1] |= R300_INPUT_CNTL_COLOR; - vinfo.hwfmt[2] |= (R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i); + vinfo->hwfmt[1] |= R300_INPUT_CNTL_COLOR; + vinfo->hwfmt[2] |= (R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i); } for (i = 0; i < texs; i++) { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_GENERIC, i)); - vinfo.hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); - vinfo.hwfmt[3] |= (4 << (3 * i)); + vinfo->hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); + vinfo->hwfmt[3] |= (4 << (3 * i)); } if (fog) { i++; - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_FOG, 0)); - vinfo.hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); - vinfo.hwfmt[3] |= (4 << (3 * i)); + vinfo->hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); + vinfo->hwfmt[3] |= (4 << (3 * i)); + } + + draw_compute_vertex_size(vinfo); +} + +/* Update the PSC tables. */ +static void r300_vertex_psc(struct r300_context* r300, + struct r300_vertex_format* vformat) +{ + struct vertex_info* vinfo = &vformat->vinfo; + int* tab = vformat->vs_tab; + uint32_t temp; + int i; + + debug_printf("r300: attrib count: %d\n", vinfo->num_attribs); + for (i = 0; i < vinfo->num_attribs; i++) { + debug_printf("r300: attrib: offset %d, interp %d, size %d," + " tab %d\n", vinfo->attrib[i].src_index, + vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit, + tab[i]); } - draw_compute_vertex_size(&vinfo); - - if (memcmp(&r300->vertex_info, &vinfo, sizeof(struct vertex_info))) { - uint32_t temp; - debug_printf("attrib count: %d, fp input count: %d\n", - vinfo.num_attribs, info->num_inputs); - for (i = 0; i < vinfo.num_attribs; i++) { - debug_printf("attrib: offset %d, interp %d, size %d," - " tab %d\n", vinfo.attrib[i].src_index, - vinfo.attrib[i].interp_mode, vinfo.attrib[i].emit, - tab[i]); + for (i = 0; i < vinfo->num_attribs; i++) { + /* Make sure we have a proper destination for our attribute */ + assert(tab[i] != -1); + + /* Add the attribute to the PSC table. */ + temp = translate_vertex_data_type(vinfo->attrib[i].emit) | + (tab[i] << R300_DST_VEC_LOC_SHIFT); + if (i & 1) { + vformat->vap_prog_stream_cntl[i >> 1] &= 0x0000ffff; + vformat->vap_prog_stream_cntl[i >> 1] |= temp << 16; + + vformat->vap_prog_stream_cntl_ext[i >> 1] |= + (R300_VAP_SWIZZLE_XYZW << 16); + } else { + vformat->vap_prog_stream_cntl[i >> 1] &= 0xffff0000; + vformat->vap_prog_stream_cntl[i >> 1] |= temp << 0; + + vformat->vap_prog_stream_cntl_ext[i >> 1] |= + (R300_VAP_SWIZZLE_XYZW << 0); } + } - for (i = 0; i < vinfo.num_attribs; i++) { - /* Make sure we have a proper destination for our attribute */ - assert(tab[i] != -1); + /* Set the last vector in the PSC. */ + i--; + vformat->vap_prog_stream_cntl[i >> 1] |= + (R300_LAST_VEC << (i & 1 ? 16 : 0)); +} - temp = translate_vertex_data_type(vinfo.attrib[i].emit) | - (tab[i] << R300_DST_VEC_LOC_SHIFT); - if (i & 1) { - r300->vertex_info.vap_prog_stream_cntl[i >> 1] &= 0x0000ffff; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= temp << 16; - } else { - r300->vertex_info.vap_prog_stream_cntl[i >> 1] &= 0xffff0000; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= temp; - } +/* Update the vertex format. */ +static void r300_update_vertex_format(struct r300_context* r300) +{ + struct r300_screen* r300screen = r300_screen(r300->context.screen); + struct r300_vertex_format vformat; + int i; - r300->vertex_info.vap_prog_stream_cntl_ext[i >> 1] |= - (R300_VAP_SWIZZLE_XYZW << (i & 1 ? 16 : 0)); - } - /* Set the last vector. */ - i--; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= (R300_LAST_VEC << - (i & 1 ? 16 : 0)); + memset(&vformat, 0, sizeof(struct r300_vertex_format)); + for (i = 0; i < 16; i++) { + vformat.vs_tab[i] = -1; + vformat.fs_tab[i] = -1; + } - memcpy(r300->vertex_info.tab, tab, sizeof(tab)); - memcpy(&r300->vertex_info, &vinfo, sizeof(struct vertex_info)); + r300_vs_tab_routes(r300, &vformat); + + r300_vertex_psc(r300, &vformat); + + if (memcmp(&r300->vertex_info, &vformat, + sizeof(struct r300_vertex_format))) { + memcpy(&r300->vertex_info, &vformat, + sizeof(struct r300_vertex_format)); r300->dirty_state |= R300_NEW_VERTEX_FORMAT; } } +/* Set up the mappings from GB to US, for RS block. */ +static void r300_update_fs_tab(struct r300_context* r300) +{ + struct r300_vertex_format* vformat = &r300->vertex_info; + struct tgsi_shader_info* info = &r300->fs->info; + int i, cols = 0, texs = 0, cols_emitted = 0; + int* tab = vformat->fs_tab; + + for (i = 0; i < 16; i++) { + tab[i] = -1; + } + + assert(info->num_inputs <= 16); + for (i = 0; i < info->num_inputs; i++) { + switch (info->input_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: + tab[i] = INTERP_LINEAR; + cols++; + break; + case TGSI_SEMANTIC_POSITION: + case TGSI_SEMANTIC_PSIZE: + debug_printf("r300: Implementation error: Can't use " + "pos attribs in fragshader yet!\n"); + /* Pass through for now */ + case TGSI_SEMANTIC_FOG: + case TGSI_SEMANTIC_GENERIC: + tab[i] = INTERP_PERSPECTIVE; + break; + default: + debug_printf("r300: Unknown vertex input %d\n", + info->input_semantic_name[i]); + break; + } + } + + /* Now that we know where everything is... */ + debug_printf("r300: fp input count: %d\n", info->num_inputs); + for (i = 0; i < info->num_inputs; i++) { + switch (tab[i]) { + case INTERP_LINEAR: + debug_printf("r300: attrib: " + "stack offset %d, color, tab %d\n", + i, cols_emitted); + tab[i] = cols_emitted; + cols_emitted++; + break; + case INTERP_PERSPECTIVE: + debug_printf("r300: attrib: " + "stack offset %d, texcoord, tab %d\n", + i, cols + texs); + tab[i] = cols + texs; + texs++; + break; + case -1: + debug_printf("r300: Implementation error: Bad fp interp!\n"); + default: + break; + } + } + +} + /* Set up the RS block. This is the part of the chipset that actually does * the rasterization of vertices into fragments. This is also the part of the * chipset that locks up if any part of it is even slightly wrong. */ static void r300_update_rs_block(struct r300_context* r300) { struct r300_rs_block* rs = r300->rs_block; - struct vertex_info* vinfo = &r300->vertex_info.vinfo; - int* tab = r300->vertex_info.tab; + struct tgsi_shader_info* info = &r300->fs->info; + int* tab = r300->vertex_info.fs_tab; int col_count = 0, fp_offset = 0, i, memory_pos, tex_count = 0; memset(rs, 0, sizeof(struct r300_rs_block)); if (r300_screen(r300->context.screen)->caps->is_r500) { - for (i = 0; i < vinfo->num_attribs; i++) { - assert(tab[vinfo->attrib[i].src_index] != -1); - memory_pos = tab[vinfo->attrib[i].src_index] * 4; - switch (vinfo->attrib[i].interp_mode) { - case INTERP_LINEAR: + for (i = 0; i < info->num_inputs; i++) { + assert(tab[i] != -1); + memory_pos = tab[i] * 4; + switch (info->input_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: rs->ip[col_count] |= R500_RS_COL_PTR(memory_pos) | R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA); col_count++; break; - case INTERP_PERSPECTIVE: + case TGSI_SEMANTIC_GENERIC: rs->ip[tex_count] |= R500_RS_SEL_S(memory_pos) | R500_RS_SEL_T(memory_pos + 1) | @@ -243,17 +355,17 @@ static void r300_update_rs_block(struct r300_context* r300) fp_offset++; } } else { - for (i = 0; i < vinfo->num_attribs; i++) { - memory_pos = tab[vinfo->attrib[i].src_index] * 4; - assert(tab[vinfo->attrib[i].src_index] != -1); - switch (vinfo->attrib[i].interp_mode) { - case INTERP_LINEAR: + for (i = 0; i < info->num_inputs; i++) { + assert(tab[i] != -1); + memory_pos = tab[i] * 4; + switch (info->input_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: rs->ip[col_count] |= R300_RS_COL_PTR(memory_pos) | R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA); col_count++; break; - case INTERP_PERSPECTIVE: + case TGSI_SEMANTIC_GENERIC: rs->ip[tex_count] |= R300_RS_TEX_PTR(memory_pos) | R300_RS_SEL_S(R300_RS_SEL_C0) | @@ -307,10 +419,11 @@ void r300_update_derived_state(struct r300_context* r300) { if (r300->dirty_state & (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER)) { - r300_update_vertex_layout(r300); + r300_update_vertex_format(r300); } if (r300->dirty_state & R300_NEW_VERTEX_FORMAT) { + r300_update_fs_tab(r300); r300_update_rs_block(r300); } } diff --git a/src/gallium/drivers/r300/r300_state_tcl.c b/src/gallium/drivers/r300/r300_state_tcl.c index 47d6c6dfcdf..bb96e2ad67f 100644 --- a/src/gallium/drivers/r300/r300_state_tcl.c +++ b/src/gallium/drivers/r300/r300_state_tcl.c @@ -40,6 +40,9 @@ static void r300_vs_declare(struct r300_vs_asm* assembler, /* XXX multiple? */ assembler->tab[decl->DeclarationRange.First] = 6; break; + case TGSI_SEMANTIC_PSIZE: + assembler->tab[decl->DeclarationRange.First] = 15; + break; default: debug_printf("r300: vs: Bad semantic declaration %d\n", decl->Semantic.SemanticName); @@ -117,6 +120,9 @@ static INLINE unsigned r300_vs_dst(struct r300_vs_asm* assembler, static uint32_t r300_vs_op(unsigned op) { switch (op) { + case TGSI_OPCODE_DP3: + case TGSI_OPCODE_DP4: + return R300_VE_DOT_PRODUCT; case TGSI_OPCODE_MUL: return R300_VE_MULTIPLY; case TGSI_OPCODE_ADD: @@ -195,6 +201,36 @@ static void r300_vs_instruction(struct r300_vertex_shader* vs, &inst->FullDstRegisters[0], inst->Instruction.Opcode, 2); break; + case TGSI_OPCODE_DP3: + /* Set alpha swizzle to zero for src0 and src1 */ + if (!inst->FullSrcRegisters[0].SrcRegister.Extended) { + inst->FullSrcRegisters[0].SrcRegister.Extended = TRUE; + inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtSwizzleX = + inst->FullSrcRegisters[0].SrcRegister.SwizzleX; + inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtSwizzleY = + inst->FullSrcRegisters[0].SrcRegister.SwizzleY; + inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtSwizzleZ = + inst->FullSrcRegisters[0].SrcRegister.SwizzleZ; + } + inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtSwizzleW = + TGSI_EXTSWIZZLE_ZERO; + if (!inst->FullSrcRegisters[1].SrcRegister.Extended) { + inst->FullSrcRegisters[1].SrcRegister.Extended = TRUE; + inst->FullSrcRegisters[1].SrcRegisterExtSwz.ExtSwizzleX = + inst->FullSrcRegisters[1].SrcRegister.SwizzleX; + inst->FullSrcRegisters[1].SrcRegisterExtSwz.ExtSwizzleY = + inst->FullSrcRegisters[1].SrcRegister.SwizzleY; + inst->FullSrcRegisters[1].SrcRegisterExtSwz.ExtSwizzleZ = + inst->FullSrcRegisters[1].SrcRegister.SwizzleZ; + } + inst->FullSrcRegisters[1].SrcRegisterExtSwz.ExtSwizzleW = + TGSI_EXTSWIZZLE_ZERO; + /* Fall through */ + case TGSI_OPCODE_DP4: + r300_vs_emit_inst(vs, assembler, inst->FullSrcRegisters, + &inst->FullDstRegisters[0], inst->Instruction.Opcode, + 2); + break; case TGSI_OPCODE_MOV: case TGSI_OPCODE_SWZ: inst->FullSrcRegisters[1] = r300_constant_zero; diff --git a/src/gallium/drivers/r300/r300_state_tcl.h b/src/gallium/drivers/r300/r300_state_tcl.h index 3d10e248e15..de944028baa 100644 --- a/src/gallium/drivers/r300/r300_state_tcl.h +++ b/src/gallium/drivers/r300/r300_state_tcl.h @@ -32,6 +32,7 @@ /* XXX get these to r300_reg */ #define R300_PVS_DST_OPCODE(x) ((x) << 0) +# define R300_VE_DOT_PRODUCT 1 # define R300_VE_MULTIPLY 2 # define R300_VE_ADD 3 #define R300_PVS_DST_MACRO_INST (1 << 7) diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 06ace27d14b..11aff814791 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -121,11 +121,23 @@ static void softpipe_destroy( struct pipe_context *pipe ) FREE( softpipe ); } +static unsigned int +softpipe_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +softpipe_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} struct pipe_context * -softpipe_create( struct pipe_screen *screen, - struct pipe_winsys *pipe_winsys, - void *unused ) +softpipe_create( struct pipe_screen *screen ) { struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); uint i; @@ -140,7 +152,7 @@ softpipe_create( struct pipe_screen *screen, softpipe->dump_fs = debug_get_bool_option( "GALLIUM_DUMP_FS", FALSE ); - softpipe->pipe.winsys = pipe_winsys; + softpipe->pipe.winsys = screen->winsys; softpipe->pipe.screen = screen; softpipe->pipe.destroy = softpipe_destroy; @@ -190,6 +202,9 @@ softpipe_create( struct pipe_screen *screen, softpipe->pipe.clear = softpipe_clear; softpipe->pipe.flush = softpipe_flush; + softpipe->pipe.is_texture_referenced = softpipe_is_texture_referenced; + softpipe->pipe.is_buffer_referenced = softpipe_is_buffer_referenced; + softpipe_init_query_funcs( softpipe ); softpipe_init_texture_funcs( softpipe ); diff --git a/src/gallium/drivers/softpipe/sp_winsys.h b/src/gallium/drivers/softpipe/sp_winsys.h index 4ab666486c4..cf91e7782bc 100644 --- a/src/gallium/drivers/softpipe/sp_winsys.h +++ b/src/gallium/drivers/softpipe/sp_winsys.h @@ -35,31 +35,17 @@ #define SP_WINSYS_H -#include "pipe/p_compiler.h" /* for boolean */ - - #ifdef __cplusplus extern "C" { #endif -enum pipe_format; - -struct softpipe_winsys { - /** test if the given format is supported for front/back color bufs */ - boolean (*is_format_supported)( struct softpipe_winsys *sws, - enum pipe_format format ); - -}; - struct pipe_screen; struct pipe_winsys; struct pipe_context; -struct pipe_context *softpipe_create( struct pipe_screen *, - struct pipe_winsys *, - void *unused ); +struct pipe_context *softpipe_create( struct pipe_screen * ); struct pipe_screen * diff --git a/src/gallium/drivers/trace/tr_buffer.c b/src/gallium/drivers/trace/tr_buffer.c index 6ffce1660ec..4f0eff6a5a4 100644 --- a/src/gallium/drivers/trace/tr_buffer.c +++ b/src/gallium/drivers/trace/tr_buffer.c @@ -27,10 +27,10 @@ #include "util/u_memory.h" +#include "util/u_simple_list.h" #include "tr_buffer.h" - struct pipe_buffer * trace_buffer_create(struct trace_screen *tr_scr, struct pipe_buffer *buffer) @@ -52,6 +52,8 @@ trace_buffer_create(struct trace_screen *tr_scr, tr_buf->base.screen = &tr_scr->base; tr_buf->buffer = buffer; + trace_screen_add_to_list(tr_scr, buffers, tr_buf); + return &tr_buf->base; error: @@ -64,7 +66,10 @@ void trace_buffer_destroy(struct trace_screen *tr_scr, struct pipe_buffer *buffer) { - struct trace_buffer *tr_buf = trace_buffer(tr_scr, buffer); + struct trace_buffer *tr_buf = trace_buffer(buffer); + + trace_screen_remove_from_list(tr_scr, buffers, tr_buf); + pipe_buffer_reference(&tr_buf->buffer, NULL); FREE(tr_buf); } diff --git a/src/gallium/drivers/trace/tr_buffer.h b/src/gallium/drivers/trace/tr_buffer.h index e9e4d354dad..1a2d0b9aeae 100644 --- a/src/gallium/drivers/trace/tr_buffer.h +++ b/src/gallium/drivers/trace/tr_buffer.h @@ -41,19 +41,19 @@ struct trace_buffer struct pipe_buffer *buffer; + struct tr_list list; + void *map; boolean range_flushed; }; static INLINE struct trace_buffer * -trace_buffer(struct trace_screen *tr_scr, - struct pipe_buffer *buffer) +trace_buffer(struct pipe_buffer *buffer) { if(!buffer) return NULL; - assert(tr_scr); - assert(buffer->screen == &tr_scr->base); + (void)trace_screen(buffer->screen); return (struct trace_buffer *)buffer; } diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index d8d5821a1d1..47280459a75 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -26,6 +26,8 @@ **************************************************************************/ #include "util/u_memory.h" +#include "util/u_simple_list.h" + #include "pipe/p_screen.h" #include "tr_dump.h" @@ -46,7 +48,7 @@ trace_buffer_unwrap(struct trace_context *tr_ctx, if(!buffer) return NULL; - tr_buf = trace_buffer(tr_scr, buffer); + tr_buf = trace_buffer(buffer); assert(tr_buf->buffer); assert(tr_buf->buffer->screen == tr_scr->screen); @@ -142,9 +144,8 @@ trace_context_draw_elements(struct pipe_context *_pipe, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { - struct trace_screen *tr_scr = trace_screen(_pipe->screen); struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer); + struct trace_buffer *tr_buf = trace_buffer(_indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; struct pipe_buffer *indexBuffer = tr_buf->buffer; boolean result; @@ -180,9 +181,8 @@ trace_context_draw_range_elements(struct pipe_context *_pipe, unsigned start, unsigned count) { - struct trace_screen *tr_scr = trace_screen(_pipe->screen); struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer); + struct trace_buffer *tr_buf = trace_buffer(_indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; struct pipe_buffer *indexBuffer = tr_buf->buffer; boolean result; @@ -1016,20 +1016,67 @@ trace_context_flush(struct pipe_context *_pipe, static INLINE void trace_context_destroy(struct pipe_context *_pipe) { + struct trace_screen *tr_scr = trace_screen(_pipe->screen); struct trace_context *tr_ctx = trace_context(_pipe); struct pipe_context *pipe = tr_ctx->pipe; trace_dump_call_begin("pipe_context", "destroy"); - trace_dump_arg(ptr, pipe); + trace_dump_call_end(); + + trace_screen_remove_from_list(tr_scr, contexts, tr_ctx); pipe->destroy(pipe); + FREE(tr_ctx); +} + +static unsigned int +trace_is_texture_referenced( struct pipe_context *_pipe, + struct pipe_texture *_texture, + unsigned face, unsigned level) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_texture *tr_tex = trace_texture(_texture); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_texture *texture = tr_tex->texture; + unsigned int referenced; + + trace_dump_call_begin("pipe_context", "is_texture_referenced"); + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + trace_dump_arg(uint, face); + trace_dump_arg(uint, level); + + referenced = pipe->is_texture_referenced(pipe, texture, face, level); + + trace_dump_ret(uint, referenced); trace_dump_call_end(); - FREE(tr_ctx); + return referenced; } +static unsigned int +trace_is_buffer_referenced( struct pipe_context *_pipe, + struct pipe_buffer *_buf) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_buffer *tr_buf = trace_buffer(_buf); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_buffer *buf = tr_buf->buffer; + unsigned int referenced; + + trace_dump_call_begin("pipe_context", "is_buffer_referenced"); + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, buf); + + referenced = pipe->is_buffer_referenced(pipe, buf); + + trace_dump_ret(uint, referenced); + trace_dump_call_end(); + + return referenced; +} struct pipe_context * trace_context_create(struct pipe_screen *_screen, @@ -1042,7 +1089,7 @@ trace_context_create(struct pipe_screen *_screen, if(!pipe) goto error1; - if(!trace_dump_enabled()) + if(!trace_dump_trace_enabled()) goto error1; tr_scr = trace_screen(_screen); @@ -1096,6 +1143,8 @@ trace_context_create(struct pipe_screen *_screen, tr_ctx->base.surface_fill = trace_context_surface_fill; tr_ctx->base.clear = trace_context_clear; tr_ctx->base.flush = trace_context_flush; + tr_ctx->base.is_texture_referenced = trace_is_texture_referenced; + tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced; tr_ctx->pipe = pipe; @@ -1104,6 +1153,8 @@ trace_context_create(struct pipe_screen *_screen, trace_dump_ret(ptr, pipe); trace_dump_call_end(); + trace_screen_add_to_list(tr_scr, contexts, tr_ctx); + return &tr_ctx->base; error1: diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h index d02b22a069b..2512a0a2328 100644 --- a/src/gallium/drivers/trace/tr_context.h +++ b/src/gallium/drivers/trace/tr_context.h @@ -44,6 +44,8 @@ struct trace_context struct pipe_context base; struct pipe_context *pipe; + + struct tr_list list; }; diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c index 2618883e70d..3a1409e95a7 100644 --- a/src/gallium/drivers/trace/tr_dump.c +++ b/src/gallium/drivers/trace/tr_dump.c @@ -61,6 +61,8 @@ static struct util_stream *stream = NULL; static unsigned refcount = 0; static pipe_mutex call_mutex; static long unsigned call_no = 0; +static boolean dumping = FALSE; +static boolean initialized = FALSE; static INLINE void @@ -226,10 +228,22 @@ trace_dump_trace_close(void) } } +void trace_dump_init() +{ + if (initialized) + return; + + pipe_mutex_init(call_mutex); + dumping = FALSE; + initialized = TRUE; +} + boolean trace_dump_trace_begin() { const char *filename; + assert(initialized); + filename = debug_get_option("GALLIUM_TRACE", NULL); if(!filename) return FALSE; @@ -240,8 +254,6 @@ boolean trace_dump_trace_begin() if(!stream) return FALSE; - pipe_mutex_init(call_mutex); - trace_dump_writes("<?xml version='1.0' encoding='UTF-8'?>\n"); trace_dump_writes("<?xml-stylesheet type='text/xsl' href='trace.xsl'?>\n"); trace_dump_writes("<trace version='0.1'>\n"); @@ -258,7 +270,7 @@ boolean trace_dump_trace_begin() return TRUE; } -boolean trace_dump_enabled(void) +boolean trace_dump_trace_enabled(void) { return stream ? TRUE : FALSE; } @@ -270,9 +282,71 @@ void trace_dump_trace_end(void) trace_dump_trace_close(); } -void trace_dump_call_begin(const char *klass, const char *method) +/* + * Call lock + */ + +void trace_dump_call_lock(void) { pipe_mutex_lock(call_mutex); +} + +void trace_dump_call_unlock(void) +{ + pipe_mutex_unlock(call_mutex); +} + +/* + * Dumping control + */ + +void trace_dumping_start_locked(void) +{ + dumping = TRUE; +} + +void trace_dumping_stop_locked(void) +{ + dumping = FALSE; +} + +boolean trace_dumping_enabled_locked(void) +{ + return dumping; +} + +void trace_dumping_start(void) +{ + pipe_mutex_lock(call_mutex); + trace_dumping_start_locked(); + pipe_mutex_unlock(call_mutex); +} + +void trace_dumping_stop(void) +{ + pipe_mutex_lock(call_mutex); + trace_dumping_stop_locked(); + pipe_mutex_unlock(call_mutex); +} + +boolean trace_dumping_enabled(void) +{ + boolean ret; + pipe_mutex_lock(call_mutex); + ret = trace_dumping_enabled_locked(); + pipe_mutex_unlock(call_mutex); + return ret; +} + +/* + * Dump functions + */ + +void trace_dump_call_begin_locked(const char *klass, const char *method) +{ + if (!dumping) + return; + ++call_no; trace_dump_indent(1); trace_dump_writes("<call no=\'"); @@ -285,56 +359,94 @@ void trace_dump_call_begin(const char *klass, const char *method) trace_dump_newline(); } -void trace_dump_call_end(void) +void trace_dump_call_end_locked(void) { + if (!dumping) + return; + trace_dump_indent(1); trace_dump_tag_end("call"); trace_dump_newline(); util_stream_flush(stream); +} + +void trace_dump_call_begin(const char *klass, const char *method) +{ + pipe_mutex_lock(call_mutex); + trace_dump_call_begin_locked(klass, method); +} + +void trace_dump_call_end(void) +{ + trace_dump_call_end_locked(); pipe_mutex_unlock(call_mutex); } void trace_dump_arg_begin(const char *name) { + if (!dumping) + return; + trace_dump_indent(2); trace_dump_tag_begin1("arg", "name", name); } void trace_dump_arg_end(void) { + if (!dumping) + return; + trace_dump_tag_end("arg"); trace_dump_newline(); } void trace_dump_ret_begin(void) { + if (!dumping) + return; + trace_dump_indent(2); trace_dump_tag_begin("ret"); } void trace_dump_ret_end(void) { + if (!dumping) + return; + trace_dump_tag_end("ret"); trace_dump_newline(); } void trace_dump_bool(int value) { + if (!dumping) + return; + trace_dump_writef("<bool>%c</bool>", value ? '1' : '0'); } void trace_dump_int(long long int value) { + if (!dumping) + return; + trace_dump_writef("<int>%lli</int>", value); } void trace_dump_uint(long long unsigned value) { + if (!dumping) + return; + trace_dump_writef("<uint>%llu</uint>", value); } void trace_dump_float(double value) { + if (!dumping) + return; + trace_dump_writef("<float>%g</float>", value); } @@ -344,6 +456,10 @@ void trace_dump_bytes(const void *data, static const char hex_table[16] = "0123456789ABCDEF"; const uint8_t *p = data; long unsigned i; + + if (!dumping) + return; + trace_dump_writes("<bytes>"); for(i = 0; i < size; ++i) { uint8_t byte = *p++; @@ -357,6 +473,9 @@ void trace_dump_bytes(const void *data, void trace_dump_string(const char *str) { + if (!dumping) + return; + trace_dump_writes("<string>"); trace_dump_escape(str); trace_dump_writes("</string>"); @@ -364,6 +483,9 @@ void trace_dump_string(const char *str) void trace_dump_enum(const char *value) { + if (!dumping) + return; + trace_dump_writes("<enum>"); trace_dump_escape(value); trace_dump_writes("</enum>"); @@ -371,51 +493,81 @@ void trace_dump_enum(const char *value) void trace_dump_array_begin(void) { + if (!dumping) + return; + trace_dump_writes("<array>"); } void trace_dump_array_end(void) { + if (!dumping) + return; + trace_dump_writes("</array>"); } void trace_dump_elem_begin(void) { + if (!dumping) + return; + trace_dump_writes("<elem>"); } void trace_dump_elem_end(void) { + if (!dumping) + return; + trace_dump_writes("</elem>"); } void trace_dump_struct_begin(const char *name) { + if (!dumping) + return; + trace_dump_writef("<struct name='%s'>", name); } void trace_dump_struct_end(void) { + if (!dumping) + return; + trace_dump_writes("</struct>"); } void trace_dump_member_begin(const char *name) { + if (!dumping) + return; + trace_dump_writef("<member name='%s'>", name); } void trace_dump_member_end(void) { + if (!dumping) + return; + trace_dump_writes("</member>"); } void trace_dump_null(void) { + if (!dumping) + return; + trace_dump_writes("<null/>"); } void trace_dump_ptr(const void *value) { + if (!dumping) + return; + if(value) trace_dump_writef("<ptr>0x%08lx</ptr>", (unsigned long)(uintptr_t)value); else @@ -424,9 +576,11 @@ void trace_dump_ptr(const void *value) void trace_dump_buffer_ptr(struct pipe_buffer *_buffer) { + if (!dumping) + return; + if (_buffer) { - struct trace_screen *tr_scr = trace_screen(_buffer->screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); trace_dump_ptr(tr_buf->buffer); } else { trace_dump_null(); @@ -435,6 +589,9 @@ void trace_dump_buffer_ptr(struct pipe_buffer *_buffer) void trace_dump_texture_ptr(struct pipe_texture *_texture) { + if (!dumping) + return; + if (_texture) { struct trace_texture *tr_tex = trace_texture(_texture); trace_dump_ptr(tr_tex->texture); @@ -445,6 +602,9 @@ void trace_dump_texture_ptr(struct pipe_texture *_texture) void trace_dump_surface_ptr(struct pipe_surface *_surface) { + if (!dumping) + return; + if (_surface) { struct trace_surface *tr_surf = trace_surface(_surface); trace_dump_ptr(tr_surf->surface); @@ -455,6 +615,9 @@ void trace_dump_surface_ptr(struct pipe_surface *_surface) void trace_dump_transfer_ptr(struct pipe_transfer *_transfer) { + if (!dumping) + return; + if (_transfer) { struct trace_transfer *tr_tran = trace_transfer(_transfer); trace_dump_ptr(tr_tran->transfer); diff --git a/src/gallium/drivers/trace/tr_dump.h b/src/gallium/drivers/trace/tr_dump.h index 26409f26c66..31ac70802f0 100644 --- a/src/gallium/drivers/trace/tr_dump.h +++ b/src/gallium/drivers/trace/tr_dump.h @@ -42,11 +42,47 @@ struct pipe_texture; struct pipe_surface; struct pipe_transfer; +/* + * Call before use. + */ +void trace_dump_init(void); + +/* + * Low level dumping controls. + * + * Opening the trace file and checking if that is opened. + */ boolean trace_dump_trace_begin(void); -boolean trace_dump_enabled(void); +boolean trace_dump_trace_enabled(void); void trace_dump_trace_end(void); + +/* + * Lock and unlock the call mutex. + * + * It used by the none locked version of dumping control + * and begin/end call dump functions. + * + * Begin takes the lock while end unlocks it. Use the _locked + * version to avoid locking/unlocking it. + */ +void trace_dump_call_lock(void); +void trace_dump_call_unlock(void); + +/* + * High level dumping control. + */ +void trace_dumping_start_locked(void); +void trace_dumping_stop_locked(void); +boolean trace_dumping_enabled_locked(void); +void trace_dumping_start(void); +void trace_dumping_stop(void); +boolean trace_dumping_enabled(void); + +void trace_dump_call_begin_locked(const char *klass, const char *method); +void trace_dump_call_end_locked(void); void trace_dump_call_begin(const char *klass, const char *method); void trace_dump_call_end(void); + void trace_dump_arg_begin(const char *name); void trace_dump_arg_end(void); void trace_dump_ret_begin(void); diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 67925053833..12a85353428 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -26,6 +26,7 @@ **************************************************************************/ #include "util/u_memory.h" +#include "util/u_simple_list.h" #include "tr_buffer.h" #include "tr_dump.h" @@ -603,7 +604,7 @@ trace_screen_buffer_map(struct pipe_screen *_screen, unsigned usage) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); struct pipe_screen *screen = tr_scr->screen; struct pipe_buffer *buffer = tr_buf->buffer; void *map; @@ -628,7 +629,7 @@ trace_screen_buffer_map_range(struct pipe_screen *_screen, unsigned usage) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); struct pipe_screen *screen = tr_scr->screen; struct pipe_buffer *buffer = tr_buf->buffer; void *map; @@ -680,7 +681,7 @@ trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen, unsigned length) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); struct pipe_screen *screen = tr_scr->screen; struct pipe_buffer *buffer = tr_buf->buffer; @@ -696,7 +697,7 @@ trace_screen_buffer_unmap(struct pipe_screen *_screen, struct pipe_buffer *_buffer) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); struct pipe_screen *screen = tr_scr->screen; struct pipe_buffer *buffer = tr_buf->buffer; @@ -712,7 +713,7 @@ static void trace_screen_buffer_destroy(struct pipe_buffer *_buffer) { struct trace_screen *tr_scr = trace_screen(_buffer->screen); - struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer); + struct trace_buffer *tr_buf = trace_buffer(_buffer); struct pipe_screen *screen = tr_scr->screen; struct pipe_buffer *buffer = tr_buf->buffer; @@ -734,19 +735,23 @@ trace_screen_buffer_destroy(struct pipe_buffer *_buffer) static void trace_screen_fence_reference(struct pipe_screen *_screen, - struct pipe_fence_handle **dst, + struct pipe_fence_handle **pdst, struct pipe_fence_handle *src) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; + struct pipe_fence_handle *dst; + assert(pdst); + dst = *pdst; + trace_dump_call_begin("pipe_screen", "fence_reference"); trace_dump_arg(ptr, screen); trace_dump_arg(ptr, dst); trace_dump_arg(ptr, src); - screen->fence_reference(screen, dst, src); + screen->fence_reference(screen, pdst, src); trace_dump_call_end(); } @@ -755,7 +760,7 @@ trace_screen_fence_reference(struct pipe_screen *_screen, static int trace_screen_fence_signalled(struct pipe_screen *_screen, struct pipe_fence_handle *fence, - unsigned flag) + unsigned flags) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; @@ -765,9 +770,9 @@ trace_screen_fence_signalled(struct pipe_screen *_screen, trace_dump_arg(ptr, screen); trace_dump_arg(ptr, fence); - trace_dump_arg(uint, flag); + trace_dump_arg(uint, flags); - result = screen->fence_signalled(screen, fence, flag); + result = screen->fence_signalled(screen, fence, flags); trace_dump_ret(int, result); @@ -780,7 +785,7 @@ trace_screen_fence_signalled(struct pipe_screen *_screen, static int trace_screen_fence_finish(struct pipe_screen *_screen, struct pipe_fence_handle *fence, - unsigned flag) + unsigned flags) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; @@ -790,9 +795,9 @@ trace_screen_fence_finish(struct pipe_screen *_screen, trace_dump_arg(ptr, screen); trace_dump_arg(ptr, fence); - trace_dump_arg(uint, flag); + trace_dump_arg(uint, flags); - result = screen->fence_finish(screen, fence, flag); + result = screen->fence_finish(screen, fence, flags); trace_dump_ret(int, result); @@ -835,9 +840,13 @@ trace_screen_create(struct pipe_screen *screen) if(!screen) goto error1; + trace_dump_init(); + if(!trace_dump_trace_begin()) goto error1; + trace_dumping_start(); + trace_dump_call_begin("", "pipe_screen_create"); tr_scr = CALLOC_STRUCT(trace_screen); @@ -851,6 +860,12 @@ trace_screen_create(struct pipe_screen *screen) #else winsys = screen->winsys; #endif + pipe_mutex_init(tr_scr->list_mutex); + make_empty_list(&tr_scr->buffers); + make_empty_list(&tr_scr->contexts); + make_empty_list(&tr_scr->textures); + make_empty_list(&tr_scr->surfaces); + make_empty_list(&tr_scr->transfers); tr_scr->base.winsys = winsys; tr_scr->base.destroy = trace_screen_destroy; diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h index 8c65516b509..59f254166d4 100644 --- a/src/gallium/drivers/trace/tr_screen.h +++ b/src/gallium/drivers/trace/tr_screen.h @@ -30,6 +30,7 @@ #include "pipe/p_screen.h" +#include "pipe/p_thread.h" #ifdef __cplusplus @@ -37,6 +38,11 @@ extern "C" { #endif +struct tr_list { + struct tr_list *next; + struct tr_list *prev; +}; + /** * It often happens that new data is written directly to the user buffers * without mapping/unmapping. This flag marks user buffers, so that their @@ -50,6 +56,18 @@ struct trace_screen struct pipe_screen base; struct pipe_screen *screen; + + pipe_mutex list_mutex; + int num_buffers; + int num_contexts; + int num_textures; + int num_surfaces; + int num_transfers; + struct tr_list buffers; + struct tr_list contexts; + struct tr_list textures; + struct tr_list surfaces; + struct tr_list transfers; }; @@ -65,6 +83,21 @@ void trace_screen_user_buffer_update(struct pipe_screen *screen, struct pipe_buffer *buffer); +#define trace_screen_add_to_list(tr_scr, name, obj) \ + do { \ + pipe_mutex_lock(tr_scr->list_mutex); \ + insert_at_head(&tr_scr->name, &obj->list); \ + tr_scr->num_##name++; \ + pipe_mutex_unlock(tr_scr->list_mutex); \ + } while (0) + +#define trace_screen_remove_from_list(tr_scr, name, obj) \ + do { \ + pipe_mutex_lock(tr_scr->list_mutex); \ + remove_from_list(&obj->list); \ + tr_scr->num_##name--; \ + pipe_mutex_unlock(tr_scr->list_mutex); \ + } while (0) #ifdef __cplusplus } diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index f4e433792b1..1f25fe38d4c 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -27,6 +27,7 @@ #include "util/u_hash_table.h" #include "util/u_memory.h" +#include "util/u_simple_list.h" #include "tr_screen.h" #include "tr_texture.h" @@ -53,6 +54,8 @@ trace_texture_create(struct trace_screen *tr_scr, tr_tex->base.screen = &tr_scr->base; tr_tex->texture = texture; + trace_screen_add_to_list(tr_scr, textures, tr_tex); + return &tr_tex->base; error: @@ -64,6 +67,10 @@ error: void trace_texture_destroy(struct trace_texture *tr_tex) { + struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); + + trace_screen_remove_from_list(tr_scr, textures, tr_tex); + pipe_texture_reference(&tr_tex->texture, NULL); FREE(tr_tex); } @@ -73,6 +80,7 @@ struct pipe_surface * trace_surface_create(struct trace_texture *tr_tex, struct pipe_surface *surface) { + struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); struct trace_surface *tr_surf; if(!surface) @@ -91,6 +99,8 @@ trace_surface_create(struct trace_texture *tr_tex, pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base); tr_surf->surface = surface; + trace_screen_add_to_list(tr_scr, surfaces, tr_surf); + return &tr_surf->base; error: @@ -102,6 +112,10 @@ error: void trace_surface_destroy(struct trace_surface *tr_surf) { + struct trace_screen *tr_scr = trace_screen(tr_surf->base.texture->screen); + + trace_screen_remove_from_list(tr_scr, surfaces, tr_surf); + pipe_texture_reference(&tr_surf->base.texture, NULL); pipe_surface_reference(&tr_surf->surface, NULL); FREE(tr_surf); @@ -112,6 +126,7 @@ struct pipe_transfer * trace_transfer_create(struct trace_texture *tr_tex, struct pipe_transfer *transfer) { + struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); struct trace_transfer *tr_trans; if(!transfer) @@ -130,6 +145,8 @@ trace_transfer_create(struct trace_texture *tr_tex, tr_trans->transfer = transfer; assert(tr_trans->base.texture == &tr_tex->base); + trace_screen_add_to_list(tr_scr, transfers, tr_trans); + return &tr_trans->base; error: @@ -141,7 +158,11 @@ error: void trace_transfer_destroy(struct trace_transfer *tr_trans) { + struct trace_screen *tr_scr = trace_screen(tr_trans->base.texture->screen); struct pipe_screen *screen = tr_trans->transfer->texture->screen; + + trace_screen_remove_from_list(tr_scr, transfers, tr_trans); + pipe_texture_reference(&tr_trans->base.texture, NULL); screen->tex_transfer_destroy(tr_trans->transfer); FREE(tr_trans); diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index 14dafd8b2c3..395e523e73a 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -40,6 +40,8 @@ struct trace_texture struct pipe_texture base; struct pipe_texture *texture; + + struct tr_list list; }; @@ -48,6 +50,8 @@ struct trace_surface struct pipe_surface base; struct pipe_surface *surface; + + struct tr_list list; }; @@ -57,6 +61,8 @@ struct trace_transfer struct pipe_transfer *transfer; + struct tr_list list; + void *map; }; diff --git a/src/gallium/include/pipe/p_atomic.h b/src/gallium/include/pipe/p_atomic.h index f2fe083efa7..0c3fbae428c 100644 --- a/src/gallium/include/pipe/p_atomic.h +++ b/src/gallium/include/pipe/p_atomic.h @@ -18,58 +18,29 @@ extern "C" { /* Favor OS-provided implementations. + * + * Where no OS-provided implementation is available, fall back to + * locally coded assembly, compiler intrinsic or ultimately a + * mutex-based implementation. */ -#define PIPE_ATOMIC_OS_UNLOCKED \ - (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \ - defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)) - -#define PIPE_ATOMIC_OS_MS_INTERLOCK \ - (!defined(PIPE_CC_GCC) && \ - !PIPE_ATOMIC_OS_UNLOCKED && \ - defined(PIPE_SUBSYSTEM_WINDOWS_USER)) - -#define PIPE_ATOMIC_OS_PROVIDED \ - (PIPE_ATOMIC_OS_UNLOCKED || \ - PIPE_ATOMIC_OS_MS_INTERLOCK) - -/* Where no OS-provided implementation is available, fall back to - * either locally coded assembly or ultimately a mutex-based - * implementation: - */ -#define PIPE_ATOMIC_ASM_GCC_X86 \ - (!PIPE_ATOMIC_OS_PROVIDED && \ - defined(PIPE_CC_GCC) && \ - defined(PIPE_ARCH_X86)) - -/* KW: this was originally used when x86 asm wasn't available. - * Maintain that logic here. - */ -#define PIPE_ATOMIC_GCC_INTRINISIC \ - (!PIPE_ATOMIC_OS_PROVIDED && \ - !PIPE_ATOMIC_ASM_GCC_X86 && \ - defined(PIPE_CC_GCC)) - -#define PIPE_ATOMIC_ASM_MSVC_X86 \ - (!PIPE_ATOMIC_OS_PROVIDED && \ - defined(PIPE_CC_MSVC) && \ - defined(PIPE_ARCH_X86)) - -#define PIPE_ATOMIC_ASM \ - (PIPE_ATOMIC_ASM_GCC_X86 || \ - PIPE_ATOMIC_ASM_GCC_INTRINSIC || \ - PIPE_ATOMIC_ASM_MSVC_X86) - - -/* Where no OS-provided or locally-coded assembly implemenation is - * available, use pipe_mutex: - */ -#define PIPE_ATOMIC_MUTEX \ - (!PIPE_ATOMIC_OS_PROVIDED && \ - !PIPE_ATOMIC_ASM) +#if (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \ + defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)) +#define PIPE_ATOMIC_OS_UNLOCKED +#elif (defined(PIPE_CC_MSVC) && defined(PIPE_SUBSYSTEM_WINDOWS_USER)) +#define PIPE_ATOMIC_OS_MS_INTERLOCK +#elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)) +#define PIPE_ATOMIC_ASM_MSVC_X86 +#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)) +#define PIPE_ATOMIC_ASM_GCC_X86 +#elif defined(PIPE_CC_GCC) +#define PIPE_ATOMIC_GCC_INTRINSIC +#else +#define PIPE_ATOMIC_MUTEX +#endif -#if (PIPE_ATOMIC_ASM_GCC_X86) +#if defined(PIPE_ATOMIC_ASM_GCC_X86) #define PIPE_ATOMIC "GCC x86 assembly" @@ -115,7 +86,7 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new) /* Implementation using GCC-provided synchronization intrinsics */ -#if (PIPE_ATOMIC_ASM_GCC_INTRINSIC) +#if defined(PIPE_ATOMIC_GCC_INTRINSIC) #define PIPE_ATOMIC "GCC Sync Intrinsics" @@ -157,7 +128,7 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new) /* Unlocked version for single threaded environments, such as some * windows kernel modules. */ -#if (PIPE_ATOMIC_OS_UNLOCKED) +#if defined(PIPE_ATOMIC_OS_UNLOCKED) #define PIPE_ATOMIC "Unlocked" @@ -178,7 +149,7 @@ struct pipe_atomic /* Locally coded assembly for MSVC on x86: */ -#if (PIPE_ATOMIC_ASM_MSVC_X86) +#if defined(PIPE_ATOMIC_ASM_MSVC_X86) #define PIPE_ATOMIC "MSVC x86 assembly" @@ -246,7 +217,7 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new) #endif -#if (PIPE_ATOMIC_OS_MS_INTERLOCK) +#if defined(PIPE_ATOMIC_OS_MS_INTERLOCK) #define PIPE_ATOMIC "MS userspace interlocks" @@ -254,7 +225,7 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new) struct pipe_atomic { - long count; + volatile long count; }; #define p_atomic_set(_v, _i) ((_v)->count = (_i)) @@ -263,7 +234,7 @@ struct pipe_atomic static INLINE boolean p_atomic_dec_zero(struct pipe_atomic *v) { - return InterlockedDecrement(&v->count); + return InterlockedDecrement(&v->count) == 0; } static INLINE void @@ -288,7 +259,7 @@ p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new) -#if (PIPE_ATOMIC_MUTEX) +#if defined(PIPE_ATOMIC_MUTEX) #define PIPE_ATOMIC "mutex-based fallback" diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index 29095dcdc3b..57e966ac3b0 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -42,7 +42,6 @@ struct pipe_state_cache; struct pipe_query; struct pipe_winsys; - /** * Gallium rendering context. Basically: * - state setting functions @@ -192,14 +191,21 @@ struct pipe_context { * Surface functions */ /*@{*/ + + /** + * Copy a block of pixels from one surface to another. + * The surfaces must be of the same format. + */ void (*surface_copy)(struct pipe_context *pipe, struct pipe_surface *dest, unsigned destx, unsigned desty, - struct pipe_surface *src, /* don't make this const - - need to map/unmap */ + struct pipe_surface *src, unsigned srcx, unsigned srcy, unsigned width, unsigned height); + /** + * Fill a region of a surface with a constant value. + */ void (*surface_fill)(struct pipe_context *pipe, struct pipe_surface *dst, unsigned dstx, unsigned dsty, @@ -224,6 +230,34 @@ struct pipe_context { void (*flush)( struct pipe_context *pipe, unsigned flags, struct pipe_fence_handle **fence ); + + /** + * Check whether a texture is referenced by an unflushed hw command. + * The state-tracker uses this function to optimize away unnecessary + * flushes. It is safe (but wasteful) to always return. + * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. + * \param pipe The pipe context whose unflushed hw commands will be + * checked. + * \param level mipmap level. + * \param texture texture to check. + * \param face cubemap face. Use 0 for non-cubemap texture. + */ + + unsigned int (*is_texture_referenced) (struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level); + /** + * Check whether a buffer is referenced by an unflushed hw command. + * The state-tracker uses this function to optimize away unnecessary + * flushes. It is safe (but wasteful) to always return + * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. + * \param pipe The pipe context whose unflushed hw commands will be + * checked. + * \param buf Buffer to check. + */ + + unsigned int (*is_buffer_referenced) (struct pipe_context *pipe, + struct pipe_buffer *buf); }; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 81defa445bf..82e23c413c8 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -200,7 +200,7 @@ enum pipe_texture_target { enum pipe_transfer_usage { PIPE_TRANSFER_READ, PIPE_TRANSFER_WRITE, - PIPE_TRANSFER_READ_WRITE //< Read/modify/write + PIPE_TRANSFER_READ_WRITE /**< Read/modify/write */ }; @@ -312,6 +312,13 @@ enum pipe_transfer_usage { #define PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS 26 +/** + * Referenced query flags. + */ + +#define PIPE_UNREFERENCED 0 +#define PIPE_REFERENCED_FOR_READ (1 << 0) +#define PIPE_REFERENCED_FOR_WRITE (1 << 1) #ifdef __cplusplus } diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index ceac755e71e..b449522fac3 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -87,7 +87,7 @@ struct pipe_screen { * Check if the given pipe_format is supported as a texture or * drawing surface. * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_* - * \param flags bitmask of PIPE_TEXTURE_GEOM_* + * \param geom_flags bitmask of PIPE_TEXTURE_GEOM_* */ boolean (*is_format_supported)( struct pipe_screen *, enum pipe_format format, @@ -102,7 +102,7 @@ struct pipe_screen { const struct pipe_texture *templat); /** - * Create a new texture object, using the given template info, but on top of + * Create a new texture object, using the given template info, but on top of * existing memory. * * It is assumed that the buffer data is layed out according to the expected @@ -144,8 +144,10 @@ struct pipe_screen { /** - * Buffer management. Buffer attributes are mostly fixed over its lifetime. - * + * Create a new buffer. + * \param alignment buffer start address alignment in bytes + * \param usage bitmask of PIPE_BUFFER_USAGE_x + * \param size size in bytes */ struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen, unsigned alignment, @@ -264,7 +266,7 @@ struct pipe_screen { */ int (*fence_signalled)( struct pipe_screen *screen, struct pipe_fence_handle *fence, - unsigned flag ); + unsigned flags ); /** * Wait for the fence to finish. @@ -273,7 +275,7 @@ struct pipe_screen { */ int (*fence_finish)( struct pipe_screen *screen, struct pipe_fence_handle *fence, - unsigned flag ); + unsigned flags ); }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 705ae68ec65..4b590bdc906 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -336,7 +336,6 @@ struct pipe_texture unsigned nblocksy[PIPE_MAX_TEXTURE_LEVELS]; /**< allocated height in blocks */ unsigned last_level:8; /**< Index of last mipmap level present/defined */ - unsigned compressed:1; unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */ diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index f41a95e6eb0..1d513abf3c7 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -426,7 +426,7 @@ struct st_surface if(!*STRING) return; - pipe_buffer_read(screen, $self, 0, $self->size, STRING); + pipe_buffer_read(screen, $self, 0, $self->size, *STRING); } %cstring_input_binary(const char *STRING, unsigned LENGTH); diff --git a/src/gallium/state_trackers/python/retrace/interpreter.py b/src/gallium/state_trackers/python/retrace/interpreter.py index 5ea07724a50..5d4d04498b2 100755 --- a/src/gallium/state_trackers/python/retrace/interpreter.py +++ b/src/gallium/state_trackers/python/retrace/interpreter.py @@ -32,7 +32,7 @@ import struct import gallium import model -import parser +import parse as parser try: diff --git a/src/gallium/state_trackers/python/retrace/parse.py b/src/gallium/state_trackers/python/retrace/parse.py new file mode 100755 index 00000000000..b0f3e8a432f --- /dev/null +++ b/src/gallium/state_trackers/python/retrace/parse.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# 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 TUNGSTEN GRAPHICS 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. +# +########################################################################## + + +import sys +import xml.parsers.expat +import binascii +import optparse + +from model import * + + +ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4) + + +class XmlToken: + + def __init__(self, type, name_or_data, attrs = None, line = None, column = None): + assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF) + self.type = type + self.name_or_data = name_or_data + self.attrs = attrs + self.line = line + self.column = column + + def __str__(self): + if self.type == ELEMENT_START: + return '<' + self.name_or_data + ' ...>' + if self.type == ELEMENT_END: + return '</' + self.name_or_data + '>' + if self.type == CHARACTER_DATA: + return self.name_or_data + if self.type == EOF: + return 'end of file' + assert 0 + + +class XmlTokenizer: + """Expat based XML tokenizer.""" + + def __init__(self, fp, skip_ws = True): + self.fp = fp + self.tokens = [] + self.index = 0 + self.final = False + self.skip_ws = skip_ws + + self.character_pos = 0, 0 + self.character_data = '' + + self.parser = xml.parsers.expat.ParserCreate() + self.parser.StartElementHandler = self.handle_element_start + self.parser.EndElementHandler = self.handle_element_end + self.parser.CharacterDataHandler = self.handle_character_data + + def handle_element_start(self, name, attributes): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_START, name, attributes, line, column) + self.tokens.append(token) + + def handle_element_end(self, name): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_END, name, None, line, column) + self.tokens.append(token) + + def handle_character_data(self, data): + if not self.character_data: + self.character_pos = self.pos() + self.character_data += data + + def finish_character_data(self): + if self.character_data: + if not self.skip_ws or not self.character_data.isspace(): + line, column = self.character_pos + token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column) + self.tokens.append(token) + self.character_data = '' + + def next(self): + size = 16*1024 + while self.index >= len(self.tokens) and not self.final: + self.tokens = [] + self.index = 0 + data = self.fp.read(size) + self.final = len(data) < size + data = data.rstrip('\0') + try: + self.parser.Parse(data, self.final) + except xml.parsers.expat.ExpatError, e: + #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: + if e.code == 3: + pass + else: + raise e + if self.index >= len(self.tokens): + line, column = self.pos() + token = XmlToken(EOF, None, None, line, column) + else: + token = self.tokens[self.index] + self.index += 1 + return token + + def pos(self): + return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber + + +class TokenMismatch(Exception): + + def __init__(self, expected, found): + self.expected = expected + self.found = found + + def __str__(self): + return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found)) + + + +class XmlParser: + """Base XML document parser.""" + + def __init__(self, fp): + self.tokenizer = XmlTokenizer(fp) + self.consume() + + def consume(self): + self.token = self.tokenizer.next() + + def match_element_start(self, name): + return self.token.type == ELEMENT_START and self.token.name_or_data == name + + def match_element_end(self, name): + return self.token.type == ELEMENT_END and self.token.name_or_data == name + + def element_start(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_START: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + attrs = self.token.attrs + self.consume() + return attrs + + def element_end(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_END: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + self.consume() + + def character_data(self, strip = True): + data = '' + while self.token.type == CHARACTER_DATA: + data += self.token.name_or_data + self.consume() + if strip: + data = data.strip() + return data + + +class TraceParser(XmlParser): + + def __init__(self, fp): + XmlParser.__init__(self, fp) + self.last_call_no = 0 + + def parse(self): + self.element_start('trace') + while self.token.type not in (ELEMENT_END, EOF): + call = self.parse_call() + self.handle_call(call) + if self.token.type != EOF: + self.element_end('trace') + + def parse_call(self): + attrs = self.element_start('call') + try: + no = int(attrs['no']) + except KeyError: + self.last_call_no += 1 + no = self.last_call_no + else: + self.last_call_no = no + klass = attrs['class'] + method = attrs['method'] + args = [] + ret = None + while self.token.type == ELEMENT_START: + if self.token.name_or_data == 'arg': + arg = self.parse_arg() + args.append(arg) + elif self.token.name_or_data == 'ret': + ret = self.parse_ret() + elif self.token.name_or_data == 'call': + # ignore nested function calls + self.parse_call() + else: + raise TokenMismatch("<arg ...> or <ret ...>", self.token) + self.element_end('call') + + return Call(no, klass, method, args, ret) + + def parse_arg(self): + attrs = self.element_start('arg') + name = attrs['name'] + value = self.parse_value() + self.element_end('arg') + + return name, value + + def parse_ret(self): + attrs = self.element_start('ret') + value = self.parse_value() + self.element_end('ret') + + return value + + def parse_value(self): + expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes') + if self.token.type == ELEMENT_START: + if self.token.name_or_data in expected_tokens: + method = getattr(self, 'parse_' + self.token.name_or_data) + return method() + raise TokenMismatch(" or " .join(expected_tokens), self.token) + + def parse_null(self): + self.element_start('null') + self.element_end('null') + return Literal(None) + + def parse_bool(self): + self.element_start('bool') + value = int(self.character_data()) + self.element_end('bool') + return Literal(value) + + def parse_int(self): + self.element_start('int') + value = int(self.character_data()) + self.element_end('int') + return Literal(value) + + def parse_uint(self): + self.element_start('uint') + value = int(self.character_data()) + self.element_end('uint') + return Literal(value) + + def parse_float(self): + self.element_start('float') + value = float(self.character_data()) + self.element_end('float') + return Literal(value) + + def parse_enum(self): + self.element_start('enum') + name = self.character_data() + self.element_end('enum') + return NamedConstant(name) + + def parse_string(self): + self.element_start('string') + value = self.character_data() + self.element_end('string') + return Literal(value) + + def parse_bytes(self): + self.element_start('bytes') + value = binascii.a2b_hex(self.character_data()) + self.element_end('bytes') + return Literal(value) + + def parse_array(self): + self.element_start('array') + elems = [] + while self.token.type != ELEMENT_END: + elems.append(self.parse_elem()) + self.element_end('array') + return Array(elems) + + def parse_elem(self): + self.element_start('elem') + value = self.parse_value() + self.element_end('elem') + return value + + def parse_struct(self): + attrs = self.element_start('struct') + name = attrs['name'] + members = [] + while self.token.type != ELEMENT_END: + members.append(self.parse_member()) + self.element_end('struct') + return Struct(name, members) + + def parse_member(self): + attrs = self.element_start('member') + name = attrs['name'] + value = self.parse_value() + self.element_end('member') + + return name, value + + def parse_ptr(self): + self.element_start('ptr') + address = self.character_data() + self.element_end('ptr') + + return Pointer(address) + + def handle_call(self, call): + pass + + +class TraceDumper(TraceParser): + + def __init__(self, fp): + TraceParser.__init__(self, fp) + self.formatter = format.DefaultFormatter(sys.stdout) + self.pretty_printer = PrettyPrinter(self.formatter) + + def handle_call(self, call): + call.visit(self.pretty_printer) + self.formatter.newline() + + +class Main: + '''Common main class for all retrace command line utilities.''' + + def __init__(self): + pass + + def main(self): + optparser = self.get_optparser() + (options, args) = optparser.parse_args(sys.argv[1:]) + + if args: + for arg in args: + if arg.endswith('.gz'): + from gzip import GzipFile + stream = GzipFile(arg, 'rt') + elif arg.endswith('.bz2'): + from bz2 import BZ2File + stream = BZ2File(arg, 'rt') + else: + stream = open(arg, 'rt') + self.process_arg(stream, options) + else: + self.process_arg(stream, options) + + def get_optparser(self): + optparser = optparse.OptionParser( + usage="\n\t%prog [options] [traces] ...") + return optparser + + def process_arg(self, stream, options): + parser = TraceDumper(stream) + parser.parse() + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/state_trackers/python/retrace/parser.py b/src/gallium/state_trackers/python/retrace/parser.py index b0f3e8a432f..bd47c9a6b06 100755 --- a/src/gallium/state_trackers/python/retrace/parser.py +++ b/src/gallium/state_trackers/python/retrace/parser.py @@ -27,365 +27,7 @@ ########################################################################## -import sys -import xml.parsers.expat -import binascii -import optparse - -from model import * - - -ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4) - - -class XmlToken: - - def __init__(self, type, name_or_data, attrs = None, line = None, column = None): - assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF) - self.type = type - self.name_or_data = name_or_data - self.attrs = attrs - self.line = line - self.column = column - - def __str__(self): - if self.type == ELEMENT_START: - return '<' + self.name_or_data + ' ...>' - if self.type == ELEMENT_END: - return '</' + self.name_or_data + '>' - if self.type == CHARACTER_DATA: - return self.name_or_data - if self.type == EOF: - return 'end of file' - assert 0 - - -class XmlTokenizer: - """Expat based XML tokenizer.""" - - def __init__(self, fp, skip_ws = True): - self.fp = fp - self.tokens = [] - self.index = 0 - self.final = False - self.skip_ws = skip_ws - - self.character_pos = 0, 0 - self.character_data = '' - - self.parser = xml.parsers.expat.ParserCreate() - self.parser.StartElementHandler = self.handle_element_start - self.parser.EndElementHandler = self.handle_element_end - self.parser.CharacterDataHandler = self.handle_character_data - - def handle_element_start(self, name, attributes): - self.finish_character_data() - line, column = self.pos() - token = XmlToken(ELEMENT_START, name, attributes, line, column) - self.tokens.append(token) - - def handle_element_end(self, name): - self.finish_character_data() - line, column = self.pos() - token = XmlToken(ELEMENT_END, name, None, line, column) - self.tokens.append(token) - - def handle_character_data(self, data): - if not self.character_data: - self.character_pos = self.pos() - self.character_data += data - - def finish_character_data(self): - if self.character_data: - if not self.skip_ws or not self.character_data.isspace(): - line, column = self.character_pos - token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column) - self.tokens.append(token) - self.character_data = '' - - def next(self): - size = 16*1024 - while self.index >= len(self.tokens) and not self.final: - self.tokens = [] - self.index = 0 - data = self.fp.read(size) - self.final = len(data) < size - data = data.rstrip('\0') - try: - self.parser.Parse(data, self.final) - except xml.parsers.expat.ExpatError, e: - #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: - if e.code == 3: - pass - else: - raise e - if self.index >= len(self.tokens): - line, column = self.pos() - token = XmlToken(EOF, None, None, line, column) - else: - token = self.tokens[self.index] - self.index += 1 - return token - - def pos(self): - return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber - - -class TokenMismatch(Exception): - - def __init__(self, expected, found): - self.expected = expected - self.found = found - - def __str__(self): - return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found)) - - - -class XmlParser: - """Base XML document parser.""" - - def __init__(self, fp): - self.tokenizer = XmlTokenizer(fp) - self.consume() - - def consume(self): - self.token = self.tokenizer.next() - - def match_element_start(self, name): - return self.token.type == ELEMENT_START and self.token.name_or_data == name - - def match_element_end(self, name): - return self.token.type == ELEMENT_END and self.token.name_or_data == name - - def element_start(self, name): - while self.token.type == CHARACTER_DATA: - self.consume() - if self.token.type != ELEMENT_START: - raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) - if self.token.name_or_data != name: - raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) - attrs = self.token.attrs - self.consume() - return attrs - - def element_end(self, name): - while self.token.type == CHARACTER_DATA: - self.consume() - if self.token.type != ELEMENT_END: - raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) - if self.token.name_or_data != name: - raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) - self.consume() - - def character_data(self, strip = True): - data = '' - while self.token.type == CHARACTER_DATA: - data += self.token.name_or_data - self.consume() - if strip: - data = data.strip() - return data - - -class TraceParser(XmlParser): - - def __init__(self, fp): - XmlParser.__init__(self, fp) - self.last_call_no = 0 - - def parse(self): - self.element_start('trace') - while self.token.type not in (ELEMENT_END, EOF): - call = self.parse_call() - self.handle_call(call) - if self.token.type != EOF: - self.element_end('trace') - - def parse_call(self): - attrs = self.element_start('call') - try: - no = int(attrs['no']) - except KeyError: - self.last_call_no += 1 - no = self.last_call_no - else: - self.last_call_no = no - klass = attrs['class'] - method = attrs['method'] - args = [] - ret = None - while self.token.type == ELEMENT_START: - if self.token.name_or_data == 'arg': - arg = self.parse_arg() - args.append(arg) - elif self.token.name_or_data == 'ret': - ret = self.parse_ret() - elif self.token.name_or_data == 'call': - # ignore nested function calls - self.parse_call() - else: - raise TokenMismatch("<arg ...> or <ret ...>", self.token) - self.element_end('call') - - return Call(no, klass, method, args, ret) - - def parse_arg(self): - attrs = self.element_start('arg') - name = attrs['name'] - value = self.parse_value() - self.element_end('arg') - - return name, value - - def parse_ret(self): - attrs = self.element_start('ret') - value = self.parse_value() - self.element_end('ret') - - return value - - def parse_value(self): - expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes') - if self.token.type == ELEMENT_START: - if self.token.name_or_data in expected_tokens: - method = getattr(self, 'parse_' + self.token.name_or_data) - return method() - raise TokenMismatch(" or " .join(expected_tokens), self.token) - - def parse_null(self): - self.element_start('null') - self.element_end('null') - return Literal(None) - - def parse_bool(self): - self.element_start('bool') - value = int(self.character_data()) - self.element_end('bool') - return Literal(value) - - def parse_int(self): - self.element_start('int') - value = int(self.character_data()) - self.element_end('int') - return Literal(value) - - def parse_uint(self): - self.element_start('uint') - value = int(self.character_data()) - self.element_end('uint') - return Literal(value) - - def parse_float(self): - self.element_start('float') - value = float(self.character_data()) - self.element_end('float') - return Literal(value) - - def parse_enum(self): - self.element_start('enum') - name = self.character_data() - self.element_end('enum') - return NamedConstant(name) - - def parse_string(self): - self.element_start('string') - value = self.character_data() - self.element_end('string') - return Literal(value) - - def parse_bytes(self): - self.element_start('bytes') - value = binascii.a2b_hex(self.character_data()) - self.element_end('bytes') - return Literal(value) - - def parse_array(self): - self.element_start('array') - elems = [] - while self.token.type != ELEMENT_END: - elems.append(self.parse_elem()) - self.element_end('array') - return Array(elems) - - def parse_elem(self): - self.element_start('elem') - value = self.parse_value() - self.element_end('elem') - return value - - def parse_struct(self): - attrs = self.element_start('struct') - name = attrs['name'] - members = [] - while self.token.type != ELEMENT_END: - members.append(self.parse_member()) - self.element_end('struct') - return Struct(name, members) - - def parse_member(self): - attrs = self.element_start('member') - name = attrs['name'] - value = self.parse_value() - self.element_end('member') - - return name, value - - def parse_ptr(self): - self.element_start('ptr') - address = self.character_data() - self.element_end('ptr') - - return Pointer(address) - - def handle_call(self, call): - pass - - -class TraceDumper(TraceParser): - - def __init__(self, fp): - TraceParser.__init__(self, fp) - self.formatter = format.DefaultFormatter(sys.stdout) - self.pretty_printer = PrettyPrinter(self.formatter) - - def handle_call(self, call): - call.visit(self.pretty_printer) - self.formatter.newline() - - -class Main: - '''Common main class for all retrace command line utilities.''' - - def __init__(self): - pass - - def main(self): - optparser = self.get_optparser() - (options, args) = optparser.parse_args(sys.argv[1:]) - - if args: - for arg in args: - if arg.endswith('.gz'): - from gzip import GzipFile - stream = GzipFile(arg, 'rt') - elif arg.endswith('.bz2'): - from bz2 import BZ2File - stream = BZ2File(arg, 'rt') - else: - stream = open(arg, 'rt') - self.process_arg(stream, options) - else: - self.process_arg(stream, options) - - def get_optparser(self): - optparser = optparse.OptionParser( - usage="\n\t%prog [options] [traces] ...") - return optparser - - def process_arg(self, stream, options): - parser = TraceDumper(stream) - parser.parse() +from parse import * if __name__ == '__main__': diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 41cdeaa6fdc..f0a4826a001 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -260,7 +260,7 @@ st_softpipe_screen_create(void) static struct pipe_context * st_softpipe_context_create(struct pipe_screen *screen) { - return softpipe_create(screen, screen->winsys, NULL); + return softpipe_create(screen); } diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript index 038a7a31b32..61fd8bfc0c8 100644 --- a/src/gallium/state_trackers/wgl/SConscript +++ b/src/gallium/state_trackers/wgl/SConscript @@ -26,7 +26,6 @@ if env['platform'] in ['windows']: 'shared/stw_device.c', 'shared/stw_framebuffer.c', 'shared/stw_pixelformat.c', - 'shared/stw_quirks.c', 'shared/stw_arbextensionsstring.c', 'shared/stw_getprocaddress.c', 'shared/stw_arbpixelformat.c', diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.h b/src/gallium/state_trackers/wgl/icd/stw_icd.h index 8e676fb5b74..cbc1a665481 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.h +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.h @@ -25,8 +25,8 @@ * **************************************************************************/ -#ifndef DRV_H -#define DRV_H +#ifndef STW_ICD_H +#define STW_ICD_H #include <windows.h> @@ -486,4 +486,4 @@ BOOL APIENTRY DrvValidateVersion( ULONG ulVersion ); -#endif /* DRV_H */ +#endif /* STW_ICD_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c b/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c index b3934cb4643..cd9fe93eeec 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c +++ b/src/gallium/state_trackers/wgl/shared/stw_arbextensionsstring.c @@ -27,7 +27,11 @@ #include <windows.h> -#include "stw_arbextensionsstring.h" +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + WINGDIAPI const char * APIENTRY wglGetExtensionsStringARB( diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c index f5636354202..0e2d4076993 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.c @@ -25,75 +25,30 @@ * **************************************************************************/ +/** + * @file + * + * WGL_ARB_pixel_format extension implementation. + * + * @sa http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt + */ + + #include <windows.h> +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + #include "pipe/p_compiler.h" #include "util/u_memory.h" #include "stw_public.h" #include "stw_pixelformat.h" -#include "stw_arbpixelformat.h" - -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 - -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 - -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A - -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C - -/* From arb_multisample: - */ -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 static boolean -query_attrib( +stw_query_attrib( int iPixelFormat, int iLayerPlane, int attrib, @@ -101,9 +56,9 @@ query_attrib( { uint count; uint index; - const struct pixelformat_info *pf; + const struct stw_pixelformat_info *pfi; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); if (attrib == WGL_NUMBER_PIXEL_FORMATS_ARB) { *pvalue = (int) count; @@ -114,30 +69,27 @@ query_attrib( if (index >= count) return FALSE; - pf = pixelformat_get_info( index ); + pfi = stw_pixelformat_get_info( index ); switch (attrib) { case WGL_DRAW_TO_WINDOW_ARB: - *pvalue = TRUE; + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? TRUE : FALSE; return TRUE; case WGL_DRAW_TO_BITMAP_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_BITMAP ? TRUE : FALSE; return TRUE; case WGL_NEED_PALETTE_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_NEED_PALETTE ? TRUE : FALSE; return TRUE; case WGL_NEED_SYSTEM_PALETTE_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE ? TRUE : FALSE; return TRUE; case WGL_SWAP_METHOD_ARB: - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - *pvalue = WGL_SWAP_COPY_ARB; - else - *pvalue = WGL_SWAP_UNDEFINED_ARB; + *pvalue = pfi->pfd.dwFlags & PFD_SWAP_COPY ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB; return TRUE; case WGL_SWAP_LAYER_BUFFERS_ARB: @@ -179,96 +131,108 @@ query_attrib( break; case WGL_SUPPORT_GDI_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_GDI ? TRUE : FALSE; break; case WGL_SUPPORT_OPENGL_ARB: - *pvalue = TRUE; + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_OPENGL ? TRUE : FALSE; break; case WGL_DOUBLE_BUFFER_ARB: - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - *pvalue = TRUE; - else - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_DOUBLEBUFFER ? TRUE : FALSE; break; case WGL_STEREO_ARB: - *pvalue = FALSE; + *pvalue = pfi->pfd.dwFlags & PFD_STEREO ? TRUE : FALSE; break; case WGL_PIXEL_TYPE_ARB: - *pvalue = WGL_TYPE_RGBA_ARB; + switch (pfi->pfd.iPixelType) { + case PFD_TYPE_RGBA: + *pvalue = WGL_TYPE_RGBA_ARB; + break; + case PFD_TYPE_COLORINDEX: + *pvalue = WGL_TYPE_COLORINDEX_ARB; + break; + default: + return FALSE; + } break; case WGL_COLOR_BITS_ARB: - *pvalue = (int) (pf->color.redbits + pf->color.greenbits + pf->color.bluebits); + *pvalue = pfi->pfd.cColorBits; break; case WGL_RED_BITS_ARB: - *pvalue = (int) pf->color.redbits; + *pvalue = pfi->pfd.cRedBits; break; case WGL_RED_SHIFT_ARB: - *pvalue = (int) pf->color.redshift; + *pvalue = pfi->pfd.cRedShift; break; case WGL_GREEN_BITS_ARB: - *pvalue = (int) pf->color.greenbits; + *pvalue = pfi->pfd.cGreenBits; break; case WGL_GREEN_SHIFT_ARB: - *pvalue = (int) pf->color.greenshift; + *pvalue = pfi->pfd.cGreenShift; break; case WGL_BLUE_BITS_ARB: - *pvalue = (int) pf->color.bluebits; + *pvalue = pfi->pfd.cBlueBits; break; case WGL_BLUE_SHIFT_ARB: - *pvalue = (int) pf->color.blueshift; + *pvalue = pfi->pfd.cBlueShift; break; case WGL_ALPHA_BITS_ARB: - *pvalue = (int) pf->alpha.alphabits; + *pvalue = pfi->pfd.cAlphaBits; break; case WGL_ALPHA_SHIFT_ARB: - *pvalue = (int) pf->alpha.alphashift; + *pvalue = pfi->pfd.cAlphaShift; break; case WGL_ACCUM_BITS_ARB: + *pvalue = pfi->pfd.cAccumBits; + break; + case WGL_ACCUM_RED_BITS_ARB: + *pvalue = pfi->pfd.cAccumRedBits; + break; + case WGL_ACCUM_GREEN_BITS_ARB: + *pvalue = pfi->pfd.cAccumGreenBits; + break; + case WGL_ACCUM_BLUE_BITS_ARB: + *pvalue = pfi->pfd.cAccumBlueBits; + break; + case WGL_ACCUM_ALPHA_BITS_ARB: - *pvalue = 0; + *pvalue = pfi->pfd.cAccumAlphaBits; break; case WGL_DEPTH_BITS_ARB: - *pvalue = (int) pf->depth.depthbits; + *pvalue = pfi->pfd.cDepthBits; break; case WGL_STENCIL_BITS_ARB: - *pvalue = (int) pf->depth.stencilbits; + *pvalue = pfi->pfd.cStencilBits; break; case WGL_AUX_BUFFERS_ARB: - *pvalue = 0; + *pvalue = pfi->pfd.cAuxBuffers; break; case WGL_SAMPLE_BUFFERS_ARB: - if (pf->flags & PF_FLAG_MULTISAMPLED) - *pvalue = stw_query_sample_buffers(); - else - *pvalue = 0; + *pvalue = pfi->numSampleBuffers; break; case WGL_SAMPLES_ARB: - if (pf->flags & PF_FLAG_MULTISAMPLED) - *pvalue = stw_query_samples(); - else - *pvalue = 0; + *pvalue = pfi->numSamples; break; default: @@ -285,7 +249,7 @@ struct attrib_match_info BOOL exact; }; -static struct attrib_match_info attrib_match[] = { +static const struct attrib_match_info attrib_match[] = { /* WGL_ARB_pixel_format */ { WGL_DRAW_TO_WINDOW_ARB, 0, TRUE }, @@ -324,7 +288,7 @@ static struct attrib_match_info attrib_match[] = { { WGL_SAMPLES_ARB, 2, FALSE } }; -struct pixelformat_score +struct stw_pixelformat_score { int points; uint index; @@ -332,13 +296,13 @@ struct pixelformat_score static BOOL score_pixelformats( - struct pixelformat_score *scores, + struct stw_pixelformat_score *scores, uint count, int attribute, int expected_value ) { uint i; - struct attrib_match_info *ami = NULL; + const struct attrib_match_info *ami = NULL; uint index; /* Find out if a given attribute should be considered for score calculation. @@ -358,7 +322,7 @@ score_pixelformats( for (index = 0; index < count; index++) { int actual_value; - if (!query_attrib( index + 1, 0, attribute, &actual_value )) + if (!stw_query_attrib( index + 1, 0, attribute, &actual_value )) return FALSE; if (ami->exact) { @@ -395,7 +359,7 @@ wglChoosePixelFormatARB( UINT *nNumFormats ) { uint count; - struct pixelformat_score *scores; + struct stw_pixelformat_score *scores; uint i; *nNumFormats = 0; @@ -405,8 +369,8 @@ wglChoosePixelFormatARB( * points for a mismatch when the match does not have to be exact. * Set a score to 0 if there is a mismatch for an exact match criteria. */ - count = pixelformat_get_extended_count(); - scores = (struct pixelformat_score *) MALLOC( count * sizeof( struct pixelformat_score ) ); + count = stw_pixelformat_get_extended_count(); + scores = (struct stw_pixelformat_score *) MALLOC( count * sizeof( struct stw_pixelformat_score ) ); if (scores == NULL) return FALSE; for (i = 0; i < count; i++) { @@ -446,7 +410,7 @@ wglChoosePixelFormatARB( swapped = FALSE; for (i = 1; i < n; i++) { if (scores[i - 1].points < scores[i].points) { - struct pixelformat_score score = scores[i - 1]; + struct stw_pixelformat_score score = scores[i - 1]; scores[i - 1] = scores[i]; scores[i] = score; @@ -489,7 +453,7 @@ wglGetPixelFormatAttribfvARB( for (i = 0; i < nAttributes; i++) { int value; - if (!query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &value )) + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &value )) return FALSE; pfValues[i] = (FLOAT) value; } @@ -511,7 +475,7 @@ wglGetPixelFormatAttribivARB( (void) hdc; for (i = 0; i < nAttributes; i++) { - if (!query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &piValues[i] )) + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &piValues[i] )) return FALSE; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h b/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h deleted file mode 100644 index a6c42599424..00000000000 --- a/src/gallium/state_trackers/wgl/shared/stw_arbpixelformat.h +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -#ifndef WGL_ARBPIXELFORMAT_H -#define WGL_ARBPIXELFORMAT_H - - -/* Extension functions for get_proc_address: - */ -WINGDIAPI BOOL APIENTRY -wglChoosePixelFormatARB( - HDC hdc, - const int *piAttribIList, - const FLOAT *pfAttribFList, - UINT nMaxFormats, - int *piFormats, - UINT *nNumFormats ); - -WINGDIAPI BOOL APIENTRY -wglGetPixelFormatAttribfvARB( - HDC hdc, - int iPixelFormat, - int iLayerPlane, - UINT nAttributes, - const int *piAttributes, - FLOAT *pfValues ); - -WINGDIAPI BOOL APIENTRY -wglGetPixelFormatAttribivARB( - HDC hdc, - int iPixelFormat, - int iLayerPlane, - UINT nAttributes, - const int *piAttributes, - int *piValues ); - -#endif /* WGL_ARBPIXELFORMAT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index f890225242a..f3c7af93f50 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -59,8 +59,8 @@ stw_copy_context( pipe_mutex_lock( stw_dev->mutex ); - src = stw_lookup_context( hglrcSrc ); - dst = stw_lookup_context( hglrcDst ); + src = stw_lookup_context_locked( hglrcSrc ); + dst = stw_lookup_context_locked( hglrcDst ); if (src && dst) { /* FIXME */ @@ -80,7 +80,7 @@ stw_create_layer_context( int iLayerPlane ) { uint pfi; - const struct pixelformat_info *pf = NULL; + const struct stw_pixelformat_info *pf = NULL; struct stw_context *ctx = NULL; GLvisual *visual = NULL; struct pipe_screen *screen = NULL; @@ -97,7 +97,7 @@ stw_create_layer_context( if (pfi == 0) return 0; - pf = pixelformat_get_info( pfi - 1 ); + pf = stw_pixelformat_get_info( pfi - 1 ); ctx = CALLOC_STRUCT( stw_context ); if (ctx == NULL) @@ -109,21 +109,21 @@ stw_create_layer_context( /* Create visual based on flags */ visual = _mesa_create_visual( - GL_TRUE, - (pf->flags & PF_FLAG_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, - GL_FALSE, - pf->color.redbits, - pf->color.greenbits, - pf->color.bluebits, - pf->alpha.alphabits, - 0, - pf->depth.depthbits, - pf->depth.stencilbits, - 0, - 0, - 0, - 0, - (pf->flags & PF_FLAG_MULTISAMPLED) ? stw_query_samples() : 0 ); + (pf->pfd.iPixelType == PFD_TYPE_RGBA) ? GL_TRUE : GL_FALSE, + (pf->pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, + (pf->pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE, + pf->pfd.cRedBits, + pf->pfd.cGreenBits, + pf->pfd.cBlueBits, + pf->pfd.cAlphaBits, + (pf->pfd.iPixelType == PFD_TYPE_COLORINDEX) ? pf->pfd.cColorBits : 0, + pf->pfd.cDepthBits, + pf->pfd.cStencilBits, + pf->pfd.cAccumRedBits, + pf->pfd.cAccumGreenBits, + pf->pfd.cAccumBlueBits, + pf->pfd.cAccumAlphaBits, + pf->numSamples ); if (visual == NULL) goto fail; @@ -153,11 +153,10 @@ stw_create_layer_context( goto fail; ctx->st->ctx->DriverCtx = ctx; + ctx->pfi = pf; pipe_mutex_lock( stw_dev->mutex ); - { - hglrc = handle_table_add(stw_dev->ctx_table, ctx); - } + hglrc = handle_table_add(stw_dev->ctx_table, ctx); pipe_mutex_unlock( stw_dev->mutex ); /* Success? @@ -187,8 +186,10 @@ stw_delete_context( return FALSE; pipe_mutex_lock( stw_dev->mutex ); + ctx = stw_lookup_context_locked(hglrc); + handle_table_remove(stw_dev->ctx_table, hglrc); + pipe_mutex_unlock( stw_dev->mutex ); - ctx = stw_lookup_context(hglrc); if (ctx) { GLcontext *glctx = ctx->st->ctx; GET_CURRENT_CONTEXT( glcurctx ); @@ -199,26 +200,19 @@ stw_delete_context( if (glcurctx == glctx) st_make_current( NULL, NULL, NULL ); - fb = framebuffer_from_hdc( ctx->hdc ); + fb = stw_framebuffer_from_hdc( ctx->hdc ); if (fb) - framebuffer_destroy( fb ); + stw_framebuffer_destroy( fb ); if (WindowFromDC( ctx->hdc ) != NULL) ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); - pipe_mutex_lock(stw_dev->mutex); - { - st_destroy_context(ctx->st); - FREE(ctx); - handle_table_remove(stw_dev->ctx_table, hglrc); - } - pipe_mutex_unlock(stw_dev->mutex); + st_destroy_context(ctx->st); + FREE(ctx); ret = TRUE; } - pipe_mutex_unlock( stw_dev->mutex ); - return ret; } @@ -226,38 +220,40 @@ BOOL stw_release_context( UINT_PTR hglrc ) { - BOOL ret = FALSE; + struct stw_context *ctx; if (!stw_dev) - return ret; + return FALSE; pipe_mutex_lock( stw_dev->mutex ); - { - struct stw_context *ctx; - - /* XXX: The expectation is that ctx is the same context which is - * current for this thread. We should check that and return False - * if not the case. - */ - ctx = stw_lookup_context( hglrc ); - if (ctx == NULL) - goto done; + ctx = stw_lookup_context_locked( hglrc ); + pipe_mutex_unlock( stw_dev->mutex ); - if (stw_make_current( NULL, 0 ) == FALSE) - goto done; + if (!ctx) + return FALSE; + + /* The expectation is that ctx is the same context which is + * current for this thread. We should check that and return False + * if not the case. + */ + { + GLcontext *glctx = ctx->st->ctx; + GET_CURRENT_CONTEXT( glcurctx ); - ret = TRUE; + if (glcurctx != glctx) + return FALSE; } -done: - pipe_mutex_unlock( stw_dev->mutex ); - return ret; + if (stw_make_current( NULL, 0 ) == FALSE) + return FALSE; + + return TRUE; } /* Find the width and height of the window named by hdc. */ static void -get_window_size( HDC hdc, GLuint *width, GLuint *height ) +stw_get_window_size( HDC hdc, GLuint *width, GLuint *height ) { if (WindowFromDC( hdc )) { RECT rect; @@ -300,7 +296,7 @@ stw_make_current( return FALSE; pipe_mutex_lock( stw_dev->mutex ); - ctx = stw_lookup_context( hglrc ); + ctx = stw_lookup_context_locked( hglrc ); pipe_mutex_unlock( stw_dev->mutex ); stw_tls_get_data()->currentDC = hdc; @@ -325,24 +321,27 @@ stw_make_current( return TRUE; } - fb = framebuffer_from_hdc( hdc ); + fb = stw_framebuffer_from_hdc( hdc ); if (hdc != NULL) - get_window_size( hdc, &width, &height ); + stw_get_window_size( hdc, &width, &height ); - /* Lazy creation of framebuffers. + /* Lazy creation of stw_framebuffers. */ if (fb == NULL && ctx != NULL && hdc != NULL) { GLvisual *visual = &ctx->st->ctx->Visual; - fb = framebuffer_create( hdc, visual, width, height ); + fb = stw_framebuffer_create( hdc, visual, ctx->pfi, width, height ); if (fb == NULL) return FALSE; } if (ctx && fb) { + pipe_mutex_lock( fb->mutex ); st_make_current( ctx->st, fb->stfb, fb->stfb ); - framebuffer_resize( fb, width, height ); + st_resize_framebuffer( fb->stfb, width, height ); + pipe_mutex_unlock( fb->mutex ); + ctx->hdc = hdc; ctx->st->pipe->priv = hdc; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h index b2896152724..bc3b1dc880d 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.h +++ b/src/gallium/state_trackers/wgl/shared/stw_context.h @@ -31,12 +31,14 @@ #include <windows.h> struct st_context; +struct stw_pixelformat_info; struct stw_context { struct st_context *st; HDC hdc; DWORD color_bits; + const struct stw_pixelformat_info *pfi; }; #endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 51936c2bdd6..eef848988c0 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -41,6 +41,7 @@ #include "shared/stw_pixelformat.h" #include "shared/stw_public.h" #include "shared/stw_tls.h" +#include "shared/stw_framebuffer.h" #ifdef WIN32_THREADS extern _glthread_Mutex OneTimeLock; @@ -75,7 +76,7 @@ st_flush_frontbuffer(struct pipe_screen *screen, boolean -st_init(const struct stw_winsys *stw_winsys) +stw_init(const struct stw_winsys *stw_winsys) { static struct stw_device stw_dev_storage; struct pipe_screen *screen; @@ -119,7 +120,7 @@ st_init(const struct stw_winsys *stw_winsys) goto error1; } - pixelformat_init(); + stw_pixelformat_init(); return TRUE; @@ -130,25 +131,28 @@ error1: boolean -st_init_thread(void) +stw_init_thread(void) { - if (!stw_tls_init_thread()) { + if (!stw_tls_init_thread()) + return FALSE; + + if (!stw_framebuffer_init_thread()) return FALSE; - } return TRUE; } void -st_cleanup_thread(void) +stw_cleanup_thread(void) { + stw_framebuffer_cleanup_thread(); stw_tls_cleanup_thread(); } void -st_cleanup(void) +stw_cleanup(void) { unsigned i; @@ -189,7 +193,7 @@ st_cleanup(void) struct stw_context * -stw_lookup_context( UINT_PTR dhglrc ) +stw_lookup_context_locked( UINT_PTR dhglrc ) { if (dhglrc == 0) return NULL; diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h index 703cb670816..969e3843e76 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.h +++ b/src/gallium/state_trackers/wgl/shared/stw_device.h @@ -29,12 +29,19 @@ #define STW_DEVICE_H_ +#include <windows.h> + #include "pipe/p_compiler.h" #include "pipe/p_thread.h" #include "util/u_handle_table.h" +#include "stw_pixelformat.h" + + +#define STW_MAX_PIXELFORMATS 128 struct pipe_screen; +struct stw_framebuffer; struct stw_device { @@ -45,18 +52,24 @@ struct stw_device #ifdef DEBUG boolean trace_running; #endif - + + struct stw_pixelformat_info pixelformats[STW_MAX_PIXELFORMATS]; + unsigned pixelformat_count; + unsigned pixelformat_extended_count; + pipe_mutex mutex; struct handle_table *ctx_table; + struct stw_framebuffer *fb_head; + #ifdef DEBUG unsigned long memdbg_no; #endif }; struct stw_context * -stw_lookup_context( UINT_PTR hglrc ); +stw_lookup_context_locked( UINT_PTR hglrc ); extern struct stw_device *stw_dev; diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c index c96c4b8dfa8..4348b8f3262 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c @@ -42,143 +42,94 @@ #include "stw_device.h" #include "stw_public.h" #include "stw_winsys.h" +#include "stw_tls.h" -void -framebuffer_resize( - struct stw_framebuffer *fb, - GLuint width, - GLuint height ) -{ - st_resize_framebuffer( fb->stfb, width, height ); -} - -static struct stw_framebuffer *fb_head = NULL; - +/** + * @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx + * @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx + */ static LRESULT CALLBACK -window_proc( - HWND hWnd, - UINT uMsg, +stw_call_window_proc( + int nCode, WPARAM wParam, LPARAM lParam ) { - struct stw_framebuffer *fb; - - for (fb = fb_head; fb != NULL; fb = fb->next) - if (fb->hWnd == hWnd) - break; - assert( fb != NULL ); - - if (uMsg == WM_SIZE && wParam != SIZE_MINIMIZED) - framebuffer_resize( fb, LOWORD( lParam ), HIWORD( lParam ) ); - - return CallWindowProc( fb->WndProc, hWnd, uMsg, wParam, lParam ); -} + struct stw_tls_data *tls_data; + PCWPSTRUCT pParams = (PCWPSTRUCT)lParam; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return 0; + + if (nCode < 0) + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); + + if (pParams->message == WM_SIZE && pParams->wParam != SIZE_MINIMIZED) { + struct stw_framebuffer *fb; + + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) + if (fb->hWnd == pParams->hwnd) + break; + pipe_mutex_unlock( stw_dev->mutex ); + + if(fb) { + unsigned width = LOWORD( pParams->lParam ); + unsigned height = HIWORD( pParams->lParam ); + + /* FIXME: The mesa statetracker makes the assumptions that only + * one context is using the framebuffer, and that that context is the + * current one. However neither holds true, as WGL allows more than + * one context to be bound to the same drawable, and this function can + * be called from any thread. + */ + pipe_mutex_lock( fb->mutex ); + st_resize_framebuffer( fb->stfb, width, height ); + pipe_mutex_unlock( fb->mutex ); + } + } -static INLINE boolean -stw_is_supported_color(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); } -static INLINE boolean -stw_is_supported_depth_stencil(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); -} /* Create a new framebuffer object which will correspond to the given HDC. */ struct stw_framebuffer * -framebuffer_create( +stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ) { - struct stw_framebuffer *fb; enum pipe_format colorFormat, depthFormat, stencilFormat; + struct stw_framebuffer *fb; - /* Determine PIPE_FORMATs for buffers. - */ - - if(visual->alphaBits <= 0 && visual->redBits <= 5 && visual->blueBits <= 6 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_R5G6B5_UNORM)) { - colorFormat = PIPE_FORMAT_R5G6B5_UNORM; - } - else if(visual->alphaBits <= 0 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_X8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_X8R8G8B8_UNORM; - } - else if(visual->alphaBits <= 1 && visual->redBits <= 5 && visual->blueBits <= 5 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_A1R5G5B5_UNORM)) { - colorFormat = PIPE_FORMAT_A1R5G5B5_UNORM; - } - else if(visual->alphaBits <= 4 && visual->redBits <= 4 && visual->blueBits <= 4 && visual->greenBits <= 4 && - stw_is_supported_color(PIPE_FORMAT_A4R4G4B4_UNORM)) { - colorFormat = PIPE_FORMAT_A4R4G4B4_UNORM; - } - else if(visual->alphaBits <= 8 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_A8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM; - } - else { - assert(0); - return NULL; - } + colorFormat = pfi->color_format; + + assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); - if (visual->depthBits == 0) + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z )) + depthFormat = pfi->depth_stencil_format; + else depthFormat = PIPE_FORMAT_NONE; - else if (visual->depthBits <= 16 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z16_UNORM)) - depthFormat = PIPE_FORMAT_Z16_UNORM; - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_X8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_X8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24X8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24X8_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_S8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24S8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24S8_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_UNORM)) { - depthFormat = PIPE_FORMAT_Z32_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_FLOAT)) { - depthFormat = PIPE_FORMAT_Z32_FLOAT; - } - else { - assert(0); - depthFormat = PIPE_FORMAT_NONE; - } - if (depthFormat == PIPE_FORMAT_S8Z24_UNORM || - depthFormat == PIPE_FORMAT_Z24S8_UNORM) { - stencilFormat = depthFormat; - } - else if (visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8_UNORM)) { - stencilFormat = PIPE_FORMAT_S8_UNORM; - } - else { + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S )) + stencilFormat = pfi->depth_stencil_format; + else stencilFormat = PIPE_FORMAT_NONE; - } fb = CALLOC_STRUCT( stw_framebuffer ); if (fb == NULL) return NULL; + fb->hDC = hdc; + fb->hWnd = WindowFromDC( hdc ); + + pipe_mutex_init( fb->mutex ); + fb->stfb = st_create_framebuffer( visual, colorFormat, @@ -187,63 +138,60 @@ framebuffer_create( width, height, (void *) fb ); - - fb->cColorBits = GetDeviceCaps( hdc, BITSPIXEL ); - fb->hDC = hdc; - - /* Subclass a window associated with the device context. - */ - fb->hWnd = WindowFromDC( hdc ); - if (fb->hWnd != NULL) { - fb->WndProc = (WNDPROC) SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) window_proc ); + if(!fb->stfb) { + FREE(fb); + return NULL; } - fb->next = fb_head; - fb_head = fb; + pipe_mutex_lock( stw_dev->mutex ); + fb->next = stw_dev->fb_head; + stw_dev->fb_head = fb; + pipe_mutex_unlock( stw_dev->mutex ); + return fb; } void -framebuffer_destroy( +stw_framebuffer_destroy( struct stw_framebuffer *fb ) { - struct stw_framebuffer **link = &fb_head; - struct stw_framebuffer *pfb = fb_head; - - while (pfb != NULL) { - if (pfb == fb) { - if (fb->hWnd != NULL) { - SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) fb->WndProc ); - } - - *link = fb->next; - FREE( fb ); - return; - } + struct stw_framebuffer **link; - link = &pfb->next; - pfb = pfb->next; - } + pipe_mutex_lock( stw_dev->mutex ); + + link = &stw_dev->fb_head; + while (link && *link != fb) + link = &(*link)->next; + assert(*link); + if (link) + *link = fb->next; + fb->next = NULL; + + pipe_mutex_unlock( stw_dev->mutex ); + + st_unreference_framebuffer(fb->stfb); + + pipe_mutex_destroy( fb->mutex ); + + FREE( fb ); } -/* Given an hdc, return the corresponding stw_framebuffer. +/** + * Given an hdc, return the corresponding stw_framebuffer. */ struct stw_framebuffer * -framebuffer_from_hdc( +stw_framebuffer_from_hdc( HDC hdc ) { struct stw_framebuffer *fb; - for (fb = fb_head; fb != NULL; fb = fb->next) + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) if (fb->hDC == hdc) - return fb; - return NULL; + break; + pipe_mutex_unlock( stw_dev->mutex ); + + return fb; } @@ -255,10 +203,12 @@ stw_swap_buffers( struct pipe_screen *screen; struct pipe_surface *surface; - fb = framebuffer_from_hdc( hdc ); + fb = stw_framebuffer_from_hdc( hdc ); if (fb == NULL) return FALSE; + pipe_mutex_lock( fb->mutex ); + /* If we're swapping the buffer associated with the current context * we have to flush any pending rendering commands first. */ @@ -266,9 +216,11 @@ stw_swap_buffers( screen = stw_dev->screen; - if(!st_get_framebuffer_surface( fb->stfb, ST_SURFACE_BACK_LEFT, &surface )) + if(!st_get_framebuffer_surface( fb->stfb, ST_SURFACE_BACK_LEFT, &surface )) { /* FIXME: this shouldn't happen, but does on glean */ + pipe_mutex_unlock( fb->mutex ); return FALSE; + } #ifdef DEBUG if(stw_dev->trace_running) { @@ -279,5 +231,42 @@ stw_swap_buffers( stw_dev->stw_winsys->flush_frontbuffer( screen, surface, hdc ); + pipe_mutex_unlock( fb->mutex ); + return TRUE; } + + +boolean +stw_framebuffer_init_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return FALSE; + + tls_data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, + stw_call_window_proc, + NULL, + GetCurrentThreadId()); + if(tls_data->hCallWndProcHook == NULL) + return FALSE; + + return TRUE; +} + +void +stw_framebuffer_cleanup_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return; + + if(tls_data->hCallWndProcHook) { + UnhookWindowsHookEx(tls_data->hCallWndProcHook); + tls_data->hCallWndProcHook = NULL; + } +} diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h index 5abdf189970..f5b48db048c 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h @@ -28,39 +28,49 @@ #ifndef STW_FRAMEBUFFER_H #define STW_FRAMEBUFFER_H +#include <windows.h> + #include "main/mtypes.h" -/* Windows framebuffer, derived from gl_framebuffer. +#include "pipe/p_thread.h" + +struct stw_pixelformat_info; + +/** + * Windows framebuffer, derived from gl_framebuffer. */ struct stw_framebuffer { - struct st_framebuffer *stfb; HDC hDC; - BYTE cColorBits; HWND hWnd; - WNDPROC WndProc; + + pipe_mutex mutex; + struct st_framebuffer *stfb; + + /** This is protected by stw_device::mutex, not the mutex above */ struct stw_framebuffer *next; }; struct stw_framebuffer * -framebuffer_create( +stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ); void -framebuffer_destroy( +stw_framebuffer_destroy( struct stw_framebuffer *fb ); -void -framebuffer_resize( - struct stw_framebuffer *fb, - GLuint width, - GLuint height ); - struct stw_framebuffer * -framebuffer_from_hdc( +stw_framebuffer_from_hdc( HDC hdc ); +boolean +stw_framebuffer_init_thread(void); + +void +stw_framebuffer_cleanup_thread(void); + #endif /* STW_FRAMEBUFFER_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c b/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c index ac2d6fc2605..aa43120955e 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c +++ b/src/gallium/state_trackers/wgl/shared/stw_getprocaddress.c @@ -27,28 +27,31 @@ #include <windows.h> +#define WGL_WGLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/wglext.h> + #include "glapi/glapi.h" -#include "stw_arbextensionsstring.h" -#include "stw_arbpixelformat.h" #include "stw_public.h" -struct extension_entry +struct stw_extension_entry { const char *name; PROC proc; }; -#define EXTENTRY(P) { #P, (PROC) P } +#define STW_EXTENSION_ENTRY(P) { #P, (PROC) P } -static struct extension_entry extension_entries[] = { +static const struct stw_extension_entry stw_extension_entries[] = { /* WGL_ARB_extensions_string */ - EXTENTRY( wglGetExtensionsStringARB ), + STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ), /* WGL_ARB_pixel_format */ - EXTENTRY( wglChoosePixelFormatARB ), - EXTENTRY( wglGetPixelFormatAttribfvARB ), - EXTENTRY( wglGetPixelFormatAttribivARB ), + STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ), { NULL, NULL } }; @@ -57,13 +60,13 @@ PROC stw_get_proc_address( LPCSTR lpszProc ) { - struct extension_entry *entry; + const struct stw_extension_entry *entry; - PROC p = (PROC) _glapi_get_proc_address( (const char *) lpszProc ); + PROC p = (PROC) _glapi_get_proc_address( lpszProc ); if (p) return p; - for (entry = extension_entries; entry->name; entry++) + for (entry = stw_extension_entries; entry->name; entry++) if (strcmp( lpszProc, entry->name ) == 0) return entry->proc; diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c index b216ca5c823..9e642cbdd48 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c @@ -25,113 +25,237 @@ * **************************************************************************/ +#include "pipe/p_format.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" + #include "util/u_debug.h" +#include "util/u_memory.h" + +#include "stw_device.h" #include "stw_pixelformat.h" #include "stw_public.h" #include "stw_tls.h" -#define MAX_PIXELFORMATS 16 -static struct pixelformat_info pixelformats[MAX_PIXELFORMATS]; -static uint pixelformat_count = 0; -static uint pixelformat_extended_count = 0; +struct stw_pf_color_info +{ + enum pipe_format format; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } bits; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } shift; +}; + +struct stw_pf_depth_info +{ + enum pipe_format format; + struct { + unsigned char depth; + unsigned char stencil; + } bits; +}; + + +/* NOTE: order matters, since in otherwise equal circumstances the first + * format listed will get chosen */ + +static const struct stw_pf_color_info +stw_pf_color[] = { + /* no-alpha */ + { PIPE_FORMAT_X8R8G8B8_UNORM, { 8, 8, 8, 0}, {16, 8, 0, 0} }, + { PIPE_FORMAT_B8G8R8X8_UNORM, { 8, 8, 8, 0}, { 8, 16, 24, 0} }, + { PIPE_FORMAT_R5G6B5_UNORM, { 5, 6, 5, 0}, {11, 5, 0, 0} }, + /* alpha */ + { PIPE_FORMAT_A8R8G8B8_UNORM, { 8, 8, 8, 8}, {16, 8, 0, 24} }, + { PIPE_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, { 8, 16, 24, 0} }, +#if 0 + { PIPE_FORMAT_A2B10G10R10_UNORM, {10, 10, 10, 2}, { 0, 10, 20, 30} }, +#endif + { PIPE_FORMAT_A1R5G5B5_UNORM, { 5, 5, 5, 1}, {10, 5, 0, 15} }, + { PIPE_FORMAT_A4R4G4B4_UNORM, { 4, 4, 4, 4}, {16, 4, 0, 12} } +}; + + +static const struct stw_pf_depth_info +stw_pf_depth_stencil[] = { + /* pure depth */ + { PIPE_FORMAT_Z32_UNORM, {32, 0} }, + { PIPE_FORMAT_Z24X8_UNORM, {24, 0} }, + { PIPE_FORMAT_X8Z24_UNORM, {24, 0} }, + { PIPE_FORMAT_Z16_UNORM, {16, 0} }, + /* pure stencil */ + { PIPE_FORMAT_S8_UNORM, { 0, 8} }, + /* combined depth-stencil */ + { PIPE_FORMAT_S8Z24_UNORM, {24, 8} }, + { PIPE_FORMAT_Z24S8_UNORM, {24, 8} } +}; + + +static const boolean +stw_pf_doublebuffer[] = { + FALSE, + TRUE, +}; + + +const unsigned +stw_pf_multisample[] = { + 0, + 4 +}; static void -add_standard_pixelformats( - struct pixelformat_info **ppf, - uint flags ) +stw_pixelformat_add( + struct stw_device *stw_dev, + const struct stw_pf_color_info *color, + const struct stw_pf_depth_info *depth, + boolean doublebuffer, + unsigned samples ) { - struct pixelformat_info *pf = *ppf; - struct pixelformat_color_info color24 = { 8, 0, 8, 8, 8, 16 }; - struct pixelformat_alpha_info alpha8 = { 8, 24 }; - struct pixelformat_alpha_info noalpha = { 0, 0 }; - struct pixelformat_depth_info depth24s8 = { 24, 8 }; - struct pixelformat_depth_info depth16 = { 16, 0 }; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth16; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth24s8; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth16; - pf++; - - pf->flags = PF_FLAG_DOUBLEBUFFER | flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth24s8; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth16; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = alpha8; - pf->depth = depth24s8; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth16; - pf++; - - pf->flags = flags; - pf->color = color24; - pf->alpha = noalpha; - pf->depth = depth24s8; - pf++; - - *ppf = pf; + boolean extended = FALSE; + struct stw_pixelformat_info *pfi; + + assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS); + if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS) + return; + + assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha ); + assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil ); + + pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count]; + + memset(pfi, 0, sizeof *pfi); + + pfi->color_format = color->format; + pfi->depth_stencil_format = depth->format; + + pfi->pfd.nSize = sizeof pfi->pfd; + pfi->pfd.nVersion = 1; + + pfi->pfd.dwFlags = PFD_SUPPORT_OPENGL; + + /* TODO: also support non-native pixel formats */ + pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW ; + + if (doublebuffer) + pfi->pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY; + + pfi->pfd.iPixelType = PFD_TYPE_RGBA; + + pfi->pfd.cColorBits = color->bits.red + color->bits.green + color->bits.blue; + pfi->pfd.cRedBits = color->bits.red; + pfi->pfd.cRedShift = color->shift.red; + pfi->pfd.cGreenBits = color->bits.green; + pfi->pfd.cGreenShift = color->shift.green; + pfi->pfd.cBlueBits = color->bits.blue; + pfi->pfd.cBlueShift = color->shift.blue; + pfi->pfd.cAlphaBits = color->bits.alpha; + pfi->pfd.cAlphaShift = color->shift.alpha; + pfi->pfd.cAccumBits = 0; + pfi->pfd.cAccumRedBits = 0; + pfi->pfd.cAccumGreenBits = 0; + pfi->pfd.cAccumBlueBits = 0; + pfi->pfd.cAccumAlphaBits = 0; + pfi->pfd.cDepthBits = depth->bits.depth; + pfi->pfd.cStencilBits = depth->bits.stencil; + pfi->pfd.cAuxBuffers = 0; + pfi->pfd.iLayerType = 0; + pfi->pfd.bReserved = 0; + pfi->pfd.dwLayerMask = 0; + pfi->pfd.dwVisibleMask = 0; + pfi->pfd.dwDamageMask = 0; + + if(samples) { + pfi->numSampleBuffers = 1; + pfi->numSamples = samples; + extended = TRUE; + } + + ++stw_dev->pixelformat_extended_count; + + if(!extended) { + ++stw_dev->pixelformat_count; + assert(stw_dev->pixelformat_count == stw_dev->pixelformat_extended_count); + } } void -pixelformat_init( void ) +stw_pixelformat_init( void ) { - struct pixelformat_info *pf = pixelformats; - - add_standard_pixelformats( &pf, 0 ); - pixelformat_count = pf - pixelformats; - - add_standard_pixelformats( &pf, PF_FLAG_MULTISAMPLED ); - pixelformat_extended_count = pf - pixelformats; + struct pipe_screen *screen = stw_dev->screen; + unsigned i, j, k, l; + + assert( !stw_dev->pixelformat_count ); + assert( !stw_dev->pixelformat_extended_count ); + + for(i = 0; i < Elements(stw_pf_multisample); ++i) { + unsigned samples = stw_pf_multisample[i]; + + /* FIXME: re-enabled MSAA when we can query it */ + if(samples) + continue; - assert( pixelformat_extended_count <= MAX_PIXELFORMATS ); + for(j = 0; j < Elements(stw_pf_color); ++j) { + const struct stw_pf_color_info *color = &stw_pf_color[j]; + + if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) + continue; + + for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) { + unsigned doublebuffer = stw_pf_doublebuffer[k]; + + for(l = 0; l < Elements(stw_pf_depth_stencil); ++l) { + const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l]; + + if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0)) + continue; + + stw_pixelformat_add( stw_dev, color, depth, doublebuffer, samples ); + } + } + } + } + + assert( stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count ); + assert( stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS ); } uint -pixelformat_get_count( void ) +stw_pixelformat_get_count( void ) { - return pixelformat_count; + return stw_dev->pixelformat_count; } uint -pixelformat_get_extended_count( void ) +stw_pixelformat_get_extended_count( void ) { - return pixelformat_extended_count; + return stw_dev->pixelformat_extended_count; } -const struct pixelformat_info * -pixelformat_get_info( uint index ) +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ) { - assert( index < pixelformat_extended_count ); + assert( index < stw_dev->pixelformat_extended_count ); - return &pixelformats[index]; + return &stw_dev->pixelformats[index]; } @@ -144,11 +268,11 @@ stw_pixelformat_describe( { uint count; uint index; - const struct pixelformat_info *pf; + const struct stw_pixelformat_info *pfi; (void) hdc; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); index = (uint) iPixelFormat - 1; if (ppfd == NULL) @@ -156,36 +280,9 @@ stw_pixelformat_describe( if (index >= count || nBytes != sizeof( PIXELFORMATDESCRIPTOR )) return 0; - pf = pixelformat_get_info( index ); - - ppfd->nSize = sizeof( PIXELFORMATDESCRIPTOR ); - ppfd->nVersion = 1; - ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - if (pf->flags & PF_FLAG_DOUBLEBUFFER) - ppfd->dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY; - ppfd->iPixelType = PFD_TYPE_RGBA; - ppfd->cColorBits = pf->color.redbits + pf->color.greenbits + pf->color.bluebits; - ppfd->cRedBits = pf->color.redbits; - ppfd->cRedShift = pf->color.redshift; - ppfd->cGreenBits = pf->color.greenbits; - ppfd->cGreenShift = pf->color.greenshift; - ppfd->cBlueBits = pf->color.bluebits; - ppfd->cBlueShift = pf->color.blueshift; - ppfd->cAlphaBits = pf->alpha.alphabits; - ppfd->cAlphaShift = pf->alpha.alphashift; - ppfd->cAccumBits = 0; - ppfd->cAccumRedBits = 0; - ppfd->cAccumGreenBits = 0; - ppfd->cAccumBlueBits = 0; - ppfd->cAccumAlphaBits = 0; - ppfd->cDepthBits = pf->depth.depthbits; - ppfd->cStencilBits = pf->depth.stencilbits; - ppfd->cAuxBuffers = 0; - ppfd->iLayerType = 0; - ppfd->bReserved = 0; - ppfd->dwLayerMask = 0; - ppfd->dwVisibleMask = 0; - ppfd->dwDamageMask = 0; + pfi = stw_pixelformat_get_info( index ); + + memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR )); return count; } @@ -203,29 +300,30 @@ int stw_pixelformat_choose( HDC hdc, (void) hdc; - count = pixelformat_get_count(); + count = stw_pixelformat_get_count(); bestindex = count; - bestdelta = 0xffffffff; + bestdelta = ~0U; for (index = 0; index < count; index++) { uint delta = 0; - const struct pixelformat_info *pf = pixelformat_get_info( index ); + const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index ); if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && !!(ppfd->dwFlags & PFD_DOUBLEBUFFER) != - !!(pf->flags & PF_FLAG_DOUBLEBUFFER)) + !!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) continue; - if (ppfd->cColorBits != pf->color.redbits + pf->color.greenbits + pf->color.bluebits) + /* FIXME: Take in account individual channel bits */ + if (ppfd->cColorBits != pfi->pfd.cColorBits) delta += 8; - if (ppfd->cDepthBits != pf->depth.depthbits) + if (ppfd->cDepthBits != pfi->pfd.cDepthBits) delta += 4; - if (ppfd->cStencilBits != pf->depth.stencilbits) + if (ppfd->cStencilBits != pfi->pfd.cStencilBits) delta += 2; - if (ppfd->cAlphaBits != pf->alpha.alphabits) + if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits) delta++; if (delta < bestdelta) { @@ -262,7 +360,7 @@ stw_pixelformat_set( (void) hdc; index = (uint) iPixelFormat - 1; - count = pixelformat_get_extended_count(); + count = stw_pixelformat_get_extended_count(); if (index >= count) return FALSE; @@ -277,21 +375,3 @@ stw_pixelformat_set( return TRUE; } - - - -/* XXX: this needs to be turned into queries on pipe_screen or - * stw_winsys. - */ -int -stw_query_sample_buffers( void ) -{ - return 1; -} - -int -stw_query_samples( void ) -{ - return 4; -} - diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h index 7ca4194a2ae..34522ebef38 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h @@ -25,59 +25,36 @@ * **************************************************************************/ -#ifndef PIXELFORMAT_H -#define PIXELFORMAT_H +#ifndef STW_PIXELFORMAT_H +#define STW_PIXELFORMAT_H #include <windows.h> -#include "pipe/p_compiler.h" - -#define PF_FLAG_DOUBLEBUFFER 0x00000001 -#define PF_FLAG_MULTISAMPLED 0x00000002 - -struct pixelformat_color_info -{ - uint redbits; - uint redshift; - uint greenbits; - uint greenshift; - uint bluebits; - uint blueshift; -}; - -struct pixelformat_alpha_info -{ - uint alphabits; - uint alphashift; -}; -struct pixelformat_depth_info -{ - uint depthbits; - uint stencilbits; -}; +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" -struct pixelformat_info +struct stw_pixelformat_info { - uint flags; - struct pixelformat_color_info color; - struct pixelformat_alpha_info alpha; - struct pixelformat_depth_info depth; + enum pipe_format color_format; + enum pipe_format depth_stencil_format; + + PIXELFORMATDESCRIPTOR pfd; + + unsigned numSampleBuffers; + unsigned numSamples; }; void -pixelformat_init( void ); +stw_pixelformat_init( void ); uint -pixelformat_get_count( void ); +stw_pixelformat_get_count( void ); uint -pixelformat_get_extended_count( void ); - -const struct pixelformat_info * -pixelformat_get_info( uint index ); +stw_pixelformat_get_extended_count( void ); -int stw_query_sample_buffers( void ); -int stw_query_samples( void ); +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ); -#endif /* PIXELFORMAT_H */ +#endif /* STW_PIXELFORMAT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_quirks.c b/src/gallium/state_trackers/wgl/shared/stw_quirks.c deleted file mode 100644 index 2f7091a52c0..00000000000 --- a/src/gallium/state_trackers/wgl/shared/stw_quirks.c +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * - * This is hopefully a temporary hack to define some needed dispatch - * table entries. Hopefully, I'll find a better solution. The - * dispatch table generation scripts ought to be making these dummy - * stubs as well. - */ - -void gl_dispatch_stub_543(void){} -void gl_dispatch_stub_544(void){} -void gl_dispatch_stub_545(void){} -void gl_dispatch_stub_546(void){} -void gl_dispatch_stub_547(void){} -void gl_dispatch_stub_548(void){} -void gl_dispatch_stub_549(void){} -void gl_dispatch_stub_550(void){} -void gl_dispatch_stub_551(void){} -void gl_dispatch_stub_552(void){} -void gl_dispatch_stub_553(void){} -void gl_dispatch_stub_554(void){} -void gl_dispatch_stub_555(void){} -void gl_dispatch_stub_556(void){} -void gl_dispatch_stub_557(void){} -void gl_dispatch_stub_558(void){} -void gl_dispatch_stub_559(void){} -void gl_dispatch_stub_560(void){} -void gl_dispatch_stub_561(void){} -void gl_dispatch_stub_565(void){} -void gl_dispatch_stub_566(void){} -void gl_dispatch_stub_570(void){} -void gl_dispatch_stub_577(void){} -void gl_dispatch_stub_578(void){} -void gl_dispatch_stub_582(void){} -void gl_dispatch_stub_603(void){} -void gl_dispatch_stub_607(void){} -void gl_dispatch_stub_645(void){} -void gl_dispatch_stub_646(void){} -void gl_dispatch_stub_647(void){} -void gl_dispatch_stub_648(void){} -void gl_dispatch_stub_649(void){} -void gl_dispatch_stub_650(void){} -void gl_dispatch_stub_651(void){} -void gl_dispatch_stub_652(void){} -void gl_dispatch_stub_653(void){} -void gl_dispatch_stub_657(void){} -void gl_dispatch_stub_733(void){} -void gl_dispatch_stub_734(void){} -void gl_dispatch_stub_735(void){} -void gl_dispatch_stub_736(void){} -void gl_dispatch_stub_737(void){} -void gl_dispatch_stub_738(void){} -void gl_dispatch_stub_744(void){} -void gl_dispatch_stub_745(void){} -void gl_dispatch_stub_746(void){} -void gl_dispatch_stub_760(void){} -void gl_dispatch_stub_761(void){} -void gl_dispatch_stub_763(void){} -void gl_dispatch_stub_764(void){} -void gl_dispatch_stub_765(void){} -void gl_dispatch_stub_766(void){} -void gl_dispatch_stub_767(void){} -void gl_dispatch_stub_768(void){} - -void gl_dispatch_stub_562(void){} -void gl_dispatch_stub_563(void){} -void gl_dispatch_stub_564(void){} -void gl_dispatch_stub_567(void){} -void gl_dispatch_stub_568(void){} -void gl_dispatch_stub_569(void){} -void gl_dispatch_stub_580(void){} -void gl_dispatch_stub_581(void){} -void gl_dispatch_stub_606(void){} -void gl_dispatch_stub_654(void){} -void gl_dispatch_stub_655(void){} -void gl_dispatch_stub_656(void){} -void gl_dispatch_stub_739(void){} -void gl_dispatch_stub_740(void){} -void gl_dispatch_stub_741(void){} -void gl_dispatch_stub_748(void){} -void gl_dispatch_stub_749(void){} -void gl_dispatch_stub_769(void){} -void gl_dispatch_stub_770(void){} -void gl_dispatch_stub_771(void){} -void gl_dispatch_stub_772(void){} -void gl_dispatch_stub_773(void){} -void gl_dispatch_stub_774(void){} -void gl_dispatch_stub_750(void){} -void gl_dispatch_stub_742(void){} diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h index 23b61e68ff5..f5a6bdf4b1a 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_tls.h +++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h @@ -28,11 +28,14 @@ #ifndef STW_TLS_H #define STW_TLS_H +#include <windows.h> + struct stw_tls_data { uint currentPixelFormat; HDC currentDC; UINT_PTR currentGLRC; + HHOOK hCallWndProcHook; }; boolean diff --git a/src/gallium/state_trackers/wgl/shared/stw_winsys.h b/src/gallium/state_trackers/wgl/shared/stw_winsys.h index e4a1d4f979f..c0bf82c9ed7 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_winsys.h +++ b/src/gallium/state_trackers/wgl/shared/stw_winsys.h @@ -51,15 +51,15 @@ struct stw_winsys }; boolean -st_init(const struct stw_winsys *stw_winsys); +stw_init(const struct stw_winsys *stw_winsys); boolean -st_init_thread(void); +stw_init_thread(void); void -st_cleanup_thread(void); +stw_cleanup_thread(void); void -st_cleanup(void); +stw_cleanup(void); #endif /* STW_WINSYS_H */ diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys_softpipe.c b/src/gallium/winsys/drm/radeon/core/radeon_winsys_softpipe.c index 33f9ac15ab1..f038bfa40ef 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys_softpipe.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_winsys_softpipe.c @@ -31,42 +31,11 @@ #include "radeon_winsys_softpipe.h" -struct radeon_softpipe_winsys { - struct softpipe_winsys sp_winsys; - struct radeon_context *radeon_context; -}; - -/** - * Return list of surface formats supported by this driver. - */ -static boolean radeon_is_format_supported(struct softpipe_winsys *sws, - uint format) -{ - switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: - return TRUE; - default: - break; - } - return FALSE; -} - struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys) { - struct softpipe_winsys *sp_winsys; struct pipe_screen *pipe_screen; pipe_screen = softpipe_create_screen(winsys); - sp_winsys = CALLOC_STRUCT(softpipe_winsys); - if (sp_winsys == NULL) { - return NULL; - } - - sp_winsys->is_format_supported = radeon_is_format_supported; - return softpipe_create(pipe_screen, - winsys, - sp_winsys); + return softpipe_create(pipe_screen); } diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c index 9ceb67d2ac7..b52f427e4a7 100644 --- a/src/gallium/winsys/egl_xlib/egl_xlib.c +++ b/src/gallium/winsys/egl_xlib/egl_xlib.c @@ -359,7 +359,7 @@ xlib_eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, /* fall-through */ case EGL_OPENGL_API: /* create a softpipe context */ - ctx->pipe = softpipe_create(xdrv->screen, xdrv->winsys, NULL); + ctx->pipe = softpipe_create(xdrv->screen); /* Now do xlib / state tracker inits here */ _eglConfigToContextModesRec(conf, &visual); ctx->Context = st_create_context(ctx->pipe, &visual, share_ctx); @@ -388,6 +388,7 @@ xlib_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) /* API-dependent clean-up */ switch (context->Base.ClientAPI) { case EGL_OPENGL_ES_API: + case EGL_OPENVG_API: /* fall-through */ case EGL_OPENGL_API: st_destroy_context(context->Context); diff --git a/src/gallium/winsys/g3dvl/xsp_winsys.c b/src/gallium/winsys/g3dvl/xsp_winsys.c index 5b9fdb5c1f8..698c2856a4f 100644 --- a/src/gallium/winsys/g3dvl/xsp_winsys.c +++ b/src/gallium/winsys/g3dvl/xsp_winsys.c @@ -261,7 +261,7 @@ struct pipe_context* create_pipe_context(Display *display, int screen) } sp_screen = softpipe_create_screen((struct pipe_winsys*)xsp_winsys); - sp_pipe = softpipe_create(sp_screen, (struct pipe_winsys*)xsp_winsys, NULL); + sp_pipe = softpipe_create(sp_screen); xsp_context = calloc(1, sizeof(struct xsp_context)); xsp_context->display = display; diff --git a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c index d5d9431865c..33826524d7a 100644 --- a/src/gallium/winsys/gdi/gdi_softpipe_winsys.c +++ b/src/gallium/winsys/gdi/gdi_softpipe_winsys.c @@ -263,7 +263,7 @@ gdi_softpipe_screen_create(void) static struct pipe_context * gdi_softpipe_context_create(struct pipe_screen *screen) { - return softpipe_create(screen, screen->winsys, NULL); + return softpipe_create(screen); } @@ -312,21 +312,21 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: - if (!st_init(&stw_winsys)) { + if (!stw_init(&stw_winsys)) { return FALSE; } - return st_init_thread(); + return stw_init_thread(); case DLL_THREAD_ATTACH: - return st_init_thread(); + return stw_init_thread(); case DLL_THREAD_DETACH: - st_cleanup_thread(); + stw_cleanup_thread(); break; case DLL_PROCESS_DETACH: - st_cleanup_thread(); - st_cleanup(); + stw_cleanup_thread(); + stw_cleanup(); break; } return TRUE; diff --git a/src/gallium/winsys/xlib/xlib_softpipe.c b/src/gallium/winsys/xlib/xlib_softpipe.c index 762ebd98477..44b8464518a 100644 --- a/src/gallium/winsys/xlib/xlib_softpipe.c +++ b/src/gallium/winsys/xlib/xlib_softpipe.c @@ -482,7 +482,7 @@ xlib_create_softpipe_context( struct pipe_screen *screen, { struct pipe_context *pipe; - pipe = softpipe_create(screen, screen->winsys, NULL); + pipe = softpipe_create(screen); if (pipe == NULL) goto fail; diff --git a/src/gallium/winsys/xlib/xlib_trace.c b/src/gallium/winsys/xlib/xlib_trace.c index 37095c5d8ec..dbea655ab45 100644 --- a/src/gallium/winsys/xlib/xlib_trace.c +++ b/src/gallium/winsys/xlib/xlib_trace.c @@ -37,6 +37,7 @@ #include "trace/tr_screen.h" #include "trace/tr_context.h" +#include "trace/tr_texture.h" #include "pipe/p_screen.h" @@ -66,9 +67,11 @@ fail: } static struct pipe_context * -xlib_create_trace_context( struct pipe_screen *screen, +xlib_create_trace_context( struct pipe_screen *_screen, void *priv ) { + struct trace_screen *tr_scr = trace_screen( _screen ); + struct pipe_screen *screen = tr_scr->screen; struct pipe_context *pipe, *trace_pipe; pipe = xlib_softpipe_driver.create_pipe_context( screen, priv ); @@ -77,7 +80,7 @@ xlib_create_trace_context( struct pipe_screen *screen, /* Wrap it: */ - trace_pipe = trace_context_create(screen, pipe); + trace_pipe = trace_context_create(_screen, pipe); if (trace_pipe == NULL) goto fail; @@ -86,15 +89,18 @@ xlib_create_trace_context( struct pipe_screen *screen, return trace_pipe; fail: + if (pipe) + pipe->destroy( pipe ); return NULL; } static void xlib_trace_display_surface( struct xmesa_buffer *buffer, - struct pipe_surface *surf ) + struct pipe_surface *_surf ) { - /* ?? - */ + struct trace_surface *tr_surf = trace_surface( _surf ); + struct pipe_surface *surf = tr_surf->surface; + xlib_softpipe_driver.display_surface( buffer, surf ); } |