1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_state.h"
33 #include "util/u_double_list.h"
35 #include "svga_screen_cache.h"
38 #define SVGA_BUFFER_MAGIC 0x344f9005
41 * Maximum number of discontiguous ranges
43 #define SVGA_BUFFER_MAX_RANGES 32
48 struct svga_winsys_buffer
;
49 struct svga_winsys_surface
;
52 struct svga_buffer_range
64 struct pipe_buffer base
;
67 * Marker to detect bad casts in runtime.
72 * Regular (non DMA'able) memory.
74 * Used for user buffers or for buffers which we know before hand that can
75 * never be used by the virtual hardware directly, such as constant buffers.
80 * Whether swbuf was created by the user or not.
85 * Creation key for the host surface handle.
87 * This structure describes all the host surface characteristics so that it
88 * can be looked up in cache, since creating a host surface is often a slow
91 struct svga_host_surface_cache_key key
;
94 * Host surface handle.
96 * This is a platform independent abstraction for host SID. We create when
99 struct svga_winsys_surface
*handle
;
102 * Information about ongoing and past map operations.
106 * Number of concurrent mappings.
108 * XXX: It is impossible to guarantee concurrent maps work in all
109 * circumstances -- pipe_buffers really need transfer objects too.
114 * Whether this buffer is currently mapped for writing.
119 * Whether the application will tell us explicity which ranges it touched
122 boolean flush_explicit
;
127 * Ranges that were touched by the application and need to be uploaded to
130 * This information will be copied into dma.boxes, when emiting the
131 * SVGA3dCmdSurfaceDMA command.
133 struct svga_buffer_range ranges
[SVGA_BUFFER_MAX_RANGES
];
138 * Information about uploaded version of user buffers.
141 struct pipe_buffer
*buffer
;
144 * We combine multiple user buffers into the same hardware buffer. This
145 * is the relative offset within that buffer.
153 * A piece of GMR memory, with the same size of the buffer. It is created
154 * when mapping the buffer, and will be used to upload vertex data to the
157 struct svga_winsys_buffer
*hwbuf
;
160 * Information about pending DMA uploads.
165 * Whether this buffer has an unfinished DMA upload command.
167 * If not set then the rest of the information is null.
171 SVGA3dSurfaceDMAFlags flags
;
174 * Pointer to the DMA copy box *inside* the command buffer.
176 SVGA3dCopyBox
*boxes
;
179 * Context that has the pending DMA to this buffer.
181 struct svga_context
*svga
;
185 * Linked list head, used to gather all buffers with pending dma uploads on
186 * a context. It is only valid if the dma.pending is set above.
188 struct list_head head
;
192 static INLINE
struct svga_buffer
*
193 svga_buffer(struct pipe_buffer
*buffer
)
196 assert(((struct svga_buffer
*)buffer
)->magic
== SVGA_BUFFER_MAGIC
);
197 return (struct svga_buffer
*)buffer
;
204 * Returns TRUE for user buffers. We may
205 * decide to use an alternate upload path for these buffers.
207 static INLINE boolean
208 svga_buffer_is_user_buffer( struct pipe_buffer
*buffer
)
210 return svga_buffer(buffer
)->user
;
215 svga_screen_init_buffer_functions(struct pipe_screen
*screen
);
219 * Get the host surface handle for this buffer.
221 * This will ensure the host surface is updated, issuing DMAs as needed.
223 * NOTE: This may insert new commands in the context, so it *must* be called
224 * before reserving command buffer space. And, in order to insert commands
225 * it may need to call svga_context_flush().
227 struct svga_winsys_surface
*
228 svga_buffer_handle(struct svga_context
*svga
,
229 struct pipe_buffer
*buf
);
232 svga_context_flush_buffers(struct svga_context
*svga
);
234 struct svga_winsys_buffer
*
235 svga_winsys_buffer_create(struct svga_screen
*ss
,
240 #endif /* SVGA_BUFFER_H */