• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "pipe/p_context.h"
2 #include "util/u_surface.h"
3 #include "util/u_inlines.h"
4 #include "util/u_transfer.h"
5 #include "util/u_memory.h"
6 
u_default_buffer_subdata(struct pipe_context * pipe,struct pipe_resource * resource,unsigned usage,unsigned offset,unsigned size,const void * data)7 void u_default_buffer_subdata(struct pipe_context *pipe,
8                               struct pipe_resource *resource,
9                               unsigned usage, unsigned offset,
10                               unsigned size, const void *data)
11 {
12    struct pipe_transfer *transfer = NULL;
13    struct pipe_box box;
14    uint8_t *map = NULL;
15 
16    assert(!(usage & PIPE_MAP_READ));
17 
18    /* the write flag is implicit by the nature of buffer_subdata */
19    usage |= PIPE_MAP_WRITE;
20 
21    /* buffer_subdata implicitly discards the rewritten buffer range.
22     * PIPE_MAP_DIRECTLY supresses that.
23     */
24    if (!(usage & PIPE_MAP_DIRECTLY)) {
25       if (offset == 0 && size == resource->width0) {
26          usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE;
27       } else {
28          usage |= PIPE_MAP_DISCARD_RANGE;
29       }
30    }
31 
32    u_box_1d(offset, size, &box);
33 
34    map = pipe->buffer_map(pipe, resource, 0, usage, &box, &transfer);
35    if (!map)
36       return;
37 
38    memcpy(map, data, size);
39    pipe_buffer_unmap(pipe, transfer);
40 }
41 
u_default_texture_subdata(struct pipe_context * pipe,struct pipe_resource * resource,unsigned level,unsigned usage,const struct pipe_box * box,const void * data,unsigned stride,unsigned layer_stride)42 void u_default_texture_subdata(struct pipe_context *pipe,
43                                struct pipe_resource *resource,
44                                unsigned level,
45                                unsigned usage,
46                                const struct pipe_box *box,
47                                const void *data,
48                                unsigned stride,
49                                unsigned layer_stride)
50 {
51    struct pipe_transfer *transfer = NULL;
52    const uint8_t *src_data = data;
53    uint8_t *map = NULL;
54 
55    assert(!(usage & PIPE_MAP_READ));
56 
57    /* the write flag is implicit by the nature of texture_subdata */
58    usage |= PIPE_MAP_WRITE;
59 
60    /* texture_subdata implicitly discards the rewritten buffer range */
61    usage |= PIPE_MAP_DISCARD_RANGE;
62 
63    map = pipe->texture_map(pipe,
64                             resource,
65                             level,
66                             usage,
67                             box, &transfer);
68    if (!map)
69       return;
70 
71    util_copy_box(map,
72                  resource->format,
73                  transfer->stride, /* bytes */
74                  transfer->layer_stride, /* bytes */
75                  0, 0, 0,
76                  box->width,
77                  box->height,
78                  box->depth,
79                  src_data,
80                  stride,       /* bytes */
81                  layer_stride, /* bytes */
82                  0, 0, 0);
83 
84    pipe_texture_unmap(pipe, transfer);
85 }
86 
u_default_transfer_flush_region(UNUSED struct pipe_context * pipe,UNUSED struct pipe_transfer * transfer,UNUSED const struct pipe_box * box)87 void u_default_transfer_flush_region(UNUSED struct pipe_context *pipe,
88                                      UNUSED struct pipe_transfer *transfer,
89                                      UNUSED const struct pipe_box *box)
90 {
91    /* This is a no-op implementation, nothing to do.
92     */
93 }
94