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