• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // TransformFeedbackVk.h:
7 //    Defines the class interface for TransformFeedbackVk, implementing TransformFeedbackImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_TRANSFORMFEEDBACKVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_TRANSFORMFEEDBACKVK_H_
12 
13 #include "libANGLE/renderer/TransformFeedbackImpl.h"
14 
15 #include "libANGLE/renderer/vulkan/vk_helpers.h"
16 
17 namespace gl
18 {
19 class ProgramState;
20 }  // namespace gl
21 
22 namespace rx
23 {
24 class UpdateDescriptorSetsBuilder;
25 class ShaderInterfaceVariableInfoMap;
26 
27 namespace vk
28 {
29 class DescriptorSetLayoutDesc;
30 }  // namespace vk
31 
32 class TransformFeedbackVk : public TransformFeedbackImpl, public angle::ObserverInterface
33 {
34   public:
35     TransformFeedbackVk(const gl::TransformFeedbackState &state);
36     ~TransformFeedbackVk() override;
37     void onDestroy(const gl::Context *context) override;
38 
39     angle::Result begin(const gl::Context *context, gl::PrimitiveMode primitiveMode) override;
40     angle::Result end(const gl::Context *context) override;
41     angle::Result pause(const gl::Context *context) override;
42     angle::Result resume(const gl::Context *context) override;
43 
44     angle::Result bindIndexedBuffer(const gl::Context *context,
45                                     size_t index,
46                                     const gl::OffsetBindingPointer<gl::Buffer> &binding) override;
47 
48     void updateDescriptorSetLayout(ContextVk *contextVk,
49                                    const ShaderInterfaceVariableInfoMap &variableInfoMap,
50                                    size_t xfbBufferCount,
51                                    vk::DescriptorSetLayoutDesc *descSetLayoutOut) const;
52     void getBufferOffsets(ContextVk *contextVk,
53                           GLint drawCallFirstVertex,
54                           int32_t *offsetsOut,
55                           size_t offsetsSize) const;
56 
getAndResetBufferRebindState()57     bool getAndResetBufferRebindState()
58     {
59         bool retVal                    = mRebindTransformFeedbackBuffer;
60         mRebindTransformFeedbackBuffer = false;
61         return retVal;
62     }
63 
getBufferHelpers()64     const gl::TransformFeedbackBuffersArray<vk::BufferHelper *> &getBufferHelpers() const
65     {
66         return mBufferHelpers;
67     }
68 
getBufferHandles()69     const gl::TransformFeedbackBuffersArray<VkBuffer> &getBufferHandles() const
70     {
71         return mBufferHandles;
72     }
73 
getBufferOffsets()74     const gl::TransformFeedbackBuffersArray<VkDeviceSize> &getBufferOffsets() const
75     {
76         return mBufferOffsets;
77     }
78 
getBufferSizes()79     const gl::TransformFeedbackBuffersArray<VkDeviceSize> &getBufferSizes() const
80     {
81         return mBufferSizes;
82     }
83 
getCounterBufferHelpers()84     gl::TransformFeedbackBuffersArray<vk::BufferHelper> &getCounterBufferHelpers()
85     {
86         return mCounterBufferHelpers;
87     }
88 
getCounterBufferHandles()89     const gl::TransformFeedbackBuffersArray<VkBuffer> &getCounterBufferHandles() const
90     {
91         return mCounterBufferHandles;
92     }
93 
94     void updateTransformFeedbackDescriptorDesc(
95         const vk::Context *context,
96         const gl::ProgramExecutable &executable,
97         const ShaderInterfaceVariableInfoMap &variableInfoMap,
98         const vk::WriteDescriptorDescs &writeDescriptorDescs,
99         const vk::BufferHelper &emptyBuffer,
100         bool activeUnpaused,
101         vk::DescriptorSetDescBuilder *builder) const;
102 
getCounterBufferOffsets()103     const gl::TransformFeedbackBuffersArray<VkDeviceSize> &getCounterBufferOffsets() const
104     {
105         return mCounterBufferOffsets;
106     }
107 
108     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
109 
110     void onNewDescriptorSet(const gl::ProgramExecutable &executable,
111                             const vk::SharedDescriptorSetCacheKey &sharedCacheKey);
112 
113   private:
114     void initializeXFBVariables(ContextVk *contextVk, uint32_t xfbBufferCount);
115 
116     void releaseCounterBuffers(RendererVk *renderer);
117 
118     // This member variable is set when glBindTransformFeedbackBuffers/glBeginTransformFeedback
119     // is called and unset in dirty bit handler for transform feedback state change. If this
120     // value is true, vertex shader will record transform feedback varyings from the beginning
121     // of the buffer.
122     bool mRebindTransformFeedbackBuffer;
123 
124     gl::TransformFeedbackBuffersArray<vk::BufferHelper *> mBufferHelpers;
125     gl::TransformFeedbackBuffersArray<VkBuffer> mBufferHandles;
126     gl::TransformFeedbackBuffersArray<VkDeviceSize> mBufferOffsets;
127     gl::TransformFeedbackBuffersArray<VkDeviceSize> mBufferSizes;
128 
129     // Counter buffer used for pause and resume.
130     gl::TransformFeedbackBuffersArray<vk::BufferHelper> mCounterBufferHelpers;
131     gl::TransformFeedbackBuffersArray<VkBuffer> mCounterBufferHandles;
132     gl::TransformFeedbackBuffersArray<VkDeviceSize> mCounterBufferOffsets;
133 
134     // Buffer binding points
135     std::vector<angle::ObserverBinding> mBufferObserverBindings;
136 };
137 
138 }  // namespace rx
139 
140 #endif  // LIBANGLE_RENDERER_VULKAN_TRANSFORMFEEDBACKVK_H_
141