Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2012-2014 LunarG, Inc.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included
  14.  * in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Chia-I Wu <olv@lunarg.com>
  26.  */
  27.  
  28. #ifndef ILO_STATE_3D_H
  29. #define ILO_STATE_3D_H
  30.  
  31. #include "genhw/genhw.h"
  32. #include "pipe/p_state.h"
  33.  
  34. #include "ilo_core.h"
  35. #include "ilo_dev.h"
  36.  
  37. /**
  38.  * \see brw_context.h
  39.  */
  40. #define ILO_MAX_DRAW_BUFFERS    8
  41. #define ILO_MAX_CONST_BUFFERS   (1 + 12)
  42. #define ILO_MAX_SAMPLER_VIEWS   16
  43. #define ILO_MAX_SAMPLERS        16
  44. #define ILO_MAX_SO_BINDINGS     64
  45. #define ILO_MAX_SO_BUFFERS      4
  46. #define ILO_MAX_VIEWPORTS       1
  47.  
  48. #define ILO_MAX_SURFACES        256
  49.  
  50. struct intel_bo;
  51. struct ilo_buffer;
  52. struct ilo_image;
  53. struct ilo_shader_state;
  54.  
  55. struct ilo_vb_state {
  56.    struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
  57.    uint32_t enabled_mask;
  58. };
  59.  
  60. struct ilo_ib_state {
  61.    struct pipe_resource *buffer;
  62.    const void *user_buffer;
  63.    unsigned offset;
  64.    unsigned index_size;
  65.  
  66.    /* these are not valid until the state is finalized */
  67.    struct pipe_resource *hw_resource;
  68.    unsigned hw_index_size;
  69.    /* an offset to be added to pipe_draw_info::start */
  70.    int64_t draw_start_offset;
  71. };
  72.  
  73. struct ilo_ve_cso {
  74.    /* VERTEX_ELEMENT_STATE */
  75.    uint32_t payload[2];
  76. };
  77.  
  78. struct ilo_ve_state {
  79.    struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
  80.    unsigned count;
  81.  
  82.    unsigned instance_divisors[PIPE_MAX_ATTRIBS];
  83.    unsigned vb_mapping[PIPE_MAX_ATTRIBS];
  84.    unsigned vb_count;
  85.  
  86.    /* these are not valid until the state is finalized */
  87.    struct ilo_ve_cso edgeflag_cso;
  88.    bool last_cso_edgeflag;
  89.  
  90.    struct ilo_ve_cso nosrc_cso;
  91.    bool prepend_nosrc_cso;
  92. };
  93.  
  94. struct ilo_so_state {
  95.    struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
  96.    unsigned count;
  97.    unsigned append_bitmask;
  98.  
  99.    bool enabled;
  100. };
  101.  
  102. struct ilo_viewport_cso {
  103.    /* matrix form */
  104.    float m00, m11, m22, m30, m31, m32;
  105.  
  106.    /* guardband in NDC space */
  107.    float min_gbx, min_gby, max_gbx, max_gby;
  108.  
  109.    /* viewport in screen space */
  110.    float min_x, min_y, min_z;
  111.    float max_x, max_y, max_z;
  112. };
  113.  
  114. struct ilo_viewport_state {
  115.    struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
  116.    unsigned count;
  117.  
  118.    struct pipe_viewport_state viewport0;
  119. };
  120.  
  121. struct ilo_scissor_state {
  122.    /* SCISSOR_RECT */
  123.    uint32_t payload[ILO_MAX_VIEWPORTS * 2];
  124.  
  125.    struct pipe_scissor_state scissor0;
  126. };
  127.  
  128. struct ilo_rasterizer_clip {
  129.    /* 3DSTATE_CLIP */
  130.    uint32_t payload[3];
  131.  
  132.    uint32_t can_enable_guardband;
  133. };
  134.  
  135. struct ilo_rasterizer_sf {
  136.    /* 3DSTATE_SF */
  137.    uint32_t payload[3];
  138.    uint32_t dw_msaa;
  139.  
  140.    /* Global Depth Offset Constant/Scale/Clamp */
  141.    uint32_t dw_depth_offset_const;
  142.    uint32_t dw_depth_offset_scale;
  143.    uint32_t dw_depth_offset_clamp;
  144.  
  145.    /* Gen8+ 3DSTATE_RASTER */
  146.    uint32_t dw_raster;
  147. };
  148.  
  149. struct ilo_rasterizer_wm {
  150.    /* 3DSTATE_WM */
  151.    uint32_t payload[2];
  152.    uint32_t dw_msaa_rast;
  153.    uint32_t dw_msaa_disp;
  154. };
  155.  
  156. struct ilo_rasterizer_state {
  157.    struct pipe_rasterizer_state state;
  158.  
  159.    struct ilo_rasterizer_clip clip;
  160.    struct ilo_rasterizer_sf sf;
  161.    struct ilo_rasterizer_wm wm;
  162. };
  163.  
  164. struct ilo_dsa_state {
  165.    /* DEPTH_STENCIL_STATE or Gen8+ 3DSTATE_WM_DEPTH_STENCIL */
  166.    uint32_t payload[3];
  167.  
  168.    uint32_t dw_blend_alpha;
  169.    uint32_t dw_ps_blend_alpha;
  170.    ubyte alpha_ref;
  171. };
  172.  
  173. struct ilo_blend_cso {
  174.    /* BLEND_STATE */
  175.    uint32_t payload[2];
  176.  
  177.    uint32_t dw_blend;
  178.    uint32_t dw_blend_dst_alpha_forced_one;
  179. };
  180.  
  181. struct ilo_blend_state {
  182.    struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
  183.  
  184.    bool dual_blend;
  185.    bool alpha_to_coverage;
  186.  
  187.    uint32_t dw_shared;
  188.    uint32_t dw_alpha_mod;
  189.    uint32_t dw_logicop;
  190.  
  191.    /* a part of 3DSTATE_PS_BLEND */
  192.    uint32_t dw_ps_blend;
  193.    uint32_t dw_ps_blend_dst_alpha_forced_one;
  194. };
  195.  
  196. struct ilo_sampler_cso {
  197.    /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
  198.    uint32_t payload[15];
  199.  
  200.    uint32_t dw_filter;
  201.    uint32_t dw_filter_aniso;
  202.    uint32_t dw_wrap;
  203.    uint32_t dw_wrap_1d;
  204.    uint32_t dw_wrap_cube;
  205.  
  206.    bool anisotropic;
  207.    bool saturate_r;
  208.    bool saturate_s;
  209.    bool saturate_t;
  210. };
  211.  
  212. struct ilo_sampler_state {
  213.    const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
  214. };
  215.  
  216. struct ilo_view_surface {
  217.    /* SURFACE_STATE */
  218.    uint32_t payload[13];
  219.    struct intel_bo *bo;
  220.  
  221.    uint32_t scanout;
  222. };
  223.  
  224. struct ilo_view_cso {
  225.    struct pipe_sampler_view base;
  226.  
  227.    struct ilo_view_surface surface;
  228. };
  229.  
  230. struct ilo_view_state {
  231.    struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
  232.    unsigned count;
  233. };
  234.  
  235. struct ilo_cbuf_cso {
  236.    struct pipe_resource *resource;
  237.    struct ilo_view_surface surface;
  238.  
  239.    /*
  240.     * this CSO is not so constant because user buffer needs to be uploaded in
  241.     * finalize_constant_buffers()
  242.     */
  243.    const void *user_buffer;
  244.    unsigned user_buffer_size;
  245. };
  246.  
  247. struct ilo_cbuf_state {
  248.    struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
  249.    uint32_t enabled_mask;
  250. };
  251.  
  252. struct ilo_resource_state {
  253.    struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
  254.    unsigned count;
  255. };
  256.  
  257. struct ilo_surface_cso {
  258.    struct pipe_surface base;
  259.  
  260.    bool is_rt;
  261.    union {
  262.       struct ilo_view_surface rt;
  263.       struct ilo_zs_surface {
  264.          uint32_t payload[12];
  265.          uint32_t dw_aligned_8x4;
  266.  
  267.          struct intel_bo *bo;
  268.          struct intel_bo *hiz_bo;
  269.          struct intel_bo *separate_s8_bo;
  270.       } zs;
  271.    } u;
  272. };
  273.  
  274. struct ilo_fb_state {
  275.    struct pipe_framebuffer_state state;
  276.  
  277.    struct ilo_view_surface null_rt;
  278.    struct ilo_zs_surface null_zs;
  279.  
  280.    struct ilo_fb_blend_caps {
  281.       bool can_logicop;
  282.       bool can_blend;
  283.       bool can_alpha_test;
  284.       bool dst_alpha_forced_one;
  285.    } blend_caps[PIPE_MAX_COLOR_BUFS];
  286.  
  287.    unsigned num_samples;
  288. };
  289.  
  290. struct ilo_shader_cso {
  291.    uint32_t payload[5];
  292. };
  293.  
  294. /**
  295.  * Translate a pipe texture target to the matching hardware surface type.
  296.  */
  297. static inline int
  298. ilo_gpe_gen6_translate_texture(enum pipe_texture_target target)
  299. {
  300.    switch (target) {
  301.    case PIPE_BUFFER:
  302.       return GEN6_SURFTYPE_BUFFER;
  303.    case PIPE_TEXTURE_1D:
  304.    case PIPE_TEXTURE_1D_ARRAY:
  305.       return GEN6_SURFTYPE_1D;
  306.    case PIPE_TEXTURE_2D:
  307.    case PIPE_TEXTURE_RECT:
  308.    case PIPE_TEXTURE_2D_ARRAY:
  309.       return GEN6_SURFTYPE_2D;
  310.    case PIPE_TEXTURE_3D:
  311.       return GEN6_SURFTYPE_3D;
  312.    case PIPE_TEXTURE_CUBE:
  313.    case PIPE_TEXTURE_CUBE_ARRAY:
  314.       return GEN6_SURFTYPE_CUBE;
  315.    default:
  316.       assert(!"unknown texture target");
  317.       return GEN6_SURFTYPE_BUFFER;
  318.    }
  319. }
  320.  
  321. void
  322. ilo_gpe_init_ve(const struct ilo_dev *dev,
  323.                 unsigned num_states,
  324.                 const struct pipe_vertex_element *states,
  325.                 struct ilo_ve_state *ve);
  326.  
  327. void
  328. ilo_gpe_set_ve_edgeflag(const struct ilo_dev *dev,
  329.                         struct ilo_ve_cso *cso);
  330.  
  331. void
  332. ilo_gpe_init_ve_nosrc(const struct ilo_dev *dev,
  333.                       int comp0, int comp1, int comp2, int comp3,
  334.                       struct ilo_ve_cso *cso);
  335.  
  336. void
  337. ilo_gpe_set_viewport_cso(const struct ilo_dev *dev,
  338.                          const struct pipe_viewport_state *state,
  339.                          struct ilo_viewport_cso *vp);
  340.  
  341. void
  342. ilo_gpe_set_scissor(const struct ilo_dev *dev,
  343.                     unsigned start_slot,
  344.                     unsigned num_states,
  345.                     const struct pipe_scissor_state *states,
  346.                     struct ilo_scissor_state *scissor);
  347.  
  348. void
  349. ilo_gpe_set_scissor_null(const struct ilo_dev *dev,
  350.                          struct ilo_scissor_state *scissor);
  351.  
  352. void
  353. ilo_gpe_init_rasterizer(const struct ilo_dev *dev,
  354.                         const struct pipe_rasterizer_state *state,
  355.                         struct ilo_rasterizer_state *rasterizer);
  356. void
  357. ilo_gpe_init_dsa(const struct ilo_dev *dev,
  358.                  const struct pipe_depth_stencil_alpha_state *state,
  359.                  struct ilo_dsa_state *dsa);
  360.  
  361. void
  362. ilo_gpe_init_blend(const struct ilo_dev *dev,
  363.                    const struct pipe_blend_state *state,
  364.                    struct ilo_blend_state *blend);
  365.  
  366. void
  367. ilo_gpe_init_sampler_cso(const struct ilo_dev *dev,
  368.                          const struct pipe_sampler_state *state,
  369.                          struct ilo_sampler_cso *sampler);
  370.  
  371. void
  372. ilo_gpe_init_view_surface_null(const struct ilo_dev *dev,
  373.                                unsigned width, unsigned height,
  374.                                unsigned depth, unsigned level,
  375.                                struct ilo_view_surface *surf);
  376.  
  377. void
  378. ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev *dev,
  379.                                      const struct ilo_buffer *buf,
  380.                                      unsigned offset, unsigned size,
  381.                                      unsigned struct_size,
  382.                                      enum pipe_format elem_format,
  383.                                      bool is_rt, bool render_cache_rw,
  384.                                      struct ilo_view_surface *surf);
  385.  
  386. void
  387. ilo_gpe_init_view_surface_for_image(const struct ilo_dev *dev,
  388.                                     const struct ilo_image *img,
  389.                                     enum pipe_texture_target target,
  390.                                     enum pipe_format format,
  391.                                     unsigned first_level,
  392.                                     unsigned num_levels,
  393.                                     unsigned first_layer,
  394.                                     unsigned num_layers,
  395.                                     bool is_rt,
  396.                                     struct ilo_view_surface *surf);
  397.  
  398. void
  399. ilo_gpe_init_zs_surface(const struct ilo_dev *dev,
  400.                         const struct ilo_image *img,
  401.                         const struct ilo_image *s8_img,
  402.                         enum pipe_texture_target target,
  403.                         enum pipe_format format, unsigned level,
  404.                         unsigned first_layer, unsigned num_layers,
  405.                         struct ilo_zs_surface *zs);
  406.  
  407. void
  408. ilo_gpe_init_vs_cso(const struct ilo_dev *dev,
  409.                     const struct ilo_shader_state *vs,
  410.                     struct ilo_shader_cso *cso);
  411.  
  412. void
  413. ilo_gpe_init_gs_cso(const struct ilo_dev *dev,
  414.                     const struct ilo_shader_state *gs,
  415.                     struct ilo_shader_cso *cso);
  416.  
  417. void
  418. ilo_gpe_init_fs_cso(const struct ilo_dev *dev,
  419.                     const struct ilo_shader_state *fs,
  420.                     struct ilo_shader_cso *cso);
  421.  
  422. void
  423. ilo_gpe_set_fb(const struct ilo_dev *dev,
  424.                const struct pipe_framebuffer_state *state,
  425.                struct ilo_fb_state *fb);
  426.  
  427. #endif /* ILO_STATE_3D_H */
  428.