wined3d: Introduce wined3d_shader_create_hs().
[wine.git] / dlls / d3d11 / shader.c
bloba91bec7bde0ea291c4ef33fd556f76d60fc9220f
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 "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 static HRESULT shdr_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
29 struct d3d_shader_info *shader_info = ctx;
30 HRESULT hr;
32 switch (tag)
34 case TAG_ISGN:
35 if (FAILED(hr = shader_parse_signature(data, data_size, shader_info->input_signature)))
36 return hr;
37 break;
39 case TAG_OSGN:
40 if (FAILED(hr = shader_parse_signature(data, data_size, shader_info->output_signature)))
41 return hr;
42 break;
44 case TAG_SHDR:
45 case TAG_SHEX:
46 if (shader_info->shader_code) FIXME("Multiple SHDR/SHEX chunks.\n");
47 shader_info->shader_code = (const DWORD *)data;
48 break;
50 default:
51 FIXME("Unhandled chunk %s\n", debugstr_an((const char *)&tag, 4));
52 break;
55 return S_OK;
58 static HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, struct d3d_shader_info *shader_info)
60 HRESULT hr;
62 shader_info->shader_code = NULL;
63 memset(shader_info->input_signature, 0, sizeof(*shader_info->input_signature));
64 memset(shader_info->output_signature, 0, sizeof(*shader_info->output_signature));
66 hr = parse_dxbc(dxbc, dxbc_length, shdr_handler, shader_info);
67 if (!shader_info->shader_code) hr = E_INVALIDARG;
69 if (FAILED(hr))
71 FIXME("Failed to parse shader, hr %#x.\n", hr);
72 shader_free_signature(shader_info->input_signature);
73 shader_free_signature(shader_info->output_signature);
76 return hr;
79 HRESULT shader_parse_signature(const char *data, DWORD data_size, struct wined3d_shader_signature *s)
81 struct wined3d_shader_signature_element *e;
82 const char *ptr = data;
83 unsigned int i;
84 DWORD count;
86 read_dword(&ptr, &count);
87 TRACE("%u elements\n", count);
89 skip_dword_unknown(&ptr, 1);
91 e = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*e));
92 if (!e)
94 ERR("Failed to allocate input signature memory.\n");
95 return E_OUTOFMEMORY;
98 for (i = 0; i < count; ++i)
100 UINT name_offset;
102 read_dword(&ptr, &name_offset);
103 e[i].semantic_name = data + name_offset;
104 read_dword(&ptr, &e[i].semantic_idx);
105 read_dword(&ptr, &e[i].sysval_semantic);
106 read_dword(&ptr, &e[i].component_type);
107 read_dword(&ptr, &e[i].register_idx);
108 read_dword(&ptr, &e[i].mask);
110 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
111 "type %u, register idx: %u, use_mask %#x, input_mask %#x\n",
112 debugstr_a(e[i].semantic_name), e[i].semantic_idx, e[i].sysval_semantic,
113 e[i].component_type, e[i].register_idx, (e[i].mask >> 8) & 0xff, e[i].mask & 0xff);
116 s->elements = e;
117 s->element_count = count;
119 return S_OK;
122 void shader_free_signature(struct wined3d_shader_signature *s)
124 HeapFree(GetProcessHeap(), 0, s->elements);
127 /* ID3D11VertexShader methods */
129 static inline struct d3d_vertex_shader *impl_from_ID3D11VertexShader(ID3D11VertexShader *iface)
131 return CONTAINING_RECORD(iface, struct d3d_vertex_shader, ID3D11VertexShader_iface);
134 static HRESULT STDMETHODCALLTYPE d3d11_vertex_shader_QueryInterface(ID3D11VertexShader *iface,
135 REFIID riid, void **object)
137 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
139 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
141 if (IsEqualGUID(riid, &IID_ID3D11VertexShader)
142 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
143 || IsEqualGUID(riid, &IID_IUnknown))
145 ID3D11VertexShader_AddRef(iface);
146 *object = iface;
147 return S_OK;
150 if (IsEqualGUID(riid, &IID_ID3D10VertexShader)
151 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
153 IUnknown_AddRef(&shader->ID3D10VertexShader_iface);
154 *object = &shader->ID3D10VertexShader_iface;
155 return S_OK;
158 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
160 *object = NULL;
161 return E_NOINTERFACE;
164 static ULONG STDMETHODCALLTYPE d3d11_vertex_shader_AddRef(ID3D11VertexShader *iface)
166 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
167 ULONG refcount = InterlockedIncrement(&shader->refcount);
169 TRACE("%p increasing refcount to %u.\n", shader, refcount);
171 if (refcount == 1)
173 ID3D11Device_AddRef(shader->device);
174 wined3d_mutex_lock();
175 wined3d_shader_incref(shader->wined3d_shader);
176 wined3d_mutex_unlock();
179 return refcount;
182 static ULONG STDMETHODCALLTYPE d3d11_vertex_shader_Release(ID3D11VertexShader *iface)
184 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
185 ULONG refcount = InterlockedDecrement(&shader->refcount);
187 TRACE("%p decreasing refcount to %u.\n", shader, refcount);
189 if (!refcount)
191 ID3D11Device *device = shader->device;
193 wined3d_mutex_lock();
194 wined3d_shader_decref(shader->wined3d_shader);
195 wined3d_mutex_unlock();
196 /* Release the device last, it may cause the wined3d device to be
197 * destroyed. */
198 ID3D11Device_Release(device);
201 return refcount;
204 static void STDMETHODCALLTYPE d3d11_vertex_shader_GetDevice(ID3D11VertexShader *iface,
205 ID3D11Device **device)
207 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
209 TRACE("iface %p, device %p.\n", iface, device);
211 *device = shader->device;
212 ID3D11Device_AddRef(*device);
215 static HRESULT STDMETHODCALLTYPE d3d11_vertex_shader_GetPrivateData(ID3D11VertexShader *iface,
216 REFGUID guid, UINT *data_size, void *data)
218 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
220 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
222 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
225 static HRESULT STDMETHODCALLTYPE d3d11_vertex_shader_SetPrivateData(ID3D11VertexShader *iface,
226 REFGUID guid, UINT data_size, const void *data)
228 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
230 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
232 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
235 static HRESULT STDMETHODCALLTYPE d3d11_vertex_shader_SetPrivateDataInterface(ID3D11VertexShader *iface,
236 REFGUID guid, const IUnknown *data)
238 struct d3d_vertex_shader *shader = impl_from_ID3D11VertexShader(iface);
240 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
242 return d3d_set_private_data_interface(&shader->private_store, guid, data);
245 static const struct ID3D11VertexShaderVtbl d3d11_vertex_shader_vtbl =
247 /* IUnknown methods */
248 d3d11_vertex_shader_QueryInterface,
249 d3d11_vertex_shader_AddRef,
250 d3d11_vertex_shader_Release,
251 /* ID3D11DeviceChild methods */
252 d3d11_vertex_shader_GetDevice,
253 d3d11_vertex_shader_GetPrivateData,
254 d3d11_vertex_shader_SetPrivateData,
255 d3d11_vertex_shader_SetPrivateDataInterface,
258 /* ID3D10VertexShader methods */
260 static inline struct d3d_vertex_shader *impl_from_ID3D10VertexShader(ID3D10VertexShader *iface)
262 return CONTAINING_RECORD(iface, struct d3d_vertex_shader, ID3D10VertexShader_iface);
265 /* IUnknown methods */
267 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_QueryInterface(ID3D10VertexShader *iface,
268 REFIID riid, void **object)
270 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
272 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
274 return d3d11_vertex_shader_QueryInterface(&shader->ID3D11VertexShader_iface, riid, object);
277 static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_AddRef(ID3D10VertexShader *iface)
279 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
281 TRACE("iface %p.\n", iface);
283 return d3d11_vertex_shader_AddRef(&shader->ID3D11VertexShader_iface);
286 static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_Release(ID3D10VertexShader *iface)
288 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
290 TRACE("iface %p.\n", iface);
292 return d3d11_vertex_shader_Release(&shader->ID3D11VertexShader_iface);
295 /* ID3D10DeviceChild methods */
297 static void STDMETHODCALLTYPE d3d10_vertex_shader_GetDevice(ID3D10VertexShader *iface, ID3D10Device **device)
299 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
301 TRACE("iface %p, device %p.\n", iface, device);
303 ID3D11Device_QueryInterface(shader->device, &IID_ID3D10Device, (void **)device);
306 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_GetPrivateData(ID3D10VertexShader *iface,
307 REFGUID guid, UINT *data_size, void *data)
309 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
311 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
312 iface, debugstr_guid(guid), data_size, data);
314 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
317 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_SetPrivateData(ID3D10VertexShader *iface,
318 REFGUID guid, UINT data_size, const void *data)
320 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
322 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
323 iface, debugstr_guid(guid), data_size, data);
325 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
328 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_SetPrivateDataInterface(ID3D10VertexShader *iface,
329 REFGUID guid, const IUnknown *data)
331 struct d3d_vertex_shader *shader = impl_from_ID3D10VertexShader(iface);
333 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
335 return d3d_set_private_data_interface(&shader->private_store, guid, data);
338 static const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl =
340 /* IUnknown methods */
341 d3d10_vertex_shader_QueryInterface,
342 d3d10_vertex_shader_AddRef,
343 d3d10_vertex_shader_Release,
344 /* ID3D10DeviceChild methods */
345 d3d10_vertex_shader_GetDevice,
346 d3d10_vertex_shader_GetPrivateData,
347 d3d10_vertex_shader_SetPrivateData,
348 d3d10_vertex_shader_SetPrivateDataInterface,
351 static void STDMETHODCALLTYPE d3d_vertex_shader_wined3d_object_destroyed(void *parent)
353 struct d3d_vertex_shader *shader = parent;
355 wined3d_private_store_cleanup(&shader->private_store);
356 HeapFree(GetProcessHeap(), 0, parent);
359 static const struct wined3d_parent_ops d3d_vertex_shader_wined3d_parent_ops =
361 d3d_vertex_shader_wined3d_object_destroyed,
364 static unsigned int d3d_sm_from_feature_level(D3D_FEATURE_LEVEL feature_level)
366 switch (feature_level)
368 case D3D_FEATURE_LEVEL_11_1:
369 case D3D_FEATURE_LEVEL_11_0:
370 return 5;
371 case D3D_FEATURE_LEVEL_10_1:
372 case D3D_FEATURE_LEVEL_10_0:
373 return 4;
374 case D3D_FEATURE_LEVEL_9_3:
375 return 3;
376 case D3D_FEATURE_LEVEL_9_2:
377 case D3D_FEATURE_LEVEL_9_1:
378 return 2;
379 default:
380 ERR("Unexpected feature_level %#x.\n", feature_level);
382 return 0;
385 static HRESULT d3d_vertex_shader_init(struct d3d_vertex_shader *shader, struct d3d_device *device,
386 const void *byte_code, SIZE_T byte_code_length)
388 struct wined3d_shader_signature output_signature;
389 struct wined3d_shader_signature input_signature;
390 struct d3d_shader_info shader_info;
391 struct wined3d_shader_desc desc;
392 HRESULT hr;
394 shader->ID3D11VertexShader_iface.lpVtbl = &d3d11_vertex_shader_vtbl;
395 shader->ID3D10VertexShader_iface.lpVtbl = &d3d10_vertex_shader_vtbl;
396 shader->refcount = 1;
397 wined3d_mutex_lock();
398 wined3d_private_store_init(&shader->private_store);
400 shader_info.input_signature = &input_signature;
401 shader_info.output_signature = &output_signature;
402 if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
404 WARN("Failed to extract shader, hr %#x.\n", hr);
405 wined3d_private_store_cleanup(&shader->private_store);
406 wined3d_mutex_unlock();
407 return hr;
410 desc.byte_code = shader_info.shader_code;
411 desc.input_signature = &input_signature;
412 desc.output_signature = &output_signature;
413 desc.max_version = d3d_sm_from_feature_level(device->feature_level);
415 hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
416 &d3d_vertex_shader_wined3d_parent_ops, &shader->wined3d_shader);
417 shader_free_signature(&input_signature);
418 shader_free_signature(&output_signature);
419 if (FAILED(hr))
421 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
422 wined3d_private_store_cleanup(&shader->private_store);
423 wined3d_mutex_unlock();
424 return E_INVALIDARG;
426 wined3d_mutex_unlock();
428 shader->device = &device->ID3D11Device_iface;
429 ID3D11Device_AddRef(shader->device);
431 return S_OK;
434 HRESULT d3d_vertex_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
435 struct d3d_vertex_shader **shader)
437 struct d3d_vertex_shader *object;
438 HRESULT hr;
440 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
441 return E_OUTOFMEMORY;
443 if (FAILED(hr = d3d_vertex_shader_init(object, device, byte_code, byte_code_length)))
445 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
446 HeapFree(GetProcessHeap(), 0, object);
447 return hr;
450 TRACE("Created vertex shader %p.\n", object);
451 *shader = object;
453 return S_OK;
456 struct d3d_vertex_shader *unsafe_impl_from_ID3D11VertexShader(ID3D11VertexShader *iface)
458 if (!iface)
459 return NULL;
460 assert(iface->lpVtbl == &d3d11_vertex_shader_vtbl);
462 return impl_from_ID3D11VertexShader(iface);
465 struct d3d_vertex_shader *unsafe_impl_from_ID3D10VertexShader(ID3D10VertexShader *iface)
467 if (!iface)
468 return NULL;
469 assert(iface->lpVtbl == &d3d10_vertex_shader_vtbl);
471 return impl_from_ID3D10VertexShader(iface);
474 /* ID3D11HullShader methods */
476 static inline struct d3d11_hull_shader *impl_from_ID3D11HullShader(ID3D11HullShader *iface)
478 return CONTAINING_RECORD(iface, struct d3d11_hull_shader, ID3D11HullShader_iface);
481 static HRESULT STDMETHODCALLTYPE d3d11_hull_shader_QueryInterface(ID3D11HullShader *iface,
482 REFIID riid, void **object)
484 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
486 if (IsEqualGUID(riid, &IID_ID3D11HullShader)
487 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
488 || IsEqualGUID(riid, &IID_IUnknown))
490 ID3D11HullShader_AddRef(iface);
491 *object = iface;
492 return S_OK;
495 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
497 *object = NULL;
498 return E_NOINTERFACE;
501 static ULONG STDMETHODCALLTYPE d3d11_hull_shader_AddRef(ID3D11HullShader *iface)
503 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
504 ULONG refcount = InterlockedIncrement(&shader->refcount);
506 TRACE("%p increasing refcount to %u.\n", shader, refcount);
508 return refcount;
511 static ULONG STDMETHODCALLTYPE d3d11_hull_shader_Release(ID3D11HullShader *iface)
513 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
514 ULONG refcount = InterlockedDecrement(&shader->refcount);
516 TRACE("%p decreasing refcount to %u.\n", shader, refcount);
518 if (!refcount)
520 ID3D11Device *device = shader->device;
522 wined3d_mutex_lock();
523 wined3d_shader_decref(shader->wined3d_shader);
524 wined3d_mutex_unlock();
526 /* Release the device last, it may cause the wined3d device to be
527 * destroyed. */
528 ID3D11Device_Release(device);
531 return refcount;
534 static void STDMETHODCALLTYPE d3d11_hull_shader_GetDevice(ID3D11HullShader *iface,
535 ID3D11Device **device)
537 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
539 TRACE("iface %p, device %p.\n", iface, device);
541 *device = shader->device;
542 ID3D11Device_AddRef(*device);
545 static HRESULT STDMETHODCALLTYPE d3d11_hull_shader_GetPrivateData(ID3D11HullShader *iface,
546 REFGUID guid, UINT *data_size, void *data)
548 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
550 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
552 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
555 static HRESULT STDMETHODCALLTYPE d3d11_hull_shader_SetPrivateData(ID3D11HullShader *iface,
556 REFGUID guid, UINT data_size, const void *data)
558 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
560 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
562 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
565 static HRESULT STDMETHODCALLTYPE d3d11_hull_shader_SetPrivateDataInterface(ID3D11HullShader *iface,
566 REFGUID guid, const IUnknown *data)
568 struct d3d11_hull_shader *shader = impl_from_ID3D11HullShader(iface);
570 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
572 return d3d_set_private_data_interface(&shader->private_store, guid, data);
575 static const struct ID3D11HullShaderVtbl d3d11_hull_shader_vtbl =
577 /* IUnknown methods */
578 d3d11_hull_shader_QueryInterface,
579 d3d11_hull_shader_AddRef,
580 d3d11_hull_shader_Release,
581 /* ID3D11DeviceChild methods */
582 d3d11_hull_shader_GetDevice,
583 d3d11_hull_shader_GetPrivateData,
584 d3d11_hull_shader_SetPrivateData,
585 d3d11_hull_shader_SetPrivateDataInterface,
588 static void STDMETHODCALLTYPE d3d11_hull_shader_wined3d_object_destroyed(void *parent)
590 struct d3d11_hull_shader *shader = parent;
592 wined3d_private_store_cleanup(&shader->private_store);
593 HeapFree(GetProcessHeap(), 0, parent);
596 static const struct wined3d_parent_ops d3d11_hull_shader_wined3d_parent_ops =
598 d3d11_hull_shader_wined3d_object_destroyed,
601 static HRESULT d3d11_hull_shader_init(struct d3d11_hull_shader *shader, struct d3d_device *device,
602 const void *byte_code, SIZE_T byte_code_length)
604 struct wined3d_shader_signature output_signature;
605 struct wined3d_shader_signature input_signature;
606 struct d3d_shader_info shader_info;
607 struct wined3d_shader_desc desc;
608 HRESULT hr;
610 shader->ID3D11HullShader_iface.lpVtbl = &d3d11_hull_shader_vtbl;
611 shader->refcount = 1;
612 wined3d_mutex_lock();
613 wined3d_private_store_init(&shader->private_store);
615 shader_info.input_signature = &input_signature;
616 shader_info.output_signature = &output_signature;
617 if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
619 WARN("Failed to extract shader, hr %#x.\n", hr);
620 wined3d_private_store_cleanup(&shader->private_store);
621 wined3d_mutex_unlock();
622 return hr;
625 desc.byte_code = shader_info.shader_code;
626 desc.input_signature = &input_signature;
627 desc.output_signature = &output_signature;
628 desc.max_version = d3d_sm_from_feature_level(device->feature_level);
630 hr = wined3d_shader_create_hs(device->wined3d_device, &desc, shader,
631 &d3d11_hull_shader_wined3d_parent_ops, &shader->wined3d_shader);
632 shader_free_signature(&input_signature);
633 shader_free_signature(&output_signature);
634 if (FAILED(hr))
636 WARN("Failed to create wined3d hull shader, hr %#x.\n", hr);
637 wined3d_private_store_cleanup(&shader->private_store);
638 wined3d_mutex_unlock();
639 return E_INVALIDARG;
641 wined3d_mutex_unlock();
643 shader->device = &device->ID3D11Device_iface;
644 ID3D11Device_AddRef(shader->device);
646 return S_OK;
649 HRESULT d3d11_hull_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
650 struct d3d11_hull_shader **shader)
652 struct d3d11_hull_shader *object;
653 HRESULT hr;
655 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
656 return E_OUTOFMEMORY;
658 if (FAILED(hr = d3d11_hull_shader_init(object, device, byte_code, byte_code_length)))
660 HeapFree(GetProcessHeap(), 0, object);
661 return hr;
664 TRACE("Created hull shader %p.\n", object);
665 *shader = object;
667 return S_OK;
670 /* ID3D11GeometryShader methods */
672 static inline struct d3d_geometry_shader *impl_from_ID3D11GeometryShader(ID3D11GeometryShader *iface)
674 return CONTAINING_RECORD(iface, struct d3d_geometry_shader, ID3D11GeometryShader_iface);
677 static HRESULT STDMETHODCALLTYPE d3d11_geometry_shader_QueryInterface(ID3D11GeometryShader *iface,
678 REFIID riid, void **object)
680 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
682 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
684 if (IsEqualGUID(riid, &IID_ID3D11GeometryShader)
685 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
686 || IsEqualGUID(riid, &IID_IUnknown))
688 ID3D11GeometryShader_AddRef(iface);
689 *object = iface;
690 return S_OK;
693 if (IsEqualGUID(riid, &IID_ID3D10GeometryShader)
694 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
696 ID3D10GeometryShader_AddRef(&shader->ID3D10GeometryShader_iface);
697 *object = &shader->ID3D10GeometryShader_iface;
698 return S_OK;
701 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
703 *object = NULL;
704 return E_NOINTERFACE;
707 static ULONG STDMETHODCALLTYPE d3d11_geometry_shader_AddRef(ID3D11GeometryShader *iface)
709 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
710 ULONG refcount = InterlockedIncrement(&shader->refcount);
712 TRACE("%p increasing refcount to %u.\n", shader, refcount);
714 return refcount;
717 static ULONG STDMETHODCALLTYPE d3d11_geometry_shader_Release(ID3D11GeometryShader *iface)
719 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
720 ULONG refcount = InterlockedDecrement(&shader->refcount);
722 TRACE("%p decreasing refcount to %u.\n", shader, refcount);
724 if (!refcount)
726 ID3D11Device *device = shader->device;
728 wined3d_mutex_lock();
729 wined3d_shader_decref(shader->wined3d_shader);
730 wined3d_mutex_unlock();
732 /* Release the device last, it may cause the wined3d device to be
733 * destroyed. */
734 ID3D11Device_Release(device);
737 return refcount;
740 static void STDMETHODCALLTYPE d3d11_geometry_shader_GetDevice(ID3D11GeometryShader *iface,
741 ID3D11Device **device)
743 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
745 TRACE("iface %p, device %p.\n", iface, device);
747 *device = shader->device;
748 ID3D11Device_AddRef(*device);
751 static HRESULT STDMETHODCALLTYPE d3d11_geometry_shader_GetPrivateData(ID3D11GeometryShader *iface,
752 REFGUID guid, UINT *data_size, void *data)
754 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
756 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
758 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
761 static HRESULT STDMETHODCALLTYPE d3d11_geometry_shader_SetPrivateData(ID3D11GeometryShader *iface,
762 REFGUID guid, UINT data_size, const void *data)
764 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
766 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
768 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
771 static HRESULT STDMETHODCALLTYPE d3d11_geometry_shader_SetPrivateDataInterface(ID3D11GeometryShader *iface,
772 REFGUID guid, const IUnknown *data)
774 struct d3d_geometry_shader *shader = impl_from_ID3D11GeometryShader(iface);
776 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
778 return d3d_set_private_data_interface(&shader->private_store, guid, data);
781 static const struct ID3D11GeometryShaderVtbl d3d11_geometry_shader_vtbl =
783 /* IUnknown methods */
784 d3d11_geometry_shader_QueryInterface,
785 d3d11_geometry_shader_AddRef,
786 d3d11_geometry_shader_Release,
787 /* ID3D11DeviceChild methods */
788 d3d11_geometry_shader_GetDevice,
789 d3d11_geometry_shader_GetPrivateData,
790 d3d11_geometry_shader_SetPrivateData,
791 d3d11_geometry_shader_SetPrivateDataInterface,
794 /* ID3D10GeometryShader methods */
796 static inline struct d3d_geometry_shader *impl_from_ID3D10GeometryShader(ID3D10GeometryShader *iface)
798 return CONTAINING_RECORD(iface, struct d3d_geometry_shader, ID3D10GeometryShader_iface);
801 /* IUnknown methods */
803 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader *iface,
804 REFIID riid, void **object)
806 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
808 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
810 return d3d11_geometry_shader_QueryInterface(&shader->ID3D11GeometryShader_iface, riid, object);
813 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_AddRef(ID3D10GeometryShader *iface)
815 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
817 TRACE("iface %p.\n", iface);
819 return d3d11_geometry_shader_AddRef(&shader->ID3D11GeometryShader_iface);
822 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_Release(ID3D10GeometryShader *iface)
824 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
826 TRACE("iface %p.\n", iface);
828 return d3d11_geometry_shader_Release(&shader->ID3D11GeometryShader_iface);
831 /* ID3D10DeviceChild methods */
833 static void STDMETHODCALLTYPE d3d10_geometry_shader_GetDevice(ID3D10GeometryShader *iface, ID3D10Device **device)
835 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
837 TRACE("iface %p, device %p.\n", iface, device);
839 ID3D11Device_QueryInterface(shader->device, &IID_ID3D10Device, (void **)device);
842 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader *iface,
843 REFGUID guid, UINT *data_size, void *data)
845 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
847 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
848 iface, debugstr_guid(guid), data_size, data);
850 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
853 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader *iface,
854 REFGUID guid, UINT data_size, const void *data)
856 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
858 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
859 iface, debugstr_guid(guid), data_size, data);
861 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
864 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader *iface,
865 REFGUID guid, const IUnknown *data)
867 struct d3d_geometry_shader *shader = impl_from_ID3D10GeometryShader(iface);
869 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
871 return d3d_set_private_data_interface(&shader->private_store, guid, data);
874 static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
876 /* IUnknown methods */
877 d3d10_geometry_shader_QueryInterface,
878 d3d10_geometry_shader_AddRef,
879 d3d10_geometry_shader_Release,
880 /* ID3D10DeviceChild methods */
881 d3d10_geometry_shader_GetDevice,
882 d3d10_geometry_shader_GetPrivateData,
883 d3d10_geometry_shader_SetPrivateData,
884 d3d10_geometry_shader_SetPrivateDataInterface,
887 static void STDMETHODCALLTYPE d3d_geometry_shader_wined3d_object_destroyed(void *parent)
889 struct d3d_geometry_shader *shader = parent;
891 wined3d_private_store_cleanup(&shader->private_store);
892 HeapFree(GetProcessHeap(), 0, parent);
895 static const struct wined3d_parent_ops d3d_geometry_shader_wined3d_parent_ops =
897 d3d_geometry_shader_wined3d_object_destroyed,
900 static HRESULT d3d_geometry_shader_init(struct d3d_geometry_shader *shader, struct d3d_device *device,
901 const void *byte_code, SIZE_T byte_code_length)
903 struct wined3d_shader_signature output_signature;
904 struct wined3d_shader_signature input_signature;
905 struct d3d_shader_info shader_info;
906 struct wined3d_shader_desc desc;
907 HRESULT hr;
909 shader->ID3D11GeometryShader_iface.lpVtbl = &d3d11_geometry_shader_vtbl;
910 shader->ID3D10GeometryShader_iface.lpVtbl = &d3d10_geometry_shader_vtbl;
911 shader->refcount = 1;
912 wined3d_mutex_lock();
913 wined3d_private_store_init(&shader->private_store);
915 shader_info.input_signature = &input_signature;
916 shader_info.output_signature = &output_signature;
917 if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
919 WARN("Failed to extract shader, hr %#x.\n", hr);
920 wined3d_private_store_cleanup(&shader->private_store);
921 wined3d_mutex_unlock();
922 return hr;
925 desc.byte_code = shader_info.shader_code;
926 desc.input_signature = &input_signature;
927 desc.output_signature = &output_signature;
928 desc.max_version = d3d_sm_from_feature_level(device->feature_level);
930 hr = wined3d_shader_create_gs(device->wined3d_device, &desc, shader,
931 &d3d_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader);
932 shader_free_signature(&input_signature);
933 shader_free_signature(&output_signature);
934 if (FAILED(hr))
936 WARN("Failed to create wined3d geometry shader, hr %#x.\n", hr);
937 wined3d_private_store_cleanup(&shader->private_store);
938 wined3d_mutex_unlock();
939 return E_INVALIDARG;
941 wined3d_mutex_unlock();
943 shader->device = &device->ID3D11Device_iface;
944 ID3D11Device_AddRef(shader->device);
946 return S_OK;
949 HRESULT d3d_geometry_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
950 struct d3d_geometry_shader **shader)
952 struct d3d_geometry_shader *object;
953 HRESULT hr;
955 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
956 return E_OUTOFMEMORY;
958 if (FAILED(hr = d3d_geometry_shader_init(object, device, byte_code, byte_code_length)))
960 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
961 HeapFree(GetProcessHeap(), 0, object);
962 return hr;
965 TRACE("Created geometry shader %p.\n", object);
966 *shader = object;
968 return S_OK;
971 struct d3d_geometry_shader *unsafe_impl_from_ID3D11GeometryShader(ID3D11GeometryShader *iface)
973 if (!iface)
974 return NULL;
975 assert(iface->lpVtbl == &d3d11_geometry_shader_vtbl);
977 return impl_from_ID3D11GeometryShader(iface);
980 struct d3d_geometry_shader *unsafe_impl_from_ID3D10GeometryShader(ID3D10GeometryShader *iface)
982 if (!iface)
983 return NULL;
984 assert(iface->lpVtbl == &d3d10_geometry_shader_vtbl);
986 return impl_from_ID3D10GeometryShader(iface);
989 /* ID3D11PixelShader methods */
991 static inline struct d3d_pixel_shader *impl_from_ID3D11PixelShader(ID3D11PixelShader *iface)
993 return CONTAINING_RECORD(iface, struct d3d_pixel_shader, ID3D11PixelShader_iface);
996 static HRESULT STDMETHODCALLTYPE d3d11_pixel_shader_QueryInterface(ID3D11PixelShader *iface,
997 REFIID riid, void **object)
999 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1001 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1003 if (IsEqualGUID(riid, &IID_ID3D11PixelShader)
1004 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
1005 || IsEqualGUID(riid, &IID_IUnknown))
1007 ID3D11PixelShader_AddRef(iface);
1008 *object = iface;
1009 return S_OK;
1012 if (IsEqualGUID(riid, &IID_ID3D10PixelShader)
1013 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
1015 IUnknown_AddRef(&shader->ID3D10PixelShader_iface);
1016 *object = &shader->ID3D10PixelShader_iface;
1017 return S_OK;
1020 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
1022 *object = NULL;
1023 return E_NOINTERFACE;
1026 static ULONG STDMETHODCALLTYPE d3d11_pixel_shader_AddRef(ID3D11PixelShader *iface)
1028 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1029 ULONG refcount = InterlockedIncrement(&shader->refcount);
1031 TRACE("%p increasing refcount to %u.\n", shader, refcount);
1033 if (refcount == 1)
1035 ID3D11Device_AddRef(shader->device);
1036 wined3d_mutex_lock();
1037 wined3d_shader_incref(shader->wined3d_shader);
1038 wined3d_mutex_unlock();
1041 return refcount;
1044 static ULONG STDMETHODCALLTYPE d3d11_pixel_shader_Release(ID3D11PixelShader *iface)
1046 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1047 ULONG refcount = InterlockedDecrement(&shader->refcount);
1049 TRACE("%p decreasing refcount to %u.\n", shader, refcount);
1051 if (!refcount)
1053 ID3D11Device *device = shader->device;
1055 wined3d_mutex_lock();
1056 wined3d_shader_decref(shader->wined3d_shader);
1057 wined3d_mutex_unlock();
1058 /* Release the device last, it may cause the wined3d device to be
1059 * destroyed. */
1060 ID3D11Device_Release(device);
1063 return refcount;
1066 static void STDMETHODCALLTYPE d3d11_pixel_shader_GetDevice(ID3D11PixelShader *iface,
1067 ID3D11Device **device)
1069 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1071 TRACE("iface %p, device %p.\n", iface, device);
1073 *device = shader->device;
1074 ID3D11Device_AddRef(*device);
1077 static HRESULT STDMETHODCALLTYPE d3d11_pixel_shader_GetPrivateData(ID3D11PixelShader *iface,
1078 REFGUID guid, UINT *data_size, void *data)
1080 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1082 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1084 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
1087 static HRESULT STDMETHODCALLTYPE d3d11_pixel_shader_SetPrivateData(ID3D11PixelShader *iface,
1088 REFGUID guid, UINT data_size, const void *data)
1090 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1092 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1094 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
1097 static HRESULT STDMETHODCALLTYPE d3d11_pixel_shader_SetPrivateDataInterface(ID3D11PixelShader *iface,
1098 REFGUID guid, const IUnknown *data)
1100 struct d3d_pixel_shader *shader = impl_from_ID3D11PixelShader(iface);
1102 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1104 return d3d_set_private_data_interface(&shader->private_store, guid, data);
1107 static const struct ID3D11PixelShaderVtbl d3d11_pixel_shader_vtbl =
1109 /* IUnknown methods */
1110 d3d11_pixel_shader_QueryInterface,
1111 d3d11_pixel_shader_AddRef,
1112 d3d11_pixel_shader_Release,
1113 /* ID3D11DeviceChild methods */
1114 d3d11_pixel_shader_GetDevice,
1115 d3d11_pixel_shader_GetPrivateData,
1116 d3d11_pixel_shader_SetPrivateData,
1117 d3d11_pixel_shader_SetPrivateDataInterface,
1120 /* ID3D10PixelShader methods */
1122 static inline struct d3d_pixel_shader *impl_from_ID3D10PixelShader(ID3D10PixelShader *iface)
1124 return CONTAINING_RECORD(iface, struct d3d_pixel_shader, ID3D10PixelShader_iface);
1127 /* IUnknown methods */
1129 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_QueryInterface(ID3D10PixelShader *iface,
1130 REFIID riid, void **object)
1132 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1134 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1136 return d3d11_pixel_shader_QueryInterface(&shader->ID3D11PixelShader_iface, riid, object);
1139 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_AddRef(ID3D10PixelShader *iface)
1141 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1143 TRACE("iface %p.\n", iface);
1145 return d3d11_pixel_shader_AddRef(&shader->ID3D11PixelShader_iface);
1148 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_Release(ID3D10PixelShader *iface)
1150 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1152 TRACE("iface %p.\n", iface);
1154 return d3d11_pixel_shader_Release(&shader->ID3D11PixelShader_iface);
1157 /* ID3D10DeviceChild methods */
1159 static void STDMETHODCALLTYPE d3d10_pixel_shader_GetDevice(ID3D10PixelShader *iface, ID3D10Device **device)
1161 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1163 TRACE("iface %p, device %p.\n", iface, device);
1165 ID3D11Device_QueryInterface(shader->device, &IID_ID3D10Device, (void **)device);
1168 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader *iface,
1169 REFGUID guid, UINT *data_size, void *data)
1171 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1173 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1174 iface, debugstr_guid(guid), data_size, data);
1176 return d3d_get_private_data(&shader->private_store, guid, data_size, data);
1179 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader *iface,
1180 REFGUID guid, UINT data_size, const void *data)
1182 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1184 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1185 iface, debugstr_guid(guid), data_size, data);
1187 return d3d_set_private_data(&shader->private_store, guid, data_size, data);
1190 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader *iface,
1191 REFGUID guid, const IUnknown *data)
1193 struct d3d_pixel_shader *shader = impl_from_ID3D10PixelShader(iface);
1195 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1197 return d3d_set_private_data_interface(&shader->private_store, guid, data);
1200 static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
1202 /* IUnknown methods */
1203 d3d10_pixel_shader_QueryInterface,
1204 d3d10_pixel_shader_AddRef,
1205 d3d10_pixel_shader_Release,
1206 /* ID3D10DeviceChild methods */
1207 d3d10_pixel_shader_GetDevice,
1208 d3d10_pixel_shader_GetPrivateData,
1209 d3d10_pixel_shader_SetPrivateData,
1210 d3d10_pixel_shader_SetPrivateDataInterface,
1213 static void STDMETHODCALLTYPE d3d_pixel_shader_wined3d_object_destroyed(void *parent)
1215 struct d3d_pixel_shader *shader = parent;
1217 wined3d_private_store_cleanup(&shader->private_store);
1218 HeapFree(GetProcessHeap(), 0, parent);
1221 static const struct wined3d_parent_ops d3d_pixel_shader_wined3d_parent_ops =
1223 d3d_pixel_shader_wined3d_object_destroyed,
1226 static HRESULT d3d_pixel_shader_init(struct d3d_pixel_shader *shader, struct d3d_device *device,
1227 const void *byte_code, SIZE_T byte_code_length)
1229 struct wined3d_shader_signature output_signature;
1230 struct wined3d_shader_signature input_signature;
1231 struct d3d_shader_info shader_info;
1232 struct wined3d_shader_desc desc;
1233 HRESULT hr;
1235 shader->ID3D11PixelShader_iface.lpVtbl = &d3d11_pixel_shader_vtbl;
1236 shader->ID3D10PixelShader_iface.lpVtbl = &d3d10_pixel_shader_vtbl;
1237 shader->refcount = 1;
1238 wined3d_mutex_lock();
1239 wined3d_private_store_init(&shader->private_store);
1241 shader_info.input_signature = &input_signature;
1242 shader_info.output_signature = &output_signature;
1243 if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
1245 WARN("Failed to extract shader, hr %#x.\n", hr);
1246 wined3d_private_store_cleanup(&shader->private_store);
1247 wined3d_mutex_unlock();
1248 return hr;
1251 desc.byte_code = shader_info.shader_code;
1252 desc.input_signature = &input_signature;
1253 desc.output_signature = &output_signature;
1254 desc.max_version = d3d_sm_from_feature_level(device->feature_level);
1256 hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
1257 &d3d_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader);
1258 shader_free_signature(&input_signature);
1259 shader_free_signature(&output_signature);
1260 if (FAILED(hr))
1262 WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
1263 wined3d_private_store_cleanup(&shader->private_store);
1264 wined3d_mutex_unlock();
1265 return E_INVALIDARG;
1267 wined3d_mutex_unlock();
1269 shader->device = &device->ID3D11Device_iface;
1270 ID3D11Device_AddRef(shader->device);
1272 return S_OK;
1275 HRESULT d3d_pixel_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
1276 struct d3d_pixel_shader **shader)
1278 struct d3d_pixel_shader *object;
1279 HRESULT hr;
1281 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1282 return E_OUTOFMEMORY;
1284 if (FAILED(hr = d3d_pixel_shader_init(object, device, byte_code, byte_code_length)))
1286 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1287 HeapFree(GetProcessHeap(), 0, object);
1288 return hr;
1291 TRACE("Created pixel shader %p.\n", object);
1292 *shader = object;
1294 return S_OK;
1297 struct d3d_pixel_shader *unsafe_impl_from_ID3D11PixelShader(ID3D11PixelShader *iface)
1299 if (!iface)
1300 return NULL;
1301 assert(iface->lpVtbl == &d3d11_pixel_shader_vtbl);
1303 return impl_from_ID3D11PixelShader(iface);
1306 struct d3d_pixel_shader *unsafe_impl_from_ID3D10PixelShader(ID3D10PixelShader *iface)
1308 if (!iface)
1309 return NULL;
1310 assert(iface->lpVtbl == &d3d10_pixel_shader_vtbl);
1312 return impl_from_ID3D10PixelShader(iface);