Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader Pipeline #358

Merged
merged 175 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
8ff2ac8
shaders: Some work on introspection and other changes
Crisspl Aug 19, 2019
c4d0774
ICPUShaders may now contain both GLSL and SPIR-V. Also most work on #…
Crisspl Aug 19, 2019
1286734
shaders: #include's working fine
Crisspl Aug 21, 2019
7914675
shaders: COpenGLSpecializedShader: both specialization and down-compi…
Crisspl Aug 21, 2019
f5f6261
shaders: spvUtils.h (forgot to push)
Crisspl Aug 21, 2019
e722561
shaders: Recursive introspection (supporting struct-type members)
Crisspl Aug 22, 2019
074d2af
shaders: Finished COpenGLSpecializedShader
Crisspl Aug 22, 2019
c176d2d
shaders: Lots of changes after The Talk (tm) yesterday
Crisspl Aug 23, 2019
3945c3d
ICPUShader doesnt need to store ep/stage
Crisspl Aug 23, 2019
fb34171
shaders: cpu->gpu functions for shaders
Crisspl Aug 23, 2019
dee6f07
Overloads takim IReadFile for IGLSLCompiler
Crisspl Aug 23, 2019
393cddd
VERY dirty almost working shaders
Crisspl Aug 24, 2019
4a33d41
Ok, this works (i.e. is able to draw something)
Crisspl Sep 3, 2019
a4502c6
Merge pull request #10 from buildaworldnet/cleanup
Crisspl Sep 3, 2019
0c720d0
Merged shaders with matt's cleanup branch
Crisspl Sep 4, 2019
9be19a9
yea its just intellisense
Crisspl Sep 4, 2019
d3614c8
Some pipeline classes
Crisspl Sep 11, 2019
edf21df
IComputePipeline
Crisspl Sep 11, 2019
94f19bb
IBufferView
Crisspl Sep 12, 2019
ed0b7e8
pipelines: Some minor changes
Crisspl Sep 13, 2019
7638227
Got rid of IVirtualTexture and replaced with IVirtualRenderableTexture
Crisspl Sep 13, 2019
1a6c401
Replacing ITextureBufferObject with IGPUBufferView pt.1 WIP
Crisspl Sep 13, 2019
cc3f623
pipelines: Some minor changes
Crisspl Sep 16, 2019
a5888ea
Meshbuffer changes regarding pipelines introduction
Crisspl Sep 16, 2019
049f076
128 bytes for push constants can reside only in IGPUMeshBuffer
Crisspl Sep 16, 2019
5f509b1
Some changes to shader introspection and IGLSLCompiler regarding push…
Crisspl Sep 16, 2019
00f3dc3
Under-the-hood interface for setting push constants in OpenGL backend
Crisspl Sep 16, 2019
0eb3330
Many small changes in pipelines
Crisspl Sep 17, 2019
fc98f52
Uploading push constants without core::vector
Crisspl Sep 17, 2019
8d6e6b6
Initial attempt to shader programs being copied between contexts
Crisspl Sep 17, 2019
5d3edf6
Reworked GL shaders copying
Crisspl Sep 18, 2019
4efb4cf
COpenGLSpecializedShader without mutex
Crisspl Sep 18, 2019
3087449
COpenGLRenderpassIndependentPipeline
Crisspl Sep 18, 2019
e5a4462
COpenGLSpecializedShader: Fixed a bug in binding reordering
Crisspl Sep 18, 2019
4827e20
pipelines: Precomputed params for multibind GL calls
Crisspl Sep 19, 2019
eefa6c6
Initial descriptors binding code
Crisspl Sep 19, 2019
b5554e9
Mitsuba file validation + memleak fix
devshgraphicsprogramming Sep 20, 2019
f739ba7
Support for binding images + ITextureView stubs
Crisspl Sep 20, 2019
be71715
Improved processing of simple elements
devshgraphicsprogramming Sep 20, 2019
289b7ce
color retrieval done
devshgraphicsprogramming Sep 20, 2019
8c2eea8
getting closer to the ideal
devshgraphicsprogramming Sep 20, 2019
b9d0e81
translate and scale done
devshgraphicsprogramming Sep 20, 2019
5bd839d
all basic elements done
devshgraphicsprogramming Sep 20, 2019
54baaab
quaternion clean up and transform implementation for PropertyElement.cpp
devshgraphicsprogramming Sep 21, 2019
ec7a482
Added case insensitive equals and hash into irr::core
devshgraphicsprogramming Sep 22, 2019
f370f0a
Document important headers, first approach
AnastaZIuk Sep 22, 2019
131bbde
Preparing to parse objects
devshgraphicsprogramming Sep 22, 2019
a055c38
block based allocator !
devshgraphicsprogramming Sep 22, 2019
9af126c
done Sampler element
devshgraphicsprogramming Sep 22, 2019
76d1710
Changed desc set setting function to per-set
Crisspl Sep 22, 2019
d6573f8
New asset types + implemented interfaces in new asset classes
Crisspl Sep 22, 2019
5e9cd58
Support for dynamic UBOs/SSBOs
Crisspl Sep 22, 2019
85e0c61
do the integrator element
devshgraphicsprogramming Sep 23, 2019
c414a29
dispatch fixed
devshgraphicsprogramming Sep 23, 2019
6aaf603
Kinda dirty state tracking but without VAO
Crisspl Sep 23, 2019
815dba4
Parse reconstruction filter and start film+sensor
devshgraphicsprogramming Sep 23, 2019
52c0f68
Initial VAO hash proposition
Crisspl Sep 23, 2019
f93eebb
Film done
devshgraphicsprogramming Sep 24, 2019
b956f90
Fix some issues
AnastaZIuk Sep 24, 2019
0786f9a
get this thing to compile
devshgraphicsprogramming Sep 24, 2019
4dbc9d0
GL state tracker almost finished
Crisspl Sep 24, 2019
739d3d3
Introduced ISampler and friends
Crisspl Sep 25, 2019
d83193f
Removed dynamic offsets from IDescriptorSet
Crisspl Sep 25, 2019
ab8da6b
Moved SSamplerParams to ISampler and finished COpenGLSampler
Crisspl Sep 25, 2019
7010361
Integrated ISampler + implemented binding samplers
Crisspl Sep 25, 2019
6b98b55
Removed not-needed-any-more things from COpenGLDriver
Crisspl Sep 25, 2019
475ce95
Document main headers, next part
AnastaZIuk Sep 25, 2019
9ccf1e7
IRenderableVirtualTexture is not a base for IGPUBufferView now
Crisspl Sep 25, 2019
e05211c
Implemented part of state tracking using new state tracking interface
Crisspl Sep 25, 2019
ec25cd2
Removed part of not needed files
Crisspl Sep 25, 2019
c140589
Removed 2nd part of not needed files
Crisspl Sep 25, 2019
cc55eda
Cleaned driver API after changes, REMOVED XFROM FEEDBACK API
Crisspl Sep 25, 2019
398fe2b
cleansing part next
Crisspl Sep 25, 2019
e5f1255
math cleanup
devshgraphicsprogramming Sep 25, 2019
d25bbcd
Some cleaning, some GL state flushing issues fixing (the who-knows-wh…
Crisspl Sep 26, 2019
e67cd79
extGlCreateSamplers
Crisspl Sep 26, 2019
89a9a07
everything compiles now.
devshgraphicsprogramming Sep 26, 2019
99e7127
now it links, compiles and runs
devshgraphicsprogramming Sep 26, 2019
944ffaf
Fix English grammar context, fix some descriptions
AnastaZIuk Sep 26, 2019
4a8e08a
Fixes in state tracker
Crisspl Sep 26, 2019
52b1346
New descriptor sets binding in state tracker
Crisspl Sep 26, 2019
89d2b69
Removed ICPUMeshDataDormatDesc
Crisspl Sep 26, 2019
0fd6e53
Adjusted COpenGLDriver::drawMeshbuffer for using new state tracker
Crisspl Sep 26, 2019
0ea1d4a
Add some doxyComments in IAssetManager and IAssetLoader
AnastaZIuk Sep 27, 2019
424b138
Docs correction and improvement
AnastaZIuk Sep 29, 2019
bdbe701
Add some words to getLoadFilename
AnastaZIuk Sep 29, 2019
ff20cfe
Add some doxycomments
AnastaZIuk Sep 30, 2019
a889461
Fix some doxyComments and add some
AnastaZIuk Oct 1, 2019
3f4b1ee
BSDF parsing prototype
devshgraphicsprogramming Oct 2, 2019
c73dace
Merge pull request #2 from buildaworldnet/mitsuba
AnastaZIuk Oct 2, 2019
274b06f
just need to support named children and it'll work
devshgraphicsprogramming Oct 2, 2019
c02fb6b
Partial new cpu->gpu pipeline impl + some tiny fixes
Crisspl Oct 3, 2019
661da77
Made GPU buffer view creation more secure
Crisspl Oct 4, 2019
0dfef9e
Implemented the rest of missing IGPUObjectFromAssetConverter::create()'s
Crisspl Oct 4, 2019
ee5bde4
Nuked all draw2D* functions
Crisspl Oct 4, 2019
5e9e10d
Few tiny fixes
Crisspl Oct 4, 2019
f3d6c67
Adjusted IGPUObjectFromAssetConverter::create() for meshbuffers
Crisspl Oct 4, 2019
3c49074
Renamed getMaxTBOSize() to getMaxTBOSizeInTexels()
Crisspl Oct 4, 2019
f544330
Adjusted [I|C]SkinningStateManager to work with IGPUBufferVIew
Crisspl Oct 4, 2019
f3079ac
Removed driver::removeTextureBufferObject()
Crisspl Oct 4, 2019
a0a1ede
Adjusted [I|C]SkinnedMeshSceneNode and completely got rid of ITexture…
Crisspl Oct 5, 2019
c93eecf
Improved createGPURenderpassIndependentPipeline() (checks for valid s…
Crisspl Oct 5, 2019
498a341
Merge pull request #3 from buildaworldnet/mitsuba
AnastaZIuk Oct 5, 2019
60d4fa8
Filling out over half of indicies of refraction
AnastaZIuk Oct 5, 2019
2b575f8
Complete IoR table
AnastaZIuk Oct 7, 2019
c448bbf
Complete diamond (cubic) index
AnastaZIuk Oct 8, 2019
24433ef
Merge pull request #375 from AnastaZIuk/IoRtable
devshgraphicsprogramming Oct 8, 2019
bfc56fe
Complete IAssetMetadata::getLoaderName() with some words
AnastaZIuk Oct 8, 2019
f10f2d9
API for binding pipeline and desc sets
Crisspl Oct 9, 2019
5af322f
BSDF parsing and named elements done!
devshgraphicsprogramming Oct 10, 2019
5f780de
Merge branch 'mitsuba' of https://github.com/buildaworldnet/IrrlichtB…
devshgraphicsprogramming Oct 10, 2019
c49584c
Some tiny changes/fixes
Crisspl Oct 10, 2019
515a095
Forgot about those lines if cpu->gpu
Crisspl Oct 10, 2019
00df6c4
Got rid of grab/drop calls
Crisspl Oct 10, 2019
36c5253
Some minor fixes
Crisspl Oct 10, 2019
531007e
Trying to get shapes and emitters off the ground
devshgraphicsprogramming Oct 10, 2019
b291ff2
COpenGLDriver: Fixed binding descriptor sets code in flushState()
Crisspl Oct 10, 2019
380f117
Dangerous typo fix
Crisspl Oct 10, 2019
52abd3f
Removed depth range from GL state tracker
Crisspl Oct 10, 2019
3cb642c
tiny fixes
Crisspl Oct 10, 2019
bd72fa8
Binding descriptor sets another fix
Crisspl Oct 11, 2019
3cba910
Removed checking push constant ranges compatibility from isCompatible…
Crisspl Oct 11, 2019
719de14
Update contributors in readme
devshgraphicsprogramming Oct 11, 2019
66dd5d9
COpenGLDriver: finished bindDescriptorSets() and bindGraphicsPipeline()
Crisspl Oct 11, 2019
042d70b
parses (but crashes at end), next step is metadata preservation + org…
devshgraphicsprogramming Oct 11, 2019
765598e
Supporting dynamic UBOs/SSBOs with dynamic offsets!
Crisspl Oct 12, 2019
f4148b8
COpenGLDriver: per-context graphics pipeline cache + actual GL pipeli…
Crisspl Oct 12, 2019
deeeb47
fixed memory corruption + added utility function
devshgraphicsprogramming Oct 14, 2019
47d21c2
fix cylinder to not have caps (now that we have disk mesh) and cylind…
devshgraphicsprogramming Oct 14, 2019
0309c68
starting to create the meshes
devshgraphicsprogramming Oct 14, 2019
32de228
remove obsolete and long dysfunctional file archive loaders
devshgraphicsprogramming Oct 14, 2019
3fcdc84
Fixed a few minor issues
Crisspl Oct 15, 2019
09fc3fa
Actually deleting pipeline GL objects
Crisspl Oct 15, 2019
d419562
fixed OBJ file recognition (@AnastaZluk see this)
devshgraphicsprogramming Oct 15, 2019
5f9dba5
fix a few things in mesh manipulator + archive stuff
devshgraphicsprogramming Oct 15, 2019
2bdd892
Allow for Right-Handed cameras
devshgraphicsprogramming Oct 15, 2019
dffc495
fix projection matrices for choice of handedness
devshgraphicsprogramming Oct 15, 2019
66b85cc
We can load geometry!
devshgraphicsprogramming Oct 15, 2019
c07d767
Color Screenie!
devshgraphicsprogramming Oct 15, 2019
4e0475a
Mitsuba Loader now operational with textures
devshgraphicsprogramming Oct 15, 2019
e9a79a2
Finally settle on how the hirarchy in loaders will work.
devshgraphicsprogramming Oct 15, 2019
2595028
MitsubaLoader screenshot and executable
devshgraphicsprogramming Oct 15, 2019
bfffb91
Merge with baw:master
Crisspl Oct 15, 2019
9231723
Merge with anastuzluk:docs
Crisspl Oct 15, 2019
c27240b
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
bf9d1a0
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
2d8f097
Missed those
Crisspl Oct 15, 2019
0b3473b
check-in before bulldozing
devshgraphicsprogramming Oct 15, 2019
27544bc
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
0bdc182
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
dae8d65
Merge pull request #372 from buildaworldnet/mitsuba
devshgraphicsprogramming Oct 15, 2019
840fb95
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
9127628
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
bda9fbe
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
870dfe1
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
49159af
COpenGLDescriptorSet: got rid of tex targets and img formats from mul…
Crisspl Oct 15, 2019
1bc811a
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 15, 2019
7cb0ef3
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 16, 2019
95d66e4
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 16, 2019
a535197
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 16, 2019
7507937
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 16, 2019
4d1ff0f
Fixed https://github.com/buildaworldnet/IrrlichtBAW/pull/358#discussi…
Crisspl Oct 16, 2019
8e43422
Made ICPUDescriptorSet a little more comfy to use
Crisspl Oct 16, 2019
f0f24c0
driver::removeGPURenderpassIndependentPipeline()
Crisspl Oct 16, 2019
147f71b
Another merge with baw:master
Crisspl Oct 16, 2019
162295b
Fixed COpenGLDriver::clearScreen()
Crisspl Oct 17, 2019
b1ae3b6
updateDescriptorSet()
Crisspl Oct 18, 2019
3ecbc04
Input attachments support query
Crisspl Oct 18, 2019
1236be9
GLSL extensions #defines insertion
Crisspl Oct 20, 2019
f4745d2
Graphics pipeline cache fixup
Crisspl Oct 20, 2019
17780f1
oops
Crisspl Oct 21, 2019
565c7e0
Add new descriptions to IAssetLoader and IAssetManager
AnastaZIuk Oct 21, 2019
787498d
Some minor changes
Crisspl Oct 21, 2019
cd2f02c
Merge branch 'docs2' of github.com:AnastaZIuk/IrrlichtBAW into shaders
Crisspl Oct 22, 2019
247d88f
Some docs corrections
Crisspl Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/IVideoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

namespace irr
{
namespace asset
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
{
class ISpecializationInfo;
}

namespace io
{
class IReadFile;
Expand All @@ -34,6 +39,8 @@ namespace video
class IImageWriter;
class IMaterialRenderer;
class IGPUProgrammingServices;
class IGPUShader;
class IGPUSpecializedShader;

//! enumeration for geometry transformation states
enum E_4X3_TRANSFORMATION_STATE
Expand Down Expand Up @@ -115,6 +122,7 @@ namespace video
virtual bool isAllowedTextureFormat(asset::E_FORMAT _fmt) const = 0;
virtual bool isHardwareBlendableFormat(asset::E_FORMAT _fmt) const = 0;

virtual IGPUSpecializedShader* createSpecializedShader(const IGPUShader* _unspecialized, const asset::ISpecializationInfo* _specInfo) = 0;
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved

//! Applications must call this method before performing any rendering.
/** This method can clear the back- and the z-buffer.
Expand Down
3 changes: 0 additions & 3 deletions include/IrrlichtDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ namespace irr
virtual asset::IAssetManager& getAssetManager();
virtual const asset::IAssetManager& getAssetManager() const;

virtual asset::IIncludeHandler* getIncludeHandler() { return nullptr; }
virtual const asset::IIncludeHandler* getIncludeHandler() const { return nullptr; }

private:
void addLoadersAndWriters();

Expand Down
103 changes: 103 additions & 0 deletions include/irr/asset/CShaderIntrospector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef __IRR_C_SHADER_INTROSPECTOR_H_INCLUDED__
#define __IRR_C_SHADER_INTROSPECTOR_H_INCLUDED__

#include <cstdint>
#include "irr/core/Types.h"
#include "irr/asset/ShaderCommons.h"
#include "irr/asset/ShaderRes.h"
#include "irr/asset/ICPUShader.h"
#include "irr/asset/IGLSLCompiler.h"

namespace spirv_cross
{
class ParsedIR;
class Compiler;
struct SPIRType;
}
namespace irr
{
namespace asset
{

struct SIntrospectionData
{
struct SSpecConstant
{
enum E_TYPE
{
ET_U64,
ET_I64,
ET_U32,
ET_I32,
ET_F64,
ET_F32
};

uint32_t id;
size_t byteSize;
E_TYPE type;
std::string name;
union {
uint64_t u64;
int64_t i64;
uint32_t u32;
int32_t i32;
double f64;
float f32;
} defaultValue;
};
//! Sorted by `id`
core::vector<SSpecConstant> specConstants;
//! Each vector is sorted by `binding`
core::vector<SShaderResourceVariant> descriptorSetBindings[4];
//! Sorted by `location`
core::vector<SShaderInfoVariant> inputOutput;

struct {
bool present;
SShaderPushConstant info;
} pushConstant;

bool canSpecializationlesslyCreateDescSetFrom() const
{
for (const auto& descSet : descriptorSetBindings)
{
auto found = std::find_if(descSet.begin(), descSet.end(), [](const SShaderResourceVariant& bnd) { return bnd.descCountIsSpecConstant; });
if (found != descSet.end())
return false;
}
return true;
}
};

class CShaderIntrospector : public core::Uncopyable
{
public:
using SEntryPointStagePair = std::pair<std::string, E_SHADER_STAGE>;

//In the future there's also going list of enabled extensions
CShaderIntrospector(const IGLSLCompiler* _glslcomp, const SEntryPointStagePair& _ep) : m_glslCompiler(_glslcomp,core::dont_grab), m_entryPoint(_ep) {}
~CShaderIntrospector() {
for (auto& introData : m_introspectionCache)
deinitIntrospectionData(introData.second);
}

const SIntrospectionData* introspect(const ICPUShader* _shader);
private:
SIntrospectionData doIntrospection(spirv_cross::Compiler& _comp, const SEntryPointStagePair& _ep) const;
void shaderMemBlockIntrospection(spirv_cross::Compiler& _comp, impl::SShaderMemoryBlock& _res, uint32_t _blockBaseTypeID, uint32_t _varID, const core::unordered_map<uint32_t, const SIntrospectionData::SSpecConstant*>& _mapId2sconst) const;
size_t calcBytesizeforType(spirv_cross::Compiler& _comp, const spirv_cross::SPIRType& _type) const;

static void deinitIntrospectionData(SIntrospectionData& _data);
static void deinitShdrMemBlock(impl::SShaderMemoryBlock& _res);

private:
core::smart_refctd_ptr<const IGLSLCompiler> m_glslCompiler;
SEntryPointStagePair m_entryPoint;
core::unordered_map<const ICPUShader*, SIntrospectionData> m_introspectionCache;
};

}//asset
}//irr

#endif
168 changes: 18 additions & 150 deletions include/irr/asset/ICPUShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,185 +2,53 @@
#define __IRR_I_CPU_SHADER_H_INCLUDED__

#include <algorithm>
#include <string>
#include "irr/asset/IAsset.h"
#include "irr/asset/ISPIR_VProgram.h"
#include "irr/asset/ShaderCommons.h"
#include "irr/asset/ShaderRes.h"
#include "irr/core/memory/new_delete.h"
#include "irr/asset/IParsedShaderSource.h"
#include "irr/asset/IGLSLCompiler.h"

namespace spirv_cross
{
class ParsedIR;
class Compiler;
struct SPIRType;
}
namespace irr
{
namespace asset
{
using SEntryPointStagePair = std::pair<std::string, E_SHADER_STAGE>;
}//asset
namespace io
{
class IReadFile;
}//io
}//irr
namespace std
{
template<>
struct hash<irr::asset::SEntryPointStagePair>
{
using T = irr::asset::SEntryPointStagePair;
// based on boost::hash_combine
size_t operator()(const T& x) const
{
size_t seed = hash<T::first_type>{}(x.first);
return seed ^= hash<underlying_type_t<T::second_type>>{}(x.second) + 0x9e3779b9ull + (seed << 6) + (seed >> 2);
}
};
}//std

namespace irr { namespace asset
{

struct SIntrospectionData
{
struct SSpecConstant
{
enum E_TYPE
{
ET_U64,
ET_I64,
ET_U32,
ET_I32,
ET_F64,
ET_F32
};

uint32_t id;
size_t byteSize;
E_TYPE type;
std::string name;
union {
uint64_t u64;
int64_t i64;
uint32_t u32;
int32_t i32;
double f64;
float f32;
} defaultValue;
};
//! Sorted by `id`
core::vector<SSpecConstant> specConstants;
//! Each vector is sorted by `binding`
core::vector<SShaderResourceVariant> descriptorSetBindings[4];
//! Sorted by `location`
core::vector<SShaderInfoVariant> inputOutput;

struct {
bool present;
SShaderPushConstant info;
} pushConstant;

bool canSpecializationlesslyCreateDescSetFrom() const
{
for (const auto& descSet : descriptorSetBindings)
{
auto found = std::find_if(descSet.begin(), descSet.end(), [](const SShaderResourceVariant& bnd) { return bnd.descCountIsSpecConstant; });
if (found != descSet.end())
return false;
}
return true;
}
};

class ICPUShader : public IAsset
{
protected:
virtual ~ICPUShader()
{
if (m_spirvBytecode)
m_spirvBytecode->drop();
if (m_parsed)
m_parsed->drop();
for (auto& introData : m_introspectionCache)
SIntrospectionPerformer::deinitIntrospectionData(introData.second);
if (m_glslCompiler)
m_glslCompiler->drop();
if (m_code)
m_code->drop();
}

public:
ICPUShader(ICPUBuffer* _spirv) : m_glslCompiler(nullptr), m_spirvBytecode(_spirv), m_parsed(new IParsedShaderSource(m_spirvBytecode, core::defer))
{
}
//! While creating from GLSL source, entry point name and stage must be given in advance
/**
Note: file's name (_glsl param) will be used for resolving relative #include directives! See IGLSLCompiler::resolveIncludeDirectives() for more info.
*/
ICPUShader(IGLSLCompiler* _glslcompiler, core::smart_refctd_ptr<io::IReadFile> _glsl, const std::string& _entryPoint, E_SHADER_STAGE _stage);
//! While creating from GLSL source, entry point name and stage must be given in advance
/**
@param _sourceName will be used for resolving relative #include directives! See IGLSLCompiler::resolveIncludeDirectives() for more info.
*/
ICPUShader(IGLSLCompiler* _glslcompiler, const char* _glsl, const char* _sourceName, const std::string& _entryPoint, E_SHADER_STAGE _stage);
ICPUShader(ICPUBuffer* _spirv);
ICPUShader(const char* _glsl, const std::string& _entryPoint, E_SHADER_STAGE _stage);
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved

IAsset::E_TYPE getAssetType() const override { return IAsset::ET_SHADER; }
size_t conservativeSizeEstimate() const override
{
if (m_glsl.size())
return m_glsl.size();
else if (m_spirvBytecode)
return m_spirvBytecode->conservativeSizeEstimate();
return 0u; //shouldnt ever reach this line
}
void convertToDummyObject() override { m_glsl.clear(); }

const ICPUBuffer* getSPIR_VBytecode() const { return m_spirvBytecode; };

void enableIntrospection();
const SIntrospectionData* getIntrospectionData(const SEntryPointStagePair& _entryPoint) const
{
auto found = m_introspectionCache.find(_entryPoint);
return found == m_introspectionCache.end() ? nullptr : &found->second;
}

const core::vector<SEntryPointStagePair>& getStageEntryPoints();

inline const IParsedShaderSource* getParsed() const
{
obtainSPIRV();
return m_parsed;
return m_code->getSize();
}
void convertToDummyObject() override { }

protected:
const core::vector<SEntryPointStagePair>& getStageEntryPoints(spirv_cross::Compiler& _comp);
void obtainSPIRV() const;
const ICPUBuffer* getSPVorGLSL() const { return m_code; };
bool containsGLSL() const { return m_containsGLSL; }

protected:
IGLSLCompiler* m_glslCompiler;
//`mutable` implies that POINTER might be altered (specifically it can be null or not-null when object gets created)
//`const` (on the left side of `*`) implies that the OBJECT once created, is not modified
mutable const ICPUBuffer* m_spirvBytecode = nullptr;
mutable const IParsedShaderSource* m_parsed = nullptr;
std::string m_glsl;
std::string m_glslOriginFilename;

using CacheKey = SEntryPointStagePair;
core::unordered_map<CacheKey, SIntrospectionData> m_introspectionCache;
core::vector<SEntryPointStagePair> m_entryPoints;
//! Only relevant when containsGLSL returns true
const std::string& getGLSLEntryPoint() const { return m_glslEntryPoint; }
//! Only relevant when containsGLSL returns true
E_SHADER_STAGE getGLSLStage() const { return m_glslStage; }

protected:
struct SIntrospectionPerformer
{
SIntrospectionData doIntrospection(spirv_cross::Compiler& _comp, const SEntryPointStagePair& _ep) const;
void shaderMemBlockIntrospection(spirv_cross::Compiler& _comp, impl::SShaderMemoryBlock& _res, uint32_t _blockBaseTypeID, uint32_t _varID, const core::unordered_map<uint32_t, const SIntrospectionData::SSpecConstant*>& _mapId2sconst) const;
size_t calcBytesizeforType(spirv_cross::Compiler& _comp, const spirv_cross::SPIRType& _type) const;

static void deinitIntrospectionData(SIntrospectionData& _data);
static void deinitShdrMemBlock(impl::SShaderMemoryBlock& _res);
};
//! Might be GLSL null-terminated string or SPIR-V bytecode (denoted by m_containsGLSL)
ICPUBuffer* m_code;
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
const bool m_containsGLSL;
std::string m_glslEntryPoint;
E_SHADER_STAGE m_glslStage = ESS_UNKNOWN;
};

}}
Expand Down
6 changes: 0 additions & 6 deletions include/irr/asset/ICPUSpecializedShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class ICPUSpecializedShader : public IAsset
inline const ISpecializationInfo* getSpecializationInfo() const { return m_specInfo; }
inline const ICPUShader* getUnspecialized() const { return m_unspecialized; }

//! If contained unspecialized ICPUShader hasn't enabled introspection, this function will also return nullptr
inline const SIntrospectionData* getIntrospectionData() const
{
return m_unspecialized->getIntrospectionData({m_specInfo->entryPoint,m_specInfo->shaderStage});
}

private:
const ICPUShader* m_unspecialized;
const ISpecializationInfo* m_specInfo;
Expand Down
Loading