metal: vertex attribute reflection is slightly better

This commit is contained in:
Alex Szpakowski
2021-01-16 14:08:03 -04:00
parent 558cc6a111
commit 4d6cfb1f90
2 changed files with 37 additions and 13 deletions
+3 -3
View File
@@ -272,9 +272,9 @@ void setPointSize() {
)";
static const char vertex_main[] = R"(
LOVE_IO_LOCATION(0) attribute vec4 VertexPosition;
LOVE_IO_LOCATION(1) attribute vec4 VertexTexCoord;
LOVE_IO_LOCATION(2) attribute vec4 VertexColor;
attribute vec4 VertexPosition;
attribute vec4 VertexTexCoord;
attribute vec4 VertexColor;
varying vec4 VaryingTexCoord;
varying vec4 VaryingColor;
+34 -10
View File
@@ -322,8 +322,42 @@ Shader::Shader(id<MTLDevice> device, love::graphics::ShaderStage *vertex, love::
}
}
for (const auto &resource : resources.storage_buffers)
{
auto it = uniforms.find(resource.name);
if (it != uniforms.end())
{
continue;
}
// TODO
}
if (i == ShaderStage::STAGE_VERTEX)
{
int nextattributeindex = ATTRIB_MAX_ENUM;
for (const auto &var : interfacevars)
{
spv::StorageClass storage = msl.get_storage_class(var);
const std::string &name = msl.get_name(var);
if (storage == spv::StorageClassInput)
{
int index = 0;
BuiltinVertexAttribute builtinattribute;
if (graphics::getConstant(name.c_str(), builtinattribute))
index = (int) builtinattribute;
else
index = nextattributeindex++;
msl.set_decoration(var, spv::DecorationLocation, index);
attributes[name] = msl.get_decoration(var, spv::DecorationLocation);
}
}
for (const auto &varying : resources.stage_outputs)
{
// printf("vertex shader output %s: %d\n", inp.name.c_str(), msl.get_decoration(inp.id, spv::DecorationLocation));
@@ -373,16 +407,6 @@ Shader::Shader(id<MTLDevice> device, love::graphics::ShaderStage *vertex, love::
}
functions[i] = [library newFunctionWithName:library.functionNames[0]];
for (const auto &var : interfacevars)
{
spv::StorageClass storage = msl.get_storage_class(var);
const std::string &name = msl.get_name(var);
// printf("var: %s\n", name.c_str());
if (i == ShaderStage::STAGE_VERTEX && storage == spv::StorageClassInput)
attributes[name] = msl.get_decoration(var, spv::DecorationLocation);
}
}
catch (std::exception &e)
{