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