2018-03-19 22:10:59 +01:00
|
|
|
// Copyright 2018 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-08-21 05:24:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
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"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2020-05-11 21:35:04 +02:00
|
|
|
class Device;
|
2020-12-30 06:25:23 +01:00
|
|
|
class StateTracker;
|
2020-05-11 21:35:04 +02:00
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
class OGLStreamBuffer : private NonCopyable {
|
|
|
|
public:
|
2020-12-30 06:25:23 +01:00
|
|
|
explicit OGLStreamBuffer(const Device& device, StateTracker& state_tracker_);
|
2018-08-09 21:31:46 +02:00
|
|
|
~OGLStreamBuffer();
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
/*
|
|
|
|
* Allocates a linear chunk of memory in the GPU buffer with at least "size" bytes
|
|
|
|
* and the optional alignment requirement.
|
|
|
|
* If the buffer is full, the whole buffer is reallocated which invalidates old chunks.
|
2020-12-30 06:25:23 +01:00
|
|
|
* The return values are the pointer to the new chunk, and the offset within the buffer.
|
2018-08-09 21:31:46 +02:00
|
|
|
* The actual used size must be specified on unmapping the chunk.
|
|
|
|
*/
|
2020-12-30 06:25:23 +01:00
|
|
|
std::pair<u8*, GLintptr> Map(GLsizeiptr size, GLintptr alignment = 0);
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
void Unmap(GLsizeiptr size);
|
2018-03-19 22:10:59 +01:00
|
|
|
|
2020-06-09 23:27:59 +02:00
|
|
|
GLuint Handle() const {
|
|
|
|
return gl_buffer.handle;
|
|
|
|
}
|
|
|
|
|
2020-05-11 21:35:04 +02:00
|
|
|
u64 Address() const {
|
|
|
|
return gpu_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLsizeiptr Size() const noexcept {
|
2020-12-30 06:25:23 +01:00
|
|
|
return BUFFER_SIZE;
|
2020-06-09 23:27:59 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 21:31:46 +02:00
|
|
|
private:
|
2020-12-30 06:25:23 +01:00
|
|
|
static constexpr GLsizeiptr BUFFER_SIZE = 256 * 1024 * 1024;
|
|
|
|
|
|
|
|
StateTracker& state_tracker;
|
|
|
|
|
2018-03-19 22:10:59 +01:00
|
|
|
OGLBuffer gl_buffer;
|
|
|
|
|
2020-05-11 21:35:04 +02:00
|
|
|
GLuint64EXT gpu_address = 0;
|
2018-08-09 21:31:46 +02:00
|
|
|
GLintptr buffer_pos = 0;
|
|
|
|
GLsizeiptr mapped_size = 0;
|
|
|
|
u8* mapped_ptr = nullptr;
|
2018-03-19 22:10:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|