Skip to content

Commit c5ac743

Browse files
Merge pull request #336 from Devsh-Graphics-Programming/file_rework
File rework
2 parents a5ab385 + a666717 commit c5ac743

File tree

88 files changed

+3030
-3678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3030
-3678
lines changed

3rdparty/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ target_include_directories(volk PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Heade
6262
target_include_directories(volk_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include")
6363

6464
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
65-
add_subdirectory(pstl pstl)
65+
add_subdirectory(pstl pstl EXCLUDE_FROM_ALL)
6666
endif()
6767

6868

3rdparty/pstl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # only non-multi-generators and clang
77
set(PREVIOUS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
88
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
99
set(TBB_SANITIZE "" CACHE STRING "" FORCE)
10-
add_subdirectory(oneTBB oneTBB)
10+
add_subdirectory(oneTBB oneTBB EXCLUDE_FROM_ALL)
1111

1212
if(PREVIOUS_BUILD_SHARED_LIBS)
1313
set(BUILD_SHARED_LIBS ${PREVIOUS_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)

examples_tests/01.HelloWorld/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ class DemoEventCallback : public ui::IWindow::IEventCallback
103103

104104
static core::smart_refctd_ptr<system::ISystem> createSystem()
105105
{
106-
nbl::core::smart_refctd_ptr<system::ISystemCaller> caller = nullptr;
107106
#ifdef _NBL_PLATFORM_WINDOWS_
108-
caller = nbl::core::make_smart_refctd_ptr<nbl::system::CSystemCallerWin32>();
109-
#endif
110-
#ifdef _NBL_PLATFORM_WINDOWS_
111-
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemWin32>(std::move(caller));
107+
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemWin32>();
112108
#endif
113109
return nullptr;
114110
}

examples_tests/05.NablaTutorialExample/main.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class NablaTutorialExampleApp : public ApplicationBase
167167
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
168168
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
169169

170-
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
170+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
171171
window = std::move(initOutput.window);
172172
windowCb = std::move(initOutput.windowCb);
173173
apiConnection = std::move(initOutput.apiConnection);
@@ -202,13 +202,19 @@ class NablaTutorialExampleApp : public ApplicationBase
202202
Loading an asset bundle. You can specify some flags
203203
and parameters to have an impact on extraordinary
204204
tasks while loading for example.
205-
*/
205+
*/
206206

207207
asset::IAssetLoader::SAssetLoadParams loadingParams;
208208
auto images_bundle = assetManager->getAsset("../../media/color_space_test/R8G8B8A8_1.png", loadingParams);
209209
assert(!images_bundle.getContents().empty());
210210
auto image = images_bundle.getContents().begin()[0];
211+
212+
/*
213+
By default an image that comes out of an image loader will only have the TRANSFER_DST usage flag.
214+
We need to add more usages, as only we know what we'll do with the image farther along in the pipeline.
215+
*/
211216
auto image_raw = static_cast<asset::ICPUImage*>(image.get());
217+
image_raw->addImageUsageFlags(asset::IImage::EUF_SAMPLED_BIT);
212218

213219
/*
214220
Specifing gpu image view parameters to create a gpu
@@ -220,7 +226,16 @@ class NablaTutorialExampleApp : public ApplicationBase
220226
cpu2gpuParams.waitForCreationToComplete();
221227
auto& gpuParams = gpuImage->getCreationParameters();
222228

223-
IImageView<IGPUImage>::SCreationParams gpuImageViewParams = { static_cast<IGPUImageView::E_CREATE_FLAGS>(0), gpuImage, IImageView<IGPUImage>::ET_2D, gpuParams.format, {}, {static_cast<IImage::E_ASPECT_FLAGS>(0u), 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers} };
229+
IImageView<IGPUImage>::SCreationParams gpuImageViewParams = {
230+
IGPUImageView::ECF_NONE,
231+
gpuImage,
232+
IImageView<IGPUImage>::ET_2D,
233+
gpuParams.format,
234+
{},
235+
{
236+
IImage::EAF_COLOR_BIT, 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers
237+
}
238+
};
224239
auto gpuImageView = logicalDevice->createGPUImageView(std::move(gpuImageViewParams));
225240

226241
/*
@@ -279,15 +294,18 @@ class NablaTutorialExampleApp : public ApplicationBase
279294
We know ahead of time that `SBasicViewParameters` struct is the expected structure of the only UBO block in the descriptor set nr. 1 of the shader.
280295
*/
281296

282-
IGPUBuffer::SCreationParams creationParams;
297+
IGPUBuffer::SCreationParams creationParams = {};
283298
creationParams.canUpdateSubRange = true;
284299
creationParams.usage = asset::IBuffer::EUF_UNIFORM_BUFFER_BIT;
285-
creationParams.sharingMode = asset::E_SHARING_MODE::ESM_CONCURRENT;
286-
creationParams.queueFamilyIndexCount = 0u;
287-
creationParams.queueFamilyIndices = nullptr;
288300
IDriverMemoryBacked::SDriverMemoryRequirements memReq;
289301
memReq.vulkanReqs.size = sizeof(SBasicViewParameters);
290-
gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams, memReq);
302+
memReq.vulkanReqs.alignment = physicalDevice->getLimits().UBOAlignment;
303+
memReq.vulkanReqs.memoryTypeBits = 0xffffffffu;
304+
memReq.memoryHeapLocation = IDriverMemoryAllocation::ESMT_DEVICE_LOCAL;
305+
memReq.mappingCapability = IDriverMemoryAllocation::EMAF_NONE;
306+
memReq.prefersDedicatedAllocation = true;
307+
memReq.requiresDedicatedAllocation = true;
308+
gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams,memReq);
291309

292310
/*
293311
Creating descriptor sets - texture (sampler) and basic view parameters (UBO).
@@ -380,6 +398,7 @@ class NablaTutorialExampleApp : public ApplicationBase
380398
if (cpuindexbuffer)
381399
cpubuffers.push_back(cpuindexbuffer);
382400

401+
cpu2gpuParams.beginCommandBuffers();
383402
auto gpubuffers = cpu2gpu.getGPUObjectsFromAssets(cpubuffers.data(), cpubuffers.data() + cpubuffers.size(), cpu2gpuParams);
384403
cpu2gpuParams.waitForCreationToComplete();
385404

examples_tests/common/CommonAPI.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,8 @@ class CommonAPI
388388
{
389389
using namespace nbl;
390390
using namespace system;
391-
nbl::core::smart_refctd_ptr<nbl::system::ISystemCaller> caller = nullptr;
392391
#ifdef _NBL_PLATFORM_WINDOWS_
393-
caller = nbl::core::make_smart_refctd_ptr<nbl::system::CSystemCallerWin32>();
394-
#endif
395-
#ifdef _NBL_PLATFORM_WINDOWS_
396-
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemWin32>(std::move(caller));
392+
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemWin32>();
397393
#elif defined(_NBL_PLATFORM_ANDROID_)
398394
#if 0
399395
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemAndroid>(std::move(caller));

include/nbl/asset/IAssetManager.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,12 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
326326
_override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel);
327327

328328
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
329-
bool validInput = m_system->createFile(future, filePath, system::IFile::ECF_READ);
330-
if (!validInput)
329+
m_system->createFile(future, filePath, system::IFile::ECF_READ);
330+
auto file = future.get();
331+
if (!file)
331332
return SAssetBundle(0);
332333

333-
core::smart_refctd_ptr<system::IFile> file = future.get();
334-
SAssetBundle asset = getAssetInHierarchy_impl<RestoreWholeBundle>(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
335-
336-
return asset;
334+
return getAssetInHierarchy_impl<RestoreWholeBundle>(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override);
337335
}
338336

339337
//TODO change name
@@ -647,10 +645,9 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
647645
if (!_override)
648646
_override = &defOverride;
649647

650-
core::smart_refctd_ptr<system::IFile> file;
651648
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
652-
bool valid = m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE);
653-
if (valid) file = future.get();
649+
m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE);
650+
auto file = future.get();
654651
if (file) // could fail creating file (lack of permissions)
655652
{
656653
bool res = writeAsset(file.get(), _params, _override);

include/nbl/asset/ICPUShader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ class ICPUShader : public IAsset, public IShader
9595
if(isImmutable_debug())
9696
return m_shaderStage == stage;
9797
m_shaderStage = stage;
98+
return true;
9899
}
99100

100101
bool setFilePathHint(std::string&& filepathHint)
101102
{
102103
if(isImmutable_debug())
103104
return false;
104105
m_filepathHint = std::move(filepathHint);
106+
return true;
105107
}
106108

107109
bool canBeRestoredFrom(const IAsset* _other) const override

include/nbl/asset/IImageView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class IImageView : public IDescriptor
2222
// no flags for now, yet
2323
enum E_CREATE_FLAGS
2424
{
25+
ECF_NONE = 0
2526
};
2627
enum E_TYPE
2728
{

include/nbl/asset/utils/CDirQuantCacheBase.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
298298
return false;
299299

300300
auto buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(file->getSize());
301-
system::future<size_t> future;
302301

303-
file->read(future, buffer->getPointer(), 0, file->getSize());
304-
future.get();
302+
system::IFile::success_t succ;
303+
file->read(succ, buffer->getPointer(), 0, file->getSize());
304+
if (!succ)
305+
return false;
305306

306307
asset::SBufferRange<const asset::ICPUBuffer> bufferRange;
307308
bufferRange.offset = 0;
@@ -315,12 +316,11 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
315316
inline bool loadCacheFromFile(nbl::system::ISystem* system, const system::path& path, bool replaceCurrentContents = false)
316317
{
317318
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
318-
bool validInput = system->createFile(future,path,nbl::system::IFile::ECF_READ);
319-
320-
if (!validInput)
319+
system->createFile(future,path,nbl::system::IFile::ECF_READ);
320+
auto file = future.get();
321+
if (!file)
321322
return false;
322323

323-
core::smart_refctd_ptr<system::IFile> file = future.get();
324324
return loadCacheFromFile<CacheFormat>(file.get(),replaceCurrentContents);
325325
}
326326

@@ -352,25 +352,22 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase
352352

353353
saveCacheToBuffer<CacheFormat>(bufferRange);
354354

355-
system::future<size_t> future;
356-
file->write(future, bufferRange.buffer->getPointer(), 0, bufferRange.buffer->getSize());
357-
future.get(); // NOTE: should it wait?
358-
359-
return true;
355+
system::IFile::success_t succ;
356+
file->write(succ,bufferRange.buffer->getPointer(), 0, bufferRange.buffer->getSize());
357+
return bool(succ);
360358
}
361359

362360
//!
363361
template<E_FORMAT CacheFormat>
364362
inline bool saveCacheToFile(nbl::system::ISystem* system, const system::path& path)
365363
{
366364
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
367-
bool validInput = system->createFile(future, path, nbl::system::IFile::ECF_WRITE);
368-
369-
if (!validInput)
365+
system->createFile(future, path, nbl::system::IFile::ECF_WRITE);
366+
auto file = future.get();
367+
if (!file)
370368
return false;
371369

372-
core::smart_refctd_ptr<system::IFile> file = future.get();
373-
return saveCacheToFile<CacheFormat>(file.get());
370+
return bool(saveCacheToFile<CacheFormat>(file.get()));
374371
}
375372

376373
//!

include/nbl/core/util/bitflag.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef __NBL_CORE_C_BITFLAG_H_INCLUDED__
6-
#define __NBL_CORE_C_BITFLAG_H_INCLUDED__
5+
#ifndef _NBL_CORE_C_BITFLAG_H_INCLUDED_
6+
#define _NBL_CORE_C_BITFLAG_H_INCLUDED_
77

8-
namespace nbl
9-
{
10-
namespace core
8+
namespace nbl::core
119
{
1210

1311
template <typename ENUM_TYPE>
@@ -18,7 +16,7 @@ struct bitflag final
1816
ENUM_TYPE value = static_cast<ENUM_TYPE>(0);
1917

2018
bitflag() = default;
21-
bitflag(ENUM_TYPE value) : value(value) {}
19+
bitflag(const ENUM_TYPE value) : value(value) {}
2220

2321
inline bitflag<ENUM_TYPE> operator~() { return static_cast<ENUM_TYPE>(~value); }
2422
inline bitflag<ENUM_TYPE> operator|(bitflag<ENUM_TYPE> rhs) const { return static_cast<ENUM_TYPE>(value | rhs.value); }
@@ -30,7 +28,6 @@ struct bitflag final
3028
inline bool hasValue(bitflag<ENUM_TYPE> val) const { return (value & val.value) != 0; }
3129
};
3230

33-
}
3431
}
3532

3633
#endif

0 commit comments

Comments
 (0)