blob: da67cbc9cd73291b48d952ac0ae86ce8aa4a2567 [file] [log] [blame]
Dirk Hohndel (VMware)dff96882018-05-07 01:16:26 +02001/* SPDX-License-Identifier: GPL-2.0 OR MIT */
Thomas Hellstromd80efd52015-08-10 10:39:35 -07002/**************************************************************************
3 *
Dirk Hohndel (VMware)dff96882018-05-07 01:16:26 +02004 * Copyright 2015 VMware, Inc., Palo Alto, CA., USA
Thomas Hellstromd80efd52015-08-10 10:39:35 -07005 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27#ifndef _VMWGFX_BINDING_H_
28#define _VMWGFX_BINDING_H_
29
Thomas Hellstromd80efd52015-08-10 10:39:35 -070030#include <linux/list.h>
31
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020032#include "device_include/svga3d_reg.h"
33
Thomas Hellstromd80efd52015-08-10 10:39:35 -070034#define VMW_MAX_VIEW_BINDINGS 128
35
Deepak Rawat5e8ec0d2018-12-13 13:51:08 -080036#define VMW_MAX_UAV_BIND_TYPE 2
37
Thomas Hellstromd80efd52015-08-10 10:39:35 -070038struct vmw_private;
39struct vmw_ctx_binding_state;
40
41/*
42 * enum vmw_ctx_binding_type - abstract resource to context binding types
43 */
44enum 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,
Deepak Rawat5e8ec0d2018-12-13 13:51:08 -080056 vmw_ctx_binding_uav,
57 vmw_ctx_binding_cs_uav,
Thomas Hellstromd80efd52015-08-10 10:39:35 -070058 vmw_ctx_binding_max
59};
60
61/**
62 * struct vmw_ctx_bindinfo - single binding metadata
63 *
64 * @ctx_list: List head for the context's list of bindings.
65 * @res_list: List head for a resource's list of bindings.
66 * @ctx: Non-refcounted pointer to the context that owns the binding. NULL
67 * indicates no binding present.
68 * @res: Non-refcounted pointer to the resource the binding points to. This
69 * is typically a surface or a view.
70 * @bt: Binding type.
71 * @scrubbed: Whether the binding has been scrubbed from the context.
72 */
73struct vmw_ctx_bindinfo {
74 struct list_head ctx_list;
75 struct list_head res_list;
76 struct vmw_resource *ctx;
77 struct vmw_resource *res;
78 enum vmw_ctx_binding_type bt;
79 bool scrubbed;
80};
81
82/**
83 * struct vmw_ctx_bindinfo_tex - texture stage binding metadata
84 *
85 * @bi: struct vmw_ctx_bindinfo we derive from.
86 * @texture_stage: Device data used to reconstruct binding command.
87 */
88struct vmw_ctx_bindinfo_tex {
89 struct vmw_ctx_bindinfo bi;
90 uint32 texture_stage;
91};
92
93/**
94 * struct vmw_ctx_bindinfo_shader - Shader binding metadata
95 *
96 * @bi: struct vmw_ctx_bindinfo we derive from.
97 * @shader_slot: Device data used to reconstruct binding command.
98 */
99struct vmw_ctx_bindinfo_shader {
100 struct vmw_ctx_bindinfo bi;
101 SVGA3dShaderType shader_slot;
102};
103
104/**
105 * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata
106 *
107 * @bi: struct vmw_ctx_bindinfo we derive from.
108 * @shader_slot: Device data used to reconstruct binding command.
109 * @offset: Device data used to reconstruct binding command.
110 * @size: Device data used to reconstruct binding command.
111 * @slot: Device data used to reconstruct binding command.
112 */
113struct vmw_ctx_bindinfo_cb {
114 struct vmw_ctx_bindinfo bi;
115 SVGA3dShaderType shader_slot;
116 uint32 offset;
117 uint32 size;
118 uint32 slot;
119};
120
121/**
122 * struct vmw_ctx_bindinfo_view - View binding metadata
123 *
124 * @bi: struct vmw_ctx_bindinfo we derive from.
125 * @shader_slot: Device data used to reconstruct binding command.
126 * @slot: Device data used to reconstruct binding command.
127 */
128struct vmw_ctx_bindinfo_view {
129 struct vmw_ctx_bindinfo bi;
130 SVGA3dShaderType shader_slot;
131 uint32 slot;
132};
133
134/**
135 * struct vmw_ctx_bindinfo_so - StreamOutput binding metadata
136 *
137 * @bi: struct vmw_ctx_bindinfo we derive from.
138 * @offset: Device data used to reconstruct binding command.
139 * @size: Device data used to reconstruct binding command.
140 * @slot: Device data used to reconstruct binding command.
141 */
142struct vmw_ctx_bindinfo_so {
143 struct vmw_ctx_bindinfo bi;
144 uint32 offset;
145 uint32 size;
146 uint32 slot;
147};
148
149/**
150 * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata
151 *
152 * @bi: struct vmw_ctx_bindinfo we derive from.
153 * @offset: Device data used to reconstruct binding command.
154 * @stride: Device data used to reconstruct binding command.
155 * @slot: Device data used to reconstruct binding command.
156 */
157struct vmw_ctx_bindinfo_vb {
158 struct vmw_ctx_bindinfo bi;
159 uint32 offset;
160 uint32 stride;
161 uint32 slot;
162};
163
164/**
165 * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata
166 *
167 * @bi: struct vmw_ctx_bindinfo we derive from.
168 * @offset: Device data used to reconstruct binding command.
169 * @format: Device data used to reconstruct binding command.
170 */
171struct vmw_ctx_bindinfo_ib {
172 struct vmw_ctx_bindinfo bi;
173 uint32 offset;
174 uint32 format;
175};
176
177/**
178 * struct vmw_dx_shader_bindings - per shader type context binding state
179 *
180 * @shader: The shader binding for this shader type
181 * @const_buffer: Const buffer bindings for this shader type.
182 * @shader_res: Shader resource view bindings for this shader type.
183 * @dirty_sr: Bitmap tracking individual shader resource bindings changes
184 * that have not yet been emitted to the device.
185 * @dirty: Bitmap tracking per-binding type binding changes that have not
186 * yet been emitted to the device.
187 */
188struct vmw_dx_shader_bindings {
189 struct vmw_ctx_bindinfo_shader shader;
190 struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS];
191 struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS];
192 DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS);
193 unsigned long dirty;
194};
195
Deepak Rawat5e8ec0d2018-12-13 13:51:08 -0800196/**
197 * struct vmw_ctx_bindinfo_uav - UAV context binding state.
198 * @views: UAV view bindings.
199 * @splice_index: The device splice index set by user-space.
200 */
201struct vmw_ctx_bindinfo_uav {
202 struct vmw_ctx_bindinfo_view views[SVGA3D_MAX_UAVIEWS];
203 uint32 index;
204};
205
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700206extern void vmw_binding_add(struct vmw_ctx_binding_state *cbs,
207 const struct vmw_ctx_bindinfo *ci,
208 u32 shader_slot, u32 slot);
Deepak Rawat5e8ec0d2018-12-13 13:51:08 -0800209extern void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs,
210 uint32 slot, uint32 splice_index);
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700211extern void
212vmw_binding_state_commit(struct vmw_ctx_binding_state *to,
213 struct vmw_ctx_binding_state *from);
214extern void vmw_binding_res_list_kill(struct list_head *head);
215extern void vmw_binding_res_list_scrub(struct list_head *head);
216extern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs);
217extern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs);
218extern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs);
219extern struct vmw_ctx_binding_state *
220vmw_binding_state_alloc(struct vmw_private *dev_priv);
221extern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs);
222extern struct list_head *
223vmw_binding_state_list(struct vmw_ctx_binding_state *cbs);
224extern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs);
Thomas Hellstroma9f58c42019-02-20 08:21:26 +0100225extern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type);
226
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700227
228#endif