Jump to content
  • Advertisement
Sign in to follow this  
neeker

HLSL 2.0 vs 3.0

This topic is 2111 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I'm in the process of back-porting my version 3.0 shaders to 2.0.  The problem I'm having is my 2.0 shaders are not working at all, even a very simple pass-through vertex shader with a pixel shader that just colors the pixel red:

struct VS_INPUT {
   float4 position : POSITION;
   float3 normal : NORMAL;
   float2 Texture : TEXCOORD0;
};

struct VS_OUTPUT {
   float4 position : POSITION;
   float2 Texture : TEXCOORD0;
};

float4x4 gmatWVP : register(c0);

VS_OUTPUT vs_main(in VS_INPUT input)
{
   VS_OUTPUT output;

   output.position = mul(input.position, gmatWVP);
   output.Texture = input.Texture;

   return output;
}

struct PS_INPUT {
   float4 position : POSITION;
   float2 Texture : TEXCOORD0;
};

struct PS_OUTPUT {
   float4 color : COLOR0;
};

PS_OUTPUT ps_main(in PS_INPUT input)
{
   PS_OUTPUT output;

   output.color = float4(1.0f, 0.0f, 0.0f, 1.0f);

   return output;
}

By "Don't work" I mean that the pixels are shaded black (my clear color is magenta).  Compiling as 3.0 works fine.  I've tried a few different compile settings in fxc (e.g. /Ges, /Gec) but nothing there seems to work.  I'm not getting any errors when loading the shaders and no warnings or errors from the DX debugger.  I wondering if there's something I'm missing in the Direct3D setup that I'm missing?

Share this post


Link to post
Share on other sites
Advertisement

Well, both shaders seem fine (and compile just fine here on FXC with ps_2_0 and vs_2_0).

 

Do you compile them at runtime? If you do, double-check that you use the SM2 profiles on both shaders.

Share this post


Link to post
Share on other sites

Well, both shaders seem fine (and compile just fine here on FXC with ps_2_0 and vs_2_0).

 

Do you compile them at runtime? If you do, double-check that you use the SM2 profiles on both shaders.

 

I can't use D3DX, so I'm compiling them offline.

Edited by neeker

Share this post


Link to post
Share on other sites

There's a few subtle differences between SM2.0 and SM3.0. The one that causes the most issues is that SM3.0 shaders can only be used with other SM3.0 shaders. So you can' t have a ps_3_0 pixel shader bound at the same time as a vs_2_0 vertex shader. If you do this things won't render, and if you enable the debug runtimes you'll get a message in the debugger output telling you that this happened.

Share this post


Link to post
Share on other sites

There's a few subtle differences between SM2.0 and SM3.0. The one that causes the most issues is that SM3.0 shaders can only be used with other SM3.0 shaders. So you can' t have a ps_3_0 pixel shader bound at the same time as a vs_2_0 vertex shader. If you do this things won't render, and if you enable the debug runtimes you'll get a message in the debugger output telling you that this happened.

 

I'm using vs_2_0 and ps_2_0 for the version that doesn't work.

Share this post


Link to post
Share on other sites

Weird. When I get nothing from the debug runtime I start up PIX to see what's really going on. I recommend doing that (or use some other graphics debugger). Compare with your SM3, look if the uniform is ok, debug shader etc.

Share this post


Link to post
Share on other sites

Weird. When I get nothing from the debug runtime I start up PIX to see what's really going on. I recommend doing that (or use some other graphics debugger). Compare with your SM3, look if the uniform is ok, debug shader etc.

 

OK, finally got back to this today.  After putting PIX on the shaders, I found that they appear to be working correctly.  That is:  The pixel shader show an output of blue and the final buffer is black.  This is the only shader currently running.

 

The blue color is what I expect.  Stepping through the shader code confirms this.  However, I have no idea why the final framebuffer color is black.  And again, if I use shaders compiled with version 3_0, everything works perfectly.  Anyone have any ideas?

Edited by neeker

Share this post


Link to post
Share on other sites

Check the rest of your states; there are some (e.g. fog) where the behaviour is different between SM2 and SM3.

Share this post


Link to post
Share on other sites

Check the rest of your states; there are some (e.g. fog) where the behaviour is different between SM2 and SM3.

 

And we have a winner!  Thanks mhagain!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!