vk_rasterizer: Use xor as heuristic for HTILE clear

This commit is contained in:
IndecisiveTurtle 2025-07-15 22:07:12 +03:00
parent dec6968f5a
commit 7ae49cd06a
5 changed files with 22 additions and 7 deletions

View File

@ -3,8 +3,6 @@
#pragma once #pragma once
#include <limits>
#include "common/bit_field.h"
#include "shader_recompiler/frontend/opcodes.h" #include "shader_recompiler/frontend/opcodes.h"
namespace Shader::Gcn { namespace Shader::Gcn {

View File

@ -222,6 +222,7 @@ struct Info {
VAddr pgm_base; VAddr pgm_base;
bool has_storage_images{}; bool has_storage_images{};
bool has_discard{}; bool has_discard{};
bool has_bitwise_xor{};
bool has_image_gather{}; bool has_image_gather{};
bool has_image_query{}; bool has_image_query{};
bool uses_buffer_atomic_float_min_max{}; bool uses_buffer_atomic_float_min_max{};

View File

@ -95,6 +95,9 @@ void Visit(Info& info, const IR::Inst& inst) {
case IR::Opcode::DiscardCond: case IR::Opcode::DiscardCond:
info.has_discard = true; info.has_discard = true;
break; break;
case IR::Opcode::BitwiseXor32:
info.has_bitwise_xor = true;
break;
case IR::Opcode::ImageGather: case IR::Opcode::ImageGather:
case IR::Opcode::ImageGatherDref: case IR::Opcode::ImageGatherDref:
info.has_image_gather = true; info.has_image_gather = true;

View File

@ -503,9 +503,13 @@ bool Rasterizer::IsComputeMetaClear(const Pipeline* pipeline) {
return false; return false;
} }
// Most of the time when a metadata is updated with a shader it gets cleared. It means
// we can skip the whole dispatch and update the tracked state instead. Also, it is not
// intended to be consumed and in such rare cases (e.g. HTile introspection, CRAA) we
// will need its full emulation anyways.
const auto& info = pipeline->GetStage(Shader::LogicalStage::Compute); const auto& info = pipeline->GetStage(Shader::LogicalStage::Compute);
// Assume if a shader reads and writes metas at the same time, it is a copy shader. // Assume if a shader reads metadata, it is a copy shader.
for (const auto& desc : info.buffers) { for (const auto& desc : info.buffers) {
const VAddr address = desc.GetSharp(info).base_address; const VAddr address = desc.GetSharp(info).base_address;
if (!desc.IsSpecial() && !desc.is_written && texture_cache.IsMeta(address)) { if (!desc.IsSpecial() && !desc.is_written && texture_cache.IsMeta(address)) {
@ -513,10 +517,15 @@ bool Rasterizer::IsComputeMetaClear(const Pipeline* pipeline) {
} }
} }
// Most of the time when a metadata is updated with a shader it gets cleared. It means // Metadata surfaces are tiled and thus need address calculation to be written properly.
// we can skip the whole dispatch and update the tracked state instead. Also, it is not // If a shader wants to encode HTILE, for example, from a depth image it will have to compute
// intended to be consumed and in such rare cases (e.g. HTile introspection, CRAA) we // proper tile address from dispatch invocation id. This address calculation contains an xor
// will need its full emulation anyways. // operation so use it as a heuristic for metadata writes that are probably not clears.
if (info.has_bitwise_xor) {
return false;
}
// Assume if a shader writes metadata without address calculation, it is a clear shader.
for (const auto& desc : info.buffers) { for (const auto& desc : info.buffers) {
const VAddr address = desc.GetSharp(info).base_address; const VAddr address = desc.GetSharp(info).base_address;
if (!desc.IsSpecial() && desc.is_written && texture_cache.ClearMeta(address)) { if (!desc.IsSpecial() && desc.is_written && texture_cache.ClearMeta(address)) {

View File

@ -161,10 +161,12 @@ public:
/// Registers an image view for provided image /// Registers an image view for provided image
ImageView& RegisterImageView(ImageId image_id, const ImageViewInfo& view_info); ImageView& RegisterImageView(ImageId image_id, const ImageViewInfo& view_info);
/// Returns true if the specified address is a metadata surface.
bool IsMeta(VAddr address) const { bool IsMeta(VAddr address) const {
return surface_metas.contains(address); return surface_metas.contains(address);
} }
/// Returns true if a slice of the specified metadata surface has been cleared.
bool IsMetaCleared(VAddr address, u32 slice) const { bool IsMetaCleared(VAddr address, u32 slice) const {
const auto& it = surface_metas.find(address); const auto& it = surface_metas.find(address);
if (it != surface_metas.end()) { if (it != surface_metas.end()) {
@ -173,6 +175,7 @@ public:
return false; return false;
} }
/// Clears all slices of the specified metadata surface.
bool ClearMeta(VAddr address) { bool ClearMeta(VAddr address) {
auto it = surface_metas.find(address); auto it = surface_metas.find(address);
if (it != surface_metas.end()) { if (it != surface_metas.end()) {
@ -182,6 +185,7 @@ public:
return false; return false;
} }
/// Updates the state of a slice of the specified metadata surface.
bool TouchMeta(VAddr address, u32 slice, bool is_clear) { bool TouchMeta(VAddr address, u32 slice, bool is_clear) {
auto it = surface_metas.find(address); auto it = surface_metas.find(address);
if (it != surface_metas.end()) { if (it != surface_metas.end()) {