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
11 changes: 11 additions & 0 deletions core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4830,6 +4830,17 @@ std::shared_ptr<ComputePipelineObjects> VulkanDevice::computePipeline(const Grap

VulkanDevice::IndirectOutcome VulkanDevice::dispatch(const ShaderRecompiler::RecompileResult& shader, std::uint32_t x, std::uint32_t y, std::uint32_t z, std::uint64_t arguments, std::span<const Graphics::GuestMemorySnapshot> snapshots, std::uint64_t programAddress, std::shared_ptr<PreparedDispatch> prepared, std::shared_ptr<const Recipe>* recipeOut) {
startJournalReplay();
for (const auto& binding : shader.bindings) {
if (binding.role != ShaderRecompiler::DescriptorRole::GuestBuffers) continue;
for (std::size_t at = 0; at + 4u <= binding.guestDescriptor.size(); at += 4u) {
const auto* words = binding.guestDescriptor.data() + at;
const auto base = static_cast<std::uint64_t>(words[0]) | (static_cast<std::uint64_t>(words[1] & 0xffffu) << 32u);
const auto stride = (words[1] >> 16u) & 0x3fffu;
const auto records = static_cast<std::uint64_t>(words[2]);
const auto bytes = stride != 0 ? records * stride : records;
if (base != 0 && bytes != 0) static_cast<void>(Graphics::FlushDepthPlanes(base, static_cast<std::size_t>(bytes)));
}
}
state->recorder->BoundKeptBytes();
ShaderRecompiler::RuntimeAbi::RequireVersion(shader.runtimeAbiVersion);
PerformanceTimer timing("Vulkan.Dispatch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#include <optional>
#include <span>
#include <utility>
#include <vector>

namespace AgcDriver::Graphics {

class Texture;
class StorageTexture;

VkImageView DepthSurfaceView(const Context& context, const DepthTarget& target);
VkImageView DepthSurfaceView(const Context& context, const DepthTarget& target, bool depthWritten = true);
std::vector<std::pair<std::uint64_t, std::uint64_t>> FlushDepthPlanes(std::uint64_t address, std::size_t bytes);
bool DepthPlanesStale();
bool SampleLocationsCompatibleDepth(const Context& context, VkFormat format, std::uint32_t samples);
std::uint64_t DepthSurfacesSerial();
std::uint64_t DepthSurfacesReleased();
Expand Down
216 changes: 201 additions & 15 deletions core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,7 @@ void Draw(const Context& context, const State& state, const Pm4::DrawParameters&
}
APS5_LOG_OUT_DEBUG("Creating color target %zu address=0x%llx bytes=%llu extent=%ux%u", index, static_cast<unsigned long long>(color.address), static_cast<unsigned long long>(color.bytes), color.extent.width, color.extent.height);
const ColorTargetLayout colorLayout(color.extent.width, color.extent.height, color.tileMode, color.elementBytes);
static_cast<void>(FlushDepthPlanes(color.address, colorLayout.Bytes()));
RetireDepthSurfaces(context.device, color.address, colorLayout.Bytes());
constexpr VkBufferUsageFlags copies = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
timer.phase(PhaseSetup);
Expand Down Expand Up @@ -2156,7 +2157,7 @@ void Draw(const Context& context, const State& state, const Pm4::DrawParameters&
binding.target = std::make_unique<RenderTarget>(context, color, state.blends.at(color.exportIndex).blendEnable != 0);
targetViews.push_back(binding.target->View());
}
if (state.depth) targetViews.push_back(DepthSurfaceView(context, *state.depth));
if (state.depth) targetViews.push_back(DepthSurfaceView(context, *state.depth, state.depthWrite));
timer.phase(PhasePrepare);
const bool recordDraws = RecordDraws();
auto* recorder = Recorder::Active();
Expand Down Expand Up @@ -2711,7 +2712,7 @@ DrawRecipeOutcome DrawWithRecipe(const Context& context, const State& state, con
}
if (recipe.hasDepth) {
timer.phase(PhaseSetup);
const auto depthView = DepthSurfaceView(context, *state.depth);
const auto depthView = DepthSurfaceView(context, *state.depth, state.depthWrite);
timer.phase(PhaseReadTarget);
if (recipe.targetViews.back() != depthView) return miss(DrawRecipeMiss::TargetGone);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
#include "prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp"
#include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp"
#include "ThreadOwned.hpp"
#include "prx/libSceAgcDriver/Graphics/include/BdaResources.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Texture.hpp"
Expand Down Expand Up @@ -4045,6 +4046,7 @@ void GuestBufferMemory::UploadFinish(bool addressable) {
for (const auto& region : regions) CompletePendingCpuWrites(context, region.begin, static_cast<std::size_t>(region.end - region.begin));
if (space != nullptr) completeSpaceWrites();
uploaded = true;
for (const auto& region : regions) static_cast<void>(FlushDepthPlanes(region.begin, static_cast<std::size_t>(region.end - region.begin)));
for (const auto& [begin, end] : writes) StorageTexture::FlushPending(begin, static_cast<std::size_t>(end - begin), nullptr, "written buffer range");
if (context.hostImportAlignment != 0) {
auto& state = Imports();
Expand Down
20 changes: 15 additions & 5 deletions core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ std::shared_ptr<Texture> cachedTexture(const Context& context, std::span<const s
auto& counters = TextureCounts();
const auto address = resource.baseAddress;
const auto bytes = static_cast<std::size_t>(guestBytes);
static_cast<void>(FlushDepthPlanes(address, bytes));
// A storage image whose results for this surface (or for a mip chain containing it) are still on
// the GPU supplies the texture by a view of it; anything else needs those results in guest
// memory first.
Expand Down Expand Up @@ -1029,9 +1030,13 @@ std::shared_ptr<StorageTexture> cachedStorageTexture(const Context& context, std
Require(viewed.dimension != TextureDimension::k2DMsaa, "storage image access to a multisampled texture is not implemented");
RequireNoMultisampleTarget(viewed.baseAddress, guestBytes != 0 ? static_cast<std::size_t>(guestBytes) : 1u, "a storage image access");
if (auto depth = DepthSurfaceStorage(context, words, viewed, mip)) return depth;
if (written && DepthSurfaceOverlaps(context.device, viewed.baseAddress, guestBytes != 0 ? guestBytes : DescribeSurface(viewed).guestBytes)) {
const auto storage = WrittenStorageBytes(viewed, mip);
RetireCoveredDepthSurfaces(context.device, storage.bytes, storage.extents);
if (DepthPlanesStale() || written) {
const auto viewedBytes = guestBytes != 0 ? guestBytes : DescribeSurface(viewed).guestBytes;
static_cast<void>(FlushDepthPlanes(viewed.baseAddress, static_cast<std::size_t>(viewedBytes)));
if (written && DepthSurfaceOverlaps(context.device, viewed.baseAddress, viewedBytes)) {
const auto storage = WrittenStorageBytes(viewed, mip);
RetireCoveredDepthSurfaces(context.device, storage.bytes, storage.extents);
}
}
static const bool disabled = std::getenv("APS5_NO_TEXTURE_CACHE") != nullptr;
if (disabled) return StorageTexture::Create(context, *context.detiler, viewed, mip);
Expand Down Expand Up @@ -2812,6 +2817,7 @@ bool ShaderResources::fastRevalidate(std::uint64_t serialBefore, std::span<const
}
const auto address = surface.resource.baseAddress;
const auto bytes = static_cast<std::size_t>(surface.bytes);
if (!FlushDepthPlanes(address, bytes).empty()) return fail(FastFail::Changed);
surface.collected = GuestMemory::CollectWrites(address, bytes);
if (surface.collected == 0) return fail(FastFail::Collect);
const auto* source = surface.source;
Expand Down Expand Up @@ -2938,6 +2944,7 @@ bool ShaderResources::fastRevalidateEach() {
}
const auto address = surface.resource.baseAddress;
const auto bytes = static_cast<std::size_t>(surface.bytes);
if (!FlushDepthPlanes(address, bytes).empty()) return false;
surface.collected = GuestMemory::CollectWrites(address, bytes);
if (surface.collected == 0) return false;
if (PendingStorageOverlaps(address, bytes, surface.source)) return false;
Expand Down Expand Up @@ -3111,7 +3118,10 @@ bool ShaderResources::Revalidate(std::span<const CompiledShader> shaders, ProofR
if (!reusable || shaders.empty()) return false;
static const bool profile = std::getenv("APS5_PROFILE_DRAW") != nullptr;
const auto start = profile ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{};
for (const auto& region : directRegions) CompletePendingCpuWrites(context, region.begin, static_cast<std::size_t>(region.end - region.begin));
for (const auto& region : directRegions) {
static_cast<void>(FlushDepthPlanes(region.begin, static_cast<std::size_t>(region.end - region.begin)));
CompletePendingCpuWrites(context, region.begin, static_cast<std::size_t>(region.end - region.begin));
}
for (const auto& range : describedRanges) {
CompletePendingCpuWrites(context, range.address, static_cast<std::size_t>(range.bytes));
if (range.dccAddress != 0) CompletePendingCpuWrites(context, range.dccAddress, DccKeyBytes(range.bytes));
Expand Down Expand Up @@ -4361,7 +4371,7 @@ std::shared_ptr<Texture> ShaderResources::fastTexture(const ImageRecord& record)
// between the stages marks them uncompressed).
const auto address = record.resource.baseAddress;
const auto bytes = static_cast<std::size_t>(record.guestBytes);
if (DepthSurfaceAt(address)) return nullptr;
if (DepthSurfaceAt(address) || !FlushDepthPlanes(address, bytes).empty()) return nullptr;
if (GuestMemory::CollectWrites(address, bytes) == 0) return nullptr;
if (PendingStorageOverlaps(address, bytes, record.source.get())) return nullptr;
auto keys = record.keys;
Expand Down
2 changes: 2 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
#include "prx/libSceAgcDriver/Execution/include/CaptureTrace.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Texture.hpp"
#include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp"
#include "prx/libSceAgcDriver/Graphics/include/SlimMutex.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libSceAgcDriver/Graphics/include/BufferPool.hpp"
Expand Down Expand Up @@ -3637,6 +3638,7 @@ bool StorageTexture::pendingUnitInside(std::uint64_t address, std::size_t bytes)
}

bool StorageTexture::FlushPending(std::uint64_t address, std::size_t bytes, const StorageTexture* except, const char* reason, PublishScope scope, bool* published) {
static_cast<void>(FlushDepthPlanes(address, bytes));
if (published != nullptr) *published = false;
// The images stay alive across the scan: their last owner may be a batch's kept list, which
// another thread releases outside the GPU mutex once the batch completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct Surface {
VkFormat format;
std::uint32_t slice = 0;
std::uint8_t clearStencil = 0;
std::uint32_t swizzle = 0;
};

struct DrawOptions {
Expand Down Expand Up @@ -71,11 +72,11 @@ struct Shaders {
std::uint32_t vertexPush = 0;
};

inline Shaders Compile(AgcDriver::VulkanDevice& device) {
inline Shaders Compile(AgcDriver::VulkanDevice& device, const void* vertices = Triangles().data()) {
const auto target = device.Target();
Shaders shaders;
std::vector<std::uint32_t> vertexUserData(4, 0u);
const auto vertexBuffer = BufferDescriptor(Triangles().data(), 16u, static_cast<std::uint32_t>(Triangles().size()));
const auto vertexBuffer = BufferDescriptor(vertices, 16u, static_cast<std::uint32_t>(Triangles().size()));
std::copy(vertexBuffer.begin(), vertexBuffer.end(), vertexUserData.begin());
const std::array<ShaderRecompiler::MemoryRegion, 1> vertexMemory{{{reinterpret_cast<std::uintptr_t>(VertexCode.data()), std::as_bytes(std::span(VertexCode))}}};
ShaderRecompiler::RecompileRequest vertex{
Expand Down Expand Up @@ -121,6 +122,7 @@ inline std::uint32_t Draw(AgcDriver::VulkanDevice& device, const Shaders& compil
state.hasColorTarget = true;
state.depth = AgcDriver::Graphics::DepthTarget{surface.depth, surface.stencil, extent, surface.format, 1.0f, surface.clearStencil, surface.htile, surface.htileStencil};
state.depth->firstSlice = surface.slice;
state.depth->depthSwizzle = surface.swizzle;
state.depthTest = options.depthTest;
state.depthWrite = options.depthWrite;
state.depthCompare = options.depthCompare;
Expand Down
Loading
Loading