summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorGravatar Feng Chen2021-12-18 13:57:14 +0800
committerGravatar GitHub2021-12-18 13:57:14 +0800
commite49184e6069a9d791d2df3c1958f5c4b1187e124 (patch)
treeb776caf722e0be0e680f67b0ad0842628162ef1c /src/video_core/renderer_opengl
parentImplement convert legacy to generic (diff)
parentMerge pull request #7570 from ameerj/favorites-expanded (diff)
downloadyuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp63
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.h12
-rw-r--r--src/video_core/renderer_opengl/maxwell_to_gl.h1
3 files changed, 52 insertions, 24 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 6956535e5..14e6522f2 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -9,6 +9,7 @@
9 9
10#include <glad/glad.h> 10#include <glad/glad.h>
11 11
12#include "common/bit_util.h"
12#include "common/literals.h" 13#include "common/literals.h"
13#include "common/settings.h" 14#include "common/settings.h"
14#include "video_core/renderer_opengl/gl_device.h" 15#include "video_core/renderer_opengl/gl_device.h"
@@ -148,6 +149,8 @@ GLenum AttachmentType(PixelFormat format) {
148 switch (const SurfaceType type = VideoCore::Surface::GetFormatType(format); type) { 149 switch (const SurfaceType type = VideoCore::Surface::GetFormatType(format); type) {
149 case SurfaceType::Depth: 150 case SurfaceType::Depth:
150 return GL_DEPTH_ATTACHMENT; 151 return GL_DEPTH_ATTACHMENT;
152 case SurfaceType::Stencil:
153 return GL_STENCIL_ATTACHMENT;
151 case SurfaceType::DepthStencil: 154 case SurfaceType::DepthStencil:
152 return GL_DEPTH_STENCIL_ATTACHMENT; 155 return GL_DEPTH_STENCIL_ATTACHMENT;
153 default: 156 default:
@@ -317,13 +320,12 @@ void AttachTexture(GLuint fbo, GLenum attachment, const ImageView* image_view) {
317 } 320 }
318} 321}
319 322
320OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format) { 323OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format,
324 GLsizei gl_num_levels) {
321 const GLenum target = ImageTarget(info); 325 const GLenum target = ImageTarget(info);
322 const GLsizei width = info.size.width; 326 const GLsizei width = info.size.width;
323 const GLsizei height = info.size.height; 327 const GLsizei height = info.size.height;
324 const GLsizei depth = info.size.depth; 328 const GLsizei depth = info.size.depth;
325 const int max_host_mip_levels = std::bit_width(info.size.width);
326 const GLsizei num_levels = std::min(info.resources.levels, max_host_mip_levels);
327 const GLsizei num_layers = info.resources.layers; 329 const GLsizei num_layers = info.resources.layers;
328 const GLsizei num_samples = info.num_samples; 330 const GLsizei num_samples = info.num_samples;
329 331
@@ -335,10 +337,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
335 } 337 }
336 switch (target) { 338 switch (target) {
337 case GL_TEXTURE_1D_ARRAY: 339 case GL_TEXTURE_1D_ARRAY:
338 glTextureStorage2D(handle, num_levels, gl_internal_format, width, num_layers); 340 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, num_layers);
339 break; 341 break;
340 case GL_TEXTURE_2D_ARRAY: 342 case GL_TEXTURE_2D_ARRAY:
341 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, num_layers); 343 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, num_layers);
342 break; 344 break;
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: { 345 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: {
344 // TODO: Where should 'fixedsamplelocations' come from? 346 // TODO: Where should 'fixedsamplelocations' come from?
@@ -348,10 +350,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
348 break; 350 break;
349 } 351 }
350 case GL_TEXTURE_RECTANGLE: 352 case GL_TEXTURE_RECTANGLE:
351 glTextureStorage2D(handle, num_levels, gl_internal_format, width, height); 353 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, height);
352 break; 354 break;
353 case GL_TEXTURE_3D: 355 case GL_TEXTURE_3D:
354 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, depth); 356 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, depth);
355 break; 357 break;
356 case GL_TEXTURE_BUFFER: 358 case GL_TEXTURE_BUFFER:
357 UNREACHABLE(); 359 UNREACHABLE();
@@ -397,9 +399,6 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
397 return GL_R32UI; 399 return GL_R32UI;
398} 400}
399 401
400[[nodiscard]] u32 NextPow2(u32 value) {
401 return 1U << (32U - std::countl_zero(value - 1U));
402}
403} // Anonymous namespace 402} // Anonymous namespace
404 403
405ImageBufferMap::~ImageBufferMap() { 404ImageBufferMap::~ImageBufferMap() {
@@ -526,8 +525,8 @@ void TextureCacheRuntime::CopyImage(Image& dst_image, Image& src_image,
526 } 525 }
527} 526}
528 527
529void TextureCacheRuntime::ConvertImage(Image& dst, Image& src, 528void TextureCacheRuntime::ReinterpretImage(Image& dst, Image& src,
530 std::span<const VideoCommon::ImageCopy> copies) { 529 std::span<const VideoCommon::ImageCopy> copies) {
531 LOG_DEBUG(Render_OpenGL, "Converting {} to {}", src.info.format, dst.info.format); 530 LOG_DEBUG(Render_OpenGL, "Converting {} to {}", src.info.format, dst.info.format);
532 format_conversion_pass.ConvertImage(dst, src, copies); 531 format_conversion_pass.ConvertImage(dst, src, copies);
533} 532}
@@ -696,7 +695,9 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_,
696 gl_format = tuple.format; 695 gl_format = tuple.format;
697 gl_type = tuple.type; 696 gl_type = tuple.type;
698 } 697 }
699 texture = MakeImage(info, gl_internal_format); 698 const int max_host_mip_levels = std::bit_width(info.size.width);
699 gl_num_levels = std::min(info.resources.levels, max_host_mip_levels);
700 texture = MakeImage(info, gl_internal_format, gl_num_levels);
700 current_texture = texture.handle; 701 current_texture = texture.handle;
701 if (runtime->device.HasDebuggingToolAttached()) { 702 if (runtime->device.HasDebuggingToolAttached()) {
702 const std::string name = VideoCommon::Name(*this); 703 const std::string name = VideoCommon::Name(*this);
@@ -724,6 +725,9 @@ void Image::UploadMemory(const ImageBufferMap& map,
724 u32 current_image_height = std::numeric_limits<u32>::max(); 725 u32 current_image_height = std::numeric_limits<u32>::max();
725 726
726 for (const VideoCommon::BufferImageCopy& copy : copies) { 727 for (const VideoCommon::BufferImageCopy& copy : copies) {
728 if (copy.image_subresource.base_level >= gl_num_levels) {
729 continue;
730 }
727 if (current_row_length != copy.buffer_row_length) { 731 if (current_row_length != copy.buffer_row_length) {
728 current_row_length = copy.buffer_row_length; 732 current_row_length = copy.buffer_row_length;
729 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length); 733 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length);
@@ -753,6 +757,9 @@ void Image::DownloadMemory(ImageBufferMap& map,
753 u32 current_image_height = std::numeric_limits<u32>::max(); 757 u32 current_image_height = std::numeric_limits<u32>::max();
754 758
755 for (const VideoCommon::BufferImageCopy& copy : copies) { 759 for (const VideoCommon::BufferImageCopy& copy : copies) {
760 if (copy.image_subresource.base_level >= gl_num_levels) {
761 continue;
762 }
756 if (current_row_length != copy.buffer_row_length) { 763 if (current_row_length != copy.buffer_row_length) {
757 current_row_length = copy.buffer_row_length; 764 current_row_length = copy.buffer_row_length;
758 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length); 765 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length);
@@ -792,7 +799,7 @@ GLuint Image::StorageHandle() noexcept {
792 } 799 }
793 store_view.Create(); 800 store_view.Create();
794 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0, 801 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0,
795 info.resources.levels, 0, info.resources.layers); 802 gl_num_levels, 0, info.resources.layers);
796 return store_view.handle; 803 return store_view.handle;
797 default: 804 default:
798 return current_texture; 805 return current_texture;
@@ -907,6 +914,8 @@ void Image::Scale(bool up_scale) {
907 return GL_COLOR_ATTACHMENT0; 914 return GL_COLOR_ATTACHMENT0;
908 case SurfaceType::Depth: 915 case SurfaceType::Depth:
909 return GL_DEPTH_ATTACHMENT; 916 return GL_DEPTH_ATTACHMENT;
917 case SurfaceType::Stencil:
918 return GL_STENCIL_ATTACHMENT;
910 case SurfaceType::DepthStencil: 919 case SurfaceType::DepthStencil:
911 return GL_DEPTH_STENCIL_ATTACHMENT; 920 return GL_DEPTH_STENCIL_ATTACHMENT;
912 default: 921 default:
@@ -920,8 +929,10 @@ void Image::Scale(bool up_scale) {
920 return GL_COLOR_BUFFER_BIT; 929 return GL_COLOR_BUFFER_BIT;
921 case SurfaceType::Depth: 930 case SurfaceType::Depth:
922 return GL_DEPTH_BUFFER_BIT; 931 return GL_DEPTH_BUFFER_BIT;
932 case SurfaceType::Stencil:
933 return GL_STENCIL_BUFFER_BIT;
923 case SurfaceType::DepthStencil: 934 case SurfaceType::DepthStencil:
924 return GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; 935 return GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
925 default: 936 default:
926 UNREACHABLE(); 937 UNREACHABLE();
927 return GL_COLOR_BUFFER_BIT; 938 return GL_COLOR_BUFFER_BIT;
@@ -933,8 +944,10 @@ void Image::Scale(bool up_scale) {
933 return 0; 944 return 0;
934 case SurfaceType::Depth: 945 case SurfaceType::Depth:
935 return 1; 946 return 1;
936 case SurfaceType::DepthStencil: 947 case SurfaceType::Stencil:
937 return 2; 948 return 2;
949 case SurfaceType::DepthStencil:
950 return 3;
938 default: 951 default:
939 UNREACHABLE(); 952 UNREACHABLE();
940 return 0; 953 return 0;
@@ -956,7 +969,7 @@ void Image::Scale(bool up_scale) {
956 auto dst_info = info; 969 auto dst_info = info;
957 dst_info.size.width = scaled_width; 970 dst_info.size.width = scaled_width;
958 dst_info.size.height = scaled_height; 971 dst_info.size.height = scaled_height;
959 upscaled_backup = MakeImage(dst_info, gl_internal_format); 972 upscaled_backup = MakeImage(dst_info, gl_internal_format, gl_num_levels);
960 } 973 }
961 const u32 src_width = up_scale ? original_width : scaled_width; 974 const u32 src_width = up_scale ? original_width : scaled_width;
962 const u32 src_height = up_scale ? original_height : scaled_height; 975 const u32 src_height = up_scale ? original_height : scaled_height;
@@ -1264,10 +1277,20 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM
1264 } 1277 }
1265 1278
1266 if (const ImageView* const image_view = depth_buffer; image_view) { 1279 if (const ImageView* const image_view = depth_buffer; image_view) {
1267 if (GetFormatType(image_view->format) == SurfaceType::DepthStencil) { 1280 switch (GetFormatType(image_view->format)) {
1281 case SurfaceType::Depth:
1282 buffer_bits |= GL_DEPTH_BUFFER_BIT;
1283 break;
1284 case SurfaceType::Stencil:
1285 buffer_bits |= GL_STENCIL_BUFFER_BIT;
1286 break;
1287 case SurfaceType::DepthStencil:
1268 buffer_bits |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; 1288 buffer_bits |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
1269 } else { 1289 break;
1290 default:
1291 UNREACHABLE();
1270 buffer_bits |= GL_DEPTH_BUFFER_BIT; 1292 buffer_bits |= GL_DEPTH_BUFFER_BIT;
1293 break;
1271 } 1294 }
1272 const GLenum attachment = AttachmentType(image_view->format); 1295 const GLenum attachment = AttachmentType(image_view->format);
1273 AttachTexture(handle, attachment, image_view); 1296 AttachTexture(handle, attachment, image_view);
@@ -1308,7 +1331,7 @@ void FormatConversionPass::ConvertImage(Image& dst_image, Image& src_image,
1308 const u32 copy_size = region.width * region.height * region.depth * img_bpp; 1331 const u32 copy_size = region.width * region.height * region.depth * img_bpp;
1309 if (pbo_size < copy_size) { 1332 if (pbo_size < copy_size) {
1310 intermediate_pbo.Create(); 1333 intermediate_pbo.Create();
1311 pbo_size = NextPow2(copy_size); 1334 pbo_size = Common::NextPow2(copy_size);
1312 glNamedBufferData(intermediate_pbo.handle, pbo_size, nullptr, GL_STREAM_COPY); 1335 glNamedBufferData(intermediate_pbo.handle, pbo_size, nullptr, GL_STREAM_COPY);
1313 } 1336 }
1314 // Copy from source to PBO 1337 // Copy from source to PBO
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h
index 578f8d523..37d5e6a6b 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -84,9 +84,13 @@ public:
84 84
85 u64 GetDeviceLocalMemory() const; 85 u64 GetDeviceLocalMemory() const;
86 86
87 bool ShouldReinterpret([[maybe_unused]] Image& dst, [[maybe_unused]] Image& src) {
88 return true;
89 }
90
87 void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies); 91 void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
88 92
89 void ConvertImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies); 93 void ReinterpretImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
90 94
91 void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view, bool rescaled) { 95 void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view, bool rescaled) {
92 UNIMPLEMENTED(); 96 UNIMPLEMENTED();
@@ -164,8 +168,8 @@ private:
164 168
165 std::array<GLuint, Shader::NUM_TEXTURE_TYPES> null_image_views{}; 169 std::array<GLuint, Shader::NUM_TEXTURE_TYPES> null_image_views{};
166 170
167 std::array<OGLFramebuffer, 3> rescale_draw_fbos; 171 std::array<OGLFramebuffer, 4> rescale_draw_fbos;
168 std::array<OGLFramebuffer, 3> rescale_read_fbos; 172 std::array<OGLFramebuffer, 4> rescale_read_fbos;
169 const Settings::ResolutionScalingInfo& resolution; 173 const Settings::ResolutionScalingInfo& resolution;
170}; 174};
171 175
@@ -221,6 +225,7 @@ private:
221 GLenum gl_internal_format = GL_NONE; 225 GLenum gl_internal_format = GL_NONE;
222 GLenum gl_format = GL_NONE; 226 GLenum gl_format = GL_NONE;
223 GLenum gl_type = GL_NONE; 227 GLenum gl_type = GL_NONE;
228 GLsizei gl_num_levels{};
224 TextureCacheRuntime* runtime{}; 229 TextureCacheRuntime* runtime{};
225 GLuint current_texture{}; 230 GLuint current_texture{};
226}; 231};
@@ -338,7 +343,6 @@ struct TextureCacheParams {
338 static constexpr bool FRAMEBUFFER_BLITS = true; 343 static constexpr bool FRAMEBUFFER_BLITS = true;
339 static constexpr bool HAS_EMULATED_COPIES = true; 344 static constexpr bool HAS_EMULATED_COPIES = true;
340 static constexpr bool HAS_DEVICE_MEMORY_INFO = true; 345 static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
341 static constexpr bool HAS_PIXEL_FORMAT_CONVERSIONS = true;
342 346
343 using Runtime = OpenGL::TextureCacheRuntime; 347 using Runtime = OpenGL::TextureCacheRuntime;
344 using Image = OpenGL::Image; 348 using Image = OpenGL::Image;
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h
index 39158aa3e..daba42ed9 100644
--- a/src/video_core/renderer_opengl/maxwell_to_gl.h
+++ b/src/video_core/renderer_opengl/maxwell_to_gl.h
@@ -108,6 +108,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB
108 {GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, // E5B9G9R9_FLOAT 108 {GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, // E5B9G9R9_FLOAT
109 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, // D32_FLOAT 109 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, // D32_FLOAT
110 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, // D16_UNORM 110 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, // D16_UNORM
111 {GL_STENCIL_INDEX8, GL_STENCIL, GL_UNSIGNED_BYTE}, // S8_UINT
111 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // D24_UNORM_S8_UINT 112 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // D24_UNORM_S8_UINT
112 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // S8_UINT_D24_UNORM 113 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // S8_UINT_D24_UNORM
113 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, 114 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL,