2 * Copyright 2002-2003 Jason Edmeades
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
21 #include "d3d9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
25 static inline struct d3d9_vertexshader
*impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9
*iface
)
27 return CONTAINING_RECORD(iface
, struct d3d9_vertexshader
, IDirect3DVertexShader9_iface
);
30 static HRESULT WINAPI
d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9
*iface
, REFIID riid
, void **out
)
32 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
34 if (IsEqualGUID(riid
, &IID_IDirect3DVertexShader9
)
35 || IsEqualGUID(riid
, &IID_IUnknown
))
37 IDirect3DVertexShader9_AddRef(iface
);
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
48 static ULONG WINAPI
d3d9_vertexshader_AddRef(IDirect3DVertexShader9
*iface
)
50 struct d3d9_vertexshader
*shader
= impl_from_IDirect3DVertexShader9(iface
);
51 ULONG refcount
= InterlockedIncrement(&shader
->refcount
);
53 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
57 IDirect3DDevice9Ex_AddRef(shader
->parent_device
);
59 wined3d_shader_incref(shader
->wined3d_shader
);
60 wined3d_mutex_unlock();
66 static ULONG WINAPI
d3d9_vertexshader_Release(IDirect3DVertexShader9
*iface
)
68 struct d3d9_vertexshader
*shader
= impl_from_IDirect3DVertexShader9(iface
);
69 ULONG refcount
= InterlockedDecrement(&shader
->refcount
);
71 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
75 IDirect3DDevice9Ex
*device
= shader
->parent_device
;
78 wined3d_shader_decref(shader
->wined3d_shader
);
79 wined3d_mutex_unlock();
81 /* Release the device last, as it may cause the device to be destroyed. */
82 IDirect3DDevice9Ex_Release(device
);
88 static HRESULT WINAPI
d3d9_vertexshader_GetDevice(IDirect3DVertexShader9
*iface
, IDirect3DDevice9
**device
)
90 struct d3d9_vertexshader
*shader
= impl_from_IDirect3DVertexShader9(iface
);
92 TRACE("iface %p, device %p.\n", iface
, device
);
94 *device
= (IDirect3DDevice9
*)shader
->parent_device
;
95 IDirect3DDevice9_AddRef(*device
);
97 TRACE("Returning device %p.\n", *device
);
102 static HRESULT WINAPI
d3d9_vertexshader_GetFunction(IDirect3DVertexShader9
*iface
, void *data
, UINT
*data_size
)
104 struct d3d9_vertexshader
*shader
= impl_from_IDirect3DVertexShader9(iface
);
107 TRACE("iface %p, data %p, data_size %p.\n", iface
, data
, data_size
);
109 wined3d_mutex_lock();
110 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, data
, data_size
);
111 wined3d_mutex_unlock();
116 static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl
=
119 d3d9_vertexshader_QueryInterface
,
120 d3d9_vertexshader_AddRef
,
121 d3d9_vertexshader_Release
,
122 /* IDirect3DVertexShader9 */
123 d3d9_vertexshader_GetDevice
,
124 d3d9_vertexshader_GetFunction
,
127 static void STDMETHODCALLTYPE
d3d9_vertexshader_wined3d_object_destroyed(void *parent
)
129 HeapFree(GetProcessHeap(), 0, parent
);
132 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops
=
134 d3d9_vertexshader_wined3d_object_destroyed
,
137 HRESULT
vertexshader_init(struct d3d9_vertexshader
*shader
, struct d3d9_device
*device
, const DWORD
*byte_code
)
139 struct wined3d_shader_desc desc
;
142 shader
->refcount
= 1;
143 shader
->IDirect3DVertexShader9_iface
.lpVtbl
= &d3d9_vertexshader_vtbl
;
145 desc
.byte_code
= byte_code
;
146 desc
.byte_code_size
= ~(size_t)0;
147 desc
.format
= WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
;
148 desc
.input_signature
.element_count
= 0;
149 desc
.output_signature
.element_count
= 0;
150 desc
.patch_constant_signature
.element_count
= 0;
151 desc
.max_version
= 3;
153 wined3d_mutex_lock();
154 hr
= wined3d_shader_create_vs(device
->wined3d_device
, &desc
, shader
,
155 &d3d9_vertexshader_wined3d_parent_ops
, &shader
->wined3d_shader
);
156 wined3d_mutex_unlock();
159 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
163 shader
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
164 IDirect3DDevice9Ex_AddRef(shader
->parent_device
);
169 struct d3d9_vertexshader
*unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9
*iface
)
173 if (iface
->lpVtbl
!= &d3d9_vertexshader_vtbl
)
174 WARN("Vertex shader %p with the wrong vtbl %p\n", iface
, iface
->lpVtbl
);
176 return impl_from_IDirect3DVertexShader9(iface
);
179 static inline struct d3d9_pixelshader
*impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9
*iface
)
181 return CONTAINING_RECORD(iface
, struct d3d9_pixelshader
, IDirect3DPixelShader9_iface
);
184 static HRESULT WINAPI
d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9
*iface
, REFIID riid
, void **out
)
186 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
188 if (IsEqualGUID(riid
, &IID_IDirect3DPixelShader9
)
189 || IsEqualGUID(riid
, &IID_IUnknown
))
191 IDirect3DPixelShader9_AddRef(iface
);
196 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
199 return E_NOINTERFACE
;
202 static ULONG WINAPI
d3d9_pixelshader_AddRef(IDirect3DPixelShader9
*iface
)
204 struct d3d9_pixelshader
*shader
= impl_from_IDirect3DPixelShader9(iface
);
205 ULONG refcount
= InterlockedIncrement(&shader
->refcount
);
207 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
211 IDirect3DDevice9Ex_AddRef(shader
->parent_device
);
212 wined3d_mutex_lock();
213 wined3d_shader_incref(shader
->wined3d_shader
);
214 wined3d_mutex_unlock();
220 static ULONG WINAPI
d3d9_pixelshader_Release(IDirect3DPixelShader9
*iface
)
222 struct d3d9_pixelshader
*shader
= impl_from_IDirect3DPixelShader9(iface
);
223 ULONG refcount
= InterlockedDecrement(&shader
->refcount
);
225 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
229 IDirect3DDevice9Ex
*device
= shader
->parent_device
;
231 wined3d_mutex_lock();
232 wined3d_shader_decref(shader
->wined3d_shader
);
233 wined3d_mutex_unlock();
235 /* Release the device last, as it may cause the device to be destroyed. */
236 IDirect3DDevice9Ex_Release(device
);
242 static HRESULT WINAPI
d3d9_pixelshader_GetDevice(IDirect3DPixelShader9
*iface
, IDirect3DDevice9
**device
)
244 struct d3d9_pixelshader
*shader
= impl_from_IDirect3DPixelShader9(iface
);
246 TRACE("iface %p, device %p.\n", iface
, device
);
248 *device
= (IDirect3DDevice9
*)shader
->parent_device
;
249 IDirect3DDevice9_AddRef(*device
);
251 TRACE("Returning device %p.\n", *device
);
256 static HRESULT WINAPI
d3d9_pixelshader_GetFunction(IDirect3DPixelShader9
*iface
, void *data
, UINT
*data_size
)
258 struct d3d9_pixelshader
*shader
= impl_from_IDirect3DPixelShader9(iface
);
261 TRACE("iface %p, data %p, data_size %p.\n", iface
, data
, data_size
);
263 wined3d_mutex_lock();
264 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, data
, data_size
);
265 wined3d_mutex_unlock();
270 static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl
=
273 d3d9_pixelshader_QueryInterface
,
274 d3d9_pixelshader_AddRef
,
275 d3d9_pixelshader_Release
,
276 /* IDirect3DPixelShader9 */
277 d3d9_pixelshader_GetDevice
,
278 d3d9_pixelshader_GetFunction
,
281 static void STDMETHODCALLTYPE
d3d9_pixelshader_wined3d_object_destroyed(void *parent
)
283 HeapFree(GetProcessHeap(), 0, parent
);
286 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops
=
288 d3d9_pixelshader_wined3d_object_destroyed
,
291 HRESULT
pixelshader_init(struct d3d9_pixelshader
*shader
, struct d3d9_device
*device
, const DWORD
*byte_code
)
293 struct wined3d_shader_desc desc
;
296 shader
->refcount
= 1;
297 shader
->IDirect3DPixelShader9_iface
.lpVtbl
= &d3d9_pixelshader_vtbl
;
299 desc
.byte_code
= byte_code
;
300 desc
.byte_code_size
= ~(size_t)0;
301 desc
.format
= WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
;
302 desc
.input_signature
.element_count
= 0;
303 desc
.output_signature
.element_count
= 0;
304 desc
.patch_constant_signature
.element_count
= 0;
305 desc
.max_version
= 3;
307 wined3d_mutex_lock();
308 hr
= wined3d_shader_create_ps(device
->wined3d_device
, &desc
, shader
,
309 &d3d9_pixelshader_wined3d_parent_ops
, &shader
->wined3d_shader
);
310 wined3d_mutex_unlock();
313 WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr
);
317 shader
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
318 IDirect3DDevice9Ex_AddRef(shader
->parent_device
);
323 struct d3d9_pixelshader
*unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9
*iface
)
327 if (iface
->lpVtbl
!= &d3d9_pixelshader_vtbl
)
328 WARN("Pixel shader %p with the wrong vtbl %p\n", iface
, iface
->lpVtbl
);
330 return impl_from_IDirect3DPixelShader9(iface
);