An (unofficial) Vulkan Depth Bias Extension

An (unofficial) Vulkan Depth Bias Extension


D3D9 (Floating Point Depth Bias)

D3D9 requires us to use floating point depth bias values -- this is an issue as Vulkan uses lowest representable value for the value (which is format based), however, we can't just multiply our way out of this problem, as this wouldn't work as depth bias has completely different behaviour for floating point depth stencil formats.

Having regular floating point values is natively supported on both AMD and Intel with minimal effort.

This extension proposes the ability to set the depth bias mode, so we can take advantage of this.

D3D11 (Vendor Scale)

There is a detail I did not mention in the previous section, and that is in Vulkan (and D3D11 for some vendors), the depth bias may be scaled (eg. to get a separation between line and tri) and we have no knowledge of this scale for a given format, etc. This produces inaccurate rendering as in RADV the scales don't match that (or the lack thereof) in D3D11.

This extension propses that we have the ability to control this if we wish -- hence alleviating the problem.

Test Implementation

I've bodged together a test of this for a proof of concept that something like this could work. It's not meant to be future-proof, but hopefully it shows my point and what I mean.

I have done an implementation of what I believe the extension should look like in RADV, and hooked it up to D9VK, DXVK and WineVulkan. The appropriate patches are below:

Mesa Branch/Patches

Ext Vulkan Header Patch:
RADV Impl. Patch:

WineVulkan Branch/Patches

Pre-requisite Update Patch (1.1.113):
Add Extension Support Patch:

D9VK Branch


What it looks like

#define VK_JOSH_depth_bias_info 1

// -> The given depth bias value in VkPipelineRasterizationStateCreateInfo is
//    treat like a least representable value of the given depth format, r = format dependent
// -> The given depth bias value in VkPipelineRasterizationStateCreateInfo is
//    treat like a floating point number. r = 1
typedef enum VkDepthBiasModeJOSH {
} VkDepthBiasModeJOSH;

// depthBiasScale allows complete control of the vendor's scale for the depth bias
// only enabled if the useDepthBiasScale is VK_TRUE

// pNext of VkPipelineRasterizationStateCreateInfo
typedef struct VkPipelineRasterizationDepthBiasCreateInfoJOSH {
    VkStructureType                                        sType;
    const void*                                            pNext;
    VkBool32                                               useDepthBiasScale;
    float                                                  depthBiasScale;
    VkDepthBiasModeJOSH                                    depthBiasMode;
} VkPipelineRasterizationDepthBiasCreateInfoJOSH;

typedef struct VkPhysicalDeviceDepthBiasFeaturesJOSH {
    VkStructureType    sType;
    void*              pNext;
    VkBool32           modeFloat;
    VkBool32           userScale;
} VkPhysicalDeviceDepthBiasFeaturesJOSH;