4
\$\begingroup\$

I've got the following code in a shader:

// v & y are both uints
nPixel = v;
nPixel << 8;
nPixel |= y;

and this gives me the following error in compilation:

shader.fx(80,10): error X3535: Bitwise operations not supported on legacy targets.
shader.fx(92,18): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
ID3DXEffectCompiler: Compilation failed

The error is on the following line:

nPixel |= y;

What am I doing wrong here?

\$\endgroup\$
4
  • \$\begingroup\$ What do you expect from & or | operations on floats? \$\endgroup\$ Commented Jun 12, 2012 at 22:20
  • \$\begingroup\$ sorry, that comment was a relic. I converted those values to uints before attempting bitwise operations on them. \$\endgroup\$
    – lapin
    Commented Jun 12, 2012 at 22:38
  • \$\begingroup\$ Ok, now it makes more sense :) Also you probably have mistake in "nPixel << 8" line - it doesn't assign result of shift expression. Probably that is why it "works" for DX9 - compile simply ignores this computation. \$\endgroup\$ Commented Jun 12, 2012 at 22:59
  • \$\begingroup\$ heh. Just my luck! I suppose I meant nPixel = nPixel << 8; \$\endgroup\$
    – lapin
    Commented Jun 12, 2012 at 23:27

1 Answer 1

6
\$\begingroup\$

Bitwise operations and integer operations were new for SM 4.0/DX10. As your error says:

Bitwise operations not supported on legacy targets.

You'll have to target DX10.

Alternatively, this blog post suggests using a texture to map results of AND,OR,XOR to different color channels.

enter image description here

bitwise operators texture: AND,OR,XOR

Seems plausible, and might be faster than the alternative I suggested in the comments.

\$\endgroup\$
6
  • \$\begingroup\$ isn't there an alternative instruction to allow me to perform that calculation. I have to target dx9 \$\endgroup\$
    – lapin
    Commented Jun 12, 2012 at 20:58
  • 1
    \$\begingroup\$ Bitwise operations need to be supported by the hardware. I suppose you could attempt to write code that converts to bits (using booleans maybe?) then does an OR operation on each, then converts that back to an integer. There may be another way, but I'm not well versed in DirectX. \$\endgroup\$
    – House
    Commented Jun 12, 2012 at 21:02
  • \$\begingroup\$ thanks for your help. I'll upvote your answer when I reach the required 15 rep points. \$\endgroup\$
    – lapin
    Commented Jun 12, 2012 at 21:06
  • 1
    \$\begingroup\$ I had a task where I needed to read textures from the card back into main memory and treat the textures as though they were arrays of bitmasks. I can't share code due to NDAs, I apologize, but I did it by multiplying by the shift values (so a <<8 would be *256) plus some floating point epsilon slop to make sure the right bits got flipped. It's entirely possible this would fail for different HW but at the time it worked on NVIDIA and ATI cards. \$\endgroup\$ Commented Jun 12, 2012 at 21:25
  • 1
    \$\begingroup\$ Well, it's not so ironic. Bit shifts left are the same as multiplying by 2^(left shift amount). And shifts right are the same as dividing by 2^(right shift amount). So the probably just converted it internally. \$\endgroup\$
    – House
    Commented Jun 12, 2012 at 23:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .