vulkan: fix shaders with int vertex attributes when nothing using that attribute is drawn.

This commit is contained in:
Sasha Szpakowski
2024-04-11 22:35:43 -03:00
parent 565d635f75
commit 111bbde32d
3 changed files with 45 additions and 12 deletions
+20 -8
View File
@@ -2260,7 +2260,7 @@ void Graphics::createVulkanVertexFormat(
for (const auto &pair : shader->getVertexAttributeIndices())
{
int i = pair.second;
int i = pair.second.index;
uint32 bit = 1u << i;
VkVertexInputAttributeDescription attribdesc{};
@@ -2295,13 +2295,25 @@ void Graphics::createVulkanVertexFormat(
attribdesc.binding = DEFAULT_VERTEX_BUFFER_BINDING;
// Indices should match the creation parameters for defaultVertexBuffer.
// TODO: handle int/uint attributes?
if (i == ATTRIB_COLOR)
attribdesc.offset = defaultVertexBuffer->getDataMember(2).offset;
else
attribdesc.offset = defaultVertexBuffer->getDataMember(0).offset;
attribdesc.format = Vulkan::getVulkanVertexFormat(DATAFORMAT_FLOAT_VEC4);
switch (pair.second.baseType)
{
case DATA_BASETYPE_INT:
attribdesc.offset = defaultVertexBuffer->getDataMember(1).offset;
attribdesc.format = Vulkan::getVulkanVertexFormat(DATAFORMAT_INT32_VEC4);
break;
case DATA_BASETYPE_UINT:
attribdesc.offset = defaultVertexBuffer->getDataMember(1).offset;
attribdesc.format = Vulkan::getVulkanVertexFormat(DATAFORMAT_UINT32_VEC4);
break;
case DATA_BASETYPE_FLOAT:
default:
if (i == ATTRIB_COLOR)
attribdesc.offset = defaultVertexBuffer->getDataMember(2).offset;
else
attribdesc.offset = defaultVertexBuffer->getDataMember(0).offset;
attribdesc.format = Vulkan::getVulkanVertexFormat(DATAFORMAT_FLOAT_VEC4);
break;
}
if (usedBuffers.find(DEFAULT_VERTEX_BUFFER_BINDING) == usedBuffers.end())
{
+16 -2
View File
@@ -373,7 +373,7 @@ void Shader::attach()
int Shader::getVertexAttributeIndex(const std::string &name)
{
auto it = attributes.find(name);
return it == attributes.end() ? -1 : it->second;
return it == attributes.end() ? -1 : it->second.index;
}
const Shader::UniformInfo *Shader::getUniformInfo(BuiltinUniform builtin) const
@@ -716,7 +716,21 @@ void Shader::compileShaders()
spirv[locationOffset] = (uint32_t)index;
attributes[r.name] = index;
DataBaseType basetype = DATA_BASETYPE_FLOAT;
switch (comp.get_type(r.base_type_id).basetype)
{
case spirv_cross::SPIRType::Int:
basetype = DATA_BASETYPE_INT;
break;
case spirv_cross::SPIRType::UInt:
basetype = DATA_BASETYPE_UINT;
break;
default:
break;
}
attributes[r.name] = { index, basetype };
}
for (const auto &r : shaderResources.stage_outputs)
+9 -2
View File
@@ -52,6 +52,13 @@ class Shader final
, public Volatile
{
public:
struct AttributeInfo
{
int index;
DataBaseType baseType;
};
Shader(StrongRef<love::graphics::ShaderStage> stages[], const CompileOptions &options);
virtual ~Shader();
@@ -75,7 +82,7 @@ public:
std::string getWarnings() const override { return ""; }
int getVertexAttributeIndex(const std::string &name) override;
const std::unordered_map<std::string, int> getVertexAttributeIndices() const { return attributes; }
const std::unordered_map<std::string, AttributeInfo> getVertexAttributeIndices() const { return attributes; }
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
@@ -126,7 +133,7 @@ private:
uint32_t localUniformLocation;
OptionalInt builtinUniformDataOffset;
std::unordered_map<std::string, int> attributes;
std::unordered_map<std::string, AttributeInfo> attributes;
uint32_t currentFrame;
uint32_t currentDescriptorPool;