2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2018-08-21 05:24:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
#include <array>
|
|
|
|
#include <span>
|
2020-12-30 06:25:23 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
#include <glad/glad.h>
|
2020-12-30 06:25:23 +01:00
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
#include "common/common_types.h"
|
2021-06-23 23:18:27 +02:00
|
|
|
#include "common/literals.h"
|
2018-03-19 22:10:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2021-06-23 23:18:27 +02:00
|
|
|
using namespace Common::Literals;
|
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
class StreamBuffer {
|
2021-06-23 23:18:27 +02:00
|
|
|
static constexpr size_t STREAM_BUFFER_SIZE = 64_MiB;
|
2021-01-17 00:48:58 +01:00
|
|
|
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);
|
2020-05-11 21:35:04 +02:00
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
public:
|
2021-01-17 00:48:58 +01:00
|
|
|
explicit StreamBuffer();
|
2020-06-09 23:27:59 +02:00
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
[[nodiscard]] std::pair<std::span<u8>, size_t> Request(size_t size) noexcept;
|
2020-05-11 21:35:04 +02:00
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
[[nodiscard]] GLuint Handle() const noexcept {
|
|
|
|
return buffer.handle;
|
2020-06-09 23:27:59 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
private:
|
2021-01-17 00:48:58 +01:00
|
|
|
[[nodiscard]] static size_t Region(size_t offset) noexcept {
|
|
|
|
return offset / REGION_SIZE;
|
|
|
|
}
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
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;
|
2018-03-19 22:10:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|