// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright 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. *
**************************************************************************/ /* * This file implements the vmwgfx context binding manager, * The sole reason for having to use this code is that vmware guest * backed contexts can be swapped out to their backing mobs by the device * at any time, also swapped in at any time. At swapin time, the device * validates the context bindings to make sure they point to valid resources. * It's this outside-of-drawcall validation (that can happen at any time), * that makes this code necessary. * * We therefore need to kill any context bindings pointing to a resource * when the resource is swapped out. Furthermore, if the vmwgfx driver has * swapped out the context we can't swap it in again to kill bindings because * of backing mob reservation lockdep violations, so as part of * context swapout, also kill all bindings of a context, so that they are * already killed if a resource to which a binding points * needs to be swapped out. * * Note that a resource can be pointed to by bindings from multiple contexts, * Therefore we can't easily protect this data by a per context mutex * (unless we use deadlock-safe WW mutexes). So we use a global binding_mutex * to protect all binding manager data. * * Finally, any association between a context and a global resource * (surface, shader or even DX query) is conceptually a context binding that * needs to be tracked by this code.
*/
/** * struct vmw_ctx_binding_state - per context binding state * * @dev_priv: Pointer to device private structure. * @list: linked list of individual active bindings. * @render_targets: Render target bindings. * @texture_units: Texture units bindings. * @ds_view: Depth-stencil view binding. * @so_targets: StreamOutput target bindings. * @vertex_buffers: Vertex buffer bindings. * @index_buffer: Index buffer binding. * @per_shader: Per shader-type bindings. * @ua_views: UAV bindings. * @so_state: StreamOutput bindings. * @dirty: Bitmap tracking per binding-type changes that have not yet * been emitted to the device. * @dirty_vb: Bitmap tracking individual vertex buffer binding changes that * have not yet been emitted to the device. * @bind_cmd_buffer: Scratch space used to construct binding commands. * @bind_cmd_count: Number of binding command data entries in @bind_cmd_buffer * @bind_first_slot: Used together with @bind_cmd_buffer to indicate the * device binding slot of the first command data entry in @bind_cmd_buffer. * * Note that this structure also provides storage space for the individual * struct vmw_ctx_binding objects, so that no dynamic allocation is needed * for individual bindings. *
*/ struct vmw_ctx_binding_state { struct vmw_private *dev_priv; struct list_head list; struct vmw_ctx_bindinfo_view render_targets[SVGA3D_RT_MAX]; struct vmw_ctx_bindinfo_tex texture_units[SVGA3D_NUM_TEXTURE_UNITS]; struct vmw_ctx_bindinfo_view ds_view; struct vmw_ctx_bindinfo_so_target so_targets[SVGA3D_DX_MAX_SOTARGETS]; struct vmw_ctx_bindinfo_vb vertex_buffers[SVGA3D_DX_MAX_VERTEXBUFFERS]; struct vmw_ctx_bindinfo_ib index_buffer; struct vmw_dx_shader_bindings per_shader[SVGA3D_NUM_SHADERTYPE]; struct vmw_ctx_bindinfo_uav ua_views[VMW_MAX_UAV_BIND_TYPE]; struct vmw_ctx_bindinfo_so so_state;
/** * struct vmw_binding_info - Per binding type information for the binding * manager * * @size: The size of the struct binding derived from a struct vmw_ctx_bindinfo. * @offsets: array[shader_slot] of offsets to the array[slot] * of struct bindings for the binding type. * @scrub_func: Pointer to the scrub function for this binding type. * * Holds static information to help optimize the binding manager and avoid * an excessive amount of switch statements.
*/ struct vmw_binding_info {
size_t size; const size_t *offsets;
vmw_scrub_func scrub_func;
};
/** * vmw_cbs_context - Return a pointer to the context resource of a * context binding state tracker. * * @cbs: The context binding state tracker. * * Provided there are any active bindings, this function will return an * unreferenced pointer to the context resource that owns the context * binding state tracker. If there are no active bindings, this function * will return NULL. Note that the caller must somehow ensure that a reference * is held on the context resource prior to calling this function.
*/ staticconststruct vmw_resource *
vmw_cbs_context(conststruct vmw_ctx_binding_state *cbs)
{ if (list_empty(&cbs->list)) return NULL;
/** * vmw_binding_loc - determine the struct vmw_ctx_bindinfo slot location. * * @cbs: Pointer to a struct vmw_ctx_binding state which holds the slot. * @bt: The binding type. * @shader_slot: The shader slot of the binding. If none, then set to 0. * @slot: The slot of the binding.
*/ staticstruct vmw_ctx_bindinfo *
vmw_binding_loc(struct vmw_ctx_binding_state *cbs, enum vmw_ctx_binding_type bt, u32 shader_slot, u32 slot)
{ conststruct vmw_binding_info *b = &vmw_binding_infos[bt];
size_t offset = b->offsets[shader_slot] + b->size*slot;
return (struct vmw_ctx_bindinfo *)((u8 *) cbs + offset);
}
/** * vmw_binding_drop: Stop tracking a context binding * * @bi: Pointer to binding tracker storage. * * Stops tracking a context binding, and re-initializes its storage. * Typically used when the context binding is replaced with a binding to * another (or the same, for that matter) resource.
*/ staticvoid vmw_binding_drop(struct vmw_ctx_bindinfo *bi)
{
list_del(&bi->ctx_list); if (!list_empty(&bi->res_list))
list_del(&bi->res_list);
bi->ctx = NULL;
}
/** * vmw_binding_add: Start tracking a context binding * * @cbs: Pointer to the context binding state tracker. * @bi: Information about the binding to track. * @shader_slot: The shader slot of the binding. * @slot: The slot of the binding. * * Starts tracking the binding in the context binding * state structure @cbs.
*/ void vmw_binding_add(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_bindinfo *bi,
u32 shader_slot, u32 slot)
{ struct vmw_ctx_bindinfo *loc =
vmw_binding_loc(cbs, bi->bt, shader_slot, slot); conststruct vmw_binding_info *b = &vmw_binding_infos[bi->bt];
/** * vmw_binding_cb_offset_update: Update the offset of a cb binding * * @cbs: Pointer to the context binding state tracker. * @shader_slot: The shader slot of the binding. * @slot: The slot of the binding. * @offsetInBytes: The new offset of the binding. * * Updates the offset of an existing cb binding in the context binding * state structure @cbs.
*/ void vmw_binding_cb_offset_update(struct vmw_ctx_binding_state *cbs,
u32 shader_slot, u32 slot, u32 offsetInBytes)
{ struct vmw_ctx_bindinfo *loc =
vmw_binding_loc(cbs, vmw_ctx_binding_cb, shader_slot, slot); struct vmw_ctx_bindinfo_cb *loc_cb =
(struct vmw_ctx_bindinfo_cb *)((u8 *) loc);
loc_cb->offset = offsetInBytes;
}
/** * vmw_binding_add_uav_index - Add UAV index for tracking. * @cbs: Pointer to the context binding state tracker. * @slot: UAV type to which bind this index. * @index: The splice index to track.
*/ void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs, uint32 slot,
uint32 index)
{
cbs->ua_views[slot].index = index;
}
/** * vmw_binding_transfer: Transfer a context binding tracking entry. * * @cbs: Pointer to the persistent context binding state tracker. * @from: Staged binding info built during execbuf * @bi: Information about the binding to track. *
*/ staticvoid vmw_binding_transfer(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_binding_state *from, conststruct vmw_ctx_bindinfo *bi)
{
size_t offset = (unsignedlong)bi - (unsignedlong)from; struct vmw_ctx_bindinfo *loc = (struct vmw_ctx_bindinfo *)
((unsignedlong) cbs + offset);
/** * vmw_binding_state_kill - Kill all bindings associated with a * struct vmw_ctx_binding state structure, and re-initialize the structure. * * @cbs: Pointer to the context binding state tracker. * * Emits commands to scrub all bindings associated with the * context binding state tracker. Then re-initializes the whole structure.
*/ void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs)
{ struct vmw_ctx_bindinfo *entry, *next;
/** * vmw_binding_state_scrub - Scrub all bindings associated with a * struct vmw_ctx_binding state structure. * * @cbs: Pointer to the context binding state tracker. * * Emits commands to scrub all bindings associated with the * context binding state tracker.
*/ void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs)
{ struct vmw_ctx_bindinfo *entry;
/** * vmw_binding_res_list_kill - Kill all bindings on a * resource binding list * * @head: list head of resource binding list * * Kills all bindings associated with a specific resource. Typically * called before the resource is destroyed.
*/ void vmw_binding_res_list_kill(struct list_head *head)
{ struct vmw_ctx_bindinfo *entry, *next;
/** * vmw_binding_res_list_scrub - Scrub all bindings on a * resource binding list * * @head: list head of resource binding list * * Scrub all bindings associated with a specific resource. Typically * called before the resource is evicted.
*/ void vmw_binding_res_list_scrub(struct list_head *head)
{ struct vmw_ctx_bindinfo *entry;
/** * vmw_binding_state_commit - Commit staged binding info * * @to: Staged binding info area to copy into to. * @from: Staged binding info built during execbuf. * * Transfers binding info from a temporary structure * (typically used by execbuf) to the persistent * structure in the context. This can be done once commands have been * submitted to hardware
*/ void vmw_binding_state_commit(struct vmw_ctx_binding_state *to, struct vmw_ctx_binding_state *from)
{ struct vmw_ctx_bindinfo *entry, *next;
/* Also transfer uav splice indices */
to->ua_views[0].index = from->ua_views[0].index;
to->ua_views[1].index = from->ua_views[1].index;
}
/** * vmw_binding_rebind_all - Rebind all scrubbed bindings of a context * * @cbs: Pointer to the context binding state tracker. * * Walks through the context binding list and rebinds all scrubbed * resources.
*/ int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs)
{ struct vmw_ctx_bindinfo *entry; int ret;
list_for_each_entry(entry, &cbs->list, ctx_list) { if (likely(!entry->scrubbed)) continue;
if ((entry->res == NULL || entry->res->id ==
SVGA3D_INVALID_ID)) continue;
ret = vmw_binding_infos[entry->bt].scrub_func(entry, true); if (unlikely(ret != 0)) return ret;
entry->scrubbed = false;
}
return vmw_binding_emit_dirty(cbs);
}
/** * vmw_binding_scrub_shader - scrub a shader binding from a context. * * @bi: single binding information. * @rebind: Whether to issue a bind instead of scrub command.
*/ staticint vmw_binding_scrub_shader(struct vmw_ctx_bindinfo *bi, bool rebind)
{ struct vmw_ctx_bindinfo_shader *binding =
container_of(bi, typeof(*binding), bi); struct vmw_private *dev_priv = bi->ctx->dev_priv; struct {
SVGA3dCmdHeader header;
SVGA3dCmdSetShader body;
} *cmd;
cmd = VMW_CMD_RESERVE(dev_priv, sizeof(*cmd)); if (unlikely(cmd == NULL)) return -ENOMEM;
/** * vmw_binding_scrub_texture - scrub a texture binding from a context. * * @bi: single binding information. * @rebind: Whether to issue a bind instead of scrub command. * * TODO: Possibly complement this function with a function that takes * a list of texture bindings and combines them to a single command.
*/ staticint vmw_binding_scrub_texture(struct vmw_ctx_bindinfo *bi, bool rebind)
{ struct vmw_ctx_bindinfo_tex *binding =
container_of(bi, typeof(*binding), bi); struct vmw_private *dev_priv = bi->ctx->dev_priv; struct {
SVGA3dCmdHeader header; struct {
SVGA3dCmdSetTextureState c;
SVGA3dTextureState s1;
} body;
} *cmd;
cmd = VMW_CMD_RESERVE(dev_priv, sizeof(*cmd)); if (unlikely(cmd == NULL)) return -ENOMEM;
/** * vmw_collect_view_ids - Build view id data for a view binding command * without checking which bindings actually need to be emitted * * @cbs: Pointer to the context's struct vmw_ctx_binding_state * @biv: Pointer to where the binding info array is stored in @cbs * @max_num: Maximum number of entries in the @bi array. * * Scans the @bi array for bindings and builds a buffer of view id data. * Stops at the first non-existing binding in the @bi array. * On output, @cbs->bind_cmd_count contains the number of bindings to be * emitted, @cbs->bind_first_slot is set to zero, and @cbs->bind_cmd_buffer * contains the command data.
*/ staticvoid vmw_collect_view_ids(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_bindinfo_view *biv,
u32 max_num)
{ unsignedlong i;
/** * vmw_collect_dirty_view_ids - Build view id data for a view binding command * * @cbs: Pointer to the context's struct vmw_ctx_binding_state * @bi: Pointer to where the binding info array is stored in @cbs * @dirty: Bitmap indicating which bindings need to be emitted. * @max_num: Maximum number of entries in the @bi array. * * Scans the @bi array for bindings that need to be emitted and * builds a buffer of view id data. * On output, @cbs->bind_cmd_count contains the number of bindings to be * emitted, @cbs->bind_first_slot indicates the index of the first emitted * binding, and @cbs->bind_cmd_buffer contains the command data.
*/ staticvoid vmw_collect_dirty_view_ids(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_bindinfo *bi, unsignedlong *dirty,
u32 max_num)
{ conststruct vmw_ctx_bindinfo_view *biv =
container_of(bi, struct vmw_ctx_bindinfo_view, bi); unsignedlong i, next_bit;
/** * vmw_collect_so_targets - Build SVGA3dSoTarget data for a binding command * without checking which bindings actually need to be emitted * * @cbs: Pointer to the context's struct vmw_ctx_binding_state * @biso: Pointer to where the binding info array is stored in @cbs * @max_num: Maximum number of entries in the @bi array. * * Scans the @bi array for bindings and builds a buffer of SVGA3dSoTarget data. * Stops at the first non-existing binding in the @bi array. * On output, @cbs->bind_cmd_count contains the number of bindings to be * emitted, @cbs->bind_first_slot is set to zero, and @cbs->bind_cmd_buffer * contains the command data.
*/ staticvoid vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_bindinfo_so_target *biso,
u32 max_num)
{ unsignedlong i;
SVGA3dSoTarget *so_buffer = (SVGA3dSoTarget *) cbs->bind_cmd_buffer;
/** * vmw_binding_emit_dirty_ps - Issue delayed per shader binding commands * * @cbs: Pointer to the context's struct vmw_ctx_binding_state *
*/ staticint vmw_binding_emit_dirty_ps(struct vmw_ctx_binding_state *cbs)
{ struct vmw_dx_shader_bindings *sb = &cbs->per_shader[0];
u32 i; int ret;
for (i = 0; i < SVGA3D_NUM_SHADERTYPE_DX10; ++i, ++sb) { if (!test_bit(VMW_BINDING_PS_SR_BIT, &sb->dirty)) continue;
ret = vmw_emit_set_sr(cbs, i); if (ret) break;
__clear_bit(VMW_BINDING_PS_SR_BIT, &sb->dirty);
}
return 0;
}
/** * vmw_collect_dirty_vbs - Build SVGA3dVertexBuffer data for a * SVGA3dCmdDXSetVertexBuffers command * * @cbs: Pointer to the context's struct vmw_ctx_binding_state * @bi: Pointer to where the binding info array is stored in @cbs * @dirty: Bitmap indicating which bindings need to be emitted. * @max_num: Maximum number of entries in the @bi array. * * Scans the @bi array for bindings that need to be emitted and * builds a buffer of SVGA3dVertexBuffer data. * On output, @cbs->bind_cmd_count contains the number of bindings to be * emitted, @cbs->bind_first_slot indicates the index of the first emitted * binding, and @cbs->bind_cmd_buffer contains the command data.
*/ staticvoid vmw_collect_dirty_vbs(struct vmw_ctx_binding_state *cbs, conststruct vmw_ctx_bindinfo *bi, unsignedlong *dirty,
u32 max_num)
{ conststruct vmw_ctx_bindinfo_vb *biv =
container_of(bi, struct vmw_ctx_bindinfo_vb, bi); unsignedlong i, next_bit;
SVGA3dVertexBuffer *vbs = (SVGA3dVertexBuffer *) &cbs->bind_cmd_buffer;
/** * vmw_binding_emit_dirty - Issue delayed binding commands * * @cbs: Pointer to the context's struct vmw_ctx_binding_state * * This function issues the delayed binding commands that arise from * previous scrub / unscrub calls. These binding commands are typically * commands that batch a number of bindings and therefore it makes sense * to delay them.
*/ staticint vmw_binding_emit_dirty(struct vmw_ctx_binding_state *cbs)
{ int ret = 0; unsignedlong hit = 0;
while ((hit = find_next_bit(&cbs->dirty, VMW_BINDING_NUM_BITS, hit))
< VMW_BINDING_NUM_BITS) {
switch (hit) { case VMW_BINDING_RT_BIT:
ret = vmw_emit_set_rt(cbs); break; case VMW_BINDING_PS_BIT:
ret = vmw_binding_emit_dirty_ps(cbs); break; case VMW_BINDING_SO_T_BIT:
ret = vmw_emit_set_so_target(cbs); break; case VMW_BINDING_VB_BIT:
ret = vmw_emit_set_vb(cbs); break; case VMW_BINDING_UAV_BIT:
ret = vmw_emit_set_uav(cbs); break; case VMW_BINDING_CS_UAV_BIT:
ret = vmw_emit_set_cs_uav(cbs); break; default:
BUG();
} if (ret) return ret;
__clear_bit(hit, &cbs->dirty);
hit++;
}
return 0;
}
/** * vmw_binding_scrub_sr - Schedule a dx shaderresource binding * scrub from a context * * @bi: single binding information. * @rebind: Whether to issue a bind instead of scrub command.
*/ staticint vmw_binding_scrub_sr(struct vmw_ctx_bindinfo *bi, bool rebind)
{ struct vmw_ctx_bindinfo_view *biv =
container_of(bi, struct vmw_ctx_bindinfo_view, bi); struct vmw_ctx_binding_state *cbs =
vmw_context_binding_state(bi->ctx);
/** * vmw_binding_state_alloc - Allocate a struct vmw_ctx_binding_state. * * @dev_priv: Pointer to a device private structure. * * Returns a pointer to a newly allocated struct or an error pointer on error.
*/ struct vmw_ctx_binding_state *
vmw_binding_state_alloc(struct vmw_private *dev_priv)
{ struct vmw_ctx_binding_state *cbs;
cbs = vzalloc(sizeof(*cbs)); if (!cbs) { return ERR_PTR(-ENOMEM);
}
/** * vmw_binding_state_free - Free a struct vmw_ctx_binding_state. * * @cbs: Pointer to the struct vmw_ctx_binding_state to be freed.
*/ void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs)
{
vfree(cbs);
}
/** * vmw_binding_state_list - Get the binding list of a * struct vmw_ctx_binding_state * * @cbs: Pointer to the struct vmw_ctx_binding_state * * Returns the binding list which can be used to traverse through the bindings * and access the resource information of all bindings.
*/ struct list_head *vmw_binding_state_list(struct vmw_ctx_binding_state *cbs)
{ return &cbs->list;
}
/** * vmw_binding_state_reset - clear a struct vmw_ctx_binding_state * * @cbs: Pointer to the struct vmw_ctx_binding_state to be cleared * * Drops all bindings registered in @cbs. No device binding actions are * performed.
*/ void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs)
{ struct vmw_ctx_bindinfo *entry, *next;
/** * vmw_binding_dirtying - Return whether a binding type is dirtying its resource * @binding_type: The binding type * * Each time a resource is put on the validation list as the result of a * context binding referencing it, we need to determine whether that resource * will be dirtied (written to by the GPU) as a result of the corresponding * GPU operation. Currently rendertarget-, depth-stencil-, stream-output-target * and unordered access view bindings are capable of dirtying its resource. * * Return: Whether the binding type dirties the resource its binding points to.
*/
u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type)
{ static u32 is_binding_dirtying[vmw_ctx_binding_max] = {
[vmw_ctx_binding_rt] = VMW_RES_DIRTY_SET,
[vmw_ctx_binding_dx_rt] = VMW_RES_DIRTY_SET,
[vmw_ctx_binding_ds] = VMW_RES_DIRTY_SET,
[vmw_ctx_binding_so_target] = VMW_RES_DIRTY_SET,
[vmw_ctx_binding_uav] = VMW_RES_DIRTY_SET,
[vmw_ctx_binding_cs_uav] = VMW_RES_DIRTY_SET,
};
/* Review this function as new bindings are added. */
BUILD_BUG_ON(vmw_ctx_binding_max != 14); return is_binding_dirtying[binding_type];
}
/* * This function is unused at run-time, and only used to hold various build * asserts important for code optimization assumptions.
*/ staticvoid vmw_binding_build_asserts(void)
{
BUILD_BUG_ON(SVGA3D_NUM_SHADERTYPE_DX10 != 3);
BUILD_BUG_ON(SVGA3D_DX_MAX_RENDER_TARGETS > SVGA3D_RT_MAX);
BUILD_BUG_ON(sizeof(uint32) != sizeof(u32));
/* * struct vmw_ctx_binding_state::bind_cmd_buffer is used for various * view id arrays.
*/
BUILD_BUG_ON(VMW_MAX_VIEW_BINDINGS < SVGA3D_RT_MAX);
BUILD_BUG_ON(VMW_MAX_VIEW_BINDINGS < SVGA3D_DX_MAX_SRVIEWS);
BUILD_BUG_ON(VMW_MAX_VIEW_BINDINGS < SVGA3D_DX_MAX_CONSTBUFFERS);
/* * struct vmw_ctx_binding_state::bind_cmd_buffer is used for * u32 view ids, SVGA3dSoTargets and SVGA3dVertexBuffers
*/
BUILD_BUG_ON(SVGA3D_DX_MAX_SOTARGETS*sizeof(SVGA3dSoTarget) >
VMW_MAX_VIEW_BINDINGS*sizeof(u32));
BUILD_BUG_ON(SVGA3D_DX_MAX_VERTEXBUFFERS*sizeof(SVGA3dVertexBuffer) >
VMW_MAX_VIEW_BINDINGS*sizeof(u32));
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.72 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.