Jump to content

  • Log In with Google      Sign In   
  • Create Account


Passing macros to shader during compilation


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
2 replies to this topic

#1 maxest   Members   -  Reputation: 294

Like
0Likes
Like

Posted 15 May 2012 - 10:29 AM

I use D3DX11CompileFromFileA to compile my shader. Now I want to add some macros to it. But not macros like:
#define USE_FEATURE_A
but
#define LOOP_ITERATIONS 16
So, speaking shortly, I want to pass a macro *with* a value so that my shader can, for instance, nicely unroll a loop for which I know a number of iterations upfront. I don't want to declare such a define in the shader directly, because the shader does not have this numeric information - application, right before it compiles the shader, nows.

I tried something like:
D3D10_SHADER_MACRO macros[2];
macros[0].Definition = "LOOP_ITERATIONS";
macros[0].Name = "16";
macros[1].Definition = macros[1].Name = NULL;
or:
D3D10_SHADER_MACRO macros[2];
macros[0].Definition = "LOOP_ITERATIONS 16";
macros[0].Name = "";
macros[1].Definition = macros[1].Name = NULL;
but none of this works. Any idea?

On a side note: what's the purpose of macro's Name anyway?

Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2522

Like
2Likes
Like

Posted 15 May 2012 - 10:44 AM

Should it be oposite?
this:
macros[0].Definition = "16";
macros[0].Name = "LOOP_ITERATIONS";

instead:
macros[0].Definition = "LOOP_ITERATIONS";
macros[0].Name = "16";



#3 maxest   Members   -  Reputation: 294

Like
0Likes
Like

Posted 15 May 2012 - 10:51 AM

Oh, boy... It's funny that in my other renderer I used "Name" field correctly, leaving Definition as an empty string, and here I thought that Definition is actually the name of the macro. What a confusion... Thank you very much :).




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