I feel like the way add_vertex_attribute works at the moment is very arbitrary, counter-intuitive and it actually makes certain cases impossible as far as I can tell.
Example:
struct Vertex
{
Vector4 position;
Vector2 uv;
};
struct VertexWeight
{
Vector4i boneIds;
Vector4 boneWeights;
};
pipelineInfo.add_vertex_attribute(
0u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sfloat),
0u, /* start offset */
sizeof(Vertex), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex)
);
pipelineInfo.add_vertex_attribute(
1u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32Sfloat),
sizeof(Vector4), /* start offset */
sizeof(Vertex), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex)
);
pipelineInfo.add_vertex_attribute(
2u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sint),
0u, /* start offset */
sizeof(VertexWeight), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex)
);
pipelineInfo.add_vertex_attribute(
3u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sfloat),
sizeof(Vector4i), /* start offset */
sizeof(VertexWeight), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex)
);
After baking that would result in 4 vertex attributes and 2 vertex bindings, which is what I want.
However, if I were to extend the Vertex-struct in the future, e.g. like so:
struct Vertex
{
Vector4 position;
Vector2 uv;
Vector2 someNewProperty;
};
then I suddenly end up with 4 vertex attributes and 1 vertex binding (because Vertex and VertexWeight now have the same size/stride).
In fact, as far as I can tell this case would make it impossible to end up with 2 vertex bindings.
Even if I try using explicit binding indices like so:
pipelineInfo.add_vertex_attribute(
0u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sfloat),
0u, /* start offset */
sizeof(Vertex), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex),
0u /* explicit binding index */
);
pipelineInfo.add_vertex_attribute(
1u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32Sfloat),
sizeof(Vector4), /* start offset */
sizeof(Vertex), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex),
0u /* explicit binding index */
);
pipelineInfo.add_vertex_attribute(
2u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sint),
0u, /* start offset */
sizeof(VertexWeight), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex),
1u /* explicit binding index */
);
pipelineInfo.add_vertex_attribute(
3u, /* location */
static_cast<VkFormat>(vk::Format::eR32G32B32A32Sfloat),
sizeof(Vector4), /* start offset */
sizeof(VertexWeight), /* stride */
static_cast<VkVertexInputRate>(vk::VertexInputRate::eVertex),
1u /* explicit binding index */
);
I end up with 4 vertex attributes and 4 vertex bindings (Maybe I'm using explicit binding indices incorrectly?).
I don't think the stride should be used in the first place to determine the number of vertex bindings that will be created. To be honest, I prefer the original way of defining vertex attributes/bindings over how it's done in Anvil, I find the way Anvil tries to "merge" attributes and bindings misleading (maybe that's just me though).
I feel like the way add_vertex_attribute works at the moment is very arbitrary, counter-intuitive and it actually makes certain cases impossible as far as I can tell.
Example:
After baking that would result in 4 vertex attributes and 2 vertex bindings, which is what I want.
However, if I were to extend the Vertex-struct in the future, e.g. like so:
then I suddenly end up with 4 vertex attributes and 1 vertex binding (because Vertex and VertexWeight now have the same size/stride).
In fact, as far as I can tell this case would make it impossible to end up with 2 vertex bindings.
Even if I try using explicit binding indices like so:
I end up with 4 vertex attributes and 4 vertex bindings (Maybe I'm using explicit binding indices incorrectly?).
I don't think the stride should be used in the first place to determine the number of vertex bindings that will be created. To be honest, I prefer the original way of defining vertex attributes/bindings over how it's done in Anvil, I find the way Anvil tries to "merge" attributes and bindings misleading (maybe that's just me though).