mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
r600/sfn: emulate pmr::monotonic_buffer_resource if needed
libc++ does not yet implement the c++17 monotonic_buffer_resource,
so emulate it by doing normal allocations that are cleaned up
when the resource is destroyed.
v2: - Use C include and version without namespace aligned_alloc
- add include for sstream needed with clang++ (maurossi)
Closes: #6836
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Filip Gawin <filip@gawin.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17452>
This commit is contained in:
parent
3340c7ce35
commit
643623e1a3
5 changed files with 55 additions and 9 deletions
|
|
@ -193,11 +193,18 @@ if with_gallium_opencl
|
|||
r600_c_args += '-DHAVE_OPENCL'
|
||||
endif
|
||||
|
||||
r600_cpp_args = ['-std=c++17']
|
||||
if cpp.has_type('std::pmr::monotonic_buffer_resource',
|
||||
args:['-std=c++17'],
|
||||
prefix : '#include <memory_resource>')
|
||||
r600_cpp_args += '-DHAVE_MEMORY_RESOURCE'
|
||||
endif
|
||||
|
||||
libr600 = static_library(
|
||||
'r600',
|
||||
[files_r600, egd_tables_h],
|
||||
c_args : [r600_c_args, '-Wstrict-overflow=0'],
|
||||
cpp_args: '-std=c++17',
|
||||
cpp_args: r600_cpp_args,
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
include_directories : [
|
||||
inc_src, inc_mapi, inc_mesa, inc_include, inc_compiler, inc_gallium, inc_gallium_aux, inc_amd_common,
|
||||
|
|
|
|||
|
|
@ -29,15 +29,34 @@
|
|||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAVE_MEMORY_RESOURCE
|
||||
#include <memory_resource>
|
||||
#else
|
||||
#include <list>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
namespace r600 {
|
||||
|
||||
#ifndef HAVE_MEMORY_RESOURCE
|
||||
/* Fallback memory resource if the C++17 memory resource is not
|
||||
* avaliable
|
||||
*/
|
||||
struct MemoryBacking {
|
||||
~MemoryBacking();
|
||||
void *allocate(size_t size);
|
||||
void *allocate(size_t size, size_t align);
|
||||
std::list<void *> m_data;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct MemoryPoolImpl {
|
||||
public:
|
||||
MemoryPoolImpl();
|
||||
~MemoryPoolImpl();
|
||||
|
||||
#ifdef HAVE_MEMORY_RESOURCE
|
||||
using MemoryBacking = ::std::pmr::monotonic_buffer_resource;
|
||||
|
||||
#endif
|
||||
MemoryBacking *pool;
|
||||
};
|
||||
|
||||
|
|
@ -109,4 +128,27 @@ MemoryPoolImpl::~MemoryPoolImpl()
|
|||
delete pool;
|
||||
}
|
||||
|
||||
#ifndef HAVE_MEMORY_RESOURCE
|
||||
MemoryBacking::~MemoryBacking()
|
||||
{
|
||||
for (auto p : m_data)
|
||||
free(p);
|
||||
}
|
||||
|
||||
void *MemoryBacking::allocate(size_t size)
|
||||
{
|
||||
void *retval = malloc(size);
|
||||
m_data.push_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void *MemoryBacking::allocate(size_t size, size_t align)
|
||||
{
|
||||
void *retval = aligned_alloc(align, size);
|
||||
m_data.push_back(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,7 @@
|
|||
#include <memory>
|
||||
#include <stack>
|
||||
|
||||
#if __cplusplus >= 21703L
|
||||
#include <memory_resource>
|
||||
#define R600_POINTER_TYPE(X) X *
|
||||
#else
|
||||
#error Need C++17
|
||||
#endif
|
||||
|
||||
namespace r600 {
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@
|
|||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace r600 {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
r600_test_lib = static_library('r600_test', 'sfn_test_shaders.cpp',
|
||||
cpp_args: '-std=c++17',
|
||||
cpp_args: r600_cpp_args,
|
||||
include_directories : [ inc_src, inc_mapi, inc_mesa, inc_include,
|
||||
inc_compiler, inc_gallium, inc_gallium_aux, inc_amd_common,
|
||||
inc_gallium_drivers, ],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue