From 7b69fec8e71a1540f17a4a94e5f2d4132d5b09b6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Dec 2015 10:04:09 -0500 Subject: [PATCH 1/4] StreamBuffer: Remove unnecessary inline specifiers Methods defined directly in class bodies are inline by default --- Source/Core/VideoBackends/OGL/StreamBuffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.h b/Source/Core/VideoBackends/OGL/StreamBuffer.h index ba1f78944c..ab55fb865b 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.h +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.h @@ -33,7 +33,7 @@ public: virtual std::pair Map(u32 size) = 0; virtual void Unmap(u32 used_size) = 0; - inline std::pair Map(u32 size, u32 stride) + std::pair Map(u32 size, u32 stride) { u32 padding = m_iterator % stride; if (padding) @@ -60,7 +60,7 @@ protected: private: static const int SYNC_POINTS = 16; - inline int SLOT(u32 x) const { return x >> m_bit_per_slot; } + int SLOT(u32 x) const { return x >> m_bit_per_slot; } const int m_bit_per_slot; GLsync fences[SYNC_POINTS]; From 1eea95a5beca98a840e6725867dbdfabf467e516 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Dec 2015 10:06:40 -0500 Subject: [PATCH 2/4] StreamBuffer: Use std::array for fences --- .../Core/VideoBackends/OGL/StreamBuffer.cpp | 20 +++++++++---------- Source/Core/VideoBackends/OGL/StreamBuffer.h | 5 +++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp index 47dfd14557..705c0b6702 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp @@ -61,20 +61,20 @@ StreamBuffer::~StreamBuffer() void StreamBuffer::CreateFences() { - for (int i=0; i #include #include "Common/GL/GLUtil.h" @@ -59,11 +60,11 @@ protected: u32 m_free_iterator; private: - static const int SYNC_POINTS = 16; + static constexpr int SYNC_POINTS = 16; int SLOT(u32 x) const { return x >> m_bit_per_slot; } const int m_bit_per_slot; - GLsync fences[SYNC_POINTS]; + std::array m_fences{}; }; } From ec71452706347f6e2a0c06ed7b0d422a3df30978 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Dec 2015 10:09:03 -0500 Subject: [PATCH 3/4] StreamBuffer: Correct function casing --- Source/Core/VideoBackends/OGL/StreamBuffer.cpp | 16 ++++++++-------- Source/Core/VideoBackends/OGL/StreamBuffer.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp index 705c0b6702..5107fe0b17 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp @@ -15,7 +15,7 @@ namespace OGL { // moved out of constructor, so m_buffer is allowed to be const -static u32 genBuffer() +static u32 GenBuffer() { u32 id; glGenBuffers(1, &id); @@ -23,7 +23,7 @@ static u32 genBuffer() } StreamBuffer::StreamBuffer(u32 type, u32 size) -: m_buffer(genBuffer()), m_buffertype(type), m_size(ROUND_UP_POW2(size)), m_bit_per_slot(IntLog2(ROUND_UP_POW2(size) / SYNC_POINTS)) + : m_buffer(GenBuffer()), m_buffertype(type), m_size(ROUND_UP_POW2(size)), m_bit_per_slot(IntLog2(ROUND_UP_POW2(size) / SYNC_POINTS)) { m_iterator = 0; m_used_iterator = 0; @@ -68,11 +68,11 @@ void StreamBuffer::CreateFences() } void StreamBuffer::DeleteFences() { - for (int i = SLOT(m_free_iterator) + 1; i < SYNC_POINTS; i++) + for (int i = Slot(m_free_iterator) + 1; i < SYNC_POINTS; i++) { glDeleteSync(m_fences[i]); } - for (int i = 0; i < SLOT(m_iterator); i++) + for (int i = 0; i < Slot(m_iterator); i++) { glDeleteSync(m_fences[i]); } @@ -80,14 +80,14 @@ void StreamBuffer::DeleteFences() void StreamBuffer::AllocMemory(u32 size) { // insert waiting slots for used memory - for (int i = SLOT(m_used_iterator); i < SLOT(m_iterator); i++) + for (int i = Slot(m_used_iterator); i < Slot(m_iterator); i++) { m_fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } m_used_iterator = m_iterator; // wait for new slots to end of buffer - for (int i = SLOT(m_free_iterator) + 1; i <= SLOT(m_iterator + size) && i < SYNC_POINTS; i++) + for (int i = Slot(m_free_iterator) + 1; i <= Slot(m_iterator + size) && i < SYNC_POINTS; i++) { glClientWaitSync(m_fences[i], GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED); glDeleteSync(m_fences[i]); @@ -98,7 +98,7 @@ void StreamBuffer::AllocMemory(u32 size) if (m_iterator + size >= m_size) { // insert waiting slots in unused space at the end of the buffer - for (int i = SLOT(m_used_iterator); i < SYNC_POINTS; i++) + for (int i = Slot(m_used_iterator); i < SYNC_POINTS; i++) { m_fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } @@ -107,7 +107,7 @@ void StreamBuffer::AllocMemory(u32 size) m_used_iterator = m_iterator = 0; // offset 0 is always aligned // wait for space at the start - for (int i = 0; i <= SLOT(m_iterator + size); i++) + for (int i = 0; i <= Slot(m_iterator + size); i++) { glClientWaitSync(m_fences[i], GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED); glDeleteSync(m_fences[i]); diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.h b/Source/Core/VideoBackends/OGL/StreamBuffer.h index 2271270df8..b886e49c53 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.h +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.h @@ -61,7 +61,7 @@ protected: private: static constexpr int SYNC_POINTS = 16; - int SLOT(u32 x) const { return x >> m_bit_per_slot; } + int Slot(u32 x) const { return x >> m_bit_per_slot; } const int m_bit_per_slot; std::array m_fences{}; From d20ba76ab3a753f658533c502c72fcef86c34a1a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Dec 2015 10:15:17 -0500 Subject: [PATCH 4/4] StreamBuffer: Make factory function return a std::unique_ptr --- .../VideoBackends/OGL/ProgramShaderCache.cpp | 6 +++--- Source/Core/VideoBackends/OGL/StreamBuffer.cpp | 18 +++++++++--------- Source/Core/VideoBackends/OGL/StreamBuffer.h | 3 ++- Source/Core/VideoBackends/OGL/TextureCache.cpp | 6 +++--- .../Core/VideoBackends/OGL/VertexManager.cpp | 9 +++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 84c2ccf4d8..904f1aff06 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" @@ -28,7 +29,7 @@ static const u32 UBO_LENGTH = 32*1024*1024; u32 ProgramShaderCache::s_ubo_buffer_size; s32 ProgramShaderCache::s_ubo_align; -static StreamBuffer *s_buffer; +static std::unique_ptr s_buffer; static int num_failures = 0; static LinearDiskCache g_program_disk_cache; @@ -505,8 +506,7 @@ void ProgramShaderCache::Shutdown() pixel_uid_checker.Invalidate(); vertex_uid_checker.Invalidate(); - delete s_buffer; - s_buffer = nullptr; + s_buffer.reset(); } void ProgramShaderCache::CreateHeader() diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp index 5107fe0b17..5268423d72 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.cpp +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.cpp @@ -355,17 +355,17 @@ public: u8* m_pointer; }; -// choose best streaming library based on the supported extensions and known issues -StreamBuffer* StreamBuffer::Create(u32 type, u32 size) +// Chooses the best streaming method based on the supported extensions and known issues +std::unique_ptr StreamBuffer::Create(u32 type, u32 size) { // without basevertex support, only streaming methods whith uploads everything to zero works fine: if (!g_ogl_config.bSupportsGLBaseVertex) { if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM)) - return new BufferSubData(type, size); + return std::make_unique(type, size); // BufferData is by far the worst way, only use it if needed - return new BufferData(type, size); + return std::make_unique(type, size); } // Prefer the syncing buffers over the orphaning one @@ -374,25 +374,25 @@ StreamBuffer* StreamBuffer::Create(u32 type, u32 size) // pinned memory is much faster than buffer storage on AMD cards if (g_ogl_config.bSupportsGLPinnedMemory && !(DriverDetails::HasBug(DriverDetails::BUG_BROKENPINNEDMEMORY) && type == GL_ELEMENT_ARRAY_BUFFER)) - return new PinnedMemory(type, size); + return std::make_unique(type, size); // buffer storage works well in most situations if (g_ogl_config.bSupportsGLBufferStorage && !(DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTORAGE) && type == GL_ARRAY_BUFFER) && !(DriverDetails::HasBug(DriverDetails::BUG_INTELBROKENBUFFERSTORAGE) && type == GL_ELEMENT_ARRAY_BUFFER)) - return new BufferStorage(type, size); + return std::make_unique(type, size); // don't fall back to MapAnd* for Nvidia drivers if (DriverDetails::HasBug(DriverDetails::BUG_BROKENUNSYNCMAPPING)) - return new BufferSubData(type, size); + return std::make_unique(type, size); // mapping fallback if (g_ogl_config.bSupportsGLSync) - return new MapAndSync(type, size); + return std::make_unique(type, size); } // default fallback, should work everywhere, but isn't the best way to do this job - return new MapAndOrphan(type, size); + return std::make_unique(type, size); } } diff --git a/Source/Core/VideoBackends/OGL/StreamBuffer.h b/Source/Core/VideoBackends/OGL/StreamBuffer.h index b886e49c53..4cb1c93703 100644 --- a/Source/Core/VideoBackends/OGL/StreamBuffer.h +++ b/Source/Core/VideoBackends/OGL/StreamBuffer.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "Common/GL/GLUtil.h" @@ -20,7 +21,7 @@ class StreamBuffer { public: - static StreamBuffer* Create(u32 type, u32 size); + static std::unique_ptr Create(u32 type, u32 size); virtual ~StreamBuffer(); /* This mapping function will return a pair of: diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 3b07b44319..32cdcd6587 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "Common/Common.h" @@ -51,7 +52,7 @@ static u32 s_Textures[8]; static u32 s_ActiveTexture; static SHADER s_palette_pixel_shader[3]; -static StreamBuffer* s_palette_stream_buffer = nullptr; +static std::unique_ptr s_palette_stream_buffer; static GLuint s_palette_resolv_texture; static GLuint s_palette_buffer_offset_uniform[3]; static GLuint s_palette_multiplier_uniform[3]; @@ -318,8 +319,7 @@ TextureCache::~TextureCache() if (g_ActiveConfig.backend_info.bSupportsPaletteConversion) { - delete s_palette_stream_buffer; - s_palette_stream_buffer = nullptr; + s_palette_stream_buffer.reset(); glDeleteTextures(1, &s_palette_resolv_texture); } } diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index 5f5ddc4104..c37f4cbecd 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -36,8 +37,8 @@ namespace OGL const u32 MAX_IBUFFER_SIZE = 2*1024*1024; const u32 MAX_VBUFFER_SIZE = 32*1024*1024; -static StreamBuffer *s_vertexBuffer; -static StreamBuffer *s_indexBuffer; +static std::unique_ptr s_vertexBuffer; +static std::unique_ptr s_indexBuffer; static size_t s_baseVertex; static size_t s_index_offset; @@ -65,8 +66,8 @@ void VertexManager::CreateDeviceObjects() void VertexManager::DestroyDeviceObjects() { - delete s_vertexBuffer; - delete s_indexBuffer; + s_vertexBuffer.reset(); + s_indexBuffer.reset(); } void VertexManager::PrepareDrawBuffers(u32 stride)