mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #1177 from MichonGoddijn231849/feat/standard-64k-color-targets
feat(agc): 64 KiB standard color targets
This commit is contained in:
@@ -12,11 +12,12 @@ namespace AgcDriver::Graphics {
|
||||
enum class ColorTileMode : std::uint32_t {
|
||||
Linear = 0,
|
||||
Standard4KB = 5,
|
||||
Standard64KB = 9,
|
||||
RenderTarget = 0x1b
|
||||
};
|
||||
|
||||
constexpr TextureTileMode ColorTextureTileMode(ColorTileMode mode) {
|
||||
return mode == ColorTileMode::Linear ? TextureTileMode::kLinear : mode == ColorTileMode::Standard4KB ? TextureTileMode::kStandard4KB : TextureTileMode::kR64KBX;
|
||||
return mode == ColorTileMode::Linear ? TextureTileMode::kLinear : mode == ColorTileMode::Standard4KB ? TextureTileMode::kStandard4KB : mode == ColorTileMode::Standard64KB ? TextureTileMode::kStandard64KB : TextureTileMode::kR64KBX;
|
||||
}
|
||||
|
||||
ColorTileMode DecodeColorTileMode(std::uint32_t attrib3);
|
||||
|
||||
@@ -27,6 +27,16 @@ std::uint32_t standardOffset(std::uint32_t x, std::uint32_t y, std::uint32_t ele
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t standard64Extra(std::uint32_t x, std::uint32_t y, std::uint32_t elementBytes) {
|
||||
switch (elementBytes) {
|
||||
case 1u: return ((x << 7) & 0x2000u) ^ ((x << 8) & 0x8000u) ^ ((y << 6) & 0x1000u) ^ ((y << 7) & 0x4000u);
|
||||
case 2u: return ((x << 7) & 0x2000u) ^ ((x << 8) & 0x8000u) ^ ((y << 7) & 0x1000u) ^ ((y << 8) & 0x4000u);
|
||||
case 4u: return ((x << 8) & 0x2000u) ^ ((x << 9) & 0x8000u) ^ ((y << 7) & 0x1000u) ^ ((y << 8) & 0x4000u);
|
||||
case 8u: return ((x << 8) & 0x2000u) ^ ((x << 9) & 0x8000u) ^ ((y << 8) & 0x1000u) ^ ((y << 9) & 0x4000u);
|
||||
default: return ((x << 9) & 0x2000u) ^ ((x << 10) & 0x8000u) ^ ((y << 8) & 0x1000u) ^ ((y << 9) & 0x4000u);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ColorTileMode DecodeColorTileMode(std::uint32_t attrib3) {
|
||||
@@ -35,7 +45,7 @@ ColorTileMode DecodeColorTileMode(std::uint32_t attrib3) {
|
||||
const auto mode = (attrib3 >> 14u) & 0x1fu;
|
||||
const auto fmaskMode = (attrib3 >> 19u) & 0x1fu;
|
||||
require(fmaskMode == 0 || fmaskMode == 0x18, "AGC graphics: unsupported color FMASK swizzle mode");
|
||||
require(mode == 0 || mode == 5 || mode == 0x1b, "AGC graphics: unsupported color tile mode");
|
||||
require(mode == 0 || mode == 5 || mode == 9 || mode == 0x1b, "AGC graphics: unsupported color tile mode");
|
||||
return static_cast<ColorTileMode>(mode);
|
||||
}
|
||||
|
||||
@@ -70,18 +80,18 @@ const SwizzleTables& renderTargetTables(std::uint32_t bytesPerElement, std::uint
|
||||
return tables[index];
|
||||
}
|
||||
|
||||
const SwizzleTables& standardTables(std::uint32_t bytesPerElement, std::uint32_t blockWidth, std::uint32_t blockHeight) {
|
||||
static std::once_flag once[5];
|
||||
static SwizzleTables tables[5];
|
||||
const SwizzleTables& standardTables(std::uint32_t bytesPerElement, std::uint32_t blockWidth, std::uint32_t blockHeight, bool block64KB) {
|
||||
static std::once_flag once[2][5];
|
||||
static SwizzleTables tables[2][5];
|
||||
const auto index = static_cast<std::size_t>(std::countr_zero(bytesPerElement));
|
||||
std::call_once(once[index], [&] {
|
||||
auto& table = tables[index];
|
||||
std::call_once(once[block64KB][index], [&] {
|
||||
auto& table = tables[block64KB][index];
|
||||
table.x.resize(blockWidth);
|
||||
table.y.resize(blockHeight);
|
||||
for (std::uint32_t x = 0; x < blockWidth; ++x) table.x[x] = standardOffset(x, 0, bytesPerElement);
|
||||
for (std::uint32_t y = 0; y < blockHeight; ++y) table.y[y] = standardOffset(0, y, bytesPerElement);
|
||||
for (std::uint32_t x = 0; x < blockWidth; ++x) table.x[x] = standardOffset(x, 0, bytesPerElement) ^ (block64KB ? standard64Extra(x, 0, bytesPerElement) : 0u);
|
||||
for (std::uint32_t y = 0; y < blockHeight; ++y) table.y[y] = standardOffset(0, y, bytesPerElement) ^ (block64KB ? standard64Extra(0, y, bytesPerElement) : 0u);
|
||||
});
|
||||
return tables[index];
|
||||
return tables[block64KB][index];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -108,13 +118,16 @@ ColorTargetLayout::ColorTargetLayout(std::uint32_t width, std::uint32_t height,
|
||||
yOffsets = tables.y.data();
|
||||
break;
|
||||
}
|
||||
case ColorTileMode::Standard4KB: {
|
||||
case ColorTileMode::Standard4KB:
|
||||
case ColorTileMode::Standard64KB: {
|
||||
const auto log2Bytes = static_cast<std::uint32_t>(std::countr_zero(bytesPerElement));
|
||||
blockWidth = 1u << (6u - (log2Bytes + 1u) / 2u);
|
||||
blockHeight = 1u << (6u - log2Bytes / 2u);
|
||||
const bool block64KB = mode == ColorTileMode::Standard64KB;
|
||||
const auto log2Side = block64KB ? 8u : 6u;
|
||||
blockWidth = 1u << (log2Side - log2Bytes / 2u);
|
||||
blockHeight = 1u << (log2Side - (log2Bytes + 1u) / 2u);
|
||||
pitch = (width + blockWidth - 1u) / blockWidth * blockWidth;
|
||||
paddedHeight = (height + blockHeight - 1u) / blockHeight * blockHeight;
|
||||
const auto& tables = standardTables(bytesPerElement, blockWidth, blockHeight);
|
||||
const auto& tables = standardTables(bytesPerElement, blockWidth, blockHeight, block64KB);
|
||||
xOffsets = tables.x.data();
|
||||
yOffsets = tables.y.data();
|
||||
break;
|
||||
|
||||
@@ -42,7 +42,7 @@ std::uint32_t GuestFormatFor(VkFormat format, std::uint32_t elementBytes) {
|
||||
|
||||
// The color buffer as a single-mip 2D surface descriptor (tile mode SW_64KB_R_X).
|
||||
GuestTextureResource SurfaceForTarget(const ColorTarget& color) {
|
||||
Require(color.tileMode == ColorTileMode::RenderTarget || color.tileMode == ColorTileMode::Standard4KB, "only 4 KiB standard and 64 KiB tiled color targets are resident");
|
||||
Require(color.tileMode != ColorTileMode::Linear, "linear color targets are not resident");
|
||||
const bool chain = color.mipCount > 1;
|
||||
GuestTextureResource surface{};
|
||||
surface.baseAddress = chain ? color.surfaceAddress : color.address;
|
||||
@@ -1546,7 +1546,7 @@ void Draw(const Context& context, const State& state, const Pm4::DrawParameters&
|
||||
timer.phase(PhaseSetup);
|
||||
// Debug aid: APS5_NO_RESIDENT_TARGETS=1 copies every target in and out again.
|
||||
static const bool residentTargets = std::getenv("APS5_NO_RESIDENT_TARGETS") == nullptr;
|
||||
if ((binding.gpuTiling || (color.tileMode == ColorTileMode::Standard4KB && context.detiler != nullptr)) && residentTargets) {
|
||||
if ((binding.gpuTiling || (color.tileMode != ColorTileMode::Linear && context.detiler != nullptr)) && residentTargets) {
|
||||
// The lookup refreshes the image on every draw (StorageTexture::Refresh: FlushPending,
|
||||
// CollectWrites over the target's pages, the DCC key scan of TextureClearKeys, then
|
||||
// UnchangedSince). The page walk is skipped while the worker's collect epoch lasts
|
||||
@@ -2130,7 +2130,7 @@ DrawRecipeOutcome DrawWithRecipe(const Context& context, const State& state, con
|
||||
namespace {
|
||||
|
||||
std::shared_ptr<StorageTexture> metadataPassResident(const Context& context, const ColorTarget& color) {
|
||||
if ((color.tileMode != ColorTileMode::RenderTarget && color.tileMode != ColorTileMode::Standard4KB) || context.detiler == nullptr) return nullptr;
|
||||
if (color.tileMode == ColorTileMode::Linear || context.detiler == nullptr) return nullptr;
|
||||
std::shared_ptr<StorageTexture> resident;
|
||||
try {
|
||||
resident = CachedStorageSurface(context, SurfaceForTarget(color));
|
||||
|
||||
@@ -50,6 +50,26 @@ void RunColorTargetLayoutTests() {
|
||||
standardSeen[address / 4] = true;
|
||||
}
|
||||
}
|
||||
for (const auto mode : {ColorTileMode::Standard4KB, ColorTileMode::Standard64KB}) {
|
||||
for (const std::uint32_t bpe : {1u, 2u, 4u, 8u, 16u}) {
|
||||
const auto block = mode == ColorTileMode::Standard64KB ? 65536u : 4096u;
|
||||
const ColorTargetLayout sized(512, 512, mode, bpe);
|
||||
Require(sized.Alignment() == block && sized.Bytes() == ComputeSurfaceSize(ComputeElementMipLayout(ColorTextureTileMode(mode), bpe, 512, 512, 1), 1), "standard color layout differs from the texture layout");
|
||||
std::vector<bool> seen(block / bpe);
|
||||
std::uint32_t count = 0;
|
||||
for (std::uint32_t y = 0; y < 512 && count < seen.size(); ++y) {
|
||||
for (std::uint32_t x = 0; x < 512; ++x) {
|
||||
const auto address = sized.Offset(x, y);
|
||||
if (address >= block) continue;
|
||||
Require(address % bpe == 0 && !seen[address / bpe], "standard block aliases its texels");
|
||||
seen[address / bpe] = true;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
Require(count == seen.size(), "standard block leaves texels unaddressed");
|
||||
}
|
||||
}
|
||||
Require(DecodeColorTileMode(0x4dc24000) == ColorTileMode::Standard64KB, "64 KiB standard color descriptor was rejected");
|
||||
reject([&] { layout.Offset(257, 0); });
|
||||
std::vector<std::byte> tiled(layout.Bytes(), std::byte{0x5a});
|
||||
std::vector<std::byte> linear(layout.LinearBytes());
|
||||
|
||||
Reference in New Issue
Block a user