Commit e1a44a96 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

d3d11: Implement ID3D11ComputeShader interface.

parent 061aa115
......@@ -317,6 +317,20 @@ HRESULT d3d_pixel_shader_create(struct d3d_device *device, const void *byte_code
struct d3d_pixel_shader *unsafe_impl_from_ID3D11PixelShader(ID3D11PixelShader *iface) DECLSPEC_HIDDEN;
struct d3d_pixel_shader *unsafe_impl_from_ID3D10PixelShader(ID3D10PixelShader *iface) DECLSPEC_HIDDEN;
/* ID3D11ComputeShader */
struct d3d11_compute_shader
{
ID3D11ComputeShader ID3D11ComputeShader_iface;
LONG refcount;
struct wined3d_private_store private_store;
struct wined3d_shader *wined3d_shader;
ID3D11Device *device;
};
HRESULT d3d11_compute_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
struct d3d11_compute_shader **shader) DECLSPEC_HIDDEN;
HRESULT shader_parse_signature(const char *data, DWORD data_size, struct wined3d_shader_signature *s) DECLSPEC_HIDDEN;
void shader_free_signature(struct wined3d_shader_signature *s) DECLSPEC_HIDDEN;
......
......@@ -2235,10 +2235,22 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *i
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
{
FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
struct d3d_device *device = impl_from_ID3D11Device(iface);
struct d3d11_compute_shader *object;
HRESULT hr;
TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
iface, byte_code, byte_code_length, class_linkage, shader);
return E_NOTIMPL;
if (class_linkage)
FIXME("Class linkage is not implemented yet.\n");
if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
return hr;
*shader = &object->ID3D11ComputeShader_iface;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
......
......@@ -1500,6 +1500,190 @@ struct d3d_pixel_shader *unsafe_impl_from_ID3D10PixelShader(ID3D10PixelShader *i
return impl_from_ID3D10PixelShader(iface);
}
/* ID3D11ComputeShader methods */
static inline struct d3d11_compute_shader *impl_from_ID3D11ComputeShader(ID3D11ComputeShader *iface)
{
return CONTAINING_RECORD(iface, struct d3d11_compute_shader, ID3D11ComputeShader_iface);
}
static HRESULT STDMETHODCALLTYPE d3d11_compute_shader_QueryInterface(ID3D11ComputeShader *iface,
REFIID riid, void **object)
{
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
if (IsEqualGUID(riid, &IID_ID3D11ComputeShader)
|| IsEqualGUID(riid, &IID_ID3D11DeviceChild)
|| IsEqualGUID(riid, &IID_IUnknown))
{
ID3D11ComputeShader_AddRef(*object = iface);
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
*object = NULL;
return E_NOINTERFACE;
}
static ULONG STDMETHODCALLTYPE d3d11_compute_shader_AddRef(ID3D11ComputeShader *iface)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
ULONG refcount = InterlockedIncrement(&shader->refcount);
TRACE("%p increasing refcount to %u.\n", shader, refcount);
return refcount;
}
static ULONG STDMETHODCALLTYPE d3d11_compute_shader_Release(ID3D11ComputeShader *iface)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
ULONG refcount = InterlockedDecrement(&shader->refcount);
TRACE("%p decreasing refcount to %u.\n", shader, refcount);
if (!refcount)
{
ID3D11Device *device = shader->device;
wined3d_mutex_lock();
wined3d_shader_decref(shader->wined3d_shader);
wined3d_mutex_unlock();
/* Release the device last, it may cause the wined3d device to be
* destroyed. */
ID3D11Device_Release(device);
}
return refcount;
}
static void STDMETHODCALLTYPE d3d11_compute_shader_GetDevice(ID3D11ComputeShader *iface,
ID3D11Device **device)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
TRACE("iface %p, device %p.\n", iface, device);
ID3D11Device_AddRef(*device = shader->device);
}
static HRESULT STDMETHODCALLTYPE d3d11_compute_shader_GetPrivateData(ID3D11ComputeShader *iface,
REFGUID guid, UINT *data_size, void *data)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
return d3d_get_private_data(&shader->private_store, guid, data_size, data);
}
static HRESULT STDMETHODCALLTYPE d3d11_compute_shader_SetPrivateData(ID3D11ComputeShader *iface,
REFGUID guid, UINT data_size, const void *data)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
return d3d_set_private_data(&shader->private_store, guid, data_size, data);
}
static HRESULT STDMETHODCALLTYPE d3d11_compute_shader_SetPrivateDataInterface(ID3D11ComputeShader *iface,
REFGUID guid, const IUnknown *data)
{
struct d3d11_compute_shader *shader = impl_from_ID3D11ComputeShader(iface);
TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
return d3d_set_private_data_interface(&shader->private_store, guid, data);
}
static const struct ID3D11ComputeShaderVtbl d3d11_compute_shader_vtbl =
{
/* IUnknown methods */
d3d11_compute_shader_QueryInterface,
d3d11_compute_shader_AddRef,
d3d11_compute_shader_Release,
/* ID3D11DeviceChild methods */
d3d11_compute_shader_GetDevice,
d3d11_compute_shader_GetPrivateData,
d3d11_compute_shader_SetPrivateData,
d3d11_compute_shader_SetPrivateDataInterface,
};
static void STDMETHODCALLTYPE d3d11_compute_shader_wined3d_object_destroyed(void *parent)
{
struct d3d11_compute_shader *shader = parent;
wined3d_private_store_cleanup(&shader->private_store);
HeapFree(GetProcessHeap(), 0, parent);
}
static const struct wined3d_parent_ops d3d11_compute_shader_wined3d_parent_ops =
{
d3d11_compute_shader_wined3d_object_destroyed,
};
static HRESULT d3d11_compute_shader_init(struct d3d11_compute_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length)
{
struct wined3d_shader_desc desc;
HRESULT hr;
shader->ID3D11ComputeShader_iface.lpVtbl = &d3d11_compute_shader_vtbl;
shader->refcount = 1;
wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store);
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &desc)))
{
WARN("Failed to extract shader, hr %#x.\n", hr);
wined3d_private_store_cleanup(&shader->private_store);
wined3d_mutex_unlock();
return hr;
}
desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_cs(device->wined3d_device, &desc, shader,
&d3d11_compute_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&desc.input_signature);
shader_free_signature(&desc.output_signature);
if (FAILED(hr))
{
WARN("Failed to create wined3d compute shader, hr %#x.\n", hr);
wined3d_private_store_cleanup(&shader->private_store);
wined3d_mutex_unlock();
return E_INVALIDARG;
}
wined3d_mutex_unlock();
ID3D11Device_AddRef(shader->device = &device->ID3D11Device_iface);
return S_OK;
}
HRESULT d3d11_compute_shader_create(struct d3d_device *device, const void *byte_code, SIZE_T byte_code_length,
struct d3d11_compute_shader **shader)
{
struct d3d11_compute_shader *object;
HRESULT hr;
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
return E_OUTOFMEMORY;
if (FAILED(hr = d3d11_compute_shader_init(object, device, byte_code, byte_code_length)))
{
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
TRACE("Created compute shader %p.\n", object);
*shader = object;
return S_OK;
}
/* ID3D11ClassLinkage methods */
static inline struct d3d11_class_linkage *impl_from_ID3D11ClassLinkage(ID3D11ClassLinkage *iface)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment