ntdll: Use symbolic names when possible.
[wine] / dlls / wined3d / baseshader.c
index a1b987f..2d1c5d9 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright 2002-2003 Jason Edmeades
  * Copyright 2002-2003 Raphael Junqueira
+ * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
  * Copyright 2006 Ivan Gyurdiev
  *
@@ -30,7 +31,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
 
 #define GLNAME_REQUIRE_GLSL  ((const char *)1)
 
-inline static BOOL shader_is_version_token(DWORD token) {
+static inline BOOL shader_is_version_token(DWORD token) {
     return shader_is_pshader_version(token) ||
            shader_is_vshader_version(token);
 }
@@ -56,9 +57,18 @@ int shader_addline(
         return -1;
     }
 
+    if (buffer->newline) {
+        TRACE("GL HW (%u, %u) : %s", buffer->lineNo + 1, buffer->bsize, base);
+        buffer->newline = FALSE;
+    } else {
+        TRACE("%s", base);
+    }
+
     buffer->bsize += rc;
-    buffer->lineNo++;
-    TRACE("GL HW (%u, %u) : %s", buffer->lineNo, buffer->bsize, base); 
+    if (buffer->buffer[buffer->bsize-1] == '\n') {
+        buffer->lineNo++;
+        buffer->newline = TRUE;
+    }
     return 0;
 }
 
@@ -73,15 +83,15 @@ const SHADER_OPCODE* shader_get_opcode(
 
     /** TODO: use dichotomic search */
     while (NULL != shader_ins[i].name) {
-        if (((code & D3DSI_OPCODE_MASK) == shader_ins[i].opcode) &&
+        if (((code & WINED3DSI_OPCODE_MASK) == shader_ins[i].opcode) &&
             (((hex_version >= shader_ins[i].min_version) && (hex_version <= shader_ins[i].max_version)) ||
             ((shader_ins[i].min_version == 0) && (shader_ins[i].max_version == 0)))) {
             return &shader_ins[i];
         }
         ++i;
     }
-    FIXME("Unsupported opcode %#lx(%ld) masked %#lx, shader version %#lx\n", 
-       code, code, code & D3DSI_OPCODE_MASK, hex_version);
+    FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n", 
+       code, code, code & WINED3DSI_OPCODE_MASK, hex_version);
     return NULL;
 }
 
@@ -100,8 +110,8 @@ int shader_get_param(
      * The version check below should work in general */
 
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
-    char rel_token = D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2 &&
-        ((*pToken & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
+    char rel_token = WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2 &&
+        ((*pToken & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
 
     *param = *pToken;
     *addr_token = rel_token? *(pToken + 1): 0;
@@ -117,8 +127,8 @@ static inline int shader_skip_opcode(
    /* Shaders >= 2.0 may contain address tokens, but fortunately they
     * have a useful legnth mask - use it here. Shaders 1.0 contain no such tokens */
 
-    return (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2)?
-        ((opcode_token & D3DSI_INSTLENGTH_MASK) >> D3DSI_INSTLENGTH_SHIFT):
+    return (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 2)?
+        ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT):
         curOpcode->num_params;
 }
 
@@ -143,8 +153,8 @@ int shader_skip_unrecognized(
         tokens_read += shader_get_param(iface, pToken, &param, &addr_token);
         pToken += tokens_read;
 
-        FIXME("Unrecognized opcode param: token=%08lX "
-            "addr_token=%08lX name=", param, addr_token);
+        FIXME("Unrecognized opcode param: token=%08x "
+            "addr_token=%08x name=", param, addr_token);
         shader_dump_param(iface, param, addr_token, i);
         FIXME("\n");
         ++i;
@@ -157,155 +167,44 @@ int shader_skip_unrecognized(
 
 unsigned int shader_get_float_offset(const DWORD reg) {
 
-     unsigned int regnum = reg & D3DSP_REGNUM_MASK;
+     unsigned int regnum = reg & WINED3DSP_REGNUM_MASK;
      int regtype = shader_get_regtype(reg);
 
      switch (regtype) {
-        case D3DSPR_CONST: return regnum;
-        case D3DSPR_CONST2: return 2048 + regnum;
-        case D3DSPR_CONST3: return 4096 + regnum;
-        case D3DSPR_CONST4: return 6144 + regnum;
+        case WINED3DSPR_CONST: return regnum;
+        case WINED3DSPR_CONST2: return 2048 + regnum;
+        case WINED3DSPR_CONST3: return 4096 + regnum;
+        case WINED3DSPR_CONST4: return 6144 + regnum;
         default:
             FIXME("Unsupported register type: %d\n", regtype);
             return regnum;
      }
 }
 
-static void shader_parse_decl_usage(
-    DWORD *semantics_map,
-    DWORD usage_token, DWORD param) {
-
-    unsigned int usage = (usage_token & D3DSP_DCL_USAGE_MASK) >> D3DSP_DCL_USAGE_SHIFT;
-    unsigned int usage_idx = (usage_token & D3DSP_DCL_USAGEINDEX_MASK) >> D3DSP_DCL_USAGEINDEX_SHIFT;
-    unsigned int regnum = param & D3DSP_REGNUM_MASK;
-
-    switch(usage) {
-        case D3DDECLUSAGE_POSITION:
-            if (usage_idx == 0) { /* tween data */
-                TRACE("Setting position to %d\n", regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_POSITION] = param;
-            } else {
-                /* TODO: position indexes go from 0-8!!*/
-                TRACE("Setting position 2 to %d because usage_idx = %d\n", regnum, usage_idx);
-                /* robots uses positions up to 8, the position arrays are just packed.*/
-                if (usage_idx > 1) {
-                    TRACE("Loaded for position %d (greater than 2)\n", usage_idx);
-                }
-                semantics_map[WINED3DSHADERDECLUSAGE_POSITION2 + usage_idx-1] = param;
-            }
-            break;
-
-        case D3DDECLUSAGE_BLENDINDICES:
-            TRACE("Setting BLENDINDICES to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_BLENDINDICES] = param;
-            if (usage_idx != 0) FIXME("Extended BLENDINDICES\n");
-            break;
-
-        case D3DDECLUSAGE_BLENDWEIGHT:
-            TRACE("Setting BLENDWEIGHT to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_BLENDWEIGHT] = param;
-            if (usage_idx != 0) FIXME("Extended blend weights\n");
-            break;
-
-        case D3DDECLUSAGE_NORMAL:
-            if (usage_idx == 0) { /* tween data */
-                TRACE("Setting normal to %d\n", regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_NORMAL] = param;
-            } else {
-                TRACE("Setting normal 2 to %d because usage = %d\n", regnum, usage_idx);
-                semantics_map[WINED3DSHADERDECLUSAGE_NORMAL2] = param;
-            }
-            break;
-
-        case D3DDECLUSAGE_PSIZE:
-            TRACE("Setting PSIZE to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_PSIZE] = param;
-            if (usage_idx != 0) FIXME("Extended PSIZE\n");
-            break;
-
-        case D3DDECLUSAGE_COLOR:
-            if (usage_idx == 0)  {
-                TRACE("Setting DIFFUSE to %d\n", regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_DIFFUSE] = param;
-            } else {
-                TRACE("Setting SPECULAR to %d\n", regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_SPECULAR] = param;
-            }
-            break;
-
-        case D3DDECLUSAGE_TEXCOORD:
-            if (usage_idx > 7) {
-                FIXME("Program uses texture coordinate %d but only 0-7 have been "
-                    "implemented\n", usage_idx);
-            } else {
-                TRACE("Setting TEXCOORD %d  to %d\n", usage_idx, regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_TEXCOORD0 + usage_idx] = param;
-            }
-            break;
-
-        case D3DDECLUSAGE_TANGENT:
-            TRACE("Setting TANGENT to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_TANGENT] = param;
-            break;
-
-        case D3DDECLUSAGE_BINORMAL:
-            TRACE("Setting BINORMAL to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_BINORMAL] = param;
-            break;
-
-        case D3DDECLUSAGE_TESSFACTOR:
-            TRACE("Setting TESSFACTOR to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_TESSFACTOR] = param;
-            break;
-
-        case D3DDECLUSAGE_POSITIONT:
-            if (usage_idx == 0) { /* tween data */
-                FIXME("Setting positiont to %d\n", regnum);
-                semantics_map[WINED3DSHADERDECLUSAGE_POSITIONT] = param;
-            } else {
-                FIXME("Setting positiont 2 to %d because usage = %d\n", regnum, usage_idx);
-                semantics_map[WINED3DSHADERDECLUSAGE_POSITIONT2] = param;
-                if (usage_idx != 0) FIXME("Extended positiont\n");
-            }
-            break;
-
-        case D3DDECLUSAGE_FOG:
-            TRACE("Setting FOG to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_FOG] = param;
-            break;
-
-        case D3DDECLUSAGE_DEPTH:
-            TRACE("Setting DEPTH to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_DEPTH] = param;
-            break;
-
-        case D3DDECLUSAGE_SAMPLE:
-            TRACE("Setting SAMPLE to %d\n", regnum);
-            semantics_map[WINED3DSHADERDECLUSAGE_SAMPLE] = param;
-            break;
-
-        default:
-            FIXME("Unrecognised dcl %#x", usage);
-    }
-}
-
 /* Note that this does not count the loop register
  * as an address register. */
 
-void shader_get_registers_used(
+HRESULT shader_get_registers_used(
     IWineD3DBaseShader *iface,
     shader_reg_maps* reg_maps,
-    CONST DWORD* pToken) {
+    semantic* semantics_in,
+    semantic* semantics_out,
+    CONST DWORD* pToken,
+    IWineD3DStateBlockImpl *stateBlock) {
 
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
+    unsigned int cur_loop_depth = 0, max_loop_depth = 0;
 
     /* There are some minor differences between pixel and vertex shaders */
     char pshader = shader_is_pshader_version(This->baseShader.hex_version);
 
+    reg_maps->bumpmat = -1;
+    reg_maps->luminanceparams = -1;
+
     if (pToken == NULL)
-        return;
+        return WINED3D_OK;
 
-    while (D3DVS_END() != *pToken) {
+    while (WINED3DVS_END() != *pToken) {
         CONST SHADER_OPCODE* curOpcode;
         DWORD opcode_token;
 
@@ -316,7 +215,7 @@ void shader_get_registers_used(
 
         /* Skip comments */
         } else if (shader_is_comment(*pToken)) {
-             DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
+             DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
              ++pToken;
              pToken += comment_len;
              continue;
@@ -332,67 +231,166 @@ void shader_get_registers_used(
                ++pToken;
 
         /* Handle declarations */
-        } else if (D3DSIO_DCL == curOpcode->opcode) {
+        } else if (WINED3DSIO_DCL == curOpcode->opcode) {
 
             DWORD usage = *pToken++;
             DWORD param = *pToken++;
             DWORD regtype = shader_get_regtype(param);
-            unsigned int regnum = param & D3DSP_REGNUM_MASK;
+            unsigned int regnum = param & WINED3DSP_REGNUM_MASK;
 
             /* Vshader: mark attributes used
                Pshader: mark 3.0 input registers used, save token */
-            if (D3DSPR_INPUT == regtype) {
+            if (WINED3DSPR_INPUT == regtype) {
 
                 if (!pshader)
                     reg_maps->attributes[regnum] = 1;
                 else
                     reg_maps->packed_input[regnum] = 1;
 
-                shader_parse_decl_usage(reg_maps->semantics_in, usage, param);
+                semantics_in[regnum].usage = usage;
+                semantics_in[regnum].reg = param;
 
             /* Vshader: mark 3.0 output registers used, save token */
-            } else if (D3DSPR_OUTPUT == regtype) {
+            } else if (WINED3DSPR_OUTPUT == regtype) {
                 reg_maps->packed_output[regnum] = 1;
-                shader_parse_decl_usage(reg_maps->semantics_out, usage, param);
+                semantics_out[regnum].usage = usage;
+                semantics_out[regnum].reg = param;
+                if (usage & (WINED3DDECLUSAGE_FOG << WINED3DSP_DCL_USAGE_SHIFT))
+                    reg_maps->fog = 1;
 
             /* Save sampler usage token */
-            } else if (D3DSPR_SAMPLER == regtype)
+            } else if (WINED3DSPR_SAMPLER == regtype)
                 reg_maps->samplers[regnum] = usage;
 
-        /* Skip definitions (for now) */
-        } else if (D3DSIO_DEF == curOpcode->opcode) {
+        } else if (WINED3DSIO_DEF == curOpcode->opcode) {
+
+            local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            if (!lconst) return E_OUTOFMEMORY;
+            lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
+            memcpy(&lconst->value, pToken + 1, 4 * sizeof(DWORD));
+
+            /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
+            if(WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 && pshader) {
+                float *value = (float *) lconst->value;
+                if(value[0] < -1.0) value[0] = -1.0;
+                else if(value[0] >  1.0) value[0] =  1.0;
+                if(value[1] < -1.0) value[1] = -1.0;
+                else if(value[1] >  1.0) value[1] =  1.0;
+                if(value[2] < -1.0) value[2] = -1.0;
+                else if(value[2] >  1.0) value[2] =  1.0;
+                if(value[3] < -1.0) value[3] = -1.0;
+                else if(value[3] >  1.0) value[3] =  1.0;
+            }
+
+            list_add_head(&This->baseShader.constantsF, &lconst->entry);
+            pToken += curOpcode->num_params;
+
+        } else if (WINED3DSIO_DEFI == curOpcode->opcode) {
+
+            local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            if (!lconst) return E_OUTOFMEMORY;
+            lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
+            memcpy(&lconst->value, pToken + 1, 4 * sizeof(DWORD));
+            list_add_head(&This->baseShader.constantsI, &lconst->entry);
+            pToken += curOpcode->num_params;
+
+        } else if (WINED3DSIO_DEFB == curOpcode->opcode) {
+
+            local_constant* lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            if (!lconst) return E_OUTOFMEMORY;
+            lconst->idx = *pToken & WINED3DSP_REGNUM_MASK;
+            memcpy(&lconst->value, pToken + 1, 1 * sizeof(DWORD));
+            list_add_head(&This->baseShader.constantsB, &lconst->entry);
             pToken += curOpcode->num_params;
 
         /* If there's a loop in the shader */
-        } else if (D3DSIO_LOOP == curOpcode->opcode) {
-            reg_maps->loop = 1;
+        } else if (WINED3DSIO_LOOP == curOpcode->opcode ||
+                   WINED3DSIO_REP == curOpcode->opcode) {
+            cur_loop_depth++;
+            if(cur_loop_depth > max_loop_depth)
+                max_loop_depth = cur_loop_depth;
+            pToken += curOpcode->num_params;
+
+        } else if (WINED3DSIO_ENDLOOP == curOpcode->opcode ||
+                   WINED3DSIO_ENDREP == curOpcode->opcode) {
+            cur_loop_depth--;
+
+        /* For subroutine prototypes */
+        } else if (WINED3DSIO_LABEL == curOpcode->opcode) {
+
+            DWORD snum = *pToken & WINED3DSP_REGNUM_MASK; 
+            reg_maps->labels[snum] = 1;
             pToken += curOpcode->num_params;
-        
+
         /* Set texture, address, temporary registers */
         } else {
             int i, limit;
 
             /* Declare 1.X samplers implicitly, based on the destination reg. number */
-            if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 && 
-                (D3DSIO_TEX == curOpcode->opcode ||
-                 D3DSIO_TEXBEM == curOpcode->opcode ||
-                 D3DSIO_TEXM3x2TEX == curOpcode->opcode ||
-                 D3DSIO_TEXM3x3TEX == curOpcode->opcode)) {
+            if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 && 
+                (WINED3DSIO_TEX == curOpcode->opcode ||
+                 WINED3DSIO_TEXBEM == curOpcode->opcode ||
+                 WINED3DSIO_TEXBEML == curOpcode->opcode ||
+                 WINED3DSIO_TEXDP3TEX == curOpcode->opcode ||
+                 WINED3DSIO_TEXM3x2TEX == curOpcode->opcode ||
+                 WINED3DSIO_TEXM3x3SPEC == curOpcode->opcode ||
+                 WINED3DSIO_TEXM3x3TEX == curOpcode->opcode ||
+                 WINED3DSIO_TEXM3x3VSPEC == curOpcode->opcode ||
+                 WINED3DSIO_TEXREG2AR == curOpcode->opcode ||
+                 WINED3DSIO_TEXREG2GB == curOpcode->opcode ||
+                 WINED3DSIO_TEXREG2RGB == curOpcode->opcode)) {
 
                 /* Fake sampler usage, only set reserved bit and ttype */
-                DWORD sampler_code = *pToken & D3DSP_REGNUM_MASK;
-                reg_maps->samplers[sampler_code] = (0x1 << 31) | D3DSTT_2D;
-                
-            } else if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) == 1 &&
-                (D3DSIO_TEXM3x3SPEC == curOpcode->opcode ||
-                 D3DSIO_TEXM3x3VSPEC == curOpcode->opcode)) {
-
-                /* 3D sampler usage, only set reserved bit and ttype
-                 * FIXME: This could be either Cube or Volume, but we wouldn't know unless
-                 * we waited to generate the shader until the textures were all bound.
-                 * For now, use Cube textures because they are more common. */
-                DWORD sampler_code = *pToken & D3DSP_REGNUM_MASK;
-                reg_maps->samplers[sampler_code] = (0x1 << 31) | D3DSTT_CUBE;
+                DWORD sampler_code = *pToken & WINED3DSP_REGNUM_MASK;
+
+                if(!stateBlock->textures[sampler_code]) {
+                    ERR("No texture bound to sampler %d\n", sampler_code);
+                    reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
+                } else {
+                    int texType = IWineD3DBaseTexture_GetTextureDimensions(stateBlock->textures[sampler_code]);
+                    switch(texType) {
+                        case GL_TEXTURE_2D:
+                            reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
+                            break;
+
+                        case GL_TEXTURE_3D:
+                            reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_VOLUME;
+                            break;
+
+                        case GL_TEXTURE_CUBE_MAP_ARB:
+                            reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_CUBE;
+                            break;
+
+                        default:
+                            ERR("Unexpected gl texture type found: %d\n", texType);
+                            reg_maps->samplers[sampler_code] = (0x1 << 31) | WINED3DSTT_2D;
+                    }
+                }
+
+                /* texbem is only valid with < 1.4 pixel shaders */
+                if(WINED3DSIO_TEXBEM  == curOpcode->opcode ||
+                    WINED3DSIO_TEXBEML == curOpcode->opcode) {
+                    if(reg_maps->bumpmat != -1 && reg_maps->bumpmat != sampler_code) {
+                        FIXME("Pixel shader uses texbem instruction on more than 1 sampler\n");
+                    } else {
+                        reg_maps->bumpmat = sampler_code;
+                        if(WINED3DSIO_TEXBEML == curOpcode->opcode) {
+                            reg_maps->luminanceparams = sampler_code;
+                        }
+                    }
+                }
+            }
+            if(WINED3DSIO_NRM  == curOpcode->opcode) {
+                reg_maps->usesnrm = 1;
+            } else if(WINED3DSIO_BEM == curOpcode->opcode) {
+                DWORD regnum = *pToken & WINED3DSP_REGNUM_MASK;
+                if(reg_maps->bumpmat != -1 && reg_maps->bumpmat != regnum) {
+                    FIXME("Pixel shader uses bem or texbem instruction on more than 1 sampler\n");
+                } else {
+                    reg_maps->bumpmat = regnum;
+                }
+            } else if(WINED3DSIO_DSY  == curOpcode->opcode) {
+                reg_maps->usesdsy = 1;
             }
 
             /* This will loop over all the registers and try to
@@ -402,7 +400,7 @@ void shader_get_registers_used(
              * okay, since we'll catch any address registers when 
              * they are initialized (required by spec) */
 
-            limit = (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED)?
+            limit = (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED)?
                 curOpcode->num_params + 1: curOpcode->num_params;
 
             for (i = 0; i < limit; ++i) {
@@ -411,9 +409,9 @@ void shader_get_registers_used(
                 pToken += shader_get_param(iface, pToken, &param, &addr_token);
 
                 regtype = shader_get_regtype(param);
-                reg = param & D3DSP_REGNUM_MASK;
+                reg = param & WINED3DSP_REGNUM_MASK;
 
-                if (D3DSPR_TEXTURE == regtype) { /* vs: D3DSPR_ADDR */
+                if (WINED3DSPR_TEXTURE == regtype) { /* vs: WINED3DSPR_ADDR */
 
                     if (pshader)
                         reg_maps->texcoord[reg] = 1;
@@ -421,14 +419,23 @@ void shader_get_registers_used(
                         reg_maps->address[reg] = 1;
                 }
 
-                else if (D3DSPR_TEMP == regtype)
+                else if (WINED3DSPR_TEMP == regtype)
                     reg_maps->temporary[reg] = 1;
 
-                else if (D3DSPR_INPUT == regtype && !pshader)
+                else if (WINED3DSPR_INPUT == regtype && !pshader)
                     reg_maps->attributes[reg] = 1;
-             }
+
+                else if (WINED3DSPR_RASTOUT == regtype && reg == 1)
+                    reg_maps->fog = 1;
+
+                else if (WINED3DSPR_MISCTYPE == regtype && reg == 0 && pshader)
+                    reg_maps->vpos = 1;
+            }
         }
     }
+    reg_maps->loop_depth = max_loop_depth;
+
+    return WINED3D_OK;
 }
 
 static void shader_dump_decl_usage(
@@ -440,77 +447,77 @@ static void shader_dump_decl_usage(
 
     TRACE("dcl");
 
-    if (regtype == D3DSPR_SAMPLER) {
-        DWORD ttype = decl & D3DSP_TEXTURETYPE_MASK;
+    if (regtype == WINED3DSPR_SAMPLER) {
+        DWORD ttype = decl & WINED3DSP_TEXTURETYPE_MASK;
 
         switch (ttype) {
-            case D3DSTT_2D: TRACE("_2d"); break;
-            case D3DSTT_CUBE: TRACE("_cube"); break;
-            case D3DSTT_VOLUME: TRACE("_volume"); break;
-            default: TRACE("_unknown_ttype(%08lx)", ttype); 
+            case WINED3DSTT_2D: TRACE("_2d"); break;
+            case WINED3DSTT_CUBE: TRACE("_cube"); break;
+            case WINED3DSTT_VOLUME: TRACE("_volume"); break;
+            default: TRACE("_unknown_ttype(%08x)", ttype); 
        }
 
     } else { 
 
-        DWORD usage = decl & D3DSP_DCL_USAGE_MASK;
-        DWORD idx = (decl & D3DSP_DCL_USAGEINDEX_MASK) >> D3DSP_DCL_USAGEINDEX_SHIFT;
+        DWORD usage = decl & WINED3DSP_DCL_USAGE_MASK;
+        DWORD idx = (decl & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
 
         /* Pixel shaders 3.0 don't have usage semantics */
         char pshader = shader_is_pshader_version(This->baseShader.hex_version);
-        if (pshader && This->baseShader.hex_version < D3DPS_VERSION(3,0))
+        if (pshader && This->baseShader.hex_version < WINED3DPS_VERSION(3,0))
             return;
         else
             TRACE("_");
 
         switch(usage) {
-        case D3DDECLUSAGE_POSITION:
-            TRACE("%s%ld", "position", idx);
+        case WINED3DDECLUSAGE_POSITION:
+            TRACE("position%d", idx);
             break;
-        case D3DDECLUSAGE_BLENDINDICES:
-            TRACE("%s", "blend");
+        case WINED3DDECLUSAGE_BLENDINDICES:
+            TRACE("blend");
             break;
-        case D3DDECLUSAGE_BLENDWEIGHT:
-            TRACE("%s", "weight");
+        case WINED3DDECLUSAGE_BLENDWEIGHT:
+            TRACE("weight");
             break;
-        case D3DDECLUSAGE_NORMAL:
-            TRACE("%s%ld", "normal", idx);
+        case WINED3DDECLUSAGE_NORMAL:
+            TRACE("normal%d", idx);
             break;
-        case D3DDECLUSAGE_PSIZE:
-            TRACE("%s", "psize");
+        case WINED3DDECLUSAGE_PSIZE:
+            TRACE("psize");
             break;
-        case D3DDECLUSAGE_COLOR:
+        case WINED3DDECLUSAGE_COLOR:
             if(idx == 0)  {
-                TRACE("%s", "color");
+                TRACE("color");
             } else {
-                TRACE("%s%ld", "specular", (idx - 1));
+                TRACE("specular%d", (idx - 1));
             }
             break;
-        case D3DDECLUSAGE_TEXCOORD:
-            TRACE("%s%ld", "texture", idx);
+        case WINED3DDECLUSAGE_TEXCOORD:
+            TRACE("texture%d", idx);
             break;
-        case D3DDECLUSAGE_TANGENT:
-            TRACE("%s", "tangent");
+        case WINED3DDECLUSAGE_TANGENT:
+            TRACE("tangent");
             break;
-        case D3DDECLUSAGE_BINORMAL:
-            TRACE("%s", "binormal");
+        case WINED3DDECLUSAGE_BINORMAL:
+            TRACE("binormal");
             break;
-        case D3DDECLUSAGE_TESSFACTOR:
-            TRACE("%s", "tessfactor");
+        case WINED3DDECLUSAGE_TESSFACTOR:
+            TRACE("tessfactor");
             break;
-        case D3DDECLUSAGE_POSITIONT:
-            TRACE("%s%ld", "positionT", idx);
+        case WINED3DDECLUSAGE_POSITIONT:
+            TRACE("positionT%d", idx);
             break;
-        case D3DDECLUSAGE_FOG:
-            TRACE("%s", "fog");
+        case WINED3DDECLUSAGE_FOG:
+            TRACE("fog");
             break;
-        case D3DDECLUSAGE_DEPTH:
-            TRACE("%s", "depth");
+        case WINED3DDECLUSAGE_DEPTH:
+            TRACE("depth");
             break;
-        case D3DDECLUSAGE_SAMPLE:
-            TRACE("%s", "sample");
+        case WINED3DDECLUSAGE_SAMPLE:
+            TRACE("sample");
             break;
         default:
-            FIXME("unknown_semantics(%08lx)", usage);
+            FIXME("unknown_semantics(%08x)", usage);
         }
     }
 }
@@ -523,7 +530,7 @@ static void shader_dump_arr_entry(
     int input) {
 
     char relative =
-        ((param & D3DSHADER_ADDRESSMODE_MASK) == D3DSHADER_ADDRMODE_RELATIVE);
+        ((param & WINED3DSHADER_ADDRESSMODE_MASK) == WINED3DSHADER_ADDRMODE_RELATIVE);
 
     if (relative) {
         TRACE("[");
@@ -545,11 +552,13 @@ void shader_dump_param(
     int input) {
 
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
-    static const char* rastout_reg_names[] = { "oPos", "oFog", "oPts" };
+    static const char * const rastout_reg_names[] = { "oPos", "oFog", "oPts" };
+    static const char * const misctype_reg_names[] = { "vPos", "vFace"};
     char swizzle_reg_chars[4];
 
-    DWORD reg = param & D3DSP_REGNUM_MASK;
+    DWORD reg = param & WINED3DSP_REGNUM_MASK;
     DWORD regtype = shader_get_regtype(param);
+    DWORD modifier = param & WINED3DSP_SRCMOD_MASK;
 
     /* There are some minor differences between pixel and vertex shaders */
     char pshader = shader_is_pshader_version(This->baseShader.hex_version);
@@ -563,120 +572,132 @@ void shader_dump_param(
     swizzle_reg_chars[3] = pshader? 'a': 'w';
 
     if (input) {
-        if ( ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) ||
-             ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_BIASNEG) ||
-             ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_SIGNNEG) ||
-             ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_X2NEG) )
+        if ( (modifier == WINED3DSPSM_NEG) ||
+             (modifier == WINED3DSPSM_BIASNEG) ||
+             (modifier == WINED3DSPSM_SIGNNEG) ||
+             (modifier == WINED3DSPSM_X2NEG) ||
+             (modifier == WINED3DSPSM_ABSNEG) )
             TRACE("-");
-        else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_COMP)
+        else if (modifier == WINED3DSPSM_COMP)
             TRACE("1-");
-        else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NOT)
+        else if (modifier == WINED3DSPSM_NOT)
             TRACE("!");
+
+        if (modifier == WINED3DSPSM_ABS || modifier == WINED3DSPSM_ABSNEG) 
+            TRACE("abs(");
     }
 
     switch (regtype) {
-        case D3DSPR_TEMP:
-            TRACE("r%lu", reg);
+        case WINED3DSPR_TEMP:
+            TRACE("r%u", reg);
             break;
-        case D3DSPR_INPUT:
+        case WINED3DSPR_INPUT:
             TRACE("v");
             shader_dump_arr_entry(iface, param, addr_token, reg, input);
             break;
-        case D3DSPR_CONST:
-        case D3DSPR_CONST2:
-        case D3DSPR_CONST3:
-        case D3DSPR_CONST4:
+        case WINED3DSPR_CONST:
+        case WINED3DSPR_CONST2:
+        case WINED3DSPR_CONST3:
+        case WINED3DSPR_CONST4:
             TRACE("c");
             shader_dump_arr_entry(iface, param, addr_token, shader_get_float_offset(param), input);
             break;
-        case D3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
-            TRACE("%c%lu", (pshader? 't':'a'), reg);
+        case WINED3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
+            TRACE("%c%u", (pshader? 't':'a'), reg);
             break;        
-        case D3DSPR_RASTOUT:
+        case WINED3DSPR_RASTOUT:
             TRACE("%s", rastout_reg_names[reg]);
             break;
-        case D3DSPR_COLOROUT:
-            TRACE("oC%lu", reg);
+        case WINED3DSPR_COLOROUT:
+            TRACE("oC%u", reg);
             break;
-        case D3DSPR_DEPTHOUT:
+        case WINED3DSPR_DEPTHOUT:
             TRACE("oDepth");
             break;
-        case D3DSPR_ATTROUT:
-            TRACE("oD%lu", reg);
+        case WINED3DSPR_ATTROUT:
+            TRACE("oD%u", reg);
             break;
-        case D3DSPR_TEXCRDOUT: 
+        case WINED3DSPR_TEXCRDOUT: 
 
             /* Vertex shaders >= 3.0 use general purpose output registers
-             * (D3DSPR_OUTPUT), which can include an address token */
+             * (WINED3DSPR_OUTPUT), which can include an address token */
 
-            if (D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3) {
+            if (WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version) >= 3) {
                 TRACE("o");
                 shader_dump_arr_entry(iface, param, addr_token, reg, input);
             }
             else 
-               TRACE("oT%lu", reg);
+               TRACE("oT%u", reg);
             break;
-        case D3DSPR_CONSTINT:
+        case WINED3DSPR_CONSTINT:
             TRACE("i");
             shader_dump_arr_entry(iface, param, addr_token, reg, input);
             break;
-        case D3DSPR_CONSTBOOL:
+        case WINED3DSPR_CONSTBOOL:
             TRACE("b");
             shader_dump_arr_entry(iface, param, addr_token, reg, input);
             break;
-        case D3DSPR_LABEL:
-            TRACE("l%lu", reg);
+        case WINED3DSPR_LABEL:
+            TRACE("l%u", reg);
             break;
-        case D3DSPR_LOOP:
+        case WINED3DSPR_LOOP:
             TRACE("aL");
             break;
-        case D3DSPR_SAMPLER:
-            TRACE("s%lu", reg);
+        case WINED3DSPR_SAMPLER:
+            TRACE("s%u", reg);
+            break;
+        case WINED3DSPR_MISCTYPE:
+            if (reg > 1) {
+                FIXME("Unhandled misctype register %d\n", reg);
+            } else {
+                TRACE("%s", misctype_reg_names[reg]);
+            }
             break;
-        case D3DSPR_PREDICATE:
-            TRACE("p%lu", reg);
+        case WINED3DSPR_PREDICATE:
+            TRACE("p%u", reg);
             break;
         default:
-            TRACE("unhandled_rtype(%#lx)", regtype);
+            TRACE("unhandled_rtype(%#x)", regtype);
             break;
    }
 
    if (!input) {
        /* operand output (for modifiers and shift, see dump_ins_modifiers) */
 
-       if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
+       if ((param & WINED3DSP_WRITEMASK_ALL) != WINED3DSP_WRITEMASK_ALL) {
            TRACE(".");
-           if (param & D3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
-           if (param & D3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
-           if (param & D3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
-           if (param & D3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
+           if (param & WINED3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
+           if (param & WINED3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
+           if (param & WINED3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
+           if (param & WINED3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
        }
 
    } else {
         /** operand input */
-        DWORD swizzle = (param & D3DSP_SWIZZLE_MASK) >> D3DSP_SWIZZLE_SHIFT;
+        DWORD swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
         DWORD swizzle_r = swizzle & 0x03;
         DWORD swizzle_g = (swizzle >> 2) & 0x03;
         DWORD swizzle_b = (swizzle >> 4) & 0x03;
         DWORD swizzle_a = (swizzle >> 6) & 0x03;
 
-        if (0 != (param & D3DSP_SRCMOD_MASK)) {
-            DWORD mask = param & D3DSP_SRCMOD_MASK;
-            switch (mask) {
-                case D3DSPSM_NONE:    break;
-                case D3DSPSM_NEG:     break;
-                case D3DSPSM_NOT:     break;
-                case D3DSPSM_BIAS:    TRACE("_bias"); break;
-                case D3DSPSM_BIASNEG: TRACE("_bias"); break;
-                case D3DSPSM_SIGN:    TRACE("_bx2"); break;
-                case D3DSPSM_SIGNNEG: TRACE("_bx2"); break;
-                case D3DSPSM_COMP:    break;
-                case D3DSPSM_X2:      TRACE("_x2"); break;
-                case D3DSPSM_X2NEG:   TRACE("_x2"); break;
-                case D3DSPSM_DZ:      TRACE("_dz"); break;
-                case D3DSPSM_DW:      TRACE("_dw"); break;
+        if (0 != modifier) {
+            switch (modifier) {
+                case WINED3DSPSM_NONE:    break;
+                case WINED3DSPSM_NEG:     break;
+                case WINED3DSPSM_NOT:     break;
+                case WINED3DSPSM_BIAS:    TRACE("_bias"); break;
+                case WINED3DSPSM_BIASNEG: TRACE("_bias"); break;
+                case WINED3DSPSM_SIGN:    TRACE("_bx2"); break;
+                case WINED3DSPSM_SIGNNEG: TRACE("_bx2"); break;
+                case WINED3DSPSM_COMP:    break;
+                case WINED3DSPSM_X2:      TRACE("_x2"); break;
+                case WINED3DSPSM_X2NEG:   TRACE("_x2"); break;
+                case WINED3DSPSM_DZ:      TRACE("_dz"); break;
+                case WINED3DSPSM_DW:      TRACE("_dw"); break;
+                case WINED3DSPSM_ABSNEG:  TRACE(")"); break;
+                case WINED3DSPSM_ABS:     TRACE(")"); break;
                 default:
-                    TRACE("_unknown_modifier(%#lx)", mask >> D3DSP_SRCMOD_SHIFT);
+                    TRACE("_unknown_modifier(%#x)", modifier >> WINED3DSP_SRCMOD_SHIFT);
             }
         }
 
@@ -684,7 +705,7 @@ void shader_dump_param(
         * swizzle bits fields:
         *  RRGGBBAA
         */
-        if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
+        if ((WINED3DVS_NOSWIZZLE >> WINED3DVS_SWIZZLE_SHIFT) != swizzle) {
             if (swizzle_r == swizzle_g &&
                 swizzle_r == swizzle_b &&
                 swizzle_r == swizzle_a) {
@@ -712,10 +733,10 @@ void shader_generate_main(
     CONST DWORD* pFunction) {
 
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
     const DWORD *pToken = pFunction;
     const SHADER_OPCODE *curOpcode = NULL;
     SHADER_HANDLER hw_fct = NULL;
-    DWORD opcode_token;
     DWORD i;
     SHADER_OPCODE_ARG hw_arg;
 
@@ -727,7 +748,7 @@ void shader_generate_main(
 
     /* Second pass, process opcodes */
     if (NULL != pToken) {
-        while (D3DPS_END() != *pToken) {
+        while (WINED3DPS_END() != *pToken) {
 
             /* Skip version token */
             if (shader_is_version_token(*pToken)) {
@@ -737,30 +758,40 @@ void shader_generate_main(
 
             /* Skip comment tokens */
             if (shader_is_comment(*pToken)) {
-                DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
+                DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
                 ++pToken;
-                TRACE("#%s\n", (char*)pToken);
+                TRACE("#%s\n", (const char*)pToken);
                 pToken += comment_len;
                 continue;
             }
 
             /* Read opcode */
-            opcode_token = *pToken++;
-            curOpcode = shader_get_opcode(iface, opcode_token);
-            hw_fct = (curOpcode == NULL)? NULL:
-                     (wined3d_settings.shader_mode == SHADER_GLSL)?
-                         curOpcode->hw_glsl_fct : curOpcode->hw_fct;
+            hw_arg.opcode_token = *pToken++;
+            curOpcode = shader_get_opcode(iface, hw_arg.opcode_token);
+
+            /* Select handler */
+            if (curOpcode == NULL)
+                hw_fct = NULL;
+            else if (This->baseShader.shader_mode == SHADER_GLSL)
+                hw_fct = curOpcode->hw_glsl_fct;
+            else if (This->baseShader.shader_mode == SHADER_ARB)
+                hw_fct = curOpcode->hw_fct;
 
             /* Unknown opcode and its parameters */
             if (NULL == curOpcode) {
-                FIXME("Unrecognized opcode: token=%08lX\n", opcode_token);
+                FIXME("Unrecognized opcode: token=%08x\n", hw_arg.opcode_token);
                 pToken += shader_skip_unrecognized(iface, pToken); 
 
             /* Nothing to do */
-            } else if (D3DSIO_DCL == curOpcode->opcode ||
-                       D3DSIO_NOP == curOpcode->opcode) {
+            } else if (WINED3DSIO_DCL == curOpcode->opcode ||
+                       WINED3DSIO_NOP == curOpcode->opcode ||
+                       WINED3DSIO_DEF == curOpcode->opcode ||
+                       WINED3DSIO_DEFI == curOpcode->opcode ||
+                       WINED3DSIO_DEFB == curOpcode->opcode ||
+                       WINED3DSIO_PHASE == curOpcode->opcode ||
+                       WINED3DSIO_RET == curOpcode->opcode) {
 
-                pToken += shader_skip_opcode(This, curOpcode, opcode_token);
+                pToken += shader_skip_opcode(This, curOpcode, hw_arg.opcode_token);
 
             /* If a generator function is set for current shader target, use it */
             } else if (hw_fct != NULL) {
@@ -777,39 +808,33 @@ void shader_generate_main(
                 }
 
                 /* Predication token */
-                if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED) 
+                if (hw_arg.opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) 
                     hw_arg.predicate = *pToken++;
 
                 /* Other source tokens */
-                for (i = curOpcode->dst_token; i < curOpcode->num_params; i++) {
+                for (i = 0; i < (curOpcode->num_params - curOpcode->dst_token); i++) {
 
                     DWORD param, addr_token = 0; 
-
-                    /* DEF* instructions have constant src parameters, not registers */
-                    if (curOpcode->opcode == D3DSIO_DEF || 
-                        curOpcode->opcode == D3DSIO_DEFI || 
-                        curOpcode->opcode == D3DSIO_DEFB) {
-                        param = *pToken++;
-
-                    } else
-                        pToken += shader_get_param(iface, pToken, &param, &addr_token);
-
-                    hw_arg.src[i-1] = param;
-                    hw_arg.src_addr[i-1] = addr_token;
+                    pToken += shader_get_param(iface, pToken, &param, &addr_token);
+                    hw_arg.src[i] = param;
+                    hw_arg.src_addr[i] = addr_token;
                 }
 
                 /* Call appropriate function for output target */
                 hw_fct(&hw_arg);
 
+                /* Add color correction if needed */
+                device->shader_backend->shader_color_correction(&hw_arg);
+
                 /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
-                if (wined3d_settings.shader_mode == SHADER_GLSL)
+                if (This->baseShader.shader_mode == SHADER_GLSL)
                     shader_glsl_add_instruction_modifiers(&hw_arg);
 
             /* Unhandled opcode */
             } else {
 
                 FIXME("Can't handle opcode %s in hwShader\n", curOpcode->name);
-                pToken += shader_skip_opcode(This, curOpcode, opcode_token);
+                pToken += shader_skip_opcode(This, curOpcode, hw_arg.opcode_token);
             }
         }
         /* TODO: What about result.depth? */
@@ -819,8 +844,8 @@ void shader_generate_main(
 
 void shader_dump_ins_modifiers(const DWORD output) {
 
-    DWORD shift = (output & D3DSP_DSTSHIFT_MASK) >> D3DSP_DSTSHIFT_SHIFT;
-    DWORD mmask = output & D3DSP_DSTMOD_MASK;
+    DWORD shift = (output & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
+    DWORD mmask = output & WINED3DSP_DSTMOD_MASK;
 
     switch (shift) {
         case 0: break;
@@ -830,16 +855,16 @@ void shader_dump_ins_modifiers(const DWORD output) {
         case 1: TRACE("_x2"); break;
         case 2: TRACE("_x4"); break;
         case 3: TRACE("_x8"); break;
-        default: TRACE("_unhandled_shift(%ld)", shift); break;
+        default: TRACE("_unhandled_shift(%d)", shift); break;
     }
 
-    if (mmask & D3DSPDM_SATURATE)         TRACE("_sat");
-    if (mmask & D3DSPDM_PARTIALPRECISION) TRACE("_pp");
-    if (mmask & D3DSPDM_MSAMPCENTROID)    TRACE("_centroid");
+    if (mmask & WINED3DSPDM_SATURATE)         TRACE("_sat");
+    if (mmask & WINED3DSPDM_PARTIALPRECISION) TRACE("_pp");
+    if (mmask & WINED3DSPDM_MSAMPCENTROID)    TRACE("_centroid");
 
-    mmask &= ~(D3DSPDM_SATURATE | D3DSPDM_PARTIALPRECISION | D3DSPDM_MSAMPCENTROID);
+    mmask &= ~(WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_MSAMPCENTROID);
     if (mmask)
-        FIXME("_unrecognized_modifier(%#lx)", mmask >> D3DSP_DSTMOD_SHIFT);
+        FIXME("_unrecognized_modifier(%#x)", mmask >> WINED3DSP_DSTMOD_SHIFT);
 }
 
 /* First pass: trace shader, initialize length and version */
@@ -858,20 +883,20 @@ void shader_trace_init(
     TRACE("(%p) : Parsing programme\n", This);
 
     if (NULL != pToken) {
-        while (D3DVS_END() != *pToken) {
+        while (WINED3DVS_END() != *pToken) {
             if (shader_is_version_token(*pToken)) { /** version */
                 This->baseShader.hex_version = *pToken;
-                TRACE("%s_%lu_%lu\n", shader_is_pshader_version(This->baseShader.hex_version)? "ps": "vs",
-                    D3DSHADER_VERSION_MAJOR(This->baseShader.hex_version),
-                    D3DSHADER_VERSION_MINOR(This->baseShader.hex_version));
+                TRACE("%s_%u_%u\n", shader_is_pshader_version(This->baseShader.hex_version)? "ps": "vs",
+                    WINED3DSHADER_VERSION_MAJOR(This->baseShader.hex_version),
+                    WINED3DSHADER_VERSION_MINOR(This->baseShader.hex_version));
                 ++pToken;
                 ++len;
                 continue;
             }
             if (shader_is_comment(*pToken)) { /** comment */
-                DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
+                DWORD comment_len = (*pToken & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
                 ++pToken;
-                TRACE("//%s\n", (char*)pToken);
+                TRACE("//%s\n", (const char*)pToken);
                 pToken += comment_len;
                 len += comment_len + 1;
                 continue;
@@ -882,13 +907,13 @@ void shader_trace_init(
 
             if (NULL == curOpcode) {
                 int tokens_read;
-                FIXME("Unrecognized opcode: token=%08lX\n", opcode_token);
+                FIXME("Unrecognized opcode: token=%08x\n", opcode_token);
                 tokens_read = shader_skip_unrecognized(iface, pToken);
                 pToken += tokens_read;
                 len += tokens_read;
 
             } else {
-                if (curOpcode->opcode == D3DSIO_DCL) {
+                if (curOpcode->opcode == WINED3DSIO_DCL) {
 
                     DWORD usage = *pToken;
                     DWORD param = *(pToken + 1);
@@ -900,32 +925,32 @@ void shader_trace_init(
                     pToken += 2;
                     len += 2;
 
-                } else if (curOpcode->opcode == D3DSIO_DEF) {
+                } else if (curOpcode->opcode == WINED3DSIO_DEF) {
 
                         unsigned int offset = shader_get_float_offset(*pToken);
 
                         TRACE("def c%u = %f, %f, %f, %f", offset,
-                            *(float *)(pToken + 1),
-                            *(float *)(pToken + 2),
-                            *(float *)(pToken + 3),
-                            *(float *)(pToken + 4));
+                            *(const float *)(pToken + 1),
+                            *(const float *)(pToken + 2),
+                            *(const float *)(pToken + 3),
+                            *(const float *)(pToken + 4));
 
                         pToken += 5;
                         len += 5;
-                } else if (curOpcode->opcode == D3DSIO_DEFI) {
+                } else if (curOpcode->opcode == WINED3DSIO_DEFI) {
 
-                        TRACE("defi i%lu = %ld, %ld, %ld, %ld", *pToken & D3DSP_REGNUM_MASK,
-                            (long) *(pToken + 1),
-                            (long) *(pToken + 2),
-                            (long) *(pToken + 3),
-                            (long) *(pToken + 4));
+                        TRACE("defi i%u = %d, %d, %d, %d", *pToken & WINED3DSP_REGNUM_MASK,
+                            *(pToken + 1),
+                            *(pToken + 2),
+                            *(pToken + 3),
+                            *(pToken + 4));
 
                         pToken += 5;
                         len += 5;
 
-                } else if (curOpcode->opcode == D3DSIO_DEFB) {
+                } else if (curOpcode->opcode == WINED3DSIO_DEFB) {
 
-                        TRACE("defb b%lu = %s", *pToken & D3DSP_REGNUM_MASK,
+                        TRACE("defb b%u = %s", *pToken & WINED3DSP_REGNUM_MASK,
                             *(pToken + 1)? "true": "false");
 
                         pToken += 2;
@@ -938,14 +963,37 @@ void shader_trace_init(
 
                     /* Print out predication source token first - it follows
                      * the destination token. */
-                    if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED) {
+                    if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) {
                         TRACE("(");
                         shader_dump_param(iface, *(pToken + 2), 0, 1);
                         TRACE(") ");
                     }
+                    if (opcode_token & WINED3DSI_COISSUE) {
+                        /* PixWin marks instructions with the coissue flag with a '+' */
+                        TRACE("+");
+                    }
 
                     TRACE("%s", curOpcode->name);
 
+                    if (curOpcode->opcode == WINED3DSIO_IFC ||
+                        curOpcode->opcode == WINED3DSIO_BREAKC) {
+
+                        DWORD op = (opcode_token & INST_CONTROLS_MASK) >> INST_CONTROLS_SHIFT;
+                        switch (op) {
+                            case COMPARISON_GT: TRACE("_gt"); break;
+                            case COMPARISON_EQ: TRACE("_eq"); break;
+                            case COMPARISON_GE: TRACE("_ge"); break;
+                            case COMPARISON_LT: TRACE("_lt"); break;
+                            case COMPARISON_NE: TRACE("_ne"); break;
+                            case COMPARISON_LE: TRACE("_le"); break;
+                            default:
+                                TRACE("_(%u)", op);
+                        }
+                    } else if (curOpcode->opcode == WINED3DSIO_TEX &&
+                               This->baseShader.hex_version >= WINED3DPS_VERSION(2,0)) {
+                        if(opcode_token & WINED3DSI_TEXLD_PROJECT) TRACE("p");
+                    }
+
                     /* Destination token */
                     if (curOpcode->dst_token) {
 
@@ -960,7 +1008,7 @@ void shader_trace_init(
                     }
 
                     /* Predication token - already printed out, just skip it */
-                    if (opcode_token & D3DSHADER_INSTRUCTION_PREDICATED) {
+                    if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) {
                         pToken++;
                         len++;
                     }
@@ -985,4 +1033,28 @@ void shader_trace_init(
     }
 }
 
-/* TODO: Move other shared code here */
+void shader_delete_constant_list(
+    struct list* clist) {
+
+    struct list *ptr;
+    struct local_constant* constant;
+
+    ptr = list_head(clist);
+    while (ptr) {
+        constant = LIST_ENTRY(ptr, struct local_constant, entry);
+        ptr = list_next(clist, ptr);
+        HeapFree(GetProcessHeap(), 0, constant);
+    }
+}
+
+static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
+static void shader_none_select_depth_blt(IWineD3DDevice *iface) {}
+static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
+static void shader_none_cleanup(IWineD3DDevice *iface) {}
+
+const shader_backend_t none_shader_backend = {
+    &shader_none_select,
+    &shader_none_select_depth_blt,
+    &shader_none_load_constants,
+    &shader_none_cleanup
+};