diff --git a/Common/Vulkan/VulkanMemory.cpp b/Common/Vulkan/VulkanMemory.cpp index 54c2cb6f46..4460a57492 100644 --- a/Common/Vulkan/VulkanMemory.cpp +++ b/Common/Vulkan/VulkanMemory.cpp @@ -283,9 +283,9 @@ bool VulkanDeviceAllocator::AllocateFromSlab(Slab &slab, size_t &start, size_t b int VulkanDeviceAllocator::ComputeUsagePercent() const { int blockSum = 0; int blocksUsed = 0; - for (int i = 0; i < slabs_.size(); i++) { + for (size_t i = 0; i < slabs_.size(); i++) { blockSum += (int)slabs_[i].usage.size(); - for (int j = 0; j < slabs_[i].usage.size(); j++) { + for (size_t j = 0; j < slabs_[i].usage.size(); j++) { blocksUsed += slabs_[i].usage[j] != 0 ? 1 : 0; } } diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 0b14aa764a..0c39d9fe2f 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -351,7 +351,7 @@ std::vector CWCheatEngine::GetCodesList() { // It also goes through other "_" lines, but they all have to meet this requirement anyway // so we don't have to specify any syntax checks here that are made by cheat engine. if (line.length() >= 5 && line[0] == '_') { - for (int i = 4; i < line.length(); i++) { + for (size_t i = 4; i < line.length(); i++) { if (line[i] != ' ') { validCheatLine = true; break; diff --git a/Core/ELF/ElfReader.cpp b/Core/ELF/ElfReader.cpp index b68e7775b8..68f7531e2d 100644 --- a/Core/ELF/ElfReader.cpp +++ b/Core/ELF/ElfReader.cpp @@ -29,7 +29,7 @@ const char *ElfReader::GetSectionName(int section) const { return nullptr; int nameOffset = sections[section].sh_name; - if (nameOffset < 0 || nameOffset >= size_) { + if (nameOffset < 0 || (size_t)nameOffset >= size_) { ERROR_LOG(LOADER, "ELF: Bad name offset %d in section %d (max = %d)", nameOffset, section, (int)size_); return nullptr; } diff --git a/Core/FileSystems/BlobFileSystem.cpp b/Core/FileSystems/BlobFileSystem.cpp index b72b69ff30..b0a7639b39 100644 --- a/Core/FileSystems/BlobFileSystem.cpp +++ b/Core/FileSystems/BlobFileSystem.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017- PPSSPP Project. +// Copyright (c) 2017- PPSSPP Project. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -50,9 +50,9 @@ void BlobFileSystem::CloseFile(u32 handle) { size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) { auto entry = entries_.find(handle); if (entry != entries_.end()) { - size_t readSize = fileLoader_->ReadAt(entry->second, size, pointer); + s64 readSize = fileLoader_->ReadAt(entry->second, size, pointer); entry->second += readSize; - return readSize; + return (size_t)readSize; } return 0; } diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index 49e1b36f3c..77614c93df 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -95,7 +95,7 @@ GLRTexture *DepalShaderCacheGLES::GetClutTexture(GEPaletteFormat clutFormat, con uint8_t *clutCopy = new uint8_t[1024]; memcpy(clutCopy, rawClut, 1024); - render_->TextureImage(tex->texture, 0, texturePixels, 1, components, components2, dstFmt, clutCopy, false); + render_->TextureImage(tex->texture, 0, texturePixels, 1, components, components2, dstFmt, clutCopy, GLRAllocType::NEW, false); tex->lastFrame = gpuStats.numFlips; texCache_[clutId] = tex; diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index 5988ee5fa1..bb0676719c 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -777,7 +777,7 @@ void DrawEngineGLES::TessellationDataTransferGLES::SendDataToShader(const float uint8_t *pos_data = new uint8_t[size * sizeof(float) * 4]; memcpy(pos_data, pos, size * sizeof(float) * 4); data_tex[0] = renderManager_->CreateTexture(GL_TEXTURE_2D); - renderManager_->TextureImage(data_tex[0], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, pos_data, false); + renderManager_->TextureImage(data_tex[0], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, pos_data, GLRAllocType::NEW, false); renderManager_->FinalizeTexture(data_tex[0], 0, false); renderManager_->BindTexture(4, data_tex[0]); @@ -788,7 +788,7 @@ void DrawEngineGLES::TessellationDataTransferGLES::SendDataToShader(const float uint8_t *tex_data = new uint8_t[size * sizeof(float) * 4]; memcpy(tex_data, pos, size * sizeof(float) * 4); data_tex[1] = renderManager_->CreateTexture(GL_TEXTURE_2D); - renderManager_->TextureImage(data_tex[1], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, tex_data, false); + renderManager_->TextureImage(data_tex[1], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, tex_data, GLRAllocType::NEW, false); renderManager_->FinalizeTexture(data_tex[1], 0, false); renderManager_->BindTexture(5, data_tex[1]); } @@ -800,7 +800,7 @@ void DrawEngineGLES::TessellationDataTransferGLES::SendDataToShader(const float uint8_t *col_data = new uint8_t[sizeColor * sizeof(float) * 4]; memcpy(col_data, col, sizeColor * sizeof(float) * 4); - renderManager_->TextureImage(data_tex[2], 0, sizeColor, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, col_data, false); + renderManager_->TextureImage(data_tex[2], 0, sizeColor, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, col_data, GLRAllocType::NEW, false); renderManager_->FinalizeTexture(data_tex[2], 0, false); renderManager_->BindTexture(6, data_tex[2]); } diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index dd0a0c2473..351579744f 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -367,7 +367,7 @@ void FramebufferManagerGLES::MakePixelTexture(const u8 *srcPixels, GEBufferForma break; } } - render_->TextureImage(drawPixelsTex_, 0, texWidth, height, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, convBuf, false); + render_->TextureImage(drawPixelsTex_, 0, texWidth, height, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, convBuf, GLRAllocType::NEW, false); render_->FinalizeTexture(drawPixelsTex_, 0, false); // TODO: Return instead? diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index d16f14f372..1c1ff3551d 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -714,7 +714,7 @@ u8 *TextureCacheGLES::DecodeTextureLevelOld(GETextureFormat format, GEPaletteFor decPitch = bufw * pixelSize; } - uint8_t *texBuf = new uint8_t[std::max(w, bufw) * h * pixelSize]; + uint8_t *texBuf = (uint8_t *)AllocateAlignedMemory(std::max(w, bufw) * h * pixelSize, 16); DecodeTextureLevel(texBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false); return texBuf; } @@ -755,7 +755,7 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r PROFILE_THIS_SCOPE("replacetex"); int bpp = replaced.Format(level) == ReplacedTextureFormat::F_8888 ? 4 : 2; - uint8_t *rearrange = new uint8_t[w * h * bpp]; + uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * h * bpp, 16); replaced.Load(level, rearrange, bpp * w); pixelData = rearrange; @@ -785,7 +785,7 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r } if (scaleFactor > 1) { - uint8_t *rearrange = new uint8_t[w * scaleFactor * h * scaleFactor * 4]; + uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dstFmt, w, h, scaleFactor); pixelData = rearrange; delete [] finalBuf; @@ -817,9 +817,9 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r } else { PROFILE_THIS_SCOPE("loadtex"); if (IsFakeMipmapChange()) - render_->TextureImage(entry.textureName, 0, w, h, components, components2, dstFmt, pixelData); + render_->TextureImage(entry.textureName, 0, w, h, components, components2, dstFmt, pixelData, GLRAllocType::ALIGNED); else - render_->TextureImage(entry.textureName, level, w, h, components, components2, dstFmt, pixelData); + render_->TextureImage(entry.textureName, level, w, h, components, components2, dstFmt, pixelData, GLRAllocType::ALIGNED); } } diff --git a/GPU/Vulkan/DebugVisVulkan.cpp b/GPU/Vulkan/DebugVisVulkan.cpp index 7bfc54bdeb..9002f82a7d 100644 --- a/GPU/Vulkan/DebugVisVulkan.cpp +++ b/GPU/Vulkan/DebugVisVulkan.cpp @@ -58,7 +58,7 @@ void DrawAllocatorVis(UIContext *ui, GPUInterface *gpu) { uint32_t *wideData = (uint32_t *)initData.data(); // Convert to nice colors. If we really wanted to save on memory, we could use a 16-bit texture... - for (int j = 0; j < usage.size(); j++) { + for (size_t j = 0; j < usage.size(); j++) { switch (usage[j]) { case 0: wideData[j] = 0xFF333333; break; case 1: wideData[j] = 0xFF33FF33; break; diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index c8faa9958b..1053752af1 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -1,3 +1,4 @@ +#include "Common/MemoryUtil.h" #include "Core/Reporting.h" #include "GLQueueRunner.h" #include "GLRenderManager.h" @@ -65,7 +66,7 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { GLuint boundTexture = (GLuint)-1; bool allocatedTextures = false; - for (int i = 0; i < steps.size(); i++) { + for (size_t i = 0; i < steps.size(); i++) { const GLRInitStep &step = steps[i]; switch (step.stepType) { case GLRInitStepType::CREATE_TEXTURE: @@ -98,9 +99,9 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { GLRProgram *program = step.create_program.program; program->program = glCreateProgram(); _assert_msg_(G3D, step.create_program.num_shaders > 0, "Can't create a program with zero shaders"); - for (int i = 0; i < step.create_program.num_shaders; i++) { - _dbg_assert_msg_(G3D, step.create_program.shaders[i]->shader, "Can't create a program with a null shader"); - glAttachShader(program->program, step.create_program.shaders[i]->shader); + for (int j = 0; j < step.create_program.num_shaders; j++) { + _dbg_assert_msg_(G3D, step.create_program.shaders[j]->shader, "Can't create a program with a null shader"); + glAttachShader(program->program, step.create_program.shaders[j]->shader); } for (auto iter : program->semantics_) { @@ -161,15 +162,15 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { glUseProgram(program->program); // Query all the uniforms. - for (int i = 0; i < program->queries_.size(); i++) { - auto &x = program->queries_[i]; + for (size_t j = 0; j < program->queries_.size(); j++) { + auto &x = program->queries_[j]; assert(x.name); *x.dest = glGetUniformLocation(program->program, x.name); } // Run initializers. - for (int i = 0; i < program->initialize_.size(); i++) { - auto &init = program->initialize_[i]; + for (size_t j = 0; j < program->initialize_.size(); j++) { + auto &init = program->initialize_[j]; GLint uniform = *init.uniform; if (uniform != -1) { switch (init.type) { @@ -241,7 +242,11 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps) { // For things to show in RenderDoc, need to split into glTexImage2D(..., nullptr) and glTexSubImage. glTexImage2D(tex->target, step.texture_image.level, step.texture_image.internalFormat, step.texture_image.width, step.texture_image.height, 0, step.texture_image.format, step.texture_image.type, step.texture_image.data); allocatedTextures = true; - delete[] step.texture_image.data; + if (step.texture_image.allocType == GLRAllocType::ALIGNED) { + FreeAlignedMemory(step.texture_image.data); + } else { + delete[] step.texture_image.data; + } CHECK_GL_ERROR_IF_DEBUG(); tex->wrapS = GL_CLAMP_TO_EDGE; tex->wrapT = GL_CLAMP_TO_EDGE; @@ -399,7 +404,7 @@ void GLQueueRunner::InitCreateFramebuffer(const GLRInitStep &step) { } void GLQueueRunner::RunSteps(const std::vector &steps) { - for (int i = 0; i < steps.size(); i++) { + for (size_t i = 0; i < steps.size(); i++) { const GLRStep &step = *steps[i]; switch (step.stepType) { case GLRStepType::RENDER: diff --git a/ext/native/thin3d/GLQueueRunner.h b/ext/native/thin3d/GLQueueRunner.h index 63a17503c4..9119b0d05f 100644 --- a/ext/native/thin3d/GLQueueRunner.h +++ b/ext/native/thin3d/GLQueueRunner.h @@ -19,6 +19,10 @@ struct GLOffset2D { int x, y; }; +enum class GLRAllocType { + NEW, + ALIGNED, +}; class GLRShader; class GLRTexture; @@ -242,6 +246,7 @@ struct GLRInitStep { int level; int width; int height; + GLRAllocType allocType; bool linearFilter; uint8_t *data; // owned, delete[]-d } texture_image; diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 8b489c197d..c3b473e605 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -267,7 +267,7 @@ public: step.create_program.program->initialize_ = initalizers; step.create_program.support_dual_source = supportDualSource; _assert_msg_(G3D, shaders.size() > 0, "Can't create a program with zero shaders"); - for (int i = 0; i < shaders.size(); i++) { + for (size_t i = 0; i < shaders.size(); i++) { step.create_program.shaders[i] = shaders[i]; } #ifdef _DEBUG @@ -337,7 +337,7 @@ public: } // Takes ownership over the data pointer and delete[]-s it. - void TextureImage(GLRTexture *texture, int level, int width, int height, GLenum internalFormat, GLenum format, GLenum type, uint8_t *data, bool linearFilter = false) { + void TextureImage(GLRTexture *texture, int level, int width, int height, GLenum internalFormat, GLenum format, GLenum type, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW, bool linearFilter = false) { GLRInitStep step{ GLRInitStepType::TEXTURE_IMAGE }; step.texture_image.texture = texture; step.texture_image.data = data; @@ -347,6 +347,7 @@ public: step.texture_image.level = level; step.texture_image.width = width; step.texture_image.height = height; + step.texture_image.allocType = allocType; step.texture_image.linearFilter = linearFilter; initSteps_.push_back(step); } diff --git a/ext/native/thin3d/VulkanQueueRunner.cpp b/ext/native/thin3d/VulkanQueueRunner.cpp index 5cd4008386..6c04fd3d30 100644 --- a/ext/native/thin3d/VulkanQueueRunner.cpp +++ b/ext/native/thin3d/VulkanQueueRunner.cpp @@ -241,7 +241,7 @@ void VulkanQueueRunner::RunSteps(VkCommandBuffer cmd, const std::vector &steps) { ILOG("======================================="); - for (int i = 0; i < steps.size(); i++) { + for (size_t i = 0; i < steps.size(); i++) { const VKRStep &step = *steps[i]; switch (step.stepType) { case VKRStepType::RENDER: