Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ enum class ColorTileMode : std::uint32_t {
GcnDisplay1D = 0x101,
GcnDisplay2D = 0x102,
GcnThin2D = 0x103,
GcnLinear = 0x104
GcnLinear = 0x104,
GcnLinearGeneral = 0x109
};

constexpr bool ColorTileModeIsGcn(ColorTileMode mode) {
return mode == ColorTileMode::GcnThin1D || mode == ColorTileMode::GcnDisplay1D || mode == ColorTileMode::GcnDisplay2D || mode == ColorTileMode::GcnThin2D || mode == ColorTileMode::GcnLinear;
return mode == ColorTileMode::GcnThin1D || mode == ColorTileMode::GcnDisplay1D || mode == ColorTileMode::GcnDisplay2D || mode == ColorTileMode::GcnThin2D || mode == ColorTileMode::GcnLinear || mode == ColorTileMode::GcnLinearGeneral;
}

constexpr bool ColorTileModeIsLinear(ColorTileMode mode) {
return mode == ColorTileMode::Linear || mode == ColorTileMode::GcnLinear;
return mode == ColorTileMode::Linear || mode == ColorTileMode::GcnLinear || mode == ColorTileMode::GcnLinearGeneral;
}

constexpr bool ColorTileModeIsXor(ColorTileMode mode) {
return mode == ColorTileMode::S4KBX || mode == ColorTileMode::D4KBX || mode == ColorTileMode::Z64KBX || mode == ColorTileMode::D64KBX || mode == ColorTileMode::RenderTarget;
}

constexpr std::uint32_t ColorTileModeBlockBytes(ColorTileMode mode) {
if (mode == ColorTileMode::GcnLinearGeneral) return 1u;
return ColorTileModeIsLinear(mode) ? 256u : mode == ColorTileMode::Standard4KB || mode == ColorTileMode::S4KBX || mode == ColorTileMode::D4KBX ? 4096u : 65536u;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ ColorTargetLayout::ColorTargetLayout(std::uint32_t width, std::uint32_t height,
pitch = (width + pitchAlignment - 1u) / pitchAlignment * pitchAlignment;
break;
}
case ColorTileMode::GcnLinearGeneral:
pitch = width;
break;
case ColorTileMode::S4KBX:
case ColorTileMode::D4KBX:
case ColorTileMode::Z64KBX:
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4840,7 +4840,7 @@ void recordPreparedDraw(const Context& context, const State& state, const Pm4::D
if (checkRecords) checkRecords();
timer.phase(PhaseSync);
APS5_LOG_CHARS_OUT_DEBUG("SubmitAndWait OK");
for (const auto& binding : targets) GuestMemory::CheckRange(reinterpret_cast<const void*>(binding.color.MemoryAddress()), binding.color.bytes, 256, true);
for (const auto& binding : targets) GuestMemory::CheckRange(reinterpret_cast<const void*>(binding.color.MemoryAddress()), binding.color.bytes, std::min<std::size_t>(256u, ColorTileModeBlockBytes(binding.color.tileMode)), true);
for (auto& binding : targets) {
if (!binding.dump) continue;
std::lock_guard lock(dumpMutex);
Expand Down
12 changes: 8 additions & 4 deletions core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,10 +2454,13 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
Require(fragments <= color.coverageSamples, "GCN color targets with more fragments than samples are not implemented");
color.samples = fragments == 1u ? 1u : color.coverageSamples;
if (fragments > 1u && fragments < color.coverageSamples) color.eqaaFragments = fragments;
Require((info & 0x3u) == 0 && (info & 0x80u) == 0, "endian-swapped or linear-general GCN color targets are not implemented");
Require((info & 0x3u) == 0, "endian-swapped GCN color targets are not implemented");
const bool linearGeneral = (info & 0x80u) != 0;
Require(!linearGeneral || color.coverageSamples == 1u, "multisampled linear-general GCN color targets are not implemented");
Require((info & 0x8000u) != 0 || number == 7 || number == 4 || number == 5, "unclamped normalized color is unsupported");
const auto view = read(cx, 0x31b + stride);
const auto slice = view & 0x7ffu;
Require(!linearGeneral || (view & 0x700u) == 0, "a linear-general GCN color view with SLICE_START bits above its low address byte is not implemented");
const auto slice = linearGeneral ? 0u : view & 0x7ffu;
const auto lastSlice = (view >> 13u) & 0x7ffu;
Require(lastSlice >= slice, "the color view ends before its first slice");
const auto exports = find(cx, 0x207);
Expand All @@ -2467,7 +2470,8 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
color.extent = {pitch, sliceElements / pitch};
color.surfaceExtent = color.extent;
color.elementBytes = decoded.elementBytes;
switch (attrib & 0x1fu) {
if (linearGeneral) color.tileMode = ColorTileMode::GcnLinearGeneral;
else switch (attrib & 0x1fu) {
case 8u: color.tileMode = ColorTileMode::GcnLinear; break;
case 5u: case 13u: color.tileMode = ColorTileMode::GcnThin1D; break;
case 9u: color.tileMode = ColorTileMode::GcnDisplay1D; break;
Expand All @@ -2481,7 +2485,7 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
color.mipCount = 1;
const ColorTargetLayout layout(color.extent.width, color.extent.height, color.tileMode, color.elementBytes, color.pipeBankXor);
Require(layout.Bytes() == static_cast<std::size_t>(pitch) * color.extent.height * color.elementBytes, "PS4 color target pitch or slice is not padded the way its tile mode pads them");
color.surfaceAddress = (static_cast<std::uint64_t>(read(cx, 0x318 + stride)) << 8u) + static_cast<std::uint64_t>(slice) * layout.Bytes() * fragments;
color.surfaceAddress = (static_cast<std::uint64_t>(read(cx, 0x318 + stride)) << 8u) + (linearGeneral ? view & 0xffu : static_cast<std::uint64_t>(slice) * layout.Bytes() * fragments);
color.address = color.surfaceAddress;
color.bytes = layout.Bytes();
color.format = decoded.format;
Expand Down
32 changes: 31 additions & 1 deletion core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ constexpr std::uint32_t Format8888 = 10u;
constexpr std::uint32_t BlendClamp = 1u << 15u;
constexpr std::uint32_t FastClear = 1u << 13u;
constexpr std::uint32_t Compression = 1u << 14u;
constexpr std::uint32_t LinearGeneral = 1u << 7u;
constexpr std::uint32_t Thin1D = 13u;
constexpr std::uint32_t Display2D = 10u;
constexpr std::uint32_t Thin2D = 14u;
Expand Down Expand Up @@ -229,6 +230,34 @@ void LaterSlicesDecode() {
Check(Failure([base] { DecodeSlice(base, Thin2D, 1u, 4u); }).find("multisampled color views of a later slice of a 2D-tiled array") != std::string::npos, "slice 1 of a 2D-tiled 4x GCN array was accepted");
}

AgcDriver::Graphics::ColorTarget DecodeLinearGeneral(std::uint32_t format, std::uint32_t pitch, std::uint32_t height, std::uint32_t view, std::uint32_t attrib, std::uint32_t flags) {
AgcDriver::Registers cx;
cx[0x318] = static_cast<std::uint32_t>(AddressOf(colorMemory) >> 8u);
cx[0x319] = pitch / 8u - 1u;
cx[0x31a] = pitch * height / 64u - 1u;
cx[0x31b] = view;
cx[0x31c] = (format << 2u) | BlendClamp | flags;
cx[0x31d] = attrib;
return AgcDriver::Graphics::DecodeColorBuffer(cx, 0);
}

void LinearGeneralTargetsDecode() {
using AgcDriver::Graphics::ColorTileMode;
constexpr std::uint32_t Format8 = 1u;
constexpr std::uint32_t Pitch = 24u;
constexpr std::uint32_t Rows = 8u;
const auto base = AddressOf(colorMemory);
const auto offset = DecodeLinearGeneral(Format8888, Width, Height, 0x40u | (3u << 13u), Thin2D, LinearGeneral);
Check(offset.tileMode == ColorTileMode::GcnLinearGeneral && offset.address == base + 0x40u && offset.surfaceAddress == offset.address && offset.bytes == ColorBytes && offset.pipeBankXor == 0u, "a linear-general GCN target did not decode as a linear surface at CB_COLOR_BASE plus SLICE_START's low byte, whatever its tile mode index");
const auto narrow = DecodeLinearGeneral(Format8, Pitch, Rows, 0x07u, Thin1D, LinearGeneral);
Check(narrow.tileMode == ColorTileMode::GcnLinearGeneral && narrow.extent.width == Pitch && narrow.extent.height == Rows && narrow.elementBytes == 1u && narrow.bytes == std::size_t{Pitch} * Rows && narrow.address == base + 7u, "an 8-bit linear-general GCN target with a 24-texel pitch did not decode unpadded at a byte offset");
Check(Failure([] { DecodeLinearGeneral(Format8, Pitch, Rows, 0u, 8u, 0u); }).find("not padded the way its tile mode pads them") != std::string::npos, "an 8-bit linear-aligned GCN target with a 24-texel pitch was accepted");
Check(Failure([] { DecodeLinearGeneral(Format8888, Width, Height, 0x100u, Thin1D, LinearGeneral); }).find("SLICE_START bits above its low address byte") != std::string::npos, "a linear-general GCN view with SLICE_START above 0xff was accepted");
Check(Failure([] { DecodeLinearGeneral(Format8888, Width, Height, 0u, Thin1D | (2u << 12u) | (2u << 15u), LinearGeneral); }).find("multisampled linear-general") != std::string::npos, "a 4x linear-general GCN target was accepted");
Check(Failure([] { DecodeLinearGeneral(Format8888, Width, Height, 0u, 31u, 0u); }).find("tile mode index 31") != std::string::npos, "GCN tile mode index 31 without CB_COLOR_INFO LINEAR_GENERAL was accepted");
Check(Failure([] { DecodeLinearGeneral(Format8888, Width, Height, 0u, Thin1D, 1u); }).find("endian-swapped") != std::string::npos, "an endian-swapped GCN target was accepted");
}

void PaddedTargetsAreCovered() {
Check(FmaskDecompress(Height).empty(), "an FMASK decompress over a whole 4x GCN target was refused");
const auto padded = FmaskDecompress(Height - 4u);
Expand All @@ -253,11 +282,12 @@ int main() {
MultisampledSlicesDecode();
PaddedTargetsAreCovered();
LaterSlicesDecode();
LinearGeneralTargetsDecode();
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
if (failures != 0) return 1;
std::puts("GCN multisampled color targets decode with their CMASK, EQAA and one-fragment targets with their FMASK base and size, and a metadata pass over the visible rows of a padded target is covered");
std::puts("GCN multisampled color targets decode with their CMASK, EQAA and one-fragment targets with their FMASK base and size, a metadata pass over the visible rows of a padded target is covered, and linear-general targets decode unpadded at CB_COLOR_BASE plus SLICE_START's low byte");
return 0;
}
Loading
Loading