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"
12 struct nvfx_transfer
{
13 struct pipe_transfer base
;
14 struct pipe_surface
*surface
;
19 nvfx_compatible_transfer_tex(struct pipe_texture
*pt
, unsigned width
, unsigned height
,
20 struct pipe_texture
*template)
22 memset(template, 0, sizeof(struct pipe_texture
));
23 template->target
= pt
->target
;
24 template->format
= pt
->format
;
25 template->width0
= width
;
26 template->height0
= height
;
28 template->last_level
= 0;
29 template->nr_samples
= pt
->nr_samples
;
31 template->tex_usage
= PIPE_TEXTURE_USAGE_DYNAMIC
|
32 NOUVEAU_TEXTURE_USAGE_LINEAR
;
35 static struct pipe_transfer
*
36 nvfx_transfer_new(struct pipe_context
*pcontext
, struct pipe_texture
*pt
,
37 unsigned face
, unsigned level
, unsigned zslice
,
38 enum pipe_transfer_usage usage
,
39 unsigned x
, unsigned y
, unsigned w
, unsigned h
)
41 struct pipe_screen
*pscreen
= pcontext
->screen
;
42 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)pt
;
43 struct nvfx_transfer
*tx
;
44 struct pipe_texture tx_tex_template
, *tx_tex
;
46 tx
= CALLOC_STRUCT(nvfx_transfer
);
50 pipe_texture_reference(&tx
->base
.texture
, pt
);
55 tx
->base
.stride
= mt
->level
[level
].pitch
;
56 tx
->base
.usage
= usage
;
58 tx
->base
.level
= level
;
59 tx
->base
.zslice
= zslice
;
61 /* Direct access to texture */
62 if ((pt
->tex_usage
& PIPE_TEXTURE_USAGE_DYNAMIC
||
63 debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE
/*XXX:FALSE*/)) &&
64 pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
)
67 tx
->surface
= pscreen
->get_tex_surface(pscreen
, pt
,
69 pipe_transfer_buffer_flags(&tx
->base
));
75 nvfx_compatible_transfer_tex(pt
, w
, h
, &tx_tex_template
);
77 tx_tex
= pscreen
->texture_create(pscreen
, &tx_tex_template
);
84 tx
->base
.stride
= ((struct nvfx_miptree
*)tx_tex
)->level
[0].pitch
;
86 tx
->surface
= pscreen
->get_tex_surface(pscreen
, tx_tex
,
88 pipe_transfer_buffer_flags(&tx
->base
));
90 pipe_texture_reference(&tx_tex
, NULL
);
94 pipe_surface_reference(&tx
->surface
, NULL
);
99 if (usage
& PIPE_TRANSFER_READ
) {
100 struct nvfx_screen
*nvscreen
= nvfx_screen(pscreen
);
101 struct pipe_surface
*src
;
103 src
= pscreen
->get_tex_surface(pscreen
, pt
,
105 PIPE_BUFFER_USAGE_GPU_READ
);
107 /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
108 /* TODO: Check if SIFM can un-swizzle */
109 nvscreen
->eng2d
->copy(nvscreen
->eng2d
,
114 pipe_surface_reference(&src
, NULL
);
121 nvfx_transfer_del(struct pipe_context
*pcontext
,
122 struct pipe_transfer
*ptx
)
124 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
126 if (!tx
->direct
&& (ptx
->usage
& PIPE_TRANSFER_WRITE
)) {
127 struct pipe_screen
*pscreen
= pcontext
->screen
;
128 struct nvfx_screen
*nvscreen
= nvfx_screen(pscreen
);
129 struct pipe_surface
*dst
;
131 dst
= pscreen
->get_tex_surface(pscreen
, ptx
->texture
,
132 ptx
->face
, ptx
->level
, ptx
->zslice
,
133 PIPE_BUFFER_USAGE_GPU_WRITE
| NOUVEAU_BUFFER_USAGE_NO_RENDER
);
135 /* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
136 nvscreen
->eng2d
->copy(nvscreen
->eng2d
,
137 dst
, tx
->base
.x
, tx
->base
.y
,
139 tx
->base
.width
, tx
->base
.height
);
141 pipe_surface_reference(&dst
, NULL
);
144 pipe_surface_reference(&tx
->surface
, NULL
);
145 pipe_texture_reference(&ptx
->texture
, NULL
);
150 nvfx_transfer_map(struct pipe_context
*pcontext
, struct pipe_transfer
*ptx
)
152 struct pipe_screen
*pscreen
= pcontext
->screen
;
153 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
154 struct nv04_surface
*ns
= (struct nv04_surface
*)tx
->surface
;
155 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)tx
->surface
->texture
;
156 void *map
= pipe_buffer_map(pscreen
, mt
->buffer
,
157 pipe_transfer_buffer_flags(ptx
));
160 return map
+ ns
->base
.offset
;
162 return map
+ ns
->base
.offset
+ ptx
->y
* ns
->pitch
+ ptx
->x
* util_format_get_blocksize(ptx
->texture
->format
);
166 nvfx_transfer_unmap(struct pipe_context
*pcontext
, struct pipe_transfer
*ptx
)
168 struct pipe_screen
*pscreen
= pcontext
->screen
;
169 struct nvfx_transfer
*tx
= (struct nvfx_transfer
*)ptx
;
170 struct nvfx_miptree
*mt
= (struct nvfx_miptree
*)tx
->surface
->texture
;
172 pipe_buffer_unmap(pscreen
, mt
->buffer
);
176 nvfx_init_transfer_functions(struct nvfx_context
*nvfx
)
178 nvfx
->pipe
.get_tex_transfer
= nvfx_transfer_new
;
179 nvfx
->pipe
.tex_transfer_destroy
= nvfx_transfer_del
;
180 nvfx
->pipe
.transfer_map
= nvfx_transfer_map
;
181 nvfx
->pipe
.transfer_unmap
= nvfx_transfer_unmap
;