I'm struggling to figure out how to set up my hlsl shaders to work with Premake5 and Visual Studio 2017.
I have no idea how to tell Premake5 to compile my hlsl shaders, as a pre-build step.
Here are my goals for this pre-build step:
- Specify shader model
- Specify debug/release compilation
- Only compile files that have changed
- Produce dxasm files
- Place resulting *.asms and *.cso in appropriate release/debug folders
Update 1: Investigating a little further I found that Premake5 has buildaction which makes direct reference to FxCompile.
Update 2: Thanks to mukunda. I was able to configure my project perfectly! I had to build premake5 from source in order to get this premake script to run.
Because as of March, 2019 the binary distributed doesn't support shader model greater than 5.
hf.deactivate_filter()
files(src_dir.."shaders/*.hlsl")
shadermodel("6.3")
shaderassembler("AssemblyCode")
local shader_dir = _WORKING_DIR.."/"..src_dir.."shaders/%{cfg.buildcfg}/"
-- HLSL files that don't end with 'Extensions' will be ignored as they will be
-- used as includes
filter("files:**.hlsl")
flags("ExcludeFromBuild")
shaderobjectfileoutput(shader_dir.."%{file.basename}"..".cso")
shaderassembleroutput(shader_dir.."%{file.basename}"..".asm")
filter("files:**_ps.hlsl")
removeflags("ExcludeFromBuild")
shadertype("Pixel")
filter("files:**_vs.hlsl")
removeflags("ExcludeFromBuild")
shadertype("Vertex")
hf.deactivate_filter()
-- Warnings as errors
shaderoptions({"/WX"})
Update 3: I figured out how to handle command line parameters.