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
4 changes: 1 addition & 3 deletions core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ void Validate(std::span<const std::uint32_t> packet, std::uint32_t queue) {
graphics();
size(6);
require(packet[3] <= 0xffffu, "unsupported index address bits");
require(packet[4] <= packet[1], "index count exceeds maximum index size");
require((packet[5] & ~0x20u) == 0, "unsupported indexed draw flags");
break;
case 0x2a: graphics(); size(2); require(packet[1] <= 3, "unsupported index-type modifiers"); break;
Expand All @@ -421,7 +420,6 @@ void Validate(std::span<const std::uint32_t> packet, std::uint32_t queue) {
case 0x35:
graphics();
size(5);
require(packet[3] <= packet[1], "index count exceeds maximum index size");
require((packet[4] & ~0x20u) == 0, "unsupported indexed draw flags");
break;
case 0x24: case 0x25:
Expand Down Expand Up @@ -1056,7 +1054,7 @@ DrawParameters ResolveDraw(std::span<const std::uint32_t> packet, const QueueSta
require(queue.indexType <= 2, "unsupported index type");
const std::uint32_t indexSize = queue.indexType == 0 ? 2 : queue.indexType == 1 ? 4 : 1;
const auto base = explicitAddress ? address(packet[2], packet[3]) : queue.indexBase;
const auto count = explicitAddress ? packet[4] : packet[3];
const auto count = std::min(explicitAddress ? packet[4] : packet[3], packet[1]);
require(base != 0 && base % indexSize == 0, "null or misaligned index base");
const auto offset = explicitAddress ? 0 : static_cast<std::uint64_t>(packet[2]) * indexSize;
require(offset <= std::numeric_limits<std::uint64_t>::max() - base, "index address overflow");
Expand Down
6 changes: 5 additions & 1 deletion core/libs/prx/libSceAgcDriver/tests/Pm4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,15 @@ void testIndexedDraw() {
const auto address = reinterpret_cast<std::uintptr_t>(indices.data());
const auto explicitDraw = AgcDriver::Pm4::ResolveDraw(makePacket(0x27, {4, static_cast<std::uint32_t>(address), static_cast<std::uint32_t>(address >> 32u), 4, 0}), state);
check(explicitDraw.indexed && explicitDraw.firstVertex == 0xd4d4 && explicitDraw.indexAddress == address, "DRAW_INDEX_2 ignored GE_INDX_OFFSET");
const auto clippedOffsetDraw = AgcDriver::Pm4::ResolveDraw(makePacket(0x35, {3, 2, 6, 0}), state);
check(clippedOffsetDraw.indexAddress == state.indexBase + 4 && clippedOffsetDraw.indexCount == 3, "DRAW_INDEX_OFFSET_2 read past MAX_SIZE");
const auto clippedExplicitDraw = AgcDriver::Pm4::ResolveDraw(makePacket(0x27, {2, static_cast<std::uint32_t>(address), static_cast<std::uint32_t>(address >> 32u), 5, 0}), state);
check(clippedExplicitDraw.indexAddress == address && clippedExplicitDraw.indexCount == 2, "DRAW_INDEX_2 read past MAX_SIZE");
check(AgcDriver::Pm4::ResolveDraw(makePacket(0x35, {0, 0, 4, 0}), state).indexCount == 0, "DRAW_INDEX_OFFSET_2 with MAX_SIZE 0 read indices");
state.userConfig.erase(0x24a);
expectFailure([&] { AgcDriver::Pm4::ResolveDraw(packet, state); }, "GE_INDX_OFFSET");
state.userConfig[0x24a] = 0;
expectFailure([&] { AgcDriver::Pm4::Validate(packet, 0x20); }, "compute queue");
expectFailure([] { AgcDriver::Pm4::Validate(makePacket(0x35, {3, 0, 4, 0}), 0); }, "maximum index size");
expectFailure([] { AgcDriver::Pm4::Validate(makePacket(0x35, {4, 0, 4, 1}), 0); }, "draw flags");
expectFailure([] { AgcDriver::Pm4::Validate(makePacket(0x35, {4, 0, 4}), 0); }, "packet size");
state.indexType = 3;
Expand Down
20 changes: 12 additions & 8 deletions core/libs/tests/GuestIndexedDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ int main() {
draw[1] = 0; draw[4] = 0;
Require(AgcDriver::Pm4::ResolveDraw({draw,6},queue).indexCount == 0);
draw[1] = 3; draw[4] = 3;
draw[4]=4;
Reject([&]{AgcDriver::Pm4::Validate({draw,6},0);});
draw[4]=0xffffffffu;
Reject([&]{AgcDriver::Pm4::Validate({draw,6},0);});
for (const std::uint32_t count : {4u,0xffffffffu}) {
draw[4]=count;
AgcDriver::Pm4::Validate({draw,6},0);
Require(AgcDriver::Pm4::ResolveDraw({draw,6},queue).indexCount==3);
}
draw[4]=3;
draw[5]=2;
Reject([&]{AgcDriver::Pm4::Validate({draw,6},0);});
Expand All @@ -68,10 +69,13 @@ int main() {
queue.indexBase=0;
Reject([&]{AgcDriver::Pm4::ResolveDraw(offsetDraw,queue);});
queue.indexBase=reinterpret_cast<std::uintptr_t>(indices.data());
const std::array<std::uint32_t,5> invalidOffsetCount{0xc0033500u,2,1,3,0};
Reject([&]{AgcDriver::Pm4::Validate(invalidOffsetCount,0);});
const std::array<std::uint32_t,5> maxOffsetCount{0xc0033500u,2,1,0xffffffffu,0};
Reject([&]{AgcDriver::Pm4::Validate(maxOffsetCount,0);});
const auto unclamped=AgcDriver::Pm4::ResolveDraw(offsetDraw,queue);
for (const std::uint32_t count : {3u,0xffffffffu}) {
const std::array<std::uint32_t,5> clampedOffsetDraw{0xc0033500u,2,1,count,0};
AgcDriver::Pm4::Validate(clampedOffsetDraw,0);
const auto clamped=AgcDriver::Pm4::ResolveDraw(clampedOffsetDraw,queue);
Require(clamped.indexAddress==unclamped.indexAddress&&clamped.indexCount==2);
}
auto* saved=buffer.cursor_up;
Reject([&]{sceAgcDcbDrawIndex(&buffer,3,nullptr,0);});
Require(buffer.cursor_up==saved);
Expand Down
5 changes: 5 additions & 0 deletions docs/dev/debt/changes/fix-agc-index-count-past-max-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libSceAgcDriver

## add Functional

- [Indexed draws whose INDEX_COUNT exceeds MAX_SIZE](../../../core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp) (libSceAgcDriver, DRAW_INDEX_2 0x27 and DRAW_INDEX_OFFSET_2 0x35) drop the indices past MAX_SIZE, which the hardware reads as 0 instead ([Mesa 26.2.2 RADV](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-26.2.2/src/amd/vulkan/radv_cmd_buffer.c#L11354-L11360)), so a triangle that straddles MAX_SIZE, or the extra points of a point list, are not drawn as on the console. AMD PAL [c5e80007](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9UniversalCmdBuffer.cpp#L3040-L3051) writes MAX_SIZE as the indices left in the bound buffer from the draw's first index and INDEX_COUNT as the draw's own count. The CPU indirect path ([Draw.cpp](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp)) clamps a record past INDEX_BUFFER_SIZE the same way. Not measured on a console.
Loading