1
2#ifndef __NV50_RESOURCE_H__
3#define __NV50_RESOURCE_H__
4
5#include "util/u_transfer.h"
6#include "util/list.h"
7
8#include "nouveau_winsys.h"
9#include "nouveau_buffer.h"
10
11#ifndef __NVC0_RESOURCE_H__ /* make sure we don't use these in nvc0: */
12
13void
14nv50_init_resource_functions(struct pipe_context *pcontext);
15
16void
17nv50_screen_init_resource_functions(struct pipe_screen *pscreen);
18
19#define NV50_RESOURCE_FLAG_VIDEO (NOUVEAU_RESOURCE_FLAG_DRV_PRIV << 0)
20#define NV50_RESOURCE_FLAG_NOALLOC (NOUVEAU_RESOURCE_FLAG_DRV_PRIV << 1)
21
22#define NV50_TILE_SHIFT_X(m) 6
23#define NV50_TILE_SHIFT_Y(m) ((((m) >> 4) & 0xf) + 2)
24#define NV50_TILE_SHIFT_Z(m) ((((m) >> 8) & 0xf) + 0)
25
26#define NV50_TILE_SIZE_X(m) 64
27#define NV50_TILE_SIZE_Y(m) ( 4 << (((m) >> 4) & 0xf))
28#define NV50_TILE_SIZE_Z(m) ( 1 << (((m) >> 8) & 0xf))
29
30#define NV50_TILE_SIZE_2D(m) (NV50_TILE_SIZE_X(m) << NV50_TILE_SHIFT_Y(m))
31
32#define NV50_TILE_SIZE(m) (NV50_TILE_SIZE_2D(m) << NV50_TILE_SHIFT_Z(m))
33
34#endif /* __NVC0_RESOURCE_H__ */
35
36uint32_t
37nv50_tex_choose_tile_dims_helper(unsigned nx, unsigned ny, unsigned nz,
38                                 bool is_3d);
39
40struct nv50_miptree_level {
41   uint32_t offset;
42   uint32_t pitch;
43   uint32_t tile_mode;
44};
45
46#define NV50_MAX_TEXTURE_LEVELS 16
47
48struct nv50_miptree {
49   struct nv04_resource base;
50   struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
51   uint32_t total_size;
52   uint32_t layer_stride;
53   bool layout_3d; /* true if layer count varies with mip level */
54   uint8_t ms_x;      /* log2 of number of samples in x/y dimension */
55   uint8_t ms_y;
56   uint8_t ms_mode;
57};
58
59static inline struct nv50_miptree *
60nv50_miptree(struct pipe_resource *pt)
61{
62   return (struct nv50_miptree *)pt;
63}
64
65
66#define NV50_TEXVIEW_SCALED_COORDS     (1 << 0)
67#define NV50_TEXVIEW_FILTER_MSAA8      (1 << 1)
68#define NV50_TEXVIEW_ACCESS_RESOLVE    (1 << 2)
69#define NV50_TEXVIEW_IMAGE_GM107       (1 << 3)
70
71
72/* Internal functions:
73 */
74bool
75nv50_miptree_init_layout_linear(struct nv50_miptree *mt, unsigned pitch_align);
76
77struct pipe_resource *
78nv50_miptree_create(struct pipe_screen *pscreen,
79                    const struct pipe_resource *tmp);
80
81void
82nv50_miptree_destroy(struct pipe_screen *pscreen, struct pipe_resource *pt);
83
84struct pipe_resource *
85nv50_miptree_from_handle(struct pipe_screen *pscreen,
86                         const struct pipe_resource *template,
87                         struct winsys_handle *whandle);
88
89bool
90nv50_miptree_get_handle(struct pipe_screen *pscreen,
91                        struct pipe_context *context,
92                        struct pipe_resource *pt,
93                        struct winsys_handle *whandle,
94                        unsigned usage);
95
96struct nv50_surface {
97   struct pipe_surface base;
98   uint32_t offset;
99   uint32_t width;
100   uint16_t height;
101   uint16_t depth;
102};
103
104static inline struct nv50_surface *
105nv50_surface(struct pipe_surface *ps)
106{
107   return (struct nv50_surface *)ps;
108}
109
110static inline enum pipe_format
111nv50_zs_to_s_format(enum pipe_format format)
112{
113   switch (format) {
114   case PIPE_FORMAT_Z24_UNORM_S8_UINT: return PIPE_FORMAT_X24S8_UINT;
115   case PIPE_FORMAT_S8_UINT_Z24_UNORM: return PIPE_FORMAT_S8X24_UINT;
116   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: return PIPE_FORMAT_X32_S8X24_UINT;
117   default:
118      return format;
119   }
120}
121
122#ifndef __NVC0_RESOURCE_H__
123
124unsigned
125nv50_mt_zslice_offset(const struct nv50_miptree *mt, unsigned l, unsigned z);
126
127struct pipe_surface *
128nv50_miptree_surface_new(struct pipe_context *,
129                         struct pipe_resource *,
130                         const struct pipe_surface *templ);
131
132void *
133nv50_miptree_transfer_map(struct pipe_context *pctx,
134                          struct pipe_resource *res,
135                          unsigned level,
136                          unsigned usage,
137                          const struct pipe_box *box,
138                          struct pipe_transfer **ptransfer);
139void
140nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
141                            struct pipe_transfer *ptx);
142
143#endif /* __NVC0_RESOURCE_H__ */
144
145struct nv50_surface *
146nv50_surface_from_miptree(struct nv50_miptree *mt,
147                          const struct pipe_surface *templ);
148
149struct pipe_surface *
150nv50_surface_from_buffer(struct pipe_context *pipe,
151                         struct pipe_resource *pt,
152                         const struct pipe_surface *templ);
153
154void
155nv50_surface_destroy(struct pipe_context *, struct pipe_surface *);
156
157void
158nv50_invalidate_resource(struct pipe_context *, struct pipe_resource *);
159
160void
161nv50_clear_texture(struct pipe_context *pipe,
162                   struct pipe_resource *res,
163                   unsigned level,
164                   const struct pipe_box *box,
165                   const void *data);
166
167#endif /* __NV50_RESOURCE_H__ */
168