mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): preserve LDS conditional addresses
Use the shared atomic bounds check instead of wrapping at 64 KiB. Expect zero returns and unchanged LDS for aligned out-of-range accesses, and record the gfx1035 hardware measurements.
This commit is contained in:
@@ -103,8 +103,9 @@ void Fill(std::uint32_t threads, std::uint32_t offset, bool contended) {
|
||||
in[1] = contended ? 0xfffffffeu : static_cast<std::uint32_t>(seed >> 32u);
|
||||
in[2] = contended ? Sign | (tid + 1u) : ((tid & 1u) != 0u ? Sign : 0u) | ((tid / 4u) % 2u != 0u ? 0x7fffffffu : 0u);
|
||||
in[3] = contended ? Sign | (tid + 1u) : ((tid & 2u) != 0u ? Sign : 0u) | ((tid / 8u) % 2u != 0u ? 0x13579bdfu : 0u);
|
||||
in[4] = contended ? 0u : LdsDwords * 4u - 24u - tid * 32u;
|
||||
in[5] = in[4] - offset + (tid & 7u) + ((tid & 8u) != 0u ? 0u : 0x10000u);
|
||||
const bool outOfRange = !contended && ((tid & 8u) == 0u || offset >= LdsDwords * 4u);
|
||||
in[4] = contended ? 0u : outOfRange ? tid * 32u : LdsDwords * 4u - 24u - tid * 32u;
|
||||
in[5] = in[4] + (outOfRange ? 0x10000u : 0u) - offset;
|
||||
in[6] = 0xa5a5a5a5u;
|
||||
in[7] = 0x5a5a5a5au;
|
||||
}
|
||||
@@ -138,10 +139,11 @@ void Run(AgcDriver::VulkanDevice& device, std::uint32_t waveSize, const ShaderRe
|
||||
const auto* in = &Input[tid * Words];
|
||||
if (!contended) {
|
||||
const bool active = !inactive || tid % 2u == 0u;
|
||||
Expect(tid, 0u, active ? in[0] : destination == 12u ? in[3] : in[5]);
|
||||
Expect(tid, 1u, active ? in[1] : destination == 12u ? Sentinel : in[6]);
|
||||
Expect(tid, 2u, active && (in[2] & Sign) != 0u ? in[2] & ~Sign : in[0]);
|
||||
Expect(tid, 3u, active && (in[3] & Sign) != 0u ? in[3] & ~Sign : in[1]);
|
||||
const bool inBounds = in[5] + offset < LdsDwords * 4u;
|
||||
Expect(tid, 0u, active ? inBounds ? in[0] : 0u : destination == 12u ? in[3] : in[5]);
|
||||
Expect(tid, 1u, active ? inBounds ? in[1] : 0u : destination == 12u ? Sentinel : in[6]);
|
||||
Expect(tid, 2u, active && inBounds && (in[2] & Sign) != 0u ? in[2] & ~Sign : in[0]);
|
||||
Expect(tid, 3u, active && inBounds && (in[3] & Sign) != 0u ? in[3] & ~Sign : in[1]);
|
||||
}
|
||||
for (std::uint32_t index = 4u; index < Words; ++index) Expect(tid, index, in[6u + index % 2u]);
|
||||
}
|
||||
@@ -149,10 +151,10 @@ void Run(AgcDriver::VulkanDevice& device, std::uint32_t waveSize, const ShaderRe
|
||||
}
|
||||
|
||||
void CheckExecution(AgcDriver::VulkanDevice& device, std::uint32_t waveSize, const ShaderRecompiler::SpirvTarget& target) {
|
||||
for (const auto offset : {0u, 0x123u, 0xffffu}) Run(device, waveSize, target, offset, 12u, false, false);
|
||||
Run(device, waveSize, target, 0x123u, 12u, true, false);
|
||||
Run(device, waveSize, target, 0xffffu, 7u, true, false);
|
||||
Run(device, waveSize, target, 0x123u, 12u, false, true);
|
||||
for (const auto offset : {0u, 0x120u, 0xfff8u}) Run(device, waveSize, target, offset, 12u, false, false);
|
||||
Run(device, waveSize, target, 0x120u, 12u, true, false);
|
||||
Run(device, waveSize, target, 0xfff8u, 7u, true, false);
|
||||
Run(device, waveSize, target, 0x120u, 12u, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -232,15 +232,15 @@ bool TranslationContext::dsCondxchg32(const RdnaInstruction& inst) {
|
||||
memory.dataDwords = 1u;
|
||||
memory.componentCount = 1u;
|
||||
const auto data = readU32Pair(inst.source1);
|
||||
IrValue& address = ir.BitwiseAnd(ir.IAdd(readU32(inst.source0).Value(), ir.Constant(inst.memoryOffset)), ir.Constant(0xfff8u));
|
||||
const IrU32 address = readU32(inst.source0);
|
||||
IrValue& active = ir.GetExec();
|
||||
std::array<IrValue*, 2> old{};
|
||||
for (std::uint32_t index = 0u; index < 2u; ++index) {
|
||||
IrValue& enabled = ir.UGreaterThan(data[index].Value(), ir.Constant(0x7fffffffu));
|
||||
IrValue& mask = ir.Select(enabled, ir.Constant(0xffffffffu), ir.Constant(0u));
|
||||
IrValue& value = ir.Select(enabled, ir.BitwiseAnd(data[index].Value(), ir.Constant(0x7fffffffu)), ir.Constant(0u));
|
||||
memory.offset = index * 4u;
|
||||
old[index] = &ir.Emit(IrOpcode::SharedAtomicMskor32, IrType::U32, {&address, &mask, &value, &active}, addMemoryInfo(memory, inst.programCounter));
|
||||
memory.offset = inst.memoryOffset + index * 4u;
|
||||
old[index] = &ir.Emit(IrOpcode::SharedAtomicMskor32, IrType::U32, {&address.Value(), &mask, &value, &active}, addMemoryInfo(memory, inst.programCounter));
|
||||
}
|
||||
writeOperand(inst.destination, old[0]);
|
||||
writeOperand(offsetOperand(inst.destination, 1u), old[1]);
|
||||
|
||||
@@ -215,7 +215,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- An [unnormalized S#](../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp) (libSceAgcDriver) throws with unequal minification and magnification filters, anisotropy, `TRUNC_COORD`, `MC_COORD_TRUNC` or X/Y clamping other than last-texel or border.
|
||||
- [Image atomics](../../core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp) on 32_SINT and 32_FLOAT surfaces act on the raw dword through an R32_UINT storage view; their float results are assumed to match those measured on 32_UINT surfaces. Other formats throw.
|
||||
- [`ds_wrxchg2_rtn_b32`, `ds_wrxchg2st64_rtn_b32`, `ds_wrxchg2_rtn_b64` and `ds_wrxchg2st64_rtn_b64`](../../core/shader/recompiler/Translation/src/MemoryInstructions/SharedMemoryInstructions.cpp) are translated as two separate 32-bit or 64-bit atomic swaps per invocation. RDNA2 hardware (measured on gfx1035) performs every lane's first exchange before any lane's second one, so when lanes of the same wave or of different waves overlap addresses, the result can differ from hardware. `offset0 == offset1` throws, although on hardware it is two exchanges in order.
|
||||
- [`ds_condxchg32_rtn_b64`](../../core/shader/recompiler/Translation/src/MemoryInstructions/SharedMemoryInstructions.cpp) uses two 32-bit atomic conditional exchanges: the address mask and bit clearing follow [RDNA3 ISA](https://gpuopen.com/download/rdna3-shader-instruction-set-architecture-feb-2023.pdf), section 16.15, page 530, and the access width follows the 32-bit atomic classification in [RDNA4 ISA](https://gpuopen.com/download/rdna4-instruction-set-architecture.pdf), section 12.5.1, pages 152-153. These details and contended lane ordering were not measured on RDNA2 or the console; pair-wide indivisibility is not assumed, and concurrent 64-bit LDS atomics use a separate lock. GDS throws. VGPR pairs extending beyond v255 throw; allocated-VGPR EXEC nullification is not emulated.
|
||||
- [`ds_condxchg32_rtn_b64`](../../core/shader/recompiler/Translation/src/MemoryInstructions/SharedMemoryInstructions.cpp) uses two 32-bit atomic conditional exchanges. RDNA2 (gfx1035) measurements confirmed aligned return values, conditional bit clearing and 16-bit offsets; out-of-range accesses return zero without modifying LDS. Misaligned accesses fault the wave on gfx1035; the recompiler does not model this fault. Radeon 780M (gfx1103, RDNA3) measurements confirmed aligned return values, conditional bit clearing, EXEC masking and operand overlap in wave32 and wave64; contended cases passed per-dword conservation checks. Contended lane ordering and gfx1013 remain unmeasured; pair-wide indivisibility is not assumed, and concurrent 64-bit LDS atomics use a separate lock. GDS throws. VGPR pairs extending beyond v255 throw; allocated-VGPR EXEC nullification is not emulated.
|
||||
- [64-bit image atomics](../../core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp) (`image_atomic_*` with a two-dword data mask) need `VK_EXT_shader_image_atomic_int64` and act on 32_32 UINT, SINT and FLOAT surfaces through an R64_UINT storage view. 64-bit `image_atomic_inc`, `image_atomic_dec` and the float atomics throw, as does any other access in the same shader to an image it updates with 64-bit atomics.
|
||||
- [8_SRGB and 8_8_SRGB loads](../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) on a device that cannot sample R8_SRGB or R8G8_SRGB return the sRGB EOTF rounded to nearest even at bf16 precision, as adriadam10 measured on RDNA2 (gfx1035) in #866; the PS5's gfx1013 is not measured.
|
||||
- [8_SRGB and 8_8_SRGB textures](../../core/libs/prx/libSceAgcDriver/Graphics/src/TextureFormat.cpp) (libSceAgcDriver) that the device samples as R8_SRGB or R8G8_SRGB use its own decode, which need not match gfx1035: NVIDIA's R8_SRGB is one bf16 step off in 29 of 256 codes.
|
||||
|
||||
Reference in New Issue
Block a user