Browse Source
Merge pull request #2318 from ReinUsesLisp/sampler-cache
Merge pull request #2318 from ReinUsesLisp/sampler-cache
gl_sampler_cache: Port sampler cache to OpenGLpull/15/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 183 additions and 181 deletions
-
4src/video_core/CMakeLists.txt
-
94src/video_core/renderer_opengl/gl_rasterizer.cpp
-
32src/video_core/renderer_opengl/gl_rasterizer.h
-
52src/video_core/renderer_opengl/gl_sampler_cache.cpp
-
25src/video_core/renderer_opengl/gl_sampler_cache.h
-
40src/video_core/renderer_vulkan/vk_sampler_cache.cpp
-
36src/video_core/renderer_vulkan/vk_sampler_cache.h
-
21src/video_core/sampler_cache.cpp
-
60src/video_core/sampler_cache.h
@ -0,0 +1,52 @@ |
|||
// Copyright 2019 yuzu Emulator Project
|
|||
// Licensed under GPLv2 or any later version
|
|||
// Refer to the license.txt file included.
|
|||
|
|||
#include "common/logging/log.h"
|
|||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|||
#include "video_core/renderer_opengl/gl_sampler_cache.h"
|
|||
#include "video_core/renderer_opengl/maxwell_to_gl.h"
|
|||
|
|||
namespace OpenGL { |
|||
|
|||
SamplerCacheOpenGL::SamplerCacheOpenGL() = default; |
|||
|
|||
SamplerCacheOpenGL::~SamplerCacheOpenGL() = default; |
|||
|
|||
OGLSampler SamplerCacheOpenGL::CreateSampler(const Tegra::Texture::TSCEntry& tsc) const { |
|||
OGLSampler sampler; |
|||
sampler.Create(); |
|||
|
|||
const GLuint sampler_id{sampler.handle}; |
|||
glSamplerParameteri( |
|||
sampler_id, GL_TEXTURE_MAG_FILTER, |
|||
MaxwellToGL::TextureFilterMode(tsc.mag_filter, Tegra::Texture::TextureMipmapFilter::None)); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, |
|||
MaxwellToGL::TextureFilterMode(tsc.min_filter, tsc.mipmap_filter)); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(tsc.wrap_u)); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(tsc.wrap_v)); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(tsc.wrap_p)); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_MODE, |
|||
tsc.depth_compare_enabled == 1 ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE); |
|||
glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_FUNC, |
|||
MaxwellToGL::DepthCompareFunc(tsc.depth_compare_func)); |
|||
glSamplerParameterfv(sampler_id, GL_TEXTURE_BORDER_COLOR, tsc.GetBorderColor().data()); |
|||
glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, tsc.GetMinLod()); |
|||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, tsc.GetMaxLod()); |
|||
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, tsc.GetLodBias()); |
|||
if (GLAD_GL_ARB_texture_filter_anisotropic) { |
|||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY, tsc.GetMaxAnisotropy()); |
|||
} else if (GLAD_GL_EXT_texture_filter_anisotropic) { |
|||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, tsc.GetMaxAnisotropy()); |
|||
} else if (tsc.GetMaxAnisotropy() != 1) { |
|||
LOG_WARNING(Render_OpenGL, "Anisotropy not supported by host GPU driver"); |
|||
} |
|||
|
|||
return sampler; |
|||
} |
|||
|
|||
GLuint SamplerCacheOpenGL::ToSamplerType(const OGLSampler& sampler) const { |
|||
return sampler.handle; |
|||
} |
|||
|
|||
} // namespace OpenGL
|
|||
@ -0,0 +1,25 @@ |
|||
// Copyright 2019 yuzu Emulator Project |
|||
// Licensed under GPLv2 or any later version |
|||
// Refer to the license.txt file included. |
|||
|
|||
#pragma once |
|||
|
|||
#include <glad/glad.h> |
|||
|
|||
#include "video_core/renderer_opengl/gl_resource_manager.h" |
|||
#include "video_core/sampler_cache.h" |
|||
|
|||
namespace OpenGL { |
|||
|
|||
class SamplerCacheOpenGL final : public VideoCommon::SamplerCache<GLuint, OGLSampler> { |
|||
public: |
|||
explicit SamplerCacheOpenGL(); |
|||
~SamplerCacheOpenGL(); |
|||
|
|||
protected: |
|||
OGLSampler CreateSampler(const Tegra::Texture::TSCEntry& tsc) const; |
|||
|
|||
GLuint ToSamplerType(const OGLSampler& sampler) const; |
|||
}; |
|||
|
|||
} // namespace OpenGL |
|||
@ -0,0 +1,21 @@ |
|||
// Copyright 2019 yuzu Emulator Project
|
|||
// Licensed under GPLv2 or any later version
|
|||
// Refer to the license.txt file included.
|
|||
|
|||
#include "common/cityhash.h"
|
|||
#include "common/common_types.h"
|
|||
#include "video_core/sampler_cache.h"
|
|||
|
|||
namespace VideoCommon { |
|||
|
|||
std::size_t SamplerCacheKey::Hash() const { |
|||
static_assert(sizeof(raw) % sizeof(u64) == 0); |
|||
return static_cast<std::size_t>( |
|||
Common::CityHash64(reinterpret_cast<const char*>(raw.data()), sizeof(raw) / sizeof(u64))); |
|||
} |
|||
|
|||
bool SamplerCacheKey::operator==(const SamplerCacheKey& rhs) const { |
|||
return raw == rhs.raw; |
|||
} |
|||
|
|||
} // namespace VideoCommon
|
|||
@ -0,0 +1,60 @@ |
|||
// Copyright 2019 yuzu Emulator Project |
|||
// Licensed under GPLv2 or any later version |
|||
// Refer to the license.txt file included. |
|||
|
|||
#pragma once |
|||
|
|||
#include <cstddef> |
|||
#include <unordered_map> |
|||
|
|||
#include "video_core/textures/texture.h" |
|||
|
|||
namespace VideoCommon { |
|||
|
|||
struct SamplerCacheKey final : public Tegra::Texture::TSCEntry { |
|||
std::size_t Hash() const; |
|||
|
|||
bool operator==(const SamplerCacheKey& rhs) const; |
|||
|
|||
bool operator!=(const SamplerCacheKey& rhs) const { |
|||
return !operator==(rhs); |
|||
} |
|||
}; |
|||
|
|||
} // namespace VideoCommon |
|||
|
|||
namespace std { |
|||
|
|||
template <> |
|||
struct hash<VideoCommon::SamplerCacheKey> { |
|||
std::size_t operator()(const VideoCommon::SamplerCacheKey& k) const noexcept { |
|||
return k.Hash(); |
|||
} |
|||
}; |
|||
|
|||
} // namespace std |
|||
|
|||
namespace VideoCommon { |
|||
|
|||
template <typename SamplerType, typename SamplerStorageType> |
|||
class SamplerCache { |
|||
public: |
|||
SamplerType GetSampler(const Tegra::Texture::TSCEntry& tsc) { |
|||
const auto [entry, is_cache_miss] = cache.try_emplace(SamplerCacheKey{tsc}); |
|||
auto& sampler = entry->second; |
|||
if (is_cache_miss) { |
|||
sampler = CreateSampler(tsc); |
|||
} |
|||
return ToSamplerType(sampler); |
|||
} |
|||
|
|||
protected: |
|||
virtual SamplerStorageType CreateSampler(const Tegra::Texture::TSCEntry& tsc) const = 0; |
|||
|
|||
virtual SamplerType ToSamplerType(const SamplerStorageType& sampler) const = 0; |
|||
|
|||
private: |
|||
std::unordered_map<SamplerCacheKey, SamplerStorageType> cache; |
|||
}; |
|||
|
|||
} // namespace VideoCommon |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue