|
6 | 6 | #include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h" |
7 | 7 | #include "nbl/builtin/hlsl/indirect_commands.hlsl" |
8 | 8 |
|
| 9 | +#include "nbl/examples/common/BuiltinResourcesApplication.hpp" |
9 | 10 |
|
10 | | -class RaytracingPipelineApp final : public SimpleWindowedApplication, public application_templates::MonoAssetManagerAndBuiltinResourceApplication |
| 11 | + |
| 12 | +class RaytracingPipelineApp final : public SimpleWindowedApplication, public BuiltinResourcesApplication |
11 | 13 | { |
12 | 14 | using device_base_t = SimpleWindowedApplication; |
13 | | - using asset_base_t = application_templates::MonoAssetManagerAndBuiltinResourceApplication; |
| 15 | + using asset_base_t = BuiltinResourcesApplication; |
14 | 16 | using clock_t = std::chrono::steady_clock; |
15 | 17 |
|
16 | 18 | constexpr static inline uint32_t WIN_W = 1280, WIN_H = 720; |
@@ -1220,14 +1222,15 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1220 | 1222 | } |
1221 | 1223 | else |
1222 | 1224 | { |
1223 | | - auto triangles = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUBottomLevelAccelerationStructure::Triangles<ICPUBuffer>>>(cpuObjects[i].data->exportForBLAS()); |
| 1225 | + auto triangles = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUBottomLevelAccelerationStructure::Triangles<ICPUBuffer>>>(1u); |
1224 | 1226 | auto primitiveCounts = make_refctd_dynamic_array<smart_refctd_dynamic_array<uint32_t>>(1u); |
1225 | 1227 |
|
1226 | 1228 | auto& tri = triangles->front(); |
1227 | 1229 |
|
1228 | 1230 | auto& primCount = primitiveCounts->front(); |
1229 | 1231 | primCount = cpuObjects[i].data->getPrimitiveCount(); |
1230 | 1232 |
|
| 1233 | + tri = cpuObjects[i].data->exportForBLAS(); |
1231 | 1234 | tri.geometryFlags = cpuObjects[i].material.isTransparent() ? |
1232 | 1235 | IGPUBottomLevelAccelerationStructure::GEOMETRY_FLAGS::NO_DUPLICATE_ANY_HIT_INVOCATION_BIT : |
1233 | 1236 | IGPUBottomLevelAccelerationStructure::GEOMETRY_FLAGS::OPAQUE_BIT; |
@@ -1257,7 +1260,7 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1257 | 1260 | inst.base.blas = cpuBlasList[i]; |
1258 | 1261 | inst.base.flags = static_cast<uint32_t>(IGPUTopLevelAccelerationStructure::INSTANCE_FLAGS::TRIANGLE_FACING_CULL_DISABLE_BIT); |
1259 | 1262 | inst.base.instanceCustomIndex = i; |
1260 | | - inst.base.instanceShaderBindingTableRecordOffset = isProceduralInstance ? 2 : 0;; |
| 1263 | + inst.base.instanceShaderBindingTableRecordOffset = isProceduralInstance ? 2 : 0; |
1261 | 1264 | inst.base.mask = 0xFF; |
1262 | 1265 | inst.transform = isProceduralInstance ? matrix3x4SIMD() : cpuObjects[i].transform; |
1263 | 1266 |
|
@@ -1305,19 +1308,22 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1305 | 1308 | inputs.allocator = &myalloc; |
1306 | 1309 |
|
1307 | 1310 | std::array<ICPUTopLevelAccelerationStructure*, 1u> tmpTlas; |
1308 | | - std::array<ICPUPolygonGeometry*, std::size(cpuObjects)> tmpGeometries; |
1309 | 1311 | std::array<ICPUBuffer*, 1> tmpBuffers; |
| 1312 | + std::array<ICPUPolygonGeometry*, std::size(cpuObjects)> tmpGeometries; |
| 1313 | + std::array<CAssetConverter::patch_t<asset::ICPUPolygonGeometry>, std::size(cpuObjects)> tmpGeometryPatches; |
1310 | 1314 | { |
1311 | 1315 | tmpTlas[0] = cpuTlas.get(); |
1312 | 1316 | tmpBuffers[0] = cpuProcBuffer.get(); |
1313 | 1317 | for (uint32_t i = 0; i < cpuObjects.size(); i++) |
1314 | 1318 | { |
1315 | 1319 | tmpGeometries[i] = cpuObjects[i].data.get(); |
| 1320 | + tmpGeometryPatches[i].indexBufferUsages= IGPUBuffer::E_USAGE_FLAGS::EUF_SHADER_DEVICE_ADDRESS_BIT; |
1316 | 1321 | } |
1317 | 1322 |
|
1318 | 1323 | std::get<CAssetConverter::SInputs::asset_span_t<ICPUTopLevelAccelerationStructure>>(inputs.assets) = tmpTlas; |
1319 | 1324 | std::get<CAssetConverter::SInputs::asset_span_t<ICPUBuffer>>(inputs.assets) = tmpBuffers; |
1320 | 1325 | std::get<CAssetConverter::SInputs::asset_span_t<ICPUPolygonGeometry>>(inputs.assets) = tmpGeometries; |
| 1326 | + std::get<CAssetConverter::SInputs::patch_span_t<ICPUPolygonGeometry>>(inputs.patches) = tmpGeometryPatches; |
1321 | 1327 | } |
1322 | 1328 |
|
1323 | 1329 | auto reservation = converter->reserve(inputs); |
@@ -1346,6 +1352,7 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1346 | 1352 |
|
1347 | 1353 | prepass.template operator() < ICPUTopLevelAccelerationStructure > (tmpTlas); |
1348 | 1354 | prepass.template operator() < ICPUBuffer > (tmpBuffers); |
| 1355 | + prepass.template operator() < ICPUPolygonGeometry > (tmpGeometries); |
1349 | 1356 | } |
1350 | 1357 |
|
1351 | 1358 | constexpr auto CompBufferCount = 2; |
@@ -1425,25 +1432,37 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1425 | 1432 | auto&& tlases = reservation.getGPUObjects<ICPUTopLevelAccelerationStructure>(); |
1426 | 1433 | m_gpuTlas = tlases[0].value; |
1427 | 1434 | auto&& buffers = reservation.getGPUObjects<ICPUBuffer>(); |
| 1435 | + m_proceduralAabbBuffer = buffers[0].value; |
1428 | 1436 |
|
1429 | | - m_proceduralAabbBuffer = buffers[2 * proceduralBlasIdx].value; |
| 1437 | + auto&& gpuPolygonGeometries = reservation.getGPUObjects<ICPUPolygonGeometry>(); |
| 1438 | + m_gpuPolygons.resize(gpuPolygonGeometries.size()); |
1430 | 1439 |
|
1431 | | - for (uint32_t i = 0; i < cpuObjects.size(); i++) |
| 1440 | + for (uint32_t i = 0; i < gpuPolygonGeometries.size(); i++) |
1432 | 1441 | { |
1433 | 1442 | const auto& cpuObject = cpuObjects[i]; |
1434 | | - const auto& cpuBlas = cpuBlasList[i]; |
1435 | | - const auto& geometry = cpuBlas->getTriangleGeometries()[0]; |
1436 | | - const uint64_t vertexBufferAddress = buffers[2 * i].value->getDeviceAddress(); |
1437 | | - const uint64_t indexBufferAddress = buffers[(2 * i) + 1].value->getDeviceAddress(); |
1438 | | - geomInfos[i] = { |
| 1443 | + const auto& gpuPolygon = gpuPolygonGeometries[i].value; |
| 1444 | + const auto gpuTriangles = gpuPolygon->exportForBLAS(); |
| 1445 | + |
| 1446 | + const auto& vertexBufferBinding = gpuTriangles.vertexData[0]; |
| 1447 | + const uint64_t vertexBufferAddress = vertexBufferBinding.buffer->getDeviceAddress() + vertexBufferBinding.offset; |
| 1448 | + |
| 1449 | + const auto& normalView = gpuPolygon->getNormalView(); |
| 1450 | + const uint64_t normalBufferAddress = normalView ? normalView.src.buffer->getDeviceAddress() + normalView.src.offset : 0; |
| 1451 | + |
| 1452 | + const auto& indexBufferBinding = gpuTriangles.indexData; |
| 1453 | + auto& geomInfo = geomInfos[i]; |
| 1454 | + geomInfo = { |
1439 | 1455 | .material = hlsl::_static_cast<MaterialPacked>(cpuObject.material), |
1440 | 1456 | .vertexBufferAddress = vertexBufferAddress, |
1441 | | - .indexBufferAddress = geometry.indexData.buffer ? indexBufferAddress : vertexBufferAddress, |
1442 | | - .vertexStride = geometry.vertexStride, |
| 1457 | + .indexBufferAddress = indexBufferBinding.buffer ? indexBufferBinding.buffer->getDeviceAddress() + indexBufferBinding.offset : vertexBufferAddress, |
| 1458 | + .normalBufferAddress = normalBufferAddress, |
| 1459 | + .vertexStride = gpuTriangles.vertexStride, |
1443 | 1460 | .objType = cpuObject.meta.type, |
1444 | | - .indexType = geometry.indexType, |
| 1461 | + .indexType = gpuTriangles.indexType, |
1445 | 1462 | .smoothNormals = scene::s_smoothNormals[cpuObject.meta.type], |
1446 | 1463 | }; |
| 1464 | + |
| 1465 | + m_gpuPolygons[i] = gpuPolygon; |
1447 | 1466 | } |
1448 | 1467 | } |
1449 | 1468 |
|
@@ -1508,6 +1527,7 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app |
1508 | 1527 | core::vector<SProceduralGeomInfo> m_gpuIntersectionSpheres; |
1509 | 1528 | uint32_t m_intersectionHitGroupIdx; |
1510 | 1529 |
|
| 1530 | + core::vector<smart_refctd_ptr<IGPUPolygonGeometry>> m_gpuPolygons; |
1511 | 1531 | smart_refctd_ptr<IGPUTopLevelAccelerationStructure> m_gpuTlas; |
1512 | 1532 | smart_refctd_ptr<IGPUBuffer> m_instanceBuffer; |
1513 | 1533 |
|
|
0 commit comments