From 7f1c802b9fc31d36ed826692cd8d83eec9881d94 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 23 Sep 2009 18:42:11 +0200 Subject: [PATCH] d3d9: Add a separate function for pixel shader initialization. --- dlls/d3d9/d3d9_private.h | 5 ++-- dlls/d3d9/device.c | 30 ++++++++++++++++++++++++ dlls/d3d9/pixelshader.c | 50 +++++++++++----------------------------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 839ce5f5c43..6184df29f7a 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -222,8 +222,6 @@ extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDev UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface, UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN; -extern HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface, - const DWORD *pFunction, IDirect3DPixelShader9 **ppShader) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface, IDirect3DPixelShader9 *pShader) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface, @@ -551,6 +549,9 @@ typedef struct IDirect3DPixelShader9Impl { LPDIRECT3DDEVICE9EX parentDevice; } IDirect3DPixelShader9Impl; +HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, + IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN; + /* --------------- */ /* IDirect3DQuery9 */ /* --------------- */ diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 28722b27aa3..819e855519a 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1967,6 +1967,36 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetIndices(LPDIRECT3DDEVICE9EX ifac return rc; } +static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface, + const DWORD *byte_code, IDirect3DPixelShader9 **shader) +{ + IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; + IDirect3DPixelShader9Impl *object; + HRESULT hr; + + TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader); + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + { + FIXME("Failed to allocate pixel shader memory.\n"); + return E_OUTOFMEMORY; + } + + hr = pixelshader_init(object, This, byte_code); + if (FAILED(hr)) + { + WARN("Failed to initialize pixel shader, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created pixel shader %p.\n", object); + *shader = (IDirect3DPixelShader9 *)object; + + return D3D_OK; +} + static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; HRESULT hr; diff --git a/dlls/d3d9/pixelshader.c b/dlls/d3d9/pixelshader.c index 37950454521..11f275de3c9 100644 --- a/dlls/d3d9/pixelshader.c +++ b/dlls/d3d9/pixelshader.c @@ -107,49 +107,27 @@ static const IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl = IDirect3DPixelShader9Impl_GetFunction }; +HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code) +{ + HRESULT hr; -/* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow: */ -HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) { - IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; - IDirect3DPixelShader9Impl *object; - HRESULT hrc = D3D_OK; - - TRACE("(%p) Relay\n", This); - - if (ppShader == NULL) { - TRACE("(%p) Invalid call\n", This); - return D3DERR_INVALIDCALL; - } - - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); - - if (NULL == object) { - FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n"); - return E_OUTOFMEMORY; - } - - object->ref = 1; - object->lpVtbl = &Direct3DPixelShader9_Vtbl; + shader->ref = 1; + shader->lpVtbl = &Direct3DPixelShader9_Vtbl; wined3d_mutex_lock(); - hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, NULL, - &object->wineD3DPixelShader, (IUnknown *)object); + hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code, + NULL, &shader->wineD3DPixelShader, (IUnknown *)shader); wined3d_mutex_unlock(); - - if (hrc != D3D_OK) + if (FAILED(hr)) { - /* free up object */ - FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This); - HeapFree(GetProcessHeap(), 0 , object); - } else { - IDirect3DDevice9Ex_AddRef(iface); - object->parentDevice = iface; - *ppShader = (IDirect3DPixelShader9*) object; - TRACE("(%p) : Created pixel shader %p\n", This, object); + WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr); + return hr; } - TRACE("(%p) : returning %p\n", This, *ppShader); - return hrc; + shader->parentDevice = (IDirect3DDevice9Ex *)device; + IDirect3DDevice9Ex_AddRef(shader->parentDevice); + + return D3D_OK; } HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {