Direct3D 11 effect files deprecated?
Asked Answered
L

5

19

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.

Liquor answered 28/2, 2010 at 20:21 Comment(1)
I couldn't agree more. ID3DX11Effect 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.Murmuration
L
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).

Lamarlamarck answered 5/3, 2010 at 7:30 Comment(1)
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: legalizeadulthood.wordpress.com/2009/07/12/…Preposition
E
6

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.

Edris answered 21/8, 2010 at 5:3 Comment(1)
IMO this has nothing to do with the topic hereCanterbury
V
5

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.

UPDATE: With the release of the legacy Microsoft.DXSDK.D3DX NuGet repacking of the original D3DX #43, I was able to update the rest of the legacy DirectX SDK samples so they can build with the modern Windows SDK and not require the legacy DirectX SDK to be installed. Most of the Direct3D 9 and Direct3D 10 samples, and a few Direct3D 11 samples, all use legacy Effects. See 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.

Varnish answered 8/7, 2014 at 22:57 Comment(2)
So what do you use instead of fx_5_0?Hoebart
You don't use Effects at all. You build all the permutations and shader stages directly as vs_5_0, ps_5_0, etc.Varnish
L
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).

Lamarlamarck answered 5/3, 2010 at 7:30 Comment(1)
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: legalizeadulthood.wordpress.com/2009/07/12/…Preposition
A
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

Augustusaugy answered 6/7, 2012 at 17:46 Comment(1)
The latest Effects 11 is hosted on CodePlex.Varnish
W
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?

Watkin answered 3/4, 2010 at 11:18 Comment(1)
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.Preposition

© 2022 - 2024 — McMap. All rights reserved.