Search code examples
visual-studiovisual-studio-2017direct2d

Disable built-in HLSL Compiler in Visual Studio 2017?


I am trying to get custom effects in Direct2D working in my c++ project which is included in an c#/XAML solution. I have been trying to adapt the CustomPixelShader project from the D2DCustomEffects solution from the Windows-universal-samples git repo.

My problem (I think) is that they are configuring a Custom build step in the project solution to get fxc to compile the shader. When I have tried to mimic their configuration, I have noticed that in my project property pages I have an additional property - HLSL compiler - that is not present in the CustomPixelShader example project (see image).

enter image description here

When I try to build the project without trying to configure HLSL Compiler, I get the error

Error   X1507   failed to open source file: 'd2d1effecthelpers.hlsli'

which is a file that is clearly indicated in the custom effects example as important for the shader compilation. The path to d2d1effecthelpers.hlsli is included in the Custom build step config and I have checked that the file is there. However, if I add the path to d2d1effecthelpers.hlsli to Additional include directories in the HLSL Compiler config, that error message disappears but I get other problems instead. I’m interpreting this as if the HLSL compiler tries to compile the shader, even though I really want to use a Custom build step to do that instead.

My questions are: is it possible to disable the Visual Studio HLSL compiler in any way? I have noticed that if I exclude any shader files from the project the HLSL compiler disappears from the project property page, but how to do that manually?

Alternatively, is there any documentation on the Visual Studio built-in HLSL Compiler anywhere? I haven't really found any. I have tried but failed to get the HLSL Compiler to build according to the same rules as the Custom build step from the example.

I’m using Visual Studio Community 2017 v 15.3.5.


Solution

  • I got the answer in another forum (link to answer).

    Summary: right click on the .hlsl-file in the solution explorer in Visual Studio. That will result in showing the properties for that file. Under Configuration Properties -> General you can change Item Type to something other than "HLSL Compiler". Changing it to "Text" worked for me, "Does not participate in build" was suggested in the answer in the other forum. If that does not do the trick, changing the value for Exclude from build to "No" could work. For me, just changing the Item type of the .hlsl-file was enough.

    This should result in the HLSL Compiler disappearing from the project property pages (see the image in the question), and the HLSL Compiler will not try to compile the .hlsl-file.