1 /* $NetBSD: vmwgfx_binding.h,v 1.3 2021/12/18 23:45:45 riastradh Exp $ */ 2 3 /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 4 /************************************************************************** 5 * 6 * Copyright 2015 VMware, Inc., Palo Alto, CA., USA 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial portions 18 * of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 26 * USE OR OTHER DEALINGS IN THE SOFTWARE. 27 * 28 **************************************************************************/ 29 #ifndef _VMWGFX_BINDING_H_ 30 #define _VMWGFX_BINDING_H_ 31 32 #include <linux/list.h> 33 34 #include "device_include/svga3d_reg.h" 35 36 #define VMW_MAX_VIEW_BINDINGS 128 37 38 struct vmw_private; 39 struct vmw_ctx_binding_state; 40 41 /* 42 * enum vmw_ctx_binding_type - abstract resource to context binding types 43 */ 44 enum vmw_ctx_binding_type { 45 vmw_ctx_binding_shader, 46 vmw_ctx_binding_rt, 47 vmw_ctx_binding_tex, 48 vmw_ctx_binding_cb, 49 vmw_ctx_binding_dx_shader, 50 vmw_ctx_binding_dx_rt, 51 vmw_ctx_binding_sr, 52 vmw_ctx_binding_ds, 53 vmw_ctx_binding_so, 54 vmw_ctx_binding_vb, 55 vmw_ctx_binding_ib, 56 vmw_ctx_binding_max 57 }; 58 59 /** 60 * struct vmw_ctx_bindinfo - single binding metadata 61 * 62 * @ctx_list: List head for the context's list of bindings. 63 * @res_list: List head for a resource's list of bindings. 64 * @ctx: Non-refcounted pointer to the context that owns the binding. NULL 65 * indicates no binding present. 66 * @res: Non-refcounted pointer to the resource the binding points to. This 67 * is typically a surface or a view. 68 * @bt: Binding type. 69 * @scrubbed: Whether the binding has been scrubbed from the context. 70 */ 71 struct vmw_ctx_bindinfo { 72 struct list_head ctx_list; 73 struct list_head res_list; 74 struct vmw_resource *ctx; 75 struct vmw_resource *res; 76 enum vmw_ctx_binding_type bt; 77 bool scrubbed; 78 }; 79 80 /** 81 * struct vmw_ctx_bindinfo_tex - texture stage binding metadata 82 * 83 * @bi: struct vmw_ctx_bindinfo we derive from. 84 * @texture_stage: Device data used to reconstruct binding command. 85 */ 86 struct vmw_ctx_bindinfo_tex { 87 struct vmw_ctx_bindinfo bi; 88 uint32 texture_stage; 89 }; 90 91 /** 92 * struct vmw_ctx_bindinfo_shader - Shader binding metadata 93 * 94 * @bi: struct vmw_ctx_bindinfo we derive from. 95 * @shader_slot: Device data used to reconstruct binding command. 96 */ 97 struct vmw_ctx_bindinfo_shader { 98 struct vmw_ctx_bindinfo bi; 99 SVGA3dShaderType shader_slot; 100 }; 101 102 /** 103 * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata 104 * 105 * @bi: struct vmw_ctx_bindinfo we derive from. 106 * @shader_slot: Device data used to reconstruct binding command. 107 * @offset: Device data used to reconstruct binding command. 108 * @size: Device data used to reconstruct binding command. 109 * @slot: Device data used to reconstruct binding command. 110 */ 111 struct vmw_ctx_bindinfo_cb { 112 struct vmw_ctx_bindinfo bi; 113 SVGA3dShaderType shader_slot; 114 uint32 offset; 115 uint32 size; 116 uint32 slot; 117 }; 118 119 /** 120 * struct vmw_ctx_bindinfo_view - View binding metadata 121 * 122 * @bi: struct vmw_ctx_bindinfo we derive from. 123 * @shader_slot: Device data used to reconstruct binding command. 124 * @slot: Device data used to reconstruct binding command. 125 */ 126 struct vmw_ctx_bindinfo_view { 127 struct vmw_ctx_bindinfo bi; 128 SVGA3dShaderType shader_slot; 129 uint32 slot; 130 }; 131 132 /** 133 * struct vmw_ctx_bindinfo_so - StreamOutput binding metadata 134 * 135 * @bi: struct vmw_ctx_bindinfo we derive from. 136 * @offset: Device data used to reconstruct binding command. 137 * @size: Device data used to reconstruct binding command. 138 * @slot: Device data used to reconstruct binding command. 139 */ 140 struct vmw_ctx_bindinfo_so { 141 struct vmw_ctx_bindinfo bi; 142 uint32 offset; 143 uint32 size; 144 uint32 slot; 145 }; 146 147 /** 148 * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata 149 * 150 * @bi: struct vmw_ctx_bindinfo we derive from. 151 * @offset: Device data used to reconstruct binding command. 152 * @stride: Device data used to reconstruct binding command. 153 * @slot: Device data used to reconstruct binding command. 154 */ 155 struct vmw_ctx_bindinfo_vb { 156 struct vmw_ctx_bindinfo bi; 157 uint32 offset; 158 uint32 stride; 159 uint32 slot; 160 }; 161 162 /** 163 * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata 164 * 165 * @bi: struct vmw_ctx_bindinfo we derive from. 166 * @offset: Device data used to reconstruct binding command. 167 * @format: Device data used to reconstruct binding command. 168 */ 169 struct vmw_ctx_bindinfo_ib { 170 struct vmw_ctx_bindinfo bi; 171 uint32 offset; 172 uint32 format; 173 }; 174 175 /** 176 * struct vmw_dx_shader_bindings - per shader type context binding state 177 * 178 * @shader: The shader binding for this shader type 179 * @const_buffer: Const buffer bindings for this shader type. 180 * @shader_res: Shader resource view bindings for this shader type. 181 * @dirty_sr: Bitmap tracking individual shader resource bindings changes 182 * that have not yet been emitted to the device. 183 * @dirty: Bitmap tracking per-binding type binding changes that have not 184 * yet been emitted to the device. 185 */ 186 struct vmw_dx_shader_bindings { 187 struct vmw_ctx_bindinfo_shader shader; 188 struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS]; 189 struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS]; 190 DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS); 191 unsigned long dirty; 192 }; 193 194 extern void vmw_binding_add(struct vmw_ctx_binding_state *cbs, 195 const struct vmw_ctx_bindinfo *ci, 196 u32 shader_slot, u32 slot); 197 extern void 198 vmw_binding_state_commit(struct vmw_ctx_binding_state *to, 199 struct vmw_ctx_binding_state *from); 200 extern void vmw_binding_res_list_kill(struct list_head *head); 201 extern void vmw_binding_res_list_scrub(struct list_head *head); 202 extern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs); 203 extern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs); 204 extern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs); 205 extern struct vmw_ctx_binding_state * 206 vmw_binding_state_alloc(struct vmw_private *dev_priv); 207 extern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs); 208 extern struct list_head * 209 vmw_binding_state_list(struct vmw_ctx_binding_state *cbs); 210 extern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs); 211 extern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type); 212 213 214 #endif 215