• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Mike Blumenkrantz
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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 
25 /** this file exists for organization and to be included in nir_to_spirv/ without pulling in extra deps */
26 #ifndef ZINK_SHADER_KEYS_H
27 # define ZINK_SHADER_KEYS_H
28 
29 #include "compiler/shader_info.h"
30 
31 struct zink_vs_key_base {
32    bool clip_halfz;
33    bool push_drawid;
34    bool last_vertex_stage;
35 };
36 
37 struct zink_vs_key {
38    struct zink_vs_key_base base;
39    uint8_t pad;
40    union {
41       struct {
42          uint32_t decomposed_attrs;
43          uint32_t decomposed_attrs_without_w;
44       } u32;
45       struct {
46          uint16_t decomposed_attrs;
47          uint16_t decomposed_attrs_without_w;
48       } u16;
49       struct {
50          uint8_t decomposed_attrs;
51          uint8_t decomposed_attrs_without_w;
52       } u8;
53    };
54    // not hashed
55    unsigned size;
56 };
57 
58 struct zink_fs_key {
59    uint8_t coord_replace_bits;
60    bool coord_replace_yinvert;
61    bool samples;
62    bool force_dual_color_blend;
63 };
64 
65 struct zink_shader_key_base {
66    uint32_t inlined_uniform_values[MAX_INLINABLE_UNIFORMS];
67 };
68 
69 /* a shader key is used for swapping out shader modules based on pipeline states,
70  * e.g., if sampleCount changes, we must verify that the fs doesn't need a recompile
71  *       to account for GL ignoring gl_SampleMask in some cases when VK will not
72  * which allows us to avoid recompiling shaders when the pipeline state changes repeatedly
73  */
74 struct zink_shader_key {
75    union {
76       /* reuse vs key for now with tes/gs since we only use clip_halfz */
77       struct zink_vs_key vs;
78       struct zink_vs_key_base vs_base;
79       struct zink_fs_key fs;
80    } key;
81    struct zink_shader_key_base base;
82    unsigned inline_uniforms:1;
83    uint32_t size;
84 };
85 
86 static inline const struct zink_fs_key *
zink_fs_key(const struct zink_shader_key * key)87 zink_fs_key(const struct zink_shader_key *key)
88 {
89    assert(key);
90    return &key->key.fs;
91 }
92 
93 static inline const struct zink_vs_key_base *
zink_vs_key_base(const struct zink_shader_key * key)94 zink_vs_key_base(const struct zink_shader_key *key)
95 {
96    return &key->key.vs_base;
97 }
98 
99 static inline const struct zink_vs_key *
zink_vs_key(const struct zink_shader_key * key)100 zink_vs_key(const struct zink_shader_key *key)
101 {
102    assert(key);
103    return &key->key.vs;
104 }
105 
106 
107 
108 #endif
109