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 struct hash_entry
*entry
;
46 hash_table_foreach(vc4
->jobs
, entry
) {
47 struct vc4_job
*job
= entry
->data
;
48 vc4_job_submit(vc4
, job
);
53 vc4_pipe_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
56 struct vc4_context
*vc4
= vc4_context(pctx
);
61 struct pipe_screen
*screen
= pctx
->screen
;
62 struct vc4_fence
*f
= vc4_fence_create(vc4
->screen
,
63 vc4
->last_emit_seqno
);
64 screen
->fence_reference(screen
, fence
, NULL
);
65 *fence
= (struct pipe_fence_handle
*)f
;
69 /* We can't flush the texture cache within rendering a tile, so we have to
70 * flush all rendering to the kernel so that the next job reading from the
71 * tile gets a flushed cache.
74 vc4_texture_barrier(struct pipe_context
*pctx
, unsigned flags
)
80 vc4_invalidate_resource(struct pipe_context
*pctx
, struct pipe_resource
*prsc
)
82 struct vc4_context
*vc4
= vc4_context(pctx
);
83 struct vc4_resource
*rsc
= vc4_resource(prsc
);
85 rsc
->initialized_buffers
= 0;
87 struct hash_entry
*entry
= _mesa_hash_table_search(vc4
->write_jobs
,
92 struct vc4_job
*job
= entry
->data
;
93 if (job
->key
.zsbuf
&& job
->key
.zsbuf
->texture
== prsc
)
94 job
->resolve
&= ~(PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
);
98 vc4_context_destroy(struct pipe_context
*pctx
)
100 struct vc4_context
*vc4
= vc4_context(pctx
);
105 util_blitter_destroy(vc4
->blitter
);
107 if (vc4
->primconvert
)
108 util_primconvert_destroy(vc4
->primconvert
);
111 u_upload_destroy(vc4
->uploader
);
113 slab_destroy_child(&vc4
->transfer_pool
);
115 pipe_surface_reference(&vc4
->framebuffer
.cbufs
[0], NULL
);
116 pipe_surface_reference(&vc4
->framebuffer
.zsbuf
, NULL
);
118 if (vc4
->yuv_linear_blit_vs
)
119 pctx
->delete_vs_state(pctx
, vc4
->yuv_linear_blit_vs
);
120 if (vc4
->yuv_linear_blit_fs_8bit
)
121 pctx
->delete_fs_state(pctx
, vc4
->yuv_linear_blit_fs_8bit
);
122 if (vc4
->yuv_linear_blit_fs_16bit
)
123 pctx
->delete_fs_state(pctx
, vc4
->yuv_linear_blit_fs_16bit
);
125 vc4_program_fini(pctx
);
127 if (vc4
->screen
->has_syncobj
)
128 drmSyncobjDestroy(vc4
->fd
, vc4
->job_syncobj
);
133 struct pipe_context
*
134 vc4_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
)
136 struct vc4_screen
*screen
= vc4_screen(pscreen
);
137 struct vc4_context
*vc4
;
140 /* Prevent dumping of the shaders built during context setup. */
141 uint32_t saved_shaderdb_flag
= vc4_debug
& VC4_DEBUG_SHADERDB
;
142 vc4_debug
&= ~VC4_DEBUG_SHADERDB
;
144 vc4
= rzalloc(NULL
, struct vc4_context
);
147 struct pipe_context
*pctx
= &vc4
->base
;
149 vc4
->screen
= screen
;
151 pctx
->screen
= pscreen
;
153 pctx
->destroy
= vc4_context_destroy
;
154 pctx
->flush
= vc4_pipe_flush
;
155 pctx
->invalidate_resource
= vc4_invalidate_resource
;
156 pctx
->texture_barrier
= vc4_texture_barrier
;
159 vc4_state_init(pctx
);
160 vc4_program_init(pctx
);
161 vc4_query_init(pctx
);
162 vc4_resource_context_init(pctx
);
164 vc4
->fd
= screen
->fd
;
166 err
= vc4_job_init(vc4
);
170 slab_create_child(&vc4
->transfer_pool
, &screen
->transfer_pool
);
172 vc4
->uploader
= u_upload_create_default(&vc4
->base
);
173 vc4
->base
.stream_uploader
= vc4
->uploader
;
174 vc4
->base
.const_uploader
= vc4
->uploader
;
176 vc4
->blitter
= util_blitter_create(pctx
);
180 vc4
->primconvert
= util_primconvert_create(pctx
,
181 (1 << PIPE_PRIM_QUADS
) - 1);
182 if (!vc4
->primconvert
)
185 vc4_debug
|= saved_shaderdb_flag
;
187 vc4
->sample_mask
= (1 << VC4_MAX_SAMPLES
) - 1;