162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */
262306a36Sopenharmony_ci/**************************************************************************
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright 2015 VMware, Inc., Palo Alto, CA., USA
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
762306a36Sopenharmony_ci * copy of this software and associated documentation files (the
862306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
962306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
1062306a36Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
1162306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
1262306a36Sopenharmony_ci * the following conditions:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the
1562306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
1662306a36Sopenharmony_ci * of the Software.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1962306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2062306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
2162306a36Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
2262306a36Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2362306a36Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2462306a36Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci **************************************************************************/
2762306a36Sopenharmony_ci#ifndef _VMWGFX_BINDING_H_
2862306a36Sopenharmony_ci#define _VMWGFX_BINDING_H_
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#include <linux/list.h>
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#include "device_include/svga3d_reg.h"
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define VMW_MAX_VIEW_BINDINGS 128
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define VMW_MAX_UAV_BIND_TYPE 2
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistruct vmw_private;
3962306a36Sopenharmony_cistruct vmw_ctx_binding_state;
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*
4262306a36Sopenharmony_ci * enum vmw_ctx_binding_type - abstract resource to context binding types
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_cienum vmw_ctx_binding_type {
4562306a36Sopenharmony_ci	vmw_ctx_binding_shader,
4662306a36Sopenharmony_ci	vmw_ctx_binding_rt,
4762306a36Sopenharmony_ci	vmw_ctx_binding_tex,
4862306a36Sopenharmony_ci	vmw_ctx_binding_cb,
4962306a36Sopenharmony_ci	vmw_ctx_binding_dx_shader,
5062306a36Sopenharmony_ci	vmw_ctx_binding_dx_rt,
5162306a36Sopenharmony_ci	vmw_ctx_binding_sr,
5262306a36Sopenharmony_ci	vmw_ctx_binding_ds,
5362306a36Sopenharmony_ci	vmw_ctx_binding_so_target,
5462306a36Sopenharmony_ci	vmw_ctx_binding_vb,
5562306a36Sopenharmony_ci	vmw_ctx_binding_ib,
5662306a36Sopenharmony_ci	vmw_ctx_binding_uav,
5762306a36Sopenharmony_ci	vmw_ctx_binding_cs_uav,
5862306a36Sopenharmony_ci	vmw_ctx_binding_so,
5962306a36Sopenharmony_ci	vmw_ctx_binding_max
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/**
6362306a36Sopenharmony_ci * struct vmw_ctx_bindinfo - single binding metadata
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * @ctx_list: List head for the context's list of bindings.
6662306a36Sopenharmony_ci * @res_list: List head for a resource's list of bindings.
6762306a36Sopenharmony_ci * @ctx: Non-refcounted pointer to the context that owns the binding. NULL
6862306a36Sopenharmony_ci * indicates no binding present.
6962306a36Sopenharmony_ci * @res: Non-refcounted pointer to the resource the binding points to. This
7062306a36Sopenharmony_ci * is typically a surface or a view.
7162306a36Sopenharmony_ci * @bt: Binding type.
7262306a36Sopenharmony_ci * @scrubbed: Whether the binding has been scrubbed from the context.
7362306a36Sopenharmony_ci */
7462306a36Sopenharmony_cistruct vmw_ctx_bindinfo {
7562306a36Sopenharmony_ci	struct list_head ctx_list;
7662306a36Sopenharmony_ci	struct list_head res_list;
7762306a36Sopenharmony_ci	struct vmw_resource *ctx;
7862306a36Sopenharmony_ci	struct vmw_resource *res;
7962306a36Sopenharmony_ci	enum vmw_ctx_binding_type bt;
8062306a36Sopenharmony_ci	bool scrubbed;
8162306a36Sopenharmony_ci};
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/**
8462306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_tex - texture stage binding metadata
8562306a36Sopenharmony_ci *
8662306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
8762306a36Sopenharmony_ci * @texture_stage: Device data used to reconstruct binding command.
8862306a36Sopenharmony_ci */
8962306a36Sopenharmony_cistruct vmw_ctx_bindinfo_tex {
9062306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
9162306a36Sopenharmony_ci	uint32 texture_stage;
9262306a36Sopenharmony_ci};
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/**
9562306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_shader - Shader binding metadata
9662306a36Sopenharmony_ci *
9762306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
9862306a36Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command.
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_cistruct vmw_ctx_bindinfo_shader {
10162306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
10262306a36Sopenharmony_ci	SVGA3dShaderType shader_slot;
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci/**
10662306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata
10762306a36Sopenharmony_ci *
10862306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
10962306a36Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command.
11062306a36Sopenharmony_ci * @offset: Device data used to reconstruct binding command.
11162306a36Sopenharmony_ci * @size: Device data used to reconstruct binding command.
11262306a36Sopenharmony_ci * @slot: Device data used to reconstruct binding command.
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_cistruct vmw_ctx_bindinfo_cb {
11562306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
11662306a36Sopenharmony_ci	SVGA3dShaderType shader_slot;
11762306a36Sopenharmony_ci	uint32 offset;
11862306a36Sopenharmony_ci	uint32 size;
11962306a36Sopenharmony_ci	uint32 slot;
12062306a36Sopenharmony_ci};
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/**
12362306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_view - View binding metadata
12462306a36Sopenharmony_ci *
12562306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
12662306a36Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command.
12762306a36Sopenharmony_ci * @slot: Device data used to reconstruct binding command.
12862306a36Sopenharmony_ci */
12962306a36Sopenharmony_cistruct vmw_ctx_bindinfo_view {
13062306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
13162306a36Sopenharmony_ci	SVGA3dShaderType shader_slot;
13262306a36Sopenharmony_ci	uint32 slot;
13362306a36Sopenharmony_ci};
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/**
13662306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_so_target - StreamOutput binding metadata
13762306a36Sopenharmony_ci *
13862306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
13962306a36Sopenharmony_ci * @offset: Device data used to reconstruct binding command.
14062306a36Sopenharmony_ci * @size: Device data used to reconstruct binding command.
14162306a36Sopenharmony_ci * @slot: Device data used to reconstruct binding command.
14262306a36Sopenharmony_ci */
14362306a36Sopenharmony_cistruct vmw_ctx_bindinfo_so_target {
14462306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
14562306a36Sopenharmony_ci	uint32 offset;
14662306a36Sopenharmony_ci	uint32 size;
14762306a36Sopenharmony_ci	uint32 slot;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/**
15162306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata
15262306a36Sopenharmony_ci *
15362306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
15462306a36Sopenharmony_ci * @offset: Device data used to reconstruct binding command.
15562306a36Sopenharmony_ci * @stride: Device data used to reconstruct binding command.
15662306a36Sopenharmony_ci * @slot: Device data used to reconstruct binding command.
15762306a36Sopenharmony_ci */
15862306a36Sopenharmony_cistruct vmw_ctx_bindinfo_vb {
15962306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
16062306a36Sopenharmony_ci	uint32 offset;
16162306a36Sopenharmony_ci	uint32 stride;
16262306a36Sopenharmony_ci	uint32 slot;
16362306a36Sopenharmony_ci};
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci/**
16662306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata
16762306a36Sopenharmony_ci *
16862306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
16962306a36Sopenharmony_ci * @offset: Device data used to reconstruct binding command.
17062306a36Sopenharmony_ci * @format: Device data used to reconstruct binding command.
17162306a36Sopenharmony_ci */
17262306a36Sopenharmony_cistruct vmw_ctx_bindinfo_ib {
17362306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
17462306a36Sopenharmony_ci	uint32 offset;
17562306a36Sopenharmony_ci	uint32 format;
17662306a36Sopenharmony_ci};
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci/**
17962306a36Sopenharmony_ci * struct vmw_dx_shader_bindings - per shader type context binding state
18062306a36Sopenharmony_ci *
18162306a36Sopenharmony_ci * @shader: The shader binding for this shader type
18262306a36Sopenharmony_ci * @const_buffer: Const buffer bindings for this shader type.
18362306a36Sopenharmony_ci * @shader_res: Shader resource view bindings for this shader type.
18462306a36Sopenharmony_ci * @dirty_sr: Bitmap tracking individual shader resource bindings changes
18562306a36Sopenharmony_ci * that have not yet been emitted to the device.
18662306a36Sopenharmony_ci * @dirty: Bitmap tracking per-binding type binding changes that have not
18762306a36Sopenharmony_ci * yet been emitted to the device.
18862306a36Sopenharmony_ci */
18962306a36Sopenharmony_cistruct vmw_dx_shader_bindings {
19062306a36Sopenharmony_ci	struct vmw_ctx_bindinfo_shader shader;
19162306a36Sopenharmony_ci	struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS];
19262306a36Sopenharmony_ci	struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS];
19362306a36Sopenharmony_ci	DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS);
19462306a36Sopenharmony_ci	unsigned long dirty;
19562306a36Sopenharmony_ci};
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci/**
19862306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_uav - UAV context binding state.
19962306a36Sopenharmony_ci * @views: UAV view bindings.
20062306a36Sopenharmony_ci * @splice_index: The device splice index set by user-space.
20162306a36Sopenharmony_ci */
20262306a36Sopenharmony_cistruct vmw_ctx_bindinfo_uav {
20362306a36Sopenharmony_ci	struct vmw_ctx_bindinfo_view views[SVGA3D_DX11_1_MAX_UAVIEWS];
20462306a36Sopenharmony_ci	uint32 index;
20562306a36Sopenharmony_ci};
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci/**
20862306a36Sopenharmony_ci * struct vmw_ctx_bindinfo_so - Stream output binding metadata.
20962306a36Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from.
21062306a36Sopenharmony_ci * @slot: Device data used to reconstruct binding command.
21162306a36Sopenharmony_ci */
21262306a36Sopenharmony_cistruct vmw_ctx_bindinfo_so {
21362306a36Sopenharmony_ci	struct vmw_ctx_bindinfo bi;
21462306a36Sopenharmony_ci	uint32 slot;
21562306a36Sopenharmony_ci};
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ciextern void vmw_binding_add(struct vmw_ctx_binding_state *cbs,
21862306a36Sopenharmony_ci			    const struct vmw_ctx_bindinfo *ci,
21962306a36Sopenharmony_ci			    u32 shader_slot, u32 slot);
22062306a36Sopenharmony_ciextern void vmw_binding_cb_offset_update(struct vmw_ctx_binding_state *cbs,
22162306a36Sopenharmony_ci					 u32 shader_slot, u32 slot, u32 offsetInBytes);
22262306a36Sopenharmony_ciextern void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs,
22362306a36Sopenharmony_ci				      uint32 slot, uint32 splice_index);
22462306a36Sopenharmony_ciextern void
22562306a36Sopenharmony_civmw_binding_state_commit(struct vmw_ctx_binding_state *to,
22662306a36Sopenharmony_ci			 struct vmw_ctx_binding_state *from);
22762306a36Sopenharmony_ciextern void vmw_binding_res_list_kill(struct list_head *head);
22862306a36Sopenharmony_ciextern void vmw_binding_res_list_scrub(struct list_head *head);
22962306a36Sopenharmony_ciextern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs);
23062306a36Sopenharmony_ciextern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs);
23162306a36Sopenharmony_ciextern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs);
23262306a36Sopenharmony_ciextern struct vmw_ctx_binding_state *
23362306a36Sopenharmony_civmw_binding_state_alloc(struct vmw_private *dev_priv);
23462306a36Sopenharmony_ciextern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs);
23562306a36Sopenharmony_ciextern struct list_head *
23662306a36Sopenharmony_civmw_binding_state_list(struct vmw_ctx_binding_state *cbs);
23762306a36Sopenharmony_ciextern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs);
23862306a36Sopenharmony_ciextern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type);
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci#endif
242