2 #ifndef __NVC0_RESOURCE_H__
3 #define __NVC0_RESOURCE_H__
5 #include "util/u_transfer.h"
6 #include "util/u_double_list.h"
8 #include "nouveau/nouveau_winsys.h"
11 #include "nvc0_fence.h"
17 #define NVC0_BUFFER_SCORE_MIN -25000
18 #define NVC0_BUFFER_SCORE_MAX 25000
19 #define NVC0_BUFFER_SCORE_VRAM_THRESHOLD 20000
21 /* DIRTY: buffer was (or will be after the next flush) written to by GPU and
22 * resource->data has not been updated to reflect modified VRAM contents
24 * USER_MEMORY: resource->data is a pointer to client memory and may change
27 #define NVC0_BUFFER_STATUS_DIRTY (1 << 0)
28 #define NVC0_BUFFER_STATUS_USER_MEMORY (1 << 7)
30 /* Resources, if mapped into the GPU's address space, are guaranteed to
31 * have constant virtual addresses.
32 * The address of a resource will lie within the nouveau_bo referenced,
33 * and this bo should be added to the memory manager's validation list.
35 struct nvc0_resource
{
36 struct pipe_resource base
;
37 const struct u_resource_vtbl
*vtbl
;
40 struct nouveau_bo
*bo
;
46 int16_t score
; /* low if mapped very often, if high can move to VRAM */
48 struct nvc0_fence
*fence
;
49 struct nvc0_fence
*fence_wr
;
51 struct nvc0_mm_allocation
*mm
;
55 nvc0_buffer_release_gpu_storage(struct nvc0_resource
*);
58 nvc0_buffer_download(struct nvc0_context
*, struct nvc0_resource
*,
59 unsigned start
, unsigned size
);
62 nvc0_buffer_migrate(struct nvc0_context
*,
63 struct nvc0_resource
*, unsigned domain
);
66 nvc0_buffer_adjust_score(struct nvc0_context
*nvc0
, struct nvc0_resource
*res
,
70 if (res
->score
> NVC0_BUFFER_SCORE_MIN
)
74 if (res
->score
< NVC0_BUFFER_SCORE_MAX
)
76 if (res
->domain
== NOUVEAU_BO_GART
&&
77 res
->score
> NVC0_BUFFER_SCORE_VRAM_THRESHOLD
)
78 nvc0_buffer_migrate(nvc0
, res
, NOUVEAU_BO_VRAM
);
82 /* XXX: wait for fence (atm only using this for vertex push) */
84 nvc0_resource_map_offset(struct nvc0_context
*nvc0
,
85 struct nvc0_resource
*res
, uint32_t offset
,
90 nvc0_buffer_adjust_score(nvc0
, res
, -250);
92 if ((res
->domain
== NOUVEAU_BO_VRAM
) &&
93 (res
->status
& NVC0_BUFFER_STATUS_DIRTY
))
94 nvc0_buffer_download(nvc0
, res
, 0, res
->base
.width0
);
96 if ((res
->domain
!= NOUVEAU_BO_GART
) ||
97 (res
->status
& NVC0_BUFFER_STATUS_USER_MEMORY
))
98 return res
->data
+ offset
;
101 flags
|= NOUVEAU_BO_NOSYNC
;
103 if (nouveau_bo_map_range(res
->bo
, res
->offset
+ offset
,
104 res
->base
.width0
, flags
))
108 nouveau_bo_unmap(res
->bo
);
113 nvc0_resource_unmap(struct nvc0_resource
*res
)
118 #define NVC0_TILE_DIM_SHIFT(m, d) (((m) >> (d * 4)) & 0xf)
120 #define NVC0_TILE_PITCH(m) (64 << NVC0_TILE_DIM_SHIFT(m, 0))
121 #define NVC0_TILE_HEIGHT(m) ( 8 << NVC0_TILE_DIM_SHIFT(m, 1))
122 #define NVC0_TILE_DEPTH(m) ( 1 << NVC0_TILE_DIM_SHIFT(m, 2))
124 #define NVC0_TILE_SIZE_2D(m) (((64 * 8) << \
125 NVC0_TILE_DIM_SHIFT(m, 0)) << \
126 NVC0_TILE_DIM_SHIFT(m, 1))
128 #define NVC0_TILE_SIZE(m) (NVC0_TILE_SIZE_2D(m) << NVC0_TILE_DIM_SHIFT(m, 2))
130 struct nvc0_miptree_level
{
136 #define NVC0_MAX_TEXTURE_LEVELS 16
138 struct nvc0_miptree
{
139 struct nvc0_resource base
;
140 struct nvc0_miptree_level level
[NVC0_MAX_TEXTURE_LEVELS
];
142 uint32_t layer_stride
;
143 boolean layout_3d
; /* TRUE if layer count varies with mip level */
146 static INLINE
struct nvc0_miptree
*
147 nvc0_miptree(struct pipe_resource
*pt
)
149 return (struct nvc0_miptree
*)pt
;
152 static INLINE
struct nvc0_resource
*
153 nvc0_resource(struct pipe_resource
*resource
)
155 return (struct nvc0_resource
*)resource
;
158 /* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */
159 static INLINE boolean
160 nvc0_resource_mapped_by_gpu(struct pipe_resource
*resource
)
162 return nvc0_resource(resource
)->domain
!= 0;
166 nvc0_init_resource_functions(struct pipe_context
*pcontext
);
169 nvc0_screen_init_resource_functions(struct pipe_screen
*pscreen
);
171 /* Internal functions:
173 struct pipe_resource
*
174 nvc0_miptree_create(struct pipe_screen
*pscreen
,
175 const struct pipe_resource
*tmp
);
177 struct pipe_resource
*
178 nvc0_miptree_from_handle(struct pipe_screen
*pscreen
,
179 const struct pipe_resource
*template,
180 struct winsys_handle
*whandle
);
182 struct pipe_resource
*
183 nvc0_buffer_create(struct pipe_screen
*pscreen
,
184 const struct pipe_resource
*templ
);
186 struct pipe_resource
*
187 nvc0_user_buffer_create(struct pipe_screen
*screen
,
193 struct pipe_surface
*
194 nvc0_miptree_surface_new(struct pipe_context
*,
195 struct pipe_resource
*,
196 const struct pipe_surface
*templ
);
199 nvc0_miptree_surface_del(struct pipe_context
*, struct pipe_surface
*);
202 nvc0_user_buffer_upload(struct nvc0_resource
*, unsigned base
, unsigned size
);