Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help with CGFX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 drjaydenm   Members   -  Reputation: 111

Like
0Likes
Like

Posted 04 March 2013 - 09:27 PM

Hi,

 

I am making a game engine with multiple rendering interfaces (currently only DX10 and OpenGL 3) and am trying to integrate CGFX into my pipeline. I have looked at the docs for CGFX but cannot seem to find anything that suits my needs.

 

What I am trying to do is compile a CGFX file to HLSL byte code as I can then just use my DX10Effect class to load the bytecode to a DX10 effect and DX will be happy. Looking at the docs for CGFX it seems I cannot get the DX10 bytecode from a CGFX effect. This means I will have to use CG to do all the effect technique and parameter work instead of DX itself.

 

Does anyone know if it is possible to get the DX10 bytecode from a CGFX effect?

 

Thanks.



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31852

Like
0Likes
Like

Posted 04 March 2013 - 09:29 PM

I'm not sure if this is possible/impossible, but personally, I just compile my CG files with FXC myself as the syntax is basically the same as HLSL...

#3 drjaydenm   Members   -  Reputation: 111

Like
0Likes
Like

Posted 04 March 2013 - 09:53 PM

Thanks for your help,

 

I could just do that but I am trying to look for a universal solution where I can take the CGFX effect, compile to the specific rendering API like DX10, save the results as a DX10 effect and then load the DX10 effect at runtime without using the CGFX API to set each parameter and so on.

 

I could always just compile the effect using CGFX, get all programs in the effect, extract the DX10 data and make a DX10 effect out of that, although I am pretty sure I would lose the information on techniques and parameters.

 

Any ideas guys?

 

Thanks.



#4 Nyssa   Members   -  Reputation: 426

Like
0Likes
Like

Posted 05 March 2013 - 01:28 AM

cgD3D10GetCompiledProgram is suppose to return the compiled shader code. You might be right in that you could loose technique information. You may also loose any data that was compiled out.

 

I had ALOT of issues with using cg in a similar situation to yours. Kept hitting a limitation with cg, made a work around for it then hit another limitation....this went on for a while. In the end I used HLSL2GLSL. It was made for dx9 and pre ogl3 but the source is available so you can modify it to work with dx10 and suit your own needs. There is also an updated forked version made for unity so that might be worth checking out too.


Edited by Nyssa, 05 March 2013 - 01:30 AM.


#5 drjaydenm   Members   -  Reputation: 111

Like
0Likes
Like

Posted 05 March 2013 - 02:22 AM

Thanks for your advice,

 

I will take a look at HLSL2GLSL as it does look promising. It is sad though, that CG is not able to output an effect file as DX bytecode and requires you to use their runtime instead of DX's. If it allowed you to do that, it would be an efficient solution to cross platform shaders.



#6 Nyssa   Members   -  Reputation: 426

Like
0Likes
Like

Posted 05 March 2013 - 03:16 AM

  It is sad though, that CG is not able to output an effect file as DX bytecode

 

cgD3D10GetCompiledProgram will return a ID3D10Blob object. From that object you can call GetBufferPointer and that will be the compiled code for a program. It is that data that you pass into say ID3D10Device::CreateVertexShader to create your shadersIf you're after the whole effect file as byte code then I don't think cg will do that (or directx for that matter).

 

 requires you to use their runtime instead of DX's

 

If you can do without effects and just use programs, then you could also compile these shaders in an offline mode and save the compiled data to file. That way your runtime engine could just use dx libs instead of cg? Runtime loading would also be a bit faster. Of course though you would need to check that all this works with the cross-platformness of your engine.


Edited by Nyssa, 05 March 2013 - 03:26 AM.


#7 drjaydenm   Members   -  Reputation: 111

Like
0Likes
Like

Posted 05 March 2013 - 03:48 AM

I was thinking about using just the Vertex and Fragment programs instead of the whole effect file. Is there any benefit (other than the fact I can use techniques and passes), of using effects instead of the individual programs if I am doing all my state changes in my program code instead of in the effect? I can't think of any reason off the top of my head.

 

Looks like i'll try using individual programs and see how it goes.


Edited by drjaydenm, 05 March 2013 - 03:49 AM.


#8 Nyssa   Members   -  Reputation: 426

Like
0Likes
Like

Posted 05 March 2013 - 04:09 AM

 Is there any benefit (other than the fact I can use techniques and passes) of using effects instead of the individual programs

 

Not that I know of. I personally use programs rather than effects. I guess the downside is you need to do all the state changes manually, but you're doing that already anyway.



#9 drjaydenm   Members   -  Reputation: 111

Like
0Likes
Like

Posted 05 March 2013 - 03:08 PM

Alright, thanks for your help :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS