msvcrt: Add Context class static functions stubs.
[wine.git] / dlls / d3d11 / inputlayout.c
blob1fdb2c3edb738c25e96d7bb0d6af3d099d1d5ca4
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 isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
29 struct wined3d_shader_signature *is = ctx;
31 if (tag != TAG_ISGN)
32 return S_OK;
34 if (is->elements)
36 FIXME("Multiple input signatures.\n");
37 shader_free_signature(is);
39 return shader_parse_signature(data, data_size, is);
42 static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEMENT_DESC *element_descs,
43 UINT element_count, const void *shader_byte_code, SIZE_T shader_byte_code_length,
44 struct wined3d_vertex_element **wined3d_elements)
46 struct wined3d_shader_signature is;
47 unsigned int i;
48 HRESULT hr;
50 memset(&is, 0, sizeof(is));
51 if (FAILED(hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is)))
53 ERR("Failed to parse input signature.\n");
54 return E_FAIL;
57 if (!(*wined3d_elements = d3d11_calloc(element_count, sizeof(**wined3d_elements))))
59 ERR("Failed to allocate wined3d vertex element array memory.\n");
60 HeapFree(GetProcessHeap(), 0, is.elements);
61 return E_OUTOFMEMORY;
64 for (i = 0; i < element_count; ++i)
66 struct wined3d_vertex_element *e = &(*wined3d_elements)[i];
67 const D3D11_INPUT_ELEMENT_DESC *f = &element_descs[i];
68 struct wined3d_shader_signature_element *element;
70 e->format = wined3dformat_from_dxgi_format(f->Format);
71 e->input_slot = f->InputSlot;
72 e->offset = f->AlignedByteOffset;
73 e->output_slot = WINED3D_OUTPUT_SLOT_UNUSED;
74 e->input_slot_class = f->InputSlotClass;
75 e->instance_data_step_rate = f->InstanceDataStepRate;
76 e->method = WINED3D_DECL_METHOD_DEFAULT;
77 e->usage = 0;
78 e->usage_idx = 0;
80 if ((element = shader_find_signature_element(&is, f->SemanticName, f->SemanticIndex)))
81 e->output_slot = element->register_idx;
82 else
83 WARN("Unused input element %u.\n", i);
86 shader_free_signature(&is);
88 return S_OK;
91 /* ID3D11InputLayout methods */
93 static inline struct d3d_input_layout *impl_from_ID3D11InputLayout(ID3D11InputLayout *iface)
95 return CONTAINING_RECORD(iface, struct d3d_input_layout, ID3D11InputLayout_iface);
98 static HRESULT STDMETHODCALLTYPE d3d11_input_layout_QueryInterface(ID3D11InputLayout *iface,
99 REFIID riid, void **object)
101 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
103 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
105 if (IsEqualGUID(riid, &IID_ID3D11InputLayout)
106 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
107 || IsEqualGUID(riid, &IID_IUnknown))
109 ID3D11InputLayout_AddRef(iface);
110 *object = iface;
111 return S_OK;
114 if (IsEqualGUID(riid, &IID_ID3D10InputLayout)
115 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
117 ID3D10InputLayout_AddRef(&layout->ID3D10InputLayout_iface);
118 *object = &layout->ID3D10InputLayout_iface;
119 return S_OK;
122 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
124 *object = NULL;
125 return E_NOINTERFACE;
128 static ULONG STDMETHODCALLTYPE d3d11_input_layout_AddRef(ID3D11InputLayout *iface)
130 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
131 ULONG refcount = InterlockedIncrement(&layout->refcount);
133 TRACE("%p increasing refcount to %u.\n", layout, refcount);
135 if (refcount == 1)
137 wined3d_mutex_lock();
138 wined3d_vertex_declaration_incref(layout->wined3d_decl);
139 wined3d_mutex_unlock();
142 return refcount;
145 static ULONG STDMETHODCALLTYPE d3d11_input_layout_Release(ID3D11InputLayout *iface)
147 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
148 ULONG refcount = InterlockedDecrement(&layout->refcount);
150 TRACE("%p decreasing refcount to %u.\n", layout, refcount);
152 if (!refcount)
154 wined3d_mutex_lock();
155 wined3d_vertex_declaration_decref(layout->wined3d_decl);
156 wined3d_mutex_unlock();
159 return refcount;
162 static void STDMETHODCALLTYPE d3d11_input_layout_GetDevice(ID3D11InputLayout *iface,
163 ID3D11Device **device)
165 FIXME("iface %p, device %p stub!\n", iface, device);
168 static HRESULT STDMETHODCALLTYPE d3d11_input_layout_GetPrivateData(ID3D11InputLayout *iface,
169 REFGUID guid, UINT *data_size, void *data)
171 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
173 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
175 return d3d_get_private_data(&layout->private_store, guid, data_size, data);
178 static HRESULT STDMETHODCALLTYPE d3d11_input_layout_SetPrivateData(ID3D11InputLayout *iface,
179 REFGUID guid, UINT data_size, const void *data)
181 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
183 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
185 return d3d_set_private_data(&layout->private_store, guid, data_size, data);
188 static HRESULT STDMETHODCALLTYPE d3d11_input_layout_SetPrivateDataInterface(ID3D11InputLayout *iface,
189 REFGUID guid, const IUnknown *data)
191 struct d3d_input_layout *layout = impl_from_ID3D11InputLayout(iface);
193 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
195 return d3d_set_private_data_interface(&layout->private_store, guid, data);
198 static const struct ID3D11InputLayoutVtbl d3d11_input_layout_vtbl =
200 /* IUnknown methods */
201 d3d11_input_layout_QueryInterface,
202 d3d11_input_layout_AddRef,
203 d3d11_input_layout_Release,
204 /* ID3D11DeviceChild methods */
205 d3d11_input_layout_GetDevice,
206 d3d11_input_layout_GetPrivateData,
207 d3d11_input_layout_SetPrivateData,
208 d3d11_input_layout_SetPrivateDataInterface,
211 /* ID3D10InputLayout methods */
213 static inline struct d3d_input_layout *impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
215 return CONTAINING_RECORD(iface, struct d3d_input_layout, ID3D10InputLayout_iface);
218 /* IUnknown methods */
220 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_QueryInterface(ID3D10InputLayout *iface,
221 REFIID riid, void **object)
223 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
225 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
227 return d3d11_input_layout_QueryInterface(&layout->ID3D11InputLayout_iface, riid, object);
230 static ULONG STDMETHODCALLTYPE d3d10_input_layout_AddRef(ID3D10InputLayout *iface)
232 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
234 TRACE("iface %p.\n", iface);
236 return d3d11_input_layout_AddRef(&layout->ID3D11InputLayout_iface);
239 static ULONG STDMETHODCALLTYPE d3d10_input_layout_Release(ID3D10InputLayout *iface)
241 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
243 TRACE("iface %p.\n", iface);
245 return d3d11_input_layout_Release(&layout->ID3D11InputLayout_iface);
248 /* ID3D10DeviceChild methods */
250 static void STDMETHODCALLTYPE d3d10_input_layout_GetDevice(ID3D10InputLayout *iface, ID3D10Device **device)
252 FIXME("iface %p, device %p stub!\n", iface, device);
255 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_GetPrivateData(ID3D10InputLayout *iface,
256 REFGUID guid, UINT *data_size, void *data)
258 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
260 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
261 iface, debugstr_guid(guid), data_size, data);
263 return d3d_get_private_data(&layout->private_store, guid, data_size, data);
266 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateData(ID3D10InputLayout *iface,
267 REFGUID guid, UINT data_size, const void *data)
269 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
271 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
272 iface, debugstr_guid(guid), data_size, data);
274 return d3d_set_private_data(&layout->private_store, guid, data_size, data);
277 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout *iface,
278 REFGUID guid, const IUnknown *data)
280 struct d3d_input_layout *layout = impl_from_ID3D10InputLayout(iface);
282 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
284 return d3d_set_private_data_interface(&layout->private_store, guid, data);
287 static const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl =
289 /* IUnknown methods */
290 d3d10_input_layout_QueryInterface,
291 d3d10_input_layout_AddRef,
292 d3d10_input_layout_Release,
293 /* ID3D10DeviceChild methods */
294 d3d10_input_layout_GetDevice,
295 d3d10_input_layout_GetPrivateData,
296 d3d10_input_layout_SetPrivateData,
297 d3d10_input_layout_SetPrivateDataInterface,
300 static void STDMETHODCALLTYPE d3d_input_layout_wined3d_object_destroyed(void *parent)
302 struct d3d_input_layout *layout = parent;
304 wined3d_private_store_cleanup(&layout->private_store);
305 HeapFree(GetProcessHeap(), 0, parent);
308 static const struct wined3d_parent_ops d3d_input_layout_wined3d_parent_ops =
310 d3d_input_layout_wined3d_object_destroyed,
313 static HRESULT d3d_input_layout_init(struct d3d_input_layout *layout, struct d3d_device *device,
314 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
315 const void *shader_byte_code, SIZE_T shader_byte_code_length)
317 struct wined3d_vertex_element *wined3d_elements;
318 HRESULT hr;
320 layout->ID3D11InputLayout_iface.lpVtbl = &d3d11_input_layout_vtbl;
321 layout->ID3D10InputLayout_iface.lpVtbl = &d3d10_input_layout_vtbl;
322 layout->refcount = 1;
323 wined3d_mutex_lock();
324 wined3d_private_store_init(&layout->private_store);
326 if (FAILED(hr = d3d11_input_layout_to_wined3d_declaration(element_descs, element_count,
327 shader_byte_code, shader_byte_code_length, &wined3d_elements)))
329 WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
330 wined3d_private_store_cleanup(&layout->private_store);
331 wined3d_mutex_unlock();
332 return hr;
335 hr = wined3d_vertex_declaration_create(device->wined3d_device, wined3d_elements, element_count,
336 layout, &d3d_input_layout_wined3d_parent_ops, &layout->wined3d_decl);
337 HeapFree(GetProcessHeap(), 0, wined3d_elements);
338 if (FAILED(hr))
340 WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
341 wined3d_private_store_cleanup(&layout->private_store);
342 wined3d_mutex_unlock();
343 return hr;
345 wined3d_mutex_unlock();
347 return S_OK;
350 HRESULT d3d_input_layout_create(struct d3d_device *device,
351 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
352 const void *shader_byte_code, SIZE_T shader_byte_code_length,
353 struct d3d_input_layout **layout)
355 struct d3d_input_layout *object;
356 HRESULT hr;
358 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
359 if (!object)
360 return E_OUTOFMEMORY;
362 if (FAILED(hr = d3d_input_layout_init(object, device, element_descs, element_count,
363 shader_byte_code, shader_byte_code_length)))
365 WARN("Failed to initialize input layout, hr %#x.\n", hr);
366 HeapFree(GetProcessHeap(), 0, object);
367 return hr;
370 TRACE("Created input layout %p.\n", object);
371 *layout = object;
373 return S_OK;
376 struct d3d_input_layout *unsafe_impl_from_ID3D11InputLayout(ID3D11InputLayout *iface)
378 if (!iface)
379 return NULL;
380 assert(iface->lpVtbl == &d3d11_input_layout_vtbl);
382 return impl_from_ID3D11InputLayout(iface);
385 struct d3d_input_layout *unsafe_impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
387 if (!iface)
388 return NULL;
389 assert(iface->lpVtbl == &d3d10_input_layout_vtbl);
391 return impl_from_ID3D10InputLayout(iface);