winex11: Multiply the error tolerance by the table caused error magnification.
[wine/multimedia.git] / dlls / d3d9 / shader.c
blob7da93c0b454a1397a67eeb1d2040aaa80e49a79c
1 /*
2 * Copyright 2002-2003 Jason Edmeades
3 * Raphael Junqueira
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include <assert.h>
22 #include "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26 static inline IDirect3DVertexShader9Impl *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
28 return CONTAINING_RECORD(iface, IDirect3DVertexShader9Impl, IDirect3DVertexShader9_iface);
31 static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **object)
33 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
35 if (IsEqualGUID(riid, &IID_IDirect3DVertexShader9)
36 || IsEqualGUID(riid, &IID_IUnknown))
38 IDirect3DVertexShader9_AddRef(iface);
39 *object = iface;
40 return S_OK;
43 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
45 *object = NULL;
46 return E_NOINTERFACE;
49 static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
51 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
52 ULONG refcount = InterlockedIncrement(&shader->ref);
54 TRACE("%p increasing refcount to %u.\n", iface, refcount);
56 if (refcount == 1)
58 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
59 wined3d_mutex_lock();
60 wined3d_shader_incref(shader->wined3d_shader);
61 wined3d_mutex_unlock();
64 return refcount;
67 static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
69 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
70 ULONG refcount = InterlockedDecrement(&shader->ref);
72 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
74 if (!refcount)
76 IDirect3DDevice9Ex *device = shader->parentDevice;
78 wined3d_mutex_lock();
79 wined3d_shader_decref(shader->wined3d_shader);
80 wined3d_mutex_unlock();
82 /* Release the device last, as it may cause the device to be destroyed. */
83 IDirect3DDevice9Ex_Release(device);
86 return refcount;
89 static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
91 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
93 TRACE("iface %p, device %p.\n", iface, device);
95 *device = (IDirect3DDevice9 *)shader->parentDevice;
96 IDirect3DDevice9_AddRef(*device);
98 TRACE("Returning device %p.\n", *device);
100 return D3D_OK;
103 static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface,
104 void *data, UINT *data_size)
106 IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
107 HRESULT hr;
109 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
111 wined3d_mutex_lock();
112 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
113 wined3d_mutex_unlock();
115 return hr;
118 static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl =
120 /* IUnknown */
121 d3d9_vertexshader_QueryInterface,
122 d3d9_vertexshader_AddRef,
123 d3d9_vertexshader_Release,
124 /* IDirect3DVertexShader9 */
125 d3d9_vertexshader_GetDevice,
126 d3d9_vertexshader_GetFunction,
129 static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
131 HeapFree(GetProcessHeap(), 0, parent);
134 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
136 d3d9_vertexshader_wined3d_object_destroyed,
139 HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
141 HRESULT hr;
143 shader->ref = 1;
144 shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
146 wined3d_mutex_lock();
147 hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
148 shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
149 wined3d_mutex_unlock();
150 if (FAILED(hr))
152 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
153 return hr;
156 shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
157 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
159 return D3D_OK;
162 IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
164 if (!iface)
165 return NULL;
166 assert(iface->lpVtbl == &d3d9_vertexshader_vtbl);
168 return impl_from_IDirect3DVertexShader9(iface);
171 static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
173 return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, IDirect3DPixelShader9_iface);
176 static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object)
178 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
180 if (IsEqualGUID(riid, &IID_IDirect3DPixelShader9)
181 || IsEqualGUID(riid, &IID_IUnknown))
183 IDirect3DPixelShader9_AddRef(iface);
184 *object = iface;
185 return S_OK;
188 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
190 *object = NULL;
191 return E_NOINTERFACE;
194 static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
196 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
197 ULONG refcount = InterlockedIncrement(&shader->ref);
199 TRACE("%p increasing refcount to %u.\n", iface, refcount);
201 if (refcount == 1)
203 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
204 wined3d_mutex_lock();
205 wined3d_shader_incref(shader->wined3d_shader);
206 wined3d_mutex_unlock();
209 return refcount;
212 static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
214 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
215 ULONG refcount = InterlockedDecrement(&shader->ref);
217 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
219 if (!refcount)
221 IDirect3DDevice9Ex *device = shader->parentDevice;
223 wined3d_mutex_lock();
224 wined3d_shader_decref(shader->wined3d_shader);
225 wined3d_mutex_unlock();
227 /* Release the device last, as it may cause the device to be destroyed. */
228 IDirect3DDevice9Ex_Release(device);
231 return refcount;
234 static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface,
235 IDirect3DDevice9 **device)
237 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
239 TRACE("iface %p, device %p.\n", iface, device);
241 *device = (IDirect3DDevice9 *)shader->parentDevice;
242 IDirect3DDevice9_AddRef(*device);
244 TRACE("Returning device %p.\n", *device);
246 return D3D_OK;
249 static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data,
250 UINT *data_size)
252 IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
253 HRESULT hr;
255 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
257 wined3d_mutex_lock();
258 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
259 wined3d_mutex_unlock();
261 return hr;
264 static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl =
266 /* IUnknown */
267 d3d9_pixelshader_QueryInterface,
268 d3d9_pixelshader_AddRef,
269 d3d9_pixelshader_Release,
270 /* IDirect3DPixelShader9 */
271 d3d9_pixelshader_GetDevice,
272 d3d9_pixelshader_GetFunction,
275 static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
277 HeapFree(GetProcessHeap(), 0, parent);
280 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
282 d3d9_pixelshader_wined3d_object_destroyed,
285 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
287 HRESULT hr;
289 shader->ref = 1;
290 shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
292 wined3d_mutex_lock();
293 hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
294 &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
295 wined3d_mutex_unlock();
296 if (FAILED(hr))
298 WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
299 return hr;
302 shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
303 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
305 return D3D_OK;
308 IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
310 if (!iface)
311 return NULL;
312 assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
314 return impl_from_IDirect3DPixelShader9(iface);