refactor(renderer/vk/gpu): quality of life modifications
This commit is contained in:
parent
f50208653e
commit
8730d31e2f
2 changed files with 47 additions and 22 deletions
|
|
@ -5,35 +5,38 @@
|
||||||
namespace lt::renderer::vk {
|
namespace lt::renderer::vk {
|
||||||
|
|
||||||
Gpu::Gpu(IInstance *instance)
|
Gpu::Gpu(IInstance *instance)
|
||||||
|
: m_descriptor_indexing_features(
|
||||||
|
{ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES }
|
||||||
|
)
|
||||||
{
|
{
|
||||||
auto gpus = static_cast<Instance *>(instance)->enumerate_gpus();
|
auto gpus = static_cast<Instance *>(instance)->enumerate_gpus();
|
||||||
|
|
||||||
for (auto &gpu : gpus)
|
for (auto &gpu : gpus)
|
||||||
{
|
{
|
||||||
auto properties = VkPhysicalDeviceProperties {};
|
auto properties = VkPhysicalDeviceProperties {};
|
||||||
auto features = VkPhysicalDeviceFeatures {};
|
auto features = VkPhysicalDeviceFeatures2 {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||||
|
.pNext = &m_descriptor_indexing_features
|
||||||
|
};
|
||||||
|
|
||||||
vk_get_physical_device_properties(gpu, &properties);
|
vk_get_physical_device_properties(gpu, &properties);
|
||||||
vk_get_physical_device_features(gpu, &features);
|
vk_get_physical_device_features(gpu, &features);
|
||||||
|
|
||||||
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
|
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
|
||||||
&& features.geometryShader)
|
&& features.features.geometryShader)
|
||||||
{
|
{
|
||||||
m_gpu = gpu;
|
m_gpu = gpu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ensure(m_gpu, "Failed to find any suitable Vulkan physical device");
|
ensure(m_gpu, "Failed to find any suitable Vulkan physical device");
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto Gpu::get_queue_family_properties() const -> std::vector<VkQueueFamilyProperties>
|
|
||||||
{
|
vk_get_physical_device_memory_properties(m_gpu, &m_memory_properties);
|
||||||
|
|
||||||
auto count = uint32_t { 0u };
|
auto count = uint32_t { 0u };
|
||||||
vk_get_physical_device_queue_family_properties(m_gpu, &count, nullptr);
|
vk_get_physical_device_queue_family_properties(m_gpu, &count, nullptr);
|
||||||
|
m_queue_family_properties.resize(count);
|
||||||
auto properties = std::vector<VkQueueFamilyProperties>(count);
|
vk_get_physical_device_queue_family_properties(m_gpu, &count, m_queue_family_properties.data());
|
||||||
vk_get_physical_device_queue_family_properties(m_gpu, &count, properties.data());
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto Gpu::queue_family_supports_presentation(
|
[[nodiscard]] auto Gpu::queue_family_supports_presentation(
|
||||||
|
|
@ -67,11 +70,11 @@ Gpu::Gpu(IInstance *instance)
|
||||||
return formats;
|
return formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto Gpu::get_memory_properties() const -> VkPhysicalDeviceMemoryProperties
|
[[nodiscard]] auto Gpu::create_device(VkDeviceCreateInfo info) const -> VkDevice
|
||||||
{
|
{
|
||||||
auto memory_properties = VkPhysicalDeviceMemoryProperties {};
|
auto *device = VkDevice {};
|
||||||
vk_get_physical_device_memory_properties(m_gpu, &memory_properties);
|
vkc(vk_create_device(m_gpu, &info, nullptr, &device));
|
||||||
return memory_properties;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace lt::renderer::vk
|
} // namespace lt::renderer::vk
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,6 @@ class Gpu: public IGpu
|
||||||
public:
|
public:
|
||||||
Gpu(IInstance *instance);
|
Gpu(IInstance *instance);
|
||||||
|
|
||||||
[[nodiscard]] auto vk() const -> VkPhysicalDevice
|
|
||||||
{
|
|
||||||
return m_gpu;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_queue_family_properties() const -> std::vector<VkQueueFamilyProperties>;
|
|
||||||
|
|
||||||
[[nodiscard]] auto queue_family_supports_presentation(
|
[[nodiscard]] auto queue_family_supports_presentation(
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
uint32_t queue_family_idx
|
uint32_t queue_family_idx
|
||||||
|
|
@ -30,10 +23,39 @@ public:
|
||||||
[[nodiscard]] auto get_surface_formats(VkSurfaceKHR surface) const
|
[[nodiscard]] auto get_surface_formats(VkSurfaceKHR surface) const
|
||||||
-> std::vector<VkSurfaceFormatKHR>;
|
-> std::vector<VkSurfaceFormatKHR>;
|
||||||
|
|
||||||
[[nodiscard]] auto get_memory_properties() const -> VkPhysicalDeviceMemoryProperties;
|
[[nodiscard]] auto create_device(VkDeviceCreateInfo info) const -> VkDevice;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_properties() const -> VkPhysicalDeviceProperties
|
||||||
|
{
|
||||||
|
return m_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_descriptor_indexing_features() const
|
||||||
|
-> VkPhysicalDeviceDescriptorIndexingFeatures
|
||||||
|
{
|
||||||
|
return m_descriptor_indexing_features;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_memory_properties() const -> VkPhysicalDeviceMemoryProperties
|
||||||
|
{
|
||||||
|
return m_memory_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_queue_family_properties() const -> std::vector<VkQueueFamilyProperties>
|
||||||
|
{
|
||||||
|
return m_queue_family_properties;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
memory::NullOnMove<VkPhysicalDevice> m_gpu = VK_NULL_HANDLE;
|
memory::NullOnMove<VkPhysicalDevice> m_gpu = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
VkPhysicalDeviceProperties m_properties {};
|
||||||
|
|
||||||
|
VkPhysicalDeviceDescriptorIndexingFeatures m_descriptor_indexing_features;
|
||||||
|
|
||||||
|
VkPhysicalDeviceMemoryProperties m_memory_properties {};
|
||||||
|
|
||||||
|
std::vector<VkQueueFamilyProperties> m_queue_family_properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lt::renderer::vk
|
} // namespace lt::renderer::vk
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue