Index: /trunk/src/VBox/Devices/Graphics/shaderlib/shader.c
===================================================================
--- /trunk/src/VBox/Devices/Graphics/shaderlib/shader.c	(revision 82692)
+++ /trunk/src/VBox/Devices/Graphics/shaderlib/shader.c	(revision 82693)
@@ -366,11 +366,6 @@
                 {
                     unsigned int reg_idx = reg->idx;
-                    
-                    if (reg_idx >= MAX_REG_INPUT)
-                    {
-                        ERR("Invalid input register index %d.\n", reg_idx);
-                        return E_INVALIDARG;
-                    }
-                    
+                    AssertReturn(reg_idx < MAX_REG_INPUT, E_INVALIDARG);
+
                     ((IWineD3DPixelShaderImpl *)shader)->input_reg_used[reg_idx] = TRUE;
                 }
@@ -519,9 +514,5 @@
                 /* Mark input registers used. */
                 case WINED3DSPR_INPUT:
-                    if (reg_idx >= max(MAX_ATTRIBS, MAX_REG_INPUT))
-                    {
-                        ERR("Invalid input register index %d.\n", reg_idx);
-                        return E_INVALIDARG;
-                    }
+                    AssertReturn(reg_idx < max(MAX_ATTRIBS, MAX_REG_INPUT), E_INVALIDARG);
                     reg_maps->input_registers |= 1 << reg_idx;
                     shader_signature_from_semantic(&input_signature[reg_idx], &semantic);
@@ -530,9 +521,5 @@
                 /* Vertex shader: mark 3.0 output registers used, save token. */
                 case WINED3DSPR_OUTPUT:
-                    if (reg_idx >= MAX_REG_OUTPUT)
-                    {
-                        ERR("Invalid output register index %d.\n", reg_idx);
-                        return E_INVALIDARG;
-                    }
+                    AssertReturn(reg_idx < MAX_REG_OUTPUT, E_INVALIDARG);
                     reg_maps->output_registers |= 1 << reg_idx;
                     shader_signature_from_semantic(&output_signature[reg_idx], &semantic);
@@ -542,9 +529,5 @@
                 /* Save sampler usage token. */
                 case WINED3DSPR_SAMPLER:
-                    if (reg_idx >= RT_ELEMENTS(reg_maps->sampler_type))
-                    {
-                        ERR("Invalid sampler index %d.\n", reg_idx);
-                        return E_INVALIDARG;
-                    }
+                    AssertReturn(reg_idx < RT_ELEMENTS(reg_maps->sampler_type), E_INVALIDARG);
                     reg_maps->sampler_type[reg_idx] = semantic.sampler_type;
                     break;
@@ -559,11 +542,14 @@
             struct wined3d_shader_src_param rel_addr;
             struct wined3d_shader_dst_param dst;
-
-            local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            local_constant* lconst;
+
+            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
+
+            AssertReturn(dst.reg.idx < constf_size, E_INVALIDARG);
+
+            lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
             if (!lconst) return E_OUTOFMEMORY;
 
-            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
             lconst->idx = dst.reg.idx;
-
             memcpy(lconst->value, ptr, 4 * sizeof(DWORD));
             ptr += 4;
@@ -589,11 +575,14 @@
             struct wined3d_shader_src_param rel_addr;
             struct wined3d_shader_dst_param dst;
-
-            local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            local_constant* lconst;
+
+            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
+
+            AssertReturn(dst.reg.idx < MAX_CONST_I, E_INVALIDARG);
+
+            lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
             if (!lconst) return E_OUTOFMEMORY;
 
-            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
             lconst->idx = dst.reg.idx;
-
             memcpy(lconst->value, ptr, 4 * sizeof(DWORD));
             ptr += 4;
@@ -606,11 +595,14 @@
             struct wined3d_shader_src_param rel_addr;
             struct wined3d_shader_dst_param dst;
-
-            local_constant *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
+            local_constant* lconst;
+
+            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
+
+            AssertReturn(dst.reg.idx < MAX_CONST_B, E_INVALIDARG);
+
+            lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(local_constant));
             if (!lconst) return E_OUTOFMEMORY;
 
-            fe->shader_read_dst_param(fe_data, &ptr, &dst, &rel_addr);
             lconst->idx = dst.reg.idx;
-
             memcpy(lconst->value, ptr, sizeof(DWORD));
             ++ptr;
@@ -729,28 +721,25 @@
 
                 /* Declare 1.x samplers implicitly, based on the destination reg. number. */
-                if (shader_version.major == 1
-                        && (ins.handler_idx == WINED3DSIH_TEX
-                            || ins.handler_idx == WINED3DSIH_TEXBEM
-                            || ins.handler_idx == WINED3DSIH_TEXBEML
-                            || ins.handler_idx == WINED3DSIH_TEXDP3TEX
-                            || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
-                            || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
-                            || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
-                            || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
-                            || ins.handler_idx == WINED3DSIH_TEXREG2AR
-                            || ins.handler_idx == WINED3DSIH_TEXREG2GB
-                            || ins.handler_idx == WINED3DSIH_TEXREG2RGB))
+                if (ins.handler_idx == WINED3DSIH_TEX
+                    || ins.handler_idx == WINED3DSIH_TEXBEM
+                    || ins.handler_idx == WINED3DSIH_TEXBEML
+                    || ins.handler_idx == WINED3DSIH_TEXDP3TEX
+                    || ins.handler_idx == WINED3DSIH_TEXM3x2TEX
+                    || ins.handler_idx == WINED3DSIH_TEXM3x3SPEC
+                    || ins.handler_idx == WINED3DSIH_TEXM3x3TEX
+                    || ins.handler_idx == WINED3DSIH_TEXM3x3VSPEC
+                    || ins.handler_idx == WINED3DSIH_TEXREG2AR
+                    || ins.handler_idx == WINED3DSIH_TEXREG2GB
+                    || ins.handler_idx == WINED3DSIH_TEXREG2RGB)
                 {
+                    unsigned int sampler_idx;
+                    AssertReturn(shader_version.major == 1, E_INVALIDARG);
+
                     /* Fake sampler usage, only set reserved bit and type. */
-                    DWORD sampler_code = dst_param.reg.idx;
-                    
-                    if (sampler_code >= RT_ELEMENTS(reg_maps->sampler_type))
-                    {
-                        ERR("Invalid sampler index %d.\n", sampler_code);
-                        return E_INVALIDARG;
-                    }
+                    sampler_idx = dst_param.reg.idx;
+                    AssertReturn(sampler_idx < RT_ELEMENTS(reg_maps->sampler_type), E_INVALIDARG);
 
                     TRACE("Setting fake 2D sampler for 1.x pixelshader.\n");
-                    reg_maps->sampler_type[sampler_code] = WINED3DSTT_2D;
+                    reg_maps->sampler_type[sampler_idx] = WINED3DSTT_2D;
 
                     /* texbem is only valid with < 1.4 pixel shaders */
@@ -758,8 +747,8 @@
                             || ins.handler_idx == WINED3DSIH_TEXBEML)
                     {
-                        reg_maps->bumpmat |= 1 << dst_param.reg.idx;
+                        reg_maps->bumpmat |= 1 << sampler_idx;
                         if (ins.handler_idx == WINED3DSIH_TEXBEML)
                         {
-                            reg_maps->luminanceparams |= 1 << dst_param.reg.idx;
+                            reg_maps->luminanceparams |= 1 << sampler_idx;
                         }
                     }
@@ -767,5 +756,9 @@
                 else if (ins.handler_idx == WINED3DSIH_BEM)
                 {
-                    reg_maps->bumpmat |= 1 << dst_param.reg.idx;
+                    unsigned int sampler_idx = dst_param.reg.idx;
+                    AssertReturn(shader_version.major == 1, E_INVALIDARG);
+                    AssertReturn(sampler_idx < RT_ELEMENTS(reg_maps->sampler_type), E_INVALIDARG);
+
+                    reg_maps->bumpmat |= 1 << sampler_idx;
                 }
             }
