Here is a simple MSBuild task to automate shader compilation, as specifying an pre-build event for each shader file separately can be cumbersome in large projects.
Next is the original "readme" for this component (included as a docx file in attachment):
Shader compilation MSBuild task Warning: was built and tested only on Windows 8 Release Preview using Visual Studio 2012 RC Warning: this solution involves manual editing of project file, make sure you have an backup before doing anything! Nothing is guaranteed, use it at your own risk. General description:
Can be included in project to automate DirectX shader build and deployment tasks.
One shader file can be compiled only once using this method. It is not suitable if several compilations are needed for same source file. Project configuration:
Edit manually the "*.csproj" file and add at end the following code:
The file "MSBuild.Fxc.dll" should be placed in same folder as "csproj" file.
Notice the keyword "Hlsl" in InputFiles attribute: this should be the "Build Action" for shader files in project. To do this, select the shader source file in Solution Explorer and open its properties (Alt+Enter or F4), then in "Build Action" property write the needed value (it can be any identifier). Several tasks with different input files can be used in one project. The file declaration in "csproj" file should look like this:
• InputFiles - [Required]: Input shader files for compilation.
• OutputPath - [Required]: Project build output path where compiled shaders are copied. Relative paths are preserved (for example if input file is "Shaders\MyShader.ps" then output file will be at "bin\Debug\Shaders\MyShader.pso").
• FxcPath - [Optional]: Path to "fxc.exe" executable. Default value is " C:\Program Files (x86)\Windows Kits\8.0\bin\x86\fxc.exe".
• EntryMethod - [Optional]: Entry method of shader unit. Default value is "main".
• Profile - [Optional]: Shader profile for compilation. Should include only version string, for example "4_1" is correct but "ps_4_1" is incorrect. Remarks:
Shader type is inferred from file extension, for example "MyShader.ps" will be compiled as pixel shader, but "MyShader.vs" will be compiled as vertex shader. "hlsl" extension is not supported.
If shader profile is embedded in filename - it will be used, otherwise will be used the value provided in parameter "Profile". If no value is provided - an default will be used ("4_0_level_9_3" for pixel and vertex shaders, and the smallest possible for others).
For example, the file "MyShader_4_1.ps" will be compiled with profile "ps_4_1", the file "Compute5_0.cs" will be compiled with profile "cs_5_0".
All compiled files are outputted with name "<source file>o" (the letter "o" is added at end of filename). For example the file "MyShader.vs" will be compiled as "MyShader.vso". Potential issues:
• For compute shader, the extension "cs" will conflict with ".cs" extensions for C# code.
• If shader profile version is not included in file, then for each version should be used a different msbuild task.
• To avoid manual editing for each project, the task DLL can be installed in GAC and task inclusion code can be added to some common "props" or "targets" file, but this will reduce solution portability.
I'll be glad to...
Actually, it is great if such a project is maintained by a team.
Right now, I'm using it in my first SharpDX project. and here is some features:
- VS Document template to manage game assets.
- Auto inject MSBuild task into the project file when creating new assets document, so we can build assets as a part of the VS project.
- Game assets are managed using visual designer within VS and saved as XML Asset Document.
- Strong typed autogenerated c# classes reflects the assets contained in the xml asset document using C# T4 template.
- Within the asset document, you can add, resize, reformat and mimap textures. also you can compose array texture, volume texture and cube texture.
- Also, you can add Audio files either as SoundFX or music (Streaming).
- Shaders also can be included and compiled with minor editing capability.
- Bitmaps (Simple textures) which can be loaded as Direct2D Bitmaps.
- all assets can be organized into groups so they can be loaded and disposed together.
I'm using this features, but I have a long TODO and bugs list, mostly regarding user interface and VS integration.
Also I wrote a fully managed Collada importer to import a complete 3D scene along with its animation but it is not integrated into the project yet.
Don't get the impression that the project is complete, there is a lot of enhancements, missing features, bugs fixing and testing to be done, and I'll be glad to join our efforts.
The administrator has disabled public write access.
Re: Shader compilation using MSBuild
2 years 4 months ago #360