Path: blob/21.2-virgl/src/gallium/drivers/asahi/agx_uniforms.c
4570 views
/*1* Copyright 2021 Alyssa Rosenzweig2*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* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/22#include <stdio.h>23#include "agx_state.h"24#include "asahi/lib/agx_pack.h"2526/* Computes the address for a push uniform, adding referenced BOs to the27* current batch as necessary. Note anything uploaded via the batch's pool does28* not require an update to the BO list, since the entire pool will be added29* once at submit time. */3031static uint64_t32agx_const_buffer_ptr(struct agx_batch *batch,33struct pipe_constant_buffer *cb)34{35if (cb->buffer) {36struct agx_bo *bo = agx_resource(cb->buffer)->bo;37agx_batch_add_bo(batch, bo);3839return bo->ptr.gpu + cb->buffer_offset;40} else {41return agx_pool_upload_aligned(&batch->pool,42((uint8_t *) cb->user_buffer) + cb->buffer_offset,43cb->buffer_size - cb->buffer_offset, 64);44}45}4647static uint64_t48agx_push_location_direct(struct agx_context *ctx, struct agx_push push,49enum pipe_shader_type stage)50{51struct agx_batch *batch = ctx->batch;52struct agx_stage *st = &ctx->stage[stage];5354switch (push.type) {55case AGX_PUSH_UBO_BASES: {56unsigned count = util_last_bit(st->cb_mask);57struct agx_ptr ptr = agx_pool_alloc_aligned(&batch->pool, count * sizeof(uint64_t), 8);58uint64_t *addresses = ptr.cpu;5960for (unsigned i = 0; i < count; ++i) {61struct pipe_constant_buffer *cb = &st->cb[i];62addresses[i] = agx_const_buffer_ptr(batch, cb);63}6465return ptr.gpu;66}6768case AGX_PUSH_VBO_BASES: {69unsigned count = util_last_bit(ctx->vb_mask);70struct agx_ptr ptr = agx_pool_alloc_aligned(&batch->pool, count * sizeof(uint64_t), 8);71uint64_t *addresses = ptr.cpu;7273u_foreach_bit(i, ctx->vb_mask) {74struct pipe_vertex_buffer vb = ctx->vertex_buffers[i];75assert(!vb.is_user_buffer);7677struct agx_bo *bo = agx_resource(vb.buffer.resource)->bo;78agx_batch_add_bo(batch, bo);7980addresses[i] = bo->ptr.gpu + vb.buffer_offset;81}8283return ptr.gpu;84}8586case AGX_PUSH_BLEND_CONST:87{88return agx_pool_upload_aligned(&batch->pool, &ctx->blend_color,89sizeof(ctx->blend_color), 8);90}9192default:93unreachable("todo: push more");94}95}9697uint64_t98agx_push_location(struct agx_context *ctx, struct agx_push push,99enum pipe_shader_type stage)100{101uint64_t direct = agx_push_location_direct(ctx, push, stage);102struct agx_pool *pool = &ctx->batch->pool;103104if (push.indirect)105return agx_pool_upload(pool, &direct, sizeof(direct));106else107return direct;108}109110111