Skip to content
Merged
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 @@ -3671,10 +3671,11 @@ bool ImportMappedRanges(const Context& context, const GuestAllocations::Mapped&
} else if (state.refreshedGeneration > generation) {
return true;
}
if (!adopting) current = GuestAllocations::GuestAllocationsAcquire_nid_postfix();
for (const auto& mapped : ranges) {
const auto range = mapped.lock();
if (range == nullptr || leasedRangeOwner(current, range->address) != range) continue;
if (range == nullptr || range->bytes <= 0x10000) continue;
if (current.empty()) current = GuestAllocations::GuestAllocationsAcquire_nid_postfix();
if (leasedRangeOwner(current, range->address) != range) continue;
try {
if (!GuestMemory::GpuMutex().HeldByThisThread()) {
const auto run = importRun(current, range->address, std::numeric_limits<std::uint64_t>::max(), effectiveBudget(context, state));
Expand Down
33 changes: 26 additions & 7 deletions core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ class UnrelatedImportProbeRange {

void importMappedFailureGenerationTests(const Context& context) {
ClearHostImports(context.device);
WindowedRange range(context, WindowedRange::piece, 1);
WindowedRange range(context, 2 * WindowedRange::piece, 1);
ImportAllocationProbe probe(range.importing);
probe.failure = VK_ERROR_INVALID_EXTERNAL_HANDLE;
GuestAllocations::Mapped mapped;
Expand Down Expand Up @@ -1081,7 +1081,7 @@ void importNeighbouringEdgesTests(const Context& context) {
// observer holds no GPU lock, so it must not evict (before, it evicted the least recently used import to fit).
void importAtMapOverBudgetTests(const Context& context) {
ClearHostImports(context.device);
constexpr std::size_t bytes = 65536;
constexpr std::size_t bytes = 2 * 65536;
auto importing = context;
importing.hostImportAlignment = bytes;
void* kept = ::operator new(bytes, std::align_val_t{bytes});
Expand Down Expand Up @@ -1142,17 +1142,32 @@ void importRequesterTests(const Context& context, const BdaTestAccess& access) {
const auto counted = [](ImportRequester requester) { return HostImportCounters().requesters[static_cast<std::size_t>(requester)]; };
const auto made = [&](ImportRequester requester) { return counted(requester).made; };
Require(std::string(ImportRequesterName(ImportRequester::Map)) == "map" && std::string(ImportRequesterName(ImportRequester::Build)) == "build" && std::string(ImportRequesterName(ImportRequester::Access)) == "access" && std::string(ImportRequesterName(ImportRequester::Join)) == "join" && std::string(ImportRequesterName(ImportRequester::Segment)) == "segment", "an import requester has the wrong name");
change(0, true);
{
const auto mappedRange = [&](std::size_t index) {
GuestAllocations::Mapped ranges;
const auto lease = GuestAllocations::GuestAllocationsAcquire_nid_postfix();
for (const auto& range : lease) {
if (range->address == address(0)) ranges.push_back(range);
if (range->address == address(index)) ranges.push_back(range);
}
Require(ranges.size() == 1, "the requester test's mapped range is not registered");
return ranges;
};
{
GuestAllocations::Mutation mutation;
mutation.Add(block + 6 * piece, 2 * piece, true, true, true);
}
{
const auto before = made(ImportRequester::Map);
static_cast<void>(ImportMappedRanges(importing, ranges, GuestAllocations::GuestAllocationsGeneration_nid_postfix(), true));
Require(made(ImportRequester::Map) == before + 1 && HostImportCovers(importing, address(0), piece), "a range imported at map time was not counted for the map requester");
static_cast<void>(ImportMappedRanges(importing, mappedRange(6), GuestAllocations::GuestAllocationsGeneration_nid_postfix(), true));
Require(made(ImportRequester::Map) == before + 1 && HostImportCovers(importing, address(6), 2 * piece), "a range imported at map time was not counted for the map requester");
}
change(0, true);
{
const auto map = made(ImportRequester::Map);
const auto access = made(ImportRequester::Access);
static_cast<void>(ImportMappedRanges(importing, mappedRange(0), GuestAllocations::GuestAllocationsGeneration_nid_postfix(), true));
Require(made(ImportRequester::Map) == map && !HostImportCovers(importing, address(0), 16), "a range of 64 KiB was imported at map time");
Require(HostImportFor(importing, address(0), 16) != nullptr && HostImportCovers(importing, address(0), piece) && made(ImportRequester::Access) == access + 1 && made(ImportRequester::Map) == map,
"a range of 64 KiB left to its first GPU use was not imported there, or not counted for that use's requester");
}
change(1, true);
{
Expand Down Expand Up @@ -1230,6 +1245,10 @@ void importRequesterTests(const Context& context, const BdaTestAccess& access) {
const auto counts = HostImportCounters();
Require(counts.live >= 4 && counts.liveBytes == HostImportLiveBytes(), "the live import counts disagree with the live bytes");
for (std::size_t index = 0; index < 6; ++index) change(index, false);
{
GuestAllocations::Mutation mutation;
mutation.Remove(block + 6 * piece);
}
ClearHostImports(importing.device);
::operator delete(block, std::align_val_t{piece});
}
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ void remappedImportTests(const Device& device) {

void hostImportRetirementTests(const Device& device) {
const auto& context = device.GetContext();
constexpr std::size_t UnitBytes = 65536;
constexpr std::size_t UnitBytes = 2 * 65536;
constexpr std::size_t AllocationBytes = 4 * UnitBytes;
constexpr std::size_t CopyBytes = 256;
#ifdef _WIN32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
#include <mutex>
#include <string>

namespace AgcDriver {

struct VulkanDeviceTestAccess {
static Graphics::Context ContextOf(const VulkanDevice& device) { return device.graphicsContext(); }
};

}

namespace {

namespace Graphics = AgcDriver::Graphics;
Expand Down Expand Up @@ -163,6 +171,41 @@ Outcome ResidentMappingsImportAfterCollection() {
return Outcome::Passed;
}

Outcome SmallMappingsImportOnFirstUse() {
GuestBlock small(GuestAlignment);
GuestBlock large(2 * GuestAlignment);
auto device = OpenVulkanTestDevice();
if (!device) return Outcome::NoDevice;
const auto context = AgcDriver::VulkanDeviceTestAccess::ContextOf(*device);
if (context.hostImportAlignment == 0) return Outcome::NoImport;
for (auto* guest : {&small, &large}) {
Graphics::ClearHostImports(device->Device());
GuestAllocations::Mapped ranges;
for (const auto& range : GuestAllocations::GuestAllocationsAcquire_nid_postfix()) {
if (range->address == guest->Address()) ranges.push_back(range);
}
Require(ranges.size() == 1, "mapped import test lost its registered range");
{
std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex());
Require(Graphics::ImportMappedRanges(context, ranges, GuestAllocations::GuestAllocationsGeneration_nid_postfix(), true), "mapped import test could not adopt the device");
}
Require(Graphics::HostImportCovers(context, guest->Address(), ProbeBytes) == (guest == &large), "mapping did not defer exactly the small import");
Require(Fill(*device, guest->Address()), "first GPU use could not import the mapped buffer");
Require(Graphics::HostImportCovers(context, guest->Address(), ProbeBytes), "first GPU use left the mapped buffer unimported");
constexpr std::array<std::uint32_t, 4> pattern{0x11111111u, 0x22222222u, 0x33333333u, 0x44444444u};
for (std::size_t offset = 0; offset < ProbeBytes; offset += sizeof(std::uint32_t)) {
std::uint32_t actual = 0;
std::memcpy(&actual, guest->Data() + offset, sizeof(actual));
Require(actual == pattern[(offset / sizeof(actual)) % pattern.size()], "first GPU use changed the fill result");
}
for (std::size_t offset = ProbeBytes; offset < GuestAlignment; ++offset) {
Require(guest->Data()[offset] == 0, "first GPU use overwrote bytes outside the fill");
}
}
Graphics::ClearHostImports(device->Device());
return Outcome::Passed;
}

}

int main() {
Expand All @@ -176,6 +219,7 @@ int main() {
const auto windows = WindowsFollowTheirRange();
Require(windows == Outcome::Passed, "host import windows: the device stopped importing guest memory between two scenarios");
Require(ResidentMappingsImportAfterCollection() == Outcome::Passed, "resident import test failed");
Require(SmallMappingsImportOnFirstUse() == Outcome::Passed, "mapped import test lost its Vulkan device or host import support");
std::puts("host import windows tests passed");
return 0;
} catch (const std::exception& error) {
Expand Down
Loading