2019-01-08 21:30:10 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2019-01-05 05:01:38 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2019-01-08 21:30:10 +01:00
|
|
|
#include <glad/glad.h>
|
|
|
|
|
2019-01-05 05:01:38 +01:00
|
|
|
#include "common/assert.h"
|
2019-01-08 21:30:10 +01:00
|
|
|
#include "common/common_types.h"
|
2019-01-05 05:01:38 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-01-08 21:30:10 +01:00
|
|
|
#include "video_core/rasterizer_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
namespace GLShader {
|
|
|
|
class GlobalMemoryEntry;
|
|
|
|
} // namespace GLShader
|
|
|
|
|
|
|
|
class RasterizerOpenGL;
|
|
|
|
class CachedGlobalRegion;
|
|
|
|
using GlobalRegion = std::shared_ptr<CachedGlobalRegion>;
|
|
|
|
|
|
|
|
class CachedGlobalRegion final : public RasterizerCacheObject {
|
|
|
|
public:
|
|
|
|
explicit CachedGlobalRegion(VAddr addr, u32 size);
|
|
|
|
|
|
|
|
/// Gets the address of the shader in guest memory, required for cache management
|
2019-03-11 17:02:28 +01:00
|
|
|
VAddr GetAddr() const override {
|
2019-01-08 21:30:10 +01:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the size of the shader in guest memory, required for cache management
|
2019-03-11 17:02:28 +01:00
|
|
|
std::size_t GetSizeInBytes() const override {
|
2019-01-08 21:30:10 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the GL program handle for the buffer
|
|
|
|
GLuint GetBufferHandle() const {
|
|
|
|
return buffer.handle;
|
|
|
|
}
|
|
|
|
|
2019-01-05 05:01:38 +01:00
|
|
|
/// Reloads the global region from guest memory
|
|
|
|
void Reload(u32 size_);
|
|
|
|
|
2019-01-08 21:30:10 +01:00
|
|
|
// TODO(Rodrigo): When global memory is written (STG), implement flushing
|
|
|
|
void Flush() override {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
VAddr addr{};
|
|
|
|
u32 size{};
|
|
|
|
|
|
|
|
OGLBuffer buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GlobalRegionCacheOpenGL final : public RasterizerCache<GlobalRegion> {
|
|
|
|
public:
|
|
|
|
explicit GlobalRegionCacheOpenGL(RasterizerOpenGL& rasterizer);
|
2019-01-05 05:01:38 +01:00
|
|
|
|
|
|
|
/// Gets the current specified shader stage program
|
|
|
|
GlobalRegion GetGlobalRegion(const GLShader::GlobalMemoryEntry& descriptor,
|
|
|
|
Tegra::Engines::Maxwell3D::Regs::ShaderStage stage);
|
|
|
|
|
|
|
|
private:
|
|
|
|
GlobalRegion TryGetReservedGlobalRegion(VAddr addr, u32 size) const;
|
|
|
|
GlobalRegion GetUncachedGlobalRegion(VAddr addr, u32 size);
|
renderer_opengl/gl_global_cache: Replace indexing for assignment with insert_or_assign
The previous code had some minor issues with it, really not a big deal,
but amending it is basically 'free', so I figured, "why not?".
With the standard container maps, when:
map[key] = thing;
is done, this can cause potentially undesirable behavior in certain
scenarios. In particular, if there's no value associated with the key,
then the map constructs a default initialized instance of the value
type.
In this case, since it's a std::shared_ptr (as a type alias) that is
the value type, this will construct a std::shared_pointer, and then
assign over it (with objects that are quite large, or actively heap
allocate this can be extremely undesirable).
We also make the function take the region by value, as we can avoid a
copy (and by extension with std::shared_ptr, a copy causes an atomic
reference count increment), in certain scenarios when ownership isn't a
concern (i.e. when ReserveGlobalRegion is called with an rvalue
reference, then no copy at all occurs). So, it's more-or-less a "free"
gain without many downsides.
2019-03-11 17:07:20 +01:00
|
|
|
void ReserveGlobalRegion(GlobalRegion region);
|
2019-01-05 05:01:38 +01:00
|
|
|
|
|
|
|
std::unordered_map<VAddr, GlobalRegion> reserve;
|
2019-01-08 21:30:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|