Files
citra/src/video_core/rasterizer_cache/utils.h
GPUCode eaf62eb635 renderer_vulkan: Rework format handling
* This is a pretty large commit that aims to solve some issues with the current format system
* The instance now builds at application initialization an array of format traits for each pixel format
  that includes information such as blit/attachment/storage support and fallback formats
* The runtime doesn't ask the instance for formats but receives these traits and can dedice on its own what to build
  For now we do the same as before, we require both blit and attachment support

* Morton swizzling also sees many bug fixes. The previous code was very hacky and didn't work for partial
  texture updates. It was also inconsistent, as it would take a tiled_buffer and write to the middle of linear
* Now the functions have been greatly simplified and adjusted to work better with std::span. This fixes out of bounds
  errors and texture glitches (like the display in Mario Kart 7)
2022-12-25 22:07:46 +02:00

88 lines
2.6 KiB
C++

// Copyright 2022 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <span>
#include "common/hash.h"
#include "video_core/rasterizer_cache/pixel_format.h"
#include "video_core/rasterizer_cache/types.h"
namespace VideoCore {
struct HostTextureTag {
PixelFormat format{};
u32 width = 0;
u32 height = 0;
u32 layers = 1;
auto operator<=>(const HostTextureTag&) const noexcept = default;
const u64 Hash() const {
return Common::ComputeHash64(this, sizeof(HostTextureTag));
}
};
struct TextureCubeConfig {
PAddr px;
PAddr nx;
PAddr py;
PAddr ny;
PAddr pz;
PAddr nz;
u32 width;
Pica::TexturingRegs::TextureFormat format;
auto operator<=>(const TextureCubeConfig&) const noexcept = default;
const u64 Hash() const {
return Common::ComputeHash64(this, sizeof(TextureCubeConfig));
}
};
class SurfaceParams;
[[nodiscard]] ClearValue MakeClearValue(SurfaceType type, PixelFormat format, const u8* fill_data);
/**
* Converts a morton swizzled texture to linear format.
*
* @param unswizzle_info Structure used to query the surface information.
* @param start_addr The start address of the source_tiled data.
* @param end_addr The end address of the source_tiled data.
* @param source_tiled The tiled data to convert.
* @param dest_linear The output buffer where the generated linear data will be written to.
*/
void UnswizzleTexture(const SurfaceParams& unswizzle_info, PAddr start_addr, PAddr end_addr,
std::span<std::byte> source_tiled, std::span<std::byte> dest_linear);
/**
* Swizzles a linear texture according to the morton code.
*
* @param swizzle_info Structure used to query the surface information.
* @param start_addr The start address of the dest_tiled data.
* @param end_addr The end address of the dest_tiled data.
* @param source_tiled The source morton swizzled data.
* @param dest_linear The output buffer where the generated linear data will be written to.
*/
void SwizzleTexture(const SurfaceParams& swizzle_info, PAddr start_addr, PAddr end_addr,
std::span<std::byte> source_linear, std::span<std::byte> dest_tiled);
} // namespace VideoCore
namespace std {
template <>
struct hash<VideoCore::HostTextureTag> {
std::size_t operator()(const VideoCore::HostTextureTag& tag) const noexcept {
return tag.Hash();
}
};
template <>
struct hash<VideoCore::TextureCubeConfig> {
std::size_t operator()(const VideoCore::TextureCubeConfig& config) const noexcept {
return config.Hash();
}
};
} // namespace std