vulkan: Replace get_*_key with get_build_config
It is a cleaner API and gives more control about the build to the driver. Reviewed-by: Natalie Vock <natalie.vock@gmx.de> Reviewed-by: Connor Abbott <cwabbott0@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35385>
This commit is contained in:
committed by
Marge Bot
parent
37869a9bc2
commit
28713789ad
@@ -399,8 +399,7 @@ radv_get_update_scratch_size(struct vk_device *vk_device, const VkAccelerationSt
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
radv_get_encode_key(struct vk_device *vk_device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
radv_get_encode_key(struct vk_device *vk_device, const VkAccelerationStructureBuildGeometryInfoKHR *build_info)
|
||||
{
|
||||
struct radv_device *device = container_of(vk_device, struct radv_device, vk);
|
||||
struct radv_physical_device *pdev = radv_device_physical(device);
|
||||
@@ -408,7 +407,7 @@ radv_get_encode_key(struct vk_device *vk_device, VkAccelerationStructureTypeKHR
|
||||
if (radv_use_bvh8(pdev))
|
||||
return RADV_ENCODE_KEY_COMPACT;
|
||||
|
||||
if (flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR)
|
||||
if (build_info->flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR)
|
||||
return RADV_ENCODE_KEY_COMPACT;
|
||||
|
||||
return 0;
|
||||
@@ -420,6 +419,19 @@ radv_get_update_key(struct vk_device *vk_device, bool in_place)
|
||||
return in_place ? RADV_BUILD_FLAG_UPDATE_IN_PLACE : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
radv_get_build_config(struct vk_device *vk_device, struct vk_build_config *config,
|
||||
const VkAccelerationStructureBuildGeometryInfoKHR *build_info)
|
||||
{
|
||||
uint32_t encode_key = radv_get_encode_key(vk_device, build_info);
|
||||
config->encode_key[0] = encode_key;
|
||||
config->encode_key[1] = encode_key;
|
||||
|
||||
uint32_t update_key =
|
||||
radv_get_update_key(vk_device, build_info->srcAccelerationStructure == build_info->dstAccelerationStructure);
|
||||
config->update_key[0] = update_key;
|
||||
}
|
||||
|
||||
static void
|
||||
radv_bvh_build_bind_pipeline(VkCommandBuffer commandBuffer, enum radv_meta_object_key_type type, const uint32_t *spirv,
|
||||
uint32_t spirv_size, uint32_t push_constants_size, uint32_t flags)
|
||||
@@ -947,14 +959,12 @@ radv_device_init_accel_struct_build_state(struct radv_device *device)
|
||||
device->meta_state.accel_struct_build.build_ops = (struct vk_acceleration_structure_build_ops){
|
||||
.begin_debug_marker = vk_accel_struct_cmd_begin_debug_marker,
|
||||
.end_debug_marker = vk_accel_struct_cmd_end_debug_marker,
|
||||
.get_build_config = radv_get_build_config,
|
||||
.get_as_size = radv_get_as_size,
|
||||
.get_update_scratch_size = radv_get_update_scratch_size,
|
||||
.get_encode_key[0] = radv_get_encode_key,
|
||||
.get_encode_key[1] = radv_get_encode_key,
|
||||
.encode_bind_pipeline[1] = radv_init_header_bind_pipeline,
|
||||
.encode_as[1] = radv_init_header,
|
||||
.init_update_scratch = radv_init_update_scratch,
|
||||
.get_update_key[0] = radv_get_update_key,
|
||||
.update_bind_pipeline[0] = radv_update_bind_pipeline,
|
||||
};
|
||||
|
||||
|
||||
@@ -153,13 +153,26 @@ VkDeviceSize get_bvh_size(VkDevice device,
|
||||
return layout.size;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
encode_key(struct vk_device *device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* Don't bother copying over the compacted size using a compute shader if
|
||||
* compaction is never going to happen.
|
||||
*/
|
||||
enum tu_header_key {
|
||||
HEADER_NO_DISPATCH,
|
||||
HEADER_USE_DISPATCH,
|
||||
};
|
||||
|
||||
static void
|
||||
tu_get_build_config(
|
||||
struct vk_device *device,
|
||||
struct vk_build_config *config,
|
||||
const VkAccelerationStructureBuildGeometryInfoKHR *build_info)
|
||||
{
|
||||
config->encode_key[1] =
|
||||
(build_info->flags &
|
||||
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR)
|
||||
? HEADER_USE_DISPATCH
|
||||
: HEADER_NO_DISPATCH;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
encode_bind_pipeline(VkCommandBuffer commandBuffer, uint32_t key)
|
||||
@@ -224,22 +237,6 @@ encode(VkCommandBuffer commandBuffer,
|
||||
|
||||
}
|
||||
|
||||
/* Don't bother copying over the compacted size using a compute shader if
|
||||
* compaction is never going to happen.
|
||||
*/
|
||||
enum tu_header_key {
|
||||
HEADER_NO_DISPATCH,
|
||||
HEADER_USE_DISPATCH
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
header_key(struct vk_device *device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
{
|
||||
return (flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR) ?
|
||||
HEADER_USE_DISPATCH : HEADER_NO_DISPATCH;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
header_bind_pipeline(VkCommandBuffer commandBuffer, uint32_t key)
|
||||
{
|
||||
@@ -348,8 +345,8 @@ header(VkCommandBuffer commandBuffer,
|
||||
}
|
||||
|
||||
const struct vk_acceleration_structure_build_ops tu_as_build_ops = {
|
||||
.get_build_config = tu_get_build_config,
|
||||
.get_as_size = get_bvh_size,
|
||||
.get_encode_key = { encode_key, header_key },
|
||||
.encode_bind_pipeline = { encode_bind_pipeline, header_bind_pipeline },
|
||||
.encode_as = { encode, header },
|
||||
};
|
||||
|
||||
@@ -645,13 +645,6 @@ lvp_get_as_size(VkDevice device,
|
||||
return sizeof(struct lvp_bvh_header) + nodes_size;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
lvp_get_encode_key(struct vk_device *device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
lvp_encode_bind_pipeline(VkCommandBuffer cmd_buffer,
|
||||
uint32_t key)
|
||||
@@ -661,7 +654,6 @@ lvp_encode_bind_pipeline(VkCommandBuffer cmd_buffer,
|
||||
|
||||
const struct vk_acceleration_structure_build_ops accel_struct_ops = {
|
||||
.get_as_size = lvp_get_as_size,
|
||||
.get_encode_key[0] = lvp_get_encode_key,
|
||||
.encode_bind_pipeline[0] = lvp_encode_bind_pipeline,
|
||||
.encode_as[0] = lvp_enqueue_encode_as,
|
||||
};
|
||||
|
||||
@@ -356,11 +356,11 @@ anv_get_as_size(VkDevice device,
|
||||
return layout.size;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
anv_get_encode_key(struct vk_device *device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
static void
|
||||
anv_get_build_config(struct vk_device *device, struct vk_build_config *config,
|
||||
const VkAccelerationStructureBuildGeometryInfoKHR *build_info)
|
||||
{
|
||||
return 0;
|
||||
config->encode_key[1] = (build_info->flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR) ? 1 : 0;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
@@ -443,14 +443,6 @@ anv_encode_as(VkCommandBuffer commandBuffer,
|
||||
(cmd_buffer, indirect_addr, true /* is_unaligned_size_x */);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
anv_get_header_key(struct vk_device *device, VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags)
|
||||
{
|
||||
return (flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR) ?
|
||||
1 : 0;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
anv_init_header_bind_pipeline(VkCommandBuffer commandBuffer, uint32_t key)
|
||||
{
|
||||
@@ -590,7 +582,7 @@ static const struct vk_acceleration_structure_build_ops anv_build_ops = {
|
||||
.begin_debug_marker = begin_debug_marker,
|
||||
.end_debug_marker = end_debug_marker,
|
||||
.get_as_size = anv_get_as_size,
|
||||
.get_encode_key = { anv_get_encode_key, anv_get_header_key },
|
||||
.get_build_config = anv_get_build_config,
|
||||
.encode_bind_pipeline = { anv_encode_bind_pipeline,
|
||||
anv_init_header_bind_pipeline },
|
||||
.encode_as = { anv_encode_as, anv_init_header },
|
||||
|
||||
@@ -157,12 +157,8 @@ build_config(struct vk_device *device, uint32_t leaf_count,
|
||||
ops->update_as[0])
|
||||
config.updateable = true;
|
||||
|
||||
for (unsigned i = 0; i < MAX_ENCODE_PASSES; i++) {
|
||||
if (ops->get_encode_key[i])
|
||||
config.encode_key[i] = ops->get_encode_key[i](device, leaf_count, build_info->flags);
|
||||
if (ops->get_update_key[i])
|
||||
config.update_key[i] = ops->get_update_key[i](device, build_info->srcAccelerationStructure == build_info->dstAccelerationStructure);
|
||||
}
|
||||
if (ops->get_build_config)
|
||||
ops->get_build_config(device, &config, build_info);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -93,10 +93,9 @@ struct vk_acceleration_structure_build_ops {
|
||||
VkDeviceSize (*get_update_scratch_size)(struct vk_device *device,
|
||||
const VkAccelerationStructureBuildGeometryInfoKHR *build_info,
|
||||
uint32_t leaf_count);
|
||||
uint32_t (*get_encode_key[MAX_ENCODE_PASSES])(struct vk_device *device,
|
||||
VkAccelerationStructureTypeKHR type,
|
||||
VkBuildAccelerationStructureFlagBitsKHR flags);
|
||||
uint32_t (*get_update_key[MAX_ENCODE_PASSES])(struct vk_device *device, bool in_place);
|
||||
void (*get_build_config)(struct vk_device *device,
|
||||
struct vk_build_config *config,
|
||||
const VkAccelerationStructureBuildGeometryInfoKHR *build_info);
|
||||
VkResult (*encode_bind_pipeline[MAX_ENCODE_PASSES])(VkCommandBuffer cmd_buffer,
|
||||
uint32_t key);
|
||||
void (*encode_as[MAX_ENCODE_PASSES])(VkCommandBuffer cmd_buffer,
|
||||
|
||||
Reference in New Issue
Block a user