i965: Use unreachable() instead of unconditional assert().
[mesa.git] / src / mesa / drivers / dri / i965 / intel_buffer_objects.h
1 /**************************************************************************
2 *
3 * Copyright 2005 VMware, Inc.
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 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.
25 *
26 **************************************************************************/
27
28 #ifndef INTEL_BUFFEROBJ_H
29 #define INTEL_BUFFEROBJ_H
30
31 #include "main/mtypes.h"
32
33 struct brw_context;
34 struct gl_buffer_object;
35
36
37 /**
38 * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object.
39 */
40 struct intel_buffer_object
41 {
42 struct gl_buffer_object Base;
43 drm_intel_bo *buffer; /* the low-level buffer manager's buffer handle */
44
45 drm_intel_bo *range_map_bo[MAP_COUNT];
46
47 /**
48 * Alignment offset from the range_map_bo temporary mapping to the returned
49 * obj->Pointer (caused by GL_ARB_map_buffer_alignment).
50 */
51 unsigned map_extra[MAP_COUNT];
52
53 /** @{
54 * Tracking for what range of the BO may currently be in use by the GPU.
55 *
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
62 * don't.
63 *
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.
68 *
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).
71 */
72 uint32_t gpu_active_start;
73 uint32_t gpu_active_end;
74
75 /**
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.
79 */
80 bool prefer_stall_to_blit;
81 /** @} */
82 };
83
84
85 /* Get the bm buffer associated with a GL bufferobject:
86 */
87 drm_intel_bo *intel_bufferobj_buffer(struct brw_context *brw,
88 struct intel_buffer_object *obj,
89 uint32_t offset,
90 uint32_t size);
91
92 void intel_upload_data(struct brw_context *brw,
93 const void *data,
94 uint32_t size,
95 uint32_t alignment,
96 drm_intel_bo **out_bo,
97 uint32_t *out_offset);
98
99 void *intel_upload_space(struct brw_context *brw,
100 uint32_t size,
101 uint32_t alignment,
102 drm_intel_bo **out_bo,
103 uint32_t *out_offset);
104
105 void intel_upload_finish(struct brw_context *brw);
106
107 /* Hook the bufferobject implementation into mesa:
108 */
109 void intelInitBufferObjectFuncs(struct dd_function_table *functions);
110
111 static inline struct intel_buffer_object *
112 intel_buffer_object(struct gl_buffer_object *obj)
113 {
114 return (struct intel_buffer_object *) obj;
115 }
116
117 #endif