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
5 changes: 2 additions & 3 deletions core/libs/prx/libSceAgcDriver/Execution/src/BdaFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ namespace AgcDriver {

VkPhysicalDevice8BitStorageFeatures QueryBdaByteFeatures(VkPhysicalDevice physical, PFN_vkGetPhysicalDeviceFeatures2 query, std::span<const VkExtensionProperties> extensions) {
Graphics::Require(query != nullptr, "missing Vulkan feature query");
Graphics::Require(std::any_of(extensions.begin(), extensions.end(), [](const auto& extension) { return std::strcmp(extension.extensionName, VK_KHR_8BIT_STORAGE_EXTENSION_NAME) == 0; }), "VK_KHR_8bit_storage is unavailable");
VkPhysicalDevice8BitStorageFeatures bytes{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES};
if (std::none_of(extensions.begin(), extensions.end(), [](const auto& extension) { return std::strcmp(extension.extensionName, VK_KHR_8BIT_STORAGE_EXTENSION_NAME) == 0; })) return bytes;
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &bytes};
query(physical, &features);
Graphics::Require(bytes.storageBuffer8BitAccess == VK_TRUE, "BDA requires exact byte access through storageBuffer8BitAccess");
return {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES, nullptr, VK_TRUE, VK_FALSE, VK_FALSE};
return {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES, nullptr, bytes.storageBuffer8BitAccess, VK_FALSE, VK_FALSE};
}

VkPhysicalDeviceBufferDeviceAddressFeatures QueryBdaFeatures(VkPhysicalDevice physical, PFN_vkGetPhysicalDeviceFeatures2 query, std::span<const VkExtensionProperties> extensions) {
Expand Down
13 changes: 2 additions & 11 deletions core/libs/prx/libSceAgcDriver/Execution/src/HostReportVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,17 @@ HostGpuFacts CollectHostGpuFacts(const HostGpuQuery& query) {
if ((memory.memoryHeaps[index].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) largest = std::max<std::uint64_t>(largest, memory.memoryHeaps[index].size);
gpu.deviceLocalMiB = largest / (1024u * 1024u);

VkPhysicalDevice8BitStorageFeatures bytes{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES};
VkPhysicalDeviceBufferDeviceAddressFeatures address{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES};
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
const bool hasBytes = has(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
const bool hasAddress = has(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
void** featureNext = &features.pNext;
if (hasBytes) {
*featureNext = &bytes;
featureNext = &bytes.pNext;
}
if (hasAddress) *featureNext = &address;
if (hasAddress) features.pNext = &address;
load<PFN_vkGetPhysicalDeviceFeatures2>(query, "vkGetPhysicalDeviceFeatures2")(query.physical, &features);
const auto& core = features.features;
const auto required = [&](const char* name, const char* kind, bool present) { gpu.requirements.push_back({name, kind, true, present}); };
const auto optional = [&](const char* name) { gpu.requirements.push_back({name, "extension", false, has(name)}); };
if (query.presentation) required(VK_KHR_SWAPCHAIN_EXTENSION_NAME, "extension", has(VK_KHR_SWAPCHAIN_EXTENSION_NAME));
required(VK_KHR_8BIT_STORAGE_EXTENSION_NAME, "extension", hasBytes);
required(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, "extension", hasAddress);
required(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME, "extension", hasFloatControls);
required("storageBuffer8BitAccess", "feature", hasBytes && bytes.storageBuffer8BitAccess == VK_TRUE);
required("bufferDeviceAddress", "feature", hasAddress && address.bufferDeviceAddress == VK_TRUE);
required("shaderInt64", "feature", core.shaderInt64 == VK_TRUE);
required("shaderSignedZeroInfNanPreserveFloat32", "feature", hasFloatControls && floatControls.shaderSignedZeroInfNanPreserveFloat32 == VK_TRUE);
Expand All @@ -118,7 +109,7 @@ HostGpuFacts CollectHostGpuFacts(const HostGpuQuery& query) {
VK_KHR_MAINTENANCE_5_EXTENSION_NAME, VK_EXT_HDR_METADATA_EXTENSION_NAME, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME,
VK_EXT_SHADER_IMAGE_ATOMIC_INT64_EXTENSION_NAME, VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME,
VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME,
VK_KHR_PRESENT_MODE_FIFO_LATEST_READY_EXTENSION_NAME, "VK_EXT_present_mode_fifo_latest_ready"})
VK_KHR_PRESENT_MODE_FIFO_LATEST_READY_EXTENSION_NAME, "VK_EXT_present_mode_fifo_latest_ready", VK_KHR_8BIT_STORAGE_EXTENSION_NAME})
optional(name);

if (query.surface != VK_NULL_HANDLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ ShaderDeviceProfile::ShaderDeviceProfile(const ShaderRecompiler::SpirvTarget& ta
const auto* maintenance8 = findFeatures<VkPhysicalDeviceMaintenance8FeaturesKHR>(deviceInfo.pNext, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_8_FEATURES_KHR);
Require(target.bdaAbiVersion == ShaderRecompiler::BdaAbi::Version, "shader device profile has an incompatible BDA ABI");
Require(bda != nullptr && bda->bufferDeviceAddress == VK_TRUE && core.shaderInt64 == VK_TRUE, "shader runtime requires enabled bufferDeviceAddress and shaderInt64");
Require(bytes != nullptr && bytes->storageBuffer8BitAccess == VK_TRUE, "shader runtime requires enabled storageBuffer8BitAccess");
Require(core.vertexPipelineStoresAndAtomics == VK_TRUE && core.fragmentStoresAndAtomics == VK_TRUE, "shader runtime requires enabled graphics stores and atomics");
Require(limits.maxPushConstantsSize >= ShaderRecompiler::RuntimeAbi::PushConstantDwords * sizeof(std::uint32_t) && limits.maxBoundDescriptorSets > ShaderRecompiler::RuntimeAbi::DescriptorSet, "shader runtime ABI exceeds device limits");
Require(limits.maxStorageBufferRange >= sizeof(ShaderRecompiler::RuntimeAbi::ShaderData), "shader runtime ShaderData exceeds device limits");
std::ranges::sort(capabilities);
capabilities.erase(std::unique(capabilities.begin(), capabilities.end()), capabilities.end());
const auto hasCapability = [&](spv::Capability capability) { return std::ranges::binary_search(capabilities, static_cast<std::uint32_t>(capability)); };
Require(hasCapability(spv::CapabilityShader) && hasCapability(spv::CapabilityInt64) && hasCapability(spv::CapabilityPhysicalStorageBufferAddresses) && hasCapability(spv::CapabilityStorageBuffer8BitAccess), "shader device profile is missing runtime capabilities");
Require(hasCapability(spv::CapabilityShader) && hasCapability(spv::CapabilityInt64) && hasCapability(spv::CapabilityPhysicalStorageBufferAddresses), "shader device profile is missing runtime capabilities");
const auto checkFeature = [&](spv::Capability capability, bool enabled, const char* name) {
Require(!hasCapability(capability) || enabled, std::string("shader device profile advertises a disabled feature: ") + name);
};
checkFeature(spv::CapabilityStorageBuffer8BitAccess, bytes != nullptr && bytes->storageBuffer8BitAccess == VK_TRUE, "storageBuffer8BitAccess");
checkFeature(spv::CapabilityFloat64, core.shaderFloat64 == VK_TRUE, "shaderFloat64");
checkFeature(spv::CapabilityInt16, core.shaderInt16 == VK_TRUE, "shaderInt16");
checkFeature(spv::CapabilityGeometry, core.geometryShader == VK_TRUE, "geometryShader");
Expand Down Expand Up @@ -82,7 +82,8 @@ ShaderDeviceProfile::ShaderDeviceProfile(const ShaderRecompiler::SpirvTarget& ta
std::ranges::sort(extensions);
extensions.erase(std::unique(extensions.begin(), extensions.end()), extensions.end());
for (const auto& extension : extensions) extensionViews.emplace_back(extension);
Require(std::ranges::find(extensionViews, "SPV_KHR_physical_storage_buffer") != extensionViews.end() && std::ranges::find(extensionViews, "SPV_KHR_8bit_storage") != extensionViews.end(), "shader device profile is missing runtime extensions");
Require(std::ranges::find(extensionViews, "SPV_KHR_physical_storage_buffer") != extensionViews.end(), "shader device profile is missing runtime extensions");
Require(!hasCapability(spv::CapabilityStorageBuffer8BitAccess) || std::ranges::find(extensionViews, "SPV_KHR_8bit_storage") != extensionViews.end(), "shader device profile is missing runtime extensions");
Require(std::ranges::find(extensionViews, "SPV_KHR_terminate_invocation") == extensionViews.end() || (terminate != nullptr && terminate->shaderTerminateInvocation == VK_TRUE), "shader device profile advertises a disabled feature: shaderTerminateInvocation");
this->target.supportedCapabilities = capabilities;
this->target.supportedExtensions = extensionViews;
Expand Down
10 changes: 6 additions & 4 deletions core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,9 +1858,11 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window, bool compileOnly) :
state->spirvExtensions.push_back("SPV_KHR_fma");
}
deviceExtensions.push_back(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
deviceExtensions.push_back(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
state->capabilities.push_back(4448);
state->spirvExtensions.push_back("SPV_KHR_8bit_storage");
if (byteFeatures.storageBuffer8BitAccess == VK_TRUE) {
deviceExtensions.push_back(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
state->capabilities.push_back(4448);
state->spirvExtensions.push_back("SPV_KHR_8bit_storage");
}
state->capabilities.push_back(11);
state->capabilities.push_back(5347);
state->spirvExtensions.push_back("SPV_KHR_physical_storage_buffer");
Expand Down Expand Up @@ -2519,7 +2521,7 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window, bool compileOnly) :
std::fprintf(stderr, "[gpu] APS5_NV_DIAGNOSTICS: the device does not support VK_NV_device_diagnostics_config\n");
}
const bool diagnosticCheckpoints = diagnostics.config && diagnostics.checkpoints;
bdaFeatures.pNext = &byteFeatures;
bdaFeatures.pNext = byteFeatures.storageBuffer8BitAccess == VK_TRUE ? &byteFeatures : byteFeatures.pNext;
VkPhysicalDeviceRobustness2FeaturesEXT robustness2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT};
if (hasExtension(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME)) {
VkPhysicalDeviceFeatures2 queried{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &robustness2};
Expand Down
21 changes: 21 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <functional>
#include <initializer_list>
#include <string>
#include <utility>
#include <vector>
#include <utility>
#include <array>
Expand Down Expand Up @@ -257,6 +258,26 @@ void RunBdaContractTests() {
program.Resources().stage = IrShaderStage::Compute;
program.Info().usesDma = true;
ValidateBdaTarget(program, target);
const std::array<std::uint32_t, 2> wordCapabilities{spv::CapabilityInt64, spv::CapabilityPhysicalStorageBufferAddresses};
const std::array<std::string_view, 1> wordExtensions{"SPV_KHR_physical_storage_buffer"};
ValidateBdaTarget(program, SpirvTargetOptions{0x00401000u, 0x00010300u, 32, BdaAbi::Version, wordCapabilities, wordExtensions});
const auto declaresBytes = [](const std::vector<std::uint32_t>& words) {
for (std::size_t offset = 5; offset < words.size() && (words[offset] >> 16u) != 0u; offset += words[offset] >> 16u) {
const auto opcode = words[offset] & 0xffffu;
if (opcode == spv::OpCapability && words[offset + 1] == spv::CapabilityStorageBuffer8BitAccess) return true;
if (opcode == spv::OpTypeInt && words[offset + 2] == 8u) return true;
}
return false;
};
for (const bool bytePointers : {true, false}) {
SetBdaTestBytePointers(bytePointers);
const std::array<std::pair<std::vector<std::uint32_t>, bool>, 4> shaders{{{MakeBdaTestShader(0x1001, 8), false}, {MakeBdaTestShader(0x1001, 16), false}, {MakeBdaStoreTestShader(0x1001, 7, 8, false), true}, {MakeBdaWriteTestShader(0x1001, 7, 32, true), true}}};
for (const auto& [shader, stores] : shaders) {
AgcDriver::Graphics::Require(declaresBytes(shader) == bytePointers, bytePointers ? "a BDA byte access did not use 8-bit pointers on a target with StorageBuffer8BitAccess" : "a BDA byte access declared 8-bit storage on a target without StorageBuffer8BitAccess");
AgcDriver::Graphics::Require(SpirvStoresThroughAddresses(shader) == stores, "a BDA byte access was misread by the address store scan");
}
}
SetBdaTestBytePointers(true);
target.bdaAbiVersion = 0;
reject([&] { ValidateBdaTarget(program, target); }, "ABI version");
target.bdaAbiVersion = BdaAbi::Version;
Expand Down
13 changes: 7 additions & 6 deletions core/libs/prx/libSceAgcDriver/tests/BdaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ int main(int argc, char** argv) {
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");
if (device->RunsOnCpu()) {
std::cout << "CPU Vulkan device: BDA read and multi-dword write execution not tested\n";
} else {
RunBdaExecutionTests(device->GetContext());
if (device->RunsOnCpu()) std::cout << "CPU Vulkan device: BDA read and multi-dword write execution not tested\n";
for (const bool bytePointers : {true, false}) {
SetBdaTestBytePointers(bytePointers);
if (!device->RunsOnCpu()) RunBdaExecutionTests(device->GetContext());
RunBdaStoreExecutionTests(device->GetContext());
std::cout << (bytePointers ? "BDA store boundary tests passed with 8-bit pointers\n" : "BDA store boundary tests passed with 32-bit word byte access\n");
}
RunBdaStoreExecutionTests(device->GetContext());
std::cout << "BDA store boundary tests passed\n";
SetBdaTestBytePointers(true);
RunBdaFaultSlotExecutionTests(device->GetContext());
std::cout << "BDA report-only fault slot tests passed\n";
RunColorTransferTests(device->GetContext());
Expand Down
14 changes: 14 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
#include "SpirvBackend/SpirvMemory/SpirvTypes.hpp"
#include "SpirvBackend/SpirvMemory/SpirvConstants.hpp"
#include "IntermediateRepresentation/IrBuilder.hpp"
#include <array>
#if ANYPS5_ENABLE_SPIRV_TOOLS
#include "SpirvBackend/SpirvOptimizer.hpp"
#endif

namespace {

constexpr std::array<std::uint32_t, 1> BytePointerCapabilities{spv::CapabilityStorageBuffer8BitAccess};
bool bytePointers = true;

void UseTestTarget(ShaderRecompiler::SpirvEmitterState& state) {
if (bytePointers) state.supportedCapabilities = BytePointerCapabilities;
}

template<typename TEmit>
std::vector<std::uint32_t> MakeShader(std::uint64_t address, bool coherent, bool stops, const TEmit& emit, std::uint32_t extracted = 0, bool writes = false) {
using namespace ShaderRecompiler;
Expand All @@ -22,6 +30,7 @@ std::vector<std::uint32_t> MakeShader(std::uint64_t address, bool coherent, bool
program.Resources().memoryInfo = {memory};
}
SpirvEmitterState state(program, {});
UseTestTarget(state);
EmitBaseHeader(state.module, program);
const auto define = [&](std::uint32_t binding) {
const auto variable = state.module.DefineGlobalVariable(TypeStorageBufferPointer(state), spv::StorageClassStorageBuffer);
Expand Down Expand Up @@ -71,6 +80,10 @@ std::vector<std::uint32_t> MakeShader(std::uint64_t address, bool coherent, bool

}

void SetBdaTestBytePointers(bool enabled) {
bytePointers = enabled;
}

std::vector<std::uint32_t> MakeBdaTestShader(std::uint64_t address, std::uint32_t bits, std::int64_t offset) {
using namespace ShaderRecompiler;
return MakeShader(address, false, true, [&](SpirvValueEmitContext& ctx, const IrValue& instruction, std::uint32_t base) {
Expand Down Expand Up @@ -153,6 +166,7 @@ std::vector<std::uint32_t> MakeBdaAnchoredReadTestShader(const BdaAnchoredReadPr
program.Resources().memoryInfo = {memory};
}
SpirvEmitterState state(program, {});
UseTestTarget(state);
EmitBaseHeader(state.module, program);
if (reads.elect) {
state.module.EmitCapability(spv::CapabilityGroupNonUniform);
Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <initializer_list>
#include <vector>

void SetBdaTestBytePointers(bool enabled);
std::vector<std::uint32_t> MakeBdaTestShader(std::uint64_t address, std::uint32_t bits, std::int64_t offset = 0);
std::vector<std::uint32_t> MakeBdaDwordReadTestShader(std::uint64_t address, std::uint32_t dwords, bool coherent, bool stops);
std::vector<std::uint32_t> MakeBdaSpanReadTestShader(std::uint64_t address, std::uint32_t offset, std::uint32_t extracted, bool coherent, bool stops);
Expand Down
8 changes: 5 additions & 3 deletions core/libs/prx/libSceAgcDriver/tests/HostReportVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ void MissingExtensionsAreFound() {
const auto missing = AgcDriver::MissingRequirements(gpu);
std::vector<std::string> names;
for (const auto& item : missing) names.push_back(item.name);
const std::vector<std::string> expected{VK_KHR_8BIT_STORAGE_EXTENSION_NAME, VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, "bufferDeviceAddress", "storageBuffer8BitAccess"};
const std::vector<std::string> expected{VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, "bufferDeviceAddress"};
Check(names == expected, "the missing extensions and the features that depend on them were not found");
const auto message = AgcDriver::DescribeMissingRequirements(gpu);
Check(message.find("Fake GPU 9000") != std::string::npos && message.find("VK_KHR_8bit_storage (extension)") != std::string::npos, "the message does not name the GPU and the missing extension");
Check(message.find("Fake GPU 9000") != std::string::npos && message.find("VK_KHR_buffer_device_address (extension)") != std::string::npos, "the message does not name the GPU and the missing extension");
const auto* bytes = Find(gpu, VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
Check(bytes != nullptr && !bytes->required && !bytes->present, "the absent 8-bit storage extension is not listed as optional and missing");
}

void MissingFeaturesAreFound() {
Expand All @@ -199,7 +201,7 @@ void MissingFeaturesAreFound() {
device.address = false;
names.clear();
for (const auto& item : AgcDriver::MissingRequirements(AgcDriver::CollectHostGpuFacts(Query(extensions)))) names.push_back(item.name);
const std::vector<std::string> second{"bufferDeviceAddress", "fragmentStoresAndAtomics", "storageBuffer8BitAccess", "textureCompressionBC", "vertexPipelineStoresAndAtomics"};
const std::vector<std::string> second{"bufferDeviceAddress", "fragmentStoresAndAtomics", "textureCompressionBC", "vertexPipelineStoresAndAtomics"};
Check(names == second, "the second set of unsupported features was not found");
}

Expand Down
7 changes: 7 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/ShaderDeviceProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ void CheckProfile() {
invalid([](auto& value) { value.core.shaderInt64 = VK_FALSE; }, "shaderInt64");
invalid([](auto& value) { value.capabilities.push_back(spv::CapabilityGeometry); }, "geometryShader");
invalid([](auto& value) { value.bytes.storageBuffer8BitAccess = VK_FALSE; }, "storageBuffer8BitAccess");
invalid([](auto& value) { value.extensions.pop_back(); }, "missing runtime extensions");
ProfileInput withoutBytes;
withoutBytes.capabilities.pop_back();
withoutBytes.extensions.pop_back();
withoutBytes.bda.pNext = &withoutBytes.indexing;
const AgcDriver::ShaderDeviceProfile wordAccess(withoutBytes.Target(), withoutBytes.device, withoutBytes.limits);
Require(std::ranges::find(wordAccess.Target().supportedCapabilities, spv::CapabilityStorageBuffer8BitAccess) == wordAccess.Target().supportedCapabilities.end(), "a device without storageBuffer8BitAccess was profiled with 8-bit storage");
ProfileInput withoutNull;
withoutNull.robustness.nullDescriptor = VK_FALSE;
Require(!AgcDriver::ShaderDeviceProfile(withoutNull.Target(), withoutNull.device, withoutNull.limits).NullDescriptors(), "a device without nullDescriptor was profiled with it");
Expand Down
Loading
Loading