Merge pull request #941 from ThisIsAkill/fix/agc-sampler-unused-border-table

fix(agc): accept a table border colour when no axis uses a border mode
This commit is contained in:
Dean
2026-10-07 15:20:24 +13:00
committed by GitHub
2 changed files with 30 additions and 4 deletions
@@ -34,6 +34,10 @@ VkSamplerAddressMode toVkAddressMode(std::uint32_t raw) {
}
}
bool readsBorderColor(std::uint32_t raw) {
return raw >= 4u && raw <= 7u;
}
float toSignedLodBias(std::uint32_t raw) {
const auto extended = static_cast<std::int32_t>((raw ^ 0x2000u) - 0x2000u);
return static_cast<float>(extended) / 256.0f;
@@ -113,7 +117,10 @@ GuestSamplerResource DecodeSamplerResource(std::span<const std::uint32_t> words)
case 0: border = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK; break;
case 1: border = VK_BORDER_COLOR_INT_OPAQUE_BLACK; break;
case 2: border = VK_BORDER_COLOR_INT_OPAQUE_WHITE; break;
default: throw std::runtime_error("AGC graphics: guest sampler descriptor uses a border color table which is not implemented");
default:
if (readsBorderColor(clampX) || readsBorderColor(clampY) || readsBorderColor(clampZ)) throw std::runtime_error("AGC graphics: guest sampler descriptor uses a border color table which is not implemented");
border = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
break;
}
GuestSamplerResource result{};
@@ -189,9 +189,28 @@ void RunGuestSamplerResourceTests() {
badBlendZero.blendZeroPrt = true;
rejectFields(badBlendZero, "PRT blend-zero");
Fields badBorder = base;
badBorder.borderColorType = 3;
rejectFields(badBorder, "border color table");
Fields unusedTable = base;
unusedTable.borderColorType = 3;
const auto unread = DecodeSamplerResource(pack(unusedTable));
Require(unread.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && unread.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && unread.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
"a table border colour with clamp-to-edge addressing must decode");
for (std::uint32_t mode : {0u, 1u, 2u, 3u}) {
Fields unreadMode = base;
unreadMode.borderColorType = 3;
unreadMode.clampX = mode;
DecodeSamplerResource(pack(unreadMode));
}
for (std::uint32_t mode : {4u, 5u, 6u, 7u}) {
for (int axis = 0; axis < 3; ++axis) {
Fields readTable = base;
readTable.borderColorType = 3;
(axis == 0 ? readTable.clampX : axis == 1 ? readTable.clampY : readTable.clampZ) = mode;
rejectFields(readTable, "border color table");
}
}
const std::array<std::uint32_t, 4> capturedTable{0x00007092u, 0x00fff000u, 0x05000000u, 0xc0000000u};
const auto capturedUnread = DecodeSamplerResource(capturedTable);
Require(capturedUnread.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && capturedUnread.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, "captured table-border sampler decoded incorrectly");
Fields opaqueBlack = base;
opaqueBlack.borderColorType = 1;