From 48b13fe2bcf3fd6149923a10732cb57716d0d134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 13 Oct 2015 09:13:34 +0200 Subject: [PATCH] d3d11: Implement d3d11_device_CreateSamplerState(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d11/device.c | 88 +++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index f649d6bcc9c..8a7a794517c 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -1442,9 +1442,55 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface, const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state) { - FIXME("iface %p, desc %p, sampler_state %p stub!\n", iface, desc, sampler_state); + struct d3d_device *device = impl_from_ID3D11Device(iface); + D3D11_SAMPLER_DESC normalized_desc; + struct d3d_sampler_state *object; + struct wine_rb_entry *entry; + HRESULT hr; - return E_NOTIMPL; + TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state); + + if (!desc) + return E_INVALIDARG; + + normalized_desc = *desc; + if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter)) + normalized_desc.MaxAnisotropy = 0; + if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter)) + normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; + if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER + && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER + && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER) + memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor)); + + wined3d_mutex_lock(); + if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc))) + { + object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry); + + TRACE("Returning existing sampler state %p.\n", object); + *sampler_state = &object->ID3D11SamplerState_iface; + ID3D11SamplerState_AddRef(*sampler_state); + wined3d_mutex_unlock(); + + return S_OK; + } + wined3d_mutex_unlock(); + + if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)))) + return E_OUTOFMEMORY; + + if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc))) + { + WARN("Failed to initialize sampler state, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + TRACE("Created sampler state %p.\n", object); + *sampler_state = &object->ID3D11SamplerState_iface; + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface, @@ -3540,44 +3586,18 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 * const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state) { struct d3d_device *device = impl_from_ID3D10Device(iface); - struct d3d_sampler_state *object; - struct wine_rb_entry *entry; + ID3D11SamplerState *d3d11_sampler_state; HRESULT hr; TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state); - if (!desc) - return E_INVALIDARG; - - wined3d_mutex_lock(); - if ((entry = wine_rb_get(&device->sampler_states, desc))) - { - object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry); - - TRACE("Returning existing sampler state %p.\n", object); - *sampler_state = &object->ID3D10SamplerState_iface; - ID3D10SamplerState_AddRef(*sampler_state); - wined3d_mutex_unlock(); - - return S_OK; - } - wined3d_mutex_unlock(); - - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); - if (!object) - return E_OUTOFMEMORY; - - if (FAILED(hr = d3d_sampler_state_init(object, device, (const D3D11_SAMPLER_DESC *)desc))) - { - WARN("Failed to initialize sampler state, hr %#x.\n", hr); - HeapFree(GetProcessHeap(), 0, object); + if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface, + (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state))) return hr; - } - TRACE("Created sampler state %p.\n", object); - *sampler_state = &object->ID3D10SamplerState_iface; - - return S_OK; + hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state); + ID3D11SamplerState_Release(d3d11_sampler_state); + return hr; } static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,