vk/runtime: add EXT DGC layout handling

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31386>
This commit is contained in:
Mike Blumenkrantz 2024-05-21 10:43:29 -04:00 committed by Marge Bot
parent b24c340cee
commit 8097a8e81e
3 changed files with 287 additions and 0 deletions

View file

@ -22,6 +22,7 @@ vulkan_lite_runtime_files = files(
'vk_descriptors.c',
'vk_descriptor_update_template.c',
'vk_device.c',
'vk_device_generated_commands.c',
'vk_device_memory.c',
'vk_fence.c',
'vk_framebuffer.c',

View file

@ -0,0 +1,177 @@
/*
* Copyright © 2024 Valve Corporation
*
* 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, sublicense,
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#include "vk_alloc.h"
#include "vk_device.h"
#include "vk_device_generated_commands.h"
#include "vk_log.h"
#include "vk_util.h"
#include "util/compiler.h"
void *
vk_indirect_command_layout_create(struct vk_device *device,
const VkIndirectCommandsLayoutCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
size_t struct_size)
{
struct vk_indirect_command_layout *elayout;
uint32_t n_pc_layouts = 0, n_vb_layouts = 0;
for (unsigned i = 0; i < pCreateInfo->tokenCount; i++) {
const VkIndirectCommandsLayoutTokenEXT *token = &pCreateInfo->pTokens[i];
switch (token->type) {
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_EXT:
n_pc_layouts++;
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_EXT:
n_vb_layouts++;
break;
default:
break;
}
}
VK_MULTIALLOC(ma);
vk_multialloc_add_size_align(&ma, (void **)&elayout, struct_size, 8);
VK_MULTIALLOC_DECL(&ma, struct vk_indirect_command_push_constant_layout, pc_layouts, n_pc_layouts);
VK_MULTIALLOC_DECL(&ma, struct vk_indirect_command_vertex_layout, vb_layouts, n_vb_layouts);
elayout = vk_multialloc_zalloc2(&ma, &device->alloc, pAllocator,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!elayout)
return NULL;
vk_object_base_init(device, &elayout->base, VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_EXT);
elayout->pc_layouts = pc_layouts;
elayout->vb_layouts = vb_layouts;
for (unsigned i = 0; i < pCreateInfo->tokenCount; i++) {
const VkIndirectCommandsLayoutTokenEXT *token = &pCreateInfo->pTokens[i];
switch (token->type) {
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_EXECUTION_SET_EXT:
elayout->is_shaders = token->data.pExecutionSet->type == VK_INDIRECT_EXECUTION_SET_INFO_TYPE_SHADER_OBJECTS_EXT;
elayout->ies_src_offset_B = token->offset;
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_IES);
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_EXT:
assert(token->data.pVertexBuffer->vertexBindingUnit < 32);
elayout->vertex_bindings |= BITFIELD_BIT(token->data.pVertexBuffer->vertexBindingUnit);
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_VB);
vb_layouts[elayout->n_vb_layouts++] = (struct vk_indirect_command_vertex_layout) {
.binding = token->data.pVertexBuffer->vertexBindingUnit,
.src_offset_B = token->offset,
};
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_INDEX_BUFFER_EXT:
elayout->index_mode_is_dx = token->data.pIndexBuffer->mode == VK_INDIRECT_COMMANDS_INPUT_MODE_DXGI_INDEX_BUFFER_EXT;
elayout->index_src_offset_B = token->offset;
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_IB);
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_PC);
pc_layouts[elayout->n_pc_layouts++] = (struct vk_indirect_command_push_constant_layout) {
.stages = token->data.pPushConstant->updateRange.stageFlags,
.dst_offset_B = token->data.pPushConstant->updateRange.offset,
.src_offset_B = token->offset,
.size_B = token->data.pPushConstant->updateRange.size,
};
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_SEQUENCE_INDEX_EXT:
assert(token->data.pPushConstant->updateRange.size == 4);
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_SI);
elayout->si_layout = (struct vk_indirect_command_push_constant_layout) {
.stages = token->data.pPushConstant->updateRange.stageFlags,
.dst_offset_B = token->data.pPushConstant->updateRange.offset,
.src_offset_B = token->offset,
.size_B = token->data.pPushConstant->updateRange.size,
};
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_COUNT_EXT:
elayout->draw_count = true;
FALLTHROUGH;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_DRAW);
elayout->draw_src_offset_B = token->offset;
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_COUNT_EXT:
elayout->draw_count = true;
FALLTHROUGH;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_DRAW_INDEXED);
elayout->draw_src_offset_B = token->offset;
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_MESH_TASKS_COUNT_NV_EXT:
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_MESH_TASKS_COUNT_EXT:
elayout->draw_count = true;
FALLTHROUGH;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_MESH_TASKS_NV_EXT:
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_MESH_TASKS_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_DRAW_MESH);
elayout->draw_src_offset_B = token->offset;
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_DISPATCH);
elayout->dispatch_src_offset_B = token->offset;
break;
case VK_INDIRECT_COMMANDS_TOKEN_TYPE_TRACE_RAYS2_EXT:
elayout->dgc_info |= BITFIELD_BIT(MESA_VK_DGC_RT);
elayout->dispatch_src_offset_B = token->offset;
break;
default: break;
}
}
if (elayout->dgc_info & (BITFIELD_BIT(MESA_VK_DGC_PC) | BITFIELD_BIT(MESA_VK_DGC_SI))) {
if (pCreateInfo->pipelineLayout) {
elayout->layout = pCreateInfo->pipelineLayout;
} else {
const struct vk_device_dispatch_table *disp = &device->dispatch_table;
assert(device->enabled_features.dynamicGeneratedPipelineLayout);
const VkPipelineLayoutCreateInfo *plci = vk_find_struct_const(pCreateInfo->pNext, PIPELINE_LAYOUT_CREATE_INFO);
assert(plci);
disp->CreatePipelineLayout(vk_device_to_handle(device), plci, NULL, &elayout->layout);
elayout->delete_layout = true;
}
}
elayout->stages = pCreateInfo->shaderStages;
elayout->usage = pCreateInfo->flags;
elayout->stride = pCreateInfo->indirectStride;
elayout->token_count = pCreateInfo->tokenCount;
return elayout;
}
void
vk_indirect_command_layout_destroy(struct vk_device *device,
const VkAllocationCallbacks *pAllocator,
struct vk_indirect_command_layout *elayout)
{
if (elayout->delete_layout) {
const struct vk_device_dispatch_table *disp = &device->dispatch_table;
assert(device->enabled_features.dynamicGeneratedPipelineLayout);
disp->DestroyPipelineLayout(vk_device_to_handle(device), elayout->layout, NULL);
}
vk_object_base_finish(&elayout->base);
vk_free2(&device->alloc, pAllocator, elayout);
}

View file

@ -0,0 +1,109 @@
/*
* Copyright © 2024 Valve Corporation
*
* 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, sublicense,
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#ifndef VK_DEVICE_GENERATED_COMMANDS_H
#define VK_DEVICE_GENERATED_COMMANDS_H
#include <vulkan/vulkan_core.h>
#include "vk_object.h"
enum mesa_vk_dgc_types {
MESA_VK_DGC_IES,
MESA_VK_DGC_PC,
MESA_VK_DGC_SI,
MESA_VK_DGC_IB,
MESA_VK_DGC_VB,
MESA_VK_DGC_DRAW,
MESA_VK_DGC_DRAW_INDEXED,
MESA_VK_DGC_DRAW_MESH,
MESA_VK_DGC_DISPATCH,
MESA_VK_DGC_RT,
};
struct vk_indirect_command_vertex_layout {
uint32_t binding;
uint32_t src_offset_B;
};
struct vk_indirect_command_push_constant_layout {
VkShaderStageFlags stages;
uint32_t dst_offset_B;
uint32_t src_offset_B;
uint32_t size_B;
};
/* this struct must come first in the parent class,
* the final member of the parent class must be
VkIndirectCommandsLayoutTokenEXT tokens[0];
*/
struct vk_indirect_command_layout {
struct vk_object_base base;
/* mask of mesa_vk_dgc_types */
uint32_t dgc_info;
VkPipelineLayout layout;
VkIndirectCommandsLayoutUsageFlagsEXT usage;
VkShaderStageFlags stages;
size_t stride;
uint32_t vertex_bindings;
uint32_t ies_src_offset_B;
bool is_shaders;
bool delete_layout;
bool index_mode_is_dx;
uint32_t index_src_offset_B;
uint32_t draw_src_offset_B;
bool draw_count;
uint32_t dispatch_src_offset_B;
unsigned token_count;
struct vk_indirect_command_push_constant_layout si_layout;
uint32_t n_pc_layouts;
struct vk_indirect_command_push_constant_layout *pc_layouts;
uint32_t n_vb_layouts;
struct vk_indirect_command_vertex_layout *vb_layouts;
};
void *
vk_indirect_command_layout_create(struct vk_device *device,
const VkIndirectCommandsLayoutCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
size_t struct_size);
void
vk_indirect_command_layout_destroy(struct vk_device *device,
const VkAllocationCallbacks *pAllocator,
struct vk_indirect_command_layout *elayout);
#endif /* VK_DEVICE_GENERATED_COMMANDS_H */