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
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ foreach(agcExecutionTestSource IN LISTS agcExecutionTestSources)
endforeach()

if(BUILD_TESTING)
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_spirv_module_tests agc_dpp_write_tests agc_masked_select_tests agc_vop1_control_decode_tests agc_validate_program_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests})
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_spirv_module_tests agc_dpp_write_tests agc_masked_select_tests agc_vop1_control_decode_tests agc_validate_program_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests agc_driver_bda_device_tests ${agcExecutionTests})
string(REGEX REPLACE "_tests$" "" agcTestName "${agcTest}")
set_target_properties(${agcTest} PROPERTIES EXCLUDE_FROM_ALL OFF)
add_test(NAME ${agcTestName} COMMAND ${agcTest})
Expand Down
45 changes: 40 additions & 5 deletions core/libs/prx/libSceAgcDriver/tests/BdaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "prx/libSceAgcDriver/Graphics/include/Resources.hpp"
#include <SDL_loadso.h>
#include <array>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <vector>

namespace AgcDriver::Graphics {
Expand Down Expand Up @@ -42,7 +44,27 @@ class Device {
Require(count != 0, "no Vulkan device");
std::vector<VkPhysicalDevice> devices(count);
Check(enumerate(instance, &count, devices.data()), "vkEnumeratePhysicalDevices");
context.physical = devices.front();
const auto rankDeviceType = [](VkPhysicalDeviceType type) {
switch (type) {
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: return 3;
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: return 2;
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: return 1;
default: return 0;
}
};
const auto physicalProperties = function<PFN_vkGetPhysicalDeviceProperties>("vkGetPhysicalDeviceProperties");
int selectedRank = -1;
for (const auto physical : devices) {
VkPhysicalDeviceProperties candidate{};
physicalProperties(physical, &candidate);
if (candidate.apiVersion < VK_API_VERSION_1_1) continue;
const int rank = rankDeviceType(candidate.deviceType);
if (rank <= selectedRank) continue;
context.physical = physical;
selectedRank = rank;
cpu = candidate.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
}
Require(context.physical != VK_NULL_HANDLE, "no Vulkan 1.1 device");
const auto extensions = function<PFN_vkEnumerateDeviceExtensionProperties>("vkEnumerateDeviceExtensionProperties");
Check(extensions(context.physical, nullptr, &count, nullptr), "vkEnumerateDeviceExtensionProperties");
std::vector<VkExtensionProperties> available(count);
Expand Down Expand Up @@ -90,6 +112,7 @@ class Device {

~Device() { release(); }
const Context& GetContext() const { return context; }
bool RunsOnCpu() const { return cpu; }

private:
template<typename TFunction>
Expand All @@ -111,6 +134,7 @@ class Device {
PFN_vkGetInstanceProcAddr instanceProc = nullptr;
VkInstance instance = VK_NULL_HANDLE;
Context context{};
bool cpu = false;
};

}
Expand All @@ -125,13 +149,24 @@ int main(int argc, char** argv) {
Require(static_cast<bool>(file), "cannot save BDA test SPIR-V");
return 0;
}
Device device;
Buffer buffer(device.GetContext(), 256, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
std::unique_ptr<Device> device;
try {
device = std::make_unique<Device>();
} catch (const std::exception& error) {
if (std::getenv("ANYPS5_REQUIRE_VULKAN") != nullptr) throw;
std::cout << "skipped, no usable Vulkan device: " << error.what() << '\n';
return 77;
}
Buffer buffer(device->GetContext(), 256, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
Require(buffer.DeviceAddress() != 0 && buffer.Bytes().size() == 256, "invalid real BDA buffer");
buffer.Bytes()[255] = std::byte{0x5a};
Require(buffer.Bytes()[255] == std::byte{0x5a}, "real BDA buffer mapping failed");
RunBdaExecutionTests(device.GetContext());
RunColorTransferTests(device.GetContext());
if (device->RunsOnCpu()) {
std::cout << "CPU Vulkan device: BDA execution not tested\n";
} else {
RunBdaExecutionTests(device->GetContext());
}
RunColorTransferTests(device->GetContext());
std::cout << "Vulkan BDA allocation and execution tests passed\n";
return 0;
} catch (const std::exception& error) {
Expand Down
Loading