Skip to content

Commit b4040a1

Browse files
Merge pull request #36 from Crisspl/nabla-master
Mitsuba Loader utilities. `material_compiler_compatibility_impl` is kinda a lame name for this header, but lets not perfect get in the way of good.
2 parents 65874e4 + 85c9a7f commit b4040a1

File tree

13 files changed

+179
-113
lines changed

13 files changed

+179
-113
lines changed

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ int main()
183183
asset::CQuantNormalCache* qnc = am->getMeshManipulator()->getQuantNormalCache();
184184

185185
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am));
186-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am));
186+
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs));
187187

188188
std::string filePath = "../../media/mitsuba/staircase2.zip";
189189
//#define MITSUBA_LOADER_TESTS
@@ -294,6 +294,11 @@ int main()
294294
video::IVideoDriver* driver = device->getVideoDriver();
295295
asset::IAssetManager* am = device->getAssetManager();
296296

297+
// look out for this!!!
298+
// when added, CMitsubaLoader inserts its own include loader into GLSLCompiler
299+
// thats why i have to add it again here (after device recreation) to be able to compile shaders
300+
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am, device->getFileSystem()));
301+
297302
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> ds2layout;
298303
{
299304
asset::ICPUDescriptorSetLayout::SBinding bnd[4];

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main()
4343
asset::IAssetManager* am = device->getAssetManager();
4444

4545
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am));
46-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am));
46+
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am, fs));
4747

4848
//std::string filePath = "../../media/mitsuba/daily_pt.xml";
4949
std::string filePath = "../../media/mitsuba/staircase2.zip";
20 Bytes
Binary file not shown.

include/nbl/asset/IAssetManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
585585
//! @returns 0xdeadbeefu on failure or 0-based index on success.
586586
uint32_t addAssetLoader(core::smart_refctd_ptr<IAssetLoader>&& _loader)
587587
{
588+
_loader->initialize();
589+
588590
// there's no way it ever fails, so no 0xdeadbeef return
589591
const char** exts = _loader->getAssociatedFileExtensions();
590592
size_t extIx = 0u;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndef _NBL_BUILTIN_GLSL_EXT_MITSUBA_LOADER_DESCRIPTORS_INCLUDED_
2+
#define _NBL_BUILTIN_GLSL_EXT_MITSUBA_LOADER_DESCRIPTORS_INCLUDED_
3+
4+
#define _NBL_VT_DESCRIPTOR_SET 0
5+
#define _NBL_VT_PAGE_TABLE_BINDING 0
6+
7+
#define _NBL_VT_FLOAT_VIEWS_BINDING 1
8+
#define _NBL_VT_FLOAT_VIEWS_COUNT _NBL_EXT_MITSUBA_LOADER_VT_STORAGE_VIEW_COUNT
9+
#define _NBL_VT_FLOAT_VIEWS
10+
11+
#define _NBL_VT_INT_VIEWS_BINDING NotApplicable
12+
#define _NBL_VT_INT_VIEWS_COUNT 0
13+
#define _NBL_VT_INT_VIEWS
14+
15+
#define _NBL_VT_UINT_VIEWS_BINDING NotApplicable
16+
#define _NBL_VT_UINT_VIEWS_COUNT 0
17+
#define _NBL_VT_UINT_VIEWS
18+
#include <nbl/builtin/glsl/virtual_texturing/descriptors.glsl>
19+
20+
layout(set = 0, binding = 2, std430) restrict readonly buffer VT_PrecomputedStuffSSBO
21+
{
22+
uint pgtab_sz_log2;
23+
float vtex_sz_rcp;
24+
float phys_pg_tex_sz_rcp[_NBL_VT_MAX_PAGE_TABLE_LAYERS];
25+
uint layer_to_sampler_ix[_NBL_VT_MAX_PAGE_TABLE_LAYERS];
26+
} VT_precomputed;
27+
28+
layout(set = 0, binding = 3, std430) restrict readonly buffer INSTR_BUF
29+
{
30+
nbl_glsl_MC_instr_t data[];
31+
} instr_buf;
32+
layout(set = 0, binding = 4, std430) restrict readonly buffer BSDF_BUF
33+
{
34+
nbl_glsl_MC_bsdf_data_t data[];
35+
} bsdf_buf;
36+
#include <nbl/builtin/glsl/ext/MitsubaLoader/instance_data_struct.glsl>
37+
layout(set = 0, binding = 5, row_major, std430) readonly restrict buffer InstDataBuffer {
38+
nbl_glsl_ext_Mitsuba_Loader_instance_data_t data[];
39+
} InstData;
40+
layout(set = 0, binding = 6, std430) restrict readonly buffer PREFETCH_INSTR_BUF
41+
{
42+
nbl_glsl_MC_prefetch_instr_t data[];
43+
} prefetch_instr_buf;
44+
45+
// Note: this GLSL header defines just those 3 material compiler functions.
46+
// The rest of them must still be defined by the user!
47+
nbl_glsl_MC_instr_t nbl_glsl_MC_fetchInstr(in uint ix)
48+
{
49+
return instr_buf.data[ix];
50+
}
51+
nbl_glsl_MC_prefetch_instr_t nbl_glsl_MC_fetchPrefetchInstr(in uint ix)
52+
{
53+
return prefetch_instr_buf.data[ix];
54+
}
55+
nbl_glsl_MC_bsdf_data_t nbl_glsl_MC_fetchBSDFData(in uint ix)
56+
{
57+
return bsdf_buf.data[ix];
58+
}
59+
60+
uint nbl_glsl_VT_layer2pid(in uint layer)
61+
{
62+
return VT_precomputed.layer_to_sampler_ix[layer];
63+
}
64+
uint nbl_glsl_VT_getPgTabSzLog2()
65+
{
66+
return VT_precomputed.pgtab_sz_log2;
67+
}
68+
float nbl_glsl_VT_getPhysPgTexSzRcp(in uint layer)
69+
{
70+
return VT_precomputed.phys_pg_tex_sz_rcp[layer];
71+
}
72+
float nbl_glsl_VT_getVTexSzRcp()
73+
{
74+
return VT_precomputed.vtex_sz_rcp;
75+
}
76+
#define _NBL_USER_PROVIDED_VIRTUAL_TEXTURING_FUNCTIONS_
77+
78+
#include <nbl/builtin/glsl/virtual_texturing/functions.glsl/7/8>
79+
80+
#endif

include/nbl/ext/MitsubaLoader/CGlobalMitsubaMetadata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class CGlobalMitsubaMetadata : public core::IReferenceCounted
3535
std::string materialCompilerGLSL_declarations;
3636
//has to go after required user-provided descriptors and functions and before the rest of shader (especially entry point function)
3737
std::string materialCompilerGLSL_source;
38+
39+
uint32_t getVTStorageViewCount() const { return VT->getFloatViews().size(); }
3840
};
3941

4042

include/nbl/ext/MitsubaLoader/CMitsubaLoader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ class CMitsubaLoader : public asset::IAssetLoader
3333
friend class CMitsubaMaterialCompilerFrontend;
3434
public:
3535
//! Constructor
36-
CMitsubaLoader(asset::IAssetManager* _manager);
36+
CMitsubaLoader(asset::IAssetManager* _manager, io::IFileSystem* _fs);
37+
38+
void initialize() override;
3739

3840
protected:
3941
asset::IAssetManager* m_manager;
42+
io::IFileSystem* m_filesystem;
4043

4144
//! Destructor
4245
virtual ~CMitsubaLoader() = default;

src/nbl/asset/CGLSLVirtualTexturingBuiltinIncludeLoader.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,9 @@ class CGLSLVirtualTexturingBuiltinIncludeLoader : public IGLSLEmbeddedIncludeLoa
2424
const char* getVirtualDirectoryName() const override { return "glsl/virtual_texturing/"; }
2525

2626
private:
27-
static core::vector<std::string> parseArgumentsFromPath(const std::string& _path)
28-
{
29-
core::vector<std::string> args;
30-
31-
std::stringstream ss{ _path };
32-
std::string arg;
33-
while (std::getline(ss, arg, '/'))
34-
args.push_back(std::move(arg));
35-
36-
return args;
37-
}
38-
3927
static std::string getVTfunctions(const std::string& _path)
4028
{
41-
auto args = parseArgumentsFromPath(_path.substr(_path.find_last_of('glsl')+2, _path.npos));
29+
auto args = parseArgumentsFromPath(_path.substr(_path.rfind(".glsl")+6, _path.npos));
4230
if (args.size()<2u)
4331
return {};
4432

src/nbl/asset/IAssetManager.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,6 @@ void IAssetManager::addLoadersAndWriters()
185185
#ifdef _NBL_COMPILE_WITH_GLI_WRITER_
186186
addAssetWriter(core::make_smart_refctd_ptr<asset::CGLIWriter>());
187187
#endif
188-
189-
190-
for (size_t i = 0; i < m_loaders.vector.size(); i++)
191-
{
192-
m_loaders.vector[i]->initialize();
193-
}
194188
}
195189

196190

src/nbl/asset/IGLSLEmbeddedIncludeLoader.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ class IGLSLEmbeddedIncludeLoader : public IBuiltinIncludeLoader
2828
return {{std::regex{pattern},std::move(tmp)}};
2929
}
3030

31+
static core::vector<std::string> parseArgumentsFromPath(const std::string& _path)
32+
{
33+
core::vector<std::string> args;
34+
35+
std::stringstream ss{ _path };
36+
std::string arg;
37+
while (std::getline(ss, arg, '/'))
38+
args.push_back(std::move(arg));
39+
40+
return args;
41+
}
3142

3243
io::IFileSystem* fs;
3344

0 commit comments

Comments
 (0)