1 #include "util/u_staging.h"
2 #include "pipe/p_context.h"
3 #include "util/u_memory.h"
4 #include "util/u_inlines.h"
7 util_staging_resource_template(struct pipe_resource
*pt
, unsigned width
, unsigned height
, unsigned depth
, struct pipe_resource
*template)
9 memset(template, 0, sizeof(struct pipe_resource
));
10 if(pt
->target
!= PIPE_BUFFER
&& depth
<= 1)
11 template->target
= PIPE_TEXTURE_RECT
;
13 template->target
= pt
->target
;
14 template->format
= pt
->format
;
15 template->width0
= width
;
16 template->height0
= height
;
17 template->depth0
= depth
;
18 template->last_level
= 0;
19 template->nr_samples
= pt
->nr_samples
;
21 template->usage
= PIPE_USAGE_STAGING
;
25 struct util_staging_transfer
*
26 util_staging_transfer_init(struct pipe_context
*pipe
,
27 struct pipe_resource
*pt
,
28 struct pipe_subresource sr
,
30 const struct pipe_box
*box
,
31 bool direct
, struct util_staging_transfer
*tx
)
33 struct pipe_screen
*pscreen
= pipe
->screen
;
35 struct pipe_resource staging_resource_template
;
37 pipe_resource_reference(&tx
->base
.resource
, pt
);
39 tx
->base
.usage
= usage
;
44 tx
->staging_resource
= pt
;
48 util_staging_resource_template(pt
, box
->width
, box
->height
, box
->depth
, &staging_resource_template
);
49 tx
->staging_resource
= pscreen
->resource_create(pscreen
, &staging_resource_template
);
50 if (!tx
->staging_resource
)
52 pipe_resource_reference(&tx
->base
.resource
, NULL
);
57 if (usage
& PIPE_TRANSFER_READ
)
59 struct pipe_subresource dstsr
;
63 for(zi
= 0; zi
< box
->depth
; ++zi
)
64 pipe
->resource_copy_region(pipe
, tx
->staging_resource
, dstsr
, 0, 0, 0, tx
->base
.resource
, sr
, box
->x
, box
->y
, box
->z
+ zi
, box
->width
, box
->height
);
71 util_staging_transfer_destroy(struct pipe_context
*pipe
, struct pipe_transfer
*ptx
)
73 struct util_staging_transfer
*tx
= (struct util_staging_transfer
*)ptx
;
75 if (tx
->staging_resource
!= tx
->base
.resource
)
77 if(tx
->base
.usage
& PIPE_TRANSFER_WRITE
) {
78 struct pipe_subresource srcsr
;
82 for(zi
= 0; zi
< tx
->base
.box
.depth
; ++zi
)
83 pipe
->resource_copy_region(pipe
, tx
->base
.resource
, tx
->base
.sr
, tx
->base
.box
.x
, tx
->base
.box
.y
, tx
->base
.box
.z
+ zi
, tx
->staging_resource
, srcsr
, 0, 0, 0, tx
->base
.box
.width
, tx
->base
.box
.height
);
86 pipe_resource_reference(&tx
->staging_resource
, NULL
);
89 pipe_resource_reference(&ptx
->resource
, NULL
);