1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-04 16:24:29 +01:00

[d3d9] Use FLOAT or FORCE_UNORM depth bias representation

This commit is contained in:
Joshua Ashton 2023-06-15 13:01:01 +01:00 committed by Joshie
parent 4e9853f608
commit b30a4f0cc7
3 changed files with 35 additions and 6 deletions

View File

@ -116,6 +116,25 @@ namespace dxvk {
m_usingGraphicsPipelines = dxvkDevice->features().extGraphicsPipelineLibrary.graphicsPipelineLibrary;
m_depthBiasRepresentation = { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, false };
if (dxvkDevice->features().extDepthBiasControl.depthBiasControl) {
if (dxvkDevice->features().extDepthBiasControl.depthBiasExact)
m_depthBiasRepresentation.depthBiasExact = true;
if (dxvkDevice->features().extDepthBiasControl.floatRepresentation) {
m_depthBiasRepresentation.depthBiasRepresentation = VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT;
m_depthBiasScale = 1.0f;
}
else if (dxvkDevice->features().extDepthBiasControl.leastRepresentableValueForceUnormRepresentation)
m_depthBiasRepresentation.depthBiasRepresentation = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT;
}
EmitCs([
cRepresentation = m_depthBiasRepresentation
] (DxvkContext* ctx) {
ctx->setDepthBiasRepresentation(cRepresentation);
});
CreateConstantBuffers();
m_availableMemory = DetermineInitialTextureMemory();
@ -1505,9 +1524,11 @@ namespace dxvk {
FlushImplicit(FALSE);
m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
if (ds != nullptr) {
if (ds != nullptr && m_depthBiasRepresentation.depthBiasRepresentation != VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT) {
const int32_t vendorId = m_dxvkDevice->adapter()->deviceProperties().vendorID;
float rValue = GetDepthBufferRValue(ds->GetCommonTexture()->GetFormatMapping().FormatColor, vendorId);
const bool exact = m_depthBiasRepresentation.depthBiasExact;
const bool forceUnorm = m_depthBiasRepresentation.depthBiasRepresentation == VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT;
const float rValue = GetDepthBufferRValue(ds->GetCommonTexture()->GetFormatMapping().FormatColor, vendorId, exact, forceUnorm);
if (m_depthBiasScale != rValue) {
m_depthBiasScale = rValue;
m_flags.set(D3D9DeviceFlag::DirtyDepthBias);
@ -4140,6 +4161,13 @@ namespace dxvk {
enabled.extNonSeamlessCubeMap.nonSeamlessCubeMap = supported.extNonSeamlessCubeMap.nonSeamlessCubeMap;
enabled.extDepthBiasControl.depthBiasControl = supported.extDepthBiasControl.depthBiasControl;
enabled.extDepthBiasControl.depthBiasExact = supported.extDepthBiasControl.depthBiasExact;
if (supported.extDepthBiasControl.floatRepresentation)
enabled.extDepthBiasControl.floatRepresentation = VK_TRUE;
else if (supported.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation)
enabled.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation = VK_TRUE;
return enabled;
}

View File

@ -1318,6 +1318,7 @@ namespace dxvk {
bool m_usingGraphicsPipelines = false;
DxvkDepthBiasRepresentation m_depthBiasRepresentation = { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, false };
float m_depthBiasScale = 0.0f;
uint32_t m_robustSSBOAlignment = 1;

View File

@ -176,19 +176,19 @@ namespace dxvk {
void ConvertRect(RECT rect, VkOffset2D& offset, VkExtent2D& extent);
inline float GetDepthBufferRValue(VkFormat Format, int32_t vendorId) {
inline float GetDepthBufferRValue(VkFormat Format, int32_t vendorId, bool exact, bool forceUnorm) {
switch (Format) {
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D16_UNORM:
return vendorId == 0x10de ? float(1 << 15) : float(1 << 16);
return (vendorId == 0x10de && !exact) ? float(1 << 15) : float(1 << 16);
case VK_FORMAT_D24_UNORM_S8_UINT:
return vendorId == 0x10de ? float(1 << 23) : float(1 << 24);
return (vendorId == 0x10de && !exact) ? float(1 << 23) : float(1 << 24);
default:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
case VK_FORMAT_D32_SFLOAT:
return float(1 << 23);
return forceUnorm ? float(1 << 24) : float(1 << 23);
}
}