Commit 5dc0a6f9 by jchen10 Committed by Commit Bot

Vulkan: Vertex buffer should be format aligned.

The address of each attribute in a vertex buffer must be aligned according to its format. See section 20.3 of vkspec. Currently we don't handle this when using DynamicBuffer as vertex input buffer. This loosely fixes the issue by using max alignment for all formats. BUG=angleproject:2797,angleproject:2405 Change-Id: I2b27950dacc8fda75dcb646ef4b4d66ff27d629a Reviewed-on: https://chromium-review.googlesource.com/1234281 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 0f57d2e3
......@@ -25,6 +25,7 @@ namespace
{
constexpr size_t kDynamicVertexDataSize = 1024 * 1024;
constexpr size_t kDynamicIndexDataSize = 1024 * 8;
constexpr size_t kMaxVertexFormatAlignment = 4;
bool BindingIsAligned(const gl::VertexBinding &binding, unsigned componentSize)
{
......@@ -51,6 +52,7 @@ angle::Result StreamVertexData(ContextVk *contextVk,
ANGLE_TRY(dynamicBuffer->flush(contextVk));
return angle::Result::Continue();
}
} // anonymous namespace
#define INIT \
......@@ -88,9 +90,9 @@ VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state, RendererVk *rend
for (vk::DynamicBuffer &buffer : mCurrentArrayBufferConversion)
{
buffer.init(1, renderer);
buffer.init(kMaxVertexFormatAlignment, renderer);
}
mDynamicVertexData.init(1, renderer);
mDynamicVertexData.init(kMaxVertexFormatAlignment, renderer);
mDynamicIndexData.init(1, renderer);
mTranslatedByteIndexData.init(1, renderer);
......@@ -184,6 +186,8 @@ angle::Result VertexArrayVk::convertVertexBuffer(ContextVk *contextVk,
ANGLE_TRY(srcBuffer->mapImpl(contextVk, &src));
const uint8_t *srcBytes = reinterpret_cast<const uint8_t *>(src);
srcBytes += binding.getOffset();
ASSERT(GetVertexInputAlignment(*mCurrentArrayBufferFormats[attribIndex]) <=
kMaxVertexFormatAlignment);
ANGLE_TRY(StreamVertexData(contextVk, &mCurrentArrayBufferConversion[attribIndex], srcBytes,
numVertices * dstFormatSize, 0, numVertices, binding.getStride(),
mCurrentArrayBufferFormats[attribIndex]->vertexLoadFunction,
......@@ -455,6 +459,8 @@ angle::Result VertexArrayVk::updateClientAttribs(const gl::Context *context,
drawCallParams.firstVertex() * binding.getStride();
size_t destOffset = drawCallParams.firstVertex() * mCurrentArrayBufferStrides[attribIndex];
ASSERT(GetVertexInputAlignment(*mCurrentArrayBufferFormats[attribIndex]) <=
kMaxVertexFormatAlignment);
// Only vertexCount() vertices will be used by the upcoming draw. so that is all we copy.
// We allocate space for firstVertex() + vertexCount() so indexing will work. If we
......
......@@ -305,9 +305,6 @@ class VertexAttributeTest : public ANGLETest
TEST_P(VertexAttributeTest, UnsignedByteUnnormalized)
{
// TODO: Support this test on Vulkan. http://anglebug.com/2797
ANGLE_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
std::array<GLubyte, kVertexCount> inputData = {
{0, 1, 2, 3, 4, 5, 6, 7, 125, 126, 127, 128, 129, 250, 251, 252, 253, 254, 255}};
std::array<GLfloat, kVertexCount> expectedData;
......@@ -324,7 +321,6 @@ TEST_P(VertexAttributeTest, UnsignedByteUnnormalized)
TEST_P(VertexAttributeTest, UnsignedByteNormalized)
{
// TODO: Support this test on Vulkan. http://anglebug.com/2797
ANGLE_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
std::array<GLubyte, kVertexCount> inputData = {
......@@ -342,9 +338,6 @@ TEST_P(VertexAttributeTest, UnsignedByteNormalized)
TEST_P(VertexAttributeTest, ByteUnnormalized)
{
// TODO: Support this test on Vulkan. http://anglebug.com/2797
ANGLE_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
std::array<GLbyte, kVertexCount> inputData = {
{0, 1, 2, 3, 4, -1, -2, -3, -4, 125, 126, 127, -128, -127, -126}};
std::array<GLfloat, kVertexCount> expectedData;
......@@ -360,7 +353,6 @@ TEST_P(VertexAttributeTest, ByteUnnormalized)
TEST_P(VertexAttributeTest, ByteNormalized)
{
// TODO: Support this test on Vulkan. http://anglebug.com/2797
ANGLE_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
std::array<GLbyte, kVertexCount> inputData = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment