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
);
165 wined3d_shader_incref(This
->wined3d_shader
);
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
);
178 wined3d_shader_decref(This
->wined3d_shader
);
183 /* ID3D10DeviceChild methods */
185 static void STDMETHODCALLTYPE
d3d10_vertex_shader_GetDevice(ID3D10VertexShader
*iface
, ID3D10Device
**device
)
187 FIXME("iface %p, device %p stub!\n", iface
, device
);
190 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_GetPrivateData(ID3D10VertexShader
*iface
,
191 REFGUID guid
, UINT
*data_size
, void *data
)
193 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
194 iface
, debugstr_guid(guid
), data_size
, data
);
199 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_SetPrivateData(ID3D10VertexShader
*iface
,
200 REFGUID guid
, UINT data_size
, const void *data
)
202 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
203 iface
, debugstr_guid(guid
), data_size
, data
);
208 static HRESULT STDMETHODCALLTYPE
d3d10_vertex_shader_SetPrivateDataInterface(ID3D10VertexShader
*iface
,
209 REFGUID guid
, const IUnknown
*data
)
211 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
216 static const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl
=
218 /* IUnknown methods */
219 d3d10_vertex_shader_QueryInterface
,
220 d3d10_vertex_shader_AddRef
,
221 d3d10_vertex_shader_Release
,
222 /* ID3D10DeviceChild methods */
223 d3d10_vertex_shader_GetDevice
,
224 d3d10_vertex_shader_GetPrivateData
,
225 d3d10_vertex_shader_SetPrivateData
,
226 d3d10_vertex_shader_SetPrivateDataInterface
,
229 static void STDMETHODCALLTYPE
d3d10_vertex_shader_wined3d_object_destroyed(void *parent
)
231 struct d3d10_vertex_shader
*shader
= parent
;
232 shader_free_signature(&shader
->output_signature
);
233 HeapFree(GetProcessHeap(), 0, shader
);
236 static const struct wined3d_parent_ops d3d10_vertex_shader_wined3d_parent_ops
=
238 d3d10_vertex_shader_wined3d_object_destroyed
,
241 HRESULT
d3d10_vertex_shader_init(struct d3d10_vertex_shader
*shader
, struct d3d10_device
*device
,
242 const void *byte_code
, SIZE_T byte_code_length
)
244 struct d3d10_shader_info shader_info
;
247 shader
->vtbl
= &d3d10_vertex_shader_vtbl
;
248 shader
->refcount
= 1;
250 shader_info
.output_signature
= &shader
->output_signature
;
251 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
254 ERR("Failed to extract shader, hr %#x.\n", hr
);
258 hr
= wined3d_shader_create_vs(device
->wined3d_device
, shader_info
.shader_code
,
259 &shader
->output_signature
, shader
, &d3d10_vertex_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
262 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
263 shader_free_signature(&shader
->output_signature
);
270 static inline struct d3d10_geometry_shader
*impl_from_ID3D10GeometryShader(ID3D10GeometryShader
*iface
)
272 return CONTAINING_RECORD(iface
, struct d3d10_geometry_shader
, ID3D10GeometryShader_iface
);
275 /* IUnknown methods */
277 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader
*iface
,
278 REFIID riid
, void **object
)
280 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
282 if (IsEqualGUID(riid
, &IID_ID3D10GeometryShader
)
283 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
284 || IsEqualGUID(riid
, &IID_IUnknown
))
286 IUnknown_AddRef(iface
);
291 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
294 return E_NOINTERFACE
;
297 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_AddRef(ID3D10GeometryShader
*iface
)
299 struct d3d10_geometry_shader
*This
= impl_from_ID3D10GeometryShader(iface
);
300 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
302 TRACE("%p increasing refcount to %u\n", This
, refcount
);
307 static ULONG STDMETHODCALLTYPE
d3d10_geometry_shader_Release(ID3D10GeometryShader
*iface
)
309 struct d3d10_geometry_shader
*This
= impl_from_ID3D10GeometryShader(iface
);
310 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
312 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
315 wined3d_shader_decref(This
->wined3d_shader
);
320 /* ID3D10DeviceChild methods */
322 static void STDMETHODCALLTYPE
d3d10_geometry_shader_GetDevice(ID3D10GeometryShader
*iface
, ID3D10Device
**device
)
324 FIXME("iface %p, device %p stub!\n", iface
, device
);
327 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader
*iface
,
328 REFGUID guid
, UINT
*data_size
, void *data
)
330 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
331 iface
, debugstr_guid(guid
), data_size
, data
);
336 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader
*iface
,
337 REFGUID guid
, UINT data_size
, const void *data
)
339 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
340 iface
, debugstr_guid(guid
), data_size
, data
);
345 static HRESULT STDMETHODCALLTYPE
d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader
*iface
,
346 REFGUID guid
, const IUnknown
*data
)
348 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
353 static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl
=
355 /* IUnknown methods */
356 d3d10_geometry_shader_QueryInterface
,
357 d3d10_geometry_shader_AddRef
,
358 d3d10_geometry_shader_Release
,
359 /* ID3D10DeviceChild methods */
360 d3d10_geometry_shader_GetDevice
,
361 d3d10_geometry_shader_GetPrivateData
,
362 d3d10_geometry_shader_SetPrivateData
,
363 d3d10_geometry_shader_SetPrivateDataInterface
,
366 static void STDMETHODCALLTYPE
d3d10_geometry_shader_wined3d_object_destroyed(void *parent
)
368 struct d3d10_geometry_shader
*shader
= parent
;
369 shader_free_signature(&shader
->output_signature
);
370 HeapFree(GetProcessHeap(), 0, shader
);
373 static const struct wined3d_parent_ops d3d10_geometry_shader_wined3d_parent_ops
=
375 d3d10_geometry_shader_wined3d_object_destroyed
,
378 HRESULT
d3d10_geometry_shader_init(struct d3d10_geometry_shader
*shader
, struct d3d10_device
*device
,
379 const void *byte_code
, SIZE_T byte_code_length
)
381 struct d3d10_shader_info shader_info
;
384 shader
->ID3D10GeometryShader_iface
.lpVtbl
= &d3d10_geometry_shader_vtbl
;
385 shader
->refcount
= 1;
387 shader_info
.output_signature
= &shader
->output_signature
;
388 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
391 ERR("Failed to extract shader, hr %#x.\n", hr
);
395 hr
= wined3d_shader_create_gs(device
->wined3d_device
, shader_info
.shader_code
,
396 &shader
->output_signature
, shader
, &d3d10_geometry_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
399 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
400 shader_free_signature(&shader
->output_signature
);
407 /* IUnknown methods */
409 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_QueryInterface(ID3D10PixelShader
*iface
,
410 REFIID riid
, void **object
)
412 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
414 if (IsEqualGUID(riid
, &IID_ID3D10PixelShader
)
415 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
416 || IsEqualGUID(riid
, &IID_IUnknown
))
418 IUnknown_AddRef(iface
);
423 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
426 return E_NOINTERFACE
;
429 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_AddRef(ID3D10PixelShader
*iface
)
431 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
432 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
434 TRACE("%p increasing refcount to %u\n", This
, refcount
);
437 wined3d_shader_incref(This
->wined3d_shader
);
442 static ULONG STDMETHODCALLTYPE
d3d10_pixel_shader_Release(ID3D10PixelShader
*iface
)
444 struct d3d10_pixel_shader
*This
= (struct d3d10_pixel_shader
*)iface
;
445 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
447 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
450 wined3d_shader_decref(This
->wined3d_shader
);
455 /* ID3D10DeviceChild methods */
457 static void STDMETHODCALLTYPE
d3d10_pixel_shader_GetDevice(ID3D10PixelShader
*iface
, ID3D10Device
**device
)
459 FIXME("iface %p, device %p stub!\n", iface
, device
);
462 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader
*iface
,
463 REFGUID guid
, UINT
*data_size
, void *data
)
465 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
466 iface
, debugstr_guid(guid
), data_size
, data
);
471 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader
*iface
,
472 REFGUID guid
, UINT data_size
, const void *data
)
474 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
475 iface
, debugstr_guid(guid
), data_size
, data
);
480 static HRESULT STDMETHODCALLTYPE
d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader
*iface
,
481 REFGUID guid
, const IUnknown
*data
)
483 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
488 static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl
=
490 /* IUnknown methods */
491 d3d10_pixel_shader_QueryInterface
,
492 d3d10_pixel_shader_AddRef
,
493 d3d10_pixel_shader_Release
,
494 /* ID3D10DeviceChild methods */
495 d3d10_pixel_shader_GetDevice
,
496 d3d10_pixel_shader_GetPrivateData
,
497 d3d10_pixel_shader_SetPrivateData
,
498 d3d10_pixel_shader_SetPrivateDataInterface
,
501 static void STDMETHODCALLTYPE
d3d10_pixel_shader_wined3d_object_destroyed(void *parent
)
503 struct d3d10_pixel_shader
*shader
= parent
;
504 shader_free_signature(&shader
->output_signature
);
505 HeapFree(GetProcessHeap(), 0, shader
);
508 static const struct wined3d_parent_ops d3d10_pixel_shader_wined3d_parent_ops
=
510 d3d10_pixel_shader_wined3d_object_destroyed
,
513 HRESULT
d3d10_pixel_shader_init(struct d3d10_pixel_shader
*shader
, struct d3d10_device
*device
,
514 const void *byte_code
, SIZE_T byte_code_length
)
516 struct d3d10_shader_info shader_info
;
519 shader
->vtbl
= &d3d10_pixel_shader_vtbl
;
520 shader
->refcount
= 1;
522 shader_info
.output_signature
= &shader
->output_signature
;
523 hr
= shader_extract_from_dxbc(byte_code
, byte_code_length
, &shader_info
);
526 ERR("Failed to extract shader, hr %#x.\n", hr
);
530 hr
= wined3d_shader_create_ps(device
->wined3d_device
, shader_info
.shader_code
,
531 &shader
->output_signature
, shader
, &d3d10_pixel_shader_wined3d_parent_ops
, &shader
->wined3d_shader
);
534 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr
);
535 shader_free_signature(&shader
->output_signature
);