[Misc] (All): Run format_code.sh

This commit is contained in:
BZLZHH
2025-10-02 15:11:38 +08:00
parent 69fe996e15
commit ee971306ca
26 changed files with 1355 additions and 1492 deletions
@@ -90,7 +90,7 @@ namespace MobileGL {
auto location = uniform.layoutLocation();
m_uniformNames[location] = uniform.name;
m_uniformTypes[location] = uniform.glDefineType;
m_uniformIsOpaqueType[location] = uniform.getType()->isOpaque();
m_uniformIsOpaqueType[location] = uniform.getType()->isOpaque();
m_uniformArraySizes[location] = uniform.size;
}
@@ -108,12 +108,11 @@ namespace MobileGL {
m_attribTypes[location] = inVar.glDefineType;
}
// Implement glBindAttribLocation semantics
for (auto& [name, location]: m_explicitAttribLocations) {
for (auto& [name, location] : m_explicitAttribLocations) {
assert(location < m_attribs.size());
if (m_attribs[location] != name) {
auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
if (it == m_attribs.end())
continue;
if (it == m_attribs.end()) continue;
std::swap(m_attribs[location], m_attribs[std::distance(m_attribs.begin(), it)]);
std::swap(m_attribTypes[location], m_attribTypes[std::distance(m_attribs.begin(), it)]);
}
@@ -139,24 +138,21 @@ namespace MobileGL {
for (SizeT i = 0; i < m_shaders.size(); i++) {
auto shaderType = ConvertGLShaderTypeByMGLShaderStage(m_shaders[i]->GetShaderStage());
shaderTypes[i] = shaderType;
ShaderAttrib attrib {
.shaderType = shaderType,
.sourceStr = m_shaders[i]->GetShaderSource(),
.flags = 0
};
ShaderAttrib attrib{
.shaderType = shaderType, .sourceStr = m_shaders[i]->GetShaderSource(), .flags = 0};
auto res = ShaderCompiler::CompileShader(attrib);
assert(res);
shaders[i] = res.value();
}
ProgramAttrib attrib {
ProgramAttrib attrib{
.shaders = Move(shaders),
};
auto programResult = ShaderCompiler::LinkProgram(attrib);
assert(programResult);
auto program = programResult.value();
ProgramBinaryAttrib binaryAttrib {
ProgramBinaryAttrib binaryAttrib{
.shaderTypes = shaderTypes,
.program = *program,
};
@@ -187,10 +183,9 @@ namespace MobileGL {
// assert(m_uniformSizesInBytes.size() == GetUniformCount());
}
void ProgramObject::WaitUntilGenerationCompleted() {
}
void ProgramObject::WaitUntilGenerationCompleted() {}
void ProgramObject::SetExplicitAttribLocation(Uint index, const char *name) {
void ProgramObject::SetExplicitAttribLocation(Uint index, const char* name) {
m_explicitAttribLocations[name] = index;
}
@@ -257,35 +252,35 @@ namespace MobileGL {
// }
//
// void ProgramObject::PostLink() {
// if (m_programBinary.empty()) {
// assert(false);
// return;
// }
// MG_Util::ShaderTranspiler::SpvcSession session(m_programBinary[0]);
// const char* src = nullptr; // we don't care the source atm
// auto result = session.Compile(&src);
// if (result != SPVC_SUCCESS) {
// assert(false);
// return;
// }
// m_metadata = session.GetMetadata();
// auto& uniformOffsets = m_metadata.plainUniformOffsetsInUBO;
// for (const auto& [name, offset] : uniformOffsets) {
// assert(m_uniforms.find(name) != m_uniforms.end());
// assert(m_uniforms[name] < m_uniformOffsets.size());
// m_uniformOffsets[m_uniforms[name]] = offset;
// }
// m_uboScratch.resize(m_metadata.uboSize, 0);
//
// auto& types = m_metadata.plainUniformMemberTypes;
//
// assert(types.size() == m_uniformOffsets.size());
// m_uniformTypes.resize(m_uniformOffsets.size());
// for (const auto& [name, type] : types) {
// auto gltype = MG_Util::ConvertSpvcTypeToGLEnum(type);
// auto location = m_uniforms[name];
// m_uniformTypes[location] = gltype;
// }
// if (m_programBinary.empty()) {
// assert(false);
// return;
// }
// MG_Util::ShaderTranspiler::SpvcSession session(m_programBinary[0]);
// const char* src = nullptr; // we don't care the source atm
// auto result = session.Compile(&src);
// if (result != SPVC_SUCCESS) {
// assert(false);
// return;
// }
// m_metadata = session.GetMetadata();
// auto& uniformOffsets = m_metadata.plainUniformOffsetsInUBO;
// for (const auto& [name, offset] : uniformOffsets) {
// assert(m_uniforms.find(name) != m_uniforms.end());
// assert(m_uniforms[name] < m_uniformOffsets.size());
// m_uniformOffsets[m_uniforms[name]] = offset;
// }
// m_uboScratch.resize(m_metadata.uboSize, 0);
//
// auto& types = m_metadata.plainUniformMemberTypes;
//
// assert(types.size() == m_uniformOffsets.size());
// m_uniformTypes.resize(m_uniformOffsets.size());
// for (const auto& [name, type] : types) {
// auto gltype = MG_Util::ConvertSpvcTypeToGLEnum(type);
// auto location = m_uniforms[name];
// m_uniformTypes[location] = gltype;
// }
// }
} // namespace GLState
} // namespace MG_State
@@ -9,7 +9,7 @@ namespace MobileGL {
namespace GLState {
class ProgramObject {
public:
ProgramObject(const Uint id): m_id(id) {}
ProgramObject(const Uint id) : m_id(id) {}
bool ShaderIsAttached(SharedPtr<ShaderObject> shader);
bool AttachShader(SharedPtr<ShaderObject> shader);
SizeT DetachShader(SharedPtr<ShaderObject> shader);
@@ -27,20 +27,12 @@ namespace MobileGL {
const auto it = m_uniformLocations.find(name);
return (it == m_uniformLocations.end()) ? -1 : (Int)it->second;
}
GLenum GetUniformType(Uint index) const {
return m_uniformTypes[index];
}
GLenum GetUniformType(Uint index) const { return m_uniformTypes[index]; }
Bool IsUniformOpaqueAtLocation(Uint location) const {
return m_uniformIsOpaqueType[location];
}
Bool IsUniformOpaqueAtLocation(Uint location) const { return m_uniformIsOpaqueType[location]; }
const String& GetUniformName(Uint index) const {
return m_uniformNames[index];
}
Uint GetUniformOffset(Uint location) const {
return m_uniformOffsets[location];
}
const String& GetUniformName(Uint index) const { return m_uniformNames[index]; }
Uint GetUniformOffset(Uint location) const { return m_uniformOffsets[location]; }
Uint GetUniformSizesInBytes(Uint location) const {
return MG_Util::GetGLTypeSize(m_uniformTypes[location]);
}
@@ -49,15 +41,9 @@ namespace MobileGL {
const auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
return (it == m_attribs.end()) ? -1 : std::distance(m_attribs.begin(), it);
}
GLenum GetAttribType(Uint index) const {
return m_attribTypes[index];
}
const String& GetAttribName(Uint index) const {
return m_attribs[index];
}
void* MapUBO() {
return m_uboScratch.data();
}
GLenum GetAttribType(Uint index) const { return m_attribTypes[index]; }
const String& GetAttribName(Uint index) const { return m_attribs[index]; }
void* MapUBO() { return m_uboScratch.data(); }
Bool GetDeleteStatus() const { return m_deleteStatus; }
Bool GetLinkStatus() const { return m_linkStatus; }
@@ -67,6 +53,7 @@ namespace MobileGL {
Int GetActiveUniformBlocksCount() const { return m_program->getNumUniformBlocks(); }
Int GetActiveAttributesMaxLength() const { return m_attribInNameMaxLength; }
Int GetActiveUniformBlocksMaxNameLength() const { return m_uniformBlockNameMaxLength; }
private:
void DoReflection();
void GenerateBinary();
@@ -8,8 +8,7 @@ namespace MobileGL {
m_programIndexGenerator.Generate(1, &programId);
EnsureIndexAvail(programId, m_programObjects);
auto programObject = MakeShared<ProgramObject>(programId);
if (programObject == nullptr)
return 0;
if (programObject == nullptr) return 0;
m_programObjects[programId] = programObject;
return programId;
}
@@ -34,8 +33,7 @@ namespace MobileGL {
}
void ProgramState::UseProgram(Uint program) {
if (program == 0)
m_currentProgram.reset();
if (program == 0) m_currentProgram.reset();
if (!CheckIndexAvail(program, m_programObjects)) return;
m_currentProgram = m_programObjects[program];
@@ -46,8 +44,7 @@ namespace MobileGL {
m_shaderIndexGenerator.Generate(1, &shaderId);
EnsureIndexAvail(shaderId, m_shaderObjects);
auto shaderObject = MakeShared<ShaderObject>(stage, shaderId);
if (shaderObject == nullptr)
return 0;
if (shaderObject == nullptr) return 0;
m_shaderObjects[shaderId] = shaderObject;
return shaderId;
}
@@ -22,9 +22,8 @@ namespace MobileGL {
void MarkShaderObjectForDeletion(Uint shader);
Bool ValidateShaderObject(Uint shader) const;
SharedPtr<ProgramObject> GetCurrentProgram() const {
return m_currentProgram;
}
SharedPtr<ProgramObject> GetCurrentProgram() const { return m_currentProgram; }
private:
template <typename T>
static Bool CheckIndexAvail(const SizeT idx, const Vector<T>& vec) {
@@ -10,7 +10,7 @@ namespace MobileGL {
m_source = source;
}
void ShaderObject::SetShaderSource(String &&source) {
void ShaderObject::SetShaderSource(String&& source) {
m_source = Move(source);
}
@@ -24,11 +24,9 @@ namespace MobileGL {
// Compile for OpenGL here, so that we can do validation and link
// like a real OpenGL driver at linking stage
// Will compile for other backends later.
ShaderAttrib attrib{
.shaderType = ConvertGLShaderTypeByMGLShaderStage(m_stage),
.sourceStr = m_source,
.flags = ShaderCompileBits::CompileForOpenGL
};
ShaderAttrib attrib{.shaderType = ConvertGLShaderTypeByMGLShaderStage(m_stage),
.sourceStr = m_source,
.flags = ShaderCompileBits::CompileForOpenGL};
auto result = ShaderCompiler::CompileShader(attrib);
if (result) {
@@ -36,21 +36,21 @@ namespace MobileGL {
inline static ShaderStage ConvertMGLShaderStageByGLShaderType(GLenum type) {
switch (type) {
case GL_VERTEX_SHADER:
return ShaderStage::Vertex;
case GL_TESS_CONTROL_SHADER:
return ShaderStage::TessControl;
case GL_TESS_EVALUATION_SHADER:
return ShaderStage::TessEval;
case GL_GEOMETRY_SHADER:
return ShaderStage::Geometry;
case GL_FRAGMENT_SHADER:
return ShaderStage::Fragment;
case GL_COMPUTE_SHADER:
return ShaderStage::Compute;
default:
assert(false);
return ShaderStage::Unknown;
case GL_VERTEX_SHADER:
return ShaderStage::Vertex;
case GL_TESS_CONTROL_SHADER:
return ShaderStage::TessControl;
case GL_TESS_EVALUATION_SHADER:
return ShaderStage::TessEval;
case GL_GEOMETRY_SHADER:
return ShaderStage::Geometry;
case GL_FRAGMENT_SHADER:
return ShaderStage::Fragment;
case GL_COMPUTE_SHADER:
return ShaderStage::Compute;
default:
assert(false);
return ShaderStage::Unknown;
}
}
@@ -70,6 +70,7 @@ namespace MobileGL {
const UnorderedMap<String, Uint>& GetUniformLocations() const { return m_uniforms; }
Bool GetCompileStatus() const { return m_compileStatus; }
Bool GetDeleteStatus() const { return m_deleteStatus; }
private:
// bool DoReflection();
const Uint m_id = 0;