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"
32 #include "util/u_transfer.h"
34 #include "util/u_double_list.h"
36 #include "svga_screen_cache.h"
40 * Maximum number of discontiguous ranges
42 #define SVGA_BUFFER_MAX_RANGES 32
47 struct svga_winsys_buffer
;
48 struct svga_winsys_surface
;
51 extern struct u_resource_vtbl svga_buffer_vtbl
;
53 struct svga_buffer_range
68 * Regular (non DMA'able) memory.
70 * Used for user buffers or for buffers which we know before hand that can
71 * never be used by the virtual hardware directly, such as constant buffers.
76 * Whether swbuf was created by the user or not.
81 * Creation key for the host surface handle.
83 * This structure describes all the host surface characteristics so that it
84 * can be looked up in cache, since creating a host surface is often a slow
87 struct svga_host_surface_cache_key key
;
90 * Host surface handle.
92 * This is a platform independent abstraction for host SID. We create when
95 * Only set for non-user buffers.
97 struct svga_winsys_surface
*handle
;
100 * Information about ongoing and past map operations.
104 * Number of concurrent mappings.
111 * Ranges that were touched by the application and need to be uploaded to
114 * This information will be copied into dma.boxes, when emiting the
115 * SVGA3dCmdSurfaceDMA command.
117 struct svga_buffer_range ranges
[SVGA_BUFFER_MAX_RANGES
];
122 * Information about uploaded version of user buffers.
125 struct pipe_resource
*buffer
;
128 * We combine multiple user buffers into the same hardware buffer. This
129 * is the relative offset within that buffer.
137 * A piece of GMR memory, with the same size of the buffer. It is created
138 * when mapping the buffer, and will be used to upload vertex data to the
141 * Only set for non-user buffers.
143 struct svga_winsys_buffer
*hwbuf
;
146 * Information about pending DMA uploads.
151 * Whether this buffer has an unfinished DMA upload command.
153 * If not set then the rest of the information is null.
157 SVGA3dSurfaceDMAFlags flags
;
160 * Pointer to the DMA copy box *inside* the command buffer.
162 SVGA3dCopyBox
*boxes
;
165 * Context that has the pending DMA to this buffer.
167 struct svga_context
*svga
;
171 * Linked list head, used to gather all buffers with pending dma uploads on
172 * a context. It is only valid if the dma.pending is set above.
174 struct list_head head
;
178 static INLINE
struct svga_buffer
*
179 svga_buffer(struct pipe_resource
*buffer
)
182 assert(((struct svga_buffer
*)buffer
)->b
.vtbl
== &svga_buffer_vtbl
);
183 return (struct svga_buffer
*)buffer
;
190 * Returns TRUE for user buffers. We may
191 * decide to use an alternate upload path for these buffers.
193 static INLINE boolean
194 svga_buffer_is_user_buffer( struct pipe_resource
*buffer
)
196 return svga_buffer(buffer
)->user
;
202 struct pipe_resource
*
203 svga_user_buffer_create(struct pipe_screen
*screen
,
208 struct pipe_resource
*
209 svga_buffer_create(struct pipe_screen
*screen
,
210 const struct pipe_resource
*template);
215 * Get the host surface handle for this buffer.
217 * This will ensure the host surface is updated, issuing DMAs as needed.
219 * NOTE: This may insert new commands in the context, so it *must* be called
220 * before reserving command buffer space. And, in order to insert commands
221 * it may need to call svga_context_flush().
223 struct svga_winsys_surface
*
224 svga_buffer_handle(struct svga_context
*svga
,
225 struct pipe_resource
*buf
);
228 svga_context_flush_buffers(struct svga_context
*svga
);
230 struct svga_winsys_buffer
*
231 svga_winsys_buffer_create(struct svga_context
*svga
,
237 svga_redefine_user_buffer(struct pipe_context
*ctx
,
238 struct pipe_resource
*resource
,
242 #endif /* SVGA_BUFFER_H */