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 "vc4_packet.h"
44 void vc4_init_cl(struct vc4_context
*vc4
, 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
);
49 struct PACKED unaligned_16
{ uint16_t x
; };
50 struct PACKED unaligned_32
{ uint32_t x
; };
53 put_unaligned_32(void *ptr
, uint32_t val
)
55 struct unaligned_32
*p
= ptr
;
60 put_unaligned_16(void *ptr
, uint16_t val
)
62 struct unaligned_16
*p
= ptr
;
67 cl_u8(struct vc4_cl
*cl
, uint8_t n
)
69 assert((cl
->next
- cl
->base
) + 1 <= cl
->size
);
71 *(uint8_t *)cl
->next
= n
;
76 cl_u16(struct vc4_cl
*cl
, uint16_t n
)
78 assert((cl
->next
- cl
->base
) + 2 <= cl
->size
);
80 put_unaligned_16(cl
->next
, n
);
85 cl_u32(struct vc4_cl
*cl
, uint32_t n
)
87 assert((cl
->next
- cl
->base
) + 4 <= cl
->size
);
89 put_unaligned_32(cl
->next
, n
);
94 cl_aligned_u32(struct vc4_cl
*cl
, uint32_t n
)
96 assert((cl
->next
- cl
->base
) + 4 <= cl
->size
);
98 *(uint32_t *)cl
->next
= n
;
103 cl_ptr(struct vc4_cl
*cl
, void *ptr
)
105 assert((cl
->next
- cl
->base
) + sizeof(void *) <= cl
->size
);
107 *(void **)cl
->next
= ptr
;
108 cl
->next
+= sizeof(void *);
112 cl_f(struct vc4_cl
*cl
, float f
)
118 cl_aligned_f(struct vc4_cl
*cl
, float f
)
120 cl_aligned_u32(cl
, fui(f
));
124 cl_start_reloc(struct vc4_cl
*cl
, uint32_t n
)
126 assert(n
== 1 || n
== 2);
127 assert(cl
->reloc_count
== 0);
130 cl_u8(cl
, VC4_PACKET_GEM_HANDLES
);
131 cl
->reloc_next
= cl
->next
- cl
->base
;
132 cl_u32(cl
, 0); /* Space where hindex will be written. */
133 cl_u32(cl
, 0); /* Space where hindex will be written. */
137 cl_start_shader_reloc(struct vc4_cl
*cl
, uint32_t n
)
139 assert(cl
->reloc_count
== 0);
141 cl
->reloc_next
= cl
->next
- cl
->base
;
143 /* Space where hindex will be written. */
148 cl_reloc_hindex(struct vc4_cl
*cl
, uint32_t hindex
, uint32_t offset
)
150 *(uint32_t *)(cl
->base
+ cl
->reloc_next
) = hindex
;
159 cl_aligned_reloc_hindex(struct vc4_cl
*cl
, uint32_t hindex
, uint32_t offset
)
161 *(uint32_t *)(cl
->base
+ cl
->reloc_next
) = hindex
;
166 cl_aligned_u32(cl
, offset
);
170 cl_reloc(struct vc4_context
*vc4
, struct vc4_cl
*cl
,
171 struct vc4_bo
*bo
, uint32_t offset
)
173 cl_reloc_hindex(cl
, vc4_gem_hindex(vc4
, bo
), offset
);
177 cl_aligned_reloc(struct vc4_context
*vc4
, struct vc4_cl
*cl
,
178 struct vc4_bo
*bo
, uint32_t offset
)
180 cl_aligned_reloc_hindex(cl
, vc4_gem_hindex(vc4
, bo
), offset
);
183 void cl_ensure_space(struct vc4_cl
*cl
, uint32_t size
);
185 #endif /* VC4_CL_H */