@@ -1109,25 +1109,23 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1109
1109
1110
1110
// triangles geometries
1111
1111
auto geometryCreator = make_smart_refctd_ptr<CGeometryCreator>();
1112
- #if 1
1113
- return false ;
1114
- #else
1112
+
1115
1113
const auto cpuObjects = std::array{
1116
- ReferenceObjectCpu {
1117
- .meta = {.type = OT_RECTANGLE, .name = "Plane Mesh"},
1118
- .data = gc->createRectangleMesh(nbl::core::vector2df_SIMD( 10, 10) ),
1114
+ scene:: ReferenceObjectCpu {
1115
+ .meta = {.type = scene:: OT_RECTANGLE, .name = " Plane Mesh" },
1116
+ .data = geometryCreator-> createRectangle ({ 10 , 10 } ),
1119
1117
.material = defaultMaterial,
1120
1118
.transform = planeTransform,
1121
1119
},
1122
- ReferenceObjectCpu {
1123
- .meta = {.type = OT_CUBE, .name = "Cube Mesh"},
1124
- .data = gc->createCubeMesh(nbl::core::vector3df( 1, 1, 1) ),
1120
+ scene:: ReferenceObjectCpu {
1121
+ .meta = {.type = scene:: OT_CUBE, .name = " Cube Mesh" },
1122
+ .data = geometryCreator-> createCube ({ 1 , 1 , 1 } ),
1125
1123
.material = defaultMaterial,
1126
1124
.transform = getTranslationMatrix (0 , 0 .5f , 0 ),
1127
1125
},
1128
- ReferenceObjectCpu {
1129
- .meta = {.type = OT_CUBE, .name = "Cube Mesh 2"},
1130
- .data = gc->createCubeMesh(nbl::core::vector3df( 1.5, 1.5, 1.5) ),
1126
+ scene:: ReferenceObjectCpu {
1127
+ .meta = {.type = scene:: OT_CUBE, .name = " Cube Mesh 2" },
1128
+ .data = geometryCreator-> createCube ({ 1.5 , 1.5 , 1.5 } ),
1131
1129
.material = Material{
1132
1130
.ambient = {0.1 , 0.1 , 0.2 },
1133
1131
.diffuse = {0.2 , 0.2 , 0.8 },
@@ -1137,9 +1135,9 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1137
1135
},
1138
1136
.transform = getTranslationMatrix (-5 .0f , 1 .0f , 0 ),
1139
1137
},
1140
- ReferenceObjectCpu {
1141
- .meta = {.type = OT_CUBE, .name = "Transparent Cube Mesh"},
1142
- .data = gc->createCubeMesh(nbl::core::vector3df( 1.5, 1.5, 1.5) ),
1138
+ scene:: ReferenceObjectCpu {
1139
+ .meta = {.type = scene:: OT_CUBE, .name = " Transparent Cube Mesh" },
1140
+ .data = geometryCreator-> createCube ({ 1.5 , 1.5 , 1.5 } ),
1143
1141
.material = Material{
1144
1142
.ambient = {0.1 , 0.2 , 0.1 },
1145
1143
.diffuse = {0.2 , 0.8 , 0.2 },
@@ -1151,40 +1149,6 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1151
1149
},
1152
1150
};
1153
1151
1154
- struct CPUTriBufferBindings
1155
- {
1156
- nbl::asset::SBufferBinding<ICPUBuffer> vertex, index;
1157
- };
1158
- std::array<CPUTriBufferBindings, std::size(cpuObjects)> cpuTriBuffers;
1159
-
1160
- for (uint32_t i = 0; i < cpuObjects.size(); i++)
1161
- {
1162
- const auto& cpuObject = cpuObjects[i];
1163
-
1164
- auto vBuffer = smart_refctd_ptr(cpuObject.data.bindings[0].buffer); // no offset
1165
- auto vUsage = bitflag(IGPUBuffer::EUF_STORAGE_BUFFER_BIT) | IGPUBuffer::EUF_TRANSFER_DST_BIT | IGPUBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF |
1166
- IGPUBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT;
1167
- vBuffer->addUsageFlags(vUsage);
1168
- vBuffer->setContentHash(vBuffer->computeContentHash());
1169
-
1170
- auto iBuffer = smart_refctd_ptr(cpuObject.data.indexBuffer.buffer); // no offset
1171
- auto iUsage = bitflag(IGPUBuffer::EUF_STORAGE_BUFFER_BIT) | IGPUBuffer::EUF_TRANSFER_DST_BIT | IGPUBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF |
1172
- IGPUBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT | IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT;
1173
-
1174
- if (cpuObject.data.indexType != EIT_UNKNOWN)
1175
- if (iBuffer)
1176
- {
1177
- iBuffer->addUsageFlags(iUsage);
1178
- iBuffer->setContentHash(iBuffer->computeContentHash());
1179
- }
1180
-
1181
- cpuTriBuffers[i] = {
1182
- .vertex = {.offset = 0, .buffer = vBuffer},
1183
- .index = {.offset = 0, .buffer = iBuffer},
1184
- };
1185
-
1186
- }
1187
-
1188
1152
// procedural geometries
1189
1153
using Aabb = IGPUBottomLevelAccelerationStructure::AABB_t;
1190
1154
@@ -1233,10 +1197,10 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1233
1197
const auto blasCount = std::size (cpuObjects) + 1 ;
1234
1198
const auto proceduralBlasIdx = std::size (cpuObjects);
1235
1199
1236
- std::array<smart_refctd_ptr<ICPUBottomLevelAccelerationStructure>, std::size(cpuObjects)+1u> cpuBlas ;
1200
+ std::array<smart_refctd_ptr<ICPUBottomLevelAccelerationStructure>, std::size (cpuObjects)+1u > cpuBlasList ;
1237
1201
for (uint32_t i = 0 ; i < blasCount; i++)
1238
1202
{
1239
- auto& blas = cpuBlas [i];
1203
+ auto & blas = cpuBlasList [i];
1240
1204
blas = make_smart_refctd_ptr<ICPUBottomLevelAccelerationStructure>();
1241
1205
1242
1206
if (i == proceduralBlasIdx)
@@ -1256,30 +1220,15 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1256
1220
}
1257
1221
else
1258
1222
{
1259
- auto triangles = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUBottomLevelAccelerationStructure::Triangles<ICPUBuffer>>>(1u );
1223
+ auto triangles = make_refctd_dynamic_array<smart_refctd_dynamic_array<ICPUBottomLevelAccelerationStructure::Triangles<ICPUBuffer>>>(cpuObjects[i]. data -> exportForBLAS () );
1260
1224
auto primitiveCounts = make_refctd_dynamic_array<smart_refctd_dynamic_array<uint32_t >>(1u );
1261
1225
1262
1226
auto & tri = triangles->front ();
1263
- auto& primCount = primitiveCounts->front();
1264
- const auto& geom = cpuObjects[i];
1265
- const auto& cpuBuf = cpuTriBuffers[i];
1266
1227
1267
- const bool useIndex = geom.data.indexType != EIT_UNKNOWN;
1268
- const uint32_t vertexStride = geom.data.inputParams.bindings[0].stride;
1269
- const uint32_t numVertices = cpuBuf.vertex.buffer->getSize() / vertexStride;
1228
+ auto & primCount = primitiveCounts->front ();
1229
+ primCount = cpuObjects[i].data ->getPrimitiveCount ();
1270
1230
1271
- if (useIndex)
1272
- primCount = geom.data.indexCount / 3;
1273
- else
1274
- primCount = numVertices / 3;
1275
-
1276
- tri.vertexData[0] = cpuBuf.vertex;
1277
- tri.indexData = useIndex ? cpuBuf.index : cpuBuf.vertex;
1278
- tri.maxVertex = numVertices - 1;
1279
- tri.vertexStride = vertexStride;
1280
- tri.vertexFormat = EF_R32G32B32_SFLOAT;
1281
- tri.indexType = geom.data.indexType;
1282
- tri.geometryFlags = geom.material.isTransparent() ?
1231
+ tri.geometryFlags = cpuObjects[i].material .isTransparent () ?
1283
1232
IGPUBottomLevelAccelerationStructure::GEOMETRY_FLAGS::NO_DUPLICATE_ANY_HIT_INVOCATION_BIT :
1284
1233
IGPUBottomLevelAccelerationStructure::GEOMETRY_FLAGS::OPAQUE_BIT;
1285
1234
@@ -1305,7 +1254,7 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1305
1254
{
1306
1255
const auto isProceduralInstance = i == proceduralBlasIdx;
1307
1256
ICPUTopLevelAccelerationStructure::StaticInstance inst;
1308
- inst.base.blas = cpuBlas [i];
1257
+ inst.base .blas = cpuBlasList [i];
1309
1258
inst.base .flags = static_cast <uint32_t >(IGPUTopLevelAccelerationStructure::INSTANCE_FLAGS::TRIANGLE_FACING_CULL_DISABLE_BIT);
1310
1259
inst.base .instanceCustomIndex = i;
1311
1260
inst.base .instanceShaderBindingTableRecordOffset = isProceduralInstance ? 2 : 0 ;;
@@ -1356,18 +1305,19 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1356
1305
inputs.allocator = &myalloc;
1357
1306
1358
1307
std::array<ICPUTopLevelAccelerationStructure*, 1u > tmpTlas;
1359
- std::array<ICPUBuffer*, 2 * std::size(cpuObjects) + 1u> tmpBuffers;
1308
+ std::array<ICPUPolygonGeometry*, std::size (cpuObjects)> tmpGeometries;
1309
+ std::array<ICPUBuffer*, 1 > tmpBuffers;
1360
1310
{
1361
1311
tmpTlas[0 ] = cpuTlas.get ();
1312
+ tmpBuffers[0 ] = cpuProcBuffer.get ();
1362
1313
for (uint32_t i = 0 ; i < cpuObjects.size (); i++)
1363
1314
{
1364
- tmpBuffers[2 * i + 0] = cpuTriBuffers[i].vertex.buffer.get();
1365
- tmpBuffers[2 * i + 1] = cpuTriBuffers[i].index.buffer.get();
1315
+ tmpGeometries[i] = cpuObjects[i].data .get ();
1366
1316
}
1367
- tmpBuffers[2 * proceduralBlasIdx] = cpuProcBuffer.get();
1368
1317
1369
1318
std::get<CAssetConverter::SInputs::asset_span_t <ICPUTopLevelAccelerationStructure>>(inputs.assets ) = tmpTlas;
1370
1319
std::get<CAssetConverter::SInputs::asset_span_t <ICPUBuffer>>(inputs.assets ) = tmpBuffers;
1320
+ std::get<CAssetConverter::SInputs::asset_span_t <ICPUPolygonGeometry>>(inputs.assets ) = tmpGeometries;
1371
1321
}
1372
1322
1373
1323
auto reservation = converter->reserve (inputs);
@@ -1475,37 +1425,24 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1475
1425
auto && tlases = reservation.getGPUObjects <ICPUTopLevelAccelerationStructure>();
1476
1426
m_gpuTlas = tlases[0 ].value ;
1477
1427
auto && buffers = reservation.getGPUObjects <ICPUBuffer>();
1478
- for (uint32_t i = 0; i < cpuObjects.size(); i++)
1479
- {
1480
- auto& cpuObject = cpuObjects[i];
1481
-
1482
- m_gpuTriangleGeometries.push_back(ReferenceObjectGpu{
1483
- .meta = cpuObject.meta,
1484
- .bindings = {
1485
- .vertex = {.offset = 0, .buffer = buffers[2 * i + 0].value },
1486
- .index = {.offset = 0, .buffer = buffers[2 * i + 1].value },
1487
- },
1488
- .vertexStride = cpuObject.data.inputParams.bindings[0].stride,
1489
- .indexType = cpuObject.data.indexType,
1490
- .indexCount = cpuObject.data.indexCount,
1491
- .material = hlsl::_static_cast<MaterialPacked>(cpuObject.material),
1492
- .transform = cpuObject.transform,
1493
- });
1494
- }
1428
+
1495
1429
m_proceduralAabbBuffer = buffers[2 * proceduralBlasIdx].value ;
1496
1430
1497
- for (uint32_t i = 0; i < m_gpuTriangleGeometries .size(); i++)
1431
+ for (uint32_t i = 0 ; i < cpuObjects .size (); i++)
1498
1432
{
1499
- const auto& gpuObject = m_gpuTriangleGeometries[i];
1500
- const uint64_t vertexBufferAddress = gpuObject.bindings.vertex.buffer->getDeviceAddress();
1433
+ 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 ();
1501
1438
geomInfos[i] = {
1502
- .material = gpuObject .material,
1439
+ .material = hlsl::_static_cast<MaterialPacked>(cpuObject .material ) ,
1503
1440
.vertexBufferAddress = vertexBufferAddress,
1504
- .indexBufferAddress = gpuObject.useIndex() ? gpuObject.bindings.index.buffer->getDeviceAddress() : vertexBufferAddress,
1505
- .vertexStride = gpuObject .vertexStride,
1506
- .objType = gpuObject .meta.type,
1507
- .indexType = gpuObject .indexType,
1508
- .smoothNormals = s_smoothNormals[gpuObject .meta.type],
1441
+ .indexBufferAddress = geometry. indexData . buffer ? indexBufferAddress : vertexBufferAddress,
1442
+ .vertexStride = geometry .vertexStride ,
1443
+ .objType = cpuObject .meta .type ,
1444
+ .indexType = geometry .indexType ,
1445
+ .smoothNormals = scene:: s_smoothNormals[cpuObject .meta .type ],
1509
1446
};
1510
1447
}
1511
1448
}
@@ -1516,12 +1453,10 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1516
1453
params.size = geomInfoBuffer->getSize ();
1517
1454
m_utils->createFilledDeviceLocalBufferOnDedMem (SIntendedSubmitInfo{ .queue = queue }, std::move (params), geomInfos).move_into (m_triangleGeomInfoBuffer);
1518
1455
}
1519
- # endif
1456
+
1520
1457
return true ;
1521
1458
}
1522
1459
1523
-
1524
-
1525
1460
smart_refctd_ptr<IWindow> m_window;
1526
1461
smart_refctd_ptr<CSimpleResizeSurface<ISimpleManagedSurface::ISwapchainResources>> m_surface;
1527
1462
smart_refctd_ptr<ISemaphore> m_semaphore;
@@ -1570,8 +1505,6 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public app
1570
1505
} m_ui;
1571
1506
core::smart_refctd_ptr<IDescriptorPool> m_guiDescriptorSetPool;
1572
1507
1573
- // TODO: how much of this do we actually have to keep ?
1574
- // core::vector<ReferenceObjectGpu> m_gpuTriangleGeometries;
1575
1508
core::vector<SProceduralGeomInfo> m_gpuIntersectionSpheres;
1576
1509
uint32_t m_intersectionHitGroupIdx;
1577
1510
0 commit comments