mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
OGL-StreamBuffer: replace size_t with u32
Yes, this matters. We align our buffer all the the time which needs a division. u64 divisions are just so slow.
This commit is contained in:
parent
606e46ba8d
commit
d9eafd94a2
@ -22,7 +22,7 @@ static u32 genBuffer()
|
||||
return id;
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer(u32 type, size_t size)
|
||||
StreamBuffer::StreamBuffer(u32 type, u32 size)
|
||||
: m_buffer(genBuffer()), m_buffertype(type), m_size(ROUND_UP_POW2(size)), m_bit_per_slot(Log2(ROUND_UP_POW2(size) / SYNC_POINTS))
|
||||
{
|
||||
m_iterator = 0;
|
||||
@ -77,7 +77,7 @@ void StreamBuffer::DeleteFences()
|
||||
glDeleteSync(fences[i]);
|
||||
}
|
||||
}
|
||||
void StreamBuffer::AllocMemory(size_t size)
|
||||
void StreamBuffer::AllocMemory(u32 size)
|
||||
{
|
||||
// insert waiting slots for used memory
|
||||
for (int i = SLOT(m_used_iterator); i < SLOT(m_iterator); i++)
|
||||
@ -126,7 +126,7 @@ void StreamBuffer::AllocMemory(size_t size)
|
||||
class MapAndOrphan : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
MapAndOrphan(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
MapAndOrphan(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
|
||||
}
|
||||
@ -134,7 +134,7 @@ public:
|
||||
~MapAndOrphan() {
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
if (m_iterator + size >= m_size) {
|
||||
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
|
||||
m_iterator = 0;
|
||||
@ -144,7 +144,7 @@ public:
|
||||
return std::make_pair(pointer, m_iterator);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
glFlushMappedBufferRange(m_buffertype, 0, used_size);
|
||||
glUnmapBuffer(m_buffertype);
|
||||
m_iterator += used_size;
|
||||
@ -161,7 +161,7 @@ public:
|
||||
class MapAndSync : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
MapAndSync(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
MapAndSync(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
CreateFences();
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
glBufferData(m_buffertype, m_size, nullptr, GL_STREAM_DRAW);
|
||||
@ -171,14 +171,14 @@ public:
|
||||
DeleteFences();
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
AllocMemory(size);
|
||||
u8* pointer = (u8*)glMapBufferRange(m_buffertype, m_iterator, size,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
return std::make_pair(pointer, m_iterator);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
glFlushMappedBufferRange(m_buffertype, 0, used_size);
|
||||
glUnmapBuffer(m_buffertype);
|
||||
m_iterator += used_size;
|
||||
@ -201,7 +201,7 @@ public:
|
||||
class BufferStorage : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
BufferStorage(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
BufferStorage(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
CreateFences();
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
|
||||
@ -220,12 +220,12 @@ public:
|
||||
glBindBuffer(m_buffertype, 0);
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
AllocMemory(size);
|
||||
return std::make_pair(m_pointer + m_iterator, m_iterator);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
glFlushMappedBufferRange(m_buffertype, m_iterator, used_size);
|
||||
m_iterator += used_size;
|
||||
}
|
||||
@ -243,7 +243,7 @@ public:
|
||||
class PinnedMemory : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
PinnedMemory(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
PinnedMemory(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
CreateFences();
|
||||
m_pointer = (u8*)AllocateAlignedMemory(ROUND_UP(m_size,ALIGN_PINNED_MEMORY), ALIGN_PINNED_MEMORY );
|
||||
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_buffer);
|
||||
@ -260,12 +260,12 @@ public:
|
||||
m_pointer = nullptr;
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
AllocMemory(size);
|
||||
return std::make_pair(m_pointer + m_iterator, m_iterator);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
m_iterator += used_size;
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ public:
|
||||
class BufferSubData : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
BufferSubData(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
BufferSubData(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
glBufferData(m_buffertype, size, nullptr, GL_STATIC_DRAW);
|
||||
m_pointer = new u8[m_size];
|
||||
@ -291,11 +291,11 @@ public:
|
||||
delete [] m_pointer;
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
return std::make_pair(m_pointer, 0);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
glBufferSubData(m_buffertype, 0, used_size, m_pointer);
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ public:
|
||||
class BufferData : public StreamBuffer
|
||||
{
|
||||
public:
|
||||
BufferData(u32 type, size_t size) : StreamBuffer(type, size) {
|
||||
BufferData(u32 type, u32 size) : StreamBuffer(type, size) {
|
||||
glBindBuffer(m_buffertype, m_buffer);
|
||||
m_pointer = new u8[m_size];
|
||||
}
|
||||
@ -319,11 +319,11 @@ public:
|
||||
delete [] m_pointer;
|
||||
}
|
||||
|
||||
std::pair<u8*, size_t> Map(size_t size) override {
|
||||
std::pair<u8*, u32> Map(u32 size) override {
|
||||
return std::make_pair(m_pointer, 0);
|
||||
}
|
||||
|
||||
void Unmap(size_t used_size) override {
|
||||
void Unmap(u32 used_size) override {
|
||||
glBufferData(m_buffertype, used_size, m_pointer, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ public:
|
||||
};
|
||||
|
||||
// choose best streaming library based on the supported extensions and known issues
|
||||
StreamBuffer* StreamBuffer::Create(u32 type, size_t size)
|
||||
StreamBuffer* StreamBuffer::Create(u32 type, u32 size)
|
||||
{
|
||||
// without basevertex support, only streaming methods whith uploads everything to zero works fine:
|
||||
if (!g_ogl_config.bSupportsGLBaseVertex)
|
||||
|
@ -15,7 +15,7 @@ namespace OGL
|
||||
class StreamBuffer {
|
||||
|
||||
public:
|
||||
static StreamBuffer* Create(u32 type, size_t size);
|
||||
static StreamBuffer* Create(u32 type, u32 size);
|
||||
virtual ~StreamBuffer();
|
||||
|
||||
/* This mapping function will return a pair of:
|
||||
@ -26,10 +26,10 @@ public:
|
||||
* Mapping invalidates the current buffer content,
|
||||
* so it isn't allowed to access the old content any more.
|
||||
*/
|
||||
virtual std::pair<u8*, size_t> Map(size_t size) = 0;
|
||||
virtual void Unmap(size_t used_size) = 0;
|
||||
virtual std::pair<u8*, u32> Map(u32 size) = 0;
|
||||
virtual void Unmap(u32 used_size) = 0;
|
||||
|
||||
inline std::pair<u8*, size_t> Map(size_t size, u32 stride)
|
||||
inline std::pair<u8*, u32> Map(u32 size, u32 stride)
|
||||
{
|
||||
u32 padding = m_iterator % stride;
|
||||
if (padding)
|
||||
@ -42,21 +42,21 @@ public:
|
||||
const u32 m_buffer;
|
||||
|
||||
protected:
|
||||
StreamBuffer(u32 type, size_t size);
|
||||
StreamBuffer(u32 type, u32 size);
|
||||
void CreateFences();
|
||||
void DeleteFences();
|
||||
void AllocMemory(size_t size);
|
||||
void AllocMemory(u32 size);
|
||||
|
||||
const u32 m_buffertype;
|
||||
const size_t m_size;
|
||||
const u32 m_size;
|
||||
|
||||
size_t m_iterator;
|
||||
size_t m_used_iterator;
|
||||
size_t m_free_iterator;
|
||||
u32 m_iterator;
|
||||
u32 m_used_iterator;
|
||||
u32 m_free_iterator;
|
||||
|
||||
private:
|
||||
static const int SYNC_POINTS = 16;
|
||||
inline int SLOT(size_t x) const { return x >> m_bit_per_slot; }
|
||||
inline int SLOT(u32 x) const { return x >> m_bit_per_slot; }
|
||||
const int m_bit_per_slot;
|
||||
|
||||
GLsync fences[SYNC_POINTS];
|
||||
|
Loading…
x
Reference in New Issue
Block a user