1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "util/u_inlines.h"
4 #include "util/u_format.h"
5 #include "util/u_memory.h"
6 #include "util/u_math.h"
7 #include "nouveau/nouveau_winsys.h"
8 #include "nvfx_context.h"
9 #include "nvfx_screen.h"
10 #include "nvfx_state.h"
11 #include "nvfx_resource.h"
12 #include "nvfx_transfer.h"
14 struct nvfx_transfer
{
15 struct pipe_transfer base
;
16 struct pipe_surface
*surface
;
21 nvfx_compatible_transfer_tex(struct pipe_resource
*pt
, unsigned width
, unsigned height
,
23 struct pipe_resource
*template)
25 memset(template, 0, sizeof(struct pipe_resource
));
26 template->target
= pt
->target
;
27 template->format
= pt
->format
;
28 template->width0
= width
;
29 template->height0
= height
;
31 template->last_level
= 0;
32 template->nr_samples
= pt
->nr_samples
;
33 template->bind
= bind
;
34 template->usage
= PIPE_USAGE_DYNAMIC
;
35 template->flags
= NVFX_RESOURCE_FLAG_LINEAR
;
39 static unsigned nvfx_transfer_bind_flags( unsigned transfer_usage
)
43 if (transfer_usage
& PIPE_TRANSFER_WRITE
)
44 bind
|= PIPE_BIND_BLIT_SOURCE
;
46 if (transfer_usage
& PIPE_TRANSFER_READ
)
47 bind
|= PIPE_BIND_BLIT_DESTINATION
;
52 struct pipe_transfer
*
53 nvfx_miptree_transfer_new(struct pipe_context
*pipe
,
54 struct pipe_resource
*pt
,
55 struct pipe_subresource sr
,
57 const struct pipe_box
*box
)
59 struct pipe_screen
*pscreen
= pipe
->screen
;
60 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)pt
;
61 struct nvfx_transfer
*tx
;
62 struct pipe_resource tx_tex_template
, *tx_tex
;
63 static int no_transfer
= -1;
64 unsigned bind
= nvfx_transfer_bind_flags(usage
);
66 no_transfer
= debug_get_bool_option("NOUVEAU_NO_TRANSFER", FALSE
);
69 tx
= CALLOC_STRUCT(nvfx_transfer
);
73 /* Don't handle 3D transfers yet.
75 assert(box
->depth
== 1);
77 pipe_resource_reference(&tx
->base
.resource
, pt
);
79 tx
->base
.usage
= usage
;
81 tx
->base
.stride
= mt
->level
[sr
.level
].pitch
;
83 /* Direct access to texture */
84 if ((pt
->usage
== PIPE_USAGE_DYNAMIC
||
86 pt
->flags
& NVFX_RESOURCE_FLAG_LINEAR
)
90 /* XXX: just call the internal nvfx function.
92 tx
->surface
= pscreen
->get_tex_surface(pscreen
, pt
,
101 nvfx_compatible_transfer_tex(pt
, box
->width
, box
->height
, bind
, &tx_tex_template
);
103 tx_tex
= pscreen
->resource_create(pscreen
, &tx_tex_template
);
110 tx
->base
.stride
= ((struct nvfx_miptree
*)tx_tex
)->level
[0].pitch
;
112 tx
->surface
= pscreen
->get_tex_surface(pscreen
, tx_tex
,
116 pipe_resource_reference(&tx_tex
, NULL
);
120 pipe_surface_reference(&tx
->surface
, NULL
);
125 if (usage
& PIPE_TRANSFER_READ
) {
126 struct nvfx_screen
*nvscreen
= nvfx_screen(pscreen
);
127 struct pipe_surface
*src
;
129 src
= pscreen
->get_tex_surface(pscreen
, pt
,
130 sr
.face
, sr
.level
, box
->z
,
131 PIPE_BIND_BLIT_SOURCE
);
133 /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
134 /* TODO: Check if SIFM can un-swizzle */
135 nvscreen
->eng2d
->copy(nvscreen
->eng2d
,
139 box
->width
, box
->height
);
141 pipe_surface_reference(&src
, NULL
);
148 nvfx_miptree_transfer_del(struct pipe_context
*pipe
,
149 struct pipe_transfer
*ptx
)
151 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
153 if (!tx
->direct
&& (ptx
->usage
& PIPE_TRANSFER_WRITE
)) {
154 struct pipe_screen
*pscreen
= pipe
->screen
;
155 struct nvfx_screen
*nvscreen
= nvfx_screen(pscreen
);
156 struct pipe_surface
*dst
;
158 dst
= pscreen
->get_tex_surface(pscreen
,
163 PIPE_BIND_BLIT_DESTINATION
);
165 /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
166 nvscreen
->eng2d
->copy(nvscreen
->eng2d
,
167 dst
, ptx
->box
.x
, ptx
->box
.y
,
169 ptx
->box
.width
, ptx
->box
.height
);
171 pipe_surface_reference(&dst
, NULL
);
174 pipe_surface_reference(&tx
->surface
, NULL
);
175 pipe_resource_reference(&ptx
->resource
, NULL
);
180 nvfx_miptree_transfer_map(struct pipe_context
*pipe
, struct pipe_transfer
*ptx
)
182 struct pipe_screen
*pscreen
= pipe
->screen
;
183 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
184 struct nv04_surface
*ns
= (struct nv04_surface
*)tx
->surface
;
185 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)tx
->surface
->texture
;
186 uint8_t *map
= nouveau_screen_bo_map(pscreen
, mt
->base
.bo
,
187 nouveau_screen_transfer_flags(ptx
->usage
));
190 return map
+ ns
->base
.offset
;
192 return (map
+ ns
->base
.offset
+
193 ptx
->box
.y
* ns
->pitch
+
194 ptx
->box
.x
* util_format_get_blocksize(ptx
->resource
->format
));
198 nvfx_miptree_transfer_unmap(struct pipe_context
*pipe
, struct pipe_transfer
*ptx
)
200 struct pipe_screen
*pscreen
= pipe
->screen
;
201 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
202 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)tx
->surface
->texture
;
204 nouveau_screen_bo_unmap(pscreen
, mt
->base
.bo
);