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/glslang_wrapper_utils.h" 16 #include "libANGLE/renderer/vulkan/vk_helpers.h" 17 18 namespace gl 19 { 20 class ProgramState; 21 } // namespace gl 22 23 namespace rx 24 { 25 namespace vk 26 { 27 class DescriptorSetLayoutDesc; 28 } 29 30 class TransformFeedbackVk : public TransformFeedbackImpl 31 { 32 public: 33 TransformFeedbackVk(const gl::TransformFeedbackState &state); 34 ~TransformFeedbackVk() override; 35 void onDestroy(const gl::Context *context) override; 36 37 angle::Result begin(const gl::Context *context, gl::PrimitiveMode primitiveMode) override; 38 angle::Result end(const gl::Context *context) override; 39 angle::Result pause(const gl::Context *context) override; 40 angle::Result resume(const gl::Context *context) override; 41 42 angle::Result bindIndexedBuffer(const gl::Context *context, 43 size_t index, 44 const gl::OffsetBindingPointer<gl::Buffer> &binding) override; 45 46 void updateDescriptorSetLayout(ContextVk *contextVk, 47 const ShaderInterfaceVariableInfoMap &variableInfoMap, 48 size_t xfbBufferCount, 49 vk::DescriptorSetLayoutDesc *descSetLayoutOut) const; 50 void initDescriptorSet(ContextVk *contextVk, 51 const ShaderInterfaceVariableInfoMap &variableInfoMap, 52 size_t xfbBufferCount, 53 VkDescriptorSet descSet) const; 54 void updateDescriptorSet(ContextVk *contextVk, 55 const gl::ProgramState &programState, 56 const ShaderInterfaceVariableInfoMap &variableInfoMap, 57 VkDescriptorSet descSet) const; 58 void getBufferOffsets(ContextVk *contextVk, 59 GLint drawCallFirstVertex, 60 int32_t *offsetsOut, 61 size_t offsetsSize) const; 62 getAndResetBufferRebindState()63 bool getAndResetBufferRebindState() 64 { 65 bool retVal = mRebindTransformFeedbackBuffer; 66 mRebindTransformFeedbackBuffer = false; 67 return retVal; 68 } 69 getBufferHelpers()70 const gl::TransformFeedbackBuffersArray<vk::BufferHelper *> &getBufferHelpers() const 71 { 72 return mBufferHelpers; 73 } 74 getBufferHandles()75 const gl::TransformFeedbackBuffersArray<VkBuffer> &getBufferHandles() const 76 { 77 return mBufferHandles; 78 } 79 getBufferOffsets()80 const gl::TransformFeedbackBuffersArray<VkDeviceSize> &getBufferOffsets() const 81 { 82 return mBufferOffsets; 83 } 84 getBufferSizes()85 const gl::TransformFeedbackBuffersArray<VkDeviceSize> &getBufferSizes() const 86 { 87 return mBufferSizes; 88 } 89 getCounterBufferHelpers()90 gl::TransformFeedbackBuffersArray<vk::BufferHelper> &getCounterBufferHelpers() 91 { 92 return mCounterBufferHelpers; 93 } 94 getCounterBufferHandles()95 const gl::TransformFeedbackBuffersArray<VkBuffer> &getCounterBufferHandles() const 96 { 97 return mCounterBufferHandles; 98 } 99 getTransformFeedbackDesc()100 vk::UniformsAndXfbDescriptorDesc &getTransformFeedbackDesc() { return mXFBBuffersDesc; } 101 102 private: 103 void writeDescriptorSet(ContextVk *contextVk, 104 const ShaderInterfaceVariableInfoMap &variableInfoMap, 105 size_t xfbBufferCount, 106 VkDescriptorBufferInfo *bufferInfo, 107 VkDescriptorSet descSet) const; 108 109 void initializeXFBBuffersDesc(ContextVk *contextVk, size_t xfbBufferCount); 110 111 void releaseCounterBuffers(RendererVk *renderer); 112 113 // This member variable is set when glBindTransformFeedbackBuffers/glBeginTransformFeedback 114 // is called and unset in dirty bit handler for transform feedback state change. If this 115 // value is true, vertex shader will record transform feedback varyings from the beginning 116 // of the buffer. 117 bool mRebindTransformFeedbackBuffer; 118 119 gl::TransformFeedbackBuffersArray<vk::BufferHelper *> mBufferHelpers; 120 gl::TransformFeedbackBuffersArray<VkBuffer> mBufferHandles; 121 gl::TransformFeedbackBuffersArray<VkDeviceSize> mBufferOffsets; 122 gl::TransformFeedbackBuffersArray<VkDeviceSize> mBufferSizes; 123 124 // Aligned offset for emulation. Could be smaller than offset. 125 gl::TransformFeedbackBuffersArray<VkDeviceSize> mAlignedBufferOffsets; 126 127 // Counter buffer used for pause and resume. 128 gl::TransformFeedbackBuffersArray<vk::BufferHelper> mCounterBufferHelpers; 129 gl::TransformFeedbackBuffersArray<VkBuffer> mCounterBufferHandles; 130 131 // Keys to look up in the descriptor set cache 132 vk::UniformsAndXfbDescriptorDesc mXFBBuffersDesc; 133 }; 134 135 } // namespace rx 136 137 #endif // LIBANGLE_RENDERER_VULKAN_TRANSFORMFEEDBACKVK_H_ 138