2017-04-22 22:44:34 -06:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-04-22 22:44:34 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/MathUtil.h"
|
2017-06-12 11:37:28 -06:00
|
|
|
|
|
|
|
enum class AbstractTextureFormat : u32
|
|
|
|
{
|
|
|
|
RGBA8,
|
2017-09-08 23:24:41 -06:00
|
|
|
BGRA8,
|
2023-06-07 18:17:20 -06:00
|
|
|
RGB10_A2,
|
|
|
|
RGBA16F,
|
2017-06-12 11:37:28 -06:00
|
|
|
DXT1,
|
|
|
|
DXT3,
|
2017-07-27 06:00:04 -06:00
|
|
|
DXT5,
|
2017-09-08 23:24:41 -06:00
|
|
|
BPTC,
|
2018-01-21 06:59:19 -07:00
|
|
|
R16,
|
|
|
|
D16,
|
2018-07-16 21:22:48 -06:00
|
|
|
D24_S8,
|
2018-01-21 06:59:19 -07:00
|
|
|
R32F,
|
|
|
|
D32F,
|
|
|
|
D32F_S8,
|
2017-09-08 23:24:41 -06:00
|
|
|
Undefined
|
2017-06-12 11:37:28 -06:00
|
|
|
};
|
2017-04-22 22:44:34 -06:00
|
|
|
|
2017-10-21 08:49:40 -06:00
|
|
|
enum class StagingTextureType
|
|
|
|
{
|
|
|
|
Readback, // Optimize for CPU reads, GPU writes, no CPU writes
|
|
|
|
Upload, // Optimize for CPU writes, GPU reads, no CPU reads
|
|
|
|
Mutable // Optimize for CPU reads, GPU writes, allow slow CPU reads
|
|
|
|
};
|
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
enum AbstractTextureFlag : u32
|
|
|
|
{
|
|
|
|
AbstractTextureFlag_RenderTarget = (1 << 0), // Texture is used as a framebuffer.
|
|
|
|
AbstractTextureFlag_ComputeImage = (1 << 1), // Texture is used as a compute image.
|
2023-12-09 18:00:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class AbstractTextureType
|
|
|
|
{
|
|
|
|
Texture_2DArray, // Used as a 2D texture array
|
|
|
|
Texture_2D, // Used as a normal 2D texture
|
|
|
|
Texture_CubeMap, // Used as a cube map texture
|
2019-02-14 18:59:50 -07:00
|
|
|
};
|
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
struct TextureConfig
|
|
|
|
{
|
|
|
|
constexpr TextureConfig() = default;
|
2018-01-20 22:03:06 -07:00
|
|
|
constexpr TextureConfig(u32 width_, u32 height_, u32 levels_, u32 layers_, u32 samples_,
|
2023-12-09 18:00:11 -07:00
|
|
|
AbstractTextureFormat format_, u32 flags_, AbstractTextureType type_)
|
2018-01-20 22:03:06 -07:00
|
|
|
: width(width_), height(height_), levels(levels_), layers(layers_), samples(samples_),
|
2023-12-09 18:00:11 -07:00
|
|
|
format(format_), flags(flags_), type(type_)
|
2017-09-30 00:25:36 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:44:34 -06:00
|
|
|
bool operator==(const TextureConfig& o) const;
|
2017-10-21 08:49:40 -06:00
|
|
|
bool operator!=(const TextureConfig& o) const;
|
2017-04-22 22:44:34 -06:00
|
|
|
MathUtil::Rectangle<int> GetRect() const;
|
2017-10-21 08:49:40 -06:00
|
|
|
MathUtil::Rectangle<int> GetMipRect(u32 level) const;
|
|
|
|
size_t GetStride() const;
|
|
|
|
size_t GetMipStride(u32 level) const;
|
2019-02-14 18:59:50 -07:00
|
|
|
|
|
|
|
bool IsMultisampled() const { return samples > 1; }
|
|
|
|
bool IsRenderTarget() const { return (flags & AbstractTextureFlag_RenderTarget) != 0; }
|
|
|
|
bool IsComputeImage() const { return (flags & AbstractTextureFlag_ComputeImage) != 0; }
|
2017-04-22 22:44:34 -06:00
|
|
|
|
|
|
|
u32 width = 0;
|
|
|
|
u32 height = 0;
|
|
|
|
u32 levels = 1;
|
|
|
|
u32 layers = 1;
|
2018-01-20 22:03:06 -07:00
|
|
|
u32 samples = 1;
|
2017-06-12 11:37:28 -06:00
|
|
|
AbstractTextureFormat format = AbstractTextureFormat::RGBA8;
|
2019-02-14 18:59:50 -07:00
|
|
|
u32 flags = 0;
|
2023-12-09 18:00:11 -07:00
|
|
|
AbstractTextureType type = AbstractTextureType::Texture_2DArray;
|
2017-10-08 18:15:34 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2024-01-31 10:41:30 -07:00
|
|
|
struct std::hash<TextureConfig>
|
2017-10-08 18:15:34 -06:00
|
|
|
{
|
|
|
|
using argument_type = TextureConfig;
|
|
|
|
using result_type = size_t;
|
2017-04-22 22:44:34 -06:00
|
|
|
|
2017-10-08 18:15:34 -06:00
|
|
|
result_type operator()(const argument_type& c) const noexcept
|
2017-04-22 22:44:34 -06:00
|
|
|
{
|
2019-02-14 18:59:50 -07:00
|
|
|
const u64 id = static_cast<u64>(c.flags) << 58 | static_cast<u64>(c.format) << 50 |
|
2017-10-08 18:15:34 -06:00
|
|
|
static_cast<u64>(c.layers) << 48 | static_cast<u64>(c.levels) << 32 |
|
|
|
|
static_cast<u64>(c.height) << 16 | static_cast<u64>(c.width);
|
|
|
|
return std::hash<u64>{}(id);
|
|
|
|
}
|
2017-04-22 22:44:34 -06:00
|
|
|
};
|