summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-09-01 02:42:43 -0400
committerGravatar bunnei2018-09-08 02:53:37 -0400
commit030676b95d8f0c0cd6c288f59daf94bbda6c7133 (patch)
treec49f4fc4b5d797b7af730c8292555a748250ab41 /src
parentgl_rasterizer_cache: Remove unused DownloadGLTexture. (diff)
downloadyuzu-030676b95d8f0c0cd6c288f59daf94bbda6c7133.tar.gz
yuzu-030676b95d8f0c0cd6c288f59daf94bbda6c7133.tar.xz
yuzu-030676b95d8f0c0cd6c288f59daf94bbda6c7133.zip
gl_rasterizer_cache: Keep track of texture type per surface.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp1
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp80
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h35
3 files changed, 84 insertions, 32 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index d5bbfbd1c..5deee20dd 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -700,6 +700,7 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
700 Surface surface = res_cache.GetTextureSurface(texture); 700 Surface surface = res_cache.GetTextureSurface(texture);
701 if (surface != nullptr) { 701 if (surface != nullptr) {
702 state.texture_units[current_bindpoint].texture = surface->Texture().handle; 702 state.texture_units[current_bindpoint].texture = surface->Texture().handle;
703 state.texture_units[current_bindpoint].target = surface->Target();
703 state.texture_units[current_bindpoint].swizzle.r = 704 state.texture_units[current_bindpoint].swizzle.r =
704 MaxwellToGL::SwizzleSource(texture.tic.x_source); 705 MaxwellToGL::SwizzleSource(texture.tic.x_source);
705 state.texture_units[current_bindpoint].swizzle.g = 706 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 0df1bbf6b..4d6fd8b8b 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -55,6 +55,7 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) {
55 params.size_in_bytes = params.SizeInBytes(); 55 params.size_in_bytes = params.SizeInBytes();
56 params.cache_width = Common::AlignUp(params.width, 16); 56 params.cache_width = Common::AlignUp(params.width, 16);
57 params.cache_height = Common::AlignUp(params.height, 16); 57 params.cache_height = Common::AlignUp(params.height, 16);
58 params.target = SurfaceTargetFromTextureType(config.tic.texture_type);
58 return params; 59 return params;
59} 60}
60 61
@@ -73,6 +74,7 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) {
73 params.size_in_bytes = params.SizeInBytes(); 74 params.size_in_bytes = params.SizeInBytes();
74 params.cache_width = Common::AlignUp(params.width, 16); 75 params.cache_width = Common::AlignUp(params.width, 16);
75 params.cache_height = Common::AlignUp(params.height, 16); 76 params.cache_height = Common::AlignUp(params.height, 16);
77 params.target = SurfaceTarget::Texture2D;
76 return params; 78 return params;
77} 79}
78 80
@@ -93,6 +95,7 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) {
93 params.size_in_bytes = params.SizeInBytes(); 95 params.size_in_bytes = params.SizeInBytes();
94 params.cache_width = Common::AlignUp(params.width, 16); 96 params.cache_width = Common::AlignUp(params.width, 16);
95 params.cache_height = Common::AlignUp(params.height, 16); 97 params.cache_height = Common::AlignUp(params.height, 16);
98 params.target = SurfaceTarget::Texture2D;
96 return params; 99 return params;
97} 100}
98 101
@@ -166,6 +169,26 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
166 ComponentType::Float, false}, // Z32FS8 169 ComponentType::Float, false}, // Z32FS8
167}}; 170}};
168 171
172static GLenum SurfaceTargetToGL(SurfaceParams::SurfaceTarget target) {
173 switch (target) {
174 case SurfaceParams::SurfaceTarget::Texture1D:
175 return GL_TEXTURE_1D;
176 case SurfaceParams::SurfaceTarget::Texture2D:
177 return GL_TEXTURE_2D;
178 case SurfaceParams::SurfaceTarget::Texture3D:
179 return GL_TEXTURE_3D;
180 case SurfaceParams::SurfaceTarget::Texture1DArray:
181 return GL_TEXTURE_1D_ARRAY;
182 case SurfaceParams::SurfaceTarget::Texture2DArray:
183 return GL_TEXTURE_2D_ARRAY;
184 case SurfaceParams::SurfaceTarget::TextureCubemap:
185 return GL_TEXTURE_CUBE_MAP;
186 }
187 LOG_CRITICAL(Render_OpenGL, "Unimplemented texture target={}", static_cast<u32>(target));
188 UNREACHABLE();
189 return {};
190}
191
169static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) { 192static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
170 ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size()); 193 ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size());
171 auto& format = tex_format_tuples[static_cast<unsigned int>(pixel_format)]; 194 auto& format = tex_format_tuples[static_cast<unsigned int>(pixel_format)];
@@ -357,33 +380,6 @@ static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, VAddr),
357 // clang-format on 380 // clang-format on
358}; 381};
359 382
360// Allocate an uninitialized texture of appropriate size and format for the surface
361static void AllocateSurfaceTexture(GLuint texture, const FormatTuple& format_tuple, u32 width,
362 u32 height) {
363 OpenGLState cur_state = OpenGLState::GetCurState();
364
365 // Keep track of previous texture bindings
366 GLuint old_tex = cur_state.texture_units[0].texture;
367 cur_state.texture_units[0].texture = texture;
368 cur_state.Apply();
369 glActiveTexture(GL_TEXTURE0);
370
371 if (!format_tuple.compressed) {
372 // Only pre-create the texture for non-compressed textures.
373 glTexImage2D(GL_TEXTURE_2D, 0, format_tuple.internal_format, width, height, 0,
374 format_tuple.format, format_tuple.type, nullptr);
375 }
376
377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
381
382 // Restore previous texture bindings
383 cur_state.texture_units[0].texture = old_tex;
384 cur_state.Apply();
385}
386
387static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rect, GLuint dst_tex, 383static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rect, GLuint dst_tex,
388 const MathUtil::Rectangle<u32>& dst_rect, SurfaceType type, 384 const MathUtil::Rectangle<u32>& dst_rect, SurfaceType type,
389 GLuint read_fb_handle, GLuint draw_fb_handle) { 385 GLuint read_fb_handle, GLuint draw_fb_handle) {
@@ -438,12 +434,34 @@ static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rec
438 return true; 434 return true;
439} 435}
440 436
441CachedSurface::CachedSurface(const SurfaceParams& params) : params(params) { 437CachedSurface::CachedSurface(const SurfaceParams& params)
438 : params(params), gl_target(SurfaceTargetToGL(params.target)) {
442 texture.Create(); 439 texture.Create();
443 const auto& rect{params.GetRect()}; 440 const auto& rect{params.GetRect()};
444 AllocateSurfaceTexture(texture.handle, 441
445 GetFormatTuple(params.pixel_format, params.component_type), 442 OpenGLState cur_state = OpenGLState::GetCurState();
446 rect.GetWidth(), rect.GetHeight()); 443
444 // Keep track of previous texture bindings
445 GLuint old_tex = cur_state.texture_units[0].texture;
446 cur_state.texture_units[0].texture = texture.handle;
447 cur_state.Apply();
448 glActiveTexture(GL_TEXTURE0);
449
450 const auto& format_tuple = GetFormatTuple(params.pixel_format, params.component_type);
451 if (!format_tuple.compressed) {
452 // Only pre-create the texture for non-compressed textures.
453 glTexImage2D(GL_TEXTURE_2D, 0, format_tuple.internal_format, rect.GetWidth(),
454 rect.GetHeight(), 0, format_tuple.format, format_tuple.type, nullptr);
455 }
456
457 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAX_LEVEL, 0);
458 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR);
459 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
460 glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
461
462 // Restore previous texture bindings
463 cur_state.texture_units[0].texture = old_tex;
464 cur_state.Apply();
447} 465}
448 466
449static void ConvertS8Z24ToZ24S8(std::vector<u8>& data, u32 width, u32 height) { 467static void ConvertS8Z24ToZ24S8(std::vector<u8>& data, u32 width, u32 height) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index b17867f64..6693b5cda 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -109,6 +109,33 @@ struct SurfaceParams {
109 Invalid = 4, 109 Invalid = 4,
110 }; 110 };
111 111
112 enum class SurfaceTarget {
113 Texture1D,
114 Texture2D,
115 Texture3D,
116 Texture1DArray,
117 Texture2DArray,
118 TextureCubemap,
119 };
120
121 static SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type) {
122 switch (texture_type) {
123 case Tegra::Texture::TextureType::Texture1D:
124 return SurfaceTarget::Texture1D;
125 case Tegra::Texture::TextureType::Texture2D:
126 case Tegra::Texture::TextureType::Texture2DNoMipmap:
127 return SurfaceTarget::Texture2D;
128 case Tegra::Texture::TextureType::Texture1DArray:
129 return SurfaceTarget::Texture1DArray;
130 case Tegra::Texture::TextureType::Texture2DArray:
131 return SurfaceTarget::Texture2DArray;
132 default:
133 LOG_CRITICAL(HW_GPU, "Unimplemented texture_type={}", static_cast<u32>(texture_type));
134 UNREACHABLE();
135 return SurfaceTarget::Texture2D;
136 }
137 }
138
112 /** 139 /**
113 * Gets the compression factor for the specified PixelFormat. This applies to just the 140 * Gets the compression factor for the specified PixelFormat. This applies to just the
114 * "compressed width" and "compressed height", not the overall compression factor of a 141 * "compressed width" and "compressed height", not the overall compression factor of a
@@ -666,6 +693,7 @@ struct SurfaceParams {
666 u32 height; 693 u32 height;
667 u32 unaligned_height; 694 u32 unaligned_height;
668 size_t size_in_bytes; 695 size_t size_in_bytes;
696 SurfaceTarget target;
669 697
670 // Parameters used for caching only 698 // Parameters used for caching only
671 u32 cache_width; 699 u32 cache_width;
@@ -709,6 +737,10 @@ public:
709 return texture; 737 return texture;
710 } 738 }
711 739
740 GLenum Target() const {
741 return gl_target;
742 }
743
712 static constexpr unsigned int GetGLBytesPerPixel(SurfaceParams::PixelFormat format) { 744 static constexpr unsigned int GetGLBytesPerPixel(SurfaceParams::PixelFormat format) {
713 if (format == SurfaceParams::PixelFormat::Invalid) 745 if (format == SurfaceParams::PixelFormat::Invalid)
714 return 0; 746 return 0;
@@ -724,13 +756,14 @@ public:
724 void LoadGLBuffer(); 756 void LoadGLBuffer();
725 void FlushGLBuffer(); 757 void FlushGLBuffer();
726 758
727 // Upload/Download data in gl_buffer in/to this surface's texture 759 // Upload data in gl_buffer to this surface's texture
728 void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle); 760 void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle);
729 761
730private: 762private:
731 OGLTexture texture; 763 OGLTexture texture;
732 std::vector<u8> gl_buffer; 764 std::vector<u8> gl_buffer;
733 SurfaceParams params; 765 SurfaceParams params;
766 GLenum gl_target;
734}; 767};
735 768
736class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { 769class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {