2 * Copyright © 2014 Broadcom
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:
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
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
29 #include "util/u_math.h"
30 #include "util/macros.h"
32 #include "kernel/vc4_packet.h"
37 * Undefined structure, used for typechecking that you're passing the pointers
38 * to these functions correctly.
44 struct vc4_cl_out
*next
;
45 struct vc4_cl_out
*reloc_next
;
52 void vc4_init_cl(struct vc4_context
*vc4
, struct vc4_cl
*cl
);
53 void vc4_reset_cl(struct vc4_cl
*cl
);
54 void vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
);
55 uint32_t vc4_gem_hindex(struct vc4_context
*vc4
, struct vc4_bo
*bo
);
57 struct PACKED unaligned_16
{ uint16_t x
; };
58 struct PACKED unaligned_32
{ uint32_t x
; };
60 static inline uint32_t cl_offset(struct vc4_cl
*cl
)
62 return (char *)cl
->next
- (char *)cl
->base
;
66 cl_advance(struct vc4_cl_out
**cl
, uint32_t n
)
68 (*cl
) = (struct vc4_cl_out
*)((char *)(*cl
) + n
);
71 static inline struct vc4_cl_out
*
72 cl_start(struct vc4_cl
*cl
)
78 cl_end(struct vc4_cl
*cl
, struct vc4_cl_out
*next
)
81 assert(cl_offset(cl
) <= cl
->size
);
86 put_unaligned_32(struct vc4_cl_out
*ptr
, uint32_t val
)
88 struct unaligned_32
*p
= (void *)ptr
;
93 put_unaligned_16(struct vc4_cl_out
*ptr
, uint16_t val
)
95 struct unaligned_16
*p
= (void *)ptr
;
100 cl_u8(struct vc4_cl_out
**cl
, uint8_t n
)
102 *(uint8_t *)(*cl
) = n
;
107 cl_u16(struct vc4_cl_out
**cl
, uint16_t n
)
109 put_unaligned_16(*cl
, n
);
114 cl_u32(struct vc4_cl_out
**cl
, uint32_t n
)
116 put_unaligned_32(*cl
, n
);
121 cl_aligned_u32(struct vc4_cl_out
**cl
, uint32_t n
)
123 *(uint32_t *)(*cl
) = n
;
128 cl_ptr(struct vc4_cl_out
**cl
, void *ptr
)
130 *(struct vc4_cl_out
**)(*cl
) = ptr
;
131 cl_advance(cl
, sizeof(void *));
135 cl_f(struct vc4_cl_out
**cl
, float f
)
141 cl_aligned_f(struct vc4_cl_out
**cl
, float f
)
143 cl_aligned_u32(cl
, fui(f
));
147 cl_start_reloc(struct vc4_cl
*cl
, struct vc4_cl_out
**out
, uint32_t n
)
149 assert(n
== 1 || n
== 2);
151 assert(cl
->reloc_count
== 0);
155 cl_u8(out
, VC4_PACKET_GEM_HANDLES
);
156 cl
->reloc_next
= *out
;
157 cl_u32(out
, 0); /* Space where hindex will be written. */
158 cl_u32(out
, 0); /* Space where hindex will be written. */
161 static inline struct vc4_cl_out
*
162 cl_start_shader_reloc(struct vc4_cl
*cl
, uint32_t n
)
165 assert(cl
->reloc_count
== 0);
168 cl
->reloc_next
= cl
->next
;
170 /* Reserve the space where hindex will be written. */
171 cl_advance(&cl
->next
, n
* 4);
177 cl_reloc(struct vc4_context
*vc4
, struct vc4_cl
*cl
, struct vc4_cl_out
**cl_out
,
178 struct vc4_bo
*bo
, uint32_t offset
)
180 *(uint32_t *)cl
->reloc_next
= vc4_gem_hindex(vc4
, bo
);
181 cl_advance(&cl
->reloc_next
, 4);
187 cl_u32(cl_out
, offset
);
191 cl_aligned_reloc(struct vc4_context
*vc4
, struct vc4_cl
*cl
,
192 struct vc4_cl_out
**cl_out
,
193 struct vc4_bo
*bo
, uint32_t offset
)
195 *(uint32_t *)cl
->reloc_next
= vc4_gem_hindex(vc4
, bo
);
196 cl_advance(&cl
->reloc_next
, 4);
202 cl_aligned_u32(cl_out
, offset
);
205 void cl_ensure_space(struct vc4_cl
*cl
, uint32_t size
);
207 #endif /* VC4_CL_H */