Mandrill 2025.6.0
Loading...
Searching...
No Matches
Shader.h
1#pragma once
2
3#include "Common.h"
4
5#include "Device.h"
6
7namespace Mandrill
8{
9 struct ShaderDesc {
13 std::filesystem::path filename;
14
18 std::string entry;
19
23 VkShaderStageFlagBits stageFlags;
24
28 VkSpecializationInfo* pSpecializationInfo;
29
37 MANDRILL_API ShaderDesc(std::filesystem::path filename, std::string entry, VkShaderStageFlagBits stageFlags,
38 VkSpecializationInfo* pSpecializationInfo = nullptr)
39 : filename(filename), entry(entry), stageFlags(stageFlags), pSpecializationInfo(pSpecializationInfo)
40 {
41 }
42 };
43
48 class Shader
49 {
50 public:
51 MANDRILL_NON_COPYABLE(Shader)
52
53
58 MANDRILL_API Shader(ptr<Device> pDevice, const std::vector<ShaderDesc>& desc);
59
63 MANDRILL_API ~Shader();
64
68 MANDRILL_API void reload();
69
74 MANDRILL_API std::vector<VkShaderModule> getModules() const
75 {
76 return mModules;
77 }
78
83 MANDRILL_API std::vector<VkPipelineShaderStageCreateInfo> getStages() const
84 {
85 return mStages;
86 }
87
88 private:
89 void createModulesAndStages();
90 VkShaderModule loadModuleFromFile(const std::filesystem::path& input);
91
92 ptr<Device> mpDevice;
93
94 std::vector<VkShaderModule> mModules;
95 std::vector<VkPipelineShaderStageCreateInfo> mStages;
96
97 std::vector<std::string> mEntries;
98 std::vector<std::filesystem::path> mSrcFilenames;
99 std::vector<VkShaderStageFlagBits> mStageFlags;
100 std::vector<VkSpecializationInfo*> mSpecializationInfos;
101 };
102} // namespace Mandrill
Shader class that abstracts the handling of Vulkan shaders. This class manages shader modules and hot...
Definition Shader.h:49
MANDRILL_API std::vector< VkPipelineShaderStageCreateInfo > getStages() const
Get pipeline shader stage create infos.
Definition Shader.h:83
MANDRILL_API void reload()
Reload shader code from disk and recompile it.
Definition Shader.cpp:98
MANDRILL_API std::vector< VkShaderModule > getModules() const
Get shader module handles.
Definition Shader.h:74
MANDRILL_API ~Shader()
Destructor for shader.
Definition Shader.cpp:88