diff options
| author | 2019-07-04 21:10:59 -0400 | |
|---|---|---|
| committer | 2019-07-05 09:46:53 -0400 | |
| commit | 3b9d89839dc62e9e63a3cbe9636cf85276babdfb (patch) | |
| tree | d99f4a48789f01c671f132c144f2dff2256223aa /src | |
| parent | texture_cache: Correct Texture Buffer Uploading (diff) | |
| download | yuzu-3b9d89839dc62e9e63a3cbe9636cf85276babdfb.tar.gz yuzu-3b9d89839dc62e9e63a3cbe9636cf85276babdfb.tar.xz yuzu-3b9d89839dc62e9e63a3cbe9636cf85276babdfb.zip | |
texture_cache: Address Feedback
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/binary_find.h | 21 | ||||
| -rw-r--r-- | src/common/common_funcs.h | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.h | 9 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_base.h | 4 |
7 files changed, 35 insertions, 22 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 8ae05137b..2554add28 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -75,6 +75,7 @@ add_library(common STATIC | |||
| 75 | assert.h | 75 | assert.h |
| 76 | detached_tasks.cpp | 76 | detached_tasks.cpp |
| 77 | detached_tasks.h | 77 | detached_tasks.h |
| 78 | binary_find.h | ||
| 78 | bit_field.h | 79 | bit_field.h |
| 79 | bit_util.h | 80 | bit_util.h |
| 80 | cityhash.cpp | 81 | cityhash.cpp |
diff --git a/src/common/binary_find.h b/src/common/binary_find.h new file mode 100644 index 000000000..5cc523bf9 --- /dev/null +++ b/src/common/binary_find.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | // Copyright 2019 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | template <class ForwardIt, class T, class Compare = std::less<>> | ||
| 12 | ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) { | ||
| 13 | // Note: BOTH type T and the type after ForwardIt is dereferenced | ||
| 14 | // must be implicitly convertible to BOTH Type1 and Type2, used in Compare. | ||
| 15 | // This is stricter than lower_bound requirement (see above) | ||
| 16 | |||
| 17 | first = std::lower_bound(first, last, value, comp); | ||
| 18 | return first != last && !comp(value, *first) ? first : last; | ||
| 19 | } | ||
| 20 | |||
| 21 | } // namespace Common | ||
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 00a5698f3..04ecac959 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -61,14 +61,4 @@ constexpr u32 MakeMagic(char a, char b, char c, char d) { | |||
| 61 | return a | b << 8 | c << 16 | d << 24; | 61 | return a | b << 8 | c << 16 | d << 24; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | template <class ForwardIt, class T, class Compare = std::less<>> | ||
| 65 | ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) { | ||
| 66 | // Note: BOTH type T and the type after ForwardIt is dereferenced | ||
| 67 | // must be implicitly convertible to BOTH Type1 and Type2, used in Compare. | ||
| 68 | // This is stricter than lower_bound requirement (see above) | ||
| 69 | |||
| 70 | first = std::lower_bound(first, last, value, comp); | ||
| 71 | return first != last && !comp(value, *first) ? first : last; | ||
| 72 | } | ||
| 73 | |||
| 74 | } // namespace Common | 64 | } // namespace Common |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 718703091..1bd182d98 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -103,14 +103,16 @@ constexpr std::tuple<const char*, const char*, u32> GetPrimitiveDescription(GLen | |||
| 103 | /// Calculates the size of a program stream | 103 | /// Calculates the size of a program stream |
| 104 | std::size_t CalculateProgramSize(const GLShader::ProgramCode& program) { | 104 | std::size_t CalculateProgramSize(const GLShader::ProgramCode& program) { |
| 105 | constexpr std::size_t start_offset = 10; | 105 | constexpr std::size_t start_offset = 10; |
| 106 | constexpr u64 key = 0xE2400FFFFF07000FULL; | 106 | // This is the encoded version of BRA that jumps to itself. All Nvidia |
| 107 | // shaders end with one. | ||
| 108 | constexpr u64 self_jumping_branch = 0xE2400FFFFF07000FULL; | ||
| 107 | constexpr u64 mask = 0xFFFFFFFFFF7FFFFFULL; | 109 | constexpr u64 mask = 0xFFFFFFFFFF7FFFFFULL; |
| 108 | std::size_t offset = start_offset; | 110 | std::size_t offset = start_offset; |
| 109 | std::size_t size = start_offset * sizeof(u64); | 111 | std::size_t size = start_offset * sizeof(u64); |
| 110 | while (offset < program.size()) { | 112 | while (offset < program.size()) { |
| 111 | const u64 instruction = program[offset]; | 113 | const u64 instruction = program[offset]; |
| 112 | if (!IsSchedInstruction(offset, start_offset)) { | 114 | if (!IsSchedInstruction(offset, start_offset)) { |
| 113 | if ((instruction & mask) == key) { | 115 | if ((instruction & mask) == self_jumping_branch) { |
| 114 | // End on Maxwell's "nop" instruction | 116 | // End on Maxwell's "nop" instruction |
| 115 | break; | 117 | break; |
| 116 | } | 118 | } |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 780526b66..08ae1a429 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -267,7 +267,7 @@ void CachedSurface::DownloadTexture(std::vector<u8>& staging_buffer) { | |||
| 267 | } | 267 | } |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | void CachedSurface::UploadTexture(std::vector<u8>& staging_buffer) { | 270 | void CachedSurface::UploadTexture(const std::vector<u8>& staging_buffer) { |
| 271 | MICROPROFILE_SCOPE(OpenGL_Texture_Upload); | 271 | MICROPROFILE_SCOPE(OpenGL_Texture_Upload); |
| 272 | SCOPE_EXIT({ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); }); | 272 | SCOPE_EXIT({ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); }); |
| 273 | for (u32 level = 0; level < params.emulated_levels; ++level) { | 273 | for (u32 level = 0; level < params.emulated_levels; ++level) { |
| @@ -275,7 +275,7 @@ void CachedSurface::UploadTexture(std::vector<u8>& staging_buffer) { | |||
| 275 | } | 275 | } |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | void CachedSurface::UploadTextureMipmap(u32 level, std::vector<u8>& staging_buffer) { | 278 | void CachedSurface::UploadTextureMipmap(u32 level, const std::vector<u8>& staging_buffer) { |
| 279 | glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(8U, params.GetRowAlignment(level))); | 279 | glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(8U, params.GetRowAlignment(level))); |
| 280 | glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.GetMipWidth(level))); | 280 | glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.GetMipWidth(level))); |
| 281 | 281 | ||
| @@ -284,7 +284,7 @@ void CachedSurface::UploadTextureMipmap(u32 level, std::vector<u8>& staging_buff | |||
| 284 | const std::size_t mip_offset = compression_type == SurfaceCompression::Converted | 284 | const std::size_t mip_offset = compression_type == SurfaceCompression::Converted |
| 285 | ? params.GetConvertedMipmapOffset(level) | 285 | ? params.GetConvertedMipmapOffset(level) |
| 286 | : params.GetHostMipmapLevelOffset(level); | 286 | : params.GetHostMipmapLevelOffset(level); |
| 287 | u8* buffer{staging_buffer.data() + mip_offset}; | 287 | const u8* buffer{staging_buffer.data() + mip_offset}; |
| 288 | if (is_compressed) { | 288 | if (is_compressed) { |
| 289 | const auto image_size{static_cast<GLsizei>(params.GetHostMipmapSize(level))}; | 289 | const auto image_size{static_cast<GLsizei>(params.GetHostMipmapSize(level))}; |
| 290 | switch (params.target) { | 290 | switch (params.target) { |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index e7cc66fbb..ff6ab6988 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h | |||
| @@ -39,7 +39,7 @@ public: | |||
| 39 | explicit CachedSurface(GPUVAddr gpu_addr, const SurfaceParams& params); | 39 | explicit CachedSurface(GPUVAddr gpu_addr, const SurfaceParams& params); |
| 40 | ~CachedSurface(); | 40 | ~CachedSurface(); |
| 41 | 41 | ||
| 42 | void UploadTexture(std::vector<u8>& staging_buffer) override; | 42 | void UploadTexture(const std::vector<u8>& staging_buffer) override; |
| 43 | void DownloadTexture(std::vector<u8>& staging_buffer) override; | 43 | void DownloadTexture(std::vector<u8>& staging_buffer) override; |
| 44 | 44 | ||
| 45 | GLenum GetTarget() const { | 45 | GLenum GetTarget() const { |
| @@ -57,7 +57,7 @@ protected: | |||
| 57 | View CreateViewInner(const ViewParams& view_key, bool is_proxy); | 57 | View CreateViewInner(const ViewParams& view_key, bool is_proxy); |
| 58 | 58 | ||
| 59 | private: | 59 | private: |
| 60 | void UploadTextureMipmap(u32 level, std::vector<u8>& staging_buffer); | 60 | void UploadTextureMipmap(u32 level, const std::vector<u8>& staging_buffer); |
| 61 | 61 | ||
| 62 | GLenum internal_format{}; | 62 | GLenum internal_format{}; |
| 63 | GLenum format{}; | 63 | GLenum format{}; |
| @@ -72,14 +72,13 @@ private: | |||
| 72 | 72 | ||
| 73 | class CachedSurfaceView final : public VideoCommon::ViewBase { | 73 | class CachedSurfaceView final : public VideoCommon::ViewBase { |
| 74 | public: | 74 | public: |
| 75 | explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params, | 75 | explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params, bool is_proxy); |
| 76 | const bool is_proxy); | ||
| 77 | ~CachedSurfaceView(); | 76 | ~CachedSurfaceView(); |
| 78 | 77 | ||
| 79 | /// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER | 78 | /// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER |
| 80 | void Attach(GLenum attachment, GLenum target) const; | 79 | void Attach(GLenum attachment, GLenum target) const; |
| 81 | 80 | ||
| 82 | GLuint GetTexture() { | 81 | GLuint GetTexture() const { |
| 83 | if (is_proxy) { | 82 | if (is_proxy) { |
| 84 | return surface.GetTexture(); | 83 | return surface.GetTexture(); |
| 85 | } | 84 | } |
diff --git a/src/video_core/texture_cache/surface_base.h b/src/video_core/texture_cache/surface_base.h index eaed6545d..8ba386a8a 100644 --- a/src/video_core/texture_cache/surface_base.h +++ b/src/video_core/texture_cache/surface_base.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | 10 | ||
| 11 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| 12 | #include "common/common_funcs.h" | 12 | #include "common/binary_find.h" |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "video_core/gpu.h" | 14 | #include "video_core/gpu.h" |
| 15 | #include "video_core/morton.h" | 15 | #include "video_core/morton.h" |
| @@ -191,7 +191,7 @@ private: | |||
| 191 | template <typename TView> | 191 | template <typename TView> |
| 192 | class SurfaceBase : public SurfaceBaseImpl { | 192 | class SurfaceBase : public SurfaceBaseImpl { |
| 193 | public: | 193 | public: |
| 194 | virtual void UploadTexture(std::vector<u8>& staging_buffer) = 0; | 194 | virtual void UploadTexture(const std::vector<u8>& staging_buffer) = 0; |
| 195 | 195 | ||
| 196 | virtual void DownloadTexture(std::vector<u8>& staging_buffer) = 0; | 196 | virtual void DownloadTexture(std::vector<u8>& staging_buffer) = 0; |
| 197 | 197 | ||