Skip to content

Commit b1fc47c

Browse files
cclaoAngle LUCI CQ
authored andcommitted
Vulkan: add check for vertexAttributeInstanceRateZeroDivisor
Allow zero divisor for vertex attributes when mVertexAttributeDivisorFeaturesmVertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor is true. Bug: b/439073246 Change-Id: I68705faffcefb38360f6fbcf5d937d1d902180aa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6961233 Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 parent 17c0d10 commit b1fc47c

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/libANGLE/renderer/vulkan/VertexArrayVk.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,28 @@ VertexArrayVk::VertexArrayVk(ContextVk *contextVk,
313313
mVertexInputAttribDesc{},
314314
mCurrentElementArrayBuffer(nullptr),
315315
mLineLoopHelper(contextVk->getRenderer()),
316-
mDirtyLineLoopTranslation(true),
317-
mAllowZeroDivisor(!contextVk->getFeatures().supportsVertexInputDynamicState.enabled)
316+
mDirtyLineLoopTranslation(true)
318317
{
319318
vk::BufferHelper &emptyBuffer = contextVk->getEmptyBuffer();
320319

321320
mCurrentArrayBufferHandles.fill(emptyBuffer.getBuffer().getHandle());
322321
mCurrentArrayBufferOffsets.fill(0);
323322
mCurrentArrayBuffers.fill(&emptyBuffer);
324323

325-
GLuint divisor = mAllowZeroDivisor ? 0 : 1;
324+
// Divisor value is ignored by the implementation when using VK_VERTEX_INPUT_RATE_VERTEX, but it
325+
// is set to 1 to avoid a validation error due to a validation layer issue.
326+
mZeroDivisor =
327+
contextVk->getRenderer()->isVertexAttributeInstanceRateZeroDivisorAllowed() ? 0 : 1;
328+
326329
for (uint32_t attribIndex = 0; attribIndex < mVertexInputBindingDesc.size(); attribIndex++)
327330
{
328331
mVertexInputBindingDesc[attribIndex] = VkVertexInputBindingDescription2EXT{
329-
VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT, nullptr, attribIndex, 0,
330-
static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_VERTEX), divisor};
332+
VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT,
333+
nullptr,
334+
attribIndex,
335+
0,
336+
static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_VERTEX),
337+
mZeroDivisor};
331338
}
332339

333340
for (uint32_t attribIndex = 0; attribIndex < mVertexInputAttribDesc.size(); attribIndex++)
@@ -1556,23 +1563,17 @@ ANGLE_INLINE void VertexArrayVk::setVertexInputBindingDescDivisor(vk::Renderer *
15561563
size_t attribIndex,
15571564
GLuint divisor)
15581565
{
1559-
mVertexInputBindingDesc[attribIndex].divisor = divisor;
15601566
if (divisor != 0)
15611567
{
15621568
mVertexInputBindingDesc[attribIndex].inputRate =
15631569
static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_INSTANCE);
1570+
mVertexInputBindingDesc[attribIndex].divisor = divisor;
15641571
}
15651572
else
15661573
{
15671574
mVertexInputBindingDesc[attribIndex].inputRate =
15681575
static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_VERTEX);
1569-
if (!mAllowZeroDivisor)
1570-
{
1571-
// Divisor value is ignored by the implementation when using
1572-
// VK_VERTEX_INPUT_RATE_VERTEX, but it is set to 1 to avoid a validation error
1573-
// due to a validation layer issue.
1574-
mVertexInputBindingDesc[attribIndex].divisor = 1;
1575-
}
1576+
mVertexInputBindingDesc[attribIndex].divisor = mZeroDivisor;
15761577
}
15771578
}
15781579
} // namespace rx

src/libANGLE/renderer/vulkan/VertexArrayVk.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ class VertexArrayVk : public VertexArrayImpl
265265
gl::VertexArray::DirtyBindingBits mBindingDirtyBitsRequiresPipelineUpdate;
266266
gl::VertexArray::DirtyAttribBits mAttribDirtyBitsRequiresPipelineUpdate;
267267

268-
bool mAllowZeroDivisor;
268+
// This maybe 0 or 1 depends on feature bit
269+
uint32_t mZeroDivisor;
269270
};
270271
} // namespace rx
271272

src/libANGLE/renderer/vulkan/vk_renderer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,12 @@ class Renderer : angle::NonCopyable
720720
uint32_t getPreferredVectorWidthDouble() const { return mPreferredVectorWidthDouble; }
721721
uint32_t getPreferredVectorWidthHalf() const { return mPreferredVectorWidthHalf; }
722722

723+
bool isVertexAttributeInstanceRateZeroDivisorAllowed() const
724+
{
725+
return !mFeatures.supportsVertexInputDynamicState.enabled ||
726+
mVertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor == VK_TRUE;
727+
}
728+
723729
private:
724730
angle::Result setupDevice(vk::ErrorContext *context,
725731
const angle::FeatureOverrides &featureOverrides,

0 commit comments

Comments
 (0)