[Feat] (MG_State/ProgramObject, MG_State/GL_Program): implement sampler unit in program state

This commit is contained in:
2025-10-27 13:17:42 +08:00
parent 8e5cc46577
commit 5b3d5c998a
3 changed files with 29 additions and 6 deletions
+11 -4
View File
@@ -455,10 +455,17 @@ namespace MobileGL {
template <GLsizei VecCount, typename T>
void Uniform_State(MG_State::GLState::ProgramObject& programObject, GLuint location, T* value) {
auto size = programObject.GetUniformSizesInBytes(location);
auto offset = programObject.GetUniformOffset(location);
assert(size >= VecCount * sizeof(T));
memcpy((char*)programObject.MapUBO() + offset, value, VecCount * sizeof(T));
if (!programObject.IsUniformOpaqueAtLocation(location)) {
auto size = programObject.GetUniformSizesInBytes(location);
auto offset = programObject.GetUniformOffset(location);
assert(size >= VecCount * sizeof(T));
memcpy((char*)programObject.MapUBO() + offset, value, VecCount * sizeof(T));
} else {
auto* ttype = programObject.GetUniformTType(location);
if (ttype->isTexture() || ttype->isImage()) {
programObject.SetUniformSamplerOrImageUnitIndex(location, *value);
}
}
}
template <GLsizei VecCount, typename T>
@@ -92,6 +92,7 @@ namespace MobileGL {
// Be aware, there could be gaps in between these vectors
// Locations can be not sequential
m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, 4095);
m_uniformSamplerOrImageUnitIndex.resize(m_maxUniformLocation + 1, 0);
Vector<int> unallocatedUniformIndex;
@@ -29,14 +29,19 @@ namespace MobileGL {
return -1;
return (Int)it->second;
}
GLenum GetUniformType(Uint location) const {
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
return uniform.glDefineType;
}
Bool IsUniformOpaqueAtLocation(Uint location) const {
const glslang::TType* GetUniformTType(Uint location) const {
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
return uniform.getType()->isOpaque();
return uniform.getType();
}
Bool IsUniformOpaqueAtLocation(Uint location) const {
return GetUniformTType(location)->isOpaque();
}
const String& GetUniformName(Uint location) const {
@@ -56,6 +61,14 @@ namespace MobileGL {
const String& GetAttribName(Uint index) const { return m_attribs[index]; }
void* MapUBO() { return m_uboScratch.data(); }
void SetUniformSamplerOrImageUnitIndex(Uint location, Int unit) {
m_uniformSamplerOrImageUnitIndex[location] = unit;
}
Int SetUniformSamplerOrImageUnitIndex(Uint location) const {
return m_uniformSamplerOrImageUnitIndex[location];
}
Bool GetDeleteStatus() const { return m_deleteStatus; }
Bool GetLinkStatus() const { return m_linkStatus; }
Bool GetValidateStatus() const { return m_validateStatus; }
@@ -91,6 +104,8 @@ namespace MobileGL {
// Ordered by location,
// aka. m_uniformIndexInTProgram[loc] == "uniform index of TProgram at location `loc`"
Vector<Int> m_uniformIndexInTProgram;
// ditto. Will be set at glUniform1i
Vector<Int> m_uniformSamplerOrImageUnitIndex;
// Need to be reflected after linking of SPIR-V binary
Vector<Uint> m_uniformOffsets;