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 "v3d_context.h"
27 /* The branching packets are the same across V3D versions. */
28 #define V3D_VERSION 33
29 #include "broadcom/common/v3d_macros.h"
30 #include "broadcom/cle/v3dx_pack.h"
33 v3d_init_cl(struct v3d_job
*job
, struct v3d_cl
*cl
)
42 v3d_cl_ensure_space(struct v3d_cl
*cl
, uint32_t space
, uint32_t alignment
)
44 uint32_t offset
= align(cl_offset(cl
), alignment
);
46 if (offset
+ space
<= cl
->size
) {
47 cl
->next
= cl
->base
+ offset
;
51 v3d_bo_unreference(&cl
->bo
);
52 cl
->bo
= v3d_bo_alloc(cl
->job
->v3d
->screen
, align(space
, 4096), "CL");
53 cl
->base
= v3d_bo_map(cl
->bo
);
54 cl
->size
= cl
->bo
->size
;
61 v3d_cl_ensure_space_with_branch(struct v3d_cl
*cl
, uint32_t space
)
63 if (cl_offset(cl
) + space
+ cl_packet_length(BRANCH
) <= cl
->size
)
66 struct v3d_bo
*new_bo
= v3d_bo_alloc(cl
->job
->v3d
->screen
, 4096, "CL");
67 assert(space
<= new_bo
->size
);
69 /* Chain to the new BO from the old one. */
71 cl_emit(cl
, BRANCH
, branch
) {
72 branch
.address
= cl_address(new_bo
, 0);
74 v3d_bo_unreference(&cl
->bo
);
76 /* Root the first RCL/BCL BO in the job. */
77 v3d_job_add_bo(cl
->job
, cl
->bo
);
81 cl
->base
= v3d_bo_map(cl
->bo
);
82 cl
->size
= cl
->bo
->size
;
87 v3d_destroy_cl(struct v3d_cl
*cl
)
89 v3d_bo_unreference(&cl
->bo
);