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