Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_resource_texture.h
4570 views
/**********************************************************1* Copyright 2008-2009 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/2425#ifndef SVGA_TEXTURE_H26#define SVGA_TEXTURE_H272829#include "pipe/p_compiler.h"30#include "pipe/p_state.h"31#include "util/u_inlines.h"32#include "util/u_memory.h"33#include "util/u_transfer.h"34#include "svga_screen_cache.h"3536struct pipe_context;37struct pipe_screen;38struct svga_context;39struct svga_winsys_surface;40enum SVGA3dSurfaceFormat;414243#define SVGA_MAX_TEXTURE_LEVELS 164445struct svga_texture46{47struct pipe_resource b;4849ushort *defined;5051struct svga_sampler_view *cached_view;5253unsigned view_age[SVGA_MAX_TEXTURE_LEVELS];54unsigned age;5556boolean views_modified;5758/**59* Creation key for the host surface handle.60*61* This structure describes all the host surface characteristics so that it62* can be looked up in cache, since creating a host surface is often a slow63* operation.64*/65struct svga_host_surface_cache_key key;6667/**68* Handle for the host side surface.69*70* This handle is owned by this texture. Views should hold on to a reference71* to this texture and never destroy this handle directly.72*/73struct svga_winsys_surface *handle;7475/**76* Whether the host side surface is validated, either through the77* InvalidateGBSurface command or after the surface is updated78* or rendered to.79*/80boolean validated;8182/**83* Whether the host side surface is imported and not created by this84* driver.85*/86boolean imported;8788/**89* Whether texture upload buffer can be used on this texture90*/91boolean can_use_upload;9293unsigned size; /**< Approximate size in bytes */9495/** array indexed by cube face or 3D/array slice, one bit per mipmap level */96ushort *rendered_to;9798/** array indexed by cube face or 3D/array slice, one bit per mipmap level.99* Set if the level is marked as dirty.100*/101ushort *dirty;102103/**104* A cached backing host side surface to be used if this texture is being105* used for rendering and sampling at the same time.106* Currently we only cache one handle. If needed, we can extend this to107* support multiple handles.108*/109struct svga_host_surface_cache_key backed_key;110struct svga_winsys_surface *backed_handle;111unsigned backed_age;112};113114115116/* Note this is only used for texture (not buffer) transfers:117*/118struct svga_transfer119{120struct pipe_transfer base;121122unsigned slice; /**< array slice or cube face */123SVGA3dBox box; /* The adjusted box with slice index removed from z */124125struct svga_winsys_buffer *hwbuf;126127/* Height of the hardware buffer in pixel blocks */128unsigned hw_nblocksy;129130/* Temporary malloc buffer when we can't allocate a hardware buffer131* big enough */132void *swbuf;133134/* True if guest backed surface is supported and we can directly map135* to the surface for this transfer.136*/137boolean use_direct_map;138139struct {140struct pipe_resource *buf; /* points to the upload buffer if this141* transfer is done via the upload buffer142* instead of directly mapping to the143* resource's surface.144*/145void *map;146unsigned offset;147SVGA3dBox box;148unsigned nlayers;149} upload;150};151152153static inline struct svga_texture *154svga_texture(struct pipe_resource *resource)155{156struct svga_texture *tex = (struct svga_texture *)resource;157assert(tex == NULL || tex->b.target != PIPE_BUFFER);158return tex;159}160161162static inline struct svga_transfer *163svga_transfer(struct pipe_transfer *transfer)164{165assert(transfer);166return (struct svga_transfer *)transfer;167}168169170/**171* Increment the age of a view into a texture172* This is used to track updates to textures when we draw into173* them via a surface.174*/175static inline void176svga_age_texture_view(struct svga_texture *tex, unsigned level)177{178assert(level < ARRAY_SIZE(tex->view_age));179tex->view_age[level] = ++(tex->age);180}181182183/** For debugging, check that face and level are legal */184static inline void185check_face_level(const struct svga_texture *tex,186unsigned face, unsigned level)187{188if (tex->b.target == PIPE_TEXTURE_CUBE) {189assert(face < 6);190}191else if (tex->b.target == PIPE_TEXTURE_3D) {192assert(face < tex->b.depth0);193}194else {195assert(face < tex->b.array_size);196}197198assert(level < 8 * sizeof(tex->rendered_to[0]));199}200201202/**203* Mark the given texture face/level as being defined.204*/205static inline void206svga_define_texture_level(struct svga_texture *tex,207unsigned face,unsigned level)208{209check_face_level(tex, face, level);210tex->defined[face] |= 1 << level;211tex->validated = TRUE;212}213214215static inline bool216svga_is_texture_level_defined(const struct svga_texture *tex,217unsigned face, unsigned level)218{219check_face_level(tex, face, level);220return (tex->defined[face] & (1 << level)) != 0;221}222223224static inline void225svga_set_texture_rendered_to(struct svga_texture *tex,226unsigned face, unsigned level)227{228check_face_level(tex, face, level);229tex->rendered_to[face] |= 1 << level;230tex->validated = TRUE;231}232233234static inline void235svga_clear_texture_rendered_to(struct svga_texture *tex,236unsigned face, unsigned level)237{238check_face_level(tex, face, level);239tex->rendered_to[face] &= ~(1 << level);240}241242243static inline boolean244svga_was_texture_rendered_to(const struct svga_texture *tex,245unsigned face, unsigned level)246{247check_face_level(tex, face, level);248return !!(tex->rendered_to[face] & (1 << level));249}250251static inline void252svga_set_texture_dirty(struct svga_texture *tex,253unsigned face, unsigned level)254{255check_face_level(tex, face, level);256tex->dirty[face] |= 1 << level;257}258259static inline void260svga_clear_texture_dirty(struct svga_texture *tex)261{262unsigned i;263for (i = 0; i < tex->b.depth0 * tex->b.array_size; i++) {264tex->dirty[i] = 0;265}266}267268static inline boolean269svga_is_texture_dirty(const struct svga_texture *tex,270unsigned face, unsigned level)271{272check_face_level(tex, face, level);273return !!(tex->dirty[face] & (1 << level));274}275276struct pipe_resource *277svga_texture_create(struct pipe_screen *screen,278const struct pipe_resource *template);279280bool281svga_resource_get_handle(struct pipe_screen *screen,282struct pipe_context *context,283struct pipe_resource *texture,284struct winsys_handle *whandle,285unsigned usage);286287struct pipe_resource *288svga_texture_from_handle(struct pipe_screen * screen,289const struct pipe_resource *template,290struct winsys_handle *whandle);291292bool293svga_texture_generate_mipmap(struct pipe_context *pipe,294struct pipe_resource *pt,295enum pipe_format format,296unsigned base_level,297unsigned last_level,298unsigned first_layer,299unsigned last_layer);300301boolean302svga_texture_transfer_map_upload_create(struct svga_context *svga);303304void305svga_texture_transfer_map_upload_destroy(struct svga_context *svga);306307boolean308svga_texture_transfer_map_can_upload(const struct svga_screen *svgascreen,309const struct pipe_resource *pt);310311void *312svga_texture_transfer_map_upload(struct svga_context *svga,313struct svga_transfer *st);314315void316svga_texture_transfer_unmap_upload(struct svga_context *svga,317struct svga_transfer *st);318319boolean320svga_texture_device_format_has_alpha(struct pipe_resource *texture);321322void *323svga_texture_transfer_map(struct pipe_context *pipe,324struct pipe_resource *texture,325unsigned level,326unsigned usage,327const struct pipe_box *box,328struct pipe_transfer **ptransfer);329330void331svga_texture_transfer_unmap(struct pipe_context *pipe,332struct pipe_transfer *transfer);333334#endif /* SVGA_TEXTURE_H */335336337