decoders.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "common/common_types.h"
  7. #include "video_core/textures/texture.h"
  8. namespace Tegra::Texture {
  9. // GOBSize constant. Calculated by 64 bytes in x multiplied by 8 y coords, represents
  10. // an small rect of (64/bytes_per_pixel)X8.
  11. inline std::size_t GetGOBSize() {
  12. return 512;
  13. }
  14. inline std::size_t GetGOBSizeShift() {
  15. return 9;
  16. }
  17. /// Unswizzles a swizzled texture without changing its format.
  18. void UnswizzleTexture(u8* unswizzled_data, u8* address, u32 tile_size_x, u32 tile_size_y,
  19. u32 bytes_per_pixel, u32 width, u32 height, u32 depth,
  20. u32 block_height = TICEntry::DefaultBlockHeight,
  21. u32 block_depth = TICEntry::DefaultBlockHeight, u32 width_spacing = 0);
  22. /// Unswizzles a swizzled texture without changing its format.
  23. std::vector<u8> UnswizzleTexture(u8* address, u32 tile_size_x, u32 tile_size_y, u32 bytes_per_pixel,
  24. u32 width, u32 height, u32 depth,
  25. u32 block_height = TICEntry::DefaultBlockHeight,
  26. u32 block_depth = TICEntry::DefaultBlockHeight,
  27. u32 width_spacing = 0);
  28. /// Copies texture data from a buffer and performs swizzling/unswizzling as necessary.
  29. void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel,
  30. u32 out_bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data,
  31. bool unswizzle, u32 block_height, u32 block_depth, u32 width_spacing);
  32. /// Decodes an unswizzled texture into a A8R8G8B8 texture.
  33. std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
  34. u32 height);
  35. /// This function calculates the correct size of a texture depending if it's tiled or not.
  36. std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth,
  37. u32 block_height, u32 block_depth);
  38. /// Copies an untiled subrectangle into a tiled surface.
  39. void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width,
  40. u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height,
  41. u32 offset_x, u32 offset_y);
  42. /// Copies a tiled subrectangle into a linear surface.
  43. void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width,
  44. u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height,
  45. u32 offset_x, u32 offset_y);
  46. void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 dst_y,
  47. const u32 block_height, const std::size_t copy_size, const u8* source_data,
  48. u8* swizzle_data);
  49. } // namespace Tegra::Texture