Henri Verbeet : wined3d: Shaders will never have a NULL function.

Alexandre Julliard julliard at winehq.org
Tue Dec 16 08:40:35 CST 2008


Module: wine
Branch: master
Commit: f3743fb402351922f1b4fdf505fd92f2dbabcb15
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f3743fb402351922f1b4fdf505fd92f2dbabcb15

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Mon Dec 15 16:35:14 2008 +0100

wined3d: Shaders will never have a NULL function.

---

 dlls/wined3d/baseshader.c            |   15 ---------------
 dlls/wined3d/nvidia_texture_shader.c |    7 ++-----
 dlls/wined3d/pixelshader.c           |   25 ++++++++-----------------
 dlls/wined3d/state.c                 |   18 ++++--------------
 dlls/wined3d/vertexshader.c          |   30 +++++++-----------------------
 dlls/wined3d/wined3d_private.h       |    4 +---
 6 files changed, 22 insertions(+), 77 deletions(-)

diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c
index 392c512..9cc0e2b 100644
--- a/dlls/wined3d/baseshader.c
+++ b/dlls/wined3d/baseshader.c
@@ -216,13 +216,6 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, struct shader_reg_m
     memset(reg_maps->bumpmat, 0, sizeof(reg_maps->bumpmat));
     memset(reg_maps->luminanceparams, 0, sizeof(reg_maps->luminanceparams));
 
-    if (!pToken)
-    {
-        WARN("Got a NULL pFunction, returning.\n");
-        This->baseShader.functionLength = 0;
-        return WINED3D_OK;
-    }
-
     /* get_registers_used is called on every compile on some 1.x shaders, which can result
      * in stacking up a collection of local constants. Delete the old constants if existing
      */
@@ -844,8 +837,6 @@ void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer,
     hw_arg.reg_maps = reg_maps;
     This->baseShader.parse_state.current_row = 0;
 
-    if (!pToken) return;
-
     while (WINED3DPS_END() != *pToken)
     {
         /* Skip version token */
@@ -970,12 +961,6 @@ void shader_trace_init(const DWORD *pFunction, const SHADER_OPCODE *opcode_table
 
     TRACE("Parsing %p\n", pFunction);
 
-    if (!pFunction)
-    {
-        WARN("Got a NULL pFunction, returning.\n");
-        return;
-    }
-
     /* The version token is supposed to be the first token */
     if (!shader_is_version_token(*pToken))
     {
diff --git a/dlls/wined3d/nvidia_texture_shader.c b/dlls/wined3d/nvidia_texture_shader.c
index 1b31c74..e761288 100644
--- a/dlls/wined3d/nvidia_texture_shader.c
+++ b/dlls/wined3d/nvidia_texture_shader.c
@@ -457,11 +457,8 @@ static void nvrc_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3
 
     TRACE("Setting color op for stage %d\n", stage);
 
-    if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
-        ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
-        /* Using a pixel shader? Don't care for anything here, the shader applying does it */
-        return;
-    }
+    /* Using a pixel shader? Don't care for anything here, the shader applying does it */
+    if (use_ps(stateblock->wineD3DDevice)) return;
 
     if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
 
diff --git a/dlls/wined3d/pixelshader.c b/dlls/wined3d/pixelshader.c
index f3d4386..1dd3888 100644
--- a/dlls/wined3d/pixelshader.c
+++ b/dlls/wined3d/pixelshader.c
@@ -115,13 +115,10 @@ static HRESULT  WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader*
      * return D3DERR_MOREDATA. That's not actually true. */
     return WINED3DERR_INVALIDCALL;
   }
-  if (NULL == This->baseShader.function) { /* no function defined */
-    TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
-    (*(DWORD **) pData) = NULL;
-  } else {
-    TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-    memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
-  }
+
+  TRACE("(%p) : GetFunction copying to %p\n", This, pData);
+  memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
+
   return WINED3D_OK;
 }
 
@@ -382,16 +379,10 @@ static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *i
     This->baseShader.shader_mode = deviceImpl->ps_selected_mode;
 
     TRACE("(%p) : Copying the function\n", This);
-    if (NULL != pFunction) {
-        void *function;
 
-        function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
-        if (!function) return E_OUTOFMEMORY;
-        memcpy(function, pFunction, This->baseShader.functionLength);
-        This->baseShader.function = function;
-    } else {
-        This->baseShader.function = NULL;
-    }
+    This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
+    if (!This->baseShader.function) return E_OUTOFMEMORY;
+    memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
 
     return WINED3D_OK;
 }
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index ccaf6f5..085e3d4 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -2917,11 +2917,8 @@ static void tex_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3D
 
     TRACE("Setting color op for stage %d\n", stage);
 
-    if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
-        ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
-        /* Using a pixel shader? Don't care for anything here, the shader applying does it */
-        return;
-    }
+    /* Using a pixel shader? Don't care for anything here, the shader applying does it */
+    if (use_ps(stateblock->wineD3DDevice)) return;
 
     if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
 
@@ -4365,13 +4362,7 @@ static void streamsrc(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo
     BOOL load_numbered = FALSE;
     BOOL load_named = FALSE;
 
-    if (device->vs_selected_mode != SHADER_NONE && stateblock->vertexShader &&
-        ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function != NULL) {
-        useVertexShaderFunction = TRUE;
-    } else {
-        useVertexShaderFunction = FALSE;
-    }
-
+    useVertexShaderFunction = (device->vs_selected_mode != SHADER_NONE && stateblock->vertexShader) ? TRUE : FALSE;
 
     if(device->up_strided) {
         /* Note: this is a ddraw fixed-function code path */
@@ -4459,8 +4450,7 @@ static void streamsrc(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo
 
 static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
     BOOL useVertexShaderFunction = FALSE, updateFog = FALSE;
-    BOOL usePixelShaderFunction = stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE && stateblock->pixelShader
-            && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function;
+    BOOL usePixelShaderFunction = use_ps(stateblock->wineD3DDevice);
     BOOL transformed;
     /* Some stuff is in the device until we have per context tracking */
     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index ef55f67..063f576 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -412,13 +412,10 @@ static HRESULT WINAPI IWineD3DVertexShaderImpl_GetFunction(IWineD3DVertexShader*
          * return D3DERR_MOREDATA. That's not actually true. */
         return WINED3DERR_INVALIDCALL;
     }
-    if (NULL == This->baseShader.function) { /* no function defined */
-        TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
-        (*(DWORD **) pData) = NULL;
-    } else {
-        TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-        memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
-    }
+
+    TRACE("(%p) : GetFunction copying to %p\n", This, pData);
+    memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
+
     return WINED3D_OK;
 }
 
@@ -474,16 +471,9 @@ static HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader
     This->baseShader.load_local_constsF = This->baseShader.reg_maps.usesrelconstF && !list_empty(&This->baseShader.constantsF);
 
     /* copy the function ... because it will certainly be released by application */
-    if (NULL != pFunction) {
-        void *function;
-
-        function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
-        if (!function) return E_OUTOFMEMORY;
-        memcpy(function, pFunction, This->baseShader.functionLength);
-        This->baseShader.function = function;
-    } else {
-        This->baseShader.function = NULL;
-    }
+    This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
+    if (!This->baseShader.function) return E_OUTOFMEMORY;
+    memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
 
     return WINED3D_OK;
 }
@@ -611,12 +601,6 @@ HRESULT IWineD3DVertexShaderImpl_CompileShader(IWineD3DVertexShader *iface) {
         deviceImpl->shader_backend->shader_destroy((IWineD3DBaseShader *) iface);
     }
 
-    /* We don't need to compile */
-    if (!function) {
-        This->baseShader.is_compiled = TRUE;
-        return WINED3D_OK;
-    }
-
     /* Generate the HW shader */
     TRACE("(%p) : Generating hardware program\n", This);
     IWineD3DVertexShaderImpl_GenerateShader(iface, &This->baseShader.reg_maps, function);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index a660581..9500031 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2465,14 +2465,12 @@ const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt,
 static inline BOOL use_vs(IWineD3DDeviceImpl *device) {
     return (device->vs_selected_mode != SHADER_NONE
             && device->stateBlock->vertexShader
-            && ((IWineD3DVertexShaderImpl *)device->stateBlock->vertexShader)->baseShader.function
             && !device->strided_streams.u.s.position_transformed);
 }
 
 static inline BOOL use_ps(IWineD3DDeviceImpl *device) {
     return (device->ps_selected_mode != SHADER_NONE
-            && device->stateBlock->pixelShader
-            && ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->baseShader.function);
+            && device->stateBlock->pixelShader);
 }
 
 void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,




More information about the wine-cvs mailing list