summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/host_memory.cpp2
-rw-r--r--src/video_core/host_shaders/CMakeLists.txt1
-rw-r--r--src/video_core/host_shaders/opengl_copy_bgra.comp15
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp37
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.h22
-rw-r--r--src/video_core/renderer_opengl/maxwell_to_gl.h4
-rw-r--r--src/video_core/renderer_opengl/util_shaders.cpp76
-rw-r--r--src/video_core/renderer_opengl/util_shaders.h22
8 files changed, 60 insertions, 119 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index 6661244cf..b44a44949 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -314,8 +314,8 @@ private:
314 } 314 }
315 315
316 void UntrackPlaceholder(boost::icl::separate_interval_set<size_t>::iterator it) { 316 void UntrackPlaceholder(boost::icl::separate_interval_set<size_t>::iterator it) {
317 placeholders.erase(it);
318 placeholder_host_pointers.erase(it->lower()); 317 placeholder_host_pointers.erase(it->lower());
318 placeholders.erase(it);
319 } 319 }
320 320
321 /// Return true when a given memory region is a "nieche" and the placeholders don't have to be 321 /// Return true when a given memory region is a "nieche" and the placeholders don't have to be
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index c9cff7450..20d748c12 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -6,7 +6,6 @@ set(SHADER_FILES
6 convert_float_to_depth.frag 6 convert_float_to_depth.frag
7 full_screen_triangle.vert 7 full_screen_triangle.vert
8 opengl_copy_bc4.comp 8 opengl_copy_bc4.comp
9 opengl_copy_bgra.comp
10 opengl_present.frag 9 opengl_present.frag
11 opengl_present.vert 10 opengl_present.vert
12 pitch_unswizzle.comp 11 pitch_unswizzle.comp
diff --git a/src/video_core/host_shaders/opengl_copy_bgra.comp b/src/video_core/host_shaders/opengl_copy_bgra.comp
deleted file mode 100644
index 2571a4abf..000000000
--- a/src/video_core/host_shaders/opengl_copy_bgra.comp
+++ /dev/null
@@ -1,15 +0,0 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#version 430 core
6
7layout (local_size_x = 4, local_size_y = 4) in;
8
9layout(binding = 0, rgba8) readonly uniform image2DArray bgr_input;
10layout(binding = 1, rgba8) writeonly uniform image2DArray bgr_output;
11
12void main() {
13 vec4 color = imageLoad(bgr_input, ivec3(gl_GlobalInvocationID));
14 imageStore(bgr_output, ivec3(gl_GlobalInvocationID), color.bgra);
15}
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index b0aee6cc1..54dae2c41 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -461,7 +461,7 @@ bool TextureCacheRuntime::CanImageBeCopied(const Image& dst, const Image& src) {
461 if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) { 461 if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) {
462 return false; 462 return false;
463 } 463 }
464 if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { 464 if (IsPixelFormatBGR(dst.info.format) != IsPixelFormatBGR(src.info.format)) {
465 return false; 465 return false;
466 } 466 }
467 return true; 467 return true;
@@ -473,7 +473,7 @@ void TextureCacheRuntime::EmulateCopyImage(Image& dst, Image& src,
473 ASSERT(src.info.type == ImageType::e3D); 473 ASSERT(src.info.type == ImageType::e3D);
474 util_shaders.CopyBC4(dst, src, copies); 474 util_shaders.CopyBC4(dst, src, copies);
475 } else if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { 475 } else if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) {
476 util_shaders.CopyBGR(dst, src, copies); 476 bgr_copy_pass.CopyBGR(dst, src, copies);
477 } else { 477 } else {
478 UNREACHABLE(); 478 UNREACHABLE();
479 } 479 }
@@ -1112,4 +1112,37 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM
1112 framebuffer.handle = handle; 1112 framebuffer.handle = handle;
1113} 1113}
1114 1114
1115void BGRCopyPass::CopyBGR(Image& dst_image, Image& src_image,
1116 std::span<const VideoCommon::ImageCopy> copies) {
1117 static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0};
1118 const u32 requested_pbo_size =
1119 std::max(src_image.unswizzled_size_bytes, dst_image.unswizzled_size_bytes);
1120
1121 if (bgr_pbo_size < requested_pbo_size) {
1122 bgr_pbo.Create();
1123 bgr_pbo_size = requested_pbo_size;
1124 glNamedBufferData(bgr_pbo.handle, bgr_pbo_size, nullptr, GL_STREAM_COPY);
1125 }
1126 for (const ImageCopy& copy : copies) {
1127 ASSERT(copy.src_offset == zero_offset);
1128 ASSERT(copy.dst_offset == zero_offset);
1129
1130 // Copy from source to PBO
1131 glPixelStorei(GL_PACK_ALIGNMENT, 1);
1132 glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width);
1133 glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr_pbo.handle);
1134 glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
1135 copy.src_subresource.num_layers, src_image.GlFormat(),
1136 src_image.GlType(), static_cast<GLsizei>(bgr_pbo_size), nullptr);
1137
1138 // Copy from PBO to destination in desired GL format
1139 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1140 glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width);
1141 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr_pbo.handle);
1142 glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
1143 copy.dst_subresource.num_layers, dst_image.GlFormat(),
1144 dst_image.GlType(), nullptr);
1145 }
1146}
1147
1115} // namespace OpenGL 1148} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h
index 4a4f6301c..c498a8a8f 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -47,6 +47,19 @@ struct FormatProperties {
47 bool is_compressed; 47 bool is_compressed;
48}; 48};
49 49
50class BGRCopyPass {
51public:
52 BGRCopyPass() = default;
53 ~BGRCopyPass() = default;
54
55 void CopyBGR(Image& dst_image, Image& src_image,
56 std::span<const VideoCommon::ImageCopy> copies);
57
58private:
59 OGLBuffer bgr_pbo;
60 size_t bgr_pbo_size{};
61};
62
50class TextureCacheRuntime { 63class TextureCacheRuntime {
51 friend Framebuffer; 64 friend Framebuffer;
52 friend Image; 65 friend Image;
@@ -118,6 +131,7 @@ private:
118 const Device& device; 131 const Device& device;
119 StateTracker& state_tracker; 132 StateTracker& state_tracker;
120 UtilShaders util_shaders; 133 UtilShaders util_shaders;
134 BGRCopyPass bgr_copy_pass;
121 135
122 std::array<std::unordered_map<GLenum, FormatProperties>, 3> format_properties; 136 std::array<std::unordered_map<GLenum, FormatProperties>, 3> format_properties;
123 bool has_broken_texture_view_formats = false; 137 bool has_broken_texture_view_formats = false;
@@ -162,6 +176,14 @@ public:
162 return texture.handle; 176 return texture.handle;
163 } 177 }
164 178
179 GLuint GlFormat() const noexcept {
180 return gl_format;
181 }
182
183 GLuint GlType() const noexcept {
184 return gl_type;
185 }
186
165private: 187private:
166 void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset); 188 void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset);
167 189
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h
index 672f94bfc..39158aa3e 100644
--- a/src/video_core/renderer_opengl/maxwell_to_gl.h
+++ b/src/video_core/renderer_opengl/maxwell_to_gl.h
@@ -52,7 +52,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB
52 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT 52 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT
53 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT 53 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT
54 {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM 54 {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM
55 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_UNORM 55 {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_UNORM
56 {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT 56 {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT
57 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT 57 {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT
58 {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT 58 {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT
@@ -81,7 +81,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB
81 {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM 81 {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM
82 {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM 82 {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM
83 {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM 83 {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM
84 {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_SRGB 84 {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_SRGB
85 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB 85 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB
86 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB 86 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB
87 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB 87 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB
diff --git a/src/video_core/renderer_opengl/util_shaders.cpp b/src/video_core/renderer_opengl/util_shaders.cpp
index 333f35a1c..897c380b3 100644
--- a/src/video_core/renderer_opengl/util_shaders.cpp
+++ b/src/video_core/renderer_opengl/util_shaders.cpp
@@ -14,7 +14,6 @@
14#include "video_core/host_shaders/block_linear_unswizzle_2d_comp.h" 14#include "video_core/host_shaders/block_linear_unswizzle_2d_comp.h"
15#include "video_core/host_shaders/block_linear_unswizzle_3d_comp.h" 15#include "video_core/host_shaders/block_linear_unswizzle_3d_comp.h"
16#include "video_core/host_shaders/opengl_copy_bc4_comp.h" 16#include "video_core/host_shaders/opengl_copy_bc4_comp.h"
17#include "video_core/host_shaders/opengl_copy_bgra_comp.h"
18#include "video_core/host_shaders/pitch_unswizzle_comp.h" 17#include "video_core/host_shaders/pitch_unswizzle_comp.h"
19#include "video_core/renderer_opengl/gl_shader_manager.h" 18#include "video_core/renderer_opengl/gl_shader_manager.h"
20#include "video_core/renderer_opengl/gl_shader_util.h" 19#include "video_core/renderer_opengl/gl_shader_util.h"
@@ -44,11 +43,6 @@ namespace {
44OGLProgram MakeProgram(std::string_view source) { 43OGLProgram MakeProgram(std::string_view source) {
45 return CreateProgram(source, GL_COMPUTE_SHADER); 44 return CreateProgram(source, GL_COMPUTE_SHADER);
46} 45}
47
48size_t NumPixelsInCopy(const VideoCommon::ImageCopy& copy) {
49 return static_cast<size_t>(copy.extent.width * copy.extent.height *
50 copy.src_subresource.num_layers);
51}
52} // Anonymous namespace 46} // Anonymous namespace
53 47
54UtilShaders::UtilShaders(ProgramManager& program_manager_) 48UtilShaders::UtilShaders(ProgramManager& program_manager_)
@@ -56,7 +50,6 @@ UtilShaders::UtilShaders(ProgramManager& program_manager_)
56 block_linear_unswizzle_2d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_2D_COMP)), 50 block_linear_unswizzle_2d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_2D_COMP)),
57 block_linear_unswizzle_3d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_3D_COMP)), 51 block_linear_unswizzle_3d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_3D_COMP)),
58 pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)), 52 pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)),
59 copy_bgra_program(MakeProgram(OPENGL_COPY_BGRA_COMP)),
60 copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) { 53 copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) {
61 const auto swizzle_table = Tegra::Texture::MakeSwizzleTable(); 54 const auto swizzle_table = Tegra::Texture::MakeSwizzleTable();
62 swizzle_table_buffer.Create(); 55 swizzle_table_buffer.Create();
@@ -255,43 +248,6 @@ void UtilShaders::CopyBC4(Image& dst_image, Image& src_image, std::span<const Im
255 program_manager.RestoreGuestCompute(); 248 program_manager.RestoreGuestCompute();
256} 249}
257 250
258void UtilShaders::CopyBGR(Image& dst_image, Image& src_image,
259 std::span<const VideoCommon::ImageCopy> copies) {
260 static constexpr GLuint BINDING_INPUT_IMAGE = 0;
261 static constexpr GLuint BINDING_OUTPUT_IMAGE = 1;
262 static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0};
263 const u32 bytes_per_block = BytesPerBlock(dst_image.info.format);
264 switch (bytes_per_block) {
265 case 2:
266 // BGR565 copy
267 for (const ImageCopy& copy : copies) {
268 ASSERT(copy.src_offset == zero_offset);
269 ASSERT(copy.dst_offset == zero_offset);
270 bgr_copy_pass.Execute(dst_image, src_image, copy);
271 }
272 break;
273 case 4: {
274 // BGRA8 copy
275 program_manager.BindComputeProgram(copy_bgra_program.handle);
276 constexpr GLenum FORMAT = GL_RGBA8;
277 for (const ImageCopy& copy : copies) {
278 ASSERT(copy.src_offset == zero_offset);
279 ASSERT(copy.dst_offset == zero_offset);
280 glBindImageTexture(BINDING_INPUT_IMAGE, src_image.StorageHandle(),
281 copy.src_subresource.base_level, GL_FALSE, 0, GL_READ_ONLY, FORMAT);
282 glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.StorageHandle(),
283 copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, FORMAT);
284 glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth);
285 }
286 program_manager.RestoreGuestCompute();
287 break;
288 }
289 default:
290 UNREACHABLE();
291 break;
292 }
293}
294
295GLenum StoreFormat(u32 bytes_per_block) { 251GLenum StoreFormat(u32 bytes_per_block) {
296 switch (bytes_per_block) { 252 switch (bytes_per_block) {
297 case 1: 253 case 1:
@@ -309,36 +265,4 @@ GLenum StoreFormat(u32 bytes_per_block) {
309 return GL_R8UI; 265 return GL_R8UI;
310} 266}
311 267
312void Bgr565CopyPass::Execute(const Image& dst_image, const Image& src_image,
313 const ImageCopy& copy) {
314 if (CopyBufferCreationNeeded(copy)) {
315 CreateNewCopyBuffer(copy, GL_TEXTURE_2D_ARRAY, GL_RGB565);
316 }
317 // Copy from source to PBO
318 glPixelStorei(GL_PACK_ALIGNMENT, 1);
319 glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width);
320 glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr16_pbo.handle);
321 glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
322 copy.src_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
323 static_cast<GLsizei>(bgr16_pbo_size), nullptr);
324
325 // Copy from PBO to destination in reverse order
326 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
327 glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width);
328 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr16_pbo.handle);
329 glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
330 copy.dst_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV,
331 nullptr);
332}
333
334bool Bgr565CopyPass::CopyBufferCreationNeeded(const ImageCopy& copy) {
335 return bgr16_pbo_size < NumPixelsInCopy(copy) * sizeof(u16);
336}
337
338void Bgr565CopyPass::CreateNewCopyBuffer(const ImageCopy& copy, GLenum target, GLuint format) {
339 bgr16_pbo.Create();
340 bgr16_pbo_size = NumPixelsInCopy(copy) * sizeof(u16);
341 glNamedBufferData(bgr16_pbo.handle, bgr16_pbo_size, nullptr, GL_STREAM_COPY);
342}
343
344} // namespace OpenGL 268} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/util_shaders.h b/src/video_core/renderer_opengl/util_shaders.h
index ef881e35f..5de95ea7a 100644
--- a/src/video_core/renderer_opengl/util_shaders.h
+++ b/src/video_core/renderer_opengl/util_shaders.h
@@ -19,22 +19,6 @@ class ProgramManager;
19 19
20struct ImageBufferMap; 20struct ImageBufferMap;
21 21
22class Bgr565CopyPass {
23public:
24 Bgr565CopyPass() = default;
25 ~Bgr565CopyPass() = default;
26
27 void Execute(const Image& dst_image, const Image& src_image,
28 const VideoCommon::ImageCopy& copy);
29
30private:
31 [[nodiscard]] bool CopyBufferCreationNeeded(const VideoCommon::ImageCopy& copy);
32 void CreateNewCopyBuffer(const VideoCommon::ImageCopy& copy, GLenum target, GLuint format);
33
34 OGLBuffer bgr16_pbo;
35 size_t bgr16_pbo_size{};
36};
37
38class UtilShaders { 22class UtilShaders {
39public: 23public:
40 explicit UtilShaders(ProgramManager& program_manager); 24 explicit UtilShaders(ProgramManager& program_manager);
@@ -55,9 +39,6 @@ public:
55 void CopyBC4(Image& dst_image, Image& src_image, 39 void CopyBC4(Image& dst_image, Image& src_image,
56 std::span<const VideoCommon::ImageCopy> copies); 40 std::span<const VideoCommon::ImageCopy> copies);
57 41
58 void CopyBGR(Image& dst_image, Image& src_image,
59 std::span<const VideoCommon::ImageCopy> copies);
60
61private: 42private:
62 ProgramManager& program_manager; 43 ProgramManager& program_manager;
63 44
@@ -67,10 +48,7 @@ private:
67 OGLProgram block_linear_unswizzle_2d_program; 48 OGLProgram block_linear_unswizzle_2d_program;
68 OGLProgram block_linear_unswizzle_3d_program; 49 OGLProgram block_linear_unswizzle_3d_program;
69 OGLProgram pitch_unswizzle_program; 50 OGLProgram pitch_unswizzle_program;
70 OGLProgram copy_bgra_program;
71 OGLProgram copy_bc4_program; 51 OGLProgram copy_bc4_program;
72
73 Bgr565CopyPass bgr_copy_pass;
74}; 52};
75 53
76GLenum StoreFormat(u32 bytes_per_block); 54GLenum StoreFormat(u32 bytes_per_block);