101e04c3fSmrg/* 201e04c3fSmrg * Copyright 2016 Red Hat. 301e04c3fSmrg * 401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 501e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 601e04c3fSmrg * to deal in the Software without restriction, including without limitation 701e04c3fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub 801e04c3fSmrg * license, and/or sell copies of the Software, and to permit persons to whom 901e04c3fSmrg * the Software is furnished to do so, subject to the following conditions: 1001e04c3fSmrg * 1101e04c3fSmrg * The above copyright notice and this permission notice (including the next 1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1301e04c3fSmrg * Software. 1401e04c3fSmrg * 1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1801e04c3fSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2101e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 2201e04c3fSmrg */ 2301e04c3fSmrg 2401e04c3fSmrg#include "sp_context.h" 2501e04c3fSmrg#include "sp_buffer.h" 2601e04c3fSmrg#include "sp_texture.h" 2701e04c3fSmrg 287ec681f3Smrg#include "util/format/u_format.h" 2901e04c3fSmrg 307ec681f3Smrgstatic void * 317ec681f3Smrgsp_tgsi_ssbo_lookup(const struct tgsi_buffer *buffer, 327ec681f3Smrg uint32_t unit, 337ec681f3Smrg uint32_t *size) 3401e04c3fSmrg{ 3501e04c3fSmrg struct sp_tgsi_buffer *sp_buf = (struct sp_tgsi_buffer *)buffer; 3601e04c3fSmrg 377ec681f3Smrg *size = 0; 387ec681f3Smrg if (unit >= PIPE_MAX_SHADER_BUFFERS) 397ec681f3Smrg return NULL; 4001e04c3fSmrg 417ec681f3Smrg struct pipe_shader_buffer *bview = &sp_buf->sp_bview[unit]; 427ec681f3Smrg /* Sanity check the view size is within our buffer. */ 437ec681f3Smrg if (!bview->buffer || 447ec681f3Smrg bview->buffer_offset > bview->buffer->width0 || 457ec681f3Smrg bview->buffer_size > bview->buffer->width0 - bview->buffer_offset) { 467ec681f3Smrg return NULL; 4701e04c3fSmrg } 4801e04c3fSmrg 497ec681f3Smrg struct softpipe_resource *spr = softpipe_resource(bview->buffer); 507ec681f3Smrg *size = bview->buffer_size; 517ec681f3Smrg return (char *)spr->data + bview->buffer_offset; 5201e04c3fSmrg} 5301e04c3fSmrg 5401e04c3fSmrgstruct sp_tgsi_buffer * 5501e04c3fSmrgsp_create_tgsi_buffer(void) 5601e04c3fSmrg{ 5701e04c3fSmrg struct sp_tgsi_buffer *buf = CALLOC_STRUCT(sp_tgsi_buffer); 5801e04c3fSmrg if (!buf) 5901e04c3fSmrg return NULL; 6001e04c3fSmrg 617ec681f3Smrg buf->base.lookup = sp_tgsi_ssbo_lookup; 6201e04c3fSmrg return buf; 6301e04c3fSmrg}; 64