1 /**************************************************************************** 2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 ***************************************************************************/ 23 24 #pragma once 25 26 struct swr_vertex_shader; 27 struct swr_fragment_shader; 28 struct swr_geometry_shader; 29 struct swr_tess_control_shader; 30 struct swr_tess_evaluation_shader; 31 32 struct swr_jit_fs_key; 33 struct swr_jit_vs_key; 34 struct swr_jit_gs_key; 35 struct swr_jit_tcs_key; 36 struct swr_jit_tes_key; 37 38 using PFN_TCS_FUNC = PFN_HS_FUNC; 39 using PFN_TES_FUNC = PFN_DS_FUNC; 40 41 unsigned swr_so_adjust_attrib(unsigned in_attrib, 42 swr_vertex_shader *swr_vs); 43 44 PFN_VERTEX_FUNC 45 swr_compile_vs(struct swr_context *ctx, swr_jit_vs_key &key); 46 47 PFN_PIXEL_KERNEL 48 swr_compile_fs(struct swr_context *ctx, swr_jit_fs_key &key); 49 50 PFN_GS_FUNC 51 swr_compile_gs(struct swr_context *ctx, swr_jit_gs_key &key); 52 53 PFN_TCS_FUNC 54 swr_compile_tcs(struct swr_context *ctx, swr_jit_tcs_key &key); 55 56 PFN_TES_FUNC 57 swr_compile_tes(struct swr_context *ctx, swr_jit_tes_key &key); 58 59 void swr_generate_fs_key(struct swr_jit_fs_key &key, 60 struct swr_context *ctx, 61 swr_fragment_shader *swr_fs); 62 63 void swr_generate_vs_key(struct swr_jit_vs_key &key, 64 struct swr_context *ctx, 65 swr_vertex_shader *swr_vs); 66 67 void swr_generate_fetch_key(struct swr_jit_fetch_key &key, 68 struct swr_vertex_element_state *velems); 69 70 void swr_generate_gs_key(struct swr_jit_gs_key &key, 71 struct swr_context *ctx, 72 swr_geometry_shader *swr_gs); 73 74 void swr_generate_tcs_key(struct swr_jit_tcs_key &key, 75 struct swr_context *ctx, 76 swr_tess_control_shader *swr_tcs); 77 78 void swr_generate_tes_key(struct swr_jit_tes_key &key, 79 struct swr_context *ctx, 80 swr_tess_evaluation_shader *swr_tes); 81 82 struct swr_jit_sampler_key { 83 unsigned nr_samplers; 84 unsigned nr_sampler_views; 85 struct swr_sampler_static_state sampler[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 86 }; 87 88 struct swr_jit_fs_key : swr_jit_sampler_key { 89 unsigned nr_cbufs; 90 unsigned light_twoside; 91 unsigned sprite_coord_enable; 92 ubyte vs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; 93 ubyte vs_output_semantic_idx[PIPE_MAX_SHADER_OUTPUTS]; 94 bool poly_stipple_enable; 95 }; 96 97 struct swr_jit_vs_key : swr_jit_sampler_key { 98 unsigned clip_plane_mask; // from rasterizer state & vs_info 99 }; 100 101 struct swr_jit_fetch_key { 102 FETCH_COMPILE_STATE fsState; 103 }; 104 105 struct swr_jit_gs_key : swr_jit_sampler_key { 106 ubyte vs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; 107 ubyte vs_output_semantic_idx[PIPE_MAX_SHADER_OUTPUTS]; 108 }; 109 110 // TESS_TODO: revisit this - we probably need to use 111 // primitive modes, number of vertices emitted, etc. 112 struct swr_jit_tcs_key : swr_jit_sampler_key { 113 ubyte vs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; 114 ubyte vs_output_semantic_idx[PIPE_MAX_SHADER_OUTPUTS]; 115 unsigned clip_plane_mask; // from rasterizer state & tcs_info 116 }; 117 118 // TESS_TODO: revisit this 119 struct swr_jit_tes_key : swr_jit_sampler_key { 120 ubyte prev_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; 121 ubyte prev_output_semantic_idx[PIPE_MAX_SHADER_OUTPUTS]; 122 unsigned clip_plane_mask; // from rasterizer state & tes_info 123 }; 124 125 namespace std 126 { 127 template <> struct hash<swr_jit_fs_key> { 128 std::size_t operator()(const swr_jit_fs_key &k) const 129 { 130 return util_hash_crc32(&k, sizeof(k)); 131 } 132 }; 133 134 template <> struct hash<swr_jit_vs_key> { 135 std::size_t operator()(const swr_jit_vs_key &k) const 136 { 137 return util_hash_crc32(&k, sizeof(k)); 138 } 139 }; 140 141 template <> struct hash<swr_jit_fetch_key> { 142 std::size_t operator()(const swr_jit_fetch_key &k) const 143 { 144 return util_hash_crc32(&k, sizeof(k)); 145 } 146 }; 147 148 template <> struct hash<swr_jit_gs_key> { 149 std::size_t operator()(const swr_jit_gs_key &k) const 150 { 151 return util_hash_crc32(&k, sizeof(k)); 152 } 153 }; 154 155 template <> struct hash<swr_jit_tcs_key> { 156 std::size_t operator()(const swr_jit_tcs_key &k) const 157 { 158 return util_hash_crc32(&k, sizeof(k)); 159 } 160 }; 161 162 template <> struct hash<swr_jit_tes_key> { 163 std::size_t operator()(const swr_jit_tes_key &k) const 164 { 165 return util_hash_crc32(&k, sizeof(k)); 166 } 167 }; 168 }; 169 170 bool operator==(const swr_jit_fs_key &lhs, const swr_jit_fs_key &rhs); 171 bool operator==(const swr_jit_vs_key &lhs, const swr_jit_vs_key &rhs); 172 bool operator==(const swr_jit_fetch_key &lhs, const swr_jit_fetch_key &rhs); 173 bool operator==(const swr_jit_gs_key &lhs, const swr_jit_gs_key &rhs); 174 bool operator==(const swr_jit_tcs_key &lhs, const swr_jit_tcs_key &rhs); 175 bool operator==(const swr_jit_tes_key &lhs, const swr_jit_tes_key &rhs); 176