mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Revive old alignment utility functions, give them better names.
This commit is contained in:
@@ -145,7 +145,7 @@ void VulkanPushPool::NextBlock(VkDeviceSize allocationSize) {
|
||||
}
|
||||
|
||||
double start = time_now_d();
|
||||
VkDeviceSize newBlockSize = std::max(originalBlockSize_ * 2, (VkDeviceSize)RoundUpToPowerOf2((uint32_t)allocationSize));
|
||||
VkDeviceSize newBlockSize = std::max(originalBlockSize_ * 2, (VkDeviceSize)RoundToNextPowerOf2((uint32_t)allocationSize));
|
||||
|
||||
// We're still here and ran off the end of blocks. Create a new one.
|
||||
blocks_.push_back(CreateBlock(newBlockSize));
|
||||
|
||||
+10
-5
@@ -7,12 +7,12 @@
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
inline bool isPowerOf2(int n) {
|
||||
inline constexpr bool isPowerOf2(int n) {
|
||||
return n == 1 || (n & (n - 1)) == 0;
|
||||
}
|
||||
|
||||
// Next power of 2.
|
||||
inline uint32_t RoundUpToPowerOf2(uint32_t v) {
|
||||
// Next power of 2 (NOTE: Not next multiple of a power of two, like the below function!)
|
||||
inline constexpr uint32_t RoundToNextPowerOf2(uint32_t v) {
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
@@ -23,8 +23,13 @@ inline uint32_t RoundUpToPowerOf2(uint32_t v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
inline uint32_t RoundUpToPowerOf2(uint32_t v, uint32_t power) {
|
||||
return (v + power - 1) & ~(power - 1);
|
||||
// NOTE: multiple must be a power of two!
|
||||
inline constexpr uint32_t RoundUpToMultipleOf(uint32_t v, uint32_t multiple) {
|
||||
return (v + multiple - 1) & ~(multiple - 1);
|
||||
}
|
||||
|
||||
inline constexpr uint32_t RoundDownToMultipleOf(uint32_t v, uint32_t multiple) {
|
||||
return v & ~(multiple - 1);
|
||||
}
|
||||
|
||||
// TODO: this should just use a bitscan.
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "Common/Data/Encoding/Utf8.h"
|
||||
#include "Common/Log.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Math/math_util.h"
|
||||
#include "Core/MemMap.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/MIPS/MIPSDebugInterface.h"
|
||||
@@ -191,7 +192,7 @@ void DisassemblyManager::analyze(u32 address, u32 size = 1024)
|
||||
{
|
||||
u32 end = address+size;
|
||||
|
||||
address &= ~3;
|
||||
address = RoundDownToMultipleOf(address, 4);
|
||||
u32 start = address;
|
||||
|
||||
while (address < end && start <= address)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Math/math_util.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/System.h"
|
||||
@@ -30,6 +31,10 @@
|
||||
#include "Core/HLE/sceKernelThread.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
// General note: Function addresses will be snapped appropriately to full instructions
|
||||
// if they are not divisible by four. Addresses downwards, sizes upwards.
|
||||
// It's recommended to use correctly aligned addresses instead.
|
||||
|
||||
DebuggerSubscriber *WebSocketHLEInit(DebuggerEventHandlerMap &map) {
|
||||
map["hle.thread.list"] = &WebSocketHLEThreadList;
|
||||
map["hle.thread.wake"] = &WebSocketHLEThreadWake;
|
||||
@@ -254,8 +259,8 @@ void WebSocketHLEFuncAdd(DebuggerRequest &req) {
|
||||
if (size == 0)
|
||||
size = -1;
|
||||
|
||||
addr &= ~0x3; // Align.
|
||||
size = (size + 3) & ~0x3; // Align.
|
||||
addr = RoundDownToMultipleOf(addr, 4);
|
||||
size = RoundUpToMultipleOf(size, 4);
|
||||
|
||||
std::string name;
|
||||
if (!req.ParamString("name", &name, DebuggerParamType::OPTIONAL))
|
||||
@@ -330,7 +335,7 @@ void WebSocketHLEFuncRemove(DebuggerRequest &req) {
|
||||
if (!req.ParamU32("address", &addr))
|
||||
return;
|
||||
|
||||
addr &= ~0x3; // Align.
|
||||
addr = RoundDownToMultipleOf(addr, 4);
|
||||
|
||||
u32 funcBegin = g_symbolMap->GetFunctionStart(addr);
|
||||
if (funcBegin == -1)
|
||||
@@ -424,8 +429,8 @@ void WebSocketHLEFuncRemoveRange(DebuggerRequest &req) {
|
||||
if (!req.ParamU32("size", &size))
|
||||
return;
|
||||
|
||||
addr &= ~0x3; // Align.
|
||||
size = (size + 3) & ~0x3; // Align.
|
||||
addr = RoundDownToMultipleOf(addr, 4);
|
||||
size = RoundUpToMultipleOf(size, 4);
|
||||
|
||||
if (!Memory::IsValidRange(addr, size))
|
||||
return req.Fail("Address or size outside valid memory");
|
||||
@@ -459,7 +464,7 @@ void WebSocketHLEFuncRename(DebuggerRequest &req) {
|
||||
if (!req.ParamString("name", &name))
|
||||
return;
|
||||
|
||||
addr &= ~0x3; // Align.
|
||||
addr = RoundDownToMultipleOf(addr, 4);
|
||||
|
||||
u32 funcBegin = g_symbolMap->GetFunctionStart(addr);
|
||||
if (funcBegin == -1)
|
||||
@@ -505,8 +510,8 @@ void WebSocketHLEFuncScan(DebuggerRequest &req) {
|
||||
if (!req.ParamU32("size", &size))
|
||||
return;
|
||||
|
||||
addr &= ~0x3; // Align.
|
||||
size = (size + 3) & ~0x3; // Align.
|
||||
addr = RoundDownToMultipleOf(addr, 4);
|
||||
size = RoundUpToMultipleOf(size, 4);
|
||||
|
||||
bool remove = false;
|
||||
if (!req.ParamBool("remove", &remove, DebuggerParamType::OPTIONAL))
|
||||
|
||||
@@ -1172,7 +1172,7 @@ void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate)
|
||||
}
|
||||
|
||||
if (needsDepthXSwizzle) {
|
||||
texWidth = RoundUpToPowerOf2(texWidth);
|
||||
texWidth = RoundToNextPowerOf2(texWidth);
|
||||
}
|
||||
|
||||
gstate_c.curTextureWidth = texWidth;
|
||||
@@ -2359,7 +2359,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
|
||||
int depalWidth = framebuffer->renderWidth;
|
||||
int texWidth = framebuffer->bufferWidth;
|
||||
if (needsDepthXSwizzle) {
|
||||
texWidth = RoundUpToPowerOf2(framebuffer->bufferWidth);
|
||||
texWidth = RoundToNextPowerOf2(framebuffer->bufferWidth);
|
||||
depalWidth = texWidth * framebuffer->renderScaleFactor;
|
||||
gstate_c.Dirty(DIRTY_UVSCALEOFFSET);
|
||||
}
|
||||
|
||||
@@ -582,8 +582,9 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
plan.GetMipSize(i, &mipWidth, &mipHeight);
|
||||
|
||||
int bpp = VkFormatBytesPerPixel(actualFmt);
|
||||
int optimalStrideAlignment = std::max(4, (int)vulkan->GetPhysicalDeviceProperties().properties.limits.optimalBufferCopyRowPitchAlignment);
|
||||
int byteStride = RoundUpToPowerOf2(mipWidth * bpp, optimalStrideAlignment); // output stride
|
||||
// RoundToNextPowerOf2 is probably not necessary as the optimal alignment is gonna be a power of 2.
|
||||
int optimalStrideAlignment = RoundToNextPowerOf2(std::max(4, (int)vulkan->GetPhysicalDeviceProperties().properties.limits.optimalBufferCopyRowPitchAlignment));
|
||||
int byteStride = RoundUpToMultipleOf(mipWidth * bpp, optimalStrideAlignment); // output stride
|
||||
int pixelStride = byteStride / bpp;
|
||||
int uploadSize = byteStride * mipHeight;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user