Compare commits

..

No commits in common. "main" and "vulkan_api_wrapper" have entirely different histories.

5 changed files with 78 additions and 72 deletions

View file

@ -172,7 +172,7 @@ private:
{ {
// I know this makes the tests too verbose... // I know this makes the tests too verbose...
// but makes it easier to figure out what the problem is when things fail on ci // but makes it easier to figure out what the problem is when things fail on ci
lt::log::trace("vulkan: {}", std::string { data.message }); lt::log::debug("vulkan: {}", data.message);
std::ignore = data; std::ignore = data;
std::ignore = type; std::ignore = type;
@ -221,6 +221,10 @@ public:
return m_system; return m_system;
} }
auto device() -> lt::renderer::IDevice &
{
}
[[nodiscard]] auto has_any_messages() const -> bool [[nodiscard]] auto has_any_messages() const -> bool
{ {
return m_user_data->m_has_any_messages; return m_user_data->m_has_any_messages;
@ -242,7 +246,7 @@ private:
{ {
// I know this makes the tests too verbose... // I know this makes the tests too verbose...
// but makes it easier to figure out what the problem is when things fail on ci // but makes it easier to figure out what the problem is when things fail on ci
lt::log::trace("vulkan: {}", std::string { data.message }); lt::log::trace("vulkan: {}", data.message);
std::ignore = data; std::ignore = data;
std::ignore = type; std::ignore = type;

View file

@ -56,7 +56,7 @@ public:
System(CreateInfo info); System(CreateInfo info);
~System() override = default; ~System() override;
System(System &&) = default; System(System &&) = default;
@ -152,6 +152,8 @@ System::System(CreateInfo info)
) }; ) };
} }
System::~System() = default;
void System::on_register() void System::on_register()
{ {
} }

View file

@ -1306,8 +1306,10 @@ public:
/** de-allocation functions */ /** de-allocation functions */
void free_memory(VkDeviceMemory memory) const; void free_memory(VkDeviceMemory memory) const;
void free_descriptor_set(VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) void free_descriptor_set(
const; VkDescriptorPool descriptor_pool,
VkDescriptorSet descriptor_set
) const;
/** destroy functions */ /** destroy functions */
void destroy_swapchain(VkSwapchainKHR swapchain) const; void destroy_swapchain(VkSwapchainKHR swapchain) const;
@ -3069,7 +3071,7 @@ Instance::Instance(CreateInfo info)
layer_names.emplace_back(layer.name.c_str()); layer_names.emplace_back(layer.name.c_str());
for (const auto &setting : layer.settings) for (const auto &setting : layer.settings)
{ {
const auto *values = static_cast<void *>(nullptr); const auto *values = (void *) { nullptr };
if (setting.values.index() == 0) if (setting.values.index() == 0)
{ {
@ -3086,13 +3088,15 @@ Instance::Instance(CreateInfo info)
debug::ensure(values, "Failed to get variant from setting.values"); debug::ensure(values, "Failed to get variant from setting.values");
layer_settings.emplace_back(VkLayerSettingEXT { layer_settings.emplace_back(
VkLayerSettingEXT {
.pLayerName = layer.name.c_str(), .pLayerName = layer.name.c_str(),
.pSettingName = setting.name.c_str(), .pSettingName = setting.name.c_str(),
.type = std::visit(layer_setting_type_visitor, setting.values), .type = std::visit(layer_setting_type_visitor, setting.values),
.valueCount = 1u, .valueCount = 1u,
.pValues = values, .pValues = values,
}); }
);
} }
} }
@ -3104,8 +3108,8 @@ Instance::Instance(CreateInfo info)
auto app_info = VkApplicationInfo { auto app_info = VkApplicationInfo {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = constants::engine_name,
.applicationVersion = constants::application_version, .applicationVersion = constants::application_version,
.pApplicationName = constants::engine_name,
.pEngineName = constants::app_name, .pEngineName = constants::app_name,
.apiVersion = constants::api_version, .apiVersion = constants::api_version,
}; };
@ -3114,11 +3118,11 @@ Instance::Instance(CreateInfo info)
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = &layer_settings_create_info, .pNext = &layer_settings_create_info,
.flags = {}, .flags = {},
.pApplicationInfo = &app_info,
.enabledLayerCount = static_cast<uint32_t>(info.layers.size()), .enabledLayerCount = static_cast<uint32_t>(info.layers.size()),
.ppEnabledLayerNames = layer_names.data(), .ppEnabledLayerNames = layer_names.data(),
.enabledExtensionCount = static_cast<uint32_t>(extension_names.size()), .enabledExtensionCount = static_cast<uint32_t>(extension_names.size()),
.ppEnabledExtensionNames = extension_names.data(), .ppEnabledExtensionNames = extension_names.data(),
.pApplicationInfo = &app_info,
}; };
vkc(api::create_instance(&vk_info, nullptr, &m_instance)); vkc(api::create_instance(&vk_info, nullptr, &m_instance));
@ -3291,7 +3295,7 @@ Surface::~Surface()
.shader_sampled_image_array_non_uniform_indexing =true, .shader_sampled_image_array_non_uniform_indexing =true,
.shader_storage_buffer_array_non_uniform_indexing =true, .shader_storage_buffer_array_non_uniform_indexing =true,
.shader_storage_image_array_non_uniform_indexing =true, .shader_storage_image_array_non_uniform_indexing =true,
.shader_input_attachment_array_non_uniform_indexing =false, .shader_input_attachment_array_non_uniform_indexing =true,
.shader_uniform_texel_buffer_array_non_uniform_indexing =true, .shader_uniform_texel_buffer_array_non_uniform_indexing =true,
.shader_storage_texel_buffer_array_non_uniform_indexing =true, .shader_storage_texel_buffer_array_non_uniform_indexing =true,
.descriptor_binding_uniform_buffer_update_after_bind =true, .descriptor_binding_uniform_buffer_update_after_bind =true,
@ -3581,10 +3585,12 @@ Surface::~Surface()
auto formats = std::vector<Surface::Format> {}; auto formats = std::vector<Surface::Format> {};
for (auto &vk_format : vk_formats) for (auto &vk_format : vk_formats)
{ {
formats.emplace_back(Surface::Format { formats.emplace_back(
Surface::Format {
.format = static_cast<Format>(vk_format.format), .format = static_cast<Format>(vk_format.format),
.color_space = static_cast<ColorSpace>(vk_format.colorSpace), .color_space = static_cast<ColorSpace>(vk_format.colorSpace),
}); }
);
} }
return formats; return formats;
@ -3641,12 +3647,14 @@ Device::Device(const Gpu &gpu, CreateInfo info)
auto vk_queue_infos = std::vector<VkDeviceQueueCreateInfo> {}; auto vk_queue_infos = std::vector<VkDeviceQueueCreateInfo> {};
for (auto queue_family : info.queue_indices) for (auto queue_family : info.queue_indices)
{ {
vk_queue_infos.emplace_back(VkDeviceQueueCreateInfo { vk_queue_infos.emplace_back(
VkDeviceQueueCreateInfo {
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.queueFamilyIndex = queue_family, .queueFamilyIndex = queue_family,
.queueCount = 1u, .queueCount = 1u,
.pQueuePriorities = &priorities, .pQueuePriorities = &priorities,
}); }
);
} }
auto vk_extension_names = std::vector<const char *> {}; auto vk_extension_names = std::vector<const char *> {};
@ -4039,8 +4047,10 @@ void Device::free_memory(VkDeviceMemory memory) const
api::free_memory(m_device, memory, nullptr); api::free_memory(m_device, memory, nullptr);
} }
void Device::free_descriptor_set(VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set) void Device::free_descriptor_set(
const VkDescriptorPool descriptor_pool,
VkDescriptorSet descriptor_set
) const
{ {
vkc(api::free_descriptor_sets(m_device, descriptor_pool, 1, &descriptor_set)); vkc(api::free_descriptor_sets(m_device, descriptor_pool, 1, &descriptor_set));
} }
@ -4444,8 +4454,8 @@ CommandPool::CommandPool(Device &device, CreateInfo info): m_device(device.get_v
{ {
auto vk_info = VkCommandPoolCreateInfo { auto vk_info = VkCommandPoolCreateInfo {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = {},
.flags = info.flags, .flags = info.flags,
.pNext = {},
.queueFamilyIndex = {}, .queueFamilyIndex = {},
}; };
@ -4669,13 +4679,15 @@ DescriptorSetLayout::DescriptorSetLayout(Device &device, CreateInfo info)
vk_binding_flag_values.reserve(info.bindings.size()); vk_binding_flag_values.reserve(info.bindings.size());
for (auto &binding_info : info.bindings) for (auto &binding_info : info.bindings)
{ {
vk_bindings.emplace_back(VkDescriptorSetLayoutBinding { vk_bindings.emplace_back(
VkDescriptorSetLayoutBinding {
.binding = binding_info.idx, .binding = binding_info.idx,
.descriptorType = static_cast<VkDescriptorType>(binding_info.type), .descriptorType = static_cast<VkDescriptorType>(binding_info.type),
.descriptorCount = binding_info.count, .descriptorCount = binding_info.count,
.stageFlags = binding_info.shader_stages, .stageFlags = binding_info.shader_stages,
.pImmutableSamplers = {}, .pImmutableSamplers = {},
}); }
);
vk_binding_flag_values.emplace_back(binding_info.flags); vk_binding_flag_values.emplace_back(binding_info.flags);
} }
@ -4717,10 +4729,12 @@ DescriptorPool::DescriptorPool(Device &device, CreateInfo info): m_device(device
vk_sizes.reserve(info.sizes.size()); vk_sizes.reserve(info.sizes.size());
for (auto &size : info.sizes) for (auto &size : info.sizes)
{ {
vk_sizes.emplace_back(VkDescriptorPoolSize { vk_sizes.emplace_back(
VkDescriptorPoolSize {
.type = static_cast<VkDescriptorType>(size.type), .type = static_cast<VkDescriptorType>(size.type),
.descriptorCount = size.count, .descriptorCount = size.count,
}); }
);
} }
auto vk_info = VkDescriptorPoolCreateInfo { auto vk_info = VkDescriptorPoolCreateInfo {
@ -4774,12 +4788,14 @@ Pipeline::Pipeline(Device &device, PipelineLayout &layout, CreateInfo info)
auto shader_stages = std::vector<VkPipelineShaderStageCreateInfo> {}; auto shader_stages = std::vector<VkPipelineShaderStageCreateInfo> {};
for (auto &[shader, stage] : info.shaders) for (auto &[shader, stage] : info.shaders)
{ {
shader_stages.emplace_back(VkPipelineShaderStageCreateInfo { shader_stages.emplace_back(
VkPipelineShaderStageCreateInfo {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = static_cast<VkShaderStageFlagBits>(stage), .stage = static_cast<VkShaderStageFlagBits>(stage),
.module = shader.get_vk_handle(), .module = shader.get_vk_handle(),
.pName = "main", .pName = "main",
}); }
);
} }
auto dynamic_states = std::array<VkDynamicState, 2> { auto dynamic_states = std::array<VkDynamicState, 2> {
@ -4862,7 +4878,8 @@ Pipeline::Pipeline(Device &device, PipelineLayout &layout, CreateInfo info)
.colorAttachmentCount = static_cast<uint32_t>(color_attachment_formats.size()), .colorAttachmentCount = static_cast<uint32_t>(color_attachment_formats.size()),
.pColorAttachmentFormats = std::bit_cast<VkFormat *>(color_attachment_formats.data()), .pColorAttachmentFormats = std::bit_cast<VkFormat *>(color_attachment_formats.data()),
.depthAttachmentFormat = info.attachment_state.depth_attachment ? .depthAttachmentFormat = info.attachment_state.depth_attachment ?
static_cast<VkFormat>(*info.attachment_state.depth_attachment static_cast<VkFormat>(
*info.attachment_state.depth_attachment
) : ) :
VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED,
@ -4914,11 +4931,13 @@ PipelineLayout::PipelineLayout(Device &device, CreateInfo info): m_device(device
for (const auto &range : info.push_constant_ranges) for (const auto &range : info.push_constant_ranges)
{ {
vk_push_constant_ranges.emplace_back(VkPushConstantRange { vk_push_constant_ranges.emplace_back(
VkPushConstantRange {
.stageFlags = range.shader_stages, .stageFlags = range.shader_stages,
.offset = range.offset, .offset = range.offset,
.size = range.size, .size = range.size,
}); }
);
} }
for (const auto &layout : info.descriptor_set_layouts) for (const auto &layout : info.descriptor_set_layouts)

View file

@ -105,9 +105,9 @@ void Device::initialize_logical_device()
.features = { .features = {
.geometry_shader = true, .geometry_shader = true,
.sampler_anisotropy = true,
.multi_draw_indirect = true, .multi_draw_indirect = true,
.draw_indirect_first_instance = true, .draw_indirect_first_instance = true,
.sampler_anisotropy = true,
}, },
.dynamic_rendering_features = m_gpu->vk().get_supported_dynamic_rendering_features(), .dynamic_rendering_features = m_gpu->vk().get_supported_dynamic_rendering_features(),

View file

@ -1,6 +1,5 @@
export module renderer.vk.gpu; export module renderer.vk.gpu;
import renderer.vk.api_wrapper; import renderer.vk.api_wrapper;
import logger;
import debug.assertions; import debug.assertions;
import renderer.frontend; import renderer.frontend;
import renderer.vk.instance; import renderer.vk.instance;
@ -76,30 +75,12 @@ Gpu::Gpu(IInstance *instance)
auto properties = gpu.get_properties(); auto properties = gpu.get_properties();
auto features = gpu.get_features(); auto features = gpu.get_features();
// GPU is dedicated, a great success!
if (properties.device_type == vk::Gpu::Type::discrete_gpu && features.geometry_shader) if (properties.device_type == vk::Gpu::Type::discrete_gpu && features.geometry_shader)
{ {
m_gpu = gpu; m_gpu = gpu;
} }
} }
if (!m_gpu)
{
for (auto &gpu : gpus)
{
auto properties = gpu.get_properties();
auto features = gpu.get_features();
// GPU is integrated, fall back to anything with geometry shader support...
if (features.geometry_shader)
{
m_gpu = gpu;
log::warn("Using integrated GPU");
}
}
}
// No suitable GPU is fonud...
debug::ensure(m_gpu, "Failed to find any suitable Vulkan physical device"); debug::ensure(m_gpu, "Failed to find any suitable Vulkan physical device");
m_memory_properties = m_gpu.get_memory_properties(); m_memory_properties = m_gpu.get_memory_properties();