Skip to content

Commit 08b8a38

Browse files
author
devsh
committed
staging cache merge
1 parent cb903df commit 08b8a38

File tree

2 files changed

+1
-136
lines changed

2 files changed

+1
-136
lines changed

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -7,145 +7,10 @@
77
#include "nbl/core/declarations.h"
88
#include "nbl/core/alloc/LinearAddressAllocator.h"
99

10-
#include <iterator>
11-
12-
13-
//#include "nbl/asset/asset.h"
14-
15-
16-
#include "nbl/video/asset_traits.h"
1710
#include "nbl/video/ISemaphore.h"
1811
#include "nbl/video/ILogicalDevice.h"
1912

2013
#if 0
21-
auto IGPUObjectFromAssetConverter::create(const asset::ICPUBuffer** const _begin, const asset::ICPUBuffer** const _end, SParams& _params) -> created_gpu_object_array<asset::ICPUBuffer> // TODO: improve for caches of very large buffers!!!
22-
{
23-
const auto assetCount = std::distance(_begin, _end);
24-
auto res = core::make_refctd_dynamic_array<created_gpu_object_array<asset::ICPUBuffer> >(assetCount);
25-
26-
const auto& limits = _params.device->getPhysicalDevice()->getLimits();
27-
28-
const uint64_t alignment =
29-
std::max<uint64_t>(
30-
std::max<uint64_t>(limits.bufferViewAlignment,limits.minSSBOAlignment),
31-
std::max<uint64_t>(limits.minUBOAlignment, _NBL_SIMD_ALIGNMENT)
32-
);
33-
34-
const uint64_t maxBufferSize = limits.maxBufferSize;
35-
auto out = res->begin();
36-
auto firstInBlock = out;
37-
auto newBlock = [&]() -> auto
38-
{
39-
return core::LinearAddressAllocator<uint64_t>(nullptr, 0u, 0u, alignment, maxBufferSize);
40-
};
41-
auto addrAllctr = newBlock();
42-
43-
auto & fence = _params.fences[EQU_TRANSFER];
44-
fence = _params.device->createFence(static_cast<IGPUFence::E_CREATE_FLAGS>(0));
45-
core::smart_refctd_ptr<IGPUCommandBuffer> cmdbuf = _params.perQueue[EQU_TRANSFER].cmdbuf;
46-
47-
IQueue::SSubmitInfo submit;
48-
{
49-
submit.commandBufferCount = 1u;
50-
submit.commandBuffers = &cmdbuf.get();
51-
// CPU to GPU upload doesn't need to wait for anything or narrow down the execution barrier
52-
// buffer and addresses we're writing into are fresh and brand new, don't need to synchronize the writing with anything
53-
submit.waitSemaphoreCount = 0u;
54-
submit.pWaitDstStageMask = nullptr;
55-
submit.pWaitSemaphores = nullptr;
56-
}
57-
58-
assert(cmdbuf && cmdbuf->getState() == IGPUCommandBuffer::STATE::RECORDING);
59-
// cmdbuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
60-
61-
auto finalizeBlock = [&]() -> void
62-
{
63-
auto bufferSize = addrAllctr.get_allocated_size();
64-
if (bufferSize==0u)
65-
return;
66-
67-
IGPUBuffer::SCreationParams bufparams = {};
68-
bufparams.size = bufferSize;
69-
bufparams.usage = core::bitflag(IGPUBuffer::EUF_TRANSFER_DST_BIT);
70-
71-
for (auto it = firstInBlock; it != out; it++)
72-
{
73-
auto cpubuffer = _begin[std::distance(res->begin(), it)];
74-
bufparams.usage |= cpubuffer->getUsageFlags();
75-
}
76-
77-
uint32_t qfams[2]{ _params.perQueue[EQU_TRANSFER].queue->getFamilyIndex(), _params.finalQueueFamIx };
78-
bufparams.queueFamilyIndices = qfams;
79-
bufparams.queueFamilyIndexCount = (qfams[0] == qfams[1]) ? 0u : 2u;
80-
81-
core::bitflag<IDeviceMemoryAllocation::E_MEMORY_ALLOCATE_FLAGS> allocateFlags(IDeviceMemoryAllocation::EMAF_NONE);
82-
if(bufparams.usage.hasFlags(IGPUBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT))
83-
allocateFlags |= IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT;
84-
85-
auto gpubuffer = _params.device->createBuffer(std::move(bufparams));
86-
auto gpubufferMemReqs = gpubuffer->getMemoryReqs();
87-
gpubufferMemReqs.memoryTypeBits &= _params.device->getPhysicalDevice()->getDeviceLocalMemoryTypeBits();
88-
auto gpubufferMem = _params.device->allocate(gpubufferMemReqs, gpubuffer.get(), allocateFlags);
89-
90-
for (auto it = firstInBlock; it != out; it++)
91-
{
92-
if (auto output = *it)
93-
{
94-
auto cpubuffer = _begin[std::distance(res->begin(), it)];
95-
asset::SBufferRange<IGPUBuffer> bufrng;
96-
bufrng.offset = output->getOffset();
97-
bufrng.size = cpubuffer->getSize();
98-
bufrng.buffer = gpubuffer;
99-
output->setBuffer(core::smart_refctd_ptr(gpubuffer));
100-
submit = _params.utilities->updateBufferRangeViaStagingBuffer(
101-
bufrng,cpubuffer->getPointer(),
102-
_params.perQueue[EQU_TRANSFER].queue, fence.get(), submit
103-
);
104-
}
105-
}
106-
};
107-
for (auto it=_begin; it!=_end; it++,out++)
108-
{
109-
auto cpubuffer = *it;
110-
if (cpubuffer->getSize()>maxBufferSize)
111-
continue;
112-
113-
uint64_t addr = addrAllctr.alloc_addr(cpubuffer->getSize(),alignment);
114-
if (addr==decltype(addrAllctr)::invalid_address)
115-
{
116-
finalizeBlock();
117-
firstInBlock = out;
118-
addrAllctr = newBlock();
119-
addr = addrAllctr.alloc_addr(cpubuffer->getSize(),alignment);
120-
}
121-
assert(addr != decltype(addrAllctr)::invalid_address);
122-
*out = core::make_smart_refctd_ptr<typename asset_traits<asset::ICPUBuffer>::GPUObjectType>(addr);
123-
}
124-
finalizeBlock();
125-
126-
// TODO: submit outside of `create` and make the function take an already created semaphore to signal
127-
cmdbuf->end();
128-
core::smart_refctd_ptr<IGPUSemaphore> sem;
129-
if (_params.perQueue[EQU_TRANSFER].semaphore)
130-
{
131-
sem = _params.device->createSemaphore();
132-
submit.signalSemaphoreCount = 1u;
133-
submit.pSignalSemaphores = &sem.get();
134-
}
135-
else
136-
{
137-
submit.signalSemaphoreCount = 0u;
138-
submit.pSignalSemaphores = nullptr;
139-
}
140-
// transfer_fence needs to be signalled because of the streaming buffer uploads need to be fenced
141-
_params.perQueue[EQU_TRANSFER].queue->submit(1u,&submit,fence.get());
142-
if (_params.perQueue[EQU_TRANSFER].semaphore)
143-
_params.perQueue[EQU_TRANSFER].semaphore[0] = std::move(sem);
144-
145-
return res;
146-
}
147-
148-
14914
// TODO: rewrite after GPU polyphase implementation
15015
auto IGPUObjectFromAssetConverter::create(const asset::ICPUImage** const _begin, const asset::ICPUImage** const _end, SParams& _params) -> created_gpu_object_array<asset::ICPUImage>
15116
{

0 commit comments

Comments
 (0)