From 4d6cfb1f90823e16d4bb4479b70a4e9b6b8d7cca Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 16 Jan 2021 14:08:03 -0400 Subject: [PATCH] metal: vertex attribute reflection is slightly better --- src/modules/graphics/Shader.cpp | 6 ++-- src/modules/graphics/metal/Shader.mm | 44 +++++++++++++++++++++------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index 904fbb841..8f70a1bbf 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -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; diff --git a/src/modules/graphics/metal/Shader.mm b/src/modules/graphics/metal/Shader.mm index d86664f37..f4bd6eecc 100644 --- a/src/modules/graphics/metal/Shader.mm +++ b/src/modules/graphics/metal/Shader.mm @@ -322,8 +322,42 @@ Shader::Shader(id 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 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) {