xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a2xx/ir2.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Jonathan Marek <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Jonathan Marek <[email protected]>
7  */
8 
9 #ifndef IR2_H_
10 #define IR2_H_
11 
12 #include "compiler/nir/nir.h"
13 #include "pipe/p_context.h"
14 
15 struct ir2_fetch_info {
16    /* dword offset of the fetch instruction */
17    uint16_t offset;
18    union {
19       /* swizzle to merge with tgsi swizzle */
20       struct {
21          uint16_t dst_swiz;
22       } vtx;
23       /* sampler id to patch const_idx */
24       struct {
25          uint16_t samp_id;
26          uint8_t src_swiz;
27       } tex;
28    };
29 };
30 
31 struct ir2_shader_info {
32    /* compiler shader */
33    uint32_t *dwords;
34 
35    /* size of the compiled shader in dwords */
36    uint16_t sizedwords;
37 
38    /* highest GPR # used by shader */
39    int8_t max_reg;
40 
41    /* offset in dwords of first MEMORY export CF (for a20x hw binning) */
42    int16_t mem_export_ptr;
43 
44    /* fetch instruction info for patching */
45    uint16_t num_fetch_instrs;
46    struct ir2_fetch_info fetch_info[64];
47 };
48 
49 struct ir2_frag_linkage {
50    unsigned inputs_count;
51    struct {
52       uint8_t slot;
53       uint8_t ncomp;
54    } inputs[16];
55 
56    /* driver_location of fragcoord.zw, -1 if not used */
57    int fragcoord;
58 };
59 
60 struct ir2_shader_variant {
61    struct ir2_shader_info info;
62    struct ir2_frag_linkage f;
63 };
64 
65 struct fd2_shader_stateobj;
66 struct tgsi_token;
67 
68 void ir2_compile(struct fd2_shader_stateobj *so, unsigned variant,
69                  struct fd2_shader_stateobj *fp);
70 
71 struct nir_shader *ir2_tgsi_to_nir(const struct tgsi_token *tokens,
72                                    struct pipe_screen *screen);
73 
74 const nir_shader_compiler_options *ir2_get_compiler_options(void);
75 
76 int ir2_optimize_nir(nir_shader *s, bool lower);
77 
78 #endif /* IR2_H_ */
79