[Fix] (MG_Backend/DirectVulkan): fixing Photon v1.1

- Flatten DailyWeatherVariation interface varyings
- Correct internal-format component counts
- Preserve GL draw-buffer slot semantics in render pass creation
- relax GL_NONE / vec4-to-RGB pipeline checks
This commit is contained in:
2026-05-09 09:56:45 +08:00
parent 407d4344c4
commit 39c5b28dfb
11 changed files with 1876 additions and 22 deletions
+42
View File
@@ -140,6 +140,48 @@ namespace MobileGL::MG_State {
return m_vertexArrayState.GetBoundVertexArray();
}
void GLContext::SetCurrentVertexAttributeFloat(Uint index, const Array<Float, 4>& value) {
MOBILEGL_ASSERT(index < m_currentVertexAttributes.size(),
"SetCurrentVertexAttributeFloat: index %u is out of range", index);
auto& current = m_currentVertexAttributes[index];
current.floatValue = value;
for (SizeT component = 0; component < value.size(); ++component) {
current.intValue[component] = static_cast<Int32>(value[component]);
current.uintValue[component] = static_cast<Uint32>(value[component]);
}
}
void GLContext::SetCurrentVertexAttributeInt(Uint index, const Array<Int32, 4>& value) {
MOBILEGL_ASSERT(index < m_currentVertexAttributes.size(),
"SetCurrentVertexAttributeInt: index %u is out of range", index);
auto& current = m_currentVertexAttributes[index];
current.intValue = value;
for (SizeT component = 0; component < value.size(); ++component) {
current.floatValue[component] = static_cast<Float>(value[component]);
current.uintValue[component] = static_cast<Uint32>(value[component]);
}
}
void GLContext::SetCurrentVertexAttributeUint(Uint index, const Array<Uint32, 4>& value) {
MOBILEGL_ASSERT(index < m_currentVertexAttributes.size(),
"SetCurrentVertexAttributeUint: index %u is out of range", index);
auto& current = m_currentVertexAttributes[index];
current.uintValue = value;
for (SizeT component = 0; component < value.size(); ++component) {
current.floatValue[component] = static_cast<Float>(value[component]);
current.intValue[component] = static_cast<Int32>(value[component]);
}
}
const CurrentVertexAttributeValue& GLContext::GetCurrentVertexAttribute(Uint index) const {
MOBILEGL_ASSERT(index < m_currentVertexAttributes.size(),
"GetCurrentVertexAttribute: index %u is out of range", index);
return m_currentVertexAttributes[index];
}
// Texture
void GLContext::GenTextureNames(Uint number, Vector<Uint>& textures) {
m_textureState.GenerateNames(number, textures);
+11
View File
@@ -25,6 +25,12 @@ namespace MobileGL {
void Init();
namespace GLState {
struct CurrentVertexAttributeValue {
Array<Float, 4> floatValue{0.f, 0.f, 0.f, 1.f};
Array<Int32, 4> intValue{0, 0, 0, 1};
Array<Uint32, 4> uintValue{0u, 0u, 0u, 1u};
};
class GLContext {
public:
GLContext() = default;
@@ -61,6 +67,10 @@ namespace MobileGL {
Bool ValidateVertexArrayName(Uint index) const;
Bool ValidateVertexArrayObject(Uint index) const;
const SharedPtr<VertexArrayObject>& GetBoundVertexArray();
void SetCurrentVertexAttributeFloat(Uint index, const Array<Float, 4>& value);
void SetCurrentVertexAttributeInt(Uint index, const Array<Int32, 4>& value);
void SetCurrentVertexAttributeUint(Uint index, const Array<Uint32, 4>& value);
const CurrentVertexAttributeValue& GetCurrentVertexAttribute(Uint index) const;
// Texture
void GenTextureNames(Uint number, Vector<Uint>& textures);
@@ -152,6 +162,7 @@ namespace MobileGL {
ErrorState m_errorState;
BufferState m_bufferState;
VertexArrayState m_vertexArrayState;
Array<CurrentVertexAttributeValue, VertexArrayObject::MAX_VERTEX_ATTRIBS> m_currentVertexAttributes{};
TextureState m_textureState;
ProgramState m_programState;
RenderState m_renderState;
@@ -18,6 +18,46 @@ layout(location = 0) out vec4 FragColor;
void main() {}
)";
namespace {
static int GetVertexInputLocationSpan(GLenum glType) {
switch (glType) {
case GL_FLOAT_MAT2:
case GL_FLOAT_MAT2x3:
case GL_FLOAT_MAT2x4:
return 2;
case GL_FLOAT_MAT3:
case GL_FLOAT_MAT3x2:
case GL_FLOAT_MAT3x4:
return 3;
case GL_FLOAT_MAT4:
case GL_FLOAT_MAT4x2:
case GL_FLOAT_MAT4x3:
return 4;
default:
return 1;
}
}
static GLenum GetVertexInputLocationType(GLenum glType) {
switch (glType) {
case GL_FLOAT_MAT2:
case GL_FLOAT_MAT3x2:
case GL_FLOAT_MAT4x2:
return GL_FLOAT_VEC2;
case GL_FLOAT_MAT3:
case GL_FLOAT_MAT2x3:
case GL_FLOAT_MAT4x3:
return GL_FLOAT_VEC3;
case GL_FLOAT_MAT4:
case GL_FLOAT_MAT2x4:
case GL_FLOAT_MAT3x4:
return GL_FLOAT_VEC4;
default:
return glType;
}
}
}
namespace MobileGL::MG_State::GLState {
bool ProgramObject::ShaderIsAttached(const SharedPtr<ShaderObject>& shader) {
MGLOG_D("ProgramObject %u: ShaderIsAttached check for shader %p", m_externalIndex, shader.get());
@@ -264,7 +304,10 @@ namespace MobileGL::MG_State::GLState {
Int maxLoc = -1;
for (int i = 0; i < inCount; ++i) {
Int loc = (Int)m_program->getPipeInput(i).layoutLocation();
if (loc >= 0 && loc != glslang::TQualifier::layoutLocationEnd) maxLoc = std::max(maxLoc, loc);
if (loc >= 0 && loc != glslang::TQualifier::layoutLocationEnd) {
const Int locationSpan = GetVertexInputLocationSpan(m_program->getPipeInput(i).glDefineType);
maxLoc = std::max(maxLoc, loc + locationSpan - 1);
}
MGLOG_D("ProgramObject %u: Reflection - pipe input[%d] name='%s' layoutLocation=%d glType=%u",
m_externalIndex, i, m_program->getPipeInput(i).name.c_str(), loc,
m_program->getPipeInput(i).glDefineType);
@@ -294,10 +337,25 @@ namespace MobileGL::MG_State::GLState {
m_attribInNameMaxLength = std::max(m_attribInNameMaxLength, (Int)inVar.name.length());
if (location >= 0 && location < (int)m_attribs.size()) {
m_attribs[location] = inVar.name;
m_attribTypes[location] = inVar.glDefineType;
MGLOG_D("ProgramObject %u: Reflection - got attrib '%s' at explicit location %d", m_externalIndex,
inVar.name.c_str(), location);
const Int locationSpan = GetVertexInputLocationSpan(inVar.glDefineType);
const GLenum locationType = GetVertexInputLocationType(inVar.glDefineType);
for (Int locationOffset = 0; locationOffset < locationSpan; ++locationOffset) {
const Int expandedLocation = location + locationOffset;
if (expandedLocation < 0 || expandedLocation >= static_cast<Int>(m_attribs.size())) {
break;
}
m_attribs[expandedLocation] = inVar.name;
m_attribTypes[expandedLocation] = locationType;
MGLOG_D(
"ProgramObject %u: Reflection - got attrib '%s' at expanded location %d (baseLocation=%d glType=%u expandedType=%u)",
m_externalIndex,
inVar.name.c_str(),
expandedLocation,
location,
inVar.glDefineType,
static_cast<Uint32>(locationType));
}
}
// else if (location >= (int)m_attribs.size()) {
// MGLOG_W("ProgramObject %u: ProgramObject::DoReflection - attrib location %d >= attribs.size()
@@ -63,6 +63,48 @@ namespace MobileGL::MG_State::GLState {
const auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
return (it == m_attribs.end()) ? -1 : (Int)std::distance(m_attribs.begin(), it);
}
Uint32 GetActiveAttributeLocationMask() const {
Uint32 mask = 0;
const SizeT count = std::min<SizeT>(m_attribs.size(), 32);
for (SizeT index = 0; index < count; ++index) {
if (!m_attribs[index].empty()) {
mask |= (1u << index);
}
}
return mask;
}
Uint32 GetActiveFragmentOutputLocationMask() const {
if (!m_program) {
return 0;
}
Uint32 mask = 0;
const Int outputCount = m_program->getNumPipeOutputs();
for (Int index = 0; index < outputCount; ++index) {
const Int location = static_cast<Int>(m_program->getPipeOutput(index).layoutLocation());
if (location >= 0 && location < 32) {
mask |= (1u << location);
}
}
return mask;
}
Int GetActiveFragmentOutputCount() const {
return m_program ? m_program->getNumPipeOutputs() : 0;
}
Int GetFragmentOutputLocation(Uint index) const {
MOBILEGL_ASSERT(m_program != nullptr, "ProgramObject::GetFragmentOutputLocation: program is null");
MOBILEGL_ASSERT(index < static_cast<Uint>(m_program->getNumPipeOutputs()),
"ProgramObject::GetFragmentOutputLocation: index=%u out of range",
index);
return static_cast<Int>(m_program->getPipeOutput(static_cast<Int>(index)).layoutLocation());
}
GLenum GetFragmentOutputType(Uint index) const {
MOBILEGL_ASSERT(m_program != nullptr, "ProgramObject::GetFragmentOutputType: program is null");
MOBILEGL_ASSERT(index < static_cast<Uint>(m_program->getNumPipeOutputs()),
"ProgramObject::GetFragmentOutputType: index=%u out of range",
index);
return m_program->getPipeOutput(static_cast<Int>(index)).glDefineType;
}
GLenum GetAttribType(Uint index) const { return m_attribTypes[index]; }
const String& GetAttribName(Uint index) const { return m_attribs[index]; }
void* MapUBO() { return m_globalUboScratch.data(); }