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
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
;
34 return shader_parse_signature(data
, data_size
, is
);
37 FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag
, 4));
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
)
46 struct wined3d_shader_signature is
;
50 hr
= parse_dxbc(shader_byte_code
, shader_byte_code_length
, isgn_handler
, &is
);
53 ERR("Failed to parse input signature.\n");
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
);
65 for (i
= 0; i
< element_count
; ++i
)
67 struct wined3d_vertex_element
*e
= &(*wined3d_elements
)[i
];
68 const D3D10_INPUT_ELEMENT_DESC
*f
= &element_descs
[i
];
71 e
->format
= wined3dformat_from_dxgi_format(f
->Format
);
72 e
->input_slot
= f
->InputSlot
;
73 e
->offset
= f
->AlignedByteOffset
;
74 e
->output_slot
= WINED3D_OUTPUT_SLOT_UNUSED
;
75 e
->input_slot_class
= f
->InputSlotClass
;
76 e
->instance_data_step_rate
= f
->InstanceDataStepRate
;
77 e
->method
= WINED3D_DECL_METHOD_DEFAULT
;
81 for (j
= 0; j
< is
.element_count
; ++j
)
83 if (!strcmp(element_descs
[i
].SemanticName
, is
.elements
[j
].semantic_name
)
84 && element_descs
[i
].SemanticIndex
== is
.elements
[j
].semantic_idx
)
86 e
->output_slot
= is
.elements
[j
].register_idx
;
92 shader_free_signature(&is
);
97 static inline struct d3d10_input_layout
*impl_from_ID3D10InputLayout(ID3D10InputLayout
*iface
)
99 return CONTAINING_RECORD(iface
, struct d3d10_input_layout
, ID3D10InputLayout_iface
);
102 /* IUnknown methods */
104 static HRESULT STDMETHODCALLTYPE
d3d10_input_layout_QueryInterface(ID3D10InputLayout
*iface
,
105 REFIID riid
, void **object
)
107 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
109 if (IsEqualGUID(riid
, &IID_ID3D10InputLayout
)
110 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
111 || IsEqualGUID(riid
, &IID_IUnknown
))
113 IUnknown_AddRef(iface
);
118 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
121 return E_NOINTERFACE
;
124 static ULONG STDMETHODCALLTYPE
d3d10_input_layout_AddRef(ID3D10InputLayout
*iface
)
126 struct d3d10_input_layout
*This
= impl_from_ID3D10InputLayout(iface
);
127 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
129 TRACE("%p increasing refcount to %u\n", This
, refcount
);
133 wined3d_mutex_lock();
134 wined3d_vertex_declaration_incref(This
->wined3d_decl
);
135 wined3d_mutex_unlock();
141 static ULONG STDMETHODCALLTYPE
d3d10_input_layout_Release(ID3D10InputLayout
*iface
)
143 struct d3d10_input_layout
*This
= impl_from_ID3D10InputLayout(iface
);
144 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
146 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
150 wined3d_mutex_lock();
151 wined3d_vertex_declaration_decref(This
->wined3d_decl
);
152 wined3d_mutex_unlock();
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 struct d3d10_input_layout
*layout
= impl_from_ID3D10InputLayout(iface
);
170 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
171 iface
, debugstr_guid(guid
), data_size
, data
);
173 return d3d10_get_private_data(&layout
->private_store
, guid
, data_size
, data
);
176 static HRESULT STDMETHODCALLTYPE
d3d10_input_layout_SetPrivateData(ID3D10InputLayout
*iface
,
177 REFGUID guid
, UINT data_size
, const void *data
)
179 struct d3d10_input_layout
*layout
= impl_from_ID3D10InputLayout(iface
);
181 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
182 iface
, debugstr_guid(guid
), data_size
, data
);
184 return d3d10_set_private_data(&layout
->private_store
, guid
, data_size
, data
);
187 static HRESULT STDMETHODCALLTYPE
d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout
*iface
,
188 REFGUID guid
, const IUnknown
*data
)
190 struct d3d10_input_layout
*layout
= impl_from_ID3D10InputLayout(iface
);
192 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
194 return d3d10_set_private_data_interface(&layout
->private_store
, guid
, data
);
197 static const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl
=
199 /* IUnknown methods */
200 d3d10_input_layout_QueryInterface
,
201 d3d10_input_layout_AddRef
,
202 d3d10_input_layout_Release
,
203 /* ID3D10DeviceChild methods */
204 d3d10_input_layout_GetDevice
,
205 d3d10_input_layout_GetPrivateData
,
206 d3d10_input_layout_SetPrivateData
,
207 d3d10_input_layout_SetPrivateDataInterface
,
210 static void STDMETHODCALLTYPE
d3d10_input_layout_wined3d_object_destroyed(void *parent
)
212 struct d3d10_input_layout
*layout
= parent
;
214 wined3d_private_store_cleanup(&layout
->private_store
);
215 HeapFree(GetProcessHeap(), 0, parent
);
218 static const struct wined3d_parent_ops d3d10_input_layout_wined3d_parent_ops
=
220 d3d10_input_layout_wined3d_object_destroyed
,
223 HRESULT
d3d10_input_layout_init(struct d3d10_input_layout
*layout
, struct d3d10_device
*device
,
224 const D3D10_INPUT_ELEMENT_DESC
*element_descs
, UINT element_count
,
225 const void *shader_byte_code
, SIZE_T shader_byte_code_length
)
227 struct wined3d_vertex_element
*wined3d_elements
;
230 layout
->ID3D10InputLayout_iface
.lpVtbl
= &d3d10_input_layout_vtbl
;
231 layout
->refcount
= 1;
232 wined3d_mutex_lock();
233 wined3d_private_store_init(&layout
->private_store
);
235 if (FAILED(hr
= d3d10_input_layout_to_wined3d_declaration(element_descs
, element_count
,
236 shader_byte_code
, shader_byte_code_length
, &wined3d_elements
)))
238 WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr
);
239 wined3d_private_store_cleanup(&layout
->private_store
);
240 wined3d_mutex_unlock();
244 hr
= wined3d_vertex_declaration_create(device
->wined3d_device
, wined3d_elements
, element_count
,
245 layout
, &d3d10_input_layout_wined3d_parent_ops
, &layout
->wined3d_decl
);
246 HeapFree(GetProcessHeap(), 0, wined3d_elements
);
249 WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr
);
250 wined3d_private_store_cleanup(&layout
->private_store
);
251 wined3d_mutex_unlock();
254 wined3d_mutex_unlock();
259 struct d3d10_input_layout
*unsafe_impl_from_ID3D10InputLayout(ID3D10InputLayout
*iface
)
263 assert(iface
->lpVtbl
== &d3d10_input_layout_vtbl
);
265 return impl_from_ID3D10InputLayout(iface
);