#Index vertex texture coordenates

47 messages · Page 1 of 1 (latest)

wraith rose
#

Ideally I can store vertices textures and normals all in separate arraylists (saves padding space) is this possible in vulkan. The "Vertex" seems to need to store all of that in one in vulkan

glad oriole
#

There is no "the vertex" in Vulkan. What exactly are you referring too?

#

You can provide vertex attributes both interleaved (single buffer) or separte (multiple buffers).

wraith rose
#

what is the difference in how you set it up then, do you create multiple uniforms

glad oriole
#

vertex data is provided via attributes in the pipeline state, not as uniforms

#

The difference is simply in how you bind buffers in the vertex input state

#

Interleaved is one binding

#

Separate is multiple bindings

wraith rose
#

I currently have this ```c++
c.vkCmdBindVertexBuffers(buffer, 0, 1, &self.vertex_buffer.buffer.buffer, &offsets);
c.vkCmdBindIndexBuffer(buffer, self.vertex_buffer.indices.buffer, 0, c.VK_INDEX_TYPE_UINT32);

#

Would it be possible to have a separate index buffer for position and texture

#

I would probably need to change the way I am drawing too right ?

#

currently ```cpp
c.vkCmdDrawIndexed(buffer, @intCast(self.vertex_buffer.indices_len), 1, 0, 0, 0);

glad oriole
#

no, you can only ever bind one index buffer for a draw

#

but you can bind an arbitrary number of vertex buffers per draw

wraith rose
#

so I need to store the position and texture position together then ?

#

Cause my obj loader loads the raw data, and to get the ordered vertices you look at the faces

#

ideally I can represent faces to vulkan so I dont have to copy after loading to wrap each raw vertex position with its associated texture coord

#

if that makes sense ?

glad oriole
#

it doesn't matter for Vulkan. You can do both, interleaved or separate.

wraith rose
#

but there is a single index buffer, sorry I am not quite sure what you mean

glad oriole
#

for indexed rendering it doesn't matter if you use interleaved or separate vertex attributes

#

as long as the indices are the same

#

if you don't know enough yet about Vulkan to understand that, just go with a single interleaved buffer

wraith rose
#

and you just have multiple bindings for the different buffers in pVertexBindingDescriptions ?

glad oriole
#

it would use different buffers

#

that's why it's called separated

#

offsets are for interleaved buffers

wraith rose
#

ahh ok

#

thanks, ill try implement this

wraith rose
#

i will need to copy

#

to a certain extent

wraith rose
#

here are my binding and attribute descriptions ```cpp
const binding_descriptions = [_]c.VkVertexInputBindingDescription{ .{
.binding = 0,
.stride = @sizeOf(@Vector(4, f32)),
.inputRate = c.VK_VERTEX_INPUT_RATE_VERTEX,
}, .{
.binding = 1,
.stride = @sizeOf(@Vector(2, f32)),
.inputRate = c.VK_VERTEX_INPUT_RATE_VERTEX,
} };

    const attribute_descriptions = [_]c.VkVertexInputAttributeDescription{
        .{
            .binding = 0,
            .location = 0,
            .format = c.VK_FORMAT_R32G32B32A32_SFLOAT,
            .offset = 0,
        },
        .{
            .binding = 1,
            .location = 0,
            .format = c.VK_FORMAT_R32G32_SFLOAT,
            .offset = 0,
        },
    };
#

This raises validation error

#
VUID-vkCmdDrawIndexed-None-02721(ERROR / SPEC): msgNum: 615493573 - Validation Error: [ VUID-vkCmdDrawIndexed-None-02721 ] Object 0: handle = 0x301e6c0000000022, type = VK_OBJECT_TYPE_BUFFER; Object 1: handle = 0xb12fb2000000002c, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0x24afafc5 | vkCmdDrawIndexed():  Format VK_FORMAT_R32G32_SFLOAT has an alignment of 4 but the alignment of attribAddress (9) is not aligned in pVertexAttributeDescriptions[1](binding=1 location=0) where attribAddress = vertex buffer offset (1) + binding stride (8) + attribute offset (0). The Vulkan spec states: For a given vertex buffer binding, any attribute data fetched must be entirely contained within the corresponding vertex buffer binding, as described in Vertex Input Description (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdDrawIndexed-None-02721)```
#

also ```cpp
const offsets = []c.VkDeviceSize{ 0, 1 };
c.vkCmdBindVertexBuffers(buffer, 0, 2, &[
]c.VkBuffer{ self.vertex_buffer.position_buffer.buffer, self.vertex_buffer.texel_buffer.buffer }, &offsets);
c.vkCmdBindIndexBuffer(buffer, self.vertex_buffer.index_buffer.buffer, 0, c.VK_INDEX_TYPE_UINT32);

glad oriole
#

why is offset[1] = 1 ?

#

should be zero instead

wraith rose
#

got it working

#

I was being a bit dumb you are correct

#

I ended up just changin the location also

#

in the input attribute

#

then I just needed to update the shaders

#

thanks for all the help

#

I have been slowly reading what you were saying above and it finally clicked

#

Much easier to work with the vertex data now thank god