static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
+ TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
+
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
- IUnknown_AddRef(iface);
+ IDirect3DVertexShader9_AddRef(iface);
*ppobj = This;
return S_OK;
}
IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
- TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+ TRACE("%p increasing refcount to %u.\n", iface, ref);
+
+ if (ref == 1)
+ {
+ IDirect3DDevice9Ex_AddRef(This->parentDevice);
+ wined3d_mutex_lock();
+ IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
+ wined3d_mutex_unlock();
+ }
return ref;
}
IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
- TRACE("(%p) : ReleaseRef to %d\n", This, ref);
+ TRACE("%p decreasing refcount to %u.\n", iface, ref);
if (ref == 0) {
- EnterCriticalSection(&d3d9_cs);
+ IDirect3DDevice9Ex *parentDevice = This->parentDevice;
+
+ wined3d_mutex_lock();
IWineD3DVertexShader_Release(This->wineD3DVertexShader);
- LeaveCriticalSection(&d3d9_cs);
- IUnknown_Release(This->parentDevice);
- HeapFree(GetProcessHeap(), 0, This);
+ wined3d_mutex_unlock();
+
+ /* Release the device last, as it may cause the device to be destroyed. */
+ IDirect3DDevice9Ex_Release(parentDevice);
}
return ref;
}
/* IDirect3DVertexShader9 Interface follow: */
-static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
+static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
+{
IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
- IWineD3DDevice *myDevice = NULL;
- HRESULT hr = D3D_OK;
- TRACE("(%p) : Relay\n", This);
-
- EnterCriticalSection(&d3d9_cs);
- if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
- hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
- IWineD3DDevice_Release(myDevice);
- } else {
- *ppDevice = NULL;
- }
- LeaveCriticalSection(&d3d9_cs);
- TRACE("(%p) returning (%p)\n", This, *ppDevice);
- return hr;
+
+ TRACE("iface %p, device %p.\n", iface, device);
+
+ *device = (IDirect3DDevice9 *)This->parentDevice;
+ IDirect3DDevice9_AddRef(*device);
+
+ TRACE("Returning device %p.\n", *device);
+
+ return D3D_OK;
}
static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
+
+ wined3d_mutex_lock();
hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
IDirect3DVertexShader9Impl_GetFunction
};
+static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
+{
+ HeapFree(GetProcessHeap(), 0, parent);
+}
-/* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
-HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
- IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
- HRESULT hrc = D3D_OK;
- IDirect3DVertexShader9Impl *object;
-
- /* Setup a stub object for now */
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
- TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
- if (NULL == object) {
- FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
- return D3DERR_OUTOFVIDEOMEMORY;
- }
+static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
+{
+ d3d9_vertexshader_wined3d_object_destroyed,
+};
+
+HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
+{
+ HRESULT hr;
- object->ref = 1;
- object->lpVtbl = &Direct3DVertexShader9_Vtbl;
- EnterCriticalSection(&d3d9_cs);
- hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, NULL /* declaration */, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
- LeaveCriticalSection(&d3d9_cs);
-
- if (FAILED(hrc)) {
-
- /* free up object */
- FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
- HeapFree(GetProcessHeap(), 0, object);
- }else{
- IUnknown_AddRef(iface);
- object->parentDevice = iface;
- *ppShader = (IDirect3DVertexShader9 *)object;
- TRACE("(%p) : Created vertex shader %p\n", This, object);
+ shader->ref = 1;
+ shader->lpVtbl = &Direct3DVertexShader9_Vtbl;
+
+ wined3d_mutex_lock();
+ hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
+ NULL /* output signature */, &shader->wineD3DVertexShader,
+ (IUnknown *)shader, &d3d9_vertexshader_wined3d_parent_ops);
+ wined3d_mutex_unlock();
+ if (FAILED(hr))
+ {
+ WARN("Failed to create wined3d vertex 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_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hrc = D3D_OK;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, shader %p.\n", iface, pShader);
+
+ wined3d_mutex_lock();
hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
TRACE("(%p) : returning hr(%u)\n", This, hrc);
return hrc;
IWineD3DVertexShader *pShader;
HRESULT hrc = D3D_OK;
- TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, shader %p.\n", iface, ppShader);
+
+ wined3d_mutex_lock();
hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
- if(hrc == D3D_OK && pShader != NULL){
- hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
- IWineD3DVertexShader_Release(pShader);
- } else {
+ if (SUCCEEDED(hrc))
+ {
+ if (pShader)
+ {
+ hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
+ IWineD3DVertexShader_Release(pShader);
+ }
+ else
+ {
+ *ppShader = NULL;
+ }
+ }
+ else
+ {
WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
}
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
TRACE("(%p) : returning %p\n", This, *ppShader);
return hrc;
}
HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, Vector4fCount);
+
+ if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
+ WARN("Trying to access %u constants, but d3d9 only supports %u\n",
+ Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
+ return D3DERR_INVALIDCALL;
+ }
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, Vector4fCount);
+
+ if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
+ WARN("Trying to access %u constants, but d3d9 only supports %u\n",
+ Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
+ return D3DERR_INVALIDCALL;
+ }
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, Vector4iCount);
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, Vector4iCount);
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, BoolCount);
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}
HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
- TRACE("(%p) : Relay\n", This);
- EnterCriticalSection(&d3d9_cs);
+ TRACE("iface %p, register %u, data %p, count %u.\n",
+ iface, Register, pConstantData, BoolCount);
+
+ wined3d_mutex_lock();
hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
- LeaveCriticalSection(&d3d9_cs);
+ wined3d_mutex_unlock();
+
return hr;
}