Skip to content
Snippets Groups Projects
Commit 48077c15 authored by Artur Wasmut's avatar Artur Wasmut
Browse files

Remove offset calculation in shader reflection. Proper offsets are now...

Remove offset calculation in shader reflection. Proper offsets are now calculated on vertex binding creation.
parent bf7c6167
No related branches found
No related tags found
1 merge request!61Resolve "Refactor(?) VertexLayout"
Pipeline #25688 passed
......@@ -19,14 +19,15 @@ namespace vkcv{
uint32_t getFormatSize(VertexAttachmentFormat format);
struct VertexAttachment{
friend struct VertexBinding;
/**
* Describes an individual vertex input attribute/attachment.
* @param inputLocation its location in the vertex shader.
* @param name the name referred to in the shader.
* @param format the format (and therefore, the size) this attachment is in.
* @param offset the attachment's byte offset within a vertex.
* The offset is calculated when a collection of attachments forms a binding, hence the friend declaration.
*/
VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format, uint32_t offset) noexcept;
VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format) noexcept;
VertexAttachment() = delete;
uint32_t inputLocation;
......
......@@ -101,15 +101,6 @@ int main(int argc, const char** argv) {
firstMeshProgram.addShader(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/vert.spv"));
firstMeshProgram.addShader(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/frag.spv"));
/**
* TODO:
* Since the framework's vertex layout specification is now separate
* from that defined in the asset loader module, there needs to be a smarter way to translate the asset loader's
* specific layout into "our" uniform vertex layout spec.
*
* This is just a quick hack.
*/
const std::vector<vkcv::VertexAttachment> vertexAttachments = firstMeshProgram.getVertexAttachments();
std::vector<vkcv::VertexBinding> bindings;
......
......@@ -91,17 +91,8 @@ int main(int argc, const char** argv) {
std::sort(attributes.begin(), attributes.end(), [](const vkcv::asset::VertexAttribute& x, const vkcv::asset::VertexAttribute& y) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
});
/**
* TODO:
* Since the framework's vertex layout specification is now separate
* from that defined in the asset loader module, there needs to be a smarter way to translate the asset loader's
* specific layout into "our" uniform vertex layout spec.
*
*/
const std::vector<vkcv::VertexAttachment> vertexAttachments = firstMeshProgram.getVertexAttachments();
std::vector<vkcv::VertexBinding> bindings;
for (size_t i = 0; i < vertexAttachments.size(); i++) {
bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] }));
......@@ -138,18 +129,10 @@ int main(int argc, const char** argv) {
vkcv::SamplerAddressMode::REPEAT
);
/*
const std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
vkcv::VertexBufferBinding( static_cast<vk::DeviceSize>(mesh.vertexGroups[0].vertexBuffer.attributes[0].offset), vertexBuffer.getVulkanHandle() ),
vkcv::VertexBufferBinding( static_cast<vk::DeviceSize>(mesh.vertexGroups[0].vertexBuffer.attributes[1].offset), vertexBuffer.getVulkanHandle() ),
vkcv::VertexBufferBinding( static_cast<vk::DeviceSize>(mesh.vertexGroups[0].vertexBuffer.attributes[2].offset), vertexBuffer.getVulkanHandle() )
};
*/
const std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
vkcv::VertexBufferBinding(attributes[0].offset, vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(attributes[1].offset, vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(attributes[2].offset, vertexBuffer.getVulkanHandle()) };
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[0].offset), vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[1].offset), vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[2].offset), vertexBuffer.getVulkanHandle()) };
vkcv::DescriptorWrites setWrites;
setWrites.sampledImageWrites = { vkcv::SampledImageDescriptorWrite(0, texture.getHandle()) };
......
......@@ -117,8 +117,6 @@ namespace vkcv {
//reflect vertex input
if (shaderStage == ShaderStage::VERTEX)
{
uint32_t attachment_offset = 0;
// spirv-cross API (hopefully) returns the stage_inputs in order
for (uint32_t i = 0; i < resources.stage_inputs.size(); i++)
{
......@@ -133,13 +131,7 @@ namespace vkcv {
// vertex input format (implies its size)
const VertexAttachmentFormat attachment_format = convertFormat(base_type.basetype, base_type.vecsize);
m_VertexAttachments.emplace_back(attachment_loc,
attachment_name,
attachment_format,
attachment_offset);
// calculate offset for the next vertex attachment input in line
attachment_offset += base_type.vecsize * base_type.width / 8;
m_VertexAttachments.emplace_back(attachment_loc, attachment_name, attachment_format);
}
}
......
......@@ -30,11 +30,11 @@ namespace vkcv {
}
}
VertexAttachment::VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format, uint32_t offset) noexcept:
VertexAttachment::VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format) noexcept:
inputLocation{inputLocation},
name{name},
format{format},
offset{offset}
offset{0}
{}
......@@ -43,8 +43,13 @@ namespace vkcv {
stride{0},
vertexAttachments{attachments}
{
for (const auto &attachment : attachments)
stride += getFormatSize(attachment.format);
uint32_t offset = 0;
for (auto &attachment : vertexAttachments)
{
offset += getFormatSize(attachment.format);
attachment.offset = offset;
stride += offset;
}
}
VertexLayout::VertexLayout() noexcept :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment