mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Feat]: (MG_Util/ShaderTranspiler): TMglGlslIoResolver: a custom glslang IoResolver to realize glBindAttribLocation semantics
This commit is contained in:
@@ -174,13 +174,13 @@ namespace MobileGL {
|
||||
return std::unexpected(r);
|
||||
}
|
||||
|
||||
UniquePtr<glslang::TIoMapResolver> resolver;
|
||||
// UniquePtr<glslang::TIoMapResolver> resolver;
|
||||
UniquePtr<TMglGlslIoResolver> resolver;
|
||||
for (unsigned stage = 0; stage < EShLangCount; stage++) {
|
||||
auto* pResolver = program->getGlslIoResolver((EShLanguage)stage);
|
||||
if (pResolver) {
|
||||
resolver = UniquePtr<glslang::TIoMapResolver>(pResolver);
|
||||
break;
|
||||
}
|
||||
if (program->getIntermediate((EShLanguage)stage) == nullptr)
|
||||
continue;
|
||||
resolver = MakeUnique<TMglGlslIoResolver>(*program, (EShLanguage)stage, attrib.explicitAttribLocations);
|
||||
break;
|
||||
}
|
||||
auto ioMapper = UniquePtr<glslang::TIoMapper>(glslang::GetGlslIoMapper());
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace MobileGL {
|
||||
|
||||
struct ProgramAttrib {
|
||||
Vector<SharedPtr<glslang::TShader>> shaders;
|
||||
UnorderedMap<String, Uint> explicitAttribLocations;
|
||||
};
|
||||
|
||||
struct ProgramBinaryAttrib {
|
||||
|
||||
@@ -4,10 +4,17 @@
|
||||
|
||||
#include "TMglGlslIoResolver.h"
|
||||
|
||||
int TMglGlslIoResolver::resolveInOutLocation(EShLanguage stage, glslang::TVarEntryInfo &ent) {
|
||||
return glslang::TDefaultGlslIoResolver::resolveInOutLocation(stage, ent);
|
||||
}
|
||||
|
||||
int TMglGlslIoResolver::resolveUniformLocation(EShLanguage stage, glslang::TVarEntryInfo &ent) {
|
||||
return glslang::TDefaultGlslIoResolver::resolveUniformLocation(stage, ent);
|
||||
}
|
||||
namespace MobileGL {
|
||||
void TMglGlslIoResolver::reserverStorageSlot(glslang::TVarEntryInfo& ent, TInfoSink& infoSink) {
|
||||
const glslang::TType& type = ent.symbol->getType();
|
||||
const glslang::TString& name = ent.symbol->getAccessName();
|
||||
if (type.getQualifier().isPipeInput()) {
|
||||
auto it = m_explicitAttribLocations.find(name.c_str());
|
||||
if (it != m_explicitAttribLocations.end()) {
|
||||
auto& writableType = ent.symbol->getWritableType();
|
||||
writableType.getQualifier().layoutLocation = it->second;
|
||||
}
|
||||
}
|
||||
TDefaultGlslIoResolver::reserverStorageSlot(ent, infoSink);
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,21 @@
|
||||
#include <glslang/Include/intermediate.h>
|
||||
#include <glslang/MachineIndependent/iomapper.h>
|
||||
#include "TVarEntryInfo.h"
|
||||
#include "MG_Util/Types.h"
|
||||
|
||||
class TMglGlslIoResolver: public glslang::TDefaultGlslIoResolver {
|
||||
int resolveInOutLocation(EShLanguage stage, glslang::TVarEntryInfo& ent) override;
|
||||
int resolveUniformLocation(EShLanguage /*stage*/, glslang::TVarEntryInfo& ent) override;
|
||||
};
|
||||
namespace MobileGL {
|
||||
class TMglGlslIoResolver: public glslang::TDefaultGlslIoResolver {
|
||||
public:
|
||||
using ExplicitVarSlotMap = UnorderedMap<String, Uint>;
|
||||
TMglGlslIoResolver(const glslang::TIntermediate& intermediate, const ExplicitVarSlotMap& attribLocations):
|
||||
TDefaultGlslIoResolver(intermediate), m_explicitAttribLocations(attribLocations) {}
|
||||
TMglGlslIoResolver(const glslang::TProgram& program, const EShLanguage stage, const ExplicitVarSlotMap& attribLocations):
|
||||
TDefaultGlslIoResolver(*program.getIntermediate(stage)),
|
||||
m_explicitAttribLocations(attribLocations) {}
|
||||
void reserverStorageSlot(glslang::TVarEntryInfo& ent, TInfoSink& infoSink) override;
|
||||
protected:
|
||||
const ExplicitVarSlotMap& m_explicitAttribLocations;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user