Commit b738c422 authored by Joshua Ashton's avatar Joshua Ashton 🐸

[d3d9] Scale depth bias value based on current format's `r` value

parent 2d7f4b1a
Pipeline #987 passed with stage
in 4 minutes and 5 seconds
......@@ -1231,6 +1231,14 @@ namespace dxvk {
FlushImplicit(FALSE);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
if (ds != nullptr) {
float rValue = GetDepthBufferRValue(ds->GetCommonTexture()->GetFormatMapping().FormatColor);
if (m_depthBiasScale != rValue) {
m_depthBiasScale = rValue;
m_flags.set(D3D9DeviceFlag::DirtyDepthBias);
}
}
m_state.depthStencil = ds;
return D3D_OK;
......@@ -5096,12 +5104,9 @@ namespace dxvk {
void D3D9DeviceEx::BindDepthBias() {
m_flags.clr(D3D9DeviceFlag::DirtyDepthBias);
// TODO: Can we get a specific non-magic number in Vulkan for this based on device/adapter?
constexpr float DepthBiasFactor = float(1 << 23);
auto& rs = m_state.renderStates;
float depthBias = bit::cast<float>(rs[D3DRS_DEPTHBIAS]) * DepthBiasFactor;
float depthBias = bit::cast<float>(rs[D3DRS_DEPTHBIAS]) * m_depthBiasScale;
float slopeScaledDepthBias = bit::cast<float>(rs[D3DRS_SLOPESCALEDEPTHBIAS]);
DxvkDepthBias biases;
......
......@@ -1025,6 +1025,8 @@ namespace dxvk {
bool m_nvATOC = false;
bool m_ffZTest = false;
float m_depthBiasScale = 0.0f;
D3D9ConstantLayout m_vsLayout;
D3D9ConstantLayout m_psLayout;
......
......@@ -176,6 +176,22 @@ namespace dxvk {
void ConvertRect(RECT rect, VkOffset2D& offset, VkExtent2D& extent);
inline float GetDepthBufferRValue(VkFormat Format) {
switch (Format) {
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D16_UNORM:
return float(1 << 16);
case VK_FORMAT_D24_UNORM_S8_UINT:
return float(1 << 24);
default:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
case VK_FORMAT_D32_SFLOAT:
return float(1 << 23);
}
}
template<typename T>
UINT CompactSparseList(T* pData, UINT Mask) {
uint32_t count = 0;
......
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