mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-09-25 02:26:03 -05:00
GeneralSettings: Do not enumerate devices while running and disable drop-down
Also replace pointer with span for better compile-time safety checks
This commit is contained in:
@@ -164,6 +164,8 @@ MetalRenderer::MetalRenderer() : Renderer(RendererAPI::Metal)
|
||||
else
|
||||
m_vendor = GfxVendor::Generic;
|
||||
|
||||
m_selectedDeviceName = deviceName;
|
||||
|
||||
// Feature support
|
||||
m_isAppleGPU = m_device->supportsFamily(MTL::GPUFamilyApple1);
|
||||
m_supportsFramebufferFetch = GetConfig().framebuffer_fetch.GetValue() ? m_device->supportsFamily(MTL::GPUFamilyApple2) : false;
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
virtual ~Renderer() = default;
|
||||
|
||||
RendererAPI GetType() const { return m_rendererAPI; }
|
||||
const std::string& GetDeviceName() { return m_selectedDeviceName; }
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Shutdown();
|
||||
@@ -165,6 +166,7 @@ protected:
|
||||
virtual void GetVendorInformation() { }
|
||||
RendererAPI m_rendererAPI;
|
||||
GfxVendor m_vendor = GfxVendor::Generic;
|
||||
std::string m_selectedDeviceName = "";
|
||||
|
||||
static uint8 SRGBComponentToRGB(uint8 ci);
|
||||
static uint8 RGBComponentToSRGB(uint8 cli);
|
||||
|
||||
@@ -573,6 +573,7 @@ VulkanRenderer::VulkanRenderer() : Renderer(RendererAPI::Vulkan)
|
||||
const bool has_device_set = config.vk_graphic_device_uuid != zero;
|
||||
|
||||
VkPhysicalDevice fallbackDevice = VK_NULL_HANDLE;
|
||||
std::string fallbackDeviceName = "";
|
||||
|
||||
std::vector<VkPhysicalDevice> devices(device_count);
|
||||
vkEnumeratePhysicalDevices(m_instance, &device_count, devices.data());
|
||||
@@ -580,21 +581,25 @@ VulkanRenderer::VulkanRenderer() : Renderer(RendererAPI::Vulkan)
|
||||
{
|
||||
if (IsDeviceSuitable(surface, device))
|
||||
{
|
||||
VkPhysicalDeviceIDProperties physDeviceIDProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES };
|
||||
VkPhysicalDeviceProperties2 physDeviceProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
|
||||
physDeviceProps.pNext = &physDeviceIDProps;
|
||||
vkGetPhysicalDeviceProperties2(device, &physDeviceProps);
|
||||
|
||||
if (fallbackDevice == VK_NULL_HANDLE)
|
||||
{
|
||||
fallbackDevice = device;
|
||||
fallbackDeviceName = physDeviceProps.properties.deviceName;
|
||||
}
|
||||
|
||||
if (has_device_set)
|
||||
{
|
||||
VkPhysicalDeviceIDProperties physDeviceIDProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES };
|
||||
VkPhysicalDeviceProperties2 physDeviceProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
|
||||
physDeviceProps.pNext = &physDeviceIDProps;
|
||||
vkGetPhysicalDeviceProperties2(device, &physDeviceProps);
|
||||
|
||||
if (memcmp(config.vk_graphic_device_uuid.data(), physDeviceIDProps.deviceUUID, VK_UUID_SIZE) != 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
m_physicalDevice = device;
|
||||
m_selectedDeviceName = physDeviceProps.properties.deviceName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -603,6 +608,7 @@ VulkanRenderer::VulkanRenderer() : Renderer(RendererAPI::Vulkan)
|
||||
{
|
||||
cemuLog_log(LogType::Force, "The selected GPU could not be found or is not suitable. Falling back to first available device instead");
|
||||
m_physicalDevice = fallbackDevice;
|
||||
m_selectedDeviceName = fallbackDeviceName;
|
||||
config.vk_graphic_device_uuid = {}; // resetting device selection
|
||||
}
|
||||
else if (m_physicalDevice == VK_NULL_HANDLE)
|
||||
|
||||
@@ -175,10 +175,10 @@ public:
|
||||
|
||||
struct DeviceInfo
|
||||
{
|
||||
DeviceInfo(const std::string name, uint8* uuid)
|
||||
DeviceInfo(const std::string name, std::span<uint8, VK_UUID_SIZE> uuid)
|
||||
: name(name)
|
||||
{
|
||||
std::copy(uuid, uuid + VK_UUID_SIZE, this->uuid.data());
|
||||
std::copy(uuid.begin(), uuid.end(), this->uuid.begin());
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
@@ -380,11 +380,6 @@ wxPanel* GeneralSettings2::AddGraphicsPage(wxNotebook* notebook)
|
||||
m_graphic_api->SetSelection(0);
|
||||
if (api_size > 1)
|
||||
m_graphic_api->SetToolTip(_("Select one of the available graphic back ends"));
|
||||
if (CafeSystem::IsTitleRunning())
|
||||
{
|
||||
m_graphic_api->Disable();
|
||||
m_graphic_api->SetToolTip(_("Graphics API cannot be changed while a title is running"));
|
||||
}
|
||||
row->Add(m_graphic_api, 0, wxALL, 5);
|
||||
m_graphic_api->Bind(wxEVT_CHOICE, &GeneralSettings2::OnGraphicAPISelected, this);
|
||||
|
||||
@@ -1232,37 +1227,40 @@ void GeneralSettings2::StoreConfig()
|
||||
// graphics
|
||||
config.graphic_api = m_api_map[m_graphic_api->GetSelection()];
|
||||
|
||||
selection = m_graphic_device->GetSelection();
|
||||
#ifdef ENABLE_VULKAN
|
||||
if (config.graphic_api == GraphicAPI::kVulkan)
|
||||
if (!CafeSystem::IsTitleRunning())
|
||||
{
|
||||
if (selection != wxNOT_FOUND)
|
||||
{
|
||||
const auto* info = (wxVulkanUUID*)m_graphic_device->GetClientObject(selection);
|
||||
if (info)
|
||||
config.vk_graphic_device_uuid = info->GetDeviceInfo().uuid;
|
||||
else
|
||||
config.vk_graphic_device_uuid = {};
|
||||
}
|
||||
else
|
||||
config.vk_graphic_device_uuid = {};
|
||||
}
|
||||
selection = m_graphic_device->GetSelection();
|
||||
#ifdef ENABLE_VULKAN
|
||||
if (config.graphic_api == GraphicAPI::kVulkan)
|
||||
{
|
||||
if (selection != wxNOT_FOUND)
|
||||
{
|
||||
const auto* info = (wxVulkanUUID*)m_graphic_device->GetClientObject(selection);
|
||||
if (info)
|
||||
config.vk_graphic_device_uuid = info->GetDeviceInfo().uuid;
|
||||
else
|
||||
config.vk_graphic_device_uuid = {};
|
||||
}
|
||||
else
|
||||
config.vk_graphic_device_uuid = {};
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_METAL
|
||||
if (config.graphic_api == GraphicAPI::kMetal)
|
||||
{
|
||||
if (selection != wxNOT_FOUND)
|
||||
if (config.graphic_api == GraphicAPI::kMetal)
|
||||
{
|
||||
const auto* info = (wxMetalUUID*)m_graphic_device->GetClientObject(selection);
|
||||
if (info)
|
||||
config.mtl_graphic_device_uuid = info->GetDeviceInfo().uuid;
|
||||
if (selection != wxNOT_FOUND)
|
||||
{
|
||||
const auto* info = (wxMetalUUID*)m_graphic_device->GetClientObject(selection);
|
||||
if (info)
|
||||
config.mtl_graphic_device_uuid = info->GetDeviceInfo().uuid;
|
||||
else
|
||||
config.mtl_graphic_device_uuid = {};
|
||||
}
|
||||
else
|
||||
config.mtl_graphic_device_uuid = {};
|
||||
}
|
||||
else
|
||||
config.mtl_graphic_device_uuid = {};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
config.gx2drawdone_sync = m_gx2drawdone_sync->IsChecked();
|
||||
@@ -1332,6 +1330,13 @@ void GeneralSettings2::ValidateConfig()
|
||||
|
||||
void GeneralSettings2::DisableSettings(bool game_launched)
|
||||
{
|
||||
if (game_launched)
|
||||
{
|
||||
m_graphic_api->Disable();
|
||||
m_graphic_api->SetToolTip(_("Graphics API cannot be changed while a title is running"));
|
||||
m_graphic_device->Disable();
|
||||
m_graphic_device->SetToolTip(_("Graphics Device cannot be changed while a title is running"));
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralSettings2::OnAudioLatencyChanged(wxCommandEvent& event)
|
||||
@@ -1783,26 +1788,35 @@ void GeneralSettings2::HandleGraphicsApiSelection()
|
||||
m_vsync->Select(selection);
|
||||
|
||||
m_graphic_device->Enable();
|
||||
auto devices = VulkanRenderer::GetDevices();
|
||||
m_graphic_device->Clear();
|
||||
if(!devices.empty())
|
||||
if (!CafeSystem::IsTitleRunning())
|
||||
{
|
||||
for(const auto& device : devices)
|
||||
auto devices = VulkanRenderer::GetDevices();
|
||||
if(!devices.empty())
|
||||
{
|
||||
m_graphic_device->Append(device.name, new wxVulkanUUID(device));
|
||||
}
|
||||
m_graphic_device->SetSelection(0);
|
||||
|
||||
const auto& config = GetConfig();
|
||||
for(size_t i = 0; i < devices.size(); ++i)
|
||||
{
|
||||
if(config.vk_graphic_device_uuid == devices[i].uuid)
|
||||
for(const auto& device : devices)
|
||||
{
|
||||
m_graphic_device->SetSelection(i);
|
||||
break;
|
||||
m_graphic_device->Append(device.name, new wxVulkanUUID(device));
|
||||
}
|
||||
m_graphic_device->SetSelection(0);
|
||||
|
||||
const auto& config = GetConfig();
|
||||
for(size_t i = 0; i < devices.size(); ++i)
|
||||
{
|
||||
if(config.vk_graphic_device_uuid == devices[i].uuid)
|
||||
{
|
||||
m_graphic_device->SetSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cemu_assert(g_renderer != nullptr);
|
||||
m_graphic_device->Append(g_renderer->GetDeviceName());
|
||||
m_graphic_device->SetSelection(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -1822,25 +1836,34 @@ void GeneralSettings2::HandleGraphicsApiSelection()
|
||||
m_graphic_device->Enable();
|
||||
m_graphic_device->Clear();
|
||||
|
||||
auto devices = MetalRenderer::GetDevices();
|
||||
if(!devices.empty())
|
||||
if (!CafeSystem::IsTitleRunning())
|
||||
{
|
||||
for (const auto& device : devices)
|
||||
auto devices = MetalRenderer::GetDevices();
|
||||
if(!devices.empty())
|
||||
{
|
||||
m_graphic_device->Append(device.name, new wxMetalUUID(device));
|
||||
}
|
||||
m_graphic_device->SetSelection(0);
|
||||
|
||||
const auto& config = GetConfig();
|
||||
for (size_t i = 0; i < devices.size(); ++i)
|
||||
{
|
||||
if (config.mtl_graphic_device_uuid == devices[i].uuid)
|
||||
for (const auto& device : devices)
|
||||
{
|
||||
m_graphic_device->SetSelection(i);
|
||||
break;
|
||||
m_graphic_device->Append(device.name, new wxMetalUUID(device));
|
||||
}
|
||||
m_graphic_device->SetSelection(0);
|
||||
|
||||
const auto& config = GetConfig();
|
||||
for (size_t i = 0; i < devices.size(); ++i)
|
||||
{
|
||||
if (config.mtl_graphic_device_uuid == devices[i].uuid)
|
||||
{
|
||||
m_graphic_device->SetSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cemu_assert(g_renderer != nullptr);
|
||||
m_graphic_device->Append(g_renderer->GetDeviceName());
|
||||
m_graphic_device->SetSelection(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -2276,6 +2299,7 @@ void GeneralSettings2::OnAudioChannelsSelected(wxCommandEvent& event)
|
||||
|
||||
void GeneralSettings2::OnGraphicAPISelected(wxCommandEvent& event)
|
||||
{
|
||||
cemu_assert_debug(!CafeSystem::IsTitleRunning());
|
||||
HandleGraphicsApiSelection();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user