v3d: add new flag dirty TMU cache at v3d_compiler
[mesa.git] / src / gallium / drivers / v3d / v3d_cl.c
1 /*
2 * Copyright © 2014-2017 Broadcom
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
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"
31
32 void
33 v3d_init_cl(struct v3d_job *job, struct v3d_cl *cl)
34 {
35 cl->base = NULL;
36 cl->next = cl->base;
37 cl->size = 0;
38 cl->job = job;
39 }
40
41 uint32_t
42 v3d_cl_ensure_space(struct v3d_cl *cl, uint32_t space, uint32_t alignment)
43 {
44 uint32_t offset = align(cl_offset(cl), alignment);
45
46 if (offset + space <= cl->size) {
47 cl->next = cl->base + offset;
48 return offset;
49 }
50
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;
55 cl->next = cl->base;
56
57 return 0;
58 }
59
60 void
61 v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space)
62 {
63 if (cl_offset(cl) + space + cl_packet_length(BRANCH) <= cl->size)
64 return;
65
66 struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen, 4096, "CL");
67 assert(space <= new_bo->size);
68
69 /* Chain to the new BO from the old one. */
70 if (cl->bo) {
71 cl_emit(cl, BRANCH, branch) {
72 branch.address = cl_address(new_bo, 0);
73 }
74 v3d_bo_unreference(&cl->bo);
75 } else {
76 /* Root the first RCL/BCL BO in the job. */
77 v3d_job_add_bo(cl->job, cl->bo);
78 }
79
80 cl->bo = new_bo;
81 cl->base = v3d_bo_map(cl->bo);
82 cl->size = cl->bo->size;
83 cl->next = cl->base;
84 }
85
86 void
87 v3d_destroy_cl(struct v3d_cl *cl)
88 {
89 v3d_bo_unreference(&cl->bo);
90 }