Passing macros to shader during compilation

Started by
1 comment, last by maxest 11 years, 11 months ago
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?
Advertisement
Should it be oposite?
this:

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


instead:

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

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 :).

This topic is closed to new replies.

Advertisement