diff options
| author | 2019-01-06 23:02:27 -0300 | |
|---|---|---|
| committer | 2019-01-30 19:10:35 -0300 | |
| commit | 704744bb72972f99fa992e286b3de5967b48af37 (patch) | |
| tree | d3e7f51187daf4bba5f93df6cb72503961d210d0 /src | |
| parent | gl_state: Use DSA and multi bind to update texture bindings (diff) | |
| download | yuzu-704744bb72972f99fa992e286b3de5967b48af37.tar.gz yuzu-704744bb72972f99fa992e286b3de5967b48af37.tar.xz yuzu-704744bb72972f99fa992e286b3de5967b48af37.zip | |
gl_rasterizer_cache: Move swizzling to textures instead of state
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 20 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 16 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 1 |
6 files changed, 35 insertions, 28 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index ee313cb2f..79d16d1f3 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -1022,11 +1022,11 @@ void RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, const Shader& s | |||
| 1022 | if (surface != nullptr) { | 1022 | if (surface != nullptr) { |
| 1023 | unit.texture = | 1023 | unit.texture = |
| 1024 | entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle; | 1024 | entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle; |
| 1025 | unit.target = entry.IsArray() ? surface->TargetLayer() : surface->Target(); | 1025 | const GLenum target = entry.IsArray() ? surface->TargetLayer() : surface->Target(); |
| 1026 | unit.swizzle.r = MaxwellToGL::SwizzleSource(texture.tic.x_source); | 1026 | surface->UpdateSwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source, |
| 1027 | unit.swizzle.g = MaxwellToGL::SwizzleSource(texture.tic.y_source); | 1027 | texture.tic.w_source); |
| 1028 | unit.swizzle.b = MaxwellToGL::SwizzleSource(texture.tic.z_source); | 1028 | unit.texture = handle; |
| 1029 | unit.swizzle.a = MaxwellToGL::SwizzleSource(texture.tic.w_source); | 1029 | unit.target = target; |
| 1030 | } else { | 1030 | } else { |
| 1031 | // Can occur when texture addr is null or its memory is unmapped/invalid | 1031 | // Can occur when texture addr is null or its memory is unmapped/invalid |
| 1032 | unit.texture = 0; | 1032 | unit.texture = 0; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index a3c782972..0dc4857e8 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -857,6 +857,8 @@ void CachedSurface::EnsureTextureView() { | |||
| 857 | glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, | 857 | glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, |
| 858 | params.max_mip_level, 0, 1); | 858 | params.max_mip_level, 0, 1); |
| 859 | ApplyTextureDefaults(texture_view.handle, params.max_mip_level); | 859 | ApplyTextureDefaults(texture_view.handle, params.max_mip_level); |
| 860 | glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA, | ||
| 861 | reinterpret_cast<const GLint*>(swizzle.data())); | ||
| 860 | } | 862 | } |
| 861 | 863 | ||
| 862 | MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); | 864 | MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); |
| @@ -870,6 +872,24 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle | |||
| 870 | UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle); | 872 | UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle); |
| 871 | } | 873 | } |
| 872 | 874 | ||
| 875 | void CachedSurface::UpdateSwizzle(Tegra::Texture::SwizzleSource swizzle_x, | ||
| 876 | Tegra::Texture::SwizzleSource swizzle_y, | ||
| 877 | Tegra::Texture::SwizzleSource swizzle_z, | ||
| 878 | Tegra::Texture::SwizzleSource swizzle_w) { | ||
| 879 | const GLenum new_x = MaxwellToGL::SwizzleSource(swizzle_x); | ||
| 880 | const GLenum new_y = MaxwellToGL::SwizzleSource(swizzle_y); | ||
| 881 | const GLenum new_z = MaxwellToGL::SwizzleSource(swizzle_z); | ||
| 882 | const GLenum new_w = MaxwellToGL::SwizzleSource(swizzle_w); | ||
| 883 | if (swizzle[0] != new_x || swizzle[1] != new_y || swizzle[2] != new_z || swizzle[3] != new_w) { | ||
| 884 | swizzle = {new_x, new_y, new_z, new_w}; | ||
| 885 | const auto swizzle_data = reinterpret_cast<const GLint*>(swizzle.data()); | ||
| 886 | glTextureParameteriv(texture.handle, GL_TEXTURE_SWIZZLE_RGBA, swizzle_data); | ||
| 887 | if (texture_view.handle != 0) { | ||
| 888 | glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA, swizzle_data); | ||
| 889 | } | ||
| 890 | } | ||
| 891 | } | ||
| 892 | |||
| 873 | RasterizerCacheOpenGL::RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer) | 893 | RasterizerCacheOpenGL::RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer) |
| 874 | : RasterizerCache{rasterizer} { | 894 | : RasterizerCache{rasterizer} { |
| 875 | read_framebuffer.Create(); | 895 | read_framebuffer.Create(); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index 9ee6f3f65..490b8252e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h | |||
| @@ -382,6 +382,11 @@ public: | |||
| 382 | // Upload data in gl_buffer to this surface's texture | 382 | // Upload data in gl_buffer to this surface's texture |
| 383 | void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle); | 383 | void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle); |
| 384 | 384 | ||
| 385 | void UpdateSwizzle(Tegra::Texture::SwizzleSource swizzle_x, | ||
| 386 | Tegra::Texture::SwizzleSource swizzle_y, | ||
| 387 | Tegra::Texture::SwizzleSource swizzle_z, | ||
| 388 | Tegra::Texture::SwizzleSource swizzle_w); | ||
| 389 | |||
| 385 | private: | 390 | private: |
| 386 | void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); | 391 | void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); |
| 387 | 392 | ||
| @@ -394,6 +399,7 @@ private: | |||
| 394 | GLenum gl_target{}; | 399 | GLenum gl_target{}; |
| 395 | GLenum gl_internal_format{}; | 400 | GLenum gl_internal_format{}; |
| 396 | std::size_t cached_size_in_bytes{}; | 401 | std::size_t cached_size_in_bytes{}; |
| 402 | std::array<GLenum, 4> swizzle{GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; | ||
| 397 | }; | 403 | }; |
| 398 | 404 | ||
| 399 | class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { | 405 | class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { |
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 997325efc..81af803bc 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -463,7 +463,8 @@ void OpenGLState::ApplyPolygonOffset() const { | |||
| 463 | 463 | ||
| 464 | void OpenGLState::ApplyTextures() const { | 464 | void OpenGLState::ApplyTextures() const { |
| 465 | bool has_delta{}; | 465 | bool has_delta{}; |
| 466 | std::size_t first{}, last{}; | 466 | std::size_t first{}; |
| 467 | std::size_t last{}; | ||
| 467 | std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures; | 468 | std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures; |
| 468 | 469 | ||
| 469 | for (std::size_t i = 0; i < std::size(texture_units); ++i) { | 470 | for (std::size_t i = 0; i < std::size(texture_units); ++i) { |
| @@ -478,16 +479,6 @@ void OpenGLState::ApplyTextures() const { | |||
| 478 | } | 479 | } |
| 479 | last = i; | 480 | last = i; |
| 480 | } | 481 | } |
| 481 | |||
| 482 | // Update the texture swizzle | ||
| 483 | if (textures[i] != 0 && (texture_unit.swizzle.r != cur_state_texture_unit.swizzle.r || | ||
| 484 | texture_unit.swizzle.g != cur_state_texture_unit.swizzle.g || | ||
| 485 | texture_unit.swizzle.b != cur_state_texture_unit.swizzle.b || | ||
| 486 | texture_unit.swizzle.a != cur_state_texture_unit.swizzle.a)) { | ||
| 487 | std::array<GLint, 4> mask = {texture_unit.swizzle.r, texture_unit.swizzle.g, | ||
| 488 | texture_unit.swizzle.b, texture_unit.swizzle.a}; | ||
| 489 | glTextureParameteriv(texture_unit.texture, GL_TEXTURE_SWIZZLE_RGBA, mask.data()); | ||
| 490 | } | ||
| 491 | } | 482 | } |
| 492 | 483 | ||
| 493 | if (has_delta) { | 484 | if (has_delta) { |
| @@ -498,7 +489,8 @@ void OpenGLState::ApplyTextures() const { | |||
| 498 | 489 | ||
| 499 | void OpenGLState::ApplySamplers() const { | 490 | void OpenGLState::ApplySamplers() const { |
| 500 | bool has_delta{}; | 491 | bool has_delta{}; |
| 501 | std::size_t first{}, last{}; | 492 | std::size_t first{}; |
| 493 | std::size_t last{}; | ||
| 502 | std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers; | 494 | std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers; |
| 503 | for (std::size_t i = 0; i < std::size(samplers); ++i) { | 495 | for (std::size_t i = 0; i < std::size(samplers); ++i) { |
| 504 | samplers[i] = texture_units[i].sampler; | 496 | samplers[i] = texture_units[i].sampler; |
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index a5a7c0920..ced602bf6 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h | |||
| @@ -127,19 +127,9 @@ public: | |||
| 127 | GLuint texture; // GL_TEXTURE_BINDING_2D | 127 | GLuint texture; // GL_TEXTURE_BINDING_2D |
| 128 | GLuint sampler; // GL_SAMPLER_BINDING | 128 | GLuint sampler; // GL_SAMPLER_BINDING |
| 129 | GLenum target; | 129 | GLenum target; |
| 130 | struct { | ||
| 131 | GLint r; // GL_TEXTURE_SWIZZLE_R | ||
| 132 | GLint g; // GL_TEXTURE_SWIZZLE_G | ||
| 133 | GLint b; // GL_TEXTURE_SWIZZLE_B | ||
| 134 | GLint a; // GL_TEXTURE_SWIZZLE_A | ||
| 135 | } swizzle; | ||
| 136 | 130 | ||
| 137 | void Unbind() { | 131 | void Unbind() { |
| 138 | texture = 0; | 132 | texture = 0; |
| 139 | swizzle.r = GL_RED; | ||
| 140 | swizzle.g = GL_GREEN; | ||
| 141 | swizzle.b = GL_BLUE; | ||
| 142 | swizzle.a = GL_ALPHA; | ||
| 143 | } | 133 | } |
| 144 | 134 | ||
| 145 | void Reset() { | 135 | void Reset() { |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 761dd6be3..5b09c38ea 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -320,7 +320,6 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x, | |||
| 320 | }}; | 320 | }}; |
| 321 | 321 | ||
| 322 | state.texture_units[0].texture = screen_info.display_texture; | 322 | state.texture_units[0].texture = screen_info.display_texture; |
| 323 | state.texture_units[0].swizzle = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; | ||
| 324 | // Workaround brigthness problems in SMO by enabling sRGB in the final output | 323 | // Workaround brigthness problems in SMO by enabling sRGB in the final output |
| 325 | // if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987 | 324 | // if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987 |
| 326 | state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed(); | 325 | state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed(); |