xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/nine/buffer9.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker  * Copyright 2011 Joakim Sindholt <[email protected]>
3*61046927SAndroid Build Coastguard Worker  * Copyright 2015 Patrick Rudolph <[email protected]>
4*61046927SAndroid Build Coastguard Worker  * SPDX-License-Identifier: MIT
5*61046927SAndroid Build Coastguard Worker  */
6*61046927SAndroid Build Coastguard Worker 
7*61046927SAndroid Build Coastguard Worker #ifndef _NINE_BUFFER9_H_
8*61046927SAndroid Build Coastguard Worker #define _NINE_BUFFER9_H_
9*61046927SAndroid Build Coastguard Worker 
10*61046927SAndroid Build Coastguard Worker #include "device9.h"
11*61046927SAndroid Build Coastguard Worker #include "nine_buffer_upload.h"
12*61046927SAndroid Build Coastguard Worker #include "nine_state.h"
13*61046927SAndroid Build Coastguard Worker #include "resource9.h"
14*61046927SAndroid Build Coastguard Worker #include "pipe/p_context.h"
15*61046927SAndroid Build Coastguard Worker #include "pipe/p_defines.h"
16*61046927SAndroid Build Coastguard Worker #include "pipe/p_state.h"
17*61046927SAndroid Build Coastguard Worker #include "util/list.h"
18*61046927SAndroid Build Coastguard Worker #include "util/box.h"
19*61046927SAndroid Build Coastguard Worker #include "util/u_upload_mgr.h"
20*61046927SAndroid Build Coastguard Worker 
21*61046927SAndroid Build Coastguard Worker struct pipe_screen;
22*61046927SAndroid Build Coastguard Worker struct pipe_context;
23*61046927SAndroid Build Coastguard Worker struct pipe_transfer;
24*61046927SAndroid Build Coastguard Worker 
25*61046927SAndroid Build Coastguard Worker struct NineTransfer {
26*61046927SAndroid Build Coastguard Worker     struct pipe_transfer *transfer;
27*61046927SAndroid Build Coastguard Worker     bool is_pipe_secondary;
28*61046927SAndroid Build Coastguard Worker     struct nine_subbuffer *buf; /* NULL unless subbuffer are used */
29*61046927SAndroid Build Coastguard Worker     bool should_destroy_buf; /* If the subbuffer should be destroyed */
30*61046927SAndroid Build Coastguard Worker };
31*61046927SAndroid Build Coastguard Worker 
32*61046927SAndroid Build Coastguard Worker struct NineBuffer9
33*61046927SAndroid Build Coastguard Worker {
34*61046927SAndroid Build Coastguard Worker     struct NineResource9 base;
35*61046927SAndroid Build Coastguard Worker 
36*61046927SAndroid Build Coastguard Worker     /* G3D */
37*61046927SAndroid Build Coastguard Worker     struct NineTransfer *maps;
38*61046927SAndroid Build Coastguard Worker     int nlocks, nmaps, maxmaps;
39*61046927SAndroid Build Coastguard Worker     UINT size;
40*61046927SAndroid Build Coastguard Worker 
41*61046927SAndroid Build Coastguard Worker     int16_t bind_count; /* to Device9->state.stream */
42*61046927SAndroid Build Coastguard Worker     /* Whether only discard and nooverwrite were used so far
43*61046927SAndroid Build Coastguard Worker      * for this buffer. Allows some optimization. */
44*61046927SAndroid Build Coastguard Worker     bool discard_nooverwrite_only;
45*61046927SAndroid Build Coastguard Worker     bool need_sync_if_nooverwrite;
46*61046927SAndroid Build Coastguard Worker     struct nine_subbuffer *buf;
47*61046927SAndroid Build Coastguard Worker 
48*61046927SAndroid Build Coastguard Worker     /* Specific to managed buffers */
49*61046927SAndroid Build Coastguard Worker     struct {
50*61046927SAndroid Build Coastguard Worker         void *data;
51*61046927SAndroid Build Coastguard Worker         bool dirty;
52*61046927SAndroid Build Coastguard Worker         struct pipe_box dirty_box; /* region in the resource to update */
53*61046927SAndroid Build Coastguard Worker         struct pipe_box upload_pending_regions; /* region with uploads pending */
54*61046927SAndroid Build Coastguard Worker         struct list_head list; /* for update_buffers */
55*61046927SAndroid Build Coastguard Worker         struct list_head list2; /* for managed_buffers */
56*61046927SAndroid Build Coastguard Worker         unsigned pending_upload; /* for uploads */
57*61046927SAndroid Build Coastguard Worker         /* SYSTEMMEM DYNAMIC */
58*61046927SAndroid Build Coastguard Worker         bool can_unsynchronized; /* Whether the upload can use nooverwrite */
59*61046927SAndroid Build Coastguard Worker         struct pipe_box valid_region; /* Region in the GPU buffer with valid content */
60*61046927SAndroid Build Coastguard Worker         struct pipe_box required_valid_region; /* Region that needs to be valid right now. */
61*61046927SAndroid Build Coastguard Worker         struct pipe_box filled_region; /* Region in the GPU buffer filled since last discard */
62*61046927SAndroid Build Coastguard Worker         unsigned num_worker_thread_syncs;
63*61046927SAndroid Build Coastguard Worker         unsigned frame_count_last_discard;
64*61046927SAndroid Build Coastguard Worker     } managed;
65*61046927SAndroid Build Coastguard Worker };
66*61046927SAndroid Build Coastguard Worker static inline struct NineBuffer9 *
NineBuffer9(void * data)67*61046927SAndroid Build Coastguard Worker NineBuffer9( void *data )
68*61046927SAndroid Build Coastguard Worker {
69*61046927SAndroid Build Coastguard Worker     return (struct NineBuffer9 *)data;
70*61046927SAndroid Build Coastguard Worker }
71*61046927SAndroid Build Coastguard Worker 
72*61046927SAndroid Build Coastguard Worker HRESULT
73*61046927SAndroid Build Coastguard Worker NineBuffer9_ctor( struct NineBuffer9 *This,
74*61046927SAndroid Build Coastguard Worker                         struct NineUnknownParams *pParams,
75*61046927SAndroid Build Coastguard Worker                         D3DRESOURCETYPE Type,
76*61046927SAndroid Build Coastguard Worker                         DWORD Usage,
77*61046927SAndroid Build Coastguard Worker                         UINT Size,
78*61046927SAndroid Build Coastguard Worker                         D3DPOOL Pool );
79*61046927SAndroid Build Coastguard Worker 
80*61046927SAndroid Build Coastguard Worker void
81*61046927SAndroid Build Coastguard Worker NineBuffer9_dtor( struct NineBuffer9 *This );
82*61046927SAndroid Build Coastguard Worker 
83*61046927SAndroid Build Coastguard Worker struct pipe_resource *
84*61046927SAndroid Build Coastguard Worker NineBuffer9_GetResource( struct NineBuffer9 *This, unsigned *offset );
85*61046927SAndroid Build Coastguard Worker 
86*61046927SAndroid Build Coastguard Worker HRESULT NINE_WINAPI
87*61046927SAndroid Build Coastguard Worker NineBuffer9_Lock( struct NineBuffer9 *This,
88*61046927SAndroid Build Coastguard Worker                         UINT OffsetToLock,
89*61046927SAndroid Build Coastguard Worker                         UINT SizeToLock,
90*61046927SAndroid Build Coastguard Worker                         void **ppbData,
91*61046927SAndroid Build Coastguard Worker                         DWORD Flags );
92*61046927SAndroid Build Coastguard Worker 
93*61046927SAndroid Build Coastguard Worker HRESULT NINE_WINAPI
94*61046927SAndroid Build Coastguard Worker NineBuffer9_Unlock( struct NineBuffer9 *This );
95*61046927SAndroid Build Coastguard Worker 
96*61046927SAndroid Build Coastguard Worker void
97*61046927SAndroid Build Coastguard Worker NineBuffer9_Upload( struct NineBuffer9 *This );
98*61046927SAndroid Build Coastguard Worker 
99*61046927SAndroid Build Coastguard Worker static void inline
NineBindBufferToDevice(struct NineDevice9 * device,struct NineBuffer9 ** slot,struct NineBuffer9 * buf)100*61046927SAndroid Build Coastguard Worker NineBindBufferToDevice( struct NineDevice9 *device,
101*61046927SAndroid Build Coastguard Worker                         struct NineBuffer9 **slot,
102*61046927SAndroid Build Coastguard Worker                         struct NineBuffer9 *buf )
103*61046927SAndroid Build Coastguard Worker {
104*61046927SAndroid Build Coastguard Worker     struct NineBuffer9 *old = *slot;
105*61046927SAndroid Build Coastguard Worker 
106*61046927SAndroid Build Coastguard Worker     if (buf) {
107*61046927SAndroid Build Coastguard Worker         if ((buf->managed.dirty) && list_is_empty(&buf->managed.list))
108*61046927SAndroid Build Coastguard Worker             list_add(&buf->managed.list, &device->update_buffers);
109*61046927SAndroid Build Coastguard Worker         buf->bind_count++;
110*61046927SAndroid Build Coastguard Worker     }
111*61046927SAndroid Build Coastguard Worker     if (old) {
112*61046927SAndroid Build Coastguard Worker         old->bind_count--;
113*61046927SAndroid Build Coastguard Worker         if (!old->bind_count && old->managed.dirty)
114*61046927SAndroid Build Coastguard Worker             list_delinit(&old->managed.list);
115*61046927SAndroid Build Coastguard Worker     }
116*61046927SAndroid Build Coastguard Worker 
117*61046927SAndroid Build Coastguard Worker     nine_bind(slot, buf);
118*61046927SAndroid Build Coastguard Worker }
119*61046927SAndroid Build Coastguard Worker 
120*61046927SAndroid Build Coastguard Worker void
121*61046927SAndroid Build Coastguard Worker NineBuffer9_SetDirty( struct NineBuffer9 *This );
122*61046927SAndroid Build Coastguard Worker 
123*61046927SAndroid Build Coastguard Worker #define BASEBUF_REGISTER_UPDATE(b) { \
124*61046927SAndroid Build Coastguard Worker     if ((b)->managed.dirty && (b)->bind_count) \
125*61046927SAndroid Build Coastguard Worker         if (list_is_empty(&(b)->managed.list)) \
126*61046927SAndroid Build Coastguard Worker             list_add(&(b)->managed.list, &(b)->base.base.device->update_buffers); \
127*61046927SAndroid Build Coastguard Worker     }
128*61046927SAndroid Build Coastguard Worker 
129*61046927SAndroid Build Coastguard Worker #endif /* _NINE_BUFFER9_H_ */
130