1 /*
2 * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
3 * SPDX-License-Identifier: MIT
4 */
5 #ifndef NVK_MME_H
6 #define NVK_MME_H 1
7
8 #include "mme_builder.h"
9
10 struct nv_device_info;
11
12 enum nvk_mme {
13 NVK_MME_BIND_CBUF_DESC,
14 NVK_MME_CLEAR,
15 NVK_MME_DRAW,
16 NVK_MME_DRAW_INDEXED,
17 NVK_MME_DRAW_INDIRECT,
18 NVK_MME_DRAW_INDEXED_INDIRECT,
19 NVK_MME_DRAW_INDIRECT_COUNT,
20 NVK_MME_DRAW_INDEXED_INDIRECT_COUNT,
21 NVK_MME_ADD_CS_INVOCATIONS,
22 NVK_MME_DISPATCH_INDIRECT,
23 NVK_MME_WRITE_CS_INVOCATIONS,
24 NVK_MME_COPY_QUERIES,
25 NVK_MME_XFB_COUNTER_LOAD,
26 NVK_MME_XFB_DRAW_INDIRECT,
27 NVK_MME_SET_PRIV_REG,
28 NVK_MME_SET_WRITE_MASK,
29 NVK_MME_COUNT,
30 };
31
32 enum nvk_mme_scratch {
33 NVK_MME_SCRATCH_CS_INVOCATIONS_HI = 0,
34 NVK_MME_SCRATCH_CS_INVOCATIONS_LO,
35 NVK_MME_SCRATCH_DRAW_BEGIN,
36 NVK_MME_SCRATCH_DRAW_COUNT,
37 NVK_MME_SCRATCH_DRAW_PAD_DW,
38 NVK_MME_SCRATCH_DRAW_IDX,
39 NVK_MME_SCRATCH_VIEW_MASK,
40
41 /* Must be at the end */
42 NVK_MME_NUM_SCRATCH,
43 };
44
45 static inline void
_nvk_mme_load_scratch_to(struct mme_builder * b,struct mme_value val,enum nvk_mme_scratch scratch)46 _nvk_mme_load_scratch_to(struct mme_builder *b, struct mme_value val,
47 enum nvk_mme_scratch scratch)
48 {
49 mme_state_to(b, val, 0x3400 + scratch * 4);
50 }
51
52 static inline struct mme_value
_nvk_mme_load_scratch(struct mme_builder * b,enum nvk_mme_scratch scratch)53 _nvk_mme_load_scratch(struct mme_builder *b, enum nvk_mme_scratch scratch)
54 {
55 struct mme_value val = mme_alloc_reg(b);
56 _nvk_mme_load_scratch_to(b, val, scratch);
57 return val;
58 }
59 #define nvk_mme_load_scratch(b, S) \
60 _nvk_mme_load_scratch(b, NVK_MME_SCRATCH_##S)
61
62 static inline void
_nvk_mme_store_scratch(struct mme_builder * b,enum nvk_mme_scratch scratch,struct mme_value data)63 _nvk_mme_store_scratch(struct mme_builder *b, enum nvk_mme_scratch scratch,
64 struct mme_value data)
65 {
66 mme_mthd(b, 0x3400 + scratch * 4);
67 mme_emit(b, data);
68 }
69 #define nvk_mme_store_scratch(b, S, v) \
70 _nvk_mme_store_scratch(b, NVK_MME_SCRATCH_##S, v)
71
72 static inline void
_nvk_mme_load_to_scratch(struct mme_builder * b,enum nvk_mme_scratch scratch)73 _nvk_mme_load_to_scratch(struct mme_builder *b, enum nvk_mme_scratch scratch)
74 {
75 struct mme_value val = mme_load(b);
76 _nvk_mme_store_scratch(b, scratch, val);
77 mme_free_reg(b, val);
78 }
79 #define nvk_mme_load_to_scratch(b, S) \
80 _nvk_mme_load_to_scratch(b, NVK_MME_SCRATCH_##S)
81
82 static void
_nvk_mme_spill(struct mme_builder * b,enum nvk_mme_scratch scratch,struct mme_value val)83 _nvk_mme_spill(struct mme_builder *b, enum nvk_mme_scratch scratch,
84 struct mme_value val)
85 {
86 if (val.type == MME_VALUE_TYPE_REG) {
87 _nvk_mme_store_scratch(b, scratch, val);
88 mme_free_reg(b, val);
89 }
90 }
91 #define nvk_mme_spill(b, S, v) \
92 _nvk_mme_spill(b, NVK_MME_SCRATCH_##S, v)
93
94 static void
_nvk_mme_unspill(struct mme_builder * b,enum nvk_mme_scratch scratch,struct mme_value val)95 _nvk_mme_unspill(struct mme_builder *b, enum nvk_mme_scratch scratch,
96 struct mme_value val)
97 {
98 if (val.type == MME_VALUE_TYPE_REG) {
99 mme_realloc_reg(b, val);
100 _nvk_mme_load_scratch_to(b, val, scratch);
101 }
102 }
103 #define nvk_mme_unspill(b, S, v) \
104 _nvk_mme_unspill(b, NVK_MME_SCRATCH_##S, v)
105
106 typedef void (*nvk_mme_builder_func)(struct mme_builder *b);
107
108 uint32_t *nvk_build_mme(const struct nv_device_info *devinfo,
109 enum nvk_mme mme, size_t *size_out);
110
111 void nvk_test_build_all_mmes(const struct nv_device_info *devinfo);
112
113 void nvk_mme_bind_cbuf_desc(struct mme_builder *b);
114 void nvk_mme_clear(struct mme_builder *b);
115 void nvk_mme_draw(struct mme_builder *b);
116 void nvk_mme_draw_indexed(struct mme_builder *b);
117 void nvk_mme_draw_indirect(struct mme_builder *b);
118 void nvk_mme_draw_indexed_indirect(struct mme_builder *b);
119 void nvk_mme_draw_indirect_count(struct mme_builder *b);
120 void nvk_mme_draw_indexed_indirect_count(struct mme_builder *b);
121 void nvk_mme_add_cs_invocations(struct mme_builder *b);
122 void nvk_mme_dispatch_indirect(struct mme_builder *b);
123 void nvk_mme_write_cs_invocations(struct mme_builder *b);
124 void nvk_mme_copy_queries(struct mme_builder *b);
125 void nvk_mme_xfb_counter_load(struct mme_builder *b);
126 void nvk_mme_xfb_draw_indirect(struct mme_builder *b);
127 void nvk_mme_set_priv_reg(struct mme_builder *b);
128 void nvk_mme_set_write_mask(struct mme_builder *b);
129
130 #endif /* NVK_MME_H */
131