archive_shaders.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Merge binary shaders to archivess
  2. rule("archive.shaders")
  3. set_extensions(".nzsla")
  4. add_deps("@nzsl/find_nzsl")
  5. if add_orders then
  6. add_deps("@nzsl/compile.shaders")
  7. add_orders("@nzsl/compile.shaders", "@nzsl/archive.shaders")
  8. else
  9. add_deps("@nzsl/compile.shaders", { order = true })
  10. end
  11. before_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  12. local nzsla = target:data("nzsla")
  13. local runenvs = target:data("nzsl_runenv")
  14. assert(nzsla, "nzsla not found! please install nzsl package with nzsla enabled")
  15. local fileconfig = target:fileconfig(sourcefile)
  16. batchcmds:show_progress(opt.progress, "${color.build.object}archiving.shaders %s", sourcefile)
  17. local argv = { "--archive" }
  18. if fileconfig.compress then
  19. if type(fileconfig.compress) == "string" then
  20. table.insert(argv, "--compress=" .. fileconfig.compress)
  21. else
  22. table.insert(argv, "--compress")
  23. end
  24. end
  25. local outputfile = sourcefile
  26. if fileconfig.header then
  27. table.insert(argv, "--header")
  28. if type(fileconfig.header) == "string" then
  29. outputfile = outputfile .. fileconfig.header
  30. end
  31. end
  32. table.insert(argv, "--output=" .. outputfile)
  33. for _, shaderfile in ipairs(fileconfig.files) do
  34. table.insert(argv, shaderfile)
  35. batchcmds:add_depfiles(shaderfile)
  36. end
  37. batchcmds:vrunv(nzsla.program, argv, { curdir = ".", envs = runenvs })
  38. -- add deps
  39. batchcmds:add_depvalues(nzsla.version)
  40. batchcmds:set_depmtime(os.mtime(outputfile))
  41. batchcmds:set_depcache(target:dependfile(sourcefile))
  42. end)