2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 * Copyright 2015 Patrick Rudolph <siro@das-labor.org>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #ifndef _NINE_BUFFER9_H_
25 #define _NINE_BUFFER9_H_
28 #include "nine_buffer_upload.h"
29 #include "nine_state.h"
30 #include "resource9.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33 #include "util/list.h"
40 struct pipe_transfer
*transfer
;
41 bool is_pipe_secondary
;
42 struct nine_subbuffer
*buf
; /* NULL unless subbuffer are used */
43 bool should_destroy_buf
; /* If the subbuffer should be destroyed */
48 struct NineResource9 base
;
51 struct NineTransfer
*maps
;
55 int16_t bind_count
; /* to Device9->state.stream */
56 /* Whether only discard and nooverwrite were used so far
57 * for this buffer. Allows some optimization. */
58 boolean discard_nooverwrite_only
;
59 boolean need_sync_if_nooverwrite
;
60 struct nine_subbuffer
*buf
;
62 /* Specific to managed buffers */
66 struct pipe_box dirty_box
;
67 struct list_head list
; /* for update_buffers */
68 struct list_head list2
; /* for managed_buffers */
69 unsigned pending_upload
; /* for uploads */
72 static inline struct NineBuffer9
*
73 NineBuffer9( void *data
)
75 return (struct NineBuffer9
*)data
;
79 NineBuffer9_ctor( struct NineBuffer9
*This
,
80 struct NineUnknownParams
*pParams
,
87 NineBuffer9_dtor( struct NineBuffer9
*This
);
89 struct pipe_resource
*
90 NineBuffer9_GetResource( struct NineBuffer9
*This
, unsigned *offset
);
93 NineBuffer9_Lock( struct NineBuffer9
*This
,
100 NineBuffer9_Unlock( struct NineBuffer9
*This
);
103 NineBuffer9_Upload( struct NineBuffer9
*This
)
105 struct NineDevice9
*device
= This
->base
.base
.device
;
107 assert(This
->base
.pool
== D3DPOOL_MANAGED
&& This
->managed
.dirty
);
108 nine_context_range_upload(device
, &This
->managed
.pending_upload
,
109 (struct NineUnknown
*)This
,
111 This
->managed
.dirty_box
.x
,
112 This
->managed
.dirty_box
.width
,
113 (char *)This
->managed
.data
+ This
->managed
.dirty_box
.x
);
114 This
->managed
.dirty
= FALSE
;
118 NineBindBufferToDevice( struct NineDevice9
*device
,
119 struct NineBuffer9
**slot
,
120 struct NineBuffer9
*buf
)
122 struct NineBuffer9
*old
= *slot
;
125 if ((buf
->managed
.dirty
) && list_is_empty(&buf
->managed
.list
))
126 list_add(&buf
->managed
.list
, &device
->update_buffers
);
131 if (!old
->bind_count
&& old
->managed
.dirty
)
132 list_delinit(&old
->managed
.list
);
135 nine_bind(slot
, buf
);
139 NineBuffer9_SetDirty( struct NineBuffer9
*This
);
141 #define BASEBUF_REGISTER_UPDATE(b) { \
142 if ((b)->managed.dirty && (b)->bind_count) \
143 if (list_is_empty(&(b)->managed.list)) \
144 list_add(&(b)->managed.list, &(b)->base.base.device->update_buffers); \
147 #endif /* _NINE_BUFFER9_H_ */