Revert "use unordered_dense to mitigate __next_prime overflow error"

This reverts commit b082e2e06b.
This commit is contained in:
BZLZHH
2025-05-17 11:13:19 +08:00
parent c848255b43
commit 9297542dcf
9 changed files with 34 additions and 2142 deletions
+3 -3
View File
@@ -8,13 +8,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fvisibility=hidden -funwind-tables -g -D_THREAD_SAFE -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fvisibility=hidden -funwind-tables -g -D_THREAD_SAFE -fPIC -stdlib=libc++")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -g -std=gnu99 -funwind-tables -O3 -fvisibility=hidden") #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -g -std=gnu99 -funwind-tables -O3 -fvisibility=hidden")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
#set(CMAKE_ANDROID_STL_TYPE c++_static) set(CMAKE_ANDROID_STL_TYPE c++_static)
#set(CMAKE_BUILD_TYPE Release) #set(CMAKE_BUILD_TYPE Release)
-1
View File
@@ -108,7 +108,6 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "GLES3/gl32.h" #include "GLES3/gl32.h"
#include <ankerl/unordered_dense.h>
#include "MG_Include/UncertainBool.hpp" #include "MG_Include/UncertainBool.hpp"
+11 -14
View File
@@ -13,18 +13,22 @@ VertexArrayState::VertexArrayState() {
GLenum VertexArrayState::Create(GLuint* array) { GLenum VertexArrayState::Create(GLuint* array) {
if (array == nullptr) return GL_INVALID_VALUE; if (array == nullptr) return GL_INVALID_VALUE;
GLuint id = freeId_.empty() ? lastId_++ : freeId_.back(); GLuint id = freeIds_.empty() ? ++lastId_ : *freeIds_.begin();
if (!freeId_.empty()) { if (!freeIds_.empty()) {
freeId_.pop_back(); freeIds_.erase(freeIds_.begin());
} }
*array = id; *array = id;
vaos_[id] = { .generated = false }; // vaos_[id].generated = true;
return GL_NO_ERROR; return GL_NO_ERROR;
} }
GLenum VertexArrayState::CreateN(GLsizei n, GLuint* arrays) { GLenum VertexArrayState::CreateN(GLsizei n, GLuint* arrays) {
if (n <= 0 || arrays == nullptr) { if (n < 0) {
return GL_INVALID_VALUE;
}
if (n > 0 && arrays == nullptr) {
return GL_INVALID_VALUE; return GL_INVALID_VALUE;
} }
@@ -37,9 +41,7 @@ GLenum VertexArrayState::CreateN(GLsizei n, GLuint* arrays) {
} }
GLenum VertexArrayState::Bind(GLuint array) { GLenum VertexArrayState::Bind(GLuint array) {
if (array != 0 && vaos_.find(array) == vaos_.end()) if (array != 0 && vaos_.find(array) == vaos_.end()) return GL_INVALID_OPERATION;
return GL_INVALID_OPERATION;
currentVao_ = array; currentVao_ = array;
GetCurrentVAO()->generated = true; GetCurrentVAO()->generated = true;
return GL_NO_ERROR; return GL_NO_ERROR;
@@ -90,10 +92,5 @@ GLuint VertexArrayState::GetBoundElementBuffer() {
VertexArrayObject* VertexArrayState::GetCurrentVAO() { VertexArrayObject* VertexArrayState::GetCurrentVAO() {
auto it = vaos_.find(currentVao_); auto it = vaos_.find(currentVao_);
if (it != vaos_.end()) return (it != vaos_.end()) ? &it->second : &vaos_.at(0);
return &it->second;
else {
MG_Util::Debug::LogD("%s: VAO not found, currentVao_ = %u !", __func__, currentVao_);
return nullptr;
}
} }
@@ -45,9 +45,8 @@ public:
public: // TODO public: // TODO
std::unordered_map<GLuint, VertexArrayObject> vaos_; std::unordered_map<GLuint, VertexArrayObject> vaos_;
// std::set<GLuint> freeIds_; std::set<GLuint> freeIds_;
std::vector<GLuint> freeId_; GLuint lastId_ = 0;
GLuint lastId_ = 1; // reserve 0 for default vao
GLuint currentVao_ = 0; GLuint currentVao_ = 0;
}; };
+9 -8
View File
@@ -280,8 +280,8 @@ namespace MG_RHI::GLES {
SyncAllBuffersToGLES(bufferState); SyncAllBuffersToGLES(bufferState);
// VAO // VAO
GLuint mgVAOId = vaState->currentVao_; GLuint mgVAO = vaState->currentVao_;
VertexArrayObject* vao = &vaState->vaos_[mgVAOId]; VertexArrayObject* vao = &vaState->vaos_[vaState->currentVao_];
for (auto& [mgVAOId, mgVAO] : vaState->vaos_) { for (auto& [mgVAOId, mgVAO] : vaState->vaos_) {
MG_Util::Debug::LogD("Uploading VAO: %d", mgVAOId); MG_Util::Debug::LogD("Uploading VAO: %d", mgVAOId);
if (!mgVAO.generated) continue; if (!mgVAO.generated) continue;
@@ -290,7 +290,6 @@ namespace MG_RHI::GLES {
GLuint glVAO; GLuint glVAO;
if (vaoMap_.find(mgVAOId) == vaoMap_.end()) { if (vaoMap_.find(mgVAOId) == vaoMap_.end()) {
MGL_TRY(::GLES::glGenVertexArrays(1, &glVAO);) MGL_TRY(::GLES::glGenVertexArrays(1, &glVAO);)
MG_Util::Debug::LogD("Saving VAO: %d -> %d", mgVAOId, glVAO);
vaoMap_[mgVAOId] = glVAO; vaoMap_[mgVAOId] = glVAO;
} else { } else {
glVAO = vaoMap_[mgVAOId]; glVAO = vaoMap_[mgVAOId];
@@ -302,7 +301,7 @@ namespace MG_RHI::GLES {
} }
for (auto& [index, attrib] : mgVAO.attribs) { for (auto& [index, attrib] : mgVAO.attribs) {
MG_Util::Debug::LogD("attrib #%d, type = %s, size = %d, stride = %d, pointer = %p", MG_Util::Debug::LogD("attrib #%s, type = %s, size = %d, stride = %d, pointer = %p",
index, MG_Util::Debug::GLEnumToString(attrib.type), attrib.size, attrib.stride, attrib.pointer); index, MG_Util::Debug::GLEnumToString(attrib.type), attrib.size, attrib.stride, attrib.pointer);
if (attrib.buffer != 0 && bufferMap_.count(attrib.buffer)) { if (attrib.buffer != 0 && bufferMap_.count(attrib.buffer)) {
MGL_TRY(::GLES::glBindBuffer(GL_ARRAY_BUFFER, bufferMap_[attrib.buffer]);) MGL_TRY(::GLES::glBindBuffer(GL_ARRAY_BUFFER, bufferMap_[attrib.buffer]);)
@@ -330,11 +329,11 @@ namespace MG_RHI::GLES {
MGL_TRY(::GLES::glBindVertexArray(0);) MGL_TRY(::GLES::glBindVertexArray(0);)
//} //}
} }
// GLuint currentMgVAO = vaState->currentVao_; GLuint currentMgVAO = vaState->currentVao_;
if (vaoMap_.find(mgVAOId) != vaoMap_.end()) { if (vaoMap_.count(currentMgVAO)) {
MGL_TRY(::GLES::glBindVertexArray(vaoMap_[mgVAOId]);) MGL_TRY(::GLES::glBindVertexArray(vaoMap_[currentMgVAO]);)
VertexArrayObject& currentVAO = vaState->vaos_[mgVAOId]; VertexArrayObject& currentVAO = vaState->vaos_[currentMgVAO];
for (auto& [index, attrib] : currentVAO.attribs) { for (auto& [index, attrib] : currentVAO.attribs) {
if (attrib.enabled) { if (attrib.enabled) {
MGL_TRY(::GLES::glEnableVertexAttribArray(index);) MGL_TRY(::GLES::glEnableVertexAttribArray(index);)
@@ -624,6 +623,8 @@ namespace MG_RHI::GLES {
lastBoundFBO = currentFBO; lastBoundFBO = currentFBO;
} }
} }
} }
} }
+7 -10
View File
@@ -8,9 +8,6 @@
#include "../../Includes.h" #include "../../Includes.h"
namespace MG_RHI::GLES { namespace MG_RHI::GLES {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
enum class State { enum class State {
None, None,
DrawArrays, DrawArrays,
@@ -33,14 +30,14 @@ namespace MG_RHI::GLES {
private: private:
State currentState_ = State::None; State currentState_ = State::None;
unordered_map<GLuint, GLuint> textureMap_; std::unordered_map<GLuint, GLuint> textureMap_;
unordered_map<GLuint, GLuint> bufferMap_; std::unordered_map<GLuint, std::unordered_map<GLint, bool>> textureLevelUploaded_;
unordered_map<GLuint, GLuint> vaoMap_; std::unordered_map<GLuint, GLuint> bufferMap_;
unordered_map<GLuint, GLuint> programMap_;
unordered_map<GLuint, GLuint> framebufferMap_;
unordered_map<GLuint, unordered_map<GLint, bool>> textureLevelUploaded_;
std::array<GLuint, 32> lastBoundTextures { 0 }; std::array<GLuint, 32> lastBoundTextures { 0 };
std::unordered_map<GLuint, GLuint> vaoMap_;
std::unordered_map<GLuint, GLuint> programMap_;
std::unordered_map<GLuint, GLuint> framebufferMap_;
GLuint lastBoundVAO = 0; GLuint lastBoundVAO = 0;
GLuint lastBoundProgram = 0; GLuint lastBoundProgram = 0;
+1 -1
View File
@@ -7,7 +7,7 @@
#include "../../Includes.h" #include "../../Includes.h"
#define FORCE_SYNC_WITH_LOG_FILE 1 #define FORCE_SYNC_WITH_LOG_FILE 0
namespace MG_Util { namespace MG_Util {
namespace Debug { namespace Debug {
+1 -1
View File
@@ -8,7 +8,7 @@ android {
minSdk 26 minSdk 26
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndkVersion '27.2.12479018' ndkVersion '27.1.12297006'
} }
buildTypes { buildTypes {
File diff suppressed because it is too large Load Diff