add bgfx shader rules (#3109)

* update opencv

* update bgfx
pull/3111/head
Hoildkv 1 year ago committed by GitHub
parent 57b9e335df
commit a44046a94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 135
      packages/b/bgfx/rules/shaders.lua
  2. 3
      packages/b/bgfx/xmake.lua
  3. 2
      packages/o/opencv/xmake.lua

@ -0,0 +1,135 @@
-- Compile bgfx shader files. Substitution for scripts/shader.mk.
--
-- Usage:
--
-- add_rules("@bgfx/shaders")
-- add_files("shader.vert", {type = "vertex", output_dir = "shaders", output_name = "shader.vert.bin", profiles = {glsl = "330"}})
rule("shaders")
set_extensions(".vert", ".frag", ".comp")
on_buildcmd_file(function (target, batchcmds, shaderfile, opt)
import("lib.detect.find_program")
import("core.base.option")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.shaderc %s", shaderfile)
-- get bgfx shaderc
local shaderc = find_program("shadercRelease") or find_program("shadercDebug")
assert(shaderc, "bgfx shaderc not found! please check your bgfx installation.")
-- determine arguments for shaderc from fileconfig
local fileconfig = target:fileconfig(shaderfile)
local output_filename
if fileconfig and fileconfig.output_name then
output_filename = fileconfig.output_name
else
output_filename = path.filename(shaderfile) .. ".bin"
end
local output_dir
if fileconfig and fileconfig.output_dir then
output_dir = fileconfig.output_dir
else
output_dir = "shaders"
end
local vardef_filename
if fileconfig and fileconfig.vardef then
vardef_filename = fileconfig.vardef
else
vardef_filename = path.join(
path.directory(shaderfile),
path.basename(shaderfile) .. ".varying.def.sc")
end
local shader_type
if fileconfig and fileconfig.type then
if table.contains(bgfx_types, fileconfig.type) then
shader_type = fileconfig.type
else
raise("unsupported shader type " .. fileconfig.type)
end
elseif shaderfile:match("%.vert$") then
shader_type = "vertex"
elseif shaderfile:match("%.frag$") then
shader_type = "fragment"
elseif shaderfile:match("%.comp$") then
shader_type = "compute"
else
raise("cannot determine shader type from file name " .. path.filename(shaderfile))
end
-- determine platform-specific shaderc arguments
local bgfx_platforms = {
windows = "windows",
macosx = "osx",
linux = "linux"
}
local bgfx_types = {
"vertex",
"fragment",
"compute"
}
local bgfx_default_profiles = {
windows = {
vertex = {dx9 = "vs_3_0", dx11 = "vs_5_0", glsl = "120"},
fragment = {dx9 = "ps_3_0", dx11 = "ps_5_0", glsl = "120"},
compute = {dx11 = "cs_5_0", glsl = "430"},
},
macosx = {
vertex = {metal = "metal", glsl = "120"},
fragment = {metal = "metal", glsl = "120"},
compute = {metal = "metal", glsl = "430"}
},
linux = {
vertex = {glsl = "120", spirv = "spirv"},
fragment = {glsl = "120", spirv = "spirv"},
compute = {glsl = "430", spirv = "spirv"}
}
}
-- build command args
local args = {
"-f", shaderfile,
"--type", shader_type,
"--varyingdef", vardef_filename,
"--platform", bgfx_platforms[target:plat()],
}
for _, includedir in ipairs(target:get("includedirs")) do
table.insert(args, "-i")
table.insert(args, includedir)
end
local mtime = 0
local shader_profiles
if fileconfig and fileconfig.profiles then
shader_profiles = fileconfig.profiles
else
shader_profiles = bgfx_default_profiles[target:plat()][shader_type]
end
for folder, profile in pairs(shader_profiles) do
-- set output dir
local outputdir = path.join(target:targetdir(), output_dir, folder)
batchcmds:mkdir(outputdir)
local binary = path.join(outputdir, output_filename)
-- compiling
local real_args = {}
table.join2(real_args, args)
table.insert(real_args, "-o")
table.insert(real_args, binary)
table.insert(real_args, "--profile")
table.insert(real_args, profile)
if option.get("verbose") then
batchcmds:show(shaderc .. " " .. os.args(real_args))
end
batchcmds:vrunv(shaderc, real_args)
if (mtime == 0) then mtime = os.mtime(binary) end
end
-- add deps
batchcmds:add_depfiles(shaderfile)
batchcmds:set_depmtime(mtime)
end)

@ -7,11 +7,14 @@ package("bgfx")
add_urls("https://github.com/bkaradzic/bgfx.git")
add_versions("7816", "5ecddbf4d51e2dda2a56ae8cafef4810e3a45d87")
add_versions("8203", "484a5f0c25b53584a6b7fce0702a6bb580072d81")
add_versions("8674", "f42134876038027667ef7e47c9a612dca1051ef2")
add_resources("7816", "bx", "https://github.com/bkaradzic/bx.git", "51f25ba638b9cb35eb2ac078f842a4bed0746d56")
add_resources("8203", "bx", "https://github.com/bkaradzic/bx.git", "b9501348c596b68e5e655a8308df5c55f61ecd80")
add_resources("8674", "bx", "https://github.com/bkaradzic/bx.git", "67dfdf34f642a4a807b75eb600f82f4f04027963")
add_resources("7816", "bimg", "https://github.com/bkaradzic/bimg.git", "8355d36befc90c1db82fca8e54f38bfb7eeb3530")
add_resources("8203", "bimg", "https://github.com/bkaradzic/bimg.git", "663f724186e26caf46494e389ed82409106205fb")
add_resources("8674", "bimg", "https://github.com/bkaradzic/bimg.git", "964a5b85483cdf59a30dc006e9bd8bbdde6cb2be")
if is_plat("windows") then
add_syslinks("user32", "gdi32", "psapi")

@ -6,6 +6,7 @@ package("opencv")
add_urls("https://github.com/opencv/opencv/archive/$(version).tar.gz",
"https://github.com/opencv/opencv.git")
add_versions("4.9.0", "ddf76f9dffd322c7c3cb1f721d0887f62d747b82059342213138dc190f28bc6c")
add_versions("4.8.0", "cbf47ecc336d2bff36b0dcd7d6c179a9bb59e805136af6b9670ca944aef889bd")
add_versions("4.6.0", "1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277")
add_versions("4.5.5", "a1cfdcf6619387ca9e232687504da996aaa9f7b5689986b8331ec02cb61d28ad")
@ -16,6 +17,7 @@ package("opencv")
add_versions("4.2.0", "9ccb2192d7e8c03c58fee07051364d94ed7599363f3b0dce1c5e6cc11c1bb0ec")
add_versions("3.4.9", "b7ea364de7273cfb3b771a0d9c111b8b8dfb42ff2bcd2d84681902fb8f49892a")
add_resources("4.9.0", "opencv_contrib", "https://github.com/opencv/opencv_contrib/archive/4.9.0.tar.gz", "8952c45a73b75676c522dd574229f563e43c271ae1d5bbbd26f8e2b6bc1a4dae")
add_resources("4.8.0", "opencv_contrib", "https://github.com/opencv/opencv_contrib/archive/4.8.0.tar.gz", "b4aef0f25a22edcd7305df830fa926ca304ea9db65de6ccd02f6cfa5f3357dbb")
add_resources("4.6.0", "opencv_contrib", "https://github.com/opencv/opencv_contrib/archive/4.6.0.tar.gz", "1777d5fd2b59029cf537e5fd6f8aa68d707075822f90bde683fcde086f85f7a7")
add_resources("4.5.5", "opencv_contrib", "https://github.com/opencv/opencv_contrib/archive/4.5.5.tar.gz", "a97c2eaecf7a23c6dbd119a609c6d7fae903e5f9ff5f1fe678933e01c67a6c11")

Loading…
Cancel
Save