Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_cl.c
4570 views
/*1* Copyright © 2014 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "util/u_math.h"24#include "util/ralloc.h"25#include "vc4_context.h"2627void28vc4_init_cl(struct vc4_job *job, struct vc4_cl *cl)29{30cl->base = rzalloc_size(job, 1); /* TODO: don't use rzalloc */31cl->next = cl->base;32cl->size = 0;33cl->job = job;34}3536void37cl_ensure_space(struct vc4_cl *cl, uint32_t space)38{39uint32_t offset = cl_offset(cl);4041if (offset + space <= cl->size)42return;4344uint32_t size = MAX2(cl->size + space, cl->size * 2);4546cl->base = reralloc(ralloc_parent(cl->base), cl->base, uint8_t, size);47cl->size = size;48cl->next = cl->base + offset;49}5051void52vc4_reset_cl(struct vc4_cl *cl)53{54assert(cl->reloc_count == 0);55cl->next = cl->base;56}5758uint32_t59vc4_gem_hindex(struct vc4_job *job, struct vc4_bo *bo)60{61uint32_t hindex;62uint32_t *current_handles = job->bo_handles.base;63uint32_t cl_hindex_count = cl_offset(&job->bo_handles) / 4;64uint32_t last_hindex = bo->last_hindex; /* volatile read! */6566if (last_hindex < cl_hindex_count &&67current_handles[last_hindex] == bo->handle) {68return last_hindex;69}7071for (hindex = 0; hindex < cl_hindex_count; hindex++) {72if (current_handles[hindex] == bo->handle) {73bo->last_hindex = hindex;74return hindex;75}76}7778struct vc4_cl_out *out;7980out = cl_start(&job->bo_handles);81cl_u32(&out, bo->handle);82cl_end(&job->bo_handles, out);8384out = cl_start(&job->bo_pointers);85cl_ptr(&out, vc4_bo_reference(bo));86cl_end(&job->bo_pointers, out);8788job->bo_space += bo->size;8990bo->last_hindex = hindex;91return hindex;92}939495