SpiecsEngine
 
Loading...
Searching...
No Matches

◆ VulkanShaderModule() [1/2]

Spices::VulkanShaderModule::VulkanShaderModule ( VulkanState & vulkanState,
const std::string & shaderName,
const std::string & shaderStage )

Constructor Function. Create VkShaderModule.

Parameters
[in]vulkanStateThe global VulkanState.
[in]shaderNameThe Shader name.
[in]shaderStageThe Shader usage stage.

Get Shader File Path.

Confirm file existence.

Open Shader File.

Read Shader File.

Instance a VkShaderModuleCreateInfo.

Create Shader Module.

Add to Aftermath.

Get Shader File Path.

Confirm file existence.

Open Shader File.

Read Shader File.

Instance a VkShaderModuleCreateInfo.

Create Shader Module.

Add to Aftermath.

Definition at line 14 of file VulkanShaderModule.cpp.

19 : VulkanObject(vulkanState)
21 {
23
27 const std::string filePath = GetShaderPath(shaderName, shaderStage);
28
32 FileHandle fileHandle = {};
33 fileHandle.is_valid = FileLibrary::FileLibrary_Exists(filePath.c_str());
34
35 if (!fileHandle.is_valid)
36 {
37 SPICES_CORE_ERROR("File is not exist.");
38 }
39
43 FileLibrary::FileLibrary_Open(filePath.c_str(), FILE_MODE_READ, 1, &fileHandle);
44
45 uint64_t fileSize = 0;
46 FileLibrary::FileLibrary_Size(&fileHandle, &fileSize);
47
51 std::vector<char> shaderChar;
52 shaderChar.resize(fileSize);
53 FileLibrary::FileLibrary_Read_all_bytes(&fileHandle, shaderChar.data(), &fileSize);
54
58 VkShaderModuleCreateInfo createInfo{};
59 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
60 createInfo.codeSize = fileSize;
61 createInfo.pCode = reinterpret_cast<const uint32_t*>(shaderChar.data());
62
66 VK_CHECK(vkCreateShaderModule(vulkanState.m_Device, &createInfo, nullptr, &m_ShaderModule))
67 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast<uint64_t>(m_ShaderModule), m_VulkanState.m_Device, shaderName)
68
70
74 NSIGHTAFTERMATH_GPUCRASHTRACKER_ADDSHADERBINARY(filePath.c_str())
75 NSIGHTAFTERMATH_GPUCRASHTRACKER_ADDSHADERBINARY_WITHDEBUGINFO(filePath.c_str(), filePath.c_str())
76 }
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
static bool FileLibrary_Size(const FileHandle *handle, uint64_t *out_size)
Calculate The file size.
static bool FileLibrary_Open(const char *path, FileModes mode, bool binary, FileHandle *out_handle)
Open the file using given string.
static void FileLibrary_Close(FileHandle *handle)
Close the file by the file handle.
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static bool FileLibrary_Read_all_bytes(const FileHandle *handle, char *out_bytes, uint64_t *out_bytes_read)
Read all data form the current file handle pointer.
static ShaderStage ToStage(std::string stage)
Convert String to ShaderStage.
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
std::string GetShaderPath(const std::string &name, const std::string &shaderType)
Get shader path string.
VkShaderModule m_ShaderModule
The VkShaderModule this class handled.
@ FILE_MODE_READ
model : read
Definition FileLibrary.h:37

References Spices::FILE_MODE_READ, Spices::FileLibrary::FileLibrary_Exists(), Spices::FileLibrary::FileLibrary_Open(), Spices::FileLibrary::FileLibrary_Size(), GetShaderPath(), Spices::FileHandle::is_valid, m_ShaderStage, Spices::ShaderHelper::ToStage(), and Spices::VulkanObject::VulkanObject().