mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-12-18 16:56:19 +00:00
renderer_vulkan: Remove two step initialization on VKDevice
The Vulkan device abstraction either initializes successfully on the constructor or throws a Vulkan exception.
This commit is contained in:
parent
085adfea00
commit
53ea06dc17
|
@ -133,10 +133,8 @@ bool RendererVulkan::Init() try {
|
||||||
debug_callback = CreateDebugCallback(instance);
|
debug_callback = CreateDebugCallback(instance);
|
||||||
}
|
}
|
||||||
surface = CreateSurface(instance, render_window);
|
surface = CreateSurface(instance, render_window);
|
||||||
if (!PickDevices()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
InitializeDevice();
|
||||||
Report();
|
Report();
|
||||||
|
|
||||||
memory_manager = std::make_unique<VKMemoryManager>(*device);
|
memory_manager = std::make_unique<VKMemoryManager>(*device);
|
||||||
|
@ -178,21 +176,16 @@ void RendererVulkan::ShutDown() {
|
||||||
device.reset();
|
device.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RendererVulkan::PickDevices() {
|
void RendererVulkan::InitializeDevice() {
|
||||||
const std::vector<VkPhysicalDevice> devices = instance.EnumeratePhysicalDevices();
|
const std::vector<VkPhysicalDevice> devices = instance.EnumeratePhysicalDevices();
|
||||||
const s32 device_index = Settings::values.vulkan_device.GetValue();
|
const s32 device_index = Settings::values.vulkan_device.GetValue();
|
||||||
if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) {
|
if (device_index < 0 || device_index >= static_cast<s32>(devices.size())) {
|
||||||
LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index);
|
LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index);
|
||||||
return false;
|
throw vk::Exception(VK_ERROR_INITIALIZATION_FAILED);
|
||||||
}
|
}
|
||||||
const vk::PhysicalDevice physical_device(devices[static_cast<std::size_t>(device_index)], dld);
|
const vk::PhysicalDevice physical_device(devices[static_cast<size_t>(device_index)], dld);
|
||||||
if (!VKDevice::IsSuitable(physical_device, *surface)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
device =
|
device =
|
||||||
std::make_unique<VKDevice>(*instance, instance_version, physical_device, *surface, dld);
|
std::make_unique<VKDevice>(*instance, instance_version, physical_device, *surface, dld);
|
||||||
return device->Create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::Report() const {
|
void RendererVulkan::Report() const {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
static std::vector<std::string> EnumerateDevices();
|
static std::vector<std::string> EnumerateDevices();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool PickDevices();
|
void InitializeDevice();
|
||||||
|
|
||||||
void Report() const;
|
void Report() const;
|
||||||
|
|
||||||
|
|
|
@ -212,11 +212,7 @@ VKDevice::VKDevice(VkInstance instance_, u32 instance_version_, vk::PhysicalDevi
|
||||||
instance_version{instance_version_}, format_properties{GetFormatProperties(physical, dld)} {
|
instance_version{instance_version_}, format_properties{GetFormatProperties(physical, dld)} {
|
||||||
SetupFamilies(surface);
|
SetupFamilies(surface);
|
||||||
SetupFeatures();
|
SetupFeatures();
|
||||||
}
|
|
||||||
|
|
||||||
VKDevice::~VKDevice() = default;
|
|
||||||
|
|
||||||
bool VKDevice::Create() {
|
|
||||||
const auto queue_cis = GetDeviceQueueCreateInfos();
|
const auto queue_cis = GetDeviceQueueCreateInfos();
|
||||||
const std::vector extensions = LoadExtensions();
|
const std::vector extensions = LoadExtensions();
|
||||||
|
|
||||||
|
@ -426,12 +422,7 @@ bool VKDevice::Create() {
|
||||||
};
|
};
|
||||||
first_next = &diagnostics_nv;
|
first_next = &diagnostics_nv;
|
||||||
}
|
}
|
||||||
|
|
||||||
logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
|
logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
|
||||||
if (!logical) {
|
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to create logical device");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CollectTelemetryParameters();
|
CollectTelemetryParameters();
|
||||||
CollectToolingInfo();
|
CollectToolingInfo();
|
||||||
|
@ -455,9 +446,10 @@ bool VKDevice::Create() {
|
||||||
present_queue = logical.GetQueue(present_family);
|
present_queue = logical.GetQueue(present_family);
|
||||||
|
|
||||||
use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
|
use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VKDevice::~VKDevice() = default;
|
||||||
|
|
||||||
VkFormat VKDevice::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
VkFormat VKDevice::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
|
||||||
FormatType format_type) const {
|
FormatType format_type) const {
|
||||||
if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
|
if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
|
||||||
|
|
|
@ -28,9 +28,6 @@ public:
|
||||||
VkSurfaceKHR surface, const vk::InstanceDispatch& dld);
|
VkSurfaceKHR surface, const vk::InstanceDispatch& dld);
|
||||||
~VKDevice();
|
~VKDevice();
|
||||||
|
|
||||||
/// Initializes the device. Returns true on success.
|
|
||||||
bool Create();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a format supported by the device for the passed requeriments.
|
* Returns a format supported by the device for the passed requeriments.
|
||||||
* @param wanted_format The ideal format to be returned. It may not be the returned format.
|
* @param wanted_format The ideal format to be returned. It may not be the returned format.
|
||||||
|
|
|
@ -580,7 +580,7 @@ void Semaphore::SetObjectNameEXT(const char* name) const {
|
||||||
|
|
||||||
Device Device::Create(VkPhysicalDevice physical_device, Span<VkDeviceQueueCreateInfo> queues_ci,
|
Device Device::Create(VkPhysicalDevice physical_device, Span<VkDeviceQueueCreateInfo> queues_ci,
|
||||||
Span<const char*> enabled_extensions, const void* next,
|
Span<const char*> enabled_extensions, const void* next,
|
||||||
DeviceDispatch& dispatch) noexcept {
|
DeviceDispatch& dispatch) {
|
||||||
const VkDeviceCreateInfo ci{
|
const VkDeviceCreateInfo ci{
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
.pNext = next,
|
.pNext = next,
|
||||||
|
@ -593,11 +593,8 @@ Device Device::Create(VkPhysicalDevice physical_device, Span<VkDeviceQueueCreate
|
||||||
.ppEnabledExtensionNames = enabled_extensions.data(),
|
.ppEnabledExtensionNames = enabled_extensions.data(),
|
||||||
.pEnabledFeatures = nullptr,
|
.pEnabledFeatures = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
if (dispatch.vkCreateDevice(physical_device, &ci, nullptr, &device) != VK_SUCCESS) {
|
Check(dispatch.vkCreateDevice(physical_device, &ci, nullptr, &device));
|
||||||
return {};
|
|
||||||
}
|
|
||||||
Load(device, dispatch);
|
Load(device, dispatch);
|
||||||
return Device(device, dispatch);
|
return Device(device, dispatch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,7 +796,7 @@ class Device : public Handle<VkDevice, NoOwner, DeviceDispatch> {
|
||||||
public:
|
public:
|
||||||
static Device Create(VkPhysicalDevice physical_device, Span<VkDeviceQueueCreateInfo> queues_ci,
|
static Device Create(VkPhysicalDevice physical_device, Span<VkDeviceQueueCreateInfo> queues_ci,
|
||||||
Span<const char*> enabled_extensions, const void* next,
|
Span<const char*> enabled_extensions, const void* next,
|
||||||
DeviceDispatch& dispatch) noexcept;
|
DeviceDispatch& dispatch);
|
||||||
|
|
||||||
Queue GetQueue(u32 family_index) const noexcept;
|
Queue GetQueue(u32 family_index) const noexcept;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue