50cc2afdbe138dbae14e32fab28b928ceb07e85f
[mesa.git] / src / gallium / drivers / nv50 / nv50_resource.h
1
2 #ifndef __NV50_RESOURCE_H__
3 #define __NV50_RESOURCE_H__
4
5 #include "util/u_transfer.h"
6 #include "util/u_double_list.h"
7 #define NOUVEAU_NVC0
8 #include "nouveau/nouveau_winsys.h"
9 #include "nouveau/nouveau_buffer.h"
10 #undef NOUVEAU_NVC0
11
12 #ifndef __NVC0_RESOURCE_H__ /* make sure we don't use these in nvc0: */
13
14 void
15 nv50_init_resource_functions(struct pipe_context *pcontext);
16
17 void
18 nv50_screen_init_resource_functions(struct pipe_screen *pscreen);
19
20
21 #define NV50_TILE_SHIFT_X(m) 6
22 #define NV50_TILE_SHIFT_Y(m) ((((m) >> 0) & 0xf) + 2)
23 #define NV50_TILE_SHIFT_Z(m) ((((m) >> 4) & 0xf) + 0)
24
25 #define NV50_TILE_SIZE_X(m) 64
26 #define NV50_TILE_SIZE_Y(m) ( 4 << (((m) >> 0) & 0xf))
27 #define NV50_TILE_SIZE_Z(m) ( 1 << (((m) >> 4) & 0xf))
28
29 #define NV50_TILE_SIZE_2D(m) (NV50_TILE_SIZE_X(m) << NV50_TILE_SHIFT_Y(m))
30
31 #define NV50_TILE_SIZE(m) (NV50_TILE_SIZE_2D(m) << NV50_TILE_SHIFT_Z(m))
32
33 #endif /* __NVC0_RESOURCE_H__ */
34
35 uint32_t
36 nvc0_tex_choose_tile_dims(unsigned nx, unsigned ny, unsigned nz);
37
38
39 struct nv50_miptree_level {
40 uint32_t offset;
41 uint32_t pitch;
42 uint32_t tile_mode;
43 };
44
45 #define NV50_MAX_TEXTURE_LEVELS 16
46
47 struct nv50_miptree {
48 struct nv04_resource base;
49 struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
50 uint32_t total_size;
51 uint32_t layer_stride;
52 boolean layout_3d; /* TRUE if layer count varies with mip level */
53 uint8_t ms_x; /* log2 of number of samples in x/y dimension */
54 uint8_t ms_y;
55 uint8_t ms_mode;
56 };
57
58 static INLINE struct nv50_miptree *
59 nv50_miptree(struct pipe_resource *pt)
60 {
61 return (struct nv50_miptree *)pt;
62 }
63
64 /* Internal functions:
65 */
66 boolean
67 nv50_miptree_init_layout_linear(struct nv50_miptree *mt);
68
69 struct pipe_resource *
70 nv50_miptree_create(struct pipe_screen *pscreen,
71 const struct pipe_resource *tmp);
72
73 void
74 nv50_miptree_destroy(struct pipe_screen *pscreen, struct pipe_resource *pt);
75
76 struct pipe_resource *
77 nv50_miptree_from_handle(struct pipe_screen *pscreen,
78 const struct pipe_resource *template,
79 struct winsys_handle *whandle);
80
81 boolean
82 nv50_miptree_get_handle(struct pipe_screen *pscreen,
83 struct pipe_resource *pt,
84 struct winsys_handle *whandle);
85
86 struct nv50_surface {
87 struct pipe_surface base;
88 uint32_t offset;
89 uint32_t width;
90 uint16_t height;
91 uint16_t depth;
92 };
93
94 static INLINE struct nv50_surface *
95 nv50_surface(struct pipe_surface *ps)
96 {
97 return (struct nv50_surface *)ps;
98 }
99
100 #ifndef __NVC0_RESOURCE_H__
101
102 unsigned
103 nv50_mt_zslice_offset(const struct nv50_miptree *mt, unsigned l, unsigned z);
104
105 struct pipe_surface *
106 nv50_miptree_surface_new(struct pipe_context *,
107 struct pipe_resource *,
108 const struct pipe_surface *templ);
109
110 struct pipe_transfer *
111 nv50_miptree_transfer_new(struct pipe_context *pcontext,
112 struct pipe_resource *pt,
113 unsigned level,
114 unsigned usage,
115 const struct pipe_box *box);
116 void
117 nv50_miptree_transfer_del(struct pipe_context *pcontext,
118 struct pipe_transfer *ptx);
119 void *
120 nv50_miptree_transfer_map(struct pipe_context *pcontext,
121 struct pipe_transfer *ptx);
122 void
123 nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
124 struct pipe_transfer *ptx);
125
126 #endif /* __NVC0_RESOURCE_H__ */
127
128 struct nv50_surface *
129 nv50_surface_from_miptree(struct nv50_miptree *mt,
130 const struct pipe_surface *templ);
131
132 struct pipe_surface *
133 nv50_surface_from_buffer(struct pipe_context *pipe,
134 struct pipe_resource *pt,
135 const struct pipe_surface *templ);
136
137 void
138 nv50_surface_destroy(struct pipe_context *, struct pipe_surface *);
139
140 #endif /* __NV50_RESOURCE_H__ */