1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /**************************************************************************
4 * Copyright 2015 VMware, Inc., Palo Alto, CA., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
27 #ifndef _VMWGFX_BINDING_H_
28 #define _VMWGFX_BINDING_H_
30 #include <linux/list.h>
32 #include "device_include/svga3d_reg.h"
34 #define VMW_MAX_VIEW_BINDINGS 128
36 #define VMW_MAX_UAV_BIND_TYPE 2
39 struct vmw_ctx_binding_state;
42 * enum vmw_ctx_binding_type - abstract resource to context binding types
44 enum vmw_ctx_binding_type {
45 vmw_ctx_binding_shader,
49 vmw_ctx_binding_dx_shader,
50 vmw_ctx_binding_dx_rt,
53 vmw_ctx_binding_so_target,
57 vmw_ctx_binding_cs_uav,
63 * struct vmw_ctx_bindinfo - single binding metadata
65 * @ctx_list: List head for the context's list of bindings.
66 * @res_list: List head for a resource's list of bindings.
67 * @ctx: Non-refcounted pointer to the context that owns the binding. NULL
68 * indicates no binding present.
69 * @res: Non-refcounted pointer to the resource the binding points to. This
70 * is typically a surface or a view.
72 * @scrubbed: Whether the binding has been scrubbed from the context.
74 struct vmw_ctx_bindinfo {
75 struct list_head ctx_list;
76 struct list_head res_list;
77 struct vmw_resource *ctx;
78 struct vmw_resource *res;
79 enum vmw_ctx_binding_type bt;
84 * struct vmw_ctx_bindinfo_tex - texture stage binding metadata
86 * @bi: struct vmw_ctx_bindinfo we derive from.
87 * @texture_stage: Device data used to reconstruct binding command.
89 struct vmw_ctx_bindinfo_tex {
90 struct vmw_ctx_bindinfo bi;
95 * struct vmw_ctx_bindinfo_shader - Shader binding metadata
97 * @bi: struct vmw_ctx_bindinfo we derive from.
98 * @shader_slot: Device data used to reconstruct binding command.
100 struct vmw_ctx_bindinfo_shader {
101 struct vmw_ctx_bindinfo bi;
102 SVGA3dShaderType shader_slot;
106 * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata
108 * @bi: struct vmw_ctx_bindinfo we derive from.
109 * @shader_slot: Device data used to reconstruct binding command.
110 * @offset: Device data used to reconstruct binding command.
111 * @size: Device data used to reconstruct binding command.
112 * @slot: Device data used to reconstruct binding command.
114 struct vmw_ctx_bindinfo_cb {
115 struct vmw_ctx_bindinfo bi;
116 SVGA3dShaderType shader_slot;
123 * struct vmw_ctx_bindinfo_view - View binding metadata
125 * @bi: struct vmw_ctx_bindinfo we derive from.
126 * @shader_slot: Device data used to reconstruct binding command.
127 * @slot: Device data used to reconstruct binding command.
129 struct vmw_ctx_bindinfo_view {
130 struct vmw_ctx_bindinfo bi;
131 SVGA3dShaderType shader_slot;
136 * struct vmw_ctx_bindinfo_so_target - StreamOutput binding metadata
138 * @bi: struct vmw_ctx_bindinfo we derive from.
139 * @offset: Device data used to reconstruct binding command.
140 * @size: Device data used to reconstruct binding command.
141 * @slot: Device data used to reconstruct binding command.
143 struct vmw_ctx_bindinfo_so_target {
144 struct vmw_ctx_bindinfo bi;
151 * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata
153 * @bi: struct vmw_ctx_bindinfo we derive from.
154 * @offset: Device data used to reconstruct binding command.
155 * @stride: Device data used to reconstruct binding command.
156 * @slot: Device data used to reconstruct binding command.
158 struct vmw_ctx_bindinfo_vb {
159 struct vmw_ctx_bindinfo bi;
166 * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata
168 * @bi: struct vmw_ctx_bindinfo we derive from.
169 * @offset: Device data used to reconstruct binding command.
170 * @format: Device data used to reconstruct binding command.
172 struct vmw_ctx_bindinfo_ib {
173 struct vmw_ctx_bindinfo bi;
179 * struct vmw_dx_shader_bindings - per shader type context binding state
181 * @shader: The shader binding for this shader type
182 * @const_buffer: Const buffer bindings for this shader type.
183 * @shader_res: Shader resource view bindings for this shader type.
184 * @dirty_sr: Bitmap tracking individual shader resource bindings changes
185 * that have not yet been emitted to the device.
186 * @dirty: Bitmap tracking per-binding type binding changes that have not
187 * yet been emitted to the device.
189 struct vmw_dx_shader_bindings {
190 struct vmw_ctx_bindinfo_shader shader;
191 struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS];
192 struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS];
193 DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS);
198 * struct vmw_ctx_bindinfo_uav - UAV context binding state.
199 * @views: UAV view bindings.
200 * @splice_index: The device splice index set by user-space.
202 struct vmw_ctx_bindinfo_uav {
203 struct vmw_ctx_bindinfo_view views[SVGA3D_DX11_1_MAX_UAVIEWS];
208 * struct vmw_ctx_bindinfo_so - Stream output binding metadata.
209 * @bi: struct vmw_ctx_bindinfo we derive from.
210 * @slot: Device data used to reconstruct binding command.
212 struct vmw_ctx_bindinfo_so {
213 struct vmw_ctx_bindinfo bi;
217 extern void vmw_binding_add(struct vmw_ctx_binding_state *cbs,
218 const struct vmw_ctx_bindinfo *ci,
219 u32 shader_slot, u32 slot);
220 extern void vmw_binding_cb_offset_update(struct vmw_ctx_binding_state *cbs,
221 u32 shader_slot, u32 slot, u32 offsetInBytes);
222 extern void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs,
223 uint32 slot, uint32 splice_index);
225 vmw_binding_state_commit(struct vmw_ctx_binding_state *to,
226 struct vmw_ctx_binding_state *from);
227 extern void vmw_binding_res_list_kill(struct list_head *head);
228 extern void vmw_binding_res_list_scrub(struct list_head *head);
229 extern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs);
230 extern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs);
231 extern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs);
232 extern struct vmw_ctx_binding_state *
233 vmw_binding_state_alloc(struct vmw_private *dev_priv);
234 extern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs);
235 extern struct list_head *
236 vmw_binding_state_list(struct vmw_ctx_binding_state *cbs);
237 extern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs);
238 extern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type);