Implemented scanline and silhouette effect #363
|
@ -7,14 +7,14 @@ namespace SHADE
|
|||
{
|
||||
struct SHCompileAssetEvent
|
||||
{
|
||||
//! Name of the shader. Should just contain stem from file path.
|
||||
std::string shaderName;
|
||||
//! Name of the asset (where applicable)
|
||||
std::string assetName;
|
||||
|
||||
//! NEw binary data for shader module to use
|
||||
std::vector<uint32_t> newBinaryData;
|
||||
//! asset ID of the asset
|
||||
AssetID assetID;
|
||||
|
||||
//! Extension to check for type
|
||||
std::string ext;
|
||||
//! type of the asset
|
||||
AssetType assetType;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHShaderSourceCompiler.h"
|
||||
#include "shaderc/shaderc.hpp"
|
||||
#include "Assets/Events/SHAssetManagerEvents.h"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
@ -142,14 +141,6 @@ namespace SHADE
|
|||
return{};
|
||||
}
|
||||
|
||||
SHCompileAssetEvent compileShaderEvent
|
||||
{
|
||||
.shaderName = std::filesystem::path (data->name).stem().string(),
|
||||
.newBinaryData = data->spirvBinary,
|
||||
.ext = GLSL_EXTENSION.data(),
|
||||
};
|
||||
SHEventManager::BroadcastEvent<SHCompileAssetEvent>(compileShaderEvent, SH_ASSET_COMPILE_EVENT);
|
||||
|
||||
return CompileShaderSourceToBinary(path, *data);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "Filesystem/SHFileSystem.h"
|
||||
#include <rttr/registration.h>
|
||||
#include "Assets/Events/SHAssetManagerEvents.h"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -458,6 +460,14 @@ namespace SHADE
|
|||
else
|
||||
{
|
||||
target = GetAssetIDFromPath(path);
|
||||
// send compile asset event
|
||||
SHCompileAssetEvent compileShaderEvent
|
||||
{
|
||||
.assetName = newPath.filename().stem().string(),
|
||||
.assetID = id,
|
||||
.assetType = AssetType::SHADER,
|
||||
};
|
||||
SHEventManager::BroadcastEvent<SHCompileAssetEvent>(compileShaderEvent, SH_ASSET_COMPILE_EVENT);
|
||||
}
|
||||
|
||||
//TODO SEND EVENT HERE
|
||||
|
|
|
@ -893,15 +893,21 @@ namespace SHADE
|
|||
{
|
||||
auto const& EVENT_DATA = reinterpret_cast<const SHEventSpec<SHCompileAssetEvent>*>(eventPtr.get())->data;
|
||||
|
||||
// check for asset type
|
||||
if (EVENT_DATA->assetType == AssetType::SHADER)
|
||||
{
|
||||
// loop through all shaders
|
||||
auto denseIterators = SHVkInstance::GetResourceManager().GetDenseAccess<SHVkShaderModule>();
|
||||
for (auto it = denseIterators.first; it != denseIterators.second; ++it)
|
||||
{
|
||||
if (it->GetName() == EVENT_DATA->shaderName)
|
||||
if (it->GetName() == EVENT_DATA->assetName)
|
||||
{
|
||||
it->OnChange();
|
||||
auto* shaderAsset = SHAssetManager::GetData<SHShaderAsset>(EVENT_DATA->assetID);
|
||||
it->OnChange(shaderAsset->spirvBinary);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eventPtr->handle;
|
||||
}
|
||||
|
|
|
@ -235,6 +235,9 @@ namespace SHADE
|
|||
, pipelineLayout { inPipelineLayout }
|
||||
, created {false}
|
||||
{
|
||||
if (pipelineLayout)
|
||||
pipelineLayout->AddCallback([this]() {ConstructPipeline();});
|
||||
|
||||
// We want to create a pipeline
|
||||
if (state != nullptr)
|
||||
{
|
||||
|
|
|
@ -450,6 +450,15 @@ namespace SHADE
|
|||
}
|
||||
else
|
||||
SHVulkanDebugUtil::ReportVkSuccess("Successfully created Pipeline Layout. ");
|
||||
|
||||
// Call callbacks
|
||||
for (auto& callback : onChangeCallbacks)
|
||||
callback();
|
||||
}
|
||||
|
||||
void SHVkPipelineLayout::AddCallback(ChangeCallback&& callback) noexcept
|
||||
{
|
||||
onChangeCallbacks.emplace_back(std::move(callback));
|
||||
}
|
||||
|
||||
std::vector<Handle<SHVkShaderModule>> const& SHVkPipelineLayout::GetShaderModules(void) const noexcept
|
||||
|
|
|
@ -10,6 +10,9 @@ namespace SHADE
|
|||
|
||||
class SHVkPipelineLayout
|
||||
{
|
||||
public:
|
||||
using ChangeCallback = std::function<void()>;
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER VARIABLES */
|
||||
|
@ -51,6 +54,12 @@ namespace SHADE
|
|||
//! Store for pipeline layout recreation
|
||||
std::vector<vk::DescriptorSetLayout> vkDescriptorSetLayoutsPipeline;
|
||||
|
||||
//! When pipeline layout needs to be recreated, this container could serve as an event
|
||||
//! response to call all the functions that need to be called. Specifically
|
||||
//! pipelines that need to use the new pipeline layout
|
||||
std::vector<ChangeCallback> onChangeCallbacks;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -73,6 +82,7 @@ namespace SHADE
|
|||
/* PUBLIC MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void RecreateIfNeeded (void) noexcept;
|
||||
void AddCallback(ChangeCallback&& callback) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
|
|
|
@ -7,20 +7,16 @@
|
|||
namespace SHADE
|
||||
{
|
||||
|
||||
SHVkShaderModule::SHVkShaderModule(Handle<SHVkLogicalDevice> const& inLogicalDeviceHdl, std::vector<uint32_t> const& binaryData, std::string inEntryPoint, vk::ShaderStageFlagBits stage, std::string const& name) noexcept
|
||||
: logicalDeviceHdl {inLogicalDeviceHdl}
|
||||
, shaderStage {stage}
|
||||
, entryPoint {inEntryPoint}
|
||||
, vkShaderModule {nullptr}
|
||||
, spirvBinary{}
|
||||
, shaderName {name}
|
||||
, reflectedData {}
|
||||
void SHVkShaderModule::Recompile(void) noexcept
|
||||
{
|
||||
if (vkShaderModule)
|
||||
logicalDeviceHdl->GetVkLogicalDevice().destroyShaderModule(vkShaderModule, nullptr);
|
||||
|
||||
// Prepare the create info
|
||||
vk::ShaderModuleCreateInfo moduleCreateInfo
|
||||
{
|
||||
.codeSize = binaryData.size() * sizeof (uint32_t),
|
||||
.pCode = binaryData.data(),
|
||||
.codeSize = spirvBinary.size() * sizeof(uint32_t),
|
||||
.pCode = spirvBinary.data(),
|
||||
};
|
||||
|
||||
if (auto result = logicalDeviceHdl->GetVkLogicalDevice().createShaderModule(&moduleCreateInfo, nullptr, &vkShaderModule); result != vk::Result::eSuccess)
|
||||
|
@ -30,10 +26,18 @@ namespace SHADE
|
|||
}
|
||||
else
|
||||
SHVulkanDebugUtil::ReportVkSuccess("Successfully created shader module.");
|
||||
}
|
||||
|
||||
// TODO: Right now, this is doing a copy, we need to figure out if its better to just move from the resource management (source library) instead. The hope is that
|
||||
// shader modules only need 1 of themselves.
|
||||
spirvBinary = binaryData;
|
||||
SHVkShaderModule::SHVkShaderModule(Handle<SHVkLogicalDevice> const& inLogicalDeviceHdl, std::vector<uint32_t> const& binaryData, std::string inEntryPoint, vk::ShaderStageFlagBits stage, std::string const& name) noexcept
|
||||
: logicalDeviceHdl {inLogicalDeviceHdl}
|
||||
, shaderStage {stage}
|
||||
, entryPoint {inEntryPoint}
|
||||
, vkShaderModule {nullptr}
|
||||
, spirvBinary{binaryData}
|
||||
, shaderName {name}
|
||||
, reflectedData {}
|
||||
{
|
||||
Recompile();
|
||||
}
|
||||
|
||||
SHVkShaderModule::SHVkShaderModule(SHVkShaderModule&& rhs) noexcept
|
||||
|
@ -81,13 +85,18 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHVkShaderModule::OnChange(void) noexcept
|
||||
void SHVkShaderModule::OnChange(std::vector<uint32_t> const& newBinaryData) noexcept
|
||||
{
|
||||
// assign new binary data and recompile shader
|
||||
spirvBinary = newBinaryData;
|
||||
|
||||
Recompile();
|
||||
|
||||
for (auto& callback : onChangeCallbacks)
|
||||
callback();
|
||||
}
|
||||
|
||||
void SHVkShaderModule::AddCallback(SHShaderChangeCallback&& callback) noexcept
|
||||
void SHVkShaderModule::AddCallback(ChangeCallback&& callback) noexcept
|
||||
{
|
||||
onChangeCallbacks.emplace_back(std::move(callback));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* TYPE DEFINITIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
using SHShaderChangeCallback = std::function<void()>;
|
||||
using ChangeCallback = std::function<void()>;
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -47,12 +47,13 @@ namespace SHADE
|
|||
//! response to call all the functions that need to be called. Specifically
|
||||
//! pipeline layouts that need to re-parse the newly reflected data and create
|
||||
//! descriptor set layouts and push constant ranges.
|
||||
std::vector<SHShaderChangeCallback> onChangeCallbacks;
|
||||
std::vector<ChangeCallback> onChangeCallbacks;
|
||||
|
||||
// #NoteToSelf: From Tomas module, pipeline shader stage create info isn't created here
|
||||
// because the struct allows specialization info which should not be part of a module itself.
|
||||
// This struct should be created in the pipeline instead.
|
||||
|
||||
void Recompile (void) noexcept;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -67,8 +68,8 @@ namespace SHADE
|
|||
/* PUBLIC MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void Reflect (void) noexcept;
|
||||
void OnChange (void) noexcept;
|
||||
void AddCallback (SHShaderChangeCallback&& callback) noexcept;
|
||||
void OnChange (std::vector<uint32_t> const& newBinaryData) noexcept;
|
||||
void AddCallback (ChangeCallback&& callback) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* SETTERS AND GETTERS */
|
||||
|
|
Loading…
Reference in New Issue