Jump to content

  • Log In with Google      Sign In   
  • Create Account

Use SM5 in DX9? - Shader Model vs. DirectX version


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Meltac   Members   -  Reputation: 401

Like
0Likes
Like

Posted 02 June 2012 - 02:22 AM

Hi everyone

I've got a question that is partly conceptual and partly practical oriented. I didn't find a good web resource to clarify the relation between Shader Model and DirectX library version, as they are shipped together by Microsoft - but seem possible to be used apart from each other.

For example, when I compile my shaders against Shader Model 4 or 5 (vs/ps_4_0 or 5_0) I can easily use them in my directX 9 game. This makes the compilation faster and lets me use new intrinsic functions like ddx_coarse/fine.

But: Does this bring any benefits in terms of graphical features, quality, or hardware support? Or is a newer Shader Model alone purely extending the syntactical/functional power of the HLSL language, without giving access to any DX10/11 features in a DX9 game?

Thanks in advance for helping me with that.

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2570

Like
0Likes
Like

Posted 02 June 2012 - 07:47 AM

I m quite sure that advanced features of SM4 and SM5 aren't available under Direct3D 9. It is more like a question if the compiler is able to emulate the features with the SM3 feature set. There are cases which won't compile under Direct3D 9.

Cheers!

#3 Hodgman   Moderators   -  Reputation: 30424

Like
0Likes
Like

Posted 02 June 2012 - 09:21 AM

For example, when I compile my shaders against Shader Model 4 or 5 (vs/ps_4_0 or 5_0) I can easily use them in my directX 9 game. This makes the compilation faster and lets me use new intrinsic functions like ddx_coarse/fine.

Wow, this actually really surprises me - I would've assumed that D3D9 was limited to only using SM3!
How are you compiling your shaders? With FXC and the right command-line args, then loaded as a blob thru DX9, or compiled by D3DX, etc? Are you using a D9 or D9Ex device?

AFAIK, there's no way to query the D3D9 API as to whether it supports SM4/5, so I wonder what happens when you try to do this on an actual SM3 level GPU?

#4 MJP   Moderators   -  Reputation: 11446

Like
0Likes
Like

Posted 02 June 2012 - 11:54 AM

You can't use SM4.0 or greater through D3D9, the highest that D3D9 supports is SM3.0. The way it works is that D3D9-capable GPU's support up to SM3.0, and you're supposed to query the device for the shader model that it supports. D3D10-capable GPU's are required to support SM4.0 and D3D10.1-capable GPU's are required to support SM4.1. With D3D11 you have feature levels, where FEATURE_LEVEL_10_0 corresponds to SM4.0-level support, 10_1 corresponds to SM4.1 support, and 11_0 corresponds to SM5.0 support.

Shader models aren't just syntax changes, they directly correspond feature set of the GPU. For instance SM4.0 features integer arithmetic, geometry shaders, sampling MSAA textures, and a whole slew of other things that D3D9-level GPU's don't support.

#5 Tasty Texel   Members   -  Reputation: 1308

Like
0Likes
Like

Posted 03 June 2012 - 10:52 AM

But what about running f.i. a SM4.0 shader on a D3D10 level GPU with a DX9 based engine? What he wrote sounded like he actually already did it.

#6 Meltac   Members   -  Reputation: 401

Like
0Likes
Like

Posted 03 June 2012 - 12:54 PM

But what about running f.i. a SM4.0 shader on a D3D10 level GPU with a DX9 based engine? What he wrote sounded like he actually already did it.


Exactly.

I can confirm that the game I'm talking about (STALKER Shadow of Chernobyl) is built on a DX8/9 engine (X-Ray 1.0) which doesn't provide DX10 or 11 support, and that I managed to compile the game's original shader source code (after some changes) with both SM4 and 5 simply by replacing the DirectX-DLL that the game uses with a newer version and changing the pre-defined compilation target from ps_3_0 to ps_4_0, or ps_5_0 (and vs_X_Y, respectively).

My GPU (Geforce 260) is DX11 capable, what might be the reason why I'm able to run the game with the shaders compiled under SM4/5.

However since the shader code is pure HLSL, I only can use now some additional intrinsic functions, but can't trigger any D3D... API function from shader code which would give me access to the DX10/11 features. So I'm not sure what I'd be able to do now in my SM5 shaders to access those new features through the game's DX9 engine.

#7 MJP   Moderators   -  Reputation: 11446

Like
1Likes
Like

Posted 03 June 2012 - 02:11 PM

You cannot use SM4.0+ shaders with D3D9, even if your GPU supports them. The call to CreateVertexShader or CreatePixelShader will fail if you pass it a bytecode stream with a version that it doesn't recognize. If you have the debug runtimes enabled you'll get something like this in your debug output window:

Direct3D9: Shader Validator: X245: (Global Error) Version token 0x43425844 does not represent a vertex shader.
D3D9 Helper: IDirect3DDevice9::CreateVertexShader failed: D3DERR_INVALIDCALL

Even if you could somehow trick the driver into loading the shader it would be utterly useless, since D3D9 doesn't have the API functionality required to support the newer shader models. For instance you would have no means of setting constant variables, since SM4.0+ uses constant buffers and D3D9 has no concept of those.

Edited by MJP, 03 June 2012 - 02:12 PM.


#8 Meltac   Members   -  Reputation: 401

Like
0Likes
Like

Posted 03 June 2012 - 03:25 PM

But if so, what happens then when I replace the d3dx9_31.dll used by the game with the latest d3dx9_43.dll by renaming the latter to the former, which I did?

Obviously I can compile SM4 and SM5 shader code after, and use specific intrinsic functions such as ddx_coarse/fine which was not possible before.

BTW; those two lines I have altered to successfully force SM5 compilation (don't know if anyone could make sense of them):

#define FXPS technique _render{pass _code{PixelShader=compile ps_5_0 main();}}
#define FXVS technique _render{pass _code{VertexShader=compile vs_5_0 main();}}

#9 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
0Likes
Like

Posted 03 June 2012 - 03:30 PM

d3dx...dll files is not the Direct3D runtime. They are helpers for compiling hlsl shader source to bytecode, or loading images into textures, and some other stuff.
Direct3D runtime is in d3d9.dll file (for DirectX 9), and in d3d10.dll or d3d11.dll (for DirectX 10 or 11).

Edited by Martins Mozeiko, 03 June 2012 - 03:31 PM.


#10 Meltac   Members   -  Reputation: 401

Like
0Likes
Like

Posted 03 June 2012 - 03:41 PM

d3dx...dll files is not the Direct3D runtime. They are helpers for compiling hlsl shader source to bytecode, or loading images into textures, and some other stuff.
Direct3D runtime is in d3d9.dll file (for DirectX 9), and in d3d10.dll or d3d11.dll (for DirectX 10 or 11).


Ok, that would explain why I could compile my shaders to SM4/5. But not what actually happens when they run on the Direct3D runtime for DirectX9.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS