vc4: Make some assertions about how many flushes/EOFs the simulator sees.
[mesa.git] / src / gallium / drivers / vc4 / vc4_cl.h
1 /*
2 * Copyright © 2014 Broadcom
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, sublicense,
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 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 NONINFRINGEMENT. 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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef VC4_CL_H
25 #define VC4_CL_H
26
27 #include <stdint.h>
28
29 #include "util/u_math.h"
30
31 #include "vc4_packet.h"
32
33 struct vc4_bo;
34
35 struct vc4_cl {
36 void *base;
37 void *next;
38 void *end;
39 uint32_t reloc_next;
40 uint32_t reloc_count;
41 };
42
43 void vc4_init_cl(struct vc4_context *vc4, struct vc4_cl *cl);
44 void vc4_grow_cl(struct vc4_cl *cl);
45 void vc4_reset_cl(struct vc4_cl *cl);
46 void vc4_dump_cl(void *cl, uint32_t size, bool is_render);
47 uint32_t vc4_gem_hindex(struct vc4_context *vc4, struct vc4_bo *bo);
48
49 static inline void
50 cl_u8(struct vc4_cl *cl, uint8_t n)
51 {
52 if (cl->next + 1 > cl->end)
53 vc4_grow_cl(cl);
54
55 *(uint8_t *)cl->next = n;
56 cl->next++;
57 }
58
59 static inline void
60 cl_u16(struct vc4_cl *cl, uint32_t n)
61 {
62 if (cl->next + 2 > cl->end)
63 vc4_grow_cl(cl);
64
65 *(uint16_t *)cl->next = n;
66 cl->next += 2;
67 }
68
69 static inline void
70 cl_u32(struct vc4_cl *cl, uint32_t n)
71 {
72 if (cl->next + 4 > cl->end)
73 vc4_grow_cl(cl);
74
75 *(uint32_t *)cl->next = n;
76 cl->next += 4;
77 }
78
79 static inline void
80 cl_ptr(struct vc4_cl *cl, void *ptr)
81 {
82 if (cl->next + sizeof(void *) > cl->end)
83 vc4_grow_cl(cl);
84
85 *(void **)cl->next = ptr;
86 cl->next += sizeof(void *);
87 }
88
89 static inline void
90 cl_f(struct vc4_cl *cl, float f)
91 {
92 cl_u32(cl, fui(f));
93 }
94
95 static inline void
96 cl_start_reloc(struct vc4_cl *cl, uint32_t n)
97 {
98 assert(n == 1 || n == 2);
99 assert(cl->reloc_count == 0);
100 cl->reloc_count = n;
101
102 cl_u8(cl, VC4_PACKET_GEM_HANDLES);
103 cl->reloc_next = cl->next - cl->base;
104 cl_u32(cl, 0); /* Space where hindex will be written. */
105 cl_u32(cl, 0); /* Space where hindex will be written. */
106 }
107
108 static inline void
109 cl_start_shader_reloc(struct vc4_cl *cl, uint32_t n)
110 {
111 assert(cl->reloc_count == 0);
112 cl->reloc_count = n;
113 cl->reloc_next = cl->next - cl->base;
114
115 for (int i = 0; i < n; i++)
116 cl_u32(cl, 0); /* Space where hindex will be written. */
117 }
118
119 static inline void
120 cl_reloc(struct vc4_context *vc4, struct vc4_cl *cl,
121 struct vc4_bo *bo, uint32_t offset)
122 {
123 *(uint32_t *)(cl->base + cl->reloc_next) = vc4_gem_hindex(vc4, bo);
124 cl->reloc_next += 4;
125
126 cl->reloc_count--;
127
128 cl_u32(cl, offset);
129 }
130
131 #endif /* VC4_CL_H */