From e840645bb793a2e21c7a7e227c337bf4fe6e2819 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 28 Sep 2022 14:52:41 +0200 Subject: [PATCH] r600/sfn:explicitly initialize the memory pool This reduces the overhead of checking with each allocation whether the pool is already initialized. Signed-off-by: Gert Wollny Part-of: --- .../drivers/r600/sfn/sfn_memorypool.cpp | 5 +++-- src/gallium/drivers/r600/sfn/sfn_nir.cpp | 3 +++ .../sfn/tests/sfn_instrfromstring_test.cpp | 20 +++++++++++++++---- .../sfn/tests/sfn_shaderfromstring_test.cpp | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gallium/drivers/r600/sfn/sfn_memorypool.cpp b/src/gallium/drivers/r600/sfn/sfn_memorypool.cpp index 8780d58cf76..bdc2bf41d1f 100644 --- a/src/gallium/drivers/r600/sfn/sfn_memorypool.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_memorypool.cpp @@ -67,7 +67,6 @@ MemoryPool::MemoryPool() noexcept : impl(nullptr) MemoryPool& MemoryPool::instance() { static thread_local MemoryPool me; - me.initialize(); return me; } @@ -85,11 +84,13 @@ void MemoryPool::initialize() void *MemoryPool::allocate(size_t size) { + assert(impl); return impl->pool->allocate(size); } void *MemoryPool::allocate(size_t size, size_t align) { + assert(impl); return impl->pool->allocate(size, align); } @@ -100,7 +101,7 @@ void MemoryPool::release_all() void init_pool() { - MemoryPool::instance(); + MemoryPool::instance().initialize(); } void release_pool() diff --git a/src/gallium/drivers/r600/sfn/sfn_nir.cpp b/src/gallium/drivers/r600/sfn/sfn_nir.cpp index 02eadf92e27..dade732d118 100644 --- a/src/gallium/drivers/r600/sfn/sfn_nir.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_nir.cpp @@ -638,6 +638,9 @@ bool r600_lower_to_scalar_instr_filter(const nir_instr *instr, const void *) class MallocPoolRelease { public: + MallocPoolRelease() { + r600::init_pool(); + } ~MallocPoolRelease() { r600::release_pool(); } diff --git a/src/gallium/drivers/r600/sfn/tests/sfn_instrfromstring_test.cpp b/src/gallium/drivers/r600/sfn/tests/sfn_instrfromstring_test.cpp index 4bb713edc8f..699f229b229 100644 --- a/src/gallium/drivers/r600/sfn/tests/sfn_instrfromstring_test.cpp +++ b/src/gallium/drivers/r600/sfn/tests/sfn_instrfromstring_test.cpp @@ -31,7 +31,10 @@ protected: void check(const Instr& eval, const Instr& expect); void check(const string& init, const Instr& expect); - InstrFactory m_instr_factory; + void SetUp() override; + void TearDown() override; + + InstrFactory *m_instr_factory; }; @@ -693,7 +696,7 @@ TestInstrFromString::TestInstrFromString() PInst TestInstrFromString::from_string(const std::string& s) { - return m_instr_factory.from_string(s, 0); + return m_instr_factory->from_string(s, 0); } void TestInstrFromString::check(const Instr& eval, const Instr& expect) @@ -714,15 +717,24 @@ void TestInstrFromString::check(const string& init, const Instr& expect) void TestInstrFromString::add_dest_from_string(const char *init) { - m_instr_factory.value_factory().dest_from_string(init); + m_instr_factory->value_factory().dest_from_string(init); } void TestInstrFromString::add_dest_vec4_from_string(const char *init) { RegisterVec4::Swizzle dummy; - m_instr_factory.value_factory().dest_vec4_from_string(init, dummy); + m_instr_factory->value_factory().dest_vec4_from_string(init, dummy); } +void TestInstrFromString::SetUp() +{ + MemoryPool::instance().initialize(); + m_instr_factory = new InstrFactory; +} +void TestInstrFromString::TearDown() +{ + MemoryPool::instance().free(); +} } diff --git a/src/gallium/drivers/r600/sfn/tests/sfn_shaderfromstring_test.cpp b/src/gallium/drivers/r600/sfn/tests/sfn_shaderfromstring_test.cpp index 39af43ac95e..1d13c756436 100644 --- a/src/gallium/drivers/r600/sfn/tests/sfn_shaderfromstring_test.cpp +++ b/src/gallium/drivers/r600/sfn/tests/sfn_shaderfromstring_test.cpp @@ -18,8 +18,8 @@ class TestShaderFromString : public ::testing::Test { public: void SetUp() override { - m_instr_factory = new InstrFactory(); init_pool(); + m_instr_factory = new InstrFactory(); } void TearDown() override {