2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2013-01-31 15:11:53 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2013-01-31 15:11:53 -07:00
|
|
|
|
2015-12-21 08:06:40 -07:00
|
|
|
#include <array>
|
2014-01-22 16:47:49 -07:00
|
|
|
#include <utility>
|
2015-09-18 10:40:00 -06:00
|
|
|
|
|
|
|
#include "Common/GL/GLUtil.h"
|
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/OGL/FramebufferManager.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2013-01-31 15:11:53 -07:00
|
|
|
|
|
|
|
namespace OGL
|
|
|
|
{
|
|
|
|
|
2014-08-15 12:09:53 -06:00
|
|
|
class StreamBuffer
|
|
|
|
{
|
2013-01-31 15:11:53 -07:00
|
|
|
|
|
|
|
public:
|
2014-06-05 03:51:05 -06:00
|
|
|
static StreamBuffer* Create(u32 type, u32 size);
|
2014-01-22 16:47:49 -07:00
|
|
|
virtual ~StreamBuffer();
|
|
|
|
|
|
|
|
/* This mapping function will return a pair of:
|
|
|
|
* - the pointer to the mapped buffer
|
2015-01-10 22:17:29 -07:00
|
|
|
* - the offset into the real GPU buffer (always multiple of stride)
|
2014-01-22 16:47:49 -07:00
|
|
|
* On mapping, the maximum of size for allocation has to be set.
|
|
|
|
* The size really pushed into this fifo only has to be known on Unmapping.
|
|
|
|
* Mapping invalidates the current buffer content,
|
|
|
|
* so it isn't allowed to access the old content any more.
|
|
|
|
*/
|
2014-06-05 03:51:05 -06:00
|
|
|
virtual std::pair<u8*, u32> Map(u32 size) = 0;
|
|
|
|
virtual void Unmap(u32 used_size) = 0;
|
2014-01-22 16:47:49 -07:00
|
|
|
|
2015-12-21 08:04:09 -07:00
|
|
|
std::pair<u8*, u32> Map(u32 size, u32 stride)
|
2014-06-05 03:25:57 -06:00
|
|
|
{
|
|
|
|
u32 padding = m_iterator % stride;
|
|
|
|
if (padding)
|
|
|
|
{
|
|
|
|
m_iterator += stride - padding;
|
|
|
|
}
|
|
|
|
return Map(size);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
2014-06-05 03:25:57 -06:00
|
|
|
|
2014-01-22 16:47:49 -07:00
|
|
|
const u32 m_buffer;
|
|
|
|
|
|
|
|
protected:
|
2014-06-05 03:51:05 -06:00
|
|
|
StreamBuffer(u32 type, u32 size);
|
2014-01-22 16:47:49 -07:00
|
|
|
void CreateFences();
|
2013-08-29 13:03:48 -06:00
|
|
|
void DeleteFences();
|
2014-06-05 03:51:05 -06:00
|
|
|
void AllocMemory(u32 size);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2014-01-22 16:47:49 -07:00
|
|
|
const u32 m_buffertype;
|
2014-06-05 03:51:05 -06:00
|
|
|
const u32 m_size;
|
2014-03-29 04:05:44 -06:00
|
|
|
|
2014-06-05 03:51:05 -06:00
|
|
|
u32 m_iterator;
|
|
|
|
u32 m_used_iterator;
|
|
|
|
u32 m_free_iterator;
|
2014-01-22 16:47:49 -07:00
|
|
|
|
|
|
|
private:
|
2015-12-21 08:06:40 -07:00
|
|
|
static constexpr int SYNC_POINTS = 16;
|
2015-12-21 08:04:09 -07:00
|
|
|
int SLOT(u32 x) const { return x >> m_bit_per_slot; }
|
2014-06-05 03:06:41 -06:00
|
|
|
const int m_bit_per_slot;
|
|
|
|
|
2015-12-21 08:06:40 -07:00
|
|
|
std::array<GLsync, SYNC_POINTS> m_fences{};
|
2013-01-31 15:11:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|