2 #include "util/u_format.h"
4 #include "nvc0_context.h"
6 #include "nv50/nv50_defs.xml.h"
9 struct pipe_transfer base
;
10 struct nv50_m2mf_rect rect
[2];
17 nvc0_m2mf_transfer_rect(struct nvc0_context
*nvc0
,
18 const struct nv50_m2mf_rect
*dst
,
19 const struct nv50_m2mf_rect
*src
,
20 uint32_t nblocksx
, uint32_t nblocksy
)
22 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
23 struct nouveau_bufctx
*bctx
= nvc0
->bufctx
;
24 const int cpp
= dst
->cpp
;
25 uint32_t src_ofst
= src
->base
;
26 uint32_t dst_ofst
= dst
->base
;
27 uint32_t height
= nblocksy
;
30 uint32_t exec
= (1 << 20);
32 assert(dst
->cpp
== src
->cpp
);
34 nouveau_bufctx_refn(bctx
, 0, src
->bo
, src
->domain
| NOUVEAU_BO_RD
);
35 nouveau_bufctx_refn(bctx
, 0, dst
->bo
, dst
->domain
| NOUVEAU_BO_WR
);
36 nouveau_pushbuf_bufctx(push
, bctx
);
37 nouveau_pushbuf_validate(push
);
39 if (nouveau_bo_memtype(src
->bo
)) {
40 BEGIN_NVC0(push
, NVC0_M2MF(TILING_MODE_IN
), 5);
41 PUSH_DATA (push
, src
->tile_mode
);
42 PUSH_DATA (push
, src
->width
* cpp
);
43 PUSH_DATA (push
, src
->height
);
44 PUSH_DATA (push
, src
->depth
);
45 PUSH_DATA (push
, src
->z
);
47 src_ofst
+= src
->y
* src
->pitch
+ src
->x
* cpp
;
49 BEGIN_NVC0(push
, NVC0_M2MF(PITCH_IN
), 1);
50 PUSH_DATA (push
, src
->width
* cpp
);
52 exec
|= NVC0_M2MF_EXEC_LINEAR_IN
;
55 if (nouveau_bo_memtype(dst
->bo
)) {
56 BEGIN_NVC0(push
, NVC0_M2MF(TILING_MODE_OUT
), 5);
57 PUSH_DATA (push
, dst
->tile_mode
);
58 PUSH_DATA (push
, dst
->width
* cpp
);
59 PUSH_DATA (push
, dst
->height
);
60 PUSH_DATA (push
, dst
->depth
);
61 PUSH_DATA (push
, dst
->z
);
63 dst_ofst
+= dst
->y
* dst
->pitch
+ dst
->x
* cpp
;
65 BEGIN_NVC0(push
, NVC0_M2MF(PITCH_OUT
), 1);
66 PUSH_DATA (push
, dst
->width
* cpp
);
68 exec
|= NVC0_M2MF_EXEC_LINEAR_OUT
;
72 int line_count
= height
> 2047 ? 2047 : height
;
74 BEGIN_NVC0(push
, NVC0_M2MF(OFFSET_IN_HIGH
), 2);
75 PUSH_DATAh(push
, src
->bo
->offset
+ src_ofst
);
76 PUSH_DATA (push
, src
->bo
->offset
+ src_ofst
);
78 BEGIN_NVC0(push
, NVC0_M2MF(OFFSET_OUT_HIGH
), 2);
79 PUSH_DATAh(push
, dst
->bo
->offset
+ dst_ofst
);
80 PUSH_DATA (push
, dst
->bo
->offset
+ dst_ofst
);
82 if (!(exec
& NVC0_M2MF_EXEC_LINEAR_IN
)) {
83 BEGIN_NVC0(push
, NVC0_M2MF(TILING_POSITION_IN_X
), 2);
84 PUSH_DATA (push
, src
->x
* cpp
);
87 src_ofst
+= line_count
* src
->pitch
;
89 if (!(exec
& NVC0_M2MF_EXEC_LINEAR_OUT
)) {
90 BEGIN_NVC0(push
, NVC0_M2MF(TILING_POSITION_OUT_X
), 2);
91 PUSH_DATA (push
, dst
->x
* cpp
);
94 dst_ofst
+= line_count
* dst
->pitch
;
97 BEGIN_NVC0(push
, NVC0_M2MF(LINE_LENGTH_IN
), 2);
98 PUSH_DATA (push
, nblocksx
* cpp
);
99 PUSH_DATA (push
, line_count
);
100 BEGIN_NVC0(push
, NVC0_M2MF(EXEC
), 1);
101 PUSH_DATA (push
, exec
);
103 height
-= line_count
;
108 nouveau_bufctx_reset(bctx
, 0);
112 nve4_m2mf_transfer_rect(struct nvc0_context
*nvc0
,
113 const struct nv50_m2mf_rect
*dst
,
114 const struct nv50_m2mf_rect
*src
,
115 uint32_t nblocksx
, uint32_t nblocksy
)
117 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
118 struct nouveau_bufctx
*bctx
= nvc0
->bufctx
;
120 uint32_t src_base
= src
->base
;
121 uint32_t dst_base
= dst
->base
;
122 const int cpp
= dst
->cpp
;
124 assert(dst
->cpp
== src
->cpp
);
126 nouveau_bufctx_refn(bctx
, 0, dst
->bo
, dst
->domain
| NOUVEAU_BO_WR
);
127 nouveau_bufctx_refn(bctx
, 0, src
->bo
, src
->domain
| NOUVEAU_BO_RD
);
128 nouveau_pushbuf_bufctx(push
, bctx
);
129 nouveau_pushbuf_validate(push
);
131 exec
= 0x200 /* 2D_ENABLE */ | 0x6 /* UNK */;
133 if (!nouveau_bo_memtype(dst
->bo
)) {
135 dst_base
+= dst
->y
* dst
->pitch
+ dst
->x
* cpp
;
136 exec
|= 0x100; /* DST_MODE_2D_LINEAR */
138 if (!nouveau_bo_memtype(src
->bo
)) {
140 src_base
+= src
->y
* src
->pitch
+ src
->x
* cpp
;
141 exec
|= 0x080; /* SRC_MODE_2D_LINEAR */
144 BEGIN_NVC0(push
, SUBC_COPY(0x070c), 6);
145 PUSH_DATA (push
, 0x1000 | dst
->tile_mode
);
146 PUSH_DATA (push
, dst
->pitch
);
147 PUSH_DATA (push
, dst
->height
);
148 PUSH_DATA (push
, dst
->depth
);
149 PUSH_DATA (push
, dst
->z
);
150 PUSH_DATA (push
, (dst
->y
<< 16) | (dst
->x
* cpp
));
152 BEGIN_NVC0(push
, SUBC_COPY(0x0728), 6);
153 PUSH_DATA (push
, 0x1000 | src
->tile_mode
);
154 PUSH_DATA (push
, src
->pitch
);
155 PUSH_DATA (push
, src
->height
);
156 PUSH_DATA (push
, src
->depth
);
157 PUSH_DATA (push
, src
->z
);
158 PUSH_DATA (push
, (src
->y
<< 16) | (src
->x
* cpp
));
160 BEGIN_NVC0(push
, SUBC_COPY(0x0400), 8);
161 PUSH_DATAh(push
, src
->bo
->offset
+ src_base
);
162 PUSH_DATA (push
, src
->bo
->offset
+ src_base
);
163 PUSH_DATAh(push
, dst
->bo
->offset
+ dst_base
);
164 PUSH_DATA (push
, dst
->bo
->offset
+ dst_base
);
165 PUSH_DATA (push
, src
->pitch
);
166 PUSH_DATA (push
, dst
->pitch
);
167 PUSH_DATA (push
, nblocksx
* cpp
);
168 PUSH_DATA (push
, nblocksy
);
170 BEGIN_NVC0(push
, SUBC_COPY(0x0300), 1);
171 PUSH_DATA (push
, exec
);
173 nouveau_bufctx_reset(bctx
, 0);
177 nvc0_m2mf_push_linear(struct nouveau_context
*nv
,
178 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
179 unsigned size
, const void *data
)
181 struct nvc0_context
*nvc0
= nvc0_context(&nv
->pipe
);
182 struct nouveau_pushbuf
*push
= nv
->pushbuf
;
183 uint32_t *src
= (uint32_t *)data
;
184 unsigned count
= (size
+ 3) / 4;
186 nouveau_bufctx_refn(nvc0
->bufctx
, 0, dst
, domain
| NOUVEAU_BO_WR
);
187 nouveau_pushbuf_bufctx(push
, nvc0
->bufctx
);
188 nouveau_pushbuf_validate(push
);
193 if (!PUSH_SPACE(push
, 16))
195 nr
= PUSH_AVAIL(push
);
197 nr
= MIN2(count
, nr
- 9);
198 nr
= MIN2(nr
, NV04_PFIFO_MAX_PACKET_LEN
);
200 BEGIN_NVC0(push
, NVC0_M2MF(OFFSET_OUT_HIGH
), 2);
201 PUSH_DATAh(push
, dst
->offset
+ offset
);
202 PUSH_DATA (push
, dst
->offset
+ offset
);
203 BEGIN_NVC0(push
, NVC0_M2MF(LINE_LENGTH_IN
), 2);
204 PUSH_DATA (push
, nr
* 4);
206 BEGIN_NVC0(push
, NVC0_M2MF(EXEC
), 1);
207 PUSH_DATA (push
, 0x100111);
209 /* must not be interrupted (trap on QUERY fence, 0x50 works however) */
210 BEGIN_NIC0(push
, NVC0_M2MF(DATA
), nr
);
211 PUSH_DATAp(push
, src
, nr
);
218 nouveau_bufctx_reset(nvc0
->bufctx
, 0);
222 nve4_p2mf_push_linear(struct nouveau_context
*nv
,
223 struct nouveau_bo
*dst
, unsigned offset
, unsigned domain
,
224 unsigned size
, const void *data
)
226 struct nvc0_context
*nvc0
= nvc0_context(&nv
->pipe
);
227 struct nouveau_pushbuf
*push
= nv
->pushbuf
;
228 uint32_t *src
= (uint32_t *)data
;
229 unsigned count
= (size
+ 3) / 4;
231 nouveau_bufctx_refn(nvc0
->bufctx
, 0, dst
, domain
| NOUVEAU_BO_WR
);
232 nouveau_pushbuf_bufctx(push
, nvc0
->bufctx
);
233 nouveau_pushbuf_validate(push
);
238 if (!PUSH_SPACE(push
, 16))
240 nr
= PUSH_AVAIL(push
);
242 nr
= MIN2(count
, nr
- 8);
243 nr
= MIN2(nr
, (NV04_PFIFO_MAX_PACKET_LEN
- 1));
245 BEGIN_NVC0(push
, NVE4_P2MF(DST_ADDRESS_HIGH
), 2);
246 PUSH_DATAh(push
, dst
->offset
+ offset
);
247 PUSH_DATA (push
, dst
->offset
+ offset
);
248 BEGIN_NVC0(push
, NVE4_P2MF(LINE_LENGTH_IN
), 2);
249 PUSH_DATA (push
, nr
* 4);
251 /* must not be interrupted (trap on QUERY fence, 0x50 works however) */
252 BEGIN_1IC0(push
, NVE4_P2MF(EXEC
), nr
+ 1);
253 PUSH_DATA (push
, 0x1001);
254 PUSH_DATAp(push
, src
, nr
);
261 nouveau_bufctx_reset(nvc0
->bufctx
, 0);
265 nvc0_m2mf_copy_linear(struct nouveau_context
*nv
,
266 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
267 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
270 struct nouveau_pushbuf
*push
= nv
->pushbuf
;
271 struct nouveau_bufctx
*bctx
= nvc0_context(&nv
->pipe
)->bufctx
;
273 nouveau_bufctx_refn(bctx
, 0, src
, srcdom
| NOUVEAU_BO_RD
);
274 nouveau_bufctx_refn(bctx
, 0, dst
, dstdom
| NOUVEAU_BO_WR
);
275 nouveau_pushbuf_bufctx(push
, bctx
);
276 nouveau_pushbuf_validate(push
);
279 unsigned bytes
= MIN2(size
, 1 << 17);
281 BEGIN_NVC0(push
, NVC0_M2MF(OFFSET_OUT_HIGH
), 2);
282 PUSH_DATAh(push
, dst
->offset
+ dstoff
);
283 PUSH_DATA (push
, dst
->offset
+ dstoff
);
284 BEGIN_NVC0(push
, NVC0_M2MF(OFFSET_IN_HIGH
), 2);
285 PUSH_DATAh(push
, src
->offset
+ srcoff
);
286 PUSH_DATA (push
, src
->offset
+ srcoff
);
287 BEGIN_NVC0(push
, NVC0_M2MF(LINE_LENGTH_IN
), 2);
288 PUSH_DATA (push
, bytes
);
290 BEGIN_NVC0(push
, NVC0_M2MF(EXEC
), 1);
291 PUSH_DATA (push
, (1 << NVC0_M2MF_EXEC_INC__SHIFT
) |
292 NVC0_M2MF_EXEC_LINEAR_IN
| NVC0_M2MF_EXEC_LINEAR_OUT
);
299 nouveau_bufctx_reset(bctx
, 0);
303 nve4_m2mf_copy_linear(struct nouveau_context
*nv
,
304 struct nouveau_bo
*dst
, unsigned dstoff
, unsigned dstdom
,
305 struct nouveau_bo
*src
, unsigned srcoff
, unsigned srcdom
,
308 struct nouveau_pushbuf
*push
= nv
->pushbuf
;
309 struct nouveau_bufctx
*bctx
= nvc0_context(&nv
->pipe
)->bufctx
;
311 nouveau_bufctx_refn(bctx
, 0, src
, srcdom
| NOUVEAU_BO_RD
);
312 nouveau_bufctx_refn(bctx
, 0, dst
, dstdom
| NOUVEAU_BO_WR
);
313 nouveau_pushbuf_bufctx(push
, bctx
);
314 nouveau_pushbuf_validate(push
);
316 BEGIN_NVC0(push
, SUBC_COPY(0x0400), 4);
317 PUSH_DATAh(push
, src
->offset
+ srcoff
);
318 PUSH_DATA (push
, src
->offset
+ srcoff
);
319 PUSH_DATAh(push
, dst
->offset
+ dstoff
);
320 PUSH_DATA (push
, dst
->offset
+ dstoff
);
321 BEGIN_NVC0(push
, SUBC_COPY(0x0418), 1);
322 PUSH_DATA (push
, size
);
323 BEGIN_NVC0(push
, SUBC_COPY(0x0300), 1);
324 PUSH_DATA (push
, 0x186);
326 nouveau_bufctx_reset(bctx
, 0);
329 struct pipe_transfer
*
330 nvc0_miptree_transfer_new(struct pipe_context
*pctx
,
331 struct pipe_resource
*res
,
334 const struct pipe_box
*box
)
336 struct nvc0_context
*nvc0
= nvc0_context(pctx
);
337 struct nouveau_device
*dev
= nvc0
->screen
->base
.device
;
338 struct nv50_miptree
*mt
= nv50_miptree(res
);
339 struct nvc0_transfer
*tx
;
343 if (usage
& PIPE_TRANSFER_MAP_DIRECTLY
)
346 tx
= CALLOC_STRUCT(nvc0_transfer
);
350 pipe_resource_reference(&tx
->base
.resource
, res
);
352 tx
->base
.level
= level
;
353 tx
->base
.usage
= usage
;
356 if (util_format_is_plain(res
->format
)) {
357 tx
->nblocksx
= box
->width
<< mt
->ms_x
;
358 tx
->nblocksy
= box
->height
<< mt
->ms_y
;
360 tx
->nblocksx
= util_format_get_nblocksx(res
->format
, box
->width
);
361 tx
->nblocksy
= util_format_get_nblocksy(res
->format
, box
->height
);
363 tx
->nlayers
= box
->depth
;
365 tx
->base
.stride
= tx
->nblocksx
* util_format_get_blocksize(res
->format
);
366 tx
->base
.layer_stride
= tx
->nblocksy
* tx
->base
.stride
;
368 nv50_m2mf_rect_setup(&tx
->rect
[0], res
, level
, box
->x
, box
->y
, box
->z
);
370 size
= tx
->base
.layer_stride
;
372 ret
= nouveau_bo_new(dev
, NOUVEAU_BO_GART
| NOUVEAU_BO_MAP
, 0,
373 size
* tx
->nlayers
, NULL
, &tx
->rect
[1].bo
);
379 tx
->rect
[1].cpp
= tx
->rect
[0].cpp
;
380 tx
->rect
[1].width
= tx
->nblocksx
;
381 tx
->rect
[1].height
= tx
->nblocksy
;
382 tx
->rect
[1].depth
= 1;
383 tx
->rect
[1].pitch
= tx
->base
.stride
;
384 tx
->rect
[1].domain
= NOUVEAU_BO_GART
;
386 if (usage
& PIPE_TRANSFER_READ
) {
387 unsigned base
= tx
->rect
[0].base
;
388 unsigned z
= tx
->rect
[0].z
;
390 for (i
= 0; i
< tx
->nlayers
; ++i
) {
391 nvc0
->m2mf_copy_rect(nvc0
, &tx
->rect
[1], &tx
->rect
[0],
392 tx
->nblocksx
, tx
->nblocksy
);
396 tx
->rect
[0].base
+= mt
->layer_stride
;
397 tx
->rect
[1].base
+= size
;
400 tx
->rect
[0].base
= base
;
401 tx
->rect
[1].base
= 0;
408 nvc0_miptree_transfer_del(struct pipe_context
*pctx
,
409 struct pipe_transfer
*transfer
)
411 struct nvc0_context
*nvc0
= nvc0_context(pctx
);
412 struct nvc0_transfer
*tx
= (struct nvc0_transfer
*)transfer
;
413 struct nv50_miptree
*mt
= nv50_miptree(tx
->base
.resource
);
416 if (tx
->base
.usage
& PIPE_TRANSFER_WRITE
) {
417 for (i
= 0; i
< tx
->nlayers
; ++i
) {
418 nvc0
->m2mf_copy_rect(nvc0
, &tx
->rect
[0], &tx
->rect
[1],
419 tx
->nblocksx
, tx
->nblocksy
);
423 tx
->rect
[0].base
+= mt
->layer_stride
;
424 tx
->rect
[1].base
+= tx
->nblocksy
* tx
->base
.stride
;
428 nouveau_bo_ref(NULL
, &tx
->rect
[1].bo
);
429 pipe_resource_reference(&transfer
->resource
, NULL
);
435 nvc0_miptree_transfer_map(struct pipe_context
*pctx
,
436 struct pipe_transfer
*transfer
)
438 struct nvc0_context
*nvc0
= nvc0_context(pctx
);
439 struct nvc0_transfer
*tx
= (struct nvc0_transfer
*)transfer
;
443 if (tx
->rect
[1].bo
->map
)
444 return tx
->rect
[1].bo
->map
;
446 if (transfer
->usage
& PIPE_TRANSFER_READ
)
447 flags
= NOUVEAU_BO_RD
;
448 if (transfer
->usage
& PIPE_TRANSFER_WRITE
)
449 flags
|= NOUVEAU_BO_WR
;
451 ret
= nouveau_bo_map(tx
->rect
[1].bo
, flags
, nvc0
->screen
->base
.client
);
454 return tx
->rect
[1].bo
->map
;
458 nvc0_miptree_transfer_unmap(struct pipe_context
*pctx
,
459 struct pipe_transfer
*transfer
)
464 nvc0_cb_push(struct nouveau_context
*nv
,
465 struct nouveau_bo
*bo
, unsigned domain
,
466 unsigned base
, unsigned size
,
467 unsigned offset
, unsigned words
, const uint32_t *data
)
469 struct nouveau_bufctx
*bctx
= nvc0_context(&nv
->pipe
)->bufctx
;
470 struct nouveau_pushbuf
*push
= nv
->pushbuf
;
472 assert(!(offset
& 3));
473 size
= align(size
, 0x100);
475 nouveau_bufctx_refn(bctx
, 0, bo
, NOUVEAU_BO_WR
| domain
);
476 nouveau_pushbuf_bufctx(push
, bctx
);
477 nouveau_pushbuf_validate(push
);
479 BEGIN_NVC0(push
, NVC0_3D(CB_SIZE
), 3);
480 PUSH_DATA (push
, size
);
481 PUSH_DATAh(push
, bo
->offset
+ base
);
482 PUSH_DATA (push
, bo
->offset
+ base
);
485 unsigned nr
= PUSH_AVAIL(push
);
486 nr
= MIN2(nr
, words
);
487 nr
= MIN2(nr
, NV04_PFIFO_MAX_PACKET_LEN
- 1);
489 BEGIN_1IC0(push
, NVC0_3D(CB_POS
), nr
+ 1);
490 PUSH_DATA (push
, offset
);
491 PUSH_DATAp(push
, data
, nr
);
498 nouveau_bufctx_reset(bctx
, 0);
502 nvc0_init_transfer_functions(struct nvc0_context
*nvc0
)
504 if (nvc0
->screen
->base
.class_3d
>= NVE4_3D_CLASS
) {
505 nvc0
->m2mf_copy_rect
= nve4_m2mf_transfer_rect
;
506 nvc0
->base
.copy_data
= nve4_m2mf_copy_linear
;
507 nvc0
->base
.push_data
= nve4_p2mf_push_linear
;
509 nvc0
->m2mf_copy_rect
= nvc0_m2mf_transfer_rect
;
510 nvc0
->base
.copy_data
= nvc0_m2mf_copy_linear
;
511 nvc0
->base
.push_data
= nvc0_m2mf_push_linear
;
513 nvc0
->base
.push_cb
= nvc0_cb_push
;