Skip to content

Commit

Permalink
video_core: prefer discrete gpu if available (shadps4-emu#116)
Browse files Browse the repository at this point in the history
* video_core: prefer discrete gpu if available

* ci: Upgrade to clang format 17

* rewrite w\o std::zip usage

---------

Co-authored-by: raphaelthegreat <[email protected]>
  • Loading branch information
psucien and raphaelthegreat authored Apr 29, 2024
1 parent d496fab commit 2696733
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .ci/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dis
fi

# Default clang-format points to default 3.5 version one
CLANG_FORMAT=clang-format-15
CLANG_FORMAT=clang-format-17
$CLANG_FORMAT --version

if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
with:
fetch-depth: 0
- name: Install
run: sudo apt-get install clang-format-15
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main'
sudo apt update
sudo apt install clang-format-17
- name: Build
env:
COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endfunction()
# against all the src files. This should be used before making a pull request.
# =======================================================================

set(CLANG_FORMAT_POSTFIX "-15")
set(CLANG_FORMAT_POSTFIX "-17")
find_program(CLANG_FORMAT
NAMES clang-format${CLANG_FORMAT_POSTFIX}
clang-format
Expand Down
4 changes: 2 additions & 2 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Config {
bool isNeo = false;
u32 screenWidth = 1280;
u32 screenHeight = 720;
u32 gpuId = 0; // Vulkan physical device no
s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
std::string logFilter;
std::string logType = "sync";
bool isDebugDump = false;
Expand All @@ -33,7 +33,7 @@ u32 getScreenHeight() {
return screenHeight;
}

u32 getGpuId() {
s32 getGpuId() {
return gpuId;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::string getLogType();

u32 getScreenWidth();
u32 getScreenHeight();
u32 getGpuId();
s32 getGpuId();

bool debugDump();
bool isLleLibc();
Expand Down
33 changes: 26 additions & 7 deletions src/video_core/renderer_vulkan/vk_instance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <ranges>
#include <span>
#include <boost/container/static_vector.hpp>
#include <fmt/format.h>
Expand Down Expand Up @@ -39,16 +40,34 @@ Instance::Instance(bool enable_validation, bool dump_command_buffers)
dump_command_buffers)},
physical_devices{instance->enumeratePhysicalDevices()} {}

Instance::Instance(Frontend::WindowSDL& window, u32 physical_device_index)
Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index)
: instance{CreateInstance(dl, window.getWindowInfo().type, true, false)},
debug_callback{CreateDebugCallback(*instance)}, physical_devices{
instance->enumeratePhysicalDevices()} {
debug_callback{CreateDebugCallback(*instance)},
physical_devices{instance->enumeratePhysicalDevices()} {
const std::size_t num_physical_devices = static_cast<u16>(physical_devices.size());
ASSERT_MSG(physical_device_index < num_physical_devices,
"Invalid physical device index {} provided when only {} devices exist",
physical_device_index, num_physical_devices);
ASSERT_MSG(num_physical_devices > 0, "No physical devices found");

if (physical_device_index < 0) {
std::vector<std::pair<size_t, vk::PhysicalDeviceProperties2>> properties2{};
for (auto const& physical : physical_devices) {
properties2.emplace_back(properties2.size(), physical.getProperties2());
}
std::sort(properties2.begin(), properties2.end(), [](const auto& left, const auto& right) {
if (std::get<1>(left).properties.deviceType ==
std::get<1>(right).properties.deviceType) {
return true;
}
return std::get<1>(left).properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu;
});
physical_device = physical_devices[std::get<0>(properties2[0])];
} else {
ASSERT_MSG(physical_device_index < num_physical_devices,
"Invalid physical device index {} provided when only {} devices exist",
physical_device_index, num_physical_devices);

physical_device = physical_devices[physical_device_index];
}

physical_device = physical_devices[physical_device_index];
available_extensions = GetSupportedExtensions(physical_device);
properties = physical_device.getProperties();
if (properties.apiVersion < TargetVulkanApiVersion) {
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/renderer_vulkan/vk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Vulkan {
class Instance {
public:
explicit Instance(bool validation = false, bool dump_command_buffers = false);
explicit Instance(Frontend::WindowSDL& window, u32 physical_device_index);
explicit Instance(Frontend::WindowSDL& window, s32 physical_device_index);
~Instance();

/// Returns a formatted string for the driver version
Expand Down

0 comments on commit 2696733

Please sign in to comment.