"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/auxiliary/util/u_transfer.c" (16 Sep 2020, 5090 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "u_transfer.c" see the Fossies "Dox" file reference documentation.

    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 
    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_TRANSFER_READ));
   17 
   18    /* the write flag is implicit by the nature of buffer_subdata */
   19    usage |= PIPE_TRANSFER_WRITE;
   20 
   21    /* buffer_subdata implicitly discards the rewritten buffer range.
   22     * PIPE_TRANSFER_MAP_DIRECTLY supresses that.
   23     */
   24    if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
   25       if (offset == 0 && size == resource->width0) {
   26          usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
   27       } else {
   28          usage |= PIPE_TRANSFER_DISCARD_RANGE;
   29       }
   30    }
   31 
   32    u_box_1d(offset, size, &box);
   33 
   34    map = pipe->transfer_map(pipe, resource, 0, usage, &box, &transfer);
   35    if (!map)
   36       return;
   37 
   38    memcpy(map, data, size);
   39    pipe_transfer_unmap(pipe, transfer);
   40 }
   41 
   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_TRANSFER_READ));
   56 
   57    /* the write flag is implicit by the nature of texture_subdata */
   58    usage |= PIPE_TRANSFER_WRITE;
   59 
   60    /* texture_subdata implicitly discards the rewritten buffer range */
   61    usage |= PIPE_TRANSFER_DISCARD_RANGE;
   62 
   63    map = pipe->transfer_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_transfer_unmap(pipe, transfer);
   85 }
   86 
   87 
   88 bool u_default_resource_get_handle(UNUSED struct pipe_screen *screen,
   89                                    UNUSED struct pipe_resource *resource,
   90                                    UNUSED struct winsys_handle *handle)
   91 {
   92    return FALSE;
   93 }
   94 
   95 
   96 
   97 void u_default_transfer_flush_region(UNUSED struct pipe_context *pipe,
   98                                      UNUSED struct pipe_transfer *transfer,
   99                                      UNUSED const struct pipe_box *box)
  100 {
  101    /* This is a no-op implementation, nothing to do.
  102     */
  103 }
  104 
  105 void u_default_transfer_unmap(UNUSED struct pipe_context *pipe,
  106                               UNUSED struct pipe_transfer *transfer)
  107 {
  108 }
  109 
  110 
  111 static inline struct u_resource *
  112 u_resource( struct pipe_resource *res )
  113 {
  114    return (struct u_resource *)res;
  115 }
  116 
  117 bool u_resource_get_handle_vtbl(struct pipe_screen *screen,
  118                                 UNUSED struct pipe_context *ctx,
  119                                 struct pipe_resource *resource,
  120                                 struct winsys_handle *handle,
  121                                 UNUSED unsigned usage)
  122 {
  123    struct u_resource *ur = u_resource(resource);
  124    return ur->vtbl->resource_get_handle(screen, resource, handle);
  125 }
  126 
  127 void u_resource_destroy_vtbl(struct pipe_screen *screen,
  128                              struct pipe_resource *resource)
  129 {
  130    struct u_resource *ur = u_resource(resource);
  131    ur->vtbl->resource_destroy(screen, resource);
  132 }
  133 
  134 void *u_transfer_map_vtbl(struct pipe_context *context,
  135                           struct pipe_resource *resource,
  136                           unsigned level,
  137                           unsigned usage,
  138                           const struct pipe_box *box,
  139                           struct pipe_transfer **transfer)
  140 {
  141    struct u_resource *ur = u_resource(resource);
  142    return ur->vtbl->transfer_map(context, resource, level, usage, box,
  143                                  transfer);
  144 }
  145 
  146 void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
  147                                    struct pipe_transfer *transfer,
  148                                    const struct pipe_box *box)
  149 {
  150    struct u_resource *ur = u_resource(transfer->resource);
  151    ur->vtbl->transfer_flush_region(pipe, transfer, box);
  152 }
  153 
  154 void u_transfer_unmap_vtbl( struct pipe_context *pipe,
  155                             struct pipe_transfer *transfer )
  156 {
  157    struct u_resource *ur = u_resource(transfer->resource);
  158    ur->vtbl->transfer_unmap(pipe, transfer);
  159 }