diff --git a/src/common/bitutils.h b/src/common/bitutils.h index 76e7dd74..3c207093 100644 --- a/src/common/bitutils.h +++ b/src/common/bitutils.h @@ -12,17 +12,17 @@ ALWAYS_INLINE unsigned CountLeadingZeros(T value) { #ifdef _WIN32 unsigned long index; - if constexpr (sizeof(value) >= sizeof(u64)) - _BitScanReverse64(&index, static_cast(static_cast::type>(value))); + if constexpr (sizeof(value) >= sizeof(uint64_t)) + _BitScanReverse64(&index, static_cast(static_cast::type>(value))); else - _BitScanReverse(&index, static_cast(static_cast::type>(value))); + _BitScanReverse(&index, static_cast(static_cast::type>(value))); return static_cast(index) ^ static_cast((sizeof(value) * 8u) - 1u); #else - if constexpr (sizeof(value) >= sizeof(u64)) - return static_cast(__builtin_clzl(static_cast(static_cast::type>(value)))); - else if constexpr (sizeof(value) == sizeof(u32)) - return static_cast(__builtin_clz(static_cast(static_cast::type>(value)))); - return static_cast(__builtin_clz(static_cast(static_cast::type>(value)))) & + if constexpr (sizeof(value) >= sizeof(uint64_t)) + return static_cast(__builtin_clzl(static_cast(static_cast::type>(value)))); + else if constexpr (sizeof(value) == sizeof(uint32_t)) + return static_cast(__builtin_clz(static_cast(static_cast::type>(value)))); + return static_cast(__builtin_clz(static_cast(static_cast::type>(value)))) & static_cast((sizeof(value) * 8u) - 1u); #endif } @@ -33,14 +33,14 @@ ALWAYS_INLINE unsigned CountTrailingZeros(T value) { #ifdef _WIN32 unsigned long index; - if constexpr (sizeof(value) >= sizeof(u64)) - _BitScanForward64(&index, static_cast(static_cast::type>(value))); + if constexpr (sizeof(value) >= sizeof(uint64_t)) + _BitScanForward64(&index, static_cast(static_cast::type>(value))); else - _BitScanForward(&index, static_cast(static_cast::type>(value))); + _BitScanForward(&index, static_cast(static_cast::type>(value))); return index; #else - if constexpr (sizeof(value) >= sizeof(u64)) - return static_cast(__builtin_ctzl(static_cast(static_cast::type>(value)))); - return static_cast(__builtin_ctz(static_cast(static_cast::type>(value)))); + if constexpr (sizeof(value) >= sizeof(uint64_t)) + return static_cast(__builtin_ctzl(static_cast(static_cast::type>(value)))); + return static_cast(__builtin_ctz(static_cast(static_cast::type>(value)))); #endif } diff --git a/src/common/byte_stream.cpp b/src/common/byte_stream.cpp index 43db8d75..b2cce1e9 100644 --- a/src/common/byte_stream.cpp +++ b/src/common/byte_stream.cpp @@ -33,7 +33,7 @@ public: virtual ~FileByteStream() override { fclose(m_pFile); } - bool ReadByte(u8* pDestByte) override + bool ReadByte(uint8_t* pDestByte) override { if (m_errorState) return false; @@ -47,24 +47,24 @@ public: return true; } - u32 Read(void* pDestination, u32 ByteCount) override + uint32_t Read(void* pDestination, uint32_t ByteCount) override { if (m_errorState) return 0; - u32 readCount = (u32)fread(pDestination, 1, ByteCount, m_pFile); + uint32_t readCount = (uint32_t)fread(pDestination, 1, ByteCount, m_pFile); if (readCount != ByteCount && ferror(m_pFile) != 0) m_errorState = true; return readCount; } - bool Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead) override + bool Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead) override { if (m_errorState) return false; - u32 bytesRead = Read(pDestination, ByteCount); + uint32_t bytesRead = Read(pDestination, ByteCount); if (pNumberOfBytesRead != nullptr) *pNumberOfBytesRead = bytesRead; @@ -78,7 +78,7 @@ public: return true; } - bool WriteByte(u8 SourceByte) override + bool WriteByte(uint8_t SourceByte) override { if (m_errorState) return false; @@ -92,24 +92,24 @@ public: return true; } - u32 Write(const void* pSource, u32 ByteCount) override + uint32_t Write(const void* pSource, uint32_t ByteCount) override { if (m_errorState) return 0; - u32 writeCount = (u32)fwrite(pSource, 1, ByteCount, m_pFile); + uint32_t writeCount = (uint32_t)fwrite(pSource, 1, ByteCount, m_pFile); if (writeCount != ByteCount) m_errorState = true; return writeCount; } - bool Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten) override + bool Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten) override { if (m_errorState) return false; - u32 bytesWritten = Write(pSource, ByteCount); + uint32_t bytesWritten = Write(pSource, ByteCount); if (pNumberOfBytesWritten != nullptr) *pNumberOfBytesWritten = bytesWritten; @@ -124,7 +124,7 @@ public: } #if defined(_WIN32) - bool SeekAbsolute(u64 Offset) override + bool SeekAbsolute(uint64_t Offset) override { if (m_errorState) return false; @@ -138,7 +138,7 @@ public: return true; } - bool SeekRelative(s64 Offset) override + bool SeekRelative(int64_t Offset) override { if (m_errorState) return false; @@ -152,19 +152,19 @@ public: return true; } - u64 GetPosition() const override { return _ftelli64(m_pFile); } + uint64_t GetPosition() const override { return _ftelli64(m_pFile); } - u64 GetSize() const override + uint64_t GetSize() const override { - s64 OldPos = _ftelli64(m_pFile); + int64_t OldPos = _ftelli64(m_pFile); _fseeki64(m_pFile, 0, SEEK_END); - s64 Size = _ftelli64(m_pFile); + int64_t Size = _ftelli64(m_pFile); _fseeki64(m_pFile, OldPos, SEEK_SET); - return (u64)Size; + return (uint64_t)Size; } #else - bool SeekAbsolute(u64 Offset) override + bool SeekAbsolute(uint64_t Offset) override { if (m_errorState) return false; @@ -178,7 +178,7 @@ public: return true; } - bool SeekRelative(s64 Offset) override + bool SeekRelative(int64_t Offset) override { if (m_errorState) return false; @@ -192,15 +192,15 @@ public: return true; } - u64 GetPosition() const override { return static_cast(ftello(m_pFile)); } + uint64_t GetPosition() const override { return static_cast(ftello(m_pFile)); } - u64 GetSize() const override + uint64_t GetSize() const override { off_t OldPos = ftello(m_pFile); fseeko(m_pFile, 0, SEEK_END); off_t Size = ftello(m_pFile); fseeko(m_pFile, OldPos, SEEK_SET); - return (u64)Size; + return (uint64_t)Size; } #endif bool Flush() override @@ -297,16 +297,16 @@ private: std::string m_temporaryFileName; }; -MemoryByteStream::MemoryByteStream(void* pMemory, u32 MemSize) +MemoryByteStream::MemoryByteStream(void* pMemory, uint32_t MemSize) { m_iPosition = 0; m_iSize = MemSize; - m_pMemory = (u8*)pMemory; + m_pMemory = (uint8_t*)pMemory; } MemoryByteStream::~MemoryByteStream() {} -bool MemoryByteStream::ReadByte(u8* pDestByte) +bool MemoryByteStream::ReadByte(uint8_t* pDestByte) { if (m_iPosition < m_iSize) { @@ -317,9 +317,9 @@ bool MemoryByteStream::ReadByte(u8* pDestByte) return false; } -u32 MemoryByteStream::Read(void* pDestination, u32 ByteCount) +uint32_t MemoryByteStream::Read(void* pDestination, uint32_t ByteCount) { - u32 sz = ByteCount; + uint32_t sz = ByteCount; if ((m_iPosition + ByteCount) > m_iSize) sz = m_iSize - m_iPosition; @@ -332,16 +332,16 @@ u32 MemoryByteStream::Read(void* pDestination, u32 ByteCount) return sz; } -bool MemoryByteStream::Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead /* = nullptr */) +bool MemoryByteStream::Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead /* = nullptr */) { - u32 r = Read(pDestination, ByteCount); + uint32_t r = Read(pDestination, ByteCount); if (pNumberOfBytesRead != NULL) *pNumberOfBytesRead = r; return (r == ByteCount); } -bool MemoryByteStream::WriteByte(u8 SourceByte) +bool MemoryByteStream::WriteByte(uint8_t SourceByte) { if (m_iPosition < m_iSize) { @@ -352,9 +352,9 @@ bool MemoryByteStream::WriteByte(u8 SourceByte) return false; } -u32 MemoryByteStream::Write(const void* pSource, u32 ByteCount) +uint32_t MemoryByteStream::Write(const void* pSource, uint32_t ByteCount) { - u32 sz = ByteCount; + uint32_t sz = ByteCount; if ((m_iPosition + ByteCount) > m_iSize) sz = m_iSize - m_iPosition; @@ -367,18 +367,18 @@ u32 MemoryByteStream::Write(const void* pSource, u32 ByteCount) return sz; } -bool MemoryByteStream::Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten /* = nullptr */) +bool MemoryByteStream::Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten /* = nullptr */) { - u32 r = Write(pSource, ByteCount); + uint32_t r = Write(pSource, ByteCount); if (pNumberOfBytesWritten != nullptr) *pNumberOfBytesWritten = r; return (r == ByteCount); } -bool MemoryByteStream::SeekAbsolute(u64 Offset) +bool MemoryByteStream::SeekAbsolute(uint64_t Offset) { - u32 Offset32 = (u32)Offset; + uint32_t Offset32 = (uint32_t)Offset; if (Offset32 > m_iSize) return false; @@ -386,24 +386,24 @@ bool MemoryByteStream::SeekAbsolute(u64 Offset) return true; } -bool MemoryByteStream::SeekRelative(s64 Offset) +bool MemoryByteStream::SeekRelative(int64_t Offset) { - s32 Offset32 = (s32)Offset; - if ((Offset32 < 0 && -Offset32 > (s32)m_iPosition) || (u32)((s32)m_iPosition + Offset32) > m_iSize) + int32_t Offset32 = (int32_t)Offset; + if ((Offset32 < 0 && -Offset32 > (int32_t)m_iPosition) || (uint32_t)((int32_t)m_iPosition + Offset32) > m_iSize) return false; m_iPosition += Offset32; return true; } -u64 MemoryByteStream::GetSize() const +uint64_t MemoryByteStream::GetSize() const { - return (u64)m_iSize; + return (uint64_t)m_iSize; } -u64 MemoryByteStream::GetPosition() const +uint64_t MemoryByteStream::GetPosition() const { - return (u64)m_iPosition; + return (uint64_t)m_iPosition; } bool MemoryByteStream::Flush() @@ -421,16 +421,16 @@ bool MemoryByteStream::Discard() return false; } -ReadOnlyMemoryByteStream::ReadOnlyMemoryByteStream(const void* pMemory, u32 MemSize) +ReadOnlyMemoryByteStream::ReadOnlyMemoryByteStream(const void* pMemory, uint32_t MemSize) { m_iPosition = 0; m_iSize = MemSize; - m_pMemory = reinterpret_cast(pMemory); + m_pMemory = reinterpret_cast(pMemory); } ReadOnlyMemoryByteStream::~ReadOnlyMemoryByteStream() {} -bool ReadOnlyMemoryByteStream::ReadByte(u8* pDestByte) +bool ReadOnlyMemoryByteStream::ReadByte(uint8_t* pDestByte) { if (m_iPosition < m_iSize) { @@ -441,9 +441,9 @@ bool ReadOnlyMemoryByteStream::ReadByte(u8* pDestByte) return false; } -u32 ReadOnlyMemoryByteStream::Read(void* pDestination, u32 ByteCount) +uint32_t ReadOnlyMemoryByteStream::Read(void* pDestination, uint32_t ByteCount) { - u32 sz = ByteCount; + uint32_t sz = ByteCount; if ((m_iPosition + ByteCount) > m_iSize) sz = m_iSize - m_iPosition; @@ -456,33 +456,33 @@ u32 ReadOnlyMemoryByteStream::Read(void* pDestination, u32 ByteCount) return sz; } -bool ReadOnlyMemoryByteStream::Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead /* = nullptr */) +bool ReadOnlyMemoryByteStream::Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead /* = nullptr */) { - u32 r = Read(pDestination, ByteCount); + uint32_t r = Read(pDestination, ByteCount); if (pNumberOfBytesRead != nullptr) *pNumberOfBytesRead = r; return (r == ByteCount); } -bool ReadOnlyMemoryByteStream::WriteByte(u8 SourceByte) +bool ReadOnlyMemoryByteStream::WriteByte(uint8_t SourceByte) { return false; } -u32 ReadOnlyMemoryByteStream::Write(const void* pSource, u32 ByteCount) +uint32_t ReadOnlyMemoryByteStream::Write(const void* pSource, uint32_t ByteCount) { return 0; } -bool ReadOnlyMemoryByteStream::Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten /* = nullptr */) +bool ReadOnlyMemoryByteStream::Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten /* = nullptr */) { return false; } -bool ReadOnlyMemoryByteStream::SeekAbsolute(u64 Offset) +bool ReadOnlyMemoryByteStream::SeekAbsolute(uint64_t Offset) { - u32 Offset32 = (u32)Offset; + uint32_t Offset32 = (uint32_t)Offset; if (Offset32 > m_iSize) return false; @@ -490,24 +490,24 @@ bool ReadOnlyMemoryByteStream::SeekAbsolute(u64 Offset) return true; } -bool ReadOnlyMemoryByteStream::SeekRelative(s64 Offset) +bool ReadOnlyMemoryByteStream::SeekRelative(int64_t Offset) { - s32 Offset32 = (s32)Offset; - if ((Offset32 < 0 && -Offset32 > (s32)m_iPosition) || (u32)((s32)m_iPosition + Offset32) > m_iSize) + int32_t Offset32 = (int32_t)Offset; + if ((Offset32 < 0 && -Offset32 > (int32_t)m_iPosition) || (uint32_t)((int32_t)m_iPosition + Offset32) > m_iSize) return false; m_iPosition += Offset32; return true; } -u64 ReadOnlyMemoryByteStream::GetSize() const +uint64_t ReadOnlyMemoryByteStream::GetSize() const { - return (u64)m_iSize; + return (uint64_t)m_iSize; } -u64 ReadOnlyMemoryByteStream::GetPosition() const +uint64_t ReadOnlyMemoryByteStream::GetPosition() const { - return (u64)m_iPosition; + return (uint64_t)m_iPosition; } bool ReadOnlyMemoryByteStream::Flush() @@ -525,7 +525,7 @@ bool ReadOnlyMemoryByteStream::Discard() return false; } -GrowableMemoryByteStream::GrowableMemoryByteStream(void* pInitialMem, u32 InitialMemSize) +GrowableMemoryByteStream::GrowableMemoryByteStream(void* pInitialMem, uint32_t InitialMemSize) { m_iPosition = 0; m_iSize = 0; @@ -534,12 +534,12 @@ GrowableMemoryByteStream::GrowableMemoryByteStream(void* pInitialMem, u32 Initia { m_iMemorySize = InitialMemSize; m_pPrivateMemory = nullptr; - m_pMemory = (u8*)pInitialMem; + m_pMemory = (uint8_t*)pInitialMem; } else { - m_iMemorySize = std::max(InitialMemSize, (u32)64); - m_pPrivateMemory = m_pMemory = (u8*)std::malloc(m_iMemorySize); + m_iMemorySize = std::max(InitialMemSize, (uint32_t)64); + m_pPrivateMemory = m_pMemory = (uint8_t*)std::malloc(m_iMemorySize); } } @@ -549,7 +549,7 @@ GrowableMemoryByteStream::~GrowableMemoryByteStream() std::free(m_pPrivateMemory); } -void GrowableMemoryByteStream::Resize(u32 new_size) +void GrowableMemoryByteStream::Resize(uint32_t new_size) { if (new_size > m_iMemorySize) ResizeMemory(new_size); @@ -557,26 +557,26 @@ void GrowableMemoryByteStream::Resize(u32 new_size) m_iSize = new_size; } -void GrowableMemoryByteStream::ResizeMemory(u32 new_size) +void GrowableMemoryByteStream::ResizeMemory(uint32_t new_size) { if (new_size == m_iMemorySize) return; if (m_pPrivateMemory == nullptr) { - m_pPrivateMemory = (u8*)std::malloc(new_size); + m_pPrivateMemory = (uint8_t*)std::malloc(new_size); std::memcpy(m_pPrivateMemory, m_pMemory, m_iSize); m_pMemory = m_pPrivateMemory; m_iMemorySize = new_size; } else { - m_pPrivateMemory = m_pMemory = (u8*)std::realloc(m_pPrivateMemory, new_size); + m_pPrivateMemory = m_pMemory = (uint8_t*)std::realloc(m_pPrivateMemory, new_size); m_iMemorySize = new_size; } } -bool GrowableMemoryByteStream::ReadByte(u8* pDestByte) +bool GrowableMemoryByteStream::ReadByte(uint8_t* pDestByte) { if (m_iPosition < m_iSize) { @@ -587,9 +587,9 @@ bool GrowableMemoryByteStream::ReadByte(u8* pDestByte) return false; } -u32 GrowableMemoryByteStream::Read(void* pDestination, u32 ByteCount) +uint32_t GrowableMemoryByteStream::Read(void* pDestination, uint32_t ByteCount) { - u32 sz = ByteCount; + uint32_t sz = ByteCount; if ((m_iPosition + ByteCount) > m_iSize) sz = m_iSize - m_iPosition; @@ -602,16 +602,16 @@ u32 GrowableMemoryByteStream::Read(void* pDestination, u32 ByteCount) return sz; } -bool GrowableMemoryByteStream::Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead /* = nullptr */) +bool GrowableMemoryByteStream::Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead /* = nullptr */) { - u32 r = Read(pDestination, ByteCount); + uint32_t r = Read(pDestination, ByteCount); if (pNumberOfBytesRead != NULL) *pNumberOfBytesRead = r; return (r == ByteCount); } -bool GrowableMemoryByteStream::WriteByte(u8 SourceByte) +bool GrowableMemoryByteStream::WriteByte(uint8_t SourceByte) { if (m_iPosition == m_iMemorySize) Grow(1); @@ -621,7 +621,7 @@ bool GrowableMemoryByteStream::WriteByte(u8 SourceByte) return true; } -u32 GrowableMemoryByteStream::Write(const void* pSource, u32 ByteCount) +uint32_t GrowableMemoryByteStream::Write(const void* pSource, uint32_t ByteCount) { if ((m_iPosition + ByteCount) > m_iMemorySize) Grow(ByteCount); @@ -632,18 +632,18 @@ u32 GrowableMemoryByteStream::Write(const void* pSource, u32 ByteCount) return ByteCount; } -bool GrowableMemoryByteStream::Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten /* = nullptr */) +bool GrowableMemoryByteStream::Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten /* = nullptr */) { - u32 r = Write(pSource, ByteCount); + uint32_t r = Write(pSource, ByteCount); if (pNumberOfBytesWritten != nullptr) *pNumberOfBytesWritten = r; return (r == ByteCount); } -bool GrowableMemoryByteStream::SeekAbsolute(u64 Offset) +bool GrowableMemoryByteStream::SeekAbsolute(uint64_t Offset) { - u32 Offset32 = (u32)Offset; + uint32_t Offset32 = (uint32_t)Offset; if (Offset32 > m_iSize) return false; @@ -651,24 +651,24 @@ bool GrowableMemoryByteStream::SeekAbsolute(u64 Offset) return true; } -bool GrowableMemoryByteStream::SeekRelative(s64 Offset) +bool GrowableMemoryByteStream::SeekRelative(int64_t Offset) { - s32 Offset32 = (s32)Offset; - if ((Offset32 < 0 && -Offset32 > (s32)m_iPosition) || (u32)((s32)m_iPosition + Offset32) > m_iSize) + int32_t Offset32 = (int32_t)Offset; + if ((Offset32 < 0 && -Offset32 > (int32_t)m_iPosition) || (uint32_t)((int32_t)m_iPosition + Offset32) > m_iSize) return false; m_iPosition += Offset32; return true; } -u64 GrowableMemoryByteStream::GetSize() const +uint64_t GrowableMemoryByteStream::GetSize() const { - return (u64)m_iSize; + return (uint64_t)m_iSize; } -u64 GrowableMemoryByteStream::GetPosition() const +uint64_t GrowableMemoryByteStream::GetPosition() const { - return (u64)m_iPosition; + return (uint64_t)m_iPosition; } bool GrowableMemoryByteStream::Flush() @@ -686,15 +686,15 @@ bool GrowableMemoryByteStream::Discard() return false; } -void GrowableMemoryByteStream::Grow(u32 MinimumGrowth) +void GrowableMemoryByteStream::Grow(uint32_t MinimumGrowth) { - u32 NewSize = std::max(m_iMemorySize + MinimumGrowth, m_iMemorySize * 2); + uint32_t NewSize = std::max(m_iMemorySize + MinimumGrowth, m_iMemorySize * 2); ResizeMemory(NewSize); } #if defined(_WIN32) -std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 openMode) +std::unique_ptr ByteStream_OpenFileStream(const char* fileName, uint32_t openMode) { if ((openMode & (BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE)) == BYTESTREAM_OPEN_WRITE) { @@ -704,7 +704,7 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 } char modeString[16]; - u32 modeStringLength = 0; + uint32_t modeStringLength = 0; if (openMode & BYTESTREAM_OPEN_WRITE) { @@ -743,8 +743,8 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 if (openMode & BYTESTREAM_OPEN_CREATE_PATH) { - u32 i; - u32 fileNameLength = static_cast(std::strlen(fileName)); + uint32_t i; + uint32_t fileNameLength = static_cast(std::strlen(fileName)); char* tempStr = (char*)alloca(fileNameLength + 1); // check if it starts with a drive letter. if so, skip ahead @@ -806,7 +806,7 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 if (openMode & BYTESTREAM_OPEN_ATOMIC_UPDATE) { // generate the temporary file name - u32 fileNameLength = static_cast(std::strlen(fileName)); + uint32_t fileNameLength = static_cast(std::strlen(fileName)); char* temporaryFileName = (char*)alloca(fileNameLength + 8); std::snprintf(temporaryFileName, fileNameLength + 8, "%s.XXXXXX", fileName); @@ -865,14 +865,14 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 } static const size_t BUFFERSIZE = 4096; - u8 buffer[BUFFERSIZE]; + uint8_t buffer[BUFFERSIZE]; while (!rfeof(pOriginalFile)) { - size_t nBytes = rfread(buffer, BUFFERSIZE, sizeof(u8), pOriginalFile); + size_t nBytes = rfread(buffer, BUFFERSIZE, sizeof(uint8_t), pOriginalFile); if (nBytes == 0) break; - if (pStream->Write(buffer, (u32)nBytes) != (u32)nBytes) + if (pStream->Write(buffer, (uint32_t)nBytes) != (uint32_t)nBytes) { pStream->Discard(); rfclose(pOriginalFile); @@ -902,7 +902,7 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 #else -std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 openMode) +std::unique_ptr ByteStream_OpenFileStream(const char* fileName, uint32_t openMode) { if ((openMode & (BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE)) == BYTESTREAM_OPEN_WRITE) { @@ -912,7 +912,7 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 } char modeString[16]; - u32 modeStringLength = 0; + uint32_t modeStringLength = 0; if (openMode & BYTESTREAM_OPEN_WRITE) { @@ -936,8 +936,8 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 if (openMode & BYTESTREAM_OPEN_CREATE_PATH) { - u32 i; - const u32 fileNameLength = static_cast(std::strlen(fileName)); + uint32_t i; + const uint32_t fileNameLength = static_cast(std::strlen(fileName)); char* tempStr = (char*)alloca(fileNameLength + 1); // step through each path component, create folders as necessary @@ -979,7 +979,7 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 if (openMode & BYTESTREAM_OPEN_ATOMIC_UPDATE) { // generate the temporary file name - const u32 fileNameLength = static_cast(std::strlen(fileName)); + const uint32_t fileNameLength = static_cast(std::strlen(fileName)); char* temporaryFileName = (char*)alloca(fileNameLength + 8); std::snprintf(temporaryFileName, fileNameLength + 8, "%s.XXXXXX", fileName); @@ -1014,14 +1014,14 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 } static const size_t BUFFERSIZE = 4096; - u8 buffer[BUFFERSIZE]; + uint8_t buffer[BUFFERSIZE]; while (!rfeof(pOriginalFile)) { - size_t nBytes = rfread(buffer, BUFFERSIZE, sizeof(u8), pOriginalFile); + size_t nBytes = rfread(buffer, BUFFERSIZE, sizeof(uint8_t), pOriginalFile); if (nBytes == 0) break; - if (pStream->Write(buffer, (u32)nBytes) != (u32)nBytes) + if (pStream->Write(buffer, (uint32_t)nBytes) != (uint32_t)nBytes) { pStream->SetErrorState(); rfclose(pOriginalFile); @@ -1048,17 +1048,17 @@ std::unique_ptr ByteStream_OpenFileStream(const char* fileName, u32 #endif -std::unique_ptr ByteStream_CreateMemoryStream(void* pMemory, u32 Size) +std::unique_ptr ByteStream_CreateMemoryStream(void* pMemory, uint32_t Size) { return std::make_unique(pMemory, Size); } -std::unique_ptr ByteStream_CreateReadOnlyMemoryStream(const void* pMemory, u32 Size) +std::unique_ptr ByteStream_CreateReadOnlyMemoryStream(const void* pMemory, uint32_t Size) { return std::make_unique(pMemory, Size); } -std::unique_ptr ByteStream_CreateGrowableMemoryStream(void* pInitialMemory, u32 InitialSize) +std::unique_ptr ByteStream_CreateGrowableMemoryStream(void* pInitialMemory, uint32_t InitialSize) { return std::make_unique(pInitialMemory, InitialSize); } diff --git a/src/common/byte_stream.h b/src/common/byte_stream.h index d780f209..52bdfd1f 100644 --- a/src/common/byte_stream.h +++ b/src/common/byte_stream.h @@ -3,7 +3,7 @@ #include // base byte stream creation functions -inline constexpr u32 BYTESTREAM_OPEN_READ = 1, // open stream for writing +inline constexpr uint32_t BYTESTREAM_OPEN_READ = 1, // open stream for writing BYTESTREAM_OPEN_WRITE = 2, // open stream for writing BYTESTREAM_OPEN_APPEND = 4, // seek to the end BYTESTREAM_OPEN_TRUNCATE = 8, // truncate the file, seek to start @@ -19,35 +19,35 @@ public: virtual ~ByteStream() {} // reads a single byte from the stream. - virtual bool ReadByte(u8* pDestByte) = 0; + virtual bool ReadByte(uint8_t* pDestByte) = 0; // read bytes from this stream. returns the number of bytes read, if this isn't equal to the requested size, an error // or EOF occurred. - virtual u32 Read(void* pDestination, u32 ByteCount) = 0; + virtual uint32_t Read(void* pDestination, uint32_t ByteCount) = 0; // read bytes from this stream, optionally returning the number of bytes read. - virtual bool Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead = nullptr) = 0; + virtual bool Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead = nullptr) = 0; // writes a single byte to the stream. - virtual bool WriteByte(u8 SourceByte) = 0; + virtual bool WriteByte(uint8_t SourceByte) = 0; // write bytes to this stream, returns the number of bytes written. if this isn't equal to the requested size, a // buffer overflow, or write error occurred. - virtual u32 Write(const void* pSource, u32 ByteCount) = 0; + virtual uint32_t Write(const void* pSource, uint32_t ByteCount) = 0; // write bytes to this stream, optionally returning the number of bytes written. - virtual bool Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten = nullptr) = 0; + virtual bool Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten = nullptr) = 0; // seeks to the specified position in the stream // if seek failed, returns false. - virtual bool SeekAbsolute(u64 Offset) = 0; - virtual bool SeekRelative(s64 Offset) = 0; + virtual bool SeekAbsolute(uint64_t Offset) = 0; + virtual bool SeekRelative(int64_t Offset) = 0; // gets the current offset in the stream - virtual u64 GetPosition() const = 0; + virtual uint64_t GetPosition() const = 0; // gets the size of the stream - virtual u64 GetSize() const = 0; + virtual uint64_t GetSize() const = 0; // flush any changes to the stream to disk virtual bool Flush() = 0; @@ -75,101 +75,101 @@ protected: class MemoryByteStream final : public ByteStream { public: - MemoryByteStream(void* pMemory, u32 MemSize); + MemoryByteStream(void* pMemory, uint32_t MemSize); ~MemoryByteStream() override; - bool ReadByte(u8* pDestByte) override; - u32 Read(void* pDestination, u32 ByteCount) override; - bool Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead) override; - bool WriteByte(u8 SourceByte) override; - u32 Write(const void* pSource, u32 ByteCount) override; - bool Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten) override; - bool SeekAbsolute(u64 Offset) override; - bool SeekRelative(s64 Offset) override; - u64 GetSize() const override; - u64 GetPosition() const override; + bool ReadByte(uint8_t* pDestByte) override; + uint32_t Read(void* pDestination, uint32_t ByteCount) override; + bool Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead) override; + bool WriteByte(uint8_t SourceByte) override; + uint32_t Write(const void* pSource, uint32_t ByteCount) override; + bool Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten) override; + bool SeekAbsolute(uint64_t Offset) override; + bool SeekRelative(int64_t Offset) override; + uint64_t GetSize() const override; + uint64_t GetPosition() const override; bool Flush() override; bool Commit() override; bool Discard() override; private: - u8* m_pMemory; - u32 m_iPosition; - u32 m_iSize; + uint8_t* m_pMemory; + uint32_t m_iPosition; + uint32_t m_iSize; }; class ReadOnlyMemoryByteStream final : public ByteStream { public: - ReadOnlyMemoryByteStream(const void* pMemory, u32 MemSize); + ReadOnlyMemoryByteStream(const void* pMemory, uint32_t MemSize); ~ReadOnlyMemoryByteStream() override; - bool ReadByte(u8* pDestByte) override; - u32 Read(void* pDestination, u32 ByteCount) override; - bool Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead) override; - bool WriteByte(u8 SourceByte) override; - u32 Write(const void* pSource, u32 ByteCount) override; - bool Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten) override; - bool SeekAbsolute(u64 Offset) override; - bool SeekRelative(s64 Offset) override; - u64 GetSize() const override; - u64 GetPosition() const override; + bool ReadByte(uint8_t* pDestByte) override; + uint32_t Read(void* pDestination, uint32_t ByteCount) override; + bool Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead) override; + bool WriteByte(uint8_t SourceByte) override; + uint32_t Write(const void* pSource, uint32_t ByteCount) override; + bool Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten) override; + bool SeekAbsolute(uint64_t Offset) override; + bool SeekRelative(int64_t Offset) override; + uint64_t GetSize() const override; + uint64_t GetPosition() const override; bool Flush() override; bool Commit() override; bool Discard() override; private: - const u8* m_pMemory; - u32 m_iPosition; - u32 m_iSize; + const uint8_t* m_pMemory; + uint32_t m_iPosition; + uint32_t m_iSize; }; class GrowableMemoryByteStream final : public ByteStream { public: - GrowableMemoryByteStream(void* pInitialMem, u32 InitialMemSize); + GrowableMemoryByteStream(void* pInitialMem, uint32_t InitialMemSize); ~GrowableMemoryByteStream() override; - void Resize(u32 new_size); - void ResizeMemory(u32 new_size); + void Resize(uint32_t new_size); + void ResizeMemory(uint32_t new_size); - bool ReadByte(u8* pDestByte) override; - u32 Read(void* pDestination, u32 ByteCount) override; - bool Read2(void* pDestination, u32 ByteCount, u32* pNumberOfBytesRead) override; - bool WriteByte(u8 SourceByte) override; - u32 Write(const void* pSource, u32 ByteCount) override; - bool Write2(const void* pSource, u32 ByteCount, u32* pNumberOfBytesWritten) override; - bool SeekAbsolute(u64 Offset) override; - bool SeekRelative(s64 Offset) override; - u64 GetSize() const override; - u64 GetPosition() const override; + bool ReadByte(uint8_t* pDestByte) override; + uint32_t Read(void* pDestination, uint32_t ByteCount) override; + bool Read2(void* pDestination, uint32_t ByteCount, uint32_t* pNumberOfBytesRead) override; + bool WriteByte(uint8_t SourceByte) override; + uint32_t Write(const void* pSource, uint32_t ByteCount) override; + bool Write2(const void* pSource, uint32_t ByteCount, uint32_t* pNumberOfBytesWritten) override; + bool SeekAbsolute(uint64_t Offset) override; + bool SeekRelative(int64_t Offset) override; + uint64_t GetSize() const override; + uint64_t GetPosition() const override; bool Flush() override; bool Commit() override; bool Discard() override; private: - void Grow(u32 MinimumGrowth); + void Grow(uint32_t MinimumGrowth); - u8* m_pPrivateMemory; - u8* m_pMemory; - u32 m_iPosition; - u32 m_iSize; - u32 m_iMemorySize; + uint8_t* m_pPrivateMemory; + uint8_t* m_pMemory; + uint32_t m_iPosition; + uint32_t m_iSize; + uint32_t m_iMemorySize; }; // base byte stream creation functions // opens a local file-based stream. fills in error if passed, and returns false if the file cannot be opened. -std::unique_ptr ByteStream_OpenFileStream(const char* FileName, u32 OpenMode); +std::unique_ptr ByteStream_OpenFileStream(const char* FileName, uint32_t OpenMode); // memory byte stream, caller is responsible for management, therefore it can be located on either the stack or on the // heap. -std::unique_ptr ByteStream_CreateMemoryStream(void* pMemory, u32 Size); +std::unique_ptr ByteStream_CreateMemoryStream(void* pMemory, uint32_t Size); // a growable memory byte stream will automatically allocate its own memory if the provided memory is overflowed. // a "pure heap" buffer, i.e. a buffer completely managed by this implementation, can be created by supplying a NULL // pointer and initialSize of zero. -std::unique_ptr ByteStream_CreateGrowableMemoryStream(void* pInitialMemory, u32 InitialSize); +std::unique_ptr ByteStream_CreateGrowableMemoryStream(void* pInitialMemory, uint32_t InitialSize); std::unique_ptr ByteStream_CreateGrowableMemoryStream(); // readable memory stream -std::unique_ptr ByteStream_CreateReadOnlyMemoryStream(const void* pMemory, u32 Size); +std::unique_ptr ByteStream_CreateReadOnlyMemoryStream(const void* pMemory, uint32_t Size); diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp index 3881bf03..eb57e056 100644 --- a/src/common/cd_image.cpp +++ b/src/common/cd_image.cpp @@ -10,10 +10,10 @@ CDImage::CDImage(OpenFlags open_flags) : m_open_flags(open_flags) {} CDImage::~CDImage() = default; -u32 CDImage::GetBytesPerSector(TrackMode mode) +uint32_t CDImage::GetBytesPerSector(TrackMode mode) { - static constexpr std::array sizes = {{2352, 2048, 2352, 2336, 2048, 2324, 2332, 2352}}; - return sizes[static_cast(mode)]; + static constexpr std::array sizes = {{2352, 2048, 2352, 2336, 2048, 2324, 2332, 2352}}; + return sizes[static_cast(mode)]; } std::unique_ptr CDImage::Open(const char* filename, OpenFlags open_flags, Common::Error* error) @@ -72,22 +72,22 @@ std::unique_ptr CDImage::Open(const char* filename, OpenFlags open_flag return nullptr; } -CDImage::Position CDImage::GetTrackStartMSFPosition(u8 track) const +CDImage::Position CDImage::GetTrackStartMSFPosition(uint8_t track) const { return Position::FromLBA(m_tracks[track - 1].start_lba); } -CDImage::LBA CDImage::GetTrackLength(u8 track) const +CDImage::LBA CDImage::GetTrackLength(uint8_t track) const { return m_tracks[track - 1].length; } -CDImage::TrackMode CDImage::GetTrackMode(u8 track) const +CDImage::TrackMode CDImage::GetTrackMode(uint8_t track) const { return m_tracks[track - 1].mode; } -CDImage::LBA CDImage::GetTrackIndexPosition(u8 track, u8 index) const +CDImage::LBA CDImage::GetTrackIndexPosition(uint8_t track, uint8_t index) const { for (const Index& current_index : m_indices) { @@ -98,7 +98,7 @@ CDImage::LBA CDImage::GetTrackIndexPosition(u8 track, u8 index) const return m_lba_count; } -CDImage::LBA CDImage::GetTrackIndexLength(u8 track, u8 index) const +CDImage::LBA CDImage::GetTrackIndexLength(uint8_t track, uint8_t index) const { for (const Index& current_index : m_indices) { @@ -109,12 +109,12 @@ CDImage::LBA CDImage::GetTrackIndexLength(u8 track, u8 index) const return 0; } -const CDImage::CDImage::Track& CDImage::GetTrack(u32 track) const +const CDImage::CDImage::Track& CDImage::GetTrack(uint32_t track) const { return m_tracks[track - 1]; } -const CDImage::CDImage::Index& CDImage::GetIndex(u32 i) const +const CDImage::CDImage::Index& CDImage::GetIndex(uint32_t i) const { return m_indices[i]; } @@ -145,7 +145,7 @@ bool CDImage::Seek(LBA lba) return true; } -bool CDImage::Seek(u32 track_number, const Position& pos_in_track) +bool CDImage::Seek(uint32_t track_number, const Position& pos_in_track) { if (track_number < 1 || track_number > m_tracks.size()) return false; @@ -163,7 +163,7 @@ bool CDImage::Seek(const Position& pos) return Seek(pos.ToLBA()); } -bool CDImage::Seek(u32 track_number, LBA lba) +bool CDImage::Seek(uint32_t track_number, LBA lba) { if (track_number < 1 || track_number > m_tracks.size()) return false; @@ -172,14 +172,14 @@ bool CDImage::Seek(u32 track_number, LBA lba) return Seek(track.start_lba + lba); } -u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer) +uint32_t CDImage::Read(ReadMode read_mode, uint32_t sector_count, void* buffer) { - u8* buffer_ptr = static_cast(buffer); - u32 sectors_read = 0; + uint8_t* buffer_ptr = static_cast(buffer); + uint32_t sectors_read = 0; for (; sectors_read < sector_count; sectors_read++) { // get raw sector - u8 raw_sector[RAW_SECTOR_SIZE]; + uint8_t raw_sector[RAW_SECTOR_SIZE]; if (!ReadRawSector(raw_sector, nullptr)) break; @@ -233,12 +233,12 @@ bool CDImage::ReadRawSector(void* buffer, SubChannelQ* subq) if (m_current_index->track_number == LEAD_OUT_TRACK_NUMBER) { // Lead-out area. - std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0xAA)); + std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, uint8_t(0xAA)); } else { // This in an implicit pregap. Return silence. - std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, u8(0)); + std::fill(static_cast(buffer), static_cast(buffer) + RAW_SECTOR_SIZE, uint8_t(0)); } } } @@ -284,22 +284,22 @@ bool CDImage::HasSubImages() const return false; } -u32 CDImage::GetSubImageCount() const +uint32_t CDImage::GetSubImageCount() const { return 0; } -u32 CDImage::GetCurrentSubImage() const +uint32_t CDImage::GetCurrentSubImage() const { return 0; } -bool CDImage::SwitchSubImage(u32 index, Common::Error* error) +bool CDImage::SwitchSubImage(uint32_t index, Common::Error* error) { return false; } -std::string CDImage::GetSubImageMetadata(u32 index, const std::string_view& type) const +std::string CDImage::GetSubImageMetadata(uint32_t index, const std::string_view& type) const { return {}; } @@ -343,7 +343,7 @@ const CDImage::Index* CDImage::GetIndexForDiscPosition(LBA pos) return nullptr; } -const CDImage::Index* CDImage::GetIndexForTrackPosition(u32 track_number, LBA track_pos) +const CDImage::Index* CDImage::GetIndexForTrackPosition(uint32_t track_number, LBA track_pos) { if (track_number < 1 || track_number > m_tracks.size()) return nullptr; @@ -361,17 +361,17 @@ bool CDImage::GenerateSubChannelQ(SubChannelQ* subq, LBA lba) if (!index) return false; - const u32 index_offset = index->start_lba_on_disc - lba; + const uint32_t index_offset = index->start_lba_on_disc - lba; GenerateSubChannelQ(subq, *index, index_offset); return true; } -void CDImage::GenerateSubChannelQ(SubChannelQ* subq, const Index& index, u32 index_offset) +void CDImage::GenerateSubChannelQ(SubChannelQ* subq, const Index& index, uint32_t index_offset) { subq->control_bits = index.control.bits; - subq->track_number_bcd = (index.track_number <= m_tracks.size() ? BinaryToBCD(static_cast(index.track_number)) : - static_cast(index.track_number)); - subq->index_number_bcd = BinaryToBCD(static_cast(index.index_number)); + subq->track_number_bcd = (index.track_number <= m_tracks.size() ? BinaryToBCD(static_cast(index.track_number)) : + static_cast(index.track_number)); + subq->index_number_bcd = BinaryToBCD(static_cast(index.index_number)); Position relative_position; if (index.is_pregap) @@ -407,9 +407,9 @@ void CDImage::AddLeadOutIndex() m_indices.push_back(index); } -u16 CDImage::SubChannelQ::ComputeCRC(const Data& data) +uint16_t CDImage::SubChannelQ::ComputeCRC(const Data& data) { - static constexpr std::array crc16_table = { + static constexpr std::array crc16_table = { {0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, @@ -430,8 +430,8 @@ u16 CDImage::SubChannelQ::ComputeCRC(const Data& data) 0x1CE0, 0x0CC1, 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0}}; - u16 value = 0; - for (u32 i = 0; i < 10; i++) + uint16_t value = 0; + for (uint32_t i = 0; i < 10; i++) value = crc16_table[(value >> 8) ^ data[i]] ^ (value << 8); return ~(value >> 8) | (~(value) << 8); diff --git a/src/common/cd_image.h b/src/common/cd_image.h index 15a44ab6..829a207a 100644 --- a/src/common/cd_image.h +++ b/src/common/cd_image.h @@ -15,7 +15,7 @@ class Error; class CDImage { public: - enum class OpenFlags : u8 + enum class OpenFlags : uint8_t { None = 0, PreCache = (1 << 0), // Pre-cache image to RAM, if supported. @@ -24,23 +24,23 @@ public: CDImage(OpenFlags open_flags); virtual ~CDImage(); - using LBA = u32; + using LBA = uint32_t; - static constexpr u32 RAW_SECTOR_SIZE = 2352, DATA_SECTOR_SIZE = 2048, SECTOR_SYNC_SIZE = 12, SECTOR_HEADER_SIZE = 4, + static constexpr uint32_t RAW_SECTOR_SIZE = 2352, DATA_SECTOR_SIZE = 2048, SECTOR_SYNC_SIZE = 12, SECTOR_HEADER_SIZE = 4, FRAMES_PER_SECOND = 75, // "sectors", or "timecode frames" (not "channel frames") SECONDS_PER_MINUTE = 60, FRAMES_PER_MINUTE = FRAMES_PER_SECOND * SECONDS_PER_MINUTE, SUBCHANNEL_BYTES_PER_FRAME = 12, LEAD_OUT_SECTOR_COUNT = 6750; - static constexpr u8 LEAD_OUT_TRACK_NUMBER = 0xAA; + static constexpr uint8_t LEAD_OUT_TRACK_NUMBER = 0xAA; - enum class ReadMode : u32 + enum class ReadMode : uint32_t { DataOnly, // 2048 bytes per sector. RawSector, // 2352 bytes per sector. RawNoSync, // 2340 bytes per sector. }; - enum class TrackMode : u32 + enum class TrackMode : uint32_t { Audio, // 2352 bytes per sector Mode1, // 2048 bytes per sector @@ -54,44 +54,44 @@ public: struct SectorHeader { - u8 minute; - u8 second; - u8 frame; - u8 sector_mode; + uint8_t minute; + uint8_t second; + uint8_t frame; + uint8_t sector_mode; }; struct Position { - u8 minute; - u8 second; - u8 frame; + uint8_t minute; + uint8_t second; + uint8_t frame; - static constexpr Position FromBCD(u8 minute, u8 second, u8 frame) + static constexpr Position FromBCD(uint8_t minute, uint8_t second, uint8_t frame) { return Position{PackedBCDToBinary(minute), PackedBCDToBinary(second), PackedBCDToBinary(frame)}; } static constexpr Position FromLBA(LBA lba) { - const u8 frame = static_cast(lba % FRAMES_PER_SECOND); + const uint8_t frame = static_cast(lba % FRAMES_PER_SECOND); lba /= FRAMES_PER_SECOND; - const u8 second = static_cast(lba % SECONDS_PER_MINUTE); + const uint8_t second = static_cast(lba % SECONDS_PER_MINUTE); lba /= SECONDS_PER_MINUTE; - const u8 minute = static_cast(lba); + const uint8_t minute = static_cast(lba); return Position{minute, second, frame}; } LBA ToLBA() const { - return static_cast(minute) * FRAMES_PER_MINUTE + static_cast(second) * FRAMES_PER_SECOND + static_cast(frame); + return static_cast(minute) * FRAMES_PER_MINUTE + static_cast(second) * FRAMES_PER_SECOND + static_cast(frame); } - constexpr std::tuple ToBCD() const + constexpr std::tuple ToBCD() const { - return std::make_tuple(BinaryToBCD(minute), BinaryToBCD(second), BinaryToBCD(frame)); + return std::make_tuple(BinaryToBCD(minute), BinaryToBCD(second), BinaryToBCD(frame)); } Position operator+(const Position& rhs) { return FromLBA(ToLBA() + rhs.ToLBA()); } @@ -119,17 +119,17 @@ public: union SubChannelQ { - using Data = std::array; + using Data = std::array; union Control { - u8 bits; + uint8_t bits; - BitField adr; - BitField audio_preemphasis; - BitField digital_copy_permitted; - BitField data; - BitField four_channel_audio; + BitField adr; + BitField audio_preemphasis; + BitField digital_copy_permitted; + BitField data; + BitField four_channel_audio; Control() = default; Control(const Control&) = default; @@ -143,22 +143,22 @@ public: struct { - u8 control_bits; - u8 track_number_bcd; - u8 index_number_bcd; - u8 relative_minute_bcd; - u8 relative_second_bcd; - u8 relative_frame_bcd; - u8 reserved; - u8 absolute_minute_bcd; - u8 absolute_second_bcd; - u8 absolute_frame_bcd; - u16 crc; + uint8_t control_bits; + uint8_t track_number_bcd; + uint8_t index_number_bcd; + uint8_t relative_minute_bcd; + uint8_t relative_second_bcd; + uint8_t relative_frame_bcd; + uint8_t reserved; + uint8_t absolute_minute_bcd; + uint8_t absolute_second_bcd; + uint8_t absolute_frame_bcd; + uint16_t crc; }; Data data; - static u16 ComputeCRC(const Data& data); + static uint16_t ComputeCRC(const Data& data); Control GetControl() const { return Control{control_bits}; } bool IsData() const { return GetControl().data; } @@ -174,31 +174,31 @@ public: struct Track { - u32 track_number; + uint32_t track_number; LBA start_lba; - u32 first_index; - u32 length; + uint32_t first_index; + uint32_t length; TrackMode mode; SubChannelQ::Control control; }; struct Index { - u64 file_offset; - u32 file_index; - u32 file_sector_size; + uint64_t file_offset; + uint32_t file_index; + uint32_t file_sector_size; LBA start_lba_on_disc; - u32 track_number; - u32 index_number; + uint32_t track_number; + uint32_t index_number; LBA start_lba_in_track; - u32 length; + uint32_t length; TrackMode mode; SubChannelQ::Control control; bool is_pregap; }; // Helper functions. - static u32 GetBytesPerSector(TrackMode mode); + static uint32_t GetBytesPerSector(TrackMode mode); // Opening disc image. static std::unique_ptr Open(const char* filename, OpenFlags open_flags, Common::Error* error); @@ -222,21 +222,21 @@ public: LBA GetPositionInTrack() const { return m_position_in_track; } Position GetMSFPositionInTrack() const { return Position::FromLBA(m_position_in_track); } LBA GetLBACount() const { return m_lba_count; } - u32 GetIndexNumber() const { return m_current_index->index_number; } - u32 GetTrackNumber() const { return m_current_index->track_number; } - u32 GetTrackCount() const { return static_cast(m_tracks.size()); } - Position GetTrackStartMSFPosition(u8 track) const; - LBA GetTrackLength(u8 track) const; - TrackMode GetTrackMode(u8 track) const; - LBA GetTrackIndexPosition(u8 track, u8 index) const; - LBA GetTrackIndexLength(u8 track, u8 index) const; - u32 GetFirstTrackNumber() const { return m_tracks.front().track_number; } - u32 GetLastTrackNumber() const { return m_tracks.back().track_number; } - u32 GetIndexCount() const { return static_cast(m_indices.size()); } + uint32_t GetIndexNumber() const { return m_current_index->index_number; } + uint32_t GetTrackNumber() const { return m_current_index->track_number; } + uint32_t GetTrackCount() const { return static_cast(m_tracks.size()); } + Position GetTrackStartMSFPosition(uint8_t track) const; + LBA GetTrackLength(uint8_t track) const; + TrackMode GetTrackMode(uint8_t track) const; + LBA GetTrackIndexPosition(uint8_t track, uint8_t index) const; + LBA GetTrackIndexLength(uint8_t track, uint8_t index) const; + uint32_t GetFirstTrackNumber() const { return m_tracks.front().track_number; } + uint32_t GetLastTrackNumber() const { return m_tracks.back().track_number; } + uint32_t GetIndexCount() const { return static_cast(m_indices.size()); } const std::vector& GetTracks() const { return m_tracks; } const std::vector& GetIndices() const { return m_indices; } - const Track& GetTrack(u32 track) const; - const Index& GetIndex(u32 i) const; + const Track& GetTrack(uint32_t track) const; + const Index& GetIndex(uint32_t i) const; OpenFlags GetOpenFlags() const { return m_open_flags; } // Seek to data LBA. @@ -246,13 +246,13 @@ public: bool Seek(const Position& pos); // Seek to track and position. - bool Seek(u32 track_number, const Position& pos_in_track); + bool Seek(uint32_t track_number, const Position& pos_in_track); // Seek to track and LBA. - bool Seek(u32 track_number, LBA lba); + bool Seek(uint32_t track_number, LBA lba); // Read from the current LBA. Returns the number of sectors read. - u32 Read(ReadMode read_mode, u32 sector_count, void* buffer); + uint32_t Read(ReadMode read_mode, uint32_t sector_count, void* buffer); // Read a single raw sector, and subchannel from the current LBA. bool ReadRawSector(void* buffer, SubChannelQ* subq); @@ -273,35 +273,35 @@ public: virtual bool HasSubImages() const; // Returns the number of sub-images in this image, if the format supports multiple. - virtual u32 GetSubImageCount() const; + virtual uint32_t GetSubImageCount() const; // Returns the current sub-image index, if any. - virtual u32 GetCurrentSubImage() const; + virtual uint32_t GetCurrentSubImage() const; // Changes the current sub-image. If this fails, the image state is unchanged. - virtual bool SwitchSubImage(u32 index, Common::Error* error); + virtual bool SwitchSubImage(uint32_t index, Common::Error* error); // Retrieve sub-image metadata. - virtual std::string GetSubImageMetadata(u32 index, const std::string_view& type) const; + virtual std::string GetSubImageMetadata(uint32_t index, const std::string_view& type) const; protected: void ClearTOC(); void CopyTOC(const CDImage* image); const Index* GetIndexForDiscPosition(LBA pos); - const Index* GetIndexForTrackPosition(u32 track_number, LBA track_pos); + const Index* GetIndexForTrackPosition(uint32_t track_number, LBA track_pos); /// Generates sub-channel Q given the specified position. bool GenerateSubChannelQ(SubChannelQ* subq, LBA lba); /// Generates sub-channel Q from the given index and index-offset. - void GenerateSubChannelQ(SubChannelQ* subq, const Index& index, u32 index_offset); + void GenerateSubChannelQ(SubChannelQ* subq, const Index& index, uint32_t index_offset); /// Synthesis of lead-out data. void AddLeadOutIndex(); std::string m_filename; - u32 m_lba_count = 0; + uint32_t m_lba_count = 0; std::vector m_tracks; std::vector m_indices; diff --git a/src/common/cd_image_bin.cpp b/src/common/cd_image_bin.cpp index b9a0b816..beb50036 100644 --- a/src/common/cd_image_bin.cpp +++ b/src/common/cd_image_bin.cpp @@ -22,7 +22,7 @@ protected: private: RFILE* m_fp = nullptr; - u64 m_file_position = 0; + uint64_t m_file_position = 0; CDSubChannelReplacement m_sbi; }; @@ -45,11 +45,11 @@ bool CDImageBin::Open(const char* filename, Common::Error* error) return false; } - const u32 track_sector_size = RAW_SECTOR_SIZE; + const uint32_t track_sector_size = RAW_SECTOR_SIZE; // determine the length from the file rfseek(m_fp, 0, SEEK_END); - const u32 file_size = static_cast(rftell(m_fp)); + const uint32_t file_size = static_cast(rftell(m_fp)); rfseek(m_fp, 0, SEEK_SET); m_lba_count = file_size / track_sector_size; @@ -59,11 +59,11 @@ bool CDImageBin::Open(const char* filename, Common::Error* error) control.data = mode != TrackMode::Audio; // Two seconds default pregap. - const u32 pregap_frames = 2 * FRAMES_PER_SECOND; + const uint32_t pregap_frames = 2 * FRAMES_PER_SECOND; Index pregap_index = {}; pregap_index.file_sector_size = track_sector_size; pregap_index.start_lba_on_disc = 0; - pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); + pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = 1; pregap_index.index_number = 0; @@ -88,7 +88,7 @@ bool CDImageBin::Open(const char* filename, Common::Error* error) // Assume a single track. m_tracks.push_back( - Track{static_cast(1), data_index.start_lba_on_disc, static_cast(0), m_lba_count, mode, control}); + Track{static_cast(1), data_index.start_lba_on_disc, static_cast(0), m_lba_count, mode, control}); AddLeadOutIndex(); @@ -112,7 +112,7 @@ bool CDImageBin::HasNonStandardSubchannel() const bool CDImageBin::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u64 file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); + const uint64_t file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); if (m_file_position != file_position) { if (rfseek(m_fp, static_cast(file_position), SEEK_SET) != 0) diff --git a/src/common/cd_image_chd.cpp b/src/common/cd_image_chd.cpp index 8200cdfd..92ad7777 100644 --- a/src/common/cd_image_chd.cpp +++ b/src/common/cd_image_chd.cpp @@ -55,17 +55,17 @@ protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; private: - static constexpr u32 CHD_CD_SECTOR_DATA_SIZE = 2352 + 96, CHD_CD_TRACK_ALIGNMENT = 4; + static constexpr uint32_t CHD_CD_SECTOR_DATA_SIZE = 2352 + 96, CHD_CD_TRACK_ALIGNMENT = 4; - bool ReadHunk(u32 hunk_index); + bool ReadHunk(uint32_t hunk_index); RFILE* m_fp = nullptr; chd_file* m_chd = nullptr; - u32 m_hunk_size = 0; - u32 m_sectors_per_hunk = 0; + uint32_t m_hunk_size = 0; + uint32_t m_sectors_per_hunk = 0; - std::vector m_hunk_buffer; - u32 m_current_hunk_index = static_cast(-1); + std::vector m_hunk_buffer; + uint32_t m_current_hunk_index = static_cast(-1); CDSubChannelReplacement m_sbi; }; @@ -125,8 +125,8 @@ bool CDImageCHD::Open(const char* filename, Common::Error* error) m_hunk_buffer.resize(m_hunk_size); m_filename = filename; - u32 disc_lba = 0; - u64 file_lba = 0; + uint32_t disc_lba = 0; + uint64_t file_lba = 0; // for each track.. int num_tracks = 0; @@ -137,7 +137,7 @@ bool CDImageCHD::Open(const char* filename, Common::Error* error) char subtype_str[256]; char pgtype_str[256]; char pgsub_str[256]; - u32 metadata_length; + uint32_t metadata_length; int track_num = 0, frames = 0, pregap_frames = 0, postgap_frames = 0; err = chd_get_metadata(m_chd, CDROM_TRACK_METADATA2_TAG, num_tracks, metadata_str, sizeof(metadata_str), @@ -243,8 +243,8 @@ bool CDImageCHD::Open(const char* filename, Common::Error* error) } // add the track itself - m_tracks.push_back(Track{static_cast(track_num), disc_lba, static_cast(m_indices.size()), - static_cast(frames + pregap_frames), mode.value(), control}); + m_tracks.push_back(Track{static_cast(track_num), disc_lba, static_cast(m_indices.size()), + static_cast(frames + pregap_frames), mode.value(), control}); // how many indices in this track? Index index = {}; @@ -258,7 +258,7 @@ bool CDImageCHD::Open(const char* filename, Common::Error* error) index.mode = mode.value(); index.control.bits = control.bits; index.is_pregap = false; - index.length = static_cast(frames); + index.length = static_cast(frames); m_indices.push_back(index); disc_lba += index.length; @@ -314,17 +314,17 @@ bool CDImageCHD::HasNonStandardSubchannel() const // fallback handles the byte swap two bytes at a time. All three // LE branches produce the same result; only the LE/BE split is // guarded by MSB_FIRST.) -ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data_size) +ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const uint8_t* src_ptr, uint32_t data_size) { #if defined(MSB_FIRST) std::memcpy(dst_ptr, src_ptr, data_size); #else - u8* dst_ptr_byte = static_cast(dst_ptr); + uint8_t* dst_ptr_byte = static_cast(dst_ptr); #if defined(CPU_X64) || defined(CPU_AARCH64) - const u32 num_values = data_size / 8; - for (u32 i = 0; i < num_values; i++) + const uint32_t num_values = data_size / 8; + for (uint32_t i = 0; i < num_values; i++) { - u64 value; + uint64_t value; std::memcpy(&value, src_ptr, sizeof(value)); value = ((value >> 8) & UINT64_C(0x00FF00FF00FF00FF)) | ((value << 8) & UINT64_C(0xFF00FF00FF00FF00)); std::memcpy(dst_ptr_byte, &value, sizeof(value)); @@ -332,10 +332,10 @@ ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data dst_ptr_byte += sizeof(value); } #elif defined(CPU_X86) || defined(CPU_ARM) - const u32 num_values = data_size / 4; - for (u32 i = 0; i < num_values; i++) + const uint32_t num_values = data_size / 4; + for (uint32_t i = 0; i < num_values; i++) { - u32 value; + uint32_t value; std::memcpy(&value, src_ptr, sizeof(value)); value = ((value >> 8) & UINT32_C(0x00FF00FF)) | ((value << 8) & UINT32_C(0xFF00FF00)); std::memcpy(dst_ptr_byte, &value, sizeof(value)); @@ -343,10 +343,10 @@ ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data dst_ptr_byte += sizeof(value); } #else - const u32 num_values = data_size / sizeof(u16); - for (u32 i = 0; i < num_values; i++) + const uint32_t num_values = data_size / sizeof(uint16_t); + for (uint32_t i = 0; i < num_values; i++) { - u16 value; + uint16_t value; std::memcpy(&value, src_ptr, sizeof(value)); value = (value << 8) | (value >> 8); std::memcpy(dst_ptr_byte, &value, sizeof(value)); @@ -359,9 +359,9 @@ ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data bool CDImageCHD::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u32 disc_frame = static_cast(index.file_offset) + lba_in_index; - const u32 hunk_index = static_cast(disc_frame / m_sectors_per_hunk); - const u32 hunk_offset = static_cast((disc_frame % m_sectors_per_hunk) * CHD_CD_SECTOR_DATA_SIZE); + const uint32_t disc_frame = static_cast(index.file_offset) + lba_in_index; + const uint32_t hunk_index = static_cast(disc_frame / m_sectors_per_hunk); + const uint32_t hunk_offset = static_cast((disc_frame % m_sectors_per_hunk) * CHD_CD_SECTOR_DATA_SIZE); if (m_current_hunk_index != hunk_index && !ReadHunk(hunk_index)) return false; @@ -375,7 +375,7 @@ bool CDImageCHD::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_i return true; } -bool CDImageCHD::ReadHunk(u32 hunk_index) +bool CDImageCHD::ReadHunk(uint32_t hunk_index) { const chd_error err = chd_read(m_chd, hunk_index, m_hunk_buffer.data()); if (err != CHDERR_NONE) @@ -383,7 +383,7 @@ bool CDImageCHD::ReadHunk(u32 hunk_index) Log_ErrorPrintf("chd_read(%u) failed: %s", hunk_index, chd_error_string(err)); // data might have been partially written - m_current_hunk_index = static_cast(-1); + m_current_hunk_index = static_cast(-1); return false; } diff --git a/src/common/cd_image_cue.cpp b/src/common/cd_image_cue.cpp index d3c88296..b777ee5a 100644 --- a/src/common/cd_image_cue.cpp +++ b/src/common/cd_image_cue.cpp @@ -29,7 +29,7 @@ private: { std::string filename; RFILE* file; - u64 file_position; + uint64_t file_position; }; std::vector m_files; @@ -63,10 +63,10 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) m_filename = filename; - u32 disc_lba = 0; + uint32_t disc_lba = 0; // for each track.. - for (u32 track_num = 1; track_num <= CueParser::MAX_TRACK_NUMBER; track_num++) + for (uint32_t track_num = 1; track_num <= CueParser::MAX_TRACK_NUMBER; track_num++) { const CueParser::Track* track = parser.GetTrack(track_num); if (!track) @@ -75,7 +75,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) const std::string track_filename(track->file); LBA track_start = track->start.ToLBA(); - u32 track_file_index = 0; + uint32_t track_file_index = 0; for (; track_file_index < m_files.size(); track_file_index++) { const TrackFile& t = m_files[track_file_index]; @@ -119,7 +119,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) // data type determines the sector size const TrackMode mode = track->mode; - const u32 track_sector_size = GetBytesPerSector(mode); + const uint32_t track_sector_size = GetBytesPerSector(mode); // precompute subchannel q flags for the whole track SubChannelQ::Control control{}; @@ -133,7 +133,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) if (!track->length.has_value()) { FileSystem::FSeek64(m_files[track_file_index].file, 0, SEEK_END); - u64 file_size = static_cast(FileSystem::FTell64(m_files[track_file_index].file)); + uint64_t file_size = static_cast(FileSystem::FTell64(m_files[track_file_index].file)); FileSystem::FSeek64(m_files[track_file_index].file, 0, SEEK_SET); file_size /= track_sector_size; @@ -166,7 +166,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) // Pregap/index 0 is in the file, easy. Index pregap_index = {}; pregap_index.start_lba_on_disc = disc_lba; - pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); + pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = track_num; pregap_index.index_number = 0; @@ -174,7 +174,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) pregap_index.control.bits = control.bits; pregap_index.is_pregap = true; pregap_index.file_index = track_file_index; - pregap_index.file_offset = static_cast(static_cast(track_start - pregap_frames)) * track_sector_size; + pregap_index.file_offset = static_cast(static_cast(track_start - pregap_frames)) * track_sector_size; pregap_index.file_sector_size = track_sector_size; m_indices.push_back(pregap_index); @@ -205,7 +205,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) { Index pregap_index = {}; pregap_index.start_lba_on_disc = disc_lba; - pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); + pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = track_num; pregap_index.index_number = 0; @@ -220,7 +220,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) // add the track itself m_tracks.push_back( - Track{track_num, disc_lba, static_cast(m_indices.size()), track_length + pregap_frames, mode, control}); + Track{track_num, disc_lba, static_cast(m_indices.size()), track_length + pregap_frames, mode, control}); // how many indices in this track? Index last_index; @@ -230,19 +230,19 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) last_index.index_number = 1; last_index.file_index = track_file_index; last_index.file_sector_size = track_sector_size; - last_index.file_offset = static_cast(track_start) * track_sector_size; + last_index.file_offset = static_cast(track_start) * track_sector_size; last_index.mode = mode; last_index.control.bits = control.bits; last_index.is_pregap = false; - u32 last_index_offset = track_start; - for (u32 index_num = 1;; index_num++) + uint32_t last_index_offset = track_start; + for (uint32_t index_num = 1;; index_num++) { const Position* pos = track->GetIndex(index_num); if (!pos) break; - const u32 index_offset = pos->ToLBA(); + const uint32_t index_offset = pos->ToLBA(); // add an index between the track indices if (index_offset > last_index_offset) @@ -257,12 +257,12 @@ bool CDImageCueSheet::OpenAndParse(const char* filename, Common::Error* error) } last_index.file_offset = index_offset * last_index.file_sector_size; - last_index.index_number = static_cast(index_num); + last_index.index_number = static_cast(index_num); last_index_offset = index_offset; } // and the last index is added here - const u32 track_end_index = track_start + track_length; + const uint32_t track_end_index = track_start + track_length; if (track_end_index > last_index_offset) { last_index.length = track_end_index - last_index_offset; @@ -304,7 +304,7 @@ bool CDImageCueSheet::HasNonStandardSubchannel() const bool CDImageCueSheet::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { TrackFile& tf = m_files[index.file_index]; - const u64 file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); + const uint64_t file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); if (tf.file_position != file_position) { if (rfseek(tf.file, static_cast(file_position), SEEK_SET) != 0) diff --git a/src/common/cd_image_ecm.cpp b/src/common/cd_image_ecm.cpp index 4363ebb0..209d8c74 100644 --- a/src/common/cd_image_ecm.cpp +++ b/src/common/cd_image_ecm.cpp @@ -13,59 +13,59 @@ Log_SetChannel(CDImageEcm); /* LUTs used for computing ECC/EDC */ -static constexpr std::array ComputeECCFLUT() +static constexpr std::array ComputeECCFLUT() { - std::array ecc_lut{}; - for (u32 i = 0; i < 256; i++) + std::array ecc_lut{}; + for (uint32_t i = 0; i < 256; i++) { - u32 j = (i << 1) ^ (i & 0x80 ? 0x11D : 0); - ecc_lut[i] = static_cast(j); + uint32_t j = (i << 1) ^ (i & 0x80 ? 0x11D : 0); + ecc_lut[i] = static_cast(j); } return ecc_lut; } -static constexpr std::array ComputeECCBLUT() +static constexpr std::array ComputeECCBLUT() { - std::array ecc_lut{}; - for (u32 i = 0; i < 256; i++) + std::array ecc_lut{}; + for (uint32_t i = 0; i < 256; i++) { - u32 j = (i << 1) ^ (i & 0x80 ? 0x11D : 0); - ecc_lut[i ^ j] = static_cast(i); + uint32_t j = (i << 1) ^ (i & 0x80 ? 0x11D : 0); + ecc_lut[i ^ j] = static_cast(i); } return ecc_lut; } -static constexpr std::array ComputeEDCLUT() +static constexpr std::array ComputeEDCLUT() { - std::array edc_lut{}; - for (u32 i = 0; i < 256; i++) + std::array edc_lut{}; + for (uint32_t i = 0; i < 256; i++) { - u32 edc = i; - for (u32 k = 0; k < 8; k++) + uint32_t edc = i; + for (uint32_t k = 0; k < 8; k++) edc = (edc >> 1) ^ (edc & 1 ? 0xD8018001 : 0); edc_lut[i] = edc; } return edc_lut; } -static constexpr std::array ecc_f_lut = ComputeECCFLUT(); -static constexpr std::array ecc_b_lut = ComputeECCBLUT(); -static constexpr std::array edc_lut = ComputeEDCLUT(); +static constexpr std::array ecc_f_lut = ComputeECCFLUT(); +static constexpr std::array ecc_b_lut = ComputeECCBLUT(); +static constexpr std::array edc_lut = ComputeEDCLUT(); /***************************************************************************/ /* ** Compute EDC for a block */ -static u32 edc_partial_computeblock(u32 edc, const u8* src, u16 size) +static uint32_t edc_partial_computeblock(uint32_t edc, const uint8_t* src, uint16_t size) { while (size--) edc = (edc >> 8) ^ edc_lut[(edc ^ (*src++)) & 0xFF]; return edc; } -static void edc_computeblock(const u8* src, u16 size, u8* dest) +static void edc_computeblock(const uint8_t* src, uint16_t size, uint8_t* dest) { - u32 edc = edc_partial_computeblock(0, src, size); + uint32_t edc = edc_partial_computeblock(0, src, size); dest[0] = (edc >> 0) & 0xFF; dest[1] = (edc >> 8) & 0xFF; dest[2] = (edc >> 16) & 0xFF; @@ -76,18 +76,18 @@ static void edc_computeblock(const u8* src, u16 size, u8* dest) /* ** Compute ECC for a block (can do either P or Q) */ -static void ecc_computeblock(u8* src, u32 major_count, u32 minor_count, u32 major_mult, u32 minor_inc, u8* dest) +static void ecc_computeblock(uint8_t* src, uint32_t major_count, uint32_t minor_count, uint32_t major_mult, uint32_t minor_inc, uint8_t* dest) { - u32 size = major_count * minor_count; - u32 major, minor; + uint32_t size = major_count * minor_count; + uint32_t major, minor; for (major = 0; major < major_count; major++) { - u32 index = (major >> 1) * major_mult + (major & 1); - u8 ecc_a = 0; - u8 ecc_b = 0; + uint32_t index = (major >> 1) * major_mult + (major & 1); + uint8_t ecc_a = 0; + uint8_t ecc_b = 0; for (minor = 0; minor < minor_count; minor++) { - u8 temp = src[index]; + uint8_t temp = src[index]; index += minor_inc; if (index >= size) index -= size; @@ -104,9 +104,9 @@ static void ecc_computeblock(u8* src, u32 major_count, u32 minor_count, u32 majo /* ** Generate ECC P and Q codes for a block */ -static void ecc_generate(u8* sector, int zeroaddress) +static void ecc_generate(uint8_t* sector, int zeroaddress) { - u8 address[4], i; + uint8_t address[4], i; /* Save the address and zero it out */ if (zeroaddress) for (i = 0; i < 4; i++) @@ -129,7 +129,7 @@ static void ecc_generate(u8* sector, int zeroaddress) ** Generate ECC/EDC information for a sector (must be 2352 = 0x930 bytes) ** Returns 0 on success */ -static void eccedc_generate(u8* sector, int type) +static void eccedc_generate(uint8_t* sector, int type) { switch (type) { @@ -137,7 +137,7 @@ static void eccedc_generate(u8* sector, int type) /* Compute EDC */ edc_computeblock(sector + 0x00, 0x810, sector + 0x810); /* Write out zero bytes */ - for (u32 i = 0; i < 8; i++) + for (uint32_t i = 0; i < 8; i++) sector[0x814 + i] = 0; /* Generate ECC P/Q codes */ ecc_generate(sector, 0); @@ -170,11 +170,11 @@ protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; private: - bool ReadChunks(u32 disc_offset, u32 size); + bool ReadChunks(uint32_t disc_offset, uint32_t size); RFILE* m_fp = nullptr; - enum class SectorType : u32 + enum class SectorType : uint32_t { Raw = 0x00, Mode1 = 0x01, @@ -183,14 +183,14 @@ private: Count, }; - static constexpr std::array(SectorType::Count)> s_sector_sizes = { + static constexpr std::array(SectorType::Count)> s_sector_sizes = { 0x930, // raw 0x803, // mode1 0x804, // mode2form1 0x918, // mode2form2 }; - static constexpr std::array(SectorType::Count)> s_chunk_sizes = { + static constexpr std::array(SectorType::Count)> s_chunk_sizes = { 0, // raw 2352, // mode1 2336, // mode2form1 @@ -199,16 +199,16 @@ private: struct SectorEntry { - u32 file_offset; - u32 chunk_size; + uint32_t file_offset; + uint32_t chunk_size; SectorType type; }; - using DataMap = std::map; + using DataMap = std::map; DataMap m_data_map; - std::vector m_chunk_buffer; - u32 m_chunk_start = 0; + std::vector m_chunk_buffer; + uint32_t m_chunk_start = 0; CDSubChannelReplacement m_sbi; }; @@ -231,7 +231,7 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) return false; } - s64 file_size; + int64_t file_size; if (FileSystem::FSeek64(m_fp, 0, SEEK_END) != 0 || (file_size = FileSystem::FTell64(m_fp)) <= 0 || FileSystem::FSeek64(m_fp, 0, SEEK_SET) != 0) { @@ -251,8 +251,8 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) } // build sector map - u32 file_offset = static_cast(rftell(m_fp)); - u32 disc_offset = 0; + uint32_t file_offset = static_cast(rftell(m_fp)); + uint32_t disc_offset = 0; for (;;) { @@ -267,9 +267,9 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) } file_offset++; - const SectorType type = static_cast(static_cast(bits) & 0x03u); - u32 count = (static_cast(bits) >> 2) & 0x1F; - u32 shift = 5; + const SectorType type = static_cast(static_cast(bits) & 0x03u); + uint32_t count = (static_cast(bits) >> 2) & 0x1F; + uint32_t shift = 5; while (bits & 0x80) { bits = rfgetc(m_fp); @@ -282,7 +282,7 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) return false; } - count |= (static_cast(bits) & 0x7F) << shift; + count |= (static_cast(bits) & 0x7F) << shift; shift += 7; file_offset++; } @@ -306,13 +306,13 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) { while (count > 0) { - const u32 size = std::min(count, 2352); + const uint32_t size = std::min(count, 2352); m_data_map.emplace(disc_offset, SectorEntry{file_offset, size, type}); disc_offset += size; file_offset += size; count -= size; - if (static_cast(file_offset) > file_size) + if (static_cast(file_offset) > file_size) { Log_ErrorPrintf("Out of file bounds after %zu chunks", m_data_map.size()); if (error) @@ -322,15 +322,15 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) } else { - const u32 size = s_sector_sizes[static_cast(type)]; - const u32 chunk_size = s_chunk_sizes[static_cast(type)]; - for (u32 i = 0; i < count; i++) + const uint32_t size = s_sector_sizes[static_cast(type)]; + const uint32_t chunk_size = s_chunk_sizes[static_cast(type)]; + for (uint32_t i = 0; i < count; i++) { m_data_map.emplace(disc_offset, SectorEntry{file_offset, chunk_size, type}); disc_offset += chunk_size; file_offset += size; - if (static_cast(file_offset) > file_size) + if (static_cast(file_offset) > file_size) { Log_ErrorPrintf("Out of file bounds after %zu chunks", m_data_map.size()); if (error) @@ -369,11 +369,11 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) control.data = mode != TrackMode::Audio; // Two seconds default pregap. - const u32 pregap_frames = 2 * FRAMES_PER_SECOND; + const uint32_t pregap_frames = 2 * FRAMES_PER_SECOND; Index pregap_index = {}; pregap_index.file_sector_size = RAW_SECTOR_SIZE; pregap_index.start_lba_on_disc = 0; - pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); + pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.track_number = 1; pregap_index.index_number = 0; @@ -398,7 +398,7 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) // Assume a single track. m_tracks.push_back( - Track{static_cast(1), data_index.start_lba_on_disc, static_cast(0), m_lba_count, mode, control}); + Track{static_cast(1), data_index.start_lba_on_disc, static_cast(0), m_lba_count, mode, control}); AddLeadOutIndex(); @@ -408,7 +408,7 @@ bool CDImageEcm::Open(const char* filename, Common::Error* error) return Seek(1, Position{0, 0, 0}); } -bool CDImageEcm::ReadChunks(u32 disc_offset, u32 size) +bool CDImageEcm::ReadChunks(uint32_t disc_offset, uint32_t size) { DataMap::iterator next = m_data_map.lower_bound((disc_offset > RAW_SECTOR_SIZE) ? (disc_offset - RAW_SECTOR_SIZE) : 0); @@ -422,14 +422,14 @@ bool CDImageEcm::ReadChunks(u32 disc_offset, u32 size) if (m_chunk_start < disc_offset) size += (disc_offset - current->first); - u32 total_bytes_read = 0; + uint32_t total_bytes_read = 0; while (total_bytes_read < size) { if (current == m_data_map.end() || rfseek(m_fp, current->second.file_offset, SEEK_SET) != 0) return false; - const u32 chunk_size = current->second.chunk_size; - const u32 chunk_start = static_cast(m_chunk_buffer.size()); + const uint32_t chunk_size = current->second.chunk_size; + const uint32_t chunk_start = static_cast(m_chunk_buffer.size()); m_chunk_buffer.resize(chunk_start + chunk_size); if (current->second.type == SectorType::Raw) @@ -441,14 +441,14 @@ bool CDImageEcm::ReadChunks(u32 disc_offset, u32 size) } else { - // u8* sector = &m_chunk_buffer[chunk_start]; - u8 sector[RAW_SECTOR_SIZE]; + // uint8_t* sector = &m_chunk_buffer[chunk_start]; + uint8_t sector[RAW_SECTOR_SIZE]; // TODO: needed? std::memset(sector, 0, RAW_SECTOR_SIZE); std::memset(sector + 1, 0xFF, 10); - u32 skip; + uint32_t skip; switch (current->second.type) { case SectorType::Mode1: @@ -523,8 +523,8 @@ bool CDImageEcm::HasNonStandardSubchannel() const bool CDImageEcm::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u32 file_start = static_cast(index.file_offset) + (lba_in_index * index.file_sector_size); - const u32 file_end = file_start + RAW_SECTOR_SIZE; + const uint32_t file_start = static_cast(index.file_offset) + (lba_in_index * index.file_sector_size); + const uint32_t file_end = file_start + RAW_SECTOR_SIZE; if (file_start < m_chunk_start || file_end > (m_chunk_start + m_chunk_buffer.size())) { diff --git a/src/common/cd_image_m3u.cpp b/src/common/cd_image_m3u.cpp index e5dfdf5c..eb8d3797 100644 --- a/src/common/cd_image_m3u.cpp +++ b/src/common/cd_image_m3u.cpp @@ -20,10 +20,10 @@ public: bool HasNonStandardSubchannel() const override; bool HasSubImages() const override; - u32 GetSubImageCount() const override; - u32 GetCurrentSubImage() const override; - std::string GetSubImageMetadata(u32 index, const std::string_view& type) const override; - bool SwitchSubImage(u32 index, Common::Error* error) override; + uint32_t GetSubImageCount() const override; + uint32_t GetCurrentSubImage() const override; + std::string GetSubImageMetadata(uint32_t index, const std::string_view& type) const override; + bool SwitchSubImage(uint32_t index, Common::Error* error) override; protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; @@ -38,7 +38,7 @@ private: std::vector m_entries; std::unique_ptr m_current_image; - u32 m_current_image_index = UINT32_C(0xFFFFFFFF); + uint32_t m_current_image_index = UINT32_C(0xFFFFFFFF); }; CDImageM3u::CDImageM3u(OpenFlags open_flags) : CDImage(open_flags) {} @@ -67,7 +67,7 @@ bool CDImageM3u::Open(const char* path, Common::Error* error) std::string line; while (std::getline(ifs, line)) { - u32 start_offset = 0; + uint32_t start_offset = 0; while (start_offset < line.size() && std::isspace(line[start_offset])) start_offset++; @@ -76,7 +76,7 @@ bool CDImageM3u::Open(const char* path, Common::Error* error) continue; // strip ending whitespace - u32 end_offset = static_cast(line.size()) - 1; + uint32_t end_offset = static_cast(line.size()) - 1; while (std::isspace(line[end_offset]) && end_offset > start_offset) end_offset--; @@ -109,17 +109,17 @@ bool CDImageM3u::HasSubImages() const return true; } -u32 CDImageM3u::GetSubImageCount() const +uint32_t CDImageM3u::GetSubImageCount() const { - return static_cast(m_entries.size()); + return static_cast(m_entries.size()); } -u32 CDImageM3u::GetCurrentSubImage() const +uint32_t CDImageM3u::GetCurrentSubImage() const { return m_current_image_index; } -bool CDImageM3u::SwitchSubImage(u32 index, Common::Error* error) +bool CDImageM3u::SwitchSubImage(uint32_t index, Common::Error* error) { if (index >= m_entries.size()) return false; @@ -142,7 +142,7 @@ bool CDImageM3u::SwitchSubImage(u32 index, Common::Error* error) return true; } -std::string CDImageM3u::GetSubImageMetadata(u32 index, const std::string_view& type) const +std::string CDImageM3u::GetSubImageMetadata(uint32_t index, const std::string_view& type) const { if (index > m_entries.size()) return {}; diff --git a/src/common/cd_image_mds.cpp b/src/common/cd_image_mds.cpp index 8dc6b3cf..09cabccc 100644 --- a/src/common/cd_image_mds.cpp +++ b/src/common/cd_image_mds.cpp @@ -11,19 +11,19 @@ Log_SetChannel(CDImageMds); #pragma pack(push, 1) struct TrackEntry { - u8 track_type; - u8 has_subchannel_data; - u8 unk1; - u8 unk2; - u8 track_number; - u8 unk3[4]; - u8 start_m; - u8 start_s; - u8 start_f; - u32 extra_offset; - u8 unk4[24]; - u32 track_offset_in_mdf; - u8 unk5[36]; + uint8_t track_type; + uint8_t has_subchannel_data; + uint8_t unk1; + uint8_t unk2; + uint8_t track_number; + uint8_t unk3[4]; + uint8_t start_m; + uint8_t start_s; + uint8_t start_f; + uint32_t extra_offset; + uint8_t unk4[24]; + uint32_t track_offset_in_mdf; + uint8_t unk5[36]; }; #pragma pack(pop) @@ -43,7 +43,7 @@ protected: private: RFILE* m_mdf_file = nullptr; - u64 m_mdf_file_position = 0; + uint64_t m_mdf_file_position = 0; CDSubChannelReplacement m_sbi; }; @@ -64,7 +64,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) return false; } - std::optional> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp)); + std::optional> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp)); rfclose(mds_fp); if (!mds_data_opt.has_value() || mds_data_opt->size() < 0x54) { @@ -86,7 +86,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) return false; } - const std::vector& mds = mds_data_opt.value(); + const std::vector& mds = mds_data_opt.value(); static constexpr char expected_signature[] = "MEDIA DESCRIPTOR"; if (std::memcmp(&mds[0], expected_signature, sizeof(expected_signature) - 1) != 0) { @@ -97,7 +97,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) return false; } - u32 session_offset; + uint32_t session_offset; std::memcpy(&session_offset, &mds[0x50], sizeof(session_offset)); if ((session_offset + 24) > mds.size()) { @@ -108,8 +108,8 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) return false; } - u16 track_count; - u32 track_offset; + uint16_t track_count; + uint32_t track_offset; std::memcpy(&track_count, &mds[session_offset + 14], sizeof(track_count)); std::memcpy(&track_offset, &mds[session_offset + 20], sizeof(track_offset)); if (track_count > 99 || track_offset >= mds.size()) @@ -131,7 +131,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) track_offset += sizeof(TrackEntry); } - for (u32 track_number = 1; track_number <= track_count; track_number++) + for (uint32_t track_number = 1; track_number <= track_count; track_number++) { if ((track_offset + sizeof(TrackEntry)) > mds.size()) { @@ -156,10 +156,10 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) } const bool contains_subchannel = (track.has_subchannel_data != 0); - const u32 track_sector_size = (contains_subchannel ? 2448 : RAW_SECTOR_SIZE); + const uint32_t track_sector_size = (contains_subchannel ? 2448 : RAW_SECTOR_SIZE); const TrackMode mode = (track.track_type == 0xA9) ? TrackMode::Audio : TrackMode::Mode2Raw; - if ((track.extra_offset + sizeof(u32) + sizeof(u32)) > mds.size()) + if ((track.extra_offset + sizeof(uint32_t) + sizeof(uint32_t)) > mds.size()) { Log_ErrorPrintf("Invalid extra offset %u in track %u", track.extra_offset, track_number); if (error) @@ -168,13 +168,13 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) return false; } - u32 track_start_lba = Position::FromBCD(track.start_m, track.start_s, track.start_f).ToLBA(); - u32 track_file_offset = track.track_offset_in_mdf; + uint32_t track_start_lba = Position::FromBCD(track.start_m, track.start_s, track.start_f).ToLBA(); + uint32_t track_file_offset = track.track_offset_in_mdf; - u32 track_pregap; - u32 track_length; + uint32_t track_pregap; + uint32_t track_length; std::memcpy(&track_pregap, &mds[track.extra_offset], sizeof(track_pregap)); - std::memcpy(&track_length, &mds[track.extra_offset + sizeof(u32)], sizeof(track_length)); + std::memcpy(&track_length, &mds[track.extra_offset + sizeof(uint32_t)], sizeof(track_length)); // precompute subchannel q flags for the whole track // todo: pull from mds? @@ -195,7 +195,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) Index pregap_index = {}; pregap_index.start_lba_on_disc = track_start_lba - track_pregap; - pregap_index.start_lba_in_track = static_cast(-static_cast(track_pregap)); + pregap_index.start_lba_in_track = static_cast(-static_cast(track_pregap)); pregap_index.length = track_pregap; pregap_index.track_number = track_number; pregap_index.index_number = 0; @@ -216,8 +216,8 @@ bool CDImageMds::OpenAndParse(const char* filename, Common::Error* error) } // add the track itself - m_tracks.push_back(Track{static_cast(track_number), track_start_lba, static_cast(m_indices.size()), - static_cast(track_length), mode, control}); + m_tracks.push_back(Track{static_cast(track_number), track_start_lba, static_cast(m_indices.size()), + static_cast(track_length), mode, control}); // how many indices in this track? Index last_index; @@ -267,7 +267,7 @@ bool CDImageMds::HasNonStandardSubchannel() const bool CDImageMds::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u64 file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); + const uint64_t file_position = index.file_offset + (static_cast(lba_in_index) * index.file_sector_size); if (m_mdf_file_position != file_position) { if (rfseek(m_mdf_file, static_cast(file_position), SEEK_SET) != 0) @@ -277,7 +277,7 @@ bool CDImageMds::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_i } // we don't want the subchannel data - const u32 read_size = RAW_SECTOR_SIZE; + const uint32_t read_size = RAW_SECTOR_SIZE; if (rfread(buffer, read_size, 1, m_mdf_file) != 1) { rfseek(m_mdf_file, static_cast(m_mdf_file_position), SEEK_SET); diff --git a/src/common/cd_image_memory.cpp b/src/common/cd_image_memory.cpp index 15cf274e..0aae1283 100644 --- a/src/common/cd_image_memory.cpp +++ b/src/common/cd_image_memory.cpp @@ -22,8 +22,8 @@ protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; private: - u8* m_memory = nullptr; - u32 m_memory_sectors = 0; + uint8_t* m_memory = nullptr; + uint32_t m_memory_sectors = 0; CDSubChannelReplacement m_sbi; }; @@ -39,15 +39,15 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) { // figure out the total number of sectors (not including blank pregaps) m_memory_sectors = 0; - for (u32 i = 0; i < image->GetIndexCount(); i++) + for (uint32_t i = 0; i < image->GetIndexCount(); i++) { const Index& index = image->GetIndex(i); if (index.file_sector_size > 0) m_memory_sectors += image->GetIndex(i).length; } - if ((static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors)) >= - static_cast(std::numeric_limits::max())) + if ((static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors)) >= + static_cast(std::numeric_limits::max())) { progress->DisplayFormattedModalError("Insufficient address space"); return false; @@ -56,7 +56,7 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) progress->SetFormattedStatusText("Allocating memory for %u sectors...", m_memory_sectors); m_memory = - static_cast(std::malloc(static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors))); + static_cast(std::malloc(static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors))); if (!m_memory) { progress->DisplayFormattedModalError("Failed to allocate memory for %u sectors", m_memory_sectors); @@ -67,15 +67,15 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) progress->SetProgressRange(m_memory_sectors); progress->SetProgressValue(0); - u8* memory_ptr = m_memory; - u32 sectors_read = 0; - for (u32 i = 0; i < image->GetIndexCount(); i++) + uint8_t* memory_ptr = m_memory; + uint32_t sectors_read = 0; + for (uint32_t i = 0; i < image->GetIndexCount(); i++) { const Index& index = image->GetIndex(i); if (index.file_sector_size == 0) continue; - for (u32 lba = 0; lba < index.length; lba++) + for (uint32_t lba = 0; lba < index.length; lba++) { if (!image->ReadSectorFromIndex(memory_ptr, index, lba)) { @@ -89,11 +89,11 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) } } - for (u32 i = 1; i <= image->GetTrackCount(); i++) + for (uint32_t i = 1; i <= image->GetTrackCount(); i++) m_tracks.push_back(image->GetTrack(i)); - u32 current_offset = 0; - for (u32 i = 0; i < image->GetIndexCount(); i++) + uint32_t current_offset = 0; + for (uint32_t i = 0; i < image->GetIndexCount(); i++) { Index new_index = image->GetIndex(i); new_index.file_index = 0; @@ -128,7 +128,7 @@ bool CDImageMemory::HasNonStandardSubchannel() const bool CDImageMemory::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u64 sector_number = index.file_offset + lba_in_index; + const uint64_t sector_number = index.file_offset + lba_in_index; if (sector_number >= m_memory_sectors) return false; diff --git a/src/common/cd_image_pbp.cpp b/src/common/cd_image_pbp.cpp index 0a2f0587..a1dd840f 100644 --- a/src/common/cd_image_pbp.cpp +++ b/src/common/cd_image_pbp.cpp @@ -27,11 +27,11 @@ public: bool HasNonStandardSubchannel() const override; bool HasSubImages() const override; - u32 GetSubImageCount() const override; - u32 GetCurrentSubImage() const override; - bool SwitchSubImage(u32 index, Common::Error* error) override; + uint32_t GetSubImageCount() const override; + uint32_t GetCurrentSubImage() const override; + bool SwitchSubImage(uint32_t index, Common::Error* error) override; std::string GetMetadata(const std::string_view& type) const override; - std::string GetSubImageMetadata(u32 index, const std::string_view& type) const override; + std::string GetSubImageMetadata(uint32_t index, const std::string_view& type) const override; protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; @@ -39,8 +39,8 @@ protected: private: struct BlockInfo { - u32 offset; // Absolute offset from start of file - u16 size; + uint32_t offset; // Absolute offset from start of file + uint16_t size; }; bool LoadPBPHeader(); @@ -53,7 +53,7 @@ private: bool InitDecompressionStream(); bool DecompressBlock(const BlockInfo& block_info); - bool OpenDisc(u32 index, Common::Error* error); + bool OpenDisc(uint32_t index, Common::Error* error); static const std::string* LookupStringSFOTableEntry(const char* key, const SFOTable& table); @@ -65,17 +65,17 @@ private: SFOIndexTable m_sfo_index_table; // Absolute offsets to ISO headers, size is the number of discs in the file - std::vector m_disc_offsets; - u32 m_current_disc = 0; + std::vector m_disc_offsets; + uint32_t m_current_disc = 0; // Absolute offsets and sizes of blocks in m_file std::array m_blockinfo_table; std::array m_toc; - u32 m_current_block = static_cast(-1); - std::array m_decompressed_block; - std::vector m_compressed_block; + uint32_t m_current_block = static_cast(-1); + std::array m_decompressed_block; + std::vector m_compressed_block; z_stream m_inflate_stream; @@ -87,8 +87,8 @@ static constexpr bool HostIsLittleEndian() { constexpr union { - u8 a[4]; - u32 b; + uint8_t a[4]; + uint32_t b; } test_val = {{1}}; return test_val.a[0] == 1; @@ -100,7 +100,7 @@ static void SwapByteOrder(T& val) union { T t; - std::array arr; + std::array arr; } swap_val; swap_val.t = val; @@ -184,9 +184,9 @@ bool CDImagePBP::LoadSFOTable() for (size_t i = 0; i < static_cast(m_sfo_header.num_table_entries); ++i) { - u32 abs_key_offset = + uint32_t abs_key_offset = m_pbp_header.param_sfo_offset + m_sfo_header.key_table_offset + m_sfo_index_table[i].key_offset; - u32 abs_data_offset = + uint32_t abs_data_offset = m_pbp_header.param_sfo_offset + m_sfo_header.data_table_offset + m_sfo_index_table[i].data_offset; if (FileSystem::FSeek64(m_file, abs_key_offset, SEEK_SET) != 0) @@ -227,8 +227,8 @@ bool CDImagePBP::LoadSFOTable() } else if (m_sfo_index_table[i].data_type == 0x0404) // uint32_t { - u32 val; - if (rfread(&val, sizeof(u32), 1, m_file) != 1) + uint32_t val; + if (rfread(&val, sizeof(uint32_t), 1, m_file) != 1) { Log_ErrorPrintf("Failed to read unsigned data value for SFO table entry %zu", i); return false; @@ -255,7 +255,7 @@ bool CDImagePBP::IsValidEboot(Common::Error* error) if (a_it != m_sfo_table.end()) { SFOTableDataValue data_value = a_it->second; - if (!std::holds_alternative(data_value) || std::get(data_value) != 1) + if (!std::holds_alternative(data_value) || std::get(data_value) != 1) { Log_ErrorPrint("Invalid BOOTABLE value"); if (error) @@ -369,8 +369,8 @@ bool CDImagePBP::Open(const char* filename, Common::Error* error) if (FileSystem::FSeek64(m_file, m_pbp_header.data_psar_offset + 0x200, SEEK_SET) != 0) return false; - u32 disc_table[DISC_TABLE_NUM_ENTRIES] = {}; - if (rfread(disc_table, sizeof(u32), DISC_TABLE_NUM_ENTRIES, m_file) != DISC_TABLE_NUM_ENTRIES) + uint32_t disc_table[DISC_TABLE_NUM_ENTRIES] = {}; + if (rfread(disc_table, sizeof(uint32_t), DISC_TABLE_NUM_ENTRIES, m_file) != DISC_TABLE_NUM_ENTRIES) return false; // Ignore encrypted files @@ -384,7 +384,7 @@ bool CDImagePBP::Open(const char* filename, Common::Error* error) } // Convert relative offsets to absolute offsets for available discs - for (u32 i = 0; i < DISC_TABLE_NUM_ENTRIES; i++) + for (uint32_t i = 0; i < DISC_TABLE_NUM_ENTRIES; i++) { if (disc_table[i] != 0) m_disc_offsets.push_back(m_pbp_header.data_psar_offset + disc_table[i]); @@ -423,7 +423,7 @@ bool CDImagePBP::Open(const char* filename, Common::Error* error) // Ronnie Sahlberg , author of pop-fe. if (m_disc_offsets.size() < 1) { - Log_ErrorPrintf("Invalid number of discs (%u) in multi-disc PBP file", static_cast(m_disc_offsets.size())); + Log_ErrorPrintf("Invalid number of discs (%u) in multi-disc PBP file", static_cast(m_disc_offsets.size())); return false; } } @@ -436,7 +436,7 @@ bool CDImagePBP::Open(const char* filename, Common::Error* error) return OpenDisc(0, error); } -bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) +bool CDImagePBP::OpenDisc(uint32_t index, Common::Error* error) { if (index >= m_disc_offsets.size()) { @@ -446,14 +446,14 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) return false; } - m_current_block = static_cast(-1); + m_current_block = static_cast(-1); m_blockinfo_table.fill({}); m_toc.fill({}); m_decompressed_block.fill(0x00); m_compressed_block.clear(); // Go to ISO header - const u32 iso_header_start = m_disc_offsets[index]; + const uint32_t iso_header_start = m_disc_offsets[index]; if (FileSystem::FSeek64(m_file, iso_header_start, SEEK_SET) != 0) return false; @@ -468,7 +468,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) } // Ignore encrypted files - u32 pgd_magic; + uint32_t pgd_magic; if (FileSystem::FSeek64(m_file, iso_header_start + 0x400, SEEK_SET) != 0) return false; @@ -488,7 +488,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) if (FileSystem::FSeek64(m_file, iso_header_start + 0x800, SEEK_SET) != 0) return false; - for (u32 i = 0; i < TOC_NUM_ENTRIES; i++) + for (uint32_t i = 0; i < TOC_NUM_ENTRIES; i++) { if (rfread(&m_toc[i], sizeof(m_toc[i]), 1, m_file) != 1) return false; @@ -501,7 +501,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) if (FileSystem::FSeek64(m_file, iso_header_start + 0xBFC, SEEK_SET) != 0) return false; - u32 iso_offset; + uint32_t iso_offset; if (rfread(&iso_offset, sizeof(iso_offset), 1, m_file) != 1) return false; @@ -509,7 +509,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) if (FileSystem::FSeek64(m_file, iso_header_start + 0x4000, SEEK_SET) != 0) return false; - for (u32 i = 0; i < BLOCK_TABLE_NUM_ENTRIES; i++) + for (uint32_t i = 0; i < BLOCK_TABLE_NUM_ENTRIES; i++) { BlockTableEntry bte; if (rfread(&bte, sizeof(bte), 1, m_file) != 1) @@ -532,8 +532,8 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) return false; } - const u8 first_track = PackedBCDToBinary(m_toc[0].userdata_start.m); - const u8 last_track = PackedBCDToBinary(m_toc[1].userdata_start.m); + const uint8_t first_track = PackedBCDToBinary(m_toc[0].userdata_start.m); + const uint8_t last_track = PackedBCDToBinary(m_toc[1].userdata_start.m); const LBA sectors_on_file = Position::FromBCD(m_toc[2].userdata_start.m, m_toc[2].userdata_start.s, m_toc[2].userdata_start.f).ToLBA(); @@ -551,19 +551,19 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) ClearTOC(); m_lba_count = sectors_on_file; LBA track1_pregap_frames = 0; - for (u32 curr_track = 1; curr_track <= last_track; curr_track++) + for (uint32_t curr_track = 1; curr_track <= last_track; curr_track++) { // Load in all the user stuff to m_tracks and m_indices const TOCEntry& t = m_toc[static_cast(curr_track) + 2]; - const u8 track_num = PackedBCDToBinary(t.point); + const uint8_t track_num = PackedBCDToBinary(t.point); if (track_num != curr_track) - Log_WarningPrintf("Mismatched TOC track number, expected %u but got %u", static_cast(curr_track), track_num); + Log_WarningPrintf("Mismatched TOC track number, expected %u but got %u", static_cast(curr_track), track_num); const bool is_audio_track = t.type == 0x01; const bool is_first_track = curr_track == 1; const bool is_last_track = curr_track == last_track; const TrackMode track_mode = is_audio_track ? TrackMode::Audio : TrackMode::Mode2Raw; - const u32 track_sector_size = GetBytesPerSector(track_mode); + const uint32_t track_sector_size = GetBytesPerSector(track_mode); SubChannelQ::Control track_control = {}; track_control.data = !is_audio_track; @@ -571,20 +571,20 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) LBA pregap_start = Position::FromBCD(t.pregap_start.m, t.pregap_start.s, t.pregap_start.f).ToLBA(); LBA userdata_start = Position::FromBCD(t.userdata_start.m, t.userdata_start.s, t.userdata_start.f).ToLBA(); LBA pregap_frames; - u32 pregap_sector_size; + uint32_t pregap_sector_size; if (userdata_start < pregap_start) { if (!is_first_track || is_audio_track) { Log_ErrorPrintf("Invalid TOC entry at index %u, user data (%u) should not start before pregap (%u)", - static_cast(curr_track), userdata_start, pregap_start); + static_cast(curr_track), userdata_start, pregap_start); return false; } Log_WarningPrintf( "Invalid TOC entry at index %u, user data (%u) should not start before pregap (%u), assuming not in file.", - static_cast(curr_track), userdata_start, pregap_start); + static_cast(curr_track), userdata_start, pregap_start); pregap_start = 0; pregap_frames = userdata_start; pregap_sector_size = 0; @@ -603,13 +603,13 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) Index pregap_index = {}; pregap_index.file_offset = - is_first_track ? 0 : (static_cast(pregap_start - track1_pregap_frames) * pregap_sector_size); + is_first_track ? 0 : (static_cast(pregap_start - track1_pregap_frames) * pregap_sector_size); pregap_index.file_index = 0; pregap_index.file_sector_size = pregap_sector_size; pregap_index.start_lba_on_disc = pregap_start; pregap_index.track_number = curr_track; pregap_index.index_number = 0; - pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); + pregap_index.start_lba_in_track = static_cast(-static_cast(pregap_frames)); pregap_index.length = pregap_frames; pregap_index.mode = track_mode; pregap_index.control.bits = track_control.bits; @@ -618,7 +618,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) m_indices.push_back(pregap_index); Index userdata_index = {}; - userdata_index.file_offset = static_cast(userdata_start - track1_pregap_frames) * track_sector_size; + userdata_index.file_offset = static_cast(userdata_start - track1_pregap_frames) * track_sector_size; userdata_index.file_index = 0; userdata_index.file_sector_size = track_sector_size; userdata_index.start_lba_on_disc = userdata_start; @@ -634,7 +634,7 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) if (userdata_start >= m_lba_count) { Log_ErrorPrintf("Last user data index on disc for TOC entry %u should not be 0 or less in length", - static_cast(curr_track)); + static_cast(curr_track)); return false; } userdata_index.length = m_lba_count - userdata_start; @@ -644,11 +644,11 @@ bool CDImagePBP::OpenDisc(u32 index, Common::Error* error) const TOCEntry& next_track = m_toc[static_cast(curr_track) + 3]; const LBA next_track_start = Position::FromBCD(next_track.pregap_start.m, next_track.pregap_start.s, next_track.pregap_start.f).ToLBA(); - const u8 next_track_num = PackedBCDToBinary(next_track.point); + const uint8_t next_track_num = PackedBCDToBinary(next_track.point); if (next_track_num != curr_track + 1 || next_track_start < userdata_start) { - Log_ErrorPrintf("Unable to calculate user data index length for TOC entry %u", static_cast(curr_track)); + Log_ErrorPrintf("Unable to calculate user data index length for TOC entry %u", static_cast(curr_track)); return false; } @@ -717,13 +717,13 @@ bool CDImagePBP::DecompressBlock(const BlockInfo& block_info) // Compression level 0 has compressed size == decompressed size. if (block_info.size == m_decompressed_block.size()) { - return (rfread(m_decompressed_block.data(), sizeof(u8), m_decompressed_block.size(), m_file) == static_cast( + return (rfread(m_decompressed_block.data(), sizeof(uint8_t), m_decompressed_block.size(), m_file) == static_cast( m_decompressed_block.size())); } m_compressed_block.resize(block_info.size); - if (rfread(m_compressed_block.data(), sizeof(u8), m_compressed_block.size(), m_file) != static_cast(m_compressed_block.size())) + if (rfread(m_compressed_block.data(), sizeof(uint8_t), m_compressed_block.size(), m_file) != static_cast(m_compressed_block.size())) return false; m_inflate_stream.next_in = m_compressed_block.data(); @@ -759,9 +759,9 @@ bool CDImagePBP::HasNonStandardSubchannel() const bool CDImagePBP::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u32 offset_in_file = static_cast(index.file_offset) + (lba_in_index * index.file_sector_size); - const u32 offset_in_block = offset_in_file % DECOMPRESSED_BLOCK_SIZE; - const u32 requested_block = offset_in_file / DECOMPRESSED_BLOCK_SIZE; + const uint32_t offset_in_file = static_cast(index.file_offset) + (lba_in_index * index.file_sector_size); + const uint32_t offset_in_block = offset_in_file % DECOMPRESSED_BLOCK_SIZE; + const uint32_t requested_block = offset_in_file / DECOMPRESSED_BLOCK_SIZE; BlockInfo& bi = m_blockinfo_table[requested_block]; @@ -798,22 +798,22 @@ std::string CDImagePBP::GetMetadata(const std::string_view& type) const return CDImage::GetMetadata(type); } -u32 CDImagePBP::GetSubImageCount() const +uint32_t CDImagePBP::GetSubImageCount() const { - return static_cast(m_disc_offsets.size()); + return static_cast(m_disc_offsets.size()); } -u32 CDImagePBP::GetCurrentSubImage() const +uint32_t CDImagePBP::GetCurrentSubImage() const { return m_current_disc; } -bool CDImagePBP::SwitchSubImage(u32 index, Common::Error* error) +bool CDImagePBP::SwitchSubImage(uint32_t index, Common::Error* error) { if (index >= m_disc_offsets.size()) return false; - const u32 old_disc = m_current_disc; + const uint32_t old_disc = m_current_disc; // return to old disc, this should never fail... in theory. if (!OpenDisc(index, error)) OpenDisc(old_disc, nullptr); @@ -821,7 +821,7 @@ bool CDImagePBP::SwitchSubImage(u32 index, Common::Error* error) return true; } -std::string CDImagePBP::GetSubImageMetadata(u32 index, const std::string_view& type) const +std::string CDImagePBP::GetSubImageMetadata(uint32_t index, const std::string_view& type) const { if (type == "title") { diff --git a/src/common/cd_image_ppf.cpp b/src/common/cd_image_ppf.cpp index 4d4ec317..985c52c2 100644 --- a/src/common/cd_image_ppf.cpp +++ b/src/common/cd_image_ppf.cpp @@ -9,7 +9,7 @@ #include Log_SetChannel(CDImagePPF); -static constexpr u32 DESC_SIZE = 50, BLOCKCHECK_SIZE = 1024; +static constexpr uint32_t DESC_SIZE = 50, BLOCKCHECK_SIZE = 1024; class CDImagePPF : public CDImage { @@ -23,7 +23,7 @@ public: bool HasNonStandardSubchannel() const override; std::string GetMetadata(const std::string_view& type) const override; - std::string GetSubImageMetadata(u32 index, const std::string_view& type) const override; + std::string GetSubImageMetadata(uint32_t index, const std::string_view& type) const override; protected: bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override; @@ -32,14 +32,14 @@ private: bool ReadV1Patch(RFILE* fp); bool ReadV2Patch(RFILE* fp); bool ReadV3Patch(RFILE* fp); - u32 ReadFileIDDiz(RFILE* fp, u32 version); + uint32_t ReadFileIDDiz(RFILE* fp, uint32_t version); - bool AddPatch(u64 offset, const u8* patch, u32 patch_size); + bool AddPatch(uint64_t offset, const uint8_t* patch, uint32_t patch_size); std::unique_ptr m_parent_image; - std::vector m_replacement_data; - std::unordered_map m_replacement_map; - u32 m_replacement_offset = 0; + std::vector m_replacement_data; + std::unordered_map m_replacement_map; + uint32_t m_replacement_offset = 0; }; CDImagePPF::CDImagePPF(OpenFlags open_flags) : CDImage(open_flags) {} @@ -55,7 +55,7 @@ bool CDImagePPF::Open(const char* filename, std::unique_ptr parent_imag return false; } - u32 magic; + uint32_t magic; if (rfread(&magic, sizeof(magic), 1, fp) != 1) { Log_ErrorPrintf("Failed to read magic from '%s'", filename); @@ -104,11 +104,11 @@ bool CDImagePPF::Open(const char* filename, std::unique_ptr parent_imag return false; } -u32 CDImagePPF::ReadFileIDDiz(RFILE* fp, u32 version) +uint32_t CDImagePPF::ReadFileIDDiz(RFILE* fp, uint32_t version) { const int lenidx = (version == 2) ? 4 : 2; - u32 magic; + uint32_t magic; if (rfseek(fp, -(lenidx + 4), SEEK_END) != 0 || rfread(&magic, sizeof(magic), 1, fp) != 1) { Log_WarningPrintf("Failed to read diz magic"); @@ -118,14 +118,14 @@ u32 CDImagePPF::ReadFileIDDiz(RFILE* fp, u32 version) if (magic != 0x5A49442E) // .DIZ return 0; - u32 dlen = 0; + uint32_t dlen = 0; if (rfseek(fp, -lenidx, SEEK_END) != 0 || rfread(&dlen, lenidx, 1, fp) != 1) { Log_WarningPrintf("Failed to read diz length"); return 0; } - if (dlen > static_cast(rftell(fp))) + if (dlen > static_cast(rftell(fp))) { Log_WarningPrintf("diz length out of range"); return 0; @@ -146,7 +146,7 @@ u32 CDImagePPF::ReadFileIDDiz(RFILE* fp, u32 version) bool CDImagePPF::ReadV1Patch(RFILE* fp) { - u32 filelen; + uint32_t filelen; char desc[DESC_SIZE + 1] = {}; if (rfseek(fp, 6, SEEK_SET) != 0 || rfread(desc, sizeof(char), DESC_SIZE, fp) != DESC_SIZE) { @@ -154,24 +154,24 @@ bool CDImagePPF::ReadV1Patch(RFILE* fp) return false; } - if (rfseek(fp, 0, SEEK_END) != 0 || (filelen = static_cast(rftell(fp))) == 0 || filelen < 56) + if (rfseek(fp, 0, SEEK_END) != 0 || (filelen = static_cast(rftell(fp))) == 0 || filelen < 56) { Log_ErrorPrintf("Invalid ppf file"); return false; } - u32 count = filelen - 56; + uint32_t count = filelen - 56; if (count <= 0) return false; if (rfseek(fp, 56, SEEK_SET) != 0) return false; - std::vector temp; + std::vector temp; while (count > 0) { - u32 offset; - u8 chunk_size; + uint32_t offset; + uint8_t chunk_size; if ( rfread(&offset, sizeof(offset), 1, fp) != 1 || rfread(&chunk_size, sizeof(chunk_size), 1, fp) != 1) { @@ -198,7 +198,7 @@ bool CDImagePPF::ReadV1Patch(RFILE* fp) bool CDImagePPF::ReadV2Patch(RFILE* fp) { - u32 origlen; + uint32_t origlen; char desc[DESC_SIZE + 1] = {}; if (rfseek(fp, 6, SEEK_SET) != 0 || rfread(desc, sizeof(char), DESC_SIZE, fp) != DESC_SIZE) { @@ -208,7 +208,7 @@ bool CDImagePPF::ReadV2Patch(RFILE* fp) Log_InfoPrintf("Patch description: %s", desc); - const u32 idlen = ReadFileIDDiz(fp, 2); + const uint32_t idlen = ReadFileIDDiz(fp, 2); if (rfseek(fp, 56, SEEK_SET) != 0 || rfread(&origlen, sizeof(origlen), 1, fp) != 1) { @@ -216,7 +216,7 @@ bool CDImagePPF::ReadV2Patch(RFILE* fp) return false; } - std::vector temp; + std::vector temp; temp.resize(BLOCKCHECK_SIZE); if (rfread(temp.data(), 1, BLOCKCHECK_SIZE, fp) != BLOCKCHECK_SIZE) { @@ -226,10 +226,10 @@ bool CDImagePPF::ReadV2Patch(RFILE* fp) // do blockcheck { - u32 blockcheck_src_sector = 16 + m_replacement_offset; - u32 blockcheck_src_offset = 32; + uint32_t blockcheck_src_sector = 16 + m_replacement_offset; + uint32_t blockcheck_src_offset = 32; - std::vector src_sector(RAW_SECTOR_SIZE); + std::vector src_sector(RAW_SECTOR_SIZE); if (m_parent_image->Seek(blockcheck_src_sector) && m_parent_image->ReadRawSector(src_sector.data(), nullptr)) { if (std::memcmp(&src_sector[blockcheck_src_offset], temp.data(), BLOCKCHECK_SIZE) != 0) @@ -241,14 +241,14 @@ bool CDImagePPF::ReadV2Patch(RFILE* fp) } } - u32 filelen; - if (rfseek(fp, 0, SEEK_END) != 0 || (filelen = static_cast(rftell(fp))) == 0 || filelen < 1084) + uint32_t filelen; + if (rfseek(fp, 0, SEEK_END) != 0 || (filelen = static_cast(rftell(fp))) == 0 || filelen < 1084) { Log_ErrorPrintf("Invalid ppf file"); return false; } - u32 count = filelen - 1084; + uint32_t count = filelen - 1084; if (idlen > 0) count -= (idlen + 38); @@ -260,8 +260,8 @@ bool CDImagePPF::ReadV2Patch(RFILE* fp) while (count > 0) { - u32 offset; - u8 chunk_size; + uint32_t offset; + uint8_t chunk_size; if (rfread(&offset, sizeof(offset), 1, fp) != 1 || rfread(&chunk_size, sizeof(chunk_size), 1, fp) != 1) { Log_ErrorPrintf("Incomplete ppf"); @@ -296,11 +296,11 @@ bool CDImagePPF::ReadV3Patch(RFILE* fp) Log_InfoPrintf("Patch description: %s", desc); - u32 idlen = ReadFileIDDiz(fp, 3); + uint32_t idlen = ReadFileIDDiz(fp, 3); - u8 image_type; - u8 block_check; - u8 undo; + uint8_t image_type; + uint8_t block_check; + uint8_t undo; if (rfseek(fp, 56, SEEK_SET) != 0 || rfread(&image_type, sizeof(image_type), 1, fp) != 1 || rfread(&block_check, sizeof(block_check), 1, fp) != 1 || rfread(&undo, sizeof(undo), 1, fp) != 1) { @@ -311,9 +311,9 @@ bool CDImagePPF::ReadV3Patch(RFILE* fp) // TODO: Blockcheck rfseek(fp, 0, SEEK_END); - u32 count = static_cast(rftell(fp)); + uint32_t count = static_cast(rftell(fp)); - u32 seekpos = (block_check) ? 1084 : 60; + uint32_t seekpos = (block_check) ? 1084 : 60; if (seekpos >= count) { Log_ErrorPrintf("File is too short"); @@ -323,7 +323,7 @@ bool CDImagePPF::ReadV3Patch(RFILE* fp) count -= seekpos; if (idlen > 0) { - const u32 extralen = idlen + 18 + 16 + 2; + const uint32_t extralen = idlen + 18 + 16 + 2; if (count < extralen) { Log_ErrorPrintf("File is too short (diz)"); @@ -336,12 +336,12 @@ bool CDImagePPF::ReadV3Patch(RFILE* fp) if (rfseek(fp, seekpos, SEEK_SET) != 0) return false; - std::vector temp; + std::vector temp; while (count > 0) { - u64 offset; - u8 chunk_size; + uint64_t offset; + uint8_t chunk_size; if (rfread(&offset, sizeof(offset), 1, fp) != 1 || rfread(&chunk_size, sizeof(chunk_size), 1, fp) != 1) { Log_ErrorPrintf("Incomplete ppf"); @@ -365,24 +365,24 @@ bool CDImagePPF::ReadV3Patch(RFILE* fp) return true; } -bool CDImagePPF::AddPatch(u64 offset, const u8* patch, u32 patch_size) +bool CDImagePPF::AddPatch(uint64_t offset, const uint8_t* patch, uint32_t patch_size) { while (patch_size > 0) { - const u32 sector_index = static_cast(offset / RAW_SECTOR_SIZE) + m_replacement_offset; - const u32 sector_offset = static_cast(offset % RAW_SECTOR_SIZE); + const uint32_t sector_index = static_cast(offset / RAW_SECTOR_SIZE) + m_replacement_offset; + const uint32_t sector_offset = static_cast(offset % RAW_SECTOR_SIZE); if (sector_index >= m_parent_image->GetLBACount()) { Log_ErrorPrintf("Sector %u in patch is out of range", sector_index); return false; } - const u32 bytes_to_patch = std::min(patch_size, RAW_SECTOR_SIZE - sector_offset); + const uint32_t bytes_to_patch = std::min(patch_size, RAW_SECTOR_SIZE - sector_offset); auto iter = m_replacement_map.find(sector_index); if (iter == m_replacement_map.end()) { - const u32 replacement_buffer_start = static_cast(m_replacement_data.size()); + const uint32_t replacement_buffer_start = static_cast(m_replacement_data.size()); m_replacement_data.resize(m_replacement_data.size() + RAW_SECTOR_SIZE); if (!m_parent_image->Seek(sector_index) || !m_parent_image->ReadRawSector(&m_replacement_data[replacement_buffer_start], nullptr)) @@ -419,7 +419,7 @@ std::string CDImagePPF::GetMetadata(const std::string_view& type) const return m_parent_image->GetMetadata(type); } -std::string CDImagePPF::GetSubImageMetadata(u32 index, const std::string_view& type) const +std::string CDImagePPF::GetSubImageMetadata(uint32_t index, const std::string_view& type) const { // We only support a single sub-image for patched games. std::string ret; @@ -431,7 +431,7 @@ std::string CDImagePPF::GetSubImageMetadata(u32 index, const std::string_view& t bool CDImagePPF::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) { - const u32 sector_number = index.start_lba_on_disc + lba_in_index; + const uint32_t sector_number = index.start_lba_on_disc + lba_in_index; const auto it = m_replacement_map.find(sector_number); if (it == m_replacement_map.end()) return m_parent_image->ReadSectorFromIndex(buffer, index, lba_in_index); diff --git a/src/common/cd_subchannel_replacement.cpp b/src/common/cd_subchannel_replacement.cpp index c95c3efa..9a4c5c74 100644 --- a/src/common/cd_subchannel_replacement.cpp +++ b/src/common/cd_subchannel_replacement.cpp @@ -9,11 +9,11 @@ Log_SetChannel(CDSubChannelReplacement); #pragma pack(push, 1) struct SBIFileEntry { - u8 minute_bcd; - u8 second_bcd; - u8 frame_bcd; - u8 type; - u8 data[10]; + uint8_t minute_bcd; + uint8_t second_bcd; + uint8_t frame_bcd; + uint8_t type; + uint8_t data[10]; }; #pragma pack(pop) @@ -21,13 +21,13 @@ CDSubChannelReplacement::CDSubChannelReplacement() = default; CDSubChannelReplacement::~CDSubChannelReplacement() = default; -static constexpr u32 MSFToLBA(u8 minute_bcd, u8 second_bcd, u8 frame_bcd) +static constexpr uint32_t MSFToLBA(uint8_t minute_bcd, uint8_t second_bcd, uint8_t frame_bcd) { - const u8 minute = PackedBCDToBinary(minute_bcd); - const u8 second = PackedBCDToBinary(second_bcd); - const u8 frame = PackedBCDToBinary(frame_bcd); + const uint8_t minute = PackedBCDToBinary(minute_bcd); + const uint8_t second = PackedBCDToBinary(second_bcd); + const uint8_t frame = PackedBCDToBinary(frame_bcd); - return (static_cast(minute) * 60 * 75) + (static_cast(second) * 75) + static_cast(frame); + return (static_cast(minute) * 60 * 75) + (static_cast(second) * 75) + static_cast(frame); } bool CDSubChannelReplacement::LoadSBI(const char* path) @@ -71,15 +71,15 @@ bool CDSubChannelReplacement::LoadSBI(const char* path) return false; } - const u32 lba = MSFToLBA(entry.minute_bcd, entry.second_bcd, entry.frame_bcd); + const uint32_t lba = MSFToLBA(entry.minute_bcd, entry.second_bcd, entry.frame_bcd); CDImage::SubChannelQ subq; std::copy_n(entry.data, countof(entry.data), subq.data.data()); // generate an invalid crc by flipping all bits from the valid crc (will never collide) - const u16 crc = subq.ComputeCRC(subq.data) ^ 0xFFFF; - subq.data[10] = static_cast(crc); - subq.data[11] = static_cast(crc >> 8); + const uint16_t crc = subq.ComputeCRC(subq.data) ^ 0xFFFF; + subq.data[10] = static_cast(crc); + subq.data[11] = static_cast(crc >> 8); m_replacement_subq.emplace(lba, subq); } @@ -94,7 +94,7 @@ bool CDSubChannelReplacement::LoadSBIFromImagePath(const char* image_path) return LoadSBI(FileSystem::ReplaceExtension(image_path, "sbi").c_str()); } -void CDSubChannelReplacement::AddReplacementSubChannelQ(u32 lba, const CDImage::SubChannelQ& subq) +void CDSubChannelReplacement::AddReplacementSubChannelQ(uint32_t lba, const CDImage::SubChannelQ& subq) { auto iter = m_replacement_subq.find(lba); if (iter != m_replacement_subq.end()) @@ -103,13 +103,13 @@ void CDSubChannelReplacement::AddReplacementSubChannelQ(u32 lba, const CDImage:: m_replacement_subq.emplace(lba, subq); } -bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, +bool CDSubChannelReplacement::GetReplacementSubChannelQ(uint8_t minute_bcd, uint8_t second_bcd, uint8_t frame_bcd, CDImage::SubChannelQ* subq) const { return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq); } -bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, CDImage::SubChannelQ* subq) const +bool CDSubChannelReplacement::GetReplacementSubChannelQ(uint32_t lba, CDImage::SubChannelQ* subq) const { const auto iter = m_replacement_subq.find(lba); if (iter == m_replacement_subq.cend()) diff --git a/src/common/cd_subchannel_replacement.h b/src/common/cd_subchannel_replacement.h index 0c0bdf1e..47389e0e 100644 --- a/src/common/cd_subchannel_replacement.h +++ b/src/common/cd_subchannel_replacement.h @@ -10,22 +10,22 @@ public: CDSubChannelReplacement(); ~CDSubChannelReplacement(); - u32 GetReplacementSectorCount() const { return static_cast(m_replacement_subq.size()); } + uint32_t GetReplacementSectorCount() const { return static_cast(m_replacement_subq.size()); } bool LoadSBI(const char* path); bool LoadSBIFromImagePath(const char* image_path); /// Adds a sector to the replacement map. - void AddReplacementSubChannelQ(u32 lba, const CDImage::SubChannelQ& subq); + void AddReplacementSubChannelQ(uint32_t lba, const CDImage::SubChannelQ& subq); /// Returns the replacement subchannel data for the specified position (in BCD). - bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, CDImage::SubChannelQ* subq) const; + bool GetReplacementSubChannelQ(uint8_t minute_bcd, uint8_t second_bcd, uint8_t frame_bcd, CDImage::SubChannelQ* subq) const; /// Returns the replacement subchannel data for the specified sector. - bool GetReplacementSubChannelQ(u32 lba, CDImage::SubChannelQ* subq) const; + bool GetReplacementSubChannelQ(uint32_t lba, CDImage::SubChannelQ* subq) const; private: - using ReplacementMap = std::unordered_map; + using ReplacementMap = std::unordered_map; ReplacementMap m_replacement_subq; }; diff --git a/src/common/cd_xa.cpp b/src/common/cd_xa.cpp index 870a86be..3d28c4ef 100644 --- a/src/common/cd_xa.cpp +++ b/src/common/cd_xa.cpp @@ -4,75 +4,75 @@ #include namespace CDXA { -static constexpr std::array s_xa_adpcm_filter_table_pos = {{0, 60, 115, 98}}; -static constexpr std::array s_xa_adpcm_filter_table_neg = {{0, 0, -52, -55}}; +static constexpr std::array s_xa_adpcm_filter_table_pos = {{0, 60, 115, 98}}; +static constexpr std::array s_xa_adpcm_filter_table_neg = {{0, 0, -52, -55}}; template -static void DecodeXA_ADPCMChunk(const u8* chunk_ptr, s16* samples, s32* last_samples) +static void DecodeXA_ADPCMChunk(const uint8_t* chunk_ptr, int16_t* samples, int32_t* last_samples) { // The data layout is annoying here. Each word of data is interleaved with the other blocks, requiring multiple // passes to decode the whole chunk. - constexpr u32 NUM_BLOCKS = IS_8BIT ? 4 : 8; - constexpr u32 WORDS_PER_BLOCK = 28; + constexpr uint32_t NUM_BLOCKS = IS_8BIT ? 4 : 8; + constexpr uint32_t WORDS_PER_BLOCK = 28; - const u8* headers_ptr = chunk_ptr + 4; - const u8* words_ptr = chunk_ptr + 16; + const uint8_t* headers_ptr = chunk_ptr + 4; + const uint8_t* words_ptr = chunk_ptr + 16; - for (u32 block = 0; block < NUM_BLOCKS; block++) + for (uint32_t block = 0; block < NUM_BLOCKS; block++) { const XA_ADPCMBlockHeader block_header{headers_ptr[block]}; - const u8 shift = block_header.GetShift(); - const u8 filter = block_header.GetFilter(); - const s32 filter_pos = s_xa_adpcm_filter_table_pos[filter]; - const s32 filter_neg = s_xa_adpcm_filter_table_neg[filter]; + const uint8_t shift = block_header.GetShift(); + const uint8_t filter = block_header.GetFilter(); + const int32_t filter_pos = s_xa_adpcm_filter_table_pos[filter]; + const int32_t filter_neg = s_xa_adpcm_filter_table_neg[filter]; - s16* out_samples_ptr = + int16_t* out_samples_ptr = IS_STEREO ? &samples[(block / 2) * (WORDS_PER_BLOCK * 2) + (block % 2)] : &samples[block * WORDS_PER_BLOCK]; - constexpr u32 out_samples_increment = IS_STEREO ? 2 : 1; + constexpr uint32_t out_samples_increment = IS_STEREO ? 2 : 1; - for (u32 word = 0; word < 28; word++) + for (uint32_t word = 0; word < 28; word++) { // The 32-bit XA-ADPCM word as stored on disc is little-endian. - // The original code memcpy'd four host-order bytes into a u32 + // The original code memcpy'd four host-order bytes into a uint32_t // and then shifted: that works on a little-endian host (where // the LE-on-disc layout matches the host layout) but reverses // which nibble the (block * N) shift selects on a big-endian - // host. Build the u32 explicitly from individual bytes so the + // host. Build the uint32_t explicitly from individual bytes so the // subsequent shifts pick the same nibble regardless of host // byte order. - const u8* const word_bytes = &words_ptr[word * sizeof(u32)]; - const u32 word_data = static_cast(word_bytes[0]) - | (static_cast(word_bytes[1]) << 8) - | (static_cast(word_bytes[2]) << 16) - | (static_cast(word_bytes[3]) << 24); + const uint8_t* const word_bytes = &words_ptr[word * sizeof(uint32_t)]; + const uint32_t word_data = static_cast(word_bytes[0]) + | (static_cast(word_bytes[1]) << 8) + | (static_cast(word_bytes[2]) << 16) + | (static_cast(word_bytes[3]) << 24); // extract nibble from block - const u32 nibble = IS_8BIT ? ((word_data >> (block * 8)) & 0xFF) : ((word_data >> (block * 4)) & 0x0F); - const s16 sample = static_cast(static_cast(nibble << 12)) >> shift; + const uint32_t nibble = IS_8BIT ? ((word_data >> (block * 8)) & 0xFF) : ((word_data >> (block * 4)) & 0x0F); + const int16_t sample = static_cast(static_cast(nibble << 12)) >> shift; // mix in previous values - s32* prev = IS_STEREO ? &last_samples[(block & 1) * 2] : last_samples; - const s32 interp_sample = s32(sample) + ((prev[0] * filter_pos) + (prev[1] * filter_neg) + 32) / 64; + int32_t* prev = IS_STEREO ? &last_samples[(block & 1) * 2] : last_samples; + const int32_t interp_sample = int32_t(sample) + ((prev[0] * filter_pos) + (prev[1] * filter_neg) + 32) / 64; // update previous values prev[1] = prev[0]; prev[0] = interp_sample; - *out_samples_ptr = static_cast(std::clamp(interp_sample, -0x8000, 0x7FFF)); + *out_samples_ptr = static_cast(std::clamp(interp_sample, -0x8000, 0x7FFF)); out_samples_ptr += out_samples_increment; } } } template -static void DecodeXA_ADPCMChunks(const u8* chunk_ptr, s16* samples, s32* last_samples) +static void DecodeXA_ADPCMChunks(const uint8_t* chunk_ptr, int16_t* samples, int32_t* last_samples) { - constexpr u32 NUM_CHUNKS = 18; - constexpr u32 CHUNK_SIZE_IN_BYTES = 128; - constexpr u32 WORDS_PER_CHUNK = 28; - constexpr u32 SAMPLES_PER_CHUNK = WORDS_PER_CHUNK * (IS_8BIT ? 4 : 8); + constexpr uint32_t NUM_CHUNKS = 18; + constexpr uint32_t CHUNK_SIZE_IN_BYTES = 128; + constexpr uint32_t WORDS_PER_CHUNK = 28; + constexpr uint32_t SAMPLES_PER_CHUNK = WORDS_PER_CHUNK * (IS_8BIT ? 4 : 8); - for (u32 i = 0; i < NUM_CHUNKS; i++) + for (uint32_t i = 0; i < NUM_CHUNKS; i++) { DecodeXA_ADPCMChunk(chunk_ptr, samples, last_samples); samples += SAMPLES_PER_CHUNK; @@ -80,13 +80,13 @@ static void DecodeXA_ADPCMChunks(const u8* chunk_ptr, s16* samples, s32* last_sa } } -void DecodeADPCMSector(const void* data, s16* samples, s32* last_samples) +void DecodeADPCMSector(const void* data, int16_t* samples, int32_t* last_samples) { const XASubHeader* subheader = reinterpret_cast( - reinterpret_cast(data) + CDImage::SECTOR_SYNC_SIZE + sizeof(CDImage::SectorHeader)); + reinterpret_cast(data) + CDImage::SECTOR_SYNC_SIZE + sizeof(CDImage::SectorHeader)); // The XA subheader is repeated? - const u8* chunk_ptr = reinterpret_cast(data) + CDImage::SECTOR_SYNC_SIZE + sizeof(CDImage::SectorHeader) + + const uint8_t* chunk_ptr = reinterpret_cast(data) + CDImage::SECTOR_SYNC_SIZE + sizeof(CDImage::SectorHeader) + sizeof(XASubHeader) + 4; if (subheader->codinginfo.bits_per_sample != 1) diff --git a/src/common/cd_xa.h b/src/common/cd_xa.h index d4a80218..7dbff765 100644 --- a/src/common/cd_xa.h +++ b/src/common/cd_xa.h @@ -4,40 +4,40 @@ namespace CDXA { -inline constexpr u32 XA_SUBHEADER_SIZE = 4, +inline constexpr uint32_t XA_SUBHEADER_SIZE = 4, XA_ADPCM_SAMPLES_PER_SECTOR_4BIT = 4032, // 28 words * 8 nibbles per word * 18 chunks XA_ADPCM_SAMPLES_PER_SECTOR_8BIT = 2016; // 28 words * 4 bytes per word * 18 chunks struct XASubHeader { - u8 file_number; - u8 channel_number; + uint8_t file_number; + uint8_t channel_number; union Submode { - u8 bits; - BitField eor; - BitField video; - BitField audio; - BitField data; - BitField trigger; - BitField form2; - BitField realtime; - BitField eof; + uint8_t bits; + BitField eor; + BitField video; + BitField audio; + BitField data; + BitField trigger; + BitField form2; + BitField realtime; + BitField eof; } submode; union Codinginfo { - u8 bits; + uint8_t bits; - BitField mono_stereo; - BitField sample_rate; - BitField bits_per_sample; - BitField emphasis; + BitField mono_stereo; + BitField sample_rate; + BitField bits_per_sample; + BitField emphasis; bool IsStereo() const { return mono_stereo == 1; } bool IsHalfSampleRate() const { return sample_rate == 1; } - u32 GetSampleRate() const { return sample_rate == 1 ? 18900 : 37800; } - u32 GetBitsPerSample() const { return bits_per_sample == 1 ? 8 : 4; } - u32 GetSamplesPerSector() const + uint32_t GetSampleRate() const { return sample_rate == 1 ? 18900 : 37800; } + uint32_t GetBitsPerSample() const { return bits_per_sample == 1 ? 8 : 4; } + uint32_t GetSamplesPerSector() const { return bits_per_sample == 1 ? XA_ADPCM_SAMPLES_PER_SECTOR_8BIT : XA_ADPCM_SAMPLES_PER_SECTOR_4BIT; } @@ -46,22 +46,22 @@ struct XASubHeader union XA_ADPCMBlockHeader { - u8 bits; + uint8_t bits; - BitField shift; - BitField filter; + BitField shift; + BitField filter; // For both 4bit and 8bit ADPCM, reserved shift values 13..15 will act same as shift=9). - u8 GetShift() const + uint8_t GetShift() const { - const u8 shift_value = shift; + const uint8_t shift_value = shift; return (shift_value > 12) ? 9 : shift_value; } - u8 GetFilter() const { return filter; } + uint8_t GetFilter() const { return filter; } }; // Decodes XA-ADPCM samples in an audio sector. Stereo samples are interleaved with left first. -void DecodeADPCMSector(const void* data, s16* samples, s32* last_samples); +void DecodeADPCMSector(const void* data, int16_t* samples, int32_t* last_samples); } // namespace CDXA diff --git a/src/common/cue_parser.cpp b/src/common/cue_parser.cpp index a3e3100a..5644e471 100644 --- a/src/common/cue_parser.cpp +++ b/src/common/cue_parser.cpp @@ -22,7 +22,7 @@ File::File() = default; File::~File() = default; -const Track* File::GetTrack(u32 n) const +const Track* File::GetTrack(uint32_t n) const { for (const auto& it : m_tracks) { @@ -33,7 +33,7 @@ const Track* File::GetTrack(u32 n) const return nullptr; } -Track* File::GetMutableTrack(u32 n) +Track* File::GetMutableTrack(uint32_t n) { for (auto& it : m_tracks) { @@ -47,7 +47,7 @@ Track* File::GetMutableTrack(u32 n) bool File::Parse(RFILE* fp, Common::Error* error) { char line[1024]; - u32 line_number = 1; + uint32_t line_number = 1; while (rfgets(line, sizeof(line), fp)) { if (!ParseLine(line, line_number, error)) @@ -65,7 +65,7 @@ bool File::Parse(RFILE* fp, Common::Error* error) return true; } -void File::SetError(u32 line_number, Common::Error* error, const char* format, ...) +void File::SetError(uint32_t line_number, Common::Error* error, const char* format, ...) { std::va_list ap; SmallString str; @@ -122,12 +122,12 @@ std::string_view File::GetToken(const char*& line) std::optional File::GetMSF(const std::string_view& token) { - static const s32 max_values[] = {std::numeric_limits::max(), 60, 75}; + static const int32_t max_values[] = {std::numeric_limits::max(), 60, 75}; - u32 parts[3] = {}; - u32 part = 0; + uint32_t parts[3] = {}; + uint32_t part = 0; - u32 start = 0; + uint32_t start = 0; for (;;) { while (start < token.length() && token[start] < '0' && token[start] <= '9') @@ -136,15 +136,15 @@ std::optional File::GetMSF(const std::string_view& token) if (start == token.length()) return std::nullopt; - u32 end = start; + uint32_t end = start; while (end < token.length() && token[end] >= '0' && token[end] <= '9') end++; - const std::optional value = StringUtil::FromChars(token.substr(start, end - start)); + const std::optional value = StringUtil::FromChars(token.substr(start, end - start)); if (!value.has_value() || value.value() < 0 || value.value() > max_values[part]) return std::nullopt; - parts[part] = static_cast(value.value()); + parts[part] = static_cast(value.value()); part++; if (part == 3) @@ -159,13 +159,13 @@ std::optional File::GetMSF(const std::string_view& token) } MSF ret; - ret.minute = static_cast(parts[0]); - ret.second = static_cast(parts[1]); - ret.frame = static_cast(parts[2]); + ret.minute = static_cast(parts[0]); + ret.second = static_cast(parts[1]); + ret.frame = static_cast(parts[2]); return ret; } -bool File::ParseLine(const char* line, u32 line_number, Common::Error* error) +bool File::ParseLine(const char* line, uint32_t line_number, Common::Error* error) { const std::string_view command(GetToken(line)); if (command.empty()) @@ -209,7 +209,7 @@ bool File::ParseLine(const char* line, u32 line_number, Common::Error* error) return false; } -bool File::HandleFileCommand(const char* line, u32 line_number, Common::Error* error) +bool File::HandleFileCommand(const char* line, uint32_t line_number, Common::Error* error) { const std::string_view filename(GetToken(line)); const std::string_view mode(GetToken(line)); @@ -230,7 +230,7 @@ bool File::HandleFileCommand(const char* line, u32 line_number, Common::Error* e return true; } -bool File::HandleTrackCommand(const char* line, u32 line_number, Common::Error* error) +bool File::HandleTrackCommand(const char* line, uint32_t line_number, Common::Error* error) { if (!CompleteLastTrack(line_number, error)) return false; @@ -248,7 +248,7 @@ bool File::HandleTrackCommand(const char* line, u32 line_number, Common::Error* return false; } - const std::optional track_number = StringUtil::FromChars(track_number_str); + const std::optional track_number = StringUtil::FromChars(track_number_str); if (track_number.value_or(0) < MIN_TRACK_NUMBER || track_number.value_or(0) > MAX_TRACK_NUMBER) { SetError(line_number, error, "Invalid track number %d", track_number.value_or(0)); @@ -280,13 +280,13 @@ bool File::HandleTrackCommand(const char* line, u32 line_number, Common::Error* } m_current_track = Track(); - m_current_track->number = static_cast(track_number.value()); + m_current_track->number = static_cast(track_number.value()); m_current_track->file = m_current_file.value(); m_current_track->mode = mode; return true; } -bool File::HandleIndexCommand(const char* line, u32 line_number, Common::Error* error) +bool File::HandleIndexCommand(const char* line, uint32_t line_number, Common::Error* error) { if (!m_current_track.has_value()) { @@ -301,14 +301,14 @@ bool File::HandleIndexCommand(const char* line, u32 line_number, Common::Error* return false; } - const std::optional index_number = StringUtil::FromChars(index_number_str); + const std::optional index_number = StringUtil::FromChars(index_number_str); if (index_number.value_or(-1) < MIN_INDEX_NUMBER || index_number.value_or(-1) > MAX_INDEX_NUMBER) { SetError(line_number, error, "Invalid index number %d", index_number.value_or(-1)); return false; } - if (m_current_track->GetIndex(static_cast(index_number.value())) != nullptr) + if (m_current_track->GetIndex(static_cast(index_number.value())) != nullptr) { SetError(line_number, error, "Duplicate index %d", index_number.value()); return false; @@ -328,11 +328,11 @@ bool File::HandleIndexCommand(const char* line, u32 line_number, Common::Error* return false; } - m_current_track->indices.emplace_back(static_cast(index_number.value()), msf.value()); + m_current_track->indices.emplace_back(static_cast(index_number.value()), msf.value()); return true; } -bool File::HandlePregapCommand(const char* line, u32 line_number, Common::Error* error) +bool File::HandlePregapCommand(const char* line, uint32_t line_number, Common::Error* error) { if (!m_current_track.has_value()) { @@ -364,7 +364,7 @@ bool File::HandlePregapCommand(const char* line, u32 line_number, Common::Error* return true; } -bool File::HandleFlagCommand(const char* line, u32 line_number, Common::Error* error) +bool File::HandleFlagCommand(const char* line, uint32_t line_number, Common::Error* error) { if (!m_current_track.has_value()) { @@ -393,7 +393,7 @@ bool File::HandleFlagCommand(const char* line, u32 line_number, Common::Error* e return true; } -bool File::CompleteLastTrack(u32 line_number, Common::Error* error) +bool File::CompleteLastTrack(uint32_t line_number, Common::Error* error) { if (!m_current_track.has_value()) return true; @@ -434,7 +434,7 @@ bool File::CompleteLastTrack(u32 line_number, Common::Error* error) return true; } -bool File::SetTrackLengths(u32 line_number, Common::Error* error) +bool File::SetTrackLengths(uint32_t line_number, Common::Error* error) { for (const Track& track : m_tracks) { @@ -464,7 +464,7 @@ bool File::SetTrackLengths(u32 line_number, Common::Error* error) return true; } -const CueParser::MSF* Track::GetIndex(u32 n) const +const CueParser::MSF* Track::GetIndex(uint32_t n) const { for (const auto& it : indices) { diff --git a/src/common/cue_parser.h b/src/common/cue_parser.h index 333ba6b2..251c387d 100644 --- a/src/common/cue_parser.h +++ b/src/common/cue_parser.h @@ -16,9 +16,9 @@ namespace CueParser { using TrackMode = CDImage::TrackMode; using MSF = CDImage::Position; -inline constexpr s32 MIN_TRACK_NUMBER = 1, MAX_TRACK_NUMBER = 99, MIN_INDEX_NUMBER = 0, MAX_INDEX_NUMBER = 99; +inline constexpr int32_t MIN_TRACK_NUMBER = 1, MAX_TRACK_NUMBER = 99, MIN_INDEX_NUMBER = 0, MAX_INDEX_NUMBER = 99; -enum class TrackFlag : u32 +enum class TrackFlag : uint32_t { PreEmphasis = (1 << 0), CopyPermitted = (1 << 1), @@ -28,20 +28,20 @@ enum class TrackFlag : u32 struct Track { - u32 number; - u32 flags; + uint32_t number; + uint32_t flags; std::string file; - std::vector> indices; + std::vector> indices; TrackMode mode; MSF start; std::optional length; std::optional zero_pregap; - const MSF* GetIndex(u32 n) const; + const MSF* GetIndex(uint32_t n) const; - ALWAYS_INLINE bool HasFlag(TrackFlag flag) const { return (flags & static_cast(flag)) != 0; } - ALWAYS_INLINE void SetFlag(TrackFlag flag) { flags |= static_cast(flag); } - ALWAYS_INLINE void RemoveFlag(TrackFlag flag) { flags &= ~static_cast(flag); } + ALWAYS_INLINE bool HasFlag(TrackFlag flag) const { return (flags & static_cast(flag)) != 0; } + ALWAYS_INLINE void SetFlag(TrackFlag flag) { flags |= static_cast(flag); } + ALWAYS_INLINE void RemoveFlag(TrackFlag flag) { flags &= ~static_cast(flag); } }; class File @@ -50,28 +50,28 @@ public: File(); ~File(); - const Track* GetTrack(u32 n) const; + const Track* GetTrack(uint32_t n) const; bool Parse(RFILE* fp, Common::Error* error); private: - Track* GetMutableTrack(u32 n); + Track* GetMutableTrack(uint32_t n); - void SetError(u32 line_number, Common::Error* error, const char* format, ...); + void SetError(uint32_t line_number, Common::Error* error, const char* format, ...); static std::string_view GetToken(const char*& line); static std::optional GetMSF(const std::string_view& token); - bool ParseLine(const char* line, u32 line_number, Common::Error* error); + bool ParseLine(const char* line, uint32_t line_number, Common::Error* error); - bool HandleFileCommand(const char* line, u32 line_number, Common::Error* error); - bool HandleTrackCommand(const char* line, u32 line_number, Common::Error* error); - bool HandleIndexCommand(const char* line, u32 line_number, Common::Error* error); - bool HandlePregapCommand(const char* line, u32 line_number, Common::Error* error); - bool HandleFlagCommand(const char* line, u32 line_number, Common::Error* error); + bool HandleFileCommand(const char* line, uint32_t line_number, Common::Error* error); + bool HandleTrackCommand(const char* line, uint32_t line_number, Common::Error* error); + bool HandleIndexCommand(const char* line, uint32_t line_number, Common::Error* error); + bool HandlePregapCommand(const char* line, uint32_t line_number, Common::Error* error); + bool HandleFlagCommand(const char* line, uint32_t line_number, Common::Error* error); - bool CompleteLastTrack(u32 line_number, Common::Error* error); - bool SetTrackLengths(u32 line_number, Common::Error* error); + bool CompleteLastTrack(uint32_t line_number, Common::Error* error); + bool SetTrackLengths(uint32_t line_number, Common::Error* error); std::vector m_tracks; std::optional m_current_file; diff --git a/src/common/d3d11/shader_cache.cpp b/src/common/d3d11/shader_cache.cpp index 281e8391..0c3d9508 100644 --- a/src/common/d3d11/shader_cache.cpp +++ b/src/common/d3d11/shader_cache.cpp @@ -14,12 +14,12 @@ namespace D3D11 { #pragma pack(push, 1) struct CacheIndexEntry { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; - u32 shader_type; - u32 file_offset; - u32 blob_size; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; + uint32_t shader_type; + uint32_t file_offset; + uint32_t blob_size; }; #pragma pack(pop) @@ -45,7 +45,7 @@ bool ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) const source_length != key.source_length || shader_type != key.shader_type); } -void ShaderCache::Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, u32 version, bool debug) +void ShaderCache::Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, uint32_t version, bool debug) { m_feature_level = feature_level; m_version = version; @@ -82,7 +82,7 @@ bool ShaderCache::CreateNew(const std::string& index_filename, const std::string return false; } - const u32 index_version = FILE_VERSION; + const uint32_t index_version = FILE_VERSION; if (rfwrite(&index_version, sizeof(index_version), 1, m_index_file) != 1 || rfwrite(&m_version, sizeof(m_version), 1, m_index_file) != 1) { @@ -112,8 +112,8 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str if (!m_index_file) return false; - u32 file_version = 0; - u32 data_version = 0; + uint32_t file_version = 0; + uint32_t data_version = 0; if (rfread(&file_version, sizeof(file_version), 1, m_index_file) != 1 || file_version != FILE_VERSION || rfread(&data_version, sizeof(data_version), 1, m_index_file) != 1 || data_version != m_version) { @@ -133,7 +133,7 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str } rfseek(m_blob_file, 0, SEEK_END); - const u32 blob_file_size = static_cast(rftell(m_blob_file)); + const uint32_t blob_file_size = static_cast(rftell(m_blob_file)); for (;;) { @@ -200,17 +200,17 @@ ShaderCache::CacheIndexKey ShaderCache::GetCacheKey(ShaderCompiler::Type type, c { struct { - u64 hash_low; - u64 hash_high; + uint64_t hash_low; + uint64_t hash_high; } s; - u8 hash[16]; + uint8_t hash[16]; }; MD5Digest digest; - digest.Update(shader_code.data(), static_cast(shader_code.length())); + digest.Update(shader_code.data(), static_cast(shader_code.length())); digest.Final(hash); - return CacheIndexKey{s.hash_low, s.hash_high, static_cast(shader_code.length()), type}; + return CacheIndexKey{s.hash_low, s.hash_high, static_cast(shader_code.length()), type}; } ShaderCache::ComPtr ShaderCache::GetShaderBlob(ShaderCompiler::Type type, std::string_view shader_code) @@ -261,14 +261,14 @@ ShaderCache::ComPtr ShaderCache::CompileAndAddShaderBlob(const CacheIn return blob; CacheIndexData data; - data.file_offset = static_cast(rftell(m_blob_file)); - data.blob_size = static_cast(blob->GetBufferSize()); + data.file_offset = static_cast(rftell(m_blob_file)); + data.blob_size = static_cast(blob->GetBufferSize()); CacheIndexEntry entry = {}; entry.source_hash_low = key.source_hash_low; entry.source_hash_high = key.source_hash_high; entry.source_length = key.source_length; - entry.shader_type = static_cast(key.shader_type); + entry.shader_type = static_cast(key.shader_type); entry.blob_size = data.blob_size; entry.file_offset = data.file_offset; diff --git a/src/common/d3d11/shader_cache.h b/src/common/d3d11/shader_cache.h index d19aab7b..69671d2a 100644 --- a/src/common/d3d11/shader_cache.h +++ b/src/common/d3d11/shader_cache.h @@ -22,7 +22,7 @@ public: ShaderCache(); ~ShaderCache(); - void Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, u32 version, bool debug); + void Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_level, uint32_t version, bool debug); // Returns whether Open() has already been called successfully on // this instance. Used by the persistent (lazy-compile) GPU backend @@ -37,13 +37,13 @@ public: ComPtr GetPixelShader(ID3D11Device* device, std::string_view shader_code); private: - static constexpr u32 FILE_VERSION = 2; + static constexpr uint32_t FILE_VERSION = 2; struct CacheIndexKey { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; ShaderCompiler::Type shader_type; bool operator==(const CacheIndexKey& key) const; @@ -62,8 +62,8 @@ private: struct CacheIndexData { - u32 file_offset; - u32 blob_size; + uint32_t file_offset; + uint32_t blob_size; }; using CacheIndex = std::unordered_map; @@ -84,7 +84,7 @@ private: CacheIndex m_index; D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_11_0; - u32 m_version = 0; + uint32_t m_version = 0; bool m_debug = false; }; diff --git a/src/common/d3d11/staging_texture.cpp b/src/common/d3d11/staging_texture.cpp index c58ccc74..db7ee1c6 100644 --- a/src/common/d3d11/staging_texture.cpp +++ b/src/common/d3d11/staging_texture.cpp @@ -10,7 +10,7 @@ StagingTexture::~StagingTexture() Destroy(); } -bool StagingTexture::Create(ID3D11Device* device, u32 width, u32 height, DXGI_FORMAT format, bool for_uploading) +bool StagingTexture::Create(ID3D11Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading) { CD3D11_TEXTURE2D_DESC desc(format, width, height, 1, 1, 0, for_uploading ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_STAGING, for_uploading ? D3D11_CPU_ACCESS_WRITE : D3D11_CPU_ACCESS_READ, 1, 0, 0); @@ -47,8 +47,8 @@ void StagingTexture::Unmap(ID3D11DeviceContext* context) m_map = {}; } -void StagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, u32 src_subresource, - u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) +void StagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, uint32_t src_subresource, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height) { D3D11_BOX box; box.left = static_cast(src_x); @@ -60,7 +60,7 @@ void StagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resourc context->CopySubresourceRegion(m_texture.Get(), 0, dst_x, dst_y, 0, src_texture, src_subresource, &box); } -bool AutoStagingTexture::EnsureSize(ID3D11DeviceContext* context, u32 width, u32 height, DXGI_FORMAT format, +bool AutoStagingTexture::EnsureSize(ID3D11DeviceContext* context, uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading) { if (m_texture && m_width >= width && m_height >= height && m_format == format) @@ -84,8 +84,8 @@ bool AutoStagingTexture::EnsureSize(ID3D11DeviceContext* context, u32 width, u32 return true; } -void AutoStagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, u32 src_subresource, - u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) +void AutoStagingTexture::CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, uint32_t src_subresource, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height) { if (!EnsureSize(context, width, height, m_format, false)) return; diff --git a/src/common/d3d11/staging_texture.h b/src/common/d3d11/staging_texture.h index 101768ba..3373f1ed 100644 --- a/src/common/d3d11/staging_texture.h +++ b/src/common/d3d11/staging_texture.h @@ -17,30 +17,30 @@ public: ALWAYS_INLINE ID3D11Texture2D* GetD3DTexture() const { return m_texture.Get(); } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return m_format; } ALWAYS_INLINE bool IsMapped() const { return m_map.pData != nullptr; } ALWAYS_INLINE operator bool() const { return static_cast(m_texture); } - bool Create(ID3D11Device* device, u32 width, u32 height, DXGI_FORMAT format, bool for_uploading); + bool Create(ID3D11Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading); void Destroy(); bool Map(ID3D11DeviceContext* context, bool writing); void Unmap(ID3D11DeviceContext* context); - void CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, u32 src_subresource, u32 src_x, - u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height); + void CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, uint32_t src_subresource, uint32_t src_x, + uint32_t src_y, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height); template - void ReadPixels(u32 x, u32 y, u32 width, u32 height, u32 stride, T* data) + void ReadPixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t stride, T* data) { - const u8* src_ptr = static_cast(m_map.pData) + (y * m_map.RowPitch) + (x * sizeof(T)); - u8* dst_ptr = reinterpret_cast(data); + const uint8_t* src_ptr = static_cast(m_map.pData) + (y * m_map.RowPitch) + (x * sizeof(T)); + uint8_t* dst_ptr = reinterpret_cast(data); if (m_map.RowPitch != stride || width != m_width || x != 0) { - for (u32 row = 0; row < height; row++) + for (uint32_t row = 0; row < height; row++) { std::memcpy(dst_ptr, src_ptr, sizeof(T) * width); src_ptr += m_map.RowPitch; @@ -53,8 +53,8 @@ public: protected: ComPtr m_texture; - u32 m_width; - u32 m_height; + uint32_t m_width; + uint32_t m_height; DXGI_FORMAT m_format; D3D11_MAPPED_SUBRESOURCE m_map = {}; @@ -63,9 +63,9 @@ protected: class AutoStagingTexture : public StagingTexture { public: - bool EnsureSize(ID3D11DeviceContext* context, u32 width, u32 height, DXGI_FORMAT format, bool for_uploading); + bool EnsureSize(ID3D11DeviceContext* context, uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading); - void CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, u32 src_subresource, u32 src_x, - u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height); + void CopyFromTexture(ID3D11DeviceContext* context, ID3D11Resource* src_texture, uint32_t src_subresource, uint32_t src_x, + uint32_t src_y, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height); }; } // namespace D3D11 diff --git a/src/common/d3d11/stream_buffer.cpp b/src/common/d3d11/stream_buffer.cpp index 630be68d..efb80082 100644 --- a/src/common/d3d11/stream_buffer.cpp +++ b/src/common/d3d11/stream_buffer.cpp @@ -19,7 +19,7 @@ StreamBuffer::~StreamBuffer() Release(); } -bool StreamBuffer::Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, u32 size) +bool StreamBuffer::Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, uint32_t size) { CD3D11_BUFFER_DESC desc(size, bind_flags, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE, 0, 0); ComPtr buffer; @@ -66,7 +66,7 @@ void StreamBuffer::Release() m_buffer.Reset(); } -StreamBuffer::MappingResult StreamBuffer::Map(ID3D11DeviceContext* context, u32 alignment, u32 min_size) +StreamBuffer::MappingResult StreamBuffer::Map(ID3D11DeviceContext* context, uint32_t alignment, uint32_t min_size) { m_position = Common::AlignUp(m_position, alignment); if ((m_position + min_size) >= m_size || !m_use_map_no_overwrite) @@ -81,7 +81,7 @@ StreamBuffer::MappingResult StreamBuffer::Map(ID3D11DeviceContext* context, u32 if (FAILED(hr)) { Log_ErrorPrintf("Map failed: 0x%08X (alignment %u, minsize %u, size %u, position %u, map type %u)", hr, alignment, - min_size, m_size, m_position, static_cast(map_type)); + min_size, m_size, m_position, static_cast(map_type)); return {}; } @@ -89,7 +89,7 @@ StreamBuffer::MappingResult StreamBuffer::Map(ID3D11DeviceContext* context, u32 (m_size - m_position) / alignment}; } -void StreamBuffer::Unmap(ID3D11DeviceContext* context, u32 used_size) +void StreamBuffer::Unmap(ID3D11DeviceContext* context, uint32_t used_size) { context->Unmap(m_buffer.Get(), 0); m_position += used_size; diff --git a/src/common/d3d11/stream_buffer.h b/src/common/d3d11/stream_buffer.h index 50da4e3c..759ab316 100644 --- a/src/common/d3d11/stream_buffer.h +++ b/src/common/d3d11/stream_buffer.h @@ -17,27 +17,27 @@ public: ALWAYS_INLINE ID3D11Buffer* GetD3DBuffer() const { return m_buffer.Get(); } ALWAYS_INLINE ID3D11Buffer* const* GetD3DBufferArray() const { return m_buffer.GetAddressOf(); } - ALWAYS_INLINE u32 GetSize() const { return m_size; } - ALWAYS_INLINE u32 GetPosition() const { return m_position; } + ALWAYS_INLINE uint32_t GetSize() const { return m_size; } + ALWAYS_INLINE uint32_t GetPosition() const { return m_position; } - bool Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, u32 size); + bool Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, uint32_t size); void Release(); struct MappingResult { void* pointer; - u32 buffer_offset; - u32 index_aligned; // offset / alignment, suitable for base vertex - u32 space_aligned; // remaining space / alignment + uint32_t buffer_offset; + uint32_t index_aligned; // offset / alignment, suitable for base vertex + uint32_t space_aligned; // remaining space / alignment }; - MappingResult Map(ID3D11DeviceContext* context, u32 alignment, u32 min_size); - void Unmap(ID3D11DeviceContext* context, u32 used_size); + MappingResult Map(ID3D11DeviceContext* context, uint32_t alignment, uint32_t min_size); + void Unmap(ID3D11DeviceContext* context, uint32_t used_size); private: ComPtr m_buffer; - u32 m_size; - u32 m_position; + uint32_t m_size; + uint32_t m_position; bool m_use_map_no_overwrite = false; }; } // namespace GL diff --git a/src/common/d3d11/texture.cpp b/src/common/d3d11/texture.cpp index 7ebb2008..cfd5ecb4 100644 --- a/src/common/d3d11/texture.cpp +++ b/src/common/d3d11/texture.cpp @@ -13,7 +13,7 @@ Texture::Texture(ComPtr texture, ComPtr(desc.SampleDesc.Count); + m_samples = static_cast(desc.SampleDesc.Count); } Texture::~Texture() @@ -28,8 +28,8 @@ D3D11_TEXTURE2D_DESC Texture::GetDesc() const return desc; } -bool Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 levels, u32 samples, DXGI_FORMAT format, - u32 bind_flags, const void* initial_data /* = nullptr */, u32 initial_data_stride /* = 0 */, +bool Texture::Create(ID3D11Device* device, uint32_t width, uint32_t height, uint32_t levels, uint32_t samples, DXGI_FORMAT format, + uint32_t bind_flags, const void* initial_data /* = nullptr */, uint32_t initial_data_stride /* = 0 */, bool dynamic) { CD3D11_TEXTURE2D_DESC desc(format, width, height, 1, levels, bind_flags, @@ -84,8 +84,8 @@ bool Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 levels, u3 m_rtv = std::move(rtv); m_width = width; m_height = height; - m_levels = static_cast(levels); - m_samples = static_cast(samples); + m_levels = static_cast(levels); + m_samples = static_cast(samples); return true; } diff --git a/src/common/d3d11/texture.h b/src/common/d3d11/texture.h index 7c92d069..e12d9f96 100644 --- a/src/common/d3d11/texture.h +++ b/src/common/d3d11/texture.h @@ -21,10 +21,10 @@ public: ALWAYS_INLINE ID3D11ShaderResourceView* const* GetD3DSRVArray() const { return m_srv.GetAddressOf(); } ALWAYS_INLINE ID3D11RenderTargetView* const* GetD3DRTVArray() const { return m_rtv.GetAddressOf(); } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } - ALWAYS_INLINE u16 GetLevels() const { return m_levels; } - ALWAYS_INLINE u16 GetSamples() const { return m_samples; } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } + ALWAYS_INLINE uint16_t GetLevels() const { return m_levels; } + ALWAYS_INLINE uint16_t GetSamples() const { return m_samples; } ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; } ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return GetDesc().Format; } D3D11_TEXTURE2D_DESC GetDesc() const; @@ -34,8 +34,8 @@ public: ALWAYS_INLINE operator ID3D11RenderTargetView*() const { return m_rtv.Get(); } ALWAYS_INLINE operator bool() const { return static_cast(m_texture); } - bool Create(ID3D11Device* device, u32 width, u32 height, u32 levels, u32 samples, DXGI_FORMAT format, u32 bind_flags, - const void* initial_data = nullptr, u32 initial_data_stride = 0, bool dynamic = false); + bool Create(ID3D11Device* device, uint32_t width, uint32_t height, uint32_t levels, uint32_t samples, DXGI_FORMAT format, uint32_t bind_flags, + const void* initial_data = nullptr, uint32_t initial_data_stride = 0, bool dynamic = false); void Destroy(); @@ -43,9 +43,9 @@ private: ComPtr m_texture; ComPtr m_srv; ComPtr m_rtv; - u32 m_width; - u32 m_height; - u16 m_levels; - u16 m_samples; + uint32_t m_width; + uint32_t m_height; + uint16_t m_levels; + uint16_t m_samples; }; } // namespace D3D11 diff --git a/src/common/d3d12/context.cpp b/src/common/d3d12/context.cpp index 3eee57a7..35fc44e1 100644 --- a/src/common/d3d12/context.cpp +++ b/src/common/d3d12/context.cpp @@ -118,14 +118,14 @@ D3D12::Context::ComPtr Context::CreateRootSignature(const D bool Context::SupportsTextureFormat(DXGI_FORMAT format) { - const u32 required = D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE; + const uint32_t required = D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE; D3D12_FEATURE_DATA_FORMAT_SUPPORT support = {format}; return SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &support, sizeof(support))) && (support.Support1 & required) == required; } -bool Context::Create(IDXGIFactory* dxgi_factory, u32 adapter_index, bool enable_debug_layer) +bool Context::Create(IDXGIFactory* dxgi_factory, uint32_t adapter_index, bool enable_debug_layer) { if (!LoadD3D12Library()) return false; @@ -151,7 +151,7 @@ void Context::Destroy() UnloadD3D12Library(); } -bool Context::CreateDevice(IDXGIFactory* dxgi_factory, u32 adapter_index, bool enable_debug_layer) +bool Context::CreateDevice(IDXGIFactory* dxgi_factory, uint32_t adapter_index, bool enable_debug_layer) { ComPtr adapter; HRESULT hr = dxgi_factory->EnumAdapters(adapter_index, &adapter); @@ -274,7 +274,7 @@ bool Context::CreateDescriptorHeaps() bool Context::CreateCommandLists() { - for (u32 i = 0; i < NUM_COMMAND_LISTS; i++) + for (uint32_t i = 0; i < NUM_COMMAND_LISTS; i++) { CommandListResources& res = m_command_lists[i]; HRESULT hr = m_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, @@ -347,7 +347,7 @@ void Context::DeferResourceDestruction(ID3D12Resource* resource) m_command_lists[m_current_command_list].pending_resources.push_back(resource); } -void Context::DeferDescriptorDestruction(DescriptorHeapManager& manager, u32 index) +void Context::DeferDescriptorDestruction(DescriptorHeapManager& manager, uint32_t index) { m_command_lists[m_current_command_list].pending_descriptors.emplace_back(manager, index); } @@ -397,7 +397,7 @@ void Context::DestroyResources() m_device.Reset(); } -void Context::WaitForFence(u64 fence) +void Context::WaitForFence(uint64_t fence) { if (m_completed_fence_value >= fence) return; @@ -413,8 +413,8 @@ void Context::WaitForFence(u64 fence) } // Release resources for as many command lists which have completed. - u32 index = (m_current_command_list + 1) % NUM_COMMAND_LISTS; - for (u32 i = 0; i < NUM_COMMAND_LISTS; i++) + uint32_t index = (m_current_command_list + 1) % NUM_COMMAND_LISTS; + for (uint32_t i = 0; i < NUM_COMMAND_LISTS; i++) { CommandListResources& res = m_command_lists[index]; if (m_completed_fence_value < res.ready_fence_value) @@ -427,8 +427,8 @@ void Context::WaitForFence(u64 fence) void Context::WaitForGPUIdle() { - u32 index = (m_current_command_list + 1) % NUM_COMMAND_LISTS; - for (u32 i = 0; i < (NUM_COMMAND_LISTS - 1); i++) + uint32_t index = (m_current_command_list + 1) % NUM_COMMAND_LISTS; + for (uint32_t i = 0; i < (NUM_COMMAND_LISTS - 1); i++) { WaitForFence(m_command_lists[index].ready_fence_value); index = (index + 1) % NUM_COMMAND_LISTS; diff --git a/src/common/d3d12/context.h b/src/common/d3d12/context.h index 429abcb6..27d3bb9a 100644 --- a/src/common/d3d12/context.h +++ b/src/common/d3d12/context.h @@ -24,7 +24,7 @@ public: template using ComPtr = Microsoft::WRL::ComPtr; - static constexpr u32 + static constexpr uint32_t // Number of command lists. One is being built while the other(s) are executed. NUM_COMMAND_LISTS = 3, @@ -34,7 +34,7 @@ public: ~Context(); // Creates new device and context. - static bool Create(IDXGIFactory* dxgi_factory, u32 adapter_index, bool enable_debug_layer); + static bool Create(IDXGIFactory* dxgi_factory, uint32_t adapter_index, bool enable_debug_layer); // Destroys active context. static void Destroy(); @@ -54,7 +54,7 @@ public: DescriptorHeapManager& GetDSVHeapManager() { return m_dsv_heap_manager; } DescriptorHeapManager& GetSamplerHeapManager() { return m_sampler_heap_manager; } ID3D12DescriptorHeap* const* GetGPUDescriptorHeaps() const { return m_gpu_descriptor_heaps.data(); } - u32 GetGPUDescriptorHeapCount() const { return static_cast(m_gpu_descriptor_heaps.size()); } + uint32_t GetGPUDescriptorHeapCount() const { return static_cast(m_gpu_descriptor_heaps.size()); } const DescriptorHandle& GetNullSRVDescriptor() const { return m_null_srv_descriptor; } StreamBuffer& GetTextureStreamBuffer() { return m_texture_stream_buffer; } @@ -63,10 +63,10 @@ public: ComPtr CreateRootSignature(const D3D12_ROOT_SIGNATURE_DESC* desc); // Fence value for current command list. - u64 GetCurrentFenceValue() const { return m_current_fence_value; } + uint64_t GetCurrentFenceValue() const { return m_current_fence_value; } // Last "completed" fence. - u64 GetCompletedFenceValue() const { return m_completed_fence_value; } + uint64_t GetCompletedFenceValue() const { return m_completed_fence_value; } // Feature level to use when compiling shaders. D3D_FEATURE_LEVEL GetFeatureLevel() const { return m_feature_level; } @@ -78,7 +78,7 @@ public: void ExecuteCommandList(bool wait_for_completion); // Waits for a specific fence. - void WaitForFence(u64 fence); + void WaitForFence(uint64_t fence); // Waits for any in-flight command buffers to complete. void WaitForGPUIdle(); @@ -87,7 +87,7 @@ public: void DeferResourceDestruction(ID3D12Resource* resource); // Defers destruction of a descriptor handle (associates it with the current list). - void DeferDescriptorDestruction(DescriptorHeapManager& manager, u32 index); + void DeferDescriptorDestruction(DescriptorHeapManager& manager, uint32_t index); void DeferDescriptorDestruction(DescriptorHeapManager& manager, DescriptorHandle* handle); private: @@ -96,13 +96,13 @@ private: ComPtr command_allocator; ComPtr command_list; std::vector pending_resources; - std::vector> pending_descriptors; - u64 ready_fence_value = 0; + std::vector> pending_descriptors; + uint64_t ready_fence_value = 0; }; Context(); - bool CreateDevice(IDXGIFactory* dxgi_factory, u32 adapter_index, bool enable_debug_layer); + bool CreateDevice(IDXGIFactory* dxgi_factory, uint32_t adapter_index, bool enable_debug_layer); bool CreateCommandQueue(); bool CreateFence(); bool CreateDescriptorHeaps(); @@ -118,11 +118,11 @@ private: ComPtr m_fence = nullptr; HANDLE m_fence_event = {}; - u32 m_current_fence_value = 0; - u64 m_completed_fence_value = 0; + uint32_t m_current_fence_value = 0; + uint64_t m_completed_fence_value = 0; std::array m_command_lists; - u32 m_current_command_list = NUM_COMMAND_LISTS - 1; + uint32_t m_current_command_list = NUM_COMMAND_LISTS - 1; DescriptorHeapManager m_descriptor_heap_manager; DescriptorHeapManager m_rtv_heap_manager; diff --git a/src/common/d3d12/descriptor_heap_manager.cpp b/src/common/d3d12/descriptor_heap_manager.cpp index 2c1bebf5..36a2ac14 100644 --- a/src/common/d3d12/descriptor_heap_manager.cpp +++ b/src/common/d3d12/descriptor_heap_manager.cpp @@ -11,7 +11,7 @@ namespace D3D12 { DescriptorHeapManager::DescriptorHeapManager() = default; DescriptorHeapManager::~DescriptorHeapManager() = default; -bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors, +bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t num_descriptors, bool shader_visible) { D3D12_DESCRIPTOR_HEAP_DESC desc = {type, static_cast(num_descriptors), @@ -28,7 +28,7 @@ bool DescriptorHeapManager::Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_T m_descriptor_increment_size = device->GetDescriptorHandleIncrementSize(type); // Set all slots to unallocated (1) - const u32 bitset_count = num_descriptors / BITSET_SIZE + (((num_descriptors % BITSET_SIZE) != 0) ? 1 : 0); + const uint32_t bitset_count = num_descriptors / BITSET_SIZE + (((num_descriptors % BITSET_SIZE) != 0) ? 1 : 0); m_free_slots.resize(bitset_count); for (BitSetType& bs : m_free_slots) bs.flip(); @@ -49,20 +49,20 @@ void DescriptorHeapManager::Destroy() bool DescriptorHeapManager::Allocate(DescriptorHandle* handle) { // Start past the temporary slots, no point in searching those. - for (u32 group = 0; group < m_free_slots.size(); group++) + for (uint32_t group = 0; group < m_free_slots.size(); group++) { BitSetType& bs = m_free_slots[group]; if (bs.none()) continue; - u32 bit = 0; + uint32_t bit = 0; for (; bit < BITSET_SIZE; bit++) { if (bs[bit]) break; } - u32 index = group * BITSET_SIZE + bit; + uint32_t index = group * BITSET_SIZE + bit; bs[bit] = false; handle->index = index; @@ -73,10 +73,10 @@ bool DescriptorHeapManager::Allocate(DescriptorHandle* handle) return false; } -void DescriptorHeapManager::Free(u32 index) +void DescriptorHeapManager::Free(uint32_t index) { - u32 group = index / BITSET_SIZE; - u32 bit = index % BITSET_SIZE; + uint32_t group = index / BITSET_SIZE; + uint32_t bit = index % BITSET_SIZE; m_free_slots[group][bit] = true; } diff --git a/src/common/d3d12/descriptor_heap_manager.h b/src/common/d3d12/descriptor_heap_manager.h index 6372ec50..349cd807 100644 --- a/src/common/d3d12/descriptor_heap_manager.h +++ b/src/common/d3d12/descriptor_heap_manager.h @@ -16,11 +16,11 @@ namespace D3D12 { // This class provides an abstraction for D3D12 descriptor heaps. struct DescriptorHandle final { - static constexpr u32 INVALID_INDEX = 0xFFFFFFFF; + static constexpr uint32_t INVALID_INDEX = 0xFFFFFFFF; D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle{}; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle{}; - u32 index = INVALID_INDEX; + uint32_t index = INVALID_INDEX; ALWAYS_INLINE operator bool() const { return index != INVALID_INDEX; } @@ -42,24 +42,24 @@ public: ~DescriptorHeapManager(); ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.Get(); } - u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; } + uint32_t GetDescriptorIncrementSize() const { return m_descriptor_increment_size; } - bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors, bool shader_visible); + bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t num_descriptors, bool shader_visible); void Destroy(); bool Allocate(DescriptorHandle* handle); void Free(DescriptorHandle* handle); - void Free(u32 index); + void Free(uint32_t index); private: Microsoft::WRL::ComPtr m_descriptor_heap; - u32 m_num_descriptors = 0; - u32 m_descriptor_increment_size = 0; + uint32_t m_num_descriptors = 0; + uint32_t m_descriptor_increment_size = 0; D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {}; D3D12_GPU_DESCRIPTOR_HANDLE m_heap_base_gpu = {}; - static constexpr u32 BITSET_SIZE = 1024; + static constexpr uint32_t BITSET_SIZE = 1024; using BitSetType = std::bitset; std::vector m_free_slots = {}; }; diff --git a/src/common/d3d12/shader_cache.cpp b/src/common/d3d12/shader_cache.cpp index 3b4381df..b65a39b8 100644 --- a/src/common/d3d12/shader_cache.cpp +++ b/src/common/d3d12/shader_cache.cpp @@ -15,12 +15,12 @@ namespace D3D12 { #pragma pack(push, 1) struct CacheIndexEntry { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; - u32 shader_type; - u32 file_offset; - u32 blob_size; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; + uint32_t shader_type; + uint32_t file_offset; + uint32_t blob_size; }; #pragma pack(pop) @@ -134,7 +134,7 @@ bool ShaderCache::CreateNew(const std::string& index_filename, const std::string return false; } - const u32 index_version = FILE_VERSION; + const uint32_t index_version = FILE_VERSION; if (rfwrite(&index_version, sizeof(index_version), 1, index_file) != 1) { Log_ErrorPrintf("Failed to write version to index file '%s'", index_filename.c_str()); @@ -164,7 +164,7 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str if (!index_file) return false; - u32 file_version; + uint32_t file_version; if (rfread(&file_version, sizeof(file_version), 1, index_file) != 1 || file_version != FILE_VERSION) { Log_ErrorPrintf("Bad file version in '%s'", index_filename.c_str()); @@ -183,7 +183,7 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str } rfseek(blob_file, 0, SEEK_END); - const u32 blob_file_size = static_cast(rftell(blob_file)); + const uint32_t blob_file_size = static_cast(rftell(blob_file)); for (;;) { @@ -249,41 +249,41 @@ union MD5Hash { struct { - u64 low; - u64 high; + uint64_t low; + uint64_t high; }; - u8 hash[16]; + uint8_t hash[16]; }; ShaderCache::CacheIndexKey ShaderCache::GetShaderCacheKey(EntryType type, const std::string_view& shader_code) { MD5Hash h; MD5Digest digest; - digest.Update(shader_code.data(), static_cast(shader_code.length())); + digest.Update(shader_code.data(), static_cast(shader_code.length())); digest.Final(h.hash); - return CacheIndexKey{h.low, h.high, static_cast(shader_code.length()), type}; + return CacheIndexKey{h.low, h.high, static_cast(shader_code.length()), type}; } ShaderCache::CacheIndexKey ShaderCache::GetPipelineCacheKey(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& gpdesc) { MD5Digest digest; - u32 length = sizeof(D3D12_GRAPHICS_PIPELINE_STATE_DESC); + uint32_t length = sizeof(D3D12_GRAPHICS_PIPELINE_STATE_DESC); if (gpdesc.VS.BytecodeLength > 0) { - digest.Update(gpdesc.VS.pShaderBytecode, static_cast(gpdesc.VS.BytecodeLength)); - length += static_cast(gpdesc.VS.BytecodeLength); + digest.Update(gpdesc.VS.pShaderBytecode, static_cast(gpdesc.VS.BytecodeLength)); + length += static_cast(gpdesc.VS.BytecodeLength); } if (gpdesc.GS.BytecodeLength > 0) { - digest.Update(gpdesc.GS.pShaderBytecode, static_cast(gpdesc.GS.BytecodeLength)); - length += static_cast(gpdesc.GS.BytecodeLength); + digest.Update(gpdesc.GS.pShaderBytecode, static_cast(gpdesc.GS.BytecodeLength)); + length += static_cast(gpdesc.GS.BytecodeLength); } if (gpdesc.PS.BytecodeLength > 0) { - digest.Update(gpdesc.PS.pShaderBytecode, static_cast(gpdesc.PS.BytecodeLength)); - length += static_cast(gpdesc.PS.BytecodeLength); + digest.Update(gpdesc.PS.pShaderBytecode, static_cast(gpdesc.PS.BytecodeLength)); + length += static_cast(gpdesc.PS.BytecodeLength); } digest.Update(&gpdesc.BlendState, sizeof(gpdesc.BlendState)); @@ -291,10 +291,10 @@ ShaderCache::CacheIndexKey ShaderCache::GetPipelineCacheKey(const D3D12_GRAPHICS digest.Update(&gpdesc.RasterizerState, sizeof(gpdesc.RasterizerState)); digest.Update(&gpdesc.DepthStencilState, sizeof(gpdesc.DepthStencilState)); - for (u32 i = 0; i < gpdesc.InputLayout.NumElements; i++) + for (uint32_t i = 0; i < gpdesc.InputLayout.NumElements; i++) { const D3D12_INPUT_ELEMENT_DESC& ie = gpdesc.InputLayout.pInputElementDescs[i]; - digest.Update(ie.SemanticName, static_cast(std::strlen(ie.SemanticName))); + digest.Update(ie.SemanticName, static_cast(std::strlen(ie.SemanticName))); digest.Update(&ie.SemanticIndex, sizeof(ie.SemanticIndex)); digest.Update(&ie.Format, sizeof(ie.Format)); digest.Update(&ie.InputSlot, sizeof(ie.InputSlot)); @@ -401,14 +401,14 @@ ShaderCache::ComPtr ShaderCache::CompileAndAddShaderBlob(const CacheIn return blob; CacheIndexData data; - data.file_offset = static_cast(rftell(m_shader_blob_file)); - data.blob_size = static_cast(blob->GetBufferSize()); + data.file_offset = static_cast(rftell(m_shader_blob_file)); + data.blob_size = static_cast(blob->GetBufferSize()); CacheIndexEntry entry = {}; entry.source_hash_low = key.source_hash_low; entry.source_hash_high = key.source_hash_high; entry.source_length = key.source_length; - entry.shader_type = static_cast(key.type); + entry.shader_type = static_cast(key.type); entry.blob_size = data.blob_size; entry.file_offset = data.file_offset; @@ -448,14 +448,14 @@ ShaderCache::CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& ke } CacheIndexData data; - data.file_offset = static_cast(rftell(m_pipeline_blob_file)); - data.blob_size = static_cast(blob->GetBufferSize()); + data.file_offset = static_cast(rftell(m_pipeline_blob_file)); + data.blob_size = static_cast(blob->GetBufferSize()); CacheIndexEntry entry = {}; entry.source_hash_low = key.source_hash_low; entry.source_hash_high = key.source_hash_high; entry.source_length = key.source_length; - entry.shader_type = static_cast(key.type); + entry.shader_type = static_cast(key.type); entry.blob_size = data.blob_size; entry.file_offset = data.file_offset; diff --git a/src/common/d3d12/shader_cache.h b/src/common/d3d12/shader_cache.h index 44ddbc1a..54686dcb 100644 --- a/src/common/d3d12/shader_cache.h +++ b/src/common/d3d12/shader_cache.h @@ -55,13 +55,13 @@ public: ComPtr GetPipelineState(ID3D12Device* device, const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc); private: - static constexpr u32 FILE_VERSION = 1; + static constexpr uint32_t FILE_VERSION = 1; struct CacheIndexKey { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; EntryType type; bool operator==(const CacheIndexKey& key) const; @@ -80,8 +80,8 @@ private: struct CacheIndexData { - u32 file_offset; - u32 blob_size; + uint32_t file_offset; + uint32_t blob_size; }; using CacheIndex = std::unordered_map; diff --git a/src/common/d3d12/staging_texture.cpp b/src/common/d3d12/staging_texture.cpp index 6926d141..3fd15f33 100644 --- a/src/common/d3d12/staging_texture.cpp +++ b/src/common/d3d12/staging_texture.cpp @@ -13,11 +13,11 @@ StagingTexture::~StagingTexture() Destroy(); } -bool StagingTexture::Create(u32 width, u32 height, DXGI_FORMAT format, bool for_uploading) +bool StagingTexture::Create(uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading) { - const u32 texel_size = GetTexelSize(format); - const u32 row_pitch = Common::AlignUpPow2(width * texel_size, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); - const u32 buffer_size = height * row_pitch; + const uint32_t texel_size = GetTexelSize(format); + const uint32_t row_pitch = Common::AlignUpPow2(width * texel_size, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); + const uint32_t buffer_size = height * row_pitch; const D3D12_HEAP_PROPERTIES heap_properties = {for_uploading ? D3D12_HEAP_TYPE_UPLOAD : D3D12_HEAP_TYPE_READBACK}; @@ -104,8 +104,8 @@ void StagingTexture::Flush() g_d3d12_context->WaitForFence(m_completed_fence); } -void StagingTexture::CopyToTexture(u32 src_x, u32 src_y, ID3D12Resource* dst_texture, u32 dst_subresource, u32 dst_x, - u32 dst_y, u32 width, u32 height) +void StagingTexture::CopyToTexture(uint32_t src_x, uint32_t src_y, ID3D12Resource* dst_texture, uint32_t dst_subresource, uint32_t dst_x, + uint32_t dst_y, uint32_t width, uint32_t height) { D3D12_TEXTURE_COPY_LOCATION dst; dst.pResource = dst_texture; @@ -127,8 +127,8 @@ void StagingTexture::CopyToTexture(u32 src_x, u32 src_y, ID3D12Resource* dst_tex g_d3d12_context->GetCommandList()->CopyTextureRegion(&dst, dst_x, dst_y, 0, &src, &src_box); } -void StagingTexture::CopyFromTexture(ID3D12Resource* src_texture, u32 src_subresource, u32 src_x, u32 src_y, u32 dst_x, - u32 dst_y, u32 width, u32 height) +void StagingTexture::CopyFromTexture(ID3D12Resource* src_texture, uint32_t src_subresource, uint32_t src_x, uint32_t src_y, uint32_t dst_x, + uint32_t dst_y, uint32_t width, uint32_t height) { D3D12_TEXTURE_COPY_LOCATION src; src.pResource = src_texture; @@ -152,7 +152,7 @@ void StagingTexture::CopyFromTexture(ID3D12Resource* src_texture, u32 src_subres m_needs_flush = true; } -bool StagingTexture::ReadPixels(u32 x, u32 y, u32 width, u32 height, void* data, u32 row_pitch) +bool StagingTexture::ReadPixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* data, uint32_t row_pitch) { if (m_needs_flush) Flush(); @@ -161,12 +161,12 @@ bool StagingTexture::ReadPixels(u32 x, u32 y, u32 width, u32 height, void* data, if (!was_mapped && !Map(false)) return false; - const u8* src_ptr = static_cast(m_mapped_pointer) + (y * m_row_pitch) + (x * m_texel_size); - u8* dst_ptr = reinterpret_cast(data); + const uint8_t* src_ptr = static_cast(m_mapped_pointer) + (y * m_row_pitch) + (x * m_texel_size); + uint8_t* dst_ptr = reinterpret_cast(data); if (m_row_pitch != row_pitch || width != m_width || x != 0) { - const u32 copy_size = m_texel_size * width; - for (u32 row = 0; row < height; row++) + const uint32_t copy_size = m_texel_size * width; + for (uint32_t row = 0; row < height; row++) { std::memcpy(dst_ptr, src_ptr, copy_size); src_ptr += m_row_pitch; @@ -181,18 +181,18 @@ bool StagingTexture::ReadPixels(u32 x, u32 y, u32 width, u32 height, void* data, return true; } -bool StagingTexture::WritePixels(u32 x, u32 y, u32 width, u32 height, const void* data, u32 row_pitch) +bool StagingTexture::WritePixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data, uint32_t row_pitch) { const bool was_mapped = IsMapped(); if (!was_mapped && !Map(true)) return false; - const u8* src_ptr = reinterpret_cast(data); - u8* dst_ptr = static_cast(m_mapped_pointer) + (y * m_row_pitch) + (x * m_texel_size); + const uint8_t* src_ptr = reinterpret_cast(data); + uint8_t* dst_ptr = static_cast(m_mapped_pointer) + (y * m_row_pitch) + (x * m_texel_size); if (m_row_pitch != row_pitch || width != m_width || x != 0) { - const u32 copy_size = m_texel_size * width; - for (u32 row = 0; row < height; row++) + const uint32_t copy_size = m_texel_size * width; + for (uint32_t row = 0; row < height; row++) { std::memcpy(dst_ptr, src_ptr, copy_size); src_ptr += row_pitch; @@ -210,7 +210,7 @@ bool StagingTexture::WritePixels(u32 x, u32 y, u32 width, u32 height, const void return true; } -bool StagingTexture::EnsureSize(u32 width, u32 height, DXGI_FORMAT format, bool for_uploading) +bool StagingTexture::EnsureSize(uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading) { if (m_resource && m_width >= width && m_height >= height && m_format == format) return true; diff --git a/src/common/d3d12/staging_texture.h b/src/common/d3d12/staging_texture.h index 22bc0ba4..b40446c2 100644 --- a/src/common/d3d12/staging_texture.h +++ b/src/common/d3d12/staging_texture.h @@ -17,44 +17,44 @@ public: ALWAYS_INLINE ID3D12Resource* GetD3DResource() const { return m_resource.Get(); } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return m_format; } ALWAYS_INLINE bool IsMapped() const { return m_mapped_pointer != nullptr; } ALWAYS_INLINE const void* GetMapPointer() const { return m_mapped_pointer; } ALWAYS_INLINE operator bool() const { return static_cast(m_resource); } - bool Create(u32 width, u32 height, DXGI_FORMAT format, bool for_uploading); + bool Create(uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading); void Destroy(bool defer = true); bool Map(bool writing); void Unmap(); void Flush(); - void CopyToTexture(u32 src_x, u32 src_y, ID3D12Resource* dst_texture, u32 dst_subresource, u32 dst_x, u32 dst_y, - u32 width, u32 height); - void CopyFromTexture(ID3D12Resource* src_texture, u32 src_subresource, u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, - u32 width, u32 height); + void CopyToTexture(uint32_t src_x, uint32_t src_y, ID3D12Resource* dst_texture, uint32_t dst_subresource, uint32_t dst_x, uint32_t dst_y, + uint32_t width, uint32_t height); + void CopyFromTexture(ID3D12Resource* src_texture, uint32_t src_subresource, uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + uint32_t width, uint32_t height); - bool ReadPixels(u32 x, u32 y, u32 width, u32 height, void* data, u32 row_pitch); + bool ReadPixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* data, uint32_t row_pitch); - bool WritePixels(u32 x, u32 y, u32 width, u32 height, const void* data, u32 row_pitch); + bool WritePixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data, uint32_t row_pitch); - bool EnsureSize(u32 width, u32 height, DXGI_FORMAT format, bool for_uploading); + bool EnsureSize(uint32_t width, uint32_t height, DXGI_FORMAT format, bool for_uploading); protected: ComPtr m_resource; - u32 m_width; - u32 m_height; + uint32_t m_width; + uint32_t m_height; DXGI_FORMAT m_format; - u32 m_texel_size; - u32 m_row_pitch; - u32 m_buffer_size; + uint32_t m_texel_size; + uint32_t m_row_pitch; + uint32_t m_buffer_size; void* m_mapped_pointer = nullptr; - u64 m_completed_fence = 0; + uint64_t m_completed_fence = 0; bool m_mapped_for_write = false; bool m_needs_flush = false; }; diff --git a/src/common/d3d12/stream_buffer.cpp b/src/common/d3d12/stream_buffer.cpp index 7b858358..2aa13efc 100644 --- a/src/common/d3d12/stream_buffer.cpp +++ b/src/common/d3d12/stream_buffer.cpp @@ -18,7 +18,7 @@ StreamBuffer::~StreamBuffer() Destroy(); } -bool StreamBuffer::Create(u32 size) +bool StreamBuffer::Create(uint32_t size) { static const D3D12_HEAP_PROPERTIES heap_properties = {D3D12_HEAP_TYPE_UPLOAD}; const D3D12_RESOURCE_DESC resource_desc = { @@ -34,7 +34,7 @@ bool StreamBuffer::Create(u32 size) return false; static const D3D12_RANGE read_range = {}; - u8* host_pointer; + uint8_t* host_pointer; hr = buffer->Map(0, &read_range, reinterpret_cast(&host_pointer)); if (FAILED(hr)) return false; @@ -48,15 +48,15 @@ bool StreamBuffer::Create(u32 size) return true; } -bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) +bool StreamBuffer::ReserveMemory(uint32_t num_bytes, uint32_t alignment) { - const u32 required_bytes = num_bytes + alignment; + const uint32_t required_bytes = num_bytes + alignment; // Check for sane allocations if (num_bytes > m_size) { - Log_ErrorPrintf("Attempting to allocate %u bytes from a %u byte stream buffer", static_cast(num_bytes), - static_cast(m_size)); + Log_ErrorPrintf("Attempting to allocate %u bytes from a %u byte stream buffer", static_cast(num_bytes), + static_cast(m_size)); return false; } @@ -64,8 +64,8 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) UpdateCurrentFencePosition(); if (m_current_offset >= m_current_gpu_position) { - const u32 aligned_required_bytes = (m_current_offset > 0) ? required_bytes : num_bytes; - const u32 remaining_bytes = m_size - m_current_offset; + const uint32_t aligned_required_bytes = (m_current_offset > 0) ? required_bytes : num_bytes; + const uint32_t remaining_bytes = m_size - m_current_offset; if (aligned_required_bytes <= remaining_bytes) { // Place at the current position, after the GPU position. @@ -91,7 +91,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) if (m_current_offset < m_current_gpu_position) { // We have from m_current_offset..m_current_gpu_position space to use. - const u32 remaining_bytes = m_current_gpu_position - m_current_offset; + const uint32_t remaining_bytes = m_current_gpu_position - m_current_offset; if (required_bytes < remaining_bytes) { // Place at the current position, since this is still behind the GPU. @@ -104,7 +104,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) // Can we find a fence to wait on that will give us enough memory? if (WaitForClearSpace(required_bytes)) { - const u32 align_diff = Common::AlignUp(m_current_offset, alignment) - m_current_offset; + const uint32_t align_diff = Common::AlignUp(m_current_offset, alignment) - m_current_offset; m_current_offset += align_diff; m_current_space -= align_diff; return true; @@ -116,7 +116,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) return false; } -void StreamBuffer::CommitMemory(u32 final_num_bytes) +void StreamBuffer::CommitMemory(uint32_t final_num_bytes) { m_current_offset += final_num_bytes; m_current_space -= final_num_bytes; @@ -148,7 +148,7 @@ void StreamBuffer::UpdateCurrentFencePosition() return; // Has the offset changed since the last fence? - const u64 fence = g_d3d12_context->GetCurrentFenceValue(); + const uint64_t fence = g_d3d12_context->GetCurrentFenceValue(); if (!m_tracked_fences.empty() && m_tracked_fences.back().first == fence) { // Still haven't executed a command buffer, so just update the offset. @@ -165,7 +165,7 @@ void StreamBuffer::UpdateGPUPosition() auto start = m_tracked_fences.begin(); auto end = start; - const u64 completed_counter = g_d3d12_context->GetCompletedFenceValue(); + const uint64_t completed_counter = g_d3d12_context->GetCompletedFenceValue(); while (end != m_tracked_fences.end() && completed_counter >= end->first) { m_current_gpu_position = end->second; @@ -176,11 +176,11 @@ void StreamBuffer::UpdateGPUPosition() m_tracked_fences.erase(start, end); } -bool StreamBuffer::WaitForClearSpace(u32 num_bytes) +bool StreamBuffer::WaitForClearSpace(uint32_t num_bytes) { - u32 new_offset = 0; - u32 new_space = 0; - u32 new_gpu_position = 0; + uint32_t new_offset = 0; + uint32_t new_space = 0; + uint32_t new_gpu_position = 0; auto iter = m_tracked_fences.begin(); for (; iter != m_tracked_fences.end(); ++iter) @@ -189,7 +189,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) // This is the "last resort" case, where a command buffer execution has been forced // after no additional data has been written to it, so we can assume that after the // fence has been signaled the entire buffer is now consumed. - u32 gpu_position = iter->second; + uint32_t gpu_position = iter->second; if (m_current_offset == gpu_position) { new_offset = 0; @@ -203,7 +203,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) { // This would suggest the GPU has now followed us and wrapped around, so we have from // m_current_position..m_size free, as well as and 0..gpu_position. - const u32 remaining_space_after_offset = m_size - m_current_offset; + const uint32_t remaining_space_after_offset = m_size - m_current_offset; if (remaining_space_after_offset >= num_bytes) { // Switch to allocating in front of the GPU, using the remainder of the buffer. @@ -229,7 +229,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) // We're currently allocating behind the GPU. This would give us between the current // offset and the GPU position worth of space to work with. Again, > because we can't // align the GPU position with the buffer offset. - u32 available_space_inbetween = gpu_position - m_current_offset; + uint32_t available_space_inbetween = gpu_position - m_current_offset; if (available_space_inbetween > num_bytes) { // Leave the offset as-is, but update the GPU position. diff --git a/src/common/d3d12/stream_buffer.h b/src/common/d3d12/stream_buffer.h index 36d88ed5..d3037070 100644 --- a/src/common/d3d12/stream_buffer.h +++ b/src/common/d3d12/stream_buffer.h @@ -18,19 +18,19 @@ public: StreamBuffer(); ~StreamBuffer(); - bool Create(u32 size); + bool Create(uint32_t size); ALWAYS_INLINE bool IsValid() const { return static_cast(m_buffer); } ALWAYS_INLINE ID3D12Resource* GetBuffer() const { return m_buffer.Get(); } ALWAYS_INLINE D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const { return m_gpu_pointer; } ALWAYS_INLINE void* GetCurrentHostPointer() const { return m_host_pointer + m_current_offset; } ALWAYS_INLINE D3D12_GPU_VIRTUAL_ADDRESS GetCurrentGPUPointer() const { return m_gpu_pointer + m_current_offset; } - ALWAYS_INLINE u32 GetSize() const { return m_size; } - ALWAYS_INLINE u32 GetCurrentOffset() const { return m_current_offset; } - ALWAYS_INLINE u32 GetCurrentSpace() const { return m_current_space; } + ALWAYS_INLINE uint32_t GetSize() const { return m_size; } + ALWAYS_INLINE uint32_t GetCurrentOffset() const { return m_current_offset; } + ALWAYS_INLINE uint32_t GetCurrentSpace() const { return m_current_space; } - bool ReserveMemory(u32 num_bytes, u32 alignment); - void CommitMemory(u32 final_num_bytes); + bool ReserveMemory(uint32_t num_bytes, uint32_t alignment); + void CommitMemory(uint32_t final_num_bytes); void Destroy(bool defer = true); @@ -39,19 +39,19 @@ private: void UpdateGPUPosition(); // Waits for as many fences as needed to allocate num_bytes bytes from the buffer. - bool WaitForClearSpace(u32 num_bytes); + bool WaitForClearSpace(uint32_t num_bytes); - u32 m_size = 0; - u32 m_current_offset = 0; - u32 m_current_space = 0; - u32 m_current_gpu_position = 0; + uint32_t m_size = 0; + uint32_t m_current_offset = 0; + uint32_t m_current_space = 0; + uint32_t m_current_gpu_position = 0; Microsoft::WRL::ComPtr m_buffer; D3D12_GPU_VIRTUAL_ADDRESS m_gpu_pointer = {}; - u8* m_host_pointer = nullptr; + uint8_t* m_host_pointer = nullptr; // List of fences and the corresponding positions in the buffer - std::deque> m_tracked_fences; + std::deque> m_tracked_fences; }; } // namespace D3D12 diff --git a/src/common/d3d12/texture.cpp b/src/common/d3d12/texture.cpp index f5092a54..39c85bb8 100644 --- a/src/common/d3d12/texture.cpp +++ b/src/common/d3d12/texture.cpp @@ -13,7 +13,7 @@ Texture::Texture() = default; Texture::Texture(ID3D12Resource* resource, D3D12_RESOURCE_STATES state) : m_resource(std::move(resource)) { const D3D12_RESOURCE_DESC desc = GetDesc(); - m_width = static_cast(desc.Width); + m_width = static_cast(desc.Width); m_height = desc.Height; m_samples = desc.SampleDesc.Count; m_format = desc.Format; @@ -68,7 +68,7 @@ D3D12_RESOURCE_DESC Texture::GetDesc() const return m_resource->GetDesc(); } -bool Texture::Create(u32 width, u32 height, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, +bool Texture::Create(uint32_t width, uint32_t height, uint32_t samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags) { constexpr D3D12_HEAP_PROPERTIES heap_properties = {D3D12_HEAP_TYPE_DEFAULT}; @@ -189,10 +189,10 @@ void Texture::TransitionToState(D3D12_RESOURCE_STATES state) const m_state = state; } -bool Texture::BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_data, u32* out_data_pitch) +bool Texture::BeginStreamUpdate(uint32_t x, uint32_t y, uint32_t width, uint32_t height, void** out_data, uint32_t* out_data_pitch) { - const u32 copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); - const u32 upload_size = copy_pitch * height; + const uint32_t copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); + const uint32_t upload_size = copy_pitch * height; if (!g_d3d12_context->GetTextureStreamBuffer().ReserveMemory(upload_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT)) { @@ -206,19 +206,19 @@ bool Texture::BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_ return true; } -void Texture::EndStreamUpdate(u32 x, u32 y, u32 width, u32 height) +void Texture::EndStreamUpdate(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { - const u32 copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); - const u32 upload_size = copy_pitch * height; + const uint32_t copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); + const uint32_t upload_size = copy_pitch * height; StreamBuffer& sb = g_d3d12_context->GetTextureStreamBuffer(); - const u32 sb_offset = sb.GetCurrentOffset(); + const uint32_t sb_offset = sb.GetCurrentOffset(); sb.CommitMemory(upload_size); CopyFromBuffer(x, y, width, height, copy_pitch, sb.GetBuffer(), sb_offset); } -void Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3D12Resource* buffer, u32 buffer_offset) +void Texture::CopyFromBuffer(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pitch, ID3D12Resource* buffer, uint32_t buffer_offset) { D3D12_TEXTURE_COPY_LOCATION src; src.pResource = buffer; @@ -243,11 +243,11 @@ void Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3 TransitionToState(old_state); } -bool Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) +bool Texture::LoadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data, uint32_t pitch) { - const u32 texel_size = GetTexelSize(m_format); - const u32 upload_pitch = Common::AlignUpPow2(width * texel_size, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); - const u32 upload_size = upload_pitch * height; + const uint32_t texel_size = GetTexelSize(m_format); + const uint32_t upload_pitch = Common::AlignUpPow2(width * texel_size, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); + const uint32_t upload_size = upload_pitch * height; if (upload_size >= g_d3d12_context->GetTextureStreamBuffer().GetSize()) { StagingTexture st; @@ -263,7 +263,7 @@ bool Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u3 } void* write_ptr; - u32 write_pitch; + uint32_t write_pitch; if (!BeginStreamUpdate(x, y, width, height, &write_ptr, &write_pitch)) return false; @@ -272,18 +272,18 @@ bool Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u3 return true; } -void Texture::CopyToUploadBuffer(const void* src_data, u32 src_pitch, u32 height, void* dst_data, u32 dst_pitch) +void Texture::CopyToUploadBuffer(const void* src_data, uint32_t src_pitch, uint32_t height, void* dst_data, uint32_t dst_pitch) { - const u8* src_ptr = static_cast(src_data); - u8* dst_ptr = static_cast(dst_data); + const uint8_t* src_ptr = static_cast(src_data); + uint8_t* dst_ptr = static_cast(dst_data); if (src_pitch == dst_pitch) { std::memcpy(dst_ptr, src_ptr, dst_pitch * height); } else { - const u32 copy_size = std::min(src_pitch, dst_pitch); - for (u32 row = 0; row < height; row++) + const uint32_t copy_size = std::min(src_pitch, dst_pitch); + for (uint32_t row = 0; row < height; row++) { std::memcpy(dst_ptr, src_ptr, copy_size); src_ptr += src_pitch; diff --git a/src/common/d3d12/texture.h b/src/common/d3d12/texture.h index ac5f37ee..fa67afd2 100644 --- a/src/common/d3d12/texture.h +++ b/src/common/d3d12/texture.h @@ -26,16 +26,16 @@ public: ALWAYS_INLINE const DescriptorHandle& GetRTVOrDSVDescriptor() const { return m_rtv_or_dsv_descriptor; } ALWAYS_INLINE D3D12_RESOURCE_STATES GetState() const { return m_state; } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } - ALWAYS_INLINE u32 GetSamples() const { return m_samples; } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetSamples() const { return m_samples; } ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return m_format; } ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; } ALWAYS_INLINE operator ID3D12Resource*() const { return m_resource.Get(); } ALWAYS_INLINE operator bool() const { return static_cast(m_resource); } - bool Create(u32 width, u32 height, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, + bool Create(uint32_t width, uint32_t height, uint32_t samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags); D3D12_RESOURCE_DESC GetDesc() const; @@ -47,13 +47,13 @@ public: Texture& operator=(const Texture&) = delete; Texture& operator=(Texture&& texture); - bool BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_data, u32* out_data_pitch); - void EndStreamUpdate(u32 x, u32 y, u32 width, u32 height); + bool BeginStreamUpdate(uint32_t x, uint32_t y, uint32_t width, uint32_t height, void** out_data, uint32_t* out_data_pitch); + void EndStreamUpdate(uint32_t x, uint32_t y, uint32_t width, uint32_t height); - bool LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch); + bool LoadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data, uint32_t pitch); - static void CopyToUploadBuffer(const void* src_data, u32 src_pitch, u32 height, void* dst_data, u32 dst_pitch); - void CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3D12Resource* buffer, u32 buffer_offset); + static void CopyToUploadBuffer(const void* src_data, uint32_t src_pitch, uint32_t height, void* dst_data, uint32_t dst_pitch); + void CopyFromBuffer(uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pitch, ID3D12Resource* buffer, uint32_t buffer_offset); private: static bool CreateSRVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled, @@ -66,9 +66,9 @@ private: ComPtr m_resource; DescriptorHandle m_srv_descriptor = {}; DescriptorHandle m_rtv_or_dsv_descriptor = {}; - u32 m_width = 0; - u32 m_height = 0; - u32 m_samples = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + uint32_t m_samples = 0; DXGI_FORMAT m_format = DXGI_FORMAT_UNKNOWN; mutable D3D12_RESOURCE_STATES m_state = D3D12_RESOURCE_STATE_COMMON; diff --git a/src/common/d3d12/util.cpp b/src/common/d3d12/util.cpp index d909f79c..7b253d42 100644 --- a/src/common/d3d12/util.cpp +++ b/src/common/d3d12/util.cpp @@ -11,7 +11,7 @@ Log_SetChannel(D3D12); namespace D3D12 { -u32 GetTexelSize(DXGI_FORMAT format) +uint32_t GetTexelSize(DXGI_FORMAT format) { switch (format) { @@ -123,10 +123,10 @@ void GraphicsPipelineBuilder::SetRootSignature(ID3D12RootSignature* rs) void GraphicsPipelineBuilder::SetVertexShader(ID3DBlob* blob) { - SetVertexShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); + SetVertexShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); } -void GraphicsPipelineBuilder::SetVertexShader(const void* data, u32 data_size) +void GraphicsPipelineBuilder::SetVertexShader(const void* data, uint32_t data_size) { m_desc.VS.pShaderBytecode = data; m_desc.VS.BytecodeLength = data_size; @@ -134,10 +134,10 @@ void GraphicsPipelineBuilder::SetVertexShader(const void* data, u32 data_size) void GraphicsPipelineBuilder::SetGeometryShader(ID3DBlob* blob) { - SetGeometryShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); + SetGeometryShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); } -void GraphicsPipelineBuilder::SetGeometryShader(const void* data, u32 data_size) +void GraphicsPipelineBuilder::SetGeometryShader(const void* data, uint32_t data_size) { m_desc.GS.pShaderBytecode = data; m_desc.GS.BytecodeLength = data_size; @@ -145,19 +145,19 @@ void GraphicsPipelineBuilder::SetGeometryShader(const void* data, u32 data_size) void GraphicsPipelineBuilder::SetPixelShader(ID3DBlob* blob) { - SetPixelShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); + SetPixelShader(blob->GetBufferPointer(), static_cast(blob->GetBufferSize())); } -void GraphicsPipelineBuilder::SetPixelShader(const void* data, u32 data_size) +void GraphicsPipelineBuilder::SetPixelShader(const void* data, uint32_t data_size) { m_desc.PS.pShaderBytecode = data; m_desc.PS.BytecodeLength = data_size; } -void GraphicsPipelineBuilder::AddVertexAttribute(const char* semantic_name, u32 semantic_index, DXGI_FORMAT format, - u32 buffer, u32 offset) +void GraphicsPipelineBuilder::AddVertexAttribute(const char* semantic_name, uint32_t semantic_index, DXGI_FORMAT format, + uint32_t buffer, uint32_t offset) { - const u32 index = m_desc.InputLayout.NumElements; + const uint32_t index = m_desc.InputLayout.NumElements; m_input_elements[index].SemanticIndex = semantic_index; m_input_elements[index].SemanticName = semantic_name; m_input_elements[index].Format = format; @@ -183,7 +183,7 @@ void GraphicsPipelineBuilder::SetRasterizationState(D3D12_FILL_MODE polygon_mode m_desc.RasterizerState.FrontCounterClockwise = front_face_ccw; } -void GraphicsPipelineBuilder::SetMultisamples(u32 multisamples) +void GraphicsPipelineBuilder::SetMultisamples(uint32_t multisamples) { m_desc.RasterizerState.MultisampleEnable = multisamples > 1; m_desc.SampleDesc.Count = multisamples; @@ -206,10 +206,10 @@ void GraphicsPipelineBuilder::SetNoDepthTestState() SetDepthState(false, false, D3D12_COMPARISON_FUNC_ALWAYS); } -void GraphicsPipelineBuilder::SetBlendState(u32 rt, bool blend_enable, D3D12_BLEND src_factor, D3D12_BLEND dst_factor, +void GraphicsPipelineBuilder::SetBlendState(uint32_t rt, bool blend_enable, D3D12_BLEND src_factor, D3D12_BLEND dst_factor, D3D12_BLEND_OP op, D3D12_BLEND alpha_src_factor, D3D12_BLEND alpha_dst_factor, D3D12_BLEND_OP alpha_op, - u8 write_mask /*= 0xFF*/) + uint8_t write_mask /*= 0xFF*/) { m_desc.BlendState.RenderTarget[rt].BlendEnable = blend_enable; m_desc.BlendState.RenderTarget[rt].SrcBlend = src_factor; @@ -234,11 +234,11 @@ void GraphicsPipelineBuilder::SetNoBlendingState() void GraphicsPipelineBuilder::ClearRenderTargets() { m_desc.NumRenderTargets = 0; - for (u32 i = 0; i < sizeof(m_desc.RTVFormats) / sizeof(m_desc.RTVFormats[0]); i++) + for (uint32_t i = 0; i < sizeof(m_desc.RTVFormats) / sizeof(m_desc.RTVFormats[0]); i++) m_desc.RTVFormats[i] = DXGI_FORMAT_UNKNOWN; } -void GraphicsPipelineBuilder::SetRenderTarget(u32 rt, DXGI_FORMAT format) +void GraphicsPipelineBuilder::SetRenderTarget(uint32_t rt, DXGI_FORMAT format) { m_desc.RTVFormats[rt] = format; if (rt >= m_desc.NumRenderTargets) @@ -286,9 +286,9 @@ void RootSignatureBuilder::SetInputAssemblerFlag() m_desc.Flags |= D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; } -u32 RootSignatureBuilder::Add32BitConstants(u32 shader_reg, u32 num_values, D3D12_SHADER_VISIBILITY visibility) +uint32_t RootSignatureBuilder::Add32BitConstants(uint32_t shader_reg, uint32_t num_values, D3D12_SHADER_VISIBILITY visibility) { - const u32 index = m_desc.NumParameters++; + const uint32_t index = m_desc.NumParameters++; m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; m_params[index].ShaderVisibility = visibility; @@ -299,9 +299,9 @@ u32 RootSignatureBuilder::Add32BitConstants(u32 shader_reg, u32 num_values, D3D1 return index; } -u32 RootSignatureBuilder::AddCBVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility) +uint32_t RootSignatureBuilder::AddCBVParameter(uint32_t shader_reg, D3D12_SHADER_VISIBILITY visibility) { - const u32 index = m_desc.NumParameters++; + const uint32_t index = m_desc.NumParameters++; m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; m_params[index].ShaderVisibility = visibility; @@ -311,9 +311,9 @@ u32 RootSignatureBuilder::AddCBVParameter(u32 shader_reg, D3D12_SHADER_VISIBILIT return index; } -u32 RootSignatureBuilder::AddSRVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility) +uint32_t RootSignatureBuilder::AddSRVParameter(uint32_t shader_reg, D3D12_SHADER_VISIBILITY visibility) { - const u32 index = m_desc.NumParameters++; + const uint32_t index = m_desc.NumParameters++; m_params[index].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV; m_params[index].ShaderVisibility = visibility; @@ -323,11 +323,11 @@ u32 RootSignatureBuilder::AddSRVParameter(u32 shader_reg, D3D12_SHADER_VISIBILIT return index; } -u32 RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE rt, u32 start_shader_reg, u32 num_shader_regs, +uint32_t RootSignatureBuilder::AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE rt, uint32_t start_shader_reg, uint32_t num_shader_regs, D3D12_SHADER_VISIBILITY visibility) { - const u32 index = m_desc.NumParameters++; - const u32 dr_index = m_num_descriptor_ranges++; + const uint32_t index = m_desc.NumParameters++; + const uint32_t dr_index = m_num_descriptor_ranges++; m_descriptor_ranges[dr_index].RangeType = rt; m_descriptor_ranges[dr_index].NumDescriptors = num_shader_regs; diff --git a/src/common/d3d12/util.h b/src/common/d3d12/util.h index 2dde51f7..d8a7496d 100644 --- a/src/common/d3d12/util.h +++ b/src/common/d3d12/util.h @@ -43,7 +43,7 @@ static inline void SetViewportAndScissor(ID3D12GraphicsCommandList* cmdlist, int SetScissor(cmdlist, x, y, width, height); } -u32 GetTexelSize(DXGI_FORMAT format); +uint32_t GetTexelSize(DXGI_FORMAT format); void SetDefaultSampler(D3D12_SAMPLER_DESC* desc); @@ -62,7 +62,7 @@ static inline void SetObjectNameFormatted(ID3D12Object* object, const char* form class RootSignatureBuilder { public: - static constexpr u32 MAX_PARAMETERS = 16, MAX_DESCRIPTOR_RANGES = 16; + static constexpr uint32_t MAX_PARAMETERS = 16, MAX_DESCRIPTOR_RANGES = 16; RootSignatureBuilder(); @@ -72,23 +72,23 @@ public: void SetInputAssemblerFlag(); - u32 Add32BitConstants(u32 shader_reg, u32 num_values, D3D12_SHADER_VISIBILITY visibility); - u32 AddCBVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility); - u32 AddSRVParameter(u32 shader_reg, D3D12_SHADER_VISIBILITY visibility); - u32 AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE rt, u32 start_shader_reg, u32 num_shader_regs, + uint32_t Add32BitConstants(uint32_t shader_reg, uint32_t num_values, D3D12_SHADER_VISIBILITY visibility); + uint32_t AddCBVParameter(uint32_t shader_reg, D3D12_SHADER_VISIBILITY visibility); + uint32_t AddSRVParameter(uint32_t shader_reg, D3D12_SHADER_VISIBILITY visibility); + uint32_t AddDescriptorTable(D3D12_DESCRIPTOR_RANGE_TYPE rt, uint32_t start_shader_reg, uint32_t num_shader_regs, D3D12_SHADER_VISIBILITY visibility); private: D3D12_ROOT_SIGNATURE_DESC m_desc{}; std::array m_params{}; std::array m_descriptor_ranges{}; - u32 m_num_descriptor_ranges = 0; + uint32_t m_num_descriptor_ranges = 0; }; class GraphicsPipelineBuilder { public: - static constexpr u32 MAX_VERTEX_ATTRIBUTES = 16; + static constexpr uint32_t MAX_VERTEX_ATTRIBUTES = 16; GraphicsPipelineBuilder(); @@ -101,21 +101,21 @@ public: void SetRootSignature(ID3D12RootSignature* rs); - void SetVertexShader(const void* data, u32 data_size); - void SetGeometryShader(const void* data, u32 data_size); - void SetPixelShader(const void* data, u32 data_size); + void SetVertexShader(const void* data, uint32_t data_size); + void SetGeometryShader(const void* data, uint32_t data_size); + void SetPixelShader(const void* data, uint32_t data_size); void SetVertexShader(ID3DBlob* blob); void SetGeometryShader(ID3DBlob* blob); void SetPixelShader(ID3DBlob* blob); - void AddVertexAttribute(const char* semantic_name, u32 semantic_index, DXGI_FORMAT format, u32 buffer, u32 offset); + void AddVertexAttribute(const char* semantic_name, uint32_t semantic_index, DXGI_FORMAT format, uint32_t buffer, uint32_t offset); void SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE type); void SetRasterizationState(D3D12_FILL_MODE polygon_mode, D3D12_CULL_MODE cull_mode, bool front_face_ccw); - void SetMultisamples(u32 multisamples); + void SetMultisamples(uint32_t multisamples); void SetNoCullRasterizationState(); @@ -123,15 +123,15 @@ public: void SetNoDepthTestState(); - void SetBlendState(u32 rt, bool blend_enable, D3D12_BLEND src_factor, D3D12_BLEND dst_factor, D3D12_BLEND_OP op, + void SetBlendState(uint32_t rt, bool blend_enable, D3D12_BLEND src_factor, D3D12_BLEND dst_factor, D3D12_BLEND_OP op, D3D12_BLEND alpha_src_factor, D3D12_BLEND alpha_dst_factor, D3D12_BLEND_OP alpha_op, - u8 write_mask = D3D12_COLOR_WRITE_ENABLE_ALL); + uint8_t write_mask = D3D12_COLOR_WRITE_ENABLE_ALL); void SetNoBlendingState(); void ClearRenderTargets(); - void SetRenderTarget(u32 rt, DXGI_FORMAT format); + void SetRenderTarget(uint32_t rt, DXGI_FORMAT format); void ClearDepthStencilFormat(); diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h index 211baa4b..b69975e9 100644 --- a/src/common/fifo_queue.h +++ b/src/common/fifo_queue.h @@ -10,7 +10,7 @@ #include // posix_memalign #endif -template +template class FIFOQueue { public: @@ -18,11 +18,11 @@ public: T* GetDataPointer() { return m_ptr; } const T* GetReadPointer() const { return &m_ptr[m_head]; } T* GetReadPointer() { return &m_ptr[m_head]; } - constexpr u32 GetCapacity() const { return CAPACITY; } + constexpr uint32_t GetCapacity() const { return CAPACITY; } T* GetWritePointer() { return &m_ptr[m_tail]; } - u32 GetSize() const { return m_size; } - u32 GetSpace() const { return CAPACITY - m_size; } - u32 GetContiguousSpace() const + uint32_t GetSize() const { return m_size; } + uint32_t GetSpace() const { return CAPACITY - m_size; } + uint32_t GetContiguousSpace() const { if (m_tail == m_head && m_size > 0) return 0; @@ -30,7 +30,7 @@ public: return (CAPACITY - m_tail); return (m_head - m_tail); } - u32 GetContiguousSize() const { return std::min(CAPACITY - m_head, m_size); } + uint32_t GetContiguousSize() const { return std::min(CAPACITY - m_head, m_size); } bool IsEmpty() const { return m_size == 0; } bool IsFull() const { return m_size == CAPACITY; } @@ -59,11 +59,11 @@ public: // faster version of push_back_range for POD types which can be memcpy()ed template, int> = 0> - void PushRange(const T* data, u32 size) + void PushRange(const T* data, uint32_t size) { - const u32 space_before_end = CAPACITY - m_tail; - const u32 size_before_end = (size > space_before_end) ? space_before_end : size; - const u32 size_after_end = size - size_before_end; + const uint32_t space_before_end = CAPACITY - m_tail; + const uint32_t size_before_end = (size > space_before_end) ? space_before_end : size; + const uint32_t size_after_end = size - size_before_end; std::memcpy(&m_ptr[m_tail], data, sizeof(T) * size_before_end); m_tail = (m_tail + size_before_end) % CAPACITY; @@ -78,7 +78,7 @@ public: } template, int> = 0> - void PushRange(const T* data, u32 size) + void PushRange(const T* data, uint32_t size) { while (size > 0) { @@ -90,11 +90,11 @@ public: } const T& Peek() const { return m_ptr[m_head]; } - const T& Peek(u32 offset) { return m_ptr[(m_head + offset) % CAPACITY]; } + const T& Peek(uint32_t offset) { return m_ptr[(m_head + offset) % CAPACITY]; } - void Remove(u32 count) + void Remove(uint32_t count) { - for (u32 i = 0; i < count; i++) + for (uint32_t i = 0; i < count; i++) { m_ptr[m_head].~T(); m_head = (m_head + 1) % CAPACITY; @@ -119,10 +119,10 @@ public: return val; } - void PopRange(T* out_data, u32 count) + void PopRange(T* out_data, uint32_t count) { - for (u32 i = 0; i < count; i++) + for (uint32_t i = 0; i < count; i++) { out_data[i] = std::move(m_ptr[m_head]); m_ptr[m_head].~T(); @@ -131,7 +131,7 @@ public: } } - template + template void PushFromQueue(FIFOQueue* other_queue) { while (!other_queue->IsEmpty() && !IsFull()) @@ -141,7 +141,7 @@ public: } } - void AdvanceTail(u32 count) + void AdvanceTail(uint32_t count) { m_tail = (m_tail + count) % CAPACITY; m_size += count; @@ -159,12 +159,12 @@ protected: } T* m_ptr = nullptr; - u32 m_head = 0; - u32 m_tail = 0; - u32 m_size = 0; + uint32_t m_head = 0; + uint32_t m_tail = 0; + uint32_t m_size = 0; }; -template +template class InlineFIFOQueue : public FIFOQueue { public: @@ -174,7 +174,7 @@ private: T m_inline_data[CAPACITY] = {}; }; -template +template class HeapFIFOQueue : public FIFOQueue { public: diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index b2d90db9..c00c586c 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -247,7 +247,7 @@ std::string BuildRelativePath(const std::string_view& filename, const std::strin return new_string; } -std::unique_ptr OpenFile(const char* FileName, u32 Flags) +std::unique_ptr OpenFile(const char* FileName, uint32_t Flags) { // TODO: Handle Android content URIs here. @@ -291,7 +291,7 @@ std::FILE* OpenCFile(const char* filename, const char* mode) #endif } -std::optional> ReadBinaryFile(const char* filename) +std::optional> ReadBinaryFile(const char* filename) { RFILE *fp = OpenRFile(filename, "rb"); if (!fp) @@ -306,7 +306,7 @@ std::optional> ReadBinaryFile(const char* filename) return std::nullopt; } - std::vector res(static_cast(size)); + std::vector res(static_cast(size)); if (size > 0 && rfread(res.data(), 1u, static_cast(size), fp) != static_cast(size)) { rfclose(fp); @@ -316,7 +316,7 @@ std::optional> ReadBinaryFile(const char* filename) return res; } -std::optional> ReadBinaryFile(RFILE* fp) +std::optional> ReadBinaryFile(RFILE* fp) { rfseek(fp, 0, SEEK_END); int64_t size = rftell(fp); @@ -324,7 +324,7 @@ std::optional> ReadBinaryFile(RFILE* fp) if (size < 0) return std::nullopt; - std::vector res(static_cast(size)); + std::vector res(static_cast(size)); if (size > 0 && rfread(res.data(), 1u, static_cast(size), fp) != static_cast(size)) return std::nullopt; @@ -360,8 +360,8 @@ bool WriteBinaryFile(const char* filename, const void* data, size_t data_length) } #ifdef _WIN32 -static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern, - u32 Flags, FileSystem::FindResultsArray* pResults) +static uint32_t RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern, + uint32_t Flags, FileSystem::FindResultsArray* pResults) { std::string tempStr; if (Path) @@ -388,7 +388,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co // small speed optimization for '*' case bool hasWildCards = false; bool wildCardMatchAll = false; - u32 nFiles = 0; + uint32_t nFiles = 0; if (std::strpbrk(Pattern, "*?") != nullptr) { hasWildCards = true; @@ -488,7 +488,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co outData.FileName = std::string(utf8_filename); } - outData.Size = (u64)wfd.nFileSizeHigh << 32 | (u64)wfd.nFileSizeLow; + outData.Size = (uint64_t)wfd.nFileSizeHigh << 32 | (uint64_t)wfd.nFileSizeLow; nFiles++; pResults->push_back(std::move(outData)); @@ -500,8 +500,8 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co } #else -static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern, - u32 Flags, FindResultsArray* pResults) +static uint32_t RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern, + uint32_t Flags, FindResultsArray* pResults) { std::string tempStr; if (Path) @@ -523,7 +523,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co // small speed optimization for '*' case bool hasWildCards = false; bool wildCardMatchAll = false; - u32 nFiles = 0; + uint32_t nFiles = 0; if (std::strpbrk(Pattern, "*?")) { hasWildCards = true; @@ -589,7 +589,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co continue; } - outData.Size = static_cast(sdir_size); + outData.Size = static_cast(sdir_size); // match the filename if (hasWildCards) @@ -628,7 +628,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co } #endif -bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults) +bool FindFiles(const char* Path, const char* Pattern, uint32_t Flags, FindResultsArray* pResults) { // has a path if (Path[0] == '\0') @@ -683,7 +683,7 @@ RFILE* OpenRFile(const char *filename, const char *mode) return output; } -s64 FSeek64(RFILE* fp, s64 offset, int whence) +int64_t FSeek64(RFILE* fp, int64_t offset, int whence) { int seek_position = -1; @@ -706,7 +706,7 @@ s64 FSeek64(RFILE* fp, s64 offset, int whence) return filestream_seek(fp, offset, seek_position); } -s64 FTell64(RFILE* fp) +int64_t FTell64(RFILE* fp) { return filestream_tell(fp); } diff --git a/src/common/file_system.h b/src/common/file_system.h index 4642dd62..4fde7430 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -20,18 +20,18 @@ class ByteStream; #define FS_OSPATH_SEPARATOR_STR "/" #endif -inline constexpr u32 FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY = 1, FILESYSTEM_FILE_ATTRIBUTE_READ_ONLY = 2, +inline constexpr uint32_t FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY = 1, FILESYSTEM_FILE_ATTRIBUTE_READ_ONLY = 2, FILESYSTEM_FILE_ATTRIBUTE_COMPRESSED = 4; -inline constexpr u32 FILESYSTEM_FIND_RECURSIVE = (1 << 0), FILESYSTEM_FIND_RELATIVE_PATHS = (1 << 1), +inline constexpr uint32_t FILESYSTEM_FIND_RECURSIVE = (1 << 0), FILESYSTEM_FIND_RELATIVE_PATHS = (1 << 1), FILESYSTEM_FIND_HIDDEN_FILES = (1 << 2), FILESYSTEM_FIND_FOLDERS = (1 << 3), FILESYSTEM_FIND_FILES = (1 << 4), FILESYSTEM_FIND_KEEP_ARRAY = (1 << 5); struct FILESYSTEM_FIND_DATA { std::string FileName; - u32 Attributes; - u64 Size; + uint32_t Attributes; + uint64_t Size; }; namespace FileSystem { @@ -61,21 +61,21 @@ std::string_view GetFileNameFromPath(const std::string_view& path); std::string_view GetFileTitleFromPath(const std::string_view& path); // search for files -bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults); +bool FindFiles(const char* Path, const char* Pattern, uint32_t Flags, FindResultsArray* pResults); // open files -std::unique_ptr OpenFile(const char* FileName, u32 Flags); +std::unique_ptr OpenFile(const char* FileName, uint32_t Flags); std::FILE* OpenCFile(const char* filename, const char* mode); -std::optional> ReadBinaryFile(const char* filename); +std::optional> ReadBinaryFile(const char* filename); bool WriteBinaryFile(const char* filename, const void* data, size_t data_length); RFILE *OpenRFile(const char* filename, const char* mode); -s64 FSeek64(RFILE* fp, s64 offset, int whence); -s64 FTell64(RFILE* fp); +int64_t FSeek64(RFILE* fp, int64_t offset, int whence); +int64_t FTell64(RFILE* fp); std::optional ReadFileToString(RFILE* fp); -std::optional> ReadBinaryFile(RFILE* fp); +std::optional> ReadBinaryFile(RFILE* fp); }; // namespace FileSystem diff --git a/src/common/gl/program.cpp b/src/common/gl/program.cpp index 518a9551..248dab14 100644 --- a/src/common/gl/program.cpp +++ b/src/common/gl/program.cpp @@ -120,7 +120,7 @@ bool Program::Compile(const std::string_view vertex_shader, const std::string_vi return true; } -bool Program::CreateFromBinary(const void* data, u32 data_length, u32 data_format) +bool Program::CreateFromBinary(const void* data, uint32_t data_length, uint32_t data_format) { GLuint prog = glCreateProgram(); glProgramBinary(prog, static_cast(data_format), data, data_length); @@ -138,7 +138,7 @@ bool Program::CreateFromBinary(const void* data, u32 data_length, u32 data_forma return true; } -bool Program::GetBinary(std::vector* out_data, u32* out_data_format) +bool Program::GetBinary(std::vector* out_data, uint32_t* out_data_format) { GLint binary_size = 0; glGetProgramiv(m_program_id, GL_PROGRAM_BINARY_LENGTH, &binary_size); @@ -162,7 +162,7 @@ bool Program::GetBinary(std::vector* out_data, u32* out_data_format) out_data->resize(static_cast(binary_size)); } - *out_data_format = static_cast(format); + *out_data_format = static_cast(format); Log_InfoPrintf("Program binary retrieved, %zu bytes, format %u", out_data->size(), *out_data_format); return true; } @@ -282,56 +282,56 @@ int Program::RegisterUniform(const char* name) return id; } -void Program::Uniform1ui(int index, u32 x) const +void Program::Uniform1ui(int index, uint32_t x) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform1ui(location, x); } -void Program::Uniform2ui(int index, u32 x, u32 y) const +void Program::Uniform2ui(int index, uint32_t x, uint32_t y) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform2ui(location, x, y); } -void Program::Uniform3ui(int index, u32 x, u32 y, u32 z) const +void Program::Uniform3ui(int index, uint32_t x, uint32_t y, uint32_t z) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform3ui(location, x, y, z); } -void Program::Uniform4ui(int index, u32 x, u32 y, u32 z, u32 w) const +void Program::Uniform4ui(int index, uint32_t x, uint32_t y, uint32_t z, uint32_t w) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform4ui(location, x, y, z, w); } -void Program::Uniform1i(int index, s32 x) const +void Program::Uniform1i(int index, int32_t x) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform1i(location, x); } -void Program::Uniform2i(int index, s32 x, s32 y) const +void Program::Uniform2i(int index, int32_t x, int32_t y) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform2i(location, x, y); } -void Program::Uniform3i(int index, s32 x, s32 y, s32 z) const +void Program::Uniform3i(int index, int32_t x, int32_t y, int32_t z) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform3i(location, x, y, z); } -void Program::Uniform4i(int index, s32 x, s32 y, s32 z, s32 w) const +void Program::Uniform4i(int index, int32_t x, int32_t y, int32_t z, int32_t w) const { const GLint location = m_uniform_locations[index]; if (location >= 0) @@ -366,42 +366,42 @@ void Program::Uniform4f(int index, float x, float y, float z, float w) const glUniform4f(location, x, y, z, w); } -void Program::Uniform2uiv(int index, const u32* v) const +void Program::Uniform2uiv(int index, const uint32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform2uiv(location, 1, v); } -void Program::Uniform3uiv(int index, const u32* v) const +void Program::Uniform3uiv(int index, const uint32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform3uiv(location, 1, v); } -void Program::Uniform4uiv(int index, const u32* v) const +void Program::Uniform4uiv(int index, const uint32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform4uiv(location, 1, v); } -void Program::Uniform2iv(int index, const s32* v) const +void Program::Uniform2iv(int index, const int32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform2iv(location, 1, v); } -void Program::Uniform3iv(int index, const s32* v) const +void Program::Uniform3iv(int index, const int32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) glUniform3iv(location, 1, v); } -void Program::Uniform4iv(int index, const s32* v) const +void Program::Uniform4iv(int index, const int32_t* v) const { const GLint location = m_uniform_locations[index]; if (location >= 0) @@ -429,56 +429,56 @@ void Program::Uniform4fv(int index, const float* v) const glUniform4fv(location, 1, v); } -void Program::Uniform1ui(const char* name, u32 x) const +void Program::Uniform1ui(const char* name, uint32_t x) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform1ui(location, x); } -void Program::Uniform2ui(const char* name, u32 x, u32 y) const +void Program::Uniform2ui(const char* name, uint32_t x, uint32_t y) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform2ui(location, x, y); } -void Program::Uniform3ui(const char* name, u32 x, u32 y, u32 z) const +void Program::Uniform3ui(const char* name, uint32_t x, uint32_t y, uint32_t z) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform3ui(location, x, y, z); } -void Program::Uniform4ui(const char* name, u32 x, u32 y, u32 z, u32 w) const +void Program::Uniform4ui(const char* name, uint32_t x, uint32_t y, uint32_t z, uint32_t w) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform4ui(location, x, y, z, w); } -void Program::Uniform1i(const char* name, s32 x) const +void Program::Uniform1i(const char* name, int32_t x) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform1i(location, x); } -void Program::Uniform2i(const char* name, s32 x, s32 y) const +void Program::Uniform2i(const char* name, int32_t x, int32_t y) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform2i(location, x, y); } -void Program::Uniform3i(const char* name, s32 x, s32 y, s32 z) const +void Program::Uniform3i(const char* name, int32_t x, int32_t y, int32_t z) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform3i(location, x, y, z); } -void Program::Uniform4i(const char* name, s32 x, s32 y, s32 z, s32 w) const +void Program::Uniform4i(const char* name, int32_t x, int32_t y, int32_t z, int32_t w) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) @@ -513,42 +513,42 @@ void Program::Uniform4f(const char* name, float x, float y, float z, float w) co glUniform4f(location, x, y, z, w); } -void Program::Uniform2uiv(const char* name, const u32* v) const +void Program::Uniform2uiv(const char* name, const uint32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform2uiv(location, 1, v); } -void Program::Uniform3uiv(const char* name, const u32* v) const +void Program::Uniform3uiv(const char* name, const uint32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform3uiv(location, 1, v); } -void Program::Uniform4uiv(const char* name, const u32* v) const +void Program::Uniform4uiv(const char* name, const uint32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform4uiv(location, 1, v); } -void Program::Uniform2iv(const char* name, const s32* v) const +void Program::Uniform2iv(const char* name, const int32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform2iv(location, 1, v); } -void Program::Uniform3iv(const char* name, const s32* v) const +void Program::Uniform3iv(const char* name, const int32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) glUniform3iv(location, 1, v); } -void Program::Uniform4iv(const char* name, const s32* v) const +void Program::Uniform4iv(const char* name, const int32_t* v) const { const GLint location = glGetUniformLocation(m_program_id, name); if (location >= 0) @@ -576,7 +576,7 @@ void Program::Uniform4fv(const char* name, const float* v) const glUniform4fv(location, 1, v); } -void Program::BindUniformBlock(const char* name, u32 index) +void Program::BindUniformBlock(const char* name, uint32_t index) { const GLint location = glGetUniformBlockIndex(m_program_id, name); if (location >= 0) diff --git a/src/common/gl/program.h b/src/common/gl/program.h index 4220932d..18295d35 100644 --- a/src/common/gl/program.h +++ b/src/common/gl/program.h @@ -19,9 +19,9 @@ public: bool Compile(const std::string_view vertex_shader, const std::string_view geometry_shader, const std::string_view fragment_shader); - bool CreateFromBinary(const void* data, u32 data_length, u32 data_format); + bool CreateFromBinary(const void* data, uint32_t data_length, uint32_t data_format); - bool GetBinary(std::vector* out_data, u32* out_data_format); + bool GetBinary(std::vector* out_data, uint32_t* out_data_format); void SetBinaryRetrievableHint(); void BindAttribute(GLuint index, const char* name); @@ -43,57 +43,57 @@ public: void Destroy(); int RegisterUniform(const char* name); - void Uniform1ui(int index, u32 x) const; - void Uniform2ui(int index, u32 x, u32 y) const; - void Uniform3ui(int index, u32 x, u32 y, u32 z) const; - void Uniform4ui(int index, u32 x, u32 y, u32 z, u32 w) const; - void Uniform1i(int index, s32 x) const; - void Uniform2i(int index, s32 x, s32 y) const; - void Uniform3i(int index, s32 x, s32 y, s32 z) const; - void Uniform4i(int index, s32 x, s32 y, s32 z, s32 w) const; + void Uniform1ui(int index, uint32_t x) const; + void Uniform2ui(int index, uint32_t x, uint32_t y) const; + void Uniform3ui(int index, uint32_t x, uint32_t y, uint32_t z) const; + void Uniform4ui(int index, uint32_t x, uint32_t y, uint32_t z, uint32_t w) const; + void Uniform1i(int index, int32_t x) const; + void Uniform2i(int index, int32_t x, int32_t y) const; + void Uniform3i(int index, int32_t x, int32_t y, int32_t z) const; + void Uniform4i(int index, int32_t x, int32_t y, int32_t z, int32_t w) const; void Uniform1f(int index, float x) const; void Uniform2f(int index, float x, float y) const; void Uniform3f(int index, float x, float y, float z) const; void Uniform4f(int index, float x, float y, float z, float w) const; - void Uniform2uiv(int index, const u32* v) const; - void Uniform3uiv(int index, const u32* v) const; - void Uniform4uiv(int index, const u32* v) const; - void Uniform2iv(int index, const s32* v) const; - void Uniform3iv(int index, const s32* v) const; - void Uniform4iv(int index, const s32* v) const; + void Uniform2uiv(int index, const uint32_t* v) const; + void Uniform3uiv(int index, const uint32_t* v) const; + void Uniform4uiv(int index, const uint32_t* v) const; + void Uniform2iv(int index, const int32_t* v) const; + void Uniform3iv(int index, const int32_t* v) const; + void Uniform4iv(int index, const int32_t* v) const; void Uniform2fv(int index, const float* v) const; void Uniform3fv(int index, const float* v) const; void Uniform4fv(int index, const float* v) const; - void Uniform1ui(const char* name, u32 x) const; - void Uniform2ui(const char* name, u32 x, u32 y) const; - void Uniform3ui(const char* name, u32 x, u32 y, u32 z) const; - void Uniform4ui(const char* name, u32 x, u32 y, u32 z, u32 w) const; - void Uniform1i(const char* name, s32 x) const; - void Uniform2i(const char* name, s32 x, s32 y) const; - void Uniform3i(const char* name, s32 x, s32 y, s32 z) const; - void Uniform4i(const char* name, s32 x, s32 y, s32 z, s32 w) const; + void Uniform1ui(const char* name, uint32_t x) const; + void Uniform2ui(const char* name, uint32_t x, uint32_t y) const; + void Uniform3ui(const char* name, uint32_t x, uint32_t y, uint32_t z) const; + void Uniform4ui(const char* name, uint32_t x, uint32_t y, uint32_t z, uint32_t w) const; + void Uniform1i(const char* name, int32_t x) const; + void Uniform2i(const char* name, int32_t x, int32_t y) const; + void Uniform3i(const char* name, int32_t x, int32_t y, int32_t z) const; + void Uniform4i(const char* name, int32_t x, int32_t y, int32_t z, int32_t w) const; void Uniform1f(const char* name, float x) const; void Uniform2f(const char* name, float x, float y) const; void Uniform3f(const char* name, float x, float y, float z) const; void Uniform4f(const char* name, float x, float y, float z, float w) const; - void Uniform2uiv(const char* name, const u32* v) const; - void Uniform3uiv(const char* name, const u32* v) const; - void Uniform4uiv(const char* name, const u32* v) const; - void Uniform2iv(const char* name, const s32* v) const; - void Uniform3iv(const char* name, const s32* v) const; - void Uniform4iv(const char* name, const s32* v) const; + void Uniform2uiv(const char* name, const uint32_t* v) const; + void Uniform3uiv(const char* name, const uint32_t* v) const; + void Uniform4uiv(const char* name, const uint32_t* v) const; + void Uniform2iv(const char* name, const int32_t* v) const; + void Uniform3iv(const char* name, const int32_t* v) const; + void Uniform4iv(const char* name, const int32_t* v) const; void Uniform2fv(const char* name, const float* v) const; void Uniform3fv(const char* name, const float* v) const; void Uniform4fv(const char* name, const float* v) const; - void BindUniformBlock(const char* name, u32 index); + void BindUniformBlock(const char* name, uint32_t index); Program& operator=(const Program&) = delete; Program& operator=(Program&& prog); private: - static u32 s_last_program_id; + static uint32_t s_last_program_id; GLuint m_program_id = 0; GLuint m_vertex_shader_id = 0; diff --git a/src/common/gl/shader_cache.cpp b/src/common/gl/shader_cache.cpp index 0abc751b..99562932 100644 --- a/src/common/gl/shader_cache.cpp +++ b/src/common/gl/shader_cache.cpp @@ -13,18 +13,18 @@ namespace GL { #pragma pack(push, 1) struct CacheIndexEntry { - u64 vertex_source_hash_low; - u64 vertex_source_hash_high; - u32 vertex_source_length; - u64 geometry_source_hash_low; - u64 geometry_source_hash_high; - u32 geometry_source_length; - u64 fragment_source_hash_low; - u64 fragment_source_hash_high; - u32 fragment_source_length; - u32 file_offset; - u32 blob_size; - u32 blob_format; + uint64_t vertex_source_hash_low; + uint64_t vertex_source_hash_high; + uint32_t vertex_source_length; + uint64_t geometry_source_hash_low; + uint64_t geometry_source_hash_high; + uint32_t geometry_source_length; + uint64_t fragment_source_hash_low; + uint64_t fragment_source_hash_high; + uint32_t fragment_source_length; + uint32_t file_offset; + uint32_t blob_size; + uint32_t blob_format; }; #pragma pack(pop) @@ -55,7 +55,7 @@ bool ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) const fragment_source_hash_high != key.fragment_source_hash_high || fragment_source_length != key.fragment_source_length); } -void ShaderCache::Open(bool is_gles, std::string_view base_path, u32 version) +void ShaderCache::Open(bool is_gles, std::string_view base_path, uint32_t version) { m_base_path = base_path; m_version = version; @@ -106,7 +106,7 @@ bool ShaderCache::CreateNew(const std::string& index_filename, const std::string return false; } - const u32 index_version = FILE_VERSION; + const uint32_t index_version = FILE_VERSION; if (rfwrite(&index_version, sizeof(index_version), 1, m_index_file) != 1 || rfwrite(&m_version, sizeof(m_version), 1, m_index_file) != 1) { @@ -136,8 +136,8 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str if (!m_index_file) return false; - u32 file_version = 0; - u32 data_version = 0; + uint32_t file_version = 0; + uint32_t data_version = 0; if (rfread(&file_version, sizeof(file_version), 1, m_index_file) != 1 || file_version != FILE_VERSION || rfread(&data_version, sizeof(data_version), 1, m_index_file) != 1 || data_version != m_version) { @@ -157,7 +157,7 @@ bool ShaderCache::ReadExisting(const std::string& index_filename, const std::str } rfseek(m_blob_file, 0, SEEK_END); - const u32 blob_file_size = static_cast(rftell(m_blob_file)); + const uint32_t blob_file_size = static_cast(rftell(m_blob_file)); for (;;) { @@ -216,10 +216,10 @@ ShaderCache::CacheIndexKey ShaderCache::GetCacheKey(const std::string_view& vert { struct { - u64 low; - u64 high; + uint64_t low; + uint64_t high; }; - u8 bytes[16]; + uint8_t bytes[16]; }; ShaderHash vertex_hash = {}; @@ -229,27 +229,27 @@ ShaderCache::CacheIndexKey ShaderCache::GetCacheKey(const std::string_view& vert MD5Digest digest; if (!vertex_shader.empty()) { - digest.Update(vertex_shader.data(), static_cast(vertex_shader.length())); + digest.Update(vertex_shader.data(), static_cast(vertex_shader.length())); digest.Final(vertex_hash.bytes); } if (!geometry_shader.empty()) { digest.Reset(); - digest.Update(geometry_shader.data(), static_cast(geometry_shader.length())); + digest.Update(geometry_shader.data(), static_cast(geometry_shader.length())); digest.Final(geometry_hash.bytes); } if (!fragment_shader.empty()) { digest.Reset(); - digest.Update(fragment_shader.data(), static_cast(fragment_shader.length())); + digest.Update(fragment_shader.data(), static_cast(fragment_shader.length())); digest.Final(fragment_hash.bytes); } - return CacheIndexKey{vertex_hash.low, vertex_hash.high, static_cast(vertex_shader.length()), - geometry_hash.low, geometry_hash.high, static_cast(geometry_shader.length()), - fragment_hash.low, fragment_hash.high, static_cast(fragment_shader.length())}; + return CacheIndexKey{vertex_hash.low, vertex_hash.high, static_cast(vertex_shader.length()), + geometry_hash.low, geometry_hash.high, static_cast(geometry_shader.length()), + fragment_hash.low, fragment_hash.high, static_cast(fragment_shader.length())}; } std::string ShaderCache::GetIndexFileName() const @@ -274,7 +274,7 @@ std::optional ShaderCache::GetProgram(const std::string_view vertex_sha if (iter == m_index.end()) return CompileAndAddProgram(key, vertex_shader, geometry_shader, fragment_shader, callback); - std::vector data(iter->second.blob_size); + std::vector data(iter->second.blob_size); if (rfseek(m_blob_file, iter->second.file_offset, SEEK_SET) != 0 || rfread(data.data(), 1, iter->second.blob_size, m_blob_file) != iter->second.blob_size) { @@ -283,7 +283,7 @@ std::optional ShaderCache::GetProgram(const std::string_view vertex_sha } Program prog; - if (prog.CreateFromBinary(data.data(), static_cast(data.size()), iter->second.blob_format)) + if (prog.CreateFromBinary(data.data(), static_cast(data.size()), iter->second.blob_format)) return std::optional(std::move(prog)); Log_WarningPrintf( @@ -325,8 +325,8 @@ std::optional ShaderCache::CompileAndAddProgram(const CacheIndexKey& ke if (!prog) return std::nullopt; - std::vector prog_data; - u32 prog_format = 0; + std::vector prog_data; + uint32_t prog_format = 0; if (!prog->GetBinary(&prog_data, &prog_format)) return std::nullopt; @@ -334,8 +334,8 @@ std::optional ShaderCache::CompileAndAddProgram(const CacheIndexKey& ke return prog; CacheIndexData data; - data.file_offset = static_cast(rftell(m_blob_file)); - data.blob_size = static_cast(prog_data.size()); + data.file_offset = static_cast(rftell(m_blob_file)); + data.blob_size = static_cast(prog_data.size()); data.blob_format = prog_format; CacheIndexEntry entry = {}; diff --git a/src/common/gl/shader_cache.h b/src/common/gl/shader_cache.h index 93864a5b..f19c2031 100644 --- a/src/common/gl/shader_cache.h +++ b/src/common/gl/shader_cache.h @@ -21,7 +21,7 @@ public: ShaderCache(); ~ShaderCache(); - void Open(bool is_gles, std::string_view base_path, u32 version); + void Open(bool is_gles, std::string_view base_path, uint32_t version); // Returns whether Open() has already been called successfully on // this instance. Used by the lazy-compile path in GPU_HW_OpenGL @@ -35,19 +35,19 @@ public: const std::string_view fragment_shader, const PreLinkCallback& callback = {}); private: - static constexpr u32 FILE_VERSION = 3; + static constexpr uint32_t FILE_VERSION = 3; struct CacheIndexKey { - u64 vertex_source_hash_low; - u64 vertex_source_hash_high; - u32 vertex_source_length; - u64 geometry_source_hash_low; - u64 geometry_source_hash_high; - u32 geometry_source_length; - u64 fragment_source_hash_low; - u64 fragment_source_hash_high; - u32 fragment_source_length; + uint64_t vertex_source_hash_low; + uint64_t vertex_source_hash_high; + uint32_t vertex_source_length; + uint64_t geometry_source_hash_low; + uint64_t geometry_source_hash_high; + uint32_t geometry_source_length; + uint64_t fragment_source_hash_low; + uint64_t fragment_source_hash_high; + uint32_t fragment_source_length; bool operator==(const CacheIndexKey& key) const; bool operator!=(const CacheIndexKey& key) const; @@ -67,9 +67,9 @@ private: struct CacheIndexData { - u32 file_offset; - u32 blob_size; - u32 blob_format; + uint32_t file_offset; + uint32_t blob_size; + uint32_t blob_format; }; using CacheIndex = std::unordered_map; @@ -97,7 +97,7 @@ private: RFILE* m_blob_file = nullptr; CacheIndex m_index; - u32 m_version = 0; + uint32_t m_version = 0; bool m_program_binary_supported = false; }; diff --git a/src/common/gl/stream_buffer.cpp b/src/common/gl/stream_buffer.cpp index 806d07ce..37e1d700 100644 --- a/src/common/gl/stream_buffer.cpp +++ b/src/common/gl/stream_buffer.cpp @@ -5,7 +5,7 @@ namespace GL { -StreamBuffer::StreamBuffer(GLenum target, GLuint buffer_id, u32 size) +StreamBuffer::StreamBuffer(GLenum target, GLuint buffer_id, uint32_t size) : m_target(target), m_buffer_id(buffer_id), m_size(size) { } @@ -33,12 +33,12 @@ class BufferSubDataStreamBuffer final : public StreamBuffer public: ~BufferSubDataStreamBuffer() override = default; - MappingResult Map(u32 alignment, u32 min_size) override + MappingResult Map(uint32_t alignment, uint32_t min_size) override { return MappingResult{static_cast(m_cpu_buffer.data()), 0, 0, m_size / alignment}; } - void Unmap(u32 used_size) override + void Unmap(uint32_t used_size) override { if (used_size == 0) return; @@ -47,7 +47,7 @@ public: glBufferSubData(m_target, 0, used_size, m_cpu_buffer.data()); } - static std::unique_ptr Create(GLenum target, u32 size) + static std::unique_ptr Create(GLenum target, uint32_t size) { glGetError(); @@ -67,12 +67,12 @@ public: } private: - BufferSubDataStreamBuffer(GLenum target, GLuint buffer_id, u32 size) + BufferSubDataStreamBuffer(GLenum target, GLuint buffer_id, uint32_t size) : StreamBuffer(target, buffer_id, size), m_cpu_buffer(size) { } - std::vector m_cpu_buffer; + std::vector m_cpu_buffer; }; // Uses BufferData() to orphan the buffer after every update. Used on Mali where BufferSubData forces a sync. @@ -81,12 +81,12 @@ class BufferDataStreamBuffer final : public StreamBuffer public: ~BufferDataStreamBuffer() override = default; - MappingResult Map(u32 alignment, u32 min_size) override + MappingResult Map(uint32_t alignment, uint32_t min_size) override { return MappingResult{static_cast(m_cpu_buffer.data()), 0, 0, m_size / alignment}; } - void Unmap(u32 used_size) override + void Unmap(uint32_t used_size) override { if (used_size == 0) return; @@ -95,7 +95,7 @@ public: glBufferData(m_target, used_size, m_cpu_buffer.data(), GL_STREAM_DRAW); } - static std::unique_ptr Create(GLenum target, u32 size) + static std::unique_ptr Create(GLenum target, uint32_t size) { glGetError(); @@ -115,40 +115,40 @@ public: } private: - BufferDataStreamBuffer(GLenum target, GLuint buffer_id, u32 size) + BufferDataStreamBuffer(GLenum target, GLuint buffer_id, uint32_t size) : StreamBuffer(target, buffer_id, size), m_cpu_buffer(size) { } - std::vector m_cpu_buffer; + std::vector m_cpu_buffer; }; // Base class for implementations which require syncing. class SyncingStreamBuffer : public StreamBuffer { public: - enum : u32 + enum : uint32_t { NUM_SYNC_POINTS = 16 }; virtual ~SyncingStreamBuffer() override { - for (u32 i = m_available_block_index; i <= m_used_block_index; i++) + for (uint32_t i = m_available_block_index; i <= m_used_block_index; i++) glDeleteSync(m_sync_objects[i]); } protected: - SyncingStreamBuffer(GLenum target, GLuint buffer_id, u32 size) + SyncingStreamBuffer(GLenum target, GLuint buffer_id, uint32_t size) : StreamBuffer(target, buffer_id, size), m_bytes_per_block((size + (NUM_SYNC_POINTS)-1) / NUM_SYNC_POINTS) { } - u32 GetSyncIndexForOffset(u32 offset) { return offset / m_bytes_per_block; } + uint32_t GetSyncIndexForOffset(uint32_t offset) { return offset / m_bytes_per_block; } - void AddSyncsForOffset(u32 offset) + void AddSyncsForOffset(uint32_t offset) { - const u32 end = GetSyncIndexForOffset(offset); + const uint32_t end = GetSyncIndexForOffset(offset); for (; m_used_block_index < end; m_used_block_index++) m_sync_objects[m_used_block_index] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } @@ -160,14 +160,14 @@ protected: sync = nullptr; } - void EnsureSyncsWaitedForOffset(u32 offset) + void EnsureSyncsWaitedForOffset(uint32_t offset) { - const u32 end = std::min(GetSyncIndexForOffset(offset) + 1, NUM_SYNC_POINTS); + const uint32_t end = std::min(GetSyncIndexForOffset(offset) + 1, NUM_SYNC_POINTS); for (; m_available_block_index < end; m_available_block_index++) WaitForSync(m_sync_objects[m_available_block_index]); } - void AllocateSpace(u32 size) + void AllocateSpace(uint32_t size) { // add sync objects for writes since the last allocation AddSyncsForOffset(m_position); @@ -194,10 +194,10 @@ protected: } } - u32 m_position = 0; - u32 m_used_block_index = 0; - u32 m_available_block_index = NUM_SYNC_POINTS; - u32 m_bytes_per_block; + uint32_t m_position = 0; + uint32_t m_used_block_index = 0; + uint32_t m_available_block_index = NUM_SYNC_POINTS; + uint32_t m_bytes_per_block; std::array m_sync_objects{}; }; @@ -210,19 +210,19 @@ public: glUnmapBuffer(m_target); } - MappingResult Map(u32 alignment, u32 min_size) override + MappingResult Map(uint32_t alignment, uint32_t min_size) override { if (m_position > 0) m_position = Common::AlignUp(m_position, alignment); AllocateSpace(min_size); - const u32 free_space_in_block = ((m_available_block_index * m_bytes_per_block) - m_position); + const uint32_t free_space_in_block = ((m_available_block_index * m_bytes_per_block) - m_position); return MappingResult{static_cast(m_mapped_ptr + m_position), m_position, m_position / alignment, free_space_in_block / alignment}; } - void Unmap(u32 used_size) override + void Unmap(uint32_t used_size) override { if (!m_coherent) { @@ -233,7 +233,7 @@ public: m_position += used_size; } - static std::unique_ptr Create(GLenum target, u32 size, bool coherent = true) + static std::unique_ptr Create(GLenum target, uint32_t size, bool coherent = true) { glGetError(); @@ -241,8 +241,8 @@ public: glGenBuffers(1, &buffer_id); glBindBuffer(target, buffer_id); - const u32 flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | (coherent ? GL_MAP_COHERENT_BIT : 0); - const u32 map_flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | (coherent ? 0 : GL_MAP_FLUSH_EXPLICIT_BIT); + const uint32_t flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | (coherent ? GL_MAP_COHERENT_BIT : 0); + const uint32_t map_flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | (coherent ? 0 : GL_MAP_FLUSH_EXPLICIT_BIT); if (GLAD_GL_VERSION_4_4 || GLAD_GL_ARB_buffer_storage) glBufferStorage(target, size, nullptr, flags); else if (GLAD_GL_EXT_buffer_storage) @@ -255,23 +255,23 @@ public: return {}; } - u8* mapped_ptr = static_cast(glMapBufferRange(target, 0, size, map_flags)); + uint8_t* mapped_ptr = static_cast(glMapBufferRange(target, 0, size, map_flags)); return std::unique_ptr(new BufferStorageStreamBuffer(target, buffer_id, size, mapped_ptr, coherent)); } private: - BufferStorageStreamBuffer(GLenum target, GLuint buffer_id, u32 size, u8* mapped_ptr, bool coherent) + BufferStorageStreamBuffer(GLenum target, GLuint buffer_id, uint32_t size, uint8_t* mapped_ptr, bool coherent) : SyncingStreamBuffer(target, buffer_id, size), m_mapped_ptr(mapped_ptr), m_coherent(coherent) { } - u8* m_mapped_ptr; + uint8_t* m_mapped_ptr; bool m_coherent; }; } // namespace detail -std::unique_ptr StreamBuffer::Create(GLenum target, u32 size) +std::unique_ptr StreamBuffer::Create(GLenum target, uint32_t size) { std::unique_ptr buf; if (GLAD_GL_VERSION_4_4 || GLAD_GL_ARB_buffer_storage || GLAD_GL_EXT_buffer_storage) diff --git a/src/common/gl/stream_buffer.h b/src/common/gl/stream_buffer.h index 78958dcf..a4e08b6f 100644 --- a/src/common/gl/stream_buffer.h +++ b/src/common/gl/stream_buffer.h @@ -13,7 +13,7 @@ public: ALWAYS_INLINE GLuint GetGLBufferId() const { return m_buffer_id; } ALWAYS_INLINE GLenum GetGLTarget() const { return m_target; } - ALWAYS_INLINE u32 GetSize() const { return m_size; } + ALWAYS_INLINE uint32_t GetSize() const { return m_size; } void Bind(); void Unbind(); @@ -21,21 +21,21 @@ public: struct MappingResult { void* pointer; - u32 buffer_offset; - u32 index_aligned; // offset / alignment, suitable for base vertex - u32 space_aligned; // remaining space / alignment + uint32_t buffer_offset; + uint32_t index_aligned; // offset / alignment, suitable for base vertex + uint32_t space_aligned; // remaining space / alignment }; - virtual MappingResult Map(u32 alignment, u32 min_size) = 0; - virtual void Unmap(u32 used_size) = 0; + virtual MappingResult Map(uint32_t alignment, uint32_t min_size) = 0; + virtual void Unmap(uint32_t used_size) = 0; - static std::unique_ptr Create(GLenum target, u32 size); + static std::unique_ptr Create(GLenum target, uint32_t size); protected: - StreamBuffer(GLenum target, GLuint buffer_id, u32 size); + StreamBuffer(GLenum target, GLuint buffer_id, uint32_t size); GLenum m_target; GLuint m_buffer_id; - u32 m_size; + uint32_t m_size; }; } // namespace GL \ No newline at end of file diff --git a/src/common/gl/texture.cpp b/src/common/gl/texture.cpp index f2b28914..79fbf79e 100644 --- a/src/common/gl/texture.cpp +++ b/src/common/gl/texture.cpp @@ -20,7 +20,7 @@ Texture::~Texture() Destroy(); } -bool Texture::Create(u32 width, u32 height, u32 samples, GLenum internal_format, GLenum format, GLenum type, +bool Texture::Create(uint32_t width, uint32_t height, uint32_t samples, GLenum internal_format, GLenum format, GLenum type, const void* data, bool linear_filter, bool wrap) { glGetError(); @@ -72,7 +72,7 @@ bool Texture::Create(u32 width, u32 height, u32 samples, GLenum internal_format, return true; } -void Texture::Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data) +void Texture::Replace(uint32_t width, uint32_t height, GLenum internal_format, GLenum format, GLenum type, const void* data) { m_width = width; m_height = height; diff --git a/src/common/gl/texture.h b/src/common/gl/texture.h index e8abfde4..fbed1da5 100644 --- a/src/common/gl/texture.h +++ b/src/common/gl/texture.h @@ -10,9 +10,9 @@ public: Texture(Texture&& moved); ~Texture(); - bool Create(u32 width, u32 height, u32 samples, GLenum internal_format, GLenum format, GLenum type, + bool Create(uint32_t width, uint32_t height, uint32_t samples, GLenum internal_format, GLenum format, GLenum type, const void* data = nullptr, bool linear_filter = false, bool wrap = false); - void Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data); + void Replace(uint32_t width, uint32_t height, GLenum internal_format, GLenum format, GLenum type, const void* data); bool CreateFramebuffer(); void Destroy(); @@ -20,9 +20,9 @@ public: bool IsValid() const { return m_id != 0; } bool IsMultisampled() const { return m_samples > 1; } GLuint GetGLId() const { return m_id; } - u32 GetWidth() const { return m_width; } - u32 GetHeight() const { return m_height; } - u32 GetSamples() const { return m_samples; } + uint32_t GetWidth() const { return m_width; } + uint32_t GetHeight() const { return m_height; } + uint32_t GetSamples() const { return m_samples; } GLenum GetGLTarget() const { return IsMultisampled() ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D; } @@ -36,9 +36,9 @@ public: private: GLuint m_id = 0; - u32 m_width = 0; - u32 m_height = 0; - u32 m_samples = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + uint32_t m_samples = 0; GLuint m_fbo_id = 0; }; diff --git a/src/common/image.cpp b/src/common/image.cpp index 12b1907d..50df7567 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -12,14 +12,14 @@ bool LoadImageFromFile(Common::RGBA8Image* image, const char* filename) return false; int width, height, file_channels; - u8* pixel_data = stbi_load_from_file(fp, &width, &height, &file_channels, 4); + uint8_t* pixel_data = stbi_load_from_file(fp, &width, &height, &file_channels, 4); if (!pixel_data) { rfclose(fp); return false; } - image->SetPixels(static_cast(width), static_cast(height), reinterpret_cast(pixel_data)); + image->SetPixels(static_cast(width), static_cast(height), reinterpret_cast(pixel_data)); stbi_image_free(pixel_data); rfclose(fp); return true; diff --git a/src/common/image.h b/src/common/image.h index ff4ba31c..412f756e 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -11,7 +11,7 @@ class Image { public: Image() = default; - Image(u32 width, u32 height, const PixelType* pixels) { SetPixels(width, height, pixels); } + Image(uint32_t width, uint32_t height, const PixelType* pixels) { SetPixels(width, height, pixels); } Image(const Image& copy) { m_width = copy.m_width; @@ -45,13 +45,13 @@ public: } ALWAYS_INLINE bool IsValid() const { return (m_width > 0 && m_height > 0); } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } - ALWAYS_INLINE u32 GetByteStride() const { return (sizeof(PixelType) * m_width); } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetByteStride() const { return (sizeof(PixelType) * m_width); } ALWAYS_INLINE const PixelType* GetPixels() const { return m_pixels.data(); } ALWAYS_INLINE PixelType* GetPixels() { return m_pixels.data(); } - ALWAYS_INLINE void SetPixel(u32 x, u32 y, PixelType pixel) { m_pixels[y * m_width + x] = pixel; } - ALWAYS_INLINE PixelType GetPixel(u32 x, u32 y) const { return m_pixels[y * m_width + x]; } + ALWAYS_INLINE void SetPixel(uint32_t x, uint32_t y, PixelType pixel) { m_pixels[y * m_width + x] = pixel; } + ALWAYS_INLINE PixelType GetPixel(uint32_t x, uint32_t y) const { return m_pixels[y * m_width + x]; } void Clear(PixelType fill_value = static_cast(0)) { @@ -65,7 +65,7 @@ public: m_pixels.clear(); } - void SetSize(u32 new_width, u32 new_height, PixelType fill_value = static_cast(0)) + void SetSize(uint32_t new_width, uint32_t new_height, PixelType fill_value = static_cast(0)) { m_width = new_width; m_height = new_height; @@ -73,7 +73,7 @@ public: Clear(fill_value); } - void SetPixels(u32 width, u32 height, const PixelType* pixels) + void SetPixels(uint32_t width, uint32_t height, const PixelType* pixels) { m_width = width; m_height = height; @@ -82,12 +82,12 @@ public: } private: - u32 m_width = 0; - u32 m_height = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; std::vector m_pixels; }; -using RGBA8Image = Image; +using RGBA8Image = Image; bool LoadImageFromFile(Common::RGBA8Image* image, const char* filename); diff --git a/src/common/iso_reader.cpp b/src/common/iso_reader.cpp index bac906fc..5e7cabd1 100644 --- a/src/common/iso_reader.cpp +++ b/src/common/iso_reader.cpp @@ -5,9 +5,9 @@ #include Log_SetChannel(ISOReader); -static bool FilenamesEqual(const char* a, const char* b, u32 length) +static bool FilenamesEqual(const char* a, const char* b, uint32_t length) { - u32 pos = 0; + uint32_t pos = 0; for (; pos < length && *a != '\0' && *b != '\0'; pos++) { if (std::tolower(*(a++)) != std::tolower(*(b++))) @@ -21,7 +21,7 @@ ISOReader::ISOReader() = default; ISOReader::~ISOReader() = default; -bool ISOReader::Open(CDImage* image, u32 track_number) +bool ISOReader::Open(CDImage* image, uint32_t track_number) { m_image = image; m_track_number = track_number; @@ -38,9 +38,9 @@ bool ISOReader::ReadPVD() return false; // try only a maximum of 256 volume descriptors - for (u32 i = 0; i < 256; i++) + for (uint32_t i = 0; i < 256; i++) { - u8 buffer[SECTOR_SIZE]; + uint8_t buffer[SECTOR_SIZE]; if (m_image->Read(CDImage::ReadMode::DataOnly, 1, buffer) != 1) return false; @@ -60,7 +60,7 @@ bool ISOReader::ReadPVD() std::optional ISOReader::LocateFile(const char* path) { - u8 sector_buffer[SECTOR_SIZE]; + uint8_t sector_buffer[SECTOR_SIZE]; const ISODirectoryEntry* root_de = reinterpret_cast(m_pvd.root_directory_entry); if (*path == '\0' || std::strcmp(path, "/") == 0) @@ -73,8 +73,8 @@ std::optional ISOReader::LocateFile(const char* pa return LocateFile(path, sector_buffer, root_de->location_le, root_de->length_le); } -std::optional ISOReader::LocateFile(const char* path, u8* sector_buffer, - u32 directory_record_lba, u32 directory_record_size) +std::optional ISOReader::LocateFile(const char* path, uint8_t* sector_buffer, + uint32_t directory_record_lba, uint32_t directory_record_size) { if (directory_record_size == 0) { @@ -87,7 +87,7 @@ std::optional ISOReader::LocateFile(const char* pa while (*path_component_start == '/' || *path_component_start == '\\') path_component_start++; - u32 path_component_length = 0; + uint32_t path_component_length = 0; const char* path_component_end = path_component_start; while (*path_component_end != '\0' && *path_component_end != '/' && *path_component_end != '\\') { @@ -96,14 +96,14 @@ std::optional ISOReader::LocateFile(const char* pa } // start reading directory entries - const u32 num_sectors = (directory_record_size + (SECTOR_SIZE - 1)) / SECTOR_SIZE; + const uint32_t num_sectors = (directory_record_size + (SECTOR_SIZE - 1)) / SECTOR_SIZE; if (!m_image->Seek(m_track_number, directory_record_lba)) { Log_ErrorPrintf("Seek to LBA %u failed", directory_record_lba); return std::nullopt; } - for (u32 i = 0; i < num_sectors; i++) + for (uint32_t i = 0; i < num_sectors; i++) { if (m_image->Read(CDImage::ReadMode::DataOnly, 1, sector_buffer) != 1) { @@ -111,7 +111,7 @@ std::optional ISOReader::LocateFile(const char* pa return std::nullopt; } - u32 sector_offset = 0; + uint32_t sector_offset = 0; while ((sector_offset + sizeof(ISODirectoryEntry)) < SECTOR_SIZE) { const ISODirectoryEntry* de = reinterpret_cast(§or_buffer[sector_offset]); @@ -171,7 +171,7 @@ std::optional ISOReader::LocateFile(const char* pa return std::nullopt; } -bool ISOReader::ReadFile(const char* path, std::vector* data) +bool ISOReader::ReadFile(const char* path, std::vector* data) { auto de = LocateFile(path); if (!de) @@ -194,8 +194,8 @@ bool ISOReader::ReadFile(const char* path, std::vector* data) return true; } - const u32 num_sectors = (de->length_le + (SECTOR_SIZE - 1)) / SECTOR_SIZE; - data->resize(num_sectors * u64(SECTOR_SIZE)); + const uint32_t num_sectors = (de->length_le + (SECTOR_SIZE - 1)) / SECTOR_SIZE; + data->resize(num_sectors * uint64_t(SECTOR_SIZE)); if (m_image->Read(CDImage::ReadMode::DataOnly, num_sectors, data->data()) != num_sectors) return false; diff --git a/src/common/iso_reader.h b/src/common/iso_reader.h index 82a308e1..765c5130 100644 --- a/src/common/iso_reader.h +++ b/src/common/iso_reader.h @@ -9,15 +9,15 @@ class CDImage; class ISOReader { public: - static constexpr u32 SECTOR_SIZE = 2048; + static constexpr uint32_t SECTOR_SIZE = 2048; #pragma pack(push, 1) struct ISOVolumeDescriptorHeader { - u8 type_code; + uint8_t type_code; char standard_identifier[5]; - u8 version; + uint8_t version; }; struct ISOBootRecord @@ -25,7 +25,7 @@ public: ISOVolumeDescriptorHeader header; char boot_system_identifier[32]; char boot_identifier[32]; - u8 data[1977]; + uint8_t data[1977]; }; struct ISOPVDDateTime @@ -37,32 +37,32 @@ public: char minute[2]; char second[2]; char milliseconds[2]; - s8 gmt_offset; + int8_t gmt_offset; }; struct ISOPrimaryVolumeDescriptor { ISOVolumeDescriptorHeader header; - u8 unused; + uint8_t unused; char system_identifier[32]; char volume_identifier[32]; char unused2[8]; - u32 total_sectors_le; - u32 total_sectors_be; + uint32_t total_sectors_le; + uint32_t total_sectors_be; char unused3[32]; - u16 volume_set_size_le; - u16 volume_set_size_be; - u16 volume_sequence_number_le; - u16 volume_sequence_number_be; - u16 block_size_le; - u16 block_size_be; - u32 path_table_size_le; - u32 path_table_size_be; - u32 path_table_location_le; - u32 optional_path_table_location_le; - u32 path_table_location_be; - u32 optional_path_table_location_be; - u8 root_directory_entry[34]; + uint16_t volume_set_size_le; + uint16_t volume_set_size_be; + uint16_t volume_sequence_number_le; + uint16_t volume_sequence_number_be; + uint16_t block_size_le; + uint16_t block_size_be; + uint32_t path_table_size_le; + uint32_t path_table_size_be; + uint32_t path_table_location_le; + uint32_t optional_path_table_location_le; + uint32_t path_table_location_be; + uint32_t optional_path_table_location_be; + uint8_t root_directory_entry[34]; char volume_set_identifier[128]; char publisher_identifier[128]; char data_preparer_identifier[128]; @@ -74,24 +74,24 @@ public: ISOPVDDateTime volume_modification_time; ISOPVDDateTime volume_expiration_time; ISOPVDDateTime volume_effective_time; - u8 structure_version; - u8 unused4; - u8 application_used[512]; - u8 reserved[653]; + uint8_t structure_version; + uint8_t unused4; + uint8_t application_used[512]; + uint8_t reserved[653]; }; struct ISODirectoryEntryDateTime { - u8 years_since_1900; - u8 month; - u8 day; - u8 hour; - u8 minute; - u8 second; - s8 gmt_offset; + uint8_t years_since_1900; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + int8_t gmt_offset; }; - enum ISODirectoryEntryFlags : u8 + enum ISODirectoryEntryFlags : uint8_t { ISODirectoryEntryFlag_Hidden = (1 << 0), ISODirectoryEntryFlag_Directory = (1 << 1), @@ -103,19 +103,19 @@ public: struct ISODirectoryEntry { - u8 entry_length; - u8 extended_attribute_length; - u32 location_le; - u32 location_be; - u32 length_le; - u32 length_be; + uint8_t entry_length; + uint8_t extended_attribute_length; + uint32_t location_le; + uint32_t location_be; + uint32_t length_le; + uint32_t length_be; ISODirectoryEntryDateTime recoding_time; ISODirectoryEntryFlags flags; - u8 interleaved_unit_size; - u8 interleaved_gap_size; - u16 sequence_le; - u16 sequence_be; - u8 filename_length; + uint8_t interleaved_unit_size; + uint8_t interleaved_gap_size; + uint16_t sequence_le; + uint16_t sequence_be; + uint8_t filename_length; }; #pragma pack(pop) @@ -124,22 +124,22 @@ public: ~ISOReader(); ALWAYS_INLINE const CDImage* GetImage() const { return m_image; } - ALWAYS_INLINE u32 GetTrackNumber() const { return m_track_number; } + ALWAYS_INLINE uint32_t GetTrackNumber() const { return m_track_number; } ALWAYS_INLINE const ISOPrimaryVolumeDescriptor& GetPVD() const { return m_pvd; } - bool Open(CDImage* image, u32 track_number); + bool Open(CDImage* image, uint32_t track_number); - bool ReadFile(const char* path, std::vector* data); + bool ReadFile(const char* path, std::vector* data); private: bool ReadPVD(); std::optional LocateFile(const char* path); - std::optional LocateFile(const char* path, u8* sector_buffer, u32 directory_record_lba, - u32 directory_record_size); + std::optional LocateFile(const char* path, uint8_t* sector_buffer, uint32_t directory_record_lba, + uint32_t directory_record_size); CDImage* m_image; - u32 m_track_number; + uint32_t m_track_number; ISOPrimaryVolumeDescriptor m_pvd = {}; }; diff --git a/src/common/jit_code_buffer.cpp b/src/common/jit_code_buffer.cpp index d7684a32..2a82b84f 100644 --- a/src/common/jit_code_buffer.cpp +++ b/src/common/jit_code_buffer.cpp @@ -22,14 +22,14 @@ JitCodeBuffer::~JitCodeBuffer() Destroy(); } -bool JitCodeBuffer::Allocate(u32 size /* = 64 * 1024 * 1024 */, u32 far_code_size /* = 0 */) +bool JitCodeBuffer::Allocate(uint32_t size /* = 64 * 1024 * 1024 */, uint32_t far_code_size /* = 0 */) { Destroy(); m_total_size = size + far_code_size; #if defined(_WIN32) - m_code_ptr = static_cast(VirtualAlloc(nullptr, m_total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE)); + m_code_ptr = static_cast(VirtualAlloc(nullptr, m_total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE)); if (!m_code_ptr) return false; #elif defined(__linux__) || defined(__ANDROID__) || defined(__APPLE__) || defined(__HAIKU__) || defined(__FreeBSD__) @@ -39,7 +39,7 @@ bool JitCodeBuffer::Allocate(u32 size /* = 64 * 1024 * 1024 */, u32 far_code_siz flags |= MAP_JIT; #endif - m_code_ptr = static_cast(mmap(nullptr, m_total_size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0)); + m_code_ptr = static_cast(mmap(nullptr, m_total_size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0)); if (!m_code_ptr) return false; #else @@ -50,7 +50,7 @@ bool JitCodeBuffer::Allocate(u32 size /* = 64 * 1024 * 1024 */, u32 far_code_siz m_code_size = size; m_code_used = 0; - m_far_code_ptr = static_cast(m_code_ptr) + size; + m_far_code_ptr = static_cast(m_code_ptr) + size; m_free_far_code_ptr = m_far_code_ptr; m_far_code_size = far_code_size; m_far_code_used = 0; @@ -60,7 +60,7 @@ bool JitCodeBuffer::Allocate(u32 size /* = 64 * 1024 * 1024 */, u32 far_code_siz return true; } -bool JitCodeBuffer::Initialize(void* buffer, u32 size, u32 far_code_size /* = 0 */, u32 guard_size /* = 0 */) +bool JitCodeBuffer::Initialize(void* buffer, uint32_t size, uint32_t far_code_size /* = 0 */, uint32_t guard_size /* = 0 */) { Destroy(); @@ -75,27 +75,27 @@ bool JitCodeBuffer::Initialize(void* buffer, u32 size, u32 far_code_size /* = 0 if (guard_size > 0) { DWORD old_guard_protect = 0; - u8* guard_at_end = (static_cast(buffer) + size) - guard_size; + uint8_t* guard_at_end = (static_cast(buffer) + size) - guard_size; if (!VirtualProtect(buffer, guard_size, PAGE_NOACCESS, &old_guard_protect) || !VirtualProtect(guard_at_end, guard_size, PAGE_NOACCESS, &old_guard_protect)) return false; } - m_code_ptr = static_cast(buffer); - m_old_protection = static_cast(old_protect); + m_code_ptr = static_cast(buffer); + m_old_protection = static_cast(old_protect); #elif defined(__linux__) || defined(__ANDROID__) || defined(__APPLE__) || defined(__HAIKU__) || defined(__FreeBSD__) if (mprotect(buffer, size, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) return false; if (guard_size > 0) { - u8* guard_at_end = (static_cast(buffer) + size) - guard_size; + uint8_t* guard_at_end = (static_cast(buffer) + size) - guard_size; if (mprotect(buffer, guard_size, PROT_NONE) != 0 || mprotect(guard_at_end, guard_size, PROT_NONE) != 0) return false; } // reasonable default? - m_code_ptr = static_cast(buffer); + m_code_ptr = static_cast(buffer); m_old_protection = PROT_READ | PROT_WRITE; #else m_code_ptr = nullptr; @@ -109,7 +109,7 @@ bool JitCodeBuffer::Initialize(void* buffer, u32 size, u32 far_code_size /* = 0 m_code_size = size - far_code_size - (guard_size * 2); m_code_used = 0; - m_far_code_ptr = static_cast(m_code_ptr) + m_code_size; + m_far_code_ptr = static_cast(m_code_ptr) + m_code_size; m_free_far_code_ptr = m_far_code_ptr; m_far_code_size = far_code_size - guard_size; m_far_code_used = 0; @@ -154,14 +154,14 @@ void JitCodeBuffer::Destroy() m_owns_buffer = false; } -void JitCodeBuffer::ReserveCode(u32 size) +void JitCodeBuffer::ReserveCode(uint32_t size) { m_code_reserve_size += size; m_free_code_ptr += size; m_code_size -= size; } -void JitCodeBuffer::CommitCode(u32 length) +void JitCodeBuffer::CommitCode(uint32_t length) { if (length == 0) return; @@ -175,7 +175,7 @@ void JitCodeBuffer::CommitCode(u32 length) m_code_used += length; } -void JitCodeBuffer::CommitFarCode(u32 length) +void JitCodeBuffer::CommitFarCode(uint32_t length) { if (length == 0) return; @@ -209,10 +209,10 @@ void JitCodeBuffer::Reset() WriteProtect(true); } -void JitCodeBuffer::Align(u32 alignment, u8 padding_value) +void JitCodeBuffer::Align(uint32_t alignment, uint8_t padding_value) { - const u32 num_padding_bytes = - std::min(static_cast(Common::AlignUpPow2(reinterpret_cast(m_free_code_ptr), alignment) - + const uint32_t num_padding_bytes = + std::min(static_cast(Common::AlignUpPow2(reinterpret_cast(m_free_code_ptr), alignment) - reinterpret_cast(m_free_code_ptr)), GetFreeCodeSpace()); std::memset(m_free_code_ptr, padding_value, num_padding_bytes); @@ -220,7 +220,7 @@ void JitCodeBuffer::Align(u32 alignment, u8 padding_value) m_code_used += num_padding_bytes; } -void JitCodeBuffer::FlushInstructionCache(void* address, u32 size) +void JitCodeBuffer::FlushInstructionCache(void* address, uint32_t size) { #if defined(_WIN32) ::FlushInstructionCache(GetCurrentProcess(), address, size); diff --git a/src/common/jit_code_buffer.h b/src/common/jit_code_buffer.h index 0fd06b05..73ad5b04 100644 --- a/src/common/jit_code_buffer.h +++ b/src/common/jit_code_buffer.h @@ -9,29 +9,29 @@ public: bool IsValid() const { return (m_code_ptr != nullptr); } - bool Allocate(u32 size = 64 * 1024 * 1024, u32 far_code_size = 0); - bool Initialize(void* buffer, u32 size, u32 far_code_size = 0, u32 guard_size = 0); + bool Allocate(uint32_t size = 64 * 1024 * 1024, uint32_t far_code_size = 0); + bool Initialize(void* buffer, uint32_t size, uint32_t far_code_size = 0, uint32_t guard_size = 0); void Destroy(); void Reset(); - ALWAYS_INLINE u8* GetCodePointer() const { return m_code_ptr; } - ALWAYS_INLINE u32 GetTotalSize() const { return m_total_size; } + ALWAYS_INLINE uint8_t* GetCodePointer() const { return m_code_ptr; } + ALWAYS_INLINE uint32_t GetTotalSize() const { return m_total_size; } - ALWAYS_INLINE u8* GetFreeCodePointer() const { return m_free_code_ptr; } - ALWAYS_INLINE u32 GetFreeCodeSpace() const { return static_cast(m_code_size - m_code_used); } - void ReserveCode(u32 size); - void CommitCode(u32 length); + ALWAYS_INLINE uint8_t* GetFreeCodePointer() const { return m_free_code_ptr; } + ALWAYS_INLINE uint32_t GetFreeCodeSpace() const { return static_cast(m_code_size - m_code_used); } + void ReserveCode(uint32_t size); + void CommitCode(uint32_t length); - ALWAYS_INLINE u8* GetFreeFarCodePointer() const { return m_free_far_code_ptr; } - ALWAYS_INLINE u32 GetFreeFarCodeSpace() const { return static_cast(m_far_code_size - m_far_code_used); } - void CommitFarCode(u32 length); + ALWAYS_INLINE uint8_t* GetFreeFarCodePointer() const { return m_free_far_code_ptr; } + ALWAYS_INLINE uint32_t GetFreeFarCodeSpace() const { return static_cast(m_far_code_size - m_far_code_used); } + void CommitFarCode(uint32_t length); /// Adjusts the free code pointer to the specified alignment, padding with bytes. /// Assumes alignment is a power-of-two. - void Align(u32 alignment, u8 padding_value); + void Align(uint32_t alignment, uint8_t padding_value); /// Flushes the instruction cache on the host for the specified range. - static void FlushInstructionCache(void* address, u32 size); + static void FlushInstructionCache(void* address, uint32_t size); /// For Apple Silicon - Toggles write protection on the JIT space. #if defined(__APPLE__) && defined(__aarch64__) @@ -41,19 +41,19 @@ public: #endif private: - u8* m_code_ptr = nullptr; - u8* m_free_code_ptr = nullptr; - u32 m_code_size = 0; - u32 m_code_reserve_size = 0; - u32 m_code_used = 0; + uint8_t* m_code_ptr = nullptr; + uint8_t* m_free_code_ptr = nullptr; + uint32_t m_code_size = 0; + uint32_t m_code_reserve_size = 0; + uint32_t m_code_used = 0; - u8* m_far_code_ptr = nullptr; - u8* m_free_far_code_ptr = nullptr; - u32 m_far_code_size = 0; - u32 m_far_code_used = 0; + uint8_t* m_far_code_ptr = nullptr; + uint8_t* m_free_far_code_ptr = nullptr; + uint32_t m_far_code_size = 0; + uint32_t m_far_code_used = 0; - u32 m_total_size = 0; - u32 m_guard_size = 0; - u32 m_old_protection = 0; + uint32_t m_total_size = 0; + uint32_t m_guard_size = 0; + uint32_t m_old_protection = 0; bool m_owns_buffer = false; }; diff --git a/src/common/log.cpp b/src/common/log.cpp index 5ffacddc..2eb9b8fb 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -80,9 +80,9 @@ void Writev(const char* channelName, const char* functionName, LogLevel level, c va_copy(apCopy, ap); #ifdef _WIN32 - u32 requiredSize = static_cast(_vscprintf(format, apCopy)); + uint32_t requiredSize = static_cast(_vscprintf(format, apCopy)); #else - u32 requiredSize = std::vsnprintf(nullptr, 0, format, apCopy); + uint32_t requiredSize = std::vsnprintf(nullptr, 0, format, apCopy); #endif va_end(apCopy); diff --git a/src/common/log.h b/src/common/log.h index 9df5cf80..99526e6c 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -3,7 +3,7 @@ #include #include -enum class LogLevel : u8 +enum class LogLevel : uint8_t { None = 0, // Silences all log traffic Error = 1, // "ErrorPrint" diff --git a/src/common/md5_digest.cpp b/src/common/md5_digest.cpp index 2127f9fe..c09409c7 100644 --- a/src/common/md5_digest.cpp +++ b/src/common/md5_digest.cpp @@ -22,11 +22,11 @@ */ static void byteReverse(unsigned char* buf, unsigned longs) { - u32 t; + uint32_t t; do { - t = (u32)((unsigned)buf[3] << 8 | buf[2]) << 16 | ((unsigned)buf[1] << 8 | buf[0]); - *(u32*)buf = t; + t = (uint32_t)((unsigned)buf[3] << 8 | buf[2]) << 16 | ((unsigned)buf[1] << 8 | buf[0]); + *(uint32_t*)buf = t; buf += 4; } while (--longs); } @@ -48,10 +48,10 @@ static void byteReverse(unsigned char* buf, unsigned longs) * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -static void MD5Transform(u32 buf[4], u32 in[16]) +static void MD5Transform(uint32_t buf[4], uint32_t in[16]) { - // register u32 a, b, c, d; - u32 a, b, c, d; + // register uint32_t a, b, c, d; + uint32_t a, b, c, d; a = buf[0]; b = buf[1]; @@ -148,15 +148,15 @@ void MD5Digest::Reset() this->bits[1] = 0; } -void MD5Digest::Update(const void* pData, u32 cbData) +void MD5Digest::Update(const void* pData, uint32_t cbData) { - u32 t; - const u8* pByteData = reinterpret_cast(pData); + uint32_t t; + const uint8_t* pByteData = reinterpret_cast(pData); /* Update bitcount */ t = this->bits[0]; - if ((this->bits[0] = t + ((u32)cbData << 3)) < t) + if ((this->bits[0] = t + ((uint32_t)cbData << 3)) < t) this->bits[1]++; /* Carry from low to high */ this->bits[1] += cbData >> 29; @@ -166,7 +166,7 @@ void MD5Digest::Update(const void* pData, u32 cbData) if (t) { - u8* p = (u8*)this->in + t; + uint8_t* p = (uint8_t*)this->in + t; t = 64 - t; if (cbData < t) @@ -176,7 +176,7 @@ void MD5Digest::Update(const void* pData, u32 cbData) } std::memcpy(p, pByteData, t); byteReverse(this->in, 16); - MD5Transform(this->buf, (u32*)this->in); + MD5Transform(this->buf, (uint32_t*)this->in); pByteData += t; cbData -= t; } @@ -186,7 +186,7 @@ void MD5Digest::Update(const void* pData, u32 cbData) { std::memcpy(this->in, pByteData, 64); byteReverse(this->in, 16); - MD5Transform(this->buf, (u32*)this->in); + MD5Transform(this->buf, (uint32_t*)this->in); pByteData += 64; cbData -= 64; } @@ -196,10 +196,10 @@ void MD5Digest::Update(const void* pData, u32 cbData) std::memcpy(this->in, pByteData, cbData); } -void MD5Digest::Final(u8 Digest[16]) +void MD5Digest::Final(uint8_t Digest[16]) { - u32 count; - u8* p; + uint32_t count; + uint8_t* p; /* Compute number of bytes mod 64 */ count = (this->bits[0] >> 3) & 0x3F; @@ -218,7 +218,7 @@ void MD5Digest::Final(u8 Digest[16]) /* Two lots of padding: Pad the first block to 64 bytes */ std::memset(p, 0, count); byteReverse(this->in, 16); - MD5Transform(this->buf, (u32*)this->in); + MD5Transform(this->buf, (uint32_t*)this->in); /* Now fill the next block with 56 bytes */ std::memset(this->in, 0, 56); @@ -231,10 +231,10 @@ void MD5Digest::Final(u8 Digest[16]) byteReverse(this->in, 14); /* Append length in bits and transform */ - ((u32*)this->in)[14] = this->bits[0]; - ((u32*)this->in)[15] = this->bits[1]; + ((uint32_t*)this->in)[14] = this->bits[0]; + ((uint32_t*)this->in)[15] = this->bits[1]; - MD5Transform(this->buf, (u32*)this->in); + MD5Transform(this->buf, (uint32_t*)this->in); byteReverse((unsigned char*)this->buf, 4); std::memcpy(Digest, this->buf, 16); } diff --git a/src/common/md5_digest.h b/src/common/md5_digest.h index 3ff5a473..427cdda9 100644 --- a/src/common/md5_digest.h +++ b/src/common/md5_digest.h @@ -9,12 +9,12 @@ class MD5Digest public: MD5Digest(); - void Update(const void* pData, u32 cbData); - void Final(u8 Digest[16]); + void Update(const void* pData, uint32_t cbData); + void Final(uint8_t Digest[16]); void Reset(); private: - u32 buf[4]; - u32 bits[2]; - u8 in[64]; + uint32_t buf[4]; + uint32_t bits[2]; + uint8_t in[64]; }; diff --git a/src/common/memory_arena.cpp b/src/common/memory_arena.cpp index 8c085f8b..e152428c 100644 --- a/src/common/memory_arena.cpp +++ b/src/common/memory_arena.cpp @@ -127,7 +127,7 @@ bool MemoryArena::Create(size_t size, bool writable, bool executable) #if defined(_WIN32) const DWORD protect = (writable ? (executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE) : PAGE_READONLY); - m_file_handle = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, protect, static_cast(size >> 16 >> 16), static_cast(size), + m_file_handle = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, protect, static_cast(size >> 16 >> 16), static_cast(size), file_mapping_name.c_str()); if (!m_file_handle) { @@ -250,7 +250,7 @@ void* MemoryArena::CreateViewPtr(size_t offset, size_t size, bool writable, bool #if defined(_WIN32) const DWORD desired_access = FILE_MAP_READ | (writable ? FILE_MAP_WRITE : 0) | (executable ? FILE_MAP_EXECUTE : 0); base_pointer = - MapViewOfFileEx(m_file_handle, desired_access, static_cast(offset >> 16 >> 16), static_cast(offset), size, fixed_address); + MapViewOfFileEx(m_file_handle, desired_access, static_cast(offset >> 16 >> 16), static_cast(offset), size, fixed_address); if (!base_pointer) return nullptr; #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) diff --git a/src/common/page_fault_handler.cpp b/src/common/page_fault_handler.cpp index df877a42..f977a333 100644 --- a/src/common/page_fault_handler.cpp +++ b/src/common/page_fault_handler.cpp @@ -27,7 +27,7 @@ struct RegisteredHandler Callback callback; const void* owner; void* start_pc; - u32 code_size; + uint32_t code_size; }; static std::vector m_handlers; static std::mutex m_handler_lock; @@ -36,7 +36,7 @@ static thread_local bool s_in_handler; #if defined(CPU_AARCH32) static bool IsStoreInstruction(const void* ptr) { - u32 bits; + uint32_t bits; std::memcpy(&bits, ptr, sizeof(bits)); // TODO @@ -46,7 +46,7 @@ static bool IsStoreInstruction(const void* ptr) #elif defined(CPU_AARCH64) static bool IsStoreInstruction(const void* ptr) { - u32 bits; + uint32_t bits; std::memcpy(&bits, ptr, sizeof(bits)); // Based on vixl's disassembler Instruction::IsStore(). @@ -116,7 +116,7 @@ static LONG ExceptionHandler(PEXCEPTION_POINTERS exi) return EXCEPTION_CONTINUE_SEARCH; } -u32 GetHandlerCodeSize() +uint32_t GetHandlerCodeSize() { return 0; } @@ -211,21 +211,21 @@ static void SIGSEGVHandler(int sig, siginfo_t* info, void* ctx) sa.sa_handler(sig); } -u32 GetHandlerCodeSize() +uint32_t GetHandlerCodeSize() { return 0; } #else -u32 GetHandlerCodeSize() +uint32_t GetHandlerCodeSize() { return 0; } #endif -bool InstallHandler(const void* owner, void* start_pc, u32 code_size, Callback callback) +bool InstallHandler(const void* owner, void* start_pc, uint32_t code_size, Callback callback) { bool was_empty; { diff --git a/src/common/page_fault_handler.h b/src/common/page_fault_handler.h index f4b57b23..61ce1f8d 100644 --- a/src/common/page_fault_handler.h +++ b/src/common/page_fault_handler.h @@ -11,9 +11,9 @@ enum class HandlerResult using Callback = HandlerResult (*)(void* exception_pc, void* fault_address, bool is_write); using Handle = void*; -u32 GetHandlerCodeSize(); +uint32_t GetHandlerCodeSize(); -bool InstallHandler(const void* owner, void* start_pc, u32 code_size, Callback callback); +bool InstallHandler(const void* owner, void* start_pc, uint32_t code_size, Callback callback); bool RemoveHandler(const void* owner); } // namespace Common::PageFaultHandler diff --git a/src/common/pbp_types.h b/src/common/pbp_types.h index 56148a5d..98603e0c 100644 --- a/src/common/pbp_types.h +++ b/src/common/pbp_types.h @@ -7,7 +7,7 @@ namespace PBP { -inline constexpr u32 PBP_HEADER_OFFSET_COUNT = 8u, TOC_NUM_ENTRIES = 102u, BLOCK_TABLE_NUM_ENTRIES = 32256u, +inline constexpr uint32_t PBP_HEADER_OFFSET_COUNT = 8u, TOC_NUM_ENTRIES = 102u, BLOCK_TABLE_NUM_ENTRIES = 32256u, DISC_TABLE_NUM_ENTRIES = 5u, DECOMPRESSED_BLOCK_SIZE = 37632u; // 2352 bytes per sector * 16 sectors per block @@ -15,72 +15,72 @@ inline constexpr u32 PBP_HEADER_OFFSET_COUNT = 8u, TOC_NUM_ENTRIES = 102u, BLOCK struct PBPHeader { - u8 magic[4]; // "\0PBP" - u32 version; + uint8_t magic[4]; // "\0PBP" + uint32_t version; union { - u32 offsets[PBP_HEADER_OFFSET_COUNT]; + uint32_t offsets[PBP_HEADER_OFFSET_COUNT]; struct { - u32 param_sfo_offset; // 0x00000028 - u32 icon0_png_offset; - u32 icon1_png_offset; - u32 pic0_png_offset; - u32 pic1_png_offset; - u32 snd0_at3_offset; - u32 data_psp_offset; - u32 data_psar_offset; + uint32_t param_sfo_offset; // 0x00000028 + uint32_t icon0_png_offset; + uint32_t icon1_png_offset; + uint32_t pic0_png_offset; + uint32_t pic1_png_offset; + uint32_t snd0_at3_offset; + uint32_t data_psp_offset; + uint32_t data_psar_offset; }; }; }; struct SFOHeader { - u8 magic[4]; // "\0PSF" - u32 version; - u32 key_table_offset; // Relative to start of SFOHeader, 0x000000A4 expected - u32 data_table_offset; // Relative to start of SFOHeader, 0x00000100 expected - u32 num_table_entries; // 0x00000009 + uint8_t magic[4]; // "\0PSF" + uint32_t version; + uint32_t key_table_offset; // Relative to start of SFOHeader, 0x000000A4 expected + uint32_t data_table_offset; // Relative to start of SFOHeader, 0x00000100 expected + uint32_t num_table_entries; // 0x00000009 }; struct SFOIndexTableEntry { - u16 key_offset; // Relative to key_table_offset - u16 data_type; - u32 data_size; // Size of actual data in bytes - u32 data_total_size; // Size of data field in bytes, data_total_size >= data_size - u32 data_offset; // Relative to data_table_offset + uint16_t key_offset; // Relative to key_table_offset + uint16_t data_type; + uint32_t data_size; // Size of actual data in bytes + uint32_t data_total_size; // Size of data field in bytes, data_total_size >= data_size + uint32_t data_offset; // Relative to data_table_offset }; using SFOIndexTable = std::vector; -using SFOTableDataValue = std::variant; +using SFOTableDataValue = std::variant; using SFOTable = std::map; struct BlockTableEntry { - u32 offset; - u16 size; - u16 marker; - u8 checksum[0x10]; - u64 padding; + uint32_t offset; + uint16_t size; + uint16_t marker; + uint8_t checksum[0x10]; + uint64_t padding; }; struct TOCEntry { struct Timecode { - u8 m; - u8 s; - u8 f; + uint8_t m; + uint8_t s; + uint8_t f; }; - u8 type; - u8 unknown; - u8 point; + uint8_t type; + uint8_t unknown; + uint8_t point; Timecode pregap_start; - u8 zero; + uint8_t zero; Timecode userdata_start; }; diff --git a/src/common/progress_callback.cpp b/src/common/progress_callback.cpp index 4ec32f00..597edbbf 100644 --- a/src/common/progress_callback.cpp +++ b/src/common/progress_callback.cpp @@ -104,8 +104,8 @@ void ProgressCallback::DisplayFormattedModalInformation(const char* format, ...) void ProgressCallback::UpdateProgressFromStream(ByteStream* pStream) { - u32 streamSize = (u32)pStream->GetSize(); - u32 streamPosition = (u32)pStream->GetPosition(); + uint32_t streamSize = (uint32_t)pStream->GetSize(); + uint32_t streamPosition = (uint32_t)pStream->GetPosition(); SetProgressRange(streamSize); SetProgressValue(streamPosition); @@ -123,8 +123,8 @@ public: void SetCancellable(bool cancellable) override {} void SetTitle(const char* title) override {} void SetStatusText(const char* statusText) override {} - void SetProgressRange(u32 range) override {} - void SetProgressValue(u32 value) override {} + void SetProgressRange(uint32_t range) override {} + void SetProgressValue(uint32_t value) override {} void IncrementProgressValue() override {} void DisplayError(const char* message) override { Log_ErrorPrint(message); } @@ -179,9 +179,9 @@ void BaseProgressCallback::PopState() m_saved_state = nullptr; // impose the current position into the previous range - const u32 new_progress_value = + const uint32_t new_progress_value = (m_progress_range != 0) ? - static_cast(((float)m_progress_value / (float)m_progress_range) * (float)state->progress_range) : + static_cast(((float)m_progress_value / (float)m_progress_range) * (float)state->progress_range) : state->progress_value; m_cancellable = state->cancellable; @@ -214,7 +214,7 @@ void BaseProgressCallback::SetStatusText(const char* text) m_status_text = text; } -void BaseProgressCallback::SetProgressRange(u32 range) +void BaseProgressCallback::SetProgressRange(uint32_t range) { if (m_saved_state) { @@ -230,7 +230,7 @@ void BaseProgressCallback::SetProgressRange(u32 range) } } -void BaseProgressCallback::SetProgressValue(u32 value) +void BaseProgressCallback::SetProgressValue(uint32_t value) { m_progress_value = m_base_progress_value + value; } diff --git a/src/common/progress_callback.h b/src/common/progress_callback.h index be1f6450..250c56a9 100644 --- a/src/common/progress_callback.h +++ b/src/common/progress_callback.h @@ -19,8 +19,8 @@ public: virtual void SetTitle(const char* title) = 0; virtual void SetStatusText(const char* text) = 0; - virtual void SetProgressRange(u32 range) = 0; - virtual void SetProgressValue(u32 value) = 0; + virtual void SetProgressRange(uint32_t range) = 0; + virtual void SetProgressValue(uint32_t value) = 0; virtual void IncrementProgressValue() = 0; void SetFormattedStatusText(const char* Format, ...) printflike(2, 3); @@ -62,8 +62,8 @@ public: virtual void SetCancellable(bool cancellable) override; virtual void SetStatusText(const char* text) override; - virtual void SetProgressRange(u32 range) override; - virtual void SetProgressValue(u32 value) override; + virtual void SetProgressRange(uint32_t range) override; + virtual void SetProgressValue(uint32_t value) override; virtual void IncrementProgressValue() override; protected: @@ -71,19 +71,19 @@ protected: { State* next_saved_state; String status_text; - u32 progress_range; - u32 progress_value; - u32 base_progress_value; + uint32_t progress_range; + uint32_t progress_value; + uint32_t base_progress_value; bool cancellable; }; bool m_cancellable; bool m_cancelled; String m_status_text; - u32 m_progress_range; - u32 m_progress_value; + uint32_t m_progress_range; + uint32_t m_progress_value; - u32 m_base_progress_value; + uint32_t m_base_progress_value; State* m_saved_state; }; diff --git a/src/common/state_wrapper.cpp b/src/common/state_wrapper.cpp index ef9439e8..106470ad 100644 --- a/src/common/state_wrapper.cpp +++ b/src/common/state_wrapper.cpp @@ -5,7 +5,7 @@ #include Log_SetChannel(StateWrapper); -StateWrapper::StateWrapper(ByteStream* stream, Mode mode, u32 version) +StateWrapper::StateWrapper(ByteStream* stream, Mode mode, uint32_t version) : m_stream(stream), m_mode(mode), m_version(version) { } @@ -16,13 +16,13 @@ void StateWrapper::DoBytes(void* data, size_t length) { if (m_mode == Mode::Read) { - if (m_error || (m_error |= !m_stream->Read2(data, static_cast(length))) == true) + if (m_error || (m_error |= !m_stream->Read2(data, static_cast(length))) == true) std::memset(data, 0, length); } else { if (!m_error) - m_error |= !m_stream->Write2(data, static_cast(length)); + m_error |= !m_stream->Write2(data, static_cast(length)); } } @@ -30,14 +30,14 @@ void StateWrapper::Do(bool* value_ptr) { if (m_mode == Mode::Read) { - u8 value = 0; + uint8_t value = 0; if (!m_error) m_error |= !m_stream->ReadByte(&value); *value_ptr = (value != 0); } else { - u8 value = static_cast(*value_ptr); + uint8_t value = static_cast(*value_ptr); if (!m_error) m_error |= !m_stream->WriteByte(value); } @@ -45,7 +45,7 @@ void StateWrapper::Do(bool* value_ptr) void StateWrapper::Do(std::string* value_ptr) { - u32 length = static_cast(value_ptr->length()); + uint32_t length = static_cast(value_ptr->length()); Do(&length); if (m_mode == Mode::Read) value_ptr->resize(length); @@ -55,7 +55,7 @@ void StateWrapper::Do(std::string* value_ptr) void StateWrapper::Do(String* value_ptr) { - u32 length = static_cast(value_ptr->GetLength()); + uint32_t length = static_cast(value_ptr->GetLength()); Do(&length); if (m_mode == Mode::Read) value_ptr->Resize(length); diff --git a/src/common/state_wrapper.h b/src/common/state_wrapper.h index 8a72e349..8f96165e 100644 --- a/src/common/state_wrapper.h +++ b/src/common/state_wrapper.h @@ -20,7 +20,7 @@ public: Write }; - StateWrapper(ByteStream* stream, Mode mode, u32 version); + StateWrapper(ByteStream* stream, Mode mode, uint32_t version); StateWrapper(const StateWrapper&) = delete; ~StateWrapper(); @@ -29,7 +29,7 @@ public: bool IsWriting() const { return (m_mode == Mode::Write); } Mode GetMode() const { return m_mode; } void SetMode(Mode mode) { m_mode = mode; } - u32 GetVersion() const { return m_version; } + uint32_t GetVersion() const { return m_version; } /// Overload for integral or floating-point types. Writes bytes as-is. template || std::is_floating_point_v, int> = 0> @@ -113,7 +113,7 @@ public: template void Do(std::vector* data) { - u32 length = static_cast(data->size()); + uint32_t length = static_cast(data->size()); Do(&length); if (m_mode == Mode::Read) data->resize(length); @@ -123,12 +123,12 @@ public: template void Do(std::deque* data) { - u32 length = static_cast(data->size()); + uint32_t length = static_cast(data->size()); Do(&length); if (m_mode == Mode::Read) { data->clear(); - for (u32 i = 0; i < length; i++) + for (uint32_t i = 0; i < length; i++) { T value; Do(&value); @@ -137,15 +137,15 @@ public: } else { - for (u32 i = 0; i < length; i++) + for (uint32_t i = 0; i < length; i++) Do(&data[i]); } } - template + template void Do(FIFOQueue* data) { - u32 size = data->GetSize(); + uint32_t size = data->GetSize(); Do(&size); if (m_mode == Mode::Read) @@ -158,7 +158,7 @@ public: } else { - for (u32 i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) { T temp(data->Peek(i)); Do(&temp); @@ -169,7 +169,7 @@ public: bool DoMarker(const char* marker); template - void DoEx(T* data, u32 version_introduced, T default_value) + void DoEx(T* data, uint32_t version_introduced, T default_value) { if (m_version < version_introduced) { @@ -183,6 +183,6 @@ public: private: ByteStream* m_stream; Mode m_mode; - u32 m_version; + uint32_t m_version; bool m_error = false; }; diff --git a/src/common/string.cpp b/src/common/string.cpp index 4f1c7473..3b3128e3 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -13,7 +13,7 @@ const String::StringData String::s_EmptyStringData = {const_cast(""), 0, 1, -1, true}; // helper functions -static String::StringData* StringDataAllocate(u32 allocSize) +static String::StringData* StringDataAllocate(uint32_t allocSize) { String::StringData* pStringData = reinterpret_cast(std::malloc(sizeof(String::StringData) + allocSize)); @@ -40,17 +40,17 @@ static inline void StringDataRelease(String::StringData* pStringData) if (pStringData->ReferenceCount == -1) return; - u32 newRefCount = --pStringData->ReferenceCount; + uint32_t newRefCount = --pStringData->ReferenceCount; if (!newRefCount) std::free(pStringData); } -static String::StringData* StringDataClone(const String::StringData* pStringData, u32 newSize, bool copyPastString) +static String::StringData* StringDataClone(const String::StringData* pStringData, uint32_t newSize, bool copyPastString) { String::StringData* pClone = StringDataAllocate(newSize); if (pStringData->StringLength > 0) { - u32 copyLength; + uint32_t copyLength; if (copyPastString) { @@ -78,7 +78,7 @@ static String::StringData* StringDataClone(const String::StringData* pStringData return pClone; } -static String::StringData* StringDataReallocate(String::StringData* pStringData, u32 newSize) +static String::StringData* StringDataReallocate(String::StringData* pStringData, uint32_t newSize) { // perform realloc pStringData = reinterpret_cast(std::realloc(pStringData, sizeof(String::StringData) + newSize)); @@ -88,7 +88,7 @@ static String::StringData* StringDataReallocate(String::StringData* pStringData, #ifdef _DEBUG if (newSize > pStringData->BufferSize) { - u32 bytesToZero = newSize - pStringData->BufferSize; + uint32_t bytesToZero = newSize - pStringData->BufferSize; std::memset(pStringData->pBuffer + (newSize - bytesToZero), 0, bytesToZero); } #else @@ -140,7 +140,7 @@ String::String(const char* Text) : m_pStringData(const_cast Assign(Text); } -String::String(const char* Text, u32 Count) : m_pStringData(const_cast(&s_EmptyStringData)) +String::String(const char* Text, uint32_t Count) : m_pStringData(const_cast(&s_EmptyStringData)) { AppendString(Text, Count); } @@ -152,7 +152,7 @@ String::String(String&& moveString) String::String(const std::string_view& sv) { - AppendString(sv.data(), static_cast(sv.size())); + AppendString(sv.data(), static_cast(sv.size())); } String::~String() @@ -170,10 +170,10 @@ void String::EnsureOwnWritableCopy() } } -void String::EnsureRemainingSpace(u32 spaceRequired) +void String::EnsureRemainingSpace(uint32_t spaceRequired) { StringData* pNewStringData; - u32 requiredReserve = m_pStringData->StringLength + spaceRequired + 1; + uint32_t requiredReserve = m_pStringData->StringLength + spaceRequired + 1; if (StringDataIsShared(m_pStringData) || m_pStringData->ReadOnly) { @@ -183,7 +183,7 @@ void String::EnsureRemainingSpace(u32 spaceRequired) } else if (m_pStringData->BufferSize < requiredReserve) { - u32 newSize = std::max(requiredReserve, m_pStringData->BufferSize * 2); + uint32_t newSize = std::max(requiredReserve, m_pStringData->BufferSize * 2); // if we are the only owner of the buffer, we can simply realloc it if (m_pStringData->ReferenceCount == 1) @@ -201,7 +201,7 @@ void String::EnsureRemainingSpace(u32 spaceRequired) } } -void String::InternalAppend(const char* pString, u32 Length) +void String::InternalAppend(const char* pString, uint32_t Length) { EnsureRemainingSpace(Length); @@ -218,12 +218,12 @@ void String::AppendString(const String& appendStr) void String::AppendString(const char* appendText) { - u32 textLength = static_cast(std::strlen(appendText)); + uint32_t textLength = static_cast(std::strlen(appendText)); if (textLength > 0) InternalAppend(appendText, textLength); } -void String::AppendString(const char* appendString, u32 Count) +void String::AppendString(const char* appendString, uint32_t Count) { if (Count > 0) InternalAppend(appendString, Count); @@ -232,13 +232,13 @@ void String::AppendString(const char* appendString, u32 Count) void String::AppendString(const std::string& appendString) { if (!appendString.empty()) - InternalAppend(appendString.c_str(), static_cast(appendString.size())); + InternalAppend(appendString.c_str(), static_cast(appendString.size())); } void String::AppendString(const std::string_view& appendString) { if (!appendString.empty()) - InternalAppend(appendString.data(), static_cast(appendString.size())); + InternalAppend(appendString.data(), static_cast(appendString.size())); } void String::Format(const char* FormatString, ...) @@ -259,8 +259,8 @@ void String::FormatVA(const char* FormatString, std::va_list ArgPtr) char stackBuffer[1024]; char* pHeapBuffer = NULL; char* pBuffer = stackBuffer; - u32 currentBufferSize = countof(stackBuffer); - u32 charsWritten; + uint32_t currentBufferSize = countof(stackBuffer); + uint32_t charsWritten; for (;;) { @@ -268,14 +268,14 @@ void String::FormatVA(const char* FormatString, std::va_list ArgPtr) va_copy(ArgPtrCopy, ArgPtr); int ret = std::vsnprintf(pBuffer, currentBufferSize, FormatString, ArgPtrCopy); va_end(ArgPtrCopy); - if (ret < 0 || ((u32)ret >= (currentBufferSize - 1))) + if (ret < 0 || ((uint32_t)ret >= (currentBufferSize - 1))) { currentBufferSize *= 2; pBuffer = pHeapBuffer = reinterpret_cast(std::realloc(pHeapBuffer, currentBufferSize)); continue; } - charsWritten = (u32)ret; + charsWritten = (uint32_t)ret; break; } @@ -323,13 +323,13 @@ void String::Assign(String&& moveString) void String::Assign(const std::string& copyString) { Clear(); - AppendString(copyString.data(), static_cast(copyString.size())); + AppendString(copyString.data(), static_cast(copyString.size())); } void String::Assign(const std::string_view& copyString) { Clear(); - AppendString(copyString.data(), static_cast(copyString.size())); + AppendString(copyString.data(), static_cast(copyString.size())); } bool String::Compare(const String& otherString) const @@ -344,7 +344,7 @@ bool String::Compare(const char* otherText) const bool String::StartsWith(const char* compareString, bool caseSensitive /*= true*/) const { - u32 compareStringLength = static_cast(std::strlen(compareString)); + uint32_t compareStringLength = static_cast(std::strlen(compareString)); if (compareStringLength > m_pStringData->StringLength) return false; @@ -354,7 +354,7 @@ bool String::StartsWith(const char* compareString, bool caseSensitive /*= true*/ bool String::StartsWith(const String& compareString, bool caseSensitive /*= true*/) const { - u32 compareStringLength = compareString.GetLength(); + uint32_t compareStringLength = compareString.GetLength(); if (compareStringLength > m_pStringData->StringLength) return false; @@ -365,11 +365,11 @@ bool String::StartsWith(const String& compareString, bool caseSensitive /*= true bool String::EndsWith(const char* compareString, bool caseSensitive /*= true*/) const { - u32 compareStringLength = static_cast(std::strlen(compareString)); + uint32_t compareStringLength = static_cast(std::strlen(compareString)); if (compareStringLength > m_pStringData->StringLength) return false; - u32 startOffset = m_pStringData->StringLength - compareStringLength; + uint32_t startOffset = m_pStringData->StringLength - compareStringLength; return (caseSensitive) ? (std::strncmp(compareString, m_pStringData->pBuffer + startOffset, compareStringLength) == 0) : (CASE_N_COMPARE(compareString, m_pStringData->pBuffer + startOffset, compareStringLength) == 0); @@ -377,11 +377,11 @@ bool String::EndsWith(const char* compareString, bool caseSensitive /*= true*/) bool String::EndsWith(const String& compareString, bool caseSensitive /*= true*/) const { - u32 compareStringLength = compareString.GetLength(); + uint32_t compareStringLength = compareString.GetLength(); if (compareStringLength > m_pStringData->StringLength) return false; - u32 startOffset = m_pStringData->StringLength - compareStringLength; + uint32_t startOffset = m_pStringData->StringLength - compareStringLength; return (caseSensitive) ? (std::strncmp(compareString.m_pStringData->pBuffer, m_pStringData->pBuffer + startOffset, compareStringLength) == 0) : (CASE_N_COMPARE(compareString.m_pStringData->pBuffer, m_pStringData->pBuffer + startOffset, @@ -415,9 +415,9 @@ void String::Clear() // Internal: ensure the buffer can hold at least newReserve characters plus the // terminator. Only used by Replace below. -static void StringReserve(String::StringData*& pStringData, u32 newReserve) +static void StringReserve(String::StringData*& pStringData, uint32_t newReserve) { - u32 newSize = std::max(newReserve + 1, pStringData->BufferSize); + uint32_t newSize = std::max(newReserve + 1, pStringData->BufferSize); String::StringData* pNewStringData; if (StringDataIsShared(pStringData) || pStringData->ReadOnly) @@ -448,7 +448,7 @@ static void StringReserve(String::StringData*& pStringData, u32 newReserve) } } -void String::Resize(u32 newSize, char fillerCharacter /* = ' ' */) +void String::Resize(uint32_t newSize, char fillerCharacter /* = ' ' */) { StringData* pNewStringData; @@ -483,13 +483,13 @@ void String::Resize(u32 newSize, char fillerCharacter /* = ' ' */) void String::UpdateSize() { EnsureOwnWritableCopy(); - m_pStringData->StringLength = static_cast(std::strlen(m_pStringData->pBuffer)); + m_pStringData->StringLength = static_cast(std::strlen(m_pStringData->pBuffer)); } -u32 String::Replace(const char* searchString, const char* replaceString) +uint32_t String::Replace(const char* searchString, const char* replaceString) { - u32 nReplacements = 0; - u32 searchStringLength = static_cast(std::strlen(searchString)); + uint32_t nReplacements = 0; + uint32_t searchStringLength = static_cast(std::strlen(searchString)); // TODO: Fastpath if strlen(searchString) == strlen(replaceString) @@ -503,7 +503,7 @@ u32 String::Replace(const char* searchString, const char* replaceString) StringReserve(tempString.m_pStringData, m_pStringData->StringLength); // append [pStart, pCurrent) range from this string into tempString - u32 chunkLen = static_cast(pCurrent - pStart); + uint32_t chunkLen = static_cast(pCurrent - pStart); if (chunkLen > 0) tempString.InternalAppend(pStart, chunkLen); tempString.AppendString(replaceString); @@ -517,7 +517,7 @@ u32 String::Replace(const char* searchString, const char* replaceString) if (pLast != NULL) { // append remainder [pStart, end) into tempString - u32 remainLen = m_pStringData->StringLength - static_cast(pStart - m_pStringData->pBuffer); + uint32_t remainLen = m_pStringData->StringLength - static_cast(pStart - m_pStringData->pBuffer); if (remainLen > 0) tempString.InternalAppend(pStart, remainLen); } diff --git a/src/common/string.h b/src/common/string.h index d49187c5..832a721c 100644 --- a/src/common/string.h +++ b/src/common/string.h @@ -21,15 +21,15 @@ public: char* pBuffer; // Length of the string located in pBuffer (in characters) - u32 StringLength; + uint32_t StringLength; // Size of the buffer pointed to by pBuffer - u32 BufferSize; + uint32_t BufferSize; // Reference count of this data object. If set to -1, // it is considered noncopyable and any copies of the string // will always create their own copy. - s32 ReferenceCount; + int32_t ReferenceCount; // Whether the memory pointed to by pBuffer is writable. bool ReadOnly; @@ -45,7 +45,7 @@ public: String(const char* Text); // Creates a string contained the specified text (with length). - String(const char* Text, u32 Count); + String(const char* Text, uint32_t Count); // Creates a string using the same buffer as another string (copy-on-write). String(const String& copyString); @@ -73,7 +73,7 @@ public: void EnsureOwnWritableCopy(); // Ensures that we have our own copy of the buffer, and spaceRequired bytes free in the buffer. - void EnsureRemainingSpace(u32 spaceRequired); + void EnsureRemainingSpace(uint32_t spaceRequired); // clears the contents of the string void Clear(); @@ -81,7 +81,7 @@ public: // append a string to this string void AppendString(const String& appendStr); void AppendString(const char* appendText); - void AppendString(const char* appendString, u32 Count); + void AppendString(const char* appendString, uint32_t Count); void AppendString(const std::string& appendString); void AppendString(const std::string_view& appendString); @@ -100,21 +100,21 @@ public: bool EndsWith(const String& compareString, bool caseSensitive = true) const; // Cuts characters off the string to reduce it to len bytes long. - void Resize(u32 newSize, char fillerCharacter = ' '); + void Resize(uint32_t newSize, char fillerCharacter = ' '); // updates the internal length counter when the string is externally modified void UpdateSize(); // gets the size of the string - u32 GetLength() const { return m_pStringData->StringLength; } + uint32_t GetLength() const { return m_pStringData->StringLength; } bool IsEmpty() const { return (m_pStringData->StringLength == 0); } // gets the maximum number of bytes we can write to the string, currently - u32 GetBufferSize() const { return m_pStringData->BufferSize; } + uint32_t GetBufferSize() const { return m_pStringData->BufferSize; } // replaces all instances of string s with string r in this string // returns the number of changes - u32 Replace(const char* searchString, const char* replaceString); + uint32_t Replace(const char* searchString, const char* replaceString); // gets a constant pointer to the string const char* GetCharArray() const { return m_pStringData->pBuffer; } @@ -170,7 +170,7 @@ public: protected: // Internal append function. - void InternalAppend(const char* pString, u32 Length); + void InternalAppend(const char* pString, uint32_t Length); // Pointer to string data. StringData* m_pStringData; @@ -180,7 +180,7 @@ protected: }; // stack-allocated string -template +template class StackString : public String { public: @@ -192,7 +192,7 @@ public: Assign(Text); } - StackString(const char* Text, u32 Count) : String(&m_sStringData) + StackString(const char* Text, uint32_t Count) : String(&m_sStringData) { InitStackStringData(); AppendString(Text, Count); @@ -215,7 +215,7 @@ public: StackString(const std::string_view& sv) : String(&m_sStringData) { InitStackStringData(); - AppendString(sv.data(), static_cast(sv.size())); + AppendString(sv.data(), static_cast(sv.size())); } // Override the fromstring method diff --git a/src/common/types.h b/src/common/types.h index c1a62476..d0e08913 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -61,29 +61,20 @@ char (&__countof_ArraySizeHelper(T (&array)[N]))[N]; #pragma warning(disable : 4355) // warning C4355: 'this' : used in base member initializer list #endif -using s8 = int8_t; -using u8 = uint8_t; -using s16 = int16_t; -using u16 = uint16_t; -using s32 = int32_t; -using u32 = uint32_t; -using s64 = int64_t; -using u64 = uint64_t; - // BCD helpers -ALWAYS_INLINE constexpr u8 BinaryToBCD(u8 value) +ALWAYS_INLINE constexpr uint8_t BinaryToBCD(uint8_t value) { return ((value / 10) << 4) + (value % 10); } -ALWAYS_INLINE constexpr u8 PackedBCDToBinary(u8 value) +ALWAYS_INLINE constexpr uint8_t PackedBCDToBinary(uint8_t value) { return ((value >> 4) * 10) + (value % 16); } -ALWAYS_INLINE constexpr bool IsValidBCDDigit(u8 digit) +ALWAYS_INLINE constexpr bool IsValidBCDDigit(uint8_t digit) { return (digit <= 9); } -ALWAYS_INLINE constexpr bool IsValidPackedBCD(u8 value) +ALWAYS_INLINE constexpr bool IsValidPackedBCD(uint8_t value) { return IsValidBCDDigit(value & 0x0F) && IsValidBCDDigit(value >> 4); } diff --git a/src/common/vulkan/builders.cpp b/src/common/vulkan/builders.cpp index a395f942..c595c7a4 100644 --- a/src/common/vulkan/builders.cpp +++ b/src/common/vulkan/builders.cpp @@ -32,7 +32,7 @@ VkDescriptorSetLayout DescriptorSetLayoutBuilder::Create(VkDevice device) return layout; } -void DescriptorSetLayoutBuilder::AddBinding(u32 binding, VkDescriptorType dtype, u32 dcount, VkShaderStageFlags stages) +void DescriptorSetLayoutBuilder::AddBinding(uint32_t binding, VkDescriptorType dtype, uint32_t dcount, VkShaderStageFlags stages) { VkDescriptorSetLayoutBinding& b = m_bindings[m_ci.bindingCount]; b.binding = binding; @@ -83,7 +83,7 @@ void PipelineLayoutBuilder::AddDescriptorSet(VkDescriptorSetLayout layout) m_ci.pSetLayouts = m_sets.data(); } -void PipelineLayoutBuilder::AddPushConstants(VkShaderStageFlags stages, u32 offset, u32 size) +void PipelineLayoutBuilder::AddPushConstants(VkShaderStageFlags stages, uint32_t offset, uint32_t size) { VkPushConstantRange& r = m_push_constants[m_ci.pushConstantRangeCount]; r.stageFlags = stages; @@ -167,7 +167,7 @@ VkPipeline GraphicsPipelineBuilder::Create(VkDevice device, VkPipelineCache pipe void GraphicsPipelineBuilder::SetShaderStage(VkShaderStageFlagBits stage, VkShaderModule module, const char* entry_point) { - u32 index = 0; + uint32_t index = 0; for (; index < m_ci.stageCount; index++) { if (m_shader_stages[index].stage == stage) @@ -186,7 +186,7 @@ void GraphicsPipelineBuilder::SetShaderStage(VkShaderStageFlagBits stage, VkShad s.pName = entry_point; } -void GraphicsPipelineBuilder::AddVertexBuffer(u32 binding, u32 stride, +void GraphicsPipelineBuilder::AddVertexBuffer(uint32_t binding, uint32_t stride, VkVertexInputRate input_rate /*= VK_VERTEX_INPUT_RATE_VERTEX*/) { VkVertexInputBindingDescription& b = m_vertex_buffers[m_vertex_input_state.vertexBindingDescriptionCount]; @@ -199,7 +199,7 @@ void GraphicsPipelineBuilder::AddVertexBuffer(u32 binding, u32 stride, m_ci.pVertexInputState = &m_vertex_input_state; } -void GraphicsPipelineBuilder::AddVertexAttribute(u32 location, u32 binding, VkFormat format, u32 offset) +void GraphicsPipelineBuilder::AddVertexAttribute(uint32_t location, uint32_t binding, VkFormat format, uint32_t offset) { VkVertexInputAttributeDescription& a = m_vertex_attributes[m_vertex_input_state.vertexAttributeDescriptionCount]; a.location = location; @@ -236,7 +236,7 @@ void GraphicsPipelineBuilder::SetLineWidth(float width) m_rasterization_state.lineWidth = width; } -void GraphicsPipelineBuilder::SetMultisamples(u32 multisamples, bool per_sample_shading) +void GraphicsPipelineBuilder::SetMultisamples(uint32_t multisamples, bool per_sample_shading) { m_multisample_state.rasterizationSamples = static_cast(multisamples); m_multisample_state.sampleShadingEnable = per_sample_shading; @@ -291,7 +291,7 @@ void GraphicsPipelineBuilder::AddBlendAttachment( } void GraphicsPipelineBuilder::SetBlendAttachment( - u32 attachment, bool blend_enable, VkBlendFactor src_factor, VkBlendFactor dst_factor, VkBlendOp op, + uint32_t attachment, bool blend_enable, VkBlendFactor src_factor, VkBlendFactor dst_factor, VkBlendOp op, VkBlendFactor alpha_src_factor, VkBlendFactor alpha_dst_factor, VkBlendOp alpha_op, VkColorComponentFlags write_mask /*= VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT*/) { VkPipelineColorBlendAttachmentState& bs = m_blend_attachments[attachment]; @@ -355,7 +355,7 @@ void GraphicsPipelineBuilder::SetViewport(float x, float y, float width, float h m_ci.pViewportState = &m_viewport_state; } -void GraphicsPipelineBuilder::SetScissorRect(s32 x, s32 y, u32 width, u32 height) +void GraphicsPipelineBuilder::SetScissorRect(int32_t x, int32_t y, uint32_t width, uint32_t height) { m_scissor.offset.x = x; m_scissor.offset.y = y; @@ -378,7 +378,7 @@ void GraphicsPipelineBuilder::SetPipelineLayout(VkPipelineLayout layout) m_ci.layout = layout; } -void GraphicsPipelineBuilder::SetRenderPass(VkRenderPass render_pass, u32 subpass) +void GraphicsPipelineBuilder::SetRenderPass(VkRenderPass render_pass, uint32_t subpass) { m_ci.renderPass = render_pass; m_ci.subpass = subpass; @@ -464,7 +464,7 @@ void DescriptorSetUpdateBuilder::Update(VkDevice device, bool clear /*= true*/) } void DescriptorSetUpdateBuilder::AddImageDescriptorWrite( - VkDescriptorSet set, u32 binding, VkImageView view, + VkDescriptorSet set, uint32_t binding, VkImageView view, VkImageLayout layout /*= VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL*/) { VkDescriptorImageInfo& ii = m_infos[m_num_infos++].image; @@ -481,7 +481,7 @@ void DescriptorSetUpdateBuilder::AddImageDescriptorWrite( dw.pImageInfo = ⅈ } -void DescriptorSetUpdateBuilder::AddSamplerDescriptorWrite(VkDescriptorSet set, u32 binding, VkSampler sampler) +void DescriptorSetUpdateBuilder::AddSamplerDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkSampler sampler) { VkDescriptorImageInfo& ii = m_infos[m_num_infos++].image; ii.imageView = VK_NULL_HANDLE; @@ -498,7 +498,7 @@ void DescriptorSetUpdateBuilder::AddSamplerDescriptorWrite(VkDescriptorSet set, } void DescriptorSetUpdateBuilder::AddCombinedImageSamplerDescriptorWrite( - VkDescriptorSet set, u32 binding, VkImageView view, VkSampler sampler, + VkDescriptorSet set, uint32_t binding, VkImageView view, VkSampler sampler, VkImageLayout layout /*= VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL*/) { VkDescriptorImageInfo& ii = m_infos[m_num_infos++].image; @@ -515,8 +515,8 @@ void DescriptorSetUpdateBuilder::AddCombinedImageSamplerDescriptorWrite( dw.pImageInfo = ⅈ } -void DescriptorSetUpdateBuilder::AddBufferDescriptorWrite(VkDescriptorSet set, u32 binding, VkDescriptorType dtype, - VkBuffer buffer, u32 offset, u32 size) +void DescriptorSetUpdateBuilder::AddBufferDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkDescriptorType dtype, + VkBuffer buffer, uint32_t offset, uint32_t size) { VkDescriptorBufferInfo& bi = m_infos[m_num_infos++].buffer; bi.buffer = buffer; @@ -532,7 +532,7 @@ void DescriptorSetUpdateBuilder::AddBufferDescriptorWrite(VkDescriptorSet set, u dw.pBufferInfo = &bi; } -void DescriptorSetUpdateBuilder::AddBufferViewDescriptorWrite(VkDescriptorSet set, u32 binding, VkDescriptorType dtype, +void DescriptorSetUpdateBuilder::AddBufferViewDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkDescriptorType dtype, VkBufferView view) { VkBufferView& bi = m_infos[m_num_infos++].buffer_view; @@ -583,7 +583,7 @@ void FramebufferBuilder::AddAttachment(VkImageView image) m_ci.pAttachments = m_images.data(); } -void FramebufferBuilder::SetSize(u32 width, u32 height, u32 layers) +void FramebufferBuilder::SetSize(uint32_t width, uint32_t height, uint32_t layers) { m_ci.width = width; m_ci.height = height; @@ -620,7 +620,7 @@ VkBufferView BufferViewBuilder::Create(VkDevice device, bool clear /*= true*/) return bv; } -void BufferViewBuilder::Set(VkBuffer buffer, VkFormat format, u32 offset, u32 size) +void BufferViewBuilder::Set(VkBuffer buffer, VkFormat format, uint32_t offset, uint32_t size) { m_ci.buffer = buffer; m_ci.format = format; diff --git a/src/common/vulkan/builders.h b/src/common/vulkan/builders.h index 2c5a27af..aedb1567 100644 --- a/src/common/vulkan/builders.h +++ b/src/common/vulkan/builders.h @@ -8,7 +8,7 @@ namespace Vulkan { class DescriptorSetLayoutBuilder { public: - static constexpr u32 MAX_BINDINGS = 16; + static constexpr uint32_t MAX_BINDINGS = 16; DescriptorSetLayoutBuilder(); @@ -16,7 +16,7 @@ public: VkDescriptorSetLayout Create(VkDevice device); - void AddBinding(u32 binding, VkDescriptorType dtype, u32 dcount, VkShaderStageFlags stages); + void AddBinding(uint32_t binding, VkDescriptorType dtype, uint32_t dcount, VkShaderStageFlags stages); private: VkDescriptorSetLayoutCreateInfo m_ci{}; @@ -26,7 +26,7 @@ private: class PipelineLayoutBuilder { public: - static constexpr u32 MAX_SETS = 8, MAX_PUSH_CONSTANTS = 1; + static constexpr uint32_t MAX_SETS = 8, MAX_PUSH_CONSTANTS = 1; PipelineLayoutBuilder(); @@ -36,7 +36,7 @@ public: void AddDescriptorSet(VkDescriptorSetLayout layout); - void AddPushConstants(VkShaderStageFlags stages, u32 offset, u32 size); + void AddPushConstants(VkShaderStageFlags stages, uint32_t offset, uint32_t size); private: VkPipelineLayoutCreateInfo m_ci{}; @@ -47,7 +47,7 @@ private: class GraphicsPipelineBuilder { public: - static constexpr u32 MAX_SHADER_STAGES = 3, MAX_VERTEX_ATTRIBUTES = 16, MAX_VERTEX_BUFFERS = 8, MAX_ATTACHMENTS = 2, + static constexpr uint32_t MAX_SHADER_STAGES = 3, MAX_VERTEX_ATTRIBUTES = 16, MAX_VERTEX_BUFFERS = 8, MAX_ATTACHMENTS = 2, MAX_DYNAMIC_STATE = 8; GraphicsPipelineBuilder(); @@ -61,14 +61,14 @@ public: void SetGeometryShader(VkShaderModule module) { SetShaderStage(VK_SHADER_STAGE_GEOMETRY_BIT, module, "main"); } void SetFragmentShader(VkShaderModule module) { SetShaderStage(VK_SHADER_STAGE_FRAGMENT_BIT, module, "main"); } - void AddVertexBuffer(u32 binding, u32 stride, VkVertexInputRate input_rate = VK_VERTEX_INPUT_RATE_VERTEX); - void AddVertexAttribute(u32 location, u32 binding, VkFormat format, u32 offset); + void AddVertexBuffer(uint32_t binding, uint32_t stride, VkVertexInputRate input_rate = VK_VERTEX_INPUT_RATE_VERTEX); + void AddVertexAttribute(uint32_t location, uint32_t binding, VkFormat format, uint32_t offset); void SetPrimitiveTopology(VkPrimitiveTopology topology, bool enable_primitive_restart = false); void SetRasterizationState(VkPolygonMode polygon_mode, VkCullModeFlags cull_mode, VkFrontFace front_face); void SetLineWidth(float width); - void SetMultisamples(u32 multisamples, bool per_sample_shading); + void SetMultisamples(uint32_t multisamples, bool per_sample_shading); void SetNoCullRasterizationState(); void SetDepthState(bool depth_test, bool depth_write, VkCompareOp compare_op); @@ -78,7 +78,7 @@ public: VkBlendFactor alpha_src_factor, VkBlendFactor alpha_dst_factor, VkBlendOp alpha_op, VkColorComponentFlags write_mask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT); - void SetBlendAttachment(u32 attachment, bool blend_enable, VkBlendFactor src_factor, VkBlendFactor dst_factor, + void SetBlendAttachment(uint32_t attachment, bool blend_enable, VkBlendFactor src_factor, VkBlendFactor dst_factor, VkBlendOp op, VkBlendFactor alpha_src_factor, VkBlendFactor alpha_dst_factor, VkBlendOp alpha_op, VkColorComponentFlags write_mask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | @@ -92,12 +92,12 @@ public: void SetDynamicViewportAndScissorState(); void SetViewport(float x, float y, float width, float height, float min_depth, float max_depth); - void SetScissorRect(s32 x, s32 y, u32 width, u32 height); + void SetScissorRect(int32_t x, int32_t y, uint32_t width, uint32_t height); void SetMultisamples(VkSampleCountFlagBits samples); void SetPipelineLayout(VkPipelineLayout layout); - void SetRenderPass(VkRenderPass render_pass, u32 subpass); + void SetRenderPass(VkRenderPass render_pass, uint32_t subpass); private: VkGraphicsPipelineCreateInfo m_ci; @@ -146,7 +146,7 @@ private: class DescriptorSetUpdateBuilder { - static constexpr u32 MAX_WRITES = 16, MAX_INFOS = 16; + static constexpr uint32_t MAX_WRITES = 16, MAX_INFOS = 16; public: DescriptorSetUpdateBuilder(); @@ -155,14 +155,14 @@ public: void Update(VkDevice device, bool clear = true); - void AddImageDescriptorWrite(VkDescriptorSet set, u32 binding, VkImageView view, + void AddImageDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkImageView view, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - void AddSamplerDescriptorWrite(VkDescriptorSet set, u32 binding, VkSampler sampler); - void AddCombinedImageSamplerDescriptorWrite(VkDescriptorSet set, u32 binding, VkImageView view, VkSampler sampler, + void AddSamplerDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkSampler sampler); + void AddCombinedImageSamplerDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkImageView view, VkSampler sampler, VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - void AddBufferDescriptorWrite(VkDescriptorSet set, u32 binding, VkDescriptorType dtype, VkBuffer buffer, u32 offset, - u32 size); - void AddBufferViewDescriptorWrite(VkDescriptorSet set, u32 binding, VkDescriptorType dtype, VkBufferView view); + void AddBufferDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkDescriptorType dtype, VkBuffer buffer, uint32_t offset, + uint32_t size); + void AddBufferViewDescriptorWrite(VkDescriptorSet set, uint32_t binding, VkDescriptorType dtype, VkBufferView view); private: union InfoUnion @@ -173,15 +173,15 @@ private: }; std::array m_writes; - u32 m_num_writes = 0; + uint32_t m_num_writes = 0; std::array m_infos; - u32 m_num_infos = 0; + uint32_t m_num_infos = 0; }; class FramebufferBuilder { - static constexpr u32 MAX_ATTACHMENTS = 2; + static constexpr uint32_t MAX_ATTACHMENTS = 2; public: FramebufferBuilder(); @@ -192,7 +192,7 @@ public: void AddAttachment(VkImageView image); - void SetSize(u32 width, u32 height, u32 layers); + void SetSize(uint32_t width, uint32_t height, uint32_t layers); void SetRenderPass(VkRenderPass render_pass); @@ -210,7 +210,7 @@ public: VkBufferView Create(VkDevice device, bool clear = true); - void Set(VkBuffer buffer, VkFormat format, u32 offset, u32 size); + void Set(VkBuffer buffer, VkFormat format, uint32_t offset, uint32_t size); private: VkBufferViewCreateInfo m_ci; diff --git a/src/common/vulkan/context.cpp b/src/common/vulkan/context.cpp index 5bda1c3e..a3e0adb2 100644 --- a/src/common/vulkan/context.cpp +++ b/src/common/vulkan/context.cpp @@ -59,7 +59,7 @@ Context::~Context() Context::GPUList Context::EnumerateGPUs(VkInstance instance) { - u32 gpu_count = 0; + uint32_t gpu_count = 0; VkResult res = vkEnumeratePhysicalDevices(instance, &gpu_count, nullptr); if (res != VK_SUCCESS || gpu_count == 0) { @@ -83,9 +83,9 @@ Context::GPUList Context::EnumerateGPUs(VkInstance instance) bool Context::CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface, bool take_ownership, bool enable_validation_layer, bool enable_debug_utils, const char** required_device_extensions /* = nullptr */, - u32 num_required_device_extensions /* = 0 */, + uint32_t num_required_device_extensions /* = 0 */, const char** required_device_layers /* = nullptr */, - u32 num_required_device_layers /* = 0 */, + uint32_t num_required_device_layers /* = 0 */, const VkPhysicalDeviceFeatures* required_features /* = nullptr */) { g_vulkan_context.reset(new Context(instance, gpu, take_ownership)); @@ -114,7 +114,7 @@ void Context::Destroy() bool Context::SelectDeviceExtensions(ExtensionList* extension_list, bool enable_surface) { - u32 extension_count = 0; + uint32_t extension_count = 0; VkResult res = vkEnumerateDeviceExtensionProperties(m_physical_device, nullptr, &extension_count, nullptr); if (res != VK_SUCCESS) { @@ -178,10 +178,10 @@ bool Context::SelectDeviceFeatures(const VkPhysicalDeviceFeatures* required_feat } bool Context::CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer, const char** required_device_extensions, - u32 num_required_device_extensions, const char** required_device_layers, - u32 num_required_device_layers, const VkPhysicalDeviceFeatures* required_features) + uint32_t num_required_device_extensions, const char** required_device_layers, + uint32_t num_required_device_layers, const VkPhysicalDeviceFeatures* required_features) { - u32 queue_family_count; + uint32_t queue_family_count; vkGetPhysicalDeviceQueueFamilyProperties(m_physical_device, &queue_family_count, nullptr); if (queue_family_count == 0) { @@ -277,7 +277,7 @@ bool Context::CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer, c device_info.pQueueCreateInfos = queue_infos.data(); ExtensionList enabled_extensions; - for (u32 i = 0; i < num_required_device_extensions; i++) + for (uint32_t i = 0; i < num_required_device_extensions; i++) enabled_extensions.emplace_back(required_device_extensions[i]); if (!SelectDeviceExtensions(&enabled_extensions, surface != VK_NULL_HANDLE)) return false; @@ -367,7 +367,7 @@ bool Context::CreateCommandBuffers() nullptr, 0, 1024, // TODO: tweak this - static_cast(countof(pool_sizes)), + static_cast(countof(pool_sizes)), pool_sizes}; res = vkCreateDescriptorPool(m_device, &pool_create_info, nullptr, &resources.descriptor_pool); @@ -426,7 +426,7 @@ bool Context::CreateGlobalDescriptorPool() nullptr, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1024, // TODO: tweak this - static_cast(countof(pool_sizes)), + static_cast(countof(pool_sizes)), pool_sizes}; VkResult res = vkCreateDescriptorPool(m_device, &pool_create_info, nullptr, &m_global_descriptor_pool); @@ -490,13 +490,13 @@ void Context::FreeGlobalDescriptorSet(VkDescriptorSet set) vkFreeDescriptorSets(m_device, m_global_descriptor_pool, 1, &set); } -void Context::WaitForFenceCounter(u64 fence_counter) +void Context::WaitForFenceCounter(uint64_t fence_counter) { if (m_completed_fence_counter >= fence_counter) return; // Find the first command buffer which covers this counter value. - u32 index = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; + uint32_t index = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; while (index != m_current_frame) { if (m_frame_resources[index].fence_counter >= fence_counter) @@ -513,7 +513,7 @@ void Context::WaitForGPUIdle() vkDeviceWaitIdle(m_device); } -void Context::WaitForCommandBufferCompletion(u32 index) +void Context::WaitForCommandBufferCompletion(uint32_t index) { // Wait for this command buffer to be completed. VkResult res = vkWaitForFences(m_device, 1, &m_frame_resources[index].fence, VK_TRUE, UINT64_MAX); @@ -522,8 +522,8 @@ void Context::WaitForCommandBufferCompletion(u32 index) // Clean up any resources for command buffers between the last known completed buffer and this // now-completed command buffer. If we use >2 buffers, this may be more than one buffer. - const u64 now_completed_counter = m_frame_resources[index].fence_counter; - u32 cleanup_index = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; + const uint64_t now_completed_counter = m_frame_resources[index].fence_counter; + uint32_t cleanup_index = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; while (cleanup_index != m_current_frame) { FrameResources& resources = m_frame_resources[cleanup_index]; @@ -563,7 +563,7 @@ void Context::SubmitCommandBuffer(VkSemaphore wait_semaphore /* = VK_NULL_HANDLE DoSubmitCommandBuffer(m_current_frame, wait_semaphore, signal_semaphore); } -void Context::DoSubmitCommandBuffer(u32 index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore) +void Context::DoSubmitCommandBuffer(uint32_t index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore) { FrameResources& resources = m_frame_resources[index]; @@ -595,7 +595,7 @@ void Context::MoveToNextCommandBuffer() ActivateCommandBuffer((m_current_frame + 1) % NUM_COMMAND_BUFFERS); } -void Context::ActivateCommandBuffer(u32 index) +void Context::ActivateCommandBuffer(uint32_t index) { FrameResources& resources = m_frame_resources[index]; @@ -633,7 +633,7 @@ void Context::ActivateCommandBuffer(u32 index) void Context::ExecuteCommandBuffer(bool wait_for_completion) { // If we're waiting for completion, don't bother waking the worker thread. - const u32 current_frame = m_current_frame; + const uint32_t current_frame = m_current_frame; SubmitCommandBuffer(); MoveToNextCommandBuffer(); if (wait_for_completion) @@ -744,13 +744,13 @@ void Context::DisableDebugUtils() } } -bool Context::GetMemoryType(u32 bits, VkMemoryPropertyFlags properties, u32* out_type_index) +bool Context::GetMemoryType(uint32_t bits, VkMemoryPropertyFlags properties, uint32_t* out_type_index) { - for (u32 i = 0; i < VK_MAX_MEMORY_TYPES; i++) + for (uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; i++) { if ((bits & (1 << i)) != 0) { - u32 supported = m_device_memory_properties.memoryTypes[i].propertyFlags & properties; + uint32_t supported = m_device_memory_properties.memoryTypes[i].propertyFlags & properties; if (supported == properties) { *out_type_index = i; @@ -762,9 +762,9 @@ bool Context::GetMemoryType(u32 bits, VkMemoryPropertyFlags properties, u32* out return false; } -u32 Context::GetMemoryType(u32 bits, VkMemoryPropertyFlags properties) +uint32_t Context::GetMemoryType(uint32_t bits, VkMemoryPropertyFlags properties) { - u32 type_index = VK_MAX_MEMORY_TYPES; + uint32_t type_index = VK_MAX_MEMORY_TYPES; if (!GetMemoryType(bits, properties, &type_index)) { Log_ErrorPrintf("Unable to find memory type for %x:%x", bits, properties); @@ -773,12 +773,12 @@ u32 Context::GetMemoryType(u32 bits, VkMemoryPropertyFlags properties) return type_index; } -u32 Context::GetUploadMemoryType(u32 bits, bool* is_coherent) +uint32_t Context::GetUploadMemoryType(uint32_t bits, bool* is_coherent) { // Try for coherent memory first. VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - u32 type_index; + uint32_t type_index; if (!GetMemoryType(bits, flags, &type_index)) { Log_WarningPrintf("Vulkan: Failed to find a coherent memory type for uploads, this will affect performance."); @@ -798,13 +798,13 @@ u32 Context::GetUploadMemoryType(u32 bits, bool* is_coherent) return type_index; } -u32 Context::GetReadbackMemoryType(u32 bits, bool* is_coherent, bool* is_cached) +uint32_t Context::GetReadbackMemoryType(uint32_t bits, bool* is_coherent, bool* is_cached) { // Try for cached and coherent memory first. VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - u32 type_index; + uint32_t type_index; if (!GetMemoryType(bits, flags, &type_index)) { // For readbacks, caching is more important than coherency. @@ -843,7 +843,7 @@ VkRenderPass Context::GetRenderPass(VkFormat color_format, VkFormat depth_format VkAttachmentReference depth_reference; VkAttachmentReference* depth_reference_ptr = nullptr; std::array attachments; - u32 num_attachments = 0; + uint32_t num_attachments = 0; if (color_format != VK_FORMAT_UNDEFINED) { attachments[num_attachments] = {0, diff --git a/src/common/vulkan/context.h b/src/common/vulkan/context.h index 70420db3..2ab54843 100644 --- a/src/common/vulkan/context.h +++ b/src/common/vulkan/context.h @@ -19,7 +19,7 @@ namespace Vulkan { class Context { public: - static constexpr u32 NUM_COMMAND_BUFFERS = 2; + static constexpr uint32_t NUM_COMMAND_BUFFERS = 2; ~Context(); @@ -31,9 +31,9 @@ public: static bool CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface, bool take_ownership, bool enable_validation_layer, bool enable_debug_utils, const char** required_device_extensions = nullptr, - u32 num_required_device_extensions = 0, + uint32_t num_required_device_extensions = 0, const char** required_device_layers = nullptr, - u32 num_required_device_layers = 0, + uint32_t num_required_device_layers = 0, const VkPhysicalDeviceFeatures* required_features = nullptr); // Destroys context. @@ -48,9 +48,9 @@ public: ALWAYS_INLINE VkPhysicalDevice GetPhysicalDevice() const { return m_physical_device; } ALWAYS_INLINE VkDevice GetDevice() const { return m_device; } ALWAYS_INLINE VkQueue GetGraphicsQueue() const { return m_graphics_queue; } - ALWAYS_INLINE u32 GetGraphicsQueueFamilyIndex() const { return m_graphics_queue_family_index; } + ALWAYS_INLINE uint32_t GetGraphicsQueueFamilyIndex() const { return m_graphics_queue_family_index; } ALWAYS_INLINE VkQueue GetPresentQueue() const { return m_present_queue; } - ALWAYS_INLINE u32 GetPresentQueueFamilyIndex() const { return m_present_queue_family_index; } + ALWAYS_INLINE uint32_t GetPresentQueueFamilyIndex() const { return m_present_queue_family_index; } ALWAYS_INLINE const VkQueueFamilyProperties& GetGraphicsQueueProperties() const { return m_graphics_queue_properties; @@ -87,12 +87,12 @@ public: // Finds a memory type index for the specified memory properties and the bits returned by // vkGetImageMemoryRequirements - bool GetMemoryType(u32 bits, VkMemoryPropertyFlags properties, u32* out_type_index); - u32 GetMemoryType(u32 bits, VkMemoryPropertyFlags properties); + bool GetMemoryType(uint32_t bits, VkMemoryPropertyFlags properties, uint32_t* out_type_index); + uint32_t GetMemoryType(uint32_t bits, VkMemoryPropertyFlags properties); // Finds a memory type for upload or readback buffers. - u32 GetUploadMemoryType(u32 bits, bool* is_coherent = nullptr); - u32 GetReadbackMemoryType(u32 bits, bool* is_coherent = nullptr, bool* is_cached = nullptr); + uint32_t GetUploadMemoryType(uint32_t bits, bool* is_coherent = nullptr); + uint32_t GetReadbackMemoryType(uint32_t bits, bool* is_coherent = nullptr, bool* is_cached = nullptr); // Creates a simple render pass. VkRenderPass GetRenderPass(VkFormat color_format, VkFormat depth_format, VkSampleCountFlagBits samples, @@ -124,11 +124,11 @@ public: // If the last completed fence counter is greater or equal to N, it means that the work // associated counter N has been completed by the GPU. The value of N to associate with // commands can be retreived by calling GetCurrentFenceCounter(). - u64 GetCompletedFenceCounter() const { return m_completed_fence_counter; } + uint64_t GetCompletedFenceCounter() const { return m_completed_fence_counter; } // Gets the fence that will be signaled when the currently executing command buffer is // queued and executed. Do not wait for this fence before the buffer is executed. - u64 GetCurrentFenceCounter() const { return m_frame_resources[m_current_frame].fence_counter; } + uint64_t GetCurrentFenceCounter() const { return m_frame_resources[m_current_frame].fence_counter; } void SubmitCommandBuffer(VkSemaphore wait_semaphore = VK_NULL_HANDLE, VkSemaphore signal_semaphore = VK_NULL_HANDLE, VkSwapchainKHR present_swap_chain = VK_NULL_HANDLE, @@ -149,7 +149,7 @@ public: // Wait for a fence to be completed. // Also invokes callbacks for completion. - void WaitForFenceCounter(u64 fence_counter); + void WaitForFenceCounter(uint64_t fence_counter); void WaitForGPUIdle(); @@ -160,8 +160,8 @@ private: bool SelectDeviceExtensions(ExtensionList* extension_list, bool enable_surface); bool SelectDeviceFeatures(const VkPhysicalDeviceFeatures* required_features); bool CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer, const char** required_device_extensions, - u32 num_required_device_extensions, const char** required_device_layers, - u32 num_required_device_layers, const VkPhysicalDeviceFeatures* required_features); + uint32_t num_required_device_extensions, const char** required_device_layers, + uint32_t num_required_device_layers, const VkPhysicalDeviceFeatures* required_features); bool CreateCommandBuffers(); void DestroyCommandBuffers(); @@ -169,10 +169,10 @@ private: void DestroyGlobalDescriptorPool(); void DestroyRenderPassCache(); - void ActivateCommandBuffer(u32 index); - void WaitForCommandBufferCompletion(u32 index); + void ActivateCommandBuffer(uint32_t index); + void WaitForCommandBufferCompletion(uint32_t index); - void DoSubmitCommandBuffer(u32 index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore); + void DoSubmitCommandBuffer(uint32_t index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore); struct FrameResources { @@ -181,7 +181,7 @@ private: VkCommandBuffer command_buffer = VK_NULL_HANDLE; VkDescriptorPool descriptor_pool = VK_NULL_HANDLE; VkFence fence = VK_NULL_HANDLE; - u64 fence_counter = 0; + uint64_t fence_counter = 0; bool needs_fence_wait = false; std::vector> cleanup_resources; @@ -196,14 +196,14 @@ private: VkDescriptorPool m_global_descriptor_pool = VK_NULL_HANDLE; VkQueue m_graphics_queue = VK_NULL_HANDLE; - u32 m_graphics_queue_family_index = 0; + uint32_t m_graphics_queue_family_index = 0; VkQueue m_present_queue = VK_NULL_HANDLE; - u32 m_present_queue_family_index = 0; + uint32_t m_present_queue_family_index = 0; std::array m_frame_resources; - u64 m_next_fence_counter = 1; - u64 m_completed_fence_counter = 0; - u32 m_current_frame; + uint64_t m_next_fence_counter = 1; + uint64_t m_completed_fence_counter = 0; + uint32_t m_current_frame; bool m_owns_device = false; diff --git a/src/common/vulkan/shader_cache.cpp b/src/common/vulkan/shader_cache.cpp index 83390527..7954ddfa 100644 --- a/src/common/vulkan/shader_cache.cpp +++ b/src/common/vulkan/shader_cache.cpp @@ -22,21 +22,21 @@ using ShaderCompiler::SPIRVCodeVector; #pragma pack(push, 4) struct VK_PIPELINE_CACHE_HEADER { - u32 header_length; - u32 header_version; - u32 vendor_id; - u32 device_id; - u8 uuid[VK_UUID_SIZE]; + uint32_t header_length; + uint32_t header_version; + uint32_t vendor_id; + uint32_t device_id; + uint8_t uuid[VK_UUID_SIZE]; }; struct CacheIndexEntry { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; - u32 shader_type; - u32 file_offset; - u32 blob_size; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; + uint32_t shader_type; + uint32_t file_offset; + uint32_t blob_size; }; #pragma pack(pop) @@ -107,7 +107,7 @@ bool ShaderCache::CacheIndexKey::operator!=(const CacheIndexKey& key) const source_length != key.source_length || shader_type != key.shader_type); } -void ShaderCache::Create(std::string_view base_path, u32 version, bool debug) +void ShaderCache::Create(std::string_view base_path, uint32_t version, bool debug) { g_vulkan_shader_cache.reset(new ShaderCache()); g_vulkan_shader_cache->Open(base_path, version, debug); @@ -118,7 +118,7 @@ void ShaderCache::Destroy() g_vulkan_shader_cache.reset(); } -void ShaderCache::Open(std::string_view base_path, u32 version, bool debug) +void ShaderCache::Open(std::string_view base_path, uint32_t version, bool debug) { m_version = version; m_debug = debug; @@ -172,7 +172,7 @@ bool ShaderCache::CreateNewShaderCache(const std::string& index_filename, const return false; } - const u32 index_version = FILE_VERSION; + const uint32_t index_version = FILE_VERSION; VK_PIPELINE_CACHE_HEADER header; FillPipelineCacheHeader(&header); @@ -206,8 +206,8 @@ bool ShaderCache::ReadExistingShaderCache(const std::string& index_filename, con if (!m_index_file) return false; - u32 file_version = 0; - u32 data_version = 0; + uint32_t file_version = 0; + uint32_t data_version = 0; if (rfread(&file_version, sizeof(file_version), 1, m_index_file) != 1 || file_version != FILE_VERSION || rfread(&data_version, sizeof(data_version), 1, m_index_file) != 1 || data_version != m_version) { @@ -236,7 +236,7 @@ bool ShaderCache::ReadExistingShaderCache(const std::string& index_filename, con } rfseek(m_blob_file, 0, SEEK_END); - const u32 blob_file_size = static_cast(rftell(m_blob_file)); + const uint32_t blob_file_size = static_cast(rftell(m_blob_file)); for (;;) { @@ -305,7 +305,7 @@ bool ShaderCache::CreateNewPipelineCache() bool ShaderCache::ReadExistingPipelineCache() { - std::optional> data = FileSystem::ReadBinaryFile(m_pipeline_cache_filename.c_str()); + std::optional> data = FileSystem::ReadBinaryFile(m_pipeline_cache_filename.c_str()); if (!data.has_value()) return false; @@ -345,7 +345,7 @@ bool ShaderCache::FlushPipelineCache() return false; } - std::vector data(data_size); + std::vector data(data_size); res = vkGetPipelineCacheData(g_vulkan_context->GetDevice(), m_pipeline_cache, &data_size, data.data()); if (res != VK_SUCCESS) { @@ -413,18 +413,18 @@ ShaderCache::CacheIndexKey ShaderCache::GetCacheKey(ShaderCompiler::Type type, c { struct { - u64 hash_low; - u64 hash_high; + uint64_t hash_low; + uint64_t hash_high; }; - u8 hash[16]; + uint8_t hash[16]; }; HashParts h; MD5Digest digest; - digest.Update(shader_code.data(), static_cast(shader_code.length())); + digest.Update(shader_code.data(), static_cast(shader_code.length())); digest.Final(h.hash); - return CacheIndexKey{h.hash_low, h.hash_high, static_cast(shader_code.length()), type}; + return CacheIndexKey{h.hash_low, h.hash_high, static_cast(shader_code.length()), type}; } std::optional ShaderCache::GetShaderSPV(ShaderCompiler::Type type, @@ -487,14 +487,14 @@ std::optional ShaderCache::CompileAndAddShaderS return spv; CacheIndexData data; - data.file_offset = static_cast(rftell(m_blob_file)); - data.blob_size = static_cast(spv->size()); + data.file_offset = static_cast(rftell(m_blob_file)); + data.blob_size = static_cast(spv->size()); CacheIndexEntry entry = {}; entry.source_hash_low = key.source_hash_low; entry.source_hash_high = key.source_hash_high; entry.source_length = key.source_length; - entry.shader_type = static_cast(key.shader_type); + entry.shader_type = static_cast(key.shader_type); entry.blob_size = data.blob_size; entry.file_offset = data.file_offset; diff --git a/src/common/vulkan/shader_cache.h b/src/common/vulkan/shader_cache.h index 13bc90b8..0b3ce96a 100644 --- a/src/common/vulkan/shader_cache.h +++ b/src/common/vulkan/shader_cache.h @@ -19,7 +19,7 @@ class ShaderCache public: ~ShaderCache(); - static void Create(std::string_view base_path, u32 version, bool debug); + static void Create(std::string_view base_path, uint32_t version, bool debug); static void Destroy(); /// Returns a handle to the pipeline cache. Set set_dirty to true if you are planning on writing to it externally. @@ -35,13 +35,13 @@ public: VkShaderModule GetFragmentShader(std::string_view shader_code); private: - static constexpr u32 FILE_VERSION = 2; + static constexpr uint32_t FILE_VERSION = 2; struct CacheIndexKey { - u64 source_hash_low; - u64 source_hash_high; - u32 source_length; + uint64_t source_hash_low; + uint64_t source_hash_high; + uint32_t source_length; ShaderCompiler::Type shader_type; bool operator==(const CacheIndexKey& key) const; @@ -60,8 +60,8 @@ private: struct CacheIndexData { - u32 file_offset; - u32 blob_size; + uint32_t file_offset; + uint32_t blob_size; }; using CacheIndex = std::unordered_map; @@ -72,7 +72,7 @@ private: static std::string GetPipelineCacheBaseFileName(const std::string_view& base_path, bool debug); static CacheIndexKey GetCacheKey(ShaderCompiler::Type type, const std::string_view& shader_code); - void Open(std::string_view base_path, u32 version, bool debug); + void Open(std::string_view base_path, uint32_t version, bool debug); bool CreateNewShaderCache(const std::string& index_filename, const std::string& blob_filename); bool ReadExistingShaderCache(const std::string& index_filename, const std::string& blob_filename); @@ -92,7 +92,7 @@ private: CacheIndex m_index; VkPipelineCache m_pipeline_cache = VK_NULL_HANDLE; - u32 m_version = 0; + uint32_t m_version = 0; bool m_debug = false; bool m_pipeline_cache_dirty = false; }; diff --git a/src/common/vulkan/shader_compiler.h b/src/common/vulkan/shader_compiler.h index adafc9d6..6b50fc6e 100644 --- a/src/common/vulkan/shader_compiler.h +++ b/src/common/vulkan/shader_compiler.h @@ -24,7 +24,7 @@ enum class Type void DeinitializeGlslang(); // SPIR-V compiled code type -using SPIRVCodeType = u32; +using SPIRVCodeType = uint32_t; using SPIRVCodeVector = std::vector; std::optional CompileShader(Type type, std::string_view source_code, bool debug); diff --git a/src/common/vulkan/staging_buffer.cpp b/src/common/vulkan/staging_buffer.cpp index 62747314..29e0fad9 100644 --- a/src/common/vulkan/staging_buffer.cpp +++ b/src/common/vulkan/staging_buffer.cpp @@ -163,7 +163,7 @@ bool StagingBuffer::AllocateBuffer(Type type, VkDeviceSize size, VkBufferUsageFl VkMemoryRequirements requirements; vkGetBufferMemoryRequirements(g_vulkan_context->GetDevice(), *out_buffer, &requirements); - u32 type_index; + uint32_t type_index; if (type == Type::Upload) type_index = g_vulkan_context->GetUploadMemoryType(requirements.memoryTypeBits, out_coherent); else diff --git a/src/common/vulkan/staging_texture.cpp b/src/common/vulkan/staging_texture.cpp index 2f964d2f..f86fc998 100644 --- a/src/common/vulkan/staging_texture.cpp +++ b/src/common/vulkan/staging_texture.cpp @@ -43,11 +43,11 @@ StagingTexture::~StagingTexture() Destroy(true); } -bool StagingTexture::Create(StagingBuffer::Type type, VkFormat format, u32 width, u32 height) +bool StagingTexture::Create(StagingBuffer::Type type, VkFormat format, uint32_t width, uint32_t height) { - const u32 texel_size = Util::GetTexelSize(format); - const u32 map_stride = texel_size * width; - const u32 buffer_size = map_stride * height; + const uint32_t texel_size = Util::GetTexelSize(format); + const uint32_t map_stride = texel_size * width; + const uint32_t buffer_size = map_stride * height; VkBufferUsageFlags usage_flags; switch (type) @@ -92,8 +92,8 @@ void StagingTexture::Destroy(bool defer /* = true */) m_map_stride = 0; } -void StagingTexture::CopyFromTexture(VkCommandBuffer command_buffer, Texture& src_texture, u32 src_x, u32 src_y, - u32 src_layer, u32 src_level, u32 dst_x, u32 dst_y, u32 width, u32 height) +void StagingTexture::CopyFromTexture(VkCommandBuffer command_buffer, Texture& src_texture, uint32_t src_x, uint32_t src_y, + uint32_t src_layer, uint32_t src_level, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height) { VkImageLayout old_layout = src_texture.GetLayout(); src_texture.TransitionToLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); @@ -115,8 +115,8 @@ void StagingTexture::CopyFromTexture(VkCommandBuffer command_buffer, Texture& sr src_texture.TransitionToLayout(command_buffer, old_layout); } -void StagingTexture::CopyFromTexture(Texture& src_texture, u32 src_x, u32 src_y, u32 src_layer, u32 src_level, - u32 dst_x, u32 dst_y, u32 width, u32 height) +void StagingTexture::CopyFromTexture(Texture& src_texture, uint32_t src_x, uint32_t src_y, uint32_t src_layer, uint32_t src_level, + uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height) { CopyFromTexture(g_vulkan_context->GetCurrentCommandBuffer(), src_texture, src_x, src_y, src_layer, src_level, dst_x, dst_y, width, height); @@ -125,8 +125,8 @@ void StagingTexture::CopyFromTexture(Texture& src_texture, u32 src_x, u32 src_y, m_flush_fence_counter = g_vulkan_context->GetCurrentFenceCounter(); } -void StagingTexture::CopyToTexture(VkCommandBuffer command_buffer, u32 src_x, u32 src_y, Texture& dst_texture, - u32 dst_x, u32 dst_y, u32 dst_layer, u32 dst_level, u32 width, u32 height) +void StagingTexture::CopyToTexture(VkCommandBuffer command_buffer, uint32_t src_x, uint32_t src_y, Texture& dst_texture, + uint32_t dst_x, uint32_t dst_y, uint32_t dst_layer, uint32_t dst_level, uint32_t width, uint32_t height) { // Flush caches before copying. m_staging_buffer.FlushCPUCache(); @@ -149,8 +149,8 @@ void StagingTexture::CopyToTexture(VkCommandBuffer command_buffer, u32 src_x, u3 dst_texture.TransitionToLayout(command_buffer, old_layout); } -void StagingTexture::CopyToTexture(u32 src_x, u32 src_y, Texture& dst_texture, u32 dst_x, u32 dst_y, u32 dst_layer, - u32 dst_level, u32 width, u32 height) +void StagingTexture::CopyToTexture(uint32_t src_x, uint32_t src_y, Texture& dst_texture, uint32_t dst_x, uint32_t dst_y, uint32_t dst_layer, + uint32_t dst_level, uint32_t width, uint32_t height) { CopyToTexture(g_vulkan_context->GetCurrentCommandBuffer(), src_x, src_y, dst_texture, dst_x, dst_y, dst_layer, dst_level, width, height); @@ -186,7 +186,7 @@ void StagingTexture::Flush() m_needs_flush = false; } -void StagingTexture::ReadTexels(u32 src_x, u32 src_y, u32 width, u32 height, void* out_ptr, u32 out_stride) +void StagingTexture::ReadTexels(uint32_t src_x, uint32_t src_y, uint32_t width, uint32_t height, void* out_ptr, uint32_t out_stride) { PrepareForAccess(); @@ -202,9 +202,9 @@ void StagingTexture::ReadTexels(u32 src_x, u32 src_y, u32 width, u32 height, voi return; } - size_t copy_size = std::min(width * m_texel_size, m_map_stride); + size_t copy_size = std::min(width * m_texel_size, m_map_stride); char* dst_ptr = reinterpret_cast(out_ptr); - for (u32 row = 0; row < height; row++) + for (uint32_t row = 0; row < height; row++) { std::memcpy(dst_ptr, current_ptr, copy_size); current_ptr += m_map_stride; @@ -212,7 +212,7 @@ void StagingTexture::ReadTexels(u32 src_x, u32 src_y, u32 width, u32 height, voi } } -void StagingTexture::ReadTexel(u32 x, u32 y, void* out_ptr) +void StagingTexture::ReadTexel(uint32_t x, uint32_t y, void* out_ptr) { PrepareForAccess(); @@ -220,7 +220,7 @@ void StagingTexture::ReadTexel(u32 x, u32 y, void* out_ptr) std::memcpy(out_ptr, src_ptr, m_texel_size); } -void StagingTexture::WriteTexels(u32 dst_x, u32 dst_y, u32 width, u32 height, const void* in_ptr, u32 in_stride) +void StagingTexture::WriteTexels(uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height, const void* in_ptr, uint32_t in_stride) { PrepareForAccess(); @@ -236,9 +236,9 @@ void StagingTexture::WriteTexels(u32 dst_x, u32 dst_y, u32 width, u32 height, co return; } - size_t copy_size = std::min(width * m_texel_size, m_map_stride); + size_t copy_size = std::min(width * m_texel_size, m_map_stride); const char* src_ptr = reinterpret_cast(in_ptr); - for (u32 row = 0; row < height; row++) + for (uint32_t row = 0; row < height; row++) { std::memcpy(current_ptr, src_ptr, copy_size); current_ptr += m_map_stride; @@ -246,7 +246,7 @@ void StagingTexture::WriteTexels(u32 dst_x, u32 dst_y, u32 width, u32 height, co } } -void StagingTexture::WriteTexel(u32 x, u32 y, const void* in_ptr) +void StagingTexture::WriteTexel(uint32_t x, uint32_t y, const void* in_ptr) { PrepareForAccess(); diff --git a/src/common/vulkan/staging_texture.h b/src/common/vulkan/staging_texture.h index f2a7b694..37f4ba97 100644 --- a/src/common/vulkan/staging_texture.h +++ b/src/common/vulkan/staging_texture.h @@ -24,26 +24,26 @@ public: ALWAYS_INLINE bool IsMapped() const { return m_staging_buffer.IsMapped(); } ALWAYS_INLINE const char* GetMappedPointer() const { return m_staging_buffer.GetMapPointer(); } ALWAYS_INLINE char* GetMappedPointer() { return m_staging_buffer.GetMapPointer(); } - ALWAYS_INLINE u32 GetMappedStride() const { return m_map_stride; } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetMappedStride() const { return m_map_stride; } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } - bool Create(StagingBuffer::Type type, VkFormat format, u32 width, u32 height); + bool Create(StagingBuffer::Type type, VkFormat format, uint32_t width, uint32_t height); void Destroy(bool defer = true); // Copies from the GPU texture object to the staging texture, which can be mapped/read by the CPU. // Both src_rect and dst_rect must be with within the bounds of the the specified textures. - void CopyFromTexture(VkCommandBuffer command_buffer, Texture& src_texture, u32 src_x, u32 src_y, u32 src_layer, - u32 src_level, u32 dst_x, u32 dst_y, u32 width, u32 height); - void CopyFromTexture(Texture& src_texture, u32 src_x, u32 src_y, u32 src_layer, u32 src_level, u32 dst_x, u32 dst_y, - u32 width, u32 height); + void CopyFromTexture(VkCommandBuffer command_buffer, Texture& src_texture, uint32_t src_x, uint32_t src_y, uint32_t src_layer, + uint32_t src_level, uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height); + void CopyFromTexture(Texture& src_texture, uint32_t src_x, uint32_t src_y, uint32_t src_layer, uint32_t src_level, uint32_t dst_x, uint32_t dst_y, + uint32_t width, uint32_t height); // Wrapper for copying a whole layer of a texture to a readback texture. // Assumes that the level of src texture and this texture have the same dimensions. - void CopyToTexture(VkCommandBuffer command_buffer, u32 src_x, u32 src_y, Texture& dst_texture, u32 dst_x, u32 dst_y, - u32 dst_layer, u32 dst_level, u32 width, u32 height); - void CopyToTexture(u32 src_x, u32 src_y, Texture& dst_texture, u32 dst_x, u32 dst_y, u32 dst_layer, u32 dst_level, - u32 width, u32 height); + void CopyToTexture(VkCommandBuffer command_buffer, uint32_t src_x, uint32_t src_y, Texture& dst_texture, uint32_t dst_x, uint32_t dst_y, + uint32_t dst_layer, uint32_t dst_level, uint32_t width, uint32_t height); + void CopyToTexture(uint32_t src_x, uint32_t src_y, Texture& dst_texture, uint32_t dst_x, uint32_t dst_y, uint32_t dst_layer, uint32_t dst_level, + uint32_t width, uint32_t height); // Flushes pending writes from the CPU to the GPU, and reads from the GPU to the CPU. // This may cause a command buffer flush depending on if one has occurred between the last @@ -53,24 +53,24 @@ public: // Reads the specified rectangle from the staging texture to out_ptr, with the specified stride // (length in bytes of each row). CopyFromTexture must be called first. The contents of any // texels outside of the rectangle used for CopyFromTexture is undefined. - void ReadTexels(u32 src_x, u32 src_y, u32 width, u32 height, void* out_ptr, u32 out_stride); - void ReadTexel(u32 x, u32 y, void* out_ptr); + void ReadTexels(uint32_t src_x, uint32_t src_y, uint32_t width, uint32_t height, void* out_ptr, uint32_t out_stride); + void ReadTexel(uint32_t x, uint32_t y, void* out_ptr); // Copies the texels from in_ptr to the staging texture, which can be read by the GPU, with the // specified stride (length in bytes of each row). After updating the staging texture with all // changes, call CopyToTexture() to update the GPU copy. - void WriteTexels(u32 dst_x, u32 dst_y, u32 width, u32 height, const void* in_ptr, u32 in_stride); - void WriteTexel(u32 x, u32 y, const void* in_ptr); + void WriteTexels(uint32_t dst_x, uint32_t dst_y, uint32_t width, uint32_t height, const void* in_ptr, uint32_t in_stride); + void WriteTexel(uint32_t x, uint32_t y, const void* in_ptr); private: void PrepareForAccess(); StagingBuffer m_staging_buffer; - u64 m_flush_fence_counter = 0; - u32 m_width = 0; - u32 m_height = 0; - u32 m_texel_size = 0; - u32 m_map_stride = 0; + uint64_t m_flush_fence_counter = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + uint32_t m_texel_size = 0; + uint32_t m_map_stride = 0; bool m_needs_flush = false; }; diff --git a/src/common/vulkan/stream_buffer.cpp b/src/common/vulkan/stream_buffer.cpp index 0d87fd24..b8e9d1cc 100644 --- a/src/common/vulkan/stream_buffer.cpp +++ b/src/common/vulkan/stream_buffer.cpp @@ -45,7 +45,7 @@ StreamBuffer& StreamBuffer::operator=(StreamBuffer&& move) return *this; } -bool StreamBuffer::Create(VkBufferUsageFlags usage, u32 size) +bool StreamBuffer::Create(VkBufferUsageFlags usage, uint32_t size) { // Create the buffer descriptor VkBufferCreateInfo buffer_create_info = { @@ -72,7 +72,7 @@ bool StreamBuffer::Create(VkBufferUsageFlags usage, u32 size) vkGetBufferMemoryRequirements(g_vulkan_context->GetDevice(), buffer, &memory_requirements); // Aim for a coherent mapping if possible. - u32 memory_type_index = + uint32_t memory_type_index = g_vulkan_context->GetUploadMemoryType(memory_requirements.memoryTypeBits, &m_coherent_mapping); // Allocate memory for backing this buffer @@ -124,7 +124,7 @@ bool StreamBuffer::Create(VkBufferUsageFlags usage, u32 size) m_size = size; m_buffer = buffer; m_memory = memory; - m_host_pointer = reinterpret_cast(mapped_ptr); + m_host_pointer = reinterpret_cast(mapped_ptr); m_current_offset = 0; m_current_gpu_position = 0; m_tracked_fences.clear(); @@ -157,9 +157,9 @@ void StreamBuffer::Destroy(bool defer) } } -bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) +bool StreamBuffer::ReserveMemory(uint32_t num_bytes, uint32_t alignment) { - const u32 required_bytes = num_bytes + alignment; + const uint32_t required_bytes = num_bytes + alignment; // Check for sane allocations if (required_bytes > m_size) @@ -170,7 +170,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) // Is the GPU behind or up to date with our current offset? if (m_current_offset >= m_current_gpu_position) { - const u32 remaining_bytes = m_size - m_current_offset; + const uint32_t remaining_bytes = m_size - m_current_offset; if (required_bytes <= remaining_bytes) { // Place at the current position, after the GPU position. @@ -196,7 +196,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) if (m_current_offset < m_current_gpu_position) { // We have from m_current_offset..m_current_gpu_position space to use. - const u32 remaining_bytes = m_current_gpu_position - m_current_offset; + const uint32_t remaining_bytes = m_current_gpu_position - m_current_offset; if (required_bytes < remaining_bytes) { // Place at the current position, since this is still behind the GPU. @@ -209,7 +209,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) // Can we find a fence to wait on that will give us enough memory? if (WaitForClearSpace(required_bytes)) { - const u32 align_diff = Common::AlignUp(m_current_offset, alignment) - m_current_offset; + const uint32_t align_diff = Common::AlignUp(m_current_offset, alignment) - m_current_offset; m_current_offset += align_diff; m_current_space -= align_diff; return true; @@ -221,7 +221,7 @@ bool StreamBuffer::ReserveMemory(u32 num_bytes, u32 alignment) return false; } -void StreamBuffer::CommitMemory(u32 final_num_bytes) +void StreamBuffer::CommitMemory(uint32_t final_num_bytes) { // For non-coherent mappings, flush the memory range if (!m_coherent_mapping) @@ -239,7 +239,7 @@ void StreamBuffer::CommitMemory(u32 final_num_bytes) void StreamBuffer::UpdateCurrentFencePosition() { // Has the offset changed since the last fence? - const u64 counter = g_vulkan_context->GetCurrentFenceCounter(); + const uint64_t counter = g_vulkan_context->GetCurrentFenceCounter(); if (!m_tracked_fences.empty() && m_tracked_fences.back().first == counter) { // Still haven't executed a command buffer, so just update the offset. @@ -256,7 +256,7 @@ void StreamBuffer::UpdateGPUPosition() auto start = m_tracked_fences.begin(); auto end = start; - const u64 completed_counter = g_vulkan_context->GetCompletedFenceCounter(); + const uint64_t completed_counter = g_vulkan_context->GetCompletedFenceCounter(); while (end != m_tracked_fences.end() && completed_counter >= end->first) { m_current_gpu_position = end->second; @@ -276,11 +276,11 @@ void StreamBuffer::UpdateGPUPosition() } } -bool StreamBuffer::WaitForClearSpace(u32 num_bytes) +bool StreamBuffer::WaitForClearSpace(uint32_t num_bytes) { - u32 new_offset = 0; - u32 new_space = 0; - u32 new_gpu_position = 0; + uint32_t new_offset = 0; + uint32_t new_space = 0; + uint32_t new_gpu_position = 0; auto iter = m_tracked_fences.begin(); for (; iter != m_tracked_fences.end(); ++iter) @@ -289,7 +289,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) // This is the "last resort" case, where a command buffer execution has been forced // after no additional data has been written to it, so we can assume that after the // fence has been signaled the entire buffer is now consumed. - u32 gpu_position = iter->second; + uint32_t gpu_position = iter->second; if (m_current_offset == gpu_position) { new_offset = 0; @@ -303,7 +303,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) { // This would suggest the GPU has now followed us and wrapped around, so we have from // m_current_position..m_size free, as well as and 0..gpu_position. - const u32 remaining_space_after_offset = m_size - m_current_offset; + const uint32_t remaining_space_after_offset = m_size - m_current_offset; if (remaining_space_after_offset >= num_bytes) { // Switch to allocating in front of the GPU, using the remainder of the buffer. @@ -329,7 +329,7 @@ bool StreamBuffer::WaitForClearSpace(u32 num_bytes) // We're currently allocating behind the GPU. This would give us between the current // offset and the GPU position worth of space to work with. Again, > because we can't // align the GPU position with the buffer offset. - u32 available_space_inbetween = gpu_position - m_current_offset; + uint32_t available_space_inbetween = gpu_position - m_current_offset; if (available_space_inbetween > num_bytes) { // Leave the offset as-is, but update the GPU position. diff --git a/src/common/vulkan/stream_buffer.h b/src/common/vulkan/stream_buffer.h index 4ade5644..1ff141c1 100644 --- a/src/common/vulkan/stream_buffer.h +++ b/src/common/vulkan/stream_buffer.h @@ -27,36 +27,36 @@ public: ALWAYS_INLINE VkBuffer GetBuffer() const { return m_buffer; } ALWAYS_INLINE const VkBuffer* GetBufferPointer() const { return &m_buffer; } ALWAYS_INLINE void* GetCurrentHostPointer() const { return m_host_pointer + m_current_offset; } - ALWAYS_INLINE u32 GetCurrentSize() const { return m_size; } - ALWAYS_INLINE u32 GetCurrentSpace() const { return m_current_space; } - ALWAYS_INLINE u32 GetCurrentOffset() const { return m_current_offset; } + ALWAYS_INLINE uint32_t GetCurrentSize() const { return m_size; } + ALWAYS_INLINE uint32_t GetCurrentSpace() const { return m_current_space; } + ALWAYS_INLINE uint32_t GetCurrentOffset() const { return m_current_offset; } - bool Create(VkBufferUsageFlags usage, u32 size); + bool Create(VkBufferUsageFlags usage, uint32_t size); void Destroy(bool defer); - bool ReserveMemory(u32 num_bytes, u32 alignment); - void CommitMemory(u32 final_num_bytes); + bool ReserveMemory(uint32_t num_bytes, uint32_t alignment); + void CommitMemory(uint32_t final_num_bytes); private: - bool AllocateBuffer(VkBufferUsageFlags usage, u32 size); + bool AllocateBuffer(VkBufferUsageFlags usage, uint32_t size); void UpdateCurrentFencePosition(); void UpdateGPUPosition(); // Waits for as many fences as needed to allocate num_bytes bytes from the buffer. - bool WaitForClearSpace(u32 num_bytes); + bool WaitForClearSpace(uint32_t num_bytes); VkBufferUsageFlags m_usage = 0; - u32 m_size = 0; - u32 m_current_offset = 0; - u32 m_current_space = 0; - u32 m_current_gpu_position = 0; + uint32_t m_size = 0; + uint32_t m_current_offset = 0; + uint32_t m_current_space = 0; + uint32_t m_current_gpu_position = 0; VkBuffer m_buffer = VK_NULL_HANDLE; VkDeviceMemory m_memory = VK_NULL_HANDLE; - u8* m_host_pointer = nullptr; + uint8_t* m_host_pointer = nullptr; // List of fences and the corresponding positions in the buffer - std::deque> m_tracked_fences; + std::deque> m_tracked_fences; bool m_coherent_mapping = false; }; diff --git a/src/common/vulkan/texture.cpp b/src/common/vulkan/texture.cpp index 7c9fdb79..a8690d27 100644 --- a/src/common/vulkan/texture.cpp +++ b/src/common/vulkan/texture.cpp @@ -55,7 +55,7 @@ Vulkan::Texture& Texture::operator=(Texture&& move) return *this; } -bool Texture::Create(u32 width, u32 height, u32 levels, u32 layers, VkFormat format, VkSampleCountFlagBits samples, +bool Texture::Create(uint32_t width, uint32_t height, uint32_t levels, uint32_t layers, VkFormat format, VkSampleCountFlagBits samples, VkImageViewType view_type, VkImageTiling tiling, VkImageUsageFlags usage) { VkImageCreateInfo image_info = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, @@ -202,8 +202,8 @@ void Texture::TransitionToLayout(VkCommandBuffer command_buffer, VkImageLayout n m_layout = new_layout; } -void Texture::TransitionSubresourcesToLayout(VkCommandBuffer command_buffer, u32 start_level, u32 num_levels, - u32 start_layer, u32 num_layers, VkImageLayout old_layout, +void Texture::TransitionSubresourcesToLayout(VkCommandBuffer command_buffer, uint32_t start_level, uint32_t num_levels, + uint32_t start_layer, uint32_t num_layers, VkImageLayout old_layout, VkImageLayout new_layout) { VkImageMemoryBarrier barrier = { @@ -334,8 +334,8 @@ VkFramebuffer Texture::CreateFramebuffer(VkRenderPass render_pass) return fb; } -void Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, - VkBuffer buffer, u32 buffer_offset, u32 row_length) +void Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, uint32_t level, uint32_t layer, uint32_t x, uint32_t y, uint32_t width, uint32_t height, + VkBuffer buffer, uint32_t buffer_offset, uint32_t row_length) { const VkImageLayout old_layout = m_layout; TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); diff --git a/src/common/vulkan/texture.h b/src/common/vulkan/texture.h index ffb07d56..2ab59936 100644 --- a/src/common/vulkan/texture.h +++ b/src/common/vulkan/texture.h @@ -26,12 +26,12 @@ public: /// An image is considered owned/managed if we control the memory. ALWAYS_INLINE bool IsOwned() const { return (m_device_memory != VK_NULL_HANDLE); } - ALWAYS_INLINE u32 GetWidth() const { return m_width; } - ALWAYS_INLINE u32 GetHeight() const { return m_height; } - ALWAYS_INLINE u32 GetLevels() const { return m_levels; } - ALWAYS_INLINE u32 GetLayers() const { return m_layers; } - ALWAYS_INLINE u32 GetMipWidth(u32 level) const { return std::max(m_width >> level, 1u); } - ALWAYS_INLINE u32 GetMipHeight(u32 level) const { return std::max(m_height >> level, 1u); } + ALWAYS_INLINE uint32_t GetWidth() const { return m_width; } + ALWAYS_INLINE uint32_t GetHeight() const { return m_height; } + ALWAYS_INLINE uint32_t GetLevels() const { return m_levels; } + ALWAYS_INLINE uint32_t GetLayers() const { return m_layers; } + ALWAYS_INLINE uint32_t GetMipWidth(uint32_t level) const { return std::max(m_width >> level, 1u); } + ALWAYS_INLINE uint32_t GetMipHeight(uint32_t level) const { return std::max(m_height >> level, 1u); } ALWAYS_INLINE VkFormat GetFormat() const { return m_format; } ALWAYS_INLINE VkSampleCountFlagBits GetSamples() const { return m_samples; } ALWAYS_INLINE VkImageLayout GetLayout() const { return m_layout; } @@ -39,7 +39,7 @@ public: ALWAYS_INLINE VkImage GetImage() const { return m_image; } ALWAYS_INLINE VkImageView GetView() const { return m_view; } - bool Create(u32 width, u32 height, u32 levels, u32 layers, VkFormat format, VkSampleCountFlagBits samples, + bool Create(uint32_t width, uint32_t height, uint32_t levels, uint32_t layers, VkFormat format, VkSampleCountFlagBits samples, VkImageViewType view_type, VkImageTiling tiling, VkImageUsageFlags usage); void Destroy(bool defer = true); @@ -50,19 +50,19 @@ public: void OverrideImageLayout(VkImageLayout new_layout); void TransitionToLayout(VkCommandBuffer command_buffer, VkImageLayout new_layout); - void TransitionSubresourcesToLayout(VkCommandBuffer command_buffer, u32 start_level, u32 num_levels, u32 start_layer, - u32 num_layers, VkImageLayout old_layout, VkImageLayout new_layout); + void TransitionSubresourcesToLayout(VkCommandBuffer command_buffer, uint32_t start_level, uint32_t num_levels, uint32_t start_layer, + uint32_t num_layers, VkImageLayout old_layout, VkImageLayout new_layout); VkFramebuffer CreateFramebuffer(VkRenderPass render_pass); - void UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 layer, u32 x, u32 y, u32 width, u32 height, - VkBuffer buffer, u32 buffer_offset, u32 row_length); + void UpdateFromBuffer(VkCommandBuffer cmdbuf, uint32_t level, uint32_t layer, uint32_t x, uint32_t y, uint32_t width, uint32_t height, + VkBuffer buffer, uint32_t buffer_offset, uint32_t row_length); private: - u32 m_width = 0; - u32 m_height = 0; - u32 m_levels = 0; - u32 m_layers = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + uint32_t m_levels = 0; + uint32_t m_layers = 0; VkFormat m_format = VK_FORMAT_UNDEFINED; VkSampleCountFlagBits m_samples = VK_SAMPLE_COUNT_1_BIT; VkImageViewType m_view_type = VK_IMAGE_VIEW_TYPE_2D; diff --git a/src/common/vulkan/util.cpp b/src/common/vulkan/util.cpp index 157c38ad..ef10635c 100644 --- a/src/common/vulkan/util.cpp +++ b/src/common/vulkan/util.cpp @@ -64,7 +64,7 @@ VkFormat GetLinearFormat(VkFormat format) } } -u32 GetTexelSize(VkFormat format) +uint32_t GetTexelSize(VkFormat format) { // Only contains pixel formats we use. switch (format) @@ -101,7 +101,7 @@ u32 GetTexelSize(VkFormat format) return 1; } -u32 GetBlockSize(VkFormat format) +uint32_t GetBlockSize(VkFormat format) { switch (format) { @@ -116,7 +116,7 @@ u32 GetBlockSize(VkFormat format) } } -VkRect2D ClampRect2D(const VkRect2D& rect, u32 width, u32 height) +VkRect2D ClampRect2D(const VkRect2D& rect, uint32_t width, uint32_t height) { VkRect2D out; out.offset.x = std::clamp(rect.offset.x, 0, static_cast(width - 1)); @@ -157,7 +157,7 @@ void SetViewport(VkCommandBuffer command_buffer, int x, int y, int width, int he void SetScissor(VkCommandBuffer command_buffer, int x, int y, int width, int height) { - const VkRect2D scissor{{x, y}, {static_cast(width), static_cast(height)}}; + const VkRect2D scissor{{x, y}, {static_cast(width), static_cast(height)}}; vkCmdSetScissor(command_buffer, 0, 1, &scissor); } @@ -170,7 +170,7 @@ void SetViewportAndScissor(VkCommandBuffer command_buffer, int x, int y, int wid static_cast(height), min_depth, max_depth}; - const VkRect2D scissor{{x, y}, {static_cast(width), static_cast(height)}}; + const VkRect2D scissor{{x, y}, {static_cast(width), static_cast(height)}}; vkCmdSetViewport(command_buffer, 0, 1, &vp); vkCmdSetScissor(command_buffer, 0, 1, &scissor); } diff --git a/src/common/vulkan/util.h b/src/common/vulkan/util.h index 6ef75012..a74336ef 100644 --- a/src/common/vulkan/util.h +++ b/src/common/vulkan/util.h @@ -17,11 +17,11 @@ namespace Util { bool IsDepthFormat(VkFormat format); bool IsCompressedFormat(VkFormat format); VkFormat GetLinearFormat(VkFormat format); -u32 GetTexelSize(VkFormat format); -u32 GetBlockSize(VkFormat format); +uint32_t GetTexelSize(VkFormat format); +uint32_t GetBlockSize(VkFormat format); // Clamps a VkRect2D to the specified dimensions. -VkRect2D ClampRect2D(const VkRect2D& rect, u32 width, u32 height); +VkRect2D ClampRect2D(const VkRect2D& rect, uint32_t width, uint32_t height); // Map {SRC,DST}_COLOR to {SRC,DST}_ALPHA VkBlendFactor GetAlphaBlendFactor(VkBlendFactor factor); diff --git a/src/common/window_info.h b/src/common/window_info.h index 3c7f09be..00c44af8 100644 --- a/src/common/window_info.h +++ b/src/common/window_info.h @@ -5,6 +5,6 @@ struct WindowInfo { void* display_connection = nullptr; - u32 surface_width = 0; - u32 surface_height = 0; + uint32_t surface_width = 0; + uint32_t surface_height = 0; }; diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 188ee937..0218224a 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -6,7 +6,7 @@ #include "system.h" #include -AnalogController::AnalogController(u32 index) : m_index(index) +AnalogController::AnalogController(uint32_t index) : m_index(index) { m_axis_state.fill(0x80); Reset(); @@ -47,10 +47,10 @@ bool AnalogController::DoState(StateWrapper& sw, bool apply_input_state) sw.DoEx(&m_legacy_rumble_unlocked, 44, false); sw.Do(&m_configuration_mode); sw.Do(&m_command_param); - sw.DoEx(&m_status_byte, 55, static_cast(0x5A)); + sw.DoEx(&m_status_byte, 55, static_cast(0x5A)); - u16 button_state = m_button_state; - sw.DoEx(&button_state, 44, static_cast(0xFFFF)); + uint16_t button_state = m_button_state; + sw.DoEx(&button_state, 44, static_cast(0xFFFF)); if (apply_input_state) m_button_state = button_state; else @@ -68,7 +68,7 @@ bool AnalogController::DoState(StateWrapper& sw, bool apply_input_state) if (sw.IsReading()) { - for (u8 i = 0; i < NUM_MOTORS; i++) + for (uint8_t i = 0; i < NUM_MOTORS; i++) SetMotorState(i, motor_state[i]); if (old_analog_mode != m_analog_mode) @@ -84,24 +84,24 @@ bool AnalogController::DoState(StateWrapper& sw, bool apply_input_state) return true; } -void AnalogController::SetAxisState(s32 axis_code, float value) +void AnalogController::SetAxisState(int32_t axis_code, float value) { - if (axis_code < 0 || axis_code >= static_cast(Axis::Count)) + if (axis_code < 0 || axis_code >= static_cast(Axis::Count)) return; // -1..1 -> 0..255 const float scaled_value = std::clamp(value * m_axis_scale, -1.0f, 1.0f); - const u8 u8_value = static_cast(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); + const uint8_t u8_value = static_cast(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); } -void AnalogController::SetAxisState(Axis axis, u8 value) +void AnalogController::SetAxisState(Axis axis, uint8_t value) { - if (value != m_axis_state[static_cast(axis)]) + if (value != m_axis_state[static_cast(axis)]) System::SetRunaheadReplayFlag(); - m_axis_state[static_cast(axis)] = value; + m_axis_state[static_cast(axis)] = value; } void AnalogController::SetButtonState(Button button, bool pressed) @@ -129,7 +129,7 @@ void AnalogController::SetButtonState(Button button, bool pressed) return; } - const u16 bit = u16(1) << static_cast(button); + const uint16_t bit = uint16_t(1) << static_cast(button); if (pressed) { @@ -147,39 +147,39 @@ void AnalogController::SetButtonState(Button button, bool pressed) } } -void AnalogController::SetButtonState(s32 button_code, bool pressed) +void AnalogController::SetButtonState(int32_t button_code, bool pressed) { - if (button_code < 0 || button_code >= static_cast(Button::Count)) + if (button_code < 0 || button_code >= static_cast(Button::Count)) return; SetButtonState(static_cast