| 1387 | } |
| 1388 | |
| 1389 | void DXRPathTracer::BuildRTAccelerationStructure() |
| 1390 | { |
| 1391 | const FormattedBuffer& idxBuffer = currentModel->IndexBuffer(); |
| 1392 | const StructuredBuffer& vtxBuffer = currentModel->VertexBuffer(); |
| 1393 | |
| 1394 | const uint64 numMeshes = currentModel->NumMeshes(); |
| 1395 | Array<D3D12_RAYTRACING_GEOMETRY_DESC> geometryDescs(numMeshes); |
| 1396 | |
| 1397 | const uint32 numGeometries = uint32(geometryDescs.Size()); |
| 1398 | Array<GeometryInfo> geoInfoBufferData(numGeometries); |
| 1399 | |
| 1400 | for(uint64 meshIdx = 0; meshIdx < numMeshes; ++meshIdx) |
| 1401 | { |
| 1402 | const Mesh& mesh = currentModel->Meshes()[meshIdx]; |
| 1403 | D3D12_RAYTRACING_GEOMETRY_DESC& geometryDesc = geometryDescs[meshIdx]; |
| 1404 | geometryDesc = { }; |
| 1405 | geometryDesc.Type = D3D12_RAYTRACING_GEOMETRY_TYPE_TRIANGLES; |
| 1406 | geometryDesc.Triangles.IndexBuffer = idxBuffer.GPUAddress + mesh.IndexOffset() * idxBuffer.Stride; |
| 1407 | geometryDesc.Triangles.IndexCount = uint32(mesh.NumIndices()); |
| 1408 | geometryDesc.Triangles.IndexFormat = idxBuffer.Format; |
| 1409 | geometryDesc.Triangles.Transform3x4 = 0; |
| 1410 | geometryDesc.Triangles.VertexFormat = DXGI_FORMAT_R32G32B32_FLOAT; |
| 1411 | geometryDesc.Triangles.VertexCount = uint32(mesh.NumVertices()); |
| 1412 | geometryDesc.Triangles.VertexBuffer.StartAddress = vtxBuffer.GPUAddress + mesh.VertexOffset() * vtxBuffer.Stride; |
| 1413 | geometryDesc.Triangles.VertexBuffer.StrideInBytes = vtxBuffer.Stride; |
| 1414 | geometryDesc.Flags = D3D12_RAYTRACING_GEOMETRY_FLAG_OPAQUE; |
| 1415 | |
| 1416 | GeometryInfo& geoInfo = geoInfoBufferData[meshIdx]; |
| 1417 | geoInfo = { }; |
| 1418 | geoInfo.VtxOffset = uint32(mesh.VertexOffset()); |
| 1419 | geoInfo.IdxOffset = uint32(mesh.IndexOffset()); |
| 1420 | geoInfo.MaterialIdx = mesh.MeshParts()[0].MaterialIdx; |
| 1421 | |
| 1422 | Assert_(mesh.NumMeshParts() == 1); |
| 1423 | } |
| 1424 | |
| 1425 | // Get required sizes for an acceleration structure |
| 1426 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS buildFlags = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_TRACE; |
| 1427 | |
| 1428 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO topLevelPrebuildInfo = {}; |
| 1429 | |
| 1430 | { |
| 1431 | D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS prebuildInfoDesc = {}; |
| 1432 | prebuildInfoDesc.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY; |
| 1433 | prebuildInfoDesc.Flags = buildFlags; |
| 1434 | prebuildInfoDesc.Type = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL; |
| 1435 | prebuildInfoDesc.pGeometryDescs = nullptr; |
| 1436 | prebuildInfoDesc.NumDescs = 1; |
| 1437 | DX12::Device->GetRaytracingAccelerationStructurePrebuildInfo(&prebuildInfoDesc, &topLevelPrebuildInfo); |
| 1438 | } |
| 1439 | |
| 1440 | Assert_(topLevelPrebuildInfo.ResultDataMaxSizeInBytes > 0); |
| 1441 | |
| 1442 | D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO bottomLevelPrebuildInfo = {}; |
| 1443 | |
| 1444 | { |
| 1445 | D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS prebuildInfoDesc = {}; |
| 1446 | prebuildInfoDesc.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY; |
nothing calls this directly
no test coverage detected