summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-04-18 15:36:00 -0400
committerGravatar GitHub2018-04-18 15:36:00 -0400
commit6a999cf800a56b5c13baba64dc560e05245c5b09 (patch)
tree2cd2be881337d77a0da33c6db8a8bcc4007349e9 /src
parentMerge pull request #349 from Subv/texturing (diff)
parentGLCache: Added boilerplate code to make supporting configurable texture compo... (diff)
downloadyuzu-6a999cf800a56b5c13baba64dc560e05245c5b09.tar.gz
yuzu-6a999cf800a56b5c13baba64dc560e05245c5b09.tar.xz
yuzu-6a999cf800a56b5c13baba64dc560e05245c5b09.zip
Merge pull request #350 from Subv/tex_components
GPU: Fixed the incorrect component order in ABGR8 textures.
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp55
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h76
3 files changed, 90 insertions, 43 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 9522a35ea..13e2a77ce 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -527,6 +527,8 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& framebu
527 src_params.block_height = Tegra::Texture::TICEntry::DefaultBlockHeight; 527 src_params.block_height = Tegra::Texture::TICEntry::DefaultBlockHeight;
528 src_params.pixel_format = 528 src_params.pixel_format =
529 SurfaceParams::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format); 529 SurfaceParams::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format);
530 src_params.component_type =
531 SurfaceParams::ComponentTypeFromGPUPixelFormat(framebuffer.pixel_format);
530 src_params.UpdateParams(); 532 src_params.UpdateParams();
531 533
532 MathUtil::Rectangle<u32> src_rect; 534 MathUtil::Rectangle<u32> src_rect;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index a92773f11..9ccc63090 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -36,6 +36,7 @@
36 36
37using SurfaceType = SurfaceParams::SurfaceType; 37using SurfaceType = SurfaceParams::SurfaceType;
38using PixelFormat = SurfaceParams::PixelFormat; 38using PixelFormat = SurfaceParams::PixelFormat;
39using ComponentType = SurfaceParams::ComponentType;
39 40
40struct FormatTuple { 41struct FormatTuple {
41 GLint internal_format; 42 GLint internal_format;
@@ -47,26 +48,21 @@ struct FormatTuple {
47 u32 compression_factor; 48 u32 compression_factor;
48}; 49};
49 50
50static constexpr std::array<FormatTuple, 1> fb_format_tuples = {{
51 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, false, 1}, // RGBA8
52}};
53
54static constexpr std::array<FormatTuple, 2> tex_format_tuples = {{ 51static constexpr std::array<FormatTuple, 2> tex_format_tuples = {{
55 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, false, 1}, // RGBA8 52 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false, 1}, // ABGR8
56 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1 53 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1
57}}; 54}};
58 55
59static const FormatTuple& GetFormatTuple(PixelFormat pixel_format) { 56static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
60 const SurfaceType type = SurfaceParams::GetFormatType(pixel_format); 57 const SurfaceType type = SurfaceParams::GetFormatType(pixel_format);
61 if (type == SurfaceType::Color) { 58 if (type == SurfaceType::ColorTexture) {
62 ASSERT(static_cast<size_t>(pixel_format) < fb_format_tuples.size()); 59 ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size());
63 return fb_format_tuples[static_cast<unsigned int>(pixel_format)]; 60 // For now only UNORM components are supported
61 ASSERT(component_type == ComponentType::UNorm);
62 return tex_format_tuples[static_cast<unsigned int>(pixel_format)];
64 } else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) { 63 } else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) {
65 // TODO(Subv): Implement depth formats 64 // TODO(Subv): Implement depth formats
66 ASSERT_MSG(false, "Unimplemented"); 65 ASSERT_MSG(false, "Unimplemented");
67 } else if (type == SurfaceType::Texture) {
68 ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size());
69 return tex_format_tuples[static_cast<unsigned int>(pixel_format)];
70 } 66 }
71 67
72 UNREACHABLE(); 68 UNREACHABLE();
@@ -123,13 +119,13 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, VAddr b
123 119
124static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 2> morton_to_gl_fns = 120static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 2> morton_to_gl_fns =
125 { 121 {
126 MortonCopy<true, PixelFormat::RGBA8>, 122 MortonCopy<true, PixelFormat::ABGR8>,
127 MortonCopy<true, PixelFormat::DXT1>, 123 MortonCopy<true, PixelFormat::DXT1>,
128}; 124};
129 125
130static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 2> gl_to_morton_fns = 126static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 2> gl_to_morton_fns =
131 { 127 {
132 MortonCopy<false, PixelFormat::RGBA8>, 128 MortonCopy<false, PixelFormat::ABGR8>,
133 // TODO(Subv): Swizzling the DXT1 format is not yet supported 129 // TODO(Subv): Swizzling the DXT1 format is not yet supported
134 nullptr, 130 nullptr,
135}; 131};
@@ -180,7 +176,7 @@ static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rec
180 176
181 u32 buffers = 0; 177 u32 buffers = 0;
182 178
183 if (type == SurfaceType::Color || type == SurfaceType::Texture) { 179 if (type == SurfaceType::ColorTexture) {
184 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src_tex, 180 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src_tex,
185 0); 181 0);
186 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 182 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
@@ -309,8 +305,9 @@ MathUtil::Rectangle<u32> SurfaceParams::GetScaledSubRect(const SurfaceParams& su
309bool SurfaceParams::ExactMatch(const SurfaceParams& other_surface) const { 305bool SurfaceParams::ExactMatch(const SurfaceParams& other_surface) const {
310 return std::tie(other_surface.addr, other_surface.width, other_surface.height, 306 return std::tie(other_surface.addr, other_surface.width, other_surface.height,
311 other_surface.stride, other_surface.block_height, other_surface.pixel_format, 307 other_surface.stride, other_surface.block_height, other_surface.pixel_format,
312 other_surface.is_tiled) == 308 other_surface.component_type,
313 std::tie(addr, width, height, stride, block_height, pixel_format, is_tiled) && 309 other_surface.is_tiled) == std::tie(addr, width, height, stride, block_height,
310 pixel_format, component_type, is_tiled) &&
314 pixel_format != PixelFormat::Invalid; 311 pixel_format != PixelFormat::Invalid;
315} 312}
316 313
@@ -318,6 +315,7 @@ bool SurfaceParams::CanSubRect(const SurfaceParams& sub_surface) const {
318 return sub_surface.addr >= addr && sub_surface.end <= end && 315 return sub_surface.addr >= addr && sub_surface.end <= end &&
319 sub_surface.pixel_format == pixel_format && pixel_format != PixelFormat::Invalid && 316 sub_surface.pixel_format == pixel_format && pixel_format != PixelFormat::Invalid &&
320 sub_surface.is_tiled == is_tiled && sub_surface.block_height == block_height && 317 sub_surface.is_tiled == is_tiled && sub_surface.block_height == block_height &&
318 sub_surface.component_type == component_type &&
321 (sub_surface.addr - addr) % BytesInPixels(is_tiled ? 64 : 1) == 0 && 319 (sub_surface.addr - addr) % BytesInPixels(is_tiled ? 64 : 1) == 0 &&
322 (sub_surface.stride == stride || sub_surface.height <= (is_tiled ? 8u : 1u)) && 320 (sub_surface.stride == stride || sub_surface.height <= (is_tiled ? 8u : 1u)) &&
323 GetSubRect(sub_surface).left + sub_surface.width <= stride; 321 GetSubRect(sub_surface).left + sub_surface.width <= stride;
@@ -327,7 +325,7 @@ bool SurfaceParams::CanExpand(const SurfaceParams& expanded_surface) const {
327 return pixel_format != PixelFormat::Invalid && pixel_format == expanded_surface.pixel_format && 325 return pixel_format != PixelFormat::Invalid && pixel_format == expanded_surface.pixel_format &&
328 addr <= expanded_surface.end && expanded_surface.addr <= end && 326 addr <= expanded_surface.end && expanded_surface.addr <= end &&
329 is_tiled == expanded_surface.is_tiled && block_height == expanded_surface.block_height && 327 is_tiled == expanded_surface.is_tiled && block_height == expanded_surface.block_height &&
330 stride == expanded_surface.stride && 328 component_type == expanded_surface.component_type && stride == expanded_surface.stride &&
331 (std::max(expanded_surface.addr, addr) - std::min(expanded_surface.addr, addr)) % 329 (std::max(expanded_surface.addr, addr) - std::min(expanded_surface.addr, addr)) %
332 BytesInPixels(stride * (is_tiled ? 8 : 1)) == 330 BytesInPixels(stride * (is_tiled ? 8 : 1)) ==
333 0; 331 0;
@@ -338,7 +336,8 @@ bool SurfaceParams::CanTexCopy(const SurfaceParams& texcopy_params) const {
338 end < texcopy_params.end) { 336 end < texcopy_params.end) {
339 return false; 337 return false;
340 } 338 }
341 if (texcopy_params.block_height != block_height) 339 if (texcopy_params.block_height != block_height ||
340 texcopy_params.component_type != component_type)
342 return false; 341 return false;
343 342
344 if (texcopy_params.width != texcopy_params.stride) { 343 if (texcopy_params.width != texcopy_params.stride) {
@@ -552,7 +551,7 @@ void CachedSurface::UploadGLTexture(const MathUtil::Rectangle<u32>& rect, GLuint
552 GLint y0 = static_cast<GLint>(rect.bottom); 551 GLint y0 = static_cast<GLint>(rect.bottom);
553 size_t buffer_offset = (y0 * stride + x0) * GetGLBytesPerPixel(pixel_format); 552 size_t buffer_offset = (y0 * stride + x0) * GetGLBytesPerPixel(pixel_format);
554 553
555 const FormatTuple& tuple = GetFormatTuple(pixel_format); 554 const FormatTuple& tuple = GetFormatTuple(pixel_format, component_type);
556 GLuint target_tex = texture.handle; 555 GLuint target_tex = texture.handle;
557 556
558 // If not 1x scale, create 1x texture that we will blit from to replace texture subrect in 557 // If not 1x scale, create 1x texture that we will blit from to replace texture subrect in
@@ -625,7 +624,7 @@ void CachedSurface::DownloadGLTexture(const MathUtil::Rectangle<u32>& rect, GLui
625 OpenGLState prev_state = state; 624 OpenGLState prev_state = state;
626 SCOPE_EXIT({ prev_state.Apply(); }); 625 SCOPE_EXIT({ prev_state.Apply(); });
627 626
628 const FormatTuple& tuple = GetFormatTuple(pixel_format); 627 const FormatTuple& tuple = GetFormatTuple(pixel_format, component_type);
629 628
630 // Ensure no bad interactions with GL_PACK_ALIGNMENT 629 // Ensure no bad interactions with GL_PACK_ALIGNMENT
631 ASSERT(stride * GetGLBytesPerPixel(pixel_format) % 4 == 0); 630 ASSERT(stride * GetGLBytesPerPixel(pixel_format) % 4 == 0);
@@ -658,7 +657,7 @@ void CachedSurface::DownloadGLTexture(const MathUtil::Rectangle<u32>& rect, GLui
658 state.draw.read_framebuffer = read_fb_handle; 657 state.draw.read_framebuffer = read_fb_handle;
659 state.Apply(); 658 state.Apply();
660 659
661 if (type == SurfaceType::Color || type == SurfaceType::Texture) { 660 if (type == SurfaceType::ColorTexture) {
662 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 661 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
663 texture.handle, 0); 662 texture.handle, 0);
664 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 663 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
@@ -1038,6 +1037,13 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Tegra::Texture::FullTextu
1038 params.is_tiled = config.tic.IsTiled(); 1037 params.is_tiled = config.tic.IsTiled();
1039 params.pixel_format = SurfaceParams::PixelFormatFromTextureFormat(config.tic.format); 1038 params.pixel_format = SurfaceParams::PixelFormatFromTextureFormat(config.tic.format);
1040 1039
1040 // TODO(Subv): Different types per component are not supported.
1041 ASSERT(config.tic.r_type.Value() == config.tic.g_type.Value() &&
1042 config.tic.r_type.Value() == config.tic.b_type.Value() &&
1043 config.tic.r_type.Value() == config.tic.a_type.Value());
1044
1045 params.component_type = SurfaceParams::ComponentTypeFromTexture(config.tic.r_type.Value());
1046
1041 if (config.tic.IsTiled()) { 1047 if (config.tic.IsTiled()) {
1042 params.block_height = config.tic.BlockHeight(); 1048 params.block_height = config.tic.BlockHeight();
1043 } else { 1049 } else {
@@ -1105,6 +1111,7 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces(
1105 1111
1106 color_params.addr = memory_manager->PhysicalToVirtualAddress(config.Address()); 1112 color_params.addr = memory_manager->PhysicalToVirtualAddress(config.Address());
1107 color_params.pixel_format = SurfaceParams::PixelFormatFromRenderTargetFormat(config.format); 1113 color_params.pixel_format = SurfaceParams::PixelFormatFromRenderTargetFormat(config.format);
1114 color_params.component_type = SurfaceParams::ComponentTypeFromRenderTarget(config.format);
1108 color_params.UpdateParams(); 1115 color_params.UpdateParams();
1109 1116
1110 ASSERT_MSG(!using_depth_fb, "depth buffer is unimplemented"); 1117 ASSERT_MSG(!using_depth_fb, "depth buffer is unimplemented");
@@ -1300,7 +1307,6 @@ void RasterizerCacheOpenGL::InvalidateRegion(VAddr addr, u64 size, const Surface
1300 const SurfaceInterval invalid_interval(addr, addr + size); 1307 const SurfaceInterval invalid_interval(addr, addr + size);
1301 1308
1302 if (region_owner != nullptr) { 1309 if (region_owner != nullptr) {
1303 ASSERT(region_owner->type != SurfaceType::Texture);
1304 ASSERT(addr >= region_owner->addr && addr + size <= region_owner->end); 1310 ASSERT(addr >= region_owner->addr && addr + size <= region_owner->end);
1305 // Surfaces can't have a gap 1311 // Surfaces can't have a gap
1306 ASSERT(region_owner->width == region_owner->stride); 1312 ASSERT(region_owner->width == region_owner->stride);
@@ -1362,7 +1368,8 @@ Surface RasterizerCacheOpenGL::CreateSurface(const SurfaceParams& params) {
1362 1368
1363 surface->gl_buffer_size = 0; 1369 surface->gl_buffer_size = 0;
1364 surface->invalid_regions.insert(surface->GetInterval()); 1370 surface->invalid_regions.insert(surface->GetInterval());
1365 AllocateSurfaceTexture(surface->texture.handle, GetFormatTuple(surface->pixel_format), 1371 AllocateSurfaceTexture(surface->texture.handle,
1372 GetFormatTuple(surface->pixel_format, surface->component_type),
1366 surface->GetScaledWidth(), surface->GetScaledHeight()); 1373 surface->GetScaledWidth(), surface->GetScaledHeight());
1367 1374
1368 return surface; 1375 return surface;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index 26d6c3061..0ff0ce90f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -52,18 +52,26 @@ enum class ScaleMatch {
52 52
53struct SurfaceParams { 53struct SurfaceParams {
54 enum class PixelFormat { 54 enum class PixelFormat {
55 RGBA8 = 0, 55 ABGR8 = 0,
56 DXT1 = 1, 56 DXT1 = 1,
57 Invalid = 255, 57 Invalid = 255,
58 }; 58 };
59 59
60 enum class ComponentType {
61 Invalid = 0,
62 SNorm = 1,
63 UNorm = 2,
64 SInt = 3,
65 UInt = 4,
66 Float = 5,
67 };
68
60 enum class SurfaceType { 69 enum class SurfaceType {
61 Color = 0, 70 ColorTexture = 0,
62 Texture = 1, 71 Depth = 1,
63 Depth = 2, 72 DepthStencil = 2,
64 DepthStencil = 3, 73 Fill = 3,
65 Fill = 4, 74 Invalid = 4,
66 Invalid = 5
67 }; 75 };
68 76
69 static constexpr unsigned int GetFormatBpp(PixelFormat format) { 77 static constexpr unsigned int GetFormatBpp(PixelFormat format) {
@@ -71,7 +79,7 @@ struct SurfaceParams {
71 return 0; 79 return 0;
72 80
73 constexpr std::array<unsigned int, 2> bpp_table = { 81 constexpr std::array<unsigned int, 2> bpp_table = {
74 32, // RGBA8 82 32, // ABGR8
75 64, // DXT1 83 64, // DXT1
76 }; 84 };
77 85
@@ -85,7 +93,7 @@ struct SurfaceParams {
85 static PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) { 93 static PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) {
86 switch (format) { 94 switch (format) {
87 case Tegra::RenderTargetFormat::RGBA8_UNORM: 95 case Tegra::RenderTargetFormat::RGBA8_UNORM:
88 return PixelFormat::RGBA8; 96 return PixelFormat::ABGR8;
89 default: 97 default:
90 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); 98 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
91 UNREACHABLE(); 99 UNREACHABLE();
@@ -95,7 +103,7 @@ struct SurfaceParams {
95 static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) { 103 static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
96 switch (format) { 104 switch (format) {
97 case Tegra::FramebufferConfig::PixelFormat::ABGR8: 105 case Tegra::FramebufferConfig::PixelFormat::ABGR8:
98 return PixelFormat::RGBA8; 106 return PixelFormat::ABGR8;
99 default: 107 default:
100 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); 108 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
101 UNREACHABLE(); 109 UNREACHABLE();
@@ -106,7 +114,7 @@ struct SurfaceParams {
106 // TODO(Subv): Properly implement this 114 // TODO(Subv): Properly implement this
107 switch (format) { 115 switch (format) {
108 case Tegra::Texture::TextureFormat::A8R8G8B8: 116 case Tegra::Texture::TextureFormat::A8R8G8B8:
109 return PixelFormat::RGBA8; 117 return PixelFormat::ABGR8;
110 case Tegra::Texture::TextureFormat::DXT1: 118 case Tegra::Texture::TextureFormat::DXT1:
111 return PixelFormat::DXT1; 119 return PixelFormat::DXT1;
112 default: 120 default:
@@ -118,7 +126,7 @@ struct SurfaceParams {
118 static Tegra::Texture::TextureFormat TextureFormatFromPixelFormat(PixelFormat format) { 126 static Tegra::Texture::TextureFormat TextureFormatFromPixelFormat(PixelFormat format) {
119 // TODO(Subv): Properly implement this 127 // TODO(Subv): Properly implement this
120 switch (format) { 128 switch (format) {
121 case PixelFormat::RGBA8: 129 case PixelFormat::ABGR8:
122 return Tegra::Texture::TextureFormat::A8R8G8B8; 130 return Tegra::Texture::TextureFormat::A8R8G8B8;
123 case PixelFormat::DXT1: 131 case PixelFormat::DXT1:
124 return Tegra::Texture::TextureFormat::DXT1; 132 return Tegra::Texture::TextureFormat::DXT1;
@@ -127,12 +135,45 @@ struct SurfaceParams {
127 } 135 }
128 } 136 }
129 137
138 static ComponentType ComponentTypeFromTexture(Tegra::Texture::ComponentType type) {
139 // TODO(Subv): Implement more component types
140 switch (type) {
141 case Tegra::Texture::ComponentType::UNORM:
142 return ComponentType::UNorm;
143 default:
144 NGLOG_CRITICAL(HW_GPU, "Unimplemented component type={}", static_cast<u32>(type));
145 UNREACHABLE();
146 }
147 }
148
149 static ComponentType ComponentTypeFromRenderTarget(Tegra::RenderTargetFormat format) {
150 // TODO(Subv): Implement more render targets
151 switch (format) {
152 case Tegra::RenderTargetFormat::RGBA8_UNORM:
153 case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
154 return ComponentType::UNorm;
155 default:
156 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
157 UNREACHABLE();
158 }
159 }
160
161 static ComponentType ComponentTypeFromGPUPixelFormat(
162 Tegra::FramebufferConfig::PixelFormat format) {
163 switch (format) {
164 case Tegra::FramebufferConfig::PixelFormat::ABGR8:
165 return ComponentType::UNorm;
166 default:
167 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
168 UNREACHABLE();
169 }
170 }
171
130 static bool CheckFormatsBlittable(PixelFormat pixel_format_a, PixelFormat pixel_format_b) { 172 static bool CheckFormatsBlittable(PixelFormat pixel_format_a, PixelFormat pixel_format_b) {
131 SurfaceType a_type = GetFormatType(pixel_format_a); 173 SurfaceType a_type = GetFormatType(pixel_format_a);
132 SurfaceType b_type = GetFormatType(pixel_format_b); 174 SurfaceType b_type = GetFormatType(pixel_format_b);
133 175
134 if ((a_type == SurfaceType::Color || a_type == SurfaceType::Texture) && 176 if (a_type == SurfaceType::ColorTexture && b_type == SurfaceType::ColorTexture) {
135 (b_type == SurfaceType::Color || b_type == SurfaceType::Texture)) {
136 return true; 177 return true;
137 } 178 }
138 179
@@ -148,12 +189,8 @@ struct SurfaceParams {
148 } 189 }
149 190
150 static SurfaceType GetFormatType(PixelFormat pixel_format) { 191 static SurfaceType GetFormatType(PixelFormat pixel_format) {
151 if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::RGBA8)) {
152 return SurfaceType::Color;
153 }
154
155 if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::DXT1)) { 192 if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::DXT1)) {
156 return SurfaceType::Texture; 193 return SurfaceType::ColorTexture;
157 } 194 }
158 195
159 // TODO(Subv): Implement the other formats 196 // TODO(Subv): Implement the other formats
@@ -231,6 +268,7 @@ struct SurfaceParams {
231 bool is_tiled = false; 268 bool is_tiled = false;
232 PixelFormat pixel_format = PixelFormat::Invalid; 269 PixelFormat pixel_format = PixelFormat::Invalid;
233 SurfaceType type = SurfaceType::Invalid; 270 SurfaceType type = SurfaceType::Invalid;
271 ComponentType component_type = ComponentType::Invalid;
234}; 272};
235 273
236struct CachedSurface : SurfaceParams { 274struct CachedSurface : SurfaceParams {