fix metal shader lack of texutre uniform variable

This commit is contained in:
junjie020 2018-12-26 14:19:07 +08:00
parent f63a15160b
commit 9296a44f5e
1 changed files with 54 additions and 0 deletions

View File

@ -258,6 +258,60 @@ namespace bgfx { namespace glsl
parse = eol.getPtr() + 1;
}
}
bx::StringView mainEntry("xlatMtlShaderOutput xlatMtlMain (");
parse = bx::strFind(optimizedShader, mainEntry);
end = parse;
if (!parse.isEmpty())
{
parse.set(parse.getPtr() + mainEntry.getLength(), optShader.getTerm());
end = bx::strFind(parse, "{");
}
while (parse.getPtr() < end.getPtr()
&& !parse.isEmpty())
{
parse.set(bx::strLTrimSpace(parse).getPtr(), optShader.getTerm());
const bx::StringView textureNameMark("[[texture(");
const bx::StringView textureName = bx::strFind(parse, textureNameMark);
if (!textureName.isEmpty())
{
Uniform un;
un.type = nameToUniformTypeEnum("int"); // int for sampler
const char* varNameEnd = textureName.getPtr() - 1;
parse.set(parse.getPtr(), varNameEnd - 1);
const char* varNameBeg = parse.getPtr();
for (int ii = parse.getLength() - 1; 0 <= ii; --ii)
{
if (varNameBeg[ii] == ' ')
{
parse.set(varNameBeg + ii + 1, varNameEnd);
break;
}
}
char uniformName[256];
bx::strCopy(uniformName, parse.getLength() + 1, parse);
un.name = uniformName;
const char* regIndexBeg = textureName.getPtr() + textureNameMark.getLength();
bx::StringView regIndex = bx::strFind(regIndexBeg, ")");
regIndex.set(regIndexBeg, regIndex.getPtr());
uint32_t tmp;
bx::fromString(&tmp, regIndex);
un.regIndex = uint16_t(tmp);
un.num = 1;
un.regCount = 1;
uniforms.push_back(un);
parse = regIndex.getPtr() + 1;
}
else
{
parse = textureName;
}
}
}
uint16_t count = (uint16_t)uniforms.size();