Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
Welcome to the general discussions!
  • Page:
  • 1
  • 2

TOPIC: Shader compilation using MSBuild

Shader compilation using MSBuild 1 year 9 months ago #355


  • Posts:426
  • artiom's Avatar
  • artiom
  • Moderator
  • OFFLINE
Hi everyone!
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:
  <UsingTask TaskName="MSBuild.Fxc.CompileShader" AssemblyFile="MSBuild.Fxc.dll" />
  <Target Name="BeforeBuild">
    <CompileShader InputFiles="@(Hlsl)" OutputPath="$(OutputPath)" />
  </Target>
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:
  <ItemGroup>
    <Hlsl Include="Shaders\Shader.fx" />
  </ItemGroup>
Task parameters:
• 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.

File Attachment:

File Name: ShaderCompileTask.ZIP
File Size: 45 KB


Feel free to use and modify at your taste.
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 9 months ago #356


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
Thanks for this contribution artiom, that could be useful! ;) Quite busy, but I will have a look at it soon.
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 9 months ago #357


  • Posts:56
  • Fadi's Avatar
  • Fadi
  • Senior Boarder
  • OFFLINE
Interesting, I'm working on something similar including shaders, 3D textures, D2D bitmaps, 3D models, audio files using MSBuild and VS Packages extensions.
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 9 months ago #358


  • Posts:426
  • artiom's Avatar
  • artiom
  • Moderator
  • OFFLINE
@Fadi, do you plan to implement something like XNA's content pipeline?

If needed - we can join our efforts, but I don't know how to send here an personal message to exchange contact information (don't want to post it in public to avoid spam). Any ideas?
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 9 months ago #359


  • Posts:56
  • Fadi's Avatar
  • Fadi
  • Senior Boarder
  • OFFLINE
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.

You can email me to this temporary mail : This email address is being protected from spambots. You need JavaScript enabled to view it. so we can exchange contact information.
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 9 months ago #360


  • Posts:426
  • artiom's Avatar
  • artiom
  • Moderator
  • OFFLINE
@Fadi, I have sent you an email.
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 7 months ago #747


  • Posts:5
  • flashed's Avatar
  • flashed
  • Fresh Boarder
  • OFFLINE
Hi,

Just found this post and would like to know if the project Fadi mentioned is being hosted anywhere.

Thank you
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 7 months ago #759


  • Posts:56
  • Fadi's Avatar
  • Fadi
  • Senior Boarder
  • OFFLINE
The project is just hosted at assets-builder google code
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 6 months ago #763


  • Posts:5
  • flashed's Avatar
  • flashed
  • Fresh Boarder
  • OFFLINE
Thank you
The administrator has disabled public write access.

Re: Shader compilation using MSBuild 1 year 5 months ago #1201

I've updated my csproj as suggested but when I try to change the build action I get "Property value is not valid". Has anyone else had this problem? This is Windows 8 App in VS2012.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.203 seconds