summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/vmwgfx/vmwgfx_so.h
blob: f48b84bfeeac2787a0fb448844aaadbb2e390941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/**************************************************************************
 * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/
#ifndef VMW_SO_H
#define VMW_SO_H

enum vmw_view_type {
	vmw_view_sr,
	vmw_view_rt,
	vmw_view_ds,
	vmw_view_ua,
	vmw_view_max,
};

enum vmw_so_type {
	vmw_so_el,
	vmw_so_bs,
	vmw_so_ds,
	vmw_so_rs,
	vmw_so_ss,
	vmw_so_so,
	vmw_so_max,
};

/**
 * union vmw_view_destroy - view destruction command body
 *
 * @rtv: RenderTarget view destruction command body
 * @srv: ShaderResource view destruction command body
 * @dsv: DepthStencil view destruction command body
 * @view_id: A single u32 view id.
 *
 * The assumption here is that all union members are really represented by a
 * single u32 in the command stream. If that's not the case,
 * the size of this union will not equal the size of an u32, and the
 * assumption is invalid, and we detect that at compile time in the
 * vmw_so_build_asserts() function.
 */
union vmw_view_destroy {
	struct SVGA3dCmdDXDestroyRenderTargetView rtv;
	struct SVGA3dCmdDXDestroyShaderResourceView srv;
	struct SVGA3dCmdDXDestroyDepthStencilView dsv;
	struct SVGA3dCmdDXDestroyUAView uav;
	u32 view_id;
};

/* Map enum vmw_view_type to view destroy command ids*/
extern const u32 vmw_view_destroy_cmds[];

/* Map enum vmw_view_type to SVGACOTableType */
extern const SVGACOTableType vmw_view_cotables[];

/* Map enum vmw_so_type to SVGACOTableType */
extern const SVGACOTableType vmw_so_cotables[];

/*
 * vmw_view_cmd_to_type - Return the view type for a create or destroy command
 *
 * @id: The SVGA3D command id.
 *
 * For a given view create or destroy command id, return the corresponding
 * enum vmw_view_type. If the command is unknown, return vmw_view_max.
 * The validity of the simplified calculation is verified in the
 * vmw_so_build_asserts() function.
 */
static inline enum vmw_view_type vmw_view_cmd_to_type(u32 id)
{
	u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2;

	if (id == SVGA_3D_CMD_DX_DEFINE_UA_VIEW ||
	    id == SVGA_3D_CMD_DX_DESTROY_UA_VIEW)
		return vmw_view_ua;

	if (tmp > (u32)vmw_view_max)
		return vmw_view_max;

	return (enum vmw_view_type) tmp;
}

/*
 * vmw_so_cmd_to_type - Return the state object type for a
 * create or destroy command
 *
 * @id: The SVGA3D command id.
 *
 * For a given state object create or destroy command id,
 * return the corresponding enum vmw_so_type. If the command is uknown,
 * return vmw_so_max. We should perhaps optimize this function using
 * a similar strategy as vmw_view_cmd_to_type().
 */
static inline enum vmw_so_type vmw_so_cmd_to_type(u32 id)
{
	switch (id) {
	case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
	case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
		return vmw_so_el;
	case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
	case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
		return vmw_so_bs;
	case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
	case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
		return vmw_so_ds;
	case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
	case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
		return vmw_so_rs;
	case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
	case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
		return vmw_so_ss;
	case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
	case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB:
	case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
		return vmw_so_so;
	default:
		break;
	}
	return vmw_so_max;
}

/*
 * View management - vmwgfx_so.c
 */
extern int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
			struct vmw_resource *ctx,
			struct vmw_resource *srf,
			enum vmw_view_type view_type,
			u32 user_key,
			const void *cmd,
			size_t cmd_size,
			struct list_head *list);

extern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man,
			   u32 user_key, enum vmw_view_type view_type,
			   struct list_head *list,
			   struct vmw_resource **res_p);

extern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv,
					  struct list_head *view_list);
extern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv,
					  struct list_head *list,
					  bool readback);
extern struct vmw_resource *vmw_view_srf(struct vmw_resource *res);
extern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man,
					    enum vmw_view_type view_type,
					    u32 user_key);
extern u32 vmw_view_dirtying(struct vmw_resource *res);
#endif