Changed shader module library to Import shaders and reflect all on its own
Preparation for separation for built in shaders distinction
This commit is contained in:
parent
b4726ae992
commit
84ce369607
|
@ -78,13 +78,6 @@ constexpr std::string_view MATERIAL_EXTENSION {".shmat"};
|
|||
constexpr std::string_view TEXTURE_EXTENSION {".shtex"};
|
||||
constexpr std::string_view MESH_EXTENSION {".shmesh"};
|
||||
|
||||
// EXTERNAL EXTENSIONS
|
||||
constexpr std::string_view GLSL_EXTENSION{ ".glsl" };
|
||||
constexpr std::string_view IMAGE_EXTENSION{ ".png" };
|
||||
constexpr std::string_view DDS_EXTENSION{ ".dds" };
|
||||
constexpr std::string_view FBX_EXTENSION{ ".fbx" };
|
||||
constexpr std::string_view GLTF_EXTENSION{ ".gltf" };
|
||||
|
||||
constexpr std::string_view EXTENSIONS[] = {
|
||||
AUDIO_EXTENSION,
|
||||
SHADER_EXTENSION,
|
||||
|
@ -97,6 +90,13 @@ constexpr std::string_view EXTENSIONS[] = {
|
|||
AUDIO_WAV_EXTENSION,
|
||||
};
|
||||
|
||||
// EXTERNAL EXTENSIONS
|
||||
constexpr std::string_view GLSL_EXTENSION{ ".glsl" };
|
||||
constexpr std::string_view IMAGE_EXTENSION{ ".png" };
|
||||
constexpr std::string_view DDS_EXTENSION{ ".dds" };
|
||||
constexpr std::string_view FBX_EXTENSION{ ".fbx" };
|
||||
constexpr std::string_view GLTF_EXTENSION{ ".gltf" };
|
||||
|
||||
constexpr std::string_view EXTERNALS[] = {
|
||||
GLSL_EXTENSION,
|
||||
IMAGE_EXTENSION,
|
||||
|
|
|
@ -116,22 +116,8 @@ namespace SHADE
|
|||
transferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||
graphicsTexCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||
|
||||
|
||||
// TODO: This is VERY temporarily here until a more solid resource management system is implemented
|
||||
shaderSourceLibrary.Init("../../TempShaderFolder/");
|
||||
|
||||
shaderSourceLibrary.LoadShader(0, "TestCubeVs.glsl", SH_SHADER_TYPE::VERTEX, true);
|
||||
shaderSourceLibrary.LoadShader(1, "TestCubeFs.glsl", SH_SHADER_TYPE::FRAGMENT, true);
|
||||
|
||||
shaderSourceLibrary.LoadShader(2, "KirschCs.glsl", SH_SHADER_TYPE::COMPUTE, true);
|
||||
|
||||
shaderModuleLibrary.ImportFromSourceLibrary(device, shaderSourceLibrary);
|
||||
auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl");
|
||||
auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl");
|
||||
auto greyscale = shaderModuleLibrary.GetShaderModule("KirschCs.glsl");
|
||||
cubeVS->Reflect();
|
||||
cubeFS->Reflect();
|
||||
greyscale->Reflect();
|
||||
shaderModuleLibrary.ImportAllShaderSource(device);
|
||||
shaderModuleLibrary.ReflectAllShaderModules();
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "SHShaderModuleLibrary.h"
|
||||
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||
#include "Assets/Asset Types/SHShaderAsset.h"
|
||||
#include "Assets/SHAssetManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -19,33 +20,33 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/***************************************************************************/
|
||||
void SHShaderModuleLibrary::ImportFromSourceLibrary(Handle<SHVkLogicalDevice>& logicalDeviceHdl, SHShaderSourceLibrary const& sourceLib) noexcept
|
||||
{
|
||||
auto const& sources = sourceLib.GetSourceLibrary();
|
||||
for (auto const& source : sources)
|
||||
{
|
||||
vk::ShaderStageFlagBits shaderType{};
|
||||
switch (source.shaderType)
|
||||
{
|
||||
case SH_SHADER_TYPE::VERTEX:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
case SH_SHADER_TYPE::FRAGMENT:
|
||||
shaderType = vk::ShaderStageFlagBits::eFragment;
|
||||
break;
|
||||
case SH_SHADER_TYPE::COMPUTE:
|
||||
shaderType = vk::ShaderStageFlagBits::eCompute;
|
||||
break;
|
||||
default:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
}
|
||||
//void SHShaderModuleLibrary::ImportFromSourceLibrary(Handle<SHVkLogicalDevice>& logicalDeviceHdl, SHShaderSourceLibrary const& sourceLib) noexcept
|
||||
//{
|
||||
// auto const& sources = sourceLib.GetSourceLibrary();
|
||||
// for (auto const& source : sources)
|
||||
// {
|
||||
// vk::ShaderStageFlagBits shaderType{};
|
||||
// switch (source.shaderType)
|
||||
// {
|
||||
// case SH_SHADER_TYPE::VERTEX:
|
||||
// shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
// break;
|
||||
// case SH_SHADER_TYPE::FRAGMENT:
|
||||
// shaderType = vk::ShaderStageFlagBits::eFragment;
|
||||
// break;
|
||||
// case SH_SHADER_TYPE::COMPUTE:
|
||||
// shaderType = vk::ShaderStageFlagBits::eCompute;
|
||||
// break;
|
||||
// default:
|
||||
// shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
// break;
|
||||
// }
|
||||
|
||||
Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(source.spirvBinary, "main", shaderType, source.name);
|
||||
shaderModules.emplace(source.id, newShaderModule);
|
||||
stringToID.emplace(source.name, source.id);
|
||||
}
|
||||
}
|
||||
// Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(source.spirvBinary, "main", shaderType, source.name);
|
||||
// shaderModules.emplace(source.id, newShaderModule);
|
||||
// stringToID.emplace(source.name, source.id);
|
||||
// }
|
||||
//}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
@ -59,12 +60,60 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/***************************************************************************/
|
||||
Handle<SHVkShaderModule> SHShaderModuleLibrary::GetShaderModule(std::string shaderName) const noexcept
|
||||
//Handle<SHVkShaderModule> SHShaderModuleLibrary::GetShaderModule(std::string shaderName) const noexcept
|
||||
//{
|
||||
// if (stringToID.contains(shaderName))
|
||||
// return shaderModules.at(stringToID.at(shaderName));
|
||||
// else
|
||||
// return {};
|
||||
//}
|
||||
|
||||
void SHShaderModuleLibrary::ImportBuiltInShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept
|
||||
{
|
||||
if (stringToID.contains(shaderName))
|
||||
return shaderModules.at(stringToID.at(shaderName));
|
||||
else
|
||||
return {};
|
||||
uint32_t idCounter{ 0 };
|
||||
const AssetID DEFAULT_VS_ID{ 69 };
|
||||
const AssetID DEFAULT_FS_ID{ 420 };
|
||||
|
||||
auto vsData{ SHAssetManager::GetData<SHShaderAsset>(DEFAULT_VS_ID) };
|
||||
Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(vsData->spirvBinary, "main", shaderType, vsData->name);
|
||||
shaderModules.emplace(idCounter++, newShaderModule);
|
||||
}
|
||||
|
||||
}
|
||||
void SHShaderModuleLibrary::ImportAllShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept
|
||||
{
|
||||
uint32_t idCounter{ 0 };
|
||||
|
||||
auto data = SHAssetManager::GetAllDataOfType(AssetType::SHADER);
|
||||
for (auto const& dataPtr : data)
|
||||
{
|
||||
auto shader = dynamic_cast<SHShaderAsset const*>(dataPtr);
|
||||
vk::ShaderStageFlagBits shaderType{};
|
||||
switch (shader->shaderType)
|
||||
{
|
||||
case SH_SHADER_TYPE::VERTEX:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
case SH_SHADER_TYPE::FRAGMENT:
|
||||
shaderType = vk::ShaderStageFlagBits::eFragment;
|
||||
break;
|
||||
case SH_SHADER_TYPE::COMPUTE:
|
||||
shaderType = vk::ShaderStageFlagBits::eCompute;
|
||||
break;
|
||||
default:
|
||||
shaderType = vk::ShaderStageFlagBits::eVertex;
|
||||
break;
|
||||
}
|
||||
|
||||
Handle<SHVkShaderModule> newShaderModule = logicalDeviceHdl->CreateShaderModule(shader->spirvBinary, "main", shaderType, shader->name);
|
||||
shaderModules.emplace(idCounter++, newShaderModule);
|
||||
}
|
||||
}
|
||||
|
||||
void SHShaderModuleLibrary::ReflectAllShaderModules() noexcept
|
||||
{
|
||||
for (auto& module : shaderModules)
|
||||
{
|
||||
module.second->Reflect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,20 +21,22 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
//! Stored shader modules
|
||||
std::unordered_map<uint32_t, Handle<SHVkShaderModule>> shaderModules;
|
||||
|
||||
//! We want some sort of interface with strings, instead of ints
|
||||
std::map<std::string, uint32_t> stringToID;
|
||||
std::unordered_map<std::string, Handle<SHVkShaderModule>> builtInShaderModules;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PUBLIC MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void ImportFromSourceLibrary(Handle<SHVkLogicalDevice>& logicalDeviceHdl, SHShaderSourceLibrary const& sourceLib) noexcept;
|
||||
//void ImportFromSourceLibrary(Handle<SHVkLogicalDevice>& logicalDeviceHdl, SHShaderSourceLibrary const& sourceLib) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
Handle<SHVkShaderModule> GetShaderModule(std::string shaderName) const noexcept;
|
||||
//Handle<SHVkShaderModule> GetShaderModule(std::string shaderName) const noexcept;
|
||||
|
||||
void ImportBuiltInShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept;
|
||||
void ImportAllShaderSource(Handle<SHVkLogicalDevice>& logicalDeviceHdl) noexcept;
|
||||
void ReflectAllShaderModules() noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue