Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**********************************************************
  2.  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person
  5.  * obtaining a copy of this software and associated documentation
  6.  * files (the "Software"), to deal in the Software without
  7.  * restriction, including without limitation the rights to use, copy,
  8.  * modify, merge, publish, distribute, sublicense, and/or sell copies
  9.  * of the Software, and to permit persons to whom the Software is
  10.  * furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice shall be
  13.  * included in all copies or substantial portions of the Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19.  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20.  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  *
  24.  **********************************************************/
  25.  
  26. #ifndef SVGA_CONTEXT_H
  27. #define SVGA_CONTEXT_H
  28.  
  29.  
  30. #include "pipe/p_context.h"
  31. #include "pipe/p_defines.h"
  32. #include "pipe/p_state.h"
  33.  
  34. #include "util/u_blitter.h"
  35. #include "util/u_double_list.h"
  36.  
  37. #include "tgsi/tgsi_scan.h"
  38.  
  39. #include "svga_state.h"
  40. #include "svga_tgsi.h"
  41. #include "svga_hw_reg.h"
  42. #include "svga3d_shaderdefs.h"
  43.  
  44.  
  45. /** Non-GPU queries for gallium HUD */
  46. #define SVGA_QUERY_DRAW_CALLS   (PIPE_QUERY_DRIVER_SPECIFIC + 0)
  47. #define SVGA_QUERY_FALLBACKS    (PIPE_QUERY_DRIVER_SPECIFIC + 1)
  48. #define SVGA_QUERY_MEMORY_USED  (PIPE_QUERY_DRIVER_SPECIFIC + 2)
  49.  
  50.  
  51. struct draw_vertex_shader;
  52. struct draw_fragment_shader;
  53. struct svga_shader_result;
  54. struct SVGACmdMemory;
  55. struct util_bitmask;
  56. struct u_upload_mgr;
  57.  
  58.  
  59. struct svga_shader
  60. {
  61.    const struct tgsi_token *tokens;
  62.  
  63.    struct tgsi_shader_info info;
  64.  
  65.    struct svga_shader_result *results;
  66.  
  67.    unsigned id;  /**< for debugging only */
  68. };
  69.  
  70. struct svga_fragment_shader
  71. {
  72.    struct svga_shader base;
  73.  
  74.    struct draw_fragment_shader *draw_shader;
  75.  
  76.    /** Mask of which generic varying variables are read by this shader */
  77.    unsigned generic_inputs;
  78.    /** Table mapping original TGSI generic indexes to low integers */
  79.    int8_t generic_remap_table[MAX_GENERIC_VARYING];
  80. };
  81.  
  82. struct svga_vertex_shader
  83. {
  84.    struct svga_shader base;
  85.  
  86.    struct draw_vertex_shader *draw_shader;
  87. };
  88.  
  89.  
  90. struct svga_cache_context;
  91. struct svga_tracked_state;
  92.  
  93. struct svga_blend_state {
  94.  
  95.    boolean need_white_fragments;
  96.  
  97.    /* Should be per-render-target:
  98.     */
  99.    struct {
  100.       uint8_t writemask;
  101.  
  102.       boolean blend_enable;
  103.       uint8_t srcblend;
  104.       uint8_t dstblend;
  105.       uint8_t blendeq;
  106.      
  107.       boolean separate_alpha_blend_enable;
  108.       uint8_t srcblend_alpha;
  109.       uint8_t dstblend_alpha;
  110.       uint8_t blendeq_alpha;
  111.  
  112.    } rt[1];
  113. };
  114.  
  115. struct svga_depth_stencil_state {
  116.    unsigned zfunc:8;
  117.    unsigned zenable:1;
  118.    unsigned zwriteenable:1;
  119.  
  120.    unsigned alphatestenable:1;
  121.    unsigned alphafunc:8;
  122.  
  123.    struct {
  124.       unsigned enabled:1;
  125.       unsigned func:8;
  126.       unsigned fail:8;
  127.       unsigned zfail:8;
  128.       unsigned pass:8;
  129.    } stencil[2];
  130.    
  131.    /* SVGA3D has one ref/mask/writemask triple shared between front &
  132.     * back face stencil.  We really need two:
  133.     */
  134.    unsigned stencil_mask:8;
  135.    unsigned stencil_writemask:8;
  136.  
  137.    float    alpharef;
  138. };
  139.  
  140. #define SVGA_UNFILLED_DISABLE 0
  141. #define SVGA_UNFILLED_LINE    1
  142. #define SVGA_UNFILLED_POINT   2
  143.  
  144. #define SVGA_PIPELINE_FLAG_POINTS   (1<<PIPE_PRIM_POINTS)
  145. #define SVGA_PIPELINE_FLAG_LINES    (1<<PIPE_PRIM_LINES)
  146. #define SVGA_PIPELINE_FLAG_TRIS     (1<<PIPE_PRIM_TRIANGLES)
  147.  
  148. struct svga_rasterizer_state {
  149.    struct pipe_rasterizer_state templ; /* needed for draw module */
  150.  
  151.    unsigned shademode:8;
  152.    unsigned cullmode:8;
  153.    unsigned scissortestenable:1;
  154.    unsigned multisampleantialias:1;
  155.    unsigned antialiasedlineenable:1;
  156.    unsigned lastpixel:1;
  157.    unsigned pointsprite:1;
  158.  
  159.    unsigned linepattern;
  160.  
  161.    float slopescaledepthbias;
  162.    float depthbias;
  163.    float pointsize;
  164.    
  165.    unsigned hw_unfilled:16;         /* PIPE_POLYGON_MODE_x */
  166.  
  167.    /** Which prims do we need help for?  Bitmask of (1 << PIPE_PRIM_x) flags */
  168.    unsigned need_pipeline:16;
  169.  
  170.    /** For debugging: */
  171.    const char* need_pipeline_tris_str;
  172.    const char* need_pipeline_lines_str;
  173.    const char* need_pipeline_points_str;
  174. };
  175.  
  176. struct svga_sampler_state {
  177.    unsigned mipfilter;
  178.    unsigned magfilter;
  179.    unsigned minfilter;
  180.    unsigned aniso_level;
  181.    float lod_bias;
  182.    unsigned addressu;
  183.    unsigned addressv;
  184.    unsigned addressw;
  185.    unsigned bordercolor;
  186.    unsigned normalized_coords:1;
  187.    unsigned compare_mode:1;
  188.    unsigned compare_func:3;
  189.  
  190.    unsigned min_lod;
  191.    unsigned view_min_lod;
  192.    unsigned view_max_lod;
  193. };
  194.  
  195. struct svga_velems_state {
  196.    unsigned count;
  197.    struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
  198. };
  199.  
  200. /* Use to calculate differences between state emitted to hardware and
  201.  * current driver-calculated state.  
  202.  */
  203. struct svga_state
  204. {
  205.    const struct svga_blend_state *blend;
  206.    const struct svga_depth_stencil_state *depth;
  207.    const struct svga_rasterizer_state *rast;
  208.    const struct svga_sampler_state *sampler[PIPE_MAX_SAMPLERS];
  209.    const struct svga_velems_state *velems;
  210.  
  211.    struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; /* or texture ID's? */
  212.    struct svga_fragment_shader *fs;
  213.    struct svga_vertex_shader *vs;
  214.  
  215.    struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
  216.    struct pipe_index_buffer ib;
  217.    struct pipe_resource *cb[PIPE_SHADER_TYPES];
  218.  
  219.    struct pipe_framebuffer_state framebuffer;
  220.    float depthscale;
  221.  
  222.    /* Hack to limit the number of different render targets between
  223.     * flushes.  Helps avoid blowing out our surface cache in EXA.
  224.     */
  225.    int nr_fbs;
  226.  
  227.    struct pipe_poly_stipple poly_stipple;
  228.    struct pipe_scissor_state scissor;
  229.    struct pipe_blend_color blend_color;
  230.    struct pipe_stencil_ref stencil_ref;
  231.    struct pipe_clip_state clip;
  232.    struct pipe_viewport_state viewport;
  233.  
  234.    unsigned num_samplers;
  235.    unsigned num_sampler_views;
  236.    unsigned num_vertex_buffers;
  237.    unsigned reduced_prim;
  238.  
  239.    struct {
  240.       unsigned flag_1d;
  241.       unsigned flag_srgb;
  242.    } tex_flags;
  243. };
  244.  
  245. struct svga_prescale {
  246.    float translate[4];
  247.    float scale[4];
  248.    boolean enabled;
  249. };
  250.  
  251.  
  252. /* Updated by calling svga_update_state( SVGA_STATE_HW_CLEAR )
  253.  */
  254. struct svga_hw_clear_state
  255. {
  256.    struct {
  257.       unsigned x,y,w,h;
  258.    } viewport;
  259.  
  260.    struct {
  261.       float zmin, zmax;
  262.    } depthrange;
  263.    
  264.    struct pipe_framebuffer_state framebuffer;
  265.    struct svga_prescale prescale;
  266. };
  267.  
  268. struct svga_hw_view_state
  269. {
  270.    struct pipe_resource *texture;
  271.    struct svga_sampler_view *v;
  272.    unsigned min_lod;
  273.    unsigned max_lod;
  274.    int dirty;
  275. };
  276.  
  277. /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
  278.  */
  279. struct svga_hw_draw_state
  280. {
  281.    unsigned rs[SVGA3D_RS_MAX];
  282.    unsigned ts[SVGA3D_PIXEL_SAMPLERREG_MAX][SVGA3D_TS_MAX];
  283.    float cb[PIPE_SHADER_TYPES][SVGA3D_CONSTREG_MAX][4];
  284.  
  285.    struct svga_shader_result *fs;
  286.    struct svga_shader_result *vs;
  287.    struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
  288.  
  289.    unsigned num_views;
  290. };
  291.  
  292.  
  293. /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
  294.  */
  295. struct svga_sw_state
  296. {
  297.    unsigned ve_format[PIPE_MAX_ATTRIBS]; /* NEW_VELEMENT */
  298.  
  299.    /* which parts we need */
  300.    boolean need_swvfetch;
  301.    boolean need_pipeline;
  302.    boolean need_swtnl;
  303.  
  304.    /* Flag to make sure that need sw is on while
  305.     * updating state within a swtnl call.
  306.     */
  307.    boolean in_swtnl_draw;
  308. };
  309.  
  310.  
  311. /* Queue some state updates (like rss) and submit them to hardware in
  312.  * a single packet.
  313.  */
  314. struct svga_hw_queue;
  315.  
  316. struct svga_query;
  317.  
  318. struct svga_context
  319. {
  320.    struct pipe_context pipe;
  321.    struct svga_winsys_context *swc;
  322.    struct blitter_context *blitter;
  323.  
  324.    struct {
  325.       boolean no_swtnl;
  326.       boolean force_swtnl;
  327.       boolean use_min_mipmap;
  328.  
  329.       /* incremented for each shader */
  330.       unsigned shader_id;
  331.  
  332.       unsigned disable_shader;
  333.  
  334.       boolean no_line_width;
  335.       boolean force_hw_line_stipple;
  336.    } debug;
  337.  
  338.    struct {
  339.       struct draw_context *draw;
  340.       struct vbuf_render *backend;
  341.       unsigned hw_prim;
  342.       boolean new_vbuf;
  343.       boolean new_vdecl;
  344.    } swtnl;
  345.  
  346.    /* Bitmask of used shader IDs */
  347.    struct util_bitmask *fs_bm;
  348.    struct util_bitmask *vs_bm;
  349.  
  350.    struct {
  351.       unsigned dirty[SVGA_STATE_MAX];
  352.  
  353.       unsigned texture_timestamp;
  354.  
  355.       /*
  356.        */
  357.       struct svga_sw_state          sw;
  358.       struct svga_hw_draw_state     hw_draw;
  359.       struct svga_hw_clear_state    hw_clear;
  360.    } state;
  361.  
  362.    struct svga_state curr;      /* state from the state tracker */
  363.    unsigned dirty;              /* statechanges since last update_state() */
  364.  
  365.    struct {
  366.       unsigned rendertargets:1;
  367.       unsigned texture_samplers:1;
  368.    } rebind;
  369.  
  370.    struct u_upload_mgr *upload_ib;
  371.    struct u_upload_mgr *upload_vb;
  372.    struct svga_hwtnl *hwtnl;
  373.  
  374.    /** The occlusion query currently in progress */
  375.    struct svga_query *sq;
  376.  
  377.    /** List of buffers with queued transfers */
  378.    struct list_head dirty_buffers;
  379.  
  380.    /** performance / info queries */
  381.    uint64_t num_draw_calls;  /**< SVGA_QUERY_DRAW_CALLS */
  382.    uint64_t num_fallbacks;   /**< SVGA_QUERY_FALLBACKS */
  383. };
  384.  
  385. /* A flag for each state_tracker state object:
  386.  */
  387. #define SVGA_NEW_BLEND               0x1
  388. #define SVGA_NEW_DEPTH_STENCIL       0x2
  389. #define SVGA_NEW_RAST                0x4
  390. #define SVGA_NEW_SAMPLER             0x8
  391. #define SVGA_NEW_TEXTURE             0x10
  392. #define SVGA_NEW_VBUFFER             0x20
  393. #define SVGA_NEW_VELEMENT            0x40
  394. #define SVGA_NEW_FS                  0x80
  395. #define SVGA_NEW_VS                  0x100
  396. #define SVGA_NEW_FS_CONST_BUFFER     0x200
  397. #define SVGA_NEW_VS_CONST_BUFFER     0x400
  398. #define SVGA_NEW_FRAME_BUFFER        0x800
  399. #define SVGA_NEW_STIPPLE             0x1000
  400. #define SVGA_NEW_SCISSOR             0x2000
  401. #define SVGA_NEW_BLEND_COLOR         0x4000
  402. #define SVGA_NEW_CLIP                0x8000
  403. #define SVGA_NEW_VIEWPORT            0x10000
  404. #define SVGA_NEW_PRESCALE            0x20000
  405. #define SVGA_NEW_REDUCED_PRIMITIVE   0x40000
  406. #define SVGA_NEW_TEXTURE_BINDING     0x80000
  407. #define SVGA_NEW_NEED_PIPELINE       0x100000
  408. #define SVGA_NEW_NEED_SWVFETCH       0x200000
  409. #define SVGA_NEW_NEED_SWTNL          0x400000
  410. #define SVGA_NEW_FS_RESULT           0x800000
  411. #define SVGA_NEW_VS_RESULT           0x1000000
  412. #define SVGA_NEW_TEXTURE_FLAGS       0x4000000
  413. #define SVGA_NEW_STENCIL_REF         0x8000000
  414.  
  415.  
  416.  
  417.  
  418.  
  419. /***********************************************************************
  420.  * svga_clear.c:
  421.  */
  422. void svga_clear(struct pipe_context *pipe,
  423.                 unsigned buffers,
  424.                 const union pipe_color_union *color,
  425.                 double depth,
  426.                 unsigned stencil);
  427.  
  428.  
  429. /***********************************************************************
  430.  * svga_screen_texture.c:
  431.  */
  432. void svga_mark_surfaces_dirty(struct svga_context *svga);
  433.  
  434.  
  435.  
  436.  
  437. void svga_init_state_functions( struct svga_context *svga );
  438. void svga_init_flush_functions( struct svga_context *svga );
  439. void svga_init_string_functions( struct svga_context *svga );
  440. void svga_init_blit_functions(struct svga_context *svga);
  441.  
  442. void svga_init_blend_functions( struct svga_context *svga );
  443. void svga_init_depth_stencil_functions( struct svga_context *svga );
  444. void svga_init_misc_functions( struct svga_context *svga );
  445. void svga_init_rasterizer_functions( struct svga_context *svga );
  446. void svga_init_sampler_functions( struct svga_context *svga );
  447. void svga_init_fs_functions( struct svga_context *svga );
  448. void svga_init_vs_functions( struct svga_context *svga );
  449. void svga_init_vertex_functions( struct svga_context *svga );
  450. void svga_init_constbuffer_functions( struct svga_context *svga );
  451. void svga_init_draw_functions( struct svga_context *svga );
  452. void svga_init_query_functions( struct svga_context *svga );
  453. void svga_init_surface_functions(struct svga_context *svga);
  454.  
  455. void svga_cleanup_vertex_state( struct svga_context *svga );
  456. void svga_cleanup_tss_binding( struct svga_context *svga );
  457. void svga_cleanup_framebuffer( struct svga_context *svga );
  458.  
  459. void svga_context_flush( struct svga_context *svga,
  460.                          struct pipe_fence_handle **pfence );
  461.  
  462. void svga_hwtnl_flush_retry( struct svga_context *svga );
  463. void svga_hwtnl_flush_buffer( struct svga_context *svga,
  464.                               struct pipe_resource *buffer );
  465.  
  466. void svga_surfaces_flush(struct svga_context *svga);
  467.  
  468. struct pipe_context *
  469. svga_context_create(struct pipe_screen *screen,
  470.                     void *priv);
  471.  
  472.  
  473. /***********************************************************************
  474.  * Inline conversion functions.  These are better-typed than the
  475.  * macros used previously:
  476.  */
  477. static INLINE struct svga_context *
  478. svga_context( struct pipe_context *pipe )
  479. {
  480.    return (struct svga_context *)pipe;
  481. }
  482.  
  483.  
  484.  
  485. #endif
  486.