From ed2068fb03e6c14b03bc7a379acf008a47da50f3 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 25 May 2022 23:49:08 +0300 Subject: [PATCH] gl: Rewrite buffer mapping --- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 8 +++----- rpcs3/Emu/RSX/GL/GLHelpers.h | 24 +++++++++++++++--------- rpcs3/Emu/RSX/GL/GLProcTable.h | 3 +++ rpcs3/Emu/RSX/GL/GLTexture.cpp | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index db27d87056..83ae9dcf2d 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -264,17 +264,15 @@ void GLGSRender::on_init_thread() if (gl_caps.vendor_AMD) { - m_identity_index_buffer = std::make_unique(); - m_identity_index_buffer->create(gl::buffer::target::element_array, 1 * 0x100000, nullptr, gl::buffer::memory_type::host_visible); - // Initialize with 256k identity entries - auto* dst = reinterpret_cast(m_identity_index_buffer->map(gl::buffer::access::write)); + std::vector dst(256 * 1024); for (u32 n = 0; n < (0x100000 >> 2); ++n) { dst[n] = n; } - m_identity_index_buffer->unmap(); + m_identity_index_buffer = std::make_unique(); + m_identity_index_buffer->create(gl::buffer::target::element_array,dst.size() * sizeof(u32), dst.data(), gl::buffer::memory_type::local); } else if (gl_caps.vendor_NVIDIA) { diff --git a/rpcs3/Emu/RSX/GL/GLHelpers.h b/rpcs3/Emu/RSX/GL/GLHelpers.h index 797f0fd187..7e314d3a66 100644 --- a/rpcs3/Emu/RSX/GL/GLHelpers.h +++ b/rpcs3/Emu/RSX/GL/GLHelpers.h @@ -51,11 +51,16 @@ using namespace ::rsx::format_class_; namespace gl { //Function call wrapped in ARB_DSA vs EXT_DSA compat check -#define DSA_CALL(func, texture_name, target, ...)\ +#define DSA_CALL(func, object_name, target, ...)\ if (::gl::get_driver_caps().ARB_dsa_supported)\ - gl##func(texture_name, __VA_ARGS__);\ + gl##func(object_name, __VA_ARGS__);\ else\ - gl##func##EXT(texture_name, target, __VA_ARGS__); + gl##func##EXT(object_name, target, __VA_ARGS__); + +#define DSA_CALL2(func, object_name, ...)\ + (::gl::get_driver_caps().ARB_dsa_supported) ?\ + gl##func(object_name, __VA_ARGS__) :\ + gl##func##EXT(object_name, __VA_ARGS__) class fence; @@ -520,9 +525,9 @@ namespace gl enum class access { - read = GL_READ_ONLY, - write = GL_WRITE_ONLY, - read_write = GL_READ_WRITE + read = GL_MAP_READ_BIT, + write = GL_MAP_WRITE_BIT, + read_write = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT }; enum class memory_type @@ -735,12 +740,13 @@ namespace gl m_size = size; } - GLubyte* map(access access_) + GLubyte* map(GLsizeiptr offset, GLsizeiptr length, access access_) { ensure(m_memory_type == memory_type::host_visible); - bind(current_target()); - return reinterpret_cast(glMapBuffer(static_cast(current_target()), static_cast(access_))); + const GLenum access_bits = static_cast(access_); + auto raw_data = DSA_CALL2(MapNamedBufferRange, id(), offset, length, access_bits | GL_MAP_UNSYNCHRONIZED_BIT); + return reinterpret_cast(raw_data); } void unmap() diff --git a/rpcs3/Emu/RSX/GL/GLProcTable.h b/rpcs3/Emu/RSX/GL/GLProcTable.h index 0a2a1a34eb..65bf950b51 100644 --- a/rpcs3/Emu/RSX/GL/GLProcTable.h +++ b/rpcs3/Emu/RSX/GL/GLProcTable.h @@ -174,6 +174,9 @@ OPENGL_PROC(PFNGLMAPBUFFERRANGEPROC, MapBufferRange); OPENGL_PROC(PFNGLBINDBUFFERRANGEPROC, BindBufferRange); OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase); +OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEPROC, MapNamedBufferRange); +OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEEXTPROC, MapNamedBufferRangeEXT); + OPENGL_PROC(PFNGLMULTIDRAWELEMENTSPROC, MultiDrawElements); OPENGL_PROC(PFNGLMULTIDRAWARRAYSPROC, MultiDrawArrays); diff --git a/rpcs3/Emu/RSX/GL/GLTexture.cpp b/rpcs3/Emu/RSX/GL/GLTexture.cpp index 864b39afc0..4dec07ed88 100644 --- a/rpcs3/Emu/RSX/GL/GLTexture.cpp +++ b/rpcs3/Emu/RSX/GL/GLTexture.cpp @@ -706,7 +706,7 @@ namespace gl { const u64 row_pitch = rsx::align2(layout.width_in_block * block_size_in_bytes, caps.alignment); image_linear_size = row_pitch * layout.height_in_block * layout.depth; - dst_buffer = { reinterpret_cast(upload_scratch_mem.map(buffer::access::write)), image_linear_size }; + dst_buffer = { reinterpret_cast(upload_scratch_mem.map(0, image_linear_size, gl::buffer::access::write)), image_linear_size }; } auto op = upload_texture_subresource(dst_buffer, layout, format, is_swizzled, caps);