Subversion Repositories Kolibri OS

Rev

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 TOY_TGSI_H
  29. #define TOY_TGSI_H
  30.  
  31. #include "pipe/p_state.h"
  32. #include "pipe/p_shader_tokens.h"
  33. #include "toy_compiler.h"
  34.  
  35. struct tgsi_token;
  36. struct tgsi_full_instruction;
  37. struct util_hash_table;
  38.  
  39. typedef void (*toy_tgsi_translate)(struct toy_compiler *tc,
  40.       const struct tgsi_full_instruction *tgsi_inst,
  41.       struct toy_dst *dst,
  42.       struct toy_src *src);
  43.  
  44. struct toy_tgsi {
  45.    struct toy_compiler *tc;
  46.    bool aos;
  47.    const toy_tgsi_translate *translate_table;
  48.  
  49.    struct util_hash_table *reg_mapping;
  50.  
  51.    struct {
  52.       bool vs_prohibit_ucps;
  53.       int fs_coord_origin;
  54.       int fs_coord_pixel_center;
  55.       bool fs_color0_writes_all_cbufs;
  56.       int fs_depth_layout;
  57.       int gs_input_prim;
  58.       int gs_output_prim;
  59.       int gs_max_output_vertices;
  60.    } props;
  61.  
  62.    struct {
  63.       enum toy_type *types;
  64.       uint32_t (*buf)[4];
  65.       int cur, size;
  66.    } imm_data;
  67.  
  68.    struct {
  69.       int index:16;
  70.       unsigned usage_mask:4;        /* TGSI_WRITEMASK_x */
  71.       unsigned semantic_name:8;     /* TGSI_SEMANTIC_x */
  72.       unsigned semantic_index:8;
  73.       unsigned interp:4;            /* TGSI_INTERPOLATE_x */
  74.       unsigned centroid:1;
  75.    } inputs[PIPE_MAX_SHADER_INPUTS];
  76.    int num_inputs;
  77.  
  78.    struct {
  79.       int index:16;
  80.       unsigned undefined_mask:4;
  81.       unsigned usage_mask:4;        /* TGSI_WRITEMASK_x */
  82.       unsigned semantic_name:8;     /* TGSI_SEMANTIC_x */
  83.       unsigned semantic_index:8;
  84.    } outputs[PIPE_MAX_SHADER_OUTPUTS];
  85.    int num_outputs;
  86.  
  87.    struct {
  88.       int index:16;
  89.       unsigned semantic_name:8;     /* TGSI_SEMANTIC_x */
  90.       unsigned semantic_index:8;
  91.    } system_values[8];
  92.    int num_system_values;
  93.  
  94.    int const_count;
  95.    bool const_indirect;
  96.  
  97.    bool uses_kill;
  98. };
  99.  
  100. /**
  101.  * Find the slot of the TGSI input.
  102.  */
  103. static inline int
  104. toy_tgsi_find_input(const struct toy_tgsi *tgsi, int index)
  105. {
  106.    int slot;
  107.  
  108.    for (slot = 0; slot < tgsi->num_inputs; slot++) {
  109.       if (tgsi->inputs[slot].index == index)
  110.          return slot;
  111.    }
  112.  
  113.    return -1;
  114. }
  115.  
  116. /**
  117.  * Find the slot of the TGSI system value.
  118.  */
  119. static inline int
  120. toy_tgsi_find_system_value(const struct toy_tgsi *tgsi, int index)
  121. {
  122.    int slot;
  123.  
  124.    for (slot = 0; slot < tgsi->num_system_values; slot++) {
  125.       if (tgsi->system_values[slot].index == index)
  126.          return slot;
  127.    }
  128.  
  129.    return -1;
  130. }
  131.  
  132. /**
  133.  * Return the immediate data of the TGSI immediate.
  134.  */
  135. static inline const uint32_t *
  136. toy_tgsi_get_imm(const struct toy_tgsi *tgsi, unsigned index,
  137.                  enum toy_type *type)
  138. {
  139.    const uint32_t *imm;
  140.  
  141.    if (index >= tgsi->imm_data.cur)
  142.       return NULL;
  143.  
  144.    imm = tgsi->imm_data.buf[index];
  145.    if (type)
  146.       *type = tgsi->imm_data.types[index];
  147.  
  148.    return imm;
  149. }
  150.  
  151. void
  152. toy_compiler_translate_tgsi(struct toy_compiler *tc,
  153.                             const struct tgsi_token *tokens, bool aos,
  154.                             struct toy_tgsi *tgsi);
  155.  
  156. void
  157. toy_tgsi_cleanup(struct toy_tgsi *tgsi);
  158.  
  159. int
  160. toy_tgsi_get_vrf(const struct toy_tgsi *tgsi,
  161.                  enum tgsi_file_type file, int dimension, int index);
  162.  
  163. void
  164. toy_tgsi_dump(const struct toy_tgsi *tgsi);
  165.  
  166. #endif /* TOY_TGSI_H */
  167.