Latest chapter from vkguide but doesn't work yet.
This commit is contained in:
parent
40717cf8e4
commit
a5c13d8654
10 changed files with 321 additions and 7 deletions
42
vk_pipelines.cpp
Normal file
42
vk_pipelines.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "vk_pipelines.h"
|
||||
#include <fstream>
|
||||
#include "vk_initializers.h"
|
||||
#include <print>
|
||||
|
||||
bool vkutil::load_shader_module(const char* filePath,
|
||||
VkDevice device,
|
||||
VkShaderModule* outShaderModule)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
|
||||
|
||||
if(!file.is_open()) {
|
||||
std::println("failed to open file: {}", filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t fileSize = (size_t)file.tellg();
|
||||
|
||||
//spirv expects the buffer to uint32
|
||||
std::vector<uint32_t> buffer(fileSize / sizeof(uint32_t));
|
||||
file.seekg(0);
|
||||
file.read((char*)buffer.data(), fileSize);
|
||||
|
||||
file.close();
|
||||
|
||||
VkShaderModuleCreateInfo createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.pNext = nullptr;
|
||||
|
||||
// codeSize has to be in bytes
|
||||
createInfo.codeSize = buffer.size() * sizeof(uint32_t);
|
||||
createInfo.pCode = buffer.data();
|
||||
|
||||
VkShaderModule shaderModule;
|
||||
if(vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
||||
std::println("Error after vkCreateShaderModule");
|
||||
return false;
|
||||
}
|
||||
|
||||
*outShaderModule = shaderModule;
|
||||
return true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue