Bitwise Operation in HLSL

Started by
3 comments, last by jollyjeffers 15 years, 1 month ago
Hi everybody it seems that HLSL supports bitwise operations like "&". For example the line below makes no errors: if( 0xffff & 0x8000 ){ //something } But when I'm using "int" or "uint" as the lines below, I've got the following error message : uniform extern uint gMtrlFlag; if( gMtrlFlag & 0x8000 ){ //something } Error X3535:Bitwise operations not supported on legacy targets. And I don't understand what the error message exactly trying to tell me! Thanx for advice.
Advertisement
Are you trying to target D3D9 shader models? Bitwise operations and integer operations were new for SM 4.0/DX10
Yes. I'm using DX9.
Is there any way to use bitwise operation on DX9?
Quote:Original post by Mehdi_H
Yes. I'm using DX9.
Is there any way to use bitwise operation on DX9?


Unfortunately there isn't, since bitwise and integer ops require hardware support in the shaders.
SM4 and above have integer instruction sets and thus you can do this sort of thing. D3D9 was far too vague or limited in the specification to allow a meaningful implementation of this.

If you search around (try things like the conference slidedecks and vendor websites) there are a few hacks for emulating bitwise-like behaviour and/or packing flags into colours and so on...



hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement