Jump to content
  • Advertisement
Sign in to follow this  
xen2

OpenGL CrossAPI Shader fragments / compiler ?

This topic is 4975 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 As I try to develop a crossplatform engine supporting shaders, I was wondering few points : 1/ D3DX9 brings "fragment" (not in the sense of pixel) shader that can be compiled together, but that doesnt exists in OpenGL... Nevertheless I would like to support that in my engine, this brings me few options : Doing a little thing that merge fragments shaders non-compiled code in one simple HLSL/Cg vertex shader (that has to be compiled with HLSL/Cg) or (yeah I'm courageous :p) working on a real opensource shader compiler such as Cg that would be well supported. 2/ The second option gives several question : how works the internal of Cg ? I have to compile high level code to shader assembly of opengl/d3d then compile it with gl extensions/D3DXAssembleShader, or compiled bytecode is the same for D3D/OpenGL so I have to search for opcode doc and gives a buffer that can be used directly with both CreateVertexBuffer and OpenGL ? (any doc ?) 3/ ID3DXFragmentLinker say its "very lightweight operation" to merge shader. To me, it sounds like it only make a buffer filled with each fragment compiled byte code, but I guess it still have to do some things to fix up shader common variable right ? i.e. take the good registry for each variable ? that would mean if its not possible to generate bytecode shader myself (by doing it via low level shader code), I'll have no way to do it without recompiling low level code to compiled bytecode (non lightweight) and have to take the first option (merging shader non-compiled high level code) ? thx in advance and sry about the bad english :) xen [Edited by - xen2 on December 30, 2004 1:22:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think the best way to do this would be to represent the shaders/effects in some sort of meta language. I'm doing some research into this myself atm but haven't even begun to implement anything.

Here are some links that might be helpful, check the last one for a dynamic shader compiler implementation (flash demo).

Sh High level meta programming

Dynamic shader compilation

Material system / JIT shader generator

Offset software dynamic xml generator / compiler

HTH

Share this post


Link to post
Share on other sites
As far as I understand, the latest one isnt really a shader compiler, but a tool that generate source code, would be kind of equivalent to the first way I explained (merging fragments in standard hlsl/cg source and passing it to appropriate compiler).

Share this post


Link to post
Share on other sites
1) Merging shader parts at runtime to form new shaders is actually a widespread technique of meta-shader generation. Newer games, like HL2 or Doom3, already make use of such techniques. It's really not very complex from the technical side, just stitch snippets of ASCII text together.

2) OpenGL doesn't expose bytecode at all. The (currently) only way to upload a shader to OpenGL is through an uncompiled language, either high level or ASM. Cg compiles down to ASM, which has to be assembled by the driver (using the appropriate ARB extension). GLSL has the compiler built into the driver.

The non-exposure of compiled byte code has advantages and disadvantages, although generally the positive points outweight the negative ones. Positive being, that the driver can optimize the code in the most optimal way, as he knows the exact target hardware. Also, it's forward compatible: new chipsets will directly optimize the same an unmodified code to their hardware, a precompiled shader would have to be recompiled for that target.

Now, intermediate byte code can also be optimized for specific platforms at runtime, just not as well as high level code. Platform portability and endianness also have to be taken in account when dealing with multiplatform byte code. But it can offer a few advantages over raw source: obfuscation, and faster compile times. There have been discussions about adding precompiled byte code shaders to OpenGL in the december ARB notes:

Quote:

Precompiled shaders - Khronos still working on this, no final spec yet. Might be ready in ~3 months. MAYBE - wait and see.

Simon notes that supporting a platform-independent binary format is also desirable. Will ask Khronos to encompass that, as well as platform-dependent formats.


So we'll have to see. But personally, I see this as a very low priority.

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.

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!