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 IWineD3DBaseShader_AddRef(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 IWineD3DBaseShader_Release(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 = IWineD3DDevice_CreateVertexShader(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 /* IUnknown methods */
272 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader *iface,
273 REFIID riid, void **object)
275 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
277 if (IsEqualGUID(riid, &IID_ID3D10GeometryShader)
278 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
279 || IsEqualGUID(riid, &IID_IUnknown))
281 IUnknown_AddRef(iface);
286 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
289 return E_NOINTERFACE;
292 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_AddRef(ID3D10GeometryShader *iface)
294 struct d3d10_geometry_shader *This = (struct d3d10_geometry_shader *)iface;
295 ULONG refcount = InterlockedIncrement(&This->refcount);
297 TRACE("%p increasing refcount to %u\n", This, refcount);
302 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_Release(ID3D10GeometryShader *iface)
304 struct d3d10_geometry_shader *This = (struct d3d10_geometry_shader *)iface;
305 ULONG refcount = InterlockedDecrement(&This->refcount);
307 TRACE("%p decreasing refcount to %u\n", This, refcount);
310 IWineD3DBaseShader_Release(This->wined3d_shader);
315 /* ID3D10DeviceChild methods */
317 static void STDMETHODCALLTYPE d3d10_geometry_shader_GetDevice(ID3D10GeometryShader *iface, ID3D10Device **device)
319 FIXME("iface %p, device %p stub!\n", iface, device);
322 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader *iface,
323 REFGUID guid, UINT *data_size, void *data)
325 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
326 iface, debugstr_guid(guid), data_size, data);
331 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader *iface,
332 REFGUID guid, UINT data_size, const void *data)
334 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
335 iface, debugstr_guid(guid), data_size, data);
340 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader *iface,
341 REFGUID guid, const IUnknown *data)
343 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
348 static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
350 /* IUnknown methods */
351 d3d10_geometry_shader_QueryInterface,
352 d3d10_geometry_shader_AddRef,
353 d3d10_geometry_shader_Release,
354 /* ID3D10DeviceChild methods */
355 d3d10_geometry_shader_GetDevice,
356 d3d10_geometry_shader_GetPrivateData,
357 d3d10_geometry_shader_SetPrivateData,
358 d3d10_geometry_shader_SetPrivateDataInterface,
361 static void STDMETHODCALLTYPE d3d10_geometry_shader_wined3d_object_destroyed(void *parent)
363 struct d3d10_geometry_shader *shader = parent;
364 shader_free_signature(&shader->output_signature);
365 HeapFree(GetProcessHeap(), 0, shader);
368 static const struct wined3d_parent_ops d3d10_geometry_shader_wined3d_parent_ops =
370 d3d10_geometry_shader_wined3d_object_destroyed,
373 HRESULT d3d10_geometry_shader_init(struct d3d10_geometry_shader *shader, struct d3d10_device *device,
374 const void *byte_code, SIZE_T byte_code_length)
376 struct d3d10_shader_info shader_info;
379 shader->vtbl = &d3d10_geometry_shader_vtbl;
380 shader->refcount = 1;
382 shader_info.output_signature = &shader->output_signature;
383 hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
386 ERR("Failed to extract shader, hr %#x.\n", hr);
390 hr = IWineD3DDevice_CreateGeometryShader(device->wined3d_device, shader_info.shader_code,
391 &shader->output_signature, shader, &d3d10_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader);
394 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
395 shader_free_signature(&shader->output_signature);
402 /* IUnknown methods */
404 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_QueryInterface(ID3D10PixelShader *iface,
405 REFIID riid, void **object)
407 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
409 if (IsEqualGUID(riid, &IID_ID3D10PixelShader)
410 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
411 || IsEqualGUID(riid, &IID_IUnknown))
413 IUnknown_AddRef(iface);
418 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
421 return E_NOINTERFACE;
424 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_AddRef(ID3D10PixelShader *iface)
426 struct d3d10_pixel_shader *This = (struct d3d10_pixel_shader *)iface;
427 ULONG refcount = InterlockedIncrement(&This->refcount);
429 TRACE("%p increasing refcount to %u\n", This, refcount);
432 IWineD3DBaseShader_AddRef(This->wined3d_shader);
437 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_Release(ID3D10PixelShader *iface)
439 struct d3d10_pixel_shader *This = (struct d3d10_pixel_shader *)iface;
440 ULONG refcount = InterlockedDecrement(&This->refcount);
442 TRACE("%p decreasing refcount to %u\n", This, refcount);
445 IWineD3DBaseShader_Release(This->wined3d_shader);
450 /* ID3D10DeviceChild methods */
452 static void STDMETHODCALLTYPE d3d10_pixel_shader_GetDevice(ID3D10PixelShader *iface, ID3D10Device **device)
454 FIXME("iface %p, device %p stub!\n", iface, device);
457 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader *iface,
458 REFGUID guid, UINT *data_size, void *data)
460 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
461 iface, debugstr_guid(guid), data_size, data);
466 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader *iface,
467 REFGUID guid, UINT data_size, const void *data)
469 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
470 iface, debugstr_guid(guid), data_size, data);
475 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader *iface,
476 REFGUID guid, const IUnknown *data)
478 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
483 static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
485 /* IUnknown methods */
486 d3d10_pixel_shader_QueryInterface,
487 d3d10_pixel_shader_AddRef,
488 d3d10_pixel_shader_Release,
489 /* ID3D10DeviceChild methods */
490 d3d10_pixel_shader_GetDevice,
491 d3d10_pixel_shader_GetPrivateData,
492 d3d10_pixel_shader_SetPrivateData,
493 d3d10_pixel_shader_SetPrivateDataInterface,
496 static void STDMETHODCALLTYPE d3d10_pixel_shader_wined3d_object_destroyed(void *parent)
498 struct d3d10_pixel_shader *shader = parent;
499 shader_free_signature(&shader->output_signature);
500 HeapFree(GetProcessHeap(), 0, shader);
503 static const struct wined3d_parent_ops d3d10_pixel_shader_wined3d_parent_ops =
505 d3d10_pixel_shader_wined3d_object_destroyed,
508 HRESULT d3d10_pixel_shader_init(struct d3d10_pixel_shader *shader, struct d3d10_device *device,
509 const void *byte_code, SIZE_T byte_code_length)
511 struct d3d10_shader_info shader_info;
514 shader->vtbl = &d3d10_pixel_shader_vtbl;
515 shader->refcount = 1;
517 shader_info.output_signature = &shader->output_signature;
518 hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
521 ERR("Failed to extract shader, hr %#x.\n", hr);
525 hr = IWineD3DDevice_CreatePixelShader(device->wined3d_device, shader_info.shader_code,
526 &shader->output_signature, shader, &d3d10_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader);
529 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
530 shader_free_signature(&shader->output_signature);