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,11 +26,12 @@ enum class ColorTileMode : std::uint32_t {
GcnDisplay1D = 0x101,
GcnDisplay2D = 0x102,
GcnThin2D = 0x103,
GcnLinear = 0x104
GcnLinear = 0x104,
GcnThick1D = 0x10a
};

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::GcnThick1D;
}

constexpr bool ColorTileModeIsLinear(ColorTileMode mode) {
Expand All @@ -50,6 +51,7 @@ constexpr TextureTileMode ColorTextureTileMode(ColorTileMode mode) {
if (mode == ColorTileMode::GcnDisplay1D) return TextureTileMode::kGcnDisplay1D;
if (mode == ColorTileMode::GcnDisplay2D) return TextureTileMode::kGcnDisplay2D;
if (mode == ColorTileMode::GcnThin2D) return TextureTileMode::kGcnThin2D;
if (mode == ColorTileMode::GcnThick1D) return TextureTileMode::kGcnThick1D;
return ColorTileModeIsLinear(mode) ? TextureTileMode::kLinear : mode == ColorTileMode::Standard4KB ? TextureTileMode::kStandard4KB : mode == ColorTileMode::Standard64KB ? TextureTileMode::kStandard64KB : mode == ColorTileMode::S4KBX ? TextureTileMode::kS4KBX : mode == ColorTileMode::D4KBX ? TextureTileMode::kD4KBX : mode == ColorTileMode::D64KBX ? TextureTileMode::kD64KBX : mode == ColorTileMode::Z64KBX ? TextureTileMode::kZ64KBX : TextureTileMode::kR64KBX;
}

Expand Down Expand Up @@ -80,6 +82,7 @@ class ColorTargetLayout {
std::size_t blockBytes = 0;
std::uint32_t pipeBankXor = 0;
bool gcn = false;
bool thick = false;
std::array<std::uint32_t, 16> gcnEquation{};
// The XOR swizzle is linear over GF(2), so a block offset is xOffsets[x] ^ yOffsets[y].
const std::uint32_t* xOffsets = nullptr;
Expand Down
11 changes: 11 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ ColorTargetLayout::ColorTargetLayout(std::uint32_t width, std::uint32_t height,
gcnEquation = geometry.equation;
break;
}
case ColorTileMode::GcnThick1D: {
require(pipeBankXor == 0, "AGC graphics: a PS4 thick color target has no bank XOR");
blockWidth = 8u;
blockHeight = 8u;
pitch = (width + blockWidth - 1u) / blockWidth * blockWidth;
paddedHeight = (height + blockHeight - 1u) / blockHeight * blockHeight;
gcn = true;
thick = true;
break;
}
default: throw std::runtime_error("AGC graphics: unsupported color tile mode");
}
blockBytes = gcn ? static_cast<std::size_t>(blockWidth) * blockHeight * bytesPerElement : ColorTileModeBlockBytes(mode);
Expand All @@ -185,6 +195,7 @@ ColorTargetLayout::ColorTargetLayout(std::uint32_t width, std::uint32_t height,
}

std::size_t ColorTargetLayout::offset(std::uint32_t x, std::uint32_t y) const {
require(!thick, "AGC graphics: a PS4 thick color target interleaves four slices per micro tile and is addressed through its 3D surface, not a 2D layout");
if (ColorTileModeIsLinear(mode)) return (static_cast<std::size_t>(y) * pitch + x) * elementBytes;
const auto block = static_cast<std::size_t>(y / blockHeight) * (pitch / blockWidth) + x / blockWidth;
if (gcn) {
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 @@ -4379,7 +4379,7 @@ bool prepareDraw(const Context& context, const State& state, const Pm4::DrawPara
Require(color.dccAddress == 0 && color.cmaskAddress == 0 && AttachmentProxyFormat(context, color.format) == VK_FORMAT_UNDEFINED, "a slice of a 2D array color target with DCC, CMASK or an attachment proxy has no resident array image");
const auto array = ArraySurfaceForTarget(color);
// DecodeColorBuffer offsets slice s by s times this size; every slice the image stores must agree.
const auto sliceBytes = ComputeSurfaceSize(ComputeElementMipLayout(ColorTextureTileMode(color.tileMode), color.elementBytes, color.surfaceExtent.width, color.surfaceExtent.height, color.mipCount), 1);
const auto sliceBytes = ColorTileModeIsGcn(color.tileMode) ? static_cast<std::uint64_t>(color.bytes) : ComputeSurfaceSize(ComputeElementMipLayout(ColorTextureTileMode(color.tileMode), color.elementBytes, color.surfaceExtent.width, color.surfaceExtent.height, color.mipCount), 1);
const auto geometry = DescribeSurface(array);
for (std::uint32_t slice = 0; slice <= color.arrayLastSlice; ++slice) Require(geometry.GuestLayerOffset(slice) == slice * sliceBytes, "the array image's layer pitch differs from the color view's slice offset");
Require(color.surfaceAddress == color.arrayAddress + color.arraySlice * sliceBytes, "the array image's layer pitch differs from the color view's slice offset");
Expand Down
21 changes: 20 additions & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,8 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
const auto lastSlice = (view >> 13u) & 0x7ffu;
Require(lastSlice >= slice, "the color view ends before its first slice");
const auto exports = find(cx, 0x207);
Require(lastSlice == slice || exports == cx.end() || (exports->second & (1u << 18u)) == 0, "GCN layered rendering into several array slices through the vertex render target index is not implemented");
const bool layered = lastSlice != slice && exports != cx.end() && (exports->second & (1u << 18u)) != 0;
Require(!layered || color.coverageSamples == 1u, "GCN layered rendering into several slices of a multisampled color array through the vertex render target index is not implemented");
const auto pitch = ((read(cx, 0x319 + stride) & 0x7ffu) + 1u) * 8u;
const auto sliceElements = ((read(cx, 0x31a + stride) & 0x3fffffu) + 1u) * 64u;
color.extent = {pitch, sliceElements / pitch};
Expand All @@ -2550,8 +2551,13 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
case 9u: color.tileMode = ColorTileMode::GcnDisplay1D; break;
case 10u: color.tileMode = ColorTileMode::GcnDisplay2D; break;
case 14u: color.tileMode = ColorTileMode::GcnThin2D; break;
case 19u: color.tileMode = ColorTileMode::GcnThick1D; break;
default: throw std::runtime_error("AGC graphics: PS4 color target tile mode index " + std::to_string(attrib & 0x1fu) + " is not implemented");
}
const bool thick = color.tileMode == ColorTileMode::GcnThick1D;
Require(!thick || (color.coverageSamples == 1u && fragments == 1u), "a multisampled PS4 thick color target is not implemented");
Require(!thick || slice == 0u, "a PS4 thick color view that starts past slice 0 is not implemented");
Require(!thick || (info & 0x6000u) == 0u, "a fast-cleared or compressed PS4 thick color target (CMASK or FMASK) is not implemented");
const bool macroTiled = color.tileMode == ColorTileMode::GcnDisplay2D || color.tileMode == ColorTileMode::GcnThin2D;
Require(slice == 0 || !macroTiled || color.samples == 1u, "GCN multisampled color views of a later slice of a 2D-tiled array are not implemented");
if (macroTiled) color.pipeBankXor = GcnLayerBankXor(GcnTiling(ColorTextureTileMode(color.tileMode), color.elementBytes), slice);
Expand All @@ -2561,9 +2567,21 @@ ColorTarget DecodeGcnColorBuffer(const Registers& cx, std::uint32_t slot) {
color.surfaceAddress = (static_cast<std::uint64_t>(read(cx, 0x318 + stride)) << 8u) + static_cast<std::uint64_t>(slice) * layout.Bytes() * fragments;
color.address = color.surfaceAddress;
color.bytes = layout.Bytes();
if (layered && !thick) {
color.arrayAddress = static_cast<std::uint64_t>(read(cx, 0x318 + stride)) << 8u;
color.arraySlice = slice;
color.arrayLastSlice = lastSlice;
color.layers = lastSlice + 1u - slice;
}
color.format = decoded.format;
color.componentMapping = decoded.componentMapping;
color.packing = decoded.packing;
if (thick) {
color.volume = true;
color.depth = lastSlice + 1u;
color.layers = layered ? color.depth : 1u;
color.bytes = SurfaceGuestBytes(SurfaceForTarget(color));
}
for (std::uint32_t word = 0; word < 2; ++word) {
const auto clear = find(cx, 0x323 + word + stride);
color.clearWords[word] = clear == cx.end() ? 0u : clear->second;
Expand Down Expand Up @@ -2596,6 +2614,7 @@ GuestTextureResource ArraySurfaceForTarget(const ColorTarget& color) {
surface.height = color.surfaceExtent.height;
surface.depthOrLastArray = color.arrayLastSlice;
surface.dimension = TextureDimension::k2DArray;
if (ColorTileModeIsGcn(color.tileMode)) surface.pipeBankXor = 0;
return surface;
}

Expand Down
6 changes: 5 additions & 1 deletion core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,11 @@ void gcnColorSliceTests() {
queue.context[0x31b] = 1u | (2u << 13u);
Require(DecodeColorBuffer(queue.context, 0).address == base + GcnSliceBytes, "a GCN color view of several slices decoded without PA_CL_VS_OUT_CNTL does not draw into its first slice");
queue.context[0x207] = 1u << 18u;
expectFailure([&] { static_cast<void>(DecodeColorBuffer(queue.context, 0)); }, "GCN layered rendering into several array slices through the vertex render target index is not implemented");
const auto layered = DecodeColorBuffer(queue.context, 0);
Require(layered.address == base + GcnSliceBytes && layered.bytes == GcnSliceBytes && layered.layers == 2u && layered.arrayAddress == base && layered.arraySlice == 1u && layered.arrayLastSlice == 2u, "a GCN color view of slices 1 to 2 with a vertex render target index does not decode as two layers of the array at CB_COLOR_BASE");
queue.context[0x31d] = 5u | (1u << 12u) | (1u << 15u);
expectFailure([&] { static_cast<void>(DecodeColorBuffer(queue.context, 0)); }, "GCN layered rendering into several slices of a multisampled color array through the vertex render target index is not implemented");
queue.context[0x31d] = 5u;
queue.context[0x31b] = 1u | (1u << 13u);
Require(DecodeColorBuffer(queue.context, 0).address == base + GcnSliceBytes, "a GCN color view of one slice is refused for a vertex render target index");
queue.context[0x207] = 0;
Expand Down
Loading
Loading