Path: blob/21.2-virgl/src/gallium/drivers/v3d/v3d_cl.c
4570 views
/*1* Copyright © 2014-2017 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 "v3d_context.h"26/* We don't expect that the packets we use in this file change across across27* hw versions, so we just explicitly set the V3D_VERSION and include28* v3dx_pack here29*/30#define V3D_VERSION 3331#include "broadcom/common/v3d_macros.h"32#include "broadcom/cle/v3dx_pack.h"3334void35v3d_init_cl(struct v3d_job *job, struct v3d_cl *cl)36{37cl->base = NULL;38cl->next = cl->base;39cl->size = 0;40cl->job = job;41}4243uint32_t44v3d_cl_ensure_space(struct v3d_cl *cl, uint32_t space, uint32_t alignment)45{46uint32_t offset = align(cl_offset(cl), alignment);4748if (offset + space <= cl->size) {49cl->next = cl->base + offset;50return offset;51}5253v3d_bo_unreference(&cl->bo);54cl->bo = v3d_bo_alloc(cl->job->v3d->screen, align(space, 4096), "CL");55cl->base = v3d_bo_map(cl->bo);56cl->size = cl->bo->size;57cl->next = cl->base;5859return 0;60}6162void63v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space)64{65if (cl_offset(cl) + space + cl_packet_length(BRANCH) <= cl->size)66return;6768struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen, space, "CL");69assert(space <= new_bo->size);7071/* Chain to the new BO from the old one. */72if (cl->bo) {73cl_emit(cl, BRANCH, branch) {74branch.address = cl_address(new_bo, 0);75}76v3d_bo_unreference(&cl->bo);77} else {78/* Root the first RCL/BCL BO in the job. */79v3d_job_add_bo(cl->job, new_bo);80}8182cl->bo = new_bo;83cl->base = v3d_bo_map(cl->bo);84cl->size = cl->bo->size;85cl->next = cl->base;86}8788void89v3d_destroy_cl(struct v3d_cl *cl)90{91v3d_bo_unreference(&cl->bo);92}939495