From ca22a96f70a5778407debf81ff823089bb046737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 13 Apr 2018 18:01:39 -0700 Subject: [PATCH] VK: Added attribute remap for binding vertex layout to shader. --- src/renderer_vk.cpp | 18 +++++++++++++----- src/renderer_vk.h | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 9e145fc3b..4338dbc90 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -257,7 +257,7 @@ VK_IMPORT_DEVICE }; BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); - uint32_t fillVertexDecl(VkPipelineVertexInputStateCreateInfo& _vertexInputState, const VertexDecl& _decl) + uint32_t fillVertexDecl(const ShaderVK* _vsh, VkPipelineVertexInputStateCreateInfo& _vertexInputState, const VertexDecl& _decl) { VkVertexInputBindingDescription* inputBinding = const_cast(_vertexInputState.pVertexBindingDescriptions); VkVertexInputAttributeDescription* inputAttrib = const_cast(_vertexInputState.pVertexAttributeDescriptions); @@ -272,8 +272,8 @@ VK_IMPORT_DEVICE { if (UINT16_MAX != _decl.m_attributes[attr]) { - inputAttrib->location = numAttribs; - inputAttrib->binding = 0; + inputAttrib->location = _vsh->m_attrRemap[attr]; + inputAttrib->binding = 0; if (0 == _decl.m_attributes[attr]) { @@ -2554,7 +2554,7 @@ VK_IMPORT_DEVICE decl.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; } - uint32_t num = fillVertexDecl(_vertexInputState, decl); + uint32_t num = fillVertexDecl(_program.m_vsh, _vertexInputState, decl); // const D3D12_INPUT_ELEMENT_DESC inst = { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA, 1 }; @@ -3547,9 +3547,17 @@ VK_DESTROY , &m_module ) ); - bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); + bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); + bx::memSet(m_attrRemap, 0, sizeof(m_attrRemap) ); + m_attrMask[Attrib::Position] = UINT16_MAX; m_attrMask[Attrib::Color0] = UINT16_MAX; + + m_attrRemap[Attrib::Color0] = 0; + m_attrRemap[Attrib::Position] = 1; + + m_numAttrs = 2; + iohash = 0; uint8_t numAttrs = 0; diff --git a/src/renderer_vk.h b/src/renderer_vk.h index 2d1649cb1..8c293f4cd 100644 --- a/src/renderer_vk.h +++ b/src/renderer_vk.h @@ -379,11 +379,13 @@ VK_DESTROY PredefinedUniform m_predefined[PredefinedUniform::Count]; uint16_t m_attrMask[Attrib::Count]; + uint8_t m_attrRemap[Attrib::Count]; uint32_t m_hash; uint16_t m_numUniforms; uint16_t m_size; uint8_t m_numPredefined; + uint8_t m_numAttrs; }; struct ProgramVK