Jump to content
  • Advertisement
Sign in to follow this  
Meltac

Pixel shader compiling issue - Windows 10 specific !?

This topic is 517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all

I'm facing some weird problems with some game's HLSL shaders, on Windows 10 exclusively.

The shaders are compiled against DX 11 / shader model 5. In case it matters, they still use the old fashioned DX9 methods tex2D etc. for sampling because they initially had been written for DX9 / shader model 3 and later been migrated with least possible effort.

There are different variations of pixel shaders that the game engine applies depending on in-game weather (ie. one pixel shader for dry weather, a different one for rain etc.). As those variations share large parts of the same code, those code parts are being referenced as #include directives, and the differences have been implemented as #define and #undef directives (e.g. rain shader defines a part for rendering the ground as wet, dry shader does not).

The game engine compiles all source shader files upon start-up, one by one, in a predefined (hard-coded) order, using the usual D3D commands.

NOW:

  • On my Vista 64bit environment, the D3D compiler seems to figure out which included shader source files are being used anywhere (ie. in at least one of the pixel shader variants), and compiles all used includes.
     
  • On my Windows 10 64bit environment, things behave differently: If the compiler encounters some include not being used in the first compiled shader file, it DOES NOT COMPILE that include file REGARDLESS it being used in subsequent file to compile !!!

Pseudo code sample:

// Pixel shader for dry weather (= first file being compiled)

#include "SomeSettingsFile.h"

#include "GenericShaderForAllWeatherTypes.h"
// Pixel shader for rainy weather (= second file being compiled)

#include "SomeSettingsFile.h"

#define IT_RAINS

#include "GenericShaderForAllWeatherTypes.h"
// GenericShaderForAllWeatherTypes.h

[...]

#ifdef IT_RAINS

#include "RainShader.h"
render_things_as_wet();

#endif

[...]

On Vista this works as expected: Source file "RainShader.h" is always being compiled an thus available on runtime.

On Windows 10 is does not: "RainShader.h" and the code segment starting with #ifdef IT_RAINS will be omitted / "optimized away" by the compiler because the first shader being compiled does not use it!!!

Any ideas???

Edited by Meltac

Share this post


Link to post
Share on other sites
Advertisement

So I'm guessing you're linking against d3dcompiler_47.dll using the import libs from the Windows SDK? There's actually multiple versions of that DLL in the wild: they've updated it multiple times alongside Windows SDK releases, but kept the same filename. If you're linking against that and loading whatever version the OS has installed in C:\Windows\System32, you'll end up loading different versions of the DLL depending on which OS version you're running on. If you want to ensure that you always use the same compiler version, you should include the the DLL alongside your executable (or alternatively, pre-compile your shaders).

That said, I'm not sure why this behavior would be different between compiler versions. It's very possible that a bug (or different behavior) was introduced somewhere along the way.

Share this post


Link to post
Share on other sites

So I'm guessing you're linking against d3dcompiler_47.dll using the import libs from the Windows SDK? There's actually multiple versions of that DLL in the wild

 

Thanks for your answer. I am using a copy of the compiler DLL inside my bin directory, so compiler-wise the file should be the same (sorry I should mentioned that in the first place). So I suspect it must be another D3D / DX file that makes the difference, perhaps some DLL that the compiler uses. Any ideas how I could figure that out?

Share this post


Link to post
Share on other sites
So I suspect it must be another D3D / DX file that makes the difference, perhaps some DLL that the compiler uses. Any ideas how I could figure that out?

You can watch loaded dlls into process in Process Explorer ( https://technet.microsoft.com/en-us/sysinternals/bb795533.aspx )

Just press Ctrl+L on selected process and it will show all them in a tab:

oA2drxJ.png

Edited by Happy SDE

Share this post


Link to post
Share on other sites

Alright, I've compared *all* DX / D3D files in SysWOW64 from both my Vista and my W10 installation (using a Diff tool, binary content comparison) and then copied all files that were different from Vista to Win10 (DirectX 9 to 11 files, 12 was not present on Vista).

Before I had double-checked that these files are actually being used by the engine by renaming then and getting startup errors accordingly.

So now all DirectX files being used should be binary-wise identical on both installations, Vista an W10, no matter if they come from the OS or from the game installation folder.

But the behavior is still absolutely the same !?? The compiler still does not behave as in Vista, omitting the same code parts as before!

 

Any further thoughts !?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!