Skip to content

Commit

Permalink
Fix two more bugs introduced by unifying vkb::core::[HPP]Buffer
Browse files Browse the repository at this point in the history
- while combining the two versions of AccelerationStructure::add_triangle_geometry, one argument of one of those versions got lost;
- In the gltf_loader, the additional_buffer_usage_flags to be used for the vertex and index buffers got lost
  • Loading branch information
asuessenbach committed Sep 2, 2024
1 parent 46a89dd commit a496d52
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
18 changes: 11 additions & 7 deletions framework/core/acceleration_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ AccelerationStructure::~AccelerationStructure()
uint64_t AccelerationStructure::add_triangle_geometry(vkb::core::BufferC &vertex_buffer,
vkb::core::BufferC &index_buffer,
vkb::core::BufferC &transform_buffer,
uint32_t triangle_count, uint32_t max_vertex,
VkDeviceSize vertex_stride, uint32_t transform_offset,
VkFormat vertex_format, VkGeometryFlagsKHR flags,
uint64_t vertex_buffer_data_address,
uint64_t index_buffer_data_address,
uint64_t transform_buffer_data_address)
uint32_t triangle_count,
uint32_t max_vertex,
VkDeviceSize vertex_stride,
uint32_t transform_offset,
VkFormat vertex_format,
VkIndexType index_type,
VkGeometryFlagsKHR flags,
uint64_t vertex_buffer_data_address,
uint64_t index_buffer_data_address,
uint64_t transform_buffer_data_address)
{
VkAccelerationStructureGeometryKHR geometry{};
geometry.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR;
Expand All @@ -56,7 +60,7 @@ uint64_t AccelerationStructure::add_triangle_geometry(vkb::core::BufferC &vertex
geometry.geometry.triangles.vertexFormat = vertex_format;
geometry.geometry.triangles.maxVertex = max_vertex;
geometry.geometry.triangles.vertexStride = vertex_stride;
geometry.geometry.triangles.indexType = VK_INDEX_TYPE_UINT32;
geometry.geometry.triangles.indexType = index_type;
geometry.geometry.triangles.vertexData.deviceAddress = vertex_buffer_data_address == 0 ? vertex_buffer.get_device_address() : vertex_buffer_data_address;
geometry.geometry.triangles.indexData.deviceAddress = index_buffer_data_address == 0 ? index_buffer.get_device_address() : index_buffer_data_address;
geometry.geometry.triangles.transformData.deviceAddress = transform_buffer_data_address == 0 ? transform_buffer.get_device_address() : transform_buffer_data_address;
Expand Down
2 changes: 2 additions & 0 deletions framework/core/acceleration_structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AccelerationStructure
* @param vertex_stride Stride of the vertex structure
* @param transform_offset Offset of this geometry in the transform data buffer
* @param vertex_format Format of the vertex structure
* @index_type index Type of the indices
* @param flags Ray tracing geometry flags
* @param vertex_buffer_data_address set this if don't want the vertex_buffer data_address
* @param index_buffer_data_address set this if don't want the index_buffer data_address
Expand All @@ -67,6 +68,7 @@ class AccelerationStructure
VkDeviceSize vertex_stride,
uint32_t transform_offset = 0,
VkFormat vertex_format = VK_FORMAT_R32G32B32_SFLOAT,
VkIndexType index_type = VK_INDEX_TYPE_UINT32,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR,
uint64_t vertex_buffer_data_address = 0,
uint64_t index_buffer_data_address = 0,
Expand Down
4 changes: 2 additions & 2 deletions framework/gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_

vkb::core::BufferC buffer{device,
vertex_data.size(),
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | additional_buffer_usage_flags,
VMA_MEMORY_USAGE_CPU_TO_GPU};
buffer.update(vertex_data);
buffer.set_debug_name(fmt::format("'{}' mesh, primitive #{}: '{}' vertex buffer",
Expand Down Expand Up @@ -804,7 +804,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_

submesh->index_buffer = std::make_unique<vkb::core::BufferC>(device,
index_data.size(),
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_buffer_usage_flags,
VMA_MEMORY_USAGE_GPU_TO_CPU);
submesh->index_buffer->set_debug_name(fmt::format("'{}' mesh, primitive #{}: index buffer",
gltf_mesh.name, i_primitive));
Expand Down
22 changes: 12 additions & 10 deletions samples/extensions/ray_queries/ray_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,18 @@ void RayQueries::create_bottom_level_acceleration_structure()
{
bottom_level_acceleration_structure = std::make_unique<vkb::core::AccelerationStructure>(
get_device(), VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR);
bottom_level_acceleration_structure->add_triangle_geometry(
*vertex_buffer,
*index_buffer,
*transform_matrix_buffer,
static_cast<uint32_t>(model.indices.size()),
static_cast<uint32_t>(model.vertices.size()) - 1,
sizeof(Vertex),
0, VK_FORMAT_R32G32B32_SFLOAT, VK_GEOMETRY_OPAQUE_BIT_KHR,
get_buffer_device_address(vertex_buffer->get_handle()),
get_buffer_device_address(index_buffer->get_handle()));
bottom_level_acceleration_structure->add_triangle_geometry(*vertex_buffer,
*index_buffer,
*transform_matrix_buffer,
static_cast<uint32_t>(model.indices.size()),
static_cast<uint32_t>(model.vertices.size()) - 1,
sizeof(Vertex),
0,
VK_FORMAT_R32G32B32_SFLOAT,
VK_INDEX_TYPE_UINT32,
VK_GEOMETRY_OPAQUE_BIT_KHR,
get_buffer_device_address(vertex_buffer->get_handle()),
get_buffer_device_address(index_buffer->get_handle()));
}
bottom_level_acceleration_structure->build(queue, VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR, VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ void RaytracingExtended::create_bottom_level_acceleration_structure(bool is_upda
static_cast<uint32_t>(model_buffer.num_triangles),
static_cast<uint32_t>(model_buffer.num_vertices) - 1,
sizeof(NewVertex),
0, VK_FORMAT_R32G32B32_SFLOAT, VK_GEOMETRY_OPAQUE_BIT_KHR,
0,
VK_FORMAT_R32G32B32_SFLOAT,
VK_INDEX_TYPE_UINT32,
VK_GEOMETRY_OPAQUE_BIT_KHR,
model_buffer.vertex_offset + (model_buffer.is_static ? static_vertex_handle : dynamic_vertex_handle),
model_buffer.index_offset + (model_buffer.is_static ? static_index_handle : dynamic_index_handle));
}
Expand Down

0 comments on commit a496d52

Please sign in to comment.