mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Decentralize the assert for AllocateAlignedMemory failures
This commit is contained in:
parent
85410305e6
commit
f54d701a2e
@ -258,9 +258,6 @@ void *AllocateAlignedMemory(size_t size, size_t alignment) {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
char temp[32];
|
||||
NiceSizeFormat(size, temp, sizeof(temp));
|
||||
_assert_msg_(ptr != nullptr, "Failed to allocate aligned memory of size %s (%llu)", temp, (unsigned long long)size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ bool ProtectMemoryPages(const void* ptr, size_t size, uint32_t memProtFlags);
|
||||
void FreeMemoryPages(void* ptr, size_t size);
|
||||
|
||||
// Regular aligned memory. Don't try to apply memory protection willy-nilly to memory allocated this way as in-page alignment is unknown (though could be checked).
|
||||
// No longer asserts, will return nullptr on failure.
|
||||
void* AllocateAlignedMemory(size_t size, size_t alignment);
|
||||
void FreeAlignedMemory(void* ptr);
|
||||
|
||||
|
@ -97,10 +97,8 @@ bool IsFocusMovementEnabled() {
|
||||
}
|
||||
|
||||
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets) {
|
||||
if (!root) {
|
||||
ERROR_LOG(Log::System, "Tried to layout a view hierarchy from a zero pointer root");
|
||||
return;
|
||||
}
|
||||
_assert_(root);
|
||||
_assert_(&dc);
|
||||
|
||||
Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds();
|
||||
|
||||
|
@ -108,6 +108,8 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw, Draw2D *draw2D)
|
||||
// Here we need 2KB to expand a 1KB CLUT.
|
||||
expandClut_ = (u32 *)AllocateAlignedMemory(2048, 16);
|
||||
|
||||
_assert_(clutBufRaw_ && clutBufConverted_ && expandClut_);
|
||||
|
||||
// Zap so we get consistent behavior if the game fails to load some of the CLUT.
|
||||
memset(clutBufRaw_, 0, 2048);
|
||||
memset(clutBufConverted_, 0, 2048);
|
||||
|
@ -319,6 +319,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
|
||||
}
|
||||
|
||||
data = (u8 *)AllocateAlignedMemory(dataSize, 16);
|
||||
_assert_msg_(data != nullptr, "Failed to allocate aligned memory for texture level %d: %d bytes (%dx%d)", i, (int)dataSize, mipWidth, mipHeight);
|
||||
|
||||
if (!data) {
|
||||
ERROR_LOG(Log::G3D, "Ran out of RAM trying to allocate a temporary texture upload buffer (%dx%d)", mipWidth, mipHeight);
|
||||
@ -341,6 +342,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
|
||||
|
||||
size_t dataSize = levelStride * plan.depth;
|
||||
u8 *data = (u8 *)AllocateAlignedMemory(dataSize, 16);
|
||||
_assert_msg_(data != nullptr, "Failed to allocate aligned memory for 3d texture: %d bytes", (int)dataSize);
|
||||
memset(data, 0, levelStride * plan.depth);
|
||||
u8 *p = data;
|
||||
|
||||
|
@ -42,8 +42,7 @@
|
||||
|
||||
TransformUnit::TransformUnit() {
|
||||
decoded_ = (u8 *)AllocateAlignedMemory(TRANSFORM_BUF_SIZE, 16);
|
||||
if (!decoded_)
|
||||
return;
|
||||
_assert_(decoded_);
|
||||
binner_ = new BinManager();
|
||||
}
|
||||
|
||||
|
@ -216,6 +216,7 @@ ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw)
|
||||
uboAlignment_ = vulkan->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment;
|
||||
|
||||
uniforms_ = (Uniforms *)AllocateAlignedMemory(sizeof(Uniforms), 16);
|
||||
_assert_(uniforms_);
|
||||
|
||||
static_assert(sizeof(uniforms_->ub_base) <= 512, "ub_base grew too big");
|
||||
static_assert(sizeof(uniforms_->ub_lights) <= 512, "ub_lights grew too big");
|
||||
|
@ -768,8 +768,11 @@ void TextureCacheVulkan::LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *w
|
||||
if (scaleFactor > 1) {
|
||||
u32 fmt = dstFmt;
|
||||
// CPU scaling reads from the destination buffer so we want cached RAM.
|
||||
uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16);
|
||||
scaler_.ScaleAlways((u32 *)rearrange, pixelData, w, h, &w, &h, scaleFactor);
|
||||
size_t allocBytes = w * scaleFactor * h * scaleFactor * 4;
|
||||
uint8_t *scaleBuf = (uint8_t *)AllocateAlignedMemory(allocBytes, 16);
|
||||
_assert_msg_(scaleBuf, "Failed to allocate %d aligned bytes for texture scaler", (int)allocBytes);
|
||||
|
||||
scaler_.ScaleAlways((u32 *)scaleBuf, pixelData, w, h, &w, &h, scaleFactor);
|
||||
pixelData = (u32 *)writePtr;
|
||||
|
||||
// We always end up at 8888. Other parts assume this.
|
||||
@ -779,13 +782,13 @@ void TextureCacheVulkan::LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *w
|
||||
|
||||
if (decPitch != rowPitch) {
|
||||
for (int y = 0; y < h; ++y) {
|
||||
memcpy(writePtr + rowPitch * y, rearrange + decPitch * y, w * bpp);
|
||||
memcpy(writePtr + rowPitch * y, scaleBuf + decPitch * y, w * bpp);
|
||||
}
|
||||
decPitch = rowPitch;
|
||||
} else {
|
||||
memcpy(writePtr, rearrange, w * h * 4);
|
||||
memcpy(writePtr, scaleBuf, w * h * 4);
|
||||
}
|
||||
FreeAlignedMemory(rearrange);
|
||||
FreeAlignedMemory(scaleBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -774,6 +774,7 @@ void GameBrowser::Refresh() {
|
||||
auto mm = GetI18NCategory(I18NCat::MAINMENU);
|
||||
|
||||
// No topbar on recent screen
|
||||
gameList_ = nullptr;
|
||||
if (DisplayTopBar()) {
|
||||
LinearLayout *topBar = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
||||
if (browseFlags_ & BrowseFlags::NAVIGATE) {
|
||||
@ -828,12 +829,10 @@ void GameBrowser::Refresh() {
|
||||
|
||||
if (*gridStyle_) {
|
||||
gameList_ = new UI::GridLayoutList(UI::GridLayoutSettings(150*g_Config.fGameGridScale, 85*g_Config.fGameGridScale), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
||||
Add(gameList_);
|
||||
} else {
|
||||
UI::LinearLayout *gl = new UI::LinearLayoutList(UI::ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
||||
gl->SetSpacing(4.0f);
|
||||
gameList_ = gl;
|
||||
Add(gameList_);
|
||||
}
|
||||
} else {
|
||||
if (*gridStyle_) {
|
||||
@ -854,8 +853,8 @@ void GameBrowser::Refresh() {
|
||||
// grid->Add(gameList_);
|
||||
// grid->Add(gridOptionColumn);
|
||||
// Add(grid);
|
||||
Add(gameList_);
|
||||
}
|
||||
Add(gameList_);
|
||||
|
||||
// Find games in the current directory and create new ones.
|
||||
std::vector<DirButton *> dirButtons;
|
||||
|
@ -200,18 +200,18 @@ static void ExpandBezier(int &count, int op, const std::vector<SimpleVertex> &si
|
||||
output.count = 0;
|
||||
|
||||
ControlPoints cpoints;
|
||||
cpoints.pos = (Vec3f *)AllocateAlignedMemory(sizeof(Vec3f) * num_points, 16);
|
||||
cpoints.tex = (Vec2f *)AllocateAlignedMemory(sizeof(Vec2f) * num_points, 16);
|
||||
cpoints.col = (Vec4f *)AllocateAlignedMemory(sizeof(Vec4f) * num_points, 16);
|
||||
cpoints.pos = new Vec3f[num_points];
|
||||
cpoints.tex = new Vec2f[num_points];
|
||||
cpoints.col = new Vec4f[num_points];
|
||||
cpoints.Convert(points.data(), num_points);
|
||||
|
||||
surface.Init((int)generatedVerts.size());
|
||||
SoftwareTessellation(output, surface, gstate.vertType, cpoints);
|
||||
count = output.count;
|
||||
|
||||
FreeAlignedMemory(cpoints.pos);
|
||||
FreeAlignedMemory(cpoints.tex);
|
||||
FreeAlignedMemory(cpoints.col);
|
||||
delete [] cpoints.pos;
|
||||
delete [] cpoints.tex;
|
||||
delete [] cpoints.col;
|
||||
}
|
||||
|
||||
static void ExpandSpline(int &count, int op, const std::vector<SimpleVertex> &simpleVerts, const std::vector<u16> &indices, std::vector<SimpleVertex> &generatedVerts, std::vector<u16> &generatedInds) {
|
||||
|
Loading…
Reference in New Issue
Block a user