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
13 void
14 nv50_init_resource_functions(struct pipe_context *pcontext);
15
16 void
17 nv50_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
36 uint32_t
37 nv50_tex_choose_tile_dims_helper(unsigned nx, unsigned ny, unsigned nz,
38 bool is_3d);
39
40 struct nv50_miptree_level {
41 uint32_t offset;
42 uint32_t pitch;
43 uint32_t tile_mode;
44 };
45
46 struct nv50_memobj {
47 struct winsys_handle *handle;
48 struct pipe_memory_object b;
49 struct nouveau_bo *bo;
50 unsigned stride;
51 };
52
53 #define NV50_MAX_TEXTURE_LEVELS 16
54
55 struct nv50_miptree {
56 struct nv04_resource base;
57 struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
58 uint32_t total_size;
59 uint32_t layer_stride;
60 bool layout_3d; /* true if layer count varies with mip level */
61 uint8_t ms_x; /* log2 of number of samples in x/y dimension */
62 uint8_t ms_y;
63 uint8_t ms_mode;
64 };
65
66 static inline struct nv50_miptree *
nv50_miptree(struct pipe_resource * pt)67 nv50_miptree(struct pipe_resource *pt)
68 {
69 return (struct nv50_miptree *)pt;
70 }
71
72
73 #define NV50_TEXVIEW_SCALED_COORDS (1 << 0)
74 #define NV50_TEXVIEW_FILTER_MSAA8 (1 << 1)
75 #define NV50_TEXVIEW_ACCESS_RESOLVE (1 << 2)
76 #define NV50_TEXVIEW_IMAGE_GM107 (1 << 3)
77
78
79 /* Internal functions:
80 */
81 bool
82 nv50_miptree_init_layout_linear(struct nv50_miptree *mt, unsigned pitch_align);
83
84 struct pipe_resource *
85 nv50_miptree_create(struct pipe_screen *pscreen,
86 const struct pipe_resource *tmp);
87
88 void
89 nv50_miptree_destroy(struct pipe_screen *pscreen, struct pipe_resource *pt);
90
91 struct pipe_resource *
92 nv50_miptree_from_handle(struct pipe_screen *pscreen,
93 const struct pipe_resource *template,
94 struct winsys_handle *whandle);
95
96 bool
97 nv50_miptree_get_handle(struct pipe_screen *pscreen,
98 struct pipe_context *context,
99 struct pipe_resource *pt,
100 struct winsys_handle *whandle,
101 unsigned usage);
102
103 struct nv50_surface {
104 struct pipe_surface base;
105 uint32_t offset;
106 uint32_t width;
107 uint16_t height;
108 uint16_t depth;
109 };
110
111 static inline struct nv50_surface *
nv50_surface(struct pipe_surface * ps)112 nv50_surface(struct pipe_surface *ps)
113 {
114 return (struct nv50_surface *)ps;
115 }
116
117 static inline enum pipe_format
nv50_zs_to_s_format(enum pipe_format format)118 nv50_zs_to_s_format(enum pipe_format format)
119 {
120 switch (format) {
121 case PIPE_FORMAT_Z24_UNORM_S8_UINT: return PIPE_FORMAT_X24S8_UINT;
122 case PIPE_FORMAT_S8_UINT_Z24_UNORM: return PIPE_FORMAT_S8X24_UINT;
123 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: return PIPE_FORMAT_X32_S8X24_UINT;
124 default:
125 return format;
126 }
127 }
128
129 #ifndef __NVC0_RESOURCE_H__
130
131 unsigned
132 nv50_mt_zslice_offset(const struct nv50_miptree *mt, unsigned l, unsigned z);
133
134 struct pipe_surface *
135 nv50_miptree_surface_new(struct pipe_context *,
136 struct pipe_resource *,
137 const struct pipe_surface *templ);
138
139 void *
140 nv50_miptree_transfer_map(struct pipe_context *pctx,
141 struct pipe_resource *res,
142 unsigned level,
143 unsigned usage,
144 const struct pipe_box *box,
145 struct pipe_transfer **ptransfer);
146 void
147 nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
148 struct pipe_transfer *ptx);
149
150 #endif /* __NVC0_RESOURCE_H__ */
151
152 struct nv50_surface *
153 nv50_surface_from_miptree(struct nv50_miptree *mt,
154 const struct pipe_surface *templ);
155
156 struct pipe_surface *
157 nv50_surface_from_buffer(struct pipe_context *pipe,
158 struct pipe_resource *pt,
159 const struct pipe_surface *templ);
160
161 void
162 nv50_surface_destroy(struct pipe_context *, struct pipe_surface *);
163
164 void
165 nv50_invalidate_resource(struct pipe_context *, struct pipe_resource *);
166
167 void
168 nv50_clear_texture(struct pipe_context *pipe,
169 struct pipe_resource *res,
170 unsigned level,
171 const struct pipe_box *box,
172 const void *data);
173
174 struct pipe_memory_object *
175 nv50_memobj_create_from_handle(struct pipe_screen *screen,
176 struct winsys_handle *handle,
177 bool dedicated);
178
179 struct pipe_resource *
180 nv50_resource_from_memobj(struct pipe_screen *screen,
181 const struct pipe_resource *t,
182 struct pipe_memory_object *pmemobj,
183 uint64_t offset);
184
185 void
186 nv50_memobj_destroy(struct pipe_screen *screen,
187 struct pipe_memory_object *pmemobj);
188
189 #endif /* __NV50_RESOURCE_H__ */
190