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 // RenderTargetVk: 7 // Wrapper around a Vulkan renderable resource, using an ImageView. 8 // 9 10 #ifndef LIBANGLE_RENDERER_VULKAN_RENDERTARGETVK_H_ 11 #define LIBANGLE_RENDERER_VULKAN_RENDERTARGETVK_H_ 12 13 #include "volk.h" 14 15 #include "libANGLE/FramebufferAttachment.h" 16 #include "libANGLE/renderer/renderer_utils.h" 17 #include "libANGLE/renderer/vulkan/vk_helpers.h" 18 19 namespace rx 20 { 21 namespace vk 22 { 23 struct Format; 24 class FramebufferHelper; 25 class ImageHelper; 26 class ImageView; 27 class Resource; 28 class RenderPassDesc; 29 } // namespace vk 30 31 class ContextVk; 32 class TextureVk; 33 34 // This is a very light-weight class that does not own to the resources it points to. 35 // It's meant only to copy across some information from a FramebufferAttachment to the 36 // business rendering logic. It stores Images and ImageViews by pointer for performance. 37 class RenderTargetVk final : public FramebufferAttachmentRenderTarget 38 { 39 public: 40 RenderTargetVk(); 41 ~RenderTargetVk() override; 42 43 // Used in std::vector initialization. 44 RenderTargetVk(RenderTargetVk &&other); 45 46 void init(vk::ImageHelper *image, 47 vk::ImageViewHelper *imageViews, 48 uint32_t levelIndex, 49 uint32_t layerIndex); 50 void reset(); 51 // This returns the serial from underlying ImageHelper, first assigning one if required 52 vk::AttachmentSerial getAssignSerial(ContextVk *contextVk); 53 54 // Note: RenderTargets should be called in order, with the depth/stencil onRender last. 55 angle::Result onColorDraw(ContextVk *contextVk); 56 angle::Result onDepthStencilDraw(ContextVk *contextVk); 57 58 vk::ImageHelper &getImage(); 59 const vk::ImageHelper &getImage() const; 60 61 // getImageForRead will also transition the resource to the given layout. 62 vk::ImageHelper *getImageForWrite(ContextVk *contextVk) const; 63 64 // For cube maps we use single-level single-layer 2D array views. 65 angle::Result getImageView(ContextVk *contextVk, const vk::ImageView **imageViewOut) const; 66 67 const vk::Format &getImageFormat() const; 68 gl::Extents getExtents() const; getLevelIndex()69 uint32_t getLevelIndex() const { return mLevelIndex; } getLayerIndex()70 uint32_t getLayerIndex() const { return mLayerIndex; } 71 72 // Special mutator for Surface RenderTargets. Allows the Framebuffer to keep a single 73 // RenderTargetVk pointer. 74 void updateSwapchainImage(vk::ImageHelper *image, vk::ImageViewHelper *imageViews); 75 76 angle::Result flushStagedUpdates(ContextVk *contextVk); 77 78 void retainImageViews(ContextVk *contextVk) const; 79 hasDefinedContent()80 bool hasDefinedContent() const { return mContentDefined; } 81 // mark content as undefined so that certain optimizations are possible invalidateContent()82 void invalidateContent() { mContentDefined = false; } 83 84 private: 85 vk::ImageHelper *mImage; 86 vk::ImageViewHelper *mImageViews; 87 uint32_t mLevelIndex; 88 uint32_t mLayerIndex; 89 // Right now we are only tracking depth/stencil buffer. We could expand it to cover color 90 // buffers if needed in future. 91 bool mContentDefined; 92 }; 93 94 // A vector of rendertargets 95 using RenderTargetVector = std::vector<RenderTargetVk>; 96 97 } // namespace rx 98 99 #endif // LIBANGLE_RENDERER_VULKAN_RENDERTARGETVK_H_ 100