Merge pull request #1663 from lioncash/raster

rasterizer_cache: Remove reliance on the System singleton
This commit is contained in:
bunnei 2018-11-11 08:20:27 -08:00 committed by GitHub
commit c82bccab56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 25 additions and 10 deletions

View File

@ -10,10 +10,8 @@
#include <boost/range/iterator_range_core.hpp> #include <boost/range/iterator_range_core.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/core.h"
#include "core/settings.h" #include "core/settings.h"
#include "video_core/rasterizer_interface.h" #include "video_core/rasterizer_interface.h"
#include "video_core/renderer_base.h"
class RasterizerCacheObject { class RasterizerCacheObject {
public: public:
@ -66,6 +64,8 @@ class RasterizerCache : NonCopyable {
friend class RasterizerCacheObject; friend class RasterizerCacheObject;
public: public:
explicit RasterizerCache(VideoCore::RasterizerInterface& rasterizer) : rasterizer{rasterizer} {}
/// Write any cached resources overlapping the specified region back to memory /// Write any cached resources overlapping the specified region back to memory
void FlushRegion(Tegra::GPUVAddr addr, size_t size) { void FlushRegion(Tegra::GPUVAddr addr, size_t size) {
const auto& objects{GetSortedObjectsFromRegion(addr, size)}; const auto& objects{GetSortedObjectsFromRegion(addr, size)};
@ -111,14 +111,12 @@ protected:
void Register(const T& object) { void Register(const T& object) {
object->SetIsRegistered(true); object->SetIsRegistered(true);
object_cache.add({GetInterval(object), ObjectSet{object}}); object_cache.add({GetInterval(object), ObjectSet{object}});
auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer();
rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1); rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), 1);
} }
/// Unregisters an object from the cache /// Unregisters an object from the cache
void Unregister(const T& object) { void Unregister(const T& object) {
object->SetIsRegistered(false); object->SetIsRegistered(false);
auto& rasterizer = Core::System::GetInstance().Renderer().Rasterizer();
rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1); rasterizer.UpdatePagesCachedCount(object->GetAddr(), object->GetSizeInBytes(), -1);
// Only flush if use_accurate_gpu_emulation is enabled, as it incurs a performance hit // Only flush if use_accurate_gpu_emulation is enabled, as it incurs a performance hit
@ -179,4 +177,5 @@ private:
ObjectCache object_cache; ///< Cache of objects ObjectCache object_cache; ///< Cache of objects
u64 modified_ticks{}; ///< Counter of cache state ticks, used for in-order flushing u64 modified_ticks{}; ///< Counter of cache state ticks, used for in-order flushing
VideoCore::RasterizerInterface& rasterizer;
}; };

View File

@ -9,10 +9,12 @@
#include "core/core.h" #include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/renderer_opengl/gl_buffer_cache.h" #include "video_core/renderer_opengl/gl_buffer_cache.h"
#include "video_core/renderer_opengl/gl_rasterizer.h"
namespace OpenGL { namespace OpenGL {
OGLBufferCache::OGLBufferCache(std::size_t size) : stream_buffer(GL_ARRAY_BUFFER, size) {} OGLBufferCache::OGLBufferCache(RasterizerOpenGL& rasterizer, std::size_t size)
: RasterizerCache{rasterizer}, stream_buffer(GL_ARRAY_BUFFER, size) {}
GLintptr OGLBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, GLintptr OGLBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size,
std::size_t alignment, bool cache) { std::size_t alignment, bool cache) {

View File

@ -15,6 +15,8 @@
namespace OpenGL { namespace OpenGL {
class RasterizerOpenGL;
struct CachedBufferEntry final : public RasterizerCacheObject { struct CachedBufferEntry final : public RasterizerCacheObject {
VAddr GetAddr() const override { VAddr GetAddr() const override {
return addr; return addr;
@ -35,7 +37,7 @@ struct CachedBufferEntry final : public RasterizerCacheObject {
class OGLBufferCache final : public RasterizerCache<std::shared_ptr<CachedBufferEntry>> { class OGLBufferCache final : public RasterizerCache<std::shared_ptr<CachedBufferEntry>> {
public: public:
explicit OGLBufferCache(std::size_t size); explicit OGLBufferCache(RasterizerOpenGL& rasterizer, std::size_t size);
/// Uploads data from a guest GPU address. Returns host's buffer offset where it's been /// Uploads data from a guest GPU address. Returns host's buffer offset where it's been
/// allocated. /// allocated.

View File

@ -6,6 +6,7 @@
#include <array> #include <array>
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/renderer_opengl/gl_buffer_cache.h" #include "video_core/renderer_opengl/gl_buffer_cache.h"
#include "video_core/renderer_opengl/gl_primitive_assembler.h" #include "video_core/renderer_opengl/gl_primitive_assembler.h"

View File

@ -80,7 +80,8 @@ struct DrawParameters {
}; };
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo& info) RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo& info)
: emu_window{window}, screen_info{info}, buffer_cache(STREAM_BUFFER_SIZE) { : res_cache{*this}, shader_cache{*this}, emu_window{window}, screen_info{info},
buffer_cache(*this, STREAM_BUFFER_SIZE) {
// Create sampler objects // Create sampler objects
for (std::size_t i = 0; i < texture_samplers.size(); ++i) { for (std::size_t i = 0; i < texture_samplers.size(); ++i) {
texture_samplers[i].Create(); texture_samplers[i].Create();

View File

@ -15,6 +15,7 @@
#include "core/memory.h" #include "core/memory.h"
#include "core/settings.h" #include "core/settings.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_opengl/gl_rasterizer.h"
#include "video_core/renderer_opengl/gl_rasterizer_cache.h" #include "video_core/renderer_opengl/gl_rasterizer_cache.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/utils.h" #include "video_core/renderer_opengl/utils.h"
@ -1172,7 +1173,8 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle
UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle); UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle);
} }
RasterizerCacheOpenGL::RasterizerCacheOpenGL() { RasterizerCacheOpenGL::RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer)
: RasterizerCache{rasterizer} {
read_framebuffer.Create(); read_framebuffer.Create();
draw_framebuffer.Create(); draw_framebuffer.Create();
copy_pbo.Create(); copy_pbo.Create();

View File

@ -264,6 +264,8 @@ struct hash<SurfaceReserveKey> {
namespace OpenGL { namespace OpenGL {
class RasterizerOpenGL;
class CachedSurface final : public RasterizerCacheObject { class CachedSurface final : public RasterizerCacheObject {
public: public:
CachedSurface(const SurfaceParams& params); CachedSurface(const SurfaceParams& params);
@ -311,7 +313,7 @@ private:
class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {
public: public:
RasterizerCacheOpenGL(); explicit RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer);
/// Get a surface based on the texture configuration /// Get a surface based on the texture configuration
Surface GetTextureSurface(const Tegra::Texture::FullTextureInfo& config, Surface GetTextureSurface(const Tegra::Texture::FullTextureInfo& config,

View File

@ -6,10 +6,10 @@
#include "core/core.h" #include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_opengl/gl_rasterizer.h"
#include "video_core/renderer_opengl/gl_shader_cache.h" #include "video_core/renderer_opengl/gl_shader_cache.h"
#include "video_core/renderer_opengl/gl_shader_manager.h" #include "video_core/renderer_opengl/gl_shader_manager.h"
#include "video_core/renderer_opengl/utils.h" #include "video_core/renderer_opengl/utils.h"
#include "video_core/utils.h"
namespace OpenGL { namespace OpenGL {
@ -135,6 +135,8 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
return target_program.handle; return target_program.handle;
}; };
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {}
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
const VAddr program_addr{GetShaderAddress(program)}; const VAddr program_addr{GetShaderAddress(program)};

View File

@ -16,6 +16,8 @@
namespace OpenGL { namespace OpenGL {
class CachedShader; class CachedShader;
class RasterizerOpenGL;
using Shader = std::shared_ptr<CachedShader>; using Shader = std::shared_ptr<CachedShader>;
using Maxwell = Tegra::Engines::Maxwell3D::Regs; using Maxwell = Tegra::Engines::Maxwell3D::Regs;
@ -104,6 +106,8 @@ private:
class ShaderCacheOpenGL final : public RasterizerCache<Shader> { class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
public: public:
explicit ShaderCacheOpenGL(RasterizerOpenGL& rasterizer);
/// Gets the current specified shader stage program /// Gets the current specified shader stage program
Shader GetStageProgram(Maxwell::ShaderProgram program); Shader GetStageProgram(Maxwell::ShaderProgram program);
}; };