vmwgfx_so.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**************************************************************************
  2. * Copyright © 2014-2015 VMware, Inc., Palo Alto, CA., USA
  3. * All Rights Reserved.
  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_max,
  33. };
  34. enum vmw_so_type {
  35. vmw_so_el,
  36. vmw_so_bs,
  37. vmw_so_ds,
  38. vmw_so_rs,
  39. vmw_so_ss,
  40. vmw_so_so,
  41. vmw_so_max,
  42. };
  43. /**
  44. * union vmw_view_destroy - view destruction command body
  45. *
  46. * @rtv: RenderTarget view destruction command body
  47. * @srv: ShaderResource view destruction command body
  48. * @dsv: DepthStencil view destruction command body
  49. * @view_id: A single u32 view id.
  50. *
  51. * The assumption here is that all union members are really represented by a
  52. * single u32 in the command stream. If that's not the case,
  53. * the size of this union will not equal the size of an u32, and the
  54. * assumption is invalid, and we detect that at compile time in the
  55. * vmw_so_build_asserts() function.
  56. */
  57. union vmw_view_destroy {
  58. struct SVGA3dCmdDXDestroyRenderTargetView rtv;
  59. struct SVGA3dCmdDXDestroyShaderResourceView srv;
  60. struct SVGA3dCmdDXDestroyDepthStencilView dsv;
  61. u32 view_id;
  62. };
  63. /* Map enum vmw_view_type to view destroy command ids*/
  64. extern const u32 vmw_view_destroy_cmds[];
  65. /* Map enum vmw_view_type to SVGACOTableType */
  66. extern const SVGACOTableType vmw_view_cotables[];
  67. /* Map enum vmw_so_type to SVGACOTableType */
  68. extern const SVGACOTableType vmw_so_cotables[];
  69. /*
  70. * vmw_view_cmd_to_type - Return the view type for a create or destroy command
  71. *
  72. * @id: The SVGA3D command id.
  73. *
  74. * For a given view create or destroy command id, return the corresponding
  75. * enum vmw_view_type. If the command is unknown, return vmw_view_max.
  76. * The validity of the simplified calculation is verified in the
  77. * vmw_so_build_asserts() function.
  78. */
  79. static inline enum vmw_view_type vmw_view_cmd_to_type(u32 id)
  80. {
  81. u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2;
  82. if (tmp > (u32)vmw_view_max)
  83. return vmw_view_max;
  84. return (enum vmw_view_type) tmp;
  85. }
  86. /*
  87. * vmw_so_cmd_to_type - Return the state object type for a
  88. * create or destroy command
  89. *
  90. * @id: The SVGA3D command id.
  91. *
  92. * For a given state object create or destroy command id,
  93. * return the corresponding enum vmw_so_type. If the command is uknown,
  94. * return vmw_so_max. We should perhaps optimize this function using
  95. * a similar strategy as vmw_view_cmd_to_type().
  96. */
  97. static inline enum vmw_so_type vmw_so_cmd_to_type(u32 id)
  98. {
  99. switch (id) {
  100. case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
  101. case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
  102. return vmw_so_el;
  103. case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
  104. case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
  105. return vmw_so_bs;
  106. case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
  107. case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
  108. return vmw_so_ds;
  109. case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
  110. case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
  111. return vmw_so_rs;
  112. case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
  113. case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
  114. return vmw_so_ss;
  115. case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
  116. case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
  117. return vmw_so_so;
  118. default:
  119. break;
  120. }
  121. return vmw_so_max;
  122. }
  123. /*
  124. * View management - vmwgfx_so.c
  125. */
  126. extern int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
  127. struct vmw_resource *ctx,
  128. struct vmw_resource *srf,
  129. enum vmw_view_type view_type,
  130. u32 user_key,
  131. const void *cmd,
  132. size_t cmd_size,
  133. struct list_head *list);
  134. extern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man,
  135. u32 user_key, enum vmw_view_type view_type,
  136. struct list_head *list,
  137. struct vmw_resource **res_p);
  138. extern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv,
  139. struct list_head *view_list);
  140. extern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv,
  141. struct list_head *list,
  142. bool readback);
  143. extern struct vmw_resource *vmw_view_srf(struct vmw_resource *res);
  144. extern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man,
  145. enum vmw_view_type view_type,
  146. u32 user_key);
  147. #endif