2 * Copyright © 2014-2017 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/hash_table.h"
29 #include "util/ralloc.h"
30 #include "util/u_inlines.h"
31 #include "util/u_memory.h"
32 #include "util/u_blitter.h"
33 #include "util/u_upload_mgr.h"
34 #include "indices/u_primconvert.h"
35 #include "pipe/p_screen.h"
37 #include "v3d_screen.h"
38 #include "v3d_context.h"
39 #include "v3d_resource.h"
42 v3d_flush(struct pipe_context
*pctx
)
44 struct v3d_context
*v3d
= v3d_context(pctx
);
46 hash_table_foreach(v3d
->jobs
, entry
) {
47 struct v3d_job
*job
= entry
->data
;
48 v3d_job_submit(v3d
, job
);
53 v3d_pipe_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
56 struct v3d_context
*v3d
= v3d_context(pctx
);
61 struct pipe_screen
*screen
= pctx
->screen
;
62 struct v3d_fence
*f
= v3d_fence_create(v3d
);
63 screen
->fence_reference(screen
, fence
, NULL
);
64 *fence
= (struct pipe_fence_handle
*)f
;
69 v3d_set_debug_callback(struct pipe_context
*pctx
,
70 const struct pipe_debug_callback
*cb
)
72 struct v3d_context
*v3d
= v3d_context(pctx
);
77 memset(&v3d
->debug
, 0, sizeof(v3d
->debug
));
81 v3d_invalidate_resource(struct pipe_context
*pctx
, struct pipe_resource
*prsc
)
83 struct v3d_context
*v3d
= v3d_context(pctx
);
84 struct v3d_resource
*rsc
= v3d_resource(prsc
);
86 rsc
->initialized_buffers
= 0;
88 struct hash_entry
*entry
= _mesa_hash_table_search(v3d
->write_jobs
,
93 struct v3d_job
*job
= entry
->data
;
94 if (job
->key
.zsbuf
&& job
->key
.zsbuf
->texture
== prsc
)
95 job
->store
&= ~(PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
);
99 v3d_context_destroy(struct pipe_context
*pctx
)
101 struct v3d_context
*v3d
= v3d_context(pctx
);
106 util_blitter_destroy(v3d
->blitter
);
108 if (v3d
->primconvert
)
109 util_primconvert_destroy(v3d
->primconvert
);
112 u_upload_destroy(v3d
->uploader
);
113 if (v3d
->state_uploader
)
114 u_upload_destroy(v3d
->state_uploader
);
116 slab_destroy_child(&v3d
->transfer_pool
);
118 pipe_surface_reference(&v3d
->framebuffer
.cbufs
[0], NULL
);
119 pipe_surface_reference(&v3d
->framebuffer
.zsbuf
, NULL
);
121 v3d_program_fini(pctx
);
126 struct pipe_context
*
127 v3d_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
)
129 struct v3d_screen
*screen
= v3d_screen(pscreen
);
130 struct v3d_context
*v3d
;
132 /* Prevent dumping of the shaders built during context setup. */
133 uint32_t saved_shaderdb_flag
= V3D_DEBUG
& V3D_DEBUG_SHADERDB
;
134 V3D_DEBUG
&= ~V3D_DEBUG_SHADERDB
;
136 v3d
= rzalloc(NULL
, struct v3d_context
);
139 struct pipe_context
*pctx
= &v3d
->base
;
141 v3d
->screen
= screen
;
143 int ret
= drmSyncobjCreate(screen
->fd
, DRM_SYNCOBJ_CREATE_SIGNALED
,
150 pctx
->screen
= pscreen
;
152 pctx
->destroy
= v3d_context_destroy
;
153 pctx
->flush
= v3d_pipe_flush
;
154 pctx
->set_debug_callback
= v3d_set_debug_callback
;
155 pctx
->invalidate_resource
= v3d_invalidate_resource
;
157 if (screen
->devinfo
.ver
>= 41) {
158 v3d41_draw_init(pctx
);
159 v3d41_state_init(pctx
);
161 v3d33_draw_init(pctx
);
162 v3d33_state_init(pctx
);
164 v3d_program_init(pctx
);
165 v3d_query_init(pctx
);
166 v3d_resource_context_init(pctx
);
170 v3d
->fd
= screen
->fd
;
172 slab_create_child(&v3d
->transfer_pool
, &screen
->transfer_pool
);
174 v3d
->uploader
= u_upload_create_default(&v3d
->base
);
175 v3d
->base
.stream_uploader
= v3d
->uploader
;
176 v3d
->base
.const_uploader
= v3d
->uploader
;
177 v3d
->state_uploader
= u_upload_create(&v3d
->base
,
179 PIPE_BIND_CONSTANT_BUFFER
,
180 PIPE_USAGE_STREAM
, 0);
182 v3d
->blitter
= util_blitter_create(pctx
);
185 v3d
->blitter
->use_index_buffer
= true;
187 v3d
->primconvert
= util_primconvert_create(pctx
,
188 (1 << PIPE_PRIM_QUADS
) - 1);
189 if (!v3d
->primconvert
)
192 V3D_DEBUG
|= saved_shaderdb_flag
;
194 v3d
->sample_mask
= (1 << VC5_MAX_SAMPLES
) - 1;
195 v3d
->active_queries
= true;