mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 20:28:32 +09:00
[Feat] (MG_State/Program): Get current program
This commit is contained in:
@@ -81,13 +81,17 @@ namespace MobileGL {
|
||||
|
||||
m_uniformNames.resize(m_maxUniformLocation + 1);
|
||||
m_uniformTypes.resize(m_maxUniformLocation + 1);
|
||||
m_uniformIsOpaqueType.resize(m_maxUniformLocation + 1);
|
||||
m_uniformOffsets.resize(m_maxUniformLocation + 1);
|
||||
m_uniformArraySizes.resize(m_maxUniformLocation + 1);
|
||||
|
||||
for (int i = 0; i < uniformCount; i++) {
|
||||
auto& uniform = m_program->getUniform(i);
|
||||
auto location = uniform.layoutLocation();
|
||||
m_uniformNames[location] = uniform.name;
|
||||
m_uniformTypes[location] = uniform.glDefineType;
|
||||
m_uniformIsOpaqueType[location] = uniform.getType()->isOpaque();
|
||||
m_uniformArraySizes[location] = uniform.size;
|
||||
}
|
||||
|
||||
// attributes (pipe in)
|
||||
@@ -159,7 +163,12 @@ namespace MobileGL {
|
||||
auto binaryResult = ShaderCompiler::GetSpirvBinaryFromProgram(binaryAttrib);
|
||||
assert(binaryResult);
|
||||
m_generatedSpirv = Move(binaryResult.value());
|
||||
|
||||
SpvcSession session(m_generatedSpirv[0]);
|
||||
auto srcResult = ShaderCompiler::DecompileShader(session);
|
||||
assert(srcResult);
|
||||
auto src = srcResult.value();
|
||||
|
||||
auto& meta = session.GetMetadata();
|
||||
auto size = meta.uboSize;
|
||||
m_uboScratch.resize(size);
|
||||
@@ -167,11 +176,12 @@ namespace MobileGL {
|
||||
for (const auto& [name, offset] : meta.plainUniformOffsetsInUBO) {
|
||||
m_uniformOffsets[m_uniformLocations[name]] = offset;
|
||||
}
|
||||
|
||||
auto srcResult = ShaderCompiler::DecompileShader(session);
|
||||
assert(srcResult);
|
||||
auto src = srcResult.value();
|
||||
printf("decompiled src: \n%s", src.c_str());
|
||||
m_uniformSizesInBytes.resize(meta.plainUniformMemberSizesInBytes.size());
|
||||
for (const auto& [name, size] : meta.plainUniformMemberSizesInBytes) {
|
||||
m_uniformSizesInBytes[m_uniformLocations[name]] = size;
|
||||
}
|
||||
assert(m_uniformOffsets.size() == GetUniformCount());
|
||||
assert(m_uniformSizesInBytes.size() == GetUniformCount());
|
||||
}
|
||||
|
||||
void ProgramObject::WaitUntilGenerationCompleted() {
|
||||
|
||||
@@ -23,15 +23,25 @@ namespace MobileGL {
|
||||
Uint GetUniformCount() { return m_uniformNames.size(); }
|
||||
Int GetUniformLocation(const String& name) {
|
||||
const auto it = m_uniformLocations.find(name);
|
||||
return (it == m_uniformLocations.end()) ? -1 : it->second;
|
||||
return (it == m_uniformLocations.end()) ? -1 : (Int)it->second;
|
||||
}
|
||||
GLenum GetUniformType(Uint index) const {
|
||||
return m_uniformTypes[index];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
Uint GetUniformSizesInBytes(Uint location) const {
|
||||
return m_uniformSizesInBytes[location];
|
||||
}
|
||||
|
||||
Int GetAttributeLocation(const String& name) {
|
||||
const auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
|
||||
@@ -43,6 +53,9 @@ namespace MobileGL {
|
||||
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; }
|
||||
@@ -80,9 +93,12 @@ namespace MobileGL {
|
||||
Vector<String> m_uniformNames;
|
||||
// ditto.
|
||||
Vector<GLenum> m_uniformTypes;
|
||||
Vector<Bool> m_uniformIsOpaqueType;
|
||||
Vector<Int> m_uniformArraySizes;
|
||||
|
||||
// Need to be reflected after linking of SPIR-V binary
|
||||
Vector<Uint> m_uniformOffsets;
|
||||
Vector<Uint> m_uniformSizesInBytes;
|
||||
Vector<Uint8> m_uboScratch;
|
||||
|
||||
Uint m_maxUniformLocation = 0;
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace MobileGL {
|
||||
SharedPtr<ShaderObject> GetShaderObject(Uint shader);
|
||||
void MarkShaderObjectForDeletion(Uint shader);
|
||||
Bool ValidateShaderObject(Uint shader) const;
|
||||
|
||||
SharedPtr<ProgramObject> GetCurrentProgram() const {
|
||||
return m_currentProgram;
|
||||
}
|
||||
private:
|
||||
template <typename T>
|
||||
static Bool CheckIndexAvail(const SizeT idx, const Vector<T>& vec) {
|
||||
|
||||
Reference in New Issue
Block a user