1b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin/************************************************************************** 2b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * 3b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * Copyright 2010 VMware, Inc. 4b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * All Rights Reserved. 5b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * 6b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * Permission is hereby granted, free of charge, to any person obtaining a 7b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * copy of this software and associated documentation files (the 8b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * "Software"), to deal in the Software without restriction, including 9b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * without limitation the rights to use, copy, modify, merge, publish, 10b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * distribute, sub license, and/or sell copies of the Software, and to 11b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * permit persons to whom the Software is furnished to do so, subject to 12b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * the following conditions: 13b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * 14b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * The above copyright notice and this permission notice (including the 15b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * next paragraph) shall be included in all copies or substantial portions 16b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * of the Software. 17b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * 18b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin * 26b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin **************************************************************************/ 27b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 28b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin#include "lp_context.h" 29b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin#include "lp_state.h" 30b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin#include "lp_texture.h" 31b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 32b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin#include "util/u_memory.h" 33b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin#include "draw/draw_context.h" 34b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 35b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 36b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinstatic void * 37b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinllvmpipe_create_stream_output_state(struct pipe_context *pipe, 38861a029ddb31e91bb4d8e18ab708d0d172f63aadMarek Olšák const struct pipe_stream_output_info *templ) 39b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin{ 40b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct lp_so_state *so; 41b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin so = (struct lp_so_state *) CALLOC_STRUCT(lp_so_state); 42b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 43b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin if (so) { 44b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin so->base.num_outputs = templ->num_outputs; 452449695e822421fdcaf1c66dffc12d7d705ea69dMarek Olšák memcpy(so->base.stride, templ->stride, sizeof(templ->stride)); 4697144eef036cd94068944202214cb8e722b3839dChristoph Bumiller memcpy(so->base.output, templ->output, 4797144eef036cd94068944202214cb8e722b3839dChristoph Bumiller templ->num_outputs * sizeof(templ->output[0])); 48b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin } 49b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin return so; 50b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin} 51b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 52b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinstatic void 53b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinllvmpipe_bind_stream_output_state(struct pipe_context *pipe, 54b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin void *so) 55b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin{ 56b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct llvmpipe_context *lp = llvmpipe_context(pipe); 57b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct lp_so_state *lp_so = (struct lp_so_state *) so; 58b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 59b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so = lp_so; 60b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 61b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->dirty |= LP_NEW_SO; 62b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 63b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin if (lp_so) 64b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin draw_set_so_state(lp->draw, &lp_so->base); 65b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin} 66b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 67b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinstatic void 68b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinllvmpipe_delete_stream_output_state(struct pipe_context *pipe, void *so) 69b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin{ 70b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin FREE( so ); 71b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin} 72b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 73b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinstatic void 74b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinllvmpipe_set_stream_output_buffers(struct pipe_context *pipe, 75b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct pipe_resource **buffers, 76b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin int *offsets, 77b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin int num_buffers) 78b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin{ 79b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct llvmpipe_context *lp = llvmpipe_context(pipe); 80b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin int i; 81b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin void *map_buffers[PIPE_MAX_SO_BUFFERS]; 82b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 83b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin assert(num_buffers <= PIPE_MAX_SO_BUFFERS); 84b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin if (num_buffers > PIPE_MAX_SO_BUFFERS) 85b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin num_buffers = PIPE_MAX_SO_BUFFERS; 86b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 87b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->dirty |= LP_NEW_SO_BUFFERS; 88b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 89b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin for (i = 0; i < num_buffers; ++i) { 90b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin void *mapped; 91b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin struct llvmpipe_resource *res = llvmpipe_resource(buffers[i]); 92b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 93b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin if (!res) { 94b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin /* the whole call is invalid, bail out */ 95b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so_target.num_buffers = 0; 96b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin draw_set_mapped_so_buffers(lp->draw, 0, 0); 97b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin return; 98b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin } 99b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 100b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so_target.buffer[i] = res; 101b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so_target.offset[i] = offsets[i]; 102b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so_target.so_count[i] = 0; 103b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 104b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin mapped = res->data; 105b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin if (offsets[i] >= 0) 106b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin map_buffers[i] = ((char*)mapped) + offsets[i]; 107b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin else { 108b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin /* this is a buffer append */ 109b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin assert(!"appending not implemented"); 110b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin map_buffers[i] = mapped; 111b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin } 112b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin } 113b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin lp->so_target.num_buffers = num_buffers; 114b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 115b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin draw_set_mapped_so_buffers(lp->draw, map_buffers, num_buffers); 116b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin} 117b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 118b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinvoid 119b5e381d9783f17c9a527ac38122444eac6807566Zack Rusinllvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe) 120b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin{ 1214f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák#if 0 122b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe->pipe.create_stream_output_state = 123b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe_create_stream_output_state; 124b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe->pipe.bind_stream_output_state = 125b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe_bind_stream_output_state; 126b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe->pipe.delete_stream_output_state = 127b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe_delete_stream_output_state; 128b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin 129b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe->pipe.set_stream_output_buffers = 130b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin llvmpipe_set_stream_output_buffers; 1314f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák#else 1324f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák (void) llvmpipe_create_stream_output_state; 1334f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák (void) llvmpipe_bind_stream_output_state; 1344f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák (void) llvmpipe_delete_stream_output_state; 1354f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák (void) llvmpipe_set_stream_output_buffers; 1364f4a1be2009863ea34a69b22f58aa1ca08cd710fMarek Olšák#endif 137b5e381d9783f17c9a527ac38122444eac6807566Zack Rusin} 138