1 /**************************************************************************
3 * Copyright 2005 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
28 #ifndef INTEL_BUFFEROBJ_H
29 #define INTEL_BUFFEROBJ_H
31 #include "main/mtypes.h"
34 struct gl_buffer_object
;
38 * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object.
40 struct intel_buffer_object
42 struct gl_buffer_object Base
;
43 drm_intel_bo
*buffer
; /* the low-level buffer manager's buffer handle */
45 drm_intel_bo
*range_map_bo
[MAP_COUNT
];
48 * Alignment offset from the range_map_bo temporary mapping to the returned
49 * obj->Pointer (caused by GL_ARB_map_buffer_alignment).
51 unsigned map_extra
[MAP_COUNT
];
54 * Tracking for what range of the BO may currently be in use by the GPU.
56 * Users often want to either glBufferSubData() or glMapBufferRange() a
57 * buffer object where some subset of it is busy on the GPU, without either
58 * stalling or doing an extra blit (since our blits are extra expensive,
59 * given that we have to reupload most of the 3D state when switching
60 * rings). We wish they'd just use glMapBufferRange() with the
61 * UNSYNC|INVALIDATE_RANGE flag or the INVALIDATE_BUFFER flag, but lots
64 * To work around apps, we track what range of the BO we might have used on
65 * the GPU as vertex data, tranform feedback output, buffer textures, etc.,
66 * and just do glBufferSubData() with an unsynchronized map when they're
67 * outside of that range.
69 * If gpu_active_start > gpu_active_end, then the GPU is not currently
70 * accessing the BO (and we can map it without synchronization).
72 uint32_t gpu_active_start
;
73 uint32_t gpu_active_end
;
76 * If we've avoided stalls/blits using the active tracking, flag the buffer
77 * for (occasional) stalling in the future to avoid getting stuck in a
78 * cycle of blitting on buffer wraparound.
80 bool prefer_stall_to_blit
;
85 /* Get the bm buffer associated with a GL bufferobject:
87 drm_intel_bo
*intel_bufferobj_buffer(struct brw_context
*brw
,
88 struct intel_buffer_object
*obj
,
92 void intel_upload_data(struct brw_context
*brw
,
93 const void *ptr
, GLuint size
, GLuint align
,
94 drm_intel_bo
**return_bo
,
95 GLuint
*return_offset
);
97 void *intel_upload_map(struct brw_context
*brw
,
98 GLuint size
, GLuint align
);
99 void intel_upload_unmap(struct brw_context
*brw
,
100 const void *ptr
, GLuint size
, GLuint align
,
101 drm_intel_bo
**return_bo
,
102 GLuint
*return_offset
);
104 void intel_upload_finish(struct brw_context
*brw
);
106 /* Hook the bufferobject implementation into mesa:
108 void intelInitBufferObjectFuncs(struct dd_function_table
*functions
);
110 static inline struct intel_buffer_object
*
111 intel_buffer_object(struct gl_buffer_object
*obj
)
113 return (struct intel_buffer_object
*) obj
;