Export Visual Studio shader compile custom build rules to a text file

Started by
3 comments, last by Nypyren 6 years, 2 months ago

Currently, our framework only supports loading binary shader code. The way we do it in Visual Studio is through custom build tool per shader file. Now we also want to support shader recompilation when a user presses some key. This is tricky since now we don't have access to the source files. So I was thinking, if there is some way to export all the commands from the custom build tool to a text file, then we can just load that text file and execute all commands inside and then just do the regular shader loading as we do it right now.

Example custom build tool command for a shader which has vertex, pixel, and geometry shader stages:


fxc %(Identity) /E VSMain /T vs_5_0 $(HLSLCompileFlags) /Fo %(Identity)\..\Binary\%(Filename).vert.bin
fxc %(Identity) /E PSMain /T ps_5_0 $(HLSLCompileFlags) /Fo %(Identity)\..\Binary\%(Filename).frag.bin
fxc %(Identity) /E GSMain /T gs_5_0 $(HLSLCompileFlags) /Fo %(Identity)\..\Binary\%(Filename).geom.bin

So here is the process-

- Run custom build rules for the shader files

- In post-build event of the project, collect all these custom build tool commands and dump them to a text file

- Now if user wants to recompile, just load this text file and execute all commands inside

How would I get access to these custom build tool commands in the post-build event?

Advertisement

If your normal build process in Visual Studio invokes MSBuild (by default it should), then look in the options for the output verbosity (Tools/Options/Projects and Solutions/Build and Run/MSBuild project build output verbosity) and crank it all the way up (Diagnostic).  Then do whatever you normally do which invokes the custom tool and see if the command line options for the tool show up in the build output window.

In VS2017 I also see an option to do that for a build log file.  You could potentially write a command line tool which parses the log file, then run that tool for your 'when a user presses a key' case.

I've only used this for UWP packaging automation, but it might work in your case as well.

Thats a good idea. But does it crank up the verbosity only on my local machine or it is actually changing project settings?

Edit:

The .tlog folder has all the custom build commands stored in the custombuild.command.1.tlog file. This makes it straightforward.

Thanks for the help

I think it changes it for your local user settings, so the change won't affect other people on the team.  That could be good or bad depending on whether you want everyone to use the whole verbose-logging process or if you plan to distribute the resulting log after you capture it.

This topic is closed to new replies.

Advertisement