1 #ifndef NVFX_RESOURCE_H
2 #define NVFX_RESOURCE_H
4 #include "util/u_transfer.h"
5 #include "util/u_format.h"
6 #include "util/u_math.h"
7 #include "util/u_double_list.h"
8 #include "util/u_surfaces.h"
9 #include "util/u_dirty_surfaces.h"
10 #include <nouveau/nouveau_bo.h>
15 struct nvfx_resource
{
16 struct pipe_resource base
;
17 struct nouveau_bo
*bo
;
21 struct nvfx_resource
*nvfx_resource(struct pipe_resource
*resource
)
23 return (struct nvfx_resource
*)resource
;
26 #define NVFX_RESOURCE_FLAG_USER (NOUVEAU_RESOURCE_FLAG_DRV_PRIV << 0)
28 /* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */
30 nvfx_resource_mapped_by_gpu(struct pipe_resource
*resource
)
32 return nvfx_resource(resource
)->bo
->handle
;
35 /* is resource in VRAM? */
37 nvfx_resource_on_gpu(struct pipe_resource
* pr
)
40 // a compiler error here means you need to apply libdrm-nouveau-add-domain.patch to libdrm
41 // TODO: return FALSE if not VRAM and on a PCI-E system
42 return ((struct nvfx_resource
*)pr
)->bo
->domain
& (NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
);
48 #define NVFX_MAX_TEXTURE_LEVELS 16
51 struct nvfx_resource base
;
53 unsigned linear_pitch
; /* for linear textures, 0 for swizzled and compressed textures with level-dependent minimal pitch */
54 unsigned face_size
; /* 128-byte aligned face/total size */
55 unsigned level_offset
[NVFX_MAX_TEXTURE_LEVELS
];
57 struct util_surfaces surfaces
;
61 struct pipe_surface base
;
66 static INLINE
struct nouveau_bo
*
67 nvfx_surface_buffer(struct pipe_surface
*surf
)
69 struct nvfx_resource
*mt
= nvfx_resource(surf
->texture
);
75 nvfx_init_resource_functions(struct pipe_context
*pipe
);
78 nvfx_screen_init_resource_functions(struct pipe_screen
*pscreen
);
84 struct pipe_resource
*
85 nvfx_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_resource
*pt
);
88 nvfx_miptree_destroy(struct pipe_screen
*pscreen
,
89 struct pipe_resource
*presource
);
91 struct pipe_resource
*
92 nvfx_miptree_from_handle(struct pipe_screen
*pscreen
,
93 const struct pipe_resource
*template,
94 struct winsys_handle
*whandle
);
97 nvfx_miptree_surface_del(struct pipe_context
*pipe
, struct pipe_surface
*ps
);
100 nvfx_miptree_surface_new(struct pipe_context
*pipe
, struct pipe_resource
*pt
,
101 const struct pipe_surface
*surf_tmpl
);
103 /* only for miptrees, don't use for buffers */
105 /* NOTE: for swizzled 3D textures, this just returns the offset of the mipmap level */
106 static inline unsigned
107 nvfx_subresource_offset(struct pipe_resource
* pt
, unsigned face
, unsigned level
, unsigned zslice
)
109 if(pt
->target
== PIPE_BUFFER
)
113 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)pt
;
115 unsigned offset
= mt
->level_offset
[level
];
116 if (pt
->target
== PIPE_TEXTURE_CUBE
)
117 offset
+= mt
->face_size
* face
;
118 else if (pt
->target
== PIPE_TEXTURE_3D
&& mt
->linear_pitch
)
119 offset
+= zslice
* util_format_get_2d_size(pt
->format
, (mt
->linear_pitch
? mt
->linear_pitch
: util_format_get_stride(pt
->format
, u_minify(pt
->width0
, level
))), u_minify(pt
->height0
, level
));
124 static inline unsigned
125 nvfx_subresource_pitch(struct pipe_resource
* pt
, unsigned level
)
127 if(pt
->target
== PIPE_BUFFER
)
128 return ((struct nvfx_resource
*)pt
)->bo
->size
;
131 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)pt
;
134 return mt
->linear_pitch
;
136 return util_format_get_stride(pt
->format
, u_minify(pt
->width0
, level
));
142 struct nvfx_resource base
;
146 /* the range of data not yet uploaded to the GPU bo */
147 unsigned dirty_begin
;
150 /* whether all transfers were unsynchronized */
151 boolean dirty_unsynchronized
;
153 /* whether it would have been profitable to upload
154 * the latest updated data to the GPU immediately */
155 boolean last_update_static
;
157 /* how many bytes we need to draw before we deem
158 * the buffer to be static
160 long long bytes_to_draw_until_static
;
163 static inline struct nvfx_buffer
* nvfx_buffer(struct pipe_resource
* pr
)
165 return (struct nvfx_buffer
*)pr
;
168 /* this is an heuristic to determine whether we are better off uploading the
169 * buffer to the GPU, or just continuing pushing it on the FIFO
171 static inline boolean
nvfx_buffer_seems_static(struct nvfx_buffer
* buffer
)
173 return buffer
->last_update_static
174 || buffer
->bytes_to_draw_until_static
< 0;
177 struct pipe_resource
*
178 nvfx_buffer_create(struct pipe_screen
*pscreen
,
179 const struct pipe_resource
*template);
182 nvfx_buffer_destroy(struct pipe_screen
*pscreen
,
183 struct pipe_resource
*presource
);
185 struct pipe_resource
*
186 nvfx_user_buffer_create(struct pipe_screen
*screen
,
192 nvfx_buffer_upload(struct nvfx_buffer
* buffer
);