anv: Use vk_acceleration_structure
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21047>
This commit is contained in:
committed by
Marge Bot
parent
4d2a7ea146
commit
6242fe3923
@@ -968,7 +968,7 @@ void anv_CmdPushDescriptorSetKHR(
|
||||
assert(accel_write->accelerationStructureCount ==
|
||||
write->descriptorCount);
|
||||
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel,
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, accel,
|
||||
accel_write->pAccelerationStructures[j]);
|
||||
anv_descriptor_set_write_acceleration_structure(cmd_buffer->device,
|
||||
set, accel,
|
||||
|
||||
@@ -1624,7 +1624,7 @@ anv_descriptor_set_write_inline_uniform_data(struct anv_device *device,
|
||||
void
|
||||
anv_descriptor_set_write_acceleration_structure(struct anv_device *device,
|
||||
struct anv_descriptor_set *set,
|
||||
struct anv_acceleration_structure *accel,
|
||||
struct vk_acceleration_structure *accel,
|
||||
uint32_t binding,
|
||||
uint32_t element)
|
||||
{
|
||||
@@ -1641,7 +1641,7 @@ anv_descriptor_set_write_acceleration_structure(struct anv_device *device,
|
||||
|
||||
struct anv_address_range_descriptor desc_data = { };
|
||||
if (accel != NULL) {
|
||||
desc_data.address = anv_address_physical(accel->address);
|
||||
desc_data.address = vk_acceleration_structure_get_va(accel);
|
||||
desc_data.range = accel->size;
|
||||
}
|
||||
assert(sizeof(desc_data) <= bind_layout->descriptor_stride);
|
||||
@@ -1729,7 +1729,7 @@ void anv_UpdateDescriptorSets(
|
||||
assert(accel_write->accelerationStructureCount ==
|
||||
write->descriptorCount);
|
||||
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel,
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, accel,
|
||||
accel_write->pAccelerationStructures[j]);
|
||||
anv_descriptor_set_write_acceleration_structure(device, set, accel,
|
||||
write->dstBinding,
|
||||
@@ -1892,7 +1892,7 @@ anv_descriptor_set_write_template(struct anv_device *device,
|
||||
for (uint32_t j = 0; j < entry->array_count; j++) {
|
||||
VkAccelerationStructureKHR *accel_obj =
|
||||
(VkAccelerationStructureKHR *)(data + entry->offset + j * entry->stride);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel, *accel_obj);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, accel, *accel_obj);
|
||||
|
||||
anv_descriptor_set_write_acceleration_structure(device, set,
|
||||
accel,
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include "util/u_math.h"
|
||||
#include "util/vma.h"
|
||||
#include "util/xmlconfig.h"
|
||||
#include "vk_acceleration_structure.h"
|
||||
#include "vk_alloc.h"
|
||||
#include "vk_buffer.h"
|
||||
#include "vk_command_buffer.h"
|
||||
@@ -107,7 +108,6 @@ struct anv_batch;
|
||||
struct anv_buffer;
|
||||
struct anv_buffer_view;
|
||||
struct anv_image_view;
|
||||
struct anv_acceleration_structure;
|
||||
struct anv_instance;
|
||||
|
||||
struct intel_aux_map_context;
|
||||
@@ -1779,7 +1779,7 @@ struct anv_descriptor {
|
||||
|
||||
struct anv_buffer_view *buffer_view;
|
||||
|
||||
struct anv_acceleration_structure *accel_struct;
|
||||
struct vk_acceleration_structure *accel_struct;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1941,7 +1941,7 @@ anv_descriptor_write_surface_state(struct anv_device *device,
|
||||
void
|
||||
anv_descriptor_set_write_acceleration_structure(struct anv_device *device,
|
||||
struct anv_descriptor_set *set,
|
||||
struct anv_acceleration_structure *accel,
|
||||
struct vk_acceleration_structure *accel,
|
||||
uint32_t binding,
|
||||
uint32_t element);
|
||||
|
||||
@@ -4132,13 +4132,6 @@ static inline uint32_t khr_perf_query_preamble_offset(const struct anv_query_poo
|
||||
return pool->pass_size * pass + 8;
|
||||
}
|
||||
|
||||
struct anv_acceleration_structure {
|
||||
struct vk_object_base base;
|
||||
|
||||
VkDeviceSize size;
|
||||
struct anv_address address;
|
||||
};
|
||||
|
||||
struct anv_vid_mem {
|
||||
struct anv_device_memory *mem;
|
||||
VkDeviceSize offset;
|
||||
@@ -4283,9 +4276,6 @@ VK_DEFINE_HANDLE_CASTS(anv_physical_device, vk.base, VkPhysicalDevice,
|
||||
VK_OBJECT_TYPE_PHYSICAL_DEVICE)
|
||||
VK_DEFINE_HANDLE_CASTS(anv_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE)
|
||||
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_acceleration_structure, base,
|
||||
VkAccelerationStructureKHR,
|
||||
VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, vk.base, VkBuffer,
|
||||
VK_OBJECT_TYPE_BUFFER)
|
||||
VK_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, base, VkBufferView,
|
||||
|
||||
@@ -393,62 +393,6 @@ genX(GetAccelerationStructureBuildSizesKHR)(
|
||||
pSizeInfo->updateScratchSize = gpu_size_info.updateScratchSize;
|
||||
}
|
||||
|
||||
VkResult
|
||||
genX(CreateAccelerationStructureKHR)(
|
||||
VkDevice _device,
|
||||
const VkAccelerationStructureCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkAccelerationStructureKHR* pAccelerationStructure)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_device, device, _device);
|
||||
ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
|
||||
struct anv_acceleration_structure *accel;
|
||||
|
||||
accel = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*accel), 8,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (accel == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
vk_object_base_init(&device->vk, &accel->base,
|
||||
VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR);
|
||||
|
||||
accel->size = pCreateInfo->size;
|
||||
accel->address = anv_address_add(buffer->address, pCreateInfo->offset);
|
||||
|
||||
*pAccelerationStructure = anv_acceleration_structure_to_handle(accel);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
genX(DestroyAccelerationStructureKHR)(
|
||||
VkDevice _device,
|
||||
VkAccelerationStructureKHR accelerationStructure,
|
||||
const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_device, device, _device);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel, accelerationStructure);
|
||||
|
||||
if (!accel)
|
||||
return;
|
||||
|
||||
vk_object_base_finish(&accel->base);
|
||||
vk_free2(&device->vk.alloc, pAllocator, accel);
|
||||
}
|
||||
|
||||
VkDeviceAddress
|
||||
genX(GetAccelerationStructureDeviceAddressKHR)(
|
||||
VkDevice device,
|
||||
const VkAccelerationStructureDeviceAddressInfoKHR* pInfo)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel,
|
||||
pInfo->accelerationStructure);
|
||||
|
||||
assert(!anv_address_is_null(accel->address));
|
||||
|
||||
return anv_address_physical(accel->address);
|
||||
}
|
||||
|
||||
void
|
||||
genX(GetDeviceAccelerationStructureCompatibilityKHR)(
|
||||
VkDevice _device,
|
||||
@@ -697,12 +641,12 @@ cmd_build_acceleration_structures(
|
||||
const uint32_t *pMaxPrimitiveCounts =
|
||||
ppMaxPrimitiveCounts ? ppMaxPrimitiveCounts[i] : NULL;
|
||||
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, dst_accel,
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, dst_accel,
|
||||
pInfo->dstAccelerationStructure);
|
||||
|
||||
bs->build_method = device->bvh_build_method;
|
||||
|
||||
bs->bvh_addr = dst_accel->address;
|
||||
bs->bvh_addr = anv_address_from_u64(vk_acceleration_structure_get_va(dst_accel));
|
||||
|
||||
bs->estimate = get_gpu_size_estimate(pInfo, pBuildRangeInfos,
|
||||
pMaxPrimitiveCounts);
|
||||
@@ -1154,24 +1098,26 @@ genX(CmdCopyAccelerationStructureKHR)(
|
||||
const VkCopyAccelerationStructureInfoKHR* pInfo)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, src_accel, pInfo->src);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, dst_accel, pInfo->dst);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, src_accel, pInfo->src);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, dst_accel, pInfo->dst);
|
||||
|
||||
assert(pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR ||
|
||||
pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR);
|
||||
|
||||
if (pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR) {
|
||||
struct anv_address src_size_addr = anv_address_add(
|
||||
src_accel->address,
|
||||
offsetof(struct BVHBase, Meta.allocationSize));
|
||||
genX(grl_copy_clone_indirect)(cmd_buffer,
|
||||
anv_address_physical(dst_accel->address),
|
||||
anv_address_physical(src_accel->address),
|
||||
anv_address_physical(src_size_addr));
|
||||
uint64_t src_size_addr =
|
||||
vk_acceleration_structure_get_va(src_accel) +
|
||||
offsetof(struct BVHBase, Meta.allocationSize);
|
||||
genX(grl_copy_clone_indirect)(
|
||||
cmd_buffer,
|
||||
vk_acceleration_structure_get_va(dst_accel),
|
||||
vk_acceleration_structure_get_va(src_accel),
|
||||
src_size_addr);
|
||||
} else {
|
||||
genX(grl_copy_compact)(cmd_buffer,
|
||||
anv_address_physical(dst_accel->address),
|
||||
anv_address_physical(src_accel->address));
|
||||
genX(grl_copy_compact)(
|
||||
cmd_buffer,
|
||||
vk_acceleration_structure_get_va(dst_accel),
|
||||
vk_acceleration_structure_get_va(src_accel));
|
||||
}
|
||||
|
||||
cmd_buffer->state.pending_pipe_bits |= ANV_PIPE_END_OF_PIPE_SYNC_BIT;
|
||||
@@ -1183,19 +1129,20 @@ genX(CmdCopyAccelerationStructureToMemoryKHR)(
|
||||
const VkCopyAccelerationStructureToMemoryInfoKHR* pInfo)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, src_accel, pInfo->src);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, src_accel, pInfo->src);
|
||||
struct anv_device *device = cmd_buffer->device;
|
||||
struct anv_address src_size_addr = anv_address_add(
|
||||
src_accel->address,
|
||||
offsetof(struct BVHBase, Meta.allocationSize));
|
||||
uint64_t src_size_addr =
|
||||
vk_acceleration_structure_get_va(src_accel) +
|
||||
offsetof(struct BVHBase, Meta.allocationSize);
|
||||
|
||||
assert(pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR);
|
||||
|
||||
genX(grl_copy_serialize_indirect)(cmd_buffer,
|
||||
pInfo->dst.deviceAddress,
|
||||
anv_address_physical(src_accel->address),
|
||||
anv_address_physical(device->rt_uuid_addr),
|
||||
anv_address_physical(src_size_addr));
|
||||
genX(grl_copy_serialize_indirect)(
|
||||
cmd_buffer,
|
||||
pInfo->dst.deviceAddress,
|
||||
vk_acceleration_structure_get_va(src_accel),
|
||||
anv_address_physical(device->rt_uuid_addr),
|
||||
src_size_addr);
|
||||
|
||||
cmd_buffer->state.pending_pipe_bits |= ANV_PIPE_END_OF_PIPE_SYNC_BIT;
|
||||
}
|
||||
@@ -1206,16 +1153,17 @@ genX(CmdCopyMemoryToAccelerationStructureKHR)(
|
||||
const VkCopyMemoryToAccelerationStructureInfoKHR* pInfo)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, dst_accel, pInfo->dst);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, dst_accel, pInfo->dst);
|
||||
|
||||
assert(pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR);
|
||||
|
||||
uint64_t src_size_addr = pInfo->src.deviceAddress +
|
||||
offsetof(struct SerializationHeader, DeserializedSizeInBytes);
|
||||
genX(grl_copy_deserialize_indirect)(cmd_buffer,
|
||||
anv_address_physical(dst_accel->address),
|
||||
pInfo->src.deviceAddress,
|
||||
src_size_addr);
|
||||
genX(grl_copy_deserialize_indirect)(
|
||||
cmd_buffer,
|
||||
vk_acceleration_structure_get_va(dst_accel),
|
||||
pInfo->src.deviceAddress,
|
||||
src_size_addr);
|
||||
|
||||
cmd_buffer->state.pending_pipe_bits |= ANV_PIPE_END_OF_PIPE_SYNC_BIT;
|
||||
}
|
||||
|
||||
@@ -1603,27 +1603,27 @@ genX(CmdWriteAccelerationStructuresPropertiesKHR)(
|
||||
mi_builder_init(&b, cmd_buffer->device->info, &cmd_buffer->batch);
|
||||
|
||||
for (uint32_t i = 0; i < accelerationStructureCount; i++) {
|
||||
ANV_FROM_HANDLE(anv_acceleration_structure, accel, pAccelerationStructures[i]);
|
||||
ANV_FROM_HANDLE(vk_acceleration_structure, accel, pAccelerationStructures[i]);
|
||||
struct anv_address query_addr =
|
||||
anv_address_add(anv_query_address(pool, firstQuery + i), 8);
|
||||
|
||||
switch (queryType) {
|
||||
case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR:
|
||||
genX(grl_postbuild_info_compacted_size)(cmd_buffer,
|
||||
anv_address_physical(accel->address),
|
||||
vk_acceleration_structure_get_va(accel),
|
||||
anv_address_physical(query_addr));
|
||||
break;
|
||||
|
||||
case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR:
|
||||
genX(grl_postbuild_info_current_size)(cmd_buffer,
|
||||
anv_address_physical(accel->address),
|
||||
vk_acceleration_structure_get_va(accel),
|
||||
anv_address_physical(query_addr));
|
||||
break;
|
||||
|
||||
case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR:
|
||||
case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR:
|
||||
genX(grl_postbuild_info_serialized_size)(cmd_buffer,
|
||||
anv_address_physical(accel->address),
|
||||
vk_acceleration_structure_get_va(accel),
|
||||
anv_address_physical(query_addr));
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user