2 #include "pipe/p_context.h"
3 #include "util/u_inlines.h"
4 #include "util/u_format.h"
5 #include "util/u_math.h"
7 #include "nv50_context.h"
8 #include "nv50_transfer.h"
9 #include "nv50_resource.h"
11 struct nv50_transfer {
12 struct pipe_transfer base;
13 struct nouveau_bo *bo;
15 unsigned level_offset;
16 unsigned level_tiling;
29 nv50_transfer_rect_m2mf(struct pipe_screen *pscreen,
30 struct nouveau_bo *src_bo, unsigned src_offset,
31 int src_pitch, unsigned src_tile_mode,
32 int sx, int sy, int sz, int sw, int sh, int sd,
33 struct nouveau_bo *dst_bo, unsigned dst_offset,
34 int dst_pitch, unsigned dst_tile_mode,
35 int dx, int dy, int dz, int dw, int dh, int dd,
36 int cpp, int width, int height,
37 unsigned src_reloc, unsigned dst_reloc)
39 struct nv50_screen *screen = nv50_screen(pscreen);
40 struct nouveau_channel *chan = screen->m2mf->channel;
41 struct nouveau_grobj *m2mf = screen->m2mf;
43 src_reloc |= NOUVEAU_BO_RD;
44 dst_reloc |= NOUVEAU_BO_WR;
48 if (!src_bo->tile_flags) {
49 BEGIN_RING(chan, m2mf,
50 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN, 1);
52 BEGIN_RING(chan, m2mf,
53 NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_IN, 1);
54 OUT_RING (chan, src_pitch);
55 src_offset += (sy * src_pitch) + (sx * cpp);
57 BEGIN_RING(chan, m2mf,
58 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN, 6);
60 OUT_RING (chan, src_tile_mode << 4);
61 OUT_RING (chan, sw * cpp);
64 OUT_RING (chan, sz); /* copying only 1 zslice per call */
67 if (!dst_bo->tile_flags) {
68 BEGIN_RING(chan, m2mf,
69 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT, 1);
71 BEGIN_RING(chan, m2mf,
72 NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_OUT, 1);
73 OUT_RING (chan, dst_pitch);
74 dst_offset += (dy * dst_pitch) + (dx * cpp);
76 BEGIN_RING(chan, m2mf,
77 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT, 6);
79 OUT_RING (chan, dst_tile_mode << 4);
80 OUT_RING (chan, dw * cpp);
83 OUT_RING (chan, dz); /* copying only 1 zslice per call */
87 int line_count = height > 2047 ? 2047 : height;
89 MARK_RING (chan, 15, 4); /* flush on lack of space or relocs */
90 BEGIN_RING(chan, m2mf,
91 NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH, 2);
92 OUT_RELOCh(chan, src_bo, src_offset, src_reloc);
93 OUT_RELOCh(chan, dst_bo, dst_offset, dst_reloc);
94 BEGIN_RING(chan, m2mf,
95 NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 2);
96 OUT_RELOCl(chan, src_bo, src_offset, src_reloc);
97 OUT_RELOCl(chan, dst_bo, dst_offset, dst_reloc);
98 if (src_bo->tile_flags) {
99 BEGIN_RING(chan, m2mf,
100 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN, 1);
101 OUT_RING (chan, (sy << 16) | (sx * cpp));
103 src_offset += (line_count * src_pitch);
105 if (dst_bo->tile_flags) {
106 BEGIN_RING(chan, m2mf,
107 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT, 1);
108 OUT_RING (chan, (dy << 16) | (dx * cpp));
110 dst_offset += (line_count * dst_pitch);
112 BEGIN_RING(chan, m2mf,
113 NV04_MEMORY_TO_MEMORY_FORMAT_LINE_LENGTH_IN, 4);
114 OUT_RING (chan, width * cpp);
115 OUT_RING (chan, line_count);
116 OUT_RING (chan, 0x00000101);
120 height -= line_count;
126 struct pipe_transfer *
127 nv50_miptree_transfer_new(struct pipe_context *pcontext,
128 struct pipe_resource *pt,
129 struct pipe_subresource sr,
131 const struct pipe_box *box)
133 struct pipe_screen *pscreen = pcontext->screen;
134 struct nouveau_device *dev = nouveau_screen(pscreen)->device;
135 struct nv50_miptree *mt = nv50_miptree(pt);
136 struct nv50_miptree_level *lvl = &mt->level[sr.level];
137 struct nv50_transfer *tx;
138 unsigned nx, ny, image = 0;
141 if (pt->target == PIPE_TEXTURE_CUBE)
144 tx = CALLOC_STRUCT(nv50_transfer);
148 /* Don't handle 3D transfers yet.
150 assert(box->depth == 1);
153 pipe_resource_reference(&tx->base.resource, pt);
155 tx->base.usage = usage;
157 tx->nblocksx = util_format_get_nblocksx(pt->format, u_minify(pt->width0, sr.level));
158 tx->nblocksy = util_format_get_nblocksy(pt->format, u_minify(pt->height0, sr.level));
159 tx->base.stride = tx->nblocksx * util_format_get_blocksize(pt->format);
160 tx->base.usage = usage;
162 tx->level_pitch = lvl->pitch;
163 tx->level_width = u_minify(mt->base.base.width0, sr.level);
164 tx->level_height = u_minify(mt->base.base.height0, sr.level);
165 tx->level_depth = u_minify(mt->base.base.depth0, sr.level);
166 tx->level_offset = lvl->image_offset[image];
167 tx->level_tiling = lvl->tile_mode;
168 tx->level_z = box->z;
169 tx->level_x = util_format_get_nblocksx(pt->format, box->x);
170 tx->level_y = util_format_get_nblocksy(pt->format, box->y);
171 ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
172 tx->nblocksy * tx->base.stride, &tx->bo);
178 if (usage & PIPE_TRANSFER_READ) {
179 nx = util_format_get_nblocksx(pt->format, box->width);
180 ny = util_format_get_nblocksy(pt->format, box->height);
182 nv50_transfer_rect_m2mf(pscreen, mt->base.bo, tx->level_offset,
183 tx->level_pitch, tx->level_tiling,
184 box->x, box->y, box->z,
185 tx->nblocksx, tx->nblocksy,
188 tx->base.stride, tx->bo->tile_mode,
190 tx->nblocksx, tx->nblocksy, 1,
191 util_format_get_blocksize(pt->format), nx, ny,
192 NOUVEAU_BO_VRAM | NOUVEAU_BO_GART,
200 nv50_miptree_transfer_del(struct pipe_context *pcontext,
201 struct pipe_transfer *ptx)
203 struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
204 struct nv50_miptree *mt = nv50_miptree(ptx->resource);
205 struct pipe_resource *pt = ptx->resource;
207 unsigned nx = util_format_get_nblocksx(pt->format, tx->base.box.width);
208 unsigned ny = util_format_get_nblocksy(pt->format, tx->base.box.height);
210 if (ptx->usage & PIPE_TRANSFER_WRITE) {
211 struct pipe_screen *pscreen = pcontext->screen;
213 nv50_transfer_rect_m2mf(pscreen, tx->bo, 0,
214 tx->base.stride, tx->bo->tile_mode,
216 tx->nblocksx, tx->nblocksy, 1,
217 mt->base.bo, tx->level_offset,
218 tx->level_pitch, tx->level_tiling,
219 tx->level_x, tx->level_y, tx->level_z,
220 tx->nblocksx, tx->nblocksy,
222 util_format_get_blocksize(pt->format), nx, ny,
223 NOUVEAU_BO_GART, NOUVEAU_BO_VRAM |
227 nouveau_bo_ref(NULL, &tx->bo);
228 pipe_resource_reference(&ptx->resource, NULL);
233 nv50_miptree_transfer_map(struct pipe_context *pcontext,
234 struct pipe_transfer *ptx)
236 struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
240 if (tx->map_refcnt++)
243 if (ptx->usage & PIPE_TRANSFER_WRITE)
244 flags |= NOUVEAU_BO_WR;
245 if (ptx->usage & PIPE_TRANSFER_READ)
246 flags |= NOUVEAU_BO_RD;
248 ret = nouveau_bo_map(tx->bo, flags);
257 nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
258 struct pipe_transfer *ptx)
260 struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
262 if (--tx->map_refcnt)
264 nouveau_bo_unmap(tx->bo);
269 nv50_upload_sifc(struct nv50_context *nv50,
270 struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
271 unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
272 void *src, unsigned src_format, int src_pitch,
273 int x, int y, int w, int h, int cpp)
275 struct nouveau_channel *chan = nv50->screen->base.channel;
276 struct nouveau_grobj *eng2d = nv50->screen->eng2d;
277 struct nouveau_grobj *tesla = nv50->screen->tesla;
278 unsigned line_dwords = (w * cpp + 3) / 4;
280 reloc |= NOUVEAU_BO_WR;
282 MARK_RING (chan, 32, 2); /* flush on lack of space or relocs */
284 if (bo->tile_flags) {
285 BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 5);
286 OUT_RING (chan, dst_format);
288 OUT_RING (chan, bo->tile_mode << 4);
292 BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 2);
293 OUT_RING (chan, dst_format);
295 BEGIN_RING(chan, eng2d, NV50_2D_DST_PITCH, 1);
296 OUT_RING (chan, dst_pitch);
299 BEGIN_RING(chan, eng2d, NV50_2D_DST_WIDTH, 4);
300 OUT_RING (chan, dst_w);
301 OUT_RING (chan, dst_h);
302 OUT_RELOCh(chan, bo, dst_offset, reloc);
303 OUT_RELOCl(chan, bo, dst_offset, reloc);
305 /* NV50_2D_OPERATION_SRCCOPY assumed already set */
307 BEGIN_RING(chan, eng2d, NV50_2D_SIFC_BITMAP_ENABLE, 2);
309 OUT_RING (chan, src_format);
310 BEGIN_RING(chan, eng2d, NV50_2D_SIFC_WIDTH, 10);
323 const uint32_t *p = src;
324 unsigned count = line_dwords;
327 unsigned nr = MIN2(count, 1792);
329 if (AVAIL_RING(chan) <= nr) {
332 BEGIN_RING(chan, eng2d,
333 NV50_2D_DST_ADDRESS_HIGH, 2);
334 OUT_RELOCh(chan, bo, dst_offset, reloc);
335 OUT_RELOCl(chan, bo, dst_offset, reloc);
337 assert(AVAIL_RING(chan) > nr);
339 BEGIN_RING(chan, eng2d,
340 NV50_2D_SIFC_DATA | (2 << 29), nr);
341 OUT_RINGp (chan, p, nr);
350 BEGIN_RING(chan, tesla, NV50TCL_CODE_CB_FLUSH, 1);