Skip to content
Merged
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
17 changes: 13 additions & 4 deletions core/libs/prx/libSceAgcDriver/State/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstdint>
#include <cstddef>
#include <cerrno>
#include <mutex>
#include <stdexcept>
#include "SceTypes.hpp"
Expand Down Expand Up @@ -40,8 +41,12 @@ int APS5_VABI sceAgcDriverSetHsOffchipParam(uint16_t granularity, uint16_t buffe
int APS5_VABI sceAgcDriverGetHsOffchipParam(uint16_t* granularity, uint16_t* buffering) {
if (granularity == nullptr || buffering == nullptr) throw std::invalid_argument("sceAgcDriverGetHsOffchipParam: null output");
std::lock_guard lock(hsOffchipParamMutex);
*granularity = hsOffchipParam.granularity;
*buffering = hsOffchipParam.buffering;
const auto localParam = hsOffchipParam;
const int savedErrno = errno;
const bool copiedGranularity = GuestCopyOut_nid_no_patch(granularity, &localParam.granularity, sizeof(localParam.granularity));
const bool copiedBuffering = GuestCopyOut_nid_no_patch(buffering, &localParam.buffering, sizeof(localParam.buffering));
errno = savedErrno;
if (!copiedGranularity || !copiedBuffering) throw std::invalid_argument("sceAgcDriverGetHsOffchipParam: invalid output pointer");
return 0;
}

Expand All @@ -55,8 +60,12 @@ int APS5_VABI sceAgcDriverSetTFRing(const volatile void* base, uint32_t size) {
int APS5_VABI sceAgcDriverGetTFRing(uintptr_t* base, uint32_t* size) {
if (base == nullptr || size == nullptr) throw std::invalid_argument("sceAgcDriverGetTFRing: null output");
std::lock_guard lock(tessellationFactorRingMutex);
*base = tessellationFactorRing.base;
*size = tessellationFactorRing.size;
const auto localRing = tessellationFactorRing;
const int savedErrno = errno;
const bool copiedBase = GuestCopyOut_nid_no_patch(base, &localRing.base, sizeof(localRing.base));
const bool copiedSize = GuestCopyOut_nid_no_patch(size, &localRing.size, sizeof(localRing.size));
errno = savedErrno;
if (!copiedBase || !copiedSize) throw std::invalid_argument("sceAgcDriverGetTFRing: invalid output pointer");
return 0;
}

Expand Down
11 changes: 11 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/TessellationFactorRing.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prx/libSceAgcDriver/State/include/Configuration.hpp"
#include "prx/libSceAgcDriver/include/AgcDriver.hpp"
#include "SceTypes.hpp"
#include <cerrno>
#include <cstdint>
#include <cstdlib>
#include <stdexcept>
Expand Down Expand Up @@ -53,6 +54,11 @@ void CheckHsOffchipParam() {
OffchipOutput output;
Require(Rejects([&] { sceAgcDriverGetHsOffchipParam(nullptr, &output.buffering); }));
Require(Rejects([&] { sceAgcDriverGetHsOffchipParam(&output.granularity, nullptr); }));
errno = 71;
Require(Rejects([&] { sceAgcDriverGetHsOffchipParam(reinterpret_cast<uint16_t*>(0x10), &output.buffering); }));
Require(errno == 71);
Require(Rejects([&] { sceAgcDriverGetHsOffchipParam(&output.granularity, reinterpret_cast<uint16_t*>(0x10)); }));
Require(errno == 71);
}

void RequireRing(uintptr_t expectedBase, uint32_t expectedSize) {
Expand All @@ -79,4 +85,9 @@ int main() {
RingOutput output;
Require(Rejects([&] { sceAgcDriverGetTFRing(nullptr, &output.size); }));
Require(Rejects([&] { sceAgcDriverGetTFRing(&output.base, nullptr); }));
errno = 71;
Require(Rejects([&] { sceAgcDriverGetTFRing(reinterpret_cast<uintptr_t*>(0x10), &output.size); }));
Require(errno == 71);
Require(Rejects([&] { sceAgcDriverGetTFRing(&output.base, reinterpret_cast<uint32_t*>(0x10)); }));
Require(errno == 71);
}
2 changes: 1 addition & 1 deletion docs/dev/debt/libSceAgcDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Eligible single-sample draws retain native finite bounds inside [0, 1] and use a
- [FORCE_DEGAMMA on PS4 (GCN)](../../../core/libs/prx/libSceAgcDriver/Graphics/src/Sampler.cpp) (libSceAgcDriver, PS4) - not checked on a console. shadPS4 (`resource_patching_pass.cpp`, 0614ce324be0) converts the filtered texel of every non-sRGB format to linear, and fpPS4 (`ps4_shader.pas`, 04cefd43e6fd) documents the bit as applied after filtering regardless of format. Here a sampler that forces sRGB decoding reads a texture of the formats listed in the entry above through its sRGB view, so the conversion happens before filtering; the bit is ignored for sRGB formats and for a fixed list of formats, and any other format throws.
- [DISABLE_DEGAMMA](../../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp) (libSceAgcDriver) - S# word 0 bit 31 (`SKIP_DEGAMMA` on RDNA 2, Mesa `src/amd/registers/gfx10-rsrc.json` field `SKIP_DEGAMMA` in `SQ_IMG_SAMP_WORD0`, `ac_descriptors.c`) disables sRGB-to-linear conversion when sampling `_SRGB` formats. On non-sRGB formats, hardware degamma is inactive and the bit is a hardware no-op. A sampler with `SKIP_DEGAMMA` paired with an `_SRGB` format throws (`RequireDisablesDegammaOn`), as non-sRGB views for sRGB images are not implemented.
- [Tessellation factor ring](../../../core/libs/prx/libSceAgcDriver/State/src/Configuration.cpp) (libSceAgcDriver) - `sceAgcDriverSetTFRing` records the ring and `sceAgcDriverGetTFRing` reports it. Before a title sets one, it reports the console's default, 0xFF0000000 and 128 KiB, as measured in [PS5_Vulkan's hardware findings](https://github.com/mihawk-99/PS5_Vulkan/blob/fde9e3798c2ec1d8fccc90d5067cd6060490607f/docs/HARDWARE_FINDINGS.md). Nothing is written to the recorded ring: tessellated draws run as Vulkan tessellation stages, which keep their factors on the host, so a title that reads tessellation factors from the ring finds none. A null base or a zero size throws; [ps5-opengl's AGC runtime](https://github.com/blackbearreloaded/ps5-opengl/blob/67c873f985eaefe0a72f713529e5632eaa01139c/src/platform/ps5_agc_native_runtime.c) calls `sceAgcDriverSetTFRing(0, 0)` in its cleanup, and what that does on the console is unknown.
- [sceAgcDriverGetHsOffchipParam, sceAgcDriverSetHsOffchipParam](../../../core/libs/prx/libSceAgcDriver/State/src/Configuration.cpp) (libSceAgcDriver) - `Get` reports (0, 0) until a title sets the pair, and `Set(granularity, buffering)` keeps the granularity in 2 bits and the buffering in 9, so 1023 reads back as 511, as measured on a console in [PS5_Vulkan's hardware findings](https://github.com/mihawk-99/PS5_Vulkan/blob/ace98a99460c95a8d2821a9e33935c7b71070f7f/docs/HARDWARE_FINDINGS.md#L3415-L3429). The `uint16_t` arguments follow [ps5-vulkan](https://github.com/mpereiraesaa/ps5-vulkan/blob/e6d3c3f82f3c8a574e28c174b15b287f9c0ecc6d/native/graphics_queue_ps5.c#L45-L56). Values in range are taken to round-trip. Whether the console masks or clamps the rest is not measured, so a granularity above 3 or a buffering above 511 other than 1023 throws, as does a null output. Nothing reads the pair: tessellated draws run as Vulkan tessellation stages. PPSA99011 imports `Get`
- [sceAgcDriverGetHsOffchipParam, sceAgcDriverSetHsOffchipParam](../../../core/libs/prx/libSceAgcDriver/State/src/Configuration.cpp) (libSceAgcDriver) - `Get` reports (0, 0) until set, and `Set(granularity, buffering)` keeps granularity in 2 bits and buffering in 9, so 1023 reads back as 511, as measured in [PS5_Vulkan's findings](https://github.com/mihawk-99/PS5_Vulkan/blob/ace98a99460c95a8d2821a9e33935c7b71070f7f/docs/HARDWARE_FINDINGS.md#L3415-L3429). Arguments follow [ps5-vulkan](https://github.com/mpereiraesaa/ps5-vulkan/blob/e6d3c3f82f3c8a574e28c174b15b287f9c0ecc6d/native/graphics_queue_ps5.c#L45-L56). Whether the console masks or clamps other values is unmeasured; granularity above 3 or buffering above 511 other than 1023 throws, as does a null or unwritable output pointer (rejecting unwritable memory is a host-safety fallback; console fault handling is unmeasured). Nothing reads the pair: tessellated draws run as host tessellation stages. PPSA99011 imports `Get`
- [VertexBufferReadSize](../../../core/libs/prx/libSceAgcDriver/Graphics/include/VertexInput.hpp) and the [vertex staging copy](../../../core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp) (libSceAgcDriver) - a vertex fetch whose index is at or past the descriptor's `num_records` no longer throws for `OOB_SELECT` 0 and 1. The copy still spans the whole fetch, but the bytes from `num_records * stride` onward read as zeros, so the out-of-range vertex is `(0, 0, 0, 0)`. Measured with `buffer_load_format_xyzw` (`idxen`) through the [hardware oracle](../HW_ORACLE.md) on RDNA2 gfx1036 for PPSA01325's word 3 `0x0004dfac` (`OOB_SELECT` 0) in #2241: indices 3, 4 and 5 over 3 records each return `00000000 00000000 00000000 00000000`, W included, unlike Vulkan `robustBufferAccess`, which returns `(0, 0, 0, 1)`. The zeros come from the record check, not from memory: stored values placed past the records are ignored, and a `num_records` 6 control returns them. `RESOURCE_LEVEL` 1, `OOB_SELECT` 1 and FORMAT 74 `32_32_32_FLOAT` give the same zeros, in wave32 and wave64; gfx1013 (the console) is not measured. `OOB_SELECT` 2 returns the stored values past the records and `OOB_SELECT` 3 compares `num_records` against the byte offset, both measured on the same setup in #2241; the two keep throwing past `num_records` here, since each needs its own rule. Zero-stride descriptors (`stride` 0) keep their separate byte-count check and are not covered here. Each out-of-range fetch is copied alone and outside the draw-snapshot cache, which is neither read nor written for it: a reused snapshot would carry another draw's bytes into the zero region, and a stored zero-padded copy would hand zeros to a later in-range draw at the same address. The valid prefix is still flushed for GPU writes before it is read.
- [Draw snapshot buffer descriptors](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) rewrite each affected array from element zero, preserving unchanged descriptors. MoltenVK 1.4.2 writes auxiliary buffer lengths at index `i` instead of `start + i` for partial array updates ([MVKDescriptorSet.mm, BufferAuxSize](https://github.com/KhronosGroup/MoltenVK/blob/v1.4.2/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm#L1051)). Per-element writes therefore let one buffer length replace another even when Vulkan buffer handles and ranges are correct.
- The [driver](../../../core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp) binds at most 262144 table images per pipeline, fewer under lower sampled-image limits; the rest fault when selected. A device without runtime descriptor arrays or variable-count bindings throws.
Expand Down
Loading