162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */ 262306a36Sopenharmony_ci/************************************************************************** 362306a36Sopenharmony_ci * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 662306a36Sopenharmony_ci * copy of this software and associated documentation files (the 762306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 862306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 962306a36Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 1062306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 1162306a36Sopenharmony_ci * the following conditions: 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the 1462306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 1562306a36Sopenharmony_ci * of the Software. 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1862306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1962306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 2062306a36Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 2162306a36Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2262306a36Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2362306a36Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci **************************************************************************/ 2662306a36Sopenharmony_ci#ifndef VMW_SO_H 2762306a36Sopenharmony_ci#define VMW_SO_H 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cienum vmw_view_type { 3062306a36Sopenharmony_ci vmw_view_sr, 3162306a36Sopenharmony_ci vmw_view_rt, 3262306a36Sopenharmony_ci vmw_view_ds, 3362306a36Sopenharmony_ci vmw_view_ua, 3462306a36Sopenharmony_ci vmw_view_max, 3562306a36Sopenharmony_ci}; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cienum vmw_so_type { 3862306a36Sopenharmony_ci vmw_so_el, 3962306a36Sopenharmony_ci vmw_so_bs, 4062306a36Sopenharmony_ci vmw_so_ds, 4162306a36Sopenharmony_ci vmw_so_rs, 4262306a36Sopenharmony_ci vmw_so_ss, 4362306a36Sopenharmony_ci vmw_so_so, 4462306a36Sopenharmony_ci vmw_so_max, 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/** 4862306a36Sopenharmony_ci * union vmw_view_destroy - view destruction command body 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * @rtv: RenderTarget view destruction command body 5162306a36Sopenharmony_ci * @srv: ShaderResource view destruction command body 5262306a36Sopenharmony_ci * @dsv: DepthStencil view destruction command body 5362306a36Sopenharmony_ci * @view_id: A single u32 view id. 5462306a36Sopenharmony_ci * 5562306a36Sopenharmony_ci * The assumption here is that all union members are really represented by a 5662306a36Sopenharmony_ci * single u32 in the command stream. If that's not the case, 5762306a36Sopenharmony_ci * the size of this union will not equal the size of an u32, and the 5862306a36Sopenharmony_ci * assumption is invalid, and we detect that at compile time in the 5962306a36Sopenharmony_ci * vmw_so_build_asserts() function. 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ciunion vmw_view_destroy { 6262306a36Sopenharmony_ci struct SVGA3dCmdDXDestroyRenderTargetView rtv; 6362306a36Sopenharmony_ci struct SVGA3dCmdDXDestroyShaderResourceView srv; 6462306a36Sopenharmony_ci struct SVGA3dCmdDXDestroyDepthStencilView dsv; 6562306a36Sopenharmony_ci struct SVGA3dCmdDXDestroyUAView uav; 6662306a36Sopenharmony_ci u32 view_id; 6762306a36Sopenharmony_ci}; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* Map enum vmw_view_type to view destroy command ids*/ 7062306a36Sopenharmony_ciextern const u32 vmw_view_destroy_cmds[]; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* Map enum vmw_view_type to SVGACOTableType */ 7362306a36Sopenharmony_ciextern const SVGACOTableType vmw_view_cotables[]; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* Map enum vmw_so_type to SVGACOTableType */ 7662306a36Sopenharmony_ciextern const SVGACOTableType vmw_so_cotables[]; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* 7962306a36Sopenharmony_ci * vmw_view_cmd_to_type - Return the view type for a create or destroy command 8062306a36Sopenharmony_ci * 8162306a36Sopenharmony_ci * @id: The SVGA3D command id. 8262306a36Sopenharmony_ci * 8362306a36Sopenharmony_ci * For a given view create or destroy command id, return the corresponding 8462306a36Sopenharmony_ci * enum vmw_view_type. If the command is unknown, return vmw_view_max. 8562306a36Sopenharmony_ci * The validity of the simplified calculation is verified in the 8662306a36Sopenharmony_ci * vmw_so_build_asserts() function. 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_cistatic inline enum vmw_view_type vmw_view_cmd_to_type(u32 id) 8962306a36Sopenharmony_ci{ 9062306a36Sopenharmony_ci u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci if (id == SVGA_3D_CMD_DX_DEFINE_UA_VIEW || 9362306a36Sopenharmony_ci id == SVGA_3D_CMD_DX_DESTROY_UA_VIEW) 9462306a36Sopenharmony_ci return vmw_view_ua; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci if (id == SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2) 9762306a36Sopenharmony_ci return vmw_view_ds; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci if (tmp > (u32)vmw_view_ds) 10062306a36Sopenharmony_ci return vmw_view_max; 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci return (enum vmw_view_type) tmp; 10362306a36Sopenharmony_ci} 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* 10662306a36Sopenharmony_ci * vmw_so_cmd_to_type - Return the state object type for a 10762306a36Sopenharmony_ci * create or destroy command 10862306a36Sopenharmony_ci * 10962306a36Sopenharmony_ci * @id: The SVGA3D command id. 11062306a36Sopenharmony_ci * 11162306a36Sopenharmony_ci * For a given state object create or destroy command id, 11262306a36Sopenharmony_ci * return the corresponding enum vmw_so_type. If the command is uknown, 11362306a36Sopenharmony_ci * return vmw_so_max. We should perhaps optimize this function using 11462306a36Sopenharmony_ci * a similar strategy as vmw_view_cmd_to_type(). 11562306a36Sopenharmony_ci */ 11662306a36Sopenharmony_cistatic inline enum vmw_so_type vmw_so_cmd_to_type(u32 id) 11762306a36Sopenharmony_ci{ 11862306a36Sopenharmony_ci switch (id) { 11962306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT: 12062306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT: 12162306a36Sopenharmony_ci return vmw_so_el; 12262306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE: 12362306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE: 12462306a36Sopenharmony_ci return vmw_so_bs; 12562306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE: 12662306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE: 12762306a36Sopenharmony_ci return vmw_so_ds; 12862306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE: 12962306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE_V2: 13062306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE: 13162306a36Sopenharmony_ci return vmw_so_rs; 13262306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE: 13362306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE: 13462306a36Sopenharmony_ci return vmw_so_ss; 13562306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT: 13662306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB: 13762306a36Sopenharmony_ci case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT: 13862306a36Sopenharmony_ci return vmw_so_so; 13962306a36Sopenharmony_ci default: 14062306a36Sopenharmony_ci break; 14162306a36Sopenharmony_ci } 14262306a36Sopenharmony_ci return vmw_so_max; 14362306a36Sopenharmony_ci} 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/* 14662306a36Sopenharmony_ci * View management - vmwgfx_so.c 14762306a36Sopenharmony_ci */ 14862306a36Sopenharmony_ciextern int vmw_view_add(struct vmw_cmdbuf_res_manager *man, 14962306a36Sopenharmony_ci struct vmw_resource *ctx, 15062306a36Sopenharmony_ci struct vmw_resource *srf, 15162306a36Sopenharmony_ci enum vmw_view_type view_type, 15262306a36Sopenharmony_ci u32 user_key, 15362306a36Sopenharmony_ci const void *cmd, 15462306a36Sopenharmony_ci size_t cmd_size, 15562306a36Sopenharmony_ci struct list_head *list); 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciextern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man, 15862306a36Sopenharmony_ci u32 user_key, enum vmw_view_type view_type, 15962306a36Sopenharmony_ci struct list_head *list, 16062306a36Sopenharmony_ci struct vmw_resource **res_p); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ciextern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv, 16362306a36Sopenharmony_ci struct list_head *view_list); 16462306a36Sopenharmony_ciextern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv, 16562306a36Sopenharmony_ci struct list_head *list, 16662306a36Sopenharmony_ci bool readback); 16762306a36Sopenharmony_ciextern struct vmw_resource *vmw_view_srf(struct vmw_resource *res); 16862306a36Sopenharmony_ciextern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man, 16962306a36Sopenharmony_ci enum vmw_view_type view_type, 17062306a36Sopenharmony_ci u32 user_key); 17162306a36Sopenharmony_ciextern u32 vmw_view_dirtying(struct vmw_resource *res); 17262306a36Sopenharmony_ci#endif 173