ReactOS 0.4.17-dev-966-gf06eace
shader.c
Go to the documentation of this file.
1/*
2 * Copyright 2002-2003 Jason Edmeades
3 * Raphael Junqueira
4 *
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.
9 *
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.
14 *
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
18 */
19
20#include "d3d9_private.h"
21
23
24static inline struct d3d9_vertexshader *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
25{
27}
28
29static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **out)
30{
31 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
32
33 if (IsEqualGUID(riid, &IID_IDirect3DVertexShader9)
35 {
37 *out = iface;
38 return S_OK;
39 }
40
41 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
42
43 *out = NULL;
44 return E_NOINTERFACE;
45}
46
47static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
48{
51
52 TRACE("%p increasing refcount to %lu.\n", iface, refcount);
53
54 if (refcount == 1)
55 {
56 IDirect3DDevice9Ex_AddRef(shader->parent_device);
57 wined3d_shader_incref(shader->wined3d_shader);
58 }
59
60 return refcount;
61}
62
63static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
64{
67
68 TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
69
70 if (!refcount)
71 {
72 IDirect3DDevice9Ex *device = shader->parent_device;
73 wined3d_shader_decref(shader->wined3d_shader);
74 /* Release the device last, as it may cause the device to be destroyed. */
76 }
77
78 return refcount;
79}
80
81static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
82{
84
85 TRACE("iface %p, device %p.\n", iface, device);
86
87 *device = (IDirect3DDevice9 *)shader->parent_device;
89
90 TRACE("Returning device %p.\n", *device);
91
92 return D3D_OK;
93}
94
95static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface, void *data, UINT *data_size)
96{
98 HRESULT hr;
99
100 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
101
103 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
105
106 return hr;
107}
108
109static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl =
110{
111 /* IUnknown */
115 /* IDirect3DVertexShader9 */
118};
119
121{
122 free(parent);
123}
124
126{
128};
129
131{
133 HRESULT hr;
134
135 shader->refcount = 1;
136 shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
137
138 desc.byte_code = byte_code;
139 desc.byte_code_size = ~(size_t)0;
140
142 hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
145 if (FAILED(hr))
146 {
147 WARN("Failed to create wined3d vertex shader, hr %#lx.\n", hr);
148 return hr;
149 }
150
151 shader->parent_device = &device->IDirect3DDevice9Ex_iface;
152 IDirect3DDevice9Ex_AddRef(shader->parent_device);
153
154 return D3D_OK;
155}
156
157struct d3d9_vertexshader *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
158{
159 if (!iface)
160 return NULL;
161 if (iface->lpVtbl != &d3d9_vertexshader_vtbl)
162 WARN("Vertex shader %p with the wrong vtbl %p\n", iface, iface->lpVtbl);
163
165}
166
167static inline struct d3d9_pixelshader *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
168{
170}
171
172static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **out)
173{
174 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
175
176 if (IsEqualGUID(riid, &IID_IDirect3DPixelShader9)
178 {
180 *out = iface;
181 return S_OK;
182 }
183
184 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
185
186 *out = NULL;
187 return E_NOINTERFACE;
188}
189
190static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
191{
194
195 TRACE("%p increasing refcount to %lu.\n", iface, refcount);
196
197 if (refcount == 1)
198 {
199 IDirect3DDevice9Ex_AddRef(shader->parent_device);
200 wined3d_shader_incref(shader->wined3d_shader);
201 }
202
203 return refcount;
204}
205
206static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
207{
210
211 TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
212
213 if (!refcount)
214 {
215 IDirect3DDevice9Ex *device = shader->parent_device;
216 wined3d_shader_decref(shader->wined3d_shader);
217 /* Release the device last, as it may cause the device to be destroyed. */
219 }
220
221 return refcount;
222}
223
224static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
225{
227
228 TRACE("iface %p, device %p.\n", iface, device);
229
230 *device = (IDirect3DDevice9 *)shader->parent_device;
232
233 TRACE("Returning device %p.\n", *device);
234
235 return D3D_OK;
236}
237
238static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, UINT *data_size)
239{
241 HRESULT hr;
242
243 TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
244
246 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
248
249 return hr;
250}
251
252static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl =
253{
254 /* IUnknown */
258 /* IDirect3DPixelShader9 */
261};
262
264{
265 free(parent);
266}
267
269{
271};
272
274{
276 HRESULT hr;
277
278 shader->refcount = 1;
279 shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
280
281 desc.byte_code = byte_code;
282 desc.byte_code_size = ~(size_t)0;
283
285 hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
288 if (FAILED(hr))
289 {
290 WARN("Failed to created wined3d pixel shader, hr %#lx.\n", hr);
291 return hr;
292 }
293
294 shader->parent_device = &device->IDirect3DDevice9Ex_iface;
295 IDirect3DDevice9Ex_AddRef(shader->parent_device);
296
297 return D3D_OK;
298}
299
300struct d3d9_pixelshader *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
301{
302 if (!iface)
303 return NULL;
304 if (iface->lpVtbl != &d3d9_pixelshader_vtbl)
305 WARN("Pixel shader %p with the wrong vtbl %p\n", iface, iface->lpVtbl);
306
308}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define IDirect3DDevice9Ex_Release(p)
Definition: d3d9.h:1930
#define IDirect3DVertexShader9_AddRef(p)
Definition: d3d9.h:1050
#define IDirect3DDevice9Ex_AddRef(p)
Definition: d3d9.h:1929
#define IDirect3DDevice9_AddRef(p)
Definition: d3d9.h:1335
#define IDirect3DPixelShader9_AddRef(p)
Definition: d3d9.h:1088
#define D3D_OK
Definition: d3d.h:106
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **out)
Definition: shader.c:172
HRESULT vertexshader_init(struct d3d9_vertexshader *shader, struct d3d9_device *device, const DWORD *byte_code)
Definition: shader.c:130
static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops
Definition: shader.c:125
static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface, void *data, UINT *data_size)
Definition: shader.c:95
struct d3d9_vertexshader * unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
Definition: shader.c:157
static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **out)
Definition: shader.c:29
static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
Definition: shader.c:190
struct d3d9_pixelshader * unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
Definition: shader.c:300
static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:263
static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
Definition: shader.c:206
static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
Definition: shader.c:224
static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl
Definition: shader.c:252
static struct d3d9_pixelshader * impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
Definition: shader.c:167
static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, UINT *data_size)
Definition: shader.c:238
static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
Definition: shader.c:120
static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
Definition: shader.c:47
static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl
Definition: shader.c:109
static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops
Definition: shader.c:268
static struct d3d9_vertexshader * impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
Definition: shader.c:24
HRESULT pixelshader_init(struct d3d9_pixelshader *shader, struct d3d9_device *device, const DWORD *byte_code)
Definition: shader.c:273
static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
Definition: shader.c:81
static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
Definition: shader.c:63
HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const struct wined3d_shader_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
Definition: shader.c:3318
ULONG CDECL wined3d_shader_incref(struct wined3d_shader *shader)
Definition: shader.c:2535
HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const struct wined3d_shader_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
Definition: shader.c:3291
HRESULT CDECL wined3d_shader_get_byte_code(const struct wined3d_shader *shader, void *byte_code, UINT *byte_code_size)
Definition: shader.c:2612
ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
Definition: shader.c:2588
unsigned int size_t
Definition: corecrt.h:203
r parent
Definition: btrfs.c:3010
DWORD IDirect3DDevice9
Definition: dxva2api.idl:22
DWORD IDirect3DDevice9Ex
Definition: dxvahd.idl:22
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint shader
Definition: glext.h:6030
unsigned int UINT
Definition: sysinfo.c:13
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define TRACE(s)
Definition: solgame.cpp:4
IDirect3DPixelShader9 IDirect3DPixelShader9_iface
Definition: d3d9_private.h:289
IDirect3DVertexShader9 IDirect3DVertexShader9_iface
Definition: d3d9_private.h:277
Definition: devices.h:37
const DWORD * byte_code
Definition: wined3d.h:2105
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define WINAPI
Definition: msvc.h:6
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
#define E_NOINTERFACE
Definition: winerror.h:3479