Home | History | Annotate | Download | only in llvmpipe
      1 /**************************************************************************
      2  *
      3  * Copyright 2007-2009 VMware, Inc.
      4  * All Rights Reserved.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the
      8  * "Software"), to deal in the Software without restriction, including
      9  * without limitation the rights to use, copy, modify, merge, publish,
     10  * distribute, sub license, and/or sell copies of the Software, and to
     11  * permit persons to whom the Software is furnished to do so, subject to
     12  * the following conditions:
     13  *
     14  * The above copyright notice and this permission notice (including the
     15  * next paragraph) shall be included in all copies or substantial portions
     16  * of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
     22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25  *
     26  **************************************************************************/
     27 
     28 
     29 /**
     30  * The setup code is concerned with point/line/triangle setup and
     31  * putting commands/data into the bins.
     32  */
     33 
     34 
     35 #ifndef LP_SETUP_CONTEXT_H
     36 #define LP_SETUP_CONTEXT_H
     37 
     38 #include "lp_setup.h"
     39 #include "lp_rast.h"
     40 #include "lp_tile_soa.h"        /* for TILE_SIZE */
     41 #include "lp_scene.h"
     42 #include "lp_bld_interp.h"	/* for struct lp_shader_input */
     43 
     44 #include "draw/draw_vbuf.h"
     45 #include "util/u_rect.h"
     46 
     47 #define LP_SETUP_NEW_FS          0x01
     48 #define LP_SETUP_NEW_CONSTANTS   0x02
     49 #define LP_SETUP_NEW_BLEND_COLOR 0x04
     50 #define LP_SETUP_NEW_SCISSOR     0x08
     51 
     52 
     53 struct lp_setup_variant;
     54 
     55 
     56 /** Max number of scenes */
     57 #define MAX_SCENES 2
     58 
     59 
     60 
     61 /**
     62  * Point/line/triangle setup context.
     63  * Note: "stored" below indicates data which is stored in the bins,
     64  * not arbitrary malloc'd memory.
     65  *
     66  *
     67  * Subclass of vbuf_render, plugged directly into the draw module as
     68  * the rendering backend.
     69  */
     70 struct lp_setup_context
     71 {
     72    struct vbuf_render base;
     73 
     74    struct pipe_context *pipe;
     75    struct vertex_info *vertex_info;
     76    uint prim;
     77    uint vertex_size;
     78    uint nr_vertices;
     79    uint sprite_coord_enable, sprite_coord_origin;
     80    uint vertex_buffer_size;
     81    void *vertex_buffer;
     82 
     83    /* Final pipeline stage for draw module.  Draw module should
     84     * create/install this itself now.
     85     */
     86    struct draw_stage *vbuf;
     87    unsigned num_threads;
     88    unsigned scene_idx;
     89    struct lp_scene *scenes[MAX_SCENES];  /**< all the scenes */
     90    struct lp_scene *scene;               /**< current scene being built */
     91 
     92    struct lp_fence *last_fence;
     93    struct llvmpipe_query *active_query;
     94 
     95    boolean flatshade_first;
     96    boolean ccw_is_frontface;
     97    boolean scissor_test;
     98    boolean point_size_per_vertex;
     99    unsigned cullmode;
    100    float pixel_offset;
    101    float line_width;
    102    float point_size;
    103    float psize;
    104 
    105    struct pipe_framebuffer_state fb;
    106    struct u_rect framebuffer;
    107    struct u_rect scissor;
    108    struct u_rect draw_region;   /* intersection of fb & scissor */
    109 
    110    struct {
    111       unsigned flags;
    112       union lp_rast_cmd_arg color;    /**< lp_rast_clear_color() cmd */
    113       unsigned zsmask;
    114       unsigned zsvalue;               /**< lp_rast_clear_zstencil() cmd */
    115    } clear;
    116 
    117    enum setup_state {
    118       SETUP_FLUSHED,    /**< scene is null */
    119       SETUP_CLEARED,    /**< scene exists but has only clears */
    120       SETUP_ACTIVE      /**< scene exists and has at least one draw/query */
    121    } state;
    122 
    123    struct {
    124       const struct lp_rast_state *stored; /**< what's in the scene */
    125       struct lp_rast_state current;  /**< currently set state */
    126       struct pipe_resource *current_tex[PIPE_MAX_SAMPLERS];
    127    } fs;
    128 
    129    /** fragment shader constants */
    130    struct {
    131       struct pipe_resource *current;
    132       unsigned stored_size;
    133       const void *stored_data;
    134    } constants;
    135 
    136    struct {
    137       struct pipe_blend_color current;
    138       uint8_t *stored;
    139    } blend_color;
    140 
    141 
    142    struct {
    143       const struct lp_setup_variant *variant;
    144    } setup;
    145 
    146    unsigned dirty;   /**< bitmask of LP_SETUP_NEW_x bits */
    147 
    148    void (*point)( struct lp_setup_context *,
    149                   const float (*v0)[4]);
    150 
    151    void (*line)( struct lp_setup_context *,
    152                  const float (*v0)[4],
    153                  const float (*v1)[4]);
    154 
    155    void (*triangle)( struct lp_setup_context *,
    156                      const float (*v0)[4],
    157                      const float (*v1)[4],
    158                      const float (*v2)[4]);
    159 };
    160 
    161 void lp_setup_choose_triangle( struct lp_setup_context *setup );
    162 void lp_setup_choose_line( struct lp_setup_context *setup );
    163 void lp_setup_choose_point( struct lp_setup_context *setup );
    164 
    165 void lp_setup_init_vbuf(struct lp_setup_context *setup);
    166 
    167 boolean lp_setup_update_state( struct lp_setup_context *setup,
    168                             boolean update_scene);
    169 
    170 void lp_setup_destroy( struct lp_setup_context *setup );
    171 
    172 boolean lp_setup_flush_and_restart(struct lp_setup_context *setup);
    173 
    174 void
    175 lp_setup_print_triangle(struct lp_setup_context *setup,
    176                         const float (*v0)[4],
    177                         const float (*v1)[4],
    178                         const float (*v2)[4]);
    179 
    180 void
    181 lp_setup_print_vertex(struct lp_setup_context *setup,
    182                       const char *name,
    183                       const float (*v)[4]);
    184 
    185 
    186 struct lp_rast_triangle *
    187 lp_setup_alloc_triangle(struct lp_scene *scene,
    188                         unsigned num_inputs,
    189                         unsigned nr_planes,
    190                         unsigned *tri_size);
    191 
    192 boolean
    193 lp_setup_bin_triangle( struct lp_setup_context *setup,
    194                        struct lp_rast_triangle *tri,
    195                        const struct u_rect *bbox,
    196                        int nr_planes );
    197 
    198 #endif
    199