2 #include "pipe/p_context.h"
3 #include "pipe/p_inlines.h"
4 #include "util/u_math.h"
6 #include "nv50_context.h"
9 struct pipe_transfer base
;
10 struct nouveau_bo
*bo
;
11 unsigned level_offset
;
12 unsigned level_tiling
;
24 nv50_transfer_rect_m2mf(struct pipe_screen
*pscreen
,
25 struct nouveau_bo
*src_bo
, unsigned src_offset
,
26 int src_pitch
, unsigned src_tile_mode
,
27 int sx
, int sy
, int sw
, int sh
, int sd
,
28 struct nouveau_bo
*dst_bo
, unsigned dst_offset
,
29 int dst_pitch
, unsigned dst_tile_mode
,
30 int dx
, int dy
, int dw
, int dh
, int dd
,
31 int cpp
, int width
, int height
,
32 unsigned src_reloc
, unsigned dst_reloc
)
34 struct nv50_screen
*screen
= nv50_screen(pscreen
);
35 struct nouveau_channel
*chan
= screen
->m2mf
->channel
;
36 struct nouveau_grobj
*m2mf
= screen
->m2mf
;
38 src_reloc
|= NOUVEAU_BO_RD
;
39 dst_reloc
|= NOUVEAU_BO_WR
;
43 if (!src_bo
->tile_flags
) {
44 BEGIN_RING(chan
, m2mf
,
45 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN
, 1);
47 BEGIN_RING(chan
, m2mf
,
48 NV50_MEMORY_TO_MEMORY_FORMAT_PITCH_IN
, 1);
49 OUT_RING (chan
, src_pitch
);
50 src_offset
+= (sy
* src_pitch
) + (sx
* cpp
);
52 BEGIN_RING(chan
, m2mf
,
53 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN
, 6);
55 OUT_RING (chan
, src_tile_mode
<< 4);
56 OUT_RING (chan
, sw
* cpp
);
62 if (!dst_bo
->tile_flags
) {
63 BEGIN_RING(chan
, m2mf
,
64 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT
, 1);
66 BEGIN_RING(chan
, m2mf
,
67 NV50_MEMORY_TO_MEMORY_FORMAT_PITCH_OUT
, 1);
68 OUT_RING (chan
, dst_pitch
);
69 dst_offset
+= (dy
* dst_pitch
) + (dx
* cpp
);
71 BEGIN_RING(chan
, m2mf
,
72 NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT
, 6);
74 OUT_RING (chan
, dst_tile_mode
<< 4);
75 OUT_RING (chan
, dw
* cpp
);
82 int line_count
= height
> 2047 ? 2047 : height
;
85 BEGIN_RING(chan
, m2mf
,
86 NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH
, 2);
87 OUT_RELOCh(chan
, src_bo
, src_offset
, src_reloc
);
88 OUT_RELOCh(chan
, dst_bo
, dst_offset
, dst_reloc
);
89 BEGIN_RING(chan
, m2mf
,
90 NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN
, 2);
91 OUT_RELOCl(chan
, src_bo
, src_offset
, src_reloc
);
92 OUT_RELOCl(chan
, dst_bo
, dst_offset
, dst_reloc
);
93 if (src_bo
->tile_flags
) {
94 BEGIN_RING(chan
, m2mf
,
95 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN
, 1);
96 OUT_RING (chan
, (sy
<< 16) | (sx
* cpp
));
98 src_offset
+= (line_count
* src_pitch
);
100 if (dst_bo
->tile_flags
) {
101 BEGIN_RING(chan
, m2mf
,
102 NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT
, 1);
103 OUT_RING (chan
, (dy
<< 16) | (dx
* cpp
));
105 dst_offset
+= (line_count
* dst_pitch
);
107 BEGIN_RING(chan
, m2mf
,
108 NV50_MEMORY_TO_MEMORY_FORMAT_LINE_LENGTH_IN
, 4);
109 OUT_RING (chan
, width
* cpp
);
110 OUT_RING (chan
, line_count
);
111 OUT_RING (chan
, 0x00000101);
115 height
-= line_count
;
121 static INLINE
unsigned
122 get_zslice_offset(unsigned tile_mode
, unsigned z
, unsigned pitch
, unsigned ny
)
124 unsigned tile_h
= get_tile_height(tile_mode
);
125 unsigned tile_d
= get_tile_depth(tile_mode
);
127 /* pitch_2d == to next slice within this volume-tile */
128 /* pitch_3d == to next slice in next 2D array of blocks */
129 unsigned pitch_2d
= tile_h
* 64;
130 unsigned pitch_3d
= tile_d
* align(ny
, tile_h
) * pitch
;
132 return (z
% tile_d
) * pitch_2d
+ (z
/ tile_d
) * pitch_3d
;
135 static struct pipe_transfer
*
136 nv50_transfer_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
137 unsigned face
, unsigned level
, unsigned zslice
,
138 enum pipe_transfer_usage usage
,
139 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
141 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
142 struct nv50_miptree
*mt
= nv50_miptree(pt
);
143 struct nv50_miptree_level
*lvl
= &mt
->level
[level
];
144 struct nv50_transfer
*tx
;
145 unsigned nx
, ny
, image
= 0;
148 if (pt
->target
== PIPE_TEXTURE_CUBE
)
151 tx
= CALLOC_STRUCT(nv50_transfer
);
155 pipe_texture_reference(&tx
->base
.texture
, pt
);
156 tx
->nblocksx
= pf_get_nblocksx(pt
->format
, u_minify(pt
->width0
, level
));
157 tx
->nblocksy
= pf_get_nblocksy(pt
->format
, u_minify(pt
->height0
, level
));
160 tx
->base
.stride
= tx
->nblocksx
* pf_get_blocksize(pt
->format
);
161 tx
->base
.usage
= usage
;
163 tx
->level_pitch
= lvl
->pitch
;
164 tx
->level_width
= u_minify(mt
->base
.base
.width0
, level
);
165 tx
->level_height
= u_minify(mt
->base
.base
.height0
, level
);
166 tx
->level_depth
= u_minify(mt
->base
.base
.depth0
, level
);
167 tx
->level_offset
= lvl
->image_offset
[image
];
168 tx
->level_tiling
= lvl
->tile_mode
;
169 tx
->level_x
= pf_get_nblocksx(pt
->format
, x
);
170 tx
->level_y
= pf_get_nblocksy(pt
->format
, y
);
171 ret
= nouveau_bo_new(dev
, NOUVEAU_BO_GART
| NOUVEAU_BO_MAP
, 0,
172 tx
->nblocksy
* tx
->base
.stride
, &tx
->bo
);
178 if (pt
->target
== PIPE_TEXTURE_3D
)
179 tx
->level_offset
+= get_zslice_offset(lvl
->tile_mode
, zslice
,
183 if (usage
& PIPE_TRANSFER_READ
) {
184 nx
= pf_get_nblocksx(pt
->format
, tx
->base
.width
);
185 ny
= pf_get_nblocksy(pt
->format
, tx
->base
.height
);
187 nv50_transfer_rect_m2mf(pscreen
, mt
->base
.bo
, tx
->level_offset
,
188 tx
->level_pitch
, tx
->level_tiling
,
190 tx
->nblocksx
, tx
->nblocksy
,
193 tx
->base
.stride
, tx
->bo
->tile_mode
,
195 tx
->nblocksx
, tx
->nblocksy
, 1,
196 pf_get_blocksize(pt
->format
), nx
, ny
,
197 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
,
205 nv50_transfer_del(struct pipe_transfer
*ptx
)
207 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
208 struct nv50_miptree
*mt
= nv50_miptree(ptx
->texture
);
209 struct pipe_texture
*pt
= ptx
->texture
;
211 unsigned nx
= pf_get_nblocksx(pt
->format
, tx
->base
.width
);
212 unsigned ny
= pf_get_nblocksy(pt
->format
, tx
->base
.height
);
214 if (ptx
->usage
& PIPE_TRANSFER_WRITE
) {
215 struct pipe_screen
*pscreen
= pt
->screen
;
217 nv50_transfer_rect_m2mf(pscreen
, tx
->bo
, 0,
218 tx
->base
.stride
, tx
->bo
->tile_mode
,
220 tx
->nblocksx
, tx
->nblocksy
, 1,
221 mt
->base
.bo
, tx
->level_offset
,
222 tx
->level_pitch
, tx
->level_tiling
,
223 tx
->level_x
, tx
->level_y
,
224 tx
->nblocksx
, tx
->nblocksy
,
226 pf_get_blocksize(pt
->format
), nx
, ny
,
227 NOUVEAU_BO_GART
, NOUVEAU_BO_VRAM
|
231 nouveau_bo_ref(NULL
, &tx
->bo
);
232 pipe_texture_reference(&ptx
->texture
, NULL
);
237 nv50_transfer_map(struct pipe_screen
*pscreen
, struct pipe_transfer
*ptx
)
239 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
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
);
255 nv50_transfer_unmap(struct pipe_screen
*pscreen
, struct pipe_transfer
*ptx
)
257 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
259 nouveau_bo_unmap(tx
->bo
);
263 nv50_transfer_init_screen_functions(struct pipe_screen
*pscreen
)
265 pscreen
->get_tex_transfer
= nv50_transfer_new
;
266 pscreen
->tex_transfer_destroy
= nv50_transfer_del
;
267 pscreen
->transfer_map
= nv50_transfer_map
;
268 pscreen
->transfer_unmap
= nv50_transfer_unmap
;
272 nv50_upload_sifc(struct nv50_context
*nv50
,
273 struct nouveau_bo
*bo
, unsigned dst_offset
, unsigned reloc
,
274 unsigned dst_format
, int dst_w
, int dst_h
, int dst_pitch
,
275 void *src
, unsigned src_format
, int src_pitch
,
276 int x
, int y
, int w
, int h
, int cpp
)
278 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
279 struct nouveau_grobj
*eng2d
= nv50
->screen
->eng2d
;
280 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
281 unsigned line_dwords
= (w
* cpp
+ 3) / 4;
283 reloc
|= NOUVEAU_BO_WR
;
285 WAIT_RING (chan
, 32);
287 if (bo
->tile_flags
) {
288 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_FORMAT
, 5);
289 OUT_RING (chan
, dst_format
);
291 OUT_RING (chan
, bo
->tile_mode
<< 4);
295 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_FORMAT
, 2);
296 OUT_RING (chan
, dst_format
);
298 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_PITCH
, 1);
299 OUT_RING (chan
, dst_pitch
);
302 BEGIN_RING(chan
, eng2d
, NV50_2D_DST_WIDTH
, 4);
303 OUT_RING (chan
, dst_w
);
304 OUT_RING (chan
, dst_h
);
305 OUT_RELOCh(chan
, bo
, dst_offset
, reloc
);
306 OUT_RELOCl(chan
, bo
, dst_offset
, reloc
);
308 /* NV50_2D_OPERATION_SRCCOPY assumed already set */
310 BEGIN_RING(chan
, eng2d
, NV50_2D_SIFC_UNK0800
, 2);
312 OUT_RING (chan
, src_format
);
313 BEGIN_RING(chan
, eng2d
, NV50_2D_SIFC_WIDTH
, 10);
326 const uint32_t *p
= src
;
327 unsigned count
= line_dwords
;
330 unsigned nr
= MIN2(count
, 1792);
332 if (chan
->pushbuf
->remaining
<= nr
) {
335 BEGIN_RING(chan
, eng2d
,
336 NV50_2D_DST_ADDRESS_HIGH
, 2);
337 OUT_RELOCh(chan
, bo
, dst_offset
, reloc
);
338 OUT_RELOCl(chan
, bo
, dst_offset
, reloc
);
340 assert(chan
->pushbuf
->remaining
> nr
);
342 BEGIN_RING(chan
, eng2d
,
343 NV50_2D_SIFC_DATA
| (2 << 29), nr
);
344 OUT_RINGp (chan
, p
, nr
);
353 BEGIN_RING(chan
, tesla
, 0x1440, 1);