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