Hash :
251ba5cb
Author :
Date :
2020-12-03T15:55:47
Vulkan: Fix transform feedback with in-render-pass clears An in-render-pass clear now pauses transform feedback so it wouldn't contribute to it. Since it's not possible to resume the transform feedback in the same render pass (as it needs a memory barrier for its counter buffer), the render pass is broken after the clear. Bug: angleproject:5426 Change-Id: I1eaf8c153d076bd912a4a08c65960c12f00341ef Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2573579 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
ANGLE emulates transform feedback using the vertexPipelineStoresAndAtomics features in Vulkan. But some GPU vendors do not support these atomics. Also the emulation becomes more difficult in GLES 3.2. Therefore ANGLE must support using the VK_EXT_transform_feedback extension.
We also expect a performance gain when we use this extension.
The Vulkan extension does not provide separate APIs for glPauseTransformFeedback /
glEndTransformFeedback.
Instead, Vulkan introduced Counter buffers in vkCmdBeginTransformFeedbackEXT /
vkCmdEndTransformFeedbackEXT as API parameters.
To pause, we call vkCmdEndTransformFeedbackEXT and provide valid buffer handles in the
pCounterBuffers array and valid offsets in the pCounterBufferOffsets array for the
implementation to save the resume points.
Then to resume, we call vkCmdBeginTransformFeedbackEXT with the previous pCounterBuffers
and pCounterBufferOffsets values.
Between the pause and resume there needs to be a memory barrier for the counter buffers with a
source access of VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT at pipeline stage
VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT to a destination access of
VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT at pipeline stage
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT.
There is no equivalent function for glTransformFeedbackVaryings in Vulkan. The Vulkan specification states that the last vertex processing stage shader must be declared with the XFB execution mode.
The SPIR-V transformer takes care of adding this execution mode, as well as decorating the variables that need to be captured.
ANGLE modifies gl_position.z in vertex shader for the Vulkan coordinate system. So, if we capture
the value of ‘gl_position’ in the XFB buffer, the captured values will be incorrect. To resolve
this, we declare an internal position varying and copy the value from ‘gl_position’. We capture the
internal position varying during transform feedback operation. For simplicity, we do this for every
captured varying, even though we could decorate the gl_PerVertex struct members in SPIR-V
directly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# Transform Feedback via extension
## Outline
ANGLE emulates transform feedback using the vertexPipelineStoresAndAtomics features in Vulkan.
But some GPU vendors do not support these atomics. Also the emulation becomes more difficult in
GLES 3.2. Therefore ANGLE must support using the VK_EXT_transform_feedback extension.
We also expect a performance gain when we use this extension.
## Implementation of Pause/Resume using CounterBuffer
The Vulkan extension does not provide separate APIs for `glPauseTransformFeedback` /
`glEndTransformFeedback`.
Instead, Vulkan introduced Counter buffers in `vkCmdBeginTransformFeedbackEXT` /
`vkCmdEndTransformFeedbackEXT` as API parameters.
To pause, we call `vkCmdEndTransformFeedbackEXT` and provide valid buffer handles in the
`pCounterBuffers` array and valid offsets in the `pCounterBufferOffsets` array for the
implementation to save the resume points.
Then to resume, we call `vkCmdBeginTransformFeedbackEXT` with the previous `pCounterBuffers`
and `pCounterBufferOffsets` values.
Between the pause and resume there needs to be a memory barrier for the counter buffers with a
source access of `VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT` at pipeline stage
`VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT` to a destination access of
`VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT` at pipeline stage
`VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT`.
## Implementation of glTransformFeedbackVaryings
There is no equivalent function for glTransformFeedbackVaryings in Vulkan. The Vulkan specification
states that the last vertex processing stage shader must be declared with the XFB execution mode.
The SPIR-V transformer takes care of adding this execution mode, as well as decorating the variables
that need to be captured.
ANGLE modifies gl_position.z in vertex shader for the Vulkan coordinate system. So, if we capture
the value of 'gl_position' in the XFB buffer, the captured values will be incorrect. To resolve
this, we declare an internal position varying and copy the value from 'gl_position'. We capture the
internal position varying during transform feedback operation. For simplicity, we do this for every
captured varying, even though we could decorate the `gl_PerVertex` struct members in SPIR-V
directly.