gl: dynamically determine texture buffer offset alignment

fix alignment issues for gpus where align < 16 is ok
This commit is contained in:
kd-11 2016-06-12 18:54:15 +03:00
parent 28a5d4d4f0
commit 3a63b62486
4 changed files with 11 additions and 7 deletions

View File

@ -381,6 +381,7 @@ void GLGSRender::on_init_thread()
LOG_NOTICE(RSX, "%s", (const char*)glGetString(GL_VENDOR));
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &m_min_texbuffer_alignment);
m_vao.create();
for (gl::texture &tex : m_gl_attrib_buffers)

View File

@ -36,6 +36,8 @@ private:
u32 m_begin_time = 0;
u32 m_draw_time = 0;
u32 m_vertex_upload_time = 0;
GLint m_min_texbuffer_alignment = 256;
public:
gl::fbo draw_fbo;

View File

@ -645,9 +645,10 @@ namespace gl
m_mapped_bytes_available = max_size;
}
std::pair<void*, u32> alloc_from_reserve(u32 size)
std::pair<void*, u32> alloc_from_reserve(u32 size, u32 alignment = 16)
{
size = (size + 15) & ~15;
alignment -= 1;
size = (size + alignment) & ~alignment;
if (m_mapped_bytes_available < size || !m_mapped_base)
{
@ -669,7 +670,7 @@ namespace gl
m_mapped_reserve_offset += size;
m_mapped_bytes_available -= size;
EXPECTS((offset & 15) == 0);
EXPECTS((offset & alignment) == 0);
return std::make_pair(ptr, offset);
}

View File

@ -253,7 +253,7 @@ u32 GLGSRender::set_vertex_buffer()
auto &texture = m_gl_attrib_buffers[index];
u8 *src = reinterpret_cast<u8*>(inline_vertex_array.data());
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size);
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size, m_min_texbuffer_alignment);
u8 *dst = static_cast<u8*>(mapping.first);
src += offsets[index];
@ -337,7 +337,7 @@ u32 GLGSRender::set_vertex_buffer()
if (draw_command == rsx::draw_command::array)
{
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size);
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size, m_min_texbuffer_alignment);
gsl::byte *dst = static_cast<gsl::byte*>(mapping.first);
buffer_offset = mapping.second;
@ -354,7 +354,7 @@ u32 GLGSRender::set_vertex_buffer()
if (draw_command == rsx::draw_command::indexed)
{
data_size = (max_index + 1) * element_size;
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size);
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size, m_min_texbuffer_alignment);
gsl::byte *dst = static_cast<gsl::byte*>(mapping.first);
buffer_offset = mapping.second;
@ -385,7 +385,7 @@ u32 GLGSRender::set_vertex_buffer()
auto &texture = m_gl_attrib_buffers[index];
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size);
auto mapping = m_attrib_ring_buffer->alloc_from_reserve(data_size, m_min_texbuffer_alignment);
u8 *dst = static_cast<u8*>(mapping.first);
memcpy(dst, vertex_data.data(), data_size);