• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Meltac

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

9 posts in this topic

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.
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
[quote name='Meltac' timestamp='1338625350' post='4945515']
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.[/quote]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?
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Bummel' timestamp='1338742352' post='4945841']
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.
[/quote]

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.
0

Share this post


Link to post
Share on other sites
You [i]cannot[/i] 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:

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

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
1

Share this post


Link to post
Share on other sites
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();}}
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
[quote name='Martins Mozeiko' timestamp='1338759027' post='4945917']
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).
[/quote]

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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0