|
11 | 11 | #include "nbl/video/ILogicalDevice.h"
|
12 | 12 |
|
13 | 13 | #if 0
|
14 |
| -auto IGPUObjectFromAssetConverter::create(const asset::ICPUAccelerationStructure** _begin, const asset::ICPUAccelerationStructure** _end, SParams& _params) -> created_gpu_object_array<asset::ICPUAccelerationStructure> |
15 |
| -{ |
16 |
| - const size_t assetCount = std::distance(_begin, _end); |
17 |
| - auto res = core::make_refctd_dynamic_array<created_gpu_object_array<asset::ICPUAccelerationStructure> >(assetCount); |
18 |
| - auto toCreateAndBuild = std::vector<const asset::ICPUAccelerationStructure*>(); |
19 |
| - auto buildRangeInfos = std::vector<IGPUAccelerationStructure::BuildRangeInfo*>(); |
20 |
| - toCreateAndBuild.reserve(assetCount); |
21 |
| - buildRangeInfos.reserve(assetCount); |
22 |
| - // Lambda function: creates the acceleration structure and It's buffer |
23 |
| - auto allocateBufferAndCreateAccelerationStructure = [&](size_t asSize, const asset::ICPUAccelerationStructure* cpuas) |
24 |
| - { |
25 |
| - // Create buffer with cpuas->getAccelerationStructureSize |
26 |
| - IGPUBuffer::SCreationParams gpuBufParams = {}; |
27 |
| - gpuBufParams.size = asSize; |
28 |
| - gpuBufParams.usage = core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_STORAGE_BIT; |
29 |
| - auto gpubuf = _params.device->createBuffer(std::move(gpuBufParams)); |
30 |
| - auto mreqs = gpubuf->getMemoryReqs(); |
31 |
| - mreqs.memoryTypeBits &= _params.device->getPhysicalDevice()->getDeviceLocalMemoryTypeBits(); |
32 |
| - auto gpubufMem = _params.device->allocate(mreqs, gpubuf.get(), IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT); |
33 |
| - assert(gpubufMem.isValid()); |
34 |
| - |
35 |
| - // Create GPUAccelerationStructure with that buffer |
36 |
| - IGPUAccelerationStructure::SCreationParams creatationParams = {}; |
37 |
| - creatationParams.bufferRange.buffer = gpubuf; |
38 |
| - creatationParams.bufferRange.offset = 0; |
39 |
| - creatationParams.bufferRange.size = asSize; |
40 |
| - creatationParams.flags = cpuas->getCreationParameters().flags; |
41 |
| - creatationParams.type = cpuas->getCreationParameters().type; |
42 |
| - return _params.device->createAccelerationStructure(std::move(creatationParams)); |
43 |
| - }; |
44 |
| - |
45 |
| - for (ptrdiff_t i = 0u; i < assetCount; ++i) |
46 |
| - { |
47 |
| - const asset::ICPUAccelerationStructure* cpuas = _begin[i]; |
48 |
| - |
49 |
| - if(cpuas->hasBuildInfo()) |
50 |
| - { |
51 |
| - // Add to toBuild vector of ICPUAccelerationStructure |
52 |
| - toCreateAndBuild.push_back(cpuas); |
53 |
| - buildRangeInfos.push_back(const_cast<IGPUAccelerationStructure::BuildRangeInfo*>(cpuas->getBuildRanges().begin())); |
54 |
| - } |
55 |
| - else if(cpuas->getAccelerationStructureSize() > 0) |
56 |
| - { |
57 |
| - res->operator[](i) = allocateBufferAndCreateAccelerationStructure(cpuas->getAccelerationStructureSize(), cpuas); |
58 |
| - } |
59 |
| - } |
60 |
| - |
61 |
| - if(toCreateAndBuild.empty() == false) |
62 |
| - { |
63 |
| - bool hostBuildCommands = false; // get from SFeatures |
64 |
| - if(hostBuildCommands) |
65 |
| - { |
66 |
| - _NBL_TODO(); |
67 |
| - } |
68 |
| - else |
69 |
| - { |
70 |
| - core::vector<const asset::ICPUBuffer*> cpuBufferDeps; |
71 |
| - constexpr uint32_t MaxGeometryPerBuildInfo = 16; |
72 |
| - constexpr uint32_t MaxBuffersPerGeometry = 3; // TrianglesData -> vertex+index+transformation |
73 |
| - cpuBufferDeps.reserve(assetCount * MaxGeometryPerBuildInfo * MaxBuffersPerGeometry); |
74 |
| - |
75 |
| - // Get CPUBuffer Dependencies |
76 |
| - for (ptrdiff_t i = 0u; i < toCreateAndBuild.size(); ++i) |
77 |
| - { |
78 |
| - const asset::ICPUAccelerationStructure* cpuas = toCreateAndBuild[i]; |
79 |
| - |
80 |
| - auto buildInfo = cpuas->getBuildInfo(); |
81 |
| - assert(buildInfo != nullptr); |
82 |
| - |
83 |
| - auto geoms = buildInfo->getGeometries().begin(); |
84 |
| - auto geomsCount = buildInfo->getGeometries().size(); |
85 |
| - if(geomsCount == 0) |
86 |
| - { |
87 |
| - assert(false); |
88 |
| - continue; |
89 |
| - } |
90 |
| - |
91 |
| - for(uint32_t g = 0; g < geomsCount; ++g) |
92 |
| - { |
93 |
| - const auto& geom = geoms[g]; |
94 |
| - if(geom.type == asset::IAccelerationStructure::EGT_TRIANGLES) |
95 |
| - { |
96 |
| - if(geom.data.triangles.indexData.isValid()) |
97 |
| - { |
98 |
| - auto cpuBuf = geom.data.triangles.indexData.buffer.get(); |
99 |
| - cpuBuf->addUsageFlags(core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT); |
100 |
| - cpuBufferDeps.push_back(cpuBuf); |
101 |
| - } |
102 |
| - if(geom.data.triangles.vertexData.isValid()) |
103 |
| - { |
104 |
| - auto cpuBuf = geom.data.triangles.vertexData.buffer.get(); |
105 |
| - cpuBuf->addUsageFlags(core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT); |
106 |
| - cpuBufferDeps.push_back(cpuBuf); |
107 |
| - } |
108 |
| - if(geom.data.triangles.transformData.isValid()) |
109 |
| - { |
110 |
| - auto cpuBuf = geom.data.triangles.transformData.buffer.get(); |
111 |
| - cpuBuf->addUsageFlags(core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT); |
112 |
| - cpuBufferDeps.push_back(cpuBuf); |
113 |
| - } |
114 |
| - } |
115 |
| - else if(geom.type == asset::IAccelerationStructure::EGT_AABBS) |
116 |
| - { |
117 |
| - if(geom.data.aabbs.data.isValid()) |
118 |
| - { |
119 |
| - auto cpuBuf = geom.data.aabbs.data.buffer.get(); |
120 |
| - cpuBuf->addUsageFlags(core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT); |
121 |
| - cpuBufferDeps.push_back(cpuBuf); |
122 |
| - } |
123 |
| - } |
124 |
| - else if(geom.type == asset::IAccelerationStructure::EGT_INSTANCES) |
125 |
| - { |
126 |
| - if(geom.data.instances.data.isValid()) |
127 |
| - { |
128 |
| - auto cpuBuf = geom.data.instances.data.buffer.get(); |
129 |
| - cpuBuf->addUsageFlags(core::bitflag(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT) | asset::IBuffer::EUF_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT); |
130 |
| - cpuBufferDeps.push_back(cpuBuf); |
131 |
| - } |
132 |
| - } |
133 |
| - } |
134 |
| - } |
135 |
| - |
136 | 14 | // Convert CPUBuffer Deps to GPUBuffers
|
137 | 15 | core::vector<size_t> redirs = eliminateDuplicatesAndGenRedirs(cpuBufferDeps);
|
138 | 16 | auto gpuBufs = getGPUObjectsFromAssets<asset::ICPUBuffer>(cpuBufferDeps.data(), cpuBufferDeps.data()+cpuBufferDeps.size(), _params);
|
@@ -285,47 +163,6 @@ auto IGPUObjectFromAssetConverter::create(const asset::ICPUAccelerationStructure
|
285 | 163 | auto & gpuBuildInfo = buildGeomInfos[i];
|
286 | 164 | gpuBuildInfo.scratchAddr.buffer = gpuScratchBuf;
|
287 | 165 | }
|
288 |
| - |
289 |
| - // Record CommandBuffer for Building (We have Completed buildInfos + buildRanges for each CPUAS) |
290 |
| - auto & fence = _params.fences[EQU_COMPUTE]; |
291 |
| - fence = _params.device->createFence(static_cast<IGPUFence::E_CREATE_FLAGS>(0)); |
292 |
| - core::smart_refctd_ptr<IGPUCommandBuffer> cmdbuf = _params.perQueue[EQU_COMPUTE].cmdbuf; |
293 |
| - |
294 |
| - IQueue::SSubmitInfo submit; |
295 |
| - { |
296 |
| - submit.commandBufferCount = 1u; |
297 |
| - submit.commandBuffers = &cmdbuf.get(); |
298 |
| - submit.waitSemaphoreCount = 0u; |
299 |
| - submit.pWaitDstStageMask = nullptr; |
300 |
| - submit.pWaitSemaphores = nullptr; |
301 |
| - uint32_t waitSemaphoreCount = 0u; |
302 |
| - } |
303 |
| - |
304 |
| - assert(cmdbuf->getState() == IGPUCommandBuffer::STATE::RECORDING); |
305 |
| - cmdbuf->buildAccelerationStructures({buildGeomInfos.data(),buildGeomInfos.data()+buildGeomInfos.size()},buildRangeInfos.data()); |
306 |
| - cmdbuf->end(); |
307 |
| - |
308 |
| - // TODO for future to make this function more sophisticated: Compaction, MemoryLimit for Build |
309 |
| - |
310 |
| - core::smart_refctd_ptr<IGPUSemaphore> sem; |
311 |
| - |
312 |
| - if (_params.perQueue[EQU_COMPUTE].semaphore) |
313 |
| - sem = _params.device->createSemaphore(); |
314 |
| - |
315 |
| - auto* sem_ptr = sem.get(); |
316 |
| - auto* fence_ptr = fence.get(); |
317 |
| - |
318 |
| - submit.signalSemaphoreCount = sem_ptr?1u:0u; |
319 |
| - submit.pSignalSemaphores = sem_ptr?&sem_ptr:nullptr; |
320 |
| - |
321 |
| - _params.perQueue[EQU_COMPUTE].queue->submit(1u, &submit, fence_ptr); |
322 |
| - if (_params.perQueue[EQU_COMPUTE].semaphore) |
323 |
| - _params.perQueue[EQU_COMPUTE].semaphore[0] = std::move(sem); |
324 |
| - } |
325 |
| - } |
326 |
| - |
327 |
| - return res; |
328 |
| -} |
329 | 166 | #endif
|
330 | 167 |
|
331 | 168 | #endif
|
0 commit comments