decoders.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. constexpr u32 GOB_SIZE_X = 64;
  10. constexpr u32 GOB_SIZE_Y = 8;
  11. constexpr u32 GOB_SIZE_Z = 1;
  12. constexpr u32 GOB_SIZE = GOB_SIZE_X * GOB_SIZE_Y * GOB_SIZE_Z;
  13. constexpr std::size_t GOB_SIZE_X_SHIFT = 6;
  14. constexpr std::size_t GOB_SIZE_Y_SHIFT = 3;
  15. constexpr std::size_t GOB_SIZE_Z_SHIFT = 0;
  16. constexpr std::size_t GOB_SIZE_SHIFT = GOB_SIZE_X_SHIFT + GOB_SIZE_Y_SHIFT + GOB_SIZE_Z_SHIFT;
  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, const u8* unswizzled_data,
  41. u32 block_height_bit, 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. /// @brief Swizzles a 2D array of pixels into a 3D texture
  47. /// @param line_length_in Number of pixels per line
  48. /// @param line_count Number of lines
  49. /// @param pitch Number of bytes per line
  50. /// @param width Width of the swizzled texture
  51. /// @param height Height of the swizzled texture
  52. /// @param bytes_per_pixel Number of bytes used per pixel
  53. /// @param block_height Block height shift
  54. /// @param block_depth Block depth shift
  55. /// @param origin_x Column offset in pixels of the swizzled texture
  56. /// @param origin_y Row offset in pixels of the swizzled texture
  57. /// @param output Pointer to the pixels of the swizzled texture
  58. /// @param input Pointer to the 2D array of pixels used as input
  59. /// @pre input and output points to an array large enough to hold the number of bytes used
  60. void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 height,
  61. u32 bytes_per_pixel, u32 block_height, u32 block_depth, u32 origin_x,
  62. u32 origin_y, u8* output, const u8* input);
  63. void SwizzleKepler(u32 width, u32 height, u32 dst_x, u32 dst_y, u32 block_height,
  64. std::size_t copy_size, const u8* source_data, u8* swizzle_data);
  65. /// Obtains the offset of the gob for positions 'dst_x' & 'dst_y'
  66. u64 GetGOBOffset(u32 width, u32 height, u32 dst_x, u32 dst_y, u32 block_height,
  67. u32 bytes_per_pixel);
  68. } // namespace Tegra::Texture