Smart gpu selection system
This commit is contained in:
parent
872775d9e4
commit
3b89f0b59c
@ -8,6 +8,7 @@ extern char lua_eeprom[];
|
||||
extern char lua_fbgpu[];
|
||||
extern char lua_filesystem[];
|
||||
extern char lua_gpio[];
|
||||
extern char lua_gpudetect[];
|
||||
extern char lua_init[];
|
||||
extern char lua_internet[];
|
||||
extern char lua_sandbox[];
|
||||
|
@ -20,7 +20,7 @@ typedef unsigned short ushort;
|
||||
|
||||
lua_State* getL();
|
||||
|
||||
void run_init();
|
||||
void run_init(int argc, char **argv);
|
||||
void lupi_init();
|
||||
void luanative_start(lua_State *L);
|
||||
void fb_start(lua_State *L);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef RES_H
|
||||
#define RES_H
|
||||
extern char res_eepromDefault[];
|
||||
extern char res_help[];
|
||||
extern char res_unifont[];
|
||||
#endif
|
||||
|
5
resources/help
Normal file
5
resources/help
Normal file
@ -0,0 +1,5 @@
|
||||
Usage: lupi [options]
|
||||
|
||||
-h, --help This help
|
||||
-f, --fb Force framebuffer rendering
|
||||
-t, --text Force text mode rendering
|
@ -429,6 +429,19 @@ static int l_platform (lua_State *L) { /* returns platform identifiers separated
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_isinit (lua_State *L) {
|
||||
#ifndef _WIN32
|
||||
lua_pushboolean(L, 0);
|
||||
#else
|
||||
if(getpid() == 1) {
|
||||
lua_pushboolean(L, 1);
|
||||
} else {
|
||||
lua_pushboolean(L, 0);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static int l_debug (lua_State *L) {
|
||||
return 0;
|
||||
@ -464,6 +477,7 @@ void luanative_start(lua_State *L) {
|
||||
{"freeMemory", l_freeMemory},
|
||||
{"pull", l_pull},
|
||||
{"platform", l_platform},
|
||||
{"isinit", l_isinit},
|
||||
#ifdef DEBUG
|
||||
{"debug", l_debug},
|
||||
#endif
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include "lupi.h"
|
||||
|
||||
int main (void) {
|
||||
int main (int argc, char **argv) {
|
||||
puts("LuPI L0 INIT");
|
||||
lupi_init();
|
||||
run_init();
|
||||
run_init(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
void setup_modules(lua_State *L) {
|
||||
lua_createtable (L, 0, 1);
|
||||
lua_createtable (L, 0, 32);
|
||||
|
||||
pushstuple(L, "boot", lua_boot);
|
||||
pushstuple(L, "color", lua_util_color);
|
||||
@ -17,6 +17,7 @@ void setup_modules(lua_State *L) {
|
||||
pushstuple(L, "eeprom", lua_eeprom);
|
||||
pushstuple(L, "filesystem", lua_filesystem);
|
||||
pushstuple(L, "gpio", lua_gpio);
|
||||
pushstuple(L, "gpudetect", lua_gpudetect);
|
||||
pushstuple(L, "internet", lua_internet);
|
||||
pushstuple(L, "sandbox", lua_sandbox);
|
||||
pushstuple(L, "textgpu", lua_textgpu);
|
||||
@ -26,6 +27,7 @@ void setup_modules(lua_State *L) {
|
||||
pushstuple(L, "buffer", lua_util_buffer);
|
||||
|
||||
pushstuple(L, "eepromDefault", res_eepromDefault);
|
||||
pushstuple(L, "help", res_help);
|
||||
|
||||
lua_setglobal(L, "moduleCode");
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ lua_State* getL() {
|
||||
return L;
|
||||
}
|
||||
|
||||
void run_init() {
|
||||
void run_init(int argc, char **argv) {
|
||||
L = luaL_newstate();
|
||||
|
||||
luaL_openlibs (L);
|
||||
@ -36,6 +36,9 @@ void run_init() {
|
||||
fprintf(stderr, "Couldn't load init: %s\n", lua_tostring(L, -1));
|
||||
exit(1);
|
||||
}
|
||||
lua_call(L, 0, 0);
|
||||
for(int i = 0; i < argc; i++) {
|
||||
lua_pushstring(L, argv[i]);
|
||||
}
|
||||
lua_call(L, argc, 0);
|
||||
lua_close(L);
|
||||
}
|
||||
|
37
src/lua/core/gpudetect.lua
Normal file
37
src/lua/core/gpudetect.lua
Normal file
@ -0,0 +1,37 @@
|
||||
local gpudetect = {}
|
||||
|
||||
local function tryText()
|
||||
loadModule("textgpu")
|
||||
local textgpuAddr, tgfail = modules.textgpu.start()
|
||||
if not textgpuAddr then
|
||||
lprint("Couldn't initialize text gpu: " .. tostring(tgfail))
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function tryFb()
|
||||
if framebuffer.isReady() then
|
||||
loadModule("fbgpu")
|
||||
modules.fbgpu.start()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function gpudetect.run()
|
||||
local s = false
|
||||
if hasOpt("-t", "--text") then
|
||||
s = tryText()
|
||||
return
|
||||
end
|
||||
if hasOpt("-f", "--fb") or native.isinit() then
|
||||
s = tryFb()
|
||||
end
|
||||
if not s then
|
||||
lprint("Falling back to text gpu")
|
||||
s = tryText()
|
||||
end
|
||||
end
|
||||
|
||||
return gpudetect
|
@ -15,6 +15,27 @@ function checkArg(n, have, ...)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local argv = {...}
|
||||
function hasOpt(o, n, ...)
|
||||
for _, v in pairs(argv) do
|
||||
if v == o then
|
||||
return true
|
||||
end
|
||||
end
|
||||
if n then
|
||||
return hasOpt(n, ...)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
if hasOpt("-h", "--help") then
|
||||
print(moduleCode.help)
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
math.randomseed(native.uptime())--TODO: Make it better?
|
||||
|
||||
lprint = function (...)
|
||||
@ -26,7 +47,10 @@ lprint("LuPI L1 INIT")
|
||||
modules = {}
|
||||
deadhooks = {}
|
||||
|
||||
local function loadModule(name)
|
||||
function loadModule(name)
|
||||
if modules[name] then
|
||||
return
|
||||
end
|
||||
lprint("LuPI L1 INIT > Load module > " .. name)
|
||||
io.flush()
|
||||
--TODO: PRERELEASE: Module sandboxing, preferably secure-ish
|
||||
@ -63,11 +87,7 @@ function main()
|
||||
loadModule("eeprom")
|
||||
loadModule("gpio")
|
||||
|
||||
if framebuffer.isReady() then
|
||||
loadModule("fbgpu")
|
||||
else
|
||||
loadModule("textgpu")
|
||||
end
|
||||
loadModule("gpudetect")
|
||||
loadModule("filesystem")
|
||||
loadModule("internet")
|
||||
|
||||
@ -89,14 +109,7 @@ function main()
|
||||
end
|
||||
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
|
||||
|
||||
if framebuffer.isReady() then
|
||||
modules.fbgpu.start()
|
||||
else
|
||||
local textgpuAddr, tgfail = modules.textgpu.start()
|
||||
if not textgpuAddr then
|
||||
lprint("Couldn't initialize text gpu: " .. tostring(tgfail))
|
||||
end
|
||||
end
|
||||
modules.gpudetect.run()
|
||||
|
||||
if native.debug then
|
||||
modules.debug.hook()
|
||||
|
Loading…
Reference in New Issue
Block a user