From 2b6cb2567581cf5d5c31c5ce6d4a35d3ae00e53f Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 18 Dec 2017 23:24:10 +0100 Subject: [PATCH] [d3d11] Implemented D3D11_APPEND_ALIGNED_ELEMENT --- src/d3d11/d3d11_device.cpp | 18 +++++++++++++++--- src/util/util_math.h | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index e8c08983c..e65431853 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -561,10 +561,22 @@ namespace dxvk { pInputElementDescs[i].Format).actual; attrib.offset = pInputElementDescs[i].AlignedByteOffset; - // TODO implement D3D11_APPEND_ALIGNED_ELEMENT + // The application may choose to let the implementation + // generate the exact vertex layout. In that case we'll + // pack attributes on the same binding in the order they + // are declared, aligning each attribute to four bytes. if (attrib.offset == D3D11_APPEND_ALIGNED_ELEMENT) { - Logger::err("D3D11Device::CreateInputLayout: D3D11_APPEND_ALIGNED_ELEMENT not supported yet"); - return E_INVALIDARG; + attrib.offset = 0; + + for (uint32_t j = 1; j <= i; j++) { + const DxvkVertexAttribute& prev = attributes.at(i - j); + + if (prev.binding == attrib.binding) { + const DxvkFormatInfo* formatInfo = imageFormatInfo(prev.format); + attrib.offset = align(prev.offset + formatInfo->elementSize, 4); + break; + } + } } attributes.push_back(attrib); diff --git a/src/util/util_math.h b/src/util/util_math.h index 7a6386a95..5705bf7f0 100644 --- a/src/util/util_math.h +++ b/src/util/util_math.h @@ -9,8 +9,8 @@ namespace dxvk { return n; } - template - T align(T what, T to) { + template + T align(T what, U to) { return (what + to - 1) & ~(to - 1); }