mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 23:43:34 +00:00
yes
This commit is contained in:
132
Tests/xmake.lua
132
Tests/xmake.lua
@@ -1,58 +1,74 @@
|
||||
Backend = {
|
||||
local Backend = {
|
||||
VULKAN = 1,
|
||||
OPENGL = 2,
|
||||
OPENGL_ES = 3,
|
||||
}
|
||||
|
||||
local nzsl_included = false
|
||||
|
||||
function nzsl(backend)
|
||||
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
|
||||
add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } })
|
||||
if is_cross() then
|
||||
add_requires("nzsl~host", { kind = "binary", host = true })
|
||||
end
|
||||
-- Yoinked from NZSL xmake repo
|
||||
rule("find_nzsl")
|
||||
on_config(function(target)
|
||||
import("core.project.project")
|
||||
import("core.tool.toolchain")
|
||||
import("lib.detect.find_tool")
|
||||
local envs
|
||||
if is_plat("windows") then
|
||||
local msvc = target:toolchain("msvc")
|
||||
if msvc and msvc:check() then
|
||||
envs = msvc:runenvs()
|
||||
end
|
||||
elseif is_plat("mingw") then
|
||||
local mingw = target:toolchain("mingw")
|
||||
if mingw and mingw:check() then
|
||||
envs = mingw:runenvs()
|
||||
end
|
||||
end
|
||||
target:data_set("nzsl_envs", envs)
|
||||
local nzsl = project.required_package("nzsl~host") or project.required_package("nzsl")
|
||||
local nzsldir
|
||||
if nzsl then
|
||||
nzsldir = path.join(nzsl:installdir(), "bin")
|
||||
local osenvs = os.getenvs()
|
||||
envs = envs or {}
|
||||
for env, values in pairs(nzsl:get("envs")) do
|
||||
local flatval = path.joinenv(values)
|
||||
local oldenv = envs[env] or osenvs[env]
|
||||
if not oldenv or oldenv == "" then
|
||||
envs[env] = flatval
|
||||
elseif not oldenv:startswith(flatval) then
|
||||
envs[env] = flatval .. path.envsep() .. oldenv
|
||||
if not nzsl_included then
|
||||
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
|
||||
add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } })
|
||||
if is_cross() then
|
||||
add_requires("nzsl~host", { kind = "binary", host = true })
|
||||
end
|
||||
-- Yoinked from NZSL xmake repo
|
||||
rule("find_nzsl")
|
||||
on_config(function(target)
|
||||
import("core.project.project")
|
||||
import("core.tool.toolchain")
|
||||
import("lib.detect.find_tool")
|
||||
local envs
|
||||
if is_plat("windows") then
|
||||
local msvc = target:toolchain("msvc")
|
||||
if msvc and msvc:check() then
|
||||
envs = msvc:runenvs()
|
||||
end
|
||||
elseif is_plat("mingw") then
|
||||
local mingw = target:toolchain("mingw")
|
||||
if mingw and mingw:check() then
|
||||
envs = mingw:runenvs()
|
||||
end
|
||||
end
|
||||
end
|
||||
local nzsla = find_tool("nzsla", { version = true, paths = nzsldir, envs = envs })
|
||||
local nzslc = find_tool("nzslc", { version = true, paths = nzsldir, envs = envs })
|
||||
target:data_set("nzsla", nzsla)
|
||||
target:data_set("nzslc", nzslc)
|
||||
target:data_set("nzsl_runenv", envs)
|
||||
end)
|
||||
rule_end()
|
||||
rule("nzsl_compile_shaders")
|
||||
target:data_set("nzsl_envs", envs)
|
||||
local nzsl = project.required_package("nzsl~host") or project.required_package("nzsl")
|
||||
local nzsldir
|
||||
if nzsl then
|
||||
nzsldir = path.join(nzsl:installdir(), "bin")
|
||||
local osenvs = os.getenvs()
|
||||
envs = envs or {}
|
||||
for env, values in pairs(nzsl:get("envs")) do
|
||||
local flatval = path.joinenv(values)
|
||||
local oldenv = envs[env] or osenvs[env]
|
||||
if not oldenv or oldenv == "" then
|
||||
envs[env] = flatval
|
||||
elseif not oldenv:startswith(flatval) then
|
||||
envs[env] = flatval .. path.envsep() .. oldenv
|
||||
end
|
||||
end
|
||||
end
|
||||
local nzsla = find_tool("nzsla", { version = true, paths = nzsldir, envs = envs })
|
||||
local nzslc = find_tool("nzslc", { version = true, paths = nzsldir, envs = envs })
|
||||
target:data_set("nzsla", nzsla)
|
||||
target:data_set("nzslc", nzslc)
|
||||
target:data_set("nzsl_runenv", envs)
|
||||
end)
|
||||
rule_end()
|
||||
|
||||
nzsl_included = true
|
||||
end
|
||||
|
||||
local name = ""
|
||||
if backend == Backend.VULKAN then
|
||||
name = "vulkan"
|
||||
elseif backend == Backend.OPENGL_ES then
|
||||
name = "opengl_es"
|
||||
else
|
||||
name = "opengl"
|
||||
end
|
||||
|
||||
rule("nzsl_compile_shaders_" .. name)
|
||||
set_extensions(".nzsl")
|
||||
add_deps("find_nzsl")
|
||||
before_buildcmd_file(function(target, batchcmds, shaderfile, opt)
|
||||
@@ -64,7 +80,7 @@ function nzsl(backend)
|
||||
local argv = {}
|
||||
if backend == Backend.VULKAN then
|
||||
argv = { "--compile=spv-header", "--optimize" }
|
||||
elseif backend == Backend.OPENGL then
|
||||
elseif backend == Backend.OPENGL_ES then
|
||||
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-es", "--gl-bindingmap" }
|
||||
else
|
||||
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-bindingmap" }
|
||||
@@ -79,7 +95,13 @@ function nzsl(backend)
|
||||
end
|
||||
table.insert(argv, shaderfile)
|
||||
batchcmds:vrunv(nzslc.program, argv, { curdir = ".", envs = runenvs })
|
||||
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ".spv.h")
|
||||
local ext = ""
|
||||
if backend == Backend.VULKAN then
|
||||
ext = ".spv.h"
|
||||
else
|
||||
ext = ".glsl.h"
|
||||
end
|
||||
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ext)
|
||||
batchcmds:add_depfiles(shaderfile)
|
||||
batchcmds:add_depvalues(nzslc.version)
|
||||
batchcmds:set_depmtime(os.mtime(outputfile))
|
||||
@@ -95,7 +117,7 @@ local tests = {
|
||||
nzsl(Backend.VULKAN)
|
||||
end,
|
||||
custom = function()
|
||||
add_rules("nzsl_compile_shaders")
|
||||
add_rules("nzsl_compile_shaders_vulkan")
|
||||
add_packages("nzsl")
|
||||
add_files("**.nzsl")
|
||||
end
|
||||
@@ -103,10 +125,10 @@ local tests = {
|
||||
OpenGL = {
|
||||
option = "opengl",
|
||||
global_custom = function()
|
||||
nzsl(backend.OPENGL)
|
||||
nzsl(Backend.OPENGL)
|
||||
end,
|
||||
custom = function()
|
||||
add_rules("nzsl_compile_shaders")
|
||||
add_rules("nzsl_compile_shaders_opengl")
|
||||
add_packages("nzsl")
|
||||
add_files("**.nzsl")
|
||||
end
|
||||
@@ -114,10 +136,10 @@ local tests = {
|
||||
OpenGLES = {
|
||||
option = "opengl-es",
|
||||
global_custom = function()
|
||||
nzsl(Backend.OpenGLES)
|
||||
nzsl(Backend.OPENGL_ES)
|
||||
end,
|
||||
custom = function()
|
||||
add_rules("nzsl_compile_shaders")
|
||||
add_rules("nzsl_compile_shaders_opengl_es")
|
||||
add_packages("nzsl")
|
||||
add_files("**.nzsl")
|
||||
end
|
||||
@@ -161,7 +183,7 @@ for name, module in table.orderpairs(tests) do
|
||||
end
|
||||
|
||||
for name, module in pairs(tests) do
|
||||
if has_config(module.option) then
|
||||
if has_config(module.option .. "-tests") then
|
||||
if module.global_custom then
|
||||
module.global_custom()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user