Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
What do you expect from & or | operations on floats? –  Mārtiņš Možeiko Jun 12 '12 at 22:20
    
sorry, that comment was a relic. I converted those values to uints before attempting bitwise operations on them. –  lapin Jun 12 '12 at 22:38
    
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. –  Mārtiņš Možeiko Jun 12 '12 at 22:59
    
heh. Just my luck! I suppose I meant nPixel = nPixel << 8; –  lapin Jun 12 '12 at 23:27

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
isn't there an alternative instruction to allow me to perform that calculation. I have to target dx9 –  lapin Jun 12 '12 at 20:58
1  
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. –  Byte56 Jun 12 '12 at 21:02
    
thanks for your help. I'll upvote your answer when I reach the required 15 rep points. –  lapin Jun 12 '12 at 21:06
1  
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. –  Chronic Game Programmer Jun 12 '12 at 21:25
1  
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. –  Byte56 Jun 12 '12 at 23:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.