2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #include "d3d10core_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core
);
27 static HRESULT
shdr_handler(const char *data
, DWORD data_size
, DWORD tag
, void *ctx
)
29 struct d3d10_shader_info
*shader_info
= ctx
;
36 hr
= shader_parse_signature(data
, data_size
, shader_info
->output_signature
);
37 if (FAILED(hr
)) return hr
;
41 shader_info
->shader_code
= (const DWORD
*)data
;
45 memcpy(tag_str
, &tag
, 4);
47 FIXME("Unhandled chunk %s\n", tag_str
);
54 HRESULT
shader_extract_from_dxbc(const void *dxbc
, SIZE_T dxbc_length
, struct d3d10_shader_info
*shader_info
)
58 shader_info
->shader_code
= NULL
;
59 memset(shader_info
->output_signature
, 0, sizeof(*shader_info
->output_signature
));
61 hr
= parse_dxbc(dxbc
, dxbc_length
, shdr_handler
, shader_info
);
62 if (!shader_info
->shader_code
) hr
= E_FAIL
;
66 ERR("Failed to parse shader, hr %#x\n", hr
);
67 shader_free_signature(shader_info
->output_signature
);
73 HRESULT
shader_parse_signature(const char *data
, DWORD data_size
, struct wined3d_shader_signature
*s
)
75 struct wined3d_shader_signature_element
*e
;
76 unsigned int string_data_offset
;
77 unsigned int string_data_size
;
78 const char *ptr
= data
;
83 read_dword(&ptr
, &count
);
84 TRACE("%u elements\n", count
);
86 skip_dword_unknown(&ptr
, 1);
88 e
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*e
));
91 ERR("Failed to allocate input signature memory.\n");
95 /* 2 DWORDs for the header, 6 for each element. */
96 string_data_offset
= 2 * sizeof(DWORD
) + count
* 6 * sizeof(DWORD
);
97 string_data_size
= data_size
- string_data_offset
;
98 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
101 ERR("Failed to allocate string data memory.\n");
102 HeapFree(GetProcessHeap(), 0, e
);
103 return E_OUTOFMEMORY
;
105 memcpy(string_data
, data
+ string_data_offset
, string_data_size
);
107 for (i
= 0; i
< count
; ++i
)
111 read_dword(&ptr
, &name_offset
);
112 e
[i
].semantic_name
= string_data
+ (name_offset
- string_data_offset
);
113 read_dword(&ptr
, &e
[i
].semantic_idx
);
114 read_dword(&ptr
, &e
[i
].sysval_semantic
);
115 read_dword(&ptr
, &e
[i
].component_type
);
116 read_dword(&ptr
, &e
[i
].register_idx
);
117 read_dword(&ptr
, &e
[i
].mask
);
119 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
120 "type %u, register idx: %u, use_mask %#x, input_mask %#x\n",
121 e
[i
].semantic_name
, e
[i
].semantic_idx
, e
[i
].sysval_semantic
, e
[i
].component_type
,
122 e
[i
].register_idx
, (e
[i
].mask
>> 8) & 0xff, e
[i
].mask
& 0xff);
126 s
->element_count
= count
;
127 s
->string_data
= string_data
;
132 void shader_free_signature(struct wined3d_shader_signature
*s
)
134 HeapFree(GetProcessHeap(), 0, s
->string_data
);
135 HeapFree(GetProcessHeap(), 0, s
->elements
);
138 /* IUnknown methods */
140 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_QueryInterface(ID3D10VertexShader
*iface
,
141 REFIID riid
, void **object
)
143 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
145 if (IsEqualGUID(riid
, &IID_ID3D10VertexShader
)
146 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
147 || IsEqualGUID(riid
, &IID_IUnknown
))
149 IUnknown_AddRef(iface
);
154 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
157 return E_NOINTERFACE
;
160 static ULONG STDMETHODCALLTYPE
d3d10_vertex_shader_AddRef(ID3D10VertexShader
*iface
)
162 struct d3d10_vertex_shader
*This
= (struct d3d10_vertex_shader
*)iface
;
163 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
165 TRACE("%p increasing refcount to %u\n", This
, refcount
);
170 static ULONG STDMETHODCALLTYPE
d3d10_vertex_shader_Release(ID3D10VertexShader
*iface
)
172 struct d3d10_vertex_shader
*This
= (struct d3d10_vertex_shader
*)iface
;
173 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
175 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
179 IWineD3DVertexShader_Release(This
->wined3d_shader
);
180 shader_free_signature(&This
->output_signature
);
181 HeapFree(GetProcessHeap(), 0, This
);
187 /* ID3D10DeviceChild methods */
189 static void STDMETHODCALLTYPE
d3d10_vertex_shader_GetDevice(ID3D10VertexShader
*iface
, ID3D10Device
**device
)
191 FIXME("iface %p, device %p stub!\n", iface
, device
);
194 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_GetPrivateData(ID3D10VertexShader
*iface
,
195 REFGUID guid
, UINT
*data_size
, void *data
)
197 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
198 iface
, debugstr_guid(guid
), data_size
, data
);
203 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_SetPrivateData(ID3D10VertexShader
*iface
,
204 REFGUID guid
, UINT data_size
, const void *data
)
206 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
207 iface
, debugstr_guid(guid
), data_size
, data
);
212 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_SetPrivateDataInterface(ID3D10VertexShader
*iface
,
213 REFGUID guid
, const IUnknown
*data
)
215 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
220 const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl
=
222 /* IUnknown methods */
223 d3d10_vertex_shader_QueryInterface
,
224 d3d10_vertex_shader_AddRef
,
225 d3d10_vertex_shader_Release
,
226 /* ID3D10DeviceChild methods */
227 d3d10_vertex_shader_GetDevice
,
228 d3d10_vertex_shader_GetPrivateData
,
229 d3d10_vertex_shader_SetPrivateData
,
230 d3d10_vertex_shader_SetPrivateDataInterface
,
233 /* IUnknown methods */
235 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader
*iface
,
236 REFIID riid
, void **object
)
238 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
240 if (IsEqualGUID(riid
, &IID_ID3D10GeometryShader
)
241 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
242 || IsEqualGUID(riid
, &IID_IUnknown
))
244 IUnknown_AddRef(iface
);
249 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
252 return E_NOINTERFACE
;
255 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_AddRef(ID3D10GeometryShader
*iface
)
257 struct d3d10_geometry_shader
*This
= (struct d3d10_geometry_shader
*)iface
;
258 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
260 TRACE("%p increasing refcount to %u\n", This
, refcount
);
265 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_Release(ID3D10GeometryShader
*iface
)
267 struct d3d10_geometry_shader
*This
= (struct d3d10_geometry_shader
*)iface
;
268 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
270 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
274 HeapFree(GetProcessHeap(), 0, This
);
280 /* ID3D10DeviceChild methods */
282 static void STDMETHODCALLTYPE
d3d10_geometry_shader_GetDevice(ID3D10GeometryShader
*iface
, ID3D10Device
**device
)
284 FIXME("iface %p, device %p stub!\n", iface
, device
);
287 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader
*iface
,
288 REFGUID guid
, UINT
*data_size
, void *data
)
290 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
291 iface
, debugstr_guid(guid
), data_size
, data
);
296 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader
*iface
,
297 REFGUID guid
, UINT data_size
, const void *data
)
299 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
300 iface
, debugstr_guid(guid
), data_size
, data
);
305 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader
*iface
,
306 REFGUID guid
, const IUnknown
*data
)
308 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
313 const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl
=
315 /* IUnknown methods */
316 d3d10_geometry_shader_QueryInterface
,
317 d3d10_geometry_shader_AddRef
,
318 d3d10_geometry_shader_Release
,
319 /* ID3D10DeviceChild methods */
320 d3d10_geometry_shader_GetDevice
,
321 d3d10_geometry_shader_GetPrivateData
,
322 d3d10_geometry_shader_SetPrivateData
,
323 d3d10_geometry_shader_SetPrivateDataInterface
,
326 /* IUnknown methods */
328 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_QueryInterface(ID3D10PixelShader
*iface
,
329 REFIID riid
, void **object
)
331 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
333 if (IsEqualGUID(riid
, &IID_ID3D10PixelShader
)
334 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
335 || IsEqualGUID(riid
, &IID_IUnknown
))
337 IUnknown_AddRef(iface
);
342 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
345 return E_NOINTERFACE
;
348 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_AddRef(ID3D10PixelShader
*iface
)
350 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
351 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
353 TRACE("%p increasing refcount to %u\n", This
, refcount
);
358 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_Release(ID3D10PixelShader
*iface
)
360 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
361 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
363 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
367 IWineD3DPixelShader_Release(This
->wined3d_shader
);
368 shader_free_signature(&This
->output_signature
);
369 HeapFree(GetProcessHeap(), 0, This
);
375 /* ID3D10DeviceChild methods */
377 static void STDMETHODCALLTYPE
d3d10_pixel_shader_GetDevice(ID3D10PixelShader
*iface
, ID3D10Device
**device
)
379 FIXME("iface %p, device %p stub!\n", iface
, device
);
382 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader
*iface
,
383 REFGUID guid
, UINT
*data_size
, void *data
)
385 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
386 iface
, debugstr_guid(guid
), data_size
, data
);
391 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader
*iface
,
392 REFGUID guid
, UINT data_size
, const void *data
)
394 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
395 iface
, debugstr_guid(guid
), data_size
, data
);
400 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader
*iface
,
401 REFGUID guid
, const IUnknown
*data
)
403 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
408 const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl
=
410 /* IUnknown methods */
411 d3d10_pixel_shader_QueryInterface
,
412 d3d10_pixel_shader_AddRef
,
413 d3d10_pixel_shader_Release
,
414 /* ID3D10DeviceChild methods */
415 d3d10_pixel_shader_GetDevice
,
416 d3d10_pixel_shader_GetPrivateData
,
417 d3d10_pixel_shader_SetPrivateData
,
418 d3d10_pixel_shader_SetPrivateDataInterface
,