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
27 #include "pipe/p_defines.h"
28 #include "util/ralloc.h"
29 #include "util/u_inlines.h"
30 #include "util/u_memory.h"
31 #include "util/u_blitter.h"
32 #include "util/u_upload_mgr.h"
33 #include "indices/u_primconvert.h"
34 #include "pipe/p_screen.h"
36 #include "vc4_screen.h"
37 #include "vc4_context.h"
38 #include "vc4_resource.h"
41 vc4_flush(struct pipe_context
*pctx
)
43 struct vc4_context
*vc4
= vc4_context(pctx
);
45 hash_table_foreach(vc4
->jobs
, entry
) {
46 struct vc4_job
*job
= entry
->data
;
47 vc4_job_submit(vc4
, job
);
52 vc4_pipe_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
55 struct vc4_context
*vc4
= vc4_context(pctx
);
60 struct pipe_screen
*screen
= pctx
->screen
;
63 if (flags
& PIPE_FLUSH_FENCE_FD
) {
64 /* The vc4_fence takes ownership of the returned fd. */
65 drmSyncobjExportSyncFile(vc4
->fd
, vc4
->job_syncobj
,
69 struct vc4_fence
*f
= vc4_fence_create(vc4
->screen
,
72 screen
->fence_reference(screen
, fence
, NULL
);
73 *fence
= (struct pipe_fence_handle
*)f
;
77 /* We can't flush the texture cache within rendering a tile, so we have to
78 * flush all rendering to the kernel so that the next job reading from the
79 * tile gets a flushed cache.
82 vc4_texture_barrier(struct pipe_context
*pctx
, unsigned flags
)
88 vc4_set_debug_callback(struct pipe_context
*pctx
,
89 const struct pipe_debug_callback
*cb
)
91 struct vc4_context
*vc4
= vc4_context(pctx
);
96 memset(&vc4
->debug
, 0, sizeof(vc4
->debug
));
100 vc4_invalidate_resource(struct pipe_context
*pctx
, struct pipe_resource
*prsc
)
102 struct vc4_context
*vc4
= vc4_context(pctx
);
103 struct vc4_resource
*rsc
= vc4_resource(prsc
);
105 rsc
->initialized_buffers
= 0;
107 struct hash_entry
*entry
= _mesa_hash_table_search(vc4
->write_jobs
,
112 struct vc4_job
*job
= entry
->data
;
113 if (job
->key
.zsbuf
&& job
->key
.zsbuf
->texture
== prsc
)
114 job
->resolve
&= ~(PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
);
118 vc4_context_destroy(struct pipe_context
*pctx
)
120 struct vc4_context
*vc4
= vc4_context(pctx
);
125 util_blitter_destroy(vc4
->blitter
);
127 if (vc4
->primconvert
)
128 util_primconvert_destroy(vc4
->primconvert
);
131 u_upload_destroy(vc4
->uploader
);
133 slab_destroy_child(&vc4
->transfer_pool
);
135 pipe_surface_reference(&vc4
->framebuffer
.cbufs
[0], NULL
);
136 pipe_surface_reference(&vc4
->framebuffer
.zsbuf
, NULL
);
138 if (vc4
->yuv_linear_blit_vs
)
139 pctx
->delete_vs_state(pctx
, vc4
->yuv_linear_blit_vs
);
140 if (vc4
->yuv_linear_blit_fs_8bit
)
141 pctx
->delete_fs_state(pctx
, vc4
->yuv_linear_blit_fs_8bit
);
142 if (vc4
->yuv_linear_blit_fs_16bit
)
143 pctx
->delete_fs_state(pctx
, vc4
->yuv_linear_blit_fs_16bit
);
145 vc4_program_fini(pctx
);
147 if (vc4
->screen
->has_syncobj
) {
148 drmSyncobjDestroy(vc4
->fd
, vc4
->job_syncobj
);
149 drmSyncobjDestroy(vc4
->fd
, vc4
->in_syncobj
);
151 if (vc4
->in_fence_fd
>= 0)
152 close(vc4
->in_fence_fd
);
157 struct pipe_context
*
158 vc4_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
)
160 struct vc4_screen
*screen
= vc4_screen(pscreen
);
161 struct vc4_context
*vc4
;
164 /* Prevent dumping of the shaders built during context setup. */
165 uint32_t saved_shaderdb_flag
= vc4_debug
& VC4_DEBUG_SHADERDB
;
166 vc4_debug
&= ~VC4_DEBUG_SHADERDB
;
168 vc4
= rzalloc(NULL
, struct vc4_context
);
171 struct pipe_context
*pctx
= &vc4
->base
;
173 vc4
->screen
= screen
;
175 pctx
->screen
= pscreen
;
177 pctx
->destroy
= vc4_context_destroy
;
178 pctx
->flush
= vc4_pipe_flush
;
179 pctx
->set_debug_callback
= vc4_set_debug_callback
;
180 pctx
->invalidate_resource
= vc4_invalidate_resource
;
181 pctx
->texture_barrier
= vc4_texture_barrier
;
184 vc4_state_init(pctx
);
185 vc4_program_init(pctx
);
186 vc4_query_init(pctx
);
187 vc4_resource_context_init(pctx
);
189 vc4
->fd
= screen
->fd
;
191 err
= vc4_job_init(vc4
);
195 err
= vc4_fence_context_init(vc4
);
199 slab_create_child(&vc4
->transfer_pool
, &screen
->transfer_pool
);
201 vc4
->uploader
= u_upload_create_default(&vc4
->base
);
202 vc4
->base
.stream_uploader
= vc4
->uploader
;
203 vc4
->base
.const_uploader
= vc4
->uploader
;
205 vc4
->blitter
= util_blitter_create(pctx
);
209 vc4
->primconvert
= util_primconvert_create(pctx
,
210 (1 << PIPE_PRIM_QUADS
) - 1);
211 if (!vc4
->primconvert
)
214 vc4_debug
|= saved_shaderdb_flag
;
216 vc4
->sample_mask
= (1 << VC4_MAX_SAMPLES
) - 1;