From f58a6152fc89626e4a8f1746af46e9260d17d404 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 29 Jan 2019 20:33:56 -0300 Subject: [PATCH] gl_shader_cache: Fix texture view for cubemaps as cubemap arrays Cubemaps are considered layered and to create a texture view the texture mustn't be a layered texture, resulting in cubemaps being bound as cubemap arrays. To fix this issue this commit introduces an extra surface parameter called "is_array" and uses this to query for texture view creation. Now that texture views for cubemaps are actually being created, this also fixes the number of layers created for the texture view (since they have to be 6 to create a texture view of cubemaps). --- .../renderer_opengl/gl_rasterizer_cache.cpp | 8 ++++++-- .../renderer_opengl/gl_rasterizer_cache.h | 3 ++- src/video_core/surface.cpp | 18 ++++++++++++++++++ src/video_core/surface.h | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index a05b8b936..c44e2aca2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -167,6 +167,7 @@ std::size_t SurfaceParams::InnerMemorySize(bool force_gl, bool layer_only, } params.is_layered = SurfaceTargetIsLayered(params.target); + params.is_array = SurfaceTargetIsArray(params.target); params.max_mip_level = config.tic.max_mip_level + 1; params.rt = {}; @@ -877,10 +878,13 @@ void CachedSurface::EnsureTextureView() { UNIMPLEMENTED_IF(gl_is_compressed); const GLenum target{TargetLayer()}; + const GLuint num_layers{target == GL_TEXTURE_CUBE_MAP_ARRAY ? 6u : 1u}; + constexpr GLuint min_layer = 0; + constexpr GLuint min_level = 0; texture_view.Create(); - glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, - params.max_mip_level, 0, 1); + glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, min_level, + params.max_mip_level, min_layer, num_layers); OpenGLState cur_state = OpenGLState::GetCurState(); const auto& old_tex = cur_state.texture_units[0]; diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index 37611c4fc..dae0feb20 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -225,6 +225,7 @@ struct SurfaceParams { SurfaceTarget target; u32 max_mip_level; bool is_layered; + bool is_array; bool srgb_conversion; // Parameters used for caching VAddr addr; @@ -294,7 +295,7 @@ public: } const OGLTexture& TextureLayer() { - if (params.is_layered) { + if (params.is_array) { return Texture(); } EnsureTextureView(); diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index 1a344229f..2f6612a35 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -50,6 +50,24 @@ bool SurfaceTargetIsLayered(SurfaceTarget target) { } } +bool SurfaceTargetIsArray(SurfaceTarget target) { + switch (target) { + case SurfaceTarget::Texture1D: + case SurfaceTarget::Texture2D: + case SurfaceTarget::Texture3D: + case SurfaceTarget::TextureCubemap: + return false; + case SurfaceTarget::Texture1DArray: + case SurfaceTarget::Texture2DArray: + case SurfaceTarget::TextureCubeArray: + return true; + default: + LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast(target)); + UNREACHABLE(); + return false; + } +} + PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) { switch (format) { case Tegra::DepthFormat::S8_Z24_UNORM: diff --git a/src/video_core/surface.h b/src/video_core/surface.h index c2259c3c2..edd3816ba 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -441,6 +441,8 @@ SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_t bool SurfaceTargetIsLayered(SurfaceTarget target); +bool SurfaceTargetIsArray(SurfaceTarget target); + PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format); PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format);