[Fix] (MG_State): Make uniformObj.count correct. Disable all freeIds now.

This commit is contained in:
BZLZHH
2025-05-16 23:35:44 +08:00
parent 6901e9584f
commit 354d0882eb
8 changed files with 68 additions and 17 deletions
+2 -1
View File
@@ -219,7 +219,8 @@ bool BufferState::ValidateGeneratedName(GLuint buffer) {
void BufferState::Delete(GLuint buffer) {
buffers_.erase(buffer);
if (ValidateGeneratedName(buffer))
freeId_.emplace_back(buffer);
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
//freeId_.emplace_back(buffer);
for (auto& [target, id] : currentBindings_) {
if (id == buffer) id = 0;
}
@@ -32,7 +32,8 @@ GLenum FramebufferState::Delete(GLuint framebuffer) {
if (framebuffer == 0) return GL_INVALID_VALUE;
if (framebuffers_.erase(framebuffer)) {
freeIds_.insert(framebuffer);
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
//freeIds_.insert(framebuffer);
for (auto& [target, id] : currentBindings_) {
if (id == framebuffer) id = 0;
}
+55 -8
View File
@@ -48,7 +48,7 @@ GLenum ProgramState::DeleteProgram(GLuint program) {
}
programs_.erase(program);
freeProgramIds_.insert(program);
//freeProgramIds_.insert(program);
if (currentProgram_ == program)
currentProgram_ = 0;
MG_Util::Debug::LogD("MG_State: Program: DeleteProgram success, id=%u", program);
@@ -261,6 +261,7 @@ GLenum ProgramState::SetUniform(GLuint program, GLint location, GLsizei count, c
}
UniformValue& uniform = prog.uniformValues[uniformName];
uniform.setData(type, count, value);
MG_Util::Debug::LogD("MG_State: Program: SetUniform success: %s set", uniformName.c_str());
return GL_NO_ERROR;
@@ -303,7 +304,7 @@ GLenum ProgramState::SetUniformMatrix(GLuint program, GLint location, GLsizei co
}
UniformValue& uniform = prog.uniformValues[uniformName];
uniform.setData(matrixType, count * MG_Util::Program::GetMatrixElementCount(matrixType), value);
uniform.setData(matrixType, count, value);
MG_Util::Debug::LogD("MG_State: Program: SetUniformMatrix success: %s set", uniformName.c_str());
return GL_NO_ERROR;
}
@@ -334,15 +335,15 @@ void ProgramState::UpdateUniform##suffix##Vector1(GLint location, GLsizei count,
} \
void ProgramState::UpdateUniform##suffix##Vector2(GLint location, GLsizei count, const type* value) { \
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector2 called, location=%d, count=%d", location, count); \
SetUniform<type>(currentProgram_, location, count * 2, value, vecType); \
SetUniform<type>(currentProgram_, location, count, value, vecType); \
} \
void ProgramState::UpdateUniform##suffix##Vector3(GLint location, GLsizei count, const type* value) { \
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector3 called, location=%d, count=%d", location, count); \
SetUniform<type>(currentProgram_, location, count * 3, value, vecType); \
SetUniform<type>(currentProgram_, location, count, value, vecType); \
} \
void ProgramState::UpdateUniform##suffix##Vector4(GLint location, GLsizei count, const type* value) { \
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector4 called, location=%d, count=%d", location, count); \
SetUniform<type>(currentProgram_, location, count * 4, value, vecType); \
SetUniform<type>(currentProgram_, location, count, value, vecType); \
}
IMPLEMENT_UNIFORM_FUNCTIONS(GLfloat, Float, GL_FLOAT_VEC4)
@@ -462,16 +463,62 @@ void ProgramState::CleanupShaders_() {
// UniformValue
template<typename T>
void UniformValue::setData(GLenum uniformType, GLsizei numElements, const T* values) {
MG_Util::Debug::LogD("MG_State: Program: UniformValue::setData called, type=0x%X, count=%d", uniformType, numElements);
void UniformValue::setData(GLenum uniformType, GLsizei count_, const T* values) {
MG_Util::Debug::LogD("MG_State: Program: UniformValue::setData called, type=0x%X, count=%d", uniformType, count_);
//type = uniformType;
count = numElements;
count = count_;
floatData.clear();
intData.clear();
uintData.clear();
boolData.clear();
switch (type) {
case GL_FLOAT: numElements = count_ * 1; break;
case GL_FLOAT_VEC2: numElements = count_ * 2; break;
case GL_FLOAT_VEC3: numElements = count_ * 3; break;
case GL_FLOAT_VEC4: numElements = count_ * 4; break;
case GL_INT: numElements = count_ * 1; break;
case GL_INT_VEC2: numElements = count_ * 2; break;
case GL_INT_VEC3: numElements = count_ * 3; break;
case GL_INT_VEC4: numElements = count_ * 4; break;
case GL_UNSIGNED_INT: numElements = count_ * 1; break;
case GL_UNSIGNED_INT_VEC2: numElements = count_ * 2; break;
case GL_UNSIGNED_INT_VEC3: numElements = count_ * 3; break;
case GL_UNSIGNED_INT_VEC4: numElements = count_ * 4; break;
case GL_BOOL: numElements = count_ * 1; break;
case GL_BOOL_VEC2: numElements = count_ * 2; break;
case GL_BOOL_VEC3: numElements = count_ * 3; break;
case GL_BOOL_VEC4: numElements = count_ * 4; break;
case GL_FLOAT_MAT2: numElements = count_ * 4; break; // 2x2
case GL_FLOAT_MAT3: numElements = count_ * 9; break; // 3x3
case GL_FLOAT_MAT4: numElements = count_ * 16; break; // 4x4
case GL_FLOAT_MAT2x3: numElements = count_ * 6; break; // 2x3
case GL_FLOAT_MAT2x4: numElements = count_ * 8; break; // 2x4
case GL_FLOAT_MAT3x2: numElements = count_ * 6; break; // 3x2
case GL_FLOAT_MAT3x4: numElements = count_ * 12; break; // 3x4
case GL_FLOAT_MAT4x2: numElements = count_ * 8; break; // 4x2
case GL_FLOAT_MAT4x3: numElements = count_ * 12; break; // 4x3
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_CUBE_SHADOW:
case GL_SAMPLER_1D_ARRAY:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_1D_ARRAY_SHADOW:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_BUFFER:
case GL_SAMPLER_2D_MULTISAMPLE:
case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: numElements = count_ * 1; break;
default:
MG_Util::Debug::LogW("MG_State: Program: UniformValue::setData warning: unsupported type 0x%X for numElements", uniformType);
numElements = 1;
return;
}
for (GLsizei i = 0; i < numElements; ++i) {
switch (uniformType) {
case GL_FLOAT:
+3 -1
View File
@@ -27,16 +27,18 @@ struct UniformValue {
std::vector<GLuint> uintData;
std::vector<GLboolean> boolData;
GLsizei count;
GLsizei numElements;
UniformValue() : type(0), count(0) {}
template<typename T>
void setData(GLenum uniformType, GLsizei numElements, const T* values);
void setData(GLenum uniformType, GLsizei count_, const T* values);
};
struct ProgramObject {
std::vector<GLuint> attachedShaders;
UncertainBool linked;
bool dirty;
GLint linkStatus;
std::string infoLog;
std::unordered_map<std::string, GLint> attribBindings;
+2 -1
View File
@@ -60,7 +60,8 @@ GLenum ProgramState::DeleteShader(GLuint shader) {
MG_Util::Debug::LogD("MG_State: Program: DeleteShader info: shader %u marked for deferred deletion (in use)", shader);
} else {
shaders_.erase(shader);
freeShaderIds_.insert(shader);
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
//freeShaderIds_.insert(shader);
MG_Util::Debug::LogD("MG_State: Program: DeleteShader success: shader %u deleted immediately", shader);
}
return GL_NO_ERROR;
+3 -2
View File
@@ -610,7 +610,7 @@ GLenum TextureState::Delete(GLuint texture) {
if (it != this->textures.end()) {
InvalidateTextureInAllUnits_(texture);
this->textures.erase(it);
freeID_.emplace_back(texture);
//freeID_.emplace_back(texture);
MG_Util::Debug::LogD("MG_State: Texture: Delete succeeded for texture=%u", texture);
} else {
MG_Util::Debug::LogW("MG_State: Texture: Delete texture %u not found", texture);
@@ -632,7 +632,8 @@ GLenum TextureState::DeleteN(GLsizei n, const GLuint* textures) {
if (it != this->textures.end()) {
InvalidateTextureInAllUnits_(id);
this->textures.erase(it);
freeID_.emplace_back(id);
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
//freeID_.emplace_back(id);
MG_Util::Debug::LogD("MG_State: Texture: DeleteN deleted texture=%u", id);
} else {
MG_Util::Debug::LogW("MG_State: Texture: DeleteN texture %u not found", id);
+1 -1
View File
@@ -54,7 +54,7 @@ namespace MG_Util::Program {
std::ostringstream ss;
ss << "[";
const size_t elemCount = std::min<size_t>(value.count, 16); // 限制最大显示元素
const size_t elemCount = std::min<size_t>(value.count, 16);
switch(value.type) {
case GL_FLOAT:
-2
View File
@@ -395,8 +395,6 @@ namespace MG_Util::Program {
prog.uniformLocations[name] = final_location;
UniformValue uniformValue;
uniformValue.type = gl_type;
uniformValue.count = spvc_type_get_array_dimension(type, 0) > 0 ?
spvc_type_get_array_dimension(type, 0) : 1;
prog.uniformValues[name] = uniformValue;
}
}