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"
10 struct pipe_transfer base
;
11 struct nouveau_bo
*bo
;
12 unsigned level_offset
;
13 unsigned level_tiling
;
26 nv50_transfer_rect_m2mf(struct pipe_screen
*pscreen
,
27 struct nouveau_bo
*src_bo
, unsigned src_offset
,
28 int src_pitch
, unsigned src_tile_mode
,
29 int sx
, int sy
, int sz
, int sw
, int sh
, int sd
,
30 struct nouveau_bo
*dst_bo
, unsigned dst_offset
,
31 int dst_pitch
, unsigned dst_tile_mode
,
32 int dx
, int dy
, int dz
, int dw
, int dh
, int dd
,
33 int cpp
, int width
, int height
,
34 unsigned src_reloc
, unsigned dst_reloc
)
36 struct nv50_screen
*screen
= nv50_screen(pscreen
);
37 struct nouveau_channel
*chan
= screen
->m2mf
->channel
;
38 struct nouveau_grobj
*m2mf
= screen
->m2mf
;
40 src_reloc
|= NOUVEAU_BO_RD
;
41 dst_reloc
|= NOUVEAU_BO_WR
;
45 if (!src_bo
->tile_flags
) {
46 BEGIN_RING(chan
, m2mf
,
47 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN
, 1);
49 BEGIN_RING(chan
, m2mf
,
50 NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_IN
, 1);
51 OUT_RING (chan
, src_pitch
);
52 src_offset
+= (sy
* src_pitch
) + (sx
* cpp
);
54 BEGIN_RING(chan
, m2mf
,
55 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN
, 6);
57 OUT_RING (chan
, src_tile_mode
<< 4);
58 OUT_RING (chan
, sw
* cpp
);
61 OUT_RING (chan
, sz
); /* copying only 1 zslice per call */
64 if (!dst_bo
->tile_flags
) {
65 BEGIN_RING(chan
, m2mf
,
66 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT
, 1);
68 BEGIN_RING(chan
, m2mf
,
69 NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_OUT
, 1);
70 OUT_RING (chan
, dst_pitch
);
71 dst_offset
+= (dy
* dst_pitch
) + (dx
* cpp
);
73 BEGIN_RING(chan
, m2mf
,
74 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT
, 6);
76 OUT_RING (chan
, dst_tile_mode
<< 4);
77 OUT_RING (chan
, dw
* cpp
);
80 OUT_RING (chan
, dz
); /* copying only 1 zslice per call */
84 int line_count
= height
> 2047 ? 2047 : height
;
86 MARK_RING (chan
, 15, 4); /* flush on lack of space or relocs */
87 BEGIN_RING(chan
, m2mf
,
88 NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH
, 2);
89 OUT_RELOCh(chan
, src_bo
, src_offset
, src_reloc
);
90 OUT_RELOCh(chan
, dst_bo
, dst_offset
, dst_reloc
);
91 BEGIN_RING(chan
, m2mf
,
92 NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN
, 2);
93 OUT_RELOCl(chan
, src_bo
, src_offset
, src_reloc
);
94 OUT_RELOCl(chan
, dst_bo
, dst_offset
, dst_reloc
);
95 if (src_bo
->tile_flags
) {
96 BEGIN_RING(chan
, m2mf
,
97 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN
, 1);
98 OUT_RING (chan
, (sy
<< 16) | (sx
* cpp
));
100 src_offset
+= (line_count
* src_pitch
);
102 if (dst_bo
->tile_flags
) {
103 BEGIN_RING(chan
, m2mf
,
104 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT
, 1);
105 OUT_RING (chan
, (dy
<< 16) | (dx
* cpp
));
107 dst_offset
+= (line_count
* dst_pitch
);
109 BEGIN_RING(chan
, m2mf
,
110 NV04_MEMORY_TO_MEMORY_FORMAT_LINE_LENGTH_IN
, 4);
111 OUT_RING (chan
, width
* cpp
);
112 OUT_RING (chan
, line_count
);
113 OUT_RING (chan
, 0x00000101);
117 height
-= line_count
;
123 static struct pipe_transfer
*
124 nv50_transfer_new(struct pipe_context
*pcontext
, struct pipe_texture
*pt
,
125 unsigned face
, unsigned level
, unsigned zslice
,
126 enum pipe_transfer_usage usage
,
127 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
129 struct pipe_screen
*pscreen
= pcontext
->screen
;
130 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
131 struct nv50_miptree
*mt
= nv50_miptree(pt
);
132 struct nv50_miptree_level
*lvl
= &mt
->level
[level
];
133 struct nv50_transfer
*tx
;
134 unsigned nx
, ny
, image
= 0;
137 if (pt
->target
== PIPE_TEXTURE_CUBE
)
140 tx
= CALLOC_STRUCT(nv50_transfer
);
144 pipe_texture_reference(&tx
->base
.texture
, pt
);
145 tx
->nblocksx
= util_format_get_nblocksx(pt
->format
, u_minify(pt
->width0
, level
));
146 tx
->nblocksy
= util_format_get_nblocksy(pt
->format
, u_minify(pt
->height0
, level
));
149 tx
->base
.stride
= tx
->nblocksx
* util_format_get_blocksize(pt
->format
);
150 tx
->base
.usage
= usage
;
152 tx
->level_pitch
= lvl
->pitch
;
153 tx
->level_width
= u_minify(mt
->base
.base
.width0
, level
);
154 tx
->level_height
= u_minify(mt
->base
.base
.height0
, level
);
155 tx
->level_depth
= u_minify(mt
->base
.base
.depth0
, level
);
156 tx
->level_offset
= lvl
->image_offset
[image
];
157 tx
->level_tiling
= lvl
->tile_mode
;
158 tx
->level_z
= zslice
;
159 tx
->level_x
= util_format_get_nblocksx(pt
->format
, x
);
160 tx
->level_y
= util_format_get_nblocksy(pt
->format
, y
);
161 ret
= nouveau_bo_new(dev
, NOUVEAU_BO_GART
| NOUVEAU_BO_MAP
, 0,
162 tx
->nblocksy
* tx
->base
.stride
, &tx
->bo
);
168 if (usage
& PIPE_TRANSFER_READ
) {
169 nx
= util_format_get_nblocksx(pt
->format
, tx
->base
.width
);
170 ny
= util_format_get_nblocksy(pt
->format
, tx
->base
.height
);
172 nv50_transfer_rect_m2mf(pscreen
, mt
->base
.bo
, tx
->level_offset
,
173 tx
->level_pitch
, tx
->level_tiling
,
175 tx
->nblocksx
, tx
->nblocksy
,
178 tx
->base
.stride
, tx
->bo
->tile_mode
,
180 tx
->nblocksx
, tx
->nblocksy
, 1,
181 util_format_get_blocksize(pt
->format
), nx
, ny
,
182 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
,
190 nv50_transfer_del(struct pipe_context
*pcontext
, struct pipe_transfer
*ptx
)
192 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
193 struct nv50_miptree
*mt
= nv50_miptree(ptx
->texture
);
194 struct pipe_texture
*pt
= ptx
->texture
;
196 unsigned nx
= util_format_get_nblocksx(pt
->format
, tx
->base
.width
);
197 unsigned ny
= util_format_get_nblocksy(pt
->format
, tx
->base
.height
);
199 if (ptx
->usage
& PIPE_TRANSFER_WRITE
) {
200 struct pipe_screen
*pscreen
= pcontext
->screen
;
202 nv50_transfer_rect_m2mf(pscreen
, tx
->bo
, 0,
203 tx
->base
.stride
, tx
->bo
->tile_mode
,
205 tx
->nblocksx
, tx
->nblocksy
, 1,
206 mt
->base
.bo
, tx
->level_offset
,
207 tx
->level_pitch
, tx
->level_tiling
,
208 tx
->level_x
, tx
->level_y
, tx
->level_z
,
209 tx
->nblocksx
, tx
->nblocksy
,
211 util_format_get_blocksize(pt
->format
), nx
, ny
,
212 NOUVEAU_BO_GART
, NOUVEAU_BO_VRAM
|
216 nouveau_bo_ref(NULL
, &tx
->bo
);
217 pipe_texture_reference(&ptx
->texture
, NULL
);
222 nv50_transfer_map(struct pipe_context
*pcontext
, struct pipe_transfer
*ptx
)
224 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
228 if (ptx
->usage
& PIPE_TRANSFER_WRITE
)
229 flags
|= NOUVEAU_BO_WR
;
230 if (ptx
->usage
& PIPE_TRANSFER_READ
)
231 flags
|= NOUVEAU_BO_RD
;
233 ret
= nouveau_bo_map(tx
->bo
, flags
);
240 nv50_transfer_unmap(struct pipe_context
*pcontext
, struct pipe_transfer
*ptx
)
242 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
244 nouveau_bo_unmap(tx
->bo
);
248 nv50_init_transfer_functions(struct nv50_context
*nv50
)
250 nv50
->pipe
.get_tex_transfer
= nv50_transfer_new
;
251 nv50
->pipe
.tex_transfer_destroy
= nv50_transfer_del
;
252 nv50
->pipe
.transfer_map
= nv50_transfer_map
;
253 nv50
->pipe
.transfer_unmap
= nv50_transfer_unmap
;
257 nv50_upload_sifc(struct nv50_context
*nv50
,
258 struct nouveau_bo
*bo
, unsigned dst_offset
, unsigned reloc
,
259 unsigned dst_format
, int dst_w
, int dst_h
, int dst_pitch
,
260 void *src
, unsigned src_format
, int src_pitch
,
261 int x
, int y
, int w
, int h
, int cpp
)
263 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
264 struct nouveau_grobj
*eng2d
= nv50
->screen
->eng2d
;
265 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
266 unsigned line_dwords
= (w
* cpp
+ 3) / 4;
268 reloc
|= NOUVEAU_BO_WR
;
270 MARK_RING (chan
, 32, 2); /* flush on lack of space or relocs */
272 if (bo
->tile_flags
) {
273 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_FORMAT
, 5);
274 OUT_RING (chan
, dst_format
);
276 OUT_RING (chan
, bo
->tile_mode
<< 4);
280 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_FORMAT
, 2);
281 OUT_RING (chan
, dst_format
);
283 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_PITCH
, 1);
284 OUT_RING (chan
, dst_pitch
);
287 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_WIDTH
, 4);
288 OUT_RING (chan
, dst_w
);
289 OUT_RING (chan
, dst_h
);
290 OUT_RELOCh(chan
, bo
, dst_offset
, reloc
);
291 OUT_RELOCl(chan
, bo
, dst_offset
, reloc
);
293 /* NV50_2D_OPERATION_SRCCOPY assumed already set */
295 BEGIN_RING(chan
, eng2d
, NV50_2D_SIFC_BITMAP_ENABLE
, 2);
297 OUT_RING (chan
, src_format
);
298 BEGIN_RING(chan
, eng2d
, NV50_2D_SIFC_WIDTH
, 10);
311 const uint32_t *p
= src
;
312 unsigned count
= line_dwords
;
315 unsigned nr
= MIN2(count
, 1792);
317 if (AVAIL_RING(chan
) <= nr
) {
320 BEGIN_RING(chan
, eng2d
,
321 NV50_2D_DST_ADDRESS_HIGH
, 2);
322 OUT_RELOCh(chan
, bo
, dst_offset
, reloc
);
323 OUT_RELOCl(chan
, bo
, dst_offset
, reloc
);
325 assert(AVAIL_RING(chan
) > nr
);
327 BEGIN_RING(chan
, eng2d
,
328 NV50_2D_SIFC_DATA
| (2 << 29), nr
);
329 OUT_RINGp (chan
, p
, nr
);
338 BEGIN_RING(chan
, tesla
, NV50TCL_CODE_CB_FLUSH
, 1);