Sign in to follow this  

DX11 porting dx9 to dx10 or later - how hard?

Recommended Posts

Posted (edited)

porting dx9 to dx10 or later - how hard?


dx10 will get me real instancing for grass - and texture arrays. dx11 will get me things like NVIDIA turf effects.


everything i'm finding online about rendering grass is dx10 or newer.


FVF gets replaced by....   i've already done some, but i forget the name!


and i'd have to supply my own basic shaders? right?


anything else really major?  minor variations in the matrix declarations as i recall.


i may have to bite the bullet and step up to a newer version of DX. i hate to have to do so, so late in the project, but you have to break a few eggs to make a real mayonnaise.

Edited by Norman Barrows

Share this post

Link to post
Share on other sites
Posted (edited)

dx9 to 11 is not really that hard, and forget dx10, you can use dx11 with feature level from 9 to 11. The most tricky thing will be the constant buffer management and update that replace the old constant register array. Everything is shader on dx11, no more fixed pipeline, but it is usually quite simple to patch that with a few handy shaders. 


For your question about matrices, with shaders, everything is up to you, left, right, direct, indirect, row major or column major, it is all about what flavor you prefer :)

Edited by galop1n

Share this post

Link to post
Share on other sites

I did it.  It's not hard but can take a lot more time than you might think. Consider all the changes and how they might impact your project:  I would never do it near the end of a project...because then I would no longer be near the end of the project.

Share this post

Link to post
Share on other sites

If you are still using the fixed function-pipeline, then maybe before upgrading to DX10+, you should probably start by using shaders. Removing the FFP might prove to be a huge project in and off itself, and if you combine it with changing the entire API surrounding it... I'd just break it off, if you first port your DX9-game to use shaders everywhere, upgrading to DX11 is a lot easier. There are some things that are still different that have been mentioned, but nothing quite as huge as FFP => Shaders.

Share this post

Link to post
Share on other sites
I'm currently going from 9 to 11 and it's doable. My advice is to learn dx11 separately, small projects, iterate, iterate more and then update (or start from scratch, which I did) your codebase.

Share this post

Link to post
Share on other sites
Posted (edited)
I would actually recommend porting your game to "modern D3D9c" first, and then porting that to D3D11.


by that you mean vertex declarations instead of fvf, and shaders. right?  and no d3dx dependencies? i think all i use out of d3dx are the texture and mesh loading code.  - and the skinned mesh api. but i have the skinned mesh api as stand alone source code - extracted from tiny.cpp, multi_anim.cpp and dxut.cpp. but wait- that doesn't include the controller api code in d3dx9.lib!  : (


i guess turn off d3dx9.lib and see what fails to link? that will instantly tell me exactly which d3dx routines i use - and must replace.


what about basic shaders? example code is readily available? aniso mip map w/ gourard, phong, alpha test or blend, and some two stage tex blending? i've had to do much of  that stuff in software in the past, i'd hate to have to look it all up again.


there's one more thing i can try...  


there is some sort of pseudo instancing possible in dx9 using indexed buffers in a special way. i suppose i ought to give it a shot before going in the dx10-11 direction just for instancing grass.  


or maybe lookup both that and what would have to change in dx9, and figure out whats the best option.


my biggest fear is that i'd end up spending weeks or months writing shaders. although i've done similar coding in the past, and am pretty comfortable with it.  


that's also another concern, i may come to like shader coding too much, causing delays on work on the game. its been a long time since i could just get a long pointer to vidram and "party on the bitmap". going to shaders would give me that kind of power again - intoxicating at the very least. my problem is i'm trying to build games, but i also enjoy low level graphics programming. but i only need low level graphics code as required by the game. anything more is technically a waste of time. shader coding may be distractingly fun for me.

Edited by Norman Barrows

Share this post

Link to post
Share on other sites
Posted (edited)

I have just made this transition. One thing to note is that in D3D11 there is no longer any functionality provided for the loading of mesh .x files as there is in D3D9. So if you are using such files then you will probably have to write your own mesh exporter/importer.


There is also no longer any built in support for loading .tga files or .dds files. And .bmp files won't load the alpha.


It was worth it to move to D3D11 because overall it runs a lot faster, at least for me. A good thing with D3D11 is that you can sample the depth buffer directly, so when doing deferred rendering there is no need to store a separate buffer for that.


I started out with following the tutorials on this site:

Edited by CarlML

Share this post

Link to post
Share on other sites

A good thing with D3D11 is that you can sample the depth buffer directly, so when doing deferred rendering there is no need to store a separate buffer for that.
 It's a bit late for you now, but you can do that in D3D9 as long as the user has a D3D10 capable GPU.

See INTZ here:


RAWZ/DF16/DF24 also worked on a handful of particular D3D9-era GPU's (e.g. RAWZ was GeForce 7 only, maybe?), but INTZ works on all D3D10 GPUs.

Share this post

Link to post
Share on other sites
Posted (edited)

well i read the dx9 docs about shaders and effects and HLSL yesterday.


set stream, set constants, set shaders (pre-compileld, already loaded), DIP.  that seems to be what it boils down to.


i use d3dx meshes for loading, but copy them into a vb and ib, then release the d3dxmesh. so i have buffers ready to go already.  


i think the skinned mesh code in Caveman 3.0 already does this, via simple shaders and a fx file.


i'm not really doing a lot of fancy special effects, animated vegetation, alpha blended flames and smoke.


depth of field seems to be the only post processing effect that's appropriate for a scene as seen by the human eye as opposed to a camera lens.  IE the human eye doesn't have lens flare, etc. corona effects, but that's a little different. the problem with DOF is - how do you let the player control the focus distance? in real life its automatic, whatever you "look at", your brain automatically adjusts the eye muscles to focus the lens at that range. rolling the middle mouse wheel is all i can think of.


Snow and three days of lows of 15F ( -9C ) have come to the Washington DC area. In-between dealing with that - getting into the sample code is the next thing on the todo list for today / tomorrow.


It also looks like i can keep the game mostly fixed function, and just use shaders where and as needed, the way i do now for skinned meshes. in fact i've already figured out what you have to save and restore when switching from fixed function to shaders and back again.  I did that when I got skinned meshes working.





' draws a caveperson using the specified textures and animation
fn v draw_skinmesh_caveman_nohair i sex i bodT i eyeT i clothT i ani i ctrl double dt D3DXMATRIX *mWorld i topT i cloakT i braT
' sex: 0=male 1=female
' bodT is body mesh texture ID
' eyeT is eye texture ID
' clothT is clothing texture ID
' ani is which ani should be playing
' ctrl is the index of the character`s controller
i a
' a is the skinned_mesh_pool index of the body mesh
= a controller_pool[ctrl].mesh_index
' 1. set textures in the skinned mesh pool
= skinned_mesh_pool[a].body->texID bodT
= skinned_mesh_pool[a].loincloth->texID clothT
== sex 1
    = skinned_mesh_pool[a].bra->texID braT
= skinned_mesh_pool[a].top->texID topT
= skinned_mesh_pool[a].cloak->texID cloakT
' 2. set animation
c controller_pool_setani ctrl ani
' 3. draw instance ( controllerID, dt, mWorld )
c draw_skinned_mesh_instance ctrl dt mWorld
' set z3d state manager current mesh to none...
= Zcurrentmesh -1
' reset FVF back to z3d FVF...
c Zd3d_device_ptr->SetFVF ZFVF
' 4. draw eyes
c draw_eyeballs2 a eyeT



As you can see, the FVF is all you really need to restore.  I set the "current mesh" to NONE just to be safe.


apparently set_FVF and set_shader are the two calls that actually do the switch from fixed function to porgramnmable pipeline and back. 


so it could be as simple as:

set stream

set shaders

set constants

DIP     // draw animated grass

set FVF     // back to normal operating mode for the game's "graphics engine".


And that means i can use d3dx9 AND shaders!    have my cake AND eat it too!  Something which is definitely not against my religion!   <g>.


I should know in a day or two.


time to hit the books! <g>.


never stop learning.


 and you gotta break a few eggs to make a real mayonnaise

Edited by Norman Barrows

Share this post

Link to post
Share on other sites

You can check in this GameDev's post and in this other about differences of DirectX11 vs DirectX12 (in the case you are thinking to move to one of them)


Moving to DX12 would be a terrible mistake, unless you already are a DX11 guru and have reach the 99.5% of performance or need a very specific feature lock behind the DX11 abstraction, you are not ready for DX12.

Share this post

Link to post
Share on other sites

I got the basic HLSL sample running as a test in Caveman 3.0.


took a while. had to pull the camera back to -700 to see the whole mesh.  the code also seem to expect dir_light_is_coming_from, not dir_light_is_shining_towards.    ran the code - where's the mesh?  (the camera is inside it, and the light is behind it !).   eventually i got something on the screen.   why is 3d programming always like that? the first time you try something new,  the camera is aimed the wrong way, or the mesh is scaled to zero, or not where you think it is, or you forgot to turn the light on...   and then it takes you like a day to find it!   <g>.


the test code provides the basic transform, multiple lighting, and solid texturing of the fixed function pipeline.  it can be used as the basis for any special effect shader. 


setVertexShader(myShader) and {  setVertexShader(NULL)    setFVF(myFVF)  }  switches between shaders and fixed function.


the code to convert from drawSubset to drawIndexedPrimitive can be found in this thread here on gamedev:


the plan is to mod the test code to use DIP.     the game uses VBs and IBs and DIP, not D3DXmeshes and drawSubset.     strip out the scale based on fTime.     maybe kick it up to 5 or 10 lights max.    

then add the sway in the wind algo:   delta=f(sin(time),windspd,winddir)  for verts who's UVs have a V near zero (IE at the top of the plant mesh). this will give me my "grass shader".


then i'll probably need to do it with instancing.


right now the test code uses .fx files.    i think i'd like to get away from FX files, as they are deprecated.   HLSL without effects is the "more current" way of doing things?

Share this post

Link to post
Share on other sites

right now the test code uses .fx files.    i think i'd like to get away from FX files, as they are deprecated.   HLSL without effects is the "more current" way of doing things?


The effects API is deprecated. You can still use .fx files, just not the way it lays out 'techniques' I believe.

I.e. you can still pass the file and the main function for vertex and pixel shaders into the shader compiler.


I don't have much experience with the effects API so maybe someone else can comment on the difference in detail.

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  

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By GreenGodDiary
      Having some issues with a geometry shader in a very basic DX app.
      We have an assignment where we are supposed to render a rotating textured quad, and in the geometry shader duplicate this quad and offset it by its normal. Very basic stuff essentially.
      My issue is that the duplicated quad, when rendered in front of the original quad, seems to fail the Z test and thus the original quad is rendered on top of it.
      Whats even weirder is that this only happens for one of the triangles in the duplicated quad, against one of the original quads triangles.

      Here's a video to show you what happens: Video (ignore the stretched textures)

      Here's my GS: (VS is simple passthrough shader and PS is just as basic)
      struct VS_OUT { float4 Pos : SV_POSITION; float2 UV : TEXCOORD; }; struct VS_IN { float4 Pos : POSITION; float2 UV : TEXCOORD; }; cbuffer cbPerObject : register(b0) { float4x4 WVP; }; [maxvertexcount(6)] void main( triangle VS_IN input[3], inout TriangleStream< VS_OUT > output ) { //Calculate normal float4 faceEdgeA = input[1].Pos - input[0].Pos; float4 faceEdgeB = input[2].Pos - input[0].Pos; float3 faceNormal = normalize(cross(,; //Input triangle, transformed for (uint i = 0; i < 3; i++) { VS_OUT element; VS_IN vert = input[i]; element.Pos = mul(vert.Pos, WVP); element.UV = vert.UV; output.Append(element); } output.RestartStrip(); for (uint j = 0; j < 3; j++) { VS_OUT element; VS_IN vert = input[j]; element.Pos = mul(vert.Pos + float4(faceNormal, 0.0f), WVP);; element.UV = vert.UV; output.Append(element); } }  
      I havent used geometry shaders much so im not 100% on what happens behind the scenes.
      Any tips appreciated! 
    • By mister345
      Hi, I'm building a game engine using DirectX11 in c++.
      I need a basic physics engine to handle collisions and motion, and no time to write my own.
      What is the easiest solution for this? Bullet and PhysX both seem too complicated and would still require writing my own wrapper classes, it seems. 
      I found this thing called PAL - physics abstraction layer that can support bullet, physx, etc, but it's so old and no info on how to download or install it.
      The simpler the better. Please let me know, thanks!
    • By Hexaa
      I try to draw lines with different thicknesses using the geometry shader approach from here:
      It seems to work great on my development machine (some Intel HD). However, if I try it on my target (Nvidia NVS 300, yes it's old) I get different results. See the attached images. There
      seem to be gaps in my sine signal that the NVS 300 device creates, the intel does what I want and expect in the other picture.
      It's a shame, because I just can't figure out why. I expect it to be the same. I get no Error in the debug output, with enabled native debugging. I disabled culling with CullMode.None. Could it be some z-fighting? I have little clue about it but I tested to play around with the RasterizerStateDescription and DepthBias properties with no success, no change at all. Maybe I miss something there?
      I develop the application with SharpDX btw.
      Any clues or help is very welcome

    • By Beny Benz
      I'm currently trying to write a shader which shoud compute a fast fourier transform of some data, manipulating the transformed data, do an inverse FFT an then displaying the result as vertex offset and color. I use Unity3d and HLSL as shader language. One of the main problems is that the data should not be passed from CPU to GPU for every frame if possible. My original plan was to use a vertex shader and do the fft there, but I fail to find out how to store changing data betwen shader calls/passes. I found a technique called ping-ponging which seems to be based on writing and exchangeing render targets, but I couldn't find an example for HLSL as a vertex shader yet.
      I found
      which seem to use COLOR0 and COLOR1 as such render targets.
      Is it even possible to do such calculations on the gpu only? (/in this shader stage?, because I need the result of the calculation to modify the vertex offsets there)
      I also saw the use of compute shaders in simmilar projects (ocean wave simulation), do they realy copy data between CPU / GPU for every frame?
      How does this ping-ponging / rendertarget switching technique work in HLSL?
      Have you seen an example of usage?
      Any answer would be helpfull.
      Thank you
    • By ADDMX
      Just a simple question about compute shaders (CS5, DX11).
      Do the atomic operations (InterlockedAdd in my case) should work without any issues on RWByteAddressBuffer and be globaly coherent ?
      I'v come back from CUDA world and commited fairly simple kernel that does some job, the pseudo-code is as follows:
      (both kernels use that same RWByteAddressBuffer)
      first kernel does some job and sets Result[0] = 0;
      (using Result.Store(0, 0))
      I'v checked with debugger, and indeed the value stored at dword 0 is 0
      now my second kernel
      RWByteAddressBuffer Result;  [numthreads(8, 8, 8)] void main() {     for (int i = 0; i < 5; i++)     {         uint4 v0 = DoSomeCalculations1();         uint4 v1 = DoSomeCalculations2();         uint4 v2 = DoSomeCalculations3();                  if (v0.w == 0 && v1.w == 0 && v2.w)             continue;         //    increment counter by 3, and get it previous value         // this should basically allocate space for 3 uint4 values in buffer         uint prev;         Result.InterlockedAdd(0, 3, prev);                  // this fills the buffer with 3 uint4 values (+1 is here as the first 16 bytes is occupied by DrawInstancedIndirect data)         Result.Store4((prev+0+1)*16, v0);         Result.Store4((prev+1+1)*16, v1);         Result.Store4((prev+2+1)*16, v2);     } } Now I invoke it with Dispatch(4,4,4)
      Now I use DrawInstancedIndirect to draw the buffer, but ocassionaly there is missed triangle here and there for a frame, as if the atomic counter does not work as expected
      do I need any additional synchronization there ?
      I'v tried 'AllMemoryBarrierWithGroupSync' at the end of kernel, but without effect.
      If I do not use atomic counter, and istead just output empty vertices (that will transform into degenerated triangles) the all is OK - as if I'm missing some form of synchronization, but I do not see such a thing in DX11.
      I'v tested on both old and new nvidia hardware (680M and 1080, the behaviour is that same).
  • Popular Now