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
];
46 void *range_map_buffer
[MAP_COUNT
];
49 * Tracking for what range of the BO may currently be in use by the GPU.
51 * Users often want to either glBufferSubData() or glMapBufferRange() a
52 * buffer object where some subset of it is busy on the GPU, without either
53 * stalling or doing an extra blit (since our blits are extra expensive,
54 * given that we have to reupload most of the 3D state when switching
55 * rings). We wish they'd just use glMapBufferRange() with the
56 * UNSYNC|INVALIDATE_RANGE flag or the INVALIDATE_BUFFER flag, but lots
59 * To work around apps, we track what range of the BO we might have used on
60 * the GPU as vertex data, tranform feedback output, buffer textures, etc.,
61 * and just do glBufferSubData() with an unsynchronized map when they're
62 * outside of that range.
64 * If gpu_active_start > gpu_active_end, then the GPU is not currently
65 * accessing the BO (and we can map it without synchronization).
67 uint32_t gpu_active_start
;
68 uint32_t gpu_active_end
;
71 * If we've avoided stalls/blits using the active tracking, flag the buffer
72 * for (occasional) stalling in the future to avoid getting stuck in a
73 * cycle of blitting on buffer wraparound.
75 bool prefer_stall_to_blit
;
80 /* Get the bm buffer associated with a GL bufferobject:
82 drm_intel_bo
*intel_bufferobj_buffer(struct brw_context
*brw
,
83 struct intel_buffer_object
*obj
,
87 void intel_upload_data(struct brw_context
*brw
,
88 const void *ptr
, GLuint size
, GLuint align
,
89 drm_intel_bo
**return_bo
,
90 GLuint
*return_offset
);
92 void *intel_upload_map(struct brw_context
*brw
,
93 GLuint size
, GLuint align
);
94 void intel_upload_unmap(struct brw_context
*brw
,
95 const void *ptr
, GLuint size
, GLuint align
,
96 drm_intel_bo
**return_bo
,
97 GLuint
*return_offset
);
99 void intel_upload_finish(struct brw_context
*brw
);
101 /* Hook the bufferobject implementation into mesa:
103 void intelInitBufferObjectFuncs(struct dd_function_table
*functions
);
105 static inline struct intel_buffer_object
*
106 intel_buffer_object(struct gl_buffer_object
*obj
)
108 return (struct intel_buffer_object
*) obj
;