@@ -491,20 +491,32 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
491491 // triangles geometries
492492 auto gc = make_smart_refctd_ptr<CGeometryCreator>();
493493
494- std::array<ReferenceObjectCpu, OT_COUNT> cpuObjects;
495- cpuObjects[OT_CUBE] = ReferenceObjectCpu{ .meta = {.type = OT_CUBE, .name = " Cube Mesh" }, .shadersType = GP_BASIC, .data = gc->createCube ({1 .f , 1 .f , 1 .f }) };
496- cpuObjects[OT_SPHERE] = ReferenceObjectCpu{ .meta = {.type = OT_SPHERE, .name = " Sphere Mesh" }, .shadersType = GP_BASIC, .data = gc->createSphere (2 , 16 , 16 ) };
497- cpuObjects[OT_CYLINDER] = ReferenceObjectCpu{ .meta = {.type = OT_CYLINDER, .name = " Cylinder Mesh" }, .shadersType = GP_BASIC, .data = gc->createCylinder (2 , 2 , 20 ) };
498- cpuObjects[OT_RECTANGLE] = ReferenceObjectCpu{ .meta = {.type = OT_RECTANGLE, .name = " Rectangle Mesh" }, .shadersType = GP_BASIC, .data = gc->createRectangle ({1.5 , 3 }) };
499- cpuObjects[OT_CONE] = ReferenceObjectCpu{ .meta = {.type = OT_CONE, .name = " Cone Mesh" }, .shadersType = GP_CONE, .data = gc->createCone (2 , 3 , 10 ) };
500- cpuObjects[OT_ICOSPHERE] = ReferenceObjectCpu{ .meta = {.type = OT_ICOSPHERE, .name = " Icosphere Mesh" }, .shadersType = GP_ICO, .data = gc->createIcoSphere (1 , 3 , true ) };
494+ auto transform_i = 0 ;
495+ auto nextTransform = [&transform_i]()
496+ {
497+ core::matrix3x4SIMD transform;
498+ transform.setTranslation (nbl::core::vectorSIMDf (5 .f * transform_i, 0 , 0 , 0 ));
499+ transform_i++;
500+ return transform;
501+ };
501502
502- auto geomInfoBuffer = ICPUBuffer::create ({ OT_COUNT * sizeof (SGeomInfo) });
503+ std::vector<ReferenceObjectCpu> cpuObjects;
504+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_CUBE, .name = " Cube Mesh" }, .transform = nextTransform (), .data = gc->createCube ({1 .f , 1 .f , 1 .f })});
505+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_SPHERE, .name = " Sphere Mesh" }, .transform = nextTransform (), .data = gc->createSphere (2 , 16 , 16 )});
506+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_CYLINDER, .name = " Cylinder Mesh" }, .transform = nextTransform (), .data = gc->createCylinder (2 , 2 , 20 )});
507+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_RECTANGLE, .name = " Rectangle Mesh" }, .transform = nextTransform (), .data = gc->createRectangle ({1.5 , 3 })});
508+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_CONE, .name = " Cone Mesh" }, .transform = nextTransform (), .data = gc->createCone (2 , 3 , 10 )});
509+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_ICOSPHERE, .name = " Icosphere Mesh" }, .transform = nextTransform (), .data = gc->createIcoSphere (1 , 3 , true )});
510+ const auto arrowPolygons = gc->createArrow ();
511+ const auto arrowTransform = nextTransform ();
512+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_CYLINDER, .name = " Arrow Mesh" }, .transform = arrowTransform, .data = arrowPolygons[0 ]});
513+ cpuObjects.push_back (ReferenceObjectCpu{ .meta = {.type = OT_CONE, .name = " Arrow Mesh" }, .transform = arrowTransform, .data = arrowPolygons[1 ]});
514+ auto geomInfoBuffer = ICPUBuffer::create ({ cpuObjects.size () * sizeof (SGeomInfo) });
503515
504516 SGeomInfo* geomInfos = reinterpret_cast <SGeomInfo*>(geomInfoBuffer->getPointer ());
505517
506518 // get ICPUBuffers into ICPUBottomLevelAccelerationStructures
507- std::array <smart_refctd_ptr<ICPUBottomLevelAccelerationStructure>, OT_COUNT > cpuBlas;
519+ std::vector <smart_refctd_ptr<ICPUBottomLevelAccelerationStructure>> cpuBlas (cpuObjects. size ()) ;
508520 for (uint32_t i = 0 ; i < cpuBlas.size (); i++)
509521 {
510522 auto triangles = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUBottomLevelAccelerationStructure::Triangles<ICPUBuffer>>>(1u );
@@ -530,7 +542,7 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
530542 }
531543
532544 // get ICPUBottomLevelAccelerationStructure into ICPUTopLevelAccelerationStructure
533- auto geomInstances = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUTopLevelAccelerationStructure::PolymorphicInstance>>(OT_COUNT );
545+ auto geomInstances = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUTopLevelAccelerationStructure::PolymorphicInstance>>(cpuObjects. size () );
534546 {
535547 uint32_t i = 0 ;
536548 for (auto instance = geomInstances->begin (); instance != geomInstances->end (); instance++, i++)
@@ -541,11 +553,7 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
541553 inst.base .instanceCustomIndex = i;
542554 inst.base .instanceShaderBindingTableRecordOffset = 0 ;
543555 inst.base .mask = 0xFF ;
544-
545- core::matrix3x4SIMD transform;
546- transform.setTranslation (nbl::core::vectorSIMDf (5 .f * i, 0 , 0 , 0 ));
547- inst.transform = transform;
548-
556+ inst.transform = cpuObjects[i].transform ;
549557 instance->instance = inst;
550558 }
551559 }
@@ -612,9 +620,9 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
612620
613621 CAssetConverter::patch_t <ICPUTopLevelAccelerationStructure> tlasPatch = {};
614622 tlasPatch.compactAfterBuild = true ;
615- std::array <CAssetConverter::patch_t <ICPUBottomLevelAccelerationStructure>,OT_COUNT > tmpBLASPatches = {} ;
616- std::array <ICPUPolygonGeometry*, std::size (cpuObjects)> tmpGeometries ;
617- std::array <CAssetConverter::patch_t <asset::ICPUPolygonGeometry>, std::size (cpuObjects)> tmpGeometryPatches ;
623+ std::vector <CAssetConverter::patch_t <ICPUBottomLevelAccelerationStructure>> tmpBLASPatches (cpuObjects. size ()) ;
624+ std::vector <ICPUPolygonGeometry*> tmpGeometries (cpuObjects. size ()) ;
625+ std::vector <CAssetConverter::patch_t <asset::ICPUPolygonGeometry>> tmpGeometryPatches (cpuObjects. size ()) ;
618626 {
619627 tmpBLASPatches.front ().compactAfterBuild = true ;
620628 std::fill (tmpBLASPatches.begin (),tmpBLASPatches.end (),tmpBLASPatches.front ());
@@ -779,7 +787,7 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
779787 .vertexBufferAddress = vertexBufferAddress,
780788 .indexBufferAddress = indexBufferBinding.buffer ? indexBufferBinding.buffer ->getDeviceAddress () + indexBufferBinding.offset : vertexBufferAddress,
781789 .normalBufferAddress = normalBufferAddress,
782- .vertexStride = gpuTriangles. vertexStride ,
790+ .objType = cpuObject. meta . type ,
783791 .indexType = gpuTriangles.indexType ,
784792 .smoothNormals = s_smoothNormals[cpuObject.meta .type ],
785793 };
@@ -792,7 +800,7 @@ class RayQueryGeometryApp final : public SimpleWindowedApplication, public Built
792800 {
793801 IGPUBuffer::SCreationParams params;
794802 params.usage = IGPUBuffer::EUF_STORAGE_BUFFER_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT;
795- params.size = OT_COUNT * sizeof (SGeomInfo);
803+ params.size = cpuObjects. size () * sizeof (SGeomInfo);
796804 m_utils->createFilledDeviceLocalBufferOnDedMem (SIntendedSubmitInfo{ .queue = gQueue }, std::move (params), geomInfos).move_into (geometryInfoBuffer);
797805 }
798806
0 commit comments