difference between xna 4 or directx 10 HLSL?

Started by
4 comments, last by thomasvantroyen 12 years, 3 months ago
Hi,

i've been using Xna 4 for quite a while now (2D mostly), but with the rumours about xna disappearing I thought to check out the real stuff (c++ & directX 10 sdk) and learn more about the 3D using the very good "Introduction to DirectX 10 game programming" book.

Doing this I discovered something weird (to me, that is). The HLSL in my book on DirectX 10 is different than XNA 4's. I'm starting to think XNA 4 is not directX 10, but then again i'm quite certain my XNA 4 games won't run on WinXP machines, so DirectX 9c is not supported.

Anyway, when i try to compile HLSL code from my DX10 book in XNA 4, i must change these things until it compiles:
* "technique10" should be "technique"
* SetGeometryShader must be deleted, it errors about the shader version that's not supported
* the VS and PS version stated in the technique, are not supported (only <= 3_0 works)

So, why is there a difference, what am I missing between native DX10 and XNA 4? And if it's DX9c after all, why doesn't XNA 4 work on WinXP?

Sample: (DirectX 10 effect)

[font="Consolas"][size="2"][font="Consolas"][size="2"]cbuffer cbPerObject[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4x4 gWVP; [/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]};[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]void VS(float3 iPosL : POSITION,[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 iColor : COLOR,[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]out float4 oPosH : SV_POSITION,[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]out float4 oColor : COLOR)[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]// Transform to homogeneous clip space.[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]oPosH = mul(float4(iPosL, 1.0f), gWVP);[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]// Just pass vertex color into the pixel shader.[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]oColor = iColor;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 PS(float4 posH : SV_POSITION,[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 color : COLOR) : SV_Target[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]return color;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"][color=#B22222]technique10 ColorTech[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]pass P0[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]SetVertexShader( CompileShader( [color=#B22222]vs_4_0, VS() ) );[/font][/font]
[color=#B22222][font="Consolas"][size="2"][font="Consolas"][size="2"]SetGeometryShader( NULL );[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]SetPixelShader( CompileShader( [color=#B22222]ps_4_0, PS() ) );[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]thanks[/font][/font]
Advertisement
XNA 4 is built on D3D9. It absolutely works on Windows XP. XP is there in the list of supported operatoring systems. If your game doesn't work on XP, then there must be a problem with your game or how you're deploying it.

D3D10 brought some huge changes when it came out, and a lot of them had to do with Shader Model 4.0 which brought a lot of new shader features. There were also changes to the effect framework (which is seperate from core shaders), which is why you had to change "technique" to "technique10".

If you want to learn D3D10/D3D11, then I'm afraid you're going to have to actually use those API's. XNA is limited to a subset of D3D9-era functionality, which means you're going to get to a point in your book where there's no way to translate it back to XNA and SM3.0. If you want to know what you're missing out on by sticking with SM3.0, there's some info in the documentation:

http://msdn.microsof...v=vs.85%29.aspx

http://msdn.microsof...v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476342%28v=vs.85%29.aspx
thanks, after googling around a bit more, i indeed found out it's actually DX9 but with some non-standardized features (in hidef profile) that only work by DX10 supporting hardware. that's probably the reason why it's not working on xp machines, they often don't have DX10 hardware.

But thanks for clarifying even more.

So, i guess I'll have to learn C++ with all the difficult COM syntax and macro's. I'm a pro .NET guy for about 8 years, but damn, advanced C++ is hard to learn in absence of decent code completion and helping descriptions popping up everywhere. pitty c++ hasnt changed much the last decade. Even c++11 doesn't bring much improvement on the usability-domain imho. The IDE is just not very helpfull, like c# or any more mainstream language.

Ah well, i guess my hobby-games will have to settle with DX 9 :) It's more about the AI to me anyway.

thanks
I'm pretty sure the SlimDX guys have ported DX10 and 11 to C#. You may want to check that out.

Beginner in Game Development?  Read here. And read here.

 

Yeah you also have the option of managed wrappers like SlimDX and SharpDX. They fully expose D3D10/D3D11, so you don't lose out on anything that you would have by using native C++.
i'm speechless...

you just made my day, or probably even my year :)

i already wondered why there wasn't anybody making some .NET interop of DX, but i figured XNA (what i thought to be DX10 before today) made any such attempt obsolete and that explained why no decent interop project existed.. but apparently they DO exist !!

thank you for your service but please close the door behind you, XNA :)

thanks a whole lot!

This topic is closed to new replies.

Advertisement