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

softgpu: Detect binner alloc fail and bail #16690

Merged
merged 1 commit into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ bool PSP_InitUpdate(std::string *error_string) {
if (pspIsInited) {
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
pspIsRebooting = false;

// If GPU init failed during IsReady checks, bail.
if (!GPU_IsStarted()) {
*error_string = "Unable to initialize rendering engine.";
pspIsRebooting = false;
PSP_Shutdown();
return true;
}
}
return pspIsInited;
}
Expand Down
11 changes: 10 additions & 1 deletion GPU/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ bool GPU_IsReady() {
return false;
}

bool GPU_IsStarted() {
if (gpu)
return gpu->IsReady() && gpu->IsStarted();
return false;
}

bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
const auto &gpuCore = PSP_CoreParameter().gpuCore;
_assert_(draw || gpuCore == GPUCORE_SOFTWARE);
Expand Down Expand Up @@ -106,7 +112,10 @@ bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
#endif
}

return gpu != NULL;
if (gpu && gpu->IsReady() && !gpu->IsStarted())
SetGPU<SoftGPU>(nullptr);

return gpu != nullptr;
#endif
}
#ifdef USE_CRT_DBG
Expand Down
1 change: 1 addition & 0 deletions GPU/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ namespace Draw {

bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw);
bool GPU_IsReady();
bool GPU_IsStarted();
void GPU_Shutdown();
3 changes: 3 additions & 0 deletions GPU/GPUCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class GPUCommon : public GPUInterface, public GPUDebugInterface {
bool IsReady() override {
return true;
}
bool IsStarted() override {
return true;
}
void CancelReady() override {}
void Reinitialize() override;

Expand Down
1 change: 1 addition & 0 deletions GPU/GPUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class GPUInterface {
// Initialization
virtual bool IsReady() = 0;
virtual void CancelReady() = 0;
virtual bool IsStarted() = 0;
virtual void InitClear() = 0;
virtual void Reinitialize() = 0;

Expand Down
10 changes: 9 additions & 1 deletion GPU/Software/SoftGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,15 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
Rasterizer::Init();
Sampler::Init();
drawEngine_ = new SoftwareDrawEngine();
if (!drawEngine_)
return;

drawEngine_->Init();
drawEngineCommon_ = drawEngine_;

// Push the initial CLUT buffer in case it's all zero (we push only on change.)
drawEngine_->transformUnit.NotifyClutUpdate(clut);
if (drawEngine_->transformUnit.IsStarted())
drawEngine_->transformUnit.NotifyClutUpdate(clut);

// No need to flush for simple parameter changes.
flushOnParams_ = false;
Expand Down Expand Up @@ -762,6 +766,10 @@ void SoftGPU::FastRunLoop(DisplayList &list) {
dirtyFlags_ = dirty;
}

bool SoftGPU::IsStarted() {
return drawEngine_ && drawEngine_->transformUnit.IsStarted();
}

void SoftGPU::ExecuteOp(u32 op, u32 diff) {
const u8 cmd = op >> 24;
const auto info = softgpuCmdInfo[cmd];
Expand Down
1 change: 1 addition & 0 deletions GPU/Software/SoftGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class SoftGPU : public GPUCommon {
~SoftGPU();

u32 CheckGPUFeatures() const override { return 0; }
bool IsStarted() override;
void InitClear() override {}
void ExecuteOp(u32 op, u32 diff) override;
void FinishDeferred() override;
Expand Down
6 changes: 6 additions & 0 deletions GPU/Software/TransformUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

TransformUnit::TransformUnit() {
decoded_ = (u8 *)AllocateMemoryPages(TRANSFORM_BUF_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
if (!decoded_)
return;
binner_ = new BinManager();
}

Expand All @@ -50,6 +52,10 @@ TransformUnit::~TransformUnit() {
delete binner_;
}

bool TransformUnit::IsStarted() {
return binner_ && decoded_;
}

SoftwareDrawEngine::SoftwareDrawEngine() {
// All this is a LOT of memory, need to see if we can cut down somehow. Used for splines.
decoded = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
Expand Down
2 changes: 2 additions & 0 deletions GPU/Software/TransformUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class TransformUnit {
TransformUnit();
~TransformUnit();

bool IsStarted();

static WorldCoords ModelToWorldNormal(const ModelCoords& coords);
static WorldCoords ModelToWorld(const ModelCoords& coords);
static ViewCoords WorldToView(const WorldCoords& coords);
Expand Down