gdi32: Pass the source/dest visible rectangles to the AlphaBlend driver entry point.
[wine/testsucceed.git] / dlls / d3d10core / shader.c
bloba7a40d54582927c4d146160e5685f8136df95243
1 /*
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
20 #include "config.h"
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;
30 HRESULT hr;
32 switch(tag)
34 case TAG_OSGN:
35 hr = shader_parse_signature(data, data_size, shader_info->output_signature);
36 if (FAILED(hr)) return hr;
37 break;
39 case TAG_SHDR:
40 shader_info->shader_code = (const DWORD *)data;
41 break;
43 default:
44 FIXME("Unhandled chunk %s\n", debugstr_an((const char *)&tag, 4));
45 break;
48 return S_OK;
51 static HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, struct d3d10_shader_info *shader_info)
53 HRESULT hr;
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;
61 if (FAILED(hr))
63 ERR("Failed to parse shader, hr %#x\n", hr);
64 shader_free_signature(shader_info->output_signature);
67 return hr;
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;
76 char *string_data;
77 unsigned int i;
78 DWORD count;
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));
86 if (!e)
88 ERR("Failed to allocate input signature memory.\n");
89 return E_OUTOFMEMORY;
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);
96 if (!string_data)
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)
106 UINT name_offset;
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);
122 s->elements = e;
123 s->element_count = count;
124 s->string_data = string_data;
126 return S_OK;
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);
147 *object = iface;
148 return S_OK;
151 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
153 *object = NULL;
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);
164 if (refcount == 1)
165 wined3d_shader_incref(This->wined3d_shader);
167 return 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);
177 if (!refcount)
178 wined3d_shader_decref(This->wined3d_shader);
180 return refcount;
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);
196 return E_NOTIMPL;
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);
205 return E_NOTIMPL;
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);
213 return E_NOTIMPL;
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;
245 HRESULT hr;
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);
252 if (FAILED(hr))
254 ERR("Failed to extract shader, hr %#x.\n", hr);
255 return 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);
260 if (FAILED(hr))
262 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
263 shader_free_signature(&shader->output_signature);
264 return hr;
267 return S_OK;
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);
287 *object = iface;
288 return S_OK;
291 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
293 *object = NULL;
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);
304 return 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);
314 if (!refcount)
315 wined3d_shader_decref(This->wined3d_shader);
317 return refcount;
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);
333 return E_NOTIMPL;
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);
342 return E_NOTIMPL;
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);
350 return E_NOTIMPL;
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;
382 HRESULT hr;
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);
389 if (FAILED(hr))
391 ERR("Failed to extract shader, hr %#x.\n", hr);
392 return 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);
397 if (FAILED(hr))
399 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
400 shader_free_signature(&shader->output_signature);
401 return hr;
404 return S_OK;
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);
419 *object = iface;
420 return S_OK;
423 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
425 *object = NULL;
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);
436 if (refcount == 1)
437 wined3d_shader_incref(This->wined3d_shader);
439 return refcount;
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);
449 if (!refcount)
450 wined3d_shader_decref(This->wined3d_shader);
452 return refcount;
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);
468 return E_NOTIMPL;
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);
477 return E_NOTIMPL;
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);
485 return E_NOTIMPL;
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;
517 HRESULT hr;
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);
524 if (FAILED(hr))
526 ERR("Failed to extract shader, hr %#x.\n", hr);
527 return 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);
532 if (FAILED(hr))
534 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
535 shader_free_signature(&shader->output_signature);
536 return hr;
539 return S_OK;