Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Mesa 3-D graphics library
  3.  *
  4.  * Copyright (C) 2012-2013 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_SHADER_INTERNAL_H
  29. #define ILO_SHADER_INTERNAL_H
  30.  
  31. #include "ilo_common.h"
  32. #include "ilo_context.h"
  33. #include "ilo_shader.h"
  34.  
  35. /* XXX The interface needs to be reworked */
  36.  
  37. /**
  38.  * A shader variant.  It consists of non-orthogonal states of the pipe context
  39.  * affecting the compilation of a shader.
  40.  */
  41. struct ilo_shader_variant {
  42.    union {
  43.       struct {
  44.          bool rasterizer_discard;
  45.          int num_ucps;
  46.       } vs;
  47.  
  48.       struct {
  49.          bool rasterizer_discard;
  50.          int num_inputs;
  51.          int semantic_names[PIPE_MAX_SHADER_INPUTS];
  52.          int semantic_indices[PIPE_MAX_SHADER_INPUTS];
  53.       } gs;
  54.  
  55.       struct {
  56.          bool flatshade;
  57.          int fb_height;
  58.          int num_cbufs;
  59.       } fs;
  60.    } u;
  61.  
  62.    int num_sampler_views;
  63.    struct {
  64.       unsigned r:3;
  65.       unsigned g:3;
  66.       unsigned b:3;
  67.       unsigned a:3;
  68.    } sampler_view_swizzles[ILO_MAX_SAMPLER_VIEWS];
  69.  
  70.    uint32_t saturate_tex_coords[3];
  71. };
  72.  
  73. /**
  74.  * A compiled shader.
  75.  */
  76. struct ilo_shader {
  77.    struct ilo_shader_variant variant;
  78.  
  79.    struct ilo_shader_cso cso;
  80.  
  81.    struct {
  82.       int semantic_names[PIPE_MAX_SHADER_INPUTS];
  83.       int semantic_indices[PIPE_MAX_SHADER_INPUTS];
  84.       int interp[PIPE_MAX_SHADER_INPUTS];
  85.       bool centroid[PIPE_MAX_SHADER_INPUTS];
  86.       int count;
  87.  
  88.       int start_grf;
  89.       bool has_pos;
  90.       bool has_linear_interp;
  91.       int barycentric_interpolation_mode;
  92.       uint32_t const_interp_enable;
  93.       bool discard_adj;
  94.    } in;
  95.  
  96.    struct {
  97.       int register_indices[PIPE_MAX_SHADER_OUTPUTS];
  98.       int semantic_names[PIPE_MAX_SHADER_OUTPUTS];
  99.       int semantic_indices[PIPE_MAX_SHADER_OUTPUTS];
  100.       int count;
  101.  
  102.       bool has_pos;
  103.    } out;
  104.  
  105.    bool has_kill;
  106.    bool dispatch_16;
  107.  
  108.    bool stream_output;
  109.    int svbi_post_inc;
  110.    struct pipe_stream_output_info so_info;
  111.  
  112.    /* for VS stream output / rasterizer discard */
  113.    int gs_offsets[3];
  114.    int gs_start_grf;
  115.  
  116.    void *kernel;
  117.    int kernel_size;
  118.  
  119.    bool routing_initialized;
  120.    int routing_src_semantics[PIPE_MAX_SHADER_OUTPUTS];
  121.    int routing_src_indices[PIPE_MAX_SHADER_OUTPUTS];
  122.    uint32_t routing_sprite_coord_enable;
  123.    struct ilo_kernel_routing routing;
  124.  
  125.    /* what does the push constant buffer consist of? */
  126.    struct {
  127.       int clip_state_size;
  128.    } pcb;
  129.  
  130.    struct list_head list;
  131.  
  132.    /* managed by shader cache */
  133.    bool uploaded;
  134.    uint32_t cache_offset;
  135. };
  136.  
  137. /**
  138.  * Information about a shader state.
  139.  */
  140. struct ilo_shader_info {
  141.    const struct ilo_dev_info *dev;
  142.    int type;
  143.  
  144.    const struct tgsi_token *tokens;
  145.  
  146.    struct pipe_stream_output_info stream_output;
  147.    struct {
  148.       unsigned req_local_mem;
  149.       unsigned req_private_mem;
  150.       unsigned req_input_mem;
  151.    } compute;
  152.  
  153.    uint32_t non_orthogonal_states;
  154.  
  155.    bool has_color_interp;
  156.    bool has_pos;
  157.    bool has_vertexid;
  158.    bool has_instanceid;
  159.    bool fs_color0_writes_all_cbufs;
  160.  
  161.    int edgeflag_in;
  162.    int edgeflag_out;
  163.  
  164.    uint32_t shadow_samplers;
  165.    int num_samplers;
  166. };
  167.  
  168. /**
  169.  * A shader state.
  170.  */
  171. struct ilo_shader_state {
  172.    struct ilo_shader_info info;
  173.  
  174.    struct list_head variants;
  175.    int num_variants, total_size;
  176.  
  177.    struct ilo_shader *shader;
  178.  
  179.    /* managed by shader cache */
  180.    struct ilo_shader_cache *cache;
  181.    struct list_head list;
  182. };
  183.  
  184. void
  185. ilo_shader_variant_init(struct ilo_shader_variant *variant,
  186.                         const struct ilo_shader_info *info,
  187.                         const struct ilo_context *ilo);
  188.  
  189. bool
  190. ilo_shader_state_use_variant(struct ilo_shader_state *state,
  191.                              const struct ilo_shader_variant *variant);
  192.  
  193. struct ilo_shader *
  194. ilo_shader_compile_vs(const struct ilo_shader_state *state,
  195.                       const struct ilo_shader_variant *variant);
  196.  
  197. struct ilo_shader *
  198. ilo_shader_compile_gs(const struct ilo_shader_state *state,
  199.                       const struct ilo_shader_variant *variant);
  200.  
  201. bool
  202. ilo_shader_compile_gs_passthrough(const struct ilo_shader_state *vs_state,
  203.                                   const struct ilo_shader_variant *vs_variant,
  204.                                   const int *so_mapping,
  205.                                   struct ilo_shader *vs);
  206.  
  207. struct ilo_shader *
  208. ilo_shader_compile_fs(const struct ilo_shader_state *state,
  209.                       const struct ilo_shader_variant *variant);
  210.  
  211. struct ilo_shader *
  212. ilo_shader_compile_cs(const struct ilo_shader_state *state,
  213.                       const struct ilo_shader_variant *variant);
  214.  
  215. static inline void
  216. ilo_shader_destroy_kernel(struct ilo_shader *sh)
  217. {
  218.    FREE(sh->kernel);
  219.    FREE(sh);
  220. }
  221.  
  222. #endif /* ILO_SHADER_INTERNAL_H */
  223.