d8024e4aac2facd9db5a0e5e01e54d39ffffaa21
[mesa.git] / src / gallium / state_trackers / nine / buffer9.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 * Copyright 2015 Patrick Rudolph <siro@das-labor.org>
4 *
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:
11 *
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
14 * Software.
15 *
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. */
23
24 #ifndef _NINE_BUFFER9_H_
25 #define _NINE_BUFFER9_H_
26
27 #include "device9.h"
28 #include "resource9.h"
29 #include "pipe/p_context.h"
30 #include "pipe/p_state.h"
31 #include "util/list.h"
32
33 struct pipe_screen;
34 struct pipe_context;
35 struct pipe_transfer;
36
37 struct NineTransfer {
38 struct pipe_transfer *transfer;
39 bool is_pipe_secondary;
40 };
41
42 struct NineBuffer9
43 {
44 struct NineResource9 base;
45
46 /* G3D */
47 struct NineTransfer *maps;
48 int nmaps, maxmaps;
49 UINT size;
50
51 int16_t bind_count; /* to Device9->state.stream */
52
53 /* Specific to managed buffers */
54 struct {
55 void *data;
56 boolean dirty;
57 struct pipe_box dirty_box;
58 struct list_head list; /* for update_buffers */
59 struct list_head list2; /* for managed_buffers */
60 } managed;
61 };
62 static inline struct NineBuffer9 *
63 NineBuffer9( void *data )
64 {
65 return (struct NineBuffer9 *)data;
66 }
67
68 HRESULT
69 NineBuffer9_ctor( struct NineBuffer9 *This,
70 struct NineUnknownParams *pParams,
71 D3DRESOURCETYPE Type,
72 DWORD Usage,
73 UINT Size,
74 D3DPOOL Pool );
75
76 void
77 NineBuffer9_dtor( struct NineBuffer9 *This );
78
79 struct pipe_resource *
80 NineBuffer9_GetResource( struct NineBuffer9 *This );
81
82 HRESULT NINE_WINAPI
83 NineBuffer9_Lock( struct NineBuffer9 *This,
84 UINT OffsetToLock,
85 UINT SizeToLock,
86 void **ppbData,
87 DWORD Flags );
88
89 HRESULT NINE_WINAPI
90 NineBuffer9_Unlock( struct NineBuffer9 *This );
91
92 static inline void
93 NineBuffer9_Upload( struct NineBuffer9 *This )
94 {
95 struct pipe_context *pipe = NineDevice9_GetPipe(This->base.base.device);
96
97 assert(This->base.pool == D3DPOOL_MANAGED && This->managed.dirty);
98 pipe->buffer_subdata(pipe, This->base.resource, 0,
99 This->managed.dirty_box.x,
100 This->managed.dirty_box.width,
101 (char *)This->managed.data + This->managed.dirty_box.x);
102 This->managed.dirty = FALSE;
103 }
104
105 static void inline
106 NineBindBufferToDevice( struct NineDevice9 *device,
107 struct NineBuffer9 **slot,
108 struct NineBuffer9 *buf )
109 {
110 struct NineBuffer9 *old = *slot;
111
112 if (buf) {
113 if ((buf->managed.dirty) && LIST_IS_EMPTY(&buf->managed.list))
114 list_add(&buf->managed.list, &device->update_buffers);
115 buf->bind_count++;
116 }
117 if (old)
118 old->bind_count--;
119
120 nine_bind(slot, buf);
121 }
122
123 void
124 NineBuffer9_SetDirty( struct NineBuffer9 *This );
125
126 #define BASEBUF_REGISTER_UPDATE(b) { \
127 if ((b)->managed.dirty && (b)->bind_count) \
128 if (LIST_IS_EMPTY(&(b)->managed.list)) \
129 list_add(&(b)->managed.list, &(b)->base.base.device->update_buffers); \
130 }
131
132 #endif /* _NINE_BUFFER9_H_ */