u_vbuf.h revision fba685a0995e76f86af5920163297e5c3b32fb4b
1/************************************************************************** 2 * 3 * Copyright 2011 Marek Olšák <maraeo@gmail.com> 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#ifndef U_VBUF_MGR_H 29#define U_VBUF_MGR_H 30 31/* This module builds upon u_upload_mgr and translate_cache and takes care of 32 * user buffer uploads and vertex format fallbacks. It's designed 33 * for the drivers which don't always use the Draw module. (e.g. for HWTCL) 34 */ 35 36#include "pipe/p_context.h" 37#include "pipe/p_state.h" 38#include "util/u_transfer.h" 39 40/* Hardware vertex fetcher limitations can be described by this structure. */ 41struct u_vbuf_caps { 42 /* Vertex format CAPs. */ 43 /* TRUE if hardware supports it. */ 44 unsigned format_fixed32:1; /* PIPE_FORMAT_*32*_FIXED */ 45 unsigned format_float16:1; /* PIPE_FORMAT_*16*_FLOAT */ 46 unsigned format_float64:1; /* PIPE_FORMAT_*64*_FLOAT */ 47 unsigned format_norm32:1; /* PIPE_FORMAT_*32*NORM */ 48 unsigned format_scaled32:1; /* PIPE_FORMAT_*32*SCALED */ 49 50 /* Whether vertex fetches don't have to be dword-aligned. */ 51 /* TRUE if hardware supports it. */ 52 unsigned fetch_dword_unaligned:1; 53}; 54 55/* The manager. 56 * This structure should also be used to access vertex buffers 57 * from a driver. */ 58struct u_vbuf { 59 /* This is what was set in set_vertex_buffers. 60 * May contain user buffers. */ 61 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; 62 unsigned nr_vertex_buffers; 63 64 /* Contains only real vertex buffers. 65 * Hardware drivers should use real_vertex_buffers[i] 66 * instead of vertex_buffers[i].buffer. */ 67 struct pipe_vertex_buffer real_vertex_buffer[PIPE_MAX_ATTRIBS]; 68 int nr_real_vertex_buffers; 69 70 /* The index buffer. */ 71 struct pipe_index_buffer index_buffer; 72 73 /* This uploader can optionally be used by the driver. 74 * 75 * Allowed functions: 76 * - u_upload_alloc 77 * - u_upload_data 78 * - u_upload_buffer 79 * - u_upload_flush */ 80 struct u_upload_mgr *uploader; 81 82 struct u_vbuf_caps caps; 83}; 84 85struct u_vbuf_resource { 86 struct u_resource b; 87 uint8_t *user_ptr; 88}; 89 90/* Opaque type containing information about vertex elements for the manager. */ 91struct u_vbuf_elements; 92 93enum u_fetch_alignment { 94 U_VERTEX_FETCH_BYTE_ALIGNED, 95 U_VERTEX_FETCH_DWORD_ALIGNED 96}; 97 98enum u_vbuf_return_flags { 99 U_VBUF_BUFFERS_UPDATED = 1 100}; 101 102 103struct u_vbuf * 104u_vbuf_create(struct pipe_context *pipe, 105 unsigned upload_buffer_size, 106 unsigned upload_buffer_alignment, 107 unsigned upload_buffer_bind, 108 enum u_fetch_alignment fetch_alignment); 109 110void u_vbuf_destroy(struct u_vbuf *mgr); 111 112struct u_vbuf_elements * 113u_vbuf_create_vertex_elements(struct u_vbuf *mgr, 114 unsigned count, 115 const struct pipe_vertex_element *attrs, 116 struct pipe_vertex_element *native_attrs); 117 118void u_vbuf_bind_vertex_elements(struct u_vbuf *mgr, 119 void *cso, 120 struct u_vbuf_elements *ve); 121 122void u_vbuf_destroy_vertex_elements(struct u_vbuf *mgr, 123 struct u_vbuf_elements *ve); 124 125void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, 126 unsigned count, 127 const struct pipe_vertex_buffer *bufs); 128 129void u_vbuf_set_index_buffer(struct u_vbuf *mgr, 130 const struct pipe_index_buffer *ib); 131 132enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf *mgr, 133 const struct pipe_draw_info *info); 134 135unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf *mgr); 136 137void u_vbuf_draw_end(struct u_vbuf *mgr); 138 139 140static INLINE struct u_vbuf_resource *u_vbuf_resource(struct pipe_resource *r) 141{ 142 return (struct u_vbuf_resource*)r; 143} 144 145#endif 146