2 #include "pipe/p_context.h"
3 #include "pipe/p_inlines.h"
5 #include "nv50_context.h"
8 struct pipe_transfer base
;
9 struct pipe_buffer
*buffer
;
10 unsigned level_offset
;
19 nv50_transfer_rect_m2mf(struct pipe_screen
*pscreen
, struct pipe_buffer
*src
,
20 unsigned src_offset
, int src_pitch
, int sx
, int sy
,
21 int sw
, int sh
, struct pipe_buffer
*dst
,
22 unsigned dst_offset
, int dst_pitch
, int dx
, int dy
,
23 int dw
, int dh
, int cpp
, int width
, int height
,
24 unsigned src_reloc
, unsigned dst_reloc
)
26 struct nv50_screen
*screen
= nv50_screen(pscreen
);
27 struct nouveau_winsys
*nvws
= screen
->nvws
;
28 struct nouveau_channel
*chan
= nvws
->channel
;
29 struct nouveau_grobj
*m2mf
= screen
->m2mf
;
30 struct nouveau_bo
*src_bo
= nouveau_bo(src
);
31 struct nouveau_bo
*dst_bo
= nouveau_bo(dst
);
33 src_reloc
|= NOUVEAU_BO_RD
;
34 dst_reloc
|= NOUVEAU_BO_WR
;
39 BEGIN_RING(chan
, m2mf
, 0x0200, 1);
41 BEGIN_RING(chan
, m2mf
, 0x0314, 1);
42 OUT_RING (chan
, src_pitch
);
43 src_offset
+= (sy
* src_pitch
) + (sx
* cpp
);
45 BEGIN_RING(chan
, m2mf
, 0x0200, 6);
48 OUT_RING (chan
, sw
* cpp
);
55 BEGIN_RING(chan
, m2mf
, 0x021c, 1);
57 BEGIN_RING(chan
, m2mf
, 0x0318, 1);
58 OUT_RING (chan
, dst_pitch
);
59 dst_offset
+= (dy
* dst_pitch
) + (dx
* cpp
);
61 BEGIN_RING(chan
, m2mf
, 0x021c, 6);
64 OUT_RING (chan
, dw
* cpp
);
71 int line_count
= height
> 2047 ? 2047 : height
;
74 BEGIN_RING(chan
, m2mf
, 0x0238, 2);
75 OUT_RELOCh(chan
, src_bo
, src_offset
, src_reloc
);
76 OUT_RELOCh(chan
, dst_bo
, dst_offset
, dst_reloc
);
77 BEGIN_RING(chan
, m2mf
, 0x030c, 2);
78 OUT_RELOCl(chan
, src_bo
, src_offset
, src_reloc
);
79 OUT_RELOCl(chan
, dst_bo
, dst_offset
, dst_reloc
);
81 BEGIN_RING(chan
, m2mf
, 0x0218, 1);
82 OUT_RING (chan
, (dy
<< 16) | sx
);
84 src_offset
+= (line_count
* src_pitch
);
87 BEGIN_RING(chan
, m2mf
, 0x0234, 1);
88 OUT_RING (chan
, (sy
<< 16) | dx
);
90 dst_offset
+= (line_count
* dst_pitch
);
92 BEGIN_RING(chan
, m2mf
, 0x031c, 4);
93 OUT_RING (chan
, width
* cpp
);
94 OUT_RING (chan
, line_count
);
95 OUT_RING (chan
, 0x00000101);
105 static struct pipe_transfer
*
106 nv50_transfer_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
107 unsigned face
, unsigned level
, unsigned zslice
,
108 enum pipe_transfer_usage usage
,
109 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
111 struct nv50_miptree
*mt
= nv50_miptree(pt
);
112 struct nv50_miptree_level
*lvl
= &mt
->level
[level
];
113 struct nv50_transfer
*tx
;
116 if (pt
->target
== PIPE_TEXTURE_CUBE
)
119 if (pt
->target
== PIPE_TEXTURE_3D
)
122 tx
= CALLOC_STRUCT(nv50_transfer
);
126 pipe_texture_reference(&tx
->base
.texture
, pt
);
127 tx
->base
.format
= pt
->format
;
130 tx
->base
.block
= pt
->block
;
131 tx
->base
.nblocksx
= pt
->nblocksx
[level
];
132 tx
->base
.nblocksy
= pt
->nblocksy
[level
];
133 tx
->base
.stride
= (w
* pt
->block
.size
);
134 tx
->base
.usage
= usage
;
136 tx
->level_pitch
= lvl
->pitch
;
137 tx
->level_width
= mt
->base
.width
[level
];
138 tx
->level_height
= mt
->base
.height
[level
];
139 tx
->level_offset
= lvl
->image_offset
[image
];
143 pipe_buffer_create(pscreen
, 0, NOUVEAU_BUFFER_USAGE_TRANSFER
,
144 w
* tx
->base
.block
.size
* h
);
146 if (usage
!= PIPE_TRANSFER_WRITE
) {
147 nv50_transfer_rect_m2mf(pscreen
, mt
->buffer
, tx
->level_offset
,
148 tx
->level_pitch
, x
, y
, tx
->level_width
,
149 tx
->level_height
, tx
->buffer
, 0,
150 tx
->base
.stride
, 0, 0,
151 tx
->base
.width
, tx
->base
.height
,
152 tx
->base
.block
.size
, w
, h
,
153 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
,
161 nv50_transfer_del(struct pipe_transfer
*ptx
)
163 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
164 struct nv50_miptree
*mt
= nv50_miptree(ptx
->texture
);
166 if (ptx
->usage
!= PIPE_TRANSFER_READ
) {
167 struct pipe_screen
*pscreen
= ptx
->texture
->screen
;
168 nv50_transfer_rect_m2mf(pscreen
, tx
->buffer
, 0, tx
->base
.stride
,
169 0, 0, tx
->base
.width
, tx
->base
.height
,
170 mt
->buffer
, tx
->level_offset
,
171 tx
->level_pitch
, tx
->level_x
,
172 tx
->level_y
, tx
->level_width
,
173 tx
->level_height
, tx
->base
.block
.size
,
174 tx
->base
.width
, tx
->base
.height
,
175 NOUVEAU_BO_GART
, NOUVEAU_BO_VRAM
|
179 pipe_buffer_reference(&tx
->buffer
, NULL
);
180 pipe_texture_reference(&ptx
->texture
, NULL
);
185 nv50_transfer_map(struct pipe_screen
*pscreen
, struct pipe_transfer
*ptx
)
187 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
190 if (ptx
->usage
& PIPE_TRANSFER_WRITE
)
191 flags
|= PIPE_BUFFER_USAGE_CPU_WRITE
;
192 if (ptx
->usage
& PIPE_TRANSFER_READ
)
193 flags
|= PIPE_BUFFER_USAGE_CPU_READ
;
195 return pipe_buffer_map(pscreen
, tx
->buffer
, flags
);
199 nv50_transfer_unmap(struct pipe_screen
*pscreen
, struct pipe_transfer
*ptx
)
201 struct nv50_transfer
*tx
= (struct nv50_transfer
*)ptx
;
203 pipe_buffer_unmap(pscreen
, tx
->buffer
);
207 nv50_transfer_init_screen_functions(struct pipe_screen
*pscreen
)
209 pscreen
->get_tex_transfer
= nv50_transfer_new
;
210 pscreen
->tex_transfer_destroy
= nv50_transfer_del
;
211 pscreen
->transfer_map
= nv50_transfer_map
;
212 pscreen
->transfer_unmap
= nv50_transfer_unmap
;