2017-12-09 20:49:56 +01:00
|
|
|
#include "d3d11_device.h"
|
|
|
|
#include "d3d11_sampler.h"
|
2018-03-05 02:21:34 +01:00
|
|
|
#include "d3d11_util.h"
|
2017-12-09 20:49:56 +01:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D11SamplerState::D3D11SamplerState(
|
|
|
|
D3D11Device* device,
|
2018-03-05 02:21:34 +01:00
|
|
|
const D3D11_SAMPLER_DESC& desc)
|
|
|
|
: m_device(device), m_desc(desc) {
|
|
|
|
DxvkSamplerCreateInfo info;
|
2017-12-09 20:49:56 +01:00
|
|
|
|
2018-03-05 02:21:34 +01:00
|
|
|
// While D3D11_FILTER is technically an enum, its value bits
|
|
|
|
// can be used to decode the filter properties more efficiently.
|
|
|
|
const uint32_t filterBits = static_cast<uint32_t>(desc.Filter);
|
|
|
|
|
|
|
|
info.magFilter = (filterBits & 0x04) ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
|
|
|
|
info.minFilter = (filterBits & 0x10) ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
|
|
|
|
info.mipmapMode = (filterBits & 0x01) ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
|
|
|
info.useAnisotropy = (filterBits & 0x40) ? VK_TRUE : VK_FALSE;
|
|
|
|
info.compareToDepth = (filterBits & 0x80) ? VK_TRUE : VK_FALSE;
|
|
|
|
|
|
|
|
// Set up the remaining properties, which are
|
|
|
|
// stored directly in the sampler description
|
|
|
|
info.mipmapLodBias = desc.MipLODBias;
|
|
|
|
info.mipmapLodMin = desc.MinLOD;
|
|
|
|
info.mipmapLodMax = desc.MaxLOD;
|
|
|
|
info.maxAnisotropy = desc.MaxAnisotropy;
|
|
|
|
info.addressModeU = DecodeAddressMode(desc.AddressU);
|
|
|
|
info.addressModeV = DecodeAddressMode(desc.AddressV);
|
|
|
|
info.addressModeW = DecodeAddressMode(desc.AddressW);
|
|
|
|
info.compareOp = DecodeCompareOp(desc.ComparisonFunc);
|
|
|
|
info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
|
|
|
info.usePixelCoord = VK_FALSE; // Not supported in D3D11
|
|
|
|
|
2018-03-09 15:24:28 +01:00
|
|
|
// Make sure to use a valid anisotropy value
|
|
|
|
if (desc.MaxAnisotropy < 1) info.maxAnisotropy = 1.0f;
|
|
|
|
if (desc.MaxAnisotropy > 16) info.maxAnisotropy = 16.0f;
|
|
|
|
|
2018-03-05 02:21:34 +01:00
|
|
|
// Try to find a matching border color if clamp to border is enabled
|
|
|
|
if (info.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
|
|
|
|| info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
|
|
|
|| info.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)
|
|
|
|
info.borderColor = DecodeBorderColor(desc.BorderColor);
|
|
|
|
|
|
|
|
m_sampler = device->GetDXVKDevice()->createSampler(info);
|
2017-12-09 20:49:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11SamplerState::~D3D11SamplerState() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11SamplerState::QueryInterface(REFIID riid, void** ppvObject) {
|
2017-12-09 20:49:56 +01:00
|
|
|
COM_QUERY_IFACE(riid, ppvObject, IUnknown);
|
|
|
|
COM_QUERY_IFACE(riid, ppvObject, ID3D11DeviceChild);
|
|
|
|
COM_QUERY_IFACE(riid, ppvObject, ID3D11SamplerState);
|
|
|
|
|
|
|
|
Logger::warn("D3D11SamplerState::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-12-09 20:49:56 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11SamplerState::GetDevice(ID3D11Device** ppDevice) {
|
2018-03-18 14:57:14 +01:00
|
|
|
*ppDevice = ref(m_device);
|
2017-12-09 20:49:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11SamplerState::GetDesc(D3D11_SAMPLER_DESC* pDesc) {
|
2017-12-09 20:49:56 +01:00
|
|
|
*pDesc = m_desc;
|
|
|
|
}
|
|
|
|
|
2018-03-05 02:21:34 +01:00
|
|
|
|
2018-03-18 23:35:40 +01:00
|
|
|
HRESULT D3D11SamplerState::NormalizeDesc(D3D11_SAMPLER_DESC* pDesc) {
|
|
|
|
const uint32_t filterBits = static_cast<uint32_t>(pDesc->Filter);
|
2018-03-05 02:21:34 +01:00
|
|
|
|
|
|
|
if (filterBits & 0xFFFFFF2A) {
|
|
|
|
Logger::err(str::format("D3D11SamplerState: Unhandled filter: ", filterBits));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-09 20:49:56 +01:00
|
|
|
}
|