diff --git a/core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp b/core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp index c94e40eb5..ea07b09d4 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp +++ b/core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp @@ -154,6 +154,7 @@ public: void* Window() const; void Resize(std::uint32_t width, std::uint32_t height); bool Presentable() const; + bool PrimitiveListRestart() const; // A presentation is a few steps so the presenter holds GuestMemory::GpuMutex only while it // touches the queue. Presentations are slots (FlipInFlight() + 1, each with its own command // buffer, fence, kept resident image and dump buffer): RetirePresents(keep) (no mutex) retires diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp index df87df2d3..68ae97386 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp @@ -3866,8 +3866,21 @@ private: if (drawParameters.indexed) { const auto restart = queue.userConfig.find(0x24b); if (restart != queue.userConfig.end() && restart->second != 0) { - rejected = "AGC graphics: primitive restart (GE_MULTI_PRIM_IB_RESET_EN) is unsupported for indexed draws"; - return DrawVerdict::Rejected; + const auto resetIndex = queue.context.find(0x103); + const auto primitive = queue.userConfig.find(0x242); + const std::uint32_t allOnes = drawParameters.indexSize == 2 ? 0xffffu : 0xffffffffu; + const auto type = primitive == queue.userConfig.end() ? 0u : primitive->second & 0x3fu; + const bool strip = type == 3 || type == 5 || type == 6; + const bool list = type == 1 || type == 2 || type == 4; + const auto restartDevice = device.load(); + if (!strip && !(list && restartDevice != nullptr && restartDevice->PrimitiveListRestart())) { + rejected = "AGC graphics: primitive restart is only supported for strips, and for lists with VK_EXT_primitive_topology_list_restart"; + return DrawVerdict::Rejected; + } + if (resetIndex == queue.context.end() || (resetIndex->second & allOnes) != allOnes) { + rejected = "AGC graphics: primitive restart index other than all ones is unsupported"; + return DrawVerdict::Rejected; + } } } if (DrawPrecheck()) { diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp index 83bd0b373..d4df7ef97 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp @@ -185,6 +185,7 @@ struct VulkanDevice::State { // 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; + bool primitiveListRestart = false; bool depthClipControl = false; bool depthClamp = false; VkDeviceSize hostImportAlignment = 0; @@ -728,6 +729,15 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u #endif deviceExtensions.push_back(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME); } + VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT listRestartFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT}; + if (hasExtension(VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME)) { + VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &listRestartFeatures}; + state->InstanceFunction("vkGetPhysicalDeviceFeatures2")(selected, &features); + state->primitiveListRestart = listRestartFeatures.primitiveTopologyListRestart == VK_TRUE; + if (state->primitiveListRestart) deviceExtensions.push_back(VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME); + } + listRestartFeatures = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT}; + listRestartFeatures.primitiveTopologyListRestart = state->primitiveListRestart ? VK_TRUE : VK_FALSE; VkPhysicalDeviceDepthClipControlFeaturesEXT depthClipFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT}; if (hasExtension(VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME)) { VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &depthClipFeatures}; @@ -815,6 +825,10 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u depthClipFeatures.pNext = const_cast(deviceInfo.pNext); deviceInfo.pNext = &depthClipFeatures; } + if (state->primitiveListRestart) { + listRestartFeatures.pNext = const_cast(deviceInfo.pNext); + deviceInfo.pNext = &listRestartFeatures; + } byteFeatures.pNext = const_cast(deviceInfo.pNext); if (state->fragmentShaderBarycentric) { barycentricFeatures.pNext = byteFeatures.pNext; @@ -2108,6 +2122,10 @@ ShaderRecompiler::SpirvTarget VulkanDevice::Target() const { return target; } +bool VulkanDevice::PrimitiveListRestart() const { + return state->primitiveListRestart; +} + Graphics::Context VulkanDevice::graphicsContext() const { static const bool noCache = std::getenv("APS5_NO_CONTEXT_CACHE") != nullptr; if (state->contextReady && !noCache) return state->context; @@ -2152,6 +2170,7 @@ Graphics::Context VulkanDevice::buildContext() const { context.copiedWriters = state->copiedWriters.get(); context.functions = state->functionsReady ? &state->deviceFunctions : nullptr; context.descriptorIndexing = state->descriptorIndexing; + context.primitiveListRestart = state->primitiveListRestart; return context; } diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp index db6ae2af5..1160a8f35 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp @@ -125,6 +125,7 @@ struct Context { // VK_EXT_descriptor_indexing with non-uniform sampled/storage image array indexing enabled // (bindless image tables in graphics stages). bool descriptorIndexing = false; + bool primitiveListRestart = false; template TFunction Function(const char* name) const { diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp index fd90957c3..754842cef 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/include/State.hpp @@ -52,6 +52,7 @@ struct State { bool rectList = false; VkExtent2D renderExtent; VkPrimitiveTopology topology; + bool primitiveRestart = false; VkViewport viewport; bool negativeOneToOne; bool depthClamp = false; diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp index af75014dd..f2b467fef 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp @@ -118,6 +118,8 @@ Pipeline::Pipeline(const Context& context, const State& state, const VertexInput input.pVertexAttributeDescriptions = vertexInput.attributes.data(); VkPipelineInputAssemblyStateCreateInfo assembly{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO}; assembly.topology = state.topology; + const bool listTopology = state.topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST || state.topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || state.topology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + assembly.primitiveRestartEnable = state.primitiveRestart && (!listTopology || context.primitiveListRestart) ? VK_TRUE : VK_FALSE; // Viewport and scissor are set per draw (Begin), so they do not multiply pipelines; the depth // clip control stays baked in. VkPipelineViewportStateCreateInfo viewports{VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO}; @@ -313,6 +315,7 @@ std::vector pipelineKey(const Context& context, const State& state, c append(key, state.hasColorTarget); append(key, state.rectList); append(key, state.topology); + append(key, state.primitiveRestart); append(key, state.cullMode); append(key, state.frontFace); append(key, state.negativeOneToOne); diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp index dcc5a608e..1dee0ffe4 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp @@ -293,7 +293,7 @@ State DecodeState(const QueueState& queue) { default: throw std::runtime_error("AGC graphics: unsupported primitive type " + std::to_string(primitive)); } APS5_LOG_OUT_DEBUG("Topology=%u", static_cast(result.topology)); - (void)read(queue.userConfig, 0x24b, RegisterBank::UserConfig); + result.primitiveRestart = read(queue.userConfig, 0x24b, RegisterBank::UserConfig) != 0 && !result.rectList && result.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; if ((read(cx, 0x207) & LayerExports) != 0) { static bool reported = false; if (!reported) { @@ -514,7 +514,12 @@ std::string DrawRejection(const QueueState& queue, bool indexed) { const auto require = [&](bool condition, const char* reason) { return condition ? std::string() : "AGC graphics: " + std::string(reason); }; - if (auto reason = indexed ? nonzero(queue.userConfig, 0x24b, ~0u, "primitive restart (GE_MULTI_PRIM_IB_RESET_EN)") : std::string(); !reason.empty()) return reason; + if (indexed && value(queue.userConfig, 0x24b, word) && word != 0) { + std::uint32_t primitive = 0; + std::uint32_t resetIndex = 0; + if (value(queue.userConfig, 0x242, primitive) && (primitive & 0x3fu) != 1 && (primitive & 0x3fu) != 2 && (primitive & 0x3fu) != 3 && (primitive & 0x3fu) != 4 && (primitive & 0x3fu) != 5 && (primitive & 0x3fu) != 6) return "AGC graphics: primitive restart is only supported for point, line and triangle topologies"; + if (value(cx, 0x103, resetIndex) && (resetIndex & 0xffffu) != 0xffffu) return "AGC graphics: primitive restart index other than all ones is unsupported"; + } if (auto reason = nonzero(cx, 0x207, ~LayerExports, "clip distances, layer, viewport or auxiliary vertex exports"); !reason.empty()) return reason; if (value(cx, 0x200, word)) { if (!depthPassThrough(word) && !IgnoreDepthTest() && (word & DepthControlMask) != 0) return zeroMessage(0x200, word, "depth, stencil or conditional color writes"); diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index dacf921c2..0337c1019 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -89,7 +89,14 @@ void stateTests() { queue.context[0x1b4] = 2; (void)AgcDriver::Graphics::DecodeState(queue); Require(AgcDriver::Graphics::DrawRejection(queue, false).empty(), "primitive restart rejected a non-indexed draw"); - Require(AgcDriver::Graphics::DrawRejection(queue, true).find("GE_MULTI_PRIM_IB_RESET_EN") != std::string::npos, "primitive restart was accepted for an indexed draw"); + queue.userConfig[0x242] = 9; + Require(AgcDriver::Graphics::DrawRejection(queue, true).find("point, line and triangle") != std::string::npos, "primitive restart was accepted for patches"); + queue.userConfig[0x242] = 6; + queue.context[0x103] = 0xffffffffu; + Require(AgcDriver::Graphics::DrawRejection(queue, true).empty(), "primitive restart was rejected for an indexed strip"); + Require(AgcDriver::Graphics::DecodeState(queue).primitiveRestart, "primitive restart was not decoded for a strip"); + queue.context[0x103] = 5; + Require(AgcDriver::Graphics::DrawRejection(queue, true).find("all ones") != std::string::npos, "a restart index other than all ones was accepted"); queue = makeState(); queue.userConfig.erase(0x24b); queue.context[0x2a5] = 0;