Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_buffer.c
4570 views
/*1* Copyright 2016 Red Hat.2*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*/2223#include "sp_context.h"24#include "sp_buffer.h"25#include "sp_texture.h"2627#include "util/format/u_format.h"2829static void *30sp_tgsi_ssbo_lookup(const struct tgsi_buffer *buffer,31uint32_t unit,32uint32_t *size)33{34struct sp_tgsi_buffer *sp_buf = (struct sp_tgsi_buffer *)buffer;3536*size = 0;37if (unit >= PIPE_MAX_SHADER_BUFFERS)38return NULL;3940struct pipe_shader_buffer *bview = &sp_buf->sp_bview[unit];41/* Sanity check the view size is within our buffer. */42if (!bview->buffer ||43bview->buffer_offset > bview->buffer->width0 ||44bview->buffer_size > bview->buffer->width0 - bview->buffer_offset) {45return NULL;46}4748struct softpipe_resource *spr = softpipe_resource(bview->buffer);49*size = bview->buffer_size;50return (char *)spr->data + bview->buffer_offset;51}5253struct sp_tgsi_buffer *54sp_create_tgsi_buffer(void)55{56struct sp_tgsi_buffer *buf = CALLOC_STRUCT(sp_tgsi_buffer);57if (!buf)58return NULL;5960buf->base.lookup = sp_tgsi_ssbo_lookup;61return buf;62};636465