i965/wm: Use resolved miptree consistently in surface setup
[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 void *range_map_buffer[MAP_COUNT];
47
48 /** @{
49 * Tracking for what range of the BO may currently be in use by the GPU.
50 *
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
57 * don't.
58 *
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.
63 *
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).
66 */
67 uint32_t gpu_active_start;
68 uint32_t gpu_active_end;
69
70 /**
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.
74 */
75 bool prefer_stall_to_blit;
76 /** @} */
77 };
78
79
80 /* Get the bm buffer associated with a GL bufferobject:
81 */
82 drm_intel_bo *intel_bufferobj_buffer(struct brw_context *brw,
83 struct intel_buffer_object *obj,
84 uint32_t offset,
85 uint32_t size);
86
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);
91
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);
98
99 void intel_upload_finish(struct brw_context *brw);
100
101 /* Hook the bufferobject implementation into mesa:
102 */
103 void intelInitBufferObjectFuncs(struct dd_function_table *functions);
104
105 static inline struct intel_buffer_object *
106 intel_buffer_object(struct gl_buffer_object *obj)
107 {
108 return (struct intel_buffer_object *) obj;
109 }
110
111 #endif