Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_shadermodule.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_vulkan.hpp"
3#include "../osi/foray_env.hpp"
4#include "foray_context.hpp"
7
8namespace foray::core {
10 class ShaderModule : public core::VulkanResource<VkObjectType::VK_OBJECT_TYPE_SHADER_MODULE>
11 {
12 public:
13 ShaderModule() = default;
14
15 inline ~ShaderModule() { Destroy(); }
16
22 uint64_t CompileFromSource(Context* context, const osi::Utf8Path& path, const ShaderCompilerConfig& config = {});
26 void LoadFromFile(Context* context, const osi::Utf8Path& path);
30 inline void LoadFromBinary(Context* context, const std::vector<uint8_t>& binaryBuffer);
34 inline void LoadFromBinary(Context* context, const std::vector<uint32_t>& binaryBuffer);
39 template <size_t ARR_SIZE>
40 inline void LoadFromBinary(Context* context, const uint8_t binaryBuffer[ARR_SIZE]);
45 template <size_t ARR_SIZE>
46 inline void LoadFromBinary(Context* context, const uint32_t binaryBuffer[ARR_SIZE]);
51 void LoadFromBinary(Context* context, const uint8_t* binaryBuffer, size_t sizeInBytes);
56 void LoadFromBinary(Context* context, const uint32_t* binaryBuffer, size_t sizeInBytes);
57
58 inline virtual bool Exists() const override { return !!mShaderModule; }
59
60 virtual void Destroy() override;
61
63 VkPipelineShaderStageCreateInfo GetShaderStageCi(VkShaderStageFlagBits stage, const char* entry = "main") const;
64
65 operator VkShaderModule() const;
66
67 protected:
68 Context* mContext = nullptr;
69 VkShaderModule mShaderModule = nullptr;
70 };
71
72 void ShaderModule::LoadFromBinary(Context* context, const std::vector<uint8_t>& binaryBuffer)
73 {
74 return LoadFromBinary(context, binaryBuffer.data(), binaryBuffer.size());
75 }
76
77 void ShaderModule::LoadFromBinary(Context* context, const std::vector<uint32_t>& binaryBuffer)
78 {
79 return LoadFromBinary(context, binaryBuffer.data(), binaryBuffer.size());
80 }
81
82 template <size_t ARR_SIZE>
83 void ShaderModule::LoadFromBinary(Context* context, const uint8_t binaryBuffer[ARR_SIZE])
84 {
85 return LoadFromBinary(context, binaryBuffer, ARR_SIZE);
86 }
87
88 template <size_t ARR_SIZE>
89 void ShaderModule::LoadFromBinary(Context* context, const uint32_t binaryBuffer[ARR_SIZE])
90 {
91 return LoadFromBinary(context, binaryBuffer, ARR_SIZE * sizeof(uint32_t));
92 }
93} // namespace foray::core
Wraps shader code driver handle (VkShaderModule). See ShaderManager for compiling shaders dynamically...
Definition foray_shadermodule.hpp:11
VkPipelineShaderStageCreateInfo GetShaderStageCi(VkShaderStageFlagBits stage, const char *entry="main") const
Fill a shader stage create info. .sType, .stage, .module, .pName fields are set, remainder default in...
~ShaderModule()
Definition foray_shadermodule.hpp:15
Context * mContext
Definition foray_shadermodule.hpp:68
VkShaderModule mShaderModule
Definition foray_shadermodule.hpp:69
void LoadFromBinary(Context *context, const uint8_t *binaryBuffer, size_t sizeInBytes)
Loads from a binary buffer.
uint64_t CompileFromSource(Context *context, const osi::Utf8Path &path, const ShaderCompilerConfig &config={})
Loads by compiling from source using the ShaderManager.
virtual bool Exists() const override
Return true, if the managed resource is allocated.
Definition foray_shadermodule.hpp:58
void LoadFromBinary(Context *context, const std::vector< uint8_t > &binaryBuffer)
Loads from a binary buffer.
Definition foray_shadermodule.hpp:72
void LoadFromBinary(Context *context, const uint32_t *binaryBuffer, size_t sizeInBytes)
Loads from a binary buffer.
virtual void Destroy() override
Destroy the resource.
void LoadFromFile(Context *context, const osi::Utf8Path &path)
Loads from a spirv file.
ManagedResource variant which automates GetTypeName() overloading by returning a stringified version ...
Definition foray_managedresource.hpp:59
Utf8 encoded path wrapper.
Definition foray_env.hpp:28
Definition foray_commandbuffer.hpp:6
Non owning context object.
Definition foray_context.hpp:16
Shader compile Options struct (moved out of class to fix clang & gcc compiler bug https://gcc....
Definition foray_shadermanager.hpp:13