1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef ST_TEXTURE_H 29bf215546Sopenharmony_ci#define ST_TEXTURE_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "pipe/p_context.h" 33bf215546Sopenharmony_ci#include "util/u_sampler.h" 34bf215546Sopenharmony_ci#include "util/simple_mtx.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#include "main/mtypes.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistruct pipe_resource; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistruct st_texture_image_transfer 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci struct pipe_transfer *transfer; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci /* For compressed texture fallback. */ 47bf215546Sopenharmony_ci GLubyte *temp_data; /**< Temporary compressed texture storage. */ 48bf215546Sopenharmony_ci unsigned temp_stride; /**< Stride of the compressed texture storage. */ 49bf215546Sopenharmony_ci GLubyte *map; /**< Saved map pointer of the uncompressed transfer. */ 50bf215546Sopenharmony_ci}; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci/** 54bf215546Sopenharmony_ci * Container for one context's validated sampler view. 55bf215546Sopenharmony_ci */ 56bf215546Sopenharmony_cistruct st_sampler_view 57bf215546Sopenharmony_ci{ 58bf215546Sopenharmony_ci struct pipe_sampler_view *view; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci /** The context which created this view */ 61bf215546Sopenharmony_ci struct st_context *st; 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /** The glsl version of the shader seen during validation */ 64bf215546Sopenharmony_ci bool glsl130_or_later; 65bf215546Sopenharmony_ci /** Derived from the sampler's sRGBDecode state during validation */ 66bf215546Sopenharmony_ci bool srgb_skip_decode; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci /* This mechanism allows passing sampler view references to the driver 69bf215546Sopenharmony_ci * without using atomics to increase the reference count. 70bf215546Sopenharmony_ci * 71bf215546Sopenharmony_ci * This private refcount can be decremented without atomics but only one 72bf215546Sopenharmony_ci * context (st above) can use this counter (so that it's only used by 73bf215546Sopenharmony_ci * 1 thread). 74bf215546Sopenharmony_ci * 75bf215546Sopenharmony_ci * This number is atomically added to view->reference.count at 76bf215546Sopenharmony_ci * initialization. If it's never used, the same number is atomically 77bf215546Sopenharmony_ci * subtracted from view->reference.count before destruction. If this 78bf215546Sopenharmony_ci * number is decremented, we can pass one reference to the driver without 79bf215546Sopenharmony_ci * touching reference.count with atomics. At destruction we only subtract 80bf215546Sopenharmony_ci * the number of references we have not returned. This can possibly turn 81bf215546Sopenharmony_ci * a million atomic increments into 1 add and 1 subtract atomic op over 82bf215546Sopenharmony_ci * the whole lifetime of an app. 83bf215546Sopenharmony_ci */ 84bf215546Sopenharmony_ci int private_refcount; 85bf215546Sopenharmony_ci}; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci/** 89bf215546Sopenharmony_ci * Container for per-context sampler views of a texture. 90bf215546Sopenharmony_ci */ 91bf215546Sopenharmony_cistruct st_sampler_views 92bf215546Sopenharmony_ci{ 93bf215546Sopenharmony_ci struct st_sampler_views *next; 94bf215546Sopenharmony_ci uint32_t max; 95bf215546Sopenharmony_ci uint32_t count; 96bf215546Sopenharmony_ci struct st_sampler_view views[0]; 97bf215546Sopenharmony_ci}; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cistruct st_compressed_data 100bf215546Sopenharmony_ci{ 101bf215546Sopenharmony_ci struct pipe_reference reference; 102bf215546Sopenharmony_ci GLubyte *ptr; 103bf215546Sopenharmony_ci}; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_cistatic inline const struct gl_texture_image * 106bf215546Sopenharmony_cist_texture_image_const(const struct gl_texture_image *img) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci return (const struct gl_texture_image *) img; 109bf215546Sopenharmony_ci} 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_cistatic inline const struct gl_texture_object * 112bf215546Sopenharmony_cist_texture_object_const(const struct gl_texture_object *obj) 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci return (const struct gl_texture_object *) obj; 115bf215546Sopenharmony_ci} 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_cistatic inline struct pipe_resource * 119bf215546Sopenharmony_cist_get_texobj_resource(struct gl_texture_object *texObj) 120bf215546Sopenharmony_ci{ 121bf215546Sopenharmony_ci return texObj ? texObj->pt : NULL; 122bf215546Sopenharmony_ci} 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_cistatic inline struct pipe_resource * 126bf215546Sopenharmony_cist_get_stobj_resource(struct gl_texture_object *stObj) 127bf215546Sopenharmony_ci{ 128bf215546Sopenharmony_ci return stObj ? stObj->pt : NULL; 129bf215546Sopenharmony_ci} 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_cistatic inline struct gl_texture_object * 133bf215546Sopenharmony_cist_get_texture_object(struct gl_context *ctx, 134bf215546Sopenharmony_ci const struct gl_program *prog, 135bf215546Sopenharmony_ci unsigned unit) 136bf215546Sopenharmony_ci{ 137bf215546Sopenharmony_ci const GLuint texUnit = prog->SamplerUnits[unit]; 138bf215546Sopenharmony_ci return ctx->Texture.Unit[texUnit]._Current; 139bf215546Sopenharmony_ci} 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_cistatic inline enum pipe_format 142bf215546Sopenharmony_cist_get_view_format(struct gl_texture_object *stObj) 143bf215546Sopenharmony_ci{ 144bf215546Sopenharmony_ci if (!stObj) 145bf215546Sopenharmony_ci return PIPE_FORMAT_NONE; 146bf215546Sopenharmony_ci return stObj->surface_based ? stObj->surface_format : stObj->pt->format; 147bf215546Sopenharmony_ci} 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ciextern struct pipe_resource * 151bf215546Sopenharmony_cist_texture_create(struct st_context *st, 152bf215546Sopenharmony_ci enum pipe_texture_target target, 153bf215546Sopenharmony_ci enum pipe_format format, 154bf215546Sopenharmony_ci GLuint last_level, 155bf215546Sopenharmony_ci GLuint width0, 156bf215546Sopenharmony_ci GLuint height0, 157bf215546Sopenharmony_ci GLuint depth0, 158bf215546Sopenharmony_ci GLuint layers, 159bf215546Sopenharmony_ci GLuint nr_samples, 160bf215546Sopenharmony_ci GLuint tex_usage, 161bf215546Sopenharmony_ci bool sparse); 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ciextern void 165bf215546Sopenharmony_cist_gl_texture_dims_to_pipe_dims(GLenum texture, 166bf215546Sopenharmony_ci unsigned widthIn, 167bf215546Sopenharmony_ci uint16_t heightIn, 168bf215546Sopenharmony_ci uint16_t depthIn, 169bf215546Sopenharmony_ci unsigned *widthOut, 170bf215546Sopenharmony_ci uint16_t *heightOut, 171bf215546Sopenharmony_ci uint16_t *depthOut, 172bf215546Sopenharmony_ci uint16_t *layersOut); 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci/* Check if an image fits into an existing texture object. 175bf215546Sopenharmony_ci */ 176bf215546Sopenharmony_ciextern GLboolean 177bf215546Sopenharmony_cist_texture_match_image(struct st_context *st, 178bf215546Sopenharmony_ci const struct pipe_resource *pt, 179bf215546Sopenharmony_ci const struct gl_texture_image *image); 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci/* Return a pointer to an image within a texture. Return image stride as 182bf215546Sopenharmony_ci * well. 183bf215546Sopenharmony_ci */ 184bf215546Sopenharmony_ciextern GLubyte * 185bf215546Sopenharmony_cist_texture_image_map(struct st_context *st, struct gl_texture_image *stImage, 186bf215546Sopenharmony_ci enum pipe_map_flags usage, 187bf215546Sopenharmony_ci GLuint x, GLuint y, GLuint z, 188bf215546Sopenharmony_ci GLuint w, GLuint h, GLuint d, 189bf215546Sopenharmony_ci struct pipe_transfer **transfer); 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ciextern void 192bf215546Sopenharmony_cist_texture_image_unmap(struct st_context *st, 193bf215546Sopenharmony_ci struct gl_texture_image *stImage, unsigned slice); 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci/* Return pointers to each 2d slice within an image. Indexed by depth 197bf215546Sopenharmony_ci * value. 198bf215546Sopenharmony_ci */ 199bf215546Sopenharmony_ciextern const GLuint * 200bf215546Sopenharmony_cist_texture_depth_offsets(struct pipe_resource *pt, GLuint level); 201bf215546Sopenharmony_ci 202bf215546Sopenharmony_ci/* Copy an image between two textures 203bf215546Sopenharmony_ci */ 204bf215546Sopenharmony_ciextern void 205bf215546Sopenharmony_cist_texture_image_copy(struct pipe_context *pipe, 206bf215546Sopenharmony_ci struct pipe_resource *dst, GLuint dstLevel, 207bf215546Sopenharmony_ci struct pipe_resource *src, GLuint srcLevel, 208bf215546Sopenharmony_ci GLuint face); 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ciextern struct pipe_resource * 212bf215546Sopenharmony_cist_create_color_map_texture(struct gl_context *ctx); 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_civoid 215bf215546Sopenharmony_cist_destroy_bound_texture_handles(struct st_context *st); 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_civoid 218bf215546Sopenharmony_cist_destroy_bound_image_handles(struct st_context *st); 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_cibool 221bf215546Sopenharmony_cist_astc_format_fallback(const struct st_context *st, mesa_format format); 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_cibool 224bf215546Sopenharmony_cist_compressed_format_fallback(struct st_context *st, mesa_format format); 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_civoid 227bf215546Sopenharmony_cist_convert_image(const struct st_context *st, const struct gl_image_unit *u, 228bf215546Sopenharmony_ci struct pipe_image_view *img, unsigned shader_access); 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_civoid 231bf215546Sopenharmony_cist_convert_image_from_unit(const struct st_context *st, 232bf215546Sopenharmony_ci struct pipe_image_view *img, 233bf215546Sopenharmony_ci GLuint imgUnit, 234bf215546Sopenharmony_ci unsigned shader_access); 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_civoid 237bf215546Sopenharmony_cist_convert_sampler(const struct st_context *st, 238bf215546Sopenharmony_ci const struct gl_texture_object *texobj, 239bf215546Sopenharmony_ci const struct gl_sampler_object *msamp, 240bf215546Sopenharmony_ci float tex_unit_lod_bias, 241bf215546Sopenharmony_ci struct pipe_sampler_state *sampler, 242bf215546Sopenharmony_ci bool seamless_cube_map); 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_civoid 245bf215546Sopenharmony_cist_convert_sampler_from_unit(const struct st_context *st, 246bf215546Sopenharmony_ci struct pipe_sampler_state *sampler, 247bf215546Sopenharmony_ci GLuint texUnit); 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_cistruct pipe_sampler_view * 250bf215546Sopenharmony_cist_update_single_texture(struct st_context *st, 251bf215546Sopenharmony_ci GLuint texUnit, bool glsl130_or_later, 252bf215546Sopenharmony_ci bool ignore_srgb_decode, bool get_reference); 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ciunsigned 255bf215546Sopenharmony_cist_get_sampler_views(struct st_context *st, 256bf215546Sopenharmony_ci enum pipe_shader_type shader_stage, 257bf215546Sopenharmony_ci const struct gl_program *prog, 258bf215546Sopenharmony_ci struct pipe_sampler_view **sampler_views); 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_civoid 261bf215546Sopenharmony_cist_make_bound_samplers_resident(struct st_context *st, 262bf215546Sopenharmony_ci struct gl_program *prog); 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_civoid 265bf215546Sopenharmony_cist_make_bound_images_resident(struct st_context *st, 266bf215546Sopenharmony_ci struct gl_program *prog); 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci#endif 269