2 * Copyright © 2014-2017 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
24 #include "util/u_math.h"
25 #include "util/ralloc.h"
26 #include "vc5_context.h"
27 #include "broadcom/cle/v3d_packet_v33_pack.h"
30 vc5_init_cl(struct vc5_job
*job
, struct vc5_cl
*cl
)
39 vc5_cl_ensure_space(struct vc5_cl
*cl
, uint32_t space
, uint32_t alignment
)
41 uint32_t offset
= align(cl_offset(cl
), alignment
);
43 if (offset
+ space
<= cl
->size
) {
44 cl
->next
= cl
->base
+ offset
;
48 vc5_bo_unreference(&cl
->bo
);
49 cl
->bo
= vc5_bo_alloc(cl
->job
->vc5
->screen
, align(space
, 4096), "CL");
50 cl
->base
= vc5_bo_map(cl
->bo
);
51 cl
->size
= cl
->bo
->size
;
58 vc5_cl_ensure_space_with_branch(struct vc5_cl
*cl
, uint32_t space
)
60 if (cl_offset(cl
) + space
+ cl_packet_length(BRANCH
) <= cl
->size
)
63 struct vc5_bo
*new_bo
= vc5_bo_alloc(cl
->job
->vc5
->screen
, 4096, "CL");
64 assert(space
<= new_bo
->size
);
66 /* Chain to the new BO from the old one. */
68 cl_emit(cl
, BRANCH
, branch
) {
69 branch
.address
= cl_address(new_bo
, 0);
71 vc5_bo_unreference(&cl
->bo
);
73 /* Root the first RCL/BCL BO in the job. */
74 vc5_job_add_bo(cl
->job
, cl
->bo
);
78 cl
->base
= vc5_bo_map(cl
->bo
);
79 cl
->size
= cl
->bo
->size
;
84 vc5_destroy_cl(struct vc5_cl
*cl
)
86 vc5_bo_unreference(&cl
->bo
);