From 3407f5a6d1721ddc87f9bba6eb8a227d3b9b0d78 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Mon, 30 Jan 2023 21:07:51 +0530 Subject: [PATCH] Fix Depth RT layer stride The layer stride provided by the depth register in Maxwell3D needs to be shifted by 2, this caused the stride to be 1/4th of what it needed to be resulting in OOB access. --- .../skyline/gpu/interconnect/maxwell_3d/pipeline_state.cpp | 4 ++-- .../skyline/gpu/interconnect/maxwell_3d/pipeline_state.h | 6 +++++- 2 files changed, 7 insertions(+), 3 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 540b0494..c9abcfa0 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 @@ -87,7 +87,7 @@ namespace skyline::gpu::interconnect::maxwell3d { /* Depth Render Target */ void DepthRenderTargetState::EngineRegisters::DirtyBind(DirtyManager &manager, dirty::Handle handle) const { - manager.Bind(handle, ztSize, ztOffset, ztFormat, ztBlockSize, ztArrayPitch, ztSelect, ztLayer, surfaceClip); + manager.Bind(handle, ztSize, ztOffset, ztFormat, ztBlockSize, ztArrayPitchLsr2, ztSelect, ztLayer, surfaceClip); } DepthRenderTargetState::DepthRenderTargetState(dirty::Handle dirtyHandle, DirtyManager &manager, const EngineRegisters &engine) : engine{manager, dirtyHandle, engine} {} @@ -121,7 +121,7 @@ namespace skyline::gpu::interconnect::maxwell3d { .blockDepth = engine->ztBlockSize.BlockDepth(), }; - guest.layerStride = (guest.baseArrayLayer > 1 || guest.layerCount > 1) ? engine->ztArrayPitch : 0; + guest.layerStride = (guest.baseArrayLayer > 1 || guest.layerCount > 1) ? engine->ZtArrayPitch() : 0; auto mappings{ctx.channelCtx.asCtx->gmmu.TranslateRange(engine->ztOffset, guest.GetSize())}; guest.mappings.assign(mappings.begin(), mappings.end()); diff --git a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h index 33e60ac0..31e89dd9 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/maxwell_3d/pipeline_state.h @@ -40,12 +40,16 @@ namespace skyline::gpu::interconnect::maxwell3d { const soc::gm20b::engine::Address &ztOffset; const engine::ZtFormat &ztFormat; const engine::ZtBlockSize &ztBlockSize; - const u32 &ztArrayPitch; + const u32 &ztArrayPitchLsr2; const engine::ZtSelect &ztSelect; const engine::ZtLayer &ztLayer; const engine::SurfaceClip &surfaceClip; void DirtyBind(DirtyManager &manager, dirty::Handle handle) const; + + u32 ZtArrayPitch() const { + return ztArrayPitchLsr2 << 2; + } }; private: