nv50/ir: when merging immediates/consts, load directly
[mesa.git] / src / gallium / drivers / vc5 / vc5_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 "vc5_context.h"
27 #include "broadcom/cle/v3d_packet_v33_pack.h"
28
29 void
30 vc5_init_cl(struct vc5_job *job, struct vc5_cl *cl)
31 {
32 cl->base = NULL;
33 cl->next = cl->base;
34 cl->size = 0;
35 cl->job = job;
36 }
37
38 uint32_t
39 vc5_cl_ensure_space(struct vc5_cl *cl, uint32_t space, uint32_t alignment)
40 {
41 uint32_t offset = align(cl_offset(cl), alignment);
42
43 if (offset + space <= cl->size) {
44 cl->next = cl->base + offset;
45 return offset;
46 }
47
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;
52 cl->next = cl->base;
53
54 return 0;
55 }
56
57 void
58 vc5_cl_ensure_space_with_branch(struct vc5_cl *cl, uint32_t space)
59 {
60 if (cl_offset(cl) + space + cl_packet_length(BRANCH) <= cl->size)
61 return;
62
63 struct vc5_bo *new_bo = vc5_bo_alloc(cl->job->vc5->screen, 4096, "CL");
64 assert(space <= new_bo->size);
65
66 /* Chain to the new BO from the old one. */
67 if (cl->bo) {
68 cl_emit(cl, BRANCH, branch) {
69 branch.address = cl_address(new_bo, 0);
70 }
71 vc5_bo_unreference(&cl->bo);
72 } else {
73 /* Root the first RCL/BCL BO in the job. */
74 vc5_job_add_bo(cl->job, cl->bo);
75 }
76
77 cl->bo = new_bo;
78 cl->base = vc5_bo_map(cl->bo);
79 cl->size = cl->bo->size;
80 cl->next = cl->base;
81 }
82
83 void
84 vc5_destroy_cl(struct vc5_cl *cl)
85 {
86 vc5_bo_unreference(&cl->bo);
87 }