1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 *
18 */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "d3d10core_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
26
27 static HRESULT isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
28 {
29 struct wined3d_shader_signature *is = ctx;
30
31 switch(tag)
32 {
33 case TAG_ISGN:
34 return shader_parse_signature(data, data_size, is);
35
36 default:
37 FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag, 4));
38 return S_OK;
39 }
40 }
41
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 WINED3DVERTEXELEMENT **wined3d_elements, UINT *wined3d_element_count)
45 {
46 struct wined3d_shader_signature is;
47 HRESULT hr;
48 UINT i;
49
50 hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is);
51 if (FAILED(hr))
52 {
53 ERR("Failed to parse input signature.\n");
54 return E_FAIL;
55 }
56
57 *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(**wined3d_elements));
58 if (!*wined3d_elements)
59 {
60 ERR("Failed to allocate wined3d vertex element array memory.\n");
61 HeapFree(GetProcessHeap(), 0, is.elements);
62 return E_OUTOFMEMORY;
63 }
64 *wined3d_element_count = 0;
65
66 for (i = 0; i < element_count; ++i)
67 {
68 UINT j;
69
70 for (j = 0; j < is.element_count; ++j)
71 {
72 if (!strcmp(element_descs[i].SemanticName, is.elements[j].semantic_name)
73 && element_descs[i].SemanticIndex == is.elements[j].semantic_idx)
74 {
75 WINED3DVERTEXELEMENT *e = &(*wined3d_elements)[(*wined3d_element_count)++];
76 const D3D10_INPUT_ELEMENT_DESC *f = &element_descs[i];
77
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 = WINED3DDECLMETHOD_DEFAULT;
83 e->usage = 0;
84 e->usage_idx = 0;
85
86 if (f->AlignedByteOffset == D3D10_APPEND_ALIGNED_ELEMENT)
87 FIXME("D3D10_APPEND_ALIGNED_ELEMENT not supported\n");
88 if (f->InputSlotClass != D3D10_INPUT_PER_VERTEX_DATA)
89 FIXME("Ignoring input slot class (%#x)\n", f->InputSlotClass);
90 if (f->InstanceDataStepRate)
91 FIXME("Ignoring instace data step rate (%#x)\n", f->InstanceDataStepRate);
92
93 break;
94 }
95 }
96 }
97
98 shader_free_signature(&is);
99
100 return S_OK;
101 }
102
103 /* IUnknown methods */
104
105 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_QueryInterface(ID3D10InputLayout *iface,
106 REFIID riid, void **object)
107 {
108 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
109
110 if (IsEqualGUID(riid, &IID_ID3D10InputLayout)
111 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
112 || IsEqualGUID(riid, &IID_IUnknown))
113 {
114 IUnknown_AddRef(iface);
115 *object = iface;
116 return S_OK;
117 }
118
119 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
120
121 *object = NULL;
122 return E_NOINTERFACE;
123 }
124
125 static ULONG STDMETHODCALLTYPE d3d10_input_layout_AddRef(ID3D10InputLayout *iface)
126 {
127 struct d3d10_input_layout *This = (struct d3d10_input_layout *)iface;
128 ULONG refcount = InterlockedIncrement(&This->refcount);
129
130 TRACE("%p increasing refcount to %u\n", This, refcount);
131
132 if (refcount == 1)
133 {
134 IWineD3DVertexDeclaration_AddRef(This->wined3d_decl);
135 }
136
137 return refcount;
138 }
139
140 static ULONG STDMETHODCALLTYPE d3d10_input_layout_Release(ID3D10InputLayout *iface)
141 {
142 struct d3d10_input_layout *This = (struct d3d10_input_layout *)iface;
143 ULONG refcount = InterlockedDecrement(&This->refcount);
144
145 TRACE("%p decreasing refcount to %u\n", This, refcount);
146
147 if (!refcount)
148 {
149 IWineD3DVertexDeclaration_Release(This->wined3d_decl);
150 }
151
152 return refcount;
153 }
154
155 /* ID3D10DeviceChild methods */
156
157 static void STDMETHODCALLTYPE d3d10_input_layout_GetDevice(ID3D10InputLayout *iface, ID3D10Device **device)
158 {
159 FIXME("iface %p, device %p stub!\n", iface, device);
160 }
161
162 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_GetPrivateData(ID3D10InputLayout *iface,
163 REFGUID guid, UINT *data_size, void *data)
164 {
165 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
166 iface, debugstr_guid(guid), data_size, data);
167
168 return E_NOTIMPL;
169 }
170
171 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateData(ID3D10InputLayout *iface,
172 REFGUID guid, UINT data_size, const void *data)
173 {
174 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
175 iface, debugstr_guid(guid), data_size, data);
176
177 return E_NOTIMPL;
178 }
179
180 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout *iface,
181 REFGUID guid, const IUnknown *data)
182 {
183 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
184
185 return E_NOTIMPL;
186 }
187
188 static const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl =
189 {
190 /* IUnknown methods */
191 d3d10_input_layout_QueryInterface,
192 d3d10_input_layout_AddRef,
193 d3d10_input_layout_Release,
194 /* ID3D10DeviceChild methods */
195 d3d10_input_layout_GetDevice,
196 d3d10_input_layout_GetPrivateData,
197 d3d10_input_layout_SetPrivateData,
198 d3d10_input_layout_SetPrivateDataInterface,
199 };
200
201 static void STDMETHODCALLTYPE d3d10_input_layout_wined3d_object_destroyed(void *parent)
202 {
203 HeapFree(GetProcessHeap(), 0, parent);
204 }
205
206 static const struct wined3d_parent_ops d3d10_input_layout_wined3d_parent_ops =
207 {
208 d3d10_input_layout_wined3d_object_destroyed,
209 };
210
211 HRESULT d3d10_input_layout_init(struct d3d10_input_layout *layout, struct d3d10_device *device,
212 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
213 const void *shader_byte_code, SIZE_T shader_byte_code_length)
214 {
215 WINED3DVERTEXELEMENT *wined3d_elements;
216 UINT wined3d_element_count;
217 HRESULT hr;
218
219 layout->vtbl = &d3d10_input_layout_vtbl;
220 layout->refcount = 1;
221
222 hr = d3d10_input_layout_to_wined3d_declaration(element_descs, element_count,
223 shader_byte_code, shader_byte_code_length, &wined3d_elements, &wined3d_element_count);
224 if (FAILED(hr))
225 {
226 WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
227 return hr;
228 }
229
230 hr = IWineD3DDevice_CreateVertexDeclaration(device->wined3d_device, &layout->wined3d_decl,
231 (IUnknown *)layout, &d3d10_input_layout_wined3d_parent_ops, wined3d_elements, wined3d_element_count);
232 HeapFree(GetProcessHeap(), 0, wined3d_elements);
233 if (FAILED(hr))
234 {
235 WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
236 return hr;
237 }
238
239 return S_OK;
240 }
241
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.