Skip to content

Commit 1296f28

Browse files
committed
Merge branch 'master' of https://github.com/Devsh-Graphics-Programming/Nabla into mesh_packer
2 parents a2e40f0 + 85f511b commit 1296f28

File tree

80 files changed

+3537
-4463
lines changed

Some content is hidden

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

80 files changed

+3537
-4463
lines changed

.github/workflows/repo_mirroring_workflow.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ else()
7979
endif()
8080

8181
macro(nbl_adjust_flags)
82-
option(NBL_GCC_SANITIZE_ADDRESS OFF)
83-
option(NBL_GCC_SANITIZE_THREAD OFF)
82+
option(NBL_SANITIZE_ADDRESS OFF)
83+
option(NBL_GCC_SANITIZE_THREAD OFF) # @Anastazluk did MSVC finally include the thread sanitizer?
8484

8585
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
8686
if (NOT NBL_BUILD_CEGUI)
@@ -110,7 +110,7 @@ macro(nbl_adjust_flags)
110110
#"$<$<CONFIG:RELEASE>:-O3>" # added by default and apparently cmake is not clever enough to filter duplicates for this one
111111
"$<$<CONFIG:RELEASE>:-fexpensive-optimizations>"
112112
)
113-
if (NBL_GCC_SANITIZE_ADDRESS)
113+
if (NBL_SANITIZE_ADDRESS)
114114
add_compile_options(-fsanitize=address)
115115
endif()
116116
if (NBL_GCC_SANITIZE_THREAD)
@@ -132,28 +132,33 @@ macro(nbl_adjust_flags)
132132
add_compile_options("$<$<CONFIG:DEBUG>:-ggdb3>")
133133
endif()
134134
elseif(MSVC) # /arch:sse3 or anything like this is not needed on x64 on MSVC for enabling sse3 instructions
135+
if (NBL_SANITIZE_ADDRESS)
136+
set(NBL_MSVC_FLAG_SANITIZE_ADDRESS "/fsanitize=address")
137+
message(WARNING "Due to https://github.com/google/sanitizers/issues/328 expect not to be able to use the Debug target!")
138+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /wholearchive:clang_rt.asan_dbg-x86_64.lib /wholearchive:clang_rt.asan_cxx_dbg-x86_64.lib")
139+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /wholearchive:clang_rt.asan-x86_64.lib /wholearchive:clang_rt.asan_cxx-x86_64.lib")
140+
endif()
135141

136142
# debug
137143
string(REPLACE "/W3" "/W0" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
138-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zc:__cplusplus /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL" )
144+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zc:__cplusplus /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL ${NBL_MSVC_SANITIZE_ADDRESS}" )
139145
string(REPLACE "/W3" "/W0" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
140-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL")
146+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MP /ZI /fp:fast /Zc:wchar_t /INCREMENTAL ${NBL_MSVC_SANITIZE_ADDRESS}")
141147

142148
# release
143149
string(REPLACE "/GS" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") # for some reason simply replacing /GS -> /GS- doesn't work... so it vanishes here and appears a few lines below!
144-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Zc:__cplusplus /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast")
150+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Zc:__cplusplus /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
145151
string(REPLACE "/GS" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
146-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast")
152+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /MP /Gy- /Zc:wchar_t /sdl- /GF /GS- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
147153

148154
# relWithDebInfo
149155
string(REPLACE "/GS" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
150-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL /Zc:__cplusplus /Zc:wchar_t /MP /Gy /Zi /sdl- /Oy- /fp:fast")
156+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL /Zc:__cplusplus /Zc:wchar_t /MP /Gy /Zi /sdl- /Oy- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
151157
string(REPLACE "/GS" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
152-
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /GL /MP /Gy /Zc:wchar_t /Zi /sdl- /Oy- /fp:fast")
158+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /GL /MP /Gy /Zc:wchar_t /Zi /sdl- /Oy- /fp:fast ${NBL_MSVC_SANITIZE_ADDRESS}")
153159

154160
#reason for INCREMENTAL:NO: https://docs.microsoft.com/en-us/cpp/build/reference/ltcg-link-time-code-generation?view=vs-2019 /LTCG is not valid for use with /INCREMENTAL.
155161
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO /LTCG:incremental")
156-
157162
else()
158163
message(WARNING "UNTESTED COMPILER DETECTED, EXPECT WRONG OPTIMIZATION FLAGS! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues")
159164
endif()

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22

33
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
44

5-
**Nabla**(previously called **[IrrlichtBaW](https://github.com/buildaworldnet/IrrlichtBAW)** is a new renovated version of older **[Irrlicht](http://irrlicht.sourceforge.net/)** engine. The name change to Nabla allows for using Nabla side by side with the legacy Irrlicht and IrrlichtBaW engines.
6-
The project currently aims for a thread-able and *Vulkan*-centered API, but currently works on *OpenGL* only. This framework has been kindly begun by the founder ***[@devshgraphicsprogramming](https://github.com/devshgraphicsprogramming)*** of **[Devsh Graphics Programming Sp. z O.O.](http://devsh.eu/)** and almost entirely sponsored by **Build A World Aps**. in it's early days, and now picked up by the **[Ditt](https://www.ditt.nl/)** company. The `stable-ish` branch is used in production releases of **[Build A World EDU](https://edu.buildaworld.net/)**, since 2015. The framework has been used both for game development and ArchViz.
5+
**Nabla**(previously called **[IrrlichtBaW](https://github.com/buildaworldnet/IrrlichtBAW)** is a new renovated version of older **[Irrlicht](http://irrlicht.sourceforge.net/)** engine.
6+
The name change to Nabla allows for using Nabla side by side with the legacy Irrlicht and IrrlichtBaW engines.
7+
The project currently aims for a thread-able and *Vulkan*-centered API, but currently works on *OpenGL* only.
78

8-
## Contracting
9+
This framework has been kindly begun by the founder ***[@devshgraphicsprogramming](https://github.com/devshgraphicsprogramming)*** of **[Devsh Graphics Programming Sp. z O.O.](http://devsh.eu/)** and almost entirely sponsored by **Build A World Aps**. in it's early days, and now picked up by the **[Ditt](https://www.ditt.nl/)** company. The `stable-ish` branch is used in production releases of **[Build A World EDU](https://edu.buildaworld.net/)**, since 2015. The framework has been used both for game development and ArchViz.
10+
11+
## (Get Hired) Jobs and Internships
12+
13+
If you are a programmer with a passion for High Performance Computing, Mathematics and Computer Graphics
14+
15+
If you can work 100% remotely and be in charge of your own time managment
16+
17+
Then make something impressive using Nabla, open a PR and contact us (jobs devsh.eu) with your CV.
18+
19+
We would also be happy to sponsor your master thesis as long as:
20+
- You are an above average student with an interest in Graphics
21+
- It will be written in English
22+
- It will produce contributions to Nabla which we can license under Apache 2.0
23+
24+
## (Hire Us) Contracting
925

1026
The members of **Devsh Graphics Programming Sp. z O.O.** (Company Registration (KRS) #: 0000764661) are available (individually or collectively) for contracts on projects of various scopes and timescales, especially on foreign frameworks, codebases and third-party 3D frameworks.
1127

cmake/common.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
155155
endmacro()
156156

157157
macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUDES LIB_OPTIONS)
158-
set(LIB_NAME "IrrExt${EXT_NAME}")
158+
set(LIB_NAME "NblExt${EXT_NAME}")
159159
project(${LIB_NAME})
160160

161161
add_library(${LIB_NAME} ${LIB_SOURCES})

examples_tests/10.AllocatorTest/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class AllocatorHandler
106106
alctr = AlctrType(reservedSpace, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
107107
}
108108

109+
// variable shadowing and other problems @Przemog
109110
testsCnt = rng.getRndAllocCnt();
110111
for (size_t i = 0; i < testsCnt; i++)
111112
executeForFrame(alctr, randAllocParams);

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct SLight
3131
vec3 intensity;
3232
};
3333
34+
layout (push_constant) uniform Block {
35+
float camTformDeterminant;
36+
} PC;
37+
3438
layout (set = 2, binding = 0, std430) readonly restrict buffer Lights
3539
{
3640
SLight lights[];
@@ -54,25 +58,25 @@ vec2 SampleSphericalMap(in vec3 v)
5458
return uv;
5559
}
5660
57-
vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV, in nbl_glsl_MC_precomputed_t precomp)
61+
vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_interaction, in mat2 dUV)
5862
{
5963
nbl_glsl_xoroshiro64star_state_t scramble_start_state = textureLod(scramblebuf,gl_FragCoord.xy/VIEWPORT_SZ,0).rg;
6064
61-
vec3 emissive = nbl_glsl_decodeRGB19E7(InstData.data[InstanceIndex].emissive);
65+
vec3 emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
6266
6367
vec3 color = vec3(0.0);
6468
6569
#ifdef USE_ENVMAP
66-
nbl_glsl_instr_stream_t gcs = getGenChoiceStream(precomp);
67-
nbl_glsl_instr_stream_t rnps = getRemAndPdfStream(precomp);
70+
nbl_glsl_MC_instr_stream_t gcs = nbl_glsl_MC_oriented_material_t_getGenChoiceStream(material);
71+
nbl_glsl_MC_instr_stream_t rnps = nbl_glsl_MC_oriented_material_t_getRemAndPdfStream(material);
6872
for (int i = 0; i < SAMPLE_COUNT; ++i)
6973
{
7074
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
7175
7276
vec3 rand = rand3d(i,scramble_state);
7377
float pdf;
7478
nbl_glsl_LightSample s;
75-
vec3 rem = nbl_glsl_runGenerateAndRemainderStream(precomp, gcs, rnps, rand, pdf, s);
79+
vec3 rem = nbl_glsl_MC_runGenerateAndRemainderStream(precomp, gcs, rnps, rand, pdf, s);
7680
7781
vec2 uv = SampleSphericalMap(s.L);
7882
color += rem*textureLod(envMap, uv, 0.0).xyz;
@@ -83,15 +87,40 @@ vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_inte
8387
for (int i = 0; i < LIGHT_COUNT; ++i)
8488
{
8589
SLight l = lights[i];
86-
vec3 L = l.position-WorldPos;
87-
//params.L = L;
90+
const vec3 L = l.position-WorldPos;
91+
const float d2 = dot(L,L);
8892
const float intensityScale = LIGHT_INTENSITY_SCALE;//ehh might want to render to hdr fbo and do tonemapping
89-
color += nbl_bsdf_cos_eval(precomp, normalize(L), out_interaction, dUV)*l.intensity*intensityScale / dot(L,L);
93+
nbl_glsl_LightSample _sample;
94+
_sample.L = L*inversesqrt(d2);
95+
color += nbl_bsdf_cos_eval(_sample,out_interaction, dUV)*l.intensity*intensityScale/d2;
9096
}
9197
9298
return color+emissive;
9399
}
94100
)";
101+
constexpr const char* GLSL_FRAG_MAIN = R"(
102+
#define _NBL_FRAG_MAIN_DEFINED_
103+
void main()
104+
{
105+
mat2 dUV = mat2(dFdx(UV),dFdy(UV));
106+
107+
// "The sign of this computation is negated when the value of GL_CLIP_ORIGIN (the clip volume origin, set with glClipControl) is GL_UPPER_LEFT."
108+
const bool front = (!gl_FrontFacing) != (PC.camTformDeterminant*InstData.data[InstanceIndex].determinant < 0.0);
109+
nbl_glsl_MC_precomputed_t precomp = nbl_glsl_precomputeData(front);
110+
#ifdef TEX_PREFETCH_STREAM
111+
nbl_glsl_runTexPrefetchStream(getTexPrefetchStream(precomp), UV, dUV);
112+
#endif
113+
#ifdef NORM_PRECOMP_STREAM
114+
nbl_glsl_runNormalPrecompStream(getNormalPrecompStream(precomp), dUV, precomp);
115+
#endif
116+
117+
118+
nbl_glsl_IsotropicViewSurfaceInteraction inter;
119+
vec3 color = nbl_computeLighting(inter, dUV, precomp);
120+
121+
OutColor = vec4(color, 1.0);
122+
}
123+
)";
95124
static core::smart_refctd_ptr<asset::ICPUSpecializedShader> createModifiedFragShader(const asset::ICPUSpecializedShader* _fs, uint32_t viewport_w, uint32_t viewport_h, uint32_t lightCnt, uint32_t smplCnt, float intensityScale)
96125
{
97126
const asset::ICPUShader* unspec = _fs->getUnspecialized();
@@ -108,6 +137,7 @@ static core::smart_refctd_ptr<asset::ICPUSpecializedShader> createModifiedFragSh
108137
GLSL_COMPUTE_LIGHTING;
109138

110139
glsl.insert(glsl.find("#ifndef _NBL_COMPUTE_LIGHTING_DEFINED_"), extra);
140+
glsl.insert(glsl.find("#ifndef _NBL_FRAG_MAIN_DEFINED_"), GLSL_FRAG_MAIN);
111141

112142
//auto* f = fopen("fs.glsl","w");
113143
//fwrite(glsl.c_str(), 1, glsl.size(), f);
@@ -181,7 +211,7 @@ int main()
181211
asset::CQuantNormalCache* qnc = am->getMeshManipulator()->getQuantNormalCache();
182212

183213
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am));
184-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am));
214+
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs));
185215

186216
std::string filePath = "../../media/mitsuba/staircase2.zip";
187217
//#define MITSUBA_LOADER_TESTS
@@ -271,9 +301,9 @@ int main()
271301
return 1;
272302

273303
bool leftHandedCamera = false;
304+
auto cameraTransform = sensor.transform.matrix.extractSub3x4();
274305
{
275-
auto relativeTransform = sensor.transform.matrix.extractSub3x4();
276-
if (relativeTransform.getPseudoDeterminant().x < 0.f)
306+
if (cameraTransform.getPseudoDeterminant().x < 0.f)
277307
leftHandedCamera = true;
278308
}
279309

@@ -292,6 +322,11 @@ int main()
292322
video::IVideoDriver* driver = device->getVideoDriver();
293323
asset::IAssetManager* am = device->getAssetManager();
294324

325+
// look out for this!!!
326+
// when added, CMitsubaLoader inserts its own include loader into GLSLCompiler
327+
// thats why i have to add it again here (after device recreation) to be able to compile shaders
328+
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am, device->getFileSystem()));
329+
295330
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> ds2layout;
296331
{
297332
asset::ICPUDescriptorSetLayout::SBinding bnd[4];
@@ -422,7 +457,13 @@ int main()
422457
//modify pipeline layouts with our custom DS2 layout (DS2 will be used for lights buffer)
423458
for (uint32_t i = 0u; i < mesh->getMeshBufferCount(); ++i)
424459
{
425-
auto* pipeline = mesh->getMeshBuffer(i)->getPipeline();
460+
auto* meshbuffer = mesh->getMeshBuffer(i);
461+
auto* pipeline = meshbuffer->getPipeline();
462+
463+
asset::SPushConstantRange pcr;
464+
pcr.offset = 0u;
465+
pcr.size = sizeof(float);
466+
pcr.stageFlags = asset::ISpecializedShader::ESS_FRAGMENT;
426467
if (modifiedPipelines.find(pipeline) == modifiedPipelines.end())
427468
{
428469
//if (!pipeline->getLayout()->getDescriptorSetLayout(2u))
@@ -436,10 +477,14 @@ int main()
436477
modifiedShaders.insert({ core::smart_refctd_ptr<asset::ICPUSpecializedShader>(fs),newfs });
437478
pipeline->setShaderAtStage(asset::ICPUSpecializedShader::ESS_FRAGMENT, newfs.get());
438479
}
439-
// invert what is recognized as frontface in case of RH camera
440-
pipeline->getRasterizationParams().frontFaceIsCCW = !leftHandedCamera;
480+
481+
auto pc = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<asset::SPushConstantRange>>(1u);
482+
(*pc)[0] = pcr;
483+
pipeline->getLayout()->setPushConstantRanges(std::move(pc));
441484
modifiedPipelines.insert(pipeline);
442485
}
486+
487+
reinterpret_cast<float*>(meshbuffer->getPushConstantsDataPtr() + pcr.offset)[0] = cameraTransform.getPseudoDeterminant().x;
443488
}
444489
}
445490
modifiedShaders.clear();
@@ -721,7 +766,7 @@ int main()
721766
const video::IGPUDescriptorSet* ds[3]{ gpuds0.get(), gpuds1.get(), gpuds2.get() };
722767
driver->bindGraphicsPipeline(pipeline);
723768
driver->bindDescriptorSets(video::EPBP_GRAPHICS, pipeline->getLayout(), 0u, 3u, ds, nullptr);
724-
driver->pushConstants(pipeline->getLayout(), video::IGPUSpecializedShader::ESS_VERTEX|video::IGPUSpecializedShader::ESS_FRAGMENT, 0u, sizeof(uint32_t), mb->getPushConstantsDataPtr());
769+
driver->pushConstants(pipeline->getLayout(), video::IGPUSpecializedShader::ESS_VERTEX|video::IGPUSpecializedShader::ESS_FRAGMENT, 0u, sizeof(float), mb->getPushConstantsDataPtr());
725770

726771
driver->drawMeshBuffer(mb);
727772
}

examples_tests/22.RaytracedAO/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif()
3131

3232
set(EXTRA_SOURCES
3333
../../src/nbl/ext/DebugDraw/CDraw3DLine.cpp
34-
./dirty_source/ExtraCrap.cpp
34+
Renderer.cpp
3535
)
3636

3737
nbl_create_executable_project(

0 commit comments

Comments
 (0)