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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class VulkanDevice {
Graphics::SampleOrder HostSampleOrder(const Graphics::State& graphics) const;
std::optional<ShaderRecompiler::GeometryStageLimits> GeometryLimits() const;
std::uint32_t MaxFragmentInputComponents() const;
std::uint32_t MaxMeshOutputLayers() const;
const std::uint32_t* WorkGroupCountLimit() const;
std::uint64_t StorageBufferRangeLimit() const;
std::uint64_t DeviceLocalBytes() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp"
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
#include "Optimization/ResourceProgram.hpp"
#include <algorithm>
#include <chrono>
Expand Down Expand Up @@ -179,6 +180,12 @@ std::shared_ptr<const ShaderRecompiler::RecompileResult> Driver::materializeDraw
{0, 0, pushOffset, pushBytes},
ShaderRecompiler::GraphicsCompileContext{program.firstUserSgpr, linked, Graphics::StageMeshConfiguration(graphics.stages, program.binary.stage), graphics.stages.tessellation, {drawParameters.indexAddress, drawParameters.indexCount, drawParameters.indexSize, drawParameters.instanceCount}, program.binary.stage == Stage::Mesh ? meshBarycentrics : std::nullopt, emulateBarycentrics && program.binary.stage == Stage::Fragment}
};
const bool meshShader = request.target.mesh.has_value();
const bool forceMeshCompute = meshShader && request.target.meshAsCompute;
if (program.binary.stage == Stage::Mesh && Graphics::MeshDrawRunsAsCompute(meshShader, forceMeshCompute, graphics)) {
request.target.meshAsCompute = true;
request.target.meshWindowBuffer = false;
}
const auto waitedBefore = traceCapSync() || profile ? Graphics::Recorder::ThreadWaitedMs() : 0.0;
auto invocation = [&] {
try {
Expand Down
12 changes: 10 additions & 2 deletions core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window, bool compileOnly) :
if (meshAvailable) {
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &meshFeatures};
state->InstanceFunction<PFN_vkGetPhysicalDeviceFeatures2>("vkGetPhysicalDeviceFeatures2")(selected, &features);
state->meshShader = meshFeatures.meshShader == VK_TRUE;
state->meshShader = meshFeatures.meshShader == VK_TRUE && std::getenv("APS5_NO_MESH_SHADER") == nullptr;
VkPhysicalDeviceProperties2 meshProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &state->meshLimits};
state->InstanceFunction<PFN_vkGetPhysicalDeviceProperties2>("vkGetPhysicalDeviceProperties2")(selected, &meshProperties);
}
Expand Down Expand Up @@ -4929,7 +4929,9 @@ ShaderRecompiler::SpirvTarget VulkanDevice::buildTarget() const {
target.deviceScopeLdsMemoryBarriers = !state->workgroupScopeFences;
target.ldsLockFences = state->ldsLockFences;
target.deviceAtomicWorkgroupMemoryBarriers = state->deviceAtomicWorkgroupMemoryBarriers;
target.meshWindowBuffer = state->driverId == VK_DRIVER_ID_NVIDIA_PROPRIETARY && std::getenv("APS5_NO_MESH_WINDOW_BUFFER") == nullptr;
static const bool forceMeshCompute = std::getenv("APS5_FORCE_MESH_COMPUTE") != nullptr;
target.meshAsCompute = !state->meshShader || forceMeshCompute;
target.meshWindowBuffer = state->driverId == VK_DRIVER_ID_NVIDIA_PROPRIETARY && std::getenv("APS5_NO_MESH_WINDOW_BUFFER") == nullptr && !target.meshAsCompute;
target.meshInlineFunctions = state->driverId == VK_DRIVER_ID_NVIDIA_PROPRIETARY && std::getenv("APS5_NO_MESH_INLINE_FUNCTIONS") == nullptr;
target.spannedShuffleThroughMemory = state->driverId == VK_DRIVER_ID_NVIDIA_PROPRIETARY && std::getenv("APS5_NO_SPANNED_SHUFFLE_EXCHANGE") == nullptr;
target.srgbDecodeFormats = state->srgbDecodeFormats & ~state->srgbCopyFormats;
Expand All @@ -4950,6 +4952,10 @@ std::optional<ShaderRecompiler::GeometryStageLimits> VulkanDevice::GeometryLimit
return ShaderRecompiler::GeometryStageLimits{limits.maxGeometryInputComponents, limits.maxGeometryOutputComponents, limits.maxGeometryOutputVertices, limits.maxGeometryTotalOutputComponents, limits.maxFragmentInputComponents};
}

std::uint32_t VulkanDevice::MaxMeshOutputLayers() const {
return state->meshShader ? state->meshLimits.maxMeshOutputLayers : 0u;
}

std::uint32_t VulkanDevice::MaxFragmentInputComponents() const {
return state->properties.limits.maxFragmentInputComponents;
}
Expand Down Expand Up @@ -5067,6 +5073,8 @@ Graphics::Context VulkanDevice::buildContext() const {
context.mixedAttachmentSamples = state->mixedAttachmentSamples;
context.conservativeRasterization = state->conservativeRasterization;
context.meshWave32 = state->meshWave32;
context.computeWave32 = state->computeWave32;
context.maxComputeSubgroupSize = state->maxComputeSubgroupSize;
context.provokingVertexLast = state->provokingVertexLast;
context.graphicsPipelineLibrary = state->graphicsPipelineLibrary;
context.pipelineLinkTimeOptimization = state->pipelineLinkTimeOptimization;
Expand Down
2 changes: 2 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ struct Context {
bool mixedAttachmentSamples = false;
bool conservativeRasterization = false;
bool meshWave32 = false;
bool computeWave32 = false;
std::uint32_t maxComputeSubgroupSize = 0;
VkBuffer emptyBuffer = VK_NULL_HANDLE;
VkBuffer oversizedBuffer = VK_NULL_HANDLE;
bool exactRobustLoads = false;
Expand Down
11 changes: 10 additions & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/include/Draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ InPlaceIndices InPlaceIndexRange(Recorder& recorder, std::uint64_t address, std:

std::array<std::uint32_t, 4> MeshIndexBufferDescriptor(const Pm4::DrawParameters& draw);

inline constexpr std::uint64_t MeshComputeOutputLimitBytes = 256ull << 20u;
bool MeshDrawRunsAsCompute(bool meshShader, bool forceMeshCompute, const State& state);
bool MeshDrawRunsAsCompute(const Context& context, const State& state);
std::vector<CompiledShader> MeshComputeStages(const Context& context, const State& state, std::span<const CompiledShader> shaders);

struct MeshArguments {
std::uint32_t groups;
std::uint32_t instances;
Expand All @@ -108,13 +113,17 @@ struct MeshArgumentRules {
};
MeshArgumentRules MeshArgumentRulesFor(const Context& context, const ShaderRecompiler::MeshConfiguration& mesh, std::uint32_t indexCount);
MeshArgumentRules MeshArgumentRulesFor(const Context& context, const ShaderRecompiler::MeshConfiguration& mesh, const Pm4::DrawParameters& draw);
MeshArgumentRules MeshArgumentRulesFor(const Context& context, const ShaderRecompiler::MeshConfiguration& mesh, const Pm4::DrawParameters& draw, bool asCompute);
MeshArgumentRules MeshArgumentRulesFor(const Context& context, const ShaderRecompiler::MeshConfiguration& mesh, std::uint32_t indexCount, bool asCompute);
struct MeshGrid {
std::uint32_t groups;
std::uint32_t instances;
std::uint32_t layers;
std::uint32_t layerStride;
};
std::optional<MeshGrid> MeshGridFor(const Context& context, std::uint32_t groups, std::uint32_t instances);
std::optional<MeshGrid> MeshComputeGridFor(const Context& context, std::uint32_t groups, std::uint32_t instances);
MeshArgumentRules MeshArgumentRulesFor(const Context& context, const ShaderRecompiler::MeshConfiguration& mesh, const Pm4::DrawParameters& draw, bool asCompute);
MeshArguments ResolveMeshArguments(const Pm4::DrawArguments& record, const MeshArgumentRules& rules);

// Why DrawWithRecipe did not record from the recipe (the caller then runs Draw): the draw is not
Expand Down Expand Up @@ -148,7 +157,7 @@ bool DrawRecipes();
// draw index, the vertex ranges, the device features, APS5_NO_GPU_INDIRECT_DRAW) or under the device
// lock in Draw (the memory state of the records). `readMs` is the CPU read's time (its sync);
// `rewritten` counts a GPU-side draw whose records were copied and patched with a constant.
enum class IndirectDrawPath : std::uint8_t { Gpu, NotFolded, FetchUnknown, NonVertexPath, IndxOffset, DrawIndex, VertexRange, FeatureGap, PendingImage, PendingLabelOrCopy, NotImported, Disabled, IndexRange, IndexLimitUnknown, Settled, Count };
enum class IndirectDrawPath : std::uint8_t { Gpu, NotFolded, FetchUnknown, NonVertexPath, IndxOffset, DrawIndex, VertexRange, FeatureGap, PendingImage, PendingLabelOrCopy, NotImported, Disabled, IndexRange, IndexLimitUnknown, MeshCompute, Settled, Count };
void CountIndirectDraw(IndirectDrawPath path, double readMs, bool rewritten = false);
std::array<std::uint64_t, static_cast<std::size_t>(IndirectDrawPath::Count)> IndirectDrawCounts();
void CountEmptyIndirectDraw(double readMs);
Expand Down
5 changes: 5 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Pipeline {
bool Optimized() const { return optimized != nullptr && optimized->handle.load() != VK_NULL_HANDLE; }
void ContinueBackFaces(CommandState& recording, const State& state, const State* masked = nullptr) const;
bool SplitsSecondChannel() const { return secondChannel != VK_NULL_HANDLE; }
VkPipeline MeshCompute() const { return meshCompute; }
VkPipelineLayout MeshComputeLayout() const { return meshComputeLayout; }
void PushMeshCompute(VkCommandBuffer commands, std::span<const std::byte, PipelinePushConstantBytes> bytes) const;
void ContinueSecondChannel(CommandState& recording, const State& state, const State* masked = nullptr) const;
bool MasksStencilReplayPasses(const State& state) const;
void SetStencilReplayMasks(CommandState& recording, const State& state, const State* masked, bool colorAndDepth, std::uint32_t stencilBits) const;
Expand Down Expand Up @@ -92,6 +95,8 @@ class Pipeline {
VkPipeline pipeline = VK_NULL_HANDLE;
VkPipeline backFaces = VK_NULL_HANDLE;
VkPipeline secondChannel = VK_NULL_HANDLE;
VkPipeline meshCompute = VK_NULL_HANDLE;
VkPipelineLayout meshComputeLayout = VK_NULL_HANDLE;
std::size_t attachments = 0;
std::size_t colorAttachments = 0;
std::vector<bool> boundAttachments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class Recorder {
void Sync();
void CountSamples();
bool CountingSamples() const { return countingSamples; }
bool RecordMeshArguments(VkCommandBuffer commands, VkDeviceAddress record, VkDeviceAddress arguments, std::span<const std::uint32_t, 8> rules);
bool RecordMeshArguments(VkCommandBuffer commands, VkDeviceAddress record, VkDeviceAddress arguments, std::span<const std::uint32_t, 8> rules, bool compute);
bool RecordChangedCopy(VkCommandBuffer commands, VkDeviceAddress result, VkDeviceAddress snapshot, VkDeviceAddress target, std::uint32_t dwords, VkDeviceAddress counter = 0);
struct BoundWords {
VkBuffer buffer = VK_NULL_HANDLE;
Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Shaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ inline VkPipelineStageFlags PipelineStages(std::span<const CompiledShader> shade
case VK_SHADER_STAGE_GEOMETRY_BIT: result |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT; break;
case VK_SHADER_STAGE_MESH_BIT_EXT: result |= VK_PIPELINE_STAGE_MESH_SHADER_BIT_EXT; break;
case VK_SHADER_STAGE_FRAGMENT_BIT: result |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; break;
case VK_SHADER_STAGE_COMPUTE_BIT: result |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; break;
default: throw std::runtime_error("AGC graphics: invalid graphics pipeline stage");
}
}
Expand Down
Loading
Loading