Jump to content
  • Advertisement
mark_braga

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

Recommended Posts

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?

Edited by mark_braga

Share this post


Link to post
Share on other sites
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.

Edited by Nypyren

Share this post


Link to post
Share on other sites

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

Edited by mark_braga

Share this post


Link to post
Share on other sites

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.

Edited by Nypyren

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!