mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
texture_cache: Handle compressed views of uncompressed images (#3056)
* pixel_format: Remove unused tables, refactor * host_compatibilty: Cleanup and support uncompressed views of compressed formats * texture_cache: Handle compressed views of uncompressed images * tile_manager: Bump max supported mips to 16 Fixes a crash during start * oops * texture_cache: Fix order of format compat check
This commit is contained in:
@@ -914,7 +914,7 @@ struct Liverpool {
|
||||
}
|
||||
|
||||
size_t GetColorSliceSize() const {
|
||||
const auto num_bytes_per_element = NumBits(info.format) / 8u;
|
||||
const auto num_bytes_per_element = NumBitsPerBlock(info.format) / 8u;
|
||||
const auto slice_size =
|
||||
num_bytes_per_element * (slice.tile_max + 1) * 64u * NumSamples();
|
||||
return slice_size;
|
||||
|
||||
@@ -111,136 +111,106 @@ std::string_view NameOf(NumberFormat fmt) {
|
||||
}
|
||||
}
|
||||
|
||||
int NumComponents(DataFormat format) {
|
||||
constexpr std::array num_components_per_element = {
|
||||
0, 1, 1, 2, 1, 2, 3, 3, 4, 4, 4, 2, 4, 3, 4, -1, 3, 4, 4, 4, 2,
|
||||
2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 4, 4, 4, 1, 2, 3, 4,
|
||||
-1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 1, 1};
|
||||
|
||||
const u32 index = static_cast<u32>(format);
|
||||
if (index >= num_components_per_element.size()) {
|
||||
return 0;
|
||||
}
|
||||
return num_components_per_element[index];
|
||||
}
|
||||
|
||||
int NumBits(DataFormat format) {
|
||||
const std::array num_bits_per_element = {
|
||||
0, 8, 16, 16, 32, 32, 32, 32, 32, 32, 32, 64, 64, 96, 128, -1, 16, 16, 16, 16, 32,
|
||||
32, 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 16, 32, 4, 8, 8, 4, 8, 8, 8,
|
||||
-1, -1, 8, 8, 8, 8, 8, 8, 16, 16, 32, 32, 32, 64, 64, 8, 16, 1, 1};
|
||||
|
||||
const u32 index = static_cast<u32>(format);
|
||||
if (index >= num_bits_per_element.size()) {
|
||||
return 0;
|
||||
}
|
||||
return num_bits_per_element[index];
|
||||
}
|
||||
|
||||
static constexpr std::array component_bits = {
|
||||
std::array{0, 0, 0, 0}, // 0 FormatInvalid
|
||||
std::array{8, 0, 0, 0}, // 1 Format8
|
||||
std::array{16, 0, 0, 0}, // 2 Format16
|
||||
std::array{8, 8, 0, 0}, // 3 Format8_8
|
||||
std::array{32, 0, 0, 0}, // 4 Format32
|
||||
std::array{16, 16, 0, 0}, // 5 Format16_16
|
||||
std::array{11, 11, 10, 0}, // 6 Format10_11_11
|
||||
std::array{10, 11, 11, 0}, // 7 Format11_11_10
|
||||
std::array{2, 10, 10, 10}, // 8 Format10_10_10_2
|
||||
std::array{10, 10, 10, 2}, // 9 Format2_10_10_10
|
||||
std::array{8, 8, 8, 8}, // 10 Format8_8_8_8
|
||||
std::array{32, 32, 0, 0}, // 11 Format32_32
|
||||
std::array{16, 16, 16, 16}, // 12 Format16_16_16_16
|
||||
std::array{32, 32, 32, 0}, // 13 Format32_32_32
|
||||
std::array{32, 32, 32, 32}, // 14 Format32_32_32_32
|
||||
std::array{0, 0, 0, 0}, // 15
|
||||
std::array{5, 6, 5, 0}, // 16 Format5_6_5
|
||||
std::array{5, 5, 5, 1}, // 17 Format1_5_5_5
|
||||
std::array{1, 5, 5, 5}, // 18 Format5_5_5_1
|
||||
std::array{4, 4, 4, 4}, // 19 Format4_4_4_4
|
||||
std::array{24, 8, 0, 0}, // 20 Format8_24
|
||||
std::array{8, 24, 0, 0}, // 21 Format24_8
|
||||
std::array{8, 24, 0, 0}, // 22 FormatX24_8_32
|
||||
std::array{0, 0, 0, 0}, // 23
|
||||
std::array{0, 0, 0, 0}, // 24
|
||||
std::array{0, 0, 0, 0}, // 25
|
||||
std::array{0, 0, 0, 0}, // 26
|
||||
std::array{0, 0, 0, 0}, // 27
|
||||
std::array{0, 0, 0, 0}, // 28
|
||||
std::array{0, 0, 0, 0}, // 29
|
||||
std::array{0, 0, 0, 0}, // 30
|
||||
std::array{0, 0, 0, 0}, // 31
|
||||
std::array{0, 0, 0, 0}, // 32 FormatGB_GR
|
||||
std::array{0, 0, 0, 0}, // 33 FormatBG_RG
|
||||
std::array{0, 0, 0, 0}, // 34 Format5_9_9_9
|
||||
std::array{0, 0, 0, 0}, // 35 FormatBc1
|
||||
std::array{0, 0, 0, 0}, // 36 FormatBc2
|
||||
std::array{0, 0, 0, 0}, // 37 FormatBc3
|
||||
std::array{0, 0, 0, 0}, // 38 FormatBc4
|
||||
std::array{0, 0, 0, 0}, // 39 FormatBc5
|
||||
std::array{0, 0, 0, 0}, // 40 FormatBc6
|
||||
std::array{0, 0, 0, 0}, // 41 FormatBc7
|
||||
static constexpr std::array NUM_COMPONENTS = {
|
||||
0, // 0 FormatInvalid
|
||||
1, // 1 Format8
|
||||
1, // 2 Format16
|
||||
2, // 3 Format8_8
|
||||
1, // 4 Format32
|
||||
2, // 5 Format16_16
|
||||
3, // 6 Format10_11_11
|
||||
3, // 7 Format11_11_10
|
||||
4, // 8 Format10_10_10_2
|
||||
4, // 9 Format2_10_10_10
|
||||
4, // 10 Format8_8_8_8
|
||||
2, // 11 Format32_32
|
||||
4, // 12 Format16_16_16_16
|
||||
3, // 13 Format32_32_32
|
||||
4, // 14 Format32_32_32_32
|
||||
0, // 15
|
||||
3, // 16 Format5_6_5
|
||||
4, // 17 Format1_5_5_5
|
||||
4, // 18 Format5_5_5_1
|
||||
4, // 19 Format4_4_4_4
|
||||
2, // 20 Format8_24
|
||||
2, // 21 Format24_8
|
||||
2, // 22 FormatX24_8_32
|
||||
0, // 23
|
||||
0, // 24
|
||||
0, // 25
|
||||
0, // 26
|
||||
0, // 27
|
||||
0, // 28
|
||||
0, // 29
|
||||
0, // 30
|
||||
0, // 31
|
||||
3, // 32 FormatGB_GR
|
||||
3, // 33 FormatBG_RG
|
||||
4, // 34 Format5_9_9_9
|
||||
4, // 35 FormatBc1
|
||||
4, // 36 FormatBc2
|
||||
4, // 37 FormatBc3
|
||||
1, // 38 FormatBc4
|
||||
2, // 39 FormatBc5
|
||||
3, // 40 FormatBc6
|
||||
4, // 41 FormatBc7
|
||||
};
|
||||
|
||||
u32 ComponentBits(DataFormat format, u32 comp) {
|
||||
u32 NumComponents(DataFormat format) {
|
||||
const u32 index = static_cast<u32>(format);
|
||||
if (index >= component_bits.size() || comp >= 4) {
|
||||
return 0;
|
||||
}
|
||||
return component_bits[index][comp];
|
||||
ASSERT_MSG(index < NUM_COMPONENTS.size(), "Invalid data format = {}", format);
|
||||
return NUM_COMPONENTS[index];
|
||||
}
|
||||
|
||||
static constexpr std::array component_offset = {
|
||||
std::array{-1, -1, -1, -1}, // 0 FormatInvalid
|
||||
std::array{0, -1, -1, -1}, // 1 Format8
|
||||
std::array{0, -1, -1, -1}, // 2 Format16
|
||||
std::array{0, 8, -1, -1}, // 3 Format8_8
|
||||
std::array{0, -1, -1, -1}, // 4 Format32
|
||||
std::array{0, 16, -1, -1}, // 5 Format16_16
|
||||
std::array{0, 11, 22, -1}, // 6 Format10_11_11
|
||||
std::array{0, 10, 21, -1}, // 7 Format11_11_10
|
||||
std::array{0, 2, 12, 22}, // 8 Format10_10_10_2
|
||||
std::array{0, 10, 20, 30}, // 9 Format2_10_10_10
|
||||
std::array{0, 8, 16, 24}, // 10 Format8_8_8_8
|
||||
std::array{0, 32, -1, -1}, // 11 Format32_32
|
||||
std::array{0, 16, 32, 48}, // 12 Format16_16_16_16
|
||||
std::array{0, 32, 64, -1}, // 13 Format32_32_32
|
||||
std::array{0, 32, 64, 96}, // 14 Format32_32_32_32
|
||||
std::array{-1, -1, -1, -1}, // 15
|
||||
std::array{0, 5, 11, -1}, // 16 Format5_6_5
|
||||
std::array{0, 5, 10, 15}, // 17 Format1_5_5_5
|
||||
std::array{0, 1, 6, 11}, // 18 Format5_5_5_1
|
||||
std::array{0, 4, 8, 12}, // 19 Format4_4_4_4
|
||||
std::array{0, 24, -1, -1}, // 20 Format8_24
|
||||
std::array{0, 8, -1, -1}, // 21 Format24_8
|
||||
std::array{0, 8, -1, -1}, // 22 FormatX24_8_32
|
||||
std::array{-1, -1, -1, -1}, // 23
|
||||
std::array{-1, -1, -1, -1}, // 24
|
||||
std::array{-1, -1, -1, -1}, // 25
|
||||
std::array{-1, -1, -1, -1}, // 26
|
||||
std::array{-1, -1, -1, -1}, // 27
|
||||
std::array{-1, -1, -1, -1}, // 28
|
||||
std::array{-1, -1, -1, -1}, // 29
|
||||
std::array{-1, -1, -1, -1}, // 30
|
||||
std::array{-1, -1, -1, -1}, // 31
|
||||
std::array{-1, -1, -1, -1}, // 32 FormatGB_GR
|
||||
std::array{-1, -1, -1, -1}, // 33 FormatBG_RG
|
||||
std::array{-1, -1, -1, -1}, // 34 Format5_9_9_9
|
||||
std::array{-1, -1, -1, -1}, // 35 FormatBc1
|
||||
std::array{-1, -1, -1, -1}, // 36 FormatBc2
|
||||
std::array{-1, -1, -1, -1}, // 37 FormatBc3
|
||||
std::array{-1, -1, -1, -1}, // 38 FormatBc4
|
||||
std::array{-1, -1, -1, -1}, // 39 FormatBc5
|
||||
std::array{-1, -1, -1, -1}, // 40 FormatBc6
|
||||
std::array{-1, -1, -1, -1}, // 41 FormatBc7
|
||||
static constexpr std::array BITS_PER_BLOCK = {
|
||||
0, // 0 FormatInvalid
|
||||
8, // 1 Format8
|
||||
16, // 2 Format16
|
||||
16, // 3 Format8_8
|
||||
32, // 4 Format32
|
||||
32, // 5 Format16_16
|
||||
32, // 6 Format10_11_11
|
||||
32, // 7 Format11_11_10
|
||||
32, // 8 Format10_10_10_2
|
||||
32, // 9 Format2_10_10_10
|
||||
32, // 10 Format8_8_8_8
|
||||
64, // 11 Format32_32
|
||||
64, // 12 Format16_16_16_16
|
||||
96, // 13 Format32_32_32
|
||||
128, // 14 Format32_32_32_32
|
||||
0, // 15
|
||||
16, // 16 Format5_6_5
|
||||
16, // 17 Format1_5_5_5
|
||||
16, // 18 Format5_5_5_1
|
||||
16, // 19 Format4_4_4_4
|
||||
32, // 20 Format8_24
|
||||
32, // 21 Format24_8
|
||||
64, // 22 FormatX24_8_32
|
||||
0, // 23
|
||||
0, // 24
|
||||
0, // 25
|
||||
0, // 26
|
||||
0, // 27
|
||||
0, // 28
|
||||
0, // 29
|
||||
0, // 30
|
||||
0, // 31
|
||||
16, // 32 FormatGB_GR
|
||||
16, // 33 FormatBG_RG
|
||||
32, // 34 Format5_9_9_9
|
||||
64, // 35 FormatBc1
|
||||
128, // 36 FormatBc2
|
||||
128, // 37 FormatBc3
|
||||
64, // 38 FormatBc4
|
||||
128, // 39 FormatBc5
|
||||
128, // 40 FormatBc6
|
||||
128, // 41 FormatBc7
|
||||
};
|
||||
|
||||
s32 ComponentOffset(DataFormat format, u32 comp) {
|
||||
u32 NumBitsPerBlock(DataFormat format) {
|
||||
const u32 index = static_cast<u32>(format);
|
||||
if (index >= component_offset.size() || comp >= 4) {
|
||||
return -1;
|
||||
}
|
||||
return component_offset[index][comp];
|
||||
ASSERT_MSG(index < BITS_PER_BLOCK.size(), "Invalid data format = {}", format);
|
||||
return BITS_PER_BLOCK[index];
|
||||
}
|
||||
|
||||
} // namespace AmdGpu
|
||||
|
||||
@@ -310,10 +310,8 @@ constexpr bool IsInteger(const NumberFormat nfmt) {
|
||||
std::string_view NameOf(DataFormat fmt);
|
||||
std::string_view NameOf(NumberFormat fmt);
|
||||
|
||||
int NumComponents(DataFormat format);
|
||||
int NumBits(DataFormat format);
|
||||
u32 ComponentBits(DataFormat format, u32 comp);
|
||||
s32 ComponentOffset(DataFormat format, u32 comp);
|
||||
u32 NumComponents(DataFormat format);
|
||||
u32 NumBitsPerBlock(DataFormat format);
|
||||
|
||||
} // namespace AmdGpu
|
||||
|
||||
|
||||
Reference in New Issue
Block a user