18

I've been playing around with Direct3D 11 a little bit lately and have been frustrated by the lack of documentation on the basics of the API (such as simple geometry rendering). One of the points of confusion brought on by the sparse documentation is the (apparent) move away from the use of effects for shaders.

In D3D11 all of the effect (.fx) support has been removed from the D3DX libraries and buried away in a hard to find (sparsely documented, of course) shared source library. None of the included examples use it, preferring instead to compile HLSL files directly. All of this says to me that Microsoft is trying to get people to stop using the effect file format. Is that true? Is there any documentation of any kind that states that? I'm fine doing it either way, but for years now they've been promoting the .fx format so it seems odd that they would suddenly decide to drop it.

skaffman
  • 381,978
  • 94
  • 789
  • 754
Toji
  • 31,923
  • 20
  • 95
  • 113
  • I couldn't agree more. [ID3DX11Effect](http://msdn.microsoft.com/en-us/library/ff476652(VS.85).aspx) is not referenced at all in the samples (except the sample that provides ID3DX11Effect), and even that just builds a .lib file. Because its so difficult to get at, it seems to discourage people from using it. – bobobobo Sep 23 '11 at 16:49

5 Answers5

5

Many professional game and graphics developers don't use the effects interfaces in Direct3D, and many of the leading game engines do not use them either. Instead, custom material/effects subsystems are built on top of the lower-level shader and graphics state state management facilities. This allows developers to do things like target both Direct3D and OpenGL through a common asset management pipeline.

Jesse
  • 59
  • 1
  • 1
4

I'm in the exact same position, and after Googling like crazy for even the simplest sample that uses D3DX11CreateEffectFromMemory, I've too come to the conclusion that .fx file support isn't their highest prio. Although it is strange that they've added the EffectGroup concept, which is new to 11, if they don't want us to use it.

I've played a little with the new reflection API, so it looks like it will be pretty easy to hack together your own functions for setting variables etc, in essence creating your own Effect-class, and the next step is going to be to see what support their is for creating render state blocks via the API. Being able to edit those directly in the .fx file was very nice, so hopefully something like that still exists (or, at worst, I can rip that part from the Effect11 code).

Magnus Österlind
  • 1,270
  • 1
  • 12
  • 12
  • What I settled on in the end was a helper class that used the reflection API to parse the vs/ps parameters, and had methods like set_variable(name, value) to set the values (they actually mapped the cbuffer if needed, and updated the memory directly). I also implemented a system where I would get a callback if the file on disk changed, so I could dynamically reload shaders. For depth-stencil-states etc, I ended up using these helper functions: http://legalizeadulthood.wordpress.com/2009/07/12/description-helpers-for-direct3d-10-10-1-and-11/ – Magnus Österlind May 28 '10 at 08:21
4

The main issue is that the fx_5_0 profile which is needed to compile Effects 11 shaders with the required metadata is deprecated by the HLSL compiler team. The runtime is shared-source, but the compiler is not. In the latest D3DCompiler (#47) it emits a warning about this. fx_5_0 was never updated for some newer language aspects in DirectX 11.1 and 11.2, but works "as is" for Direct3D 11.

The second issue is that you need D3DCompile APIs at runtime to make use of Effects 11. Since D3DCompile was 'development only' for Windows Store apps for Windows 8.0 and Windows phone 8.0, it wasn't an option there. It is technically possible to use Effects 11 today with Windows Store apps for Windows 8.1 and Windows phone 8.1 since D3DCompile #47 is part of the OS and includes the 'deprecated/as-is' compiler support for fx_5_0, but this use is not encouraged.

The bulk of the DirectX SDK samples and all the Windows Store samples avoid use of Effects 11. I did post a few Win32 desktop samples that use it to GitHub.

So in short, yes you are discouraged from using it but you still can at the moment if you can live with the disclaimers.

Chuck Walbourn
  • 28,931
  • 1
  • 45
  • 72
1

There is an effect runtime provided as a sample in the DirectX SDK that should be able to help you to use .fx files. Check out the directory: %DXSDK_DIR%\Samples\C++\Effects11

Laserallan
  • 10,434
  • 9
  • 39
  • 63
0

http://msdn.microsoft.com/en-us/library/ff476261(v=VS.85).aspx

This suggests that it can take a shader or an effect.

http://msdn.microsoft.com/en-us/library/ff476190(v=VS.85).aspx

Also, what is the difference between a shader and an effect?

Puppy
  • 138,897
  • 33
  • 232
  • 446
  • Nah, CompileFromFile only works with shaders, as it requires a function name passed as the pFunctionName parameter, and effects don't have functions in the same way. The difference between a shader and an effect is that an effect can be seen as a container, that holds render state settings (and other metadata) along with multiple shaders, while a shader is just a single vertex or pixel shader. – Magnus Österlind Apr 08 '10 at 15:11