Skip to content
Closed
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
8 changes: 8 additions & 0 deletions core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
endforeach()
# The driver draw test again with the draw key off: the draw cache then keys on the decoded vertex
# stage, which must include PA_CL_VS_OUT_CNTL.
add_test(NAME agc_driver_vertex_clip_cull_draw_no_key COMMAND agc_driver_vertex_clip_cull_draw_tests no-key)
set_tests_properties(agc_driver_vertex_clip_cull_draw_no_key PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1;APS5_NO_DRAW_KEY=1" SKIP_RETURN_CODE 77)
if(WIN32)
set_tests_properties(agc_driver_vertex_clip_cull_draw_no_key PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test(NAME agc_driver_pm4_failure COMMAND agc_driver_pm4_tests failure)
set_tests_properties(agc_driver_pm4_failure PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77)
if(WIN32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ DrawVerdict Driver::draw(QueueState& queue, std::span<const std::uint32_t> packe
if (program.binary.stage == Stage::Fragment || roles[i] == Role::GeometryBack) return;
decodeReads[i].clear();
vertexInfos[i] = Graphics::DecodeVertexStageInfo(program.binary.header, program.binary.headerAddress, program.userData, &decodeReads[i]);
if (vertexInfos[i]) vertexInfos[i]->paClVsOutCntl = readRegister(queue.context, 0x207) & (0xffffu | (1u << 21u) | (1u << 22u) | (1u << 23u));
};
if (!registerKey) {
for (std::size_t i = 0; i < programs.size(); ++i) decodeVertexInfo(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void Driver::lookupDraw(const Submission& submission, const std::shared_ptr<Vulk
mix(vertex.fetchAttribReg);
mix(vertex.fetchBufferReg);
mix(vertex.fetchEmbedded);
mix(vertex.paClVsOutCntl);
for (std::uint32_t r = 0; r < vertex.resourcesNum; ++r) {
for (const auto field : vertex.resources[r].fields) mix(field);
const auto& destination = vertex.resourcesDst[r];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::uint64_t Driver::drawRegisterKey(const QueueState& queue, const ShaderRegis
}

bool Driver::sameVertexInfo(const ShaderRecompiler::ShaderVertexStageInfo& a, const ShaderRecompiler::ShaderVertexStageInfo& b) {
if (a.resourcesNum != b.resourcesNum || a.fetchAttribReg != b.fetchAttribReg || a.fetchBufferReg != b.fetchBufferReg || a.fetchEmbedded != b.fetchEmbedded) return false;
if (a.resourcesNum != b.resourcesNum || a.fetchAttribReg != b.fetchAttribReg || a.fetchBufferReg != b.fetchBufferReg || a.fetchEmbedded != b.fetchEmbedded || a.paClVsOutCntl != b.paClVsOutCntl) return false;
for (std::uint32_t i = 0; i < a.resourcesNum && i < a.resources.size(); ++i) {
if (a.resources[i].fields != b.resources[i].fields) return false;
const auto& x = a.resourcesDst[i];
Expand Down
26 changes: 26 additions & 0 deletions core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ struct VulkanDevice::State {
bool fragmentShaderBarycentric = false;
bool geometryShader = false;
bool sampleRateShading = false;
bool shaderClipDistance = false;
bool shaderCullDistance = false;
bool shaderClock = false;
bool narrowSubgroupClock = false;
bool demoteToHelperInvocation = false;
// VK_EXT_descriptor_indexing with non-uniform image array indexing (bindless image tables in
// graphics stages, and compute workgroups wider than a wave).
bool descriptorIndexing = false;
Expand Down Expand Up @@ -778,6 +781,14 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
state->narrowSubgroupClock = NarrowSubgroupClock(driver.driverID, state->properties.deviceName);
APS5_LOG_OUT("Shader clock driver=%d narrowSubgroupClock=%d", static_cast<int>(driver.driverID), state->narrowSubgroupClock ? 1 : 0);
}
VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demoteFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT};
if (hasExtension(VK_EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION_EXTENSION_NAME)) {
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &demoteFeatures};
state->InstanceFunction<PFN_vkGetPhysicalDeviceFeatures2>("vkGetPhysicalDeviceFeatures2")(selected, &features);
state->demoteToHelperInvocation = demoteFeatures.shaderDemoteToHelperInvocation == VK_TRUE;
}
demoteFeatures = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT};
demoteFeatures.shaderDemoteToHelperInvocation = VK_TRUE;
std::vector<const char*> deviceExtensions;
if (window != nullptr) deviceExtensions.assign(presentationExtensions.begin(), presentationExtensions.end());
if (state->fragmentShaderBarycentric) {
Expand Down Expand Up @@ -819,6 +830,11 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
state->imageInt64Atomics = true;
state->spirvExtensions.push_back("SPV_EXT_shader_image_int64");
}
if (state->demoteToHelperInvocation) {
deviceExtensions.push_back(VK_EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION_EXTENSION_NAME);
state->capabilities.push_back(spv::CapabilityDemoteToHelperInvocation);
state->spirvExtensions.push_back("SPV_EXT_demote_to_helper_invocation");
}
deviceExtensions.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME);
state->capabilities.push_back(spv::CapabilitySignedZeroInfNanPreserve);
state->spirvExtensions.push_back("SPV_KHR_float_controls");
Expand Down Expand Up @@ -971,6 +987,9 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
state->sampleRateShading = enabled.sampleRateShading == VK_TRUE;
if (enabled.geometryShader) state->capabilities.push_back(spv::CapabilityGeometry);
enabled.shaderClipDistance = available.shaderClipDistance;
enabled.shaderCullDistance = available.shaderCullDistance;
state->shaderClipDistance = enabled.shaderClipDistance == VK_TRUE;
state->shaderCullDistance = enabled.shaderCullDistance == VK_TRUE;
if (enabled.shaderStorageImageWriteWithoutFormat) state->capabilities.push_back(spv::CapabilityStorageImageWriteWithoutFormat);
if (enabled.shaderStorageImageReadWithoutFormat) state->capabilities.push_back(spv::CapabilityStorageImageReadWithoutFormat);
// Bindless image tables index an image array with a wave-uniform runtime slot.
Expand Down Expand Up @@ -1040,6 +1059,10 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
imageAtomicInt64Features.pNext = byteFeatures.pNext;
byteFeatures.pNext = &imageAtomicInt64Features;
}
if (state->demoteToHelperInvocation) {
demoteFeatures.pNext = byteFeatures.pNext;
byteFeatures.pNext = &demoteFeatures;
}
VkPhysicalDeviceImageRobustnessFeaturesEXT imageRobustnessFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_ROBUSTNESS_FEATURES_EXT, nullptr, VK_TRUE};
if (imageRobustness) {
imageRobustnessFeatures.pNext = byteFeatures.pNext;
Expand Down Expand Up @@ -2509,6 +2532,9 @@ Graphics::Context VulkanDevice::buildContext() const {
context.imageInt64Atomics = state->imageInt64Atomics;
context.geometryShader = state->geometryShader;
context.sampleRateShading = state->sampleRateShading;
context.clipDistance = state->shaderClipDistance;
context.cullDistance = state->shaderCullDistance;
context.demoteToHelperInvocation = state->demoteToHelperInvocation;
context.primitiveListRestart = state->primitiveListRestart;
context.imageViewMinLod = state->imageViewMinLod;
context.pipelineExecutableInfo = state->pipelineExecutableInfo;
Expand Down
3 changes: 3 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ struct Context {
bool imageInt64Atomics = false;
bool geometryShader = false;
bool sampleRateShading = false;
bool clipDistance = false;
bool cullDistance = false;
bool demoteToHelperInvocation = false;
bool primitiveListRestart = false;
bool imageViewMinLod = false;
bool pipelineExecutableInfo = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void ValidateDepthBounds(const Context& context, const State& state);

void ValidateShaderPair(const ShaderRecompiler::RecompileResult& vertex, const ShaderRecompiler::RecompileResult& fragment);
// Returns the color attachment locations the pixel shader writes.
std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing = false, bool imageInt64Atomics = false, bool geometryShader = false, bool sampleRateShading = false);
std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing = false, bool imageInt64Atomics = false, bool geometryShader = false, bool sampleRateShading = false, bool clipDistance = false, bool cullDistance = false, bool demoteToHelperInvocation = false);

}

Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct State {
VkFrontFace frontFace;
VkPipelineColorBlendAttachmentState blend;
std::array<float, 4> blendConstants;
std::uint32_t paClVsOutCntl = 0;
};

ShaderStages DecodeShaderStages(const QueueState& queue);
Expand Down
5 changes: 4 additions & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ bool ValidationKey(const Context& context, std::span<const CompiledShader> shade
add(context.subgroup.supportedStages);
add(context.subgroup.supportedOperations);
add(context.fragmentShaderBarycentric);
add(context.clipDistance);
add(context.cullDistance);
add(state.paClVsOutCntl);
add(state.stages.mesh.has_value());
if (state.stages.mesh) {
const auto& mesh = *state.stages.mesh;
Expand Down Expand Up @@ -545,7 +548,7 @@ std::set<std::uint32_t> CachedFragmentOutputs(const Context& context, std::span<
}
std::set<std::uint32_t> outputs;
try {
outputs = ValidateShaders(shaders, state, context.subgroup, context.fragmentShaderBarycentric, context.descriptorIndexing, context.imageInt64Atomics, context.geometryShader, context.sampleRateShading);
outputs = ValidateShaders(shaders, state, context.subgroup, context.fragmentShaderBarycentric, context.descriptorIndexing, context.imageInt64Atomics, context.geometryShader, context.sampleRateShading, context.clipDistance, context.cullDistance, context.demoteToHelperInvocation);
} catch (const std::exception& error) {
if (keyed) {
std::lock_guard lock(validationMutex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ ShaderRecompiler::ShaderPixelStageInfo DecodePixelStageInfo(const Registers& con
const bool depthExportEnable = (shaderControl & 0x1u) != 0;
const bool sampleMaskExportEnable = ((shaderControl >> 8u) & 0x1u) != 0;
const auto zOrder = (shaderControl >> 4u) & 0x3u;
const auto aaMask = read(context, 0x30e, RegisterBank::Context);
const auto aaMaskBottom = read(context, 0x30f, RegisterBank::Context);
const auto quadPixelMask = static_cast<std::uint8_t>((aaMask & 1u) | (((aaMask >> 16u) & 1u) << 1u) | ((aaMaskBottom & 1u) << 2u) | (((aaMaskBottom >> 16u) & 1u) << 3u));
const auto loaded = [&](PixelInput input) { return (activeInputs & PixelInputBit(input)) != 0; };
return ShaderRecompiler::ShaderPixelStageInfo{
.interpolatorCount = inputNum,
Expand All @@ -157,7 +160,8 @@ ShaderRecompiler::ShaderPixelStageInfo DecodePixelStageInfo(const Registers& con
.conservativeZExport = static_cast<ShaderRecompiler::ConservativeZExport>(conservativeZExport),
.orderedPixelShader = ((shaderControl >> 16u) & 0x1u) != 0,
.targetOutputMode = targetOutputMode,
.targetExportMapping = exportMappings
.targetExportMapping = exportMappings,
.quadPixelMask = quadPixelMask
};
}

Expand Down
24 changes: 19 additions & 5 deletions core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "prx/libSceAgcDriver/Graphics/include/VertexInput.hpp"
#include <spirv/unified1/spirv.hpp>
#include <algorithm>
#include <cstdio>
#include <map>
#include <optional>
#include <set>
Expand Down Expand Up @@ -120,6 +121,10 @@ struct Module {
if (vertex && storage == spv::StorageClassInput) {
Require((value == spv::BuiltInVertexIndex || value == spv::BuiltInInstanceIndex) && signature == "i32", "unsupported vertex built-in input");
} else if (vertex && storage == spv::StorageClassOutput) {
if (value == spv::BuiltInClipDistance || value == spv::BuiltInCullDistance) {
Require(signature.starts_with("f32[") && signature.size() == 6 && signature[4] >= '1' && signature[4] <= '8', "unsupported vertex clip or cull distance output");
return;
}
Require(value == spv::BuiltInPosition && signature == "f32x4" && !position, "unsupported or duplicate vertex built-in output");
position = true;
} else {
Expand All @@ -128,7 +133,7 @@ struct Module {
}
};

Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing, bool imageInt64Atomics, bool geometryShader, bool sampleRateShading) {
Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing, bool imageInt64Atomics, bool geometryShader, bool sampleRateShading, bool clipDistance, bool cullDistance, bool demoteToHelperInvocation) {
using Stage = ShaderRecompiler::ShaderStage;
Require(compiled.program != nullptr, "missing compiled shader");
const auto& shader = *compiled.program;
Expand Down Expand Up @@ -212,6 +217,13 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi
fragment &&
capability == spv::CapabilityFragmentShaderPixelInterlockEXT;

const bool isDistanceCapability = vertex && (capability == spv::CapabilityClipDistance || capability == spv::CapabilityCullDistance);
if (isDistanceCapability) {
char word[16];
std::snprintf(word, sizeof(word), "0x%08x", state.paClVsOutCntl);
Require(capability == spv::CapabilityClipDistance ? clipDistance : cullDistance, std::string("vertex clip or cull distance needs shaderClipDistance or shaderCullDistance, which the device lacks (PA_CL_VS_OUT_CNTL=") + word + ")");
}

// Enabled unconditionally or by the device setup in VulkanDevice.
const bool isFeatureCapability =
capability == spv::CapabilitySampled1D ||
Expand All @@ -220,6 +232,7 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi
capability == spv::CapabilityImageQuery ||
(fragment && geometryShader && capability == spv::CapabilityGeometry) ||
(fragment && sampleRateShading && capability == spv::CapabilitySampleRateShading) ||
isDistanceCapability ||
capability == spv::CapabilityStorageImageWriteWithoutFormat ||
capability == spv::CapabilityStorageImageReadWithoutFormat ||
capability == spv::CapabilityInt64 ||
Expand All @@ -229,7 +242,8 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi
capability == spv::CapabilityStorageBuffer8BitAccess ||
capability == spv::CapabilityPhysicalStorageBufferAddresses ||
capability == spv::CapabilitySampledImageArrayDynamicIndexing ||
capability == spv::CapabilityStorageImageArrayDynamicIndexing;
capability == spv::CapabilityStorageImageArrayDynamicIndexing ||
(fragment && demoteToHelperInvocation && capability == spv::CapabilityDemoteToHelperInvocation);

// Bindless image tables index their slots non-uniformly in graphics stages
// (VK_EXT_descriptor_indexing, enabled by the device setup when available).
Expand Down Expand Up @@ -270,7 +284,7 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi
Require(fragment && fragmentShaderBarycentric, "SPV_KHR_fragment_shader_barycentric requires enabled fragmentShaderBarycentric in a fragment shader");
break;
}
Require(extension == "SPV_KHR_float_controls" || (imageInt64Atomics && extension == "SPV_EXT_shader_image_int64") || (mesh && (extension == "SPV_EXT_mesh_shader" || extension == "SPV_KHR_physical_storage_buffer")) || (descriptorIndexing && extension == "SPV_EXT_descriptor_indexing") || (shader.bdaAbiVersion == ShaderRecompiler::BdaAbi::Version && (extension == "SPV_KHR_physical_storage_buffer" || extension == "SPV_KHR_8bit_storage")), "unsupported SPIR-V extension");
Require(extension == "SPV_KHR_float_controls" || (imageInt64Atomics && extension == "SPV_EXT_shader_image_int64") || (mesh && (extension == "SPV_EXT_mesh_shader" || extension == "SPV_KHR_physical_storage_buffer")) || (descriptorIndexing && extension == "SPV_EXT_descriptor_indexing") || (fragment && demoteToHelperInvocation && extension == "SPV_EXT_demote_to_helper_invocation") || (shader.bdaAbiVersion == ShaderRecompiler::BdaAbi::Version && (extension == "SPV_KHR_physical_storage_buffer" || extension == "SPV_KHR_8bit_storage")), "unsupported SPIR-V extension");
break;
}
case spv::OpDecorateId:
Expand Down Expand Up @@ -509,7 +523,7 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi

}

std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing, bool imageInt64Atomics, bool geometryShader, bool sampleRateShading) {
std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders, const State& state, const VkPhysicalDeviceSubgroupProperties& subgroup, bool fragmentShaderBarycentric, bool descriptorIndexing, bool imageInt64Atomics, bool geometryShader, bool sampleRateShading, bool clipDistance, bool cullDistance, bool demoteToHelperInvocation) {
using Stage = ShaderRecompiler::ShaderStage;
const bool tessellation = state.stages.path == ShaderPath::Tessellation;
const bool mesh = state.stages.path == ShaderPath::Geometry;
Expand All @@ -525,7 +539,7 @@ std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders,
Require(shaders[i].program != nullptr, "missing compiled shader");
Require(shaders[i].stage == expected, "graphics stage order disagrees");
for (const auto& binding : shaders[i].program->bindings) Require(binding.descriptorSet == 0, "graphics resource uses a descriptor set other than zero");
const auto current = Inspect(shaders[i], state, subgroup, fragmentShaderBarycentric, descriptorIndexing, imageInt64Atomics, geometryShader, sampleRateShading);
const auto current = Inspect(shaders[i], state, subgroup, fragmentShaderBarycentric, descriptorIndexing, imageInt64Atomics, geometryShader, sampleRateShading, clipDistance, cullDistance, demoteToHelperInvocation);
if (i != 0) {
for (const auto& [location, signature] : current.inputs) {
const auto output = previous.outputs.find(location);
Expand Down
Loading
Loading