0

I am applying a rule to *.hlsl files that compiles the files with the fxc tool.

rule("shadercompile.fxc")
    set_extensions(".hlsl")
    on_load(function (target)
        local headerdir = path.join(target:autogendir(), "include")
        if not os.isdir(headerdir) then
            os.mkdir(headerdir)
        end
        target:add("includedirs", headerdir,{public = true})
    end)

    before_buildcmd_file(function (target, batchcmds, sourcefile_bin, opt)
        local config = target:fileconfig(sourcefile_bin)
        local directory = config.shadercompile_directory
        local entry = config.shadercompile_fxc_entry
        local profile = config.shadercompile_fxc_profile
        -- get header file
        local headerdir = path.join(target:autogendir(), "include")
        local shaderdir = path.join(headerdir,"shaders",directory)
        local shaderfile = sourcefile_bin
        local shaderfilename = path.filename(shaderfile)
        local bytecodefile = path.join(shaderdir, shaderfilename:gsub("hlsl","dxbc") .. "")
        local headerfile = path.join(shaderdir, shaderfilename:gsub("%.hlsl",""):gsub("%.","_") .. ".h")

        -- add commands
        batchcmds:show_progress(opt.progress, "${color.build.object}generating.fxc Shader file: %s", shaderfile)
        batchcmds:show_progress(opt.progress, "${color.build.object}generating.fxc Shader bytecode file: %s", bytecodefile)
        batchcmds:show_progress(opt.progress, "${color.build.object}generating.fxc Shader profile: %s", profile)
        batchcmds:show_progress(opt.progress, "${color.build.object}generating.fxc Shader header file: %s", headerfile)
        batchcmds:mkdir(shaderdir)
        local compileargs = {"/T",profile ,"/E" ,entry ,"/WX" ,"/Zi" ,"/Zss" ,"/Ges" ,"/Gis" ,"/Od","/nologo","/Fo" ,bytecodefile , sourcefile_bin}
        batchcmds:vrunv("fxc", compileargs)
        

        -- add deps
        batchcmds:add_depfiles(sourcefile_bin)
        batchcmds:set_depmtime(os.mtime(headerfile))
        batchcmds:set_depcache(target:dependfile(headerfile))
    end)
rule_end()
add_files("shader/d3d11/*/*.vertex.hlsl", {rule = "shadercompile.fxc", shadercompile_fxc_entry = "main", shadercompile_fxc_profile = "vs_5_0", shadercompile_directory ="d3d11" })
add_files("shader/d3d11/*/*.pixel.hlsl", {rule = "shadercompile.fxc", shadercompile_fxc_entry = "main", shadercompile_fxc_profile = "ps_5_0", shadercompile_directory ="d3d11" })
    

this works, it generates dxbc files.

I want to embed these dxbc files with the bin2c rule into my executable.

How can I achieve this?

Raildex
  • 3,406
  • 1
  • 18
  • 42

0 Answers0