Last active
October 18, 2017 14:04
-
-
Save DrizztDoUrden/27b35e7268fb11598bf605b6a8eb5c1b to your computer and use it in GitHub Desktop.
MSBuild shader auto compile before build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<PropertyGroup> | |
<WindowsKitVersion Condition="$(WindowsKitVersion)==''">10</WindowsKitVersion> | |
<SaveAsm Condition="$(SaveAsm)==''">True</SaveAsm> | |
<ShadersSubDir Condition="'$(ShadersSubDir)'==''">$(OutputPath)\Shaders</ShadersSubDir> | |
<ShadersAsmSubDir Condition="'$(ShadersAsmSubDir)'==''">Shaders</ShadersAsmSubDir> | |
<ShaderModel Condition="$(ShaderModel)==''">5_1</ShaderModel> | |
<ShaderAsmExtension Condition="$(ShaderAsmExtension)==''">asm</ShaderAsmExtension> | |
<ShaderBinExtension Condition="$(ShaderBinExtension)==''">cso</ShaderBinExtension> | |
<FxcArgs Condition="'$(Configuration)'=='Debug'">$(FxcArgs) /Od /Zi</FxcArgs> | |
<FxcArgs Condition="'$(Configuration)'!='Debug'">$(FxcArgs) /O3</FxcArgs> | |
</PropertyGroup> | |
<PropertyGroup> | |
<WindowsKitsRoot Condition="$(WindowsKitsRoot)==''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot$(WindowsKitVersion)', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot> | |
<FxcPath>"$(WindowsKitsRoot)bin\x64\fxc.exe"</FxcPath> | |
</PropertyGroup> | |
<Target Name="CheckShaderCompilationDirectory"> | |
<MakeDir Condition="!Exists('$(ShadersSubDir)')" Directories="$(ShadersSubDir)" /> | |
<MakeDir Condition="!Exists('$(ShadersAsmSubDir)')" Directories="$(ShadersAsmSubDir)" /> | |
</Target> | |
<Target Name="CompileShaders" BeforeTargets="Build" DependsOnTargets="CheckShaderCompilationDirectory" | |
Inputs="@(CompileShader);%(CompileShader.Dependancies)" | |
Outputs="@(CompileShader -> '$(ShadersSubDir)\%(filename).%(Shader).$(ShaderBinExtension)');@(CompileShader -> '$(ShadersAsmSubDir)\%(filename).%(Shader).$(ShaderAsmExtension)')" > | |
<Exec WorkingDirectory="$(ProjectDir)" Condition="$(SaveAsm)=='True'" | |
Command="$(FxcPath) $(FxcArgs) "%(fullpath)" /T %(Shader)_$(ShaderModel) /E %(Entry) /Fo "$(ShadersSubDir)\%(filename).%(Shader).$(ShaderBinExtension)" %(CompileShader.Arguments) /Fc "$(ShadersAsmSubDir)\%(filename).%(Shader).$(ShaderAsmExtension)"" /> | |
<Exec WorkingDirectory="$(ProjectDir)" Condition="$(SaveAsm)!='True'" | |
Command="$(FxcPath) $(FxcArgs) "%(fullpath)" /T %(Shader)_$(ShaderModel) /E %(Entry) /Fo "$(ShadersSubDir)\%(filename).%(Shader).$(ShaderBinExtension)" %(CompileShader.Arguments)" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
<ItemGroup> | |
<CompileShader Include="shaders.hlsl" Visible="false"> | |
<Shader>vs</Shader> | |
<Entry>VSMain</Entry> | |
</CompileShader> | |
<CompileShader Include="shaders.hlsl" Visible="false"> | |
<Shader>ps</Shader> | |
<Entry>PSMain</Entry> | |
<Dependancies>include.hlsl</Dependancies> | |
</CompileShader> | |
</ItemGroup> | |
<PropertyGroup> | |
<FxcArgs>/nologo</FxcArgs> | |
<FxcArgs Condition="$(Configuration)!='Debug'">$(FxcArgs) /Od /Zi</FxcArgs> | |
</PropertyGroup> | |
<Import Project="CompileShaders.targets" /> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment