vmwgfx_so.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial portions
  15. * of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  21. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  23. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. **************************************************************************/
  26. #ifndef VMW_SO_H
  27. #define VMW_SO_H
  28. enum vmw_view_type {
  29. vmw_view_sr,
  30. vmw_view_rt,
  31. vmw_view_ds,
  32. vmw_view_ua,
  33. vmw_view_max,
  34. };
  35. enum vmw_so_type {
  36. vmw_so_el,
  37. vmw_so_bs,
  38. vmw_so_ds,
  39. vmw_so_rs,
  40. vmw_so_ss,
  41. vmw_so_so,
  42. vmw_so_max,
  43. };
  44. /**
  45. * union vmw_view_destroy - view destruction command body
  46. *
  47. * @rtv: RenderTarget view destruction command body
  48. * @srv: ShaderResource view destruction command body
  49. * @dsv: DepthStencil view destruction command body
  50. * @view_id: A single u32 view id.
  51. *
  52. * The assumption here is that all union members are really represented by a
  53. * single u32 in the command stream. If that's not the case,
  54. * the size of this union will not equal the size of an u32, and the
  55. * assumption is invalid, and we detect that at compile time in the
  56. * vmw_so_build_asserts() function.
  57. */
  58. union vmw_view_destroy {
  59. struct SVGA3dCmdDXDestroyRenderTargetView rtv;
  60. struct SVGA3dCmdDXDestroyShaderResourceView srv;
  61. struct SVGA3dCmdDXDestroyDepthStencilView dsv;
  62. struct SVGA3dCmdDXDestroyUAView uav;
  63. u32 view_id;
  64. };
  65. /* Map enum vmw_view_type to view destroy command ids*/
  66. extern const u32 vmw_view_destroy_cmds[];
  67. /* Map enum vmw_view_type to SVGACOTableType */
  68. extern const SVGACOTableType vmw_view_cotables[];
  69. /* Map enum vmw_so_type to SVGACOTableType */
  70. extern const SVGACOTableType vmw_so_cotables[];
  71. /*
  72. * vmw_view_cmd_to_type - Return the view type for a create or destroy command
  73. *
  74. * @id: The SVGA3D command id.
  75. *
  76. * For a given view create or destroy command id, return the corresponding
  77. * enum vmw_view_type. If the command is unknown, return vmw_view_max.
  78. * The validity of the simplified calculation is verified in the
  79. * vmw_so_build_asserts() function.
  80. */
  81. static inline enum vmw_view_type vmw_view_cmd_to_type(u32 id)
  82. {
  83. u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2;
  84. if (id == SVGA_3D_CMD_DX_DEFINE_UA_VIEW ||
  85. id == SVGA_3D_CMD_DX_DESTROY_UA_VIEW)
  86. return vmw_view_ua;
  87. if (id == SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2)
  88. return vmw_view_ds;
  89. if (tmp > (u32)vmw_view_ds)
  90. return vmw_view_max;
  91. return (enum vmw_view_type) tmp;
  92. }
  93. /*
  94. * vmw_so_cmd_to_type - Return the state object type for a
  95. * create or destroy command
  96. *
  97. * @id: The SVGA3D command id.
  98. *
  99. * For a given state object create or destroy command id,
  100. * return the corresponding enum vmw_so_type. If the command is uknown,
  101. * return vmw_so_max. We should perhaps optimize this function using
  102. * a similar strategy as vmw_view_cmd_to_type().
  103. */
  104. static inline enum vmw_so_type vmw_so_cmd_to_type(u32 id)
  105. {
  106. switch (id) {
  107. case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
  108. case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
  109. return vmw_so_el;
  110. case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
  111. case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
  112. return vmw_so_bs;
  113. case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
  114. case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
  115. return vmw_so_ds;
  116. case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
  117. case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE_V2:
  118. case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
  119. return vmw_so_rs;
  120. case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
  121. case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
  122. return vmw_so_ss;
  123. case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
  124. case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB:
  125. case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
  126. return vmw_so_so;
  127. default:
  128. break;
  129. }
  130. return vmw_so_max;
  131. }
  132. /*
  133. * View management - vmwgfx_so.c
  134. */
  135. extern int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
  136. struct vmw_resource *ctx,
  137. struct vmw_resource *srf,
  138. enum vmw_view_type view_type,
  139. u32 user_key,
  140. const void *cmd,
  141. size_t cmd_size,
  142. struct list_head *list);
  143. extern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man,
  144. u32 user_key, enum vmw_view_type view_type,
  145. struct list_head *list,
  146. struct vmw_resource **res_p);
  147. extern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv,
  148. struct list_head *view_list);
  149. extern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv,
  150. struct list_head *list,
  151. bool readback);
  152. extern struct vmw_resource *vmw_view_srf(struct vmw_resource *res);
  153. extern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man,
  154. enum vmw_view_type view_type,
  155. u32 user_key);
  156. extern u32 vmw_view_dirtying(struct vmw_resource *res);
  157. #endif