1848b8605Smrg#include "pipe/p_context.h" 2848b8605Smrg#include "util/u_surface.h" 3848b8605Smrg#include "util/u_inlines.h" 4848b8605Smrg#include "util/u_transfer.h" 5848b8605Smrg#include "util/u_memory.h" 6848b8605Smrg 7b8e80941Smrgvoid u_default_buffer_subdata(struct pipe_context *pipe, 8b8e80941Smrg struct pipe_resource *resource, 9b8e80941Smrg unsigned usage, unsigned offset, 10b8e80941Smrg unsigned size, const void *data) 11848b8605Smrg{ 12848b8605Smrg struct pipe_transfer *transfer = NULL; 13b8e80941Smrg struct pipe_box box; 14848b8605Smrg uint8_t *map = NULL; 15848b8605Smrg 16848b8605Smrg assert(!(usage & PIPE_TRANSFER_READ)); 17848b8605Smrg 18b8e80941Smrg /* the write flag is implicit by the nature of buffer_subdata */ 19848b8605Smrg usage |= PIPE_TRANSFER_WRITE; 20848b8605Smrg 21b8e80941Smrg /* buffer_subdata implicitly discards the rewritten buffer range */ 22b8e80941Smrg if (offset == 0 && size == resource->width0) { 23848b8605Smrg usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE; 24848b8605Smrg } else { 25848b8605Smrg usage |= PIPE_TRANSFER_DISCARD_RANGE; 26848b8605Smrg } 27848b8605Smrg 28b8e80941Smrg u_box_1d(offset, size, &box); 29b8e80941Smrg 30b8e80941Smrg map = pipe->transfer_map(pipe, resource, 0, usage, &box, &transfer); 31b8e80941Smrg if (!map) 32b8e80941Smrg return; 33b8e80941Smrg 34b8e80941Smrg memcpy(map, data, size); 35b8e80941Smrg pipe_transfer_unmap(pipe, transfer); 36b8e80941Smrg} 37b8e80941Smrg 38b8e80941Smrgvoid u_default_texture_subdata(struct pipe_context *pipe, 39b8e80941Smrg struct pipe_resource *resource, 40b8e80941Smrg unsigned level, 41b8e80941Smrg unsigned usage, 42b8e80941Smrg const struct pipe_box *box, 43b8e80941Smrg const void *data, 44b8e80941Smrg unsigned stride, 45b8e80941Smrg unsigned layer_stride) 46b8e80941Smrg{ 47b8e80941Smrg struct pipe_transfer *transfer = NULL; 48b8e80941Smrg const uint8_t *src_data = data; 49b8e80941Smrg uint8_t *map = NULL; 50b8e80941Smrg 51b8e80941Smrg assert(!(usage & PIPE_TRANSFER_READ)); 52b8e80941Smrg 53b8e80941Smrg /* the write flag is implicit by the nature of texture_subdata */ 54b8e80941Smrg usage |= PIPE_TRANSFER_WRITE; 55b8e80941Smrg 56b8e80941Smrg /* texture_subdata implicitly discards the rewritten buffer range */ 57b8e80941Smrg usage |= PIPE_TRANSFER_DISCARD_RANGE; 58b8e80941Smrg 59848b8605Smrg map = pipe->transfer_map(pipe, 60848b8605Smrg resource, 61848b8605Smrg level, 62848b8605Smrg usage, 63848b8605Smrg box, &transfer); 64b8e80941Smrg if (!map) 65848b8605Smrg return; 66848b8605Smrg 67b8e80941Smrg util_copy_box(map, 68b8e80941Smrg resource->format, 69b8e80941Smrg transfer->stride, /* bytes */ 70b8e80941Smrg transfer->layer_stride, /* bytes */ 71b8e80941Smrg 0, 0, 0, 72b8e80941Smrg box->width, 73b8e80941Smrg box->height, 74b8e80941Smrg box->depth, 75b8e80941Smrg src_data, 76b8e80941Smrg stride, /* bytes */ 77b8e80941Smrg layer_stride, /* bytes */ 78b8e80941Smrg 0, 0, 0); 79848b8605Smrg 80848b8605Smrg pipe_transfer_unmap(pipe, transfer); 81848b8605Smrg} 82848b8605Smrg 83848b8605Smrg 84b8e80941Smrgboolean u_default_resource_get_handle(UNUSED struct pipe_screen *screen, 85b8e80941Smrg UNUSED struct pipe_resource *resource, 86b8e80941Smrg UNUSED struct winsys_handle *handle) 87848b8605Smrg{ 88848b8605Smrg return FALSE; 89848b8605Smrg} 90848b8605Smrg 91848b8605Smrg 92848b8605Smrg 93b8e80941Smrgvoid u_default_transfer_flush_region(UNUSED struct pipe_context *pipe, 94b8e80941Smrg UNUSED struct pipe_transfer *transfer, 95b8e80941Smrg UNUSED const struct pipe_box *box) 96848b8605Smrg{ 97848b8605Smrg /* This is a no-op implementation, nothing to do. 98848b8605Smrg */ 99848b8605Smrg} 100848b8605Smrg 101b8e80941Smrgvoid u_default_transfer_unmap(UNUSED struct pipe_context *pipe, 102b8e80941Smrg UNUSED struct pipe_transfer *transfer) 103848b8605Smrg{ 104848b8605Smrg} 105848b8605Smrg 106848b8605Smrg 107b8e80941Smrgstatic inline struct u_resource * 108848b8605Smrgu_resource( struct pipe_resource *res ) 109848b8605Smrg{ 110848b8605Smrg return (struct u_resource *)res; 111848b8605Smrg} 112848b8605Smrg 113848b8605Smrgboolean u_resource_get_handle_vtbl(struct pipe_screen *screen, 114b8e80941Smrg UNUSED struct pipe_context *ctx, 115848b8605Smrg struct pipe_resource *resource, 116b8e80941Smrg struct winsys_handle *handle, 117b8e80941Smrg UNUSED unsigned usage) 118848b8605Smrg{ 119848b8605Smrg struct u_resource *ur = u_resource(resource); 120848b8605Smrg return ur->vtbl->resource_get_handle(screen, resource, handle); 121848b8605Smrg} 122848b8605Smrg 123848b8605Smrgvoid u_resource_destroy_vtbl(struct pipe_screen *screen, 124848b8605Smrg struct pipe_resource *resource) 125848b8605Smrg{ 126848b8605Smrg struct u_resource *ur = u_resource(resource); 127848b8605Smrg ur->vtbl->resource_destroy(screen, resource); 128848b8605Smrg} 129848b8605Smrg 130848b8605Smrgvoid *u_transfer_map_vtbl(struct pipe_context *context, 131848b8605Smrg struct pipe_resource *resource, 132848b8605Smrg unsigned level, 133848b8605Smrg unsigned usage, 134848b8605Smrg const struct pipe_box *box, 135848b8605Smrg struct pipe_transfer **transfer) 136848b8605Smrg{ 137848b8605Smrg struct u_resource *ur = u_resource(resource); 138848b8605Smrg return ur->vtbl->transfer_map(context, resource, level, usage, box, 139848b8605Smrg transfer); 140848b8605Smrg} 141848b8605Smrg 142848b8605Smrgvoid u_transfer_flush_region_vtbl( struct pipe_context *pipe, 143848b8605Smrg struct pipe_transfer *transfer, 144848b8605Smrg const struct pipe_box *box) 145848b8605Smrg{ 146848b8605Smrg struct u_resource *ur = u_resource(transfer->resource); 147848b8605Smrg ur->vtbl->transfer_flush_region(pipe, transfer, box); 148848b8605Smrg} 149848b8605Smrg 150848b8605Smrgvoid u_transfer_unmap_vtbl( struct pipe_context *pipe, 151848b8605Smrg struct pipe_transfer *transfer ) 152848b8605Smrg{ 153848b8605Smrg struct u_resource *ur = u_resource(transfer->resource); 154848b8605Smrg ur->vtbl->transfer_unmap(pipe, transfer); 155848b8605Smrg} 156