Henri Verbeet : d3d8: Add a separate function for pixel shader initialization.

Alexandre Julliard julliard at winehq.org
Thu Sep 24 10:54:28 CDT 2009


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

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Wed Sep 23 18:42:12 2009 +0200

d3d8: Add a separate function for pixel shader initialization.

---

 dlls/d3d8/d3d8_private.h |   14 ++---------
 dlls/d3d8/device.c       |   52 ++++++++++++++++++++++++---------------------
 dlls/d3d8/pixelshader.c  |   24 ++++++++++++++++++++-
 3 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 89d05c9..8adc9e3 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -603,17 +603,6 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im
 
 #define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
 
-
-/* ------------------------ */
-/* IDirect3DPixelShaderImpl */
-/* ------------------------ */
-
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl DECLSPEC_HIDDEN;
-
 /*****************************************************************************
  * IDirect3DPixelShader implementation structure
  */
@@ -625,6 +614,9 @@ typedef struct IDirect3DPixelShader8Impl {
     IWineD3DPixelShader             *wineD3DPixelShader;
 } IDirect3DPixelShader8Impl;
 
+HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
+
 /**
  * Internals functions
  *
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 3bb329f..4686f9a 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -2094,15 +2094,20 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, I
 
     return rc;
 }
-static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
+        const DWORD *byte_code, DWORD *shader)
+{
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DPixelShader8Impl *object;
+    DWORD shader_handle;
     DWORD handle;
     HRESULT hr;
 
-    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
+    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
 
-    if (NULL == ppShader) {
+    if (!shader)
+    {
         TRACE("(%p) Invalid call\n", This);
         return D3DERR_INVALIDCALL;
     }
@@ -2110,39 +2115,38 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 i
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
-        ERR("Failed to allocate memmory.\n");
+        ERR("Failed to allocate pixel shader memmory.\n");
         return E_OUTOFMEMORY;
     }
 
-    object->ref    = 1;
-    object->lpVtbl = &Direct3DPixelShader8_Vtbl;
-
     wined3d_mutex_lock();
-    hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
-            NULL, &object->wineD3DPixelShader, (IUnknown *)object);
-    if (FAILED(hr))
-    {
-        wined3d_mutex_unlock();
-        FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
-        HeapFree(GetProcessHeap(), 0 , object);
-        *ppShader = 0;
-        return hr;
-    }
-
     handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
     wined3d_mutex_unlock();
-
     if (handle == D3D8_INVALID_HANDLE)
     {
-        ERR("Failed to allocate shader handle\n");
-        IDirect3DVertexShader8_Release((IUnknown *)object);
+        ERR("Failed to allocate pixel shader handle.\n");
+        HeapFree(GetProcessHeap(), 0, object);
         return E_OUTOFMEMORY;
     }
 
-    *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
-    TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
+    shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
 
-    return hr;
+    hr = pixelshader_init(object, This, byte_code, shader_handle);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
+        wined3d_mutex_lock();
+        d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
+        wined3d_mutex_unlock();
+        HeapFree(GetProcessHeap(), 0, object);
+        *shader = 0;
+        return hr;
+    }
+
+    TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
+    *shader = shader_handle;
+
+    return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
diff --git a/dlls/d3d8/pixelshader.c b/dlls/d3d8/pixelshader.c
index 2f0fb1c..3f5ed9e 100644
--- a/dlls/d3d8/pixelshader.c
+++ b/dlls/d3d8/pixelshader.c
@@ -65,10 +65,32 @@ static ULONG WINAPI IDirect3DPixelShader8Impl_Release(IDirect3DPixelShader8 * if
     return ref;
 }
 
-const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
+static const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
 {
     /* IUnknown */
     IDirect3DPixelShader8Impl_QueryInterface,
     IDirect3DPixelShader8Impl_AddRef,
     IDirect3DPixelShader8Impl_Release,
 };
+
+HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *byte_code, DWORD shader_handle)
+{
+    HRESULT hr;
+
+    shader->ref = 1;
+    shader->lpVtbl = &Direct3DPixelShader8_Vtbl;
+    shader->handle = shader_handle;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
+            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return D3D_OK;
+}




More information about the wine-cvs mailing list