• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2005 VMware, Inc.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #ifndef INTEL_BUFFEROBJ_H
27 #define INTEL_BUFFEROBJ_H
28 
29 #include "main/mtypes.h"
30 
31 struct brw_context;
32 struct gl_buffer_object;
33 
34 
35 /**
36  * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object.
37  */
38 struct intel_buffer_object
39 {
40    struct gl_buffer_object Base;
41    struct brw_bo *buffer;     /* the low-level buffer manager's buffer handle */
42 
43    struct brw_bo *range_map_bo[MAP_COUNT];
44 
45    /**
46     * Alignment offset from the range_map_bo temporary mapping to the returned
47     * obj->Pointer (caused by GL_ARB_map_buffer_alignment).
48     */
49    unsigned map_extra[MAP_COUNT];
50 
51    /** @{
52     * Tracking for what range of the BO may currently be in use by the GPU.
53     *
54     * Users often want to either glBufferSubData() or glMapBufferRange() a
55     * buffer object where some subset of it is busy on the GPU, without either
56     * stalling or doing an extra blit (since our blits are extra expensive,
57     * given that we have to reupload most of the 3D state when switching
58     * rings).  We wish they'd just use glMapBufferRange() with the
59     * UNSYNC|INVALIDATE_RANGE flag or the INVALIDATE_BUFFER flag, but lots
60     * don't.
61     *
62     * To work around apps, we track what range of the BO we might have used on
63     * the GPU as vertex data, tranform feedback output, buffer textures, etc.,
64     * and just do glBufferSubData() with an unsynchronized map when they're
65     * outside of that range.
66     *
67     * If gpu_active_start > gpu_active_end, then the GPU is not currently
68     * accessing the BO (and we can map it without synchronization).
69     */
70    uint32_t gpu_active_start;
71    uint32_t gpu_active_end;
72 
73    /** @{
74     * Tracking for what range of the BO may contain valid data.
75     *
76     * Users may create a large buffer object and only fill part of it
77     * with valid data.  This is a conservative estimate of what part
78     * of the buffer contains valid data that we have to preserve.
79     */
80    uint32_t valid_data_start;
81    uint32_t valid_data_end;
82    /** @} */
83 
84    /**
85     * If we've avoided stalls/blits using the active tracking, flag the buffer
86     * for (occasional) stalling in the future to avoid getting stuck in a
87     * cycle of blitting on buffer wraparound.
88     */
89    bool prefer_stall_to_blit;
90    /** @} */
91 };
92 
93 
94 /* Get the bm buffer associated with a GL bufferobject:
95  */
96 struct brw_bo *intel_bufferobj_buffer(struct brw_context *brw,
97                                       struct intel_buffer_object *obj,
98                                       uint32_t offset,
99                                       uint32_t size,
100                                       bool write);
101 
102 void intel_upload_data(struct brw_context *brw,
103                        const void *data,
104                        uint32_t size,
105                        uint32_t alignment,
106                        struct brw_bo **out_bo,
107                        uint32_t *out_offset);
108 
109 void *intel_upload_space(struct brw_context *brw,
110                          uint32_t size,
111                          uint32_t alignment,
112                          struct brw_bo **out_bo,
113                          uint32_t *out_offset);
114 
115 void intel_upload_finish(struct brw_context *brw);
116 
117 /* Hook the bufferobject implementation into mesa:
118  */
119 void intelInitBufferObjectFuncs(struct dd_function_table *functions);
120 
121 static inline struct intel_buffer_object *
intel_buffer_object(struct gl_buffer_object * obj)122 intel_buffer_object(struct gl_buffer_object *obj)
123 {
124    return (struct intel_buffer_object *) obj;
125 }
126 
127 #endif
128