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"
38 * Undefined structure, used for typechecking that you're passing the pointers
39 * to these functions correctly.
45 struct vc4_cl_out
*next
;
46 struct vc4_cl_out
*reloc_next
;
53 void vc4_init_cl(void *mem_ctx
, struct vc4_cl
*cl
);
54 void vc4_reset_cl(struct vc4_cl
*cl
);
55 void vc4_dump_cl(void *cl
, uint32_t size
, bool is_render
);
56 uint32_t vc4_gem_hindex(struct vc4_job
*job
, struct vc4_bo
*bo
);
58 struct PACKED unaligned_16
{ uint16_t x
; };
59 struct PACKED unaligned_32
{ uint32_t x
; };
61 static inline uint32_t cl_offset(struct vc4_cl
*cl
)
63 return (char *)cl
->next
- (char *)cl
->base
;
67 cl_advance(struct vc4_cl_out
**cl
, uint32_t n
)
69 (*cl
) = (struct vc4_cl_out
*)((char *)(*cl
) + n
);
72 static inline struct vc4_cl_out
*
73 cl_start(struct vc4_cl
*cl
)
79 cl_end(struct vc4_cl
*cl
, struct vc4_cl_out
*next
)
82 assert(cl_offset(cl
) <= cl
->size
);
87 put_unaligned_32(struct vc4_cl_out
*ptr
, uint32_t val
)
89 struct unaligned_32
*p
= (void *)ptr
;
94 put_unaligned_16(struct vc4_cl_out
*ptr
, uint16_t val
)
96 struct unaligned_16
*p
= (void *)ptr
;
101 cl_u8(struct vc4_cl_out
**cl
, uint8_t n
)
103 *(uint8_t *)(*cl
) = n
;
108 cl_u16(struct vc4_cl_out
**cl
, uint16_t n
)
110 put_unaligned_16(*cl
, n
);
115 cl_u32(struct vc4_cl_out
**cl
, uint32_t n
)
117 put_unaligned_32(*cl
, n
);
122 cl_aligned_u32(struct vc4_cl_out
**cl
, uint32_t n
)
124 *(uint32_t *)(*cl
) = n
;
129 cl_ptr(struct vc4_cl_out
**cl
, void *ptr
)
131 *(struct vc4_cl_out
**)(*cl
) = ptr
;
132 cl_advance(cl
, sizeof(void *));
136 cl_f(struct vc4_cl_out
**cl
, float f
)
142 cl_aligned_f(struct vc4_cl_out
**cl
, float f
)
144 cl_aligned_u32(cl
, fui(f
));
148 cl_start_reloc(struct vc4_cl
*cl
, struct vc4_cl_out
**out
, uint32_t n
)
150 assert(n
== 1 || n
== 2);
152 assert(cl
->reloc_count
== 0);
156 cl_u8(out
, VC4_PACKET_GEM_HANDLES
);
157 cl
->reloc_next
= *out
;
158 cl_u32(out
, 0); /* Space where hindex will be written. */
159 cl_u32(out
, 0); /* Space where hindex will be written. */
162 static inline struct vc4_cl_out
*
163 cl_start_shader_reloc(struct vc4_cl
*cl
, uint32_t n
)
166 assert(cl
->reloc_count
== 0);
169 cl
->reloc_next
= cl
->next
;
171 /* Reserve the space where hindex will be written. */
172 cl_advance(&cl
->next
, n
* 4);
178 cl_reloc(struct vc4_job
*job
, struct vc4_cl
*cl
, struct vc4_cl_out
**cl_out
,
179 struct vc4_bo
*bo
, uint32_t offset
)
181 *(uint32_t *)cl
->reloc_next
= vc4_gem_hindex(job
, bo
);
182 cl_advance(&cl
->reloc_next
, 4);
188 cl_u32(cl_out
, offset
);
192 cl_aligned_reloc(struct vc4_job
*job
, struct vc4_cl
*cl
,
193 struct vc4_cl_out
**cl_out
,
194 struct vc4_bo
*bo
, uint32_t offset
)
196 *(uint32_t *)cl
->reloc_next
= vc4_gem_hindex(job
, bo
);
197 cl_advance(&cl
->reloc_next
, 4);
203 cl_aligned_u32(cl_out
, offset
);
206 void cl_ensure_space(struct vc4_cl
*cl
, uint32_t size
);
208 #endif /* VC4_CL_H */