some work on pad emulation (WIP)

This commit is contained in:
georgemoralis 2023-10-13 09:40:59 +03:00
parent 95f1c14dcf
commit da9adf84c0
16 changed files with 255 additions and 71 deletions

View File

@ -34,17 +34,24 @@ set(USERSERVICE_SOURCES src/Emulator/HLE/Libraries/LibUserService/user_service.c
set(PAD_SOURCES src/Emulator/HLE/Libraries/LibPad/pad.cpp set(PAD_SOURCES src/Emulator/HLE/Libraries/LibPad/pad.cpp
src/Emulator/HLE/Libraries/LibPad/pad.h src/Emulator/HLE/Libraries/LibPad/pad.h
src/Emulator/HLE/Libraries/LibPad/controller.cpp
src/Emulator/HLE/Libraries/LibPad/controller.h
) )
set(SYSTEMSERVICE_SOURCES src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp set(SYSTEMSERVICE_SOURCES src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp
src/Emulator/HLE/Libraries/LibSystemService/system_service.h src/Emulator/HLE/Libraries/LibSystemService/system_service.h
) )
set(UTIL_SOURCES src/Emulator/Util/singleton.h
)
add_executable(shadps4 add_executable(shadps4
${LIBC_SOURCES} ${LIBC_SOURCES}
${USERSERVICE_SOURCES} ${USERSERVICE_SOURCES}
${PAD_SOURCES} ${PAD_SOURCES}
${SYSTEMSERVICE_SOURCES} ${SYSTEMSERVICE_SOURCES}
${UTIL_SOURCES}
src/main.cpp src/main.cpp
src/types.h src/types.h
src/Core/FsFile.cpp src/Core/FsFile.cpp

View File

@ -78,7 +78,7 @@ bool FlipQueue::flip(u32 micros) {
auto* buffer = request.cfg->buffers[request.index].buffer_render; auto* buffer = request.cfg->buffers[request.index].buffer_render;
Emulator::DrawBuffer(buffer); Emu::DrawBuffer(buffer);
m_mutex.LockMutex(); m_mutex.LockMutex();

View File

@ -64,7 +64,7 @@ class VideoOutCtx {
Lib::LockMutexGuard lock(m_mutex); Lib::LockMutexGuard lock(m_mutex);
if (m_graphic_ctx == nullptr) { if (m_graphic_ctx == nullptr) {
m_graphic_ctx = Emulator::getGraphicCtx(); m_graphic_ctx = Emu::getGraphicCtx();
} }
return m_graphic_ctx; return m_graphic_ctx;

View File

@ -8,7 +8,7 @@ static thread_local GPU::CommandPool g_command_pool;
void GPU::renderCreateCtx() { void GPU::renderCreateCtx() {
auto* render_ctx = Singleton<RenderCtx>::Instance(); auto* render_ctx = Singleton<RenderCtx>::Instance();
render_ctx->setGraphicCtx(Emulator::getGraphicCtx()); render_ctx->setGraphicCtx(Emu::getGraphicCtx());
} }
void GPU::CommandBuffer::allocateBuffer() { void GPU::CommandBuffer::allocateBuffer() {

View File

@ -164,7 +164,7 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
int registration_index = ctx->buffers_registration_index++; int registration_index = ctx->buffers_registration_index++;
Emulator::checkAndWaitForGraphicsInit(); Emu::checkAndWaitForGraphicsInit();
GPU::renderCreateCtx(); GPU::renderCreateCtx();
// try to calculate buffer size // try to calculate buffer size

View File

@ -91,7 +91,7 @@ namespace HLE::Libs::LibSceGnmDriver {
void sceGnmDriverTriggerCapture(){} void sceGnmDriverTriggerCapture(){}
void sceGnmEndWorkload(){} void sceGnmEndWorkload(){}
void sceGnmFlushGarlic() { PRINT_FUNCTION_NAME(); void sceGnmFlushGarlic() { PRINT_FUNCTION_NAME();
GPU::flushGarlic(Emulator::getGraphicCtx()); GPU::flushGarlic(Emu::getGraphicCtx());
} }
void sceGnmGetEqEventType(){} void sceGnmGetEqEventType(){}
void sceGnmGetEqTimeStamp(){} void sceGnmGetEqTimeStamp(){}

View File

@ -0,0 +1,51 @@
#include "controller.h"
namespace Emulator::Host::Controller {
GameController::GameController() { m_states_num = 0;
m_last_state = State();
}
void GameController::readState(State* state, bool* isConnected, int* connectedCount) {
Lib::LockMutexGuard lock(m_mutex);
*isConnected = m_connected;
*connectedCount = m_connected_count;
*state = getLastState();
}
State GameController::getLastState() const {
if (m_states_num == 0) {
return m_last_state;
}
auto last = (m_first_state + m_states_num - 1) % MAX_STATES;
return m_states[last];
}
void GameController::addState(const State& state) {
if (m_states_num >= MAX_STATES) {
m_states_num = MAX_STATES - 1;
m_first_state = (m_first_state + 1) % MAX_STATES;
}
auto index = (m_first_state + m_states_num) % MAX_STATES;
m_states[index] = state;
m_last_state = state;
m_states_num++;
}
void GameController::checKButton(int id, u32 button, bool isPressed) {
Lib::LockMutexGuard lock(m_mutex);
auto state = getLastState();
if (isPressed) {
state.buttonsState |= button;
} else {
state.buttonsState &= ~button;
}
addState(state);
}
} // namespace Emulator::Host::Controller

View File

@ -0,0 +1,33 @@
#pragma once
#include <types.h>
#include "Lib/Threads.h"
namespace Emulator::Host::Controller {
struct State {
u32 buttonsState;
};
constexpr u32 MAX_STATES = 64;
class GameController {
public:
GameController();
virtual ~GameController() = default;
void readState(State* state, bool* isConnected, int* connectedCount);
State getLastState() const;
void checKButton(int id, u32 button, bool isPressed);
void addState(const State& state);
private:
Lib::Mutex m_mutex;
bool m_connected = false;
State m_last_state;
int m_connected_count = 0;
u32 m_states_num = 0;
u32 m_first_state = 0;
State m_states[MAX_STATES];
};
} // namespace Emulator::HLE::Libraries::Controller

View File

@ -3,6 +3,9 @@
#include <Core/PS4/HLE/ErrorCodes.h> #include <Core/PS4/HLE/ErrorCodes.h>
#include <Core/PS4/HLE/Libs.h> #include <Core/PS4/HLE/Libs.h>
#include "Emulator/Util/singleton.h"
#include "controller.h"
namespace Emulator::HLE::Libraries::LibPad { namespace Emulator::HLE::Libraries::LibPad {
int PS4_SYSV_ABI scePadInit() { return SCE_OK; } int PS4_SYSV_ABI scePadInit() { return SCE_OK; }
@ -12,7 +15,30 @@ int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserSer
} }
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
pData->connected = true; // make it think it is connected auto* controller = singleton<Emulator::Host::Controller::GameController>::instance();
int connectedCount = 0;
bool isConnected = false;
Emulator::Host::Controller::State state;
controller->readState(&state, &isConnected, &connectedCount);
pData->buttons = state.buttonsState;
pData->leftStick.x = 0; // dummy
pData->leftStick.y = 0; // dummy
pData->rightStick.x = 0; // dummy
pData->rightStick.y = 0; // dummy
pData->analogButtons.r2 = 0;//dummy
pData->analogButtons.l2 = 0;//dummy
pData->orientation.x = 0;
pData->orientation.y = 0;
pData->orientation.z = 0;
pData->orientation.w = 0;
pData->connected = true; // isConnected; //TODO fix me proper
pData->connectedCount = 1;//connectedCount;
pData->deviceUniqueDataLen = 0;
return SCE_OK; return SCE_OK;
} }

View File

@ -1,9 +1,31 @@
#pragma once #pragma once
#include "Core/PS4/Loader/SymbolsResolver.h"
#include <Emulator/HLE/Libraries/LibUserService/user_service.h> #include <Emulator/HLE/Libraries/LibUserService/user_service.h>
#include <types.h>
#include "Core/PS4/Loader/SymbolsResolver.h"
namespace Emulator::HLE::Libraries::LibPad { namespace Emulator::HLE::Libraries::LibPad {
typedef enum : u32 {
SCE_PAD_BUTTON_L3 = 0x00000002,
SCE_PAD_BUTTON_R3 = 0x00000004,
SCE_PAD_BUTTON_OPTIONS = 0x00000008,
SCE_PAD_BUTTON_UP = 0x00000010,
SCE_PAD_BUTTON_RIGHT = 0x00000020,
SCE_PAD_BUTTON_DOWN = 0x00000040,
SCE_PAD_BUTTON_LEFT = 0x00000080,
SCE_PAD_BUTTON_L2 = 0x00000100,
SCE_PAD_BUTTON_R2 = 0x00000200,
SCE_PAD_BUTTON_L1 = 0x00000400,
SCE_PAD_BUTTON_R1 = 0x00000800,
SCE_PAD_BUTTON_TRIANGLE = 0x00001000,
SCE_PAD_BUTTON_CIRCLE = 0x00002000,
SCE_PAD_BUTTON_CROSS = 0x00004000,
SCE_PAD_BUTTON_SQUARE = 0x00008000,
SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000,
SCE_PAD_BUTTON_INTERCEPTED = 0x80000000,
} ScePadButton;
struct ScePadOpenParam { struct ScePadOpenParam {
u08 reserve[8]; u08 reserve[8];
}; };

View File

@ -0,0 +1,24 @@
#pragma once
#include <cstdlib>
#include <new>
template <class T>
class singleton {
public:
static T* instance() {
if (!m_instance) {
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
new (m_instance) T;
}
return m_instance;
}
protected:
singleton();
~singleton();
private:
static inline T* m_instance = nullptr;
};

View File

@ -5,21 +5,23 @@
#include <vulkan_util.h> #include <vulkan_util.h>
#include "Core/PS4/HLE/Graphics/video_out.h" #include "Core/PS4/HLE/Graphics/video_out.h"
#include "Emulator/HLE/Libraries/LibPad/pad.h"
#include "version.h" #include "version.h"
#include <Emulator/HLE/Libraries/LibPad/controller.h>
namespace Emulator { namespace Emu {
bool m_emu_needs_exit = false; bool m_emu_needs_exit = false;
void emuInit(u32 width, u32 height) { void emuInit(u32 width, u32 height) {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
window_ctx->m_graphic_ctx.screen_width = width; window_ctx->m_graphic_ctx.screen_width = width;
window_ctx->m_graphic_ctx.screen_height = height; window_ctx->m_graphic_ctx.screen_height = height;
} }
void checkAndWaitForGraphicsInit() { void checkAndWaitForGraphicsInit() {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
while (!window_ctx->m_is_graphic_initialized) { while (!window_ctx->m_is_graphic_initialized) {
@ -48,7 +50,7 @@ static void CreateSdlWindow(WindowCtx* ctx) {
SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm
} }
void emuRun() { void emuRun() {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
window_ctx->m_mutex.LockMutex(); window_ctx->m_mutex.LockMutex();
{ {
// init window and wait until init finishes // init window and wait until init finishes
@ -82,7 +84,7 @@ void emuRun() {
case SDL_EVENT_DID_ENTER_FOREGROUND: break; case SDL_EVENT_DID_ENTER_FOREGROUND: break;
case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP: break; case SDL_EVENT_KEY_UP: keyboardEvent(&event); break;
} }
continue; continue;
} }
@ -96,14 +98,14 @@ void emuRun() {
} }
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
return &window_ctx->m_graphic_ctx; return &window_ctx->m_graphic_ctx;
} }
void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) { void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
if (window_ctx->is_window_hidden) { if (window_ctx->is_window_hidden) {
SDL_ShowWindow(window_ctx->m_window); SDL_ShowWindow(window_ctx->m_window);
window_ctx->is_window_hidden = false; window_ctx->is_window_hidden = false;
@ -198,4 +200,23 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
} }
} }
} // namespace Emulator void keyboardEvent(SDL_Event* event) {
using Emulator::HLE::Libraries::LibPad::ScePadButton;
if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) {
u32 button = 0;
switch (event->key.keysym.sym) {
case SDLK_UP: button = ScePadButton::SCE_PAD_BUTTON_UP; break;
case SDLK_DOWN: button = ScePadButton::SCE_PAD_BUTTON_DOWN; break;
case SDLK_LEFT: button = ScePadButton::SCE_PAD_BUTTON_LEFT; break;
case SDLK_RIGHT: button = ScePadButton::SCE_PAD_BUTTON_RIGHT; break;
default: break;
}
if (button != 0) {
auto* controller = Singleton<Emulator::Host::Controller::GameController>::Instance();
controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN);
}
}
}
} // namespace Emu

View File

@ -5,7 +5,7 @@
#include <vector> #include <vector>
namespace Emulator { namespace Emu {
struct VulkanExt { struct VulkanExt {
bool enable_validation_layers = false; bool enable_validation_layers = false;
@ -81,4 +81,5 @@ void emuRun();
void checkAndWaitForGraphicsInit(); void checkAndWaitForGraphicsInit();
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx(); HLE::Libs::Graphics::GraphicCtx* getGraphicCtx();
void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image); void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image);
void keyboardEvent(SDL_Event* event);
} // namespace Emulator } // namespace Emulator

View File

@ -3,41 +3,43 @@
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs // Read online: https://github.com/ocornut/imgui/tree/master/docs
#include "imgui.h"
#include "imgui_impl_sdl3.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <stdio.h>
#include "imgui.h"
#include "imgui_impl_opengl3.h"
#include "imgui_impl_sdl3.h"
#if defined(IMGUI_IMPL_OPENGL_ES2) #if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL3/SDL_opengles2.h> #include <SDL3/SDL_opengles2.h>
#else #else
#include <SDL3/SDL_opengl.h> #include <SDL3/SDL_opengl.h>
#endif #endif
#include <Util/log.h>
#include "GUI/ElfViewer.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "types.h" #include "types.h"
#include "GUI/ElfViewer.h"
#include <Util/log.h>
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details. // This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h" #include "../libs/emscripten/emscripten_mainloop_stub.h"
#endif #endif
#include "Core/PS4/Linker.h"
#include "Util/Singleton.h"
#include <stdio.h>
#include <inttypes.h>
#include <Zydis/Zydis.h>
#include "Core/PS4/HLE/Libs.h"
#include "Lib/Threads.h"
#include <emulator.h>
#include "discord.h"
#include <Util/config.h>
#include <Core/PS4/HLE/Graphics/video_out.h> #include <Core/PS4/HLE/Graphics/video_out.h>
#include <Util/config.h>
#include <Zydis/Zydis.h>
#include <emulator.h>
#include <inttypes.h>
#include <stdio.h>
#include "Core/PS4/HLE/Libs.h"
#include "Core/PS4/Linker.h"
#include "Lib/Threads.h"
#include "Util/Singleton.h"
#include "discord.h"
// Main code // Main code
int main(int argc, char* argv[]) int main(int argc, char* argv[]) {
{
if (argc == 1) { if (argc == 1) {
printf("Usage: %s <elf or eboot.bin path>\n", argv[0]); printf("Usage: %s <elf or eboot.bin path>\n", argv[0]);
return -1; return -1;
@ -46,7 +48,7 @@ int main(int argc, char* argv[])
logging::init(true); // init logging logging::init(true); // init logging
auto width = Config::getScreenWidth(); auto width = Config::getScreenWidth();
auto height = Config::getScreenHeight(); auto height = Config::getScreenHeight();
Emulator::emuInit(width, height); Emu::emuInit(width, height);
HLE::Libs::Graphics::VideoOut::videoOutInit(width, height); HLE::Libs::Graphics::VideoOut::videoOutInit(width, height);
Lib::InitThreads(); Lib::InitThreads();
@ -54,7 +56,7 @@ int main(int argc, char* argv[])
auto* linker = Singleton<Linker>::Instance(); auto* linker = Singleton<Linker>::Instance();
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
auto *module =linker->LoadModule(path);//load main executable auto* module = linker->LoadModule(path); // load main executable
Lib::Thread mainthread( Lib::Thread mainthread(
[](void*) { [](void*) {
auto* linker = Singleton<Linker>::Instance(); auto* linker = Singleton<Linker>::Instance();
@ -65,12 +67,9 @@ int main(int argc, char* argv[])
Discord::RPC discordRPC; Discord::RPC discordRPC;
discordRPC.init(); discordRPC.init();
discordRPC.update(Discord::RPCStatus::Idling, ""); discordRPC.update(Discord::RPCStatus::Idling, "");
Emulator::emuRun(); Emu::emuRun();
mainthread.JoinThread(); mainthread.JoinThread();
#if 0 #if 0
// Setup SDL // Setup SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0)

View File

@ -12,8 +12,8 @@
constexpr bool log_file_vulkanutil = true; // disable it to disable logging constexpr bool log_file_vulkanutil = true; // disable it to disable logging
void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { void Graphics::Vulkan::vulkanCreate(Emu::WindowCtx* ctx) {
Emulator::VulkanExt ext; Emu::VulkanExt ext;
vulkanGetInstanceExtensions(&ext); vulkanGetInstanceExtensions(&ext);
VkApplicationInfo app_info{}; VkApplicationInfo app_info{};
@ -53,8 +53,8 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) {
std::vector<const char*> device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, std::vector<const char*> device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME,
VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME, "VK_KHR_maintenance1"}; VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME, "VK_KHR_maintenance1"};
ctx->m_surface_capabilities = new Emulator::VulkanSurfaceCapabilities{}; ctx->m_surface_capabilities = new Emu::VulkanSurfaceCapabilities{};
Emulator::VulkanQueues queues; Emu::VulkanQueues queues;
vulkanFindCompatiblePhysicalDevice(ctx->m_graphic_ctx.m_instance, ctx->m_surface, device_extensions, ctx->m_surface_capabilities, vulkanFindCompatiblePhysicalDevice(ctx->m_graphic_ctx.m_instance, ctx->m_surface, device_extensions, ctx->m_surface_capabilities,
&ctx->m_graphic_ctx.m_physical_device, &queues); &ctx->m_graphic_ctx.m_physical_device, &queues);
@ -79,11 +79,11 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) {
ctx->swapchain = vulkanCreateSwapchain(&ctx->m_graphic_ctx, 2); ctx->swapchain = vulkanCreateSwapchain(&ctx->m_graphic_ctx, 2);
} }
Emulator::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) { Emu::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) {
auto* window_ctx = Singleton<Emulator::WindowCtx>::Instance(); auto* window_ctx = Singleton<Emu::WindowCtx>::Instance();
Lib::LockMutexGuard lock(window_ctx->m_mutex); Lib::LockMutexGuard lock(window_ctx->m_mutex);
auto* s = new Emulator::VulkanSwapchain; auto* s = new Emu::VulkanSwapchain;
VkExtent2D extent{}; VkExtent2D extent{};
extent.width = clamp(ctx->screen_width, window_ctx->m_surface_capabilities->capabilities.minImageExtent.width, extent.width = clamp(ctx->screen_width, window_ctx->m_surface_capabilities->capabilities.minImageExtent.width,
@ -183,8 +183,8 @@ Emulator::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Gr
return s; return s;
} }
void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues) { void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emu::VulkanQueues& queues) {
auto get_queue = [ctx](int id, const Emulator::VulkanQueueInfo& info, bool with_mutex = false) { auto get_queue = [ctx](int id, const Emu::VulkanQueueInfo& info, bool with_mutex = false) {
ctx->queues[id].family = info.family; ctx->queues[id].family = info.family;
ctx->queues[id].index = info.index; ctx->queues[id].index = info.index;
vkGetDeviceQueue(ctx->m_device, ctx->queues[id].family, ctx->queues[id].index, &ctx->queues[id].vk_queue); vkGetDeviceQueue(ctx->m_device, ctx->queues[id].family, ctx->queues[id].index, &ctx->queues[id].vk_queue);
@ -203,8 +203,8 @@ void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx,
} }
} }
VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emulator::VulkanExt* r, VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emu::VulkanExt* r,
const Emulator::VulkanQueues& queues, const std::vector<const char*>& device_extensions) { const Emu::VulkanQueues& queues, const std::vector<const char*>& device_extensions) {
std::vector<VkDeviceQueueCreateInfo> queue_create_info(queues.family_count); std::vector<VkDeviceQueueCreateInfo> queue_create_info(queues.family_count);
std::vector<std::vector<float>> queue_priority(queues.family_count); std::vector<std::vector<float>> queue_priority(queues.family_count);
uint32_t queue_create_info_num = 0; uint32_t queue_create_info_num = 0;
@ -247,7 +247,7 @@ VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device,
return device; return device;
} }
void Graphics::Vulkan::vulkanGetInstanceExtensions(Emulator::VulkanExt* ext) { void Graphics::Vulkan::vulkanGetInstanceExtensions(Emu::VulkanExt* ext) {
u32 required_extensions_count = 0; u32 required_extensions_count = 0;
u32 available_extensions_count = 0; u32 available_extensions_count = 0;
u32 available_layers_count = 0; u32 available_layers_count = 0;
@ -283,8 +283,8 @@ void Graphics::Vulkan::vulkanGetInstanceExtensions(Emulator::VulkanExt* ext) {
void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface,
const std::vector<const char*>& device_extensions, const std::vector<const char*>& device_extensions,
Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, Emu::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device,
Emulator::VulkanQueues* out_queues) { Emu::VulkanQueues* out_queues) {
u32 count_devices = 0; u32 count_devices = 0;
vkEnumeratePhysicalDevices(instance, &count_devices, nullptr); vkEnumeratePhysicalDevices(instance, &count_devices, nullptr);
@ -292,7 +292,7 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V
vkEnumeratePhysicalDevices(instance, &count_devices, devices.data()); vkEnumeratePhysicalDevices(instance, &count_devices, devices.data());
VkPhysicalDevice found_best_device = nullptr; VkPhysicalDevice found_best_device = nullptr;
Emulator::VulkanQueues found_best_queues; Emu::VulkanQueues found_best_queues;
for (const auto& device : devices) { for (const auto& device : devices) {
VkPhysicalDeviceProperties device_properties{}; VkPhysicalDeviceProperties device_properties{};
@ -316,8 +316,8 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V
*out_queues = found_best_queues; *out_queues = found_best_queues;
} }
Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) { Emu::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) {
Emulator::VulkanQueues qs; Emu::VulkanQueues qs;
u32 queue_family_count = 0; u32 queue_family_count = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr); vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr);
@ -334,7 +334,7 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic
LOG_INFO_IF(log_file_vulkanutil, "queue family: {}, count = {}, present = {}\n", string_VkQueueFlags(f.queueFlags).c_str(), f.queueCount, LOG_INFO_IF(log_file_vulkanutil, "queue family: {}, count = {}, present = {}\n", string_VkQueueFlags(f.queueFlags).c_str(), f.queueCount,
(presentation_supported == VK_TRUE ? "true" : "false")); (presentation_supported == VK_TRUE ? "true" : "false"));
for (uint32_t i = 0; i < f.queueCount; i++) { for (uint32_t i = 0; i < f.queueCount; i++) {
Emulator::VulkanQueueInfo info; Emu::VulkanQueueInfo info;
info.family = family; info.family = family;
info.index = i; info.index = i;
info.is_graphics = (f.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0; info.is_graphics = (f.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0;
@ -401,7 +401,7 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic
} }
void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface,
Emulator::VulkanSurfaceCapabilities* surfaceCap) { Emu::VulkanSurfaceCapabilities* surfaceCap) {
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surfaceCap->capabilities); vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surfaceCap->capabilities);
uint32_t formats_count = 0; uint32_t formats_count = 0;
@ -488,7 +488,7 @@ static void set_image_layout(VkCommandBuffer buffer, HLE::Libs::Graphics::Vulkan
} }
void Graphics::Vulkan::vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, void Graphics::Vulkan::vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image,
Emulator::VulkanSwapchain* dst_swapchain) { Emu::VulkanSwapchain* dst_swapchain) {
auto* vk_buffer = buffer->getPool()->buffers[buffer->getIndex()]; auto* vk_buffer = buffer->getPool()->buffers[buffer->getIndex()];
HLE::Libs::Graphics::VulkanImage swapchain_image(HLE::Libs::Graphics::VulkanImageType::Unknown); HLE::Libs::Graphics::VulkanImage swapchain_image(HLE::Libs::Graphics::VulkanImageType::Unknown);

View File

@ -26,18 +26,18 @@ const T& clamp(const T& x, const T& min, const T& max) {
return x; return x;
} }
void vulkanCreate(Emulator::WindowCtx* ctx); void vulkanCreate(Emu::WindowCtx* ctx);
void vulkanGetInstanceExtensions(Emulator::VulkanExt* ext); void vulkanGetInstanceExtensions(Emu::VulkanExt* ext);
void vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector<const char*>& device_extensions, void vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector<const char*>& device_extensions,
Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, Emu::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device,
Emulator::VulkanQueues* out_queues); Emu::VulkanQueues* out_queues);
VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emulator::VulkanExt* r, VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emu::VulkanExt* r,
const Emulator::VulkanQueues& queues, const std::vector<const char*>& device_extensions); const Emu::VulkanQueues& queues, const std::vector<const char*>& device_extensions);
Emulator::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface); Emu::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface);
void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap); void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emu::VulkanSurfaceCapabilities* surfaceCap);
void vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues); void vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emu::VulkanQueues& queues);
Emulator::VulkanSwapchain* vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count); Emu::VulkanSwapchain* vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count);
void vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, Emulator::VulkanSwapchain* dst_swapchain); void vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, Emu::VulkanSwapchain* dst_swapchain);
void vulkanFillImage(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanImage* dst_image, const void* src_data, u64 size, u32 src_pitch, void vulkanFillImage(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanImage* dst_image, const void* src_data, u64 size, u32 src_pitch,
u64 dst_layout); u64 dst_layout);
void vulkanBufferToImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanBuffer* src_buffer, u32 src_pitch, void vulkanBufferToImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanBuffer* src_buffer, u32 src_pitch,