From e483cf9634f45700870453e0c9250eb08f14862a Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 16 Oct 2022 20:59:14 +0100 Subject: [PATCH] Use shader memory mirror when reading guest shaders Avoids triggering any traps that may be present on the region --- .../gpu/interconnect/maxwell_3d/pipeline_state.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp index 962115d2..32cbe5b6 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp @@ -305,8 +305,11 @@ namespace skyline::gpu::interconnect::maxwell3d { return; } + // entry->mirror may not be a direct mirror of blockMapping and may just contain it as a subregion, so we need to explicitly calculate the offset + span blockMappingMirror{blockMapping.data() - mirrorBlock.data() + entry->mirror.data(), blockMapping.size()}; + // If nothing was in the cache then do a full shader parse - auto guest{[](span mapping) { + binary.binary = [](span mapping) { // We attempt to find the shader size by looking for "BRA $" (Infinite Loop) which is used as padding at the end of the shader // UAM Shader Compiler Reference: https://github.com/devkitPro/uam/blob/5a5afc2bae8b55409ab36ba45be63fcb73f68993/source/compiler_iface.cpp#L319-L351 constexpr u64 BraSelf1{0xE2400FFFFF87000F}, BraSelf2{0xE2400FFFFF07000F}; @@ -320,12 +323,10 @@ namespace skyline::gpu::interconnect::maxwell3d { } return span{}; - }(blockMapping.subspan(blockOffset))}; + }(blockMappingMirror.subspan(blockOffset)); binary.baseOffset = engine->pipeline.programOffset; - hash = XXH64(guest.data(), guest.size_bytes(), 0); - - binary.binary = {guest.data() - mirrorBlock.data() + entry->mirror.data(), guest.size()}; + hash = XXH64(binary.binary.data(), binary.binary.size_bytes(), 0); entry->cache.insert({blockMapping.data() + blockOffset, CacheEntry{binary, hash}}); }