Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another bunch of pre-release fixes #19556

Merged
merged 9 commits into from
Oct 25, 2024
12 changes: 8 additions & 4 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,10 @@ void VulkanRenderManager::StartThreads() {

// Called from main thread.
void VulkanRenderManager::StopThreads() {
// Make sure we don't have an open render pass.
EndCurRenderStep();
// Make sure we don't have an open non-backbuffer render pass
if (curRenderStep_ && curRenderStep_->render.framebuffer != nullptr) {
EndCurRenderStep();
}
// Not sure this is a sensible check - should be ok even if not.
// _dbg_assert_(steps_.empty());

Expand Down Expand Up @@ -1140,6 +1142,8 @@ void VulkanRenderManager::CopyImageToMemorySync(VkImage image, int mipLevel, int

// Need to call this after FlushSync so the pixels are guaranteed to be ready in CPU-accessible VRAM.
queueRunner_.CopyReadbackBuffer(frameData_[vulkan_->GetCurFrame()], nullptr, w, h, destFormat, destFormat, pixelStride, pixels);

_dbg_assert_(steps_.empty());
}

static void RemoveDrawCommands(FastVec<VkRenderData> *cmds) {
Expand Down Expand Up @@ -1338,8 +1342,6 @@ void VulkanRenderManager::BlitFramebuffer(VKRFramebuffer *src, VkRect2D srcRect,
}
}

EndCurRenderStep();

// Sanity check. Added an assert to try to gather more info.
// Got this assert in NPJH50443 FINAL FANTASY TYPE-0, but pretty rare. Moving back to debug assert.
if (aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Expand All @@ -1352,6 +1354,8 @@ void VulkanRenderManager::BlitFramebuffer(VKRFramebuffer *src, VkRect2D srcRect,
}
}

EndCurRenderStep();

VKRStep *step = new VKRStep{ VKRStepType::BLIT };
step->blit.aspectMask = aspectMask;
step->blit.src = src;
Expand Down
50 changes: 26 additions & 24 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,36 @@ bool UIScreen::UseVerticalLayout() const {
}

void UIScreen::DoRecreateViews() {
if (recreateViews_) {
std::lock_guard<std::recursive_mutex> guard(screenManager()->inputLock_);
if (!recreateViews_) {
return;
}

UI::PersistMap persisted;
bool persisting = root_ != nullptr;
if (persisting) {
root_->PersistData(UI::PERSIST_SAVE, "root", persisted);
}
std::lock_guard<std::recursive_mutex> guard(screenManager()->inputLock_);

delete root_;
root_ = nullptr;
CreateViews();
UI::View *defaultView = root_ ? root_->GetDefaultFocusView() : nullptr;
if (defaultView && defaultView->GetVisibility() == UI::V_VISIBLE) {
defaultView->SetFocus();
}
recreateViews_ = false;
UI::PersistMap persisted;
bool persisting = root_ != nullptr;
if (persisting) {
root_->PersistData(UI::PERSIST_SAVE, "root", persisted);
}

if (persisting && root_ != nullptr) {
root_->PersistData(UI::PERSIST_RESTORE, "root", persisted);
delete root_;
root_ = nullptr;
CreateViews();
UI::View *defaultView = root_ ? root_->GetDefaultFocusView() : nullptr;
if (defaultView && defaultView->GetVisibility() == UI::V_VISIBLE) {
defaultView->SetFocus();
}
recreateViews_ = false;

// Update layout and refocus so things scroll into view.
// This is for resizing down, when focused on something now offscreen.
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_);
UI::View *focused = UI::GetFocusedView();
if (focused) {
root_->SubviewFocused(focused);
}
if (persisting && root_ != nullptr) {
root_->PersistData(UI::PERSIST_RESTORE, "root", persisted);

// Update layout and refocus so things scroll into view.
// This is for resizing down, when focused on something now offscreen.
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_);
UI::View *focused = UI::GetFocusedView();
if (focused) {
root_->SubviewFocused(focused);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void Event::Add(std::function<EventReturn(EventParams&)> func) {

// Call this from input thread or whatever, it doesn't matter
void Event::Trigger(EventParams &e) {
if (handlers_.empty()) {
return;
}
EventTriggered(this, e);
}

Expand Down
11 changes: 11 additions & 0 deletions Core/FileSystems/BlockDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
ERROR_LOG(Log::Loader, "Invalid NPUMDIMG header!");
}

u32 psar_id;
fileLoader->ReadAt(psarOffset, 4, 1, &psar_id);

INFO_LOG(Log::Loader, "NPDRM: PSAR ID: %08x");
// PS1 PSAR begins with "PSISOIMG0000"
if (psar_id == 'SISP') {
lbaSize_ = 0; // Mark invalid
ERROR_LOG(Log::Loader, "PSX not supported! Should have been caught earlier.");
return;
}

kirk_init();

// getkey
Expand Down
6 changes: 5 additions & 1 deletion Core/HLE/sceKernelInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ void __KernelReturnFromInterrupt()
PendingInterrupt pend = pendingInterrupts.front();
pendingInterrupts.pop_front();

intrHandlers[pend.intr]->handleResult(pend);
if (pend.intr >= 0 && pend.intr < ARRAY_SIZE(intrHandlers)) {
intrHandlers[pend.intr]->handleResult(pend);
} else {
_assert_msg_(false, "Bad pend.intr: %d", pend.intr);
}
inInterrupt = false;

// Restore context after running the interrupt.
Expand Down
1 change: 0 additions & 1 deletion Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ bool PSP_Reboot(std::string *error_string) {
}

void PSP_BeginHostFrame() {
// Reapply the graphics state of the PSP
if (gpu) {
gpu->BeginHostFrame();
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
WRITE(p, " v.rgb = abs(v.rgb - destColor.rgb);\n");
break;
default:
*errorString = "Bad replace blend eq";
*errorString = StringFromFormat("Bad replace blend eq: %d", (int)replaceBlendEq);
return false;
}
}
Expand Down
6 changes: 6 additions & 0 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void FramebufferManagerCommon::Init(int msaaLevel) {
NotifyRenderResized(msaaLevel);
}

// Returns true if we need to stop the render thread
bool FramebufferManagerCommon::UpdateRenderSize(int msaaLevel) {
const bool newRender = renderWidth_ != (float)PSP_CoreParameter().renderWidth || renderHeight_ != (float)PSP_CoreParameter().renderHeight || msaaLevel_ != msaaLevel;

Expand All @@ -111,6 +112,11 @@ bool FramebufferManagerCommon::UpdateRenderSize(int msaaLevel) {
useBufferedRendering_ = newBuffered;

presentation_->UpdateRenderSize(renderWidth_, renderHeight_);

// If just switching TO buffered rendering, no need to pause the threads. In fact this causes problems due to the open backbuffer renderpass.
if (!useBufferedRendering_ && newBuffered) {
return false;
}
return newRender || newSettings;
}

Expand Down
7 changes: 5 additions & 2 deletions GPU/Common/GPUStateUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ ReplaceBlendType ReplaceBlendWithShader(GEBufferFormat bufferFormat) {
case GE_BLENDMODE_MUL_AND_ADD:
case GE_BLENDMODE_MUL_AND_SUBTRACT:
case GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE:
// Handled below.
// Other blend equations simply don't blend on hardware.
break;

default:
// Other blend equations simply don't blend on hardware.
return REPLACE_BLEND_NO;
}

Expand Down Expand Up @@ -849,6 +848,8 @@ static const BlendEq eqLookupNoMinMax[] = {
BlendEq::ADD, // GE_BLENDMODE_MIN
BlendEq::ADD, // GE_BLENDMODE_MAX
BlendEq::ADD, // GE_BLENDMODE_ABSDIFF
BlendEq::ADD,
BlendEq::ADD,
};

static const BlendEq eqLookup[] = {
Expand All @@ -858,6 +859,8 @@ static const BlendEq eqLookup[] = {
BlendEq::MIN, // GE_BLENDMODE_MIN
BlendEq::MAX, // GE_BLENDMODE_MAX
BlendEq::MAX, // GE_BLENDMODE_ABSDIFF
BlendEq::ADD,
BlendEq::ADD,
};

static BlendFactor toDualSource(BlendFactor blendfunc) {
Expand Down
9 changes: 8 additions & 1 deletion GPU/Common/ShaderId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ bool FragmentIdNeedsFramebufferRead(const FShaderID &id) {
(ReplaceBlendType)id.Bits(FS_BIT_REPLACE_BLEND, 3) == REPLACE_BLEND_READ_FRAMEBUFFER;
}

inline u32 SanitizeBlendMode(GEBlendMode mode) {
if (mode > GE_BLENDMODE_ABSDIFF)
return GE_BLENDMODE_MUL_AND_ADD; // Not sure what the undefined modes are.
else
return mode;
}

// Here we must take all the bits of the gstate that determine what the fragment shader will
// look like, and concatenate them together into an ID.
void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pipelineState, const Draw::Bugs &bugs) {
Expand Down Expand Up @@ -371,7 +378,7 @@ void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pip
// 3 bits.
id.SetBits(FS_BIT_REPLACE_BLEND, 3, replaceBlend);
// 11 bits total.
id.SetBits(FS_BIT_BLENDEQ, 3, gstate.getBlendEq());
id.SetBits(FS_BIT_BLENDEQ, 3, SanitizeBlendMode(gstate.getBlendEq()));
id.SetBits(FS_BIT_BLENDFUNC_A, 4, gstate.getBlendFuncA());
id.SetBits(FS_BIT_BLENDFUNC_B, 4, gstate.getBlendFuncB());
}
Expand Down
12 changes: 12 additions & 0 deletions GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,18 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
}

bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags) {
/*
// TODO: Should add this. But let's do it after the 1.18 release.
if (dest == 0 || src == 0) {
_dbg_assert_msg_(false, "Bad PerformMemoryCopy: %08x -> %08x, size %d (flag: %d)", src, dest, size, (int)flags);
return false;
}
*/
if (size == 0) {
_dbg_assert_msg_(false, "Zero-sized PerformMemoryCopy: %08x -> %08x, size %d (flag: %d)", src, dest, size, (int)flags);
// Let's not ignore this yet but if we hit this, we should investigate.
}

// Track stray copies of a framebuffer in RAM. MotoGP does this.
if (framebufferManager_->MayIntersectFramebufferColor(src) || framebufferManager_->MayIntersectFramebufferColor(dest)) {
if (!framebufferManager_->NotifyFramebufferCopy(src, dest, size, flags, gstate_c.skipDrawReason)) {
Expand Down
36 changes: 18 additions & 18 deletions Tools/langtool/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,10 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
if (!framebufferBound) {
draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, }, "EmuScreen_Behind");
}

Draw::BackendState state = draw->GetCurrentBackendState();
_assert_msg_(!state.valid || state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d tag: %s", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, screenManager()->topScreen()->tag());

// Need to make sure the UI texture is available, for "darken".
screenManager()->getUIContext()->BeginFrame();
draw->SetViewport(viewport);
Expand Down Expand Up @@ -1515,13 +1519,12 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, clearColor }, "EmuScreen_NoFrame");
draw->SetViewport(viewport);
draw->SetScissorRect(0, 0, g_display.pixel_xres, g_display.pixel_yres);
framebufferBound = true;
}

Draw::BackendState state = draw->GetCurrentBackendState();

// We allow if !state.valid, that means it's not the Vulkan backend.
_assert_msg_(!state.valid || state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend);
_assert_msg_(!state.valid || state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d bound: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, (int)framebufferBound);

screenManager()->getUIContext()->BeginFrame();

Expand Down
1 change: 1 addition & 0 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,5 +1765,6 @@ UI::EventReturn GridSettingsPopupScreen::GridMinusClick(UI::EventParams &e) {
UI::EventReturn GridSettingsPopupScreen::OnRecentClearClick(UI::EventParams &e) {
g_Config.ClearRecentIsos();
OnRecentChanged.Trigger(e);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
Loading
Loading