d3d10core: Implement d3d10_input_layout_SetPrivateData().
[wine/multimedia.git] / dlls / d3d10core / inputlayout.c
blob79ebea356562f4c26c22c414afa881bb42a2d24c
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 isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
29 struct wined3d_shader_signature *is = ctx;
31 switch(tag)
33 case TAG_ISGN:
34 return shader_parse_signature(data, data_size, is);
36 default:
37 FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag, 4));
38 return S_OK;
42 static HRESULT d3d10_input_layout_to_wined3d_declaration(const D3D10_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, UINT *wined3d_element_count)
46 struct wined3d_shader_signature is;
47 HRESULT hr;
48 UINT i;
50 hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is);
51 if (FAILED(hr))
53 ERR("Failed to parse input signature.\n");
54 return E_FAIL;
57 *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(**wined3d_elements));
58 if (!*wined3d_elements)
60 ERR("Failed to allocate wined3d vertex element array memory.\n");
61 HeapFree(GetProcessHeap(), 0, is.elements);
62 return E_OUTOFMEMORY;
64 *wined3d_element_count = 0;
66 for (i = 0; i < element_count; ++i)
68 UINT j;
70 for (j = 0; j < is.element_count; ++j)
72 if (!strcmp(element_descs[i].SemanticName, is.elements[j].semantic_name)
73 && element_descs[i].SemanticIndex == is.elements[j].semantic_idx)
75 struct wined3d_vertex_element *e = &(*wined3d_elements)[(*wined3d_element_count)++];
76 const D3D10_INPUT_ELEMENT_DESC *f = &element_descs[i];
78 e->format = wined3dformat_from_dxgi_format(f->Format);
79 e->input_slot = f->InputSlot;
80 e->offset = f->AlignedByteOffset;
81 e->output_slot = is.elements[j].register_idx;
82 e->method = WINED3D_DECL_METHOD_DEFAULT;
83 e->usage = 0;
84 e->usage_idx = 0;
86 if (f->InputSlotClass != D3D10_INPUT_PER_VERTEX_DATA)
87 FIXME("Ignoring input slot class (%#x)\n", f->InputSlotClass);
88 if (f->InstanceDataStepRate)
89 FIXME("Ignoring instance data step rate (%#x)\n", f->InstanceDataStepRate);
91 break;
96 shader_free_signature(&is);
98 return S_OK;
101 static inline struct d3d10_input_layout *impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
103 return CONTAINING_RECORD(iface, struct d3d10_input_layout, ID3D10InputLayout_iface);
106 /* IUnknown methods */
108 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_QueryInterface(ID3D10InputLayout *iface,
109 REFIID riid, void **object)
111 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
113 if (IsEqualGUID(riid, &IID_ID3D10InputLayout)
114 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
115 || IsEqualGUID(riid, &IID_IUnknown))
117 IUnknown_AddRef(iface);
118 *object = 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 d3d10_input_layout_AddRef(ID3D10InputLayout *iface)
130 struct d3d10_input_layout *This = impl_from_ID3D10InputLayout(iface);
131 ULONG refcount = InterlockedIncrement(&This->refcount);
133 TRACE("%p increasing refcount to %u\n", This, refcount);
135 if (refcount == 1)
137 wined3d_vertex_declaration_incref(This->wined3d_decl);
140 return refcount;
143 static ULONG STDMETHODCALLTYPE d3d10_input_layout_Release(ID3D10InputLayout *iface)
145 struct d3d10_input_layout *This = impl_from_ID3D10InputLayout(iface);
146 ULONG refcount = InterlockedDecrement(&This->refcount);
148 TRACE("%p decreasing refcount to %u\n", This, refcount);
150 if (!refcount)
152 wined3d_vertex_declaration_decref(This->wined3d_decl);
155 return refcount;
158 /* ID3D10DeviceChild methods */
160 static void STDMETHODCALLTYPE d3d10_input_layout_GetDevice(ID3D10InputLayout *iface, ID3D10Device **device)
162 FIXME("iface %p, device %p stub!\n", iface, device);
165 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_GetPrivateData(ID3D10InputLayout *iface,
166 REFGUID guid, UINT *data_size, void *data)
168 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
169 iface, debugstr_guid(guid), data_size, data);
171 return E_NOTIMPL;
174 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateData(ID3D10InputLayout *iface,
175 REFGUID guid, UINT data_size, const void *data)
177 struct d3d10_input_layout *layout = impl_from_ID3D10InputLayout(iface);
179 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
180 iface, debugstr_guid(guid), data_size, data);
182 return d3d10_set_private_data(&layout->private_store, guid, data_size, data);
185 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout *iface,
186 REFGUID guid, const IUnknown *data)
188 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
190 return E_NOTIMPL;
193 static const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl =
195 /* IUnknown methods */
196 d3d10_input_layout_QueryInterface,
197 d3d10_input_layout_AddRef,
198 d3d10_input_layout_Release,
199 /* ID3D10DeviceChild methods */
200 d3d10_input_layout_GetDevice,
201 d3d10_input_layout_GetPrivateData,
202 d3d10_input_layout_SetPrivateData,
203 d3d10_input_layout_SetPrivateDataInterface,
206 static void STDMETHODCALLTYPE d3d10_input_layout_wined3d_object_destroyed(void *parent)
208 struct d3d10_input_layout *layout = parent;
210 wined3d_private_store_cleanup(&layout->private_store);
211 HeapFree(GetProcessHeap(), 0, parent);
214 static const struct wined3d_parent_ops d3d10_input_layout_wined3d_parent_ops =
216 d3d10_input_layout_wined3d_object_destroyed,
219 HRESULT d3d10_input_layout_init(struct d3d10_input_layout *layout, struct d3d10_device *device,
220 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
221 const void *shader_byte_code, SIZE_T shader_byte_code_length)
223 struct wined3d_vertex_element *wined3d_elements;
224 UINT wined3d_element_count;
225 HRESULT hr;
227 layout->ID3D10InputLayout_iface.lpVtbl = &d3d10_input_layout_vtbl;
228 layout->refcount = 1;
229 wined3d_private_store_init(&layout->private_store);
231 hr = d3d10_input_layout_to_wined3d_declaration(element_descs, element_count,
232 shader_byte_code, shader_byte_code_length, &wined3d_elements, &wined3d_element_count);
233 if (FAILED(hr))
235 WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
236 wined3d_private_store_cleanup(&layout->private_store);
237 return hr;
240 hr = wined3d_vertex_declaration_create(device->wined3d_device, wined3d_elements, wined3d_element_count,
241 layout, &d3d10_input_layout_wined3d_parent_ops, &layout->wined3d_decl);
242 HeapFree(GetProcessHeap(), 0, wined3d_elements);
243 if (FAILED(hr))
245 WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
246 wined3d_private_store_cleanup(&layout->private_store);
247 return hr;
250 return S_OK;
253 struct d3d10_input_layout *unsafe_impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
255 if (!iface)
256 return NULL;
257 assert(iface->lpVtbl == &d3d10_input_layout_vtbl);
259 return impl_from_ID3D10InputLayout(iface);