1287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
2f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller#ifndef __NV50_RESOURCE_H__
3f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller#define __NV50_RESOURCE_H__
4287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
5287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "util/u_transfer.h"
67a30668ad665f3315106e1a959c6186dea79a24aJason Ekstrand#include "util/list.h"
76d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
85eb7ff1175a644ffe3b0f1a75cb235400355f9fbJohannes Obermayr#include "nouveau_winsys.h"
95eb7ff1175a644ffe3b0f1a75cb235400355f9fbJohannes Obermayr#include "nouveau_buffer.h"
10f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
11cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#ifndef __NVC0_RESOURCE_H__ /* make sure we don't use these in nvc0: */
12cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
13f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillervoid
1479079141fa7cbf395d1ffc77364ac301d9824211Ben Skeggsnv50_init_resource_functions(struct pipe_context *pcontext);
15f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
1679079141fa7cbf395d1ffc77364ac301d9824211Ben Skeggsvoid
1779079141fa7cbf395d1ffc77364ac301d9824211Ben Skeggsnv50_screen_init_resource_functions(struct pipe_screen *pscreen);
18f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
19fbdae1ca41946af374c7924fd4c296199172890dIlia Mirkin#define NV50_RESOURCE_FLAG_VIDEO (NOUVEAU_RESOURCE_FLAG_DRV_PRIV << 0)
20b3f6f127f28737d034dcf1c12a9b66b88750e93bIlia Mirkin#define NV50_RESOURCE_FLAG_NOALLOC (NOUVEAU_RESOURCE_FLAG_DRV_PRIV << 1)
21f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
22cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#define NV50_TILE_SHIFT_X(m) 6
236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV50_TILE_SHIFT_Y(m) ((((m) >> 4) & 0xf) + 2)
246d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV50_TILE_SHIFT_Z(m) ((((m) >> 8) & 0xf) + 0)
25cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
26cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#define NV50_TILE_SIZE_X(m) 64
276d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV50_TILE_SIZE_Y(m) ( 4 << (((m) >> 4) & 0xf))
286d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV50_TILE_SIZE_Z(m) ( 1 << (((m) >> 8) & 0xf))
29cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
30cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#define NV50_TILE_SIZE_2D(m) (NV50_TILE_SIZE_X(m) << NV50_TILE_SHIFT_Y(m))
31cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
32cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#define NV50_TILE_SIZE(m) (NV50_TILE_SIZE_2D(m) << NV50_TILE_SHIFT_Z(m))
33cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
34cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#endif /* __NVC0_RESOURCE_H__ */
35f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
36cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumilleruint32_t
37ae720c66cb91c2640dfd6707446899694a24ab5bIlia Mirkinnv50_tex_choose_tile_dims_helper(unsigned nx, unsigned ny, unsigned nz,
38cd0dec0d9dfab642c51774c3f5788cbdf00b8c9bSamuel Pitoiset                                 bool is_3d);
39f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller
40287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct nv50_miptree_level {
41f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t offset;
42f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t pitch;
43f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t tile_mode;
44287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell};
45287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
46287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#define NV50_MAX_TEXTURE_LEVELS 16
47287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
48287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct nv50_miptree {
4979079141fa7cbf395d1ffc77364ac301d9824211Ben Skeggs   struct nv04_resource base;
50f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
51f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t total_size;
52f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   uint32_t layer_stride;
53cd0dec0d9dfab642c51774c3f5788cbdf00b8c9bSamuel Pitoiset   bool layout_3d; /* true if layer count varies with mip level */
54cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint8_t ms_x;      /* log2 of number of samples in x/y dimension */
55cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint8_t ms_y;
56cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint8_t ms_mode;
57287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell};
58287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
59a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkinstatic inline struct nv50_miptree *
60287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellnv50_miptree(struct pipe_resource *pt)
61287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
62f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller   return (struct nv50_miptree *)pt;
63287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
64287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
6536ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller
6636ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller#define NV50_TEXVIEW_SCALED_COORDS     (1 << 0)
6736ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller#define NV50_TEXVIEW_FILTER_MSAA8      (1 << 1)
684da54c91d24da891c56957f29274e7821c8254f6Christoph Bumiller#define NV50_TEXVIEW_ACCESS_RESOLVE    (1 << 2)
6936ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller
7036ea744f58e5b436c45ed857bd92bbb472e641d5Christoph Bumiller
71f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller/* Internal functions:
72287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell */
73cd0dec0d9dfab642c51774c3f5788cbdf00b8c9bSamuel Pitoisetbool
748e1dd58a7e76834c1fb6d117b6ea5755e05cfb77Christoph Bumillernv50_miptree_init_layout_linear(struct nv50_miptree *mt, unsigned pitch_align);
75cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
76287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct pipe_resource *
77287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellnv50_miptree_create(struct pipe_screen *pscreen,
78f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                    const struct pipe_resource *tmp);
79287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
80cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillervoid
81cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillernv50_miptree_destroy(struct pipe_screen *pscreen, struct pipe_resource *pt);
82cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
83287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct pipe_resource *
84287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellnv50_miptree_from_handle(struct pipe_screen *pscreen,
85f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         const struct pipe_resource *template,
86f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         struct winsys_handle *whandle);
87287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
88cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillerboolean
89cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillernv50_miptree_get_handle(struct pipe_screen *pscreen,
90cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller                        struct pipe_resource *pt,
91cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller                        struct winsys_handle *whandle);
92cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
93cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillerstruct nv50_surface {
94cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   struct pipe_surface base;
95cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint32_t offset;
96cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint32_t width;
97cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint16_t height;
98cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   uint16_t depth;
99cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller};
100cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
101a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkinstatic inline struct nv50_surface *
102cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillernv50_surface(struct pipe_surface *ps)
103cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller{
104cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller   return (struct nv50_surface *)ps;
105cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller}
106cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
107a2a1a5805fd617e7f3cc8be44dd79b50da07ebb9Ilia Mirkinstatic inline enum pipe_format
108b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumillernv50_zs_to_s_format(enum pipe_format format)
109b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller{
110b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   switch (format) {
111b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   case PIPE_FORMAT_Z24_UNORM_S8_UINT: return PIPE_FORMAT_X24S8_UINT;
112b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   case PIPE_FORMAT_S8_UINT_Z24_UNORM: return PIPE_FORMAT_S8X24_UINT;
113b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: return PIPE_FORMAT_X32_S8X24_UINT;
114b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   default:
115b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller      return format;
116b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller   }
117b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller}
118b328949a37fee7b0f68ed3e068ffc4426c083042Christoph Bumiller
119cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#ifndef __NVC0_RESOURCE_H__
120cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
121cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillerunsigned
122cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillernv50_mt_zslice_offset(const struct nv50_miptree *mt, unsigned l, unsigned z);
123cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
124287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct pipe_surface *
125f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumillernv50_miptree_surface_new(struct pipe_context *,
126f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         struct pipe_resource *,
127f80c03e1875fe96ff2f4c022e3cb76357828140dChristoph Bumiller                         const struct pipe_surface *templ);
128287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
129369e46888904c6d379b8b477d9242cff1608e30eMarek Olšákvoid *
130369e46888904c6d379b8b477d9242cff1608e30eMarek Olšáknv50_miptree_transfer_map(struct pipe_context *pctx,
131369e46888904c6d379b8b477d9242cff1608e30eMarek Olšák                          struct pipe_resource *res,
132b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller                          unsigned level,
133b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller                          unsigned usage,
134369e46888904c6d379b8b477d9242cff1608e30eMarek Olšák                          const struct pipe_box *box,
135369e46888904c6d379b8b477d9242cff1608e30eMarek Olšák                          struct pipe_transfer **ptransfer);
136b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumillervoid
137b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumillernv50_miptree_transfer_unmap(struct pipe_context *pcontext,
138b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller                            struct pipe_transfer *ptx);
139b2dcf880e8bcd61be59602f5a2d18c77a5fc60c1Christoph Bumiller
140cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#endif /* __NVC0_RESOURCE_H__ */
141cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
142cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillerstruct nv50_surface *
143cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumillernv50_surface_from_miptree(struct nv50_miptree *mt,
144cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller                          const struct pipe_surface *templ);
145cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller
14628271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumillerstruct pipe_surface *
14728271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumillernv50_surface_from_buffer(struct pipe_context *pipe,
14828271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller                         struct pipe_resource *pt,
14928271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller                         const struct pipe_surface *templ);
15028271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumiller
151287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid
15228271fd00dc5dd83f95b5cb890e0ab2c0ff6159dChristoph Bumillernv50_surface_destroy(struct pipe_context *, struct pipe_surface *);
153287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
154c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkinvoid
155f9480d7918a2da19b8ac85a8326049488feef92bIlia Mirkinnv50_invalidate_resource(struct pipe_context *, struct pipe_resource *);
156f9480d7918a2da19b8ac85a8326049488feef92bIlia Mirkin
157f9480d7918a2da19b8ac85a8326049488feef92bIlia Mirkinvoid
158c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkinnv50_clear_texture(struct pipe_context *pipe,
159c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkin                   struct pipe_resource *res,
160c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkin                   unsigned level,
161c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkin                   const struct pipe_box *box,
162c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkin                   const void *data);
163c4182bb9b0897b4a4ac4f06b54fc7f6a2ddeb105Ilia Mirkin
164cad17554c4b121c03e188dd0281718a52d603a15Christoph Bumiller#endif /* __NV50_RESOURCE_H__ */
165