summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp55
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h6
-rw-r--r--src/video_core/textures/texture.h15
3 files changed, 57 insertions, 19 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 1d992b301..3fe8ceb41 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -735,9 +735,8 @@ void RasterizerOpenGL::SamplerInfo::Create() {
735 glSamplerParameteri(sampler.handle, GL_TEXTURE_COMPARE_FUNC, GL_NEVER); 735 glSamplerParameteri(sampler.handle, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
736} 736}
737 737
738void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::FullTextureInfo& info) { 738void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntry& config) {
739 const GLuint s = sampler.handle; 739 const GLuint s = sampler.handle;
740 const Tegra::Texture::TSCEntry& config = info.tsc;
741 if (mag_filter != config.mag_filter) { 740 if (mag_filter != config.mag_filter) {
742 mag_filter = config.mag_filter; 741 mag_filter = config.mag_filter;
743 glSamplerParameteri( 742 glSamplerParameteri(
@@ -779,28 +778,50 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::FullTex
779 MaxwellToGL::DepthCompareFunc(depth_compare_func)); 778 MaxwellToGL::DepthCompareFunc(depth_compare_func));
780 } 779 }
781 780
782 const GLvec4 new_border_color = {{config.border_color_r, config.border_color_g, 781 GLvec4 new_border_color;
783 config.border_color_b, config.border_color_a}}; 782 if (config.srgb_conversion) {
783 new_border_color[0] = config.srgb_border_color_r / 255.0f;
784 new_border_color[1] = config.srgb_border_color_g / 255.0f;
785 new_border_color[2] = config.srgb_border_color_g / 255.0f;
786 } else {
787 new_border_color[0] = config.border_color_r;
788 new_border_color[1] = config.border_color_g;
789 new_border_color[2] = config.border_color_b;
790 }
791 new_border_color[3] = config.border_color_a;
792
784 if (border_color != new_border_color) { 793 if (border_color != new_border_color) {
785 border_color = new_border_color; 794 border_color = new_border_color;
786 glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, border_color.data()); 795 glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, border_color.data());
787 } 796 }
788 797
789 if (info.tic.use_header_opt_control == 0) { 798 const float anisotropic_max = static_cast<float>(1 << config.max_anisotropy.Value());
799 if (anisotropic_max != max_anisotropic) {
800 max_anisotropic = anisotropic_max;
790 if (GLAD_GL_ARB_texture_filter_anisotropic) { 801 if (GLAD_GL_ARB_texture_filter_anisotropic) {
791 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY, 802 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropic);
792 static_cast<float>(1 << info.tic.max_anisotropy.Value()));
793 } else if (GLAD_GL_EXT_texture_filter_anisotropic) { 803 } else if (GLAD_GL_EXT_texture_filter_anisotropic) {
794 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY_EXT, 804 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropic);
795 static_cast<float>(1 << info.tic.max_anisotropy.Value()));
796 } 805 }
797 glSamplerParameterf(s, GL_TEXTURE_MIN_LOD, 806 }
798 static_cast<float>(info.tic.res_min_mip_level.Value())); 807 const float lod_min = static_cast<float>(config.min_lod_clamp.Value()) / 256.0f;
799 glSamplerParameterf(s, GL_TEXTURE_MAX_LOD, 808 if (lod_min != min_lod) {
800 static_cast<float>(info.tic.res_max_mip_level.Value() == 0 809 min_lod = lod_min;
801 ? 16 810 glSamplerParameterf(s, GL_TEXTURE_MIN_LOD, min_lod);
802 : info.tic.res_max_mip_level.Value())); 811 }
803 glSamplerParameterf(s, GL_TEXTURE_LOD_BIAS, info.tic.mip_lod_bias.Value() / 256.f); 812
813 const float lod_max = static_cast<float>(config.max_lod_clamp.Value()) / 256.0f;
814 if (lod_max != max_lod) {
815 max_lod = lod_max;
816 glSamplerParameterf(s, GL_TEXTURE_MAX_LOD, max_lod);
817 }
818 const u32 bias = config.mip_lod_bias.Value();
819 // Sign extend the 13-bit value.
820 const u32 mask = 1U << (13 - 1);
821 const float bias_lod = static_cast<s32>((bias ^ mask) - mask) / 256.f;
822 if (lod_bias != bias_lod) {
823 lod_bias = bias_lod;
824 glSamplerParameterf(s, GL_TEXTURE_LOD_BIAS, lod_bias);
804 } 825 }
805} 826}
806 827
@@ -899,7 +920,7 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
899 continue; 920 continue;
900 } 921 }
901 922
902 texture_samplers[current_bindpoint].SyncWithConfig(texture); 923 texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc);
903 Surface surface = res_cache.GetTextureSurface(texture, entry); 924 Surface surface = res_cache.GetTextureSurface(texture, entry);
904 if (surface != nullptr) { 925 if (surface != nullptr) {
905 state.texture_units[current_bindpoint].texture = surface->Texture().handle; 926 state.texture_units[current_bindpoint].texture = surface->Texture().handle;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 8994e134a..6e78ab4cd 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -88,7 +88,7 @@ private:
88 /// SamplerInfo struct. 88 /// SamplerInfo struct.
89 void Create(); 89 void Create();
90 /// Syncs the sampler object with the config, updating any necessary state. 90 /// Syncs the sampler object with the config, updating any necessary state.
91 void SyncWithConfig(const Tegra::Texture::FullTextureInfo& info); 91 void SyncWithConfig(const Tegra::Texture::TSCEntry& info);
92 92
93 private: 93 private:
94 Tegra::Texture::TextureFilter mag_filter; 94 Tegra::Texture::TextureFilter mag_filter;
@@ -100,6 +100,10 @@ private:
100 bool uses_depth_compare; 100 bool uses_depth_compare;
101 Tegra::Texture::DepthCompareFunc depth_compare_func; 101 Tegra::Texture::DepthCompareFunc depth_compare_func;
102 GLvec4 border_color; 102 GLvec4 border_color;
103 float min_lod;
104 float max_lod;
105 float lod_bias;
106 float max_anisotropic;
103 }; 107 };
104 108
105 /** 109 /**
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h
index e199d019a..ffa08f5c1 100644
--- a/src/video_core/textures/texture.h
+++ b/src/video_core/textures/texture.h
@@ -190,6 +190,7 @@ struct TICEntry {
190 union { 190 union {
191 BitField<0, 4, u32> res_min_mip_level; 191 BitField<0, 4, u32> res_min_mip_level;
192 BitField<4, 4, u32> res_max_mip_level; 192 BitField<4, 4, u32> res_max_mip_level;
193 BitField<12, 12, u32> min_lod_clamp;
193 }; 194 };
194 195
195 GPUVAddr Address() const { 196 GPUVAddr Address() const {
@@ -284,13 +285,25 @@ struct TSCEntry {
284 BitField<6, 3, WrapMode> wrap_p; 285 BitField<6, 3, WrapMode> wrap_p;
285 BitField<9, 1, u32> depth_compare_enabled; 286 BitField<9, 1, u32> depth_compare_enabled;
286 BitField<10, 3, DepthCompareFunc> depth_compare_func; 287 BitField<10, 3, DepthCompareFunc> depth_compare_func;
288 BitField<13, 1, u32> srgb_conversion;
289 BitField<20, 3, u32> max_anisotropy;
287 }; 290 };
288 union { 291 union {
289 BitField<0, 2, TextureFilter> mag_filter; 292 BitField<0, 2, TextureFilter> mag_filter;
290 BitField<4, 2, TextureFilter> min_filter; 293 BitField<4, 2, TextureFilter> min_filter;
291 BitField<6, 2, TextureMipmapFilter> mip_filter; 294 BitField<6, 2, TextureMipmapFilter> mip_filter;
295 BitField<9, 1, u32> cubemap_interface_filtering;
296 BitField<12, 13, u32> mip_lod_bias;
297 };
298 union {
299 BitField<0, 12, u32> min_lod_clamp;
300 BitField<12, 12, u32> max_lod_clamp;
301 BitField<24, 8, u32> srgb_border_color_r;
302 };
303 union {
304 BitField<12, 8, u32> srgb_border_color_g;
305 BitField<20, 8, u32> srgb_border_color_b;
292 }; 306 };
293 INSERT_PADDING_BYTES(8);
294 float border_color_r; 307 float border_color_r;
295 float border_color_g; 308 float border_color_g;
296 float border_color_b; 309 float border_color_b;