66cba1f33e0282ac9a86b7192501f0eebe3898d9
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
28 #include "pipe/p_defines.h"
29 #include "util/u_inlines.h"
30 #include "util/u_memory.h"
31 #include "util/u_blitter.h"
32 #include "indices/u_primconvert.h"
33 #include "pipe/p_screen.h"
37 #include "vc4_screen.h"
38 #include "vc4_context.h"
39 #include "vc4_resource.h"
42 dump_fbo(struct vc4_context
*vc4
, struct vc4_bo
*fbo
)
44 #ifndef USE_VC4_SIMULATOR
45 uint32_t *map
= vc4_bo_map(fbo
);
46 uint32_t width
= vc4
->framebuffer
.width
;
47 uint32_t height
= vc4
->framebuffer
.height
;
48 uint32_t chunk_w
= width
/ 79;
49 uint32_t chunk_h
= height
/ 40;
50 uint32_t found_colors
[10];
51 uint32_t num_found_colors
= 0;
53 for (int by
= 0; by
< height
; by
+= chunk_h
) {
54 for (int bx
= 0; bx
< width
; bx
+= chunk_w
) {
55 bool on
= false, black
= false;
57 for (int y
= by
; y
< MIN2(height
, by
+ chunk_h
); y
++) {
58 for (int x
= bx
; x
< MIN2(width
, bx
+ chunk_w
); x
++) {
59 uint32_t pix
= map
[y
* width
+ x
];
61 black
|= pix
== 0xff000000;
64 for (i
= 0; i
< num_found_colors
; i
++) {
65 if (pix
== found_colors
[i
])
68 if (i
== num_found_colors
&&
69 num_found_colors
< Elements(found_colors
))
70 found_colors
[num_found_colors
++] = pix
;
80 fprintf(stderr
, "\n");
83 for (int i
= 0; i
< num_found_colors
; i
++) {
84 fprintf(stderr
, "color %d: 0x%08x\n", i
, found_colors
[i
]);
90 vc4_flush(struct pipe_context
*pctx
)
92 struct vc4_context
*vc4
= vc4_context(pctx
);
94 if (!vc4
->needs_flush
)
97 struct vc4_surface
*csurf
= vc4_surface(vc4
->framebuffer
.cbufs
[0]);
98 struct vc4_resource
*ctex
= vc4_resource(csurf
->base
.texture
);
99 struct drm_vc4_submit_cl submit
;
100 memset(&submit
, 0, sizeof(submit
));
102 submit
.bo_handles
= vc4
->bo_handles
.base
;
103 submit
.bo_handle_count
= (vc4
->bo_handles
.next
-
104 vc4
->bo_handles
.base
) / 4;
105 submit
.bin_cl
= vc4
->bcl
.base
;
106 submit
.bin_cl_len
= vc4
->bcl
.next
- vc4
->bcl
.base
;
107 submit
.render_cl
= vc4
->rcl
.base
;
108 submit
.render_cl_len
= vc4
->rcl
.next
- vc4
->rcl
.base
;
109 submit
.shader_records
= vc4
->shader_rec
.base
;
110 submit
.shader_record_len
= vc4
->shader_rec
.next
- vc4
->shader_rec
.base
;
111 submit
.shader_record_count
= vc4
->shader_rec_count
;
113 #ifndef USE_VC4_SIMULATOR
114 int ret
= drmIoctl(vc4
->fd
, DRM_IOCTL_VC4_SUBMIT_CL
, &submit
);
116 errx(1, "VC4 submit failed\n");
118 vc4_simulator_flush(vc4
, csurf
);
120 vc4_reset_cl(&vc4
->bcl
);
121 vc4_reset_cl(&vc4
->rcl
);
122 vc4_reset_cl(&vc4
->shader_rec
);
123 vc4_reset_cl(&vc4
->bo_handles
);
124 vc4
->shader_rec_count
= 0;
126 vc4
->needs_flush
= false;
129 dump_fbo(vc4
, ctex
->bo
);
133 vc4_pipe_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
140 vc4_context_destroy(struct pipe_context
*pctx
)
142 struct vc4_context
*vc4
= vc4_context(pctx
);
145 util_blitter_destroy(vc4
->blitter
);
147 if (vc4
->primconvert
)
148 util_primconvert_destroy(vc4
->primconvert
);
150 util_slab_destroy(&vc4
->transfer_pool
);
155 struct pipe_context
*
156 vc4_context_create(struct pipe_screen
*pscreen
, void *priv
)
158 struct vc4_screen
*screen
= vc4_screen(pscreen
);
159 struct vc4_context
*vc4
;
161 vc4
= CALLOC_STRUCT(vc4_context
);
164 struct pipe_context
*pctx
= &vc4
->base
;
166 vc4
->screen
= screen
;
168 pctx
->screen
= pscreen
;
170 pctx
->destroy
= vc4_context_destroy
;
171 pctx
->flush
= vc4_pipe_flush
;
174 vc4_state_init(pctx
);
175 vc4_program_init(pctx
);
176 vc4_resource_context_init(pctx
);
178 vc4_init_cl(vc4
, &vc4
->bcl
);
179 vc4_init_cl(vc4
, &vc4
->rcl
);
180 vc4_init_cl(vc4
, &vc4
->shader_rec
);
181 vc4_init_cl(vc4
, &vc4
->bo_handles
);
184 vc4
->fd
= screen
->fd
;
186 util_slab_create(&vc4
->transfer_pool
, sizeof(struct pipe_transfer
),
187 16, UTIL_SLAB_SINGLETHREADED
);
188 vc4
->blitter
= util_blitter_create(pctx
);
192 vc4
->primconvert
= util_primconvert_create(pctx
,
193 !((1 << PIPE_PRIM_QUADS
) - 1));
194 if (!vc4
->primconvert
)