Compare commits
1 commit
vulkan_api
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 569c4dc3b6 |
5 changed files with 72 additions and 78 deletions
|
|
@ -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::debug("vulkan: {}", data.message);
|
lt::log::trace("vulkan: {}", std::string { data.message });
|
||||||
std::ignore = data;
|
std::ignore = data;
|
||||||
std::ignore = type;
|
std::ignore = type;
|
||||||
|
|
||||||
|
|
@ -221,10 +221,6 @@ 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;
|
||||||
|
|
@ -246,7 +242,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: {}", data.message);
|
lt::log::trace("vulkan: {}", std::string { data.message });
|
||||||
|
|
||||||
std::ignore = data;
|
std::ignore = data;
|
||||||
std::ignore = type;
|
std::ignore = type;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
System(CreateInfo info);
|
System(CreateInfo info);
|
||||||
|
|
||||||
~System() override;
|
~System() override = default;
|
||||||
|
|
||||||
System(System &&) = default;
|
System(System &&) = default;
|
||||||
|
|
||||||
|
|
@ -152,8 +152,6 @@ System::System(CreateInfo info)
|
||||||
) };
|
) };
|
||||||
}
|
}
|
||||||
|
|
||||||
System::~System() = default;
|
|
||||||
|
|
||||||
void System::on_register()
|
void System::on_register()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1306,10 +1306,8 @@ public:
|
||||||
/** de-allocation functions */
|
/** de-allocation functions */
|
||||||
void free_memory(VkDeviceMemory memory) const;
|
void free_memory(VkDeviceMemory memory) const;
|
||||||
|
|
||||||
void free_descriptor_set(
|
void free_descriptor_set(VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set)
|
||||||
VkDescriptorPool descriptor_pool,
|
const;
|
||||||
VkDescriptorSet descriptor_set
|
|
||||||
) const;
|
|
||||||
|
|
||||||
/** destroy functions */
|
/** destroy functions */
|
||||||
void destroy_swapchain(VkSwapchainKHR swapchain) const;
|
void destroy_swapchain(VkSwapchainKHR swapchain) const;
|
||||||
|
|
@ -3071,7 +3069,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 = (void *) { nullptr };
|
const auto *values = static_cast<void *>(nullptr);
|
||||||
|
|
||||||
if (setting.values.index() == 0)
|
if (setting.values.index() == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -3088,15 +3086,13 @@ 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(
|
layer_settings.emplace_back(VkLayerSettingEXT {
|
||||||
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,
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3108,8 +3104,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,
|
||||||
.applicationVersion = constants::application_version,
|
|
||||||
.pApplicationName = constants::engine_name,
|
.pApplicationName = constants::engine_name,
|
||||||
|
.applicationVersion = constants::application_version,
|
||||||
.pEngineName = constants::app_name,
|
.pEngineName = constants::app_name,
|
||||||
.apiVersion = constants::api_version,
|
.apiVersion = constants::api_version,
|
||||||
};
|
};
|
||||||
|
|
@ -3118,11 +3114,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));
|
||||||
|
|
@ -3295,7 +3291,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 =true,
|
.shader_input_attachment_array_non_uniform_indexing =false,
|
||||||
.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,
|
||||||
|
|
@ -3585,12 +3581,10 @@ 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(
|
formats.emplace_back(Surface::Format {
|
||||||
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;
|
||||||
|
|
@ -3647,14 +3641,12 @@ 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(
|
vk_queue_infos.emplace_back(VkDeviceQueueCreateInfo {
|
||||||
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 *> {};
|
||||||
|
|
@ -4047,10 +4039,8 @@ 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(
|
void Device::free_descriptor_set(VkDescriptorPool descriptor_pool, VkDescriptorSet descriptor_set)
|
||||||
VkDescriptorPool descriptor_pool,
|
const
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
@ -4454,8 +4444,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,
|
||||||
.flags = info.flags,
|
|
||||||
.pNext = {},
|
.pNext = {},
|
||||||
|
.flags = info.flags,
|
||||||
.queueFamilyIndex = {},
|
.queueFamilyIndex = {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -4679,15 +4669,13 @@ 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(
|
vk_bindings.emplace_back(VkDescriptorSetLayoutBinding {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
@ -4729,12 +4717,10 @@ 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(
|
vk_sizes.emplace_back(VkDescriptorPoolSize {
|
||||||
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 {
|
||||||
|
|
@ -4788,14 +4774,12 @@ 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(
|
shader_stages.emplace_back(VkPipelineShaderStageCreateInfo {
|
||||||
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> {
|
||||||
|
|
@ -4878,8 +4862,7 @@ 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>(
|
static_cast<VkFormat>(*info.attachment_state.depth_attachment
|
||||||
*info.attachment_state.depth_attachment
|
|
||||||
) :
|
) :
|
||||||
VK_FORMAT_UNDEFINED,
|
VK_FORMAT_UNDEFINED,
|
||||||
|
|
||||||
|
|
@ -4931,13 +4914,11 @@ 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(
|
vk_push_constant_ranges.emplace_back(VkPushConstantRange {
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -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(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
|
@ -75,12 +76,30 @@ 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();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue