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
;
35 hr
= shader_parse_signature(data
, data_size
, shader_info
->output_signature
);
36 if (FAILED(hr
)) return hr
;
40 shader_info
->shader_code
= (const DWORD
*)data
;
44 FIXME("Unhandled chunk %s\n", debugstr_an((const char *)&tag
, 4));
51 static HRESULT
shader_extract_from_dxbc(const void *dxbc
, SIZE_T dxbc_length
, struct d3d10_shader_info
*shader_info
)
55 shader_info
->shader_code
= NULL
;
56 memset(shader_info
->output_signature
, 0, sizeof(*shader_info
->output_signature
));
58 hr
= parse_dxbc(dxbc
, dxbc_length
, shdr_handler
, shader_info
);
59 if (!shader_info
->shader_code
) hr
= E_FAIL
;
63 ERR("Failed to parse shader, hr %#x\n", hr
);
64 shader_free_signature(shader_info
->output_signature
);
70 HRESULT
shader_parse_signature(const char *data
, DWORD data_size
, struct wined3d_shader_signature
*s
)
72 struct wined3d_shader_signature_element
*e
;
73 unsigned int string_data_offset
;
74 unsigned int string_data_size
;
75 const char *ptr
= data
;
80 read_dword(&ptr
, &count
);
81 TRACE("%u elements\n", count
);
83 skip_dword_unknown(&ptr
, 1);
85 e
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*e
));
88 ERR("Failed to allocate input signature memory.\n");
92 /* 2 DWORDs for the header, 6 for each element. */
93 string_data_offset
= 2 * sizeof(DWORD
) + count
* 6 * sizeof(DWORD
);
94 string_data_size
= data_size
- string_data_offset
;
95 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
98 ERR("Failed to allocate string data memory.\n");
99 HeapFree(GetProcessHeap(), 0, e
);
100 return E_OUTOFMEMORY
;
102 memcpy(string_data
, data
+ string_data_offset
, string_data_size
);
104 for (i
= 0; i
< count
; ++i
)
108 read_dword(&ptr
, &name_offset
);
109 e
[i
].semantic_name
= string_data
+ (name_offset
- string_data_offset
);
110 read_dword(&ptr
, &e
[i
].semantic_idx
);
111 read_dword(&ptr
, &e
[i
].sysval_semantic
);
112 read_dword(&ptr
, &e
[i
].component_type
);
113 read_dword(&ptr
, &e
[i
].register_idx
);
114 read_dword(&ptr
, &e
[i
].mask
);
116 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
117 "type %u, register idx: %u, use_mask %#x, input_mask %#x\n",
118 debugstr_a(e
[i
].semantic_name
), e
[i
].semantic_idx
, e
[i
].sysval_semantic
,
119 e
[i
].component_type
, e
[i
].register_idx
, (e
[i
].mask
>> 8) & 0xff, e
[i
].mask
& 0xff);
123 s
->element_count
= count
;
124 s
->string_data
= string_data
;
129 void shader_free_signature(struct wined3d_shader_signature
*s
)
131 HeapFree(GetProcessHeap(), 0, s
->string_data
);
132 HeapFree(GetProcessHeap(), 0, s
->elements
);
135 /* IUnknown methods */
137 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_QueryInterface(ID3D10VertexShader
*iface
,
138 REFIID riid
, void **object
)
140 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
142 if (IsEqualGUID(riid
, &IID_ID3D10VertexShader
)
143 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
144 || IsEqualGUID(riid
, &IID_IUnknown
))
146 IUnknown_AddRef(iface
);
151 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
154 return E_NOINTERFACE
;
157 static ULONG STDMETHODCALLTYPE
d3d10_vertex_shader_AddRef(ID3D10VertexShader
*iface
)
159 struct d3d10_vertex_shader
*This
= (struct d3d10_vertex_shader
*)iface
;
160 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
162 TRACE("%p increasing refcount to %u\n", This
, refcount
);
166 IWineD3DVertexShader_AddRef(This
->wined3d_shader
);
172 static ULONG STDMETHODCALLTYPE
d3d10_vertex_shader_Release(ID3D10VertexShader
*iface
)
174 struct d3d10_vertex_shader
*This
= (struct d3d10_vertex_shader
*)iface
;
175 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
177 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
181 IWineD3DVertexShader_Release(This
->wined3d_shader
);
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 static 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 static void STDMETHODCALLTYPE
d3d10_vertex_shader_wined3d_object_destroyed(void *parent
)
235 struct d3d10_vertex_shader
*shader
= parent
;
236 shader_free_signature(&shader
->output_signature
);
237 HeapFree(GetProcessHeap(), 0, shader
);
240 static const struct wined3d_parent_ops d3d10_vertex_shader_wined3d_parent_ops
=
242 d3d10_vertex_shader_wined3d_object_destroyed
,
245 HRESULT
d3d10_vertex_shader_init(struct d3d10_vertex_shader
*shader
, struct d3d10_device
*device
,
246 const void *byte_code
, SIZE_T byte_code_length
)
248 struct d3d10_shader_info shader_info
;
251 shader
->vtbl
= &d3d10_vertex_shader_vtbl
;
252 shader
->refcount
= 1;
254 shader_info
.output_signature
= &shader
->output_signature
;
255 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
258 ERR("Failed to extract shader, hr %#x.\n", hr
);
262 hr
= IWineD3DDevice_CreateVertexShader(device
->wined3d_device
, shader_info
.shader_code
,
263 &shader
->output_signature
, shader
, &d3d10_vertex_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
266 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
267 shader_free_signature(&shader
->output_signature
);
274 /* IUnknown methods */
276 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader
*iface
,
277 REFIID riid
, void **object
)
279 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
281 if (IsEqualGUID(riid
, &IID_ID3D10GeometryShader
)
282 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
283 || IsEqualGUID(riid
, &IID_IUnknown
))
285 IUnknown_AddRef(iface
);
290 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
293 return E_NOINTERFACE
;
296 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_AddRef(ID3D10GeometryShader
*iface
)
298 struct d3d10_geometry_shader
*This
= (struct d3d10_geometry_shader
*)iface
;
299 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
301 TRACE("%p increasing refcount to %u\n", This
, refcount
);
306 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_Release(ID3D10GeometryShader
*iface
)
308 struct d3d10_geometry_shader
*This
= (struct d3d10_geometry_shader
*)iface
;
309 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
311 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
315 IWineD3DGeometryShader_Release(This
->wined3d_shader
);
321 /* ID3D10DeviceChild methods */
323 static void STDMETHODCALLTYPE
d3d10_geometry_shader_GetDevice(ID3D10GeometryShader
*iface
, ID3D10Device
**device
)
325 FIXME("iface %p, device %p stub!\n", iface
, device
);
328 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader
*iface
,
329 REFGUID guid
, UINT
*data_size
, void *data
)
331 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
332 iface
, debugstr_guid(guid
), data_size
, data
);
337 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader
*iface
,
338 REFGUID guid
, UINT data_size
, const void *data
)
340 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
341 iface
, debugstr_guid(guid
), data_size
, data
);
346 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader
*iface
,
347 REFGUID guid
, const IUnknown
*data
)
349 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
354 static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl
=
356 /* IUnknown methods */
357 d3d10_geometry_shader_QueryInterface
,
358 d3d10_geometry_shader_AddRef
,
359 d3d10_geometry_shader_Release
,
360 /* ID3D10DeviceChild methods */
361 d3d10_geometry_shader_GetDevice
,
362 d3d10_geometry_shader_GetPrivateData
,
363 d3d10_geometry_shader_SetPrivateData
,
364 d3d10_geometry_shader_SetPrivateDataInterface
,
367 static void STDMETHODCALLTYPE
d3d10_geometry_shader_wined3d_object_destroyed(void *parent
)
369 struct d3d10_geometry_shader
*shader
= parent
;
370 shader_free_signature(&shader
->output_signature
);
371 HeapFree(GetProcessHeap(), 0, shader
);
374 static const struct wined3d_parent_ops d3d10_geometry_shader_wined3d_parent_ops
=
376 d3d10_geometry_shader_wined3d_object_destroyed
,
379 HRESULT
d3d10_geometry_shader_init(struct d3d10_geometry_shader
*shader
, struct d3d10_device
*device
,
380 const void *byte_code
, SIZE_T byte_code_length
)
382 struct d3d10_shader_info shader_info
;
385 shader
->vtbl
= &d3d10_geometry_shader_vtbl
;
386 shader
->refcount
= 1;
388 shader_info
.output_signature
= &shader
->output_signature
;
389 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
392 ERR("Failed to extract shader, hr %#x.\n", hr
);
396 hr
= IWineD3DDevice_CreateGeometryShader(device
->wined3d_device
, shader_info
.shader_code
,
397 &shader
->output_signature
, shader
, &d3d10_geometry_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
400 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
401 shader_free_signature(&shader
->output_signature
);
408 /* IUnknown methods */
410 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_QueryInterface(ID3D10PixelShader
*iface
,
411 REFIID riid
, void **object
)
413 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
415 if (IsEqualGUID(riid
, &IID_ID3D10PixelShader
)
416 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
417 || IsEqualGUID(riid
, &IID_IUnknown
))
419 IUnknown_AddRef(iface
);
424 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
427 return E_NOINTERFACE
;
430 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_AddRef(ID3D10PixelShader
*iface
)
432 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
433 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
435 TRACE("%p increasing refcount to %u\n", This
, refcount
);
439 IWineD3DPixelShader_AddRef(This
->wined3d_shader
);
445 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_Release(ID3D10PixelShader
*iface
)
447 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
448 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
450 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
454 IWineD3DPixelShader_Release(This
->wined3d_shader
);
460 /* ID3D10DeviceChild methods */
462 static void STDMETHODCALLTYPE
d3d10_pixel_shader_GetDevice(ID3D10PixelShader
*iface
, ID3D10Device
**device
)
464 FIXME("iface %p, device %p stub!\n", iface
, device
);
467 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader
*iface
,
468 REFGUID guid
, UINT
*data_size
, void *data
)
470 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
471 iface
, debugstr_guid(guid
), data_size
, data
);
476 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader
*iface
,
477 REFGUID guid
, UINT data_size
, const void *data
)
479 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
480 iface
, debugstr_guid(guid
), data_size
, data
);
485 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader
*iface
,
486 REFGUID guid
, const IUnknown
*data
)
488 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
493 static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl
=
495 /* IUnknown methods */
496 d3d10_pixel_shader_QueryInterface
,
497 d3d10_pixel_shader_AddRef
,
498 d3d10_pixel_shader_Release
,
499 /* ID3D10DeviceChild methods */
500 d3d10_pixel_shader_GetDevice
,
501 d3d10_pixel_shader_GetPrivateData
,
502 d3d10_pixel_shader_SetPrivateData
,
503 d3d10_pixel_shader_SetPrivateDataInterface
,
506 static void STDMETHODCALLTYPE
d3d10_pixel_shader_wined3d_object_destroyed(void *parent
)
508 struct d3d10_pixel_shader
*shader
= parent
;
509 shader_free_signature(&shader
->output_signature
);
510 HeapFree(GetProcessHeap(), 0, shader
);
513 static const struct wined3d_parent_ops d3d10_pixel_shader_wined3d_parent_ops
=
515 d3d10_pixel_shader_wined3d_object_destroyed
,
518 HRESULT
d3d10_pixel_shader_init(struct d3d10_pixel_shader
*shader
, struct d3d10_device
*device
,
519 const void *byte_code
, SIZE_T byte_code_length
)
521 struct d3d10_shader_info shader_info
;
524 shader
->vtbl
= &d3d10_pixel_shader_vtbl
;
525 shader
->refcount
= 1;
527 shader_info
.output_signature
= &shader
->output_signature
;
528 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
531 ERR("Failed to extract shader, hr %#x.\n", hr
);
535 hr
= IWineD3DDevice_CreatePixelShader(device
->wined3d_device
, shader_info
.shader_code
,
536 &shader
->output_signature
, shader
, &d3d10_pixel_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
539 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr
);
540 shader_free_signature(&shader
->output_signature
);