Skip to content

Commit fa7ee6e

Browse files
committed
Merge branch 'hlsl' of https://github.com/kpentaris/Nabla into hlsl
2 parents 34ebc4c + 5317ee4 commit fa7ee6e

File tree

136 files changed

+6209
-6961
lines changed

Some content is hidden

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

136 files changed

+6209
-6961
lines changed

include/nbl/asset/ECommonEnums.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __NBL_E_COMMON_ENUMS_H_INCLUDED__
2-
#define __NBL_E_COMMON_ENUMS_H_INCLUDED__
1+
#ifndef __NBL_ASSET_E_COMMON_ENUMS_H_INCLUDED__
2+
#define __NBL_ASSET_E_COMMON_ENUMS_H_INCLUDED__
33

44
#include "nbl/core/declarations.h"
55

@@ -66,6 +66,7 @@ enum E_PIPELINE_STAGE_FLAGS : uint32_t
6666

6767
enum E_ACCESS_FLAGS : uint32_t
6868
{
69+
EAF_NONE = 0,
6970
EAF_INDIRECT_COMMAND_READ_BIT = 0x00000001,
7071
EAF_INDEX_READ_BIT = 0x00000002,
7172
EAF_VERTEX_ATTRIBUTE_READ_BIT = 0x00000004,

include/nbl/asset/IAssetManager.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "nbl/asset/interchange/IAssetLoader.h"
1818
#include "nbl/asset/interchange/IAssetWriter.h"
1919

20-
#include "nbl/asset/utils/IGLSLCompiler.h"
20+
#include "nbl/asset/utils/CCompilerSet.h"
2121
#include "nbl/asset/utils/IGeometryCreator.h"
2222

2323

@@ -119,14 +119,15 @@ class NBL_API IAssetManager : public core::IReferenceCounted, public core::QuitS
119119

120120
core::smart_refctd_ptr<IGeometryCreator> m_geometryCreator;
121121
core::smart_refctd_ptr<IMeshManipulator> m_meshManipulator;
122-
core::smart_refctd_ptr<IGLSLCompiler> m_glslCompiler;
122+
core::smart_refctd_ptr<CCompilerSet> m_compilerSet;
123123
// called as a part of constructor only
124124
void initializeMeshTools();
125125

126126
public:
127127
//! Constructor
128-
explicit IAssetManager(core::smart_refctd_ptr<system::ISystem>&& _s) :
129-
m_system(std::move(_s)),
128+
explicit IAssetManager(core::smart_refctd_ptr<system::ISystem>&& system, core::smart_refctd_ptr<CCompilerSet>&& compilerSet = nullptr) :
129+
m_system(std::move(system)),
130+
m_compilerSet(std::move(compilerSet)),
130131
m_defaultLoaderOverride(this)
131132
{
132133
initializeMeshTools();
@@ -144,7 +145,7 @@ class NBL_API IAssetManager : public core::IReferenceCounted, public core::QuitS
144145

145146
const IGeometryCreator* getGeometryCreator() const;
146147
IMeshManipulator* getMeshManipulator();
147-
IGLSLCompiler* getGLSLCompiler() const { return m_glslCompiler.get(); }
148+
CCompilerSet* getCompilerSet() const { return m_compilerSet.get(); }
148149

149150
protected:
150151
virtual ~IAssetManager()

include/nbl/asset/ICPUBuffer.h

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace nbl::asset
1919

2020
//! One of CPU class-object representing an Asset
2121
/**
22-
One of Assets used for storage of large arrays, so that storage can be decoupled
23-
from other objects such as meshbuffers, images, animations and shader source/bytecode.
22+
One of Assets used for storage of large arrays, so that storage can be decoupled
23+
from other objects such as meshbuffers, images, animations and shader source/bytecode.
2424
25-
@see IAsset
25+
@see IAsset
2626
*/
2727
class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
2828
{
@@ -35,12 +35,12 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
3535
//! Non-allocating constructor for CCustormAllocatorCPUBuffer derivative
3636
ICPUBuffer(size_t sizeInBytes, void* dat) : asset::IBuffer({dat ? sizeInBytes:0,EUF_TRANSFER_DST_BIT}), data(dat) {}
3737
public:
38-
//! Constructor. TODO: remove, alloc can fail, should be a static create method instead!
39-
/** @param sizeInBytes Size in bytes. If `dat` argument is present, it denotes size of data pointed by `dat`, otherwise - size of data to be allocated.
40-
*/
38+
//! Constructor. TODO: remove, alloc can fail, should be a static create method instead!
39+
/** @param sizeInBytes Size in bytes. If `dat` argument is present, it denotes size of data pointed by `dat`, otherwise - size of data to be allocated.
40+
*/
4141
ICPUBuffer(size_t sizeInBytes) : asset::IBuffer({0,EUF_TRANSFER_DST_BIT})
4242
{
43-
data = _NBL_ALIGNED_MALLOC(sizeInBytes,_NBL_SIMD_ALIGNMENT);
43+
data = _NBL_ALIGNED_MALLOC(sizeInBytes,_NBL_SIMD_ALIGNMENT);
4444
if (!data)
4545
return;
4646

@@ -74,7 +74,7 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
7474

7575
virtual size_t conservativeSizeEstimate() const override { return getSize(); }
7676

77-
//! Returns pointer to data.
77+
//! Returns pointer to data.
7878
virtual const void* getPointer() const {return data;}
7979
virtual void* getPointer()
8080
{
@@ -90,22 +90,22 @@ class NBL_API ICPUBuffer : public asset::IBuffer, public asset::IAsset
9090
return true;
9191
}
9292

93-
inline core::bitflag<E_USAGE_FLAGS> getUsageFlags() const
94-
{
95-
return m_creationParams.usage;
96-
}
97-
inline bool setUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
98-
{
99-
assert(!isImmutable_debug());
93+
inline core::bitflag<E_USAGE_FLAGS> getUsageFlags() const
94+
{
95+
return m_creationParams.usage;
96+
}
97+
inline bool setUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
98+
{
99+
assert(!isImmutable_debug());
100100
m_creationParams.usage = _usage;
101-
return true;
102-
}
103-
inline bool addUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
104-
{
105-
assert(!isImmutable_debug());
101+
return true;
102+
}
103+
inline bool addUsageFlags(core::bitflag<E_USAGE_FLAGS> _usage)
104+
{
105+
assert(!isImmutable_debug());
106106
m_creationParams.usage |= _usage;
107-
return true;
108-
}
107+
return true;
108+
}
109109

110110
protected:
111111
void restoreFromDummy_impl(IAsset* _other, uint32_t _levelsBelow) override
@@ -125,6 +125,8 @@ template<
125125
>
126126
class NBL_API CCustomAllocatorCPUBuffer;
127127

128+
using CDummyCPUBuffer = CCustomAllocatorCPUBuffer<core::null_allocator<uint8_t>, true>;
129+
128130
//! Specialization of ICPUBuffer capable of taking custom allocators
129131
/*
130132
Take a look that with this usage you have to specify custom alloctor
@@ -140,51 +142,51 @@ class NBL_API CCustomAllocatorCPUBuffer;
140142
template<typename Allocator>
141143
class NBL_API CCustomAllocatorCPUBuffer<Allocator, true> : public ICPUBuffer
142144
{
143-
static_assert(sizeof(typename Allocator::value_type) == 1u, "Allocator::value_type must be of size 1");
144-
protected:
145-
Allocator m_allocator;
145+
static_assert(sizeof(typename Allocator::value_type) == 1u, "Allocator::value_type must be of size 1");
146+
protected:
147+
Allocator m_allocator;
146148

147149
virtual ~CCustomAllocatorCPUBuffer()
148150
{
149151
this->convertToDummyObject();
150152
}
151153

152-
public:
153-
CCustomAllocatorCPUBuffer(size_t sizeInBytes, void* dat, core::adopt_memory_t, Allocator&& alctr = Allocator()) : ICPUBuffer(sizeInBytes, dat), m_allocator(std::move(alctr))
154-
{
155-
}
154+
public:
155+
CCustomAllocatorCPUBuffer(size_t sizeInBytes, void* dat, core::adopt_memory_t, Allocator&& alctr = Allocator()) : ICPUBuffer(sizeInBytes, dat), m_allocator(std::move(alctr))
156+
{
157+
}
156158

157-
virtual void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override
158-
{
159+
virtual void convertToDummyObject(uint32_t referenceLevelsBelowToConvert = 0u) override
160+
{
159161
if (isDummyObjectForCacheAliasing)
160162
return;
161163
convertToDummyObject_common(referenceLevelsBelowToConvert);
162164
if (!canBeConvertedToDummy())
163165
return;
164166

165-
if (ICPUBuffer::data)
166-
m_allocator.deallocate(reinterpret_cast<typename Allocator::pointer>(ICPUBuffer::data), ICPUBuffer::size);
167-
ICPUBuffer::data = nullptr; // so that ICPUBuffer won't try deallocating
168-
}
167+
if (ICPUBuffer::data)
168+
m_allocator.deallocate(reinterpret_cast<typename Allocator::pointer>(ICPUBuffer::data), ICPUBuffer::m_creationParams.size);
169+
ICPUBuffer::data = nullptr; // so that ICPUBuffer won't try deallocating
170+
}
169171
};
170172

171173
template<typename Allocator>
172174
class NBL_API CCustomAllocatorCPUBuffer<Allocator, false> : public CCustomAllocatorCPUBuffer<Allocator, true>
173175
{
174-
using Base = CCustomAllocatorCPUBuffer<Allocator, true>;
175-
protected:
176-
virtual ~CCustomAllocatorCPUBuffer() = default;
176+
using Base = CCustomAllocatorCPUBuffer<Allocator, true>;
177+
protected:
178+
virtual ~CCustomAllocatorCPUBuffer() = default;
177179

178-
public:
179-
using Base::Base;
180+
public:
181+
using Base::Base;
180182

181183
// TODO: remove, alloc can fail, should be a static create method instead!
182-
CCustomAllocatorCPUBuffer(size_t sizeInBytes, const void* dat, Allocator&& alctr = Allocator()) : Base(sizeInBytes, alctr.allocate(sizeInBytes), core::adopt_memory, std::move(alctr))
183-
{
184-
memcpy(Base::data,dat,sizeInBytes);
185-
}
184+
CCustomAllocatorCPUBuffer(size_t sizeInBytes, const void* dat, Allocator&& alctr = Allocator()) : Base(sizeInBytes, alctr.allocate(sizeInBytes), core::adopt_memory, std::move(alctr))
185+
{
186+
memcpy(Base::data,dat,sizeInBytes);
187+
}
186188
};
187189

188190
} // end namespace nbl::asset
189191

190-
#endif
192+
#endif

include/nbl/asset/ICPUImage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ class NBL_API ICPUImage final : public IImage, public IAsset
176176
assert(!isImmutable_debug());
177177

178178
if (!IImage::validateCopies(_regions->begin(),_regions->end(),_buffer.get()))
179+
{
180+
assert(false);
179181
return false;
182+
}
180183

181184
buffer = std::move(_buffer);
182185
regions = _regions;

include/nbl/asset/ICPUShader.h

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,22 @@ class NBL_API ICPUShader : public IAsset, public IShader
2929
protected:
3030
virtual ~ICPUShader() = default;
3131

32-
private:
33-
ICPUShader(core::smart_refctd_ptr<ICPUBuffer>&& _code, bool _isGLSL, const E_SHADER_STAGE stage, std::string&& filepathHint)
34-
: IShader(stage, std::move(filepathHint)), m_code(std::move(_code)), m_containsGLSL(_isGLSL)
35-
{}
36-
3732
public:
38-
ICPUShader(
39-
core::smart_refctd_ptr<ICPUBuffer>&& _spirv,
40-
const E_SHADER_STAGE stage,
41-
std::string&& filepathHint)
42-
: ICPUShader(std::move(_spirv), false, stage, std::move(filepathHint))
43-
{}
4433

45-
ICPUShader(
46-
core::smart_refctd_ptr<ICPUBuffer>&& _glsl,
47-
buffer_contains_glsl_t _buffer_contains_glsl,
48-
const E_SHADER_STAGE stage,
49-
std::string&& filepathHint)
50-
: ICPUShader(std::move(_glsl), true, stage, std::move(filepathHint))
34+
ICPUShader(core::smart_refctd_ptr<ICPUBuffer>&& code, const E_SHADER_STAGE stage, E_CONTENT_TYPE contentType, std::string&& filepathHint)
35+
: IShader(stage, std::move(filepathHint)), m_code(std::move(code))
36+
, m_contentType(contentType)
5137
{}
5238

5339
ICPUShader(
54-
const char* _glsl,
40+
const char* code,
5541
const E_SHADER_STAGE stage,
56-
std::string&& filepathHint)
57-
: ICPUShader(core::make_smart_refctd_ptr<ICPUBuffer>(strlen(_glsl) + 1u), true,
58-
stage, std::move(filepathHint))
42+
E_CONTENT_TYPE contentType,
43+
std::string&& filepathHint)
44+
: ICPUShader(core::make_smart_refctd_ptr<ICPUBuffer>(strlen(code) + 1u), stage, contentType, std::move(filepathHint))
5945
{
60-
memcpy(m_code->getPointer(), _glsl, m_code->getSize());
46+
assert(contentType != E_CONTENT_TYPE::ECT_SPIRV); // because using strlen needs `code` to be null-terminated
47+
memcpy(m_code->getPointer(), code, m_code->getSize());
6148
}
6249

6350
_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_SHADER;
@@ -70,26 +57,32 @@ class NBL_API ICPUShader : public IAsset, public IShader
7057
return estimate;
7158
}
7259

73-
core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override
74-
{
75-
auto buf = (_depth > 0u && m_code) ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_code->clone(_depth-1u)) : m_code;
76-
auto cp = core::smart_refctd_ptr<ICPUShader>(new ICPUShader(std::move(buf), m_containsGLSL, getStage(), std::string(getFilepathHint())), core::dont_grab);
77-
clone_common(cp.get());
60+
core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override
61+
{
62+
auto buf = (_depth > 0u && m_code) ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_code->clone(_depth-1u)) : m_code;
63+
auto cp = core::smart_refctd_ptr<ICPUShader>(new ICPUShader(std::move(buf), getStage(), m_contentType, std::string(getFilepathHint())), core::dont_grab);
64+
clone_common(cp.get());
7865

79-
return cp;
80-
}
66+
return cp;
67+
}
8168

8269
void convertToDummyObject(uint32_t referenceLevelsBelowToConvert=0u) override
8370
{
84-
convertToDummyObject_common(referenceLevelsBelowToConvert);
71+
convertToDummyObject_common(referenceLevelsBelowToConvert);
8572

8673
if (referenceLevelsBelowToConvert)
8774
m_code->convertToDummyObject(referenceLevelsBelowToConvert-1u);
8875
}
8976

90-
const ICPUBuffer* getSPVorGLSL() const { return m_code.get(); };
91-
bool containsGLSL() const { return m_containsGLSL; }
77+
const ICPUBuffer* getContent() const { return m_code.get(); };
78+
79+
inline E_CONTENT_TYPE getContentType() const { return m_contentType; }
9280

81+
inline bool isContentHighLevelLanguage() const
82+
{
83+
return (m_contentType == E_CONTENT_TYPE::ECT_GLSL || m_contentType == E_CONTENT_TYPE::ECT_HLSL);
84+
}
85+
9386
bool setShaderStage(const E_SHADER_STAGE stage)
9487
{
9588
if(isImmutable_debug())
@@ -109,7 +102,7 @@ class NBL_API ICPUShader : public IAsset, public IShader
109102
bool canBeRestoredFrom(const IAsset* _other) const override
110103
{
111104
auto* other = static_cast<const ICPUShader*>(_other);
112-
if (m_containsGLSL != other->m_containsGLSL)
105+
if (m_contentType != other->m_contentType)
113106
return false;
114107
if (getFilepathHint() != other->getFilepathHint())
115108
return false;
@@ -140,9 +133,8 @@ class NBL_API ICPUShader : public IAsset, public IShader
140133
return m_code->isAnyDependencyDummy(_levelsBelow);
141134
}
142135

143-
//! Might be GLSL null-terminated string or SPIR-V bytecode (denoted by m_containsGLSL)
144-
core::smart_refctd_ptr<ICPUBuffer> m_code;
145-
const bool m_containsGLSL;
136+
core::smart_refctd_ptr<ICPUBuffer> m_code;
137+
E_CONTENT_TYPE m_contentType;
146138
};
147139

148140
}

include/nbl/asset/ICommandBuffer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct NBL_API SImageResolve
4646

4747
struct NBL_API SMemoryBarrier
4848
{
49-
core::bitflag<asset::E_ACCESS_FLAGS> srcAccessMask = static_cast<asset::E_ACCESS_FLAGS>(0u);
50-
core::bitflag<asset::E_ACCESS_FLAGS> dstAccessMask = static_cast<asset::E_ACCESS_FLAGS>(0u);
49+
core::bitflag<asset::E_ACCESS_FLAGS> srcAccessMask = asset::EAF_NONE;
50+
core::bitflag<asset::E_ACCESS_FLAGS> dstAccessMask = asset::EAF_NONE;
5151
};
5252

5353
union SClearColorValue
@@ -352,9 +352,6 @@ class NBL_API ICommandBuffer
352352
return true;
353353
}
354354

355-
virtual bool regenerateMipmaps(image_t* imgview, uint32_t lastReadyMip, asset::IImage::E_ASPECT_FLAGS aspect) = 0;
356-
357-
358355

359356
protected:
360357
ICommandBuffer(E_LEVEL lvl) : m_level(lvl) {}

0 commit comments

Comments
 (0)