From f5f6292810dab70bc9be0fa4d9f37fe2b5544d86 Mon Sep 17 00:00:00 2001 From: Carl Kenner Date: Fri, 5 Oct 2018 12:52:49 +0930 Subject: [PATCH 01/11] logging: Add DebuggerBackend for logging to Visual Studio --- src/common/logging/backend.cpp | 11 +++++++++-- src/common/logging/backend.h | 14 ++++++++++++++ src/yuzu/main.cpp | 3 +++ src/yuzu_cmd/yuzu.cpp | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 9f59188510..31ad72f386 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -12,7 +12,8 @@ #include #include #ifdef _WIN32 -#include // For _SH_DENYWR +#include // For _SH_DENYWR +#include // For OutputDebugStringA #else #define _SH_DENYWR 0 #endif @@ -139,12 +140,18 @@ void FileBackend::Write(const Entry& entry) { if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { return; } - bytes_written += file.WriteString(FormatLogMessage(entry) + '\n'); + bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); if (entry.log_level >= Level::Error) { file.Flush(); } } +void DebuggerBackend::Write(const Entry& entry) { +#ifdef _WIN32 + ::OutputDebugStringA(FormatLogMessage(entry).append(1, '\n').c_str()); +#endif +} + /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. #define ALL_LOG_CLASSES() \ CLS(Log) \ diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 11edbf1b6a..91bb0c309c 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -103,6 +103,20 @@ private: std::size_t bytes_written; }; +/** + * Backend that writes to Visual Studio's output window + */ +class DebuggerBackend : public Backend { +public: + static const char* Name() { + return "debugger"; + } + const char* GetName() const override { + return Name(); + } + void Write(const Entry& entry) override; +}; + void AddBackend(std::unique_ptr backend); void RemoveBackend(std::string_view backend_name); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index ad62a82d0a..1d06d6c95a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -135,6 +135,9 @@ static void InitializeLogging() { const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); FileUtil::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); +#ifdef _WIN32 + Log::AddBackend(std::make_unique()); +#endif } GMainWindow::GMainWindow() diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 1d951ca3f1..bab465c1d6 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -75,6 +75,9 @@ static void InitializeLogging() { const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); FileUtil::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); +#ifdef _WIN32 + Log::AddBackend(std::make_unique()); +#endif } /// Application entry point From 678c18aa5cca65042d3b91b655fd713f37304592 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Thu, 18 Oct 2018 20:04:43 -0400 Subject: [PATCH 02/11] Implement Cube Arrays --- .../renderer_opengl/gl_rasterizer_cache.cpp | 14 ++++++++++++++ .../renderer_opengl/gl_rasterizer_cache.h | 2 ++ src/video_core/surface.cpp | 3 +++ src/video_core/surface.h | 1 + 4 files changed, 20 insertions(+) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index f194a76872..752c4ee84f 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -128,6 +128,13 @@ std::size_t SurfaceParams::InnerMemorySize(bool force_gl, bool layer_only, params.target = SurfaceTarget::Texture2D; } break; + case SurfaceTarget::TextureCubeArray: + params.depth = config.tic.Depth() * 6; + if (!entry.IsArray()) { + ASSERT(params.depth == 6); + params.target = SurfaceTarget::TextureCubemap; + } + break; default: LOG_CRITICAL(HW_GPU, "Unknown depth for target={}", static_cast(params.target)); UNREACHABLE(); @@ -334,6 +341,8 @@ static GLenum SurfaceTargetToGL(SurfaceTarget target) { return GL_TEXTURE_2D_ARRAY; case SurfaceTarget::TextureCubemap: return GL_TEXTURE_CUBE_MAP; + case SurfaceTarget::TextureCubeArray: + return GL_TEXTURE_CUBE_MAP_ARRAY_ARB; } LOG_CRITICAL(Render_OpenGL, "Unimplemented texture target={}", static_cast(target)); UNREACHABLE(); @@ -754,6 +763,7 @@ static void CopySurface(const Surface& src_surface, const Surface& dst_surface, break; case SurfaceTarget::Texture3D: case SurfaceTarget::Texture2DArray: + case SurfaceTarget::TextureCubeArray: glTextureSubImage3D(dst_surface->Texture().handle, 0, 0, 0, 0, width, height, static_cast(dst_params.depth), dest_format.format, dest_format.type, nullptr); @@ -806,6 +816,7 @@ CachedSurface::CachedSurface(const SurfaceParams& params) break; case SurfaceTarget::Texture3D: case SurfaceTarget::Texture2DArray: + case SurfaceTarget::TextureCubeArray: glTexStorage3D(SurfaceTargetToGL(params.target), params.max_mip_level, format_tuple.internal_format, rect.GetWidth(), rect.GetHeight(), params.depth); @@ -1055,6 +1066,7 @@ void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, &gl_buffer[mip_map][buffer_offset]); break; case SurfaceTarget::Texture2DArray: + case SurfaceTarget::TextureCubeArray: glCompressedTexImage3D(SurfaceTargetToGL(params.target), mip_map, tuple.internal_format, static_cast(params.MipWidth(mip_map)), static_cast(params.MipHeight(mip_map)), @@ -1104,6 +1116,7 @@ void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, tuple.format, tuple.type, &gl_buffer[mip_map][buffer_offset]); break; case SurfaceTarget::Texture2DArray: + case SurfaceTarget::TextureCubeArray: glTexSubImage3D(SurfaceTargetToGL(params.target), mip_map, x0, y0, 0, static_cast(rect.GetWidth()), static_cast(rect.GetHeight()), params.depth, tuple.format, @@ -1306,6 +1319,7 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& old_surface, break; case SurfaceTarget::TextureCubemap: case SurfaceTarget::Texture3D: + case SurfaceTarget::TextureCubeArray: AccurateCopySurface(old_surface, new_surface); break; default: diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index f255f4419c..5a5f2cec0f 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -49,6 +49,8 @@ struct SurfaceParams { return "Texture2DArray"; case SurfaceTarget::TextureCubemap: return "TextureCubemap"; + case SurfaceTarget::TextureCubeArray: + return "TextureCubeArray"; default: LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast(target)); UNREACHABLE(); diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index d9a97e30b9..e6941b95f6 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -19,6 +19,8 @@ SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_t return SurfaceTarget::Texture3D; case Tegra::Texture::TextureType::TextureCubemap: return SurfaceTarget::TextureCubemap; + case Tegra::Texture::TextureType::TextureCubeArray: + return SurfaceTarget::TextureCubeArray; case Tegra::Texture::TextureType::Texture1DArray: return SurfaceTarget::Texture1DArray; case Tegra::Texture::TextureType::Texture2DArray: @@ -39,6 +41,7 @@ bool SurfaceTargetIsLayered(SurfaceTarget target) { case SurfaceTarget::Texture1DArray: case SurfaceTarget::Texture2DArray: case SurfaceTarget::TextureCubemap: + case SurfaceTarget::TextureCubeArray: return true; default: LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast(target)); diff --git a/src/video_core/surface.h b/src/video_core/surface.h index 3232e437f3..25300a193c 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -118,6 +118,7 @@ enum class SurfaceTarget { Texture1DArray, Texture2DArray, TextureCubemap, + TextureCubeArray, }; /** From 31930a3334df4fc352621d3c0bd31d03c81bc99e Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 29 Oct 2018 18:23:32 -0400 Subject: [PATCH 03/11] Implemented ASTC 5x5 --- src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index f194a76872..43c47cb109 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -305,6 +305,8 @@ static constexpr std::array tex {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X8_SRGB {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_8X5_SRGB {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X4_SRGB + {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X5 + {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_5X5_SRGB // Depth formats {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, ComponentType::Float, false}, // Z32F @@ -903,10 +905,12 @@ static void ConvertFormatAsNeeded_LoadGLBuffer(std::vector& data, PixelForma case PixelFormat::ASTC_2D_8X8: case PixelFormat::ASTC_2D_8X5: case PixelFormat::ASTC_2D_5X4: + case PixelFormat::ASTC_2D_5X5: case PixelFormat::ASTC_2D_4X4_SRGB: case PixelFormat::ASTC_2D_8X8_SRGB: case PixelFormat::ASTC_2D_8X5_SRGB: - case PixelFormat::ASTC_2D_5X4_SRGB: { + case PixelFormat::ASTC_2D_5X4_SRGB: + case PixelFormat::ASTC_2D_5X5_SRGB: { // Convert ASTC pixel formats to RGBA8, as most desktop GPUs do not support ASTC. u32 block_width{}; u32 block_height{}; From aee93f98f9ea68404a3de0ab8d7bd7e954924318 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 29 Oct 2018 21:34:44 -0400 Subject: [PATCH 04/11] Fix ASTC formats --- .../renderer_opengl/gl_rasterizer_cache.cpp | 15 +++++++++++---- src/video_core/textures/decoders.cpp | 12 +++++++----- src/video_core/textures/decoders.h | 4 ++-- src/yuzu/debugger/graphics/graphics_surface.cpp | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 43c47cb109..19b1d04b96 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -366,15 +366,18 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 d // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual // pixel values. - const u32 tile_size{IsFormatBCn(format) ? 4U : 1U}; + const u32 tile_size_x{SurfaceParams::GetDefaultBlockWidth(format)}; + const u32 tile_size_y{SurfaceParams::GetDefaultBlockHeight(format)}; if (morton_to_gl) { - const std::vector data = Tegra::Texture::UnswizzleTexture( - addr, tile_size, bytes_per_pixel, stride, height, depth, block_height, block_depth); + const std::vector data = + Tegra::Texture::UnswizzleTexture(addr, tile_size_x, tile_size_y, bytes_per_pixel, + stride, height, depth, block_height, block_depth); const std::size_t size_to_copy{std::min(gl_buffer_size, data.size())}; memcpy(gl_buffer, data.data(), size_to_copy); } else { - Tegra::Texture::CopySwizzledData(stride / tile_size, height / tile_size, depth, + Tegra::Texture::CopySwizzledData((stride + tile_size_x - 1) / tile_size_x, + (height + tile_size_y - 1) / tile_size_y, depth, bytes_per_pixel, bytes_per_pixel, Memory::GetPointer(addr), gl_buffer, false, block_height, block_depth); } @@ -442,6 +445,8 @@ static constexpr GLConversionArray morton_to_gl_fns = { MortonCopy, MortonCopy, MortonCopy, + MortonCopy, + MortonCopy, MortonCopy, MortonCopy, MortonCopy, @@ -510,6 +515,8 @@ static constexpr GLConversionArray gl_to_morton_fns = { nullptr, nullptr, nullptr, + nullptr, + nullptr, MortonCopy, MortonCopy, MortonCopy, diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 550ca856cb..3066abf61b 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -227,12 +227,14 @@ u32 BytesPerPixel(TextureFormat format) { } } -std::vector UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pixel, u32 width, - u32 height, u32 depth, u32 block_height, u32 block_depth) { +std::vector UnswizzleTexture(VAddr address, u32 tile_size_x, u32 tile_size_y, + u32 bytes_per_pixel, u32 width, u32 height, u32 depth, + u32 block_height, u32 block_depth) { std::vector unswizzled_data(width * height * depth * bytes_per_pixel); - CopySwizzledData(width / tile_size, height / tile_size, depth, bytes_per_pixel, bytes_per_pixel, - Memory::GetPointer(address), unswizzled_data.data(), true, block_height, - block_depth); + CopySwizzledData((width + tile_size_x - 1) / tile_size_x, + (height + tile_size_y - 1) / tile_size_y, depth, bytes_per_pixel, + bytes_per_pixel, Memory::GetPointer(address), unswizzled_data.data(), true, + block_height, block_depth); return unswizzled_data; } diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h index b390219e4b..ba065510b9 100644 --- a/src/video_core/textures/decoders.h +++ b/src/video_core/textures/decoders.h @@ -19,8 +19,8 @@ inline std::size_t GetGOBSize() { /** * Unswizzles a swizzled texture without changing its format. */ -std::vector UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pixel, u32 width, - u32 height, u32 depth, +std::vector UnswizzleTexture(VAddr address, u32 tile_size_x, u32 tile_size_y, + u32 bytes_per_pixel, u32 width, u32 height, u32 depth, u32 block_height = TICEntry::DefaultBlockHeight, u32 block_depth = TICEntry::DefaultBlockHeight); diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp index 0adbab27d1..b994a27899 100644 --- a/src/yuzu/debugger/graphics/graphics_surface.cpp +++ b/src/yuzu/debugger/graphics/graphics_surface.cpp @@ -387,7 +387,7 @@ void GraphicsSurfaceWidget::OnUpdate() { // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles. // Needs to be fixed if we plan to use this feature more, otherwise we may remove it. auto unswizzled_data = - Tegra::Texture::UnswizzleTexture(*address, 1, Tegra::Texture::BytesPerPixel(surface_format), + Tegra::Texture::UnswizzleTexture(*address, 1, 1, Tegra::Texture::BytesPerPixel(surface_format), surface_width, surface_height, 1U); auto texture_data = Tegra::Texture::DecodeTexture(unswizzled_data, surface_format, From 60a184455c5aef7cce7e6232cab738f66cb0aac0 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 29 Oct 2018 22:46:09 -0400 Subject: [PATCH 05/11] Fix ASTC Decompressor to support depth parameter --- .../renderer_opengl/gl_rasterizer_cache.cpp | 21 ++-- .../renderer_opengl/gl_rasterizer_cache.h | 2 +- src/video_core/surface.cpp | 26 +---- src/video_core/surface.h | 107 +++++++++++++++--- src/video_core/textures/astc.cpp | 32 +++--- src/video_core/textures/astc.h | 2 +- .../debugger/graphics/graphics_surface.cpp | 6 +- 7 files changed, 131 insertions(+), 65 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 19b1d04b96..0e11557c44 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -58,16 +58,14 @@ void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) { std::size_t SurfaceParams::InnerMipmapMemorySize(u32 mip_level, bool force_gl, bool layer_only, bool uncompressed) const { - const u32 compression_factor{GetCompressionFactor(pixel_format)}; + const u32 tile_x{GetDefaultBlockWidth(pixel_format)}; + const u32 tile_y{GetDefaultBlockHeight(pixel_format)}; const u32 bytes_per_pixel{GetBytesPerPixel(pixel_format)}; u32 m_depth = (layer_only ? 1U : depth); u32 m_width = MipWidth(mip_level); u32 m_height = MipHeight(mip_level); - m_width = uncompressed ? m_width - : std::max(1U, (m_width + compression_factor - 1) / compression_factor); - m_height = uncompressed - ? m_height - : std::max(1U, (m_height + compression_factor - 1) / compression_factor); + m_width = uncompressed ? m_width : std::max(1U, (m_width + tile_x - 1) / tile_x); + m_height = uncompressed ? m_height : std::max(1U, (m_height + tile_y - 1) / tile_y); m_depth = std::max(1U, m_depth >> mip_level); u32 m_block_height = MipBlockHeight(mip_level); u32 m_block_depth = MipBlockDepth(mip_level); @@ -366,8 +364,8 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 d // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual // pixel values. - const u32 tile_size_x{SurfaceParams::GetDefaultBlockWidth(format)}; - const u32 tile_size_y{SurfaceParams::GetDefaultBlockHeight(format)}; + const u32 tile_size_x{GetDefaultBlockWidth(format)}; + const u32 tile_size_y{GetDefaultBlockHeight(format)}; if (morton_to_gl) { const std::vector data = @@ -906,7 +904,7 @@ static void ConvertG8R8ToR8G8(std::vector& data, u32 width, u32 height) { * typical desktop GPUs. */ static void ConvertFormatAsNeeded_LoadGLBuffer(std::vector& data, PixelFormat pixel_format, - u32 width, u32 height) { + u32 width, u32 height, u32 depth) { switch (pixel_format) { case PixelFormat::ASTC_2D_4X4: case PixelFormat::ASTC_2D_8X8: @@ -922,7 +920,8 @@ static void ConvertFormatAsNeeded_LoadGLBuffer(std::vector& data, PixelForma u32 block_width{}; u32 block_height{}; std::tie(block_width, block_height) = GetASTCBlockSize(pixel_format); - data = Tegra::Texture::ASTC::Decompress(data, width, height, block_width, block_height); + data = + Tegra::Texture::ASTC::Decompress(data, width, height, depth, block_width, block_height); break; } case PixelFormat::S8Z24: @@ -982,7 +981,7 @@ void CachedSurface::LoadGLBuffer() { } for (u32 i = 0; i < params.max_mip_level; i++) ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer[i], params.pixel_format, params.MipWidth(i), - params.MipHeight(i)); + params.MipHeight(i), params.MipDepth(i)); } MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64)); diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index f255f4419c..46ad37897c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -139,7 +139,7 @@ struct SurfaceParams { } u32 MipDepth(u32 mip_level) const { - return std::max(1U, depth >> mip_level); + return is_layered ? depth : std::max(1U, depth >> mip_level); } // Auto block resizing algorithm from: diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index d9a97e30b9..e284a4604e 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -297,6 +297,8 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format, return is_srgb ? PixelFormat::ASTC_2D_4X4_SRGB : PixelFormat::ASTC_2D_4X4; case Tegra::Texture::TextureFormat::ASTC_2D_5X4: return is_srgb ? PixelFormat::ASTC_2D_5X4_SRGB : PixelFormat::ASTC_2D_5X4; + case Tegra::Texture::TextureFormat::ASTC_2D_5X5: + return is_srgb ? PixelFormat::ASTC_2D_5X5_SRGB : PixelFormat::ASTC_2D_5X5; case Tegra::Texture::TextureFormat::ASTC_2D_8X8: return is_srgb ? PixelFormat::ASTC_2D_8X8_SRGB : PixelFormat::ASTC_2D_8X8; case Tegra::Texture::TextureFormat::ASTC_2D_8X5: @@ -440,10 +442,12 @@ bool IsPixelFormatASTC(PixelFormat format) { switch (format) { case PixelFormat::ASTC_2D_4X4: case PixelFormat::ASTC_2D_5X4: + case PixelFormat::ASTC_2D_5X5: case PixelFormat::ASTC_2D_8X8: case PixelFormat::ASTC_2D_8X5: case PixelFormat::ASTC_2D_4X4_SRGB: case PixelFormat::ASTC_2D_5X4_SRGB: + case PixelFormat::ASTC_2D_5X5_SRGB: case PixelFormat::ASTC_2D_8X8_SRGB: case PixelFormat::ASTC_2D_8X5_SRGB: return true; @@ -453,27 +457,7 @@ bool IsPixelFormatASTC(PixelFormat format) { } std::pair GetASTCBlockSize(PixelFormat format) { - switch (format) { - case PixelFormat::ASTC_2D_4X4: - return {4, 4}; - case PixelFormat::ASTC_2D_5X4: - return {5, 4}; - case PixelFormat::ASTC_2D_8X8: - return {8, 8}; - case PixelFormat::ASTC_2D_8X5: - return {8, 5}; - case PixelFormat::ASTC_2D_4X4_SRGB: - return {4, 4}; - case PixelFormat::ASTC_2D_5X4_SRGB: - return {5, 4}; - case PixelFormat::ASTC_2D_8X8_SRGB: - return {8, 8}; - case PixelFormat::ASTC_2D_8X5_SRGB: - return {8, 5}; - default: - LOG_CRITICAL(HW_GPU, "Unhandled format: {}", static_cast(format)); - UNREACHABLE(); - } + return {GetDefaultBlockWidth(format), GetDefaultBlockHeight(format)}; } bool IsFormatBCn(PixelFormat format) { diff --git a/src/video_core/surface.h b/src/video_core/surface.h index 3232e437f3..0ef7849a49 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -72,19 +72,21 @@ enum class PixelFormat { ASTC_2D_8X8_SRGB = 54, ASTC_2D_8X5_SRGB = 55, ASTC_2D_5X4_SRGB = 56, + ASTC_2D_5X5 = 57, + ASTC_2D_5X5_SRGB = 58, MaxColorFormat, // Depth formats - Z32F = 57, - Z16 = 58, + Z32F = 59, + Z16 = 60, MaxDepthFormat, // DepthStencil formats - Z24S8 = 59, - S8Z24 = 60, - Z32FS8 = 61, + Z24S8 = 61, + S8Z24 = 62, + Z32FS8 = 63, MaxDepthStencilFormat, @@ -188,6 +190,8 @@ static constexpr u32 GetCompressionFactor(PixelFormat format) { 4, // ASTC_2D_8X8_SRGB 4, // ASTC_2D_8X5_SRGB 4, // ASTC_2D_5X4_SRGB + 4, // ASTC_2D_5X5 + 4, // ASTC_2D_5X5_SRGB 1, // Z32F 1, // Z16 1, // Z24S8 @@ -199,6 +203,79 @@ static constexpr u32 GetCompressionFactor(PixelFormat format) { return compression_factor_table[static_cast(format)]; } +static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { + if (format == PixelFormat::Invalid) + return 0; + constexpr std::array block_width_table = {{ + 1, // ABGR8U + 1, // ABGR8S + 1, // ABGR8UI + 1, // B5G6R5U + 1, // A2B10G10R10U + 1, // A1B5G5R5U + 1, // R8U + 1, // R8UI + 1, // RGBA16F + 1, // RGBA16U + 1, // RGBA16UI + 1, // R11FG11FB10F + 1, // RGBA32UI + 4, // DXT1 + 4, // DXT23 + 4, // DXT45 + 4, // DXN1 + 4, // DXN2UNORM + 4, // DXN2SNORM + 4, // BC7U + 4, // BC6H_UF16 + 4, // BC6H_SF16 + 4, // ASTC_2D_4X4 + 1, // G8R8U + 1, // G8R8S + 1, // BGRA8 + 1, // RGBA32F + 1, // RG32F + 1, // R32F + 1, // R16F + 1, // R16U + 1, // R16S + 1, // R16UI + 1, // R16I + 1, // RG16 + 1, // RG16F + 1, // RG16UI + 1, // RG16I + 1, // RG16S + 1, // RGB32F + 1, // RGBA8_SRGB + 1, // RG8U + 1, // RG8S + 1, // RG32UI + 1, // R32UI + 8, // ASTC_2D_8X8 + 8, // ASTC_2D_8X5 + 5, // ASTC_2D_5X4 + 1, // BGRA8_SRGB + 4, // DXT1_SRGB + 4, // DXT23_SRGB + 4, // DXT45_SRGB + 4, // BC7U_SRGB + 4, // ASTC_2D_4X4_SRGB + 8, // ASTC_2D_8X8_SRGB + 8, // ASTC_2D_8X5_SRGB + 5, // ASTC_2D_5X4_SRGB + 5, // ASTC_2D_5X5 + 5, // ASTC_2D_5X5_SRGB + 1, // Z32F + 1, // Z16 + 1, // Z24S8 + 1, // S8Z24 + 1, // Z32FS8 + }}; + ASSERT(static_cast(format) < block_width_table.size()); + return block_width_table[static_cast(format)]; +} + static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { if (format == PixelFormat::Invalid) return 0; @@ -261,6 +338,8 @@ static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { 8, // ASTC_2D_8X8_SRGB 5, // ASTC_2D_8X5_SRGB 4, // ASTC_2D_5X4_SRGB + 5, // ASTC_2D_5X5 + 5, // ASTC_2D_5X5_SRGB 1, // Z32F 1, // Z16 1, // Z24S8 @@ -299,7 +378,7 @@ static constexpr u32 GetFormatBpp(PixelFormat format) { 128, // BC7U 128, // BC6H_UF16 128, // BC6H_SF16 - 32, // ASTC_2D_4X4 + 128, // ASTC_2D_4X4 16, // G8R8U 16, // G8R8S 32, // BGRA8 @@ -322,18 +401,20 @@ static constexpr u32 GetFormatBpp(PixelFormat format) { 16, // RG8S 64, // RG32UI 32, // R32UI - 16, // ASTC_2D_8X8 - 16, // ASTC_2D_8X5 - 32, // ASTC_2D_5X4 + 128, // ASTC_2D_8X8 + 128, // ASTC_2D_8X5 + 128, // ASTC_2D_5X4 32, // BGRA8_SRGB 64, // DXT1_SRGB 128, // DXT23_SRGB 128, // DXT45_SRGB 128, // BC7U - 32, // ASTC_2D_4X4_SRGB - 16, // ASTC_2D_8X8_SRGB - 16, // ASTC_2D_8X5_SRGB - 32, // ASTC_2D_5X4_SRGB + 128, // ASTC_2D_4X4_SRGB + 128, // ASTC_2D_8X8_SRGB + 128, // ASTC_2D_8X5_SRGB + 128, // ASTC_2D_5X4_SRGB + 128, // ASTC_2D_5X5 + 128, // ASTC_2D_5X5_SRGB 32, // Z32F 16, // Z16 32, // Z24S8 diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index b1feacae9d..bc50a4876b 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -1598,27 +1598,29 @@ static void DecompressBlock(uint8_t inBuf[16], const uint32_t blockWidth, namespace Tegra::Texture::ASTC { std::vector Decompress(std::vector& data, uint32_t width, uint32_t height, - uint32_t block_width, uint32_t block_height) { + uint32_t depth, uint32_t block_width, uint32_t block_height) { uint32_t blockIdx = 0; - std::vector outData(height * width * 4); - for (uint32_t j = 0; j < height; j += block_height) { - for (uint32_t i = 0; i < width; i += block_width) { + std::vector outData(height * width * depth * 4); + for (uint32_t k = 0; k < depth; k++) { + for (uint32_t j = 0; j < height; j += block_height) { + for (uint32_t i = 0; i < width; i += block_width) { - uint8_t* blockPtr = data.data() + blockIdx * 16; + uint8_t* blockPtr = data.data() + blockIdx * 16; - // Blocks can be at most 12x12 - uint32_t uncompData[144]; - ASTCC::DecompressBlock(blockPtr, block_width, block_height, uncompData); + // Blocks can be at most 12x12 + uint32_t uncompData[144]; + ASTCC::DecompressBlock(blockPtr, block_width, block_height, uncompData); - uint32_t decompWidth = std::min(block_width, width - i); - uint32_t decompHeight = std::min(block_height, height - j); + uint32_t decompWidth = std::min(block_width, width - i); + uint32_t decompHeight = std::min(block_height, height - j); - uint8_t* outRow = outData.data() + (j * width + i) * 4; - for (uint32_t jj = 0; jj < decompHeight; jj++) { - memcpy(outRow + jj * width * 4, uncompData + jj * block_width, decompWidth * 4); + uint8_t* outRow = outData.data() + (j * width + i) * 4; + for (uint32_t jj = 0; jj < decompHeight; jj++) { + memcpy(outRow + jj * width * 4, uncompData + jj * block_width, decompWidth * 4); + } + + blockIdx++; } - - blockIdx++; } } diff --git a/src/video_core/textures/astc.h b/src/video_core/textures/astc.h index f0d7c0e564..d419dd0250 100644 --- a/src/video_core/textures/astc.h +++ b/src/video_core/textures/astc.h @@ -10,6 +10,6 @@ namespace Tegra::Texture::ASTC { std::vector Decompress(std::vector& data, uint32_t width, uint32_t height, - uint32_t block_width, uint32_t block_height); + uint32_t depth, uint32_t block_width, uint32_t block_height); } // namespace Tegra::Texture::ASTC diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp index b994a27899..7077474228 100644 --- a/src/yuzu/debugger/graphics/graphics_surface.cpp +++ b/src/yuzu/debugger/graphics/graphics_surface.cpp @@ -386,9 +386,9 @@ void GraphicsSurfaceWidget::OnUpdate() { // TODO(bunnei): Will not work with BCn formats that swizzle 4x4 tiles. // Needs to be fixed if we plan to use this feature more, otherwise we may remove it. - auto unswizzled_data = - Tegra::Texture::UnswizzleTexture(*address, 1, 1, Tegra::Texture::BytesPerPixel(surface_format), - surface_width, surface_height, 1U); + auto unswizzled_data = Tegra::Texture::UnswizzleTexture( + *address, 1, 1, Tegra::Texture::BytesPerPixel(surface_format), surface_width, + surface_height, 1U); auto texture_data = Tegra::Texture::DecodeTexture(unswizzled_data, surface_format, surface_width, surface_height); From 0bc323bafb79442ead1511a5d7ee08f1caff171a Mon Sep 17 00:00:00 2001 From: David Marcec Date: Fri, 2 Nov 2018 12:35:49 +1100 Subject: [PATCH 06/11] Fixed HID crash when launching more than 1 game & signaled syleset change event This should fix crashes when launching multiple games in yuzu --- src/core/hle/service/hid/controllers/npad.cpp | 3 +++ src/core/hle/service/hid/hid.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 4b4d1324f8..1ef789bd04 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -427,6 +427,9 @@ void Controller_NPad::VibrateController(const std::vector& controller_ids, } Kernel::SharedPtr Controller_NPad::GetStyleSetChangedEvent() const { + // TODO(ogniK): Figure out the best time to signal this event. This event seems that it should + // be signalled at least once, and signaled after a new controller is connected? + styleset_changed_event->Signal(); return styleset_changed_event; } diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index a9aa9ec780..a45fd4954d 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -96,6 +96,8 @@ public: // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event); + + ReloadInputDevices(); } void ActivateController(HidController controller) { From 03c26d3406335d6897535850e009d6d37384039a Mon Sep 17 00:00:00 2001 From: David Marcec Date: Fri, 2 Nov 2018 15:23:38 +1100 Subject: [PATCH 07/11] Fixed incorrect hwopus assert --- src/core/hle/service/audio/hwopus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 7168c6a107..783c395030 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -161,7 +161,7 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); std::size_t worker_sz = WorkerBufferSize(channel_count); - ASSERT_MSG(buffer_sz < worker_sz, "Worker buffer too large"); + ASSERT_MSG(buffer_sz >= worker_sz, "Worker buffer too large"); std::unique_ptr decoder{ static_cast(operator new(worker_sz))}; if (opus_decoder_init(decoder.get(), sample_rate, channel_count)) { From 97187b7ef6eb842c0f8021ac500b5f7f029a5ae9 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 1 Nov 2018 22:05:44 -0400 Subject: [PATCH 08/11] qt: Add help option to open yuzu folder Opens a new file manager window at the UserDir. --- src/yuzu/main.cpp | 6 ++++++ src/yuzu/main.h | 1 + src/yuzu/main.ui | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c5a56cbfda..114b395463 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -454,6 +454,7 @@ void GMainWindow::ConnectMenuEvents() { connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen); // Help + connect(ui.action_Open_yuzu_Folder, &QAction::triggered, this, &GMainWindow::OnOpenYuzuFolder); connect(ui.action_Rederive, &QAction::triggered, this, std::bind(&GMainWindow::OnReinitializeKeys, this, ReinitializeKeyBehavior::Warning)); connect(ui.action_About, &QAction::triggered, this, &GMainWindow::OnAbout); @@ -1374,6 +1375,11 @@ void GMainWindow::OnLoadAmiibo() { } } +void GMainWindow::OnOpenYuzuFolder() { + QDesktopServices::openUrl(QUrl::fromLocalFile( + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir)))); +} + void GMainWindow::OnAbout() { AboutDialog aboutDialog(this); aboutDialog.exec(); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index af637d89e3..929250e8cd 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -167,6 +167,7 @@ private slots: void OnMenuRecentFile(); void OnConfigure(); void OnLoadAmiibo(); + void OnOpenYuzuFolder(); void OnAbout(); void OnToggleFilterBar(); void OnDisplayTitleBars(bool); diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 48d0995915..28cf269e7b 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -110,6 +110,7 @@ &Help + @@ -277,6 +278,11 @@ false + + + Open yuzu Folder + + From 1c4365d9289e2c3deeef4536246b8be9922c2e9a Mon Sep 17 00:00:00 2001 From: Frederic Laing <27208977+FreddyFunk@users.noreply.github.com> Date: Sun, 4 Nov 2018 16:56:10 +0100 Subject: [PATCH 09/11] Fix typo in BufferTransformFlags --- src/core/hle/service/nvflinger/buffer_queue.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h index 2fe81a560a..8cff5eb717 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.h +++ b/src/core/hle/service/nvflinger/buffer_queue.h @@ -58,9 +58,9 @@ public: /// Rotate source image 90 degrees clockwise Rotate90 = 0x04, /// Rotate source image 180 degrees - Roate180 = 0x03, + Rotate180 = 0x03, /// Rotate source image 270 degrees clockwise - Roate270 = 0x07, + Rotate270 = 0x07, }; struct Buffer { From b2647dba337c596ba3b3132297ee0af18033c007 Mon Sep 17 00:00:00 2001 From: Dharmin K Shah Date: Mon, 5 Nov 2018 00:36:49 +0530 Subject: [PATCH 10/11] Fix quickstart link --- src/yuzu/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c5a56cbfda..47d52c385c 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1532,7 +1532,7 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { "derivation. It will be attempted but may not complete.

") + errors + tr("

You can get all of these and dump all of your games easily by " - "following the " + "following the " "quickstart guide. Alternatively, you can use another method of dumping " "to obtain all of your keys.")); } From 54df9fe29e601609097f495d9619d28169ddb02c Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Tue, 6 Nov 2018 10:40:49 +0100 Subject: [PATCH 11/11] gl_resource_manager: Split implementations in .cpp file. Those implementations are quite costly, so there is no need to inline them to the caller. Ressource deletion is often a performance bug, so in this way, we support to add breakpoints to them. --- src/video_core/CMakeLists.txt | 1 + .../renderer_opengl/gl_rasterizer_cache.cpp | 1 + .../renderer_opengl/gl_resource_manager.cpp | 146 ++++++++++++++++++ .../renderer_opengl/gl_resource_manager.h | 132 +++------------- .../renderer_opengl/gl_shader_manager.h | 1 + 5 files changed, 167 insertions(+), 114 deletions(-) create mode 100644 src/video_core/renderer_opengl/gl_resource_manager.cpp diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index ddb1a1d69f..0b1cc1290d 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(video_core STATIC renderer_opengl/gl_rasterizer.h renderer_opengl/gl_rasterizer_cache.cpp renderer_opengl/gl_rasterizer_cache.h + renderer_opengl/gl_resource_manager.cpp renderer_opengl/gl_resource_manager.h renderer_opengl/gl_shader_cache.cpp renderer_opengl/gl_shader_cache.h diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index dcbf009c01..7d970efa0e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -16,6 +16,7 @@ #include "core/settings.h" #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_opengl/gl_rasterizer_cache.h" +#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/utils.h" #include "video_core/surface.h" #include "video_core/textures/astc.h" diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp new file mode 100644 index 0000000000..c108633374 --- /dev/null +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp @@ -0,0 +1,146 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "common/common_types.h" +#include "video_core/renderer_opengl/gl_resource_manager.h" +#include "video_core/renderer_opengl/gl_shader_util.h" +#include "video_core/renderer_opengl/gl_state.h" + +namespace OpenGL { + +void OGLTexture::Create() { + if (handle != 0) + return; + glGenTextures(1, &handle); +} + +void OGLTexture::Release() { + if (handle == 0) + return; + glDeleteTextures(1, &handle); + OpenGLState::GetCurState().UnbindTexture(handle).Apply(); + handle = 0; +} + +void OGLSampler::Create() { + if (handle != 0) + return; + glGenSamplers(1, &handle); +} + +void OGLSampler::Release() { + if (handle == 0) + return; + glDeleteSamplers(1, &handle); + OpenGLState::GetCurState().ResetSampler(handle).Apply(); + handle = 0; +} + +void OGLShader::Create(const char* source, GLenum type) { + if (handle != 0) + return; + if (source == nullptr) + return; + handle = GLShader::LoadShader(source, type); +} + +void OGLShader::Release() { + if (handle == 0) + return; + glDeleteShader(handle); + handle = 0; +} + +void OGLProgram::CreateFromSource(const char* vert_shader, const char* geo_shader, + const char* frag_shader, bool separable_program) { + OGLShader vert, geo, frag; + if (vert_shader) + vert.Create(vert_shader, GL_VERTEX_SHADER); + if (geo_shader) + geo.Create(geo_shader, GL_GEOMETRY_SHADER); + if (frag_shader) + frag.Create(frag_shader, GL_FRAGMENT_SHADER); + Create(separable_program, vert.handle, geo.handle, frag.handle); +} + +void OGLProgram::Release() { + if (handle == 0) + return; + glDeleteProgram(handle); + OpenGLState::GetCurState().ResetProgram(handle).Apply(); + handle = 0; +} + +void OGLPipeline::Create() { + if (handle != 0) + return; + glGenProgramPipelines(1, &handle); +} + +void OGLPipeline::Release() { + if (handle == 0) + return; + glDeleteProgramPipelines(1, &handle); + OpenGLState::GetCurState().ResetPipeline(handle).Apply(); + handle = 0; +} + +void OGLBuffer::Create() { + if (handle != 0) + return; + glGenBuffers(1, &handle); +} + +void OGLBuffer::Release() { + if (handle == 0) + return; + glDeleteBuffers(1, &handle); + OpenGLState::GetCurState().ResetBuffer(handle).Apply(); + handle = 0; +} + +void OGLSync::Create() { + if (handle != 0) + return; + handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); +} + +void OGLSync::Release() { + if (handle == 0) + return; + glDeleteSync(handle); + handle = 0; +} + +void OGLVertexArray::Create() { + if (handle != 0) + return; + glGenVertexArrays(1, &handle); +} + +void OGLVertexArray::Release() { + if (handle == 0) + return; + glDeleteVertexArrays(1, &handle); + OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); + handle = 0; +} + +void OGLFramebuffer::Create() { + if (handle != 0) + return; + glGenFramebuffers(1, &handle); +} + +void OGLFramebuffer::Release() { + if (handle == 0) + return; + glDeleteFramebuffers(1, &handle); + OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); + handle = 0; +} + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 3bc1b83b56..e33f1e973d 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -8,7 +8,6 @@ #include #include "common/common_types.h" #include "video_core/renderer_opengl/gl_shader_util.h" -#include "video_core/renderer_opengl/gl_state.h" namespace OpenGL { @@ -29,20 +28,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenTextures(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteTextures(1, &handle); - OpenGLState::GetCurState().UnbindTexture(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -64,20 +53,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenSamplers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteSamplers(1, &handle); - OpenGLState::GetCurState().ResetSampler(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -98,20 +77,9 @@ public: return *this; } - void Create(const char* source, GLenum type) { - if (handle != 0) - return; - if (source == nullptr) - return; - handle = GLShader::LoadShader(source, type); - } + void Create(const char* source, GLenum type); - void Release() { - if (handle == 0) - return; - glDeleteShader(handle); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -141,25 +109,10 @@ public: /// Creates a new internal OpenGL resource and stores the handle void CreateFromSource(const char* vert_shader, const char* geo_shader, const char* frag_shader, - bool separable_program = false) { - OGLShader vert, geo, frag; - if (vert_shader) - vert.Create(vert_shader, GL_VERTEX_SHADER); - if (geo_shader) - geo.Create(geo_shader, GL_GEOMETRY_SHADER); - if (frag_shader) - frag.Create(frag_shader, GL_FRAGMENT_SHADER); - Create(separable_program, vert.handle, geo.handle, frag.handle); - } + bool separable_program = false); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteProgram(handle); - OpenGLState::GetCurState().ResetProgram(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -178,20 +131,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenProgramPipelines(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteProgramPipelines(1, &handle); - OpenGLState::GetCurState().ResetPipeline(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -213,20 +156,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenBuffers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteBuffers(1, &handle); - OpenGLState::GetCurState().ResetBuffer(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -247,19 +180,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteSync(handle); - handle = 0; - } + void Release(); GLsync handle = 0; }; @@ -281,20 +205,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenVertexArrays(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteVertexArrays(1, &handle); - OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -316,20 +230,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenFramebuffers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteFramebuffers(1, &handle); - OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 36fe1f04ce..2a069cdd81 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -7,6 +7,7 @@ #include #include "video_core/renderer_opengl/gl_resource_manager.h" +#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/maxwell_to_gl.h" namespace OpenGL::GLShader {