Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2007 VMware, Inc. |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
Michel Dänzer | 753db0d | 2007-11-30 20:48:03 +0100 | [diff] [blame] | 28 | #ifndef ST_TEXTURE_H |
| 29 | #define ST_TEXTURE_H |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 30 | |
| 31 | |
Michal Krol | b8030c6 | 2010-03-12 14:37:36 +0100 | [diff] [blame] | 32 | #include "pipe/p_context.h" |
| 33 | #include "util/u_sampler.h" |
| 34 | |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 35 | #include "main/mtypes.h" |
| 36 | |
Brian Paul | 5d3d63d | 2010-04-18 17:55:23 -0600 | [diff] [blame] | 37 | |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 38 | struct pipe_resource; |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 39 | |
| 40 | |
Marek Olšák | 463b0ea | 2014-08-02 20:31:07 +0200 | [diff] [blame] | 41 | struct st_texture_image_transfer { |
| 42 | struct pipe_transfer *transfer; |
| 43 | |
| 44 | /* For ETC fallback. */ |
| 45 | GLubyte *temp_data; /**< Temporary ETC texture storage. */ |
| 46 | unsigned temp_stride; /**< Stride of the ETC texture storage. */ |
| 47 | GLubyte *map; /**< Saved map pointer of the uncompressed transfer. */ |
| 48 | }; |
| 49 | |
| 50 | |
Brian Paul | e648d4a | 2010-04-29 15:32:36 -0600 | [diff] [blame] | 51 | /** |
| 52 | * Subclass of gl_texure_image. |
| 53 | */ |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 54 | struct st_texture_image |
| 55 | { |
| 56 | struct gl_texture_image base; |
| 57 | |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 58 | /* If stImage->pt != NULL, image data is stored here. |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 59 | * Else there is no image data. |
| 60 | */ |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 61 | struct pipe_resource *pt; |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 62 | |
Marek Olšák | 26c4139 | 2014-03-10 18:43:17 +0100 | [diff] [blame] | 63 | /* List of transfers, allocated on demand. |
| 64 | * transfer[layer] is a mapping for that layer. |
| 65 | */ |
Marek Olšák | 463b0ea | 2014-08-02 20:31:07 +0200 | [diff] [blame] | 66 | struct st_texture_image_transfer *transfer; |
Marek Olšák | 26c4139 | 2014-03-10 18:43:17 +0100 | [diff] [blame] | 67 | unsigned num_transfers; |
Ilia Mirkin | d816a51 | 2016-07-08 02:44:57 -0400 | [diff] [blame] | 68 | |
| 69 | /* For ETC images, keep track of the original data. This is necessary for |
| 70 | * mapping/unmapping, as well as image copies. |
| 71 | */ |
| 72 | GLubyte *etc_data; |
| 73 | }; |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 74 | |
| 75 | |
Brian Paul | e648d4a | 2010-04-29 15:32:36 -0600 | [diff] [blame] | 76 | /** |
| 77 | * Subclass of gl_texure_object. |
| 78 | */ |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 79 | struct st_texture_object |
| 80 | { |
| 81 | struct gl_texture_object base; /* The "parent" object */ |
| 82 | |
| 83 | /* The texture must include at levels [0..lastLevel] once validated: |
| 84 | */ |
| 85 | GLuint lastLevel; |
| 86 | |
| 87 | /* On validation any active images held in main memory or in other |
| 88 | * textures will be copied to this texture and the old storage freed. |
| 89 | */ |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 90 | struct pipe_resource *pt; |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 91 | |
Christian König | 6c59be7 | 2014-03-25 17:31:49 +0100 | [diff] [blame] | 92 | /* Number of views in sampler_views array */ |
| 93 | GLuint num_sampler_views; |
| 94 | |
| 95 | /* Array of sampler views (one per context) attached to this texture |
| 96 | * object. Created lazily on first binding in context. |
Michal Krol | b8030c6 | 2010-03-12 14:37:36 +0100 | [diff] [blame] | 97 | */ |
Christian König | 6c59be7 | 2014-03-25 17:31:49 +0100 | [diff] [blame] | 98 | struct pipe_sampler_view **sampler_views; |
Michal Krol | b8030c6 | 2010-03-12 14:37:36 +0100 | [diff] [blame] | 99 | |
Marek Olšák | 639d0f7 | 2013-05-10 02:03:15 +0200 | [diff] [blame] | 100 | /* True if this texture comes from the window system. Such a texture |
| 101 | * cannot be reallocated and the format can only be changed with a sampler |
| 102 | * view or a surface. |
Chia-I Wu | 54a7115 | 2009-08-05 16:07:19 -0600 | [diff] [blame] | 103 | */ |
| 104 | GLboolean surface_based; |
Marek Olšák | 639d0f7 | 2013-05-10 02:03:15 +0200 | [diff] [blame] | 105 | |
| 106 | /* If surface_based is true, this format should be used for all sampler |
| 107 | * views and surfaces instead of pt->format. |
| 108 | */ |
| 109 | enum pipe_format surface_format; |
Brian Paul | e5cc84d | 2016-09-30 16:41:46 -0600 | [diff] [blame] | 110 | |
Nicolai Hähnle | 322483f | 2016-11-03 21:49:40 +0100 | [diff] [blame] | 111 | /* When non-zero, samplers should use this layer instead of the one |
| 112 | * specified by the GL state. |
| 113 | * |
| 114 | * This is used for VDPAU interop, where imported pipe_resources may be |
| 115 | * array textures (containing layers with different fields) even though the |
| 116 | * GL state describes one non-array texture per field. |
| 117 | */ |
| 118 | uint layer_override; |
| 119 | |
Brian Paul | e5cc84d | 2016-09-30 16:41:46 -0600 | [diff] [blame] | 120 | /** The glsl version of the shader seen during the previous validation */ |
| 121 | unsigned prev_glsl_version; |
| 122 | /** The value of the sampler's sRGBDecode state at the previous validation */ |
| 123 | GLenum prev_sRGBDecode; |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 127 | static inline struct st_texture_image * |
Brian Paul | 9d9143d | 2008-09-01 13:09:31 -0600 | [diff] [blame] | 128 | st_texture_image(struct gl_texture_image *img) |
| 129 | { |
| 130 | return (struct st_texture_image *) img; |
| 131 | } |
| 132 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 133 | static inline const struct st_texture_image * |
Brian Paul | 58e8dd6 | 2015-01-02 16:56:12 -0700 | [diff] [blame] | 134 | st_texture_image_const(const struct gl_texture_image *img) |
| 135 | { |
| 136 | return (const struct st_texture_image *) img; |
| 137 | } |
| 138 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 139 | static inline struct st_texture_object * |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 140 | st_texture_object(struct gl_texture_object *obj) |
| 141 | { |
| 142 | return (struct st_texture_object *) obj; |
| 143 | } |
| 144 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 145 | static inline const struct st_texture_object * |
Brian Paul | 31b0e7d | 2013-12-13 09:33:49 -0700 | [diff] [blame] | 146 | st_texture_object_const(const struct gl_texture_object *obj) |
| 147 | { |
| 148 | return (const struct st_texture_object *) obj; |
| 149 | } |
| 150 | |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 151 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 152 | static inline struct pipe_resource * |
Brian Paul | c3016dc | 2010-04-18 17:58:44 -0600 | [diff] [blame] | 153 | st_get_texobj_resource(struct gl_texture_object *texObj) |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 154 | { |
| 155 | struct st_texture_object *stObj = st_texture_object(texObj); |
| 156 | return stObj ? stObj->pt : NULL; |
| 157 | } |
| 158 | |
| 159 | |
Brian Paul | 164b3cd | 2015-02-26 10:03:22 -0700 | [diff] [blame] | 160 | static inline struct pipe_resource * |
Brian Paul | 1aaf41f | 2010-04-18 18:01:04 -0600 | [diff] [blame] | 161 | st_get_stobj_resource(struct st_texture_object *stObj) |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 162 | { |
| 163 | return stObj ? stObj->pt : NULL; |
| 164 | } |
| 165 | |
Brian | 58edb06 | 2008-02-20 11:20:25 -0700 | [diff] [blame] | 166 | |
Rob Clark | ecd6fce | 2016-08-31 17:44:01 -0400 | [diff] [blame] | 167 | static inline struct st_texture_object * |
| 168 | st_get_texture_object(struct gl_context *ctx, |
| 169 | const struct gl_program *prog, |
| 170 | unsigned unit) |
| 171 | { |
| 172 | const GLuint texUnit = prog->SamplerUnits[unit]; |
| 173 | struct gl_texture_object *texObj = ctx->Texture.Unit[texUnit]._Current; |
| 174 | |
| 175 | if (!texObj) |
| 176 | return NULL; |
| 177 | |
| 178 | return st_texture_object(texObj); |
| 179 | } |
| 180 | |
| 181 | static inline enum pipe_format |
| 182 | st_get_view_format(struct st_texture_object *stObj) |
| 183 | { |
| 184 | if (!stObj) |
| 185 | return PIPE_FORMAT_NONE; |
| 186 | return stObj->surface_based ? stObj->surface_format : stObj->pt->format; |
| 187 | } |
Brian Paul | 9600b07 | 2012-02-13 14:51:14 -0700 | [diff] [blame] | 188 | |
Brian Paul | f579a05 | 2011-01-20 08:38:19 -0700 | [diff] [blame] | 189 | |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 190 | extern struct pipe_resource * |
Michel Dänzer | 753db0d | 2007-11-30 20:48:03 +0100 | [diff] [blame] | 191 | st_texture_create(struct st_context *st, |
Michel Dänzer | 1c5f27a | 2008-01-04 17:06:55 +0100 | [diff] [blame] | 192 | enum pipe_texture_target target, |
| 193 | enum pipe_format format, |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 194 | GLuint last_level, |
| 195 | GLuint width0, |
| 196 | GLuint height0, |
| 197 | GLuint depth0, |
Brian Paul | db3a8af | 2011-01-28 20:25:26 -0700 | [diff] [blame] | 198 | GLuint layers, |
Dave Airlie | f152da6 | 2013-03-04 06:17:11 +1000 | [diff] [blame] | 199 | GLuint nr_samples, |
Keith Whitwell | a73ae3d | 2008-05-02 16:46:31 +0100 | [diff] [blame] | 200 | GLuint tex_usage ); |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 201 | |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 202 | |
Brian Paul | 1dd8e27 | 2011-01-28 20:25:27 -0700 | [diff] [blame] | 203 | extern void |
| 204 | st_gl_texture_dims_to_pipe_dims(GLenum texture, |
| 205 | GLuint widthIn, |
| 206 | GLuint heightIn, |
| 207 | GLuint depthIn, |
| 208 | GLuint *widthOut, |
| 209 | GLuint *heightOut, |
| 210 | GLuint *depthOut, |
| 211 | GLuint *layersOut); |
| 212 | |
Brian | a4fbf09 | 2008-02-05 17:55:16 -0700 | [diff] [blame] | 213 | /* Check if an image fits into an existing texture object. |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 214 | */ |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 215 | extern GLboolean |
Marek Olšák | 547e288 | 2014-08-02 21:00:41 +0200 | [diff] [blame] | 216 | st_texture_match_image(struct st_context *st, |
| 217 | const struct pipe_resource *pt, |
Brian Paul | 7276ab2 | 2011-09-22 16:32:49 -0600 | [diff] [blame] | 218 | const struct gl_texture_image *image); |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 219 | |
Michel Dänzer | 753db0d | 2007-11-30 20:48:03 +0100 | [diff] [blame] | 220 | /* Return a pointer to an image within a texture. Return image stride as |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 221 | * well. |
| 222 | */ |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 223 | extern GLubyte * |
Marek Olšák | ed86809 | 2012-12-20 15:15:15 +0100 | [diff] [blame] | 224 | st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, |
Michel Dänzer | 4617981 | 2009-02-05 19:41:18 +0100 | [diff] [blame] | 225 | enum pipe_transfer_usage usage, |
Marek Olšák | ed86809 | 2012-12-20 15:15:15 +0100 | [diff] [blame] | 226 | GLuint x, GLuint y, GLuint z, |
Marek Olšák | 26c4139 | 2014-03-10 18:43:17 +0100 | [diff] [blame] | 227 | GLuint w, GLuint h, GLuint d, |
| 228 | struct pipe_transfer **transfer); |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 229 | |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 230 | extern void |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 231 | st_texture_image_unmap(struct st_context *st, |
Marek Olšák | 26c4139 | 2014-03-10 18:43:17 +0100 | [diff] [blame] | 232 | struct st_texture_image *stImage, unsigned slice); |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 233 | |
| 234 | |
| 235 | /* Return pointers to each 2d slice within an image. Indexed by depth |
| 236 | * value. |
| 237 | */ |
| 238 | extern const GLuint * |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 239 | st_texture_depth_offsets(struct pipe_resource *pt, GLuint level); |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 240 | |
Michel Dänzer | 753db0d | 2007-11-30 20:48:03 +0100 | [diff] [blame] | 241 | /* Copy an image between two textures |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 242 | */ |
Brian | 0790d9a | 2007-08-06 15:49:00 -0600 | [diff] [blame] | 243 | extern void |
Michel Dänzer | 753db0d | 2007-11-30 20:48:03 +0100 | [diff] [blame] | 244 | st_texture_image_copy(struct pipe_context *pipe, |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 245 | struct pipe_resource *dst, GLuint dstLevel, |
Brian Paul | c6fdb95 | 2010-05-04 17:25:33 -0600 | [diff] [blame] | 246 | struct pipe_resource *src, GLuint srcLevel, |
Brian | 4da1cdf | 2008-02-12 14:53:25 -0700 | [diff] [blame] | 247 | GLuint face); |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 248 | |
Bryan Cain | 9adcab9 | 2011-08-04 10:15:54 -0500 | [diff] [blame] | 249 | |
| 250 | extern struct pipe_resource * |
| 251 | st_create_color_map_texture(struct gl_context *ctx); |
| 252 | |
Brian Paul | f9985db | 2014-04-09 19:22:11 -0600 | [diff] [blame] | 253 | |
Ilia Mirkin | 7727e6f | 2016-07-07 23:59:03 -0400 | [diff] [blame] | 254 | bool |
| 255 | st_etc_fallback(struct st_context *st, struct gl_texture_image *texImage); |
| 256 | |
Brian | 307fe07 | 2007-08-06 12:40:51 -0600 | [diff] [blame] | 257 | #endif |