FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_shader.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_VULKAN_C_SHADER_HPP_INCLUDED
18#define _FGE_VULKAN_C_SHADER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "volk.h"
22
23#include "C_descriptorSetLayout.hpp"
24#include <filesystem>
25#include <map>
26#include <vector>
27
28#define FGE_SHADER_MAX_BINDING_VARIABLE_DESCRIPTOR_COUNT 64
29
30namespace fge::vulkan
31{
32
33class LogicalDevice;
34
35class FGE_API Shader
36{
37public:
38 enum class Type : uint32_t
39 {
40 SHADER_NONE = 0,
41 SHADER_COMPUTE = VK_SHADER_STAGE_COMPUTE_BIT,
42 SHADER_VERTEX = VK_SHADER_STAGE_VERTEX_BIT,
43 SHADER_FRAGMENT = VK_SHADER_STAGE_FRAGMENT_BIT,
44 SHADER_GEOMETRY = VK_SHADER_STAGE_GEOMETRY_BIT
45 };
46
47 Shader();
48 Shader(Shader const& r) = delete;
49 Shader(Shader&& r) noexcept;
50 ~Shader();
51
52 Shader& operator=(Shader const& r) = delete;
53 Shader& operator=(Shader&& r) noexcept;
54
55 bool loadFromSpirVBuffer(LogicalDevice const& logicalDevice, std::vector<uint32_t> const& buffer, Type type);
56 bool loadFromFile(LogicalDevice const& logicalDevice, std::filesystem::path const& filepath, Type type);
57
58 void destroy();
59
60 [[nodiscard]] VkShaderModule getShaderModule() const;
61 [[nodiscard]] VkPipelineShaderStageCreateInfo const& getPipelineShaderStageCreateInfo() const;
62 [[nodiscard]] Type getType() const;
63
64#ifndef FGE_DEF_SERVER
65 using ReflectBindings = std::vector<DescriptorSetLayout::Binding>;
66 using ReflectSets = std::map<uint32_t, ReflectBindings, std::less<>>;
67
68 void retrieveBindings(ReflectSets& buffer) const;
69 [[nodiscard]] std::vector<VkPushConstantRange> retrievePushConstantRanges() const;
70#endif
71
72private:
73#ifndef FGE_DEF_SERVER
74 void reflect() const;
75#endif
76
77 VkShaderModule g_shaderModule;
78 VkPipelineShaderStageCreateInfo g_pipelineShaderStageCreateInfo;
79 Type g_type{Type::SHADER_NONE};
80 std::vector<uint32_t> g_spirvBuffer;
81
82 LogicalDevice const* g_logicalDevice;
83
84#ifndef FGE_DEF_SERVER
85 mutable std::vector<std::vector<DescriptorSetLayout::Binding>> g_reflectBindings;
86 mutable std::vector<VkPushConstantRange> g_reflectPushConstantRanges;
87#endif
88};
89
90} // namespace fge::vulkan
91
92#endif //_FGE_VULKAN_C_SHADER_HPP_INCLUDED
Logical device abstraction.
Definition C_logicalDevice.hpp:37
Definition C_shader.hpp:36