Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PaleRaider

HLSL or Cg?

This topic is 5709 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

I have read that they are compatible, on NVIDIA''s site http://www.nvidia.com/view.asp?IO=cg , and there for should be somewhat interchangable. Can anyone with experience recommened one over the other, or is one just as good as the other?

Share this post


Link to post
Share on other sites
Advertisement
I have experience with neither (very little with Cg) so what I''ll say might not apply.

I suppose Cg and HLSL are essentially the same thing with some minor stylistic differences. Some will tell you to use one, while others will tell you to use the other. Chances are they both do their job equally well and whether you pick one or the other depends entirely on your preference. The best thing is probably to take a look at both: learning one will definetly decrease the learning curve of the other. Then you''ll be able to make a choice which one you like better.

Share this post


Link to post
Share on other sites
You''d want to check things like:

- VS and PS versions supported. A couple of months ago, Cg didn''t have PS1.4, as far as I recall. I don''t know if that''s remedied (with the release of PS2.0 hardware and all, they should''ve updated it).

- Optimizations: Check the asm output for some shaders here and there.

- Do you consider GL support? Cg supports GL vertex/fragment programs, as far as I recall.
HLSL doesn''t.

Cheers,
Muhammad Haggag

Share this post


Link to post
Share on other sites
ATI and Microsoft is pusing HLSL and NVidia is pushing their Cg. Personally I would go for HLSL since it seems to be made for all platforms (there are no specific ATI optimizations that I know of) and it produces some pretty good code.

Share this post


Link to post
Share on other sites
While I do not have much experience with HLSL, I have done a fair amount with Cg.


- Cg supports vertex and pixel shaders up to and including 2.0.
- Cg also works quite well on ATI cards, as well as the nVidia cards.
- Cg supports both OpenGL (nVidia specific, and ARB extensions)and Direct3D8 and 9.
- The Cg toolkit contains tools and documentaion to work with the linux platform, as well as windows
- The Cg manual that the toolktit contains is nice.

So, if you want to develop with OpenGL, Cg is definitly the way to go. If you are working with Direct3d, it seems to be a tossup between the two. Try both and see which you prefer.

-Evan

---------------------------
Those who dance are considered insane by those who cannot hear the music.

Focus On: 3-D Models
Evan Pipho (evan@codershq.com)

Share this post


Link to post
Share on other sites
quote:
Original post by blue_knight
ATI and Microsoft is pusing HLSL and NVidia is pushing their Cg. Personally I would go for HLSL since it seems to be made for all platforms (there are no specific ATI optimizations that I know of) and it produces some pretty good code.



I''m not sure what you mean by all platforms , but the HLSL that Microsoft and ATI are pushing is only available in DirectX9 (not OpenGL) and only on Windows. Microsoft recently withdrew from the OpenGL Architecture Review Board, once again signalling their commitment for their platform at the exclusion of all others.

On Cg/HLSL compatibility: (http//www.nvidia.com/view.asp?IO=cg)
"Cg and Microsoft High Level Shader Language (HLSL): Cg was developed by NVIDIA in close collaboration with Microsoft, ensuring compatibility with DirectX 9.0 and HLSL. In addition, Cg will maintain compatibility with future versions of HLSL as they are made available."

The current Cg compiler (1.1) can compile vertex and fragment programs for these DirectX/OpenGL targets:
arbfp1, ps_2_x, ps_2_0, dx9ps2, fp30, vs_2_x, vs_2_0, dxvs2, arbvp1, vs_1_1, dx8vs, vp20, vp30, ps_1_3, ps_1_2, ps_1_1, dx8ps, fp20

in addition, the source code for the Cg compiler front-end is freely available from NVidia to encourage vendors to write their own backend code generator optimized for their hardware.

A chief source of complaint about Cg is ATI. ATI''s claims that Cg is ''proprietary'' and optimized for NVidia hardware are mostly political -- Cg is essentially equivalent to HLSL, which ATI embraces, and the Cg front-end is freely availble for ATI to attach their HLSL code-generator back end to. One must also bear in mind that ATI is pushing their own ''proprietary'' (DX9 only so far, but working on GL2SL) shader development tool called RenderMonkey.

So in conlusion, if you want to do any cross-platform shader development, Cg is the only game in town right now -- HLSL is DX9/Windows only, RenderMonkey is DX9/Windows only, and OpenGL 2.0 shading language (GLslang) isn''t official yet and won''t be compatible with anything else.

Share this post


Link to post
Share on other sites
Thanks for the replies! I was orignially going to use Cg, yet my development machines are all using ATI 9700 cards and as was mentioned ATI and Microsoft are really pushing HLSL. I am glad to hear that some one as heard of Cg running on ATI cards, which of course does make sense seeing as Cg is still compiled to shader assembly. I will try and start with Cg, being that I have found alot more resources covering that.

Share this post


Link to post
Share on other sites
quote:
Original post by terminate - Cg also works quite well on ATI cards, as well as the nVidia cards.


No it doesn''t. I''ve used Cg with a radeon 9700. Cg generates instructions with unecessary write and read masks and swizzles, which expand to multiple instructions on the radeon 9700. In many cases the program wouldn''t fit because of it.

quote:
Original post by kronq
ATI''s claims that Cg is ''proprietary'' and optimized for NVidia hardware are mostly political



No, they''re not. Cg IS optimized for nvidia, and the asm it generates is incredibly poor on radeons.

There''s not any really good choice. If you''re doing dx development, write in HLSL. If you''re doing opengl development, write in asm.

Share this post


Link to post
Share on other sites
Even NVidia admits that Cg was geared towards their own chipsets and not ATI''s. Stick with HLSL. Also, check out RenderMonkey - it helps you develop your shaders.

Share this post


Link to post
Share on other sites
HLSL it is then! I can flip flop with the best of them! If Cg doesn''t work well with ATI than that is a problem I would best like to avoid. Also my app is using DX9 so I don''t have any platform issues. Now to just go dig up as much HLSL documentation as I can find! Again thanks for the input.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!