diff options
| author | 2019-01-02 17:51:32 -0500 | |
|---|---|---|
| committer | 2019-01-02 17:51:32 -0500 | |
| commit | c91d2bac4556502336b7f40a8de971b8b157af22 (patch) | |
| tree | 8888bb11519f5c8e3fd9f5b607d3991d180962e2 /src | |
| parent | Merge pull request #1944 from FearlessTobi/port-4187 (diff) | |
| parent | gl_rasterizer_cache: Texture view if shader samples array but OGL is not (diff) | |
| download | yuzu-c91d2bac4556502336b7f40a8de971b8b157af22.tar.gz yuzu-c91d2bac4556502336b7f40a8de971b8b157af22.tar.xz yuzu-c91d2bac4556502336b7f40a8de971b8b157af22.zip | |
Merge pull request #1961 from ReinUsesLisp/tex-view-2d
gl_rasterizer_cache: Texture view if shader samples array but OGL is not
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 49 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.h | 32 |
3 files changed, 74 insertions, 14 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2b29fc45f..089daf96f 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -1014,8 +1014,11 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, | |||
| 1014 | texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc); | 1014 | texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc); |
| 1015 | Surface surface = res_cache.GetTextureSurface(texture, entry); | 1015 | Surface surface = res_cache.GetTextureSurface(texture, entry); |
| 1016 | if (surface != nullptr) { | 1016 | if (surface != nullptr) { |
| 1017 | state.texture_units[current_bindpoint].texture = surface->Texture().handle; | 1017 | const GLuint handle = |
| 1018 | state.texture_units[current_bindpoint].target = surface->Target(); | 1018 | entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle; |
| 1019 | const GLenum target = entry.IsArray() ? surface->TargetLayer() : surface->Target(); | ||
| 1020 | state.texture_units[current_bindpoint].texture = handle; | ||
| 1021 | state.texture_units[current_bindpoint].target = target; | ||
| 1019 | state.texture_units[current_bindpoint].swizzle.r = | 1022 | state.texture_units[current_bindpoint].swizzle.r = |
| 1020 | MaxwellToGL::SwizzleSource(texture.tic.x_source); | 1023 | MaxwellToGL::SwizzleSource(texture.tic.x_source); |
| 1021 | state.texture_units[current_bindpoint].swizzle.g = | 1024 | state.texture_units[current_bindpoint].swizzle.g = |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 75b4fe88d..d3dcb9a46 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -44,6 +44,17 @@ struct FormatTuple { | |||
| 44 | bool compressed; | 44 | bool compressed; |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | static void ApplyTextureDefaults(GLenum target, u32 max_mip_level) { | ||
| 48 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
| 49 | glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
| 50 | glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
| 51 | glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
| 52 | glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, max_mip_level - 1); | ||
| 53 | if (max_mip_level == 1) { | ||
| 54 | glTexParameterf(target, GL_TEXTURE_LOD_BIAS, 1000.0); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 47 | void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) { | 58 | void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) { |
| 48 | auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; | 59 | auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; |
| 49 | const auto cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr_)}; | 60 | const auto cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr_)}; |
| @@ -530,6 +541,9 @@ CachedSurface::CachedSurface(const SurfaceParams& params) | |||
| 530 | glActiveTexture(GL_TEXTURE0); | 541 | glActiveTexture(GL_TEXTURE0); |
| 531 | 542 | ||
| 532 | const auto& format_tuple = GetFormatTuple(params.pixel_format, params.component_type); | 543 | const auto& format_tuple = GetFormatTuple(params.pixel_format, params.component_type); |
| 544 | gl_internal_format = format_tuple.internal_format; | ||
| 545 | gl_is_compressed = format_tuple.compressed; | ||
| 546 | |||
| 533 | if (!format_tuple.compressed) { | 547 | if (!format_tuple.compressed) { |
| 534 | // Only pre-create the texture for non-compressed textures. | 548 | // Only pre-create the texture for non-compressed textures. |
| 535 | switch (params.target) { | 549 | switch (params.target) { |
| @@ -558,15 +572,7 @@ CachedSurface::CachedSurface(const SurfaceParams& params) | |||
| 558 | } | 572 | } |
| 559 | } | 573 | } |
| 560 | 574 | ||
| 561 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 575 | ApplyTextureDefaults(SurfaceTargetToGL(params.target), params.max_mip_level); |
| 562 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
| 563 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
| 564 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
| 565 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAX_LEVEL, | ||
| 566 | params.max_mip_level - 1); | ||
| 567 | if (params.max_mip_level == 1) { | ||
| 568 | glTexParameterf(SurfaceTargetToGL(params.target), GL_TEXTURE_LOD_BIAS, 1000.0); | ||
| 569 | } | ||
| 570 | 576 | ||
| 571 | LabelGLObject(GL_TEXTURE, texture.handle, params.addr, | 577 | LabelGLObject(GL_TEXTURE, texture.handle, params.addr, |
| 572 | SurfaceParams::SurfaceTargetName(params.target)); | 578 | SurfaceParams::SurfaceTargetName(params.target)); |
| @@ -864,6 +870,31 @@ void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, | |||
| 864 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | 870 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 865 | } | 871 | } |
| 866 | 872 | ||
| 873 | void CachedSurface::EnsureTextureView() { | ||
| 874 | if (texture_view.handle != 0) | ||
| 875 | return; | ||
| 876 | // Compressed texture are not being created with immutable storage | ||
| 877 | UNIMPLEMENTED_IF(gl_is_compressed); | ||
| 878 | |||
| 879 | const GLenum target{TargetLayer()}; | ||
| 880 | |||
| 881 | texture_view.Create(); | ||
| 882 | glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, | ||
| 883 | params.max_mip_level, 0, 1); | ||
| 884 | |||
| 885 | OpenGLState cur_state = OpenGLState::GetCurState(); | ||
| 886 | const auto& old_tex = cur_state.texture_units[0]; | ||
| 887 | SCOPE_EXIT({ | ||
| 888 | cur_state.texture_units[0] = old_tex; | ||
| 889 | cur_state.Apply(); | ||
| 890 | }); | ||
| 891 | cur_state.texture_units[0].texture = texture_view.handle; | ||
| 892 | cur_state.texture_units[0].target = target; | ||
| 893 | cur_state.Apply(); | ||
| 894 | |||
| 895 | ApplyTextureDefaults(target, params.max_mip_level); | ||
| 896 | } | ||
| 897 | |||
| 867 | MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); | 898 | MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); |
| 868 | void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle) { | 899 | void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle) { |
| 869 | if (params.type == SurfaceType::Fill) | 900 | if (params.type == SurfaceType::Fill) |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index c710aa245..7223700c4 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h | |||
| @@ -293,10 +293,31 @@ public: | |||
| 293 | return texture; | 293 | return texture; |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | const OGLTexture& TextureLayer() { | ||
| 297 | if (params.is_layered) { | ||
| 298 | return Texture(); | ||
| 299 | } | ||
| 300 | EnsureTextureView(); | ||
| 301 | return texture_view; | ||
| 302 | } | ||
| 303 | |||
| 296 | GLenum Target() const { | 304 | GLenum Target() const { |
| 297 | return gl_target; | 305 | return gl_target; |
| 298 | } | 306 | } |
| 299 | 307 | ||
| 308 | GLenum TargetLayer() const { | ||
| 309 | using VideoCore::Surface::SurfaceTarget; | ||
| 310 | switch (params.target) { | ||
| 311 | case SurfaceTarget::Texture1D: | ||
| 312 | return GL_TEXTURE_1D_ARRAY; | ||
| 313 | case SurfaceTarget::Texture2D: | ||
| 314 | return GL_TEXTURE_2D_ARRAY; | ||
| 315 | case SurfaceTarget::TextureCubemap: | ||
| 316 | return GL_TEXTURE_CUBE_MAP_ARRAY; | ||
| 317 | } | ||
| 318 | return Target(); | ||
| 319 | } | ||
| 320 | |||
| 300 | const SurfaceParams& GetSurfaceParams() const { | 321 | const SurfaceParams& GetSurfaceParams() const { |
| 301 | return params; | 322 | return params; |
| 302 | } | 323 | } |
| @@ -311,11 +332,16 @@ public: | |||
| 311 | private: | 332 | private: |
| 312 | void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); | 333 | void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); |
| 313 | 334 | ||
| 335 | void EnsureTextureView(); | ||
| 336 | |||
| 314 | OGLTexture texture; | 337 | OGLTexture texture; |
| 338 | OGLTexture texture_view; | ||
| 315 | std::vector<std::vector<u8>> gl_buffer; | 339 | std::vector<std::vector<u8>> gl_buffer; |
| 316 | SurfaceParams params; | 340 | SurfaceParams params{}; |
| 317 | GLenum gl_target; | 341 | GLenum gl_target{}; |
| 318 | std::size_t cached_size_in_bytes; | 342 | GLenum gl_internal_format{}; |
| 343 | bool gl_is_compressed{}; | ||
| 344 | std::size_t cached_size_in_bytes{}; | ||
| 319 | }; | 345 | }; |
| 320 | 346 | ||
| 321 | class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { | 347 | class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { |