summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/TextureEncoder.h
blob: c3fa68c7529a26ce0c283f3066d8c277975af48c (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <memory>

#include "Common/CommonTypes.h"
#include "VideoBackends/Vulkan/VulkanLoader.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/VideoCommon.h"

namespace Vulkan
{
class StagingTexture2D;
class Texture2D;

class TextureEncoder
{
public:
  TextureEncoder();
  ~TextureEncoder();

  VkRenderPass GetEncodingRenderPass() const { return m_encoding_render_pass; }
  Texture2D* GetEncodingTexture() const { return m_encoding_texture.get(); }
  VkFramebuffer GetEncodingTextureFramebuffer() const { return m_encoding_texture_framebuffer; }
  StagingTexture2D* GetDownloadTexture() const { return m_download_texture.get(); }
  bool Initialize();

  // Uses an encoding shader to copy src_texture to dest_ptr.
  // Assumes that no render pass is currently in progress.
  // WARNING: Executes the current command buffer.
  void EncodeTextureToRam(VkImageView src_texture, u8* dest_ptr, u32 format, u32 native_width,
                          u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
                          PEControl::PixelFormat src_format, bool is_intensity, int scale_by_half,
                          const EFBRectangle& source);

private:
  // From OGL.
  static const u32 NUM_TEXTURE_ENCODING_SHADERS = 64;
  static const u32 ENCODING_TEXTURE_WIDTH = EFB_WIDTH * 4;
  static const u32 ENCODING_TEXTURE_HEIGHT = 1024;
  static const VkFormat ENCODING_TEXTURE_FORMAT = VK_FORMAT_B8G8R8A8_UNORM;

  bool CompileShaders();
  bool CreateEncodingRenderPass();
  bool CreateEncodingTexture();
  bool CreateDownloadTexture();

  std::array<VkShaderModule, NUM_TEXTURE_ENCODING_SHADERS> m_texture_encoding_shaders = {};

  VkRenderPass m_encoding_render_pass = VK_NULL_HANDLE;

  std::unique_ptr<Texture2D> m_encoding_texture;
  VkFramebuffer m_encoding_texture_framebuffer = VK_NULL_HANDLE;

  std::unique_ptr<StagingTexture2D> m_download_texture;
};

}  // namespace Vulkan