diff options
Diffstat (limited to 'src/gallium/auxiliary')
52 files changed, 4418 insertions, 386 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 0bc77a5728..e6dce3f0e5 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -361,6 +361,10 @@ void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type,  void cso_cache_delete(struct cso_cache *sc)  {     assert(sc); + +   if (!sc) +      return; +     /* delete driver data */     cso_for_each_state(sc, CSO_BLEND, delete_blend_state, 0);     cso_for_each_state(sc, CSO_DEPTH_STENCIL_ALPHA, delete_depth_stencil_state, 0); diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index f388bf5d95..36c882acb7 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -55,14 +55,14 @@ struct cso_context {     void *samplers[PIPE_MAX_SAMPLERS];     unsigned nr_samplers; -   void *samplers_saved[PIPE_MAX_SAMPLERS];     unsigned nr_samplers_saved; +   void *samplers_saved[PIPE_MAX_SAMPLERS];     struct pipe_texture *textures[PIPE_MAX_SAMPLERS];     uint nr_textures; -   struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS];     uint nr_textures_saved; +   struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS];     /** Current and saved state.      * The saved state is used as a 1-deep stack. diff --git a/src/gallium/auxiliary/draw/draw_pipe.c b/src/gallium/auxiliary/draw/draw_pipe.c index 3cde9d36d3..2e3f5b2fc0 100644 --- a/src/gallium/auxiliary/draw/draw_pipe.c +++ b/src/gallium/auxiliary/draw/draw_pipe.c @@ -216,22 +216,22 @@ void draw_pipeline_run( struct draw_context *draw,                  ( DRAW_PIPE_RESET_STIPPLE |                      \                    DRAW_PIPE_EDGE_FLAG_0 |                        \                    DRAW_PIPE_EDGE_FLAG_2 ),                       \ -                 verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK), \ -                 verts + stride * (i1),                          \ +                verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK),  \ +                verts + stride * (i1),                           \                  verts + stride * (i3));                          \ -      do_triangle( draw,                                         \ -                   ( DRAW_PIPE_EDGE_FLAG_0 |                     \ -                     DRAW_PIPE_EDGE_FLAG_1 ),                    \ -                 verts + stride * ((i1) & ~DRAW_PIPE_FLAG_MASK), \ -                 verts + stride * (i2),                          \ -                 verts + stride * (i3)) +   do_triangle( draw,                                            \ +                ( DRAW_PIPE_EDGE_FLAG_0 |                        \ +                  DRAW_PIPE_EDGE_FLAG_1 ),                       \ +                verts + stride * ((i1) & ~DRAW_PIPE_FLAG_MASK),  \ +                verts + stride * (i2),                           \ +                verts + stride * (i3))  #define TRIANGLE(flags,i0,i1,i2)                                 \     do_triangle( draw,                                            \                  flags,  /* flags */                              \ -                 verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK), \ -                 verts + stride * (i1),                          \ -                 verts + stride * (i2)) +                verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK),  \ +                verts + stride * (i1),                           \ +                verts + stride * (i2))  #define LINE(flags,i0,i1)                                   \     do_line( draw,                                           \ diff --git a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c index a5d840b96e..1a5269c0de 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c +++ b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c @@ -159,8 +159,19 @@ vbuf_tri( struct draw_stage *stage,     check_space( vbuf, 3 ); -   for (i = 0; i < 3; i++) { -      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] ); +   if (vbuf->stage.draw->rasterizer->flatshade_first) { +      /* Put provoking vertex in position expected by the driver. +       * Emit last provoking vertex in first pos. +       * Swap verts 0 & 1 to preserve polygon winding. +       */ +      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[2] ); +      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[0] ); +      vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[1] ); +   } +   else { +      for (i = 0; i < 3; i++) { +         vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] ); +      }     }  } diff --git a/src/gallium/auxiliary/draw/draw_pipe_wide_point.c b/src/gallium/auxiliary/draw/draw_pipe_wide_point.c index d84bab9eaa..014d8c7346 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_wide_point.c +++ b/src/gallium/auxiliary/draw/draw_pipe_wide_point.c @@ -181,6 +181,16 @@ static void widepoint_point( struct draw_stage *stage,  } +static int +find_fog_input_attrib(struct draw_context *draw) +{ +   /* Scan the fragment program's input decls to find the fogcoord +    * attribute.  The z/w components will store the point coord. +    */ +   return 0; /* XXX fix this */ +} + +  static void widepoint_first_point( struct draw_stage *stage,   			      struct prim_header *header )  { @@ -220,7 +230,7 @@ static void widepoint_first_point( struct draw_stage *stage,        wide->num_texcoords = j;        /* find fragment shader PointCoord/Fog input */ -      wide->point_coord_fs_input = 0; /* XXX fix this! */ +      wide->point_coord_fs_input = find_fog_input_attrib(draw);        /* setup extra vp output (point coord implemented as a texcoord) */        draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC; diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h index 81e4eae401..41fcb16a0a 100644 --- a/src/gallium/auxiliary/draw/draw_private.h +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -44,7 +44,6 @@  #include "pipe/p_state.h"  #include "pipe/p_defines.h" -#include "tgsi/tgsi_exec.h"  #include "tgsi/tgsi_scan.h" @@ -55,6 +54,8 @@ struct draw_vertex_shader;  struct draw_context;  struct draw_stage;  struct vbuf_render; +struct tgsi_exec_machine; +struct tgsi_sampler;  /** @@ -185,7 +186,7 @@ struct draw_context        uint position_output;        /** TGSI program interpreter runtime state */ -      struct tgsi_exec_machine machine; +      struct tgsi_exec_machine *machine;        uint num_samplers;        struct tgsi_sampler **samplers; diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c index 9ea0cbe599..dbb5ac7182 100644 --- a/src/gallium/auxiliary/draw/draw_pt.c +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -36,6 +36,7 @@  #include "draw/draw_vs.h"  #include "tgsi/tgsi_dump.h"  #include "util/u_math.h" +#include "util/u_prim.h"  static unsigned trim( unsigned count, unsigned first, unsigned incr )  { @@ -278,7 +279,7 @@ void  draw_arrays(struct draw_context *draw, unsigned prim,              unsigned start, unsigned count)  { -   unsigned reduced_prim = draw_pt_reduced_prim(prim); +   unsigned reduced_prim = u_reduced_prim(prim);     if (reduced_prim != draw->reduced_prim) {        draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE );        draw->reduced_prim = reduced_prim; diff --git a/src/gallium/auxiliary/draw/draw_pt.h b/src/gallium/auxiliary/draw/draw_pt.h index 8ef0ea8011..7a17a9fb6b 100644 --- a/src/gallium/auxiliary/draw/draw_pt.h +++ b/src/gallium/auxiliary/draw/draw_pt.h @@ -228,7 +228,6 @@ void draw_pt_post_vs_destroy( struct pt_post_vs *pvs );   * Utils:    */  void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr); -unsigned draw_pt_reduced_prim(unsigned prim);  #endif diff --git a/src/gallium/auxiliary/draw/draw_pt_decompose.h b/src/gallium/auxiliary/draw/draw_pt_decompose.h index 3fb0695687..4ca5b52020 100644 --- a/src/gallium/auxiliary/draw/draw_pt_decompose.h +++ b/src/gallium/auxiliary/draw/draw_pt_decompose.h @@ -47,10 +47,19 @@ static void FUNC( ARGS,     case PIPE_PRIM_TRIANGLES:        for (i = 0; i+2 < count; i += 3) { -         TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, -                   (i + 0), -                   (i + 1), -                   (i + 2 )); +         if (flatfirst) { +            /* put provoking vertex in last pos for clipper */ +            TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, +                      (i + 1), +                      (i + 2), +                      (i + 0 )); +         } +         else { +            TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, +                      (i + 0), +                      (i + 1), +                      (i + 2 )); +         }        }        break; @@ -58,9 +67,9 @@ static void FUNC( ARGS,        if (flatfirst) {           for (i = 0; i+2 < count; i++) {              TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, -                      (i + 0),                        (i + 1 + (i&1)), -                      (i + 2 - (i&1))); +                      (i + 2 - (i&1)), +                      (i + 0) );           }        }        else { @@ -78,9 +87,9 @@ static void FUNC( ARGS,           if (flatfirst) {              for (i = 0; i+2 < count; i++) {                 TRIANGLE( DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, -                         (i + 1),                           (i + 2), -                         (0 )); +                         0, +                         (i + 1) );              }           }           else { @@ -96,20 +105,40 @@ static void FUNC( ARGS,     case PIPE_PRIM_QUADS: -      for (i = 0; i+3 < count; i += 4) { -         QUAD( (i + 0), -               (i + 1), -               (i + 2), -               (i + 3)); +      if (flatfirst) { +         for (i = 0; i+3 < count; i += 4) { +            QUAD( (i + 1), +                  (i + 2), +                  (i + 3), +                  (i + 0) ); +         } +      } +      else { +         for (i = 0; i+3 < count; i += 4) { +            QUAD( (i + 0), +                  (i + 1), +                  (i + 2), +                  (i + 3)); +         }        }        break;     case PIPE_PRIM_QUAD_STRIP: -      for (i = 0; i+3 < count; i += 2) { -         QUAD( (i + 2), -               (i + 0), -               (i + 1), -               (i + 3)); +      if (flatfirst) { +         for (i = 0; i+3 < count; i += 2) { +            QUAD( (i + 1), +                  (i + 3), +                  (i + 2), +                  (i + 0) ); +         } +      } +      else { +         for (i = 0; i+3 < count; i += 2) { +            QUAD( (i + 2), +                  (i + 0), +                  (i + 1), +                  (i + 3)); +         }        }        break; diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c index 6b7d02a19b..e7fe6b3b76 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c @@ -130,6 +130,10 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,        unsigned output_format;        switch (vinfo->attrib[i].emit) { +      case EMIT_4UB: +	 output_format = PIPE_FORMAT_R8G8B8A8_UNORM; +	 emit_sz = 4 * sizeof(unsigned char); +         break;        case EMIT_4F:  	 output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;  	 emit_sz = 4 * sizeof(float); @@ -153,6 +157,8 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,  	 output_format = PIPE_FORMAT_R32_FLOAT;  	 emit_sz = 1 * sizeof(float);           break; +      case EMIT_OMIT: +         continue;        default:           assert(0);  	 output_format = PIPE_FORMAT_NONE; diff --git a/src/gallium/auxiliary/draw/draw_pt_util.c b/src/gallium/auxiliary/draw/draw_pt_util.c index 3bc7939c55..b61fa29143 100644 --- a/src/gallium/auxiliary/draw/draw_pt_util.c +++ b/src/gallium/auxiliary/draw/draw_pt_util.c @@ -75,28 +75,3 @@ void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr)        break;     }  } - - -unsigned draw_pt_reduced_prim(unsigned prim) -{ -   switch (prim) { -   case PIPE_PRIM_POINTS: -      return PIPE_PRIM_POINTS; -   case PIPE_PRIM_LINES: -   case PIPE_PRIM_LINE_STRIP: -   case PIPE_PRIM_LINE_LOOP: -      return PIPE_PRIM_LINES; -   case PIPE_PRIM_TRIANGLES: -   case PIPE_PRIM_TRIANGLE_STRIP: -   case PIPE_PRIM_TRIANGLE_FAN: -   case PIPE_PRIM_POLYGON: -   case PIPE_PRIM_QUADS: -   case PIPE_PRIM_QUAD_STRIP: -      return PIPE_PRIM_TRIANGLES; -   default: -      assert(0); -      return PIPE_PRIM_POINTS; -   } -} - - diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c index 5d268a2226..1a0527be63 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache.c +++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c @@ -31,6 +31,7 @@    */  #include "util/u_memory.h" +#include "util/u_prim.h"  #include "draw/draw_context.h"  #include "draw/draw_private.h"  #include "draw/draw_pt.h" @@ -193,16 +194,30 @@ vcache_ef_quad( struct vcache_frontend *vcache,                  unsigned i2,                  unsigned i3 )  { -   vcache_triangle_flags( vcache, -                          ( DRAW_PIPE_RESET_STIPPLE | -                            DRAW_PIPE_EDGE_FLAG_0 | -                            DRAW_PIPE_EDGE_FLAG_2 ), -                          i0, i1, i3 ); +   if (vcache->draw->rasterizer->flatshade_first) { +      vcache_triangle_flags( vcache, +                             ( DRAW_PIPE_RESET_STIPPLE | +                               DRAW_PIPE_EDGE_FLAG_0 | +                               DRAW_PIPE_EDGE_FLAG_1 ), +                             i0, i1, i2 ); -   vcache_triangle_flags( vcache, -                          ( DRAW_PIPE_EDGE_FLAG_0 | -                            DRAW_PIPE_EDGE_FLAG_1 ), -                          i1, i2, i3 ); +      vcache_triangle_flags( vcache, +                             ( DRAW_PIPE_EDGE_FLAG_2 | +                               DRAW_PIPE_EDGE_FLAG_1 ), +                             i0, i2, i3 ); +   } +   else { +      vcache_triangle_flags( vcache, +                             ( DRAW_PIPE_RESET_STIPPLE | +                               DRAW_PIPE_EDGE_FLAG_0 | +                               DRAW_PIPE_EDGE_FLAG_2 ), +                             i0, i1, i3 ); + +      vcache_triangle_flags( vcache, +                             ( DRAW_PIPE_EDGE_FLAG_0 | +                               DRAW_PIPE_EDGE_FLAG_1 ), +                             i1, i2, i3 ); +   }  }  /* At least for now, we're back to using a template include file for @@ -453,7 +468,7 @@ vcache_prepare( struct draw_pt_front_end *frontend,     }     vcache->input_prim = prim; -   vcache->output_prim = draw_pt_reduced_prim(prim); +   vcache->output_prim = u_reduced_prim(prim);     vcache->middle = middle;     vcache->opt = opt; diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h index ec05bbeab4..62822a3d56 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h @@ -118,21 +118,39 @@ static void FUNC( struct draw_pt_front_end *frontend,     case PIPE_PRIM_QUADS:        for (i = 0; i+3 < count; i += 4) { -         QUAD( vcache, -               get_elt(elts, i + 0), -               get_elt(elts, i + 1), -               get_elt(elts, i + 2), -               get_elt(elts, i + 3)); +         if (flatfirst) { +            QUAD( vcache, +                  get_elt(elts, i + 0), +                  get_elt(elts, i + 1), +                  get_elt(elts, i + 2), +                  get_elt(elts, i + 3) ); +         } +         else { +            QUAD( vcache, +                  get_elt(elts, i + 0), +                  get_elt(elts, i + 1), +                  get_elt(elts, i + 2), +                  get_elt(elts, i + 3) ); +         }        }        break;     case PIPE_PRIM_QUAD_STRIP:        for (i = 0; i+3 < count; i += 2) { -         QUAD( vcache, -               get_elt(elts, i + 2), -               get_elt(elts, i + 0), -               get_elt(elts, i + 1), -               get_elt(elts, i + 3)); +         if (flatfirst) { +            QUAD( vcache, +                  get_elt(elts, i + 0), +                  get_elt(elts, i + 1), +                  get_elt(elts, i + 3), +                  get_elt(elts, i + 2) ); +         } +         else { +            QUAD( vcache, +                  get_elt(elts, i + 2), +                  get_elt(elts, i + 0), +                  get_elt(elts, i + 1), +                  get_elt(elts, i + 3) ); +         }        }        break; @@ -144,19 +162,38 @@ static void FUNC( struct draw_pt_front_end *frontend,           const ushort edge_first  = DRAW_PIPE_EDGE_FLAG_2;           const ushort edge_middle = DRAW_PIPE_EDGE_FLAG_0;           const ushort edge_last   = DRAW_PIPE_EDGE_FLAG_1; +         ushort edge_next, edge_finish; -         flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle; +         if (flatfirst) { +            flags = DRAW_PIPE_RESET_STIPPLE | edge_middle | edge_last; +            edge_next = edge_last; +            edge_finish = edge_first; +         } +         else { +            flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle; +            edge_next = edge_middle; +            edge_finish = edge_last; +         } -	 for (i = 0; i+2 < count; i++, flags = edge_middle) { +	 for (i = 0; i+2 < count; i++, flags = edge_next) {              if (i + 3 == count) -               flags |= edge_last; +               flags |= edge_finish; -	    TRIANGLE( vcache, -                      flags, -                      get_elt(elts, i + 1), -                      get_elt(elts, i + 2), -                      get_elt(elts, 0)); +            if (flatfirst) { +               TRIANGLE( vcache, +                         flags, +                         get_elt(elts, 0), +                         get_elt(elts, i + 1), +                         get_elt(elts, i + 2) ); +            } +            else { +               TRIANGLE( vcache, +                         flags, +                         get_elt(elts, i + 1), +                         get_elt(elts, i + 2), +                         get_elt(elts, 0)); +            }  	 }        }        break; diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c index c057cd67fd..790e89ed82 100644 --- a/src/gallium/auxiliary/draw/draw_vs.c +++ b/src/gallium/auxiliary/draw/draw_vs.c @@ -43,6 +43,8 @@  #include "translate/translate.h"  #include "translate/translate_cache.h" +#include "tgsi/tgsi_exec.h" + @@ -146,16 +148,8 @@ draw_delete_vertex_shader(struct draw_context *draw,  boolean   draw_vs_init( struct draw_context *draw )  { -   tgsi_exec_machine_init(&draw->vs.machine); - -   /* FIXME: give this machine thing a proper constructor: -    */ -   draw->vs.machine.Inputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16); -   if (!draw->vs.machine.Inputs) -      return FALSE; - -   draw->vs.machine.Outputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16); -   if (!draw->vs.machine.Outputs) +   draw->vs.machine = tgsi_exec_machine_create(); +   if (!draw->vs.machine)        return FALSE;     draw->vs.emit_cache = translate_cache_create(); @@ -178,12 +172,6 @@ draw_vs_init( struct draw_context *draw )  void  draw_vs_destroy( struct draw_context *draw )  { -   if (draw->vs.machine.Inputs) -      align_free(draw->vs.machine.Inputs); - -   if (draw->vs.machine.Outputs) -      align_free(draw->vs.machine.Outputs); -     if (draw->vs.fetch_cache)        translate_cache_destroy(draw->vs.fetch_cache); @@ -196,8 +184,7 @@ draw_vs_destroy( struct draw_context *draw )     if (draw->vs.aligned_constant_storage)        align_free((void*)draw->vs.aligned_constant_storage); -   tgsi_exec_machine_free_data(&draw->vs.machine); - +   tgsi_exec_machine_destroy(draw->vs.machine);  } diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c index dbbc33fffa..41cc802613 100644 --- a/src/gallium/auxiliary/draw/draw_vs_exec.c +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -41,6 +41,7 @@  #include "tgsi/tgsi_parse.h"  #include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_exec.h"  struct exec_vertex_shader { @@ -114,6 +115,12 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,  #endif           for (slot = 0; slot < shader->info.num_inputs; slot++) { +#if 0 +            assert(!util_is_inf_or_nan(input[slot][0])); +            assert(!util_is_inf_or_nan(input[slot][1])); +            assert(!util_is_inf_or_nan(input[slot][2])); +            assert(!util_is_inf_or_nan(input[slot][3])); +#endif              machine->Inputs[slot].xyzw[0].f[j] = input[slot][0];              machine->Inputs[slot].xyzw[1].f[j] = input[slot][1];              machine->Inputs[slot].xyzw[2].f[j] = input[slot][2]; @@ -195,7 +202,7 @@ draw_create_vs_exec(struct draw_context *draw,     vs->base.run_linear = vs_exec_run_linear;     vs->base.delete = vs_exec_delete;     vs->base.create_varient = draw_vs_varient_generic; -   vs->machine = &draw->vs.machine; +   vs->machine = draw->vs.machine;     return &vs->base;  } diff --git a/src/gallium/auxiliary/draw/draw_vs_ppc.c b/src/gallium/auxiliary/draw/draw_vs_ppc.c index d35db57d57..ad184bd696 100644 --- a/src/gallium/auxiliary/draw/draw_vs_ppc.c +++ b/src/gallium/auxiliary/draw/draw_vs_ppc.c @@ -48,6 +48,7 @@  #include "rtasm/rtasm_ppc.h"  #include "tgsi/tgsi_ppc.h"  #include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_exec.h" diff --git a/src/gallium/auxiliary/draw/draw_vs_sse.c b/src/gallium/auxiliary/draw/draw_vs_sse.c index 77ba5152f9..fb58983e01 100644 --- a/src/gallium/auxiliary/draw/draw_vs_sse.c +++ b/src/gallium/auxiliary/draw/draw_vs_sse.c @@ -48,27 +48,16 @@  #include "rtasm/rtasm_x86sse.h"  #include "tgsi/tgsi_sse2.h"  #include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_exec.h"  #define SSE_MAX_VERTICES 4 -typedef void (PIPE_CDECL *codegen_function) ( -   const struct tgsi_exec_vector *input, /* 1 */ -   struct tgsi_exec_vector *output, /* 2 */ -   float (*constant)[4],        /* 3 */ -   struct tgsi_exec_vector *temporary, /* 4 */ -   float (*immediates)[4],      /* 5 */ -   const float (*aos_input)[4], /* 6 */ -   uint num_inputs,             /* 7 */ -   uint input_stride,           /* 8 */ -   float (*aos_output)[4],      /* 9 */ -   uint num_outputs,            /* 10 */ -   uint output_stride );        /* 11 */  struct draw_sse_vertex_shader {     struct draw_vertex_shader base;     struct x86_function sse2_program; -   codegen_function func; +   tgsi_sse2_vs_func func;     struct tgsi_exec_machine *machine;  }; @@ -118,11 +107,9 @@ vs_sse_run_linear( struct draw_vertex_shader *base,        /* run compiled shader         */ -      shader->func(machine->Inputs, -		   machine->Outputs, -		   (float (*)[4])constants, -		   machine->Temps, -		   (float (*)[4])shader->base.immediates, +      shader->func(machine, +		   constants, +		   shader->base.immediates,                     input,                     base->info.num_inputs,                     input_stride, @@ -184,7 +171,7 @@ draw_create_vs_sse(struct draw_context *draw,     vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 *                                        sizeof(float), 16); -   vs->machine = &draw->vs.machine; +   vs->machine = draw->vs.machine;     x86_init_func( &vs->sse2_program ); @@ -194,7 +181,7 @@ draw_create_vs_sse(struct draw_context *draw,                          TRUE ))         goto fail; -   vs->func = (codegen_function) x86_get_func( &vs->sse2_program ); +   vs->func = (tgsi_sse2_vs_func) x86_get_func( &vs->sse2_program );     if (!vs->func) {        goto fail;     } diff --git a/src/gallium/auxiliary/gallivm/instructionssoa.cpp b/src/gallium/auxiliary/gallivm/instructionssoa.cpp index 925e948763..2d2af3085e 100644 --- a/src/gallium/auxiliary/gallivm/instructionssoa.cpp +++ b/src/gallium/auxiliary/gallivm/instructionssoa.cpp @@ -24,6 +24,8 @@   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.   *   **************************************************************************/ + +#include <cstdio>  #include "instructionssoa.h"  #include "storagesoa.h" diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c index 0760d60716..6bdce5fcb0 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c @@ -53,6 +53,8 @@ static INLINE struct malloc_buffer *  malloc_buffer(struct pb_buffer *buf)  {     assert(buf); +   if (!buf) +      return NULL;     assert(buf->vtbl == &malloc_buffer_vtbl);     return (struct malloc_buffer *)buf;  } diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c index bc3093f620..cb32d25136 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c @@ -74,6 +74,8 @@ static INLINE struct pb_ondemand_buffer *  pb_ondemand_buffer(struct pb_buffer *buf)  {     assert(buf); +   if (!buf) +      return NULL;     assert(buf->vtbl == &pb_ondemand_buffer_vtbl);     return (struct pb_ondemand_buffer *)buf;  } diff --git a/src/gallium/auxiliary/rbug/Makefile b/src/gallium/auxiliary/rbug/Makefile new file mode 100644 index 0000000000..cd12e8468f --- /dev/null +++ b/src/gallium/auxiliary/rbug/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = rbug + +C_SOURCES = \ +	rbug_connection.c \ +	rbug_core.c \ +	rbug_texture.c \ +	rbug_context.c \ +	rbug_shader.c \ +	rbug_demarshal.c + +include ../../Makefile.template diff --git a/src/gallium/auxiliary/rbug/README b/src/gallium/auxiliary/rbug/README new file mode 100644 index 0000000000..33d76371de --- /dev/null +++ b/src/gallium/auxiliary/rbug/README @@ -0,0 +1,21 @@ +                 GALLIUM REMOTE DEBUGGING COMMON CODE + += About = + +This directory contains the common code for the Gallium 3D remote debugging +driver and clients. The code is two parts the connection managment code and +the (de)marsheller. + +The code currently uses tcp and ip4v for connections. + +Information about driver integration can be found in: + +src/gallium/drivers/trace/README + +for information about applications look in: + +progs/rbug/README + + +-- +Jakob Bornecrantz <jakob@vmware.com> diff --git a/src/gallium/auxiliary/rbug/SConscript b/src/gallium/auxiliary/rbug/SConscript new file mode 100644 index 0000000000..4a9afb45d3 --- /dev/null +++ b/src/gallium/auxiliary/rbug/SConscript @@ -0,0 +1,14 @@ +Import('*') + +rbug = env.ConvenienceLibrary( +	target = 'rbug', +	source = [ +		'rbug_core.c', +		'rbug_shader.c', +		'rbug_context.c', +		'rbug_texture.c', +		'rbug_demarshal.c', +		'rbug_connection.c', +	]) + +auxiliaries.insert(0, rbug) diff --git a/src/gallium/auxiliary/rbug/rbug.h b/src/gallium/auxiliary/rbug/rbug.h new file mode 100644 index 0000000000..259bfc6c79 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug.h @@ -0,0 +1,33 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * Include all for users the remote debugger protocol code. + */ + +#include "rbug/rbug_core.h" +#include "rbug/rbug_shader.h" +#include "rbug/rbug_context.h" +#include "rbug/rbug_texture.h" +#include "rbug/rbug_connection.h" diff --git a/src/gallium/auxiliary/rbug/rbug_connection.c b/src/gallium/auxiliary/rbug/rbug_connection.c new file mode 100644 index 0000000000..52acb700af --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_connection.c @@ -0,0 +1,167 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +#include "rbug/rbug.h" +#include "rbug/rbug_internal.h" + +#include "util/u_network.h" + +struct rbug_connection +{ +   int socket; +   uint32_t send_serial; +   uint32_t recv_serial; +   enum rbug_opcode opcode; +}; + +/** + * Create a rbug connection from a socket created with u_socket. + * + * Result: + *    A new allocated connection using socket as communication path + */ +struct rbug_connection * +rbug_from_socket(int socket) +{ +   struct rbug_connection *c = CALLOC_STRUCT(rbug_connection); +   c->socket = socket; +   return c; +} + +/** + * Free a connection, also closes socket. + */ +void +rbug_disconnect(struct rbug_connection *c) +{ +   u_socket_close(c->socket); +   FREE(c); +} + +/** + * Waits for a message to be fully received. + * Also returns the serial for the message, serial is not touched for replys. + * + * Result: + *    demarshaled message on success, NULL on connection error + */ +struct rbug_header * +rbug_get_message(struct rbug_connection *c, uint32_t *serial) +{ +   struct rbug_proto_header header; +   struct rbug_header *out; +   struct rbug_proto_header *data; +   size_t length = 0; +   size_t read = 0; +   int ret; + + +   ret = u_socket_peek(c->socket, &header, sizeof(header)); +   if (ret <= 0) { +      return NULL; +   } + +   length = (size_t)header.length * 4; +   data = MALLOC(length); +   if (!data) { +      return NULL; +   } + +   do { +      uint8_t *ptr = ((uint8_t*)data) + read; +      ret = u_socket_recv(c->socket, ptr, length - read); + +      if (ret <= 0) { +         FREE(data); +         return NULL; +      } + +      read += ret; +   } while(read < length); + +   out = rbug_demarshal(data); +   if (!out) +      FREE(data); +   else if (serial) +      *serial = c->recv_serial++; +   else +      c->recv_serial++; + +   return out; +} + +/** + * Frees a message and associated data. + */ +void +rbug_free_header(struct rbug_header *header) +{ +   if (!header) +      return; + +   FREE(header->__message); +   FREE(header); +} + +/** + * Internal function used by rbug_send_* functions. + * + * Start sending a message. + */ +int +rbug_connection_send_start(struct rbug_connection *c, enum rbug_opcode opcode, uint32_t length) +{ +   c->opcode = opcode; +   return 0; +} + +/** + * Internal function used by rbug_send_* functions. + * + * Write data to the socket. + */ +int +rbug_connection_write(struct rbug_connection *c, void *to, uint32_t size) +{ +   int ret = u_socket_send(c->socket, to, size); +   return ret; +} + +/** + * Internal function used by rbug_send_* functions. + * + * Finish writeing data to the socket. + * Ups the send_serial and sets the serial argument if supplied. + */ +int rbug_connection_send_finish(struct rbug_connection *c, uint32_t *serial) +{ +   if (c->opcode < 0) +      return 0; +   else if (serial) +      *serial = c->send_serial++; +   else +      c->send_serial++; + +   return 0; +} diff --git a/src/gallium/auxiliary/rbug/rbug_connection.h b/src/gallium/auxiliary/rbug/rbug_connection.h new file mode 100644 index 0000000000..1f2c9ff347 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_connection.h @@ -0,0 +1,45 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file contains the function defentions for connection see c file for + * more comments covering function use. + */ + +#ifndef _RBUG_CONNECTION_H_ +#define _RBUG_CONNECTION_H_ + +#include "rbug/rbug_proto.h" + +struct rbug_connection * rbug_from_socket(int socket); + +void rbug_disconnect(struct rbug_connection *c); + +struct rbug_header * rbug_get_message(struct rbug_connection *c, uint32_t *serial); + +void rbug_free_header(struct rbug_header *header); + +struct rbug_header * rbug_demarshal(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_context.c b/src/gallium/auxiliary/rbug/rbug_context.c new file mode 100644 index 0000000000..1832425658 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_context.c @@ -0,0 +1,759 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_context.h" + +int rbug_send_context_list(struct rbug_connection *__con, +                           uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_info(struct rbug_connection *__con, +                           rbug_context_t context, +                           uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_draw_block(struct rbug_connection *__con, +                                 rbug_context_t context, +                                 rbug_block_t block, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(4); /* block */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(4, rbug_block_t, block); /* block */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCK, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_draw_step(struct rbug_connection *__con, +                                rbug_context_t context, +                                rbug_block_t step, +                                uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(4); /* step */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_STEP)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(4, rbug_block_t, step); /* step */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_STEP, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_draw_unblock(struct rbug_connection *__con, +                                   rbug_context_t context, +                                   rbug_block_t unblock, +                                   uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(4); /* unblock */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(4, rbug_block_t, unblock); /* unblock */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_UNBLOCK, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_draw_rule(struct rbug_connection *__con, +                                rbug_context_t context, +                                rbug_shader_t vertex, +                                rbug_shader_t fragment, +                                rbug_texture_t texture, +                                rbug_texture_t surface, +                                rbug_block_t block, +                                uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(8); /* vertex */ +	LEN(8); /* fragment */ +	LEN(8); /* texture */ +	LEN(8); /* surface */ +	LEN(4); /* block */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_RULE)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(8, rbug_shader_t, vertex); /* vertex */ +	WRITE(8, rbug_shader_t, fragment); /* fragment */ +	WRITE(8, rbug_texture_t, texture); /* texture */ +	WRITE(8, rbug_texture_t, surface); /* surface */ +	WRITE(4, rbug_block_t, block); /* block */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_RULE, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_flush(struct rbug_connection *__con, +                            rbug_context_t context, +                            int32_t flags, +                            uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(4); /* flags */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_FLUSH)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(4, int32_t, flags); /* flags */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_FLUSH, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_list_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_context_t *contexts, +                                 uint32_t contexts_len, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN_ARRAY(8, contexts); /* contexts */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE_ARRAY(8, rbug_context_t, contexts); /* contexts */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_info_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_shader_t vertex, +                                 rbug_shader_t fragment, +                                 rbug_texture_t *texs, +                                 uint32_t texs_len, +                                 rbug_texture_t *cbufs, +                                 uint32_t cbufs_len, +                                 rbug_texture_t zsbuf, +                                 rbug_block_t blocker, +                                 rbug_block_t blocked, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN(8); /* vertex */ +	LEN(8); /* fragment */ +	LEN_ARRAY(8, texs); /* texs */ +	LEN_ARRAY(8, cbufs); /* cbufs */ +	LEN(8); /* zsbuf */ +	LEN(4); /* blocker */ +	LEN(4); /* blocked */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE(8, rbug_shader_t, vertex); /* vertex */ +	WRITE(8, rbug_shader_t, fragment); /* fragment */ +	WRITE_ARRAY(8, rbug_texture_t, texs); /* texs */ +	WRITE_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */ +	WRITE(8, rbug_texture_t, zsbuf); /* zsbuf */ +	WRITE(4, rbug_block_t, blocker); /* blocker */ +	WRITE(4, rbug_block_t, blocked); /* blocked */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_context_draw_blocked(struct rbug_connection *__con, +                                   rbug_context_t context, +                                   rbug_block_t block, +                                   uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(4); /* block */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(4, rbug_block_t, block); /* block */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCKED, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +struct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_list *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_LIST) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + + +	return ret; +} + +struct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_info *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_INFO) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ + +	return ret; +} + +struct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_draw_block *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_DRAW_BLOCK) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(4, rbug_block_t, block); /* block */ + +	return ret; +} + +struct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_draw_step *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_DRAW_STEP) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(4, rbug_block_t, step); /* step */ + +	return ret; +} + +struct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_draw_unblock *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(4, rbug_block_t, unblock); /* unblock */ + +	return ret; +} + +struct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_draw_rule *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_DRAW_RULE) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(8, rbug_shader_t, vertex); /* vertex */ +	READ(8, rbug_shader_t, fragment); /* fragment */ +	READ(8, rbug_texture_t, texture); /* texture */ +	READ(8, rbug_texture_t, surface); /* surface */ +	READ(4, rbug_block_t, block); /* block */ + +	return ret; +} + +struct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_flush *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_FLUSH) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(4, int32_t, flags); /* flags */ + +	return ret; +} + +struct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_list_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_LIST_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ_ARRAY(8, rbug_context_t, contexts); /* contexts */ + +	return ret; +} + +struct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_info_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_INFO_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ(8, rbug_shader_t, vertex); /* vertex */ +	READ(8, rbug_shader_t, fragment); /* fragment */ +	READ_ARRAY(8, rbug_texture_t, texs); /* texs */ +	READ_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */ +	READ(8, rbug_texture_t, zsbuf); /* zsbuf */ +	READ(4, rbug_block_t, blocker); /* blocker */ +	READ(4, rbug_block_t, blocked); /* blocked */ + +	return ret; +} + +struct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_context_draw_blocked *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_CONTEXT_DRAW_BLOCKED) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(4, rbug_block_t, block); /* block */ + +	return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_context.h b/src/gallium/auxiliary/rbug/rbug_context.h new file mode 100644 index 0000000000..da61c2365b --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_context.h @@ -0,0 +1,212 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_CONTEXT_H_ +#define _RBUG_PROTO_CONTEXT_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +typedef enum +{ +	RBUG_BLOCK_BEFORE = 1, +	RBUG_BLOCK_AFTER = 2, +	RBUG_BLOCK_RULE = 4, +	RBUG_BLOCK_MASK = 7, +} rbug_block_t; + +struct rbug_proto_context_list +{ +	struct rbug_header header; +}; + +struct rbug_proto_context_info +{ +	struct rbug_header header; +	rbug_context_t context; +}; + +struct rbug_proto_context_draw_block +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_block_t block; +}; + +struct rbug_proto_context_draw_step +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_block_t step; +}; + +struct rbug_proto_context_draw_unblock +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_block_t unblock; +}; + +struct rbug_proto_context_draw_rule +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_shader_t vertex; +	rbug_shader_t fragment; +	rbug_texture_t texture; +	rbug_texture_t surface; +	rbug_block_t block; +}; + +struct rbug_proto_context_flush +{ +	struct rbug_header header; +	rbug_context_t context; +	int32_t flags; +}; + +struct rbug_proto_context_list_reply +{ +	struct rbug_header header; +	uint32_t serial; +	rbug_context_t *contexts; +	uint32_t contexts_len; +}; + +struct rbug_proto_context_info_reply +{ +	struct rbug_header header; +	uint32_t serial; +	rbug_shader_t vertex; +	rbug_shader_t fragment; +	rbug_texture_t *texs; +	uint32_t texs_len; +	rbug_texture_t *cbufs; +	uint32_t cbufs_len; +	rbug_texture_t zsbuf; +	rbug_block_t blocker; +	rbug_block_t blocked; +}; + +struct rbug_proto_context_draw_blocked +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_block_t block; +}; + +int rbug_send_context_list(struct rbug_connection *__con, +                           uint32_t *__serial); + +int rbug_send_context_info(struct rbug_connection *__con, +                           rbug_context_t context, +                           uint32_t *__serial); + +int rbug_send_context_draw_block(struct rbug_connection *__con, +                                 rbug_context_t context, +                                 rbug_block_t block, +                                 uint32_t *__serial); + +int rbug_send_context_draw_step(struct rbug_connection *__con, +                                rbug_context_t context, +                                rbug_block_t step, +                                uint32_t *__serial); + +int rbug_send_context_draw_unblock(struct rbug_connection *__con, +                                   rbug_context_t context, +                                   rbug_block_t unblock, +                                   uint32_t *__serial); + +int rbug_send_context_draw_rule(struct rbug_connection *__con, +                                rbug_context_t context, +                                rbug_shader_t vertex, +                                rbug_shader_t fragment, +                                rbug_texture_t texture, +                                rbug_texture_t surface, +                                rbug_block_t block, +                                uint32_t *__serial); + +int rbug_send_context_flush(struct rbug_connection *__con, +                            rbug_context_t context, +                            int32_t flags, +                            uint32_t *__serial); + +int rbug_send_context_list_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_context_t *contexts, +                                 uint32_t contexts_len, +                                 uint32_t *__serial); + +int rbug_send_context_info_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_shader_t vertex, +                                 rbug_shader_t fragment, +                                 rbug_texture_t *texs, +                                 uint32_t texs_len, +                                 rbug_texture_t *cbufs, +                                 uint32_t cbufs_len, +                                 rbug_texture_t zsbuf, +                                 rbug_block_t blocker, +                                 rbug_block_t blocked, +                                 uint32_t *__serial); + +int rbug_send_context_draw_blocked(struct rbug_connection *__con, +                                   rbug_context_t context, +                                   rbug_block_t block, +                                   uint32_t *__serial); + +struct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header); + +struct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header); + +struct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header); + +struct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_core.c b/src/gallium/auxiliary/rbug/rbug_core.c new file mode 100644 index 0000000000..876ae5a0ce --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_core.c @@ -0,0 +1,359 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_core.h" + +int rbug_send_noop(struct rbug_connection *__con, +                   uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_NOOP)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_NOOP, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_ping(struct rbug_connection *__con, +                   uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_PING)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_PING, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_error(struct rbug_connection *__con, +                    uint32_t error, +                    uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* error */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, error); /* error */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_ERROR, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_ping_reply(struct rbug_connection *__con, +                         uint32_t serial, +                         uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_PING_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_PING_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_error_reply(struct rbug_connection *__con, +                          uint32_t serial, +                          uint32_t error, +                          uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN(4); /* error */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE(4, uint32_t, error); /* error */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_ERROR_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +struct rbug_proto_noop * rbug_demarshal_noop(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_noop *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_NOOP) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + + +	return ret; +} + +struct rbug_proto_ping * rbug_demarshal_ping(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_ping *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_PING) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + + +	return ret; +} + +struct rbug_proto_error * rbug_demarshal_error(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_error *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_ERROR) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, error); /* error */ + +	return ret; +} + +struct rbug_proto_ping_reply * rbug_demarshal_ping_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_ping_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_PING_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ + +	return ret; +} + +struct rbug_proto_error_reply * rbug_demarshal_error_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_error_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_ERROR_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ(4, uint32_t, error); /* error */ + +	return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_core.h b/src/gallium/auxiliary/rbug/rbug_core.h new file mode 100644 index 0000000000..99a36a0163 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_core.h @@ -0,0 +1,105 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_CORE_H_ +#define _RBUG_PROTO_CORE_H_ + +#include "rbug/rbug_proto.h" + +typedef uint64_t rbug_shader_t; +typedef uint64_t rbug_context_t; +typedef uint64_t rbug_texture_t; + +struct rbug_proto_noop +{ +	struct rbug_header header; +}; + +struct rbug_proto_ping +{ +	struct rbug_header header; +}; + +struct rbug_proto_error +{ +	struct rbug_header header; +	uint32_t error; +}; + +struct rbug_proto_ping_reply +{ +	struct rbug_header header; +	uint32_t serial; +}; + +struct rbug_proto_error_reply +{ +	struct rbug_header header; +	uint32_t serial; +	uint32_t error; +}; + +int rbug_send_noop(struct rbug_connection *__con, +                   uint32_t *__serial); + +int rbug_send_ping(struct rbug_connection *__con, +                   uint32_t *__serial); + +int rbug_send_error(struct rbug_connection *__con, +                    uint32_t error, +                    uint32_t *__serial); + +int rbug_send_ping_reply(struct rbug_connection *__con, +                         uint32_t serial, +                         uint32_t *__serial); + +int rbug_send_error_reply(struct rbug_connection *__con, +                          uint32_t serial, +                          uint32_t error, +                          uint32_t *__serial); + +struct rbug_proto_noop * rbug_demarshal_noop(struct rbug_proto_header *header); + +struct rbug_proto_ping * rbug_demarshal_ping(struct rbug_proto_header *header); + +struct rbug_proto_error * rbug_demarshal_error(struct rbug_proto_header *header); + +struct rbug_proto_ping_reply * rbug_demarshal_ping_reply(struct rbug_proto_header *header); + +struct rbug_proto_error_reply * rbug_demarshal_error_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_demarshal.c b/src/gallium/auxiliary/rbug/rbug_demarshal.c new file mode 100644 index 0000000000..47390fbcee --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_demarshal.c @@ -0,0 +1,93 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +#include "rbug.h" + +/** + * Small function that looks at the proto_header and selects the correct + * demarshal functions and return the result. + */ +struct rbug_header * rbug_demarshal(struct rbug_proto_header *header) +{ +	switch(header->opcode) { +	case RBUG_OP_NOOP: +		return (struct rbug_header *)rbug_demarshal_noop(header); +	case RBUG_OP_PING: +		return (struct rbug_header *)rbug_demarshal_ping(header); +	case RBUG_OP_ERROR: +		return (struct rbug_header *)rbug_demarshal_error(header); +	case RBUG_OP_PING_REPLY: +		return (struct rbug_header *)rbug_demarshal_ping_reply(header); +	case RBUG_OP_ERROR_REPLY: +		return (struct rbug_header *)rbug_demarshal_error_reply(header); +	case RBUG_OP_TEXTURE_LIST: +		return (struct rbug_header *)rbug_demarshal_texture_list(header); +	case RBUG_OP_TEXTURE_INFO: +		return (struct rbug_header *)rbug_demarshal_texture_info(header); +	case RBUG_OP_TEXTURE_WRITE: +		return (struct rbug_header *)rbug_demarshal_texture_write(header); +	case RBUG_OP_TEXTURE_READ: +		return (struct rbug_header *)rbug_demarshal_texture_read(header); +	case RBUG_OP_TEXTURE_LIST_REPLY: +		return (struct rbug_header *)rbug_demarshal_texture_list_reply(header); +	case RBUG_OP_TEXTURE_INFO_REPLY: +		return (struct rbug_header *)rbug_demarshal_texture_info_reply(header); +	case RBUG_OP_TEXTURE_READ_REPLY: +		return (struct rbug_header *)rbug_demarshal_texture_read_reply(header); +	case RBUG_OP_CONTEXT_LIST: +		return (struct rbug_header *)rbug_demarshal_context_list(header); +	case RBUG_OP_CONTEXT_INFO: +		return (struct rbug_header *)rbug_demarshal_context_info(header); +	case RBUG_OP_CONTEXT_DRAW_BLOCK: +		return (struct rbug_header *)rbug_demarshal_context_draw_block(header); +	case RBUG_OP_CONTEXT_DRAW_STEP: +		return (struct rbug_header *)rbug_demarshal_context_draw_step(header); +	case RBUG_OP_CONTEXT_DRAW_UNBLOCK: +		return (struct rbug_header *)rbug_demarshal_context_draw_unblock(header); +	case RBUG_OP_CONTEXT_DRAW_RULE: +		return (struct rbug_header *)rbug_demarshal_context_draw_rule(header); +	case RBUG_OP_CONTEXT_FLUSH: +		return (struct rbug_header *)rbug_demarshal_context_flush(header); +	case RBUG_OP_CONTEXT_LIST_REPLY: +		return (struct rbug_header *)rbug_demarshal_context_list_reply(header); +	case RBUG_OP_CONTEXT_INFO_REPLY: +		return (struct rbug_header *)rbug_demarshal_context_info_reply(header); +	case RBUG_OP_CONTEXT_DRAW_BLOCKED: +		return (struct rbug_header *)rbug_demarshal_context_draw_blocked(header); +	case RBUG_OP_SHADER_LIST: +		return (struct rbug_header *)rbug_demarshal_shader_list(header); +	case RBUG_OP_SHADER_INFO: +		return (struct rbug_header *)rbug_demarshal_shader_info(header); +	case RBUG_OP_SHADER_DISABLE: +		return (struct rbug_header *)rbug_demarshal_shader_disable(header); +	case RBUG_OP_SHADER_REPLACE: +		return (struct rbug_header *)rbug_demarshal_shader_replace(header); +	case RBUG_OP_SHADER_LIST_REPLY: +		return (struct rbug_header *)rbug_demarshal_shader_list_reply(header); +	case RBUG_OP_SHADER_INFO_REPLY: +		return (struct rbug_header *)rbug_demarshal_shader_info_reply(header); +	default: +		return NULL; +	} +} diff --git a/src/gallium/auxiliary/rbug/rbug_internal.h b/src/gallium/auxiliary/rbug/rbug_internal.h new file mode 100644 index 0000000000..4aba1a810f --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_internal.h @@ -0,0 +1,100 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file is internal to the rbug protocol code, and contains asorted + * features needed by the code. + */ + +#ifndef _RBUG_INTERNAL_H_ +#define _RBUG_INTERNAL_H_ + +#include "rbug/rbug_proto.h" + +#include "util/u_memory.h" +#include "util/u_debug.h" +#include <errno.h> + +int rbug_connection_send_start(struct rbug_connection *con, enum rbug_opcode opcode, uint32_t length); +int rbug_connection_write(struct rbug_connection *con, void *data, uint32_t size); +int rbug_connection_send_finish(struct rbug_connection *con, uint32_t *c); + +/** + * Only works with multiples of 2 + */ +#define PAD(from, to)                       \ +do {                                        \ +	from = (from + to - 1) & ~(to - 1); \ +} while(0) + +#define LEN(size)         \ +do {                      \ +	PAD(__len, size); \ +	__len += size;    \ +} while(0) + +#define LEN_ARRAY(size, name)       \ +do {                                \ +	LEN(4);                     \ +	PAD(__len, size);           \ +	__len += size * name##_len; \ +} while(0) + +#define WRITE(size, type, name)             \ +do {                                        \ +	PAD(__pos, size);                   \ +	*((type *)(&__data[__pos])) = name; \ +	__pos += size;                      \ +} while(0) + +#define WRITE_ARRAY(size, type, name)                    \ +do {                                                     \ +	WRITE(4, uint32_t, name##_len);                  \ +	PAD(__pos, size);                                \ +	memcpy(&__data[__pos], name, size * name##_len); \ +	__pos += size * name##_len;                      \ +} while(0) + +#define READ(size, type, name)                      \ +do {                                                \ +	PAD(pos, size);                             \ +	pos += size;                                \ +	if (pos > len)                              \ +		break;                              \ +	ret->name = *((type *)(&data[pos - size])); \ +} while(0) + +#define READ_ARRAY(size, type, name)                             \ +do {                                                             \ +	READ(4, uint32_t, name##_len);                           \ +	if (pos > len)                                           \ +		break;                                           \ +	PAD(pos, size);                                          \ +	pos += size * ret->name##_len;                           \ +	if (pos > len)                                           \ +		break;                                           \ +	ret->name = (type *)&data[pos - size * ret->name##_len]; \ +} while(0) + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_proto.h b/src/gallium/auxiliary/rbug/rbug_proto.h new file mode 100644 index 0000000000..d273be0166 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_proto.h @@ -0,0 +1,94 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds common definitions of the gallium remote debugging protocol. + */ + +#ifndef _RBUG_PROTO_H_ +#define _RBUG_PROTO_H_ + +#include "pipe/p_compiler.h" + +/** + * Uniqe indentifier for each command. + * + * Replys are designated by negative. + */ +enum rbug_opcode +{ +	RBUG_OP_NOOP = 0, +	RBUG_OP_PING = 1, +	RBUG_OP_ERROR = 2, +	RBUG_OP_PING_REPLY = -1, +	RBUG_OP_ERROR_REPLY = -2, +	RBUG_OP_TEXTURE_LIST = 256, +	RBUG_OP_TEXTURE_INFO = 257, +	RBUG_OP_TEXTURE_WRITE = 258, +	RBUG_OP_TEXTURE_READ = 259, +	RBUG_OP_TEXTURE_LIST_REPLY = -256, +	RBUG_OP_TEXTURE_INFO_REPLY = -257, +	RBUG_OP_TEXTURE_READ_REPLY = -259, +	RBUG_OP_CONTEXT_LIST = 512, +	RBUG_OP_CONTEXT_INFO = 513, +	RBUG_OP_CONTEXT_DRAW_BLOCK = 514, +	RBUG_OP_CONTEXT_DRAW_STEP = 515, +	RBUG_OP_CONTEXT_DRAW_UNBLOCK = 516, +	RBUG_OP_CONTEXT_DRAW_RULE = 518, +	RBUG_OP_CONTEXT_FLUSH = 519, +	RBUG_OP_CONTEXT_LIST_REPLY = -512, +	RBUG_OP_CONTEXT_INFO_REPLY = -513, +	RBUG_OP_CONTEXT_DRAW_BLOCKED = 517, +	RBUG_OP_SHADER_LIST = 768, +	RBUG_OP_SHADER_INFO = 769, +	RBUG_OP_SHADER_DISABLE = 770, +	RBUG_OP_SHADER_REPLACE = 771, +	RBUG_OP_SHADER_LIST_REPLY = -768, +	RBUG_OP_SHADER_INFO_REPLY = -769, +}; + +/** + * Header for demarshaled message. + */ +struct rbug_header +{ +	enum rbug_opcode opcode; +	void *__message; +}; + +/** + * Header for a message in wire format. + */ +struct rbug_proto_header +{ +	int32_t opcode; +	uint32_t length; +}; + +/** + * Forward declare connection here, as this file is included by all users. + */ +struct rbug_connection; + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_shader.c b/src/gallium/auxiliary/rbug/rbug_shader.c new file mode 100644 index 0000000000..fccd2f55ef --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_shader.c @@ -0,0 +1,468 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_shader.h" + +int rbug_send_shader_list(struct rbug_connection *__con, +                          rbug_context_t context, +                          uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_shader_info(struct rbug_connection *__con, +                          rbug_context_t context, +                          rbug_shader_t shader, +                          uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(8); /* shader */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(8, rbug_shader_t, shader); /* shader */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_shader_disable(struct rbug_connection *__con, +                             rbug_context_t context, +                             rbug_shader_t shader, +                             uint8_t disable, +                             uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(8); /* shader */ +	LEN(1); /* disable */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(8, rbug_shader_t, shader); /* shader */ +	WRITE(1, uint8_t, disable); /* disable */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_shader_replace(struct rbug_connection *__con, +                             rbug_context_t context, +                             rbug_shader_t shader, +                             uint32_t *tokens, +                             uint32_t tokens_len, +                             uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* context */ +	LEN(8); /* shader */ +	LEN_ARRAY(4, tokens); /* tokens */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_context_t, context); /* context */ +	WRITE(8, rbug_shader_t, shader); /* shader */ +	WRITE_ARRAY(4, uint32_t, tokens); /* tokens */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_shader_list_reply(struct rbug_connection *__con, +                                uint32_t serial, +                                rbug_shader_t *shaders, +                                uint32_t shaders_len, +                                uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN_ARRAY(8, shaders); /* shaders */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_shader_info_reply(struct rbug_connection *__con, +                                uint32_t serial, +                                uint32_t *original, +                                uint32_t original_len, +                                uint32_t *replaced, +                                uint32_t replaced_len, +                                uint8_t disabled, +                                uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN_ARRAY(4, original); /* original */ +	LEN_ARRAY(4, replaced); /* replaced */ +	LEN(1); /* disabled */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE_ARRAY(4, uint32_t, original); /* original */ +	WRITE_ARRAY(4, uint32_t, replaced); /* replaced */ +	WRITE(1, uint8_t, disabled); /* disabled */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_list *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_LIST) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ + +	return ret; +} + +struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_info *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_INFO) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(8, rbug_shader_t, shader); /* shader */ + +	return ret; +} + +struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_disable *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_DISABLE) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(8, rbug_shader_t, shader); /* shader */ +	READ(1, uint8_t, disable); /* disable */ + +	return ret; +} + +struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_replace *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_REPLACE) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_context_t, context); /* context */ +	READ(8, rbug_shader_t, shader); /* shader */ +	READ_ARRAY(4, uint32_t, tokens); /* tokens */ + +	return ret; +} + +struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_list_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_LIST_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */ + +	return ret; +} + +struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_shader_info_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_SHADER_INFO_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ_ARRAY(4, uint32_t, original); /* original */ +	READ_ARRAY(4, uint32_t, replaced); /* replaced */ +	READ(1, uint8_t, disabled); /* disabled */ + +	return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_shader.h b/src/gallium/auxiliary/rbug/rbug_shader.h new file mode 100644 index 0000000000..b5d886781d --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_shader.h @@ -0,0 +1,142 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_SHADER_H_ +#define _RBUG_PROTO_SHADER_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +struct rbug_proto_shader_list +{ +	struct rbug_header header; +	rbug_context_t context; +}; + +struct rbug_proto_shader_info +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_shader_t shader; +}; + +struct rbug_proto_shader_disable +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_shader_t shader; +	uint8_t disable; +}; + +struct rbug_proto_shader_replace +{ +	struct rbug_header header; +	rbug_context_t context; +	rbug_shader_t shader; +	uint32_t *tokens; +	uint32_t tokens_len; +}; + +struct rbug_proto_shader_list_reply +{ +	struct rbug_header header; +	uint32_t serial; +	rbug_shader_t *shaders; +	uint32_t shaders_len; +}; + +struct rbug_proto_shader_info_reply +{ +	struct rbug_header header; +	uint32_t serial; +	uint32_t *original; +	uint32_t original_len; +	uint32_t *replaced; +	uint32_t replaced_len; +	uint8_t disabled; +}; + +int rbug_send_shader_list(struct rbug_connection *__con, +                          rbug_context_t context, +                          uint32_t *__serial); + +int rbug_send_shader_info(struct rbug_connection *__con, +                          rbug_context_t context, +                          rbug_shader_t shader, +                          uint32_t *__serial); + +int rbug_send_shader_disable(struct rbug_connection *__con, +                             rbug_context_t context, +                             rbug_shader_t shader, +                             uint8_t disable, +                             uint32_t *__serial); + +int rbug_send_shader_replace(struct rbug_connection *__con, +                             rbug_context_t context, +                             rbug_shader_t shader, +                             uint32_t *tokens, +                             uint32_t tokens_len, +                             uint32_t *__serial); + +int rbug_send_shader_list_reply(struct rbug_connection *__con, +                                uint32_t serial, +                                rbug_shader_t *shaders, +                                uint32_t shaders_len, +                                uint32_t *__serial); + +int rbug_send_shader_info_reply(struct rbug_connection *__con, +                                uint32_t serial, +                                uint32_t *original, +                                uint32_t original_len, +                                uint32_t *replaced, +                                uint32_t replaced_len, +                                uint8_t disabled, +                                uint32_t *__serial); + +struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header); + +struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header); + +struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header); + +struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header); + +struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_texture.c b/src/gallium/auxiliary/rbug/rbug_texture.c new file mode 100644 index 0000000000..5a918fe6bc --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_texture.c @@ -0,0 +1,631 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_texture.h" + +int rbug_send_texture_list(struct rbug_connection *__con, +                           uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_info(struct rbug_connection *__con, +                           rbug_texture_t texture, +                           uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* texture */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_texture_t, texture); /* texture */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_write(struct rbug_connection *__con, +                            rbug_texture_t texture, +                            uint32_t face, +                            uint32_t level, +                            uint32_t zslice, +                            uint32_t x, +                            uint32_t y, +                            uint32_t w, +                            uint32_t h, +                            uint8_t *data, +                            uint32_t data_len, +                            uint32_t stride, +                            uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* texture */ +	LEN(4); /* face */ +	LEN(4); /* level */ +	LEN(4); /* zslice */ +	LEN(4); /* x */ +	LEN(4); /* y */ +	LEN(4); /* w */ +	LEN(4); /* h */ +	LEN_ARRAY(1, data); /* data */ +	LEN(4); /* stride */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_texture_t, texture); /* texture */ +	WRITE(4, uint32_t, face); /* face */ +	WRITE(4, uint32_t, level); /* level */ +	WRITE(4, uint32_t, zslice); /* zslice */ +	WRITE(4, uint32_t, x); /* x */ +	WRITE(4, uint32_t, y); /* y */ +	WRITE(4, uint32_t, w); /* w */ +	WRITE(4, uint32_t, h); /* h */ +	WRITE_ARRAY(1, uint8_t, data); /* data */ +	WRITE(4, uint32_t, stride); /* stride */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_read(struct rbug_connection *__con, +                           rbug_texture_t texture, +                           uint32_t face, +                           uint32_t level, +                           uint32_t zslice, +                           uint32_t x, +                           uint32_t y, +                           uint32_t w, +                           uint32_t h, +                           uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(8); /* texture */ +	LEN(4); /* face */ +	LEN(4); /* level */ +	LEN(4); /* zslice */ +	LEN(4); /* x */ +	LEN(4); /* y */ +	LEN(4); /* w */ +	LEN(4); /* h */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(8, rbug_texture_t, texture); /* texture */ +	WRITE(4, uint32_t, face); /* face */ +	WRITE(4, uint32_t, level); /* level */ +	WRITE(4, uint32_t, zslice); /* zslice */ +	WRITE(4, uint32_t, x); /* x */ +	WRITE(4, uint32_t, y); /* y */ +	WRITE(4, uint32_t, w); /* w */ +	WRITE(4, uint32_t, h); /* h */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_list_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_texture_t *textures, +                                 uint32_t textures_len, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN_ARRAY(8, textures); /* textures */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_info_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 uint32_t target, +                                 uint32_t format, +                                 uint32_t *width, +                                 uint32_t width_len, +                                 uint32_t *height, +                                 uint32_t height_len, +                                 uint32_t *depth, +                                 uint32_t depth_len, +                                 uint32_t blockw, +                                 uint32_t blockh, +                                 uint32_t blocksize, +                                 uint32_t last_level, +                                 uint32_t nr_samples, +                                 uint32_t tex_usage, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN(4); /* target */ +	LEN(4); /* format */ +	LEN_ARRAY(4, width); /* width */ +	LEN_ARRAY(4, height); /* height */ +	LEN_ARRAY(4, depth); /* depth */ +	LEN(4); /* blockw */ +	LEN(4); /* blockh */ +	LEN(4); /* blocksize */ +	LEN(4); /* last_level */ +	LEN(4); /* nr_samples */ +	LEN(4); /* tex_usage */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE(4, uint32_t, target); /* target */ +	WRITE(4, uint32_t, format); /* format */ +	WRITE_ARRAY(4, uint32_t, width); /* width */ +	WRITE_ARRAY(4, uint32_t, height); /* height */ +	WRITE_ARRAY(4, uint32_t, depth); /* depth */ +	WRITE(4, uint32_t, blockw); /* blockw */ +	WRITE(4, uint32_t, blockh); /* blockh */ +	WRITE(4, uint32_t, blocksize); /* blocksize */ +	WRITE(4, uint32_t, last_level); /* last_level */ +	WRITE(4, uint32_t, nr_samples); /* nr_samples */ +	WRITE(4, uint32_t, tex_usage); /* tex_usage */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +int rbug_send_texture_read_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 uint32_t format, +                                 uint32_t blockw, +                                 uint32_t blockh, +                                 uint32_t blocksize, +                                 uint8_t *data, +                                 uint32_t data_len, +                                 uint32_t stride, +                                 uint32_t *__serial) +{ +	uint32_t __len = 0; +	uint32_t __pos = 0; +	uint8_t *__data = NULL; +	int __ret = 0; + +	LEN(8); /* header */ +	LEN(4); /* serial */ +	LEN(4); /* format */ +	LEN(4); /* blockw */ +	LEN(4); /* blockh */ +	LEN(4); /* blocksize */ +	LEN_ARRAY(1, data); /* data */ +	LEN(4); /* stride */ + +	/* align */ +	PAD(__len, 8); + +	__data = (uint8_t*)MALLOC(__len); +	if (!__data) +		return -ENOMEM; + +	WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY)); +	WRITE(4, uint32_t, ((uint32_t)(__len / 4))); +	WRITE(4, uint32_t, serial); /* serial */ +	WRITE(4, uint32_t, format); /* format */ +	WRITE(4, uint32_t, blockw); /* blockw */ +	WRITE(4, uint32_t, blockh); /* blockh */ +	WRITE(4, uint32_t, blocksize); /* blocksize */ +	WRITE_ARRAY(1, uint8_t, data); /* data */ +	WRITE(4, uint32_t, stride); /* stride */ + +	/* final pad */ +	PAD(__pos, 8); + +	if (__pos != __len) { +		__ret = -EINVAL; +	} else { +		rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len); +		rbug_connection_write(__con, __data, __len); +		__ret = rbug_connection_send_finish(__con, __serial); +	} + +	FREE(__data); +	return __ret; +} + +struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_list *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + + +	return ret; +} + +struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_info *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_texture_t, texture); /* texture */ + +	return ret; +} + +struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_write *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_WRITE) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_texture_t, texture); /* texture */ +	READ(4, uint32_t, face); /* face */ +	READ(4, uint32_t, level); /* level */ +	READ(4, uint32_t, zslice); /* zslice */ +	READ(4, uint32_t, x); /* x */ +	READ(4, uint32_t, y); /* y */ +	READ(4, uint32_t, w); /* w */ +	READ(4, uint32_t, h); /* h */ +	READ_ARRAY(1, uint8_t, data); /* data */ +	READ(4, uint32_t, stride); /* stride */ + +	return ret; +} + +struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_read *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(8, rbug_texture_t, texture); /* texture */ +	READ(4, uint32_t, face); /* face */ +	READ(4, uint32_t, level); /* level */ +	READ(4, uint32_t, zslice); /* zslice */ +	READ(4, uint32_t, x); /* x */ +	READ(4, uint32_t, y); /* y */ +	READ(4, uint32_t, w); /* w */ +	READ(4, uint32_t, h); /* h */ + +	return ret; +} + +struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_list_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_LIST_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ_ARRAY(8, rbug_texture_t, textures); /* textures */ + +	return ret; +} + +struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_info_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_INFO_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ(4, uint32_t, target); /* target */ +	READ(4, uint32_t, format); /* format */ +	READ_ARRAY(4, uint32_t, width); /* width */ +	READ_ARRAY(4, uint32_t, height); /* height */ +	READ_ARRAY(4, uint32_t, depth); /* depth */ +	READ(4, uint32_t, blockw); /* blockw */ +	READ(4, uint32_t, blockh); /* blockh */ +	READ(4, uint32_t, blocksize); /* blocksize */ +	READ(4, uint32_t, last_level); /* last_level */ +	READ(4, uint32_t, nr_samples); /* nr_samples */ +	READ(4, uint32_t, tex_usage); /* tex_usage */ + +	return ret; +} + +struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header) +{ +	uint32_t len = 0; +	uint32_t pos = 0; +	uint8_t *data =  NULL; +	struct rbug_proto_texture_read_reply *ret; + +	if (!header) +		return NULL; +	if (header->opcode != (int16_t)RBUG_OP_TEXTURE_READ_REPLY) +		return NULL; + +	pos = 0; +	len = header->length * 4; +	data = (uint8_t*)&header[1]; +	ret = MALLOC(sizeof(*ret)); +	if (!ret) +		return NULL; + +	ret->header.__message = header; +	ret->header.opcode = header->opcode; + +	READ(4, uint32_t, serial); /* serial */ +	READ(4, uint32_t, format); /* format */ +	READ(4, uint32_t, blockw); /* blockw */ +	READ(4, uint32_t, blockh); /* blockh */ +	READ(4, uint32_t, blocksize); /* blocksize */ +	READ_ARRAY(1, uint8_t, data); /* data */ +	READ(4, uint32_t, stride); /* stride */ + +	return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_texture.h b/src/gallium/auxiliary/rbug/rbug_texture.h new file mode 100644 index 0000000000..fbb247e1d4 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_texture.h @@ -0,0 +1,206 @@ +/* + * 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 + * on 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 THEIR 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_TEXTURE_H_ +#define _RBUG_PROTO_TEXTURE_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +struct rbug_proto_texture_list +{ +	struct rbug_header header; +}; + +struct rbug_proto_texture_info +{ +	struct rbug_header header; +	rbug_texture_t texture; +}; + +struct rbug_proto_texture_write +{ +	struct rbug_header header; +	rbug_texture_t texture; +	uint32_t face; +	uint32_t level; +	uint32_t zslice; +	uint32_t x; +	uint32_t y; +	uint32_t w; +	uint32_t h; +	uint8_t *data; +	uint32_t data_len; +	uint32_t stride; +}; + +struct rbug_proto_texture_read +{ +	struct rbug_header header; +	rbug_texture_t texture; +	uint32_t face; +	uint32_t level; +	uint32_t zslice; +	uint32_t x; +	uint32_t y; +	uint32_t w; +	uint32_t h; +}; + +struct rbug_proto_texture_list_reply +{ +	struct rbug_header header; +	uint32_t serial; +	rbug_texture_t *textures; +	uint32_t textures_len; +}; + +struct rbug_proto_texture_info_reply +{ +	struct rbug_header header; +	uint32_t serial; +	uint32_t target; +	uint32_t format; +	uint32_t *width; +	uint32_t width_len; +	uint32_t *height; +	uint32_t height_len; +	uint32_t *depth; +	uint32_t depth_len; +	uint32_t blockw; +	uint32_t blockh; +	uint32_t blocksize; +	uint32_t last_level; +	uint32_t nr_samples; +	uint32_t tex_usage; +}; + +struct rbug_proto_texture_read_reply +{ +	struct rbug_header header; +	uint32_t serial; +	uint32_t format; +	uint32_t blockw; +	uint32_t blockh; +	uint32_t blocksize; +	uint8_t *data; +	uint32_t data_len; +	uint32_t stride; +}; + +int rbug_send_texture_list(struct rbug_connection *__con, +                           uint32_t *__serial); + +int rbug_send_texture_info(struct rbug_connection *__con, +                           rbug_texture_t texture, +                           uint32_t *__serial); + +int rbug_send_texture_write(struct rbug_connection *__con, +                            rbug_texture_t texture, +                            uint32_t face, +                            uint32_t level, +                            uint32_t zslice, +                            uint32_t x, +                            uint32_t y, +                            uint32_t w, +                            uint32_t h, +                            uint8_t *data, +                            uint32_t data_len, +                            uint32_t stride, +                            uint32_t *__serial); + +int rbug_send_texture_read(struct rbug_connection *__con, +                           rbug_texture_t texture, +                           uint32_t face, +                           uint32_t level, +                           uint32_t zslice, +                           uint32_t x, +                           uint32_t y, +                           uint32_t w, +                           uint32_t h, +                           uint32_t *__serial); + +int rbug_send_texture_list_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 rbug_texture_t *textures, +                                 uint32_t textures_len, +                                 uint32_t *__serial); + +int rbug_send_texture_info_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 uint32_t target, +                                 uint32_t format, +                                 uint32_t *width, +                                 uint32_t width_len, +                                 uint32_t *height, +                                 uint32_t height_len, +                                 uint32_t *depth, +                                 uint32_t depth_len, +                                 uint32_t blockw, +                                 uint32_t blockh, +                                 uint32_t blocksize, +                                 uint32_t last_level, +                                 uint32_t nr_samples, +                                 uint32_t tex_usage, +                                 uint32_t *__serial); + +int rbug_send_texture_read_reply(struct rbug_connection *__con, +                                 uint32_t serial, +                                 uint32_t format, +                                 uint32_t blockw, +                                 uint32_t blockh, +                                 uint32_t blocksize, +                                 uint8_t *data, +                                 uint32_t data_len, +                                 uint32_t stride, +                                 uint32_t *__serial); + +struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header); + +struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header); + +struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header); + +struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header); + +struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header); + +struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c index 57fcf6de2a..1acf3c373e 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -993,6 +993,15 @@ void sse_pmovmskb( struct x86_function *p,     emit_modrm(p, dst, src);  } +void sse_movmskps( struct x86_function *p, +                   struct x86_reg dst, +                   struct x86_reg src) +{ +   DUMP_RR( dst, src ); +   emit_2ub(p, X86_TWOB, 0x50); +   emit_modrm(p, dst, src); +} +  /***********************************************************************   * SSE2 instructions   */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h index 1b5eaaca85..731a651796 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h @@ -223,6 +223,7 @@ void sse_unpckhps( struct x86_function *p, struct x86_reg dst, struct x86_reg sr  void sse_unpcklps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );  void sse_pmovmskb( struct x86_function *p, struct x86_reg dest, struct x86_reg src );  void sse2_punpcklbw( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movmskps( struct x86_function *p, struct x86_reg dst, struct x86_reg src);  void x86_add( struct x86_function *p, struct x86_reg dst, struct x86_reg src );  void x86_and( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 5cb322a5fa..fe571a86bc 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -365,15 +365,26 @@ tgsi_exec_machine_bind_shader(  } -void -tgsi_exec_machine_init( -   struct tgsi_exec_machine *mach ) +struct tgsi_exec_machine * +tgsi_exec_machine_create( void )  { +   struct tgsi_exec_machine *mach;     uint i; -   mach->Temps = (struct tgsi_exec_vector *) tgsi_align_128bit( mach->_Temps); +   mach = align_malloc( sizeof *mach, 16 ); +   if (!mach) +      goto fail; +     mach->Addrs = &mach->Temps[TGSI_EXEC_TEMP_ADDR]; +   mach->Samplers = NULL; +   mach->Consts = NULL; +   mach->Tokens = NULL; +   mach->Primitives = NULL; +   mach->InterpCoefs = NULL; +   mach->Instructions = NULL; +   mach->Declarations = NULL; +     /* Setup constants. */     for( i = 0; i < 4; i++ ) {        mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].u[i] = 0x00000000; @@ -393,22 +404,24 @@ tgsi_exec_machine_init(     (void) print_chan;     (void) print_temp;  #endif + +   return mach; + +fail: +   align_free(mach); +   return NULL;  }  void -tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach) +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach)  { -   if (mach->Instructions) { +   if (mach) {        FREE(mach->Instructions); -      mach->Instructions = NULL; -      mach->NumInstructions = 0; -   } -   if (mach->Declarations) {        FREE(mach->Declarations); -      mach->Declarations = NULL; -      mach->NumDeclarations = 0;     } + +   align_free(mach);  } diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h index da22baad3e..8a9100f4c3 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.h +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h @@ -29,6 +29,7 @@  #define TGSI_EXEC_H  #include "pipe/p_compiler.h" +#include "pipe/p_state.h"  #if defined __cplusplus  extern "C" { @@ -94,7 +95,6 @@ struct tgsi_exec_labels  #define TGSI_EXEC_NUM_TEMPS       128 -#define TGSI_EXEC_NUM_TEMP_EXTRAS   6  #define TGSI_EXEC_NUM_IMMEDIATES  256  /* @@ -162,9 +162,14 @@ struct tgsi_exec_labels  #define TGSI_EXEC_MASK_I            (TGSI_EXEC_NUM_TEMPS + 3)  #define TGSI_EXEC_MASK_C            2 +/* 4 register buffer for various purposes */  #define TGSI_EXEC_TEMP_R0           (TGSI_EXEC_NUM_TEMPS + 4) +#define TGSI_EXEC_NUM_TEMP_R        4 + +#define TGSI_EXEC_TEMP_ADDR         (TGSI_EXEC_NUM_TEMPS + 8) +#define TGSI_EXEC_NUM_ADDRS         1 +#define TGSI_EXEC_NUM_TEMP_EXTRAS   9 -#define TGSI_EXEC_TEMP_ADDR         (TGSI_EXEC_NUM_TEMPS + 5)  #define TGSI_EXEC_MAX_COND_NESTING  20 @@ -187,24 +192,21 @@ struct tgsi_exec_labels  struct tgsi_exec_machine  {     /* Total = program temporaries + internal temporaries -    *         + 1 padding to align to 16 bytes      */ -   struct tgsi_exec_vector       _Temps[TGSI_EXEC_NUM_TEMPS + -                                        TGSI_EXEC_NUM_TEMP_EXTRAS + 1]; +   struct tgsi_exec_vector       Temps[TGSI_EXEC_NUM_TEMPS + +                                       TGSI_EXEC_NUM_TEMP_EXTRAS]; + +   float                         Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; + +   struct tgsi_exec_vector       Inputs[PIPE_MAX_ATTRIBS]; +   struct tgsi_exec_vector       Outputs[PIPE_MAX_ATTRIBS]; -   /* -    * This will point to _Temps after aligning to 16B boundary. -    */ -   struct tgsi_exec_vector       *Temps;     struct tgsi_exec_vector       *Addrs;     struct tgsi_sampler           **Samplers; -   float                         Imms[TGSI_EXEC_NUM_IMMEDIATES][4];     unsigned                      ImmLimit;     const float                   (*Consts)[4]; -   struct tgsi_exec_vector       *Inputs; -   struct tgsi_exec_vector       *Outputs;     const struct tgsi_token       *Tokens;   /**< Declarations, instructions */     unsigned                      Processor; /**< TGSI_PROCESSOR_x */ @@ -251,9 +253,11 @@ struct tgsi_exec_machine     struct tgsi_exec_labels Labels;  }; +struct tgsi_exec_machine * +tgsi_exec_machine_create( void ); +  void -tgsi_exec_machine_init( -   struct tgsi_exec_machine *mach ); +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach);  void  @@ -268,10 +272,6 @@ tgsi_exec_machine_run(     struct tgsi_exec_machine *mach ); -void -tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach); - -  static INLINE void  tgsi_set_kill_mask(struct tgsi_exec_machine *mach, unsigned mask)  { diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.c b/src/gallium/auxiliary/tgsi/tgsi_sse2.c index ba2bfdef06..4c3343d26c 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_sse2.c +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.c @@ -32,6 +32,7 @@  #include "util/u_debug.h"  #include "pipe/p_shader_tokens.h"  #include "util/u_math.h" +#include "util/u_memory.h"  #if defined(PIPE_ARCH_SSE)  #include "util/u_sse.h"  #endif @@ -100,37 +101,55 @@ get_const_base( void )  {     return x86_make_reg(        file_REG32, -      reg_CX ); +      reg_AX );  }  static struct x86_reg -get_input_base( void ) +get_machine_base( void )  {     return x86_make_reg(        file_REG32, -      reg_AX ); +      reg_CX ); +} + +static struct x86_reg +get_input_base( void ) +{ +   return x86_make_disp( +      get_machine_base(), +      Offset(struct tgsi_exec_machine, Inputs) );  }  static struct x86_reg  get_output_base( void )  { -   return x86_make_reg( -      file_REG32, -      reg_DX ); +   return x86_make_disp( +      get_machine_base(), +      Offset(struct tgsi_exec_machine, Outputs) );  }  static struct x86_reg  get_temp_base( void )  { +   return x86_make_disp( +      get_machine_base(), +      Offset(struct tgsi_exec_machine, Temps) ); +} + +static struct x86_reg +get_coef_base( void ) +{     return x86_make_reg(        file_REG32,        reg_BX );  }  static struct x86_reg -get_coef_base( void ) +get_sampler_base( void )  { -   return get_output_base(); +   return x86_make_reg( +      file_REG32, +      reg_DI );  }  static struct x86_reg @@ -138,7 +157,7 @@ get_immediate_base( void )  {     return x86_make_reg(        file_REG32, -      reg_DI ); +      reg_DX );  } @@ -168,6 +187,15 @@ get_const(  }  static struct x86_reg +get_sampler_ptr( +   unsigned unit ) +{ +   return x86_make_disp( +      get_sampler_base(), +      unit * sizeof( struct tgsi_sampler * ) ); +} + +static struct x86_reg  get_input(     unsigned vec,     unsigned chan ) @@ -241,12 +269,14 @@ emit_const(        /* 'vec' is the offset from the address register's value.         * We're loading CONST[ADDR+vec] into an xmm register.         */ -      struct x86_reg r0 = get_input_base(); -      struct x86_reg r1 = get_output_base(); +      struct x86_reg r0 = get_immediate_base(); +      struct x86_reg r1 = get_coef_base();        uint i;        assert( indirectFile == TGSI_FILE_ADDRESS );        assert( indirectIndex == 0 ); +      assert( r0.mod == mod_REG ); +      assert( r1.mod == mod_REG );        x86_push( func, r0 );        x86_push( func, r1 ); @@ -520,24 +550,15 @@ emit_coef_dady(   * that the stack pointer is 16 byte aligned, as expected.   */  static void -emit_func_call_dst( +emit_func_call(     struct x86_function *func, -   unsigned xmm_save, -   unsigned xmm_dst, +   unsigned xmm_save_mask, +   const struct x86_reg *arg, +   unsigned nr_args,     void (PIPE_CDECL *code)() )  {     struct x86_reg ecx = x86_make_reg( file_REG32, reg_CX );     unsigned i, n; -   unsigned xmm_mask; -    -   /* Bitmask of the xmm registers to save */ -   xmm_mask = (1 << xmm_save) - 1; -   xmm_mask &= ~(1 << xmm_dst); - -   sse_movaps( -      func, -      get_temp( TEMP_R0, 0 ), -      make_xmm( xmm_dst ) );     x86_push(        func, @@ -549,8 +570,10 @@ emit_func_call_dst(        func,        x86_make_reg( file_REG32, reg_DX) ); +   /* Store XMM regs to the stack +    */     for(i = 0, n = 0; i < 8; ++i) -      if(xmm_mask & (1 << i)) +      if(xmm_save_mask & (1 << i))           ++n;     x86_sub_imm( @@ -559,26 +582,42 @@ emit_func_call_dst(        n*16);     for(i = 0, n = 0; i < 8; ++i) -      if(xmm_mask & (1 << i)) { +      if(xmm_save_mask & (1 << i)) {           sse_movups(              func,              x86_make_disp( x86_make_reg( file_REG32, reg_SP ), n*16 ),              make_xmm( i ) );           ++n;        } + +   for (i = 0; i < nr_args; i++) { +      /* Load the address of the buffer we use for passing arguments and +       * receiving results: +       */ +      x86_lea( +	 func, +	 ecx, +	 arg[i] ); -   x86_lea( -      func, -      ecx, -      get_temp( TEMP_R0, 0 ) ); -    -   x86_push( func, ecx ); +      /* Push actual function arguments (currently just the pointer to +       * the buffer above), and call the function: +       */ +      x86_push( func, ecx ); +   } +     x86_mov_reg_imm( func, ecx, (unsigned long) code );     x86_call( func, ecx ); -   x86_pop(func, ecx ); -    + +   /* Pop the arguments (or just add an immediate to esp) +    */ +   for (i = 0; i < nr_args; i++) { +      x86_pop(func, ecx ); +   } + +   /* Pop the saved XMM regs: +    */     for(i = 0, n = 0; i < 8; ++i) -      if(xmm_mask & (1 << i)) { +      if(xmm_save_mask & (1 << i)) {           sse_movups(              func,              make_xmm( i ), @@ -602,34 +641,86 @@ emit_func_call_dst(     x86_pop(        func,        x86_make_reg( file_REG32, reg_AX) ); +} + +static void +emit_func_call_dst_src1( +   struct x86_function *func, +   unsigned xmm_save,  +   unsigned xmm_dst, +   unsigned xmm_src0, +   void (PIPE_CDECL *code)() ) +{ +   struct x86_reg store = get_temp( TEMP_R0, 0 ); +   unsigned xmm_mask = ((1 << xmm_save) - 1) & ~(1 << xmm_dst); +    +   /* Store our input parameters (in xmm regs) to the buffer we use +    * for passing arguments.  We will pass a pointer to this buffer as +    * the actual function argument. +    */ +   sse_movaps( +      func, +      store, +      make_xmm( xmm_src0 ) ); + +   emit_func_call( func, +                   xmm_mask, +                   &store, +                   1, +                   code );     sse_movaps(        func,        make_xmm( xmm_dst ), -      get_temp( TEMP_R0, 0 ) ); +      store );  } +  static void -emit_func_call_dst_src( +emit_func_call_dst_src2(     struct x86_function *func,     unsigned xmm_save,      unsigned xmm_dst, -   unsigned xmm_src, +   unsigned xmm_src0, +   unsigned xmm_src1,     void (PIPE_CDECL *code)() )  { +   struct x86_reg store = get_temp( TEMP_R0, 0 ); +   unsigned xmm_mask = ((1 << xmm_save) - 1) & ~(1 << xmm_dst); + +   /* Store two inputs to parameter buffer. +    */     sse_movaps(        func, -      get_temp( TEMP_R0, 1 ), -      make_xmm( xmm_src ) ); +      store, +      make_xmm( xmm_src0 ) ); -   emit_func_call_dst( +   sse_movaps(        func, -      xmm_save, -      xmm_dst, -      code ); +      x86_make_disp( store, 4 * sizeof(float) ), +      make_xmm( xmm_src1 ) ); + + +   /* Emit the call +    */ +   emit_func_call( func, +                   xmm_mask, +                   &store, +                   1, +                   code ); + +   /* Retrieve the results: +    */ +   sse_movaps( +      func, +      make_xmm( xmm_dst ), +      store );  } + + +  #if defined(PIPE_ARCH_SSE)  /* @@ -782,10 +873,11 @@ emit_cos(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,         xmm_dst, +      xmm_dst,        cos4f );  } @@ -812,10 +904,11 @@ emit_ex2(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        ex24f );  } @@ -857,10 +950,11 @@ emit_flr(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        flr4f );  } @@ -880,10 +974,11 @@ emit_frc(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        frc4f );  } @@ -910,10 +1005,11 @@ emit_lg2(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        lg24f );  } @@ -975,13 +1071,15 @@ emit_pow(     struct x86_function *func,     unsigned xmm_save,      unsigned xmm_dst, -   unsigned xmm_src ) +   unsigned xmm_src0, +   unsigned xmm_src1 )  { -   emit_func_call_dst_src( +   emit_func_call_dst_src2(        func,        xmm_save,        xmm_dst, -      xmm_src, +      xmm_src0, +      xmm_src1,        pow4f );  } @@ -1017,10 +1115,11 @@ emit_rnd(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        rnd4f );  } @@ -1099,10 +1198,11 @@ emit_sgn(     unsigned xmm_save,      unsigned xmm_dst )  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        sgn4f );  } @@ -1121,10 +1221,11 @@ emit_sin (struct x86_function *func,            unsigned xmm_save,             unsigned xmm_dst)  { -   emit_func_call_dst( +   emit_func_call_dst_src1(        func,        xmm_save,        xmm_dst, +      xmm_dst,        sin4f );  } @@ -1140,6 +1241,12 @@ emit_sub(        make_xmm( xmm_src ) );  } + + + + + +  /**   * Register fetch.   */ @@ -1298,20 +1405,164 @@ emit_store(  #define STORE( FUNC, INST, XMM, INDEX, CHAN )\     emit_store( FUNC, XMM, &(INST).FullDstRegisters[INDEX], &(INST), CHAN ) + +static void PIPE_CDECL +fetch_texel( struct tgsi_sampler **sampler, +             float *store ) +{ +#if 0 +   uint j; + +   debug_printf("%s sampler: %p (%p) store: %p\n",  +                __FUNCTION__, +                sampler, *sampler, +                store ); + +   debug_printf("lodbias %f\n", store[12]); + +   for (j = 0; j < 4; j++) +      debug_printf("sample %d texcoord %f %f\n",  +                   j,  +                   store[0+j], +                   store[4+j]); +#endif + +   { +      float rgba[NUM_CHANNELS][QUAD_SIZE]; +      (*sampler)->get_samples(*sampler,  +                              &store[0],  +                              &store[4],  +                              &store[8],  +                              0.0f, /*store[12],  lodbias */ +                              rgba); + +      memcpy( store, rgba, 16 * sizeof(float)); +   } + +#if 0 +   for (j = 0; j < 4; j++) +      debug_printf("sample %d result %f %f %f %f\n",  +                   j,  +                   store[0+j], +                   store[4+j], +                   store[8+j], +                   store[12+j]); +#endif +} +  /**   * High-level instruction translators.   */  static void +emit_tex( struct x86_function *func, +          const struct tgsi_full_instruction *inst, +          boolean lodbias, +          boolean projected) +{ +   const uint unit = inst->FullSrcRegisters[1].SrcRegister.Index; +   struct x86_reg args[2]; +   unsigned count; +   unsigned i; + +   switch (inst->InstructionExtTexture.Texture) { +   case TGSI_TEXTURE_1D: +   case TGSI_TEXTURE_SHADOW1D: +      count = 1; +      break; +   case TGSI_TEXTURE_2D: +   case TGSI_TEXTURE_RECT: +   case TGSI_TEXTURE_SHADOW2D: +   case TGSI_TEXTURE_SHADOWRECT: +      count = 2; +      break; +   case TGSI_TEXTURE_3D: +   case TGSI_TEXTURE_CUBE: +      count = 3; +      break; +   default: +      assert(0); +      return; +   } + +   if (lodbias) { +      FETCH( func, *inst, 3, 0, 3 ); +   } +   else { +      emit_tempf( +         func, +         3, +         TGSI_EXEC_TEMP_00000000_I, +         TGSI_EXEC_TEMP_00000000_C ); + +   } + +   /* store lodbias whether enabled or not -- fetch_texel currently +    * respects it always. +    */ +   sse_movaps( func, +               get_temp( TEMP_R0, 3 ), +               make_xmm( 3 ) ); + +    +   if (projected) { +      FETCH( func, *inst, 3, 0, 3 ); + +      emit_rcp( func, 3, 3 ); +   } + +   for (i = 0; i < count; i++) { +      FETCH( func, *inst, i, 0, i ); + +      if (projected) { +         sse_mulps( +            func, +            make_xmm( i ), +            make_xmm( 3 ) ); +      } +       +      /* Store in the argument buffer: +       */ +      sse_movaps( +         func, +         get_temp( TEMP_R0, i ), +         make_xmm( i ) ); +   } + +   args[0] = get_temp( TEMP_R0, 0 ); +   args[1] = get_sampler_ptr( unit ); + + +   emit_func_call( func, +                   0, +                   args, +                   Elements(args), +                   fetch_texel ); + +   /* If all four channels are enabled, could use a pointer to +    * dst[0].x instead of TEMP_R0 for store? +    */ +   FOR_EACH_DST0_ENABLED_CHANNEL( *inst, i ) { + +      sse_movaps( +         func, +         make_xmm( 0 ), +         get_temp( TEMP_R0, i ) ); + +      STORE( func, *inst, 0, 0, i ); +   } +} + + +static void  emit_kil(     struct x86_function *func,     const struct tgsi_full_src_register *reg )  {     unsigned uniquemask; -   unsigned registers[4]; -   unsigned nextregister = 0; -   unsigned firstchan = ~0; +   unsigned unique_count = 0;     unsigned chan_index; +   unsigned i;     /* This mask stores component bits that were already tested. Note that      * we test if the value is less than zero, so 1.0 and 0.0 need not to be @@ -1331,18 +1582,11 @@ emit_kil(           uniquemask |= 1 << swizzle;           /* allocate register */ -         registers[chan_index] = nextregister;           emit_fetch(              func, -            nextregister, +            unique_count++,              reg,              chan_index ); -         nextregister++; - -         /* mark the first channel used */ -         if( firstchan == ~0 ) { -            firstchan = chan_index; -         }        }     } @@ -1353,32 +1597,32 @@ emit_kil(        func,        x86_make_reg( file_REG32, reg_DX ) ); -   FOR_EACH_CHANNEL( chan_index ) { -      if( uniquemask & (1 << chan_index) ) { -         sse_cmpps( -            func, -            make_xmm( registers[chan_index] ), -            get_temp( -               TGSI_EXEC_TEMP_00000000_I, -               TGSI_EXEC_TEMP_00000000_C ), -            cc_LessThan ); +   for (i = 0 ; i < unique_count; i++ ) { +      struct x86_reg dataXMM = make_xmm(i); -         if( chan_index == firstchan ) { -            sse_pmovmskb( -               func, -               x86_make_reg( file_REG32, reg_AX ), -               make_xmm( registers[chan_index] ) ); -         } -         else { -            sse_pmovmskb( -               func, -               x86_make_reg( file_REG32, reg_DX ), -               make_xmm( registers[chan_index] ) ); -            x86_or( -               func, -               x86_make_reg( file_REG32, reg_AX ), -               x86_make_reg( file_REG32, reg_DX ) ); -         } +      sse_cmpps( +         func, +         dataXMM, +         get_temp( +            TGSI_EXEC_TEMP_00000000_I, +            TGSI_EXEC_TEMP_00000000_C ), +         cc_LessThan ); +       +      if( i == 0 ) { +         sse_movmskps( +            func, +            x86_make_reg( file_REG32, reg_AX ), +            dataXMM ); +      } +      else { +         sse_movmskps( +            func, +            x86_make_reg( file_REG32, reg_DX ), +            dataXMM ); +         x86_or( +            func, +            x86_make_reg( file_REG32, reg_AX ), +            x86_make_reg( file_REG32, reg_DX ) );        }     } @@ -1573,7 +1817,7 @@ emit_instruction(                 get_temp(                    TGSI_EXEC_TEMP_MINUS_128_I,                    TGSI_EXEC_TEMP_MINUS_128_C ) ); -            emit_pow( func, 3, 1, 2 ); +            emit_pow( func, 3, 1, 1, 2 );              FETCH( func, *inst, 0, 0, CHAN_X );              sse_xorps(                 func, @@ -1917,7 +2161,7 @@ emit_instruction(     /* TGSI_OPCODE_POW */        FETCH( func, *inst, 0, 0, CHAN_X );        FETCH( func, *inst, 1, 1, CHAN_X ); -      emit_pow( func, 0, 0, 1 ); +      emit_pow( func, 0, 0, 0, 1 );        FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) {           STORE( func, *inst, 0, 0, chan_index );        } @@ -2086,21 +2330,7 @@ emit_instruction(        break;     case TGSI_OPCODE_TEX: -      if (0) { -	 /* Disable dummy texture code:  -	  */ -	 emit_tempf( -	    func, -	    0, -	    TEMP_ONE_I, -	    TEMP_ONE_C ); -	 FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { -	    STORE( func, *inst, 0, 0, chan_index ); -	 } -      } -      else { -	 return 0; -      } +      emit_tex( func, inst, FALSE, FALSE );        break;     case TGSI_OPCODE_TXD: @@ -2198,7 +2428,7 @@ emit_instruction(        break;     case TGSI_OPCODE_TXB: -      return 0; +      emit_tex( func, inst, TRUE, FALSE );        break;     case TGSI_OPCODE_NRM: @@ -2306,9 +2536,13 @@ emit_instruction(        break;     case TGSI_OPCODE_TXL: -      return 0; +      emit_tex( func, inst, TRUE, FALSE );        break; +   case TGSI_OPCODE_TXP: +      emit_tex( func, inst, FALSE, TRUE ); +      break; +           case TGSI_OPCODE_BRK:        return 0;        break; @@ -2488,7 +2722,7 @@ emit_declaration(  static void aos_to_soa( struct x86_function *func,                           uint arg_aos, -                        uint arg_soa,  +                        uint arg_machine,                           uint arg_num,                           uint arg_stride )  { @@ -2503,7 +2737,10 @@ static void aos_to_soa( struct x86_function *func,     x86_push( func, x86_make_reg( file_REG32, reg_BX ) );     x86_mov( func, aos_input,  x86_fn_arg( func, arg_aos ) ); -   x86_mov( func, soa_input,  x86_fn_arg( func, arg_soa ) ); +   x86_mov( func, soa_input,  x86_fn_arg( func, arg_machine ) ); +   x86_lea( func, soa_input,   +	    x86_make_disp( soa_input,  +			   Offset(struct tgsi_exec_machine, Inputs) ) );     x86_mov( func, num_inputs, x86_fn_arg( func, arg_num ) );     x86_mov( func, stride,     x86_fn_arg( func, arg_stride ) ); @@ -2545,28 +2782,30 @@ static void aos_to_soa( struct x86_function *func,     x86_jcc( func, cc_NE, inner_loop );     /* Restore EBX */ -   x86_pop( func, aos_input ); +   x86_pop( func, x86_make_reg( file_REG32, reg_BX ) );  } -static void soa_to_aos( struct x86_function *func, uint aos, uint soa, uint num, uint stride ) +static void soa_to_aos( struct x86_function *func,  +			uint arg_aos,  +			uint arg_machine,  +			uint arg_num,  +			uint arg_stride )  { -   struct x86_reg soa_output; -   struct x86_reg aos_output; -   struct x86_reg num_outputs; -   struct x86_reg temp; +   struct x86_reg soa_output = x86_make_reg( file_REG32, reg_AX ); +   struct x86_reg aos_output = x86_make_reg( file_REG32, reg_BX ); +   struct x86_reg num_outputs = x86_make_reg( file_REG32, reg_CX ); +   struct x86_reg temp = x86_make_reg( file_REG32, reg_DX );     int inner_loop; -   soa_output = x86_make_reg( file_REG32, reg_AX ); -   aos_output = x86_make_reg( file_REG32, reg_BX ); -   num_outputs = x86_make_reg( file_REG32, reg_CX ); -   temp = x86_make_reg( file_REG32, reg_DX ); -     /* Save EBX */ -   x86_push( func, aos_output ); +   x86_push( func, x86_make_reg( file_REG32, reg_BX ) ); -   x86_mov( func, soa_output, x86_fn_arg( func, soa ) ); -   x86_mov( func, aos_output, x86_fn_arg( func, aos ) ); -   x86_mov( func, num_outputs, x86_fn_arg( func, num ) ); +   x86_mov( func, aos_output, x86_fn_arg( func, arg_aos ) ); +   x86_mov( func, soa_output, x86_fn_arg( func, arg_machine ) ); +   x86_lea( func, soa_output,  +	    x86_make_disp( soa_output,  +			   Offset(struct tgsi_exec_machine, Outputs) ) ); +   x86_mov( func, num_outputs, x86_fn_arg( func, arg_num ) );     /* do */     inner_loop = x86_get_label( func ); @@ -2583,7 +2822,7 @@ static void soa_to_aos( struct x86_function *func, uint aos, uint soa, uint num,        sse_unpcklps( func, make_xmm( 3 ), make_xmm( 4 ) );        sse_unpckhps( func, make_xmm( 5 ), make_xmm( 4 ) ); -      x86_mov( func, temp, x86_fn_arg( func, stride ) ); +      x86_mov( func, temp, x86_fn_arg( func, arg_stride ) );        x86_push( func, aos_output );        sse_movlps( func, x86_make_disp( aos_output, 0 ), make_xmm( 0 ) );        sse_movlps( func, x86_make_disp( aos_output, 8 ), make_xmm( 3 ) ); @@ -2607,20 +2846,13 @@ static void soa_to_aos( struct x86_function *func, uint aos, uint soa, uint num,     x86_jcc( func, cc_NE, inner_loop );     /* Restore EBX */ -   x86_pop( func, aos_output ); +   x86_pop( func, x86_make_reg( file_REG32, reg_BX ) );  }  /**   * Translate a TGSI vertex/fragment shader to SSE2 code.   * Slightly different things are done for vertex vs. fragment shaders.   * - * Note that fragment shaders are responsible for interpolating shader - * inputs. Because on x86 we have only 4 GP registers, and here we - * have 5 shader arguments (input, output, const, temp and coef), the - * code is split into two phases -- DECLARATION and INSTRUCTION phase. - * GP register holding the output argument is aliased with the coeff - * argument, as outputs are not needed in the DECLARATION phase. - *   * \param tokens  the TGSI input shader   * \param func  the output SSE code/function   * \param immediates  buffer to place immediates, later passed to SSE func @@ -2634,7 +2866,6 @@ tgsi_emit_sse2(     boolean do_swizzles )  {     struct tgsi_parse_context parse; -   boolean instruction_phase = FALSE;     unsigned ok = 1;     uint num_immediates = 0; @@ -2646,74 +2877,48 @@ tgsi_emit_sse2(     /* Can't just use EDI, EBX without save/restoring them:      */ -   x86_push( -      func, -      get_immediate_base() ); - -   x86_push( -      func, -      get_temp_base() ); - +   x86_push( func, x86_make_reg( file_REG32, reg_BX ) ); +   x86_push( func, x86_make_reg( file_REG32, reg_DI ) );     /*      * Different function args for vertex/fragment shaders:      */ -   if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { -      /* DECLARATION phase, do not load output argument. */ -      x86_mov( -         func, -         get_input_base(), -         x86_fn_arg( func, 1 ) ); -      /* skipping outputs argument here */ -      x86_mov( -         func, -         get_const_base(), -         x86_fn_arg( func, 3 ) ); -      x86_mov( -         func, -         get_temp_base(), -         x86_fn_arg( func, 4 ) ); -      x86_mov( -         func, -         get_coef_base(), -         x86_fn_arg( func, 5 ) ); -      x86_mov( -         func, -         get_immediate_base(), -         x86_fn_arg( func, 6 ) ); -   } -   else { -      assert(parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX); - +   if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX) {        if (do_swizzles)           aos_to_soa( func,  -                     6,         /* aos_input */ -                     1,         /* machine->input */ -                     7,         /* num_inputs */ -                     8 );       /* input_stride */ +                     4,         /* aos_input */ +                     1,         /* machine */ +                     5,         /* num_inputs */ +                     6 );       /* input_stride */ +   } +   x86_mov( +      func, +      get_machine_base(), +      x86_fn_arg( func, 1 ) ); +   x86_mov( +      func, +      get_const_base(), +      x86_fn_arg( func, 2 ) ); +   x86_mov( +      func, +      get_immediate_base(), +      x86_fn_arg( func, 3 ) ); + +   if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) {        x86_mov( -         func, -         get_input_base(), -         x86_fn_arg( func, 1 ) ); -      x86_mov( -         func, -         get_output_base(), -         x86_fn_arg( func, 2 ) ); -      x86_mov( -         func, -         get_const_base(), -         x86_fn_arg( func, 3 ) ); -      x86_mov( -         func, -         get_temp_base(), -         x86_fn_arg( func, 4 ) ); -      x86_mov( -         func, -         get_immediate_base(), -         x86_fn_arg( func, 5 ) ); +	 func, +	 get_coef_base(), +	 x86_fn_arg( func, 4 ) );     } +   x86_mov( +      func, +      get_sampler_base(), +      x86_make_disp( get_machine_base(), +                     Offset( struct tgsi_exec_machine, Samplers ) ) ); + +     while( !tgsi_parse_end_of_tokens( &parse ) && ok ) {        tgsi_parse_token( &parse ); @@ -2727,17 +2932,6 @@ tgsi_emit_sse2(           break;        case TGSI_TOKEN_TYPE_INSTRUCTION: -         if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { -            if( !instruction_phase ) { -               /* INSTRUCTION phase, overwrite coeff with output. */ -               instruction_phase = TRUE; -               x86_mov( -                  func, -                  get_output_base(), -                  x86_fn_arg( func, 2 ) ); -            } -         } -           ok = emit_instruction(              func,              &parse.FullToken.FullInstruction ); @@ -2781,18 +2975,17 @@ tgsi_emit_sse2(     if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX) {        if (do_swizzles) -         soa_to_aos( func, 9, 2, 10, 11 ); +         soa_to_aos( func,  +		     7, 	/* aos_output */ +		     1, 	/* machine */ +		     8, 	/* num_outputs */ +		     9 );	/* output_stride */     }     /* Can't just use EBX, EDI without save/restoring them:      */ -   x86_pop( -      func, -      get_temp_base() ); - -   x86_pop( -      func, -      get_immediate_base() ); +   x86_pop( func, x86_make_reg( file_REG32, reg_DI ) ); +   x86_pop( func, x86_make_reg( file_REG32, reg_BX ) );     emit_ret( func ); diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.h b/src/gallium/auxiliary/tgsi/tgsi_sse2.h index af838b2a25..d81ee3d00e 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_sse2.h +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.h @@ -34,6 +34,7 @@ extern "C" {  struct tgsi_token;  struct x86_function; +struct tgsi_interp_coef;  unsigned  tgsi_emit_sse2( @@ -42,6 +43,33 @@ tgsi_emit_sse2(     float (*immediates)[4],     boolean do_swizzles ); + +/* This is the function prototype generated when do_swizzles is false + * -- effectively for fragment shaders. + */ +typedef void (PIPE_CDECL *tgsi_sse2_fs_function) ( +   struct tgsi_exec_machine *machine, /* 1 */ +   const float (*constant)[4],		    /* 2 */ +   const float (*immediate)[4],		    /* 3 */ +   const struct tgsi_interp_coef *coef	    /* 4 */ +   ); + + +/* This is the function prototype generated when do_swizzles is true + * -- effectively for vertex shaders. + */ +typedef void (PIPE_CDECL *tgsi_sse2_vs_func) ( +   struct tgsi_exec_machine *machine, /* 1 */ +   const float (*constant)[4],        /* 2 */ +   const float (*immediate)[4],       /* 3 */ +   const float (*aos_input)[4], /* 4 */ +   uint num_inputs,             /* 5 */ +   uint input_stride,           /* 6 */ +   float (*aos_output)[4],      /* 7 */ +   uint num_outputs,            /* 8 */ +   uint output_stride );        /* 9 */ + +  #if defined __cplusplus  }  #endif diff --git a/src/gallium/auxiliary/util/Makefile b/src/gallium/auxiliary/util/Makefile index 2995aba1b9..6a8eb73e84 100644 --- a/src/gallium/auxiliary/util/Makefile +++ b/src/gallium/auxiliary/util/Makefile @@ -16,6 +16,7 @@ C_SOURCES = \  	u_hash.c \  	u_keymap.c \  	u_linear.c \ +	u_network.c \  	u_math.c \  	u_mm.c \  	u_rect.c \ diff --git a/src/gallium/auxiliary/util/SConscript b/src/gallium/auxiliary/util/SConscript index d3ac7f747f..fb142eebca 100644 --- a/src/gallium/auxiliary/util/SConscript +++ b/src/gallium/auxiliary/util/SConscript @@ -17,6 +17,7 @@ util = env.ConvenienceLibrary(  		'u_hash.c',  		'u_hash_table.c',  		'u_keymap.c', +		'u_network.c',  		'u_math.c',  		'u_mm.c',  		'u_rect.c', diff --git a/src/gallium/auxiliary/util/u_cache.c b/src/gallium/auxiliary/util/u_cache.c index 41cd38171f..47c16b1c92 100644 --- a/src/gallium/auxiliary/util/u_cache.c +++ b/src/gallium/auxiliary/util/u_cache.c @@ -137,6 +137,8 @@ util_cache_set(struct util_cache *cache,     struct util_cache_entry *entry;     assert(cache); +   if (!cache) +      return;     entry = util_cache_entry_get(cache, key);     util_cache_entry_destroy(cache, entry); @@ -158,6 +160,8 @@ util_cache_get(struct util_cache *cache,     struct util_cache_entry *entry;     assert(cache); +   if (!cache) +      return NULL;     entry = util_cache_entry_get(cache, key);     if(!entry->key && !entry->value) @@ -176,7 +180,9 @@ util_cache_clear(struct util_cache *cache)     uint32_t i;     assert(cache); -    +   if (!cache) +      return; +     for(i = 0; i < cache->size; ++i)        util_cache_entry_destroy(cache, &cache->entries[i]);  } @@ -186,6 +192,8 @@ void  util_cache_destroy(struct util_cache *cache)  {     assert(cache); +   if (!cache) +      return;  #ifdef DEBUG     if(cache->count >= 20*cache->size) { diff --git a/src/gallium/auxiliary/util/u_handle_table.c b/src/gallium/auxiliary/util/u_handle_table.c index 6da7353e25..3703718a62 100644 --- a/src/gallium/auxiliary/util/u_handle_table.c +++ b/src/gallium/auxiliary/util/u_handle_table.c @@ -87,6 +87,8 @@ handle_table_set_destroy(struct handle_table *ht,                           void (*destroy)(void *object))  {     assert(ht); +   if (!ht) +      return;     ht->destroy = destroy;  } @@ -155,7 +157,7 @@ handle_table_add(struct handle_table *ht,     assert(ht);     assert(object); -   if(!object) +   if(!object || !ht)        return 0;     /* linear search for an empty handle */ @@ -193,7 +195,7 @@ handle_table_set(struct handle_table *ht,     assert(ht);     assert(handle); -   if(!handle) +   if(!handle || !ht)        return 0;     assert(object); @@ -222,7 +224,7 @@ handle_table_get(struct handle_table *ht,     assert(ht);     assert(handle); -   if(!handle || handle > ht->size) +   if(!handle || !ht || handle > ht->size)        return NULL;     object = ht->objects[handle - 1]; @@ -240,7 +242,7 @@ handle_table_remove(struct handle_table *ht,     assert(ht);     assert(handle); -   if(!handle || handle > ht->size) +   if(!handle || !ht || handle > ht->size)        return;     index = handle - 1; @@ -283,6 +285,9 @@ handle_table_destroy(struct handle_table *ht)     unsigned index;     assert(ht); +   if (!ht) +      return; +     if(ht->destroy)        for(index = 0; index < ht->size; ++index)           handle_table_clear(ht, index); diff --git a/src/gallium/auxiliary/util/u_hash_table.c b/src/gallium/auxiliary/util/u_hash_table.c index 2f83e318e4..8c2a8f454c 100644 --- a/src/gallium/auxiliary/util/u_hash_table.c +++ b/src/gallium/auxiliary/util/u_hash_table.c @@ -148,6 +148,8 @@ hash_table_set(struct hash_table *ht,     struct cso_hash_iter iter;     assert(ht); +   if (!ht) +      return PIPE_ERROR_BAD_INPUT;     key_hash = ht->hash(key); @@ -183,6 +185,8 @@ hash_table_get(struct hash_table *ht,     struct hash_table_item *item;     assert(ht); +   if (!ht) +      return NULL;     key_hash = ht->hash(key); @@ -203,6 +207,8 @@ hash_table_remove(struct hash_table *ht,     struct hash_table_item *item;     assert(ht); +   if (!ht) +      return;     key_hash = ht->hash(key); @@ -225,7 +231,9 @@ hash_table_clear(struct hash_table *ht)     struct hash_table_item *item;     assert(ht); -    +   if (!ht) +      return; +     iter = cso_hash_first_node(ht->cso);     while (!cso_hash_iter_is_null(iter)) {        item = (struct hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter)); @@ -243,9 +251,11 @@ hash_table_foreach(struct hash_table *ht,     struct cso_hash_iter iter;     struct hash_table_item *item;     enum pipe_error result; -    +     assert(ht); -    +   if (!ht) +      return PIPE_ERROR_BAD_INPUT; +     iter = cso_hash_first_node(ht->cso);     while (!cso_hash_iter_is_null(iter)) {        item = (struct hash_table_item *)cso_hash_iter_data(iter); @@ -264,9 +274,11 @@ hash_table_destroy(struct hash_table *ht)  {     struct cso_hash_iter iter;     struct hash_table_item *item; -    +     assert(ht); -    +   if (!ht) +      return; +     iter = cso_hash_first_node(ht->cso);     while (!cso_hash_iter_is_null(iter)) {        item = (struct hash_table_item *)cso_hash_iter_data(iter); diff --git a/src/gallium/auxiliary/util/u_keymap.c b/src/gallium/auxiliary/util/u_keymap.c index 3f70809efd..508a2ee063 100644 --- a/src/gallium/auxiliary/util/u_keymap.c +++ b/src/gallium/auxiliary/util/u_keymap.c @@ -194,6 +194,8 @@ util_keymap_insert(struct keymap *map, const void *key,     struct cso_hash_iter iter;     assert(map); +   if (!map) +      return FALSE;     key_hash = hash(key, map->key_size); @@ -234,6 +236,8 @@ util_keymap_lookup(const struct keymap *map, const void *key)     struct keymap_item *item;     assert(map); +   if (!map) +      return NULL;     key_hash = hash(key, map->key_size); @@ -258,6 +262,8 @@ util_keymap_remove(struct keymap *map, const void *key, void *user)     struct keymap_item *item;     assert(map); +   if (!map) +      return;     key_hash = hash(key, map->key_size); @@ -267,6 +273,8 @@ util_keymap_remove(struct keymap *map, const void *key, void *user)     item = hash_table_item(iter);     assert(item); +   if (!item) +      return;     map->delete_func(map, item->key, item->value, user);     FREE(item->key);     FREE(item); @@ -288,7 +296,9 @@ util_keymap_remove_all(struct keymap *map, void *user)     struct keymap_item *item;     assert(map); -    +   if (!map) +      return; +     iter = cso_hash_first_node(map->cso);     while (!cso_hash_iter_is_null(iter)) {        item = (struct keymap_item *) diff --git a/src/gallium/auxiliary/util/u_network.c b/src/gallium/auxiliary/util/u_network.c new file mode 100644 index 0000000000..07d804ecdb --- /dev/null +++ b/src/gallium/auxiliary/util/u_network.c @@ -0,0 +1,188 @@ + +#include "pipe/p_compiler.h" +#include "util/u_network.h" +#include "util/u_debug.h" + +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +#  include <winsock2.h> +#  include <windows.h> +#elif defined(PIPE_OS_LINUX) +#  include <sys/socket.h> +#  include <netinet/in.h> +#  include <unistd.h> +#  include <fcntl.h> +#  include <netdb.h> +#else +#  warning "No socket implementation" +#endif + +boolean +u_socket_init() +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   WORD wVersionRequested; +   WSADATA wsaData; +   int err; + +   /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ +   wVersionRequested = MAKEWORD(1, 1); + +   err = WSAStartup(wVersionRequested, &wsaData); +   if (err != 0) { +      debug_printf("WSAStartup failed with error: %d\n", err); +      return FALSE; +   } +   return TRUE; +#elif defined(PIPE_HAVE_SOCKETS) +   return TRUE; +#else +   return FALSE; +#endif +} + +void +u_socket_stop() +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   WSACleanup(); +#endif +} + +void +u_socket_close(int s) +{ +   if (s < 0) +      return; + +#if defined(PIPE_OS_LINUX) +   shutdown(s, SHUT_RDWR); +   close(s); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   shutdown(s, SD_BOTH); +   closesocket(s); +#else +   assert(0); +#endif +} + +int u_socket_accept(int s) +{ +#if defined(PIPE_HAVE_SOCKETS) +   return accept(s, NULL, NULL); +#else +   return -1; +#endif +} + +int +u_socket_send(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) +   return send(s, data, size, 0); +#else +   return -1; +#endif +} + +int +u_socket_peek(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) +   return recv(s, data, size, MSG_PEEK); +#else +   return -1; +#endif +} + +int +u_socket_recv(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) +   return recv(s, data, size, 0); +#else +   return -1; +#endif +} + +int +u_socket_connect(const char *hostname, uint16_t port) +{ +#if defined(PIPE_HAVE_SOCKETS) +   int s; +   struct sockaddr_in sa; +   struct hostent *host = NULL; + +   memset(&sa, 0, sizeof(struct sockaddr_in)); +   host = gethostbyname(hostname); +   if (!host) +      return -1; + +   memcpy((char *)&sa.sin_addr,host->h_addr,host->h_length); +   sa.sin_family= host->h_addrtype; +   sa.sin_port = htons(port); + +   s = socket(host->h_addrtype, SOCK_STREAM, IPPROTO_TCP); +   if (s < 0) +      return -1; + +   if (connect(s, (struct sockaddr *)&sa, sizeof(sa))) { +      u_socket_close(s); +      return -1; +   } + +   return s; +#else +   assert(0); +   return -1; +#endif +} + +int +u_socket_listen_on_port(uint16_t portnum) +{ +#if defined(PIPE_HAVE_SOCKETS) +   int s; +   struct sockaddr_in sa; +   memset(&sa, 0, sizeof(struct sockaddr_in)); + +   sa.sin_family = AF_INET; +   sa.sin_port = htons(portnum); + +   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); +   if (s < 0) +      return -1; + +   if (bind(s, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) == -1) { +      u_socket_close(s); +      return -1; +   } + +   listen(s, 0); + +   return s; +#else +   assert(0); +   return -1; +#endif +} + +void +u_socket_block(int s, boolean block) +{ +#if defined(PIPE_OS_LINUX) +   int old = fcntl(s, F_GETFL, 0); +   if (old == -1) +      return; + +   /* TODO obey block */ +   if (block) +      fcntl(s, F_SETFL, old & ~O_NONBLOCK); +   else +      fcntl(s, F_SETFL, old | O_NONBLOCK); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +   u_long iMode = block ? 0 : 1; +   ioctlsocket(s, FIONBIO, &iMode); +#else +   assert(0); +#endif +} diff --git a/src/gallium/auxiliary/util/u_network.h b/src/gallium/auxiliary/util/u_network.h new file mode 100644 index 0000000000..14d3884427 --- /dev/null +++ b/src/gallium/auxiliary/util/u_network.h @@ -0,0 +1,24 @@ + +#ifndef _U_NETWORK_H_ +#define _U_NETWORK_H_ + +#include "pipe/p_compiler.h" + +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +#  define PIPE_HAVE_SOCKETS +#elif defined(PIPE_OS_LINUX) +#  define PIPE_HAVE_SOCKETS +#endif + +boolean u_socket_init(void); +void u_socket_stop(void); +void u_socket_close(int s); +int u_socket_listen_on_port(uint16_t portnum); +int u_socket_accept(int s); +int u_socket_connect(const char *host, uint16_t port); +int u_socket_send(int s, void *data, size_t size); +int u_socket_peek(int s, void *data, size_t size); +int u_socket_recv(int s, void *data, size_t size); +void u_socket_block(int s, boolean block); + +#endif diff --git a/src/gallium/auxiliary/util/u_prim.h b/src/gallium/auxiliary/util/u_prim.h index d7c3995dbf..a9b533eea7 100644 --- a/src/gallium/auxiliary/util/u_prim.h +++ b/src/gallium/auxiliary/util/u_prim.h @@ -119,7 +119,7 @@ static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr )  } -static INLINE boolean u_reduced_prim( unsigned pipe_prim ) +static INLINE unsigned u_reduced_prim( unsigned pipe_prim )  {     switch (pipe_prim) {     case PIPE_PRIM_POINTS:  | 
