• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012-2015 Etnaviv Project
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, sub license,
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
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the 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 NON-INFRINGEMENT. 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
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Wladimir J. van der Laan <laanwj@gmail.com>
25  */
26 
27 #ifndef H_ETNAVIV_SHADER
28 #define H_ETNAVIV_SHADER
29 
30 #include "mesa/main/config.h"
31 #include "etna_core_info.h"
32 #include "nir.h"
33 #include "pipe/p_state.h"
34 #include "util/disk_cache.h"
35 #include "util/u_queue.h"
36 
37 struct etna_context;
38 struct etna_shader_variant;
39 struct nir_shader;
40 
41 struct etna_shader_key
42 {
43    union {
44       struct {
45          /*
46           * Combined Vertex/Fragment shader parameters:
47           */
48 
49          /* do we need to swap rb in frag colors? */
50          unsigned frag_rb_swap : PIPE_MAX_COLOR_BUFS;
51          /* do we need to invert front facing value? */
52          unsigned front_ccw : 1;
53          /* do we need to replace glTexCoord.xy ? */
54          unsigned sprite_coord_enable : MAX_TEXTURE_COORD_UNITS;
55          unsigned sprite_coord_yinvert : 1;
56          /* do we need to lower sample_tex_compare */
57          unsigned has_sample_tex_compare : 1;
58          /* color varyings should be flat shaded */
59          unsigned flatshade : 1;
60       };
61       uint32_t global;
62    };
63 
64    int num_texture_states;
65    nir_lower_tex_shadow_swizzle tex_swizzle[16];
66    enum compare_func tex_compare_func[16];
67 };
68 
69 static inline bool
etna_shader_key_equal(const struct etna_shader_key * const a,const struct etna_shader_key * const b)70 etna_shader_key_equal(const struct etna_shader_key* const a,
71                       const struct etna_shader_key* const b)
72 {
73    /* slow-path if we need to check tex_{swizzle,compare_func} */
74    if (unlikely(a->has_sample_tex_compare || b->has_sample_tex_compare))
75       return memcmp(a, b, sizeof(struct etna_shader_key)) == 0;
76    else
77       return a->global == b->global;
78 }
79 
80 struct etna_shader {
81    /* shader id (for debug): */
82    uint32_t id;
83    uint32_t variant_count;
84 
85    struct nir_shader *nir;
86    const struct etna_core_info *info;
87    const struct etna_specs *specs;
88    struct etna_compiler *compiler;
89 
90    struct etna_shader_variant *variants;
91 
92    cache_key cache_key;     /* shader disk-cache key */
93 
94    /* parallel shader compiles */
95    struct util_queue_fence ready;
96 };
97 
98 bool
99 etna_shader_link(struct etna_context *ctx);
100 
101 bool
102 etna_shader_update_vertex(struct etna_context *ctx);
103 
104 struct etna_shader_variant *
105 etna_shader_variant(struct etna_shader *shader,
106                     const struct etna_shader_key* const key,
107                     struct util_debug_callback *debug,
108                     bool called_from_draw);
109 
110 void
111 etna_shader_init(struct pipe_context *pctx);
112 
113 bool
114 etna_shader_screen_init(struct pipe_screen *pscreen);
115 
116 void
117 etna_shader_screen_fini(struct pipe_screen *pscreen);
118 
119 #endif
120