From 0268e1d5a060cadd336d336aae2e89d14d875192 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 31 Jul 2022 13:21:26 +0100 Subject: [PATCH] Force a submit before any i2m engine writes We need traps to be inplace so we dont end up overwriting a resource that's being actively used by the current context without setting it to dirty --- app/src/main/cpp/skyline/soc/gm20b/channel.cpp | 2 +- .../cpp/skyline/soc/gm20b/engines/inline2memory.cpp | 10 ++++++---- .../main/cpp/skyline/soc/gm20b/engines/inline2memory.h | 8 ++++---- .../cpp/skyline/soc/gm20b/engines/kepler_compute.cpp | 2 +- .../main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/cpp/skyline/soc/gm20b/channel.cpp b/app/src/main/cpp/skyline/soc/gm20b/channel.cpp index 9efe6b4a..f0b6b76e 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/channel.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/channel.cpp @@ -13,6 +13,6 @@ namespace skyline::soc::gm20b { fermi2D(std::make_unique(state, *this, macroState, executor)), maxwellDma(state, *this, executor), keplerCompute(state, *this), - inline2Memory(asCtx), + inline2Memory(*this), gpfifo(state, *this, numEntries) {} } diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp index 8cce3558..efa59fbd 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.cpp @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) -#include +#include #include "inline2memory.h" namespace skyline::soc::gm20b::engine { - Inline2MemoryBackend::Inline2MemoryBackend(std::shared_ptr addressSpaceContext) : addressSpaceContext(std::move(addressSpaceContext)) {} + Inline2MemoryBackend::Inline2MemoryBackend(ChannelContext &channelCtx) : channelCtx(channelCtx) {} void Inline2MemoryBackend::LaunchDma(Inline2MemoryBackend::RegisterState &state) { writeOffset = 0; @@ -17,10 +17,12 @@ namespace skyline::soc::gm20b::engine { if (state.launchDma.completion == RegisterState::DmaCompletionType::ReleaseSemaphore) throw exception("Semaphore release on I2M completion is not supported!"); + channelCtx.executor.Submit(); + if (state.launchDma.layout == RegisterState::DmaDstMemoryLayout::Pitch && state.lineCount == 1) { // TODO: we can do this with the buffer manager to avoid some overhead in the future Logger::Debug("range: 0x{:X} -> 0x{:X}", u64{state.offsetOut}, u64{state.offsetOut} + buffer.size() * 0x4); - addressSpaceContext->gmmu.Write(state.offsetOut, span(buffer)); + channelCtx.asCtx->gmmu.Write(state.offsetOut, span(buffer)); } else { Logger::Warn("Non-linear I2M uploads are not supported!"); } @@ -47,7 +49,7 @@ namespace skyline::soc::gm20b::engine { CompleteDma(state); } - Inline2Memory::Inline2Memory(std::shared_ptr addressSpaceContext) : backend(std::move(addressSpaceContext)) {} + Inline2Memory::Inline2Memory(ChannelContext &channelCtx) : backend(channelCtx) {} __attribute__((always_inline)) void Inline2Memory::CallMethod(u32 method, u32 argument) { Logger::Verbose("Called method in I2M: 0x{:X} args: 0x{:X}", method, argument); diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.h b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.h index 80e200e4..c2365d4d 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.h +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/inline2memory.h @@ -7,7 +7,7 @@ #include "engine.h" namespace skyline::soc::gm20b { - struct AddressSpaceContext; + struct ChannelContext; } namespace skyline::soc::gm20b::engine { @@ -18,7 +18,7 @@ namespace skyline::soc::gm20b::engine { private: std::vector buffer; //!< Temporary buffer to hold data being currently uploaded u32 writeOffset{}; //!< Current write offset in words into `buffer` - std::shared_ptr addressSpaceContext; + ChannelContext &channelCtx; public: /** @@ -124,7 +124,7 @@ namespace skyline::soc::gm20b::engine { void CompleteDma(RegisterState &state); public: - Inline2MemoryBackend(std::shared_ptr addressSpaceContext); + Inline2MemoryBackend(ChannelContext &channelCtx); /** * @brief Should be called when launchDma in `state` is written to @@ -164,7 +164,7 @@ namespace skyline::soc::gm20b::engine { } registers{}; public: - Inline2Memory(std::shared_ptr addressSpaceContext); + Inline2Memory(ChannelContext &channelCtx); void CallMethod(u32 method, u32 argument); diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/kepler_compute.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/kepler_compute.cpp index 59a1a48b..865b9a7c 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/kepler_compute.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/kepler_compute.cpp @@ -8,7 +8,7 @@ namespace skyline::soc::gm20b::engine { KeplerCompute::KeplerCompute(const DeviceState &state, ChannelContext &channelCtx) - : syncpoints(state.soc->host1x.syncpoints), i2m(channelCtx.asCtx) {} + : syncpoints(state.soc->host1x.syncpoints), i2m(channelCtx) {} __attribute__((always_inline)) void KeplerCompute::CallMethod(u32 method, u32 argument) { Logger::Verbose("Called method in Kepler compute: 0x{:X} args: 0x{:X}", method, argument); diff --git a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp index fd8c2976..d52ec61b 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/engines/maxwell_3d.cpp @@ -11,7 +11,7 @@ namespace skyline::soc::gm20b::engine::maxwell3d { : MacroEngineBase(macroState), syncpoints(state.soc->host1x.syncpoints), context(*state.gpu, channelCtx, executor), - i2m(channelCtx.asCtx), + i2m(channelCtx), channelCtx(channelCtx) { executor.AddFlushCallback([this]() { FlushEngineState(); }); InitializeRegisters();