mirror of
https://github.com/shadergz/cosmic-station.git
synced 2024-11-23 06:09:40 +00:00
GPU
: The Violet
layer was attributed to the functionalities of the GPU component
This commit is contained in:
parent
396f82e088
commit
f9e88c1651
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,3 +10,6 @@
|
||||
[submodule "app/src/main/cpp/addons/Vulkan-Hpp"]
|
||||
path = app/src/main/cpp/addons/Vulkan-Hpp
|
||||
url = https://github.com/KhronosGroup/Vulkan-Hpp.git
|
||||
[submodule "app/src/main/cpp/addons/VulkanMemoryAllocator"]
|
||||
path = app/src/main/cpp/addons/VulkanMemoryAllocator
|
||||
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
|
||||
|
@ -59,8 +59,9 @@ target_sources(cosmic PRIVATE
|
||||
${COSMIC_DIR}/iop/iop_intc.cpp
|
||||
${COSMIC_DIR}/gpu/render_driver.cpp
|
||||
${COSMIC_DIR}/gpu/exhibition_engine.cpp
|
||||
${COSMIC_DIR}/gpu/violet/graphics_layer.cpp
|
||||
${COSMIC_DIR}/gpu/violet/vulkan_functions.cpp
|
||||
${COSMIC_DIR}/gpu/graphics_layer.cpp
|
||||
${COSMIC_DIR}/gpu/vulcano/vulkan_functions.cpp
|
||||
${COSMIC_DIR}/gpu/vulcano/vram_allocator.cpp
|
||||
${COSMIC_DIR}/os/system_state.cpp
|
||||
${COSMIC_DIR}/java/device_handler.cpp
|
||||
${COSMIC_DIR}/java/jclasses.cpp
|
||||
@ -88,6 +89,7 @@ add_compile_definitions(VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL=0)
|
||||
|
||||
include_directories(SYSTEM "${ADDONS_DIR}/Vulkan-Hpp")
|
||||
include_directories(SYSTEM "${ADDONS_DIR}/Vulkan-Hpp/Vulkan-Headers/include")
|
||||
include_directories("${ADDONS_DIR}/VulkanMemoryAllocator/include")
|
||||
|
||||
# Define a static library for Perfetto
|
||||
add_library(perfetto STATIC ${ADDONS_DIR}/perfetto/sdk/perfetto.cc)
|
||||
|
1
app/src/main/cpp/addons/VulkanMemoryAllocator
Submodule
1
app/src/main/cpp/addons/VulkanMemoryAllocator
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 5e43c795daf43dd09398d8307212e85025215052
|
@ -1 +1,6 @@
|
||||
|
||||
// https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/quick_start.html#quick_start_project_setup
|
||||
#define VMA_IMPLEMENTATION
|
||||
#define VMA_VULKAN_VERSION 1002000 // Vulkan 1.2
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
|
||||
#include <vk_mem_alloc.h>
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <eeiv/copctrl/cop0.h>
|
||||
|
||||
#include <fuji/mipsiv_interpreter.h>
|
||||
#include <tokyo3/tokyo3_arm64_jitter.h>
|
||||
#include <tokyo/arm64_jitter.h>
|
||||
namespace cosmic::eeiv {
|
||||
EeMipsCore::EeMipsCore(std::shared_ptr<mio::DMAController>& dma)
|
||||
: ctrl0(dma),
|
||||
@ -19,10 +19,9 @@ namespace cosmic::eeiv {
|
||||
if (procCpuMode == EEExecutionMode::CachedInterpreter)
|
||||
eeExecutor = std::make_unique<fuji::MipsIVInterpreter>(*this);
|
||||
else if (procCpuMode == EEExecutionMode::JitRe)
|
||||
eeExecutor = std::make_unique<tokyo3::EEArm64Jitter>(*this);
|
||||
eeExecutor = std::make_unique<tokyo::EeArm64Jitter>(*this);
|
||||
};
|
||||
}
|
||||
|
||||
EeMipsCore::~EeMipsCore() {
|
||||
delete[] GPRs;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <jni.h>
|
||||
#include <android/native_window_jni.h>
|
||||
|
||||
#include <gpu/violet/graphics_layer.h>
|
||||
#include <gpu/graphics_layer.h>
|
||||
namespace cosmic::gpu {
|
||||
class ExhibitionEngine {
|
||||
public:
|
||||
@ -13,7 +13,7 @@ namespace cosmic::gpu {
|
||||
jobject globalSurface;
|
||||
ANativeWindow* window;
|
||||
|
||||
violet::RenderApi graphics{violet::HardwareOpenGL};
|
||||
violet::VioletLayer scene{graphics};
|
||||
RenderApi graphics{HardwareOpenGL};
|
||||
GraphicsLayer scene{graphics};
|
||||
};
|
||||
}
|
14
app/src/main/cpp/cosmic/gpu/functions.h
Normal file
14
app/src/main/cpp/cosmic/gpu/functions.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <jni.h>
|
||||
#include <common/types.h>
|
||||
namespace cosmic::gpu {
|
||||
class GraphicsLayer;
|
||||
class GraphicsFunctionsRef {
|
||||
public:
|
||||
std::function<void(raw_reference<GraphicsLayer>, jobject)> setSurface;
|
||||
std::function<void(raw_reference<GraphicsLayer>)> prepareGraphicsApi;
|
||||
std::function<void(raw_reference<GraphicsLayer>)> displayApiVersion;
|
||||
};
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
#include <common/global.h>
|
||||
#include <gpu/violet/graphics_layer.h>
|
||||
namespace cosmic::gpu::violet {
|
||||
static void startVulkanLayer(raw_reference<VioletLayer> layer) {
|
||||
#include <gpu/graphics_layer.h>
|
||||
namespace cosmic::gpu {
|
||||
static void startVulkanLayer(raw_reference<GraphicsLayer> layer) {
|
||||
layer->app = vk::raii::Context(layer->hardware->vulkanInstanceAddr);
|
||||
layer->instance = createVulkanInstance(*layer->app);
|
||||
}
|
||||
static void displayVersion(raw_reference<VioletLayer> layer) {
|
||||
static void displayVersion(raw_reference<GraphicsLayer> layer) {
|
||||
#if !defined(NDEBUG)
|
||||
if (layer->graphicsApi == HardwareVulkan) {
|
||||
u32 version{layer->app->enumerateInstanceVersion()};
|
||||
@ -23,12 +23,12 @@ namespace cosmic::gpu::violet {
|
||||
return "OpenGLES";
|
||||
case RenderApi::HardwareVulkan:
|
||||
return "Vulkan Driver";
|
||||
case SoftwareSuperSlow:
|
||||
case SoftwareSlow:
|
||||
return "Software";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void VioletLayer::updateLayer() {
|
||||
void GraphicsLayer::updateLayer() {
|
||||
u32 functions{reloadReferences()};
|
||||
u8 openGl{graphicsApi == HardwareOpenGL && functions == 0x0};
|
||||
u8 vulkan{graphicsApi == HardwareVulkan && functions == 0x1};
|
||||
@ -39,18 +39,18 @@ namespace cosmic::gpu::violet {
|
||||
prepareGraphicsApi(*this);
|
||||
displayApiVersion(*this);
|
||||
}
|
||||
VioletLayer::VioletLayer(RenderApi renderMode) : graphicsApi(renderMode) {
|
||||
GraphicsLayer::GraphicsLayer(RenderApi renderMode) : graphicsApi(renderMode) {
|
||||
hardware = std::make_unique<RenderDriver>();
|
||||
hardware->pickUserRender(renderMode);
|
||||
|
||||
device->getStates()->customDriver.observer = [this]() {
|
||||
graphicsApi = violet::HardwareVulkan;
|
||||
graphicsApi = HardwareVulkan;
|
||||
hardware->pickUserRender(graphicsApi, true);
|
||||
updateLayer();
|
||||
};
|
||||
displayApiVersion = displayVersion;
|
||||
}
|
||||
u32 VioletLayer::reloadReferences() {
|
||||
u32 GraphicsLayer::reloadReferences() {
|
||||
u32 loaded{};
|
||||
if (graphicsApi == HardwareVulkan) {
|
||||
prepareGraphicsApi = startVulkanLayer;
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include <variant>
|
||||
|
||||
#include <gpu/violet/functions.h>
|
||||
#include <gpu/violet/renders.h>
|
||||
#include <gpu/functions.h>
|
||||
#include <gpu/renders.h>
|
||||
#include <gpu/render_driver.h>
|
||||
namespace cosmic::gpu::violet {
|
||||
class VioletLayer : public VioletFunctionsRef {
|
||||
namespace cosmic::gpu {
|
||||
class GraphicsLayer : public GraphicsFunctionsRef {
|
||||
public:
|
||||
VioletLayer(RenderApi renderMode);
|
||||
GraphicsLayer(RenderApi renderMode);
|
||||
std::variant<VkRender, Gl3Render> render;
|
||||
u32 reloadReferences();
|
||||
void updateLayer();
|
@ -5,17 +5,17 @@
|
||||
#include <common/except.h>
|
||||
#include <gpu/render_driver.h>
|
||||
namespace cosmic::gpu {
|
||||
void RenderDriver::pickUserRender(const violet::RenderApi api, bool reload) {
|
||||
void RenderDriver::pickUserRender(const RenderApi api, bool reload) {
|
||||
if (driver && !reload)
|
||||
return;
|
||||
switch (api) {
|
||||
case violet::HardwareVulkan:
|
||||
case HardwareVulkan:
|
||||
if (!loadVulkanDriver()) {
|
||||
throw GpuFail("No instance of the Vulkan driver was found");
|
||||
}
|
||||
break;
|
||||
case violet::SoftwareSuperSlow:
|
||||
case violet::HardwareOpenGL:
|
||||
case SoftwareSlow:
|
||||
case HardwareOpenGL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <common/types.h>
|
||||
#include <gpu/violet/renders.h>
|
||||
#include <gpu/renders.h>
|
||||
namespace cosmic::gpu {
|
||||
using LinkableObject = void*;
|
||||
class RenderDriver {
|
||||
@ -13,7 +13,7 @@ namespace cosmic::gpu {
|
||||
LinkableObject driver{};
|
||||
PFN_vkGetInstanceProcAddr vulkanInstanceAddr{};
|
||||
|
||||
void pickUserRender(const violet::RenderApi api, bool reload = false);
|
||||
void pickUserRender(const RenderApi api, bool reload = false);
|
||||
bool loadVulkanDriver();
|
||||
};
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
#include <EGL/egl.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include <common/types.h>
|
||||
namespace cosmic::gpu::violet {
|
||||
#include <gpu/vulcano/vram_allocator.h>
|
||||
namespace cosmic::gpu {
|
||||
enum RenderApi : u8 {
|
||||
SoftwareSlow,
|
||||
HardwareVulkan,
|
||||
@ -17,5 +16,6 @@ namespace cosmic::gpu::violet {
|
||||
struct VkRender {
|
||||
VkRender() {}
|
||||
std::optional<vk::raii::SurfaceKHR> surface;
|
||||
std::unique_ptr<vulcano::VramManager> allocator;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <jni.h>
|
||||
#include <common/types.h>
|
||||
namespace cosmic::gpu::violet {
|
||||
class VioletLayer;
|
||||
class VioletFunctionsRef {
|
||||
public:
|
||||
std::function<void(raw_reference<VioletLayer>, jobject)> setSurface;
|
||||
std::function<void(raw_reference<VioletLayer>)> prepareGraphicsApi;
|
||||
std::function<void(raw_reference<VioletLayer>)> displayApiVersion;
|
||||
};
|
||||
}
|
12
app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp
Normal file
12
app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <gpu/vulcano/vram_allocator.h>
|
||||
|
||||
namespace cosmic::gpu::vulcano {
|
||||
VramManager::VramManager(raw_reference<GraphicsLayer> gpu) : graphics(gpu) {
|
||||
VmaAllocatorCreateInfo allocatorInfo{};
|
||||
vmaCreateAllocator(&allocatorInfo, &vma);
|
||||
}
|
||||
VramManager::~VramManager() {
|
||||
if (vma != VK_NULL_HANDLE)
|
||||
vmaDestroyAllocator(vma);
|
||||
}
|
||||
}
|
15
app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h
Normal file
15
app/src/main/cpp/cosmic/gpu/vulcano/vram_allocator.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/types.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
namespace cosmic::gpu::vulcano {
|
||||
class GraphicsLayer;
|
||||
class VramManager {
|
||||
public:
|
||||
VramManager(raw_reference<GraphicsLayer> gpu);
|
||||
~VramManager();
|
||||
private:
|
||||
VmaAllocator vma{VK_NULL_HANDLE};
|
||||
raw_reference<GraphicsLayer> graphics;
|
||||
};
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include <range/v3/algorithm.hpp>
|
||||
#include <gpu/violet/graphics_layer.h>
|
||||
#include <gpu/graphics_layer.h>
|
||||
|
||||
namespace cosmic::gpu::violet {
|
||||
namespace cosmic::gpu::vulcano {
|
||||
vk::raii::Instance createVulkanInstance(const vk::raii::Context& context) {
|
||||
vk::ApplicationInfo application{
|
||||
.pApplicationName = "Cosmic",
|
||||
@ -14,7 +14,7 @@ namespace cosmic::gpu::violet {
|
||||
"VK_KHR_android_surface", // Provide a way to connect/refer a VkSurfaceKHR as a ANativeWindows
|
||||
};
|
||||
for (const auto required : requiredExtensions) {
|
||||
if (!ranges::any_of(extensions, [&](const auto& available){
|
||||
if (!ranges::any_of(extensions, [&](const auto& available) {
|
||||
return std::string_view(available.extensionName) == std::string_view(required);
|
||||
})) {
|
||||
throw GpuFail("Couldn't find a Vulkan extension with name {}", required);
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <eeiv/ee_fuji.h>
|
||||
namespace cosmic::eeiv::tokyo3 {
|
||||
class EEArm64Jitter : public EeExecutor {
|
||||
namespace cosmic::eeiv::tokyo {
|
||||
class EeArm64Jitter : public EeExecutor {
|
||||
public:
|
||||
EEArm64Jitter(EeMipsCore& intCpu) : EeExecutor(intCpu) {}
|
||||
EeArm64Jitter(EeMipsCore& intCpu) : EeExecutor(intCpu) {}
|
||||
u32 executeCode() override {
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user