# Porting DX8 - DX9. Should I go for HLSL ?

## Recommended Posts

Time has come for me to finish the porting of my DX8-based renderer to DX9-based, since the HW base has finally grown enough to compensate for the effort spent. What about shaders ? My old ones are in pure ASM, so I need to write all of them again. Should I go for HLSL or Cg ? I need something that is easily debuggable - ive had my share of no debugging of ASM shaders, so Id be really glad if I could see the values of registers during the shader (and preferably stepping through them). Also, Id be glad if there was minimum effort when making the switch to XNA (which I believe uses HLSL, but am not sure). Any ideas ?

##### Share on other sites
Quote:
 Original post by joe1024Time has come for me to finish the porting of my DX8-based renderer to DX9-based, since the HW base has finally grown enough to compensate for the effort spent.What about shaders ? My old ones are in pure ASM, so I need to write all of them again. Should I go for HLSL or Cg ? I need something that is easily debuggable - ive had my share of no debugging of ASM shaders, so Id be really glad if I could see the values of registers during the shader (and preferably stepping through them).Also, Id be glad if there was minimum effort when making the switch to XNA (which I believe uses HLSL, but am not sure).Any ideas ?

HLSL is a fine choice. PIX for Windows allows you to debug shaders, but with HLSL you'll find you debug your shaders less, since you're not dealing with "asm mistakes" like wrong registers, etc. It's also good if you move to XNA and do something on the XBox, since HLSL is your only choice there.

##### Share on other sites
Thats great.

Do you have any other ideas what would be good to do now that Im putting the effort into this ? Mainly regarding refactoring since Im trying to do this as API-free as possible, mainly for later XNA usage.

##### Share on other sites
Absolutely go with HLSL - whilst some hardcore console progammers will disagree I personally can't see any place for ASM shaders anymore. Especially for the portability to D3D10/D3D11 and XNA and also the tooling and other examples/tutorials online.

Do realise that DX9 SDK's since the last year (forget exactly when) don't support SM1 compile targets unless you include the legacy compiler (extra D3DX dependency).

Another thing to consider is that if you design your D3D9 renderer well you can take advantage of SM2 and SM3. For any shader taking advantage of SM3 capabilities it'll just be a pain to do that in anything but HLSL.

hth
Jack

##### Share on other sites
Quote:
 Original post by joe1024Do you have any other ideas what would be good to do now that Im putting the effort into this ? Mainly regarding refactoring since Im trying to do this as API-free as possible, mainly for later XNA usage.
For the Microsoft platforms HLSL in FX format is pretty stable - the changes between PC/XNA/XBox and across various versions isn't too much to handle. However, going to other platforms - say Cg or GLSL your problem won't be the syntax so much as the semantics. I'm no expert, but the bind points, declarations and so on are going to be subtly different that you'll have to watch out for different meaning rather than how you express your actual functions.

Unless you have a specific goal of running your code on OpenGL platforms you might as well just run with HLSL and FX files. If you're really paranoid about lock-in then drop the FX framework but stick with HLSL...

hth
Jack

##### Share on other sites
I definitely plan on adding some SM2/SM3 effects into my pipeline. There have been lots of shaders all over the net but since I was stuck with DX8 I could only stare. Now I can finally implement them.

I definitely dont need to support OpenGL. It was barely an issue 10 yrs ago, and even less these days (unless you need Mac support, which I dont).

My only issue is that due to the fact that one doesnt do such breaking changes often (few times in ones lifetime), I just need to be sure that its the right choice, taking into accounts other MS platforms, mainly XBOX.

I would guess that the next switch will be into DX11, some 3-5 yrs down the road (assuming there wont be any DX9-era integrated chipsets produced en mass) and since that requires an almost paradigm-like change, theres probably nothing I can do now to ease my porting efforts when that time comes, right ?

Plus, at that time, it should be clear, whether raytracing is the net big thing or not.

Im especially eager to seeing that I can debug the shaders - its been a MAJOR pain in the *ss trying to guess the values. As far as I noticed I should be able to step into shaders and directly seeing the values of registers/variables (under DX9), right ? Is it better to use PIX or just the tool that is used for my card (nVidia) ?

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978705

• 21
• 14
• 12
• 10
• 12