gl: Rewrite buffer mapping

This commit is contained in:
kd-11 2022-05-25 23:49:08 +03:00 committed by kd-11
parent b61c4d3693
commit ed2068fb03
4 changed files with 22 additions and 15 deletions

View File

@ -264,17 +264,15 @@ void GLGSRender::on_init_thread()
if (gl_caps.vendor_AMD) if (gl_caps.vendor_AMD)
{ {
m_identity_index_buffer = std::make_unique<gl::buffer>();
m_identity_index_buffer->create(gl::buffer::target::element_array, 1 * 0x100000, nullptr, gl::buffer::memory_type::host_visible);
// Initialize with 256k identity entries // Initialize with 256k identity entries
auto* dst = reinterpret_cast<u32*>(m_identity_index_buffer->map(gl::buffer::access::write)); std::vector<u32> dst(256 * 1024);
for (u32 n = 0; n < (0x100000 >> 2); ++n) for (u32 n = 0; n < (0x100000 >> 2); ++n)
{ {
dst[n] = n; dst[n] = n;
} }
m_identity_index_buffer->unmap(); m_identity_index_buffer = std::make_unique<gl::buffer>();
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) else if (gl_caps.vendor_NVIDIA)
{ {

View File

@ -51,11 +51,16 @@ using namespace ::rsx::format_class_;
namespace gl namespace gl
{ {
//Function call wrapped in ARB_DSA vs EXT_DSA compat check //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)\ if (::gl::get_driver_caps().ARB_dsa_supported)\
gl##func(texture_name, __VA_ARGS__);\ gl##func(object_name, __VA_ARGS__);\
else\ 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; class fence;
@ -520,9 +525,9 @@ namespace gl
enum class access enum class access
{ {
read = GL_READ_ONLY, read = GL_MAP_READ_BIT,
write = GL_WRITE_ONLY, write = GL_MAP_WRITE_BIT,
read_write = GL_READ_WRITE read_write = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT
}; };
enum class memory_type enum class memory_type
@ -735,12 +740,13 @@ namespace gl
m_size = size; m_size = size;
} }
GLubyte* map(access access_) GLubyte* map(GLsizeiptr offset, GLsizeiptr length, access access_)
{ {
ensure(m_memory_type == memory_type::host_visible); ensure(m_memory_type == memory_type::host_visible);
bind(current_target()); const GLenum access_bits = static_cast<GLenum>(access_);
return reinterpret_cast<GLubyte*>(glMapBuffer(static_cast<GLenum>(current_target()), static_cast<GLenum>(access_))); auto raw_data = DSA_CALL2(MapNamedBufferRange, id(), offset, length, access_bits | GL_MAP_UNSYNCHRONIZED_BIT);
return reinterpret_cast<GLubyte*>(raw_data);
} }
void unmap() void unmap()

View File

@ -174,6 +174,9 @@ OPENGL_PROC(PFNGLMAPBUFFERRANGEPROC, MapBufferRange);
OPENGL_PROC(PFNGLBINDBUFFERRANGEPROC, BindBufferRange); OPENGL_PROC(PFNGLBINDBUFFERRANGEPROC, BindBufferRange);
OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase); OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase);
OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEPROC, MapNamedBufferRange);
OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEEXTPROC, MapNamedBufferRangeEXT);
OPENGL_PROC(PFNGLMULTIDRAWELEMENTSPROC, MultiDrawElements); OPENGL_PROC(PFNGLMULTIDRAWELEMENTSPROC, MultiDrawElements);
OPENGL_PROC(PFNGLMULTIDRAWARRAYSPROC, MultiDrawArrays); OPENGL_PROC(PFNGLMULTIDRAWARRAYSPROC, MultiDrawArrays);

View File

@ -706,7 +706,7 @@ namespace gl
{ {
const u64 row_pitch = rsx::align2<u64, u64>(layout.width_in_block * block_size_in_bytes, caps.alignment); const u64 row_pitch = rsx::align2<u64, u64>(layout.width_in_block * block_size_in_bytes, caps.alignment);
image_linear_size = row_pitch * layout.height_in_block * layout.depth; image_linear_size = row_pitch * layout.height_in_block * layout.depth;
dst_buffer = { reinterpret_cast<std::byte*>(upload_scratch_mem.map(buffer::access::write)), image_linear_size }; dst_buffer = { reinterpret_cast<std::byte*>(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); auto op = upload_texture_subresource(dst_buffer, layout, format, is_swizzled, caps);