From bcadc04932052550f22228c638aeaf19e575e203 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 8 Feb 2021 14:55:18 +0100 Subject: [PATCH] [dxvk] Validate vertex attribute alignment --- src/d3d11/d3d11_device.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 5b3e4175..5231f97b 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -611,6 +611,9 @@ namespace dxvk { // 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. + const DxvkFormatInfo* formatInfo = imageFormatInfo(attrib.format); + VkDeviceSize alignment = std::min(formatInfo->elementSize, 4); + if (attrib.offset == D3D11_APPEND_ALIGNED_ELEMENT) { attrib.offset = 0; @@ -618,13 +621,12 @@ namespace dxvk { const DxvkVertexAttribute& prev = attrList.at(i - j); if (prev.binding == attrib.binding) { - const DxvkFormatInfo* formatInfo = imageFormatInfo(prev.format); - VkDeviceSize alignment = std::min(formatInfo->elementSize, 4); - attrib.offset = align(prev.offset + formatInfo->elementSize, alignment); + attrib.offset = align(prev.offset + imageFormatInfo(prev.format)->elementSize, alignment); break; } } - } + } else if (attrib.offset & (alignment - 1)) + return E_INVALIDARG; attrList.at(i) = attrib;