08e85ed6312e538b8f240501d12d94f44563c07a
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"
35 #include "vc4_screen.h"
36 #include "vc4_context.h"
37 #include "vc4_resource.h"
40 dump_fbo(struct vc4_context
*vc4
, struct vc4_bo
*fbo
)
42 #ifndef USE_VC4_SIMULATOR
43 uint32_t *map
= vc4_bo_map(fbo
);
44 uint32_t width
= vc4
->framebuffer
.width
;
45 uint32_t height
= vc4
->framebuffer
.height
;
46 uint32_t chunk_w
= width
/ 79;
47 uint32_t chunk_h
= height
/ 40;
48 uint32_t found_colors
[10];
49 uint32_t num_found_colors
= 0;
51 for (int by
= 0; by
< height
; by
+= chunk_h
) {
52 for (int bx
= 0; bx
< width
; bx
+= chunk_w
) {
53 bool on
= false, black
= false;
55 for (int y
= by
; y
< MIN2(height
, by
+ chunk_h
); y
++) {
56 for (int x
= bx
; x
< MIN2(width
, bx
+ chunk_w
); x
++) {
57 uint32_t pix
= map
[y
* width
+ x
];
59 black
|= pix
== 0xff000000;
62 for (i
= 0; i
< num_found_colors
; i
++) {
63 if (pix
== found_colors
[i
])
66 if (i
== num_found_colors
&&
67 num_found_colors
< Elements(found_colors
))
68 found_colors
[num_found_colors
++] = pix
;
78 fprintf(stderr
, "\n");
81 for (int i
= 0; i
< num_found_colors
; i
++) {
82 fprintf(stderr
, "color %d: 0x%08x\n", i
, found_colors
[i
]);
88 vc4_flush(struct pipe_context
*pctx
)
90 struct vc4_context
*vc4
= vc4_context(pctx
);
92 if (!vc4
->needs_flush
)
95 struct vc4_surface
*csurf
= vc4_surface(vc4
->framebuffer
.cbufs
[0]);
96 struct vc4_resource
*ctex
= vc4_resource(csurf
->base
.texture
);
97 struct drm_vc4_submit_cl submit
;
98 memset(&submit
, 0, sizeof(submit
));
100 submit
.bo_handles
= vc4
->bo_handles
.base
;
101 submit
.bo_handle_count
= (vc4
->bo_handles
.next
-
102 vc4
->bo_handles
.base
) / 4;
103 submit
.bin_cl
= vc4
->bcl
.base
;
104 submit
.bin_cl_len
= vc4
->bcl
.next
- vc4
->bcl
.base
;
105 submit
.render_cl
= vc4
->rcl
.base
;
106 submit
.render_cl_len
= vc4
->rcl
.next
- vc4
->rcl
.base
;
107 submit
.shader_records
= vc4
->shader_rec
.base
;
108 submit
.shader_record_len
= vc4
->shader_rec
.next
- vc4
->shader_rec
.base
;
109 submit
.shader_record_count
= vc4
->shader_rec_count
;
110 submit
.uniforms
= vc4
->uniforms
.base
;
111 submit
.uniforms_len
= vc4
->uniforms
.next
- vc4
->uniforms
.base
;
113 if (!(vc4_debug
& VC4_DEBUG_NORAST
)) {
116 #ifndef USE_VC4_SIMULATOR
117 ret
= drmIoctl(vc4
->fd
, DRM_IOCTL_VC4_SUBMIT_CL
, &submit
);
119 ret
= vc4_simulator_flush(vc4
, &submit
, csurf
);
122 errx(1, "VC4 submit failed\n");
125 vc4_reset_cl(&vc4
->bcl
);
126 vc4_reset_cl(&vc4
->rcl
);
127 vc4_reset_cl(&vc4
->shader_rec
);
128 vc4_reset_cl(&vc4
->uniforms
);
129 vc4_reset_cl(&vc4
->bo_handles
);
130 #ifdef USE_VC4_SIMULATOR
131 vc4_reset_cl(&vc4
->bo_pointers
);
133 vc4
->shader_rec_count
= 0;
135 vc4
->needs_flush
= false;
138 dump_fbo(vc4
, ctex
->bo
);
142 vc4_pipe_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
149 vc4_context_destroy(struct pipe_context
*pctx
)
151 struct vc4_context
*vc4
= vc4_context(pctx
);
154 util_blitter_destroy(vc4
->blitter
);
156 if (vc4
->primconvert
)
157 util_primconvert_destroy(vc4
->primconvert
);
159 util_slab_destroy(&vc4
->transfer_pool
);
164 struct pipe_context
*
165 vc4_context_create(struct pipe_screen
*pscreen
, void *priv
)
167 struct vc4_screen
*screen
= vc4_screen(pscreen
);
168 struct vc4_context
*vc4
;
170 /* Prevent dumping of the shaders built during context setup. */
171 uint32_t saved_shaderdb_flag
= vc4_debug
& VC4_DEBUG_SHADERDB
;
172 vc4_debug
&= ~VC4_DEBUG_SHADERDB
;
174 vc4
= CALLOC_STRUCT(vc4_context
);
177 struct pipe_context
*pctx
= &vc4
->base
;
179 vc4
->screen
= screen
;
181 pctx
->screen
= pscreen
;
183 pctx
->destroy
= vc4_context_destroy
;
184 pctx
->flush
= vc4_pipe_flush
;
187 vc4_state_init(pctx
);
188 vc4_program_init(pctx
);
189 vc4_resource_context_init(pctx
);
191 vc4_init_cl(vc4
, &vc4
->bcl
);
192 vc4_init_cl(vc4
, &vc4
->rcl
);
193 vc4_init_cl(vc4
, &vc4
->shader_rec
);
194 vc4_init_cl(vc4
, &vc4
->bo_handles
);
197 vc4
->fd
= screen
->fd
;
199 util_slab_create(&vc4
->transfer_pool
, sizeof(struct pipe_transfer
),
200 16, UTIL_SLAB_SINGLETHREADED
);
201 vc4
->blitter
= util_blitter_create(pctx
);
205 vc4
->primconvert
= util_primconvert_create(pctx
,
206 !((1 << PIPE_PRIM_QUADS
) - 1));
207 if (!vc4
->primconvert
)
210 vc4_debug
|= saved_shaderdb_flag
;