Merge pull request #1371 from TibixDev/pr/depth-maintenance-precheck

fix(agc): reject depth maintenance before shader compilation
This commit is contained in:
Adrià
2026-10-08 14:37:01 +02:00
committed by GitHub
4 changed files with 37 additions and 0 deletions
@@ -23,6 +23,8 @@ std::optional<DrawVerdict> Driver::precheckDraw(const QueueState& queue, const S
localDevice->ColorMetadataPass(*pass);
return DrawVerdict::Drawn;
}
rejected = Graphics::DepthMaintenanceRejection(queue);
if (!rejected.empty()) return DrawVerdict::Rejected;
static const bool traceIndirectEnabled = std::getenv("APS5_TRACE_INDIRECT_DRAWS") != nullptr;
traceIndirect = traceIndirectEnabled;
if (traceIndirect && drawParameters.indirect) std::fprintf(stderr, "[draw] indirect packet %s args 0x%llx count %u reached\n", Pm4::Name(packet[0]).c_str(), static_cast<unsigned long long>(drawParameters.indirect->arguments), drawParameters.indirect->count);
@@ -112,6 +112,7 @@ struct ColorMetadataPass {
std::vector<ColorTarget> targets;
};
std::optional<ColorMetadataPass> DecodeColorMetadataPass(const QueueState& queue);
std::string DepthMaintenanceRejection(const QueueState& queue);
// The message DecodeState (or the pixel stage decode after it) would throw for the register rules
// this precheck covers, evaluated without exceptions before the draw is decoded; empty when they
// pass (DecodeState still checks everything). A register a rule needs that is absent is no verdict.
@@ -468,7 +468,14 @@ ShaderStages DecodeShaderStages(const QueueState& queue) {
return result;
}
std::string DepthMaintenanceRejection(const QueueState& queue) {
const auto control = find(queue.context, 0x000);
if (control == queue.context.end() || (control->second & ~0x2063u) == 0) return {};
return zeroMessage(0x000, control->second, "DB_RENDER_CONTROL depth copy, resummarize or decompress");
}
State DecodeState(const QueueState& queue) {
if (auto reason = DepthMaintenanceRejection(queue); !reason.empty()) throw std::runtime_error(reason);
const auto& cx = queue.context;
State result{};
result.conservativeRasterization = decodeConservativeRasterization(queue);
@@ -807,6 +814,7 @@ std::optional<ColorMetadataPass> DecodeColorMetadataPass(const QueueState& queue
}
std::string DrawRejection(const QueueState& queue, bool indexed) {
if (auto reason = DepthMaintenanceRejection(queue); !reason.empty()) return reason;
const auto& cx = queue.context;
// A register a rule needs that is absent gives no verdict here: DecodeState reports it.
const auto value = [&](const Registers& registers, std::uint32_t offset, std::uint32_t& out) {
@@ -718,6 +718,31 @@ void DepthStencilTests() {
expectFailure([&] { AgcDriver::Graphics::DecodeState(queue); }, "DCC 3D color targets");
}
void depthMaintenanceTests() {
for (const auto mode : {0x4u, 0x8u, 0x10u, 0x80u, 0x100u, 0x1000u, 0x4000u}) {
for (const auto clear : {0u, 1u, 2u, 3u}) {
auto queue = makeState();
queue.context[0x000] = mode | clear;
queue.context[0x200] = 0;
queue.context[0x8e] = 0;
queue.context[0x8f] = 0;
queue.shader.erase(0x8);
const auto reason = AgcDriver::Graphics::DepthMaintenanceRejection(queue);
Require(reason.find("DB_RENDER_CONTROL") != std::string::npos, "depth maintenance passed without depth tests or color writes");
Require(AgcDriver::Graphics::DrawRejection(queue, false) == reason, "draw precheck did not reject depth maintenance first");
expectFailure([&] { AgcDriver::Graphics::DecodeState(queue); }, reason);
}
}
for (const auto control : {0u, 1u, 2u, 3u, 0x20u, 0x40u, 0x2000u, 0x2063u}) {
auto queue = makeState();
queue.context[0x000] = control;
Require(AgcDriver::Graphics::DepthMaintenanceRejection(queue).empty(), "ordinary depth controls were mistaken for maintenance");
}
auto absent = makeState();
absent.context.erase(0x000);
Require(AgcDriver::Graphics::DepthMaintenanceRejection(absent).empty(), "an absent depth control produced a maintenance verdict");
}
// SPI_SHADER_Z_FORMAT (0x1c4) and the export enables of DB_SHADER_CONTROL (0x203): Z export needs a
// format with a depth channel (1, 2, 3 or 32_ABGR 9), the sample mask needs 32_ABGR, and the
// formats the export path does not lay out are refused. A missing 0x1c4 gives no verdict here.
@@ -2617,6 +2642,7 @@ int main() {
}
RunGuestLeaseWaitTests();
stateTests();
depthMaintenanceTests();
hardwareScreenOffsetTests();
srgb8TargetTests();
DepthClipTests();