summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-11-11 18:11:14 -0300
committerGravatar ReinUsesLisp2019-11-14 20:57:30 -0300
commit4681381a3413554b861f44a768fca83e8ea74cff (patch)
treeb86ce1d3f4012fdd7c8e073d5b0f752d250e0c54 /src/video_core
parenttexture_cache: Use a table instead of switch for texture formats (diff)
downloadyuzu-4681381a3413554b861f44a768fca83e8ea74cff.tar.gz
yuzu-4681381a3413554b861f44a768fca83e8ea74cff.tar.xz
yuzu-4681381a3413554b861f44a768fca83e8ea74cff.zip
format_lookup_table: Address feedback
format_lookup_table: Drop bitfields format_lookup_table: Use std::array for definition table format_lookup_table: Include <limits> instead of <numeric>
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/texture_cache/format_lookup_table.cpp52
-rw-r--r--src/video_core/texture_cache/format_lookup_table.h2
2 files changed, 24 insertions, 30 deletions
diff --git a/src/video_core/texture_cache/format_lookup_table.cpp b/src/video_core/texture_cache/format_lookup_table.cpp
index ee050cc31..271e67533 100644
--- a/src/video_core/texture_cache/format_lookup_table.cpp
+++ b/src/video_core/texture_cache/format_lookup_table.cpp
@@ -15,34 +15,31 @@ using VideoCore::Surface::PixelFormat;
15 15
16namespace { 16namespace {
17 17
18static constexpr auto SNORM = ComponentType::SNORM; 18constexpr auto SNORM = ComponentType::SNORM;
19static constexpr auto UNORM = ComponentType::UNORM; 19constexpr auto UNORM = ComponentType::UNORM;
20static constexpr auto SINT = ComponentType::SINT; 20constexpr auto SINT = ComponentType::SINT;
21static constexpr auto UINT = ComponentType::UINT; 21constexpr auto UINT = ComponentType::UINT;
22static constexpr auto SNORM_FORCE_FP16 = ComponentType::SNORM_FORCE_FP16; 22constexpr auto SNORM_FORCE_FP16 = ComponentType::SNORM_FORCE_FP16;
23static constexpr auto UNORM_FORCE_FP16 = ComponentType::UNORM_FORCE_FP16; 23constexpr auto UNORM_FORCE_FP16 = ComponentType::UNORM_FORCE_FP16;
24static constexpr auto FLOAT = ComponentType::FLOAT; 24constexpr auto FLOAT = ComponentType::FLOAT;
25static constexpr bool C = false; // Normal color 25constexpr bool C = false; // Normal color
26static constexpr bool S = true; // Srgb 26constexpr bool S = true; // Srgb
27 27
28struct Table { 28struct Table {
29 constexpr Table(TextureFormat texture_format, bool is_srgb, ComponentType red_component, 29 constexpr Table(TextureFormat texture_format, bool is_srgb, ComponentType red_component,
30 ComponentType green_component, ComponentType blue_component, 30 ComponentType green_component, ComponentType blue_component,
31 ComponentType alpha_component, PixelFormat pixel_format) 31 ComponentType alpha_component, PixelFormat pixel_format)
32 : texture_format{static_cast<u32>(texture_format)}, 32 : texture_format{texture_format}, pixel_format{pixel_format}, red_component{red_component},
33 pixel_format{static_cast<u32>(pixel_format)}, red_component{static_cast<u32>( 33 green_component{green_component}, blue_component{blue_component},
34 red_component)}, 34 alpha_component{alpha_component}, is_srgb{is_srgb} {}
35 green_component{static_cast<u32>(green_component)}, blue_component{static_cast<u32>( 35
36 blue_component)}, 36 TextureFormat texture_format;
37 alpha_component{static_cast<u32>(alpha_component)}, is_srgb{is_srgb ? 1U : 0U} {} 37 PixelFormat pixel_format;
38 38 ComponentType red_component;
39 u32 texture_format : 8; 39 ComponentType green_component;
40 u32 pixel_format : 8; 40 ComponentType blue_component;
41 u32 red_component : 3; 41 ComponentType alpha_component;
42 u32 green_component : 3; 42 bool is_srgb;
43 u32 blue_component : 3;
44 u32 alpha_component : 3;
45 u32 is_srgb : 1;
46}; 43};
47constexpr std::array<Table, 74> DefinitionTable = {{ 44constexpr std::array<Table, 74> DefinitionTable = {{
48 {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ABGR8U}, 45 {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ABGR8U},
@@ -161,12 +158,9 @@ constexpr std::array<Table, 74> DefinitionTable = {{
161FormatLookupTable::FormatLookupTable() { 158FormatLookupTable::FormatLookupTable() {
162 table.fill(static_cast<u8>(PixelFormat::Invalid)); 159 table.fill(static_cast<u8>(PixelFormat::Invalid));
163 160
164 for (const auto entry : DefinitionTable) { 161 for (const auto& entry : DefinitionTable) {
165 table[CalculateIndex(static_cast<TextureFormat>(entry.texture_format), entry.is_srgb != 0, 162 table[CalculateIndex(entry.texture_format, entry.is_srgb != 0, entry.red_component,
166 static_cast<ComponentType>(entry.red_component), 163 entry.green_component, entry.blue_component, entry.alpha_component)] =
167 static_cast<ComponentType>(entry.green_component),
168 static_cast<ComponentType>(entry.blue_component),
169 static_cast<ComponentType>(entry.alpha_component))] =
170 static_cast<u8>(entry.pixel_format); 164 static_cast<u8>(entry.pixel_format);
171 } 165 }
172} 166}
diff --git a/src/video_core/texture_cache/format_lookup_table.h b/src/video_core/texture_cache/format_lookup_table.h
index 8da7481cd..aa77e0a5a 100644
--- a/src/video_core/texture_cache/format_lookup_table.h
+++ b/src/video_core/texture_cache/format_lookup_table.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <numeric> 8#include <limits>
9#include "video_core/surface.h" 9#include "video_core/surface.h"
10#include "video_core/textures/texture.h" 10#include "video_core/textures/texture.h"
11 11