forked from suyu/suyu
82c2601555
Reimplement the buffer cache using cached bindings and page level granularity for modification tracking. This also drops the usage of shared pointers and virtual functions from the cache. - Bindings are cached, allowing to skip work when the game changes few bits between draws. - OpenGL Assembly shaders no longer copy when a region has been modified from the GPU to emulate constant buffers, instead GL_EXT_memory_object is used to alias sub-buffers within the same allocation. - OpenGL Assembly shaders stream constant buffer data using glProgramBufferParametersIuivNV, from NV_parameter_buffer_object. In theory this should save one hash table resolve inside the driver compared to glBufferSubData. - A new OpenGL stream buffer is implemented based on fences for drivers that are not Nvidia's proprietary, due to their low performance on partial glBufferSubData calls synchronized with 3D rendering (that some games use a lot). - Most optimizations are shared between APIs now, allowing Vulkan to cache more bindings than before, skipping unnecesarry work. This commit adds the necessary infrastructure to use Vulkan object from OpenGL. Overall, it improves performance and fixes some bugs present on the old cache. There are still some edge cases hit by some games that harm performance on some vendors, this are planned to be fixed in later commits.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
// Copyright 2021 yuzu Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <utility>
|
|
|
|
#include <glad/glad.h>
|
|
|
|
#include "common/common_types.h"
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
namespace OpenGL {
|
|
|
|
class StreamBuffer {
|
|
static constexpr size_t STREAM_BUFFER_SIZE = 64 * 1024 * 1024;
|
|
static constexpr size_t NUM_SYNCS = 16;
|
|
static constexpr size_t REGION_SIZE = STREAM_BUFFER_SIZE / NUM_SYNCS;
|
|
static constexpr size_t MAX_ALIGNMENT = 256;
|
|
static_assert(STREAM_BUFFER_SIZE % MAX_ALIGNMENT == 0);
|
|
static_assert(STREAM_BUFFER_SIZE % NUM_SYNCS == 0);
|
|
static_assert(REGION_SIZE % MAX_ALIGNMENT == 0);
|
|
|
|
public:
|
|
explicit StreamBuffer();
|
|
|
|
[[nodiscard]] std::pair<std::span<u8>, size_t> Request(size_t size) noexcept;
|
|
|
|
[[nodiscard]] GLuint Handle() const noexcept {
|
|
return buffer.handle;
|
|
}
|
|
|
|
private:
|
|
[[nodiscard]] static size_t Region(size_t offset) noexcept {
|
|
return offset / REGION_SIZE;
|
|
}
|
|
|
|
size_t iterator = 0;
|
|
size_t used_iterator = 0;
|
|
size_t free_iterator = 0;
|
|
u8* mapped_pointer = nullptr;
|
|
OGLBuffer buffer;
|
|
std::array<OGLSync, NUM_SYNCS> fences;
|
|
};
|
|
|
|
} // namespace OpenGL
|