2017-12-06 13:16:54 +01:00
|
|
|
#include "d3d11_device.h"
|
2017-12-10 23:27:20 +01:00
|
|
|
#include "d3d11_rasterizer.h"
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D11RasterizerState::D3D11RasterizerState(
|
|
|
|
D3D11Device* device,
|
2018-03-18 22:53:20 +01:00
|
|
|
const D3D11_RASTERIZER_DESC1& desc)
|
2018-08-11 22:44:10 +02:00
|
|
|
: m_device(device), m_desc(desc), m_d3d10(this) {
|
2017-12-06 13:16:54 +01:00
|
|
|
// Polygon mode. Determines whether the rasterizer fills
|
|
|
|
// a polygon or renders lines connecting the vertices.
|
2017-12-08 00:02:43 +01:00
|
|
|
m_state.polygonMode = VK_POLYGON_MODE_FILL;
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
switch (desc.FillMode) {
|
2017-12-08 00:02:43 +01:00
|
|
|
case D3D11_FILL_WIREFRAME: m_state.polygonMode = VK_POLYGON_MODE_LINE; break;
|
|
|
|
case D3D11_FILL_SOLID: m_state.polygonMode = VK_POLYGON_MODE_FILL; break;
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11RasterizerState: Unsupported fill mode: ",
|
|
|
|
desc.FillMode));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Face culling properties. The rasterizer may discard
|
|
|
|
// polygons that are facing towards or away from the
|
|
|
|
// viewer, depending on the options below.
|
2017-12-08 00:02:43 +01:00
|
|
|
m_state.cullMode = VK_CULL_MODE_NONE;
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
switch (desc.CullMode) {
|
2017-12-08 00:02:43 +01:00
|
|
|
case D3D11_CULL_NONE: m_state.cullMode = VK_CULL_MODE_NONE; break;
|
|
|
|
case D3D11_CULL_FRONT: m_state.cullMode = VK_CULL_MODE_FRONT_BIT; break;
|
|
|
|
case D3D11_CULL_BACK: m_state.cullMode = VK_CULL_MODE_BACK_BIT; break;
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11RasterizerState: Unsupported cull mode: ",
|
|
|
|
desc.CullMode));
|
|
|
|
}
|
|
|
|
|
2017-12-08 00:02:43 +01:00
|
|
|
m_state.frontFace = desc.FrontCounterClockwise
|
2017-12-06 13:16:54 +01:00
|
|
|
? VK_FRONT_FACE_COUNTER_CLOCKWISE
|
|
|
|
: VK_FRONT_FACE_CLOCKWISE;
|
|
|
|
|
2019-01-17 00:53:54 +01:00
|
|
|
// In the backend we treat depth bias as a dynamic state because
|
|
|
|
// some games like to put random/uninitialized numbers here, but
|
|
|
|
// we do not need to enable it in case the parameters are both 0.
|
|
|
|
m_state.depthBiasEnable = desc.DepthBias != 0 || desc.SlopeScaledDepthBias != 0.0f;
|
2017-12-08 00:02:43 +01:00
|
|
|
m_state.depthBiasConstant = static_cast<float>(desc.DepthBias);
|
|
|
|
m_state.depthBiasClamp = desc.DepthBiasClamp;
|
|
|
|
m_state.depthBiasSlope = desc.SlopeScaledDepthBias;
|
2019-01-17 01:58:03 +01:00
|
|
|
m_state.depthClipEnable = desc.DepthClipEnable;
|
2018-09-18 13:21:58 +02:00
|
|
|
m_state.sampleCount = VkSampleCountFlags(desc.ForcedSampleCount);
|
2017-12-06 13:16:54 +01:00
|
|
|
|
|
|
|
if (desc.AntialiasedLineEnable)
|
|
|
|
Logger::err("D3D11RasterizerState: Antialiased lines not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11RasterizerState::~D3D11RasterizerState() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11RasterizerState::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11RasterizerState)
|
|
|
|
|| riid == __uuidof(ID3D11RasterizerState1)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-12-06 13:16:54 +01:00
|
|
|
|
2018-08-11 22:44:10 +02:00
|
|
|
if (riid == __uuidof(ID3D10DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D10RasterizerState)) {
|
|
|
|
*ppvObject = ref(&m_d3d10);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-06 13:16:54 +01:00
|
|
|
Logger::warn("D3D11RasterizerState::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-12-06 13:16:54 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11RasterizerState::GetDevice(ID3D11Device** ppDevice) {
|
2017-12-11 17:01:38 +01:00
|
|
|
*ppDevice = ref(m_device);
|
2017-12-06 13:16:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11RasterizerState::GetDesc(D3D11_RASTERIZER_DESC* pDesc) {
|
2018-03-18 22:53:20 +01:00
|
|
|
pDesc->FillMode = m_desc.FillMode;
|
|
|
|
pDesc->CullMode = m_desc.CullMode;
|
|
|
|
pDesc->FrontCounterClockwise = m_desc.FrontCounterClockwise;
|
|
|
|
pDesc->DepthBias = m_desc.DepthBias;
|
|
|
|
pDesc->DepthBiasClamp = m_desc.DepthBiasClamp;
|
|
|
|
pDesc->SlopeScaledDepthBias = m_desc.SlopeScaledDepthBias;
|
|
|
|
pDesc->DepthClipEnable = m_desc.DepthClipEnable;
|
|
|
|
pDesc->ScissorEnable = m_desc.ScissorEnable;
|
|
|
|
pDesc->MultisampleEnable = m_desc.MultisampleEnable;
|
|
|
|
pDesc->AntialiasedLineEnable = m_desc.AntialiasedLineEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11RasterizerState::GetDesc1(D3D11_RASTERIZER_DESC1* pDesc) {
|
2017-12-06 13:16:54 +01:00
|
|
|
*pDesc = m_desc;
|
|
|
|
}
|
|
|
|
|
2017-12-11 13:07:27 +01:00
|
|
|
|
|
|
|
void D3D11RasterizerState::BindToContext(const Rc<DxvkContext>& ctx) {
|
|
|
|
ctx->setRasterizerState(m_state);
|
|
|
|
}
|
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
|
|
|
|
D3D11_RASTERIZER_DESC1 D3D11RasterizerState::DefaultDesc() {
|
|
|
|
D3D11_RASTERIZER_DESC1 dstDesc;
|
|
|
|
dstDesc.FillMode = D3D11_FILL_SOLID;
|
|
|
|
dstDesc.CullMode = D3D11_CULL_BACK;
|
|
|
|
dstDesc.FrontCounterClockwise = FALSE;
|
|
|
|
dstDesc.DepthBias = 0;
|
|
|
|
dstDesc.SlopeScaledDepthBias = 0.0f;
|
|
|
|
dstDesc.DepthBiasClamp = 0.0f;
|
|
|
|
dstDesc.DepthClipEnable = TRUE;
|
|
|
|
dstDesc.ScissorEnable = FALSE;
|
|
|
|
dstDesc.MultisampleEnable = FALSE;
|
|
|
|
dstDesc.AntialiasedLineEnable = FALSE;
|
|
|
|
dstDesc.ForcedSampleCount = 0;
|
|
|
|
return dstDesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11_RASTERIZER_DESC1 D3D11RasterizerState::PromoteDesc(
|
|
|
|
const D3D11_RASTERIZER_DESC* pSrcDesc) {
|
|
|
|
D3D11_RASTERIZER_DESC1 dstDesc;
|
|
|
|
dstDesc.FillMode = pSrcDesc->FillMode;
|
|
|
|
dstDesc.CullMode = pSrcDesc->CullMode;
|
|
|
|
dstDesc.FrontCounterClockwise = pSrcDesc->FrontCounterClockwise;
|
|
|
|
dstDesc.DepthBias = pSrcDesc->DepthBias;
|
|
|
|
dstDesc.DepthBiasClamp = pSrcDesc->DepthBiasClamp;
|
|
|
|
dstDesc.SlopeScaledDepthBias = pSrcDesc->SlopeScaledDepthBias;
|
|
|
|
dstDesc.DepthClipEnable = pSrcDesc->DepthClipEnable;
|
|
|
|
dstDesc.ScissorEnable = pSrcDesc->ScissorEnable;
|
|
|
|
dstDesc.MultisampleEnable = pSrcDesc->MultisampleEnable;
|
|
|
|
dstDesc.AntialiasedLineEnable = pSrcDesc->AntialiasedLineEnable;
|
|
|
|
dstDesc.ForcedSampleCount = 0;
|
|
|
|
return dstDesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT D3D11RasterizerState::NormalizeDesc(
|
|
|
|
D3D11_RASTERIZER_DESC1* pDesc) {
|
2018-04-30 10:41:57 +02:00
|
|
|
if (pDesc->FillMode < D3D11_FILL_WIREFRAME
|
|
|
|
|| pDesc->FillMode > D3D11_FILL_SOLID)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (pDesc->CullMode < D3D11_CULL_NONE
|
|
|
|
|| pDesc->CullMode > D3D11_CULL_BACK)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (pDesc->FrontCounterClockwise)
|
|
|
|
pDesc->FrontCounterClockwise = TRUE;
|
|
|
|
|
|
|
|
if (pDesc->DepthClipEnable)
|
|
|
|
pDesc->DepthClipEnable = TRUE;
|
|
|
|
|
|
|
|
if (pDesc->ScissorEnable)
|
|
|
|
pDesc->ScissorEnable = TRUE;
|
|
|
|
|
|
|
|
if (pDesc->MultisampleEnable)
|
|
|
|
pDesc->MultisampleEnable = TRUE;
|
|
|
|
|
|
|
|
if (pDesc->AntialiasedLineEnable)
|
|
|
|
pDesc->AntialiasedLineEnable = TRUE;
|
|
|
|
|
|
|
|
if (pDesc->ForcedSampleCount != 0) {
|
|
|
|
if (FAILED(DecodeSampleCount(pDesc->ForcedSampleCount, nullptr)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-03-18 22:53:20 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-06 13:16:54 +01:00
|
|
|
}
|