Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_resource.h
4570 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef I915_RESOURCE_H28#define I915_RESOURCE_H2930struct i915_screen;3132#include "util/u_debug.h"33#include "util/u_transfer.h"34#include "i915_winsys.h"3536struct i915_context;37struct i915_screen;3839struct i915_buffer {40struct pipe_resource b;41uint8_t *data;42bool free_on_destroy;43};4445/* Texture transfer. */46struct i915_transfer {47/* Base class. */48struct pipe_transfer b;49struct pipe_resource *staging_texture;50};5152#define I915_MAX_TEXTURE_2D_LEVELS 12 /* max 2048x2048 */53#define I915_MAX_TEXTURE_3D_LEVELS 9 /* max 256x256x256 */5455struct offset_pair {56unsigned short nblocksx;57unsigned short nblocksy;58};5960struct i915_texture {61struct pipe_resource b;6263/* tiling flags */64enum i915_winsys_buffer_tile tiling;65unsigned stride;66unsigned depth_stride; /* per-image on i945? */67unsigned total_nblocksy;6869unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];7071/* Explicitly store the offset of each image for each cube face or72* depth value.73*74* Array [depth] off offsets.75*/76struct offset_pair *image_offset[I915_MAX_TEXTURE_2D_LEVELS];7778/* The data is held here:79*/80struct i915_winsys_buffer *buffer;81};8283unsigned i915_texture_offset(const struct i915_texture *tex, unsigned level,84unsigned layer);85void i915_init_screen_resource_functions(struct i915_screen *is);86void i915_init_resource_functions(struct i915_context *i915);8788static inline struct i915_texture *89i915_texture(struct pipe_resource *resource)90{91struct i915_texture *tex = (struct i915_texture *)resource;92assert(tex->b.target != PIPE_BUFFER);93return tex;94}9596static inline struct i915_buffer *97i915_buffer(struct pipe_resource *resource)98{99struct i915_buffer *tex = (struct i915_buffer *)resource;100assert(tex->b.target == PIPE_BUFFER);101return tex;102}103104struct pipe_resource *i915_texture_create(struct pipe_screen *screen,105const struct pipe_resource *template,106bool force_untiled);107108bool i915_resource_get_handle(struct pipe_screen *screen,109struct pipe_context *context,110struct pipe_resource *texture,111struct winsys_handle *whandle, unsigned usage);112113struct pipe_resource *114i915_texture_from_handle(struct pipe_screen *screen,115const struct pipe_resource *template,116struct winsys_handle *whandle);117118struct pipe_resource *i915_user_buffer_create(struct pipe_screen *screen,119void *ptr, unsigned bytes,120unsigned usage);121122struct pipe_resource *i915_buffer_create(struct pipe_screen *screen,123const struct pipe_resource *template);124125void i915_resource_destroy(struct pipe_screen *screen,126struct pipe_resource *resource);127128void i915_buffer_subdata(struct pipe_context *rm_ctx,129struct pipe_resource *resource, unsigned usage,130unsigned offset, unsigned size, const void *data);131132void *i915_buffer_transfer_map(struct pipe_context *pipe,133struct pipe_resource *resource, unsigned level,134unsigned usage, const struct pipe_box *box,135struct pipe_transfer **ptransfer);136137void i915_buffer_transfer_unmap(struct pipe_context *pipe,138struct pipe_transfer *transfer);139140void *i915_texture_transfer_map(struct pipe_context *pipe,141struct pipe_resource *resource, unsigned level,142unsigned usage, const struct pipe_box *box,143struct pipe_transfer **ptransfer);144145void i915_texture_transfer_unmap(struct pipe_context *pipe,146struct pipe_transfer *transfer);147148#endif /* I915_RESOURCE_H */149150151