SpiecsEngine
 
Loading...
Searching...
No Matches

◆ MeshPackToVkGeometryKHR()

VulkanRayTracing::BlasInput Spices::MeshPack::MeshPackToVkGeometryKHR ( )
inherited

Convert MeshPack into the ray tracing geometry used to build the BLAS.

Returns
Returns VulkanRayTracing::BlasInput.

BLAS builder requires raw device addresses.

device pointer to the buffers holding triangle vertex/index data, along with information for interpreting it as an array (stride, data type, etc.)

wrapper around the above with the geometry type enum (triangles in this case) plus flags for the AS builder.

the indices within the vertex arrays to source input geometry for the BLAS.

Our blas is made from only one geometry, but could be made of many geometries.

BLAS builder requires raw device addresses.

device pointer to the buffers holding triangle vertex/index data, along with information for interpreting it as an array (stride, data type, etc.)

wrapper around the above with the geometry type enum (triangles in this case) plus flags for the AS builder.

the indices within the vertex arrays to source input geometry for the BLAS.

Our blas is made from only one geometry, but could be made of many geometries.

Definition at line 195 of file MeshPack.cpp.

196 {
198
202 const VkDeviceAddress vertexAddress = m_MeshResource.positions.buffer->GetAddress();
203 const VkDeviceAddress indicesAddress = m_MeshResource.primitivePoints.buffer->GetAddress();
204
205 const Lod& lod0 = (*m_MeshResource.lods.attributes)[0];
206 const uint32_t maxPrimitiveCount = lod0.nPrimitives;
207
212 VkAccelerationStructureGeometryTrianglesDataKHR triangles {};
213 triangles.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR;
214 triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
215 triangles.vertexData.deviceAddress = vertexAddress; /* @note position needs to be the first attribute of Vertex, otherwise correct offset is needs to be added here. */
216 triangles.vertexStride = sizeof(glm::vec3);
217 triangles.indexType = VK_INDEX_TYPE_UINT32;
218 triangles.indexData.deviceAddress = indicesAddress;
219 //triangles.transformData = {};
220 triangles.maxVertex = static_cast<uint32_t>(m_MeshResource.primitivePoints.buffer->GetSize() / sizeof(glm::uvec3) * 3 - 1);
221
225 VkAccelerationStructureGeometryKHR asGeom {};
226 asGeom.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR;
227 asGeom.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR;
228 asGeom.flags = VK_GEOMETRY_OPAQUE_BIT_KHR;
229 asGeom.geometry.triangles = triangles;
230
234 VkAccelerationStructureBuildRangeInfoKHR offset {};
235 offset.firstVertex = 0;
236 offset.primitiveCount = maxPrimitiveCount;
237 offset.primitiveOffset = lod0.primVertexOffset;
238 offset.transformOffset = 0;
239
243 VulkanRayTracing::BlasInput input;
244 input.asGeometry.emplace_back(asGeom);
245 input.asBuildOffsetInfo.emplace_back(offset);
246 input.accel = &m_Accel;
247
248 return input;
249 }
#define SPICES_PROFILE_ZONE
AccelKHR m_Accel
This meshPack blas accel.
Definition MeshPack.h:368
MeshResource m_MeshResource
Mesh Resources.
Definition MeshPack.h:331
std::shared_ptr< VulkanBuffer > buffer
Attribute Buffer.
Definition Attribute.h:54
std::shared_ptr< std::vector< T > > attributes
Attribute Data Array.
Definition Attribute.h:49
Positions positions
Declare value.
Definition MeshPack.h:68
PrimitivePoints primitivePoints
Definition MeshPack.h:73

References Spices::Lod::nPrimitives.