swr_shader.h revision 7ec681f3
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
26struct swr_vertex_shader;
27struct swr_fragment_shader;
28struct swr_geometry_shader;
29struct swr_tess_control_shader;
30struct swr_tess_evaluation_shader;
31
32struct swr_jit_fs_key;
33struct swr_jit_vs_key;
34struct swr_jit_gs_key;
35struct swr_jit_tcs_key;
36struct swr_jit_tes_key;
37
38using PFN_TCS_FUNC = PFN_HS_FUNC;
39using PFN_TES_FUNC = PFN_DS_FUNC;
40
41unsigned swr_so_adjust_attrib(unsigned in_attrib,
42                              swr_vertex_shader *swr_vs);
43
44PFN_VERTEX_FUNC
45swr_compile_vs(struct swr_context *ctx, swr_jit_vs_key &key);
46
47PFN_PIXEL_KERNEL
48swr_compile_fs(struct swr_context *ctx, swr_jit_fs_key &key);
49
50PFN_GS_FUNC
51swr_compile_gs(struct swr_context *ctx, swr_jit_gs_key &key);
52
53PFN_TCS_FUNC
54swr_compile_tcs(struct swr_context *ctx, swr_jit_tcs_key &key);
55
56PFN_TES_FUNC
57swr_compile_tes(struct swr_context *ctx, swr_jit_tes_key &key);
58
59void swr_generate_fs_key(struct swr_jit_fs_key &key,
60                         struct swr_context *ctx,
61                         swr_fragment_shader *swr_fs);
62
63void swr_generate_vs_key(struct swr_jit_vs_key &key,
64                         struct swr_context *ctx,
65                         swr_vertex_shader *swr_vs);
66
67void swr_generate_fetch_key(struct swr_jit_fetch_key &key,
68                            struct swr_vertex_element_state *velems);
69
70void swr_generate_gs_key(struct swr_jit_gs_key &key,
71                         struct swr_context *ctx,
72                         swr_geometry_shader *swr_gs);
73
74void swr_generate_tcs_key(struct swr_jit_tcs_key &key,
75                          struct swr_context *ctx,
76                          swr_tess_control_shader *swr_tcs);
77
78void swr_generate_tes_key(struct swr_jit_tes_key &key,
79                          struct swr_context *ctx,
80                          swr_tess_evaluation_shader *swr_tes);
81
82struct 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
88struct 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
97struct swr_jit_vs_key : swr_jit_sampler_key {
98   unsigned clip_plane_mask; // from rasterizer state & vs_info
99};
100
101struct swr_jit_fetch_key {
102   FETCH_COMPILE_STATE fsState;
103};
104
105struct 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.
112struct 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
119struct 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
125namespace std
126{
127template <> 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
134template <> 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
141template <> 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
148template <> 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
155template <> 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
162template <> 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
170bool operator==(const swr_jit_fs_key &lhs, const swr_jit_fs_key &rhs);
171bool operator==(const swr_jit_vs_key &lhs, const swr_jit_vs_key &rhs);
172bool operator==(const swr_jit_fetch_key &lhs, const swr_jit_fetch_key &rhs);
173bool operator==(const swr_jit_gs_key &lhs, const swr_jit_gs_key &rhs);
174bool operator==(const swr_jit_tcs_key &lhs, const swr_jit_tcs_key &rhs);
175bool operator==(const swr_jit_tes_key &lhs, const swr_jit_tes_key &rhs);
176