2009-03-04 07:07:38 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include "d3d10core_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
|
|
|
|
|
2009-03-30 11:24:55 +02:00
|
|
|
static HRESULT isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
|
|
|
|
{
|
2009-05-08 17:44:25 +02:00
|
|
|
struct wined3d_shader_signature *is = ctx;
|
2009-03-30 11:24:55 +02:00
|
|
|
|
|
|
|
switch(tag)
|
|
|
|
{
|
|
|
|
case TAG_ISGN:
|
2009-05-08 17:44:25 +02:00
|
|
|
return shader_parse_signature(data, data_size, is);
|
2009-03-30 11:24:55 +02:00
|
|
|
|
|
|
|
default:
|
2009-09-09 18:12:40 +02:00
|
|
|
FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag, 4));
|
2009-03-30 11:24:55 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:05:48 +02:00
|
|
|
static HRESULT d3d10_input_layout_to_wined3d_declaration(const D3D10_INPUT_ELEMENT_DESC *element_descs,
|
2009-03-30 11:24:55 +02:00
|
|
|
UINT element_count, const void *shader_byte_code, SIZE_T shader_byte_code_length,
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element **wined3d_elements, UINT *wined3d_element_count)
|
2009-03-30 11:24:55 +02:00
|
|
|
{
|
2009-05-08 17:44:25 +02:00
|
|
|
struct wined3d_shader_signature is;
|
2009-03-30 11:24:55 +02:00
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to parse input signature.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(**wined3d_elements));
|
|
|
|
if (!*wined3d_elements)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate wined3d vertex element array memory.\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, is.elements);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
*wined3d_element_count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < element_count; ++i)
|
|
|
|
{
|
|
|
|
UINT j;
|
|
|
|
|
|
|
|
for (j = 0; j < is.element_count; ++j)
|
|
|
|
{
|
|
|
|
if (!strcmp(element_descs[i].SemanticName, is.elements[j].semantic_name)
|
|
|
|
&& element_descs[i].SemanticIndex == is.elements[j].semantic_idx)
|
|
|
|
{
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *e = &(*wined3d_elements)[(*wined3d_element_count)++];
|
2009-03-30 11:24:55 +02:00
|
|
|
const D3D10_INPUT_ELEMENT_DESC *f = &element_descs[i];
|
|
|
|
|
|
|
|
e->format = wined3dformat_from_dxgi_format(f->Format);
|
|
|
|
e->input_slot = f->InputSlot;
|
|
|
|
e->offset = f->AlignedByteOffset;
|
|
|
|
e->output_slot = is.elements[j].register_idx;
|
2012-01-18 21:46:21 +01:00
|
|
|
e->method = WINED3D_DECL_METHOD_DEFAULT;
|
2009-03-30 11:24:55 +02:00
|
|
|
e->usage = 0;
|
|
|
|
e->usage_idx = 0;
|
|
|
|
|
|
|
|
if (f->AlignedByteOffset == D3D10_APPEND_ALIGNED_ELEMENT)
|
|
|
|
FIXME("D3D10_APPEND_ALIGNED_ELEMENT not supported\n");
|
|
|
|
if (f->InputSlotClass != D3D10_INPUT_PER_VERTEX_DATA)
|
|
|
|
FIXME("Ignoring input slot class (%#x)\n", f->InputSlotClass);
|
|
|
|
if (f->InstanceDataStepRate)
|
2014-01-09 15:02:45 +01:00
|
|
|
FIXME("Ignoring instance data step rate (%#x)\n", f->InstanceDataStepRate);
|
2009-03-30 11:24:55 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-08 17:44:25 +02:00
|
|
|
shader_free_signature(&is);
|
2009-03-30 11:24:55 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:50:41 +02:00
|
|
|
static inline struct d3d10_input_layout *impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
|
|
|
|
{
|
2011-07-12 12:51:54 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d10_input_layout, ID3D10InputLayout_iface);
|
2011-07-12 12:50:41 +02:00
|
|
|
}
|
|
|
|
|
2009-03-04 07:07:38 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_input_layout_QueryInterface(ID3D10InputLayout *iface,
|
|
|
|
REFIID riid, void **object)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_ID3D10InputLayout)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3D10DeviceChild)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d10_input_layout_AddRef(ID3D10InputLayout *iface)
|
|
|
|
{
|
2011-07-12 12:51:54 +02:00
|
|
|
struct d3d10_input_layout *This = impl_from_ID3D10InputLayout(iface);
|
2009-03-04 07:07:38 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u\n", This, refcount);
|
|
|
|
|
2009-09-23 10:05:52 +02:00
|
|
|
if (refcount == 1)
|
|
|
|
{
|
2011-02-02 20:22:50 +01:00
|
|
|
wined3d_vertex_declaration_incref(This->wined3d_decl);
|
2009-09-23 10:05:52 +02:00
|
|
|
}
|
|
|
|
|
2009-03-04 07:07:38 +01:00
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d10_input_layout_Release(ID3D10InputLayout *iface)
|
|
|
|
{
|
2011-07-12 12:51:54 +02:00
|
|
|
struct d3d10_input_layout *This = impl_from_ID3D10InputLayout(iface);
|
2009-03-04 07:07:38 +01:00
|
|
|
ULONG refcount = InterlockedDecrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2011-02-02 20:22:50 +01:00
|
|
|
wined3d_vertex_declaration_decref(This->wined3d_decl);
|
2009-03-04 07:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ID3D10DeviceChild methods */
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_input_layout_GetDevice(ID3D10InputLayout *iface, ID3D10Device **device)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, device %p stub!\n", iface, device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_input_layout_GetPrivateData(ID3D10InputLayout *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
|
|
|
|
iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateData(ID3D10InputLayout *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
|
|
|
|
iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout *iface,
|
|
|
|
REFGUID guid, const IUnknown *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:05:48 +02:00
|
|
|
static const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl =
|
2009-03-04 07:07:38 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
d3d10_input_layout_QueryInterface,
|
|
|
|
d3d10_input_layout_AddRef,
|
|
|
|
d3d10_input_layout_Release,
|
|
|
|
/* ID3D10DeviceChild methods */
|
|
|
|
d3d10_input_layout_GetDevice,
|
|
|
|
d3d10_input_layout_GetPrivateData,
|
|
|
|
d3d10_input_layout_SetPrivateData,
|
|
|
|
d3d10_input_layout_SetPrivateDataInterface,
|
|
|
|
};
|
2009-09-23 10:05:48 +02:00
|
|
|
|
2009-09-23 10:05:52 +02:00
|
|
|
static void STDMETHODCALLTYPE d3d10_input_layout_wined3d_object_destroyed(void *parent)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d10_input_layout_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d10_input_layout_wined3d_object_destroyed,
|
|
|
|
};
|
|
|
|
|
2009-09-23 10:05:48 +02:00
|
|
|
HRESULT d3d10_input_layout_init(struct d3d10_input_layout *layout, struct d3d10_device *device,
|
|
|
|
const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
|
|
|
|
const void *shader_byte_code, SIZE_T shader_byte_code_length)
|
|
|
|
{
|
2011-11-24 22:52:36 +01:00
|
|
|
struct wined3d_vertex_element *wined3d_elements;
|
2009-09-23 10:05:48 +02:00
|
|
|
UINT wined3d_element_count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-07-12 12:51:54 +02:00
|
|
|
layout->ID3D10InputLayout_iface.lpVtbl = &d3d10_input_layout_vtbl;
|
2009-09-23 10:05:48 +02:00
|
|
|
layout->refcount = 1;
|
|
|
|
|
|
|
|
hr = d3d10_input_layout_to_wined3d_declaration(element_descs, element_count,
|
|
|
|
shader_byte_code, shader_byte_code_length, &wined3d_elements, &wined3d_element_count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:18:47 +02:00
|
|
|
hr = wined3d_vertex_declaration_create(device->wined3d_device, wined3d_elements, wined3d_element_count,
|
2010-08-31 18:41:40 +02:00
|
|
|
layout, &d3d10_input_layout_wined3d_parent_ops, &layout->wined3d_decl);
|
2009-09-23 10:05:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2011-07-12 12:50:41 +02:00
|
|
|
|
|
|
|
struct d3d10_input_layout *unsafe_impl_from_ID3D10InputLayout(ID3D10InputLayout *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d10_input_layout_vtbl);
|
|
|
|
|
|
|
|
return impl_from_ID3D10InputLayout(iface);
|
|
|
|
}
|