42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#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;
|
|
}
|