1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2014-2017 Broadcom 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <xf86drm.h> 25bf215546Sopenharmony_ci#include <err.h> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "pipe/p_defines.h" 28bf215546Sopenharmony_ci#include "util/hash_table.h" 29bf215546Sopenharmony_ci#include "util/ralloc.h" 30bf215546Sopenharmony_ci#include "util/u_inlines.h" 31bf215546Sopenharmony_ci#include "util/u_memory.h" 32bf215546Sopenharmony_ci#include "util/u_blitter.h" 33bf215546Sopenharmony_ci#include "util/u_upload_mgr.h" 34bf215546Sopenharmony_ci#include "util/u_prim.h" 35bf215546Sopenharmony_ci#include "pipe/p_screen.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include "v3d_screen.h" 38bf215546Sopenharmony_ci#include "v3d_context.h" 39bf215546Sopenharmony_ci#include "v3d_resource.h" 40bf215546Sopenharmony_ci#include "broadcom/compiler/v3d_compiler.h" 41bf215546Sopenharmony_ci#include "broadcom/common/v3d_util.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_civoid 44bf215546Sopenharmony_civ3d_flush(struct pipe_context *pctx) 45bf215546Sopenharmony_ci{ 46bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci hash_table_foreach(v3d->jobs, entry) { 49bf215546Sopenharmony_ci struct v3d_job *job = entry->data; 50bf215546Sopenharmony_ci v3d_job_submit(v3d, job); 51bf215546Sopenharmony_ci } 52bf215546Sopenharmony_ci} 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_cistatic void 55bf215546Sopenharmony_civ3d_pipe_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence, 56bf215546Sopenharmony_ci unsigned flags) 57bf215546Sopenharmony_ci{ 58bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci v3d_flush(pctx); 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci if (fence) { 63bf215546Sopenharmony_ci struct pipe_screen *screen = pctx->screen; 64bf215546Sopenharmony_ci struct v3d_fence *f = v3d_fence_create(v3d); 65bf215546Sopenharmony_ci screen->fence_reference(screen, fence, NULL); 66bf215546Sopenharmony_ci *fence = (struct pipe_fence_handle *)f; 67bf215546Sopenharmony_ci } 68bf215546Sopenharmony_ci} 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_cistatic void 71bf215546Sopenharmony_civ3d_memory_barrier(struct pipe_context *pctx, unsigned int flags) 72bf215546Sopenharmony_ci{ 73bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci /* We only need to flush for SSBOs and images, because for everything 76bf215546Sopenharmony_ci * else we flush the job automatically when we needed. 77bf215546Sopenharmony_ci */ 78bf215546Sopenharmony_ci const unsigned int flush_flags = PIPE_BARRIER_SHADER_BUFFER | 79bf215546Sopenharmony_ci PIPE_BARRIER_IMAGE; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci if (!(flags & flush_flags)) 82bf215546Sopenharmony_ci return; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci /* We only need to flush jobs writing to SSBOs/images. */ 85bf215546Sopenharmony_ci perf_debug("Flushing all jobs for glMemoryBarrier(), could do better"); 86bf215546Sopenharmony_ci v3d_flush(pctx); 87bf215546Sopenharmony_ci} 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_cistatic void 90bf215546Sopenharmony_civ3d_set_debug_callback(struct pipe_context *pctx, 91bf215546Sopenharmony_ci const struct util_debug_callback *cb) 92bf215546Sopenharmony_ci{ 93bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci if (cb) 96bf215546Sopenharmony_ci v3d->debug = *cb; 97bf215546Sopenharmony_ci else 98bf215546Sopenharmony_ci memset(&v3d->debug, 0, sizeof(v3d->debug)); 99bf215546Sopenharmony_ci} 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_cistatic void 102bf215546Sopenharmony_civ3d_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc) 103bf215546Sopenharmony_ci{ 104bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 105bf215546Sopenharmony_ci struct v3d_resource *rsc = v3d_resource(prsc); 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci rsc->initialized_buffers = 0; 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci struct hash_entry *entry = _mesa_hash_table_search(v3d->write_jobs, 110bf215546Sopenharmony_ci prsc); 111bf215546Sopenharmony_ci if (!entry) 112bf215546Sopenharmony_ci return; 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci struct v3d_job *job = entry->data; 115bf215546Sopenharmony_ci if (job->key.zsbuf && job->key.zsbuf->texture == prsc) 116bf215546Sopenharmony_ci job->store &= ~(PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL); 117bf215546Sopenharmony_ci} 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci/** 120bf215546Sopenharmony_ci * Flushes the current job to get up-to-date primitive counts written to the 121bf215546Sopenharmony_ci * primitive counts BO, then accumulates the transform feedback primitive count 122bf215546Sopenharmony_ci * in the context and the corresponding vertex counts in the bound stream 123bf215546Sopenharmony_ci * output targets. 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_civoid 126bf215546Sopenharmony_civ3d_update_primitive_counters(struct v3d_context *v3d) 127bf215546Sopenharmony_ci{ 128bf215546Sopenharmony_ci struct v3d_job *job = v3d_get_job_for_fbo(v3d); 129bf215546Sopenharmony_ci if (job->draw_calls_queued == 0) 130bf215546Sopenharmony_ci return; 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci /* In order to get up-to-date primitive counts we need to submit 133bf215546Sopenharmony_ci * the job for execution so we get the counts written to memory. 134bf215546Sopenharmony_ci * Notice that this will require a sync wait for the buffer write. 135bf215546Sopenharmony_ci */ 136bf215546Sopenharmony_ci uint32_t prims_before = v3d->tf_prims_generated; 137bf215546Sopenharmony_ci v3d_job_submit(v3d, job); 138bf215546Sopenharmony_ci uint32_t prims_after = v3d->tf_prims_generated; 139bf215546Sopenharmony_ci if (prims_before == prims_after) 140bf215546Sopenharmony_ci return; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci enum pipe_prim_type prim_type = u_base_prim_type(v3d->prim_mode); 143bf215546Sopenharmony_ci uint32_t num_verts = u_vertices_for_prims(prim_type, 144bf215546Sopenharmony_ci prims_after - prims_before); 145bf215546Sopenharmony_ci for (int i = 0; i < v3d->streamout.num_targets; i++) { 146bf215546Sopenharmony_ci struct v3d_stream_output_target *so = 147bf215546Sopenharmony_ci v3d_stream_output_target(v3d->streamout.targets[i]); 148bf215546Sopenharmony_ci so->recorded_vertex_count += num_verts; 149bf215546Sopenharmony_ci } 150bf215546Sopenharmony_ci} 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_cibool 153bf215546Sopenharmony_civ3d_line_smoothing_enabled(struct v3d_context *v3d) 154bf215546Sopenharmony_ci{ 155bf215546Sopenharmony_ci if (!v3d->rasterizer->base.line_smooth) 156bf215546Sopenharmony_ci return false; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /* According to the OpenGL docs, line smoothing shouldn’t be applied 159bf215546Sopenharmony_ci * when multisampling 160bf215546Sopenharmony_ci */ 161bf215546Sopenharmony_ci if (v3d->job->msaa || v3d->rasterizer->base.multisample) 162bf215546Sopenharmony_ci return false; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci if (v3d->framebuffer.nr_cbufs <= 0) 165bf215546Sopenharmony_ci return false; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci struct pipe_surface *cbuf = v3d->framebuffer.cbufs[0]; 168bf215546Sopenharmony_ci if (!cbuf) 169bf215546Sopenharmony_ci return false; 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci /* Modifying the alpha for pure integer formats probably 172bf215546Sopenharmony_ci * doesn’t make sense because we don’t know how the application 173bf215546Sopenharmony_ci * uses the alpha value. 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ci if (util_format_is_pure_integer(cbuf->format)) 176bf215546Sopenharmony_ci return false; 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci return true; 179bf215546Sopenharmony_ci} 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_cifloat 182bf215546Sopenharmony_civ3d_get_real_line_width(struct v3d_context *v3d) 183bf215546Sopenharmony_ci{ 184bf215546Sopenharmony_ci float width = v3d->rasterizer->base.line_width; 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci if (v3d_line_smoothing_enabled(v3d)) { 187bf215546Sopenharmony_ci /* If line smoothing is enabled then we want to add some extra 188bf215546Sopenharmony_ci * pixels to the width in order to have some semi-transparent 189bf215546Sopenharmony_ci * edges. 190bf215546Sopenharmony_ci */ 191bf215546Sopenharmony_ci width = floorf(M_SQRT2 * width) + 3; 192bf215546Sopenharmony_ci } 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci return width; 195bf215546Sopenharmony_ci} 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_civoid 198bf215546Sopenharmony_civ3d_ensure_prim_counts_allocated(struct v3d_context *ctx) 199bf215546Sopenharmony_ci{ 200bf215546Sopenharmony_ci if (ctx->prim_counts) 201bf215546Sopenharmony_ci return; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci /* Init all 7 counters and 1 padding to 0 */ 204bf215546Sopenharmony_ci uint32_t zeroes[8] = { 0 }; 205bf215546Sopenharmony_ci u_upload_data(ctx->uploader, 206bf215546Sopenharmony_ci 0, sizeof(zeroes), 32, zeroes, 207bf215546Sopenharmony_ci &ctx->prim_counts_offset, 208bf215546Sopenharmony_ci &ctx->prim_counts); 209bf215546Sopenharmony_ci} 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_civoid 212bf215546Sopenharmony_civ3d_flag_dirty_sampler_state(struct v3d_context *v3d, 213bf215546Sopenharmony_ci enum pipe_shader_type shader) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci switch (shader) { 216bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 217bf215546Sopenharmony_ci v3d->dirty |= V3D_DIRTY_VERTTEX; 218bf215546Sopenharmony_ci break; 219bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 220bf215546Sopenharmony_ci v3d->dirty |= V3D_DIRTY_GEOMTEX; 221bf215546Sopenharmony_ci break; 222bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 223bf215546Sopenharmony_ci v3d->dirty |= V3D_DIRTY_FRAGTEX; 224bf215546Sopenharmony_ci break; 225bf215546Sopenharmony_ci case PIPE_SHADER_COMPUTE: 226bf215546Sopenharmony_ci v3d->dirty |= V3D_DIRTY_COMPTEX; 227bf215546Sopenharmony_ci break; 228bf215546Sopenharmony_ci default: 229bf215546Sopenharmony_ci unreachable("Unsupported shader stage"); 230bf215546Sopenharmony_ci } 231bf215546Sopenharmony_ci} 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_civoid 234bf215546Sopenharmony_civ3d_create_texture_shader_state_bo(struct v3d_context *v3d, 235bf215546Sopenharmony_ci struct v3d_sampler_view *so) 236bf215546Sopenharmony_ci{ 237bf215546Sopenharmony_ci if (v3d->screen->devinfo.ver >= 41) 238bf215546Sopenharmony_ci v3d41_create_texture_shader_state_bo(v3d, so); 239bf215546Sopenharmony_ci else 240bf215546Sopenharmony_ci v3d33_create_texture_shader_state_bo(v3d, so); 241bf215546Sopenharmony_ci} 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_civoid 244bf215546Sopenharmony_civ3d_get_tile_buffer_size(bool is_msaa, 245bf215546Sopenharmony_ci bool double_buffer, 246bf215546Sopenharmony_ci uint32_t nr_cbufs, 247bf215546Sopenharmony_ci struct pipe_surface **cbufs, 248bf215546Sopenharmony_ci struct pipe_surface *bbuf, 249bf215546Sopenharmony_ci uint32_t *tile_width, 250bf215546Sopenharmony_ci uint32_t *tile_height, 251bf215546Sopenharmony_ci uint32_t *max_bpp) 252bf215546Sopenharmony_ci{ 253bf215546Sopenharmony_ci assert(!is_msaa || !double_buffer); 254bf215546Sopenharmony_ci 255bf215546Sopenharmony_ci uint32_t max_cbuf_idx = 0; 256bf215546Sopenharmony_ci *max_bpp = 0; 257bf215546Sopenharmony_ci for (int i = 0; i < nr_cbufs; i++) { 258bf215546Sopenharmony_ci if (cbufs[i]) { 259bf215546Sopenharmony_ci struct v3d_surface *surf = v3d_surface(cbufs[i]); 260bf215546Sopenharmony_ci *max_bpp = MAX2(*max_bpp, surf->internal_bpp); 261bf215546Sopenharmony_ci max_cbuf_idx = MAX2(i, max_cbuf_idx); 262bf215546Sopenharmony_ci } 263bf215546Sopenharmony_ci } 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci if (bbuf) { 266bf215546Sopenharmony_ci struct v3d_surface *bsurf = v3d_surface(bbuf); 267bf215546Sopenharmony_ci assert(bbuf->texture->nr_samples <= 1 || is_msaa); 268bf215546Sopenharmony_ci *max_bpp = MAX2(*max_bpp, bsurf->internal_bpp); 269bf215546Sopenharmony_ci } 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ci v3d_choose_tile_size(max_cbuf_idx + 1, *max_bpp, 272bf215546Sopenharmony_ci is_msaa, double_buffer, 273bf215546Sopenharmony_ci tile_width, tile_height); 274bf215546Sopenharmony_ci} 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_cistatic void 277bf215546Sopenharmony_civ3d_context_destroy(struct pipe_context *pctx) 278bf215546Sopenharmony_ci{ 279bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_ci v3d_flush(pctx); 282bf215546Sopenharmony_ci 283bf215546Sopenharmony_ci if (v3d->blitter) 284bf215546Sopenharmony_ci util_blitter_destroy(v3d->blitter); 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci if (v3d->uploader) 287bf215546Sopenharmony_ci u_upload_destroy(v3d->uploader); 288bf215546Sopenharmony_ci if (v3d->state_uploader) 289bf215546Sopenharmony_ci u_upload_destroy(v3d->state_uploader); 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci if (v3d->prim_counts) 292bf215546Sopenharmony_ci pipe_resource_reference(&v3d->prim_counts, NULL); 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci slab_destroy_child(&v3d->transfer_pool); 295bf215546Sopenharmony_ci 296bf215546Sopenharmony_ci for (int i = 0; i < v3d->framebuffer.nr_cbufs; i++) 297bf215546Sopenharmony_ci pipe_surface_reference(&v3d->framebuffer.cbufs[i], NULL); 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_ci pipe_surface_reference(&v3d->framebuffer.zsbuf, NULL); 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci if (v3d->sand8_blit_vs) 302bf215546Sopenharmony_ci pctx->delete_vs_state(pctx, v3d->sand8_blit_vs); 303bf215546Sopenharmony_ci if (v3d->sand8_blit_fs_luma) 304bf215546Sopenharmony_ci pctx->delete_fs_state(pctx, v3d->sand8_blit_fs_luma); 305bf215546Sopenharmony_ci if (v3d->sand8_blit_fs_chroma) 306bf215546Sopenharmony_ci pctx->delete_fs_state(pctx, v3d->sand8_blit_fs_chroma); 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci v3d_program_fini(pctx); 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_ci ralloc_free(v3d); 311bf215546Sopenharmony_ci} 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_cistatic void 314bf215546Sopenharmony_civ3d_get_sample_position(struct pipe_context *pctx, 315bf215546Sopenharmony_ci unsigned sample_count, unsigned sample_index, 316bf215546Sopenharmony_ci float *xy) 317bf215546Sopenharmony_ci{ 318bf215546Sopenharmony_ci struct v3d_context *v3d = v3d_context(pctx); 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ci if (sample_count <= 1) { 321bf215546Sopenharmony_ci xy[0] = 0.5; 322bf215546Sopenharmony_ci xy[1] = 0.5; 323bf215546Sopenharmony_ci } else { 324bf215546Sopenharmony_ci static const int xoffsets_v33[] = { 1, -3, 3, -1 }; 325bf215546Sopenharmony_ci static const int xoffsets_v42[] = { -1, 3, -3, 1 }; 326bf215546Sopenharmony_ci const int *xoffsets = (v3d->screen->devinfo.ver >= 42 ? 327bf215546Sopenharmony_ci xoffsets_v42 : xoffsets_v33); 328bf215546Sopenharmony_ci 329bf215546Sopenharmony_ci xy[0] = 0.5 + xoffsets[sample_index] * .125; 330bf215546Sopenharmony_ci xy[1] = .125 + sample_index * .25; 331bf215546Sopenharmony_ci } 332bf215546Sopenharmony_ci} 333bf215546Sopenharmony_ci 334bf215546Sopenharmony_cistruct pipe_context * 335bf215546Sopenharmony_civ3d_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) 336bf215546Sopenharmony_ci{ 337bf215546Sopenharmony_ci struct v3d_screen *screen = v3d_screen(pscreen); 338bf215546Sopenharmony_ci struct v3d_context *v3d; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci /* Prevent dumping of the shaders built during context setup. */ 341bf215546Sopenharmony_ci uint32_t saved_shaderdb_flag = V3D_DEBUG & V3D_DEBUG_SHADERDB; 342bf215546Sopenharmony_ci V3D_DEBUG &= ~V3D_DEBUG_SHADERDB; 343bf215546Sopenharmony_ci 344bf215546Sopenharmony_ci v3d = rzalloc(NULL, struct v3d_context); 345bf215546Sopenharmony_ci if (!v3d) 346bf215546Sopenharmony_ci return NULL; 347bf215546Sopenharmony_ci struct pipe_context *pctx = &v3d->base; 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_ci v3d->screen = screen; 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci int ret = drmSyncobjCreate(screen->fd, DRM_SYNCOBJ_CREATE_SIGNALED, 352bf215546Sopenharmony_ci &v3d->out_sync); 353bf215546Sopenharmony_ci if (ret) { 354bf215546Sopenharmony_ci ralloc_free(v3d); 355bf215546Sopenharmony_ci return NULL; 356bf215546Sopenharmony_ci } 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci pctx->screen = pscreen; 359bf215546Sopenharmony_ci pctx->priv = priv; 360bf215546Sopenharmony_ci pctx->destroy = v3d_context_destroy; 361bf215546Sopenharmony_ci pctx->flush = v3d_pipe_flush; 362bf215546Sopenharmony_ci pctx->memory_barrier = v3d_memory_barrier; 363bf215546Sopenharmony_ci pctx->set_debug_callback = v3d_set_debug_callback; 364bf215546Sopenharmony_ci pctx->invalidate_resource = v3d_invalidate_resource; 365bf215546Sopenharmony_ci pctx->get_sample_position = v3d_get_sample_position; 366bf215546Sopenharmony_ci 367bf215546Sopenharmony_ci if (screen->devinfo.ver >= 41) { 368bf215546Sopenharmony_ci v3d41_draw_init(pctx); 369bf215546Sopenharmony_ci v3d41_state_init(pctx); 370bf215546Sopenharmony_ci } else { 371bf215546Sopenharmony_ci v3d33_draw_init(pctx); 372bf215546Sopenharmony_ci v3d33_state_init(pctx); 373bf215546Sopenharmony_ci } 374bf215546Sopenharmony_ci v3d_program_init(pctx); 375bf215546Sopenharmony_ci v3d_query_init(pctx); 376bf215546Sopenharmony_ci v3d_resource_context_init(pctx); 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci v3d_job_init(v3d); 379bf215546Sopenharmony_ci 380bf215546Sopenharmony_ci v3d->fd = screen->fd; 381bf215546Sopenharmony_ci 382bf215546Sopenharmony_ci slab_create_child(&v3d->transfer_pool, &screen->transfer_pool); 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_ci v3d->uploader = u_upload_create_default(&v3d->base); 385bf215546Sopenharmony_ci v3d->base.stream_uploader = v3d->uploader; 386bf215546Sopenharmony_ci v3d->base.const_uploader = v3d->uploader; 387bf215546Sopenharmony_ci v3d->state_uploader = u_upload_create(&v3d->base, 388bf215546Sopenharmony_ci 4096, 389bf215546Sopenharmony_ci PIPE_BIND_CONSTANT_BUFFER, 390bf215546Sopenharmony_ci PIPE_USAGE_STREAM, 0); 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci v3d->blitter = util_blitter_create(pctx); 393bf215546Sopenharmony_ci if (!v3d->blitter) 394bf215546Sopenharmony_ci goto fail; 395bf215546Sopenharmony_ci v3d->blitter->use_index_buffer = true; 396bf215546Sopenharmony_ci 397bf215546Sopenharmony_ci V3D_DEBUG |= saved_shaderdb_flag; 398bf215546Sopenharmony_ci 399bf215546Sopenharmony_ci v3d->sample_mask = (1 << V3D_MAX_SAMPLES) - 1; 400bf215546Sopenharmony_ci v3d->active_queries = true; 401bf215546Sopenharmony_ci 402bf215546Sopenharmony_ci return &v3d->base; 403bf215546Sopenharmony_ci 404bf215546Sopenharmony_cifail: 405bf215546Sopenharmony_ci pctx->destroy(pctx); 406bf215546Sopenharmony_ci return NULL; 407bf215546Sopenharmony_ci} 408