|
|
@ -226,12 +226,14 @@ void VulkanTutorial::create_render_pass() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void VulkanTutorial::create_graphic_pipeline() { |
|
|
void VulkanTutorial::create_graphic_pipeline() { |
|
|
auto const vertex_shader_module = create_shader_module_from_file("shaders/shader.vert.spv"); |
|
|
auto const vertex_shader_module = |
|
|
|
|
|
m_context.create_shader_module_from_file("shaders/shader.vert.spv"); |
|
|
auto const vertex_shader_guard = make_guard([&]{ |
|
|
auto const vertex_shader_guard = make_guard([&]{ |
|
|
vkDestroyShaderModule(m_context.device(), vertex_shader_module, nullptr); |
|
|
vkDestroyShaderModule(m_context.device(), vertex_shader_module, nullptr); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
auto const fragment_shader_module = create_shader_module_from_file("shaders/shader.frag.spv"); |
|
|
auto const fragment_shader_module = |
|
|
|
|
|
m_context.create_shader_module_from_file("shaders/shader.frag.spv"); |
|
|
auto const fragment_shader_guard = make_guard([&]{ |
|
|
auto const fragment_shader_guard = make_guard([&]{ |
|
|
vkDestroyShaderModule(m_context.device(), fragment_shader_module, nullptr); |
|
|
vkDestroyShaderModule(m_context.device(), fragment_shader_module, nullptr); |
|
|
}); |
|
|
}); |
|
|
@ -456,7 +458,7 @@ void VulkanTutorial::create_vertex_buffer() { |
|
|
&memory_requirements |
|
|
&memory_requirements |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const auto memory_type = find_memory( |
|
|
const auto memory_type = m_context.find_memory( |
|
|
memory_requirements.memoryTypeBits, |
|
|
memory_requirements.memoryTypeBits, |
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
|
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
|
@ -598,49 +600,3 @@ void VulkanTutorial::create_command_buffers() { |
|
|
throw("failed to record command buffer"); |
|
|
throw("failed to record command buffer"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
VkShaderModule VulkanTutorial::create_shader_module(const std::vector<char> bytecode) { |
|
|
|
|
|
VkShaderModuleCreateInfo shader_info { |
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, |
|
|
|
|
|
.codeSize = bytecode.size(), |
|
|
|
|
|
.pCode = reinterpret_cast<const uint32_t*>(bytecode.data()), |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
VkShaderModule shader_module = VK_NULL_HANDLE; |
|
|
|
|
|
if(vkCreateShaderModule( |
|
|
|
|
|
m_context.device(), |
|
|
|
|
|
&shader_info, |
|
|
|
|
|
nullptr, |
|
|
|
|
|
&shader_module |
|
|
|
|
|
) != VK_SUCCESS) |
|
|
|
|
|
throw std::runtime_error("failed to create shader module"); |
|
|
|
|
|
|
|
|
|
|
|
return shader_module; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VkShaderModule VulkanTutorial::create_shader_module_from_file(const char* path) { |
|
|
|
|
|
auto const bytecode = read_binary_file(path); |
|
|
|
|
|
try { |
|
|
|
|
|
return create_shader_module(bytecode); |
|
|
|
|
|
} |
|
|
|
|
|
catch(std::exception err) { |
|
|
|
|
|
throw std::runtime_error(cat("failed to create shader '", path, "':\n ", err.what())); |
|
|
|
|
|
} |
|
|
|
|
|
return VK_NULL_HANDLE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t VulkanTutorial::find_memory(uint32_t type_filter, VkMemoryPropertyFlags properties) { |
|
|
|
|
|
VkPhysicalDeviceMemoryProperties memory_properties; |
|
|
|
|
|
vkGetPhysicalDeviceMemoryProperties( |
|
|
|
|
|
m_context.physical_device(), |
|
|
|
|
|
&memory_properties |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
for(uint32_t type_index = 0; type_index < memory_properties.memoryTypeCount; type_index += 1) { |
|
|
|
|
|
if(((1 << type_index) & type_filter) && |
|
|
|
|
|
(memory_properties.memoryTypes[type_index].propertyFlags & properties) == properties) |
|
|
|
|
|
return type_index; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|