This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.hpp
More file actions
executable file
·66 lines (54 loc) · 1.84 KB
/
Copy pathHelpers.hpp
File metadata and controls
executable file
·66 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include <string>
#include <vector>
#include <fstream>
#include <filesystem>
#include <vulkan/vulkan.h>
static uint32_t QueryMemoryTypeIndex(VkMemoryPropertyFlagBits PreferredMemoryType, uint32_t RequiredMemoryTypes, const VkPhysicalDeviceMemoryProperties2& DeviceMemoryInfo)
{
for (uint32_t i = 0; i < DeviceMemoryInfo.memoryProperties.memoryTypeCount; i++)
{
if ((RequiredMemoryTypes & (1 << i)) && (PreferredMemoryType & DeviceMemoryInfo.memoryProperties.memoryTypes[i].propertyFlags))
{
return i;
}
}
return 0;
}
static VkShaderModule CreateShaderModule(VkDevice Device, const std::string& ShaderFilePath)
{
std::vector<char> ShaderCodeBytes(std::filesystem::file_size(ShaderFilePath), 0);
// Load file content.
{
std::ifstream ShaderFile(ShaderFilePath, std::ios::binary);
ShaderFile.read(ShaderCodeBytes.data(), ShaderCodeBytes.size());
}
// Create Vulkan shader module.
VkShaderModule ShaderModule{};
VkShaderModuleCreateInfo CreationInfo
{
.sType = VkStructureType::VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.codeSize = ShaderCodeBytes.size(),
.pCode = reinterpret_cast<const uint32_t*>(ShaderCodeBytes.data())
};
vkCreateShaderModule(Device, &CreationInfo, nullptr, &ShaderModule);
return ShaderModule;
}
struct RequiredMemory
{
size_t SegmentSize;
size_t SegmentsCount;
};
static RequiredMemory ComputeMemorySegments(VkMemoryRequirements Requirements)
{
const size_t MemoryToAlign = Requirements.size % Requirements.alignment;
const size_t MemoryWithoutAlign = (Requirements.size - MemoryToAlign) / Requirements.alignment;
const size_t RequiredSegments = MemoryWithoutAlign + (MemoryToAlign > 0 ? 1 : 0);
return RequiredMemory
{
.SegmentSize = Requirements.alignment,
.SegmentsCount = RequiredSegments
};
}