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