• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2022 Collabora, Ltd.
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef NAK_H
7 #define NAK_H
8 
9 #include "compiler/shader_enums.h"
10 #include "nir.h"
11 
12 #include <assert.h>
13 #include <stdbool.h>
14 #include <stdint.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 struct nak_compiler;
21 struct nir_shader_compiler_options;
22 struct nv_device_info;
23 
24 struct nak_compiler *nak_compiler_create(const struct nv_device_info *dev);
25 void nak_compiler_destroy(struct nak_compiler *nak);
26 
27 uint64_t nak_debug_flags(const struct nak_compiler *nak);
28 
29 const struct nir_shader_compiler_options *
30 nak_nir_options(const struct nak_compiler *nak);
31 
32 void nak_optimize_nir(nir_shader *nir, const struct nak_compiler *nak);
33 void nak_preprocess_nir(nir_shader *nir, const struct nak_compiler *nak);
34 
35 struct nak_fs_key {
36    bool zs_self_dep;
37 
38    /** True if sample shading is forced on via an API knob such as
39     * VkPipelineMultisampleStateCreateInfo::minSampleShading
40     */
41    bool force_sample_shading;
42 
43    /**
44     * The constant buffer index and offset at which the sample locations table lives.
45     * Each sample location is two 4-bit unorm values packed into an 8-bit value
46     * with the bottom 4 bits for x and the top 4 bits for y.
47    */
48    uint8_t sample_locations_cb;
49    uint32_t sample_locations_offset;
50 };
51 
52 void nak_postprocess_nir(nir_shader *nir, const struct nak_compiler *nak,
53                          nir_variable_mode robust2_modes,
54                          const struct nak_fs_key *fs_key);
55 
56 enum ENUM_PACKED nak_ts_domain {
57    NAK_TS_DOMAIN_ISOLINE = 0,
58    NAK_TS_DOMAIN_TRIANGLE = 1,
59    NAK_TS_DOMAIN_QUAD = 2,
60 };
61 
62 enum ENUM_PACKED nak_ts_spacing {
63    NAK_TS_SPACING_INTEGER = 0,
64    NAK_TS_SPACING_FRACT_ODD = 1,
65    NAK_TS_SPACING_FRACT_EVEN = 2,
66 };
67 
68 enum ENUM_PACKED nak_ts_prims {
69    NAK_TS_PRIMS_POINTS = 0,
70    NAK_TS_PRIMS_LINES = 1,
71    NAK_TS_PRIMS_TRIANGLES_CW = 2,
72    NAK_TS_PRIMS_TRIANGLES_CCW = 3,
73 };
74 
75 struct nak_xfb_info {
76    uint32_t stride[4];
77    uint8_t stream[4];
78    uint8_t attr_count[4];
79    uint8_t attr_index[4][128];
80 };
81 
82 /* This struct MUST have explicit padding fields to ensure that all padding is
83  * zeroed and the zeros get properly copied, even across API boundaries.  This
84  * is ensured in two ways:
85  *
86  *  - Bindgen is invoked with --explicit-padding and if a __bindgen_paddingN
87  *    member ever crops up, that tells us we need to add an explicit member
88  *    here.
89  *
90  *  - There is a set of const asserts in nak/api.rs which ensure that all of
91  *    the union fields are equal to NAK_SHADER_INFO_STAGE_UNION_SIZE.
92  */
93 #pragma GCC diagnostic push
94 #pragma GCC diagnostic error "-Wpadded"
95 struct nak_shader_info {
96    gl_shader_stage stage;
97 
98    /** Number of GPRs used */
99    uint8_t num_gprs;
100 
101    /** Number of barriers used */
102    uint8_t num_barriers;
103 
104    uint16_t _pad0;
105 
106    /** Size of shader local (scratch) memory */
107    uint32_t slm_size;
108 
109    union {
110       struct {
111          /* Local workgroup size */
112          uint16_t local_size[3];
113 
114          /* Shared memory size */
115          uint16_t smem_size;
116 
117          uint8_t _pad[4];
118       } cs;
119 
120       struct {
121          bool writes_depth;
122          bool reads_sample_mask;
123          bool post_depth_coverage;
124          bool uses_sample_shading;
125          bool early_fragment_tests;
126 
127          uint8_t _pad[7];
128       } fs;
129 
130       struct {
131          enum nak_ts_domain domain;
132          enum nak_ts_spacing spacing;
133          enum nak_ts_prims prims;
134 
135          uint8_t _pad[9];
136       } ts;
137 
138       /* Used to initialize the union for other stages */
139       uint8_t _pad[12];
140    };
141 
142    struct {
143       bool writes_layer;
144       bool writes_point_size;
145       uint8_t clip_enable;
146       uint8_t cull_enable;
147 
148       struct nak_xfb_info xfb;
149    } vtg;
150 
151    /** Shader header for 3D stages */
152    uint32_t hdr[32];
153 };
154 #pragma GCC diagnostic pop
155 
156 struct nak_shader_bin {
157    struct nak_shader_info info;
158 
159    uint32_t code_size;
160    const void *code;
161 
162    const char *asm_str;
163 };
164 
165 void nak_shader_bin_destroy(struct nak_shader_bin *bin);
166 
167 struct nak_shader_bin *
168 nak_compile_shader(nir_shader *nir, bool dump_asm,
169                    const struct nak_compiler *nak,
170                    nir_variable_mode robust2_modes,
171                    const struct nak_fs_key *fs_key);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif /* NAK_H */
178