Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lp_texture.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 VMware, Inc.
  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.
  21. * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  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. #ifndef LP_TEXTURE_H
  28. #define LP_TEXTURE_H
  29. #include "pipe/p_state.h"
  30. #include "util/u_debug.h"
  31. #include "lp_limits.h"
  32. enum lp_texture_usage
  33. {
  34. LP_TEX_USAGE_READ = 100,
  35. LP_TEX_USAGE_READ_WRITE,
  36. LP_TEX_USAGE_WRITE_ALL
  37. };
  38. struct pipe_context;
  39. struct pipe_screen;
  40. struct llvmpipe_context;
  41. struct sw_displaytarget;
  42. /** A 1D/2D/3D image, one mipmap level */
  43. struct llvmpipe_texture_image
  44. {
  45. void *data;
  46. };
  47. /**
  48. * llvmpipe subclass of pipe_resource. A texture, drawing surface,
  49. * vertex buffer, const buffer, etc.
  50. * Textures are stored differently than other types of objects such as
  51. * vertex buffers and const buffers.
  52. * The latter are simple malloc'd blocks of memory.
  53. */
  54. struct llvmpipe_resource
  55. {
  56. struct pipe_resource base;
  57. /** Row stride in bytes */
  58. unsigned row_stride[LP_MAX_TEXTURE_LEVELS];
  59. /** Image stride (for cube maps, array or 3D textures) in bytes */
  60. unsigned img_stride[LP_MAX_TEXTURE_LEVELS];
  61. /** Number of 3D slices or cube faces per level */
  62. unsigned num_slices_faces[LP_MAX_TEXTURE_LEVELS];
  63. /** Offset to start of mipmap level, in bytes */
  64. unsigned linear_mip_offsets[LP_MAX_TEXTURE_LEVELS];
  65. /**
  66. * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
  67. * usage.
  68. */
  69. struct sw_displaytarget *dt;
  70. /**
  71. * Malloc'ed data for regular textures, or a mapping to dt above.
  72. */
  73. struct llvmpipe_texture_image linear_img;
  74. /**
  75. * Data for non-texture resources.
  76. */
  77. void *data;
  78. boolean userBuffer; /** Is this a user-space buffer? */
  79. unsigned timestamp;
  80. unsigned id; /**< temporary, for debugging */
  81. #ifdef DEBUG
  82. /** for linked list */
  83. struct llvmpipe_resource *prev, *next;
  84. #endif
  85. };
  86. struct llvmpipe_transfer
  87. {
  88. struct pipe_transfer base;
  89. unsigned long offset;
  90. };
  91. /** cast wrappers */
  92. static INLINE struct llvmpipe_resource *
  93. llvmpipe_resource(struct pipe_resource *pt)
  94. {
  95. return (struct llvmpipe_resource *) pt;
  96. }
  97. static INLINE const struct llvmpipe_resource *
  98. llvmpipe_resource_const(const struct pipe_resource *pt)
  99. {
  100. return (const struct llvmpipe_resource *) pt;
  101. }
  102. static INLINE struct llvmpipe_transfer *
  103. llvmpipe_transfer(struct pipe_transfer *pt)
  104. {
  105. return (struct llvmpipe_transfer *) pt;
  106. }
  107. void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
  108. void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
  109. static INLINE boolean
  110. llvmpipe_resource_is_texture(const struct pipe_resource *resource)
  111. {
  112. switch (resource->target) {
  113. case PIPE_BUFFER:
  114. return FALSE;
  115. case PIPE_TEXTURE_1D:
  116. case PIPE_TEXTURE_1D_ARRAY:
  117. case PIPE_TEXTURE_2D:
  118. case PIPE_TEXTURE_2D_ARRAY:
  119. case PIPE_TEXTURE_RECT:
  120. case PIPE_TEXTURE_3D:
  121. case PIPE_TEXTURE_CUBE:
  122. return TRUE;
  123. default:
  124. assert(0);
  125. return FALSE;
  126. }
  127. }
  128. static INLINE boolean
  129. llvmpipe_resource_is_1d(const struct pipe_resource *resource)
  130. {
  131. switch (resource->target) {
  132. case PIPE_BUFFER:
  133. case PIPE_TEXTURE_1D:
  134. case PIPE_TEXTURE_1D_ARRAY:
  135. return TRUE;
  136. case PIPE_TEXTURE_2D:
  137. case PIPE_TEXTURE_2D_ARRAY:
  138. case PIPE_TEXTURE_RECT:
  139. case PIPE_TEXTURE_3D:
  140. case PIPE_TEXTURE_CUBE:
  141. return FALSE;
  142. default:
  143. assert(0);
  144. return FALSE;
  145. }
  146. }
  147. static INLINE unsigned
  148. llvmpipe_layer_stride(struct pipe_resource *resource,
  149. unsigned level)
  150. {
  151. struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
  152. assert(level < LP_MAX_TEXTURE_2D_LEVELS);
  153. return lpr->img_stride[level];
  154. }
  155. static INLINE unsigned
  156. llvmpipe_resource_stride(struct pipe_resource *resource,
  157. unsigned level)
  158. {
  159. struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
  160. assert(level < LP_MAX_TEXTURE_2D_LEVELS);
  161. return lpr->row_stride[level];
  162. }
  163. void *
  164. llvmpipe_resource_map(struct pipe_resource *resource,
  165. unsigned level,
  166. unsigned layer,
  167. enum lp_texture_usage tex_usage);
  168. void
  169. llvmpipe_resource_unmap(struct pipe_resource *resource,
  170. unsigned level,
  171. unsigned layer);
  172. void *
  173. llvmpipe_resource_data(struct pipe_resource *resource);
  174. unsigned
  175. llvmpipe_resource_size(const struct pipe_resource *resource);
  176. ubyte *
  177. llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
  178. unsigned face_slice, unsigned level);
  179. void *
  180. llvmpipe_get_texture_image(struct llvmpipe_resource *resource,
  181. unsigned face_slice, unsigned level,
  182. enum lp_texture_usage usage);
  183. void *
  184. llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
  185. unsigned level,
  186. enum lp_texture_usage usage);
  187. ubyte *
  188. llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
  189. unsigned face_slice, unsigned level,
  190. enum lp_texture_usage usage,
  191. unsigned x, unsigned y);
  192. extern void
  193. llvmpipe_print_resources(void);
  194. #define LP_UNREFERENCED 0
  195. #define LP_REFERENCED_FOR_READ (1 << 0)
  196. #define LP_REFERENCED_FOR_WRITE (1 << 1)
  197. unsigned int
  198. llvmpipe_is_resource_referenced( struct pipe_context *pipe,
  199. struct pipe_resource *presource,
  200. unsigned level);
  201. unsigned
  202. llvmpipe_get_format_alignment(enum pipe_format format);
  203. #endif /* LP_TEXTURE_H */