forked from ShuriZma/suyu
1
0
Fork 0

Merge pull request #7070 from FernandoS27/want-you-bad

Vulkan Rasterizer: Correct DepthBias/PolygonOffset on Vulkan.
This commit is contained in:
Ameer J 2021-10-23 18:02:23 -04:00 committed by GitHub
commit 494e34af6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 3 deletions

View File

@ -38,6 +38,9 @@ enum : u8 {
Shaders, Shaders,
// Special entries
DepthBiasGlobal,
LastCommonEntry, LastCommonEntry,
}; };

View File

@ -627,9 +627,21 @@ void RasterizerVulkan::UpdateDepthBias(Tegra::Engines::Maxwell3D::Regs& regs) {
if (!state_tracker.TouchDepthBias()) { if (!state_tracker.TouchDepthBias()) {
return; return;
} }
scheduler.Record([constant = regs.polygon_offset_units, clamp = regs.polygon_offset_clamp, float units = regs.polygon_offset_units / 2.0f;
const bool is_d24 = regs.zeta.format == Tegra::DepthFormat::S8_UINT_Z24_UNORM ||
regs.zeta.format == Tegra::DepthFormat::D24X8_UNORM ||
regs.zeta.format == Tegra::DepthFormat::D24S8_UNORM ||
regs.zeta.format == Tegra::DepthFormat::D24C8_UNORM;
if (is_d24 && !device.SupportsD24DepthBuffer()) {
// the base formulas can be obtained from here:
// https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage-depth-bias
const double rescale_factor =
static_cast<double>(1ULL << (32 - 24)) / (static_cast<double>(0x1.ep+127));
units = static_cast<float>(static_cast<double>(units) * rescale_factor);
}
scheduler.Record([constant = units, clamp = regs.polygon_offset_clamp,
factor = regs.polygon_offset_factor](vk::CommandBuffer cmdbuf) { factor = regs.polygon_offset_factor](vk::CommandBuffer cmdbuf) {
cmdbuf.SetDepthBias(constant, clamp, factor / 2.0f); cmdbuf.SetDepthBias(constant, clamp, factor);
}); });
} }

View File

@ -79,7 +79,8 @@ public:
} }
bool TouchDepthBias() { bool TouchDepthBias() {
return Exchange(Dirty::DepthBias, false); return Exchange(Dirty::DepthBias, false) ||
Exchange(VideoCommon::Dirty::DepthBiasGlobal, false);
} }
bool TouchBlendConstants() { bool TouchBlendConstants() {

View File

@ -221,6 +221,7 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) {
BindRenderTarget(&render_targets.depth_buffer_id, FindDepthBuffer(is_clear)); BindRenderTarget(&render_targets.depth_buffer_id, FindDepthBuffer(is_clear));
} }
const ImageViewId depth_buffer_id = render_targets.depth_buffer_id; const ImageViewId depth_buffer_id = render_targets.depth_buffer_id;
PrepareImageView(depth_buffer_id, true, is_clear && IsFullClear(depth_buffer_id)); PrepareImageView(depth_buffer_id, true, is_clear && IsFullClear(depth_buffer_id));
for (size_t index = 0; index < NUM_RT; ++index) { for (size_t index = 0; index < NUM_RT; ++index) {
@ -230,6 +231,8 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) {
maxwell3d.regs.render_area.width, maxwell3d.regs.render_area.width,
maxwell3d.regs.render_area.height, maxwell3d.regs.render_area.height,
}; };
flags[Dirty::DepthBiasGlobal] = true;
} }
template <class P> template <class P>

View File

@ -623,6 +623,10 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
is_float16_supported = false; is_float16_supported = false;
} }
supports_d24_depth =
IsFormatSupported(VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, FormatType::Optimal);
graphics_queue = logical.GetQueue(graphics_family); graphics_queue = logical.GetQueue(graphics_family);
present_queue = logical.GetQueue(present_family); present_queue = logical.GetQueue(present_family);
} }

View File

@ -332,6 +332,10 @@ public:
return sets_per_pool; return sets_per_pool;
} }
bool SupportsD24DepthBuffer() const {
return supports_d24_depth;
}
private: private:
/// Checks if the physical device is suitable. /// Checks if the physical device is suitable.
void CheckSuitability(bool requires_swapchain) const; void CheckSuitability(bool requires_swapchain) const;
@ -425,6 +429,7 @@ private:
bool has_broken_cube_compatibility{}; ///< Has broken cube compatiblity bit bool has_broken_cube_compatibility{}; ///< Has broken cube compatiblity bit
bool has_renderdoc{}; ///< Has RenderDoc attached bool has_renderdoc{}; ///< Has RenderDoc attached
bool has_nsight_graphics{}; ///< Has Nsight Graphics attached bool has_nsight_graphics{}; ///< Has Nsight Graphics attached
bool supports_d24_depth{}; ///< Supports D24 depth buffers.
// Telemetry parameters // Telemetry parameters
std::string vendor_name; ///< Device's driver name. std::string vendor_name; ///< Device's driver name.